@upcoming/bee-js 9.8.0 → 9.9.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/dist/cjs/bee.js +14 -11
- package/dist/cjs/manifest/manifest.js +23 -3
- package/dist/cjs/utils/duration.js +6 -2
- package/dist/cjs/utils/http.js +6 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +10 -9
- package/dist/mjs/manifest/manifest.js +23 -3
- package/dist/mjs/utils/duration.js +7 -3
- package/dist/mjs/utils/http.js +8 -0
- package/dist/types/utils/duration.d.ts +2 -0
- package/package.json +3 -1
package/dist/cjs/bee.js
CHANGED
|
@@ -1232,9 +1232,10 @@ class Bee {
|
|
|
1232
1232
|
const chainState = await this.getChainState(options);
|
|
1233
1233
|
const depthDelta = depth - batch.depth;
|
|
1234
1234
|
const multiplier = depthDelta === 0 ? 1n : 2n ** BigInt(depthDelta);
|
|
1235
|
-
const
|
|
1236
|
-
|
|
1237
|
-
multiplier
|
|
1235
|
+
const additionalAmount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1236
|
+
const targetAmount = duration.isZero()
|
|
1237
|
+
? BigInt(batch.amount) * multiplier
|
|
1238
|
+
: (BigInt(batch.amount) + additionalAmount) * multiplier;
|
|
1238
1239
|
const amountDelta = targetAmount - BigInt(batch.amount);
|
|
1239
1240
|
const transactionId = await this.topUpBatch(batch.batchID, amountDelta, options);
|
|
1240
1241
|
if (depthDelta) {
|
|
@@ -1249,7 +1250,7 @@ class Bee {
|
|
|
1249
1250
|
if (delta <= 0) {
|
|
1250
1251
|
throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1251
1252
|
}
|
|
1252
|
-
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta -
|
|
1253
|
+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * (2n ** BigInt(delta) - 1n) + 1n, options);
|
|
1253
1254
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1254
1255
|
}
|
|
1255
1256
|
async extendStorageDuration(postageBatchId, duration, options) {
|
|
@@ -1261,11 +1262,13 @@ class Bee {
|
|
|
1261
1262
|
async getExtensionCost(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
|
|
1262
1263
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
1263
1264
|
const chainState = await this.getChainState(options);
|
|
1264
|
-
const amount =
|
|
1265
|
+
const amount = duration.isZero()
|
|
1266
|
+
? 0n
|
|
1267
|
+
: (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
|
|
1265
1268
|
const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
|
|
1266
|
-
const
|
|
1267
|
-
const
|
|
1268
|
-
return
|
|
1269
|
+
const currentCost = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
|
|
1270
|
+
const newCost = (0, stamps_1.getStampCost)(depth, BigInt(batch.amount) + amount);
|
|
1271
|
+
return newCost.minus(currentCost);
|
|
1269
1272
|
}
|
|
1270
1273
|
async getSizeExtensionCost(postageBatchId, size, options, encryption, erasureCodeLevel) {
|
|
1271
1274
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
@@ -1274,9 +1277,9 @@ class Bee {
|
|
|
1274
1277
|
if (delta <= 0) {
|
|
1275
1278
|
throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1276
1279
|
}
|
|
1277
|
-
const
|
|
1278
|
-
const
|
|
1279
|
-
return
|
|
1280
|
+
const currentCost = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
|
|
1281
|
+
const newCost = (0, stamps_1.getStampCost)(depth, batch.amount);
|
|
1282
|
+
return newCost.minus(currentCost);
|
|
1280
1283
|
}
|
|
1281
1284
|
async getDurationExtensionCost(postageBatchId, duration, options) {
|
|
1282
1285
|
const batch = await this.getPostageBatch(postageBatchId, options);
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.MantarayNode = exports.Fork = void 0;
|
|
4
7
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
|
+
const debug_1 = __importDefault(require("debug"));
|
|
5
9
|
const __1 = require("..");
|
|
6
10
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
11
|
+
const debug = (0, debug_1.default)('bee-js:manifest');
|
|
7
12
|
const ENCODER = new TextEncoder();
|
|
8
13
|
const DECODER = new TextDecoder();
|
|
9
14
|
const TYPE_VALUE = 2;
|
|
@@ -61,6 +66,11 @@ class Fork {
|
|
|
61
66
|
data.push(new Uint8Array(30 - this.prefix.length));
|
|
62
67
|
}
|
|
63
68
|
data.push(this.node.selfAddress);
|
|
69
|
+
debug('marshalling fork', {
|
|
70
|
+
prefixLength: this.prefix.length,
|
|
71
|
+
prefix: DECODER.decode(this.prefix),
|
|
72
|
+
address: cafe_utility_1.Binary.uint8ArrayToHex(this.node.selfAddress),
|
|
73
|
+
});
|
|
64
74
|
if (this.node.metadata) {
|
|
65
75
|
const metadataBytes = cafe_utility_1.Binary.padEndToMultiple(new Uint8Array([0x00, 0x00, ...ENCODER.encode(JSON.stringify(this.node.metadata))]), 32, 0x0a);
|
|
66
76
|
const metadataLengthBytes = cafe_utility_1.Binary.numberToUint16(metadataBytes.length - 2, 'BE');
|
|
@@ -73,8 +83,17 @@ class Fork {
|
|
|
73
83
|
const type = cafe_utility_1.Binary.uint8ToNumber(reader.read(1));
|
|
74
84
|
const prefixLength = cafe_utility_1.Binary.uint8ToNumber(reader.read(1));
|
|
75
85
|
const prefix = reader.read(prefixLength);
|
|
76
|
-
|
|
86
|
+
if (prefixLength < 30) {
|
|
87
|
+
reader.read(30 - prefixLength);
|
|
88
|
+
}
|
|
77
89
|
const selfAddress = reader.read(addressLength);
|
|
90
|
+
debug('unmarshalling fork', {
|
|
91
|
+
type,
|
|
92
|
+
prefixLength,
|
|
93
|
+
prefix: DECODER.decode(prefix),
|
|
94
|
+
addressLength,
|
|
95
|
+
address: cafe_utility_1.Binary.uint8ArrayToHex(selfAddress),
|
|
96
|
+
});
|
|
78
97
|
let metadata = undefined;
|
|
79
98
|
if (isType(type, TYPE_WITH_METADATA)) {
|
|
80
99
|
const metadataLength = cafe_utility_1.Binary.uint16ToNumber(reader.read(2), 'BE');
|
|
@@ -209,12 +228,12 @@ class MantarayNode {
|
|
|
209
228
|
throw new Error('MantarayNode#unmarshal invalid version hash');
|
|
210
229
|
}
|
|
211
230
|
const targetAddressLength = cafe_utility_1.Binary.uint8ToNumber(reader.read(1));
|
|
212
|
-
const targetAddress = targetAddressLength
|
|
231
|
+
const targetAddress = targetAddressLength ? reader.read(targetAddressLength) : __1.NULL_ADDRESS;
|
|
213
232
|
const node = new MantarayNode({ selfAddress, targetAddress, obfuscationKey });
|
|
214
233
|
const forkBitmap = reader.read(32);
|
|
215
234
|
for (let i = 0; i < 256; i++) {
|
|
216
235
|
if (cafe_utility_1.Binary.getBit(forkBitmap, i, 'LE')) {
|
|
217
|
-
const newFork = Fork.unmarshal(reader,
|
|
236
|
+
const newFork = Fork.unmarshal(reader, selfAddress.length);
|
|
218
237
|
node.forks.set(i, newFork);
|
|
219
238
|
newFork.node.parent = node;
|
|
220
239
|
}
|
|
@@ -227,6 +246,7 @@ class MantarayNode {
|
|
|
227
246
|
addFork(path, reference, metadata) {
|
|
228
247
|
this.selfAddress = null;
|
|
229
248
|
path = path instanceof Uint8Array ? path : ENCODER.encode(path);
|
|
249
|
+
debug('adding fork', { path: DECODER.decode(path), reference: new typed_bytes_1.Reference(reference).represent() });
|
|
230
250
|
// TODO: this should not be ignored
|
|
231
251
|
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
232
252
|
let tip = this;
|
|
@@ -5,8 +5,8 @@ const cafe_utility_1 = require("cafe-utility");
|
|
|
5
5
|
class Duration {
|
|
6
6
|
constructor(seconds) {
|
|
7
7
|
this.seconds = Math.ceil(seconds);
|
|
8
|
-
if (seconds
|
|
9
|
-
throw Error('Duration
|
|
8
|
+
if (seconds < 0) {
|
|
9
|
+
throw Error('Duration cannot be negative');
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
static fromMilliseconds(milliseconds) {
|
|
@@ -51,5 +51,9 @@ class Duration {
|
|
|
51
51
|
represent() {
|
|
52
52
|
return cafe_utility_1.Dates.secondsToHumanTime(this.seconds);
|
|
53
53
|
}
|
|
54
|
+
isZero() {
|
|
55
|
+
return this.seconds === 0;
|
|
56
|
+
}
|
|
54
57
|
}
|
|
55
58
|
exports.Duration = Duration;
|
|
59
|
+
Duration.ZERO = new Duration(0);
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -6,7 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.http = exports.DEFAULT_HTTP_CONFIG = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
9
10
|
const index_1 = require("../index");
|
|
11
|
+
const debug = (0, debug_1.default)('bee-js:http');
|
|
10
12
|
const { AxiosError } = axios_1.default;
|
|
11
13
|
const MAX_FAILED_ATTEMPTS = 100000;
|
|
12
14
|
const DELAY_FAST = 200;
|
|
@@ -41,6 +43,10 @@ async function http(options, config) {
|
|
|
41
43
|
let failedAttempts = 0;
|
|
42
44
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
43
45
|
try {
|
|
46
|
+
debug(`${requestConfig.method || 'get'} ${cafe_utility_1.Strings.joinUrl([
|
|
47
|
+
requestConfig.baseURL,
|
|
48
|
+
requestConfig.url,
|
|
49
|
+
])}`, { headers: { ...requestConfig.headers }, params: requestConfig.params });
|
|
44
50
|
maybeRunOnRequestHook(options, requestConfig);
|
|
45
51
|
const response = await (0, axios_1.default)(requestConfig);
|
|
46
52
|
return response;
|