@upcoming/bee-js 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/cjs/bee.js +59 -9
- package/dist/cjs/chunk/soc.js +2 -2
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/manifest/manifest.js +14 -1
- package/dist/cjs/modules/debug/chequebook.js +6 -5
- package/dist/cjs/modules/debug/connectivity.js +1 -1
- package/dist/cjs/modules/debug/settlements.js +7 -6
- package/dist/cjs/modules/debug/stake.js +5 -4
- package/dist/cjs/modules/debug/states.js +3 -2
- package/dist/cjs/modules/gsoc.js +20 -0
- package/dist/cjs/utils/expose.js +2 -3
- package/dist/cjs/utils/pss.js +3 -3
- package/dist/cjs/utils/stamps.js +8 -21
- package/dist/cjs/utils/tokens.js +48 -0
- package/dist/cjs/utils/type.js +10 -11
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +62 -12
- package/dist/mjs/chunk/soc.js +2 -2
- package/dist/mjs/index.js +1 -0
- package/dist/mjs/manifest/manifest.js +14 -1
- package/dist/mjs/modules/debug/chequebook.js +11 -10
- package/dist/mjs/modules/debug/connectivity.js +3 -3
- package/dist/mjs/modules/debug/settlements.js +13 -12
- package/dist/mjs/modules/debug/stake.js +9 -8
- package/dist/mjs/modules/debug/states.js +5 -4
- package/dist/mjs/modules/gsoc.js +12 -0
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/pss.js +3 -3
- package/dist/mjs/utils/stamps.js +6 -18
- package/dist/mjs/utils/tokens.js +43 -0
- package/dist/mjs/utils/type.js +20 -10
- package/dist/types/bee.d.ts +7 -6
- package/dist/types/chunk/soc.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/manifest/manifest.d.ts +3 -0
- package/dist/types/modules/debug/stake.d.ts +2 -1
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/types/debug.d.ts +17 -16
- package/dist/types/types/index.d.ts +8 -0
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +2 -1
- package/dist/types/utils/stamps.d.ts +2 -11
- package/dist/types/utils/tokens.d.ts +21 -0
- package/dist/types/utils/type.d.ts +2 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -97,6 +97,13 @@ The `toString` method uses `toHex`.
|
|
|
97
97
|
| BatchId | 32 bytes batch ID | - |
|
|
98
98
|
| Span | 8 bytes span (LE) | `static fromBigInt`, `toBigInt` |
|
|
99
99
|
|
|
100
|
+
### Tokens
|
|
101
|
+
|
|
102
|
+
| Name | Description | Methods |
|
|
103
|
+
| ---- | --------------------------- | ------------------------------------------------------------------------------------------------ |
|
|
104
|
+
| DAI | ERC20 DAI token (18 digits) | `static fromDecimalString`, `static fromWei`, `toWeiString`, `toWeiBigInt`, `toDecimalString` |
|
|
105
|
+
| BZZ | ERC20 BZZ token (16 digits) | `static fromDecimalString`, `static fromPLUR`, `toPLURString`, `toPLURBigInt`, `toDecimalString` |
|
|
106
|
+
|
|
100
107
|
### Swarm chunks
|
|
101
108
|
|
|
102
109
|
| Name | Description | Creation |
|
|
@@ -225,8 +232,7 @@ The `toString` method uses `toHex`.
|
|
|
225
232
|
|
|
226
233
|
- `getAmountForTtl`
|
|
227
234
|
- `getDepthForCapacity`
|
|
228
|
-
- `
|
|
229
|
-
- `getStampCostInPlur`
|
|
235
|
+
- `getStampCost`
|
|
230
236
|
- `getStampEffectiveBytes`
|
|
231
237
|
- `getStampMaximumCapacityBytes`
|
|
232
238
|
- `getStampTtlSeconds`
|
package/dist/cjs/bee.js
CHANGED
|
@@ -25,6 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.Bee = void 0;
|
|
27
27
|
const cafe_utility_1 = require("cafe-utility");
|
|
28
|
+
const cac_1 = require("./chunk/cac");
|
|
28
29
|
const soc_1 = require("./chunk/soc");
|
|
29
30
|
const feed_1 = require("./feed");
|
|
30
31
|
const retrievable_1 = require("./feed/retrievable");
|
|
@@ -43,6 +44,7 @@ const transactions = __importStar(require("./modules/debug/transactions"));
|
|
|
43
44
|
const envelope_1 = require("./modules/envelope");
|
|
44
45
|
const feed_2 = require("./modules/feed");
|
|
45
46
|
const grantee = __importStar(require("./modules/grantee"));
|
|
47
|
+
const gsoc = __importStar(require("./modules/gsoc"));
|
|
46
48
|
const pinning = __importStar(require("./modules/pinning"));
|
|
47
49
|
const pss = __importStar(require("./modules/pss"));
|
|
48
50
|
const status = __importStar(require("./modules/status"));
|
|
@@ -235,9 +237,6 @@ class Bee {
|
|
|
235
237
|
/**
|
|
236
238
|
* Upload single file to a Bee node.
|
|
237
239
|
*
|
|
238
|
-
* **To make sure that you won't lose critical data it is highly recommended to also
|
|
239
|
-
* locally pin the data with `options.pin = true`**
|
|
240
|
-
*
|
|
241
240
|
* @param postageBatchId Postage BatchId to be used to upload the data with
|
|
242
241
|
* @param data Data or file to be uploaded
|
|
243
242
|
* @param name Optional name of the uploaded file
|
|
@@ -265,12 +264,6 @@ class Bee {
|
|
|
265
264
|
const fileOptions = { contentType, ...options };
|
|
266
265
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), fileData, postageBatchId, fileName, fileOptions);
|
|
267
266
|
}
|
|
268
|
-
else if ((0, type_1.isReadable)(data) && options?.tag && !options.size) {
|
|
269
|
-
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
270
|
-
const result = await bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
271
|
-
await this.updateTag(options.tag, result.reference);
|
|
272
|
-
return result;
|
|
273
|
-
}
|
|
274
267
|
else {
|
|
275
268
|
return bzz.uploadFile(this.getRequestOptionsForCall(requestOptions), data, postageBatchId, name, options);
|
|
276
269
|
}
|
|
@@ -721,6 +714,63 @@ class Bee {
|
|
|
721
714
|
}
|
|
722
715
|
});
|
|
723
716
|
}
|
|
717
|
+
gsocMine(targetOverlay, identifier, proximity = 16) {
|
|
718
|
+
targetOverlay = new typed_bytes_1.PeerAddress(targetOverlay);
|
|
719
|
+
identifier = new typed_bytes_1.Identifier(identifier);
|
|
720
|
+
const start = 0xb33n;
|
|
721
|
+
for (let i = 0n; i < 0xffffn; i++) {
|
|
722
|
+
const signer = new typed_bytes_1.PrivateKey(cafe_utility_1.Binary.numberToUint256(start + i, 'BE'));
|
|
723
|
+
const socAddress = (0, soc_1.makeSOCAddress)(identifier, signer.publicKey().address());
|
|
724
|
+
const actualProximity = 256 - cafe_utility_1.Binary.proximity(socAddress.toUint8Array(), targetOverlay.toUint8Array(), 256);
|
|
725
|
+
if (actualProximity <= 256 - proximity) {
|
|
726
|
+
return signer;
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
throw Error('Could not mine a valid signer');
|
|
730
|
+
}
|
|
731
|
+
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
732
|
+
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
733
|
+
signer = new typed_bytes_1.PrivateKey(signer);
|
|
734
|
+
identifier = new typed_bytes_1.Identifier(identifier);
|
|
735
|
+
const cac = (0, cac_1.makeContentAddressedChunk)(data);
|
|
736
|
+
const soc = (0, soc_1.makeSingleOwnerChunk)(cac, identifier, signer);
|
|
737
|
+
return gsoc.send(this.getRequestOptionsForCall(requestOptions), soc, postageBatchId, options);
|
|
738
|
+
}
|
|
739
|
+
gsocSubscribe(address, identifier, handler) {
|
|
740
|
+
address = new typed_bytes_1.EthAddress(address);
|
|
741
|
+
identifier = new typed_bytes_1.Identifier(identifier);
|
|
742
|
+
(0, type_1.assertGsocMessageHandler)(handler);
|
|
743
|
+
const socAddress = (0, soc_1.makeSOCAddress)(identifier, address);
|
|
744
|
+
const ws = gsoc.subscribe(this.url, socAddress, this.requestOptions.headers);
|
|
745
|
+
let cancelled = false;
|
|
746
|
+
const cancel = () => {
|
|
747
|
+
if (cancelled === false) {
|
|
748
|
+
cancelled = true;
|
|
749
|
+
if (ws.terminate) {
|
|
750
|
+
ws.terminate();
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
ws.close();
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
const subscription = {
|
|
758
|
+
address,
|
|
759
|
+
cancel,
|
|
760
|
+
};
|
|
761
|
+
ws.onmessage = async (event) => {
|
|
762
|
+
const data = await (0, data_1.prepareWebsocketData)(event.data);
|
|
763
|
+
if (data.length) {
|
|
764
|
+
handler.onMessage(new bytes_1.Bytes(data), subscription);
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
ws.onerror = event => {
|
|
768
|
+
if (!cancelled) {
|
|
769
|
+
handler.onError(new error_1.BeeError(event.message), subscription);
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
return subscription;
|
|
773
|
+
}
|
|
724
774
|
/**
|
|
725
775
|
* Create feed manifest chunk and return the reference to it.
|
|
726
776
|
*
|
package/dist/cjs/chunk/soc.js
CHANGED
|
@@ -86,7 +86,7 @@ exports.makeSOCAddress = makeSOCAddress;
|
|
|
86
86
|
* @param identifier The identifier of the chunk
|
|
87
87
|
* @param signer The signer interface for signing the chunk
|
|
88
88
|
*/
|
|
89
|
-
|
|
89
|
+
function makeSingleOwnerChunk(chunk, identifier, signer) {
|
|
90
90
|
identifier = new typed_bytes_1.Identifier(identifier);
|
|
91
91
|
signer = new typed_bytes_1.PrivateKey(signer);
|
|
92
92
|
const address = makeSOCAddress(identifier, signer.publicKey().address());
|
|
@@ -134,7 +134,7 @@ async function uploadSingleOwnerChunkData(requestOptions, signer, stamp, identif
|
|
|
134
134
|
signer = new typed_bytes_1.PrivateKey(signer);
|
|
135
135
|
identifier = new typed_bytes_1.Identifier(identifier);
|
|
136
136
|
const cac = (0, cac_1.makeContentAddressedChunk)(data);
|
|
137
|
-
const soc =
|
|
137
|
+
const soc = makeSingleOwnerChunk(cac, identifier, signer);
|
|
138
138
|
return uploadSingleOwnerChunk(requestOptions, soc, stamp, options);
|
|
139
139
|
}
|
|
140
140
|
exports.uploadSingleOwnerChunkData = uploadSingleOwnerChunkData;
|
package/dist/cjs/index.js
CHANGED
|
@@ -42,4 +42,5 @@ Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { r
|
|
|
42
42
|
__exportStar(require("./utils/constants"), exports);
|
|
43
43
|
__exportStar(require("./utils/error"), exports);
|
|
44
44
|
exports.Utils = __importStar(require("./utils/expose"));
|
|
45
|
+
__exportStar(require("./utils/tokens"), exports);
|
|
45
46
|
__exportStar(require("./utils/typed-bytes"), exports);
|
|
@@ -29,6 +29,8 @@ class Fork {
|
|
|
29
29
|
b.prefix = b.prefix.slice(commonPart.length);
|
|
30
30
|
node.forks.set(newAFork.prefix[0], newAFork);
|
|
31
31
|
node.forks.set(newBFork.prefix[0], newBFork);
|
|
32
|
+
newAFork.node.parent = node;
|
|
33
|
+
newBFork.node.parent = node;
|
|
32
34
|
return new Fork(commonPart, node);
|
|
33
35
|
}
|
|
34
36
|
marshal() {
|
|
@@ -74,6 +76,7 @@ class MantarayNode {
|
|
|
74
76
|
this.metadata = null;
|
|
75
77
|
this.path = new Uint8Array(0);
|
|
76
78
|
this.forks = new Map();
|
|
79
|
+
this.parent = null;
|
|
77
80
|
if (options?.targetAddress) {
|
|
78
81
|
this.targetAddress = options.targetAddress;
|
|
79
82
|
}
|
|
@@ -89,6 +92,12 @@ class MantarayNode {
|
|
|
89
92
|
if (options?.path) {
|
|
90
93
|
this.path = options.path;
|
|
91
94
|
}
|
|
95
|
+
if (options?.parent) {
|
|
96
|
+
this.parent = options.parent;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
get fullPath() {
|
|
100
|
+
return cafe_utility_1.Binary.concatBytes(this.parent?.fullPath ?? new Uint8Array(0), this.path);
|
|
92
101
|
}
|
|
93
102
|
async marshal() {
|
|
94
103
|
for (const fork of this.forks.values()) {
|
|
@@ -131,7 +140,9 @@ class MantarayNode {
|
|
|
131
140
|
const forkBitmap = reader.read(32);
|
|
132
141
|
for (let i = 0; i < 256; i++) {
|
|
133
142
|
if (cafe_utility_1.Binary.getBit(forkBitmap, i, 'LE')) {
|
|
134
|
-
|
|
143
|
+
const newFork = Fork.unmarshal(reader);
|
|
144
|
+
node.forks.set(i, newFork);
|
|
145
|
+
newFork.node.parent = node;
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
148
|
return node;
|
|
@@ -163,11 +174,13 @@ class MantarayNode {
|
|
|
163
174
|
if (existing) {
|
|
164
175
|
const fork = Fork.split(newFork, existing);
|
|
165
176
|
tip.forks.set(remainingPath[0], fork);
|
|
177
|
+
fork.node.parent = tip;
|
|
166
178
|
tip.selfAddress = null;
|
|
167
179
|
tip = newFork.node;
|
|
168
180
|
}
|
|
169
181
|
else {
|
|
170
182
|
tip.forks.set(remainingPath[0], newFork);
|
|
183
|
+
newFork.node.parent = tip;
|
|
171
184
|
tip.selfAddress = null;
|
|
172
185
|
tip = newFork.node;
|
|
173
186
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.withdrawTokens = exports.depositTokens = exports.getLastCheques = exports.getLastChequesForPeer = exports.cashoutLastCheque = exports.getLastCashoutAction = exports.getChequebookBalance = exports.getChequebookAddress = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
|
+
const tokens_1 = require("../../utils/tokens");
|
|
6
7
|
const type_1 = require("../../utils/type");
|
|
7
8
|
const typed_bytes_1 = require("../../utils/typed-bytes");
|
|
8
9
|
const chequebookEndpoint = 'chequebook';
|
|
@@ -34,8 +35,8 @@ async function getChequebookBalance(requestOptions) {
|
|
|
34
35
|
});
|
|
35
36
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
36
37
|
return {
|
|
37
|
-
availableBalance: (0, type_1.asNumberString)(body.availableBalance, { name: 'availableBalance' }),
|
|
38
|
-
totalBalance: (0, type_1.asNumberString)(body.totalBalance, { name: 'totalBalance' }),
|
|
38
|
+
availableBalance: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.availableBalance, { name: 'availableBalance' })),
|
|
39
|
+
totalBalance: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.totalBalance, { name: 'totalBalance' })),
|
|
39
40
|
};
|
|
40
41
|
}
|
|
41
42
|
exports.getChequebookBalance = getChequebookBalance;
|
|
@@ -53,7 +54,7 @@ async function getLastCashoutAction(requestOptions, peer) {
|
|
|
53
54
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
54
55
|
return {
|
|
55
56
|
peer: cafe_utility_1.Types.asString(body.peer, { name: 'peer' }),
|
|
56
|
-
uncashedAmount: (0, type_1.asNumberString)(body.uncashedAmount, { name: 'uncashedAmount' }),
|
|
57
|
+
uncashedAmount: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.uncashedAmount, { name: 'uncashedAmount' })),
|
|
57
58
|
transactionHash: cafe_utility_1.Types.asNullableString(body.transactionHash),
|
|
58
59
|
lastCashedCheque: cafe_utility_1.Types.asNullable(x => asCheque(x), body.lastCashedCheque),
|
|
59
60
|
result: cafe_utility_1.Types.asNullable(x => asCashoutResult(x), body.result),
|
|
@@ -130,14 +131,14 @@ function asCheque(x) {
|
|
|
130
131
|
return {
|
|
131
132
|
beneficiary: new typed_bytes_1.EthAddress(cafe_utility_1.Types.asString(object.beneficiary, { name: 'beneficiary' })),
|
|
132
133
|
chequebook: new typed_bytes_1.EthAddress(cafe_utility_1.Types.asString(object.chequebook, { name: 'chequebook' })),
|
|
133
|
-
payout: (0, type_1.asNumberString)(object.payout, { name: 'payout' }),
|
|
134
|
+
payout: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(object.payout, { name: 'payout' })),
|
|
134
135
|
};
|
|
135
136
|
}
|
|
136
137
|
function asCashoutResult(x) {
|
|
137
138
|
const object = cafe_utility_1.Types.asObject(x, { name: 'cashout result' });
|
|
138
139
|
return {
|
|
139
140
|
recipient: cafe_utility_1.Types.asString(object.recipient, { name: 'recipient' }),
|
|
140
|
-
lastPayout: (0, type_1.asNumberString)(object.lastPayout, { name: 'lastPayout' }),
|
|
141
|
+
lastPayout: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(object.lastPayout, { name: 'lastPayout' })),
|
|
141
142
|
bounced: cafe_utility_1.Types.asBoolean(object.bounced, { name: 'bounced' }),
|
|
142
143
|
};
|
|
143
144
|
}
|
|
@@ -11,7 +11,7 @@ async function getNodeAddresses(requestOptions) {
|
|
|
11
11
|
});
|
|
12
12
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
13
13
|
return {
|
|
14
|
-
overlay: cafe_utility_1.Types.asString(body.overlay, { name: 'overlay' }),
|
|
14
|
+
overlay: new typed_bytes_1.PeerAddress(cafe_utility_1.Types.asString(body.overlay, { name: 'overlay' })),
|
|
15
15
|
underlay: cafe_utility_1.Types.asArray(body.underlay, { name: 'underlay' }).map(x => cafe_utility_1.Types.asString(x, { name: 'underlay' })),
|
|
16
16
|
ethereum: new typed_bytes_1.EthAddress(cafe_utility_1.Types.asString(body.ethereum, { name: 'ethereum' })),
|
|
17
17
|
publicKey: new typed_bytes_1.PublicKey(cafe_utility_1.Types.asString(body.publicKey, { name: 'publicKey' })),
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getAllSettlements = exports.getSettlements = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
|
+
const tokens_1 = require("../../utils/tokens");
|
|
6
7
|
const type_1 = require("../../utils/type");
|
|
7
8
|
const settlementsEndpoint = 'settlements';
|
|
8
9
|
/**
|
|
@@ -19,8 +20,8 @@ async function getSettlements(requestOptions, peer) {
|
|
|
19
20
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
20
21
|
return {
|
|
21
22
|
peer: cafe_utility_1.Types.asString(body.peer, { name: 'peer' }),
|
|
22
|
-
sent: (0, type_1.asNumberString)(body.sent, { name: 'sent' }),
|
|
23
|
-
received: (0, type_1.asNumberString)(body.received, { name: 'received' }),
|
|
23
|
+
sent: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.sent, { name: 'sent' })),
|
|
24
|
+
received: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.received, { name: 'received' })),
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
27
|
exports.getSettlements = getSettlements;
|
|
@@ -35,16 +36,16 @@ async function getAllSettlements(requestOptions) {
|
|
|
35
36
|
responseType: 'json',
|
|
36
37
|
});
|
|
37
38
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
38
|
-
const totalSent = (0, type_1.asNumberString)(body.totalSent, { name: 'totalSent' });
|
|
39
|
-
const totalReceived = (0, type_1.asNumberString)(body.totalReceived, { name: 'totalReceived' });
|
|
39
|
+
const totalSent = tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.totalSent, { name: 'totalSent' }));
|
|
40
|
+
const totalReceived = tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.totalReceived, { name: 'totalReceived' }));
|
|
40
41
|
const settlements = cafe_utility_1.Types.asArray(body.settlements, { name: 'settlements' }).map(x => cafe_utility_1.Types.asObject(x, { name: 'settlement' }));
|
|
41
42
|
return {
|
|
42
43
|
totalSent,
|
|
43
44
|
totalReceived,
|
|
44
45
|
settlements: settlements.map(x => ({
|
|
45
46
|
peer: cafe_utility_1.Types.asString(x.peer, { name: 'peer' }),
|
|
46
|
-
sent: (0, type_1.asNumberString)(x.sent, { name: 'sent' }),
|
|
47
|
-
received: (0, type_1.asNumberString)(x.received, { name: 'received' }),
|
|
47
|
+
sent: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(x.sent, { name: 'sent' })),
|
|
48
|
+
received: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(x.received, { name: 'received' })),
|
|
48
49
|
})),
|
|
49
50
|
};
|
|
50
51
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getRedistributionState = exports.stake = exports.getStake = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
|
+
const tokens_1 = require("../../utils/tokens");
|
|
6
7
|
const type_1 = require("../../utils/type");
|
|
7
8
|
const STAKE_ENDPOINT = 'stake';
|
|
8
9
|
const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
|
|
@@ -18,7 +19,7 @@ async function getStake(requestOptions) {
|
|
|
18
19
|
url: `${STAKE_ENDPOINT}`,
|
|
19
20
|
});
|
|
20
21
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
21
|
-
return (0, type_1.asNumberString)(body.stakedAmount, { name: 'stakedAmount' });
|
|
22
|
+
return tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.stakedAmount, { name: 'stakedAmount' }));
|
|
22
23
|
}
|
|
23
24
|
exports.getStake = getStake;
|
|
24
25
|
/**
|
|
@@ -57,7 +58,7 @@ async function getRedistributionState(requestOptions) {
|
|
|
57
58
|
});
|
|
58
59
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
59
60
|
return {
|
|
60
|
-
minimumGasFunds: (0, type_1.asNumberString)(body.minimumGasFunds, { name: 'minimumGasFunds' }),
|
|
61
|
+
minimumGasFunds: tokens_1.DAI.fromWei((0, type_1.asNumberString)(body.minimumGasFunds, { name: 'minimumGasFunds' })),
|
|
61
62
|
hasSufficientFunds: cafe_utility_1.Types.asBoolean(body.hasSufficientFunds, { name: 'hasSufficientFunds' }),
|
|
62
63
|
isFrozen: cafe_utility_1.Types.asBoolean(body.isFrozen, { name: 'isFrozen' }),
|
|
63
64
|
isFullySynced: cafe_utility_1.Types.asBoolean(body.isFullySynced, { name: 'isFullySynced' }),
|
|
@@ -69,8 +70,8 @@ async function getRedistributionState(requestOptions) {
|
|
|
69
70
|
lastSelectedRound: cafe_utility_1.Types.asNumber(body.lastSelectedRound, { name: 'lastSelectedRound' }),
|
|
70
71
|
lastSampleDurationSeconds: cafe_utility_1.Types.asNumber(body.lastSampleDurationSeconds, { name: 'lastSampleDurationSeconds' }),
|
|
71
72
|
block: cafe_utility_1.Types.asNumber(body.block, { name: 'block' }),
|
|
72
|
-
reward: (0, type_1.asNumberString)(body.reward, { name: 'reward' }),
|
|
73
|
-
fees: (0, type_1.asNumberString)(body.fees, { name: 'fees' }),
|
|
73
|
+
reward: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.reward, { name: 'reward' })),
|
|
74
|
+
fees: tokens_1.DAI.fromWei((0, type_1.asNumberString)(body.fees, { name: 'fees' })),
|
|
74
75
|
isHealthy: cafe_utility_1.Types.asBoolean(body.isHealthy, { name: 'isHealthy' }),
|
|
75
76
|
};
|
|
76
77
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getWalletBalance = exports.getChainState = exports.getReserveState = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
|
+
const tokens_1 = require("../../utils/tokens");
|
|
6
7
|
const type_1 = require("../../utils/type");
|
|
7
8
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
8
9
|
const WALLET_ENDPOINT = 'wallet';
|
|
@@ -59,8 +60,8 @@ async function getWalletBalance(requestOptions) {
|
|
|
59
60
|
});
|
|
60
61
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
61
62
|
return {
|
|
62
|
-
bzzBalance: (0, type_1.asNumberString)(body.bzzBalance, { name: 'bzzBalance' }),
|
|
63
|
-
nativeTokenBalance: (0, type_1.asNumberString)(body.nativeTokenBalance, { name: 'nativeTokenBalance' }),
|
|
63
|
+
bzzBalance: tokens_1.BZZ.fromPLUR((0, type_1.asNumberString)(body.bzzBalance, { name: 'bzzBalance' })),
|
|
64
|
+
nativeTokenBalance: tokens_1.DAI.fromWei((0, type_1.asNumberString)(body.nativeTokenBalance, { name: 'nativeTokenBalance' })),
|
|
64
65
|
chainID: cafe_utility_1.Types.asNumber(body.chainID, { name: 'chainID' }),
|
|
65
66
|
chequebookContractAddress: cafe_utility_1.Types.asString(body.chequebookContractAddress, { name: 'chequebookContractAddress' }),
|
|
66
67
|
walletAddress: cafe_utility_1.Types.asString(body.walletAddress, { name: 'walletAddress' }),
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.subscribe = exports.send = void 0;
|
|
7
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
8
|
+
const soc_1 = require("../chunk/soc");
|
|
9
|
+
const endpoint = 'gsoc';
|
|
10
|
+
async function send(requestOptions, soc, stamp, options) {
|
|
11
|
+
return (0, soc_1.uploadSingleOwnerChunk)(requestOptions, soc, stamp, options);
|
|
12
|
+
}
|
|
13
|
+
exports.send = send;
|
|
14
|
+
function subscribe(url, reference, headers) {
|
|
15
|
+
const wsUrl = url.replace(/^http/i, 'ws');
|
|
16
|
+
return new isomorphic_ws_1.default(`${wsUrl}/${endpoint}/subscribe/${reference.toHex()}`, {
|
|
17
|
+
headers,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
exports.subscribe = subscribe;
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.
|
|
3
|
+
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCost = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
6
|
var collection_node_1 = require("./collection.node");
|
|
@@ -14,8 +14,7 @@ Object.defineProperty(exports, "getRedundancyStats", { enumerable: true, get: fu
|
|
|
14
14
|
var stamps_1 = require("./stamps");
|
|
15
15
|
Object.defineProperty(exports, "getAmountForTtl", { enumerable: true, get: function () { return stamps_1.getAmountForTtl; } });
|
|
16
16
|
Object.defineProperty(exports, "getDepthForCapacity", { enumerable: true, get: function () { return stamps_1.getDepthForCapacity; } });
|
|
17
|
-
Object.defineProperty(exports, "
|
|
18
|
-
Object.defineProperty(exports, "getStampCostInPlur", { enumerable: true, get: function () { return stamps_1.getStampCostInPlur; } });
|
|
17
|
+
Object.defineProperty(exports, "getStampCost", { enumerable: true, get: function () { return stamps_1.getStampCost; } });
|
|
19
18
|
Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytes; } });
|
|
20
19
|
Object.defineProperty(exports, "getStampMaximumCapacityBytes", { enumerable: true, get: function () { return stamps_1.getStampMaximumCapacityBytes; } });
|
|
21
20
|
Object.defineProperty(exports, "getStampTtlSeconds", { enumerable: true, get: function () { return stamps_1.getStampTtlSeconds; } });
|
package/dist/cjs/utils/pss.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeMaxTarget = void 0;
|
|
4
|
-
const cafe_utility_1 = require("cafe-utility");
|
|
5
4
|
const types_1 = require("../types");
|
|
5
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
6
6
|
/**
|
|
7
7
|
* Utility function that for given strings/reference takes the most specific
|
|
8
8
|
* target that Bee node will except.
|
|
@@ -11,7 +11,7 @@ const types_1 = require("../types");
|
|
|
11
11
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/develop/tools-and-features/pss)
|
|
12
12
|
*/
|
|
13
13
|
function makeMaxTarget(target) {
|
|
14
|
-
|
|
15
|
-
return
|
|
14
|
+
target = new typed_bytes_1.PeerAddress(target);
|
|
15
|
+
return target.toHex().slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
|
|
16
16
|
}
|
|
17
17
|
exports.makeMaxTarget = makeMaxTarget;
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.
|
|
3
|
+
exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCost = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const bytes_1 = require("./bytes");
|
|
6
|
+
const tokens_1 = require("./tokens");
|
|
6
7
|
const type_1 = require("./type");
|
|
7
8
|
/**
|
|
8
9
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
@@ -62,26 +63,12 @@ function getStampEffectiveBytes(depth) {
|
|
|
62
63
|
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
63
64
|
/**
|
|
64
65
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
65
|
-
*
|
|
66
|
-
* @returns {number} The cost of the postage batch in PLUR (10000000000000000 [1e16] PLUR = 1 BZZ)
|
|
67
|
-
*/
|
|
68
|
-
function getStampCostInPlur(depth, amount) {
|
|
69
|
-
const amountBigint = BigInt((0, type_1.asNumberString)(amount));
|
|
70
|
-
return 2n ** BigInt(depth) * amountBigint;
|
|
71
|
-
}
|
|
72
|
-
exports.getStampCostInPlur = getStampCostInPlur;
|
|
73
|
-
/**
|
|
74
|
-
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
75
|
-
*
|
|
76
|
-
* The returned number is lossy and should be used for display purposes only.
|
|
77
|
-
*
|
|
78
|
-
* @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
|
|
79
66
|
*/
|
|
80
|
-
function
|
|
81
|
-
const
|
|
82
|
-
return
|
|
67
|
+
function getStampCost(depth, amount) {
|
|
68
|
+
const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
|
|
69
|
+
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * amountBigInt);
|
|
83
70
|
}
|
|
84
|
-
exports.
|
|
71
|
+
exports.getStampCost = getStampCost;
|
|
85
72
|
/**
|
|
86
73
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
87
74
|
*
|
|
@@ -90,8 +77,8 @@ exports.getStampCostInBzz = getStampCostInBzz;
|
|
|
90
77
|
* @returns {number} The TTL of the postage batch in seconds.
|
|
91
78
|
*/
|
|
92
79
|
function getStampTtlSeconds(amount, pricePerBlock = 24000, blockTime = 5) {
|
|
93
|
-
const
|
|
94
|
-
return (
|
|
80
|
+
const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
|
|
81
|
+
return (amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock);
|
|
95
82
|
}
|
|
96
83
|
exports.getStampTtlSeconds = getStampTtlSeconds;
|
|
97
84
|
/**
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DAI = exports.BZZ = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
class BZZ {
|
|
6
|
+
constructor(state) {
|
|
7
|
+
this.state = state;
|
|
8
|
+
}
|
|
9
|
+
static fromDecimalString(string) {
|
|
10
|
+
return new BZZ(cafe_utility_1.FixedPointNumber.fromDecimalString(string, BZZ.DIGITS));
|
|
11
|
+
}
|
|
12
|
+
static fromPLUR(plur) {
|
|
13
|
+
return new BZZ(new cafe_utility_1.FixedPointNumber(plur, BZZ.DIGITS));
|
|
14
|
+
}
|
|
15
|
+
toPLURString() {
|
|
16
|
+
return this.state.toString();
|
|
17
|
+
}
|
|
18
|
+
toPLURBigInt() {
|
|
19
|
+
return this.state.value;
|
|
20
|
+
}
|
|
21
|
+
toDecimalString() {
|
|
22
|
+
return this.state.toDecimalString();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.BZZ = BZZ;
|
|
26
|
+
BZZ.DIGITS = 16;
|
|
27
|
+
class DAI {
|
|
28
|
+
constructor(state) {
|
|
29
|
+
this.state = state;
|
|
30
|
+
}
|
|
31
|
+
static fromDecimalString(string) {
|
|
32
|
+
return new DAI(cafe_utility_1.FixedPointNumber.fromDecimalString(string, DAI.DIGITS));
|
|
33
|
+
}
|
|
34
|
+
static fromWei(wei) {
|
|
35
|
+
return new DAI(new cafe_utility_1.FixedPointNumber(wei, DAI.DIGITS));
|
|
36
|
+
}
|
|
37
|
+
toWeiString() {
|
|
38
|
+
return this.state.toString();
|
|
39
|
+
}
|
|
40
|
+
toWeiBigInt() {
|
|
41
|
+
return this.state.value;
|
|
42
|
+
}
|
|
43
|
+
toDecimalString() {
|
|
44
|
+
return this.state.toDecimalString();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.DAI = DAI;
|
|
48
|
+
DAI.DIGITS = 18;
|
package/dist/cjs/utils/type.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertPssMessageHandler = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.asNumberString = exports.isReadable = void 0;
|
|
26
|
+
exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = exports.assertPostageBatchOptions = exports.assertGsocMessageHandler = exports.assertPssMessageHandler = exports.isTag = exports.assertCollectionUploadOptions = exports.assertFileUploadOptions = exports.assertUploadOptions = exports.assertRequestOptions = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.asNumberString = exports.isReadable = void 0;
|
|
27
27
|
const cafe_utility_1 = require("cafe-utility");
|
|
28
28
|
const stream = __importStar(require("stream"));
|
|
29
29
|
const types_1 = require("../types");
|
|
@@ -144,18 +144,17 @@ function isTag(value) {
|
|
|
144
144
|
}
|
|
145
145
|
exports.isTag = isTag;
|
|
146
146
|
function assertPssMessageHandler(value) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
const handler = value;
|
|
151
|
-
if (typeof handler.onMessage !== 'function') {
|
|
152
|
-
throw new TypeError('onMessage property of PssMessageHandler has to be function!');
|
|
153
|
-
}
|
|
154
|
-
if (typeof handler.onError !== 'function') {
|
|
155
|
-
throw new TypeError('onError property of PssMessageHandler has to be function!');
|
|
156
|
-
}
|
|
147
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'PssMessageHandler' });
|
|
148
|
+
cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' });
|
|
149
|
+
cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' });
|
|
157
150
|
}
|
|
158
151
|
exports.assertPssMessageHandler = assertPssMessageHandler;
|
|
152
|
+
function assertGsocMessageHandler(value) {
|
|
153
|
+
const object = cafe_utility_1.Types.asObject(value, { name: 'GsocMessageHandler' });
|
|
154
|
+
cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' });
|
|
155
|
+
cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' });
|
|
156
|
+
}
|
|
157
|
+
exports.assertGsocMessageHandler = assertGsocMessageHandler;
|
|
159
158
|
function assertPostageBatchOptions(value) {
|
|
160
159
|
if (value === undefined) {
|
|
161
160
|
return;
|