@ethersphere/bee-js 8.3.1 → 9.0.2
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 +192 -50
- package/dist/cjs/bee-dev.js +78 -0
- package/dist/cjs/bee.js +341 -417
- package/dist/cjs/chunk/bmt.js +15 -32
- package/dist/cjs/chunk/cac.js +26 -36
- package/dist/cjs/chunk/soc.js +56 -51
- package/dist/cjs/feed/identifier.js +3 -28
- package/dist/cjs/feed/index.js +95 -44
- package/dist/cjs/feed/retrievable.js +11 -22
- package/dist/cjs/index.js +17 -1
- package/dist/cjs/manifest/manifest.js +369 -0
- package/dist/cjs/modules/bytes.js +24 -12
- package/dist/cjs/modules/bzz.js +24 -34
- package/dist/cjs/modules/chunk.js +13 -7
- package/dist/cjs/modules/debug/balance.js +29 -4
- package/dist/cjs/modules/debug/chequebook.js +60 -16
- package/dist/cjs/modules/debug/connectivity.js +82 -4
- package/dist/cjs/modules/debug/settlements.js +22 -2
- package/dist/cjs/modules/debug/stake.js +29 -11
- package/dist/cjs/modules/debug/stamps.js +88 -7
- package/dist/cjs/modules/debug/states.js +25 -3
- package/dist/cjs/modules/debug/status.js +45 -47
- package/dist/cjs/modules/debug/transactions.js +27 -5
- package/dist/cjs/modules/envelope.js +8 -6
- package/dist/cjs/modules/feed.js +25 -10
- package/dist/cjs/modules/grantee.js +18 -12
- package/dist/cjs/modules/gsoc.js +24 -0
- package/dist/cjs/modules/pinning.js +13 -2
- package/dist/cjs/modules/pss.js +9 -3
- package/dist/cjs/modules/soc.js +9 -4
- package/dist/cjs/modules/stewardship.js +7 -3
- package/dist/cjs/modules/tag.js +35 -3
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/stamper/stamper.js +43 -0
- package/dist/cjs/types/debug.js +16 -1
- package/dist/cjs/types/index.js +2 -24
- package/dist/cjs/utils/bytes.js +67 -115
- package/dist/cjs/utils/chunk-size.js +17 -0
- package/dist/cjs/utils/chunk-stream.browser.js +85 -0
- package/dist/cjs/utils/chunk-stream.js +84 -0
- package/dist/cjs/utils/cid.js +5 -6
- package/dist/cjs/utils/collection.browser.js +2 -2
- package/dist/cjs/utils/collection.js +3 -2
- package/dist/cjs/utils/collection.node.js +0 -2
- package/dist/cjs/utils/constants.js +7 -3
- package/dist/cjs/utils/data.browser.js +6 -3
- package/dist/cjs/utils/data.js +8 -4
- package/dist/cjs/utils/duration.js +51 -0
- package/dist/cjs/utils/expose.js +11 -40
- package/dist/cjs/utils/headers.js +79 -52
- package/dist/cjs/utils/http.js +34 -10
- package/dist/cjs/utils/mime.js +78 -0
- package/dist/cjs/utils/pss.js +3 -4
- package/dist/cjs/utils/redundancy.js +18 -14
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/cjs/utils/size.js +35 -0
- package/dist/cjs/utils/stamps.js +67 -51
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/tokens.js +144 -0
- package/dist/cjs/utils/type.js +142 -350
- package/dist/cjs/utils/typed-bytes.js +179 -0
- package/dist/cjs/utils/upload-progress.js +2 -0
- package/dist/cjs/utils/url.js +0 -4
- package/dist/cjs/utils/workaround.js +27 -0
- package/dist/index.browser.min.js +1 -2
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +367 -411
- package/dist/mjs/chunk/bmt.js +13 -29
- package/dist/mjs/chunk/cac.js +26 -34
- package/dist/mjs/chunk/soc.js +57 -53
- package/dist/mjs/feed/identifier.js +3 -26
- package/dist/mjs/feed/index.js +98 -51
- package/dist/mjs/feed/retrievable.js +12 -23
- package/dist/mjs/index.js +10 -1
- package/dist/mjs/manifest/manifest.js +371 -0
- package/dist/mjs/modules/bytes.js +27 -15
- package/dist/mjs/modules/bzz.js +25 -32
- package/dist/mjs/modules/chunk.js +16 -8
- package/dist/mjs/modules/debug/balance.js +61 -4
- package/dist/mjs/modules/debug/chequebook.js +116 -16
- package/dist/mjs/modules/debug/connectivity.js +144 -3
- package/dist/mjs/modules/debug/settlements.js +46 -2
- package/dist/mjs/modules/debug/stake.js +69 -11
- package/dist/mjs/modules/debug/stamps.js +184 -7
- package/dist/mjs/modules/debug/states.js +55 -3
- package/dist/mjs/modules/debug/status.js +97 -45
- package/dist/mjs/modules/debug/transactions.js +61 -5
- package/dist/mjs/modules/envelope.js +11 -9
- package/dist/mjs/modules/feed.js +26 -10
- package/dist/mjs/modules/grantee.js +35 -13
- package/dist/mjs/modules/gsoc.js +16 -0
- package/dist/mjs/modules/pinning.js +23 -2
- package/dist/mjs/modules/pss.js +10 -4
- package/dist/mjs/modules/soc.js +10 -5
- package/dist/mjs/modules/stewardship.js +14 -4
- package/dist/mjs/modules/tag.js +93 -3
- package/dist/mjs/package.json +2 -1
- package/dist/mjs/stamper/stamper.js +39 -0
- package/dist/mjs/types/debug.js +15 -1
- package/dist/mjs/types/index.js +2 -24
- package/dist/mjs/utils/bytes.js +63 -104
- package/dist/mjs/utils/chunk-size.js +13 -0
- package/dist/mjs/utils/chunk-stream.browser.js +85 -0
- package/dist/mjs/utils/chunk-stream.js +87 -0
- package/dist/mjs/utils/cid.js +5 -6
- package/dist/mjs/utils/collection.browser.js +2 -2
- package/dist/mjs/utils/collection.js +2 -2
- package/dist/mjs/utils/collection.node.js +0 -2
- package/dist/mjs/utils/constants.js +6 -2
- package/dist/mjs/utils/data.browser.js +9 -3
- package/dist/mjs/utils/data.js +12 -4
- package/dist/mjs/utils/duration.js +47 -0
- package/dist/mjs/utils/expose.js +2 -7
- package/dist/mjs/utils/headers.js +73 -48
- package/dist/mjs/utils/http.js +33 -11
- package/dist/mjs/utils/mime.js +75 -0
- package/dist/mjs/utils/pss.js +3 -4
- package/dist/mjs/utils/redundancy.js +18 -8
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/mjs/utils/size.js +31 -0
- package/dist/mjs/utils/stamps.js +47 -44
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/tokens.js +139 -0
- package/dist/mjs/utils/type.js +216 -310
- package/dist/mjs/utils/typed-bytes.js +160 -0
- package/dist/mjs/utils/upload-progress.js +1 -0
- package/dist/mjs/utils/url.js +0 -4
- package/dist/mjs/utils/workaround.js +22 -0
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +88 -165
- package/dist/types/chunk/bmt.d.ts +2 -2
- package/dist/types/chunk/cac.d.ts +7 -24
- package/dist/types/chunk/soc.d.ts +15 -15
- package/dist/types/feed/identifier.d.ts +2 -4
- package/dist/types/feed/index.d.ts +14 -18
- package/dist/types/feed/retrievable.d.ts +3 -4
- package/dist/types/index.d.ts +28 -1
- package/dist/types/manifest/manifest.d.ts +106 -0
- package/dist/types/modules/bytes.d.ts +8 -5
- package/dist/types/modules/bzz.d.ts +8 -10
- package/dist/types/modules/chunk.d.ts +4 -3
- package/dist/types/modules/debug/balance.d.ts +3 -2
- package/dist/types/modules/debug/chequebook.d.ts +7 -6
- package/dist/types/modules/debug/connectivity.d.ts +5 -3
- package/dist/types/modules/debug/settlements.d.ts +2 -1
- package/dist/types/modules/debug/stake.d.ts +4 -2
- package/dist/types/modules/debug/stamps.d.ts +5 -4
- package/dist/types/modules/debug/status.d.ts +6 -25
- package/dist/types/modules/debug/transactions.d.ts +5 -4
- package/dist/types/modules/envelope.d.ts +3 -2
- package/dist/types/modules/feed.d.ts +20 -16
- package/dist/types/modules/grantee.d.ts +7 -6
- package/dist/types/modules/gsoc.d.ts +7 -0
- package/dist/types/modules/pinning.d.ts +2 -4
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/stewardship.d.ts +4 -4
- package/dist/types/modules/tag.d.ts +2 -1
- package/dist/types/stamper/stamper.d.ts +15 -0
- package/dist/types/types/debug.d.ts +63 -115
- package/dist/types/types/index.d.ts +103 -204
- package/dist/types/utils/bytes.d.ts +16 -90
- package/dist/types/utils/chunk-size.d.ts +1 -0
- package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
- package/dist/types/utils/chunk-stream.d.ts +6 -0
- package/dist/types/utils/cid.d.ts +3 -2
- package/dist/types/utils/collection.browser.d.ts +2 -2
- package/dist/types/utils/collection.d.ts +2 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/constants.d.ts +4 -1
- package/dist/types/utils/duration.d.ts +17 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +2 -7
- package/dist/types/utils/headers.d.ts +3 -4
- package/dist/types/utils/mime.d.ts +1 -0
- package/dist/types/utils/pss.d.ts +2 -2
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/dist/types/utils/size.d.ts +16 -0
- package/dist/types/utils/stamps.d.ts +27 -33
- package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
- package/dist/types/utils/tar-uploader.d.ts +3 -4
- package/dist/types/utils/tokens.d.ts +77 -0
- package/dist/types/utils/type.d.ts +20 -52
- package/dist/types/utils/typed-bytes.d.ts +68 -0
- package/dist/types/utils/upload-progress.d.ts +4 -0
- package/dist/types/utils/workaround.d.ts +2 -0
- package/package.json +11 -17
- package/dist/cjs/chunk/signer.js +0 -126
- package/dist/cjs/chunk/span.js +0 -25
- package/dist/cjs/feed/json.js +0 -28
- package/dist/cjs/feed/topic.js +0 -25
- package/dist/cjs/feed/type.js +0 -15
- package/dist/cjs/modules/debug/chunk.js +0 -21
- package/dist/cjs/modules/debug/tag.js +0 -19
- package/dist/cjs/utils/eth.js +0 -216
- package/dist/cjs/utils/hash.js +0 -21
- package/dist/cjs/utils/hex.js +0 -150
- package/dist/cjs/utils/reference.js +0 -36
- package/dist/index.browser.min.js.LICENSE.txt +0 -8
- package/dist/mjs/chunk/signer.js +0 -114
- package/dist/mjs/chunk/span.js +0 -21
- package/dist/mjs/feed/json.js +0 -26
- package/dist/mjs/feed/topic.js +0 -19
- package/dist/mjs/feed/type.js +0 -10
- package/dist/mjs/modules/debug/chunk.js +0 -17
- package/dist/mjs/modules/debug/tag.js +0 -15
- package/dist/mjs/utils/eth.js +0 -192
- package/dist/mjs/utils/hash.js +0 -16
- package/dist/mjs/utils/hex.js +0 -135
- package/dist/mjs/utils/reference.js +0 -29
- package/dist/types/chunk/signer.d.ts +0 -31
- package/dist/types/chunk/span.d.ts +0 -10
- package/dist/types/feed/json.d.ts +0 -4
- package/dist/types/feed/topic.d.ts +0 -3
- package/dist/types/feed/type.d.ts +0 -6
- package/dist/types/modules/debug/chunk.d.ts +0 -10
- package/dist/types/modules/debug/tag.d.ts +0 -8
- package/dist/types/utils/eth.d.ts +0 -67
- package/dist/types/utils/hash.d.ts +0 -9
- package/dist/types/utils/hex.d.ts +0 -86
- package/dist/types/utils/reference.d.ts +0 -2
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.
|
|
3
|
+
exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForSize = exports.getAmountForDuration = exports.getStampDuration = exports.getStampCost = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampTheoreticalBytes = exports.getStampUsage = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
const duration_1 = require("./duration");
|
|
7
|
+
const tokens_1 = require("./tokens");
|
|
8
|
+
const type_1 = require("./type");
|
|
5
9
|
/**
|
|
6
10
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
7
11
|
*
|
|
@@ -14,16 +18,16 @@ function getStampUsage(utilization, depth, bucketDepth) {
|
|
|
14
18
|
}
|
|
15
19
|
exports.getStampUsage = getStampUsage;
|
|
16
20
|
/**
|
|
17
|
-
* Utility function that calculates the theoritical maximum
|
|
21
|
+
* Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
|
|
18
22
|
*
|
|
19
|
-
* For smaller depths (up to
|
|
23
|
+
* For smaller depths (up to 22), this may provide less accurate results.
|
|
20
24
|
*
|
|
21
|
-
* @returns {number} The maximum
|
|
25
|
+
* @returns {number} The maximum theoretical size of the postage batch in bytes.
|
|
22
26
|
*/
|
|
23
|
-
function
|
|
24
|
-
return 2 ** depth
|
|
27
|
+
function getStampTheoreticalBytes(depth) {
|
|
28
|
+
return 4096 * 2 ** depth;
|
|
25
29
|
}
|
|
26
|
-
exports.
|
|
30
|
+
exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
|
|
27
31
|
/**
|
|
28
32
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
29
33
|
*/
|
|
@@ -42,86 +46,98 @@ const utilisationRateMap = {
|
|
|
42
46
|
33: 0.9842,
|
|
43
47
|
34: 0.9889,
|
|
44
48
|
};
|
|
49
|
+
const effectiveSizeBreakpoints = [
|
|
50
|
+
[22, 4.93],
|
|
51
|
+
[23, 17.03],
|
|
52
|
+
[24, 44.21],
|
|
53
|
+
[25, 102.78],
|
|
54
|
+
[26, 225.87],
|
|
55
|
+
[27, 480.44],
|
|
56
|
+
[28, 1001.44],
|
|
57
|
+
[29, 2060.27],
|
|
58
|
+
[30, 4201.9],
|
|
59
|
+
[31, 8519.02],
|
|
60
|
+
[32, 17199.89],
|
|
61
|
+
[33, 34628.46],
|
|
62
|
+
];
|
|
45
63
|
/**
|
|
46
|
-
* Utility function that calculates the effective
|
|
64
|
+
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
47
65
|
*
|
|
48
|
-
* Below 22 depth the effective
|
|
66
|
+
* Below 22 depth the effective size is 0
|
|
49
67
|
* Above 34 it's always > 99%
|
|
50
68
|
*
|
|
51
|
-
* @returns {number} The effective
|
|
69
|
+
* @returns {number} The effective size of the postage batch in bytes.
|
|
52
70
|
*/
|
|
53
71
|
function getStampEffectiveBytes(depth) {
|
|
54
72
|
if (depth < 22) {
|
|
55
73
|
return 0;
|
|
56
74
|
}
|
|
57
75
|
const utilRate = utilisationRateMap[depth] ?? 0.99;
|
|
58
|
-
return
|
|
76
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * utilRate);
|
|
59
77
|
}
|
|
60
78
|
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return 2 ** depth * amount;
|
|
79
|
+
function getStampEffectiveBytesBreakpoints() {
|
|
80
|
+
const map = new Map();
|
|
81
|
+
for (let i = 22; i < 35; i++) {
|
|
82
|
+
map.set(i, getStampEffectiveBytes(i));
|
|
83
|
+
}
|
|
84
|
+
return map;
|
|
68
85
|
}
|
|
69
|
-
exports.
|
|
86
|
+
exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
|
|
70
87
|
/**
|
|
71
88
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
72
|
-
*
|
|
73
|
-
* @returns {number} The cost of the postage batch in BZZ (1 BZZ = 10000000000000000 [1e16] PLUR)
|
|
74
89
|
*/
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
return getStampCostInPlur(depth, amount) / BZZ_UNIT;
|
|
90
|
+
function getStampCost(depth, amount) {
|
|
91
|
+
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
|
|
78
92
|
}
|
|
79
|
-
exports.
|
|
93
|
+
exports.getStampCost = getStampCost;
|
|
80
94
|
/**
|
|
81
95
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
82
96
|
*
|
|
83
97
|
* For more accurate results, get the price per block and block time from the Bee node or the blockchain.
|
|
84
98
|
*
|
|
85
|
-
* @returns {number} The TTL of the postage batch
|
|
99
|
+
* @returns {number} The TTL of the postage batch.
|
|
86
100
|
*/
|
|
87
|
-
function
|
|
88
|
-
|
|
101
|
+
function getStampDuration(amount, pricePerBlock, blockTime = 5) {
|
|
102
|
+
const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
|
|
103
|
+
return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
|
|
89
104
|
}
|
|
90
|
-
exports.
|
|
105
|
+
exports.getStampDuration = getStampDuration;
|
|
91
106
|
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* This function estimates the required amount based on the provided TTL in days.
|
|
107
|
+
* Get the postage batch `amount` required for a given `duration`.
|
|
95
108
|
*
|
|
96
|
-
* @param
|
|
97
|
-
* @
|
|
109
|
+
* @param duration A duration object representing the duration of the storage.
|
|
110
|
+
* @param pricePerBlock The price per block in PLUR.
|
|
111
|
+
* @param blockTime The block time in seconds.
|
|
98
112
|
*/
|
|
99
|
-
function
|
|
100
|
-
|
|
101
|
-
return ((days <= 0 ? 1 : days) * 414720000).toString();
|
|
113
|
+
function getAmountForDuration(duration, pricePerBlock, blockTime = 5) {
|
|
114
|
+
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock);
|
|
102
115
|
}
|
|
103
|
-
exports.
|
|
116
|
+
exports.getAmountForDuration = getAmountForDuration;
|
|
104
117
|
/**
|
|
105
|
-
* Utility function that calculates the depth required for a postage batch to achieve the specified
|
|
118
|
+
* Utility function that calculates the depth required for a postage batch to achieve the specified effective size
|
|
106
119
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @param {number} gigabytes - The desired capacity of the postage batch in gigabytes.
|
|
110
|
-
* @returns {number} The calculated depth necessary to achieve the specified capacity.
|
|
120
|
+
* @param size The effective size of the postage batch
|
|
121
|
+
* @returns
|
|
111
122
|
*/
|
|
112
|
-
function
|
|
113
|
-
|
|
123
|
+
function getDepthForSize(size) {
|
|
124
|
+
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
125
|
+
if (size.toGigabytes() <= sizeBreakpoint) {
|
|
126
|
+
return depth;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return 34;
|
|
114
130
|
}
|
|
115
|
-
exports.
|
|
116
|
-
function convertEnvelopeToMarshaledStamp(
|
|
117
|
-
return marshalStamp(envelope.signature,
|
|
131
|
+
exports.getDepthForSize = getDepthForSize;
|
|
132
|
+
function convertEnvelopeToMarshaledStamp(envelope) {
|
|
133
|
+
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
|
118
134
|
}
|
|
119
135
|
exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
|
|
120
|
-
function marshalStamp(signature,
|
|
136
|
+
function marshalStamp(signature, batchId, timestamp, index) {
|
|
121
137
|
if (signature.length !== 65) {
|
|
122
138
|
throw Error('invalid signature length');
|
|
123
139
|
}
|
|
124
|
-
if (
|
|
140
|
+
if (batchId.length !== 32) {
|
|
125
141
|
throw Error('invalid batch ID length');
|
|
126
142
|
}
|
|
127
143
|
if (timestamp.length !== 8) {
|
|
@@ -130,6 +146,6 @@ function marshalStamp(signature, batchID, timestamp, index) {
|
|
|
130
146
|
if (index.length !== 8) {
|
|
131
147
|
throw Error('invalid index length');
|
|
132
148
|
}
|
|
133
|
-
return cafe_utility_1.Binary.concatBytes(
|
|
149
|
+
return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
|
|
134
150
|
}
|
|
135
151
|
exports.marshalStamp = marshalStamp;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadTar = void 0;
|
|
4
|
-
const
|
|
4
|
+
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
7
7
|
const tar_writer_1 = require("./tar-writer");
|
|
@@ -18,7 +18,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
18
18
|
headers: {
|
|
19
19
|
'content-type': 'application/x-tar',
|
|
20
20
|
'swarm-collection': 'true',
|
|
21
|
-
...(0,
|
|
21
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
return response;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadTar = void 0;
|
|
4
|
-
const
|
|
4
|
+
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
7
7
|
const tar_writer_1 = require("./tar-writer");
|
|
@@ -16,7 +16,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
16
16
|
headers: {
|
|
17
17
|
'content-type': 'application/x-tar',
|
|
18
18
|
'swarm-collection': 'true',
|
|
19
|
-
...(0,
|
|
19
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
await (0, tar_writer_1.writeTar)(collection, tarStream);
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
toSignificantDigits(digits) {
|
|
25
|
+
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Does not mutate the current BZZ instance.
|
|
29
|
+
*
|
|
30
|
+
* @param other BZZ instance, or amount in PLUR
|
|
31
|
+
* @returns New BZZ instance
|
|
32
|
+
*/
|
|
33
|
+
plus(other) {
|
|
34
|
+
return new BZZ(this.state.add(other instanceof BZZ ? other.state : new cafe_utility_1.FixedPointNumber(other, BZZ.DIGITS)));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Does not mutate the current BZZ instance.
|
|
38
|
+
*
|
|
39
|
+
* @param other BZZ instance, or amount in PLUR
|
|
40
|
+
* @returns New BZZ instance
|
|
41
|
+
*/
|
|
42
|
+
minus(other) {
|
|
43
|
+
return new BZZ(this.state.subtract(other instanceof BZZ ? other.state : new cafe_utility_1.FixedPointNumber(other, BZZ.DIGITS)));
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Does not mutate the current BZZ instance.
|
|
47
|
+
*
|
|
48
|
+
* @param other Divisor
|
|
49
|
+
* @returns New BZZ instance
|
|
50
|
+
*/
|
|
51
|
+
divide(other) {
|
|
52
|
+
return new BZZ(this.state.divmod(other)[0]);
|
|
53
|
+
}
|
|
54
|
+
gt(other) {
|
|
55
|
+
return this.state.compare(other.state) === 1;
|
|
56
|
+
}
|
|
57
|
+
gte(other) {
|
|
58
|
+
return this.state.compare(other.state) !== -1;
|
|
59
|
+
}
|
|
60
|
+
lt(other) {
|
|
61
|
+
return this.state.compare(other.state) === -1;
|
|
62
|
+
}
|
|
63
|
+
lte(other) {
|
|
64
|
+
return this.state.compare(other.state) !== 1;
|
|
65
|
+
}
|
|
66
|
+
eq(other) {
|
|
67
|
+
return this.state.compare(other.state) === 0;
|
|
68
|
+
}
|
|
69
|
+
exchangeToDAI(daiPerBzz) {
|
|
70
|
+
return DAI.fromWei(this.state.exchange('*', new cafe_utility_1.FixedPointNumber(daiPerBzz.toWeiBigInt(), DAI.DIGITS), DAI.DIGITS).value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
exports.BZZ = BZZ;
|
|
74
|
+
BZZ.DIGITS = 16;
|
|
75
|
+
class DAI {
|
|
76
|
+
constructor(state) {
|
|
77
|
+
this.state = state;
|
|
78
|
+
}
|
|
79
|
+
static fromDecimalString(string) {
|
|
80
|
+
return new DAI(cafe_utility_1.FixedPointNumber.fromDecimalString(string, DAI.DIGITS));
|
|
81
|
+
}
|
|
82
|
+
static fromWei(wei) {
|
|
83
|
+
return new DAI(new cafe_utility_1.FixedPointNumber(wei, DAI.DIGITS));
|
|
84
|
+
}
|
|
85
|
+
toWeiString() {
|
|
86
|
+
return this.state.toString();
|
|
87
|
+
}
|
|
88
|
+
toWeiBigInt() {
|
|
89
|
+
return this.state.value;
|
|
90
|
+
}
|
|
91
|
+
toDecimalString() {
|
|
92
|
+
return this.state.toDecimalString();
|
|
93
|
+
}
|
|
94
|
+
toSignificantDigits(digits) {
|
|
95
|
+
return this.toDecimalString().slice(0, this.toDecimalString().indexOf('.') + digits + 1);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Does not mutate the current DAI instance.
|
|
99
|
+
*
|
|
100
|
+
* @param other DAI instance, or amount in PLUR
|
|
101
|
+
* @returns New DAI instance
|
|
102
|
+
*/
|
|
103
|
+
plus(other) {
|
|
104
|
+
return new DAI(this.state.add(other instanceof DAI ? other.state : new cafe_utility_1.FixedPointNumber(other, DAI.DIGITS)));
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Does not mutate the current DAI instance.
|
|
108
|
+
*
|
|
109
|
+
* @param other DAI instance, or amount in PLUR
|
|
110
|
+
* @returns New DAI instance
|
|
111
|
+
*/
|
|
112
|
+
minus(other) {
|
|
113
|
+
return new DAI(this.state.subtract(other instanceof DAI ? other.state : new cafe_utility_1.FixedPointNumber(other, DAI.DIGITS)));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Does not mutate the current DAI instance.
|
|
117
|
+
*
|
|
118
|
+
* @param other Divisor
|
|
119
|
+
* @returns New DAI instance
|
|
120
|
+
*/
|
|
121
|
+
divide(other) {
|
|
122
|
+
return new DAI(this.state.divmod(other)[0]);
|
|
123
|
+
}
|
|
124
|
+
gt(other) {
|
|
125
|
+
return this.state.compare(other.state) === 1;
|
|
126
|
+
}
|
|
127
|
+
gte(other) {
|
|
128
|
+
return this.state.compare(other.state) !== -1;
|
|
129
|
+
}
|
|
130
|
+
lt(other) {
|
|
131
|
+
return this.state.compare(other.state) === -1;
|
|
132
|
+
}
|
|
133
|
+
lte(other) {
|
|
134
|
+
return this.state.compare(other.state) !== 1;
|
|
135
|
+
}
|
|
136
|
+
eq(other) {
|
|
137
|
+
return this.state.compare(other.state) === 0;
|
|
138
|
+
}
|
|
139
|
+
exchangeToBZZ(daiPerBzz) {
|
|
140
|
+
return BZZ.fromPLUR(this.state.exchange('/', new cafe_utility_1.FixedPointNumber(daiPerBzz.toWeiBigInt(), DAI.DIGITS), BZZ.DIGITS).value);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.DAI = DAI;
|
|
144
|
+
DAI.DIGITS = 18;
|