@ethersphere/bee-js 12.2.2 → 12.3.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 +56 -23
- package/dist/cjs/chunk/cac.js +4 -2
- package/dist/cjs/feed/index.js +3 -1
- package/dist/cjs/modules/bytes.js +6 -4
- package/dist/cjs/modules/bzz.js +5 -4
- package/dist/cjs/modules/chunk.js +3 -2
- package/dist/cjs/modules/debug/balance.js +5 -29
- package/dist/cjs/modules/debug/chequebook.js +9 -58
- package/dist/cjs/modules/debug/connectivity.js +5 -82
- package/dist/cjs/modules/debug/settlements.js +3 -22
- package/dist/cjs/modules/debug/stake.js +8 -33
- package/dist/cjs/modules/debug/stamps.js +27 -53
- package/dist/cjs/modules/debug/states.js +6 -31
- package/dist/cjs/modules/debug/status.js +5 -37
- package/dist/cjs/modules/debug/transactions.js +5 -26
- package/dist/cjs/modules/envelope.js +6 -6
- package/dist/cjs/modules/feed.js +3 -4
- package/dist/cjs/modules/grantee.js +8 -10
- package/dist/cjs/modules/pinning.js +5 -11
- package/dist/cjs/modules/rchash.js +2 -3
- package/dist/cjs/modules/soc.js +3 -2
- package/dist/cjs/modules/status.js +3 -3
- package/dist/cjs/modules/stewardship.js +2 -3
- package/dist/cjs/modules/tag.js +4 -35
- package/dist/cjs/stamper/stamper.js +2 -1
- package/dist/cjs/types/schema/balance.js +14 -0
- package/dist/cjs/types/schema/chequebook.js +49 -0
- package/dist/cjs/types/schema/connectivity.js +46 -0
- package/dist/cjs/types/schema/envelope.js +11 -0
- package/dist/cjs/types/schema/grantee.js +10 -0
- package/dist/cjs/types/schema/pinning.js +7 -0
- package/dist/cjs/types/schema/rchash.js +7 -0
- package/dist/cjs/types/schema/settlements.js +17 -0
- package/dist/cjs/types/schema/stake.js +33 -0
- package/dist/cjs/types/schema/stamps.js +48 -0
- package/dist/cjs/types/schema/states.js +34 -0
- package/dist/cjs/types/schema/status.js +39 -0
- package/dist/cjs/types/schema/stewardship.js +7 -0
- package/dist/cjs/types/schema/tag.js +20 -0
- package/dist/cjs/types/schema/transactions.js +24 -0
- package/dist/cjs/types/schema/upload.js +8 -0
- package/dist/cjs/utils/bad-ports.js +92 -0
- package/dist/cjs/utils/bytes.js +5 -3
- package/dist/cjs/utils/error.js +1 -0
- package/dist/cjs/utils/headers.js +19 -13
- package/dist/cjs/utils/hex-schema.js +8 -0
- package/dist/cjs/utils/http.js +92 -52
- package/dist/cjs/utils/resource-locator.js +4 -3
- package/dist/cjs/utils/schema.js +88 -0
- package/dist/cjs/utils/stamps.js +2 -1
- package/dist/cjs/utils/type.js +12 -130
- package/dist/cjs/utils/url.js +24 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +59 -30
- package/dist/mjs/chunk/cac.js +5 -3
- package/dist/mjs/feed/index.js +4 -2
- package/dist/mjs/modules/bytes.js +8 -8
- package/dist/mjs/modules/bzz.js +6 -9
- package/dist/mjs/modules/chunk.js +4 -7
- package/dist/mjs/modules/debug/balance.js +5 -61
- package/dist/mjs/modules/debug/chequebook.js +9 -114
- package/dist/mjs/modules/debug/connectivity.js +5 -145
- package/dist/mjs/modules/debug/settlements.js +3 -46
- package/dist/mjs/modules/debug/stake.js +8 -85
- package/dist/mjs/modules/debug/stamps.js +24 -126
- package/dist/mjs/modules/debug/states.js +6 -71
- package/dist/mjs/modules/debug/status.js +5 -91
- package/dist/mjs/modules/debug/transactions.js +5 -60
- package/dist/mjs/modules/envelope.js +6 -20
- package/dist/mjs/modules/feed.js +6 -7
- package/dist/mjs/modules/grantee.js +8 -26
- package/dist/mjs/modules/pinning.js +7 -21
- package/dist/mjs/modules/rchash.js +2 -7
- package/dist/mjs/modules/soc.js +4 -5
- package/dist/mjs/modules/status.js +4 -4
- package/dist/mjs/modules/stewardship.js +2 -7
- package/dist/mjs/modules/tag.js +4 -93
- package/dist/mjs/stamper/stamper.js +2 -1
- package/dist/mjs/types/schema/balance.js +13 -0
- package/dist/mjs/types/schema/chequebook.js +53 -0
- package/dist/mjs/types/schema/connectivity.js +41 -0
- package/dist/mjs/types/schema/envelope.js +8 -0
- package/dist/mjs/types/schema/grantee.js +7 -0
- package/dist/mjs/types/schema/pinning.js +4 -0
- package/dist/mjs/types/schema/rchash.js +4 -0
- package/dist/mjs/types/schema/settlements.js +22 -0
- package/dist/mjs/types/schema/stake.js +40 -0
- package/dist/mjs/types/schema/stamps.js +47 -0
- package/dist/mjs/types/schema/states.js +34 -0
- package/dist/mjs/types/schema/status.js +36 -0
- package/dist/mjs/types/schema/stewardship.js +4 -0
- package/dist/mjs/types/schema/tag.js +14 -0
- package/dist/mjs/types/schema/transactions.js +25 -0
- package/dist/mjs/types/schema/upload.js +5 -0
- package/dist/mjs/utils/bad-ports.js +6 -0
- package/dist/mjs/utils/bytes.js +6 -8
- package/dist/mjs/utils/error.js +5 -0
- package/dist/mjs/utils/headers.js +19 -13
- package/dist/mjs/utils/hex-schema.js +2 -0
- package/dist/mjs/utils/http.js +97 -59
- package/dist/mjs/utils/resource-locator.js +4 -3
- package/dist/mjs/utils/schema.js +81 -0
- package/dist/mjs/utils/stamps.js +2 -1
- package/dist/mjs/utils/type.js +13 -233
- package/dist/mjs/utils/url.js +23 -0
- package/dist/types/bee.d.ts +23 -0
- package/dist/types/modules/debug/connectivity.d.ts +2 -2
- package/dist/types/modules/debug/stamps.d.ts +2 -0
- package/dist/types/types/debug.d.ts +1 -0
- package/dist/types/types/schema/balance.d.ts +12 -0
- package/dist/types/types/schema/chequebook.d.ts +104 -0
- package/dist/types/types/schema/connectivity.d.ts +49 -0
- package/dist/types/types/schema/envelope.d.ts +7 -0
- package/dist/types/types/schema/grantee.d.ts +7 -0
- package/dist/types/types/schema/pinning.d.ts +4 -0
- package/dist/types/types/schema/rchash.d.ts +4 -0
- package/dist/types/types/schema/settlements.d.ts +16 -0
- package/dist/types/types/schema/stake.d.ts +29 -0
- package/dist/types/types/schema/stamps.d.ts +77 -0
- package/dist/types/types/schema/states.d.ts +26 -0
- package/dist/types/types/schema/status.d.ts +38 -0
- package/dist/types/types/schema/stewardship.d.ts +4 -0
- package/dist/types/types/schema/tag.d.ts +23 -0
- package/dist/types/types/schema/transactions.d.ts +29 -0
- package/dist/types/types/schema/upload.d.ts +5 -0
- package/dist/types/utils/bad-ports.d.ts +6 -0
- package/dist/types/utils/error.d.ts +5 -0
- package/dist/types/utils/hex-schema.d.ts +2 -0
- package/dist/types/utils/http.d.ts +18 -3
- package/dist/types/utils/schema.d.ts +90 -0
- package/dist/types/utils/stamps.d.ts +1 -0
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/dist/types/utils/type.d.ts +1 -16
- package/dist/types/utils/url.d.ts +9 -0
- package/package.json +9 -9
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetChequebookAddressResponse, GetChequebookBalanceResponse, GetLastCashoutActionResponse, GetLastChequesForPeerResponse, GetLastChequesResponse, TransactionHashResponse } from "../../types/schema/chequebook.js";
|
|
2
2
|
import { prepareRequestHeaders } from "../../utils/headers.js";
|
|
3
3
|
import { http } from "../../utils/http.js";
|
|
4
|
-
import { BZZ } from "../../utils/tokens.js";
|
|
5
|
-
import { asNumberString } from "../../utils/type.js";
|
|
6
|
-
import { EthAddress, TransactionId } from "../../utils/typed-bytes.js";
|
|
7
4
|
const chequebookEndpoint = 'chequebook';
|
|
8
5
|
/**
|
|
9
6
|
* Get the address of the chequebook contract used
|
|
@@ -15,14 +12,7 @@ export async function getChequebookAddress(requestOptions) {
|
|
|
15
12
|
url: chequebookEndpoint + '/address',
|
|
16
13
|
responseType: 'json'
|
|
17
14
|
});
|
|
18
|
-
|
|
19
|
-
name: 'response.data'
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
chequebookAddress: new EthAddress(Types.asString(body.chequebookAddress, {
|
|
23
|
-
name: 'chequebookAddress'
|
|
24
|
-
}))
|
|
25
|
-
};
|
|
15
|
+
return GetChequebookAddressResponse.parse(response.data);
|
|
26
16
|
}
|
|
27
17
|
/**
|
|
28
18
|
* Get the balance of the chequebook
|
|
@@ -34,17 +24,7 @@ export async function getChequebookBalance(requestOptions) {
|
|
|
34
24
|
url: chequebookEndpoint + '/balance',
|
|
35
25
|
responseType: 'json'
|
|
36
26
|
});
|
|
37
|
-
|
|
38
|
-
name: 'response.data'
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
availableBalance: BZZ.fromPLUR(asNumberString(body.availableBalance, {
|
|
42
|
-
name: 'availableBalance'
|
|
43
|
-
})),
|
|
44
|
-
totalBalance: BZZ.fromPLUR(asNumberString(body.totalBalance, {
|
|
45
|
-
name: 'totalBalance'
|
|
46
|
-
}))
|
|
47
|
-
};
|
|
27
|
+
return GetChequebookBalanceResponse.parse(response.data);
|
|
48
28
|
}
|
|
49
29
|
/**
|
|
50
30
|
* Get last cashout action for the peer
|
|
@@ -57,20 +37,7 @@ export async function getLastCashoutAction(requestOptions, peer) {
|
|
|
57
37
|
url: chequebookEndpoint + `/cashout/${peer}`,
|
|
58
38
|
responseType: 'json'
|
|
59
39
|
});
|
|
60
|
-
|
|
61
|
-
name: 'response.data'
|
|
62
|
-
});
|
|
63
|
-
return {
|
|
64
|
-
peer: Types.asString(body.peer, {
|
|
65
|
-
name: 'peer'
|
|
66
|
-
}),
|
|
67
|
-
uncashedAmount: BZZ.fromPLUR(asNumberString(body.uncashedAmount, {
|
|
68
|
-
name: 'uncashedAmount'
|
|
69
|
-
})),
|
|
70
|
-
transactionHash: Types.asNullableString(body.transactionHash),
|
|
71
|
-
lastCashedCheque: Types.asNullable(x => asCheque(x), body.lastCashedCheque),
|
|
72
|
-
result: Types.asNullable(x => asCashoutResult(x), body.result)
|
|
73
|
-
};
|
|
40
|
+
return GetLastCashoutActionResponse.parse(response.data);
|
|
74
41
|
}
|
|
75
42
|
/**
|
|
76
43
|
* Cashout the last cheque for the peer
|
|
@@ -86,12 +53,7 @@ export async function cashoutLastCheque(requestOptions, peer, options) {
|
|
|
86
53
|
responseType: 'json',
|
|
87
54
|
headers: prepareRequestHeaders(null, options)
|
|
88
55
|
});
|
|
89
|
-
|
|
90
|
-
name: 'response.data'
|
|
91
|
-
});
|
|
92
|
-
return new TransactionId(Types.asString(body.transactionHash, {
|
|
93
|
-
name: 'transactionHash'
|
|
94
|
-
}));
|
|
56
|
+
return TransactionHashResponse.parse(response.data).transactionHash;
|
|
95
57
|
}
|
|
96
58
|
/**
|
|
97
59
|
* Get last cheques for the peer
|
|
@@ -104,16 +66,7 @@ export async function getLastChequesForPeer(requestOptions, peer) {
|
|
|
104
66
|
url: chequebookEndpoint + `/cheque/${peer}`,
|
|
105
67
|
responseType: 'json'
|
|
106
68
|
});
|
|
107
|
-
|
|
108
|
-
name: 'response.data'
|
|
109
|
-
});
|
|
110
|
-
return {
|
|
111
|
-
peer: Types.asString(body.peer, {
|
|
112
|
-
name: 'peer'
|
|
113
|
-
}),
|
|
114
|
-
lastreceived: Types.asNullable(x => asCheque(x), body.lastreceived),
|
|
115
|
-
lastsent: Types.asNullable(x => asCheque(x), body.lastsent)
|
|
116
|
-
};
|
|
69
|
+
return GetLastChequesForPeerResponse.parse(response.data);
|
|
117
70
|
}
|
|
118
71
|
/**
|
|
119
72
|
* Get last cheques for all peers
|
|
@@ -125,55 +78,7 @@ export async function getLastCheques(requestOptions) {
|
|
|
125
78
|
url: chequebookEndpoint + '/cheque',
|
|
126
79
|
responseType: 'json'
|
|
127
80
|
});
|
|
128
|
-
|
|
129
|
-
name: 'response.data'
|
|
130
|
-
});
|
|
131
|
-
const lastcheques = Types.asArray(body.lastcheques, {
|
|
132
|
-
name: 'lastcheques'
|
|
133
|
-
}).map(x => Types.asObject(x, {
|
|
134
|
-
name: 'lastcheque'
|
|
135
|
-
}));
|
|
136
|
-
return {
|
|
137
|
-
lastcheques: lastcheques.map(x => ({
|
|
138
|
-
peer: Types.asString(x.peer, {
|
|
139
|
-
name: 'peer'
|
|
140
|
-
}),
|
|
141
|
-
lastreceived: Types.asNullable(y => asCheque(y), x.lastreceived),
|
|
142
|
-
lastsent: Types.asNullable(y => asCheque(y), x.lastsent)
|
|
143
|
-
}))
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
function asCheque(x) {
|
|
147
|
-
const object = Types.asObject(x, {
|
|
148
|
-
name: 'cheque'
|
|
149
|
-
});
|
|
150
|
-
return {
|
|
151
|
-
beneficiary: new EthAddress(Types.asString(object.beneficiary, {
|
|
152
|
-
name: 'beneficiary'
|
|
153
|
-
})),
|
|
154
|
-
chequebook: new EthAddress(Types.asString(object.chequebook, {
|
|
155
|
-
name: 'chequebook'
|
|
156
|
-
})),
|
|
157
|
-
payout: BZZ.fromPLUR(asNumberString(object.payout, {
|
|
158
|
-
name: 'payout'
|
|
159
|
-
}))
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
function asCashoutResult(x) {
|
|
163
|
-
const object = Types.asObject(x, {
|
|
164
|
-
name: 'cashout result'
|
|
165
|
-
});
|
|
166
|
-
return {
|
|
167
|
-
recipient: Types.asString(object.recipient, {
|
|
168
|
-
name: 'recipient'
|
|
169
|
-
}),
|
|
170
|
-
lastPayout: BZZ.fromPLUR(asNumberString(object.lastPayout, {
|
|
171
|
-
name: 'lastPayout'
|
|
172
|
-
})),
|
|
173
|
-
bounced: Types.asBoolean(object.bounced, {
|
|
174
|
-
name: 'bounced'
|
|
175
|
-
})
|
|
176
|
-
};
|
|
81
|
+
return GetLastChequesResponse.parse(response.data);
|
|
177
82
|
}
|
|
178
83
|
/**
|
|
179
84
|
* Deposit tokens from overlay address into chequebook
|
|
@@ -197,12 +102,7 @@ export async function depositTokens(requestOptions, amount, gasPrice) {
|
|
|
197
102
|
},
|
|
198
103
|
headers
|
|
199
104
|
});
|
|
200
|
-
|
|
201
|
-
name: 'response.data'
|
|
202
|
-
});
|
|
203
|
-
return new TransactionId(Types.asString(body.transactionHash, {
|
|
204
|
-
name: 'transactionHash'
|
|
205
|
-
}));
|
|
105
|
+
return TransactionHashResponse.parse(response.data).transactionHash;
|
|
206
106
|
}
|
|
207
107
|
/**
|
|
208
108
|
* Withdraw tokens from the chequebook to the overlay address
|
|
@@ -226,10 +126,5 @@ export async function withdrawTokens(requestOptions, amount, gasPrice) {
|
|
|
226
126
|
},
|
|
227
127
|
headers
|
|
228
128
|
});
|
|
229
|
-
|
|
230
|
-
name: 'response.data'
|
|
231
|
-
});
|
|
232
|
-
return new TransactionId(Types.asString(body.transactionHash, {
|
|
233
|
-
name: 'transactionHash'
|
|
234
|
-
}));
|
|
129
|
+
return TransactionHashResponse.parse(response.data).transactionHash;
|
|
235
130
|
}
|
|
@@ -1,63 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetBlocklistResponse, GetNodeAddressesResponse, GetPeersResponse, GetTopologyResponse } from "../../types/schema/connectivity.js";
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
-
import { EthAddress, PeerAddress, PublicKey } from "../../utils/typed-bytes.js";
|
|
4
3
|
export async function getNodeAddresses(requestOptions) {
|
|
5
4
|
const response = await http(requestOptions, {
|
|
6
5
|
url: 'addresses',
|
|
7
6
|
responseType: 'json'
|
|
8
7
|
});
|
|
9
|
-
|
|
10
|
-
name: 'response.data'
|
|
11
|
-
});
|
|
12
|
-
return {
|
|
13
|
-
overlay: new PeerAddress(Types.asString(body.overlay, {
|
|
14
|
-
name: 'overlay'
|
|
15
|
-
})),
|
|
16
|
-
underlay: Types.asArray(body.underlay, {
|
|
17
|
-
name: 'underlay'
|
|
18
|
-
}).map(x => Types.asString(x, {
|
|
19
|
-
name: 'underlay'
|
|
20
|
-
})),
|
|
21
|
-
ethereum: new EthAddress(Types.asString(body.ethereum, {
|
|
22
|
-
name: 'ethereum'
|
|
23
|
-
})),
|
|
24
|
-
publicKey: new PublicKey(Types.asString(body.publicKey, {
|
|
25
|
-
name: 'publicKey'
|
|
26
|
-
})),
|
|
27
|
-
pssPublicKey: new PublicKey(Types.asString(body.pssPublicKey, {
|
|
28
|
-
name: 'pssPublicKey'
|
|
29
|
-
}))
|
|
30
|
-
};
|
|
8
|
+
return GetNodeAddressesResponse.parse(response.data);
|
|
31
9
|
}
|
|
32
10
|
export async function getPeers(requestOptions) {
|
|
33
11
|
const response = await http(requestOptions, {
|
|
34
12
|
url: 'peers',
|
|
35
13
|
responseType: 'json'
|
|
36
14
|
});
|
|
37
|
-
|
|
38
|
-
name: 'response.data'
|
|
39
|
-
});
|
|
40
|
-
return Types.asArray(body.peers, {
|
|
41
|
-
name: 'peers'
|
|
42
|
-
}).map(x => ({
|
|
43
|
-
address: Types.asString(Types.asObject(x, {
|
|
44
|
-
name: 'peer'
|
|
45
|
-
}).address, {
|
|
46
|
-
name: 'address'
|
|
47
|
-
}),
|
|
48
|
-
fullNode: Types.asBoolean(Types.asObject(x, {
|
|
49
|
-
name: 'peer'
|
|
50
|
-
}).fullNode, {
|
|
51
|
-
name: 'fullNode'
|
|
52
|
-
})
|
|
53
|
-
}));
|
|
15
|
+
return GetPeersResponse.parse(response.data).peers;
|
|
54
16
|
}
|
|
55
17
|
export async function getBlocklist(requestOptions) {
|
|
56
18
|
const response = await http(requestOptions, {
|
|
57
19
|
url: 'blocklist',
|
|
58
20
|
responseType: 'json'
|
|
59
21
|
});
|
|
60
|
-
return response.data.peers;
|
|
22
|
+
return GetBlocklistResponse.parse(response.data).peers;
|
|
61
23
|
}
|
|
62
24
|
export async function removePeer(requestOptions, peer) {
|
|
63
25
|
const response = await http(requestOptions, {
|
|
@@ -72,72 +34,7 @@ export async function getTopology(requestOptions) {
|
|
|
72
34
|
url: `topology`,
|
|
73
35
|
responseType: 'json'
|
|
74
36
|
});
|
|
75
|
-
|
|
76
|
-
name: 'response.data'
|
|
77
|
-
});
|
|
78
|
-
const bins = Types.asObject(body.bins, {
|
|
79
|
-
name: 'bins'
|
|
80
|
-
});
|
|
81
|
-
return {
|
|
82
|
-
baseAddr: Types.asString(body.baseAddr, {
|
|
83
|
-
name: 'baseAddr'
|
|
84
|
-
}),
|
|
85
|
-
population: Types.asNumber(body.population, {
|
|
86
|
-
name: 'population'
|
|
87
|
-
}),
|
|
88
|
-
connected: Types.asNumber(body.connected, {
|
|
89
|
-
name: 'connected'
|
|
90
|
-
}),
|
|
91
|
-
timestamp: Types.asString(body.timestamp, {
|
|
92
|
-
name: 'timestamp'
|
|
93
|
-
}),
|
|
94
|
-
nnLowWatermark: Types.asNumber(body.nnLowWatermark, {
|
|
95
|
-
name: 'nnLowWatermark'
|
|
96
|
-
}),
|
|
97
|
-
depth: Types.asNumber(body.depth, {
|
|
98
|
-
name: 'depth'
|
|
99
|
-
}),
|
|
100
|
-
reachability: Types.asString(body.reachability, {
|
|
101
|
-
name: 'reachability'
|
|
102
|
-
}),
|
|
103
|
-
networkAvailability: Types.asString(body.networkAvailability, {
|
|
104
|
-
name: 'networkAvailability'
|
|
105
|
-
}),
|
|
106
|
-
bins: {
|
|
107
|
-
bin_0: asBin(bins.bin_0, 'bin_0'),
|
|
108
|
-
bin_1: asBin(bins.bin_1, 'bin_1'),
|
|
109
|
-
bin_2: asBin(bins.bin_2, 'bin_2'),
|
|
110
|
-
bin_3: asBin(bins.bin_3, 'bin_3'),
|
|
111
|
-
bin_4: asBin(bins.bin_4, 'bin_4'),
|
|
112
|
-
bin_5: asBin(bins.bin_5, 'bin_5'),
|
|
113
|
-
bin_6: asBin(bins.bin_6, 'bin_6'),
|
|
114
|
-
bin_7: asBin(bins.bin_7, 'bin_7'),
|
|
115
|
-
bin_8: asBin(bins.bin_8, 'bin_8'),
|
|
116
|
-
bin_9: asBin(bins.bin_9, 'bin_9'),
|
|
117
|
-
bin_10: asBin(bins.bin_10, 'bin_10'),
|
|
118
|
-
bin_11: asBin(bins.bin_11, 'bin_11'),
|
|
119
|
-
bin_12: asBin(bins.bin_12, 'bin_12'),
|
|
120
|
-
bin_13: asBin(bins.bin_13, 'bin_13'),
|
|
121
|
-
bin_14: asBin(bins.bin_14, 'bin_14'),
|
|
122
|
-
bin_15: asBin(bins.bin_15, 'bin_15'),
|
|
123
|
-
bin_16: asBin(bins.bin_16, 'bin_16'),
|
|
124
|
-
bin_17: asBin(bins.bin_17, 'bin_17'),
|
|
125
|
-
bin_18: asBin(bins.bin_18, 'bin_18'),
|
|
126
|
-
bin_19: asBin(bins.bin_19, 'bin_19'),
|
|
127
|
-
bin_20: asBin(bins.bin_20, 'bin_20'),
|
|
128
|
-
bin_21: asBin(bins.bin_21, 'bin_21'),
|
|
129
|
-
bin_22: asBin(bins.bin_22, 'bin_22'),
|
|
130
|
-
bin_23: asBin(bins.bin_23, 'bin_23'),
|
|
131
|
-
bin_24: asBin(bins.bin_24, 'bin_24'),
|
|
132
|
-
bin_25: asBin(bins.bin_25, 'bin_25'),
|
|
133
|
-
bin_26: asBin(bins.bin_26, 'bin_26'),
|
|
134
|
-
bin_27: asBin(bins.bin_27, 'bin_27'),
|
|
135
|
-
bin_28: asBin(bins.bin_28, 'bin_28'),
|
|
136
|
-
bin_29: asBin(bins.bin_29, 'bin_29'),
|
|
137
|
-
bin_30: asBin(bins.bin_30, 'bin_30'),
|
|
138
|
-
bin_31: asBin(bins.bin_31, 'bin_31')
|
|
139
|
-
}
|
|
140
|
-
};
|
|
37
|
+
return GetTopologyResponse.parse(response.data);
|
|
141
38
|
}
|
|
142
39
|
export async function pingPeer(requestOptions, peer) {
|
|
143
40
|
const response = await http(requestOptions, {
|
|
@@ -146,41 +43,4 @@ export async function pingPeer(requestOptions, peer) {
|
|
|
146
43
|
method: 'POST'
|
|
147
44
|
});
|
|
148
45
|
return response.data;
|
|
149
|
-
}
|
|
150
|
-
export function asBin(value, name) {
|
|
151
|
-
const bin = Types.asObject(value, {
|
|
152
|
-
name
|
|
153
|
-
});
|
|
154
|
-
if (!bin.disconnectedPeers) {
|
|
155
|
-
bin.disconnectedPeers = [];
|
|
156
|
-
}
|
|
157
|
-
if (!bin.connectedPeers) {
|
|
158
|
-
bin.connectedPeers = [];
|
|
159
|
-
}
|
|
160
|
-
return {
|
|
161
|
-
population: Types.asNumber(bin.population, {
|
|
162
|
-
name: 'population'
|
|
163
|
-
}),
|
|
164
|
-
connected: Types.asNumber(bin.connected, {
|
|
165
|
-
name: 'connected'
|
|
166
|
-
}),
|
|
167
|
-
connectedPeers: Types.asArray(bin.connectedPeers, {
|
|
168
|
-
name: 'connectedPeers'
|
|
169
|
-
}).map(x => ({
|
|
170
|
-
address: Types.asString(Types.asObject(x, {
|
|
171
|
-
name: 'connectedPeer'
|
|
172
|
-
}).address, {
|
|
173
|
-
name: 'address'
|
|
174
|
-
})
|
|
175
|
-
})),
|
|
176
|
-
disconnectedPeers: Types.asArray(bin.disconnectedPeers, {
|
|
177
|
-
name: 'disconnectedPeers'
|
|
178
|
-
}).map(x => ({
|
|
179
|
-
address: Types.asString(Types.asObject(x, {
|
|
180
|
-
name: 'disconnectedPeer'
|
|
181
|
-
}).address, {
|
|
182
|
-
name: 'address'
|
|
183
|
-
})
|
|
184
|
-
}))
|
|
185
|
-
};
|
|
186
46
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetAllSettlementsResponse, GetSettlementsResponse } from "../../types/schema/settlements.js";
|
|
2
2
|
import { http } from "../../utils/http.js";
|
|
3
|
-
import { BZZ } from "../../utils/tokens.js";
|
|
4
|
-
import { asNumberString } from "../../utils/type.js";
|
|
5
3
|
const settlementsEndpoint = 'settlements';
|
|
6
4
|
/**
|
|
7
5
|
* Get amount of sent and received from settlements with a peer
|
|
@@ -14,20 +12,7 @@ export async function getSettlements(requestOptions, peer) {
|
|
|
14
12
|
url: `${settlementsEndpoint}/${peer}`,
|
|
15
13
|
responseType: 'json'
|
|
16
14
|
});
|
|
17
|
-
|
|
18
|
-
name: 'response.data'
|
|
19
|
-
});
|
|
20
|
-
return {
|
|
21
|
-
peer: Types.asString(body.peer, {
|
|
22
|
-
name: 'peer'
|
|
23
|
-
}),
|
|
24
|
-
sent: BZZ.fromPLUR(asNumberString(body.sent, {
|
|
25
|
-
name: 'sent'
|
|
26
|
-
})),
|
|
27
|
-
received: BZZ.fromPLUR(asNumberString(body.received, {
|
|
28
|
-
name: 'received'
|
|
29
|
-
}))
|
|
30
|
-
};
|
|
15
|
+
return GetSettlementsResponse.parse(response.data);
|
|
31
16
|
}
|
|
32
17
|
/**
|
|
33
18
|
* Get settlements with all known peers and total amount sent or received
|
|
@@ -39,33 +24,5 @@ export async function getAllSettlements(requestOptions) {
|
|
|
39
24
|
url: settlementsEndpoint,
|
|
40
25
|
responseType: 'json'
|
|
41
26
|
});
|
|
42
|
-
|
|
43
|
-
name: 'response.data'
|
|
44
|
-
});
|
|
45
|
-
const totalSent = BZZ.fromPLUR(asNumberString(body.totalSent, {
|
|
46
|
-
name: 'totalSent'
|
|
47
|
-
}));
|
|
48
|
-
const totalReceived = BZZ.fromPLUR(asNumberString(body.totalReceived, {
|
|
49
|
-
name: 'totalReceived'
|
|
50
|
-
}));
|
|
51
|
-
const settlements = Types.asArray(body.settlements, {
|
|
52
|
-
name: 'settlements'
|
|
53
|
-
}).map(x => Types.asObject(x, {
|
|
54
|
-
name: 'settlement'
|
|
55
|
-
}));
|
|
56
|
-
return {
|
|
57
|
-
totalSent,
|
|
58
|
-
totalReceived,
|
|
59
|
-
settlements: settlements.map(x => ({
|
|
60
|
-
peer: Types.asString(x.peer, {
|
|
61
|
-
name: 'peer'
|
|
62
|
-
}),
|
|
63
|
-
sent: BZZ.fromPLUR(asNumberString(x.sent, {
|
|
64
|
-
name: 'sent'
|
|
65
|
-
})),
|
|
66
|
-
received: BZZ.fromPLUR(asNumberString(x.received, {
|
|
67
|
-
name: 'received'
|
|
68
|
-
}))
|
|
69
|
-
}))
|
|
70
|
-
};
|
|
27
|
+
return GetAllSettlementsResponse.parse(response.data);
|
|
71
28
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetRedistributionStateResponse, GetStakeResponse, GetWithdrawableStakeResponse, TxHashResponse } from "../../types/schema/stake.js";
|
|
2
2
|
import { prepareRequestHeaders } from "../../utils/headers.js";
|
|
3
3
|
import { http } from "../../utils/http.js";
|
|
4
|
-
import { BZZ, DAI } from "../../utils/tokens.js";
|
|
5
|
-
import { asNumberString } from "../../utils/type.js";
|
|
6
|
-
import { TransactionId } from "../../utils/typed-bytes.js";
|
|
7
4
|
const STAKE_ENDPOINT = 'stake';
|
|
8
5
|
const REDISTRIBUTION_ENDPOINT = 'redistributionstate';
|
|
9
6
|
/**
|
|
@@ -17,12 +14,7 @@ export async function getStake(requestOptions) {
|
|
|
17
14
|
responseType: 'json',
|
|
18
15
|
url: `${STAKE_ENDPOINT}`
|
|
19
16
|
});
|
|
20
|
-
|
|
21
|
-
name: 'response.data'
|
|
22
|
-
});
|
|
23
|
-
return BZZ.fromPLUR(asNumberString(body.stakedAmount, {
|
|
24
|
-
name: 'stakedAmount'
|
|
25
|
-
}));
|
|
17
|
+
return GetStakeResponse.parse(response.data).stakedAmount;
|
|
26
18
|
}
|
|
27
19
|
/**
|
|
28
20
|
* Gets the amount of withdrawable staked BZZ
|
|
@@ -35,12 +27,7 @@ export async function getWithdrawableStake(requestOptions) {
|
|
|
35
27
|
responseType: 'json',
|
|
36
28
|
url: `${STAKE_ENDPOINT}/withdrawable`
|
|
37
29
|
});
|
|
38
|
-
|
|
39
|
-
name: 'response.data'
|
|
40
|
-
});
|
|
41
|
-
return BZZ.fromPLUR(asNumberString(body.withdrawableAmount, {
|
|
42
|
-
name: 'withdrawableAmount'
|
|
43
|
-
}));
|
|
30
|
+
return GetWithdrawableStakeResponse.parse(response.data).withdrawableAmount;
|
|
44
31
|
}
|
|
45
32
|
export async function withdrawSurplusStake(requestOptions) {
|
|
46
33
|
const response = await http(requestOptions, {
|
|
@@ -48,12 +35,7 @@ export async function withdrawSurplusStake(requestOptions) {
|
|
|
48
35
|
responseType: 'json',
|
|
49
36
|
url: `${STAKE_ENDPOINT}/withdrawable`
|
|
50
37
|
});
|
|
51
|
-
|
|
52
|
-
name: 'response.data'
|
|
53
|
-
});
|
|
54
|
-
return new TransactionId(Types.asHexString(body.txHash, {
|
|
55
|
-
name: 'txHash'
|
|
56
|
-
}));
|
|
38
|
+
return TxHashResponse.parse(response.data).txHash;
|
|
57
39
|
}
|
|
58
40
|
export async function migrateStake(requestOptions) {
|
|
59
41
|
const response = await http(requestOptions, {
|
|
@@ -61,12 +43,7 @@ export async function migrateStake(requestOptions) {
|
|
|
61
43
|
responseType: 'json',
|
|
62
44
|
url: STAKE_ENDPOINT
|
|
63
45
|
});
|
|
64
|
-
|
|
65
|
-
name: 'response.data'
|
|
66
|
-
});
|
|
67
|
-
return new TransactionId(Types.asHexString(body.txHash, {
|
|
68
|
-
name: 'txHash'
|
|
69
|
-
}));
|
|
46
|
+
return TxHashResponse.parse(response.data).txHash;
|
|
70
47
|
}
|
|
71
48
|
/**
|
|
72
49
|
* Stake given amount of tokens.
|
|
@@ -75,18 +52,13 @@ export async function migrateStake(requestOptions) {
|
|
|
75
52
|
* @param amount
|
|
76
53
|
*/
|
|
77
54
|
export async function stake(requestOptions, amount, options) {
|
|
78
|
-
const
|
|
55
|
+
const response = await http(requestOptions, {
|
|
79
56
|
method: 'post',
|
|
80
57
|
responseType: 'json',
|
|
81
58
|
url: `${STAKE_ENDPOINT}/${amount}`,
|
|
82
59
|
headers: prepareRequestHeaders(null, options)
|
|
83
60
|
});
|
|
84
|
-
|
|
85
|
-
name: 'response.data'
|
|
86
|
-
});
|
|
87
|
-
return new TransactionId(Types.asHexString(body.txHash, {
|
|
88
|
-
name: 'txHash'
|
|
89
|
-
}));
|
|
61
|
+
return TxHashResponse.parse(response.data).txHash;
|
|
90
62
|
}
|
|
91
63
|
/**
|
|
92
64
|
* Get current status of node in redistribution game
|
|
@@ -99,54 +71,5 @@ export async function getRedistributionState(requestOptions) {
|
|
|
99
71
|
responseType: 'json',
|
|
100
72
|
url: REDISTRIBUTION_ENDPOINT
|
|
101
73
|
});
|
|
102
|
-
|
|
103
|
-
name: 'response.data'
|
|
104
|
-
});
|
|
105
|
-
return {
|
|
106
|
-
minimumGasFunds: DAI.fromWei(asNumberString(body.minimumGasFunds, {
|
|
107
|
-
name: 'minimumGasFunds'
|
|
108
|
-
})),
|
|
109
|
-
hasSufficientFunds: Types.asBoolean(body.hasSufficientFunds, {
|
|
110
|
-
name: 'hasSufficientFunds'
|
|
111
|
-
}),
|
|
112
|
-
isFrozen: Types.asBoolean(body.isFrozen, {
|
|
113
|
-
name: 'isFrozen'
|
|
114
|
-
}),
|
|
115
|
-
isFullySynced: Types.asBoolean(body.isFullySynced, {
|
|
116
|
-
name: 'isFullySynced'
|
|
117
|
-
}),
|
|
118
|
-
phase: Types.asString(body.phase, {
|
|
119
|
-
name: 'phase'
|
|
120
|
-
}),
|
|
121
|
-
round: Types.asNumber(body.round, {
|
|
122
|
-
name: 'round'
|
|
123
|
-
}),
|
|
124
|
-
lastWonRound: Types.asNumber(body.lastWonRound, {
|
|
125
|
-
name: 'lastWonRound'
|
|
126
|
-
}),
|
|
127
|
-
lastPlayedRound: Types.asNumber(body.lastPlayedRound, {
|
|
128
|
-
name: 'lastPlayedRound'
|
|
129
|
-
}),
|
|
130
|
-
lastFrozenRound: Types.asNumber(body.lastFrozenRound, {
|
|
131
|
-
name: 'lastFrozenRound'
|
|
132
|
-
}),
|
|
133
|
-
lastSelectedRound: Types.asNumber(body.lastSelectedRound, {
|
|
134
|
-
name: 'lastSelectedRound'
|
|
135
|
-
}),
|
|
136
|
-
lastSampleDurationSeconds: Types.asNumber(body.lastSampleDurationSeconds, {
|
|
137
|
-
name: 'lastSampleDurationSeconds'
|
|
138
|
-
}),
|
|
139
|
-
block: Types.asNumber(body.block, {
|
|
140
|
-
name: 'block'
|
|
141
|
-
}),
|
|
142
|
-
reward: BZZ.fromPLUR(asNumberString(body.reward, {
|
|
143
|
-
name: 'reward'
|
|
144
|
-
})),
|
|
145
|
-
fees: DAI.fromWei(asNumberString(body.fees, {
|
|
146
|
-
name: 'fees'
|
|
147
|
-
})),
|
|
148
|
-
isHealthy: Types.asBoolean(body.isHealthy, {
|
|
149
|
-
name: 'isHealthy'
|
|
150
|
-
})
|
|
151
|
-
};
|
|
74
|
+
return GetRedistributionStateResponse.parse(response.data);
|
|
152
75
|
}
|