@ethersphere/bee-js 3.3.0 → 3.3.1
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/chunk/bmt.js +7 -2
- package/dist/cjs/chunk/signer.js +9 -4
- package/dist/cjs/modules/debug/status.js +5 -5
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/eth.js +8 -3
- package/dist/cjs/utils/hash.js +7 -2
- package/dist/cjs/utils/stream.js +14 -5
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +52 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/mjs/bee-debug.js +608 -508
- package/dist/mjs/bee.js +935 -836
- package/dist/mjs/chunk/bmt.js +34 -24
- package/dist/mjs/chunk/cac.js +24 -22
- package/dist/mjs/chunk/serialize.js +9 -9
- package/dist/mjs/chunk/signer.js +92 -73
- package/dist/mjs/chunk/soc.js +78 -66
- package/dist/mjs/chunk/span.js +19 -16
- package/dist/mjs/feed/index.js +110 -101
- package/dist/mjs/feed/json.js +21 -17
- package/dist/mjs/feed/topic.js +18 -17
- package/dist/mjs/feed/type.js +5 -5
- package/dist/mjs/index.js +7 -7
- package/dist/mjs/modules/bytes.js +33 -30
- package/dist/mjs/modules/bzz.js +80 -77
- package/dist/mjs/modules/chunk.js +22 -20
- package/dist/mjs/modules/debug/balance.js +26 -22
- package/dist/mjs/modules/debug/chequebook.js +84 -65
- package/dist/mjs/modules/debug/chunk.js +15 -13
- package/dist/mjs/modules/debug/connectivity.js +34 -34
- package/dist/mjs/modules/debug/settlements.js +14 -12
- package/dist/mjs/modules/debug/stamps.js +52 -47
- package/dist/mjs/modules/debug/states.js +16 -14
- package/dist/mjs/modules/debug/status.js +55 -35
- package/dist/mjs/modules/debug/tag.js +8 -7
- package/dist/mjs/modules/debug/transactions.js +31 -25
- package/dist/mjs/modules/feed.js +39 -33
- package/dist/mjs/modules/pinning.js +34 -28
- package/dist/mjs/modules/pss.js +18 -14
- package/dist/mjs/modules/soc.js +18 -15
- package/dist/mjs/modules/status.js +6 -5
- package/dist/mjs/modules/stewardship.js +13 -12
- package/dist/mjs/modules/tag.js +38 -30
- package/dist/mjs/package.json +1 -0
- package/dist/mjs/types/debug.js +5 -4
- package/dist/mjs/types/index.js +6 -2
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +32 -26
- package/dist/mjs/utils/collection.browser.js +4 -3
- package/dist/mjs/utils/collection.js +47 -35
- package/dist/mjs/utils/collection.node.js +53 -42
- package/dist/mjs/utils/data.browser.js +64 -48
- package/dist/mjs/utils/data.js +29 -25
- package/dist/mjs/utils/error.js +47 -39
- package/dist/mjs/utils/eth.js +119 -104
- package/dist/mjs/utils/expose.js +9 -9
- package/dist/mjs/utils/file.js +22 -19
- package/dist/mjs/utils/hash.js +10 -5
- package/dist/mjs/utils/headers.js +43 -39
- package/dist/mjs/utils/hex.js +78 -63
- package/dist/mjs/utils/http.js +119 -100
- package/dist/mjs/utils/merge.js +26 -20
- package/dist/mjs/utils/pss.js +8 -6
- package/dist/mjs/utils/stamps.js +7 -3
- package/dist/mjs/utils/stream.js +107 -82
- package/dist/mjs/utils/tar.js +17 -14
- package/dist/mjs/utils/type.js +249 -209
- package/dist/mjs/utils/uint64.js +16 -16
- package/dist/mjs/utils/url.js +32 -25
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/types/utils/stream.d.ts +11 -8
- package/package.json +9 -6
- package/dist/index.js +0 -28326
- package/dist/index.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { extractUploadHeaders } from
|
|
2
|
-
import { http } from
|
|
3
|
-
import { wrapBytesWithHelpers } from
|
|
1
|
+
import { extractUploadHeaders } from "../utils/headers.js";
|
|
2
|
+
import { http } from "../utils/http.js";
|
|
3
|
+
import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
4
4
|
const endpoint = 'chunks';
|
|
5
5
|
/**
|
|
6
6
|
* Upload chunk to a Bee node
|
|
@@ -14,18 +14,19 @@ const endpoint = 'chunks';
|
|
|
14
14
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
15
15
|
* @param options Additional options like tag, encryption, pinning
|
|
16
16
|
*/
|
|
17
|
+
|
|
17
18
|
export async function upload(ky, data, postageBatchId, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
const response = await http(ky, {
|
|
20
|
+
method: 'post',
|
|
21
|
+
path: `${endpoint}`,
|
|
22
|
+
body: data,
|
|
23
|
+
headers: {
|
|
24
|
+
'content-type': 'application/octet-stream',
|
|
25
|
+
...extractUploadHeaders(postageBatchId, options)
|
|
26
|
+
},
|
|
27
|
+
responseType: 'json'
|
|
28
|
+
});
|
|
29
|
+
return response.data.reference;
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* Download chunk data as a byte array
|
|
@@ -34,10 +35,11 @@ export async function upload(ky, data, postageBatchId, options) {
|
|
|
34
35
|
* @param hash Bee content reference
|
|
35
36
|
*
|
|
36
37
|
*/
|
|
38
|
+
|
|
37
39
|
export async function download(ky, hash) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
40
|
+
const response = await http(ky, {
|
|
41
|
+
responseType: 'arraybuffer',
|
|
42
|
+
path: `${endpoint}/${hash}`
|
|
43
|
+
});
|
|
44
|
+
return wrapBytesWithHelpers(new Uint8Array(response.data));
|
|
45
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const balancesEndpoint = 'balances';
|
|
3
3
|
const consumedEndpoint = 'consumed';
|
|
4
4
|
/**
|
|
@@ -6,12 +6,13 @@ const consumedEndpoint = 'consumed';
|
|
|
6
6
|
*
|
|
7
7
|
* @param ky Ky debug instance
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export async function getAllBalances(ky) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const response = await http(ky, {
|
|
12
|
+
path: balancesEndpoint,
|
|
13
|
+
responseType: 'json'
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Get the balances with a specific peer including prepaid services
|
|
@@ -19,24 +20,26 @@ export async function getAllBalances(ky) {
|
|
|
19
20
|
* @param ky Ky debug instance
|
|
20
21
|
* @param address Swarm address of peer
|
|
21
22
|
*/
|
|
23
|
+
|
|
22
24
|
export async function getPeerBalance(ky, address) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const response = await http(ky, {
|
|
26
|
+
path: `${balancesEndpoint}/${address}`,
|
|
27
|
+
responseType: 'json'
|
|
28
|
+
});
|
|
29
|
+
return response.data;
|
|
28
30
|
}
|
|
29
31
|
/**
|
|
30
32
|
* Get the past due consumption balances with all known peers
|
|
31
33
|
*
|
|
32
34
|
* @param ky Ky debug instance
|
|
33
35
|
*/
|
|
36
|
+
|
|
34
37
|
export async function getPastDueConsumptionBalances(ky) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
const response = await http(ky, {
|
|
39
|
+
path: consumedEndpoint,
|
|
40
|
+
responseType: 'json'
|
|
41
|
+
});
|
|
42
|
+
return response.data;
|
|
40
43
|
}
|
|
41
44
|
/**
|
|
42
45
|
* Get the past due consumption balance with a specific peer
|
|
@@ -44,10 +47,11 @@ export async function getPastDueConsumptionBalances(ky) {
|
|
|
44
47
|
* @param ky Ky debug instance
|
|
45
48
|
* @param address Swarm address of peer
|
|
46
49
|
*/
|
|
50
|
+
|
|
47
51
|
export async function getPastDueConsumptionPeerBalance(ky, address) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
52
|
+
const response = await http(ky, {
|
|
53
|
+
path: `${consumedEndpoint}/${address}`,
|
|
54
|
+
responseType: 'json'
|
|
55
|
+
});
|
|
56
|
+
return response.data;
|
|
57
|
+
}
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const chequebookEndpoint = 'chequebook';
|
|
3
3
|
/**
|
|
4
4
|
* Get the address of the chequebook contract used
|
|
5
5
|
*
|
|
6
6
|
* @param ky Ky debug instance
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
export async function getChequebookAddress(ky) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const response = await http(ky, {
|
|
11
|
+
path: chequebookEndpoint + '/address',
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data;
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
17
|
* Get the balance of the chequebook
|
|
17
18
|
*
|
|
18
19
|
* @param ky Ky debug instance
|
|
19
20
|
*/
|
|
21
|
+
|
|
20
22
|
export async function getChequebookBalance(ky) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const response = await http(ky, {
|
|
24
|
+
path: chequebookEndpoint + '/balance',
|
|
25
|
+
responseType: 'json'
|
|
26
|
+
});
|
|
27
|
+
return response.data;
|
|
26
28
|
}
|
|
27
29
|
/**
|
|
28
30
|
* Get last cashout action for the peer
|
|
@@ -30,12 +32,13 @@ export async function getChequebookBalance(ky) {
|
|
|
30
32
|
* @param ky Ky debug instance
|
|
31
33
|
* @param peer Swarm address of peer
|
|
32
34
|
*/
|
|
35
|
+
|
|
33
36
|
export async function getLastCashoutAction(ky, peer) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const response = await http(ky, {
|
|
38
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
39
|
+
responseType: 'json'
|
|
40
|
+
});
|
|
41
|
+
return response.data;
|
|
39
42
|
}
|
|
40
43
|
/**
|
|
41
44
|
* Cashout the last cheque for the peer
|
|
@@ -44,21 +47,25 @@ export async function getLastCashoutAction(ky, peer) {
|
|
|
44
47
|
* @param peer Swarm address of peer
|
|
45
48
|
* @param options
|
|
46
49
|
*/
|
|
50
|
+
|
|
47
51
|
export async function cashoutLastCheque(ky, peer, options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
52
|
+
const headers = {};
|
|
53
|
+
|
|
54
|
+
if (options?.gasPrice) {
|
|
55
|
+
headers['gas-price'] = options.gasPrice.toString();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (options?.gasLimit) {
|
|
59
|
+
headers['gas-limit'] = options.gasLimit.toString();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const response = await http(ky, {
|
|
63
|
+
method: 'post',
|
|
64
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
65
|
+
responseType: 'json',
|
|
66
|
+
headers
|
|
67
|
+
});
|
|
68
|
+
return response.data.transactionHash;
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
64
71
|
* Get last cheques for the peer
|
|
@@ -66,24 +73,26 @@ export async function cashoutLastCheque(ky, peer, options) {
|
|
|
66
73
|
* @param ky Ky debug instance
|
|
67
74
|
* @param peer Swarm address of peer
|
|
68
75
|
*/
|
|
76
|
+
|
|
69
77
|
export async function getLastChequesForPeer(ky, peer) {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
const response = await http(ky, {
|
|
79
|
+
path: chequebookEndpoint + `/cheque/${peer}`,
|
|
80
|
+
responseType: 'json'
|
|
81
|
+
});
|
|
82
|
+
return response.data;
|
|
75
83
|
}
|
|
76
84
|
/**
|
|
77
85
|
* Get last cheques for all peers
|
|
78
86
|
*
|
|
79
87
|
* @param ky Ky debug instance
|
|
80
88
|
*/
|
|
89
|
+
|
|
81
90
|
export async function getLastCheques(ky) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
const response = await http(ky, {
|
|
92
|
+
path: chequebookEndpoint + '/cheque',
|
|
93
|
+
responseType: 'json'
|
|
94
|
+
});
|
|
95
|
+
return response.data;
|
|
87
96
|
}
|
|
88
97
|
/**
|
|
89
98
|
* Deposit tokens from overlay address into chequebook
|
|
@@ -93,19 +102,24 @@ export async function getLastCheques(ky) {
|
|
|
93
102
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
94
103
|
* @return string Hash of the transaction
|
|
95
104
|
*/
|
|
105
|
+
|
|
96
106
|
export async function depositTokens(ky, amount, gasPrice) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
const headers = {};
|
|
108
|
+
|
|
109
|
+
if (gasPrice) {
|
|
110
|
+
headers['gas-price'] = gasPrice.toString();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const response = await http(ky, {
|
|
114
|
+
method: 'post',
|
|
115
|
+
path: chequebookEndpoint + '/deposit',
|
|
116
|
+
responseType: 'json',
|
|
117
|
+
searchParams: {
|
|
118
|
+
amount: amount.toString(10)
|
|
119
|
+
},
|
|
120
|
+
headers
|
|
121
|
+
});
|
|
122
|
+
return response.data.transactionHash;
|
|
109
123
|
}
|
|
110
124
|
/**
|
|
111
125
|
* Withdraw tokens from the chequebook to the overlay address
|
|
@@ -115,17 +129,22 @@ export async function depositTokens(ky, amount, gasPrice) {
|
|
|
115
129
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
116
130
|
* @return string Hash of the transaction
|
|
117
131
|
*/
|
|
132
|
+
|
|
118
133
|
export async function withdrawTokens(ky, amount, gasPrice) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
134
|
+
const headers = {};
|
|
135
|
+
|
|
136
|
+
if (gasPrice) {
|
|
137
|
+
headers['gas-price'] = gasPrice.toString();
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const response = await http(ky, {
|
|
141
|
+
method: 'post',
|
|
142
|
+
path: chequebookEndpoint + '/withdraw',
|
|
143
|
+
responseType: 'json',
|
|
144
|
+
searchParams: {
|
|
145
|
+
amount: amount.toString(10)
|
|
146
|
+
},
|
|
147
|
+
headers
|
|
148
|
+
});
|
|
149
|
+
return response.data.transactionHash;
|
|
150
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const endpoint = 'chunks';
|
|
3
3
|
/**
|
|
4
4
|
* Check if chunk at address exists locally
|
|
@@ -8,12 +8,13 @@ const endpoint = 'chunks';
|
|
|
8
8
|
*
|
|
9
9
|
* @returns BeeGenericResponse if chunk is found or throws an exception
|
|
10
10
|
*/
|
|
11
|
+
|
|
11
12
|
export async function checkIfChunkExistsLocally(ky, address) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const response = await http(ky, {
|
|
14
|
+
path: endpoint + `/${address}`,
|
|
15
|
+
responseType: 'json'
|
|
16
|
+
});
|
|
17
|
+
return response.data;
|
|
17
18
|
}
|
|
18
19
|
/**
|
|
19
20
|
* Delete a chunk from local storage
|
|
@@ -23,11 +24,12 @@ export async function checkIfChunkExistsLocally(ky, address) {
|
|
|
23
24
|
*
|
|
24
25
|
* @returns BeeGenericResponse if chunk was deleted or throws an exception
|
|
25
26
|
*/
|
|
27
|
+
|
|
26
28
|
export async function deleteChunkFromLocalStorage(ky, address) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
29
|
+
const response = await http(ky, {
|
|
30
|
+
method: 'delete',
|
|
31
|
+
path: endpoint + `/${address}`,
|
|
32
|
+
responseType: 'json'
|
|
33
|
+
});
|
|
34
|
+
return response.data;
|
|
35
|
+
}
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
export async function getNodeAddresses(ky) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
const response = await http(ky, {
|
|
4
|
+
path: 'addresses',
|
|
5
|
+
responseType: 'json'
|
|
6
|
+
});
|
|
7
|
+
return response.data;
|
|
8
8
|
}
|
|
9
9
|
export async function getPeers(ky) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const response = await http(ky, {
|
|
11
|
+
path: 'peers',
|
|
12
|
+
responseType: 'json'
|
|
13
|
+
});
|
|
14
|
+
return response.data.peers || [];
|
|
15
15
|
}
|
|
16
16
|
export async function getBlocklist(ky) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const response = await http(ky, {
|
|
18
|
+
path: 'blocklist',
|
|
19
|
+
responseType: 'json'
|
|
20
|
+
});
|
|
21
|
+
return response.data.peers || [];
|
|
22
22
|
}
|
|
23
23
|
export async function removePeer(ky, peer) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
const response = await http(ky, {
|
|
25
|
+
path: `peers/${peer}`,
|
|
26
|
+
responseType: 'json',
|
|
27
|
+
method: 'DELETE'
|
|
28
|
+
});
|
|
29
|
+
return response.data;
|
|
30
30
|
}
|
|
31
31
|
export async function getTopology(ky) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
const response = await http(ky, {
|
|
33
|
+
path: `topology`,
|
|
34
|
+
responseType: 'json'
|
|
35
|
+
});
|
|
36
|
+
return response.data;
|
|
37
37
|
}
|
|
38
38
|
export async function pingPeer(ky, peer) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
39
|
+
const response = await http(ky, {
|
|
40
|
+
path: `pingpong/${peer}`,
|
|
41
|
+
responseType: 'json',
|
|
42
|
+
method: 'POST'
|
|
43
|
+
});
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const settlementsEndpoint = 'settlements';
|
|
3
3
|
/**
|
|
4
4
|
* Get amount of sent and received from settlements with a peer
|
|
@@ -6,22 +6,24 @@ const settlementsEndpoint = 'settlements';
|
|
|
6
6
|
* @param ky Ky debug instance
|
|
7
7
|
* @param peer Swarm address of peer
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export async function getSettlements(ky, peer) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
const response = await http(ky, {
|
|
12
|
+
path: `${settlementsEndpoint}/${peer}`,
|
|
13
|
+
responseType: 'json'
|
|
14
|
+
});
|
|
15
|
+
return response.data;
|
|
15
16
|
}
|
|
16
17
|
/**
|
|
17
18
|
* Get settlements with all known peers and total amount sent or received
|
|
18
19
|
*
|
|
19
20
|
* @param ky Ky debug instance
|
|
20
21
|
*/
|
|
22
|
+
|
|
21
23
|
export async function getAllSettlements(ky) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
24
|
+
const response = await http(ky, {
|
|
25
|
+
path: settlementsEndpoint,
|
|
26
|
+
responseType: 'json'
|
|
27
|
+
});
|
|
28
|
+
return response.data;
|
|
29
|
+
}
|
|
@@ -1,59 +1,64 @@
|
|
|
1
|
-
import { http } from
|
|
1
|
+
import { http } from "../../utils/http.js";
|
|
2
2
|
const STAMPS_ENDPOINT = 'stamps';
|
|
3
3
|
export async function getAllPostageBatches(ky) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const response = await http(ky, {
|
|
5
|
+
method: 'get',
|
|
6
|
+
path: `${STAMPS_ENDPOINT}`,
|
|
7
|
+
responseType: 'json'
|
|
8
|
+
});
|
|
9
|
+
return response.data.stamps || [];
|
|
10
10
|
}
|
|
11
11
|
export async function getPostageBatch(ky, postageBatchId) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const response = await http(ky, {
|
|
13
|
+
method: 'get',
|
|
14
|
+
path: `${STAMPS_ENDPOINT}/${postageBatchId}`,
|
|
15
|
+
responseType: 'json'
|
|
16
|
+
});
|
|
17
|
+
return response.data;
|
|
18
18
|
}
|
|
19
19
|
export async function getPostageBatchBuckets(ky, postageBatchId) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const response = await http(ky, {
|
|
21
|
+
method: 'get',
|
|
22
|
+
path: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
|
|
23
|
+
responseType: 'json'
|
|
24
|
+
});
|
|
25
|
+
return response.data;
|
|
26
26
|
}
|
|
27
27
|
export async function createPostageBatch(ky, amount, depth, options) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
const headers = {};
|
|
29
|
+
|
|
30
|
+
if (options?.gasPrice) {
|
|
31
|
+
headers['gas-price'] = options.gasPrice.toString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (options?.immutableFlag !== undefined) {
|
|
35
|
+
headers.immutable = String(options.immutableFlag);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const response = await http(ky, {
|
|
39
|
+
method: 'post',
|
|
40
|
+
path: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
|
|
41
|
+
responseType: 'json',
|
|
42
|
+
searchParams: {
|
|
43
|
+
label: options?.label
|
|
44
|
+
},
|
|
45
|
+
headers
|
|
46
|
+
});
|
|
47
|
+
return response.data.batchID;
|
|
43
48
|
}
|
|
44
49
|
export async function topUpBatch(ky, id, amount) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
const response = await http(ky, {
|
|
51
|
+
method: 'patch',
|
|
52
|
+
path: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
|
|
53
|
+
responseType: 'json'
|
|
54
|
+
});
|
|
55
|
+
return response.data.batchID;
|
|
51
56
|
}
|
|
52
57
|
export async function diluteBatch(ky, id, depth) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
58
|
+
const response = await http(ky, {
|
|
59
|
+
method: 'patch',
|
|
60
|
+
path: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
|
|
61
|
+
responseType: 'json'
|
|
62
|
+
});
|
|
63
|
+
return response.data.batchID;
|
|
64
|
+
}
|