@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
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import { Duration } from "../../utils/duration.js";
|
|
1
3
|
import { http } from "../../utils/http.js";
|
|
4
|
+
import { Size } from "../../utils/size.js";
|
|
5
|
+
import { getStampEffectiveBytes, getStampTheoreticalBytes, getStampUsage } from "../../utils/stamps.js";
|
|
6
|
+
import { asNumberString } from "../../utils/type.js";
|
|
7
|
+
import { BatchId, EthAddress } from "../../utils/typed-bytes.js";
|
|
8
|
+
import { normalizeBatchTTL } from "../../utils/workaround.js";
|
|
2
9
|
const STAMPS_ENDPOINT = 'stamps';
|
|
3
10
|
const BATCHES_ENDPOINT = 'batches';
|
|
4
11
|
export async function getGlobalPostageBatches(requestOptions) {
|
|
@@ -7,7 +14,40 @@ export async function getGlobalPostageBatches(requestOptions) {
|
|
|
7
14
|
url: `${BATCHES_ENDPOINT}`,
|
|
8
15
|
responseType: 'json'
|
|
9
16
|
});
|
|
10
|
-
|
|
17
|
+
const body = Types.asObject(response.data, {
|
|
18
|
+
name: 'response.data'
|
|
19
|
+
});
|
|
20
|
+
const batches = Types.asArray(body.batches, {
|
|
21
|
+
name: 'batches'
|
|
22
|
+
}).map(x => Types.asObject(x, {
|
|
23
|
+
name: 'batch'
|
|
24
|
+
}));
|
|
25
|
+
return batches.map(x => ({
|
|
26
|
+
batchID: new BatchId(Types.asString(x.batchID, {
|
|
27
|
+
name: 'batchID'
|
|
28
|
+
})),
|
|
29
|
+
batchTTL: Types.asNumber(x.batchTTL, {
|
|
30
|
+
name: 'batchTTL'
|
|
31
|
+
}),
|
|
32
|
+
bucketDepth: Types.asNumber(x.bucketDepth, {
|
|
33
|
+
name: 'bucketDepth'
|
|
34
|
+
}),
|
|
35
|
+
depth: Types.asNumber(x.depth, {
|
|
36
|
+
name: 'depth'
|
|
37
|
+
}),
|
|
38
|
+
immutable: Types.asBoolean(x.immutable, {
|
|
39
|
+
name: 'immutable'
|
|
40
|
+
}),
|
|
41
|
+
owner: new EthAddress(Types.asString(x.owner, {
|
|
42
|
+
name: 'owner'
|
|
43
|
+
})),
|
|
44
|
+
start: Types.asNumber(x.start, {
|
|
45
|
+
name: 'start'
|
|
46
|
+
}),
|
|
47
|
+
value: asNumberString(x.value, {
|
|
48
|
+
name: 'value'
|
|
49
|
+
})
|
|
50
|
+
}));
|
|
11
51
|
}
|
|
12
52
|
export async function getAllPostageBatches(requestOptions) {
|
|
13
53
|
const response = await http(requestOptions, {
|
|
@@ -15,7 +55,59 @@ export async function getAllPostageBatches(requestOptions) {
|
|
|
15
55
|
url: `${STAMPS_ENDPOINT}`,
|
|
16
56
|
responseType: 'json'
|
|
17
57
|
});
|
|
18
|
-
|
|
58
|
+
const body = Types.asObject(response.data, {
|
|
59
|
+
name: 'response.data'
|
|
60
|
+
});
|
|
61
|
+
const stamps = Types.asArray(body.stamps, {
|
|
62
|
+
name: 'stamps'
|
|
63
|
+
}).map(x => Types.asObject(x, {
|
|
64
|
+
name: 'stamp'
|
|
65
|
+
}));
|
|
66
|
+
return stamps.map(x => {
|
|
67
|
+
const utilization = Types.asNumber(x.utilization, {
|
|
68
|
+
name: 'utilization'
|
|
69
|
+
});
|
|
70
|
+
const depth = Types.asNumber(x.depth, {
|
|
71
|
+
name: 'depth'
|
|
72
|
+
});
|
|
73
|
+
const bucketDepth = Types.asNumber(x.bucketDepth, {
|
|
74
|
+
name: 'bucketDepth'
|
|
75
|
+
});
|
|
76
|
+
const usage = getStampUsage(utilization, depth, bucketDepth);
|
|
77
|
+
const batchTTL = normalizeBatchTTL(Types.asNumber(x.batchTTL, {
|
|
78
|
+
name: 'batchTTL'
|
|
79
|
+
}));
|
|
80
|
+
const duration = Duration.fromSeconds(batchTTL);
|
|
81
|
+
return {
|
|
82
|
+
batchID: new BatchId(Types.asString(x.batchID, {
|
|
83
|
+
name: 'batchID'
|
|
84
|
+
})),
|
|
85
|
+
utilization,
|
|
86
|
+
usable: Types.asBoolean(x.usable, {
|
|
87
|
+
name: 'usable'
|
|
88
|
+
}),
|
|
89
|
+
label: Types.asEmptiableString(x.label, {
|
|
90
|
+
name: 'label'
|
|
91
|
+
}),
|
|
92
|
+
depth,
|
|
93
|
+
amount: asNumberString(x.amount, {
|
|
94
|
+
name: 'amount'
|
|
95
|
+
}),
|
|
96
|
+
bucketDepth,
|
|
97
|
+
blockNumber: Types.asNumber(x.blockNumber, {
|
|
98
|
+
name: 'blockNumber'
|
|
99
|
+
}),
|
|
100
|
+
immutableFlag: Types.asBoolean(x.immutableFlag, {
|
|
101
|
+
name: 'immutableFlag'
|
|
102
|
+
}),
|
|
103
|
+
usage,
|
|
104
|
+
usageText: `${Math.round(usage * 100)}%`,
|
|
105
|
+
size: Size.fromBytes(getStampEffectiveBytes(depth)),
|
|
106
|
+
remainingSize: Size.fromBytes(Math.ceil(getStampEffectiveBytes(depth) * (1 - usage))),
|
|
107
|
+
theoreticalSize: Size.fromBytes(getStampTheoreticalBytes(depth)),
|
|
108
|
+
duration
|
|
109
|
+
};
|
|
110
|
+
});
|
|
19
111
|
}
|
|
20
112
|
export async function getPostageBatch(requestOptions, postageBatchId) {
|
|
21
113
|
const response = await http(requestOptions, {
|
|
@@ -23,7 +115,52 @@ export async function getPostageBatch(requestOptions, postageBatchId) {
|
|
|
23
115
|
url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
|
|
24
116
|
responseType: 'json'
|
|
25
117
|
});
|
|
26
|
-
|
|
118
|
+
const body = Types.asObject(response.data, {
|
|
119
|
+
name: 'response.data'
|
|
120
|
+
});
|
|
121
|
+
const utilization = Types.asNumber(body.utilization, {
|
|
122
|
+
name: 'utilization'
|
|
123
|
+
});
|
|
124
|
+
const depth = Types.asNumber(body.depth, {
|
|
125
|
+
name: 'depth'
|
|
126
|
+
});
|
|
127
|
+
const bucketDepth = Types.asNumber(body.bucketDepth, {
|
|
128
|
+
name: 'bucketDepth'
|
|
129
|
+
});
|
|
130
|
+
const usage = getStampUsage(utilization, depth, bucketDepth);
|
|
131
|
+
const batchTTL = normalizeBatchTTL(Types.asNumber(body.batchTTL, {
|
|
132
|
+
name: 'batchTTL'
|
|
133
|
+
}));
|
|
134
|
+
const duration = Duration.fromSeconds(batchTTL);
|
|
135
|
+
return {
|
|
136
|
+
batchID: new BatchId(Types.asString(body.batchID, {
|
|
137
|
+
name: 'batchID'
|
|
138
|
+
})),
|
|
139
|
+
utilization,
|
|
140
|
+
usable: Types.asBoolean(body.usable, {
|
|
141
|
+
name: 'usable'
|
|
142
|
+
}),
|
|
143
|
+
label: Types.asEmptiableString(body.label, {
|
|
144
|
+
name: 'label'
|
|
145
|
+
}),
|
|
146
|
+
depth,
|
|
147
|
+
amount: asNumberString(body.amount, {
|
|
148
|
+
name: 'amount'
|
|
149
|
+
}),
|
|
150
|
+
bucketDepth,
|
|
151
|
+
blockNumber: Types.asNumber(body.blockNumber, {
|
|
152
|
+
name: 'blockNumber'
|
|
153
|
+
}),
|
|
154
|
+
immutableFlag: Types.asBoolean(body.immutableFlag, {
|
|
155
|
+
name: 'immutableFlag'
|
|
156
|
+
}),
|
|
157
|
+
usage,
|
|
158
|
+
usageText: `${Math.round(usage * 100)}%`,
|
|
159
|
+
size: Size.fromBytes(getStampEffectiveBytes(depth)),
|
|
160
|
+
remainingSize: Size.fromBytes(Math.ceil(getStampEffectiveBytes(depth) * (1 - usage))),
|
|
161
|
+
theoreticalSize: Size.fromBytes(getStampTheoreticalBytes(depth)),
|
|
162
|
+
duration
|
|
163
|
+
};
|
|
27
164
|
}
|
|
28
165
|
export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
|
|
29
166
|
const response = await http(requestOptions, {
|
|
@@ -31,7 +168,32 @@ export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
|
|
|
31
168
|
url: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
|
|
32
169
|
responseType: 'json'
|
|
33
170
|
});
|
|
34
|
-
|
|
171
|
+
const body = Types.asObject(response.data, {
|
|
172
|
+
name: 'response.data'
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
depth: Types.asNumber(body.depth, {
|
|
176
|
+
name: 'depth'
|
|
177
|
+
}),
|
|
178
|
+
bucketDepth: Types.asNumber(body.bucketDepth, {
|
|
179
|
+
name: 'bucketDepth'
|
|
180
|
+
}),
|
|
181
|
+
bucketUpperBound: Types.asNumber(body.bucketUpperBound, {
|
|
182
|
+
name: 'bucketUpperBound'
|
|
183
|
+
}),
|
|
184
|
+
buckets: Types.asArray(body.buckets, {
|
|
185
|
+
name: 'buckets'
|
|
186
|
+
}).map(x => Types.asObject(x, {
|
|
187
|
+
name: 'bucket'
|
|
188
|
+
})).map(x => ({
|
|
189
|
+
bucketID: Types.asNumber(x.bucketID, {
|
|
190
|
+
name: 'bucketID'
|
|
191
|
+
}),
|
|
192
|
+
collisions: Types.asNumber(x.collisions, {
|
|
193
|
+
name: 'collisions'
|
|
194
|
+
})
|
|
195
|
+
}))
|
|
196
|
+
};
|
|
35
197
|
}
|
|
36
198
|
export async function createPostageBatch(requestOptions, amount, depth, options) {
|
|
37
199
|
const headers = {};
|
|
@@ -50,7 +212,12 @@ export async function createPostageBatch(requestOptions, amount, depth, options)
|
|
|
50
212
|
},
|
|
51
213
|
headers
|
|
52
214
|
});
|
|
53
|
-
|
|
215
|
+
const body = Types.asObject(response.data, {
|
|
216
|
+
name: 'response.data'
|
|
217
|
+
});
|
|
218
|
+
return new BatchId(Types.asString(body.batchID, {
|
|
219
|
+
name: 'batchID'
|
|
220
|
+
}));
|
|
54
221
|
}
|
|
55
222
|
export async function topUpBatch(requestOptions, id, amount) {
|
|
56
223
|
const response = await http(requestOptions, {
|
|
@@ -58,7 +225,12 @@ export async function topUpBatch(requestOptions, id, amount) {
|
|
|
58
225
|
url: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
|
|
59
226
|
responseType: 'json'
|
|
60
227
|
});
|
|
61
|
-
|
|
228
|
+
const body = Types.asObject(response.data, {
|
|
229
|
+
name: 'response.data'
|
|
230
|
+
});
|
|
231
|
+
return new BatchId(Types.asString(body.batchID, {
|
|
232
|
+
name: 'batchID'
|
|
233
|
+
}));
|
|
62
234
|
}
|
|
63
235
|
export async function diluteBatch(requestOptions, id, depth) {
|
|
64
236
|
const response = await http(requestOptions, {
|
|
@@ -66,5 +238,10 @@ export async function diluteBatch(requestOptions, id, depth) {
|
|
|
66
238
|
url: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
|
|
67
239
|
responseType: 'json'
|
|
68
240
|
});
|
|
69
|
-
|
|
241
|
+
const body = Types.asObject(response.data, {
|
|
242
|
+
name: 'response.data'
|
|
243
|
+
});
|
|
244
|
+
return new BatchId(Types.asString(body.batchID, {
|
|
245
|
+
name: 'batchID'
|
|
246
|
+
}));
|
|
70
247
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
4
|
+
import { asNumberString } from "../../utils/type.js";
|
|
5
|
+
import { normalizeCurrentPrice } from "../../utils/workaround.js";
|
|
2
6
|
const RESERVE_STATE_ENDPOINT = 'reservestate';
|
|
3
7
|
const WALLET_ENDPOINT = 'wallet';
|
|
4
8
|
const CHAIN_STATE_ENDPOINT = 'chainstate';
|
|
@@ -13,7 +17,20 @@ export async function getReserveState(requestOptions) {
|
|
|
13
17
|
url: `${RESERVE_STATE_ENDPOINT}`,
|
|
14
18
|
responseType: 'json'
|
|
15
19
|
});
|
|
16
|
-
|
|
20
|
+
const body = Types.asObject(response.data, {
|
|
21
|
+
name: 'response.data'
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
commitment: Types.asNumber(body.commitment, {
|
|
25
|
+
name: 'commitment'
|
|
26
|
+
}),
|
|
27
|
+
radius: Types.asNumber(body.radius, {
|
|
28
|
+
name: 'radius'
|
|
29
|
+
}),
|
|
30
|
+
storageRadius: Types.asNumber(body.storageRadius, {
|
|
31
|
+
name: 'storageRadius'
|
|
32
|
+
})
|
|
33
|
+
};
|
|
17
34
|
}
|
|
18
35
|
/**
|
|
19
36
|
* Get state of reserve
|
|
@@ -26,7 +43,23 @@ export async function getChainState(requestOptions) {
|
|
|
26
43
|
url: `${CHAIN_STATE_ENDPOINT}`,
|
|
27
44
|
responseType: 'json'
|
|
28
45
|
});
|
|
29
|
-
|
|
46
|
+
const body = Types.asObject(response.data, {
|
|
47
|
+
name: 'response.data'
|
|
48
|
+
});
|
|
49
|
+
return {
|
|
50
|
+
block: Types.asNumber(body.block, {
|
|
51
|
+
name: 'block'
|
|
52
|
+
}),
|
|
53
|
+
chainTip: Types.asNumber(body.chainTip, {
|
|
54
|
+
name: 'chainTip'
|
|
55
|
+
}),
|
|
56
|
+
totalAmount: asNumberString(body.totalAmount, {
|
|
57
|
+
name: 'totalAmount'
|
|
58
|
+
}),
|
|
59
|
+
currentPrice: normalizeCurrentPrice(Types.asNumber(body.currentPrice, {
|
|
60
|
+
name: 'currentPrice'
|
|
61
|
+
}))
|
|
62
|
+
};
|
|
30
63
|
}
|
|
31
64
|
/**
|
|
32
65
|
* Get wallet balances for xDai and BZZ of the node
|
|
@@ -39,5 +72,24 @@ export async function getWalletBalance(requestOptions) {
|
|
|
39
72
|
url: `${WALLET_ENDPOINT}`,
|
|
40
73
|
responseType: 'json'
|
|
41
74
|
});
|
|
42
|
-
|
|
75
|
+
const body = Types.asObject(response.data, {
|
|
76
|
+
name: 'response.data'
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
bzzBalance: BZZ.fromPLUR(asNumberString(body.bzzBalance, {
|
|
80
|
+
name: 'bzzBalance'
|
|
81
|
+
})),
|
|
82
|
+
nativeTokenBalance: DAI.fromWei(asNumberString(body.nativeTokenBalance, {
|
|
83
|
+
name: 'nativeTokenBalance'
|
|
84
|
+
})),
|
|
85
|
+
chainID: Types.asNumber(body.chainID, {
|
|
86
|
+
name: 'chainID'
|
|
87
|
+
}),
|
|
88
|
+
chequebookContractAddress: Types.asString(body.chequebookContractAddress, {
|
|
89
|
+
name: 'chequebookContractAddress'
|
|
90
|
+
}),
|
|
91
|
+
walletAddress: Types.asString(body.walletAddress, {
|
|
92
|
+
name: 'walletAddress'
|
|
93
|
+
})
|
|
94
|
+
};
|
|
43
95
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import getMajorSemver from 'semver/functions/major.js';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
export const SUPPORTED_BEE_VERSION_EXACT = '2.
|
|
5
|
-
export const SUPPORTED_API_VERSION = '7.1.0';
|
|
3
|
+
import { toBeeMode } from "../../types/debug.js";
|
|
4
|
+
import { http } from "../../utils/http.js";
|
|
5
|
+
export const SUPPORTED_BEE_VERSION_EXACT = '2.4.0-390a402e';
|
|
6
6
|
export const SUPPORTED_BEE_VERSION = SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
|
|
7
|
+
export const SUPPORTED_API_VERSION = '7.2.0';
|
|
7
8
|
const NODE_INFO_URL = 'node';
|
|
8
9
|
const STATUS_URL = 'status';
|
|
9
10
|
const HEALTH_URL = 'health';
|
|
@@ -14,7 +15,50 @@ export async function getDebugStatus(requestOptions) {
|
|
|
14
15
|
url: STATUS_URL,
|
|
15
16
|
responseType: 'json'
|
|
16
17
|
});
|
|
17
|
-
|
|
18
|
+
const body = Types.asObject(response.data, {
|
|
19
|
+
name: 'response.data'
|
|
20
|
+
});
|
|
21
|
+
return {
|
|
22
|
+
overlay: Types.asString(body.overlay, {
|
|
23
|
+
name: 'overlay'
|
|
24
|
+
}),
|
|
25
|
+
proximity: Types.asNumber(body.proximity, {
|
|
26
|
+
name: 'proximity'
|
|
27
|
+
}),
|
|
28
|
+
beeMode: toBeeMode(Types.asString(body.beeMode, {
|
|
29
|
+
name: 'beeMode'
|
|
30
|
+
})),
|
|
31
|
+
reserveSize: Types.asNumber(body.reserveSize, {
|
|
32
|
+
name: 'reserveSize'
|
|
33
|
+
}),
|
|
34
|
+
reserveSizeWithinRadius: Types.asNumber(body.reserveSizeWithinRadius, {
|
|
35
|
+
name: 'reserveSizeWithinRadius'
|
|
36
|
+
}),
|
|
37
|
+
pullsyncRate: Types.asNumber(body.pullsyncRate, {
|
|
38
|
+
name: 'pullsyncRate'
|
|
39
|
+
}),
|
|
40
|
+
storageRadius: Types.asNumber(body.storageRadius, {
|
|
41
|
+
name: 'storageRadius'
|
|
42
|
+
}),
|
|
43
|
+
connectedPeers: Types.asNumber(body.connectedPeers, {
|
|
44
|
+
name: 'connectedPeers'
|
|
45
|
+
}),
|
|
46
|
+
neighborhoodSize: Types.asNumber(body.neighborhoodSize, {
|
|
47
|
+
name: 'neighborhoodSize'
|
|
48
|
+
}),
|
|
49
|
+
batchCommitment: Types.asNumber(body.batchCommitment, {
|
|
50
|
+
name: 'batchCommitment'
|
|
51
|
+
}),
|
|
52
|
+
isReachable: Types.asBoolean(body.isReachable, {
|
|
53
|
+
name: 'isReachable'
|
|
54
|
+
}),
|
|
55
|
+
lastSyncedBlock: Types.asNumber(body.lastSyncedBlock, {
|
|
56
|
+
name: 'lastSyncedBlock'
|
|
57
|
+
}),
|
|
58
|
+
committedDepth: Types.asNumber(body.committedDepth, {
|
|
59
|
+
name: 'committedDepth'
|
|
60
|
+
})
|
|
61
|
+
};
|
|
18
62
|
}
|
|
19
63
|
/**
|
|
20
64
|
* Get health of node
|
|
@@ -27,7 +71,20 @@ export async function getHealth(requestOptions) {
|
|
|
27
71
|
url: HEALTH_URL,
|
|
28
72
|
responseType: 'json'
|
|
29
73
|
});
|
|
30
|
-
|
|
74
|
+
const body = Types.asObject(response.data, {
|
|
75
|
+
name: 'response.data'
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
apiVersion: Types.asString(body.apiVersion, {
|
|
79
|
+
name: 'apiVersion'
|
|
80
|
+
}),
|
|
81
|
+
version: Types.asString(body.version, {
|
|
82
|
+
name: 'version'
|
|
83
|
+
}),
|
|
84
|
+
status: Types.asString(body.status, {
|
|
85
|
+
name: 'status'
|
|
86
|
+
})
|
|
87
|
+
};
|
|
31
88
|
}
|
|
32
89
|
/**
|
|
33
90
|
* Get readiness of node
|
|
@@ -35,15 +92,24 @@ export async function getHealth(requestOptions) {
|
|
|
35
92
|
* @param requestOptions Options for making requests
|
|
36
93
|
*/
|
|
37
94
|
export async function getReadiness(requestOptions) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
95
|
+
const response = await http(requestOptions, {
|
|
96
|
+
method: 'get',
|
|
97
|
+
url: READINESS_URL
|
|
98
|
+
});
|
|
99
|
+
const body = Types.asObject(response.data, {
|
|
100
|
+
name: 'response.data'
|
|
101
|
+
});
|
|
102
|
+
return {
|
|
103
|
+
apiVersion: Types.asString(body.apiVersion, {
|
|
104
|
+
name: 'apiVersion'
|
|
105
|
+
}),
|
|
106
|
+
version: Types.asString(body.version, {
|
|
107
|
+
name: 'version'
|
|
108
|
+
}),
|
|
109
|
+
status: Types.asString(body.status, {
|
|
110
|
+
name: 'status'
|
|
111
|
+
})
|
|
112
|
+
};
|
|
47
113
|
}
|
|
48
114
|
/**
|
|
49
115
|
* Get information about Bee node
|
|
@@ -56,26 +122,26 @@ export async function getNodeInfo(requestOptions) {
|
|
|
56
122
|
url: NODE_INFO_URL,
|
|
57
123
|
responseType: 'json'
|
|
58
124
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
125
|
+
const body = Types.asObject(response.data, {
|
|
126
|
+
name: 'response.data'
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
beeMode: toBeeMode(Types.asString(body.beeMode, {
|
|
130
|
+
name: 'beeMode'
|
|
131
|
+
})),
|
|
132
|
+
chequebookEnabled: Types.asBoolean(body.chequebookEnabled, {
|
|
133
|
+
name: 'chequebookEnabled'
|
|
134
|
+
}),
|
|
135
|
+
swapEnabled: Types.asBoolean(body.swapEnabled, {
|
|
136
|
+
name: 'swapEnabled'
|
|
137
|
+
})
|
|
138
|
+
};
|
|
71
139
|
}
|
|
72
140
|
/**
|
|
73
141
|
* Connects to a node and checks if its version matches with the one that bee-js supports.
|
|
74
142
|
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
77
|
-
* `isSupportedApiVersion`, `isSupportedMainApiVersion` or `isSupportedDebugApiVersion`
|
|
78
|
-
* based on your use-case.
|
|
143
|
+
* This is the most strict version check and most probably you will
|
|
144
|
+
* want to use the relaxed API-versions check `isSupportedApiVersion`.
|
|
79
145
|
*
|
|
80
146
|
* @param requestOptions Options for making requests
|
|
81
147
|
*/
|
|
@@ -85,20 +151,6 @@ export async function isSupportedExactVersion(requestOptions) {
|
|
|
85
151
|
} = await getHealth(requestOptions);
|
|
86
152
|
return version === SUPPORTED_BEE_VERSION_EXACT;
|
|
87
153
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Connects to a node and checks if its main's API version matches with the one that bee-js supports.
|
|
90
|
-
*
|
|
91
|
-
* This is useful if you are not using `Bee` class (for anything else then this check)
|
|
92
|
-
* and want to make sure about compatibility.
|
|
93
|
-
*
|
|
94
|
-
* @param requestOptions Options for making requests
|
|
95
|
-
*/
|
|
96
|
-
export async function isSupportedMainApiVersion(requestOptions) {
|
|
97
|
-
const {
|
|
98
|
-
apiVersion
|
|
99
|
-
} = await getHealth(requestOptions);
|
|
100
|
-
return getMajorSemver(apiVersion) === getMajorSemver(SUPPORTED_API_VERSION);
|
|
101
|
-
}
|
|
102
154
|
/**
|
|
103
155
|
* Connects to a node and checks if its Main API versions matches with the one that bee-js supports.
|
|
104
156
|
*
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
1
2
|
import { http } from "../../utils/http.js";
|
|
3
|
+
import { asNumberString } from "../../utils/type.js";
|
|
4
|
+
import { TransactionId } from "../../utils/typed-bytes.js";
|
|
2
5
|
const transactionsEndpoint = 'transactions';
|
|
3
6
|
/**
|
|
4
7
|
* Get list of all pending transactions
|
|
@@ -10,7 +13,13 @@ export async function getAllTransactions(requestOptions) {
|
|
|
10
13
|
url: transactionsEndpoint,
|
|
11
14
|
responseType: 'json'
|
|
12
15
|
});
|
|
13
|
-
|
|
16
|
+
const body = Types.asObject(response.data, {
|
|
17
|
+
name: 'response.data'
|
|
18
|
+
});
|
|
19
|
+
const pendingTransactions = Types.asArray(body.pendingTransactions, {
|
|
20
|
+
name: 'pendingTransactions'
|
|
21
|
+
});
|
|
22
|
+
return pendingTransactions.map(toTransaction);
|
|
14
23
|
}
|
|
15
24
|
/**
|
|
16
25
|
* Get information for specific pending transactions
|
|
@@ -23,7 +32,44 @@ export async function getTransaction(requestOptions, transactionHash) {
|
|
|
23
32
|
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
24
33
|
responseType: 'json'
|
|
25
34
|
});
|
|
26
|
-
|
|
35
|
+
const body = Types.asObject(response.data, {
|
|
36
|
+
name: 'response.data'
|
|
37
|
+
});
|
|
38
|
+
return toTransaction(body);
|
|
39
|
+
}
|
|
40
|
+
function toTransaction(value) {
|
|
41
|
+
const object = Types.asObject(value, {
|
|
42
|
+
name: 'transaction'
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
transactionHash: new TransactionId(Types.asString(object.transactionHash, {
|
|
46
|
+
name: 'transactionHash'
|
|
47
|
+
})),
|
|
48
|
+
to: Types.asString(object.to, {
|
|
49
|
+
name: 'to'
|
|
50
|
+
}),
|
|
51
|
+
nonce: Types.asNumber(object.nonce, {
|
|
52
|
+
name: 'nonce'
|
|
53
|
+
}),
|
|
54
|
+
gasPrice: asNumberString(object.gasPrice, {
|
|
55
|
+
name: 'gasPrice'
|
|
56
|
+
}),
|
|
57
|
+
gasLimit: Types.asNumber(object.gasLimit, {
|
|
58
|
+
name: 'gasLimit'
|
|
59
|
+
}),
|
|
60
|
+
data: Types.asString(object.data, {
|
|
61
|
+
name: 'data'
|
|
62
|
+
}),
|
|
63
|
+
created: Types.asString(object.created, {
|
|
64
|
+
name: 'created'
|
|
65
|
+
}),
|
|
66
|
+
description: Types.asString(object.description, {
|
|
67
|
+
name: 'description'
|
|
68
|
+
}),
|
|
69
|
+
value: asNumberString(object.value, {
|
|
70
|
+
name: 'value'
|
|
71
|
+
})
|
|
72
|
+
};
|
|
27
73
|
}
|
|
28
74
|
/**
|
|
29
75
|
* Rebroadcast existing transaction
|
|
@@ -37,7 +83,12 @@ export async function rebroadcastTransaction(requestOptions, transactionHash) {
|
|
|
37
83
|
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
38
84
|
responseType: 'json'
|
|
39
85
|
});
|
|
40
|
-
|
|
86
|
+
const body = Types.asObject(response.data, {
|
|
87
|
+
name: 'response.data'
|
|
88
|
+
});
|
|
89
|
+
return new TransactionId(Types.asString(body.transactionHash, {
|
|
90
|
+
name: 'transactionHash'
|
|
91
|
+
}));
|
|
41
92
|
}
|
|
42
93
|
/**
|
|
43
94
|
* Cancel existing transaction
|
|
@@ -49,7 +100,7 @@ export async function rebroadcastTransaction(requestOptions, transactionHash) {
|
|
|
49
100
|
export async function cancelTransaction(requestOptions, transactionHash, gasPrice) {
|
|
50
101
|
const headers = {};
|
|
51
102
|
if (gasPrice) {
|
|
52
|
-
headers['gas-price'] = gasPrice;
|
|
103
|
+
headers['gas-price'] = gasPrice.toString();
|
|
53
104
|
}
|
|
54
105
|
const response = await http(requestOptions, {
|
|
55
106
|
method: 'delete',
|
|
@@ -57,5 +108,10 @@ export async function cancelTransaction(requestOptions, transactionHash, gasPric
|
|
|
57
108
|
url: `${transactionsEndpoint}/${transactionHash}`,
|
|
58
109
|
responseType: 'json'
|
|
59
110
|
});
|
|
60
|
-
|
|
111
|
+
const body = Types.asObject(response.data, {
|
|
112
|
+
name: 'response.data'
|
|
113
|
+
});
|
|
114
|
+
return new TransactionId(Types.asString(body.transactionHash, {
|
|
115
|
+
name: 'transactionHash'
|
|
116
|
+
}));
|
|
61
117
|
}
|
|
@@ -2,32 +2,34 @@ import { Binary, Types } from 'cafe-utility';
|
|
|
2
2
|
import { http } from "../utils/http.js";
|
|
3
3
|
const ENVELOPE_ENDPOINT = 'envelope';
|
|
4
4
|
export async function postEnvelope(requestOptions, postageBatchId, reference) {
|
|
5
|
-
const {
|
|
6
|
-
data
|
|
7
|
-
} = await http(requestOptions, {
|
|
5
|
+
const response = await http(requestOptions, {
|
|
8
6
|
method: 'post',
|
|
9
7
|
responseType: 'json',
|
|
10
8
|
url: `${ENVELOPE_ENDPOINT}/${reference}`,
|
|
11
9
|
headers: {
|
|
12
|
-
'swarm-postage-batch-id': postageBatchId
|
|
10
|
+
'swarm-postage-batch-id': postageBatchId.toHex()
|
|
13
11
|
}
|
|
14
12
|
});
|
|
13
|
+
const body = Types.asObject(response.data, {
|
|
14
|
+
name: 'response.data'
|
|
15
|
+
});
|
|
15
16
|
return {
|
|
16
|
-
issuer: Binary.hexToUint8Array(Types.asHexString(
|
|
17
|
+
issuer: Binary.hexToUint8Array(Types.asHexString(body.issuer, {
|
|
17
18
|
name: 'issuer',
|
|
18
19
|
byteLength: 20
|
|
19
20
|
})),
|
|
20
|
-
index: Binary.hexToUint8Array(Types.asHexString(
|
|
21
|
+
index: Binary.hexToUint8Array(Types.asHexString(body.index, {
|
|
21
22
|
name: 'index',
|
|
22
23
|
byteLength: 8
|
|
23
24
|
})),
|
|
24
|
-
timestamp: Binary.hexToUint8Array(Types.asHexString(
|
|
25
|
+
timestamp: Binary.hexToUint8Array(Types.asHexString(body.timestamp, {
|
|
25
26
|
name: 'timestamp',
|
|
26
27
|
byteLength: 8
|
|
27
28
|
})),
|
|
28
|
-
signature: Binary.hexToUint8Array(Types.asHexString(
|
|
29
|
+
signature: Binary.hexToUint8Array(Types.asHexString(body.signature, {
|
|
29
30
|
name: 'signature',
|
|
30
31
|
byteLength: 65
|
|
31
|
-
}))
|
|
32
|
+
})),
|
|
33
|
+
batchId: postageBatchId
|
|
32
34
|
};
|
|
33
35
|
}
|