@ethersphere/bee-js 2.1.0 → 3.2.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/README.md +3 -3
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/src/bee-debug.d.ts +5 -1
- package/dist/src/bee.d.ts +23 -46
- package/dist/src/modules/chunk.d.ts +2 -10
- package/dist/src/modules/debug/status.d.ts +10 -4
- package/dist/src/types/debug.d.ts +19 -0
- package/dist/src/types/index.d.ts +31 -2
- package/dist/src/utils/bytes.d.ts +1 -1
- package/dist/src/utils/error.d.ts +21 -2
- package/dist/src/utils/expose.d.ts +1 -0
- package/dist/src/utils/http.d.ts +7 -9
- package/dist/src/utils/stamps.d.ts +12 -0
- package/dist/src/utils/type.d.ts +6 -0
- package/package.json +28 -27
- package/.babelrc.js +0 -33
- package/.depcheckrc.json +0 -27
- package/.editorconfig +0 -6
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -109
- package/.gitattributes +0 -1
- package/.github/config.yaml +0 -23
- package/.github/workflows/check.yaml +0 -57
- package/.github/workflows/publish_npmjs.yaml +0 -20
- package/.github/workflows/release_github.yaml +0 -20
- package/.github/workflows/tests.yaml +0 -128
- package/.huskyrc +0 -5
- package/.prettierrc +0 -13
- package/.vscode/launch.json +0 -49
- package/.vscode/settings.json +0 -39
- package/CHANGELOG.md +0 -520
- package/CODEOWNERS +0 -1
- package/CODE_OF_CONDUCT.md +0 -76
- package/commitlint.config.js +0 -3
- package/dist/src/modules/stamps.d.ts +0 -4
- package/jest-puppeteer.config.js +0 -5
- package/jest.config.ts +0 -85
- package/src/bee-debug.ts +0 -601
- package/src/bee.ts +0 -1087
- package/src/chunk/bmt.ts +0 -55
- package/src/chunk/cac.ts +0 -79
- package/src/chunk/serialize.ts +0 -16
- package/src/chunk/signer.ts +0 -141
- package/src/chunk/soc.ts +0 -190
- package/src/chunk/span.ts +0 -33
- package/src/feed/index.ts +0 -217
- package/src/feed/json.ts +0 -33
- package/src/feed/topic.ts +0 -23
- package/src/feed/type.ts +0 -12
- package/src/index.ts +0 -24
- package/src/modules/bytes.ts +0 -70
- package/src/modules/bzz.ts +0 -179
- package/src/modules/chunk.ts +0 -69
- package/src/modules/debug/balance.ts +0 -63
- package/src/modules/debug/chequebook.ts +0 -175
- package/src/modules/debug/chunk.ts +0 -39
- package/src/modules/debug/connectivity.ts +0 -61
- package/src/modules/debug/settlements.ts +0 -33
- package/src/modules/debug/stamps.ts +0 -96
- package/src/modules/debug/states.ts +0 -35
- package/src/modules/debug/status.ts +0 -34
- package/src/modules/debug/tag.ts +0 -19
- package/src/modules/debug/transactions.ts +0 -79
- package/src/modules/feed.ts +0 -105
- package/src/modules/pinning.ts +0 -74
- package/src/modules/pss.ts +0 -49
- package/src/modules/soc.ts +0 -40
- package/src/modules/stamps.ts +0 -59
- package/src/modules/status.ts +0 -13
- package/src/modules/stewardship.ts +0 -32
- package/src/modules/tag.ts +0 -83
- package/src/types/debug.ts +0 -204
- package/src/types/index.ts +0 -561
- package/src/types/ky-universal/common.d.ts +0 -17
- package/src/types/ky-universal/hooks.d.ts +0 -103
- package/src/types/ky-universal/index.d.ts +0 -125
- package/src/types/ky-universal/options.d.ts +0 -235
- package/src/types/ky-universal/response.d.ts +0 -38
- package/src/types/ky-universal/retry.d.ts +0 -39
- package/src/types/tar-js.d.ts +0 -1
- package/src/types/webpack-bundle-analyzer/index.d.ts +0 -13
- package/src/utils/bytes.ts +0 -144
- package/src/utils/collection.ts +0 -151
- package/src/utils/data.browser.ts +0 -68
- package/src/utils/data.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/eth.ts +0 -229
- package/src/utils/expose.ts +0 -48
- package/src/utils/file.ts +0 -40
- package/src/utils/hash.ts +0 -16
- package/src/utils/headers.ts +0 -63
- package/src/utils/hex.ts +0 -186
- package/src/utils/http.ts +0 -141
- package/src/utils/merge.ts +0 -34
- package/src/utils/pss.ts +0 -16
- package/src/utils/stream.ts +0 -146
- package/src/utils/tar.ts +0 -30
- package/src/utils/type.ts +0 -394
- package/src/utils/uint64.ts +0 -31
- package/src/utils/url.ts +0 -52
- package/test/bee.sh +0 -187
- package/test/data/1.txt +0 -1
- package/test/data/2.txt +0 -0
- package/test/data/empty +0 -0
- package/test/data/sub/3.txt +0 -1
- package/test/data/sub//303/251 +0 -0
- package/test/data/sub//360/237/230/216 +0 -0
- package/test/integration/bee-class.browser.spec.ts +0 -272
- package/test/integration/bee-class.spec.ts +0 -648
- package/test/integration/bee-debug-class.spec.ts +0 -114
- package/test/integration/chunk/bmt.spec.ts +0 -33
- package/test/integration/chunk/cac.spec.ts +0 -27
- package/test/integration/chunk/soc.spec.ts +0 -38
- package/test/integration/feed/index.spec.ts +0 -84
- package/test/integration/modules/bytes.spec.ts +0 -23
- package/test/integration/modules/bzz.spec.ts +0 -265
- package/test/integration/modules/chunk.spec.ts +0 -29
- package/test/integration/modules/debug/balance.spec.ts +0 -70
- package/test/integration/modules/debug/chequebook.spec.ts +0 -64
- package/test/integration/modules/debug/connectivity.spec.ts +0 -69
- package/test/integration/modules/debug/settlements.spec.ts +0 -34
- package/test/integration/modules/debug/states.spec.ts +0 -34
- package/test/integration/modules/debug/status.spec.ts +0 -65
- package/test/integration/modules/debug/tag.spec.ts +0 -27
- package/test/integration/modules/debug/transactions.spec.ts +0 -10
- package/test/integration/modules/feed.spec.ts +0 -61
- package/test/integration/modules/pinning.spec.ts +0 -155
- package/test/integration/modules/pss.spec.ts +0 -105
- package/test/integration/modules/status.spec.ts +0 -10
- package/test/integration/modules/stewardship.spec.ts +0 -32
- package/test/integration/modules/tag.spec.ts +0 -51
- package/test/test-type-sequencer.js +0 -36
- package/test/testpage/testpage.html +0 -20
- package/test/tests-setup.ts +0 -94
- package/test/unit/assertions.ts +0 -460
- package/test/unit/bee-class.spec.ts +0 -976
- package/test/unit/bee-debug-class.spec.ts +0 -435
- package/test/unit/chunk/bmt.spec.ts +0 -16
- package/test/unit/chunk/cac.spec.ts +0 -29
- package/test/unit/chunk/serialize.spec.ts +0 -24
- package/test/unit/chunk/signer.spec.ts +0 -140
- package/test/unit/chunk/soc.spec.ts +0 -25
- package/test/unit/chunk/span.spec.ts +0 -38
- package/test/unit/feed/json.spec.ts +0 -73
- package/test/unit/nock.ts +0 -151
- package/test/unit/utils/bytes.spec.ts +0 -32
- package/test/unit/utils/collection.spec.ts +0 -22
- package/test/unit/utils/eth.spec.ts +0 -224
- package/test/unit/utils/hex.spec.ts +0 -115
- package/test/unit/utils/stream.spec.ts +0 -30
- package/test/unit/utils/type.spec.ts +0 -32
- package/test/unit/utils/uint64.spec.ts +0 -102
- package/test/utils.ts +0 -426
- package/tsconfig.json +0 -18
- package/tsconfig.test.json +0 -11
- package/typedoc.json +0 -7
- package/webpack.config.ts +0 -141
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
import { http } from '../../utils/http'
|
|
2
|
-
import type {
|
|
3
|
-
ChequebookAddressResponse,
|
|
4
|
-
ChequebookBalanceResponse,
|
|
5
|
-
LastCashoutActionResponse,
|
|
6
|
-
TransactionResponse,
|
|
7
|
-
LastChequesForPeerResponse,
|
|
8
|
-
LastChequesResponse,
|
|
9
|
-
NumberString,
|
|
10
|
-
Ky,
|
|
11
|
-
CashoutOptions,
|
|
12
|
-
TransactionHash,
|
|
13
|
-
} from '../../types'
|
|
14
|
-
|
|
15
|
-
const chequebookEndpoint = 'chequebook'
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Get the address of the chequebook contract used
|
|
19
|
-
*
|
|
20
|
-
* @param ky Ky debug instance
|
|
21
|
-
*/
|
|
22
|
-
export async function getChequebookAddress(ky: Ky): Promise<ChequebookAddressResponse> {
|
|
23
|
-
const response = await http<ChequebookAddressResponse>(ky, {
|
|
24
|
-
path: chequebookEndpoint + '/address',
|
|
25
|
-
responseType: 'json',
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
return response.data
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Get the balance of the chequebook
|
|
33
|
-
*
|
|
34
|
-
* @param ky Ky debug instance
|
|
35
|
-
*/
|
|
36
|
-
export async function getChequebookBalance(ky: Ky): Promise<ChequebookBalanceResponse> {
|
|
37
|
-
const response = await http<ChequebookBalanceResponse>(ky, {
|
|
38
|
-
path: chequebookEndpoint + '/balance',
|
|
39
|
-
responseType: 'json',
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
return response.data
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Get last cashout action for the peer
|
|
47
|
-
*
|
|
48
|
-
* @param ky Ky debug instance
|
|
49
|
-
* @param peer Swarm address of peer
|
|
50
|
-
*/
|
|
51
|
-
export async function getLastCashoutAction(ky: Ky, peer: string): Promise<LastCashoutActionResponse> {
|
|
52
|
-
const response = await http<LastCashoutActionResponse>(ky, {
|
|
53
|
-
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
54
|
-
responseType: 'json',
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
return response.data
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Cashout the last cheque for the peer
|
|
62
|
-
*
|
|
63
|
-
* @param ky Ky debug instance
|
|
64
|
-
* @param peer Swarm address of peer
|
|
65
|
-
* @param options
|
|
66
|
-
*/
|
|
67
|
-
export async function cashoutLastCheque(ky: Ky, peer: string, options?: CashoutOptions): Promise<TransactionHash> {
|
|
68
|
-
const headers: Record<string, string> = {}
|
|
69
|
-
|
|
70
|
-
if (options?.gasPrice) {
|
|
71
|
-
headers['gas-price'] = options.gasPrice.toString()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (options?.gasLimit) {
|
|
75
|
-
headers['gas-limit'] = options.gasLimit.toString()
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const response = await http<TransactionResponse>(ky, {
|
|
79
|
-
method: 'post',
|
|
80
|
-
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
81
|
-
responseType: 'json',
|
|
82
|
-
headers,
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
return response.data.transactionHash
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Get last cheques for the peer
|
|
90
|
-
*
|
|
91
|
-
* @param ky Ky debug instance
|
|
92
|
-
* @param peer Swarm address of peer
|
|
93
|
-
*/
|
|
94
|
-
export async function getLastChequesForPeer(ky: Ky, peer: string): Promise<LastChequesForPeerResponse> {
|
|
95
|
-
const response = await http<LastChequesForPeerResponse>(ky, {
|
|
96
|
-
path: chequebookEndpoint + `/cheque/${peer}`,
|
|
97
|
-
responseType: 'json',
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
return response.data
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Get last cheques for all peers
|
|
105
|
-
*
|
|
106
|
-
* @param ky Ky debug instance
|
|
107
|
-
*/
|
|
108
|
-
export async function getLastCheques(ky: Ky): Promise<LastChequesResponse> {
|
|
109
|
-
const response = await http<LastChequesResponse>(ky, {
|
|
110
|
-
path: chequebookEndpoint + '/cheque',
|
|
111
|
-
responseType: 'json',
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
return response.data
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Deposit tokens from overlay address into chequebook
|
|
119
|
-
*
|
|
120
|
-
* @param ky Ky debug instance
|
|
121
|
-
* @param amount Amount of tokens to deposit
|
|
122
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
123
|
-
* @return string Hash of the transaction
|
|
124
|
-
*/
|
|
125
|
-
export async function depositTokens(
|
|
126
|
-
ky: Ky,
|
|
127
|
-
amount: number | NumberString,
|
|
128
|
-
gasPrice?: NumberString,
|
|
129
|
-
): Promise<TransactionHash> {
|
|
130
|
-
const headers: Record<string, string> = {}
|
|
131
|
-
|
|
132
|
-
if (gasPrice) {
|
|
133
|
-
headers['gas-price'] = gasPrice.toString()
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const response = await http<TransactionResponse>(ky, {
|
|
137
|
-
method: 'post',
|
|
138
|
-
path: chequebookEndpoint + '/deposit',
|
|
139
|
-
responseType: 'json',
|
|
140
|
-
searchParams: { amount: amount.toString(10) },
|
|
141
|
-
headers,
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
return response.data.transactionHash
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Withdraw tokens from the chequebook to the overlay address
|
|
149
|
-
*
|
|
150
|
-
* @param ky Ky debug instance
|
|
151
|
-
* @param amount Amount of tokens to withdraw
|
|
152
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
153
|
-
* @return string Hash of the transaction
|
|
154
|
-
*/
|
|
155
|
-
export async function withdrawTokens(
|
|
156
|
-
ky: Ky,
|
|
157
|
-
amount: number | NumberString,
|
|
158
|
-
gasPrice?: NumberString,
|
|
159
|
-
): Promise<TransactionHash> {
|
|
160
|
-
const headers: Record<string, string> = {}
|
|
161
|
-
|
|
162
|
-
if (gasPrice) {
|
|
163
|
-
headers['gas-price'] = gasPrice.toString()
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
const response = await http<TransactionResponse>(ky, {
|
|
167
|
-
method: 'post',
|
|
168
|
-
path: chequebookEndpoint + '/withdraw',
|
|
169
|
-
responseType: 'json',
|
|
170
|
-
searchParams: { amount: amount.toString(10) },
|
|
171
|
-
headers,
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
return response.data.transactionHash
|
|
175
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import type { BeeGenericResponse, Ky } from '../../types'
|
|
2
|
-
import { http } from '../../utils/http'
|
|
3
|
-
|
|
4
|
-
const endpoint = 'chunks'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Check if chunk at address exists locally
|
|
8
|
-
*
|
|
9
|
-
* @param ky Ky debug instance
|
|
10
|
-
* @param address Swarm address of chunk
|
|
11
|
-
*
|
|
12
|
-
* @returns BeeGenericResponse if chunk is found or throws an exception
|
|
13
|
-
*/
|
|
14
|
-
export async function checkIfChunkExistsLocally(ky: Ky, address: string): Promise<BeeGenericResponse> {
|
|
15
|
-
const response = await http<BeeGenericResponse>(ky, {
|
|
16
|
-
path: endpoint + `/${address}`,
|
|
17
|
-
responseType: 'json',
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return response.data
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Delete a chunk from local storage
|
|
25
|
-
*
|
|
26
|
-
* @param ky Ky debug instance
|
|
27
|
-
* @param address Swarm address of chunk
|
|
28
|
-
*
|
|
29
|
-
* @returns BeeGenericResponse if chunk was deleted or throws an exception
|
|
30
|
-
*/
|
|
31
|
-
export async function deleteChunkFromLocalStorage(ky: Ky, address: string): Promise<BeeGenericResponse> {
|
|
32
|
-
const response = await http<BeeGenericResponse>(ky, {
|
|
33
|
-
method: 'delete',
|
|
34
|
-
path: endpoint + `/${address}`,
|
|
35
|
-
responseType: 'json',
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return response.data
|
|
39
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { http } from '../../utils/http'
|
|
2
|
-
import type { Ky, NodeAddresses, Peer, PingResponse, RemovePeerResponse, Topology } from '../../types'
|
|
3
|
-
|
|
4
|
-
export async function getNodeAddresses(ky: Ky): Promise<NodeAddresses> {
|
|
5
|
-
const response = await http<NodeAddresses>(ky, {
|
|
6
|
-
path: 'addresses',
|
|
7
|
-
responseType: 'json',
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
return response.data
|
|
11
|
-
}
|
|
12
|
-
interface Peers {
|
|
13
|
-
peers: Peer[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function getPeers(ky: Ky): Promise<Peer[]> {
|
|
17
|
-
const response = await http<Peers>(ky, {
|
|
18
|
-
path: 'peers',
|
|
19
|
-
responseType: 'json',
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
return response.data.peers || []
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function getBlocklist(ky: Ky): Promise<Peer[]> {
|
|
26
|
-
const response = await http<Peers>(ky, {
|
|
27
|
-
path: 'blocklist',
|
|
28
|
-
responseType: 'json',
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
return response.data.peers || []
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function removePeer(ky: Ky, peer: string): Promise<RemovePeerResponse> {
|
|
35
|
-
const response = await http<RemovePeerResponse>(ky, {
|
|
36
|
-
path: `peers/${peer}`,
|
|
37
|
-
responseType: 'json',
|
|
38
|
-
method: 'DELETE',
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
return response.data
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function getTopology(ky: Ky): Promise<Topology> {
|
|
45
|
-
const response = await http<Topology>(ky, {
|
|
46
|
-
path: `topology`,
|
|
47
|
-
responseType: 'json',
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
return response.data
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export async function pingPeer(ky: Ky, peer: string): Promise<PingResponse> {
|
|
54
|
-
const response = await http<PingResponse>(ky, {
|
|
55
|
-
path: `pingpong/${peer}`,
|
|
56
|
-
responseType: 'json',
|
|
57
|
-
method: 'POST',
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
return response.data
|
|
61
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { http } from '../../utils/http'
|
|
2
|
-
import type { Settlements, AllSettlements, Ky } from '../../types'
|
|
3
|
-
|
|
4
|
-
const settlementsEndpoint = 'settlements'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Get amount of sent and received from settlements with a peer
|
|
8
|
-
*
|
|
9
|
-
* @param ky Ky debug instance
|
|
10
|
-
* @param peer Swarm address of peer
|
|
11
|
-
*/
|
|
12
|
-
export async function getSettlements(ky: Ky, peer: string): Promise<Settlements> {
|
|
13
|
-
const response = await http<Settlements>(ky, {
|
|
14
|
-
path: `${settlementsEndpoint}/${peer}`,
|
|
15
|
-
responseType: 'json',
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return response.data
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get settlements with all known peers and total amount sent or received
|
|
23
|
-
*
|
|
24
|
-
* @param ky Ky debug instance
|
|
25
|
-
*/
|
|
26
|
-
export async function getAllSettlements(ky: Ky): Promise<AllSettlements> {
|
|
27
|
-
const response = await http<AllSettlements>(ky, {
|
|
28
|
-
path: settlementsEndpoint,
|
|
29
|
-
responseType: 'json',
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
return response.data
|
|
33
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BatchId,
|
|
3
|
-
DebugPostageBatch,
|
|
4
|
-
Ky,
|
|
5
|
-
NumberString,
|
|
6
|
-
PostageBatchBuckets,
|
|
7
|
-
PostageBatchOptions,
|
|
8
|
-
} from '../../types'
|
|
9
|
-
import { http } from '../../utils/http'
|
|
10
|
-
|
|
11
|
-
const STAMPS_ENDPOINT = 'stamps'
|
|
12
|
-
|
|
13
|
-
interface GetAllStampsResponse {
|
|
14
|
-
stamps: DebugPostageBatch[]
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface StampResponse {
|
|
18
|
-
batchID: BatchId
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function getAllPostageBatches(ky: Ky): Promise<DebugPostageBatch[]> {
|
|
22
|
-
const response = await http<GetAllStampsResponse>(ky, {
|
|
23
|
-
method: 'get',
|
|
24
|
-
path: `${STAMPS_ENDPOINT}`,
|
|
25
|
-
responseType: 'json',
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
return response.data.stamps || []
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export async function getPostageBatch(ky: Ky, postageBatchId: BatchId): Promise<DebugPostageBatch> {
|
|
32
|
-
const response = await http<DebugPostageBatch>(ky, {
|
|
33
|
-
method: 'get',
|
|
34
|
-
path: `${STAMPS_ENDPOINT}/${postageBatchId}`,
|
|
35
|
-
responseType: 'json',
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
return response.data
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export async function getPostageBatchBuckets(ky: Ky, postageBatchId: BatchId): Promise<PostageBatchBuckets> {
|
|
42
|
-
const response = await http<PostageBatchBuckets>(ky, {
|
|
43
|
-
method: 'get',
|
|
44
|
-
path: `${STAMPS_ENDPOINT}/${postageBatchId}/buckets`,
|
|
45
|
-
responseType: 'json',
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return response.data
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export async function createPostageBatch(
|
|
52
|
-
ky: Ky,
|
|
53
|
-
amount: NumberString,
|
|
54
|
-
depth: number,
|
|
55
|
-
options?: PostageBatchOptions,
|
|
56
|
-
): Promise<BatchId> {
|
|
57
|
-
const headers: Record<string, string> = {}
|
|
58
|
-
|
|
59
|
-
if (options?.gasPrice) {
|
|
60
|
-
headers['gas-price'] = options.gasPrice.toString()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (options?.immutableFlag !== undefined) {
|
|
64
|
-
headers.immutable = String(options.immutableFlag)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const response = await http<StampResponse>(ky, {
|
|
68
|
-
method: 'post',
|
|
69
|
-
path: `${STAMPS_ENDPOINT}/${amount}/${depth}`,
|
|
70
|
-
responseType: 'json',
|
|
71
|
-
searchParams: { label: options?.label },
|
|
72
|
-
headers,
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
return response.data.batchID
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export async function topUpBatch(ky: Ky, id: string, amount: NumberString): Promise<BatchId> {
|
|
79
|
-
const response = await http<StampResponse>(ky, {
|
|
80
|
-
method: 'patch',
|
|
81
|
-
path: `${STAMPS_ENDPOINT}/topup/${id}/${amount}`,
|
|
82
|
-
responseType: 'json',
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
return response.data.batchID
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export async function diluteBatch(ky: Ky, id: string, depth: number): Promise<BatchId> {
|
|
89
|
-
const response = await http<StampResponse>(ky, {
|
|
90
|
-
method: 'patch',
|
|
91
|
-
path: `${STAMPS_ENDPOINT}/dilute/${id}/${depth}`,
|
|
92
|
-
responseType: 'json',
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
return response.data.batchID
|
|
96
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { http } from '../../utils/http'
|
|
2
|
-
import { ChainState, Ky, ReserveState } from '../../types'
|
|
3
|
-
|
|
4
|
-
const RESERVE_STATE_ENDPOINT = 'reservestate'
|
|
5
|
-
const CHAIN_STATE_ENDPOINT = 'chainstate'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Get state of reserve
|
|
9
|
-
*
|
|
10
|
-
* @param ky Ky debug instance
|
|
11
|
-
*/
|
|
12
|
-
export async function getReserveState(ky: Ky): Promise<ReserveState> {
|
|
13
|
-
const response = await http<ReserveState>(ky, {
|
|
14
|
-
method: 'get',
|
|
15
|
-
path: `${RESERVE_STATE_ENDPOINT}`,
|
|
16
|
-
responseType: 'json',
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
return response.data
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Get state of reserve
|
|
24
|
-
*
|
|
25
|
-
* @param ky Ky debug instance
|
|
26
|
-
*/
|
|
27
|
-
export async function getChainState(ky: Ky): Promise<ChainState> {
|
|
28
|
-
const response = await http<ChainState>(ky, {
|
|
29
|
-
method: 'get',
|
|
30
|
-
path: `${CHAIN_STATE_ENDPOINT}`,
|
|
31
|
-
responseType: 'json',
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
return response.data
|
|
35
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { http } from '../../utils/http'
|
|
2
|
-
import type { Health } from '../../types/debug'
|
|
3
|
-
import { engines } from '../../../package.json'
|
|
4
|
-
import { Ky } from '../../types'
|
|
5
|
-
export const SUPPORTED_BEE_VERSION_EXACT = engines.bee
|
|
6
|
-
export const SUPPORTED_BEE_VERSION = engines.bee.substr(0, engines.bee.indexOf('-'))
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Get health of node
|
|
10
|
-
*
|
|
11
|
-
* @param ky Ky debug instance
|
|
12
|
-
*/
|
|
13
|
-
export async function getHealth(ky: Ky): Promise<Health> | never {
|
|
14
|
-
const response = await http<Health>(ky, {
|
|
15
|
-
method: 'get',
|
|
16
|
-
path: `health`,
|
|
17
|
-
responseType: 'json',
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
return response.data
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
25
|
-
*
|
|
26
|
-
* @param ky Ky debug instance
|
|
27
|
-
*
|
|
28
|
-
* @returns true if the Bee node version is supported
|
|
29
|
-
*/
|
|
30
|
-
export async function isSupportedVersion(ky: Ky): Promise<boolean> | never {
|
|
31
|
-
const { version } = await getHealth(ky)
|
|
32
|
-
|
|
33
|
-
return version === SUPPORTED_BEE_VERSION_EXACT
|
|
34
|
-
}
|
package/src/modules/debug/tag.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ExtendedTag, Ky } from '../../types'
|
|
2
|
-
import { http } from '../../utils/http'
|
|
3
|
-
|
|
4
|
-
const endpoint = 'tags'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Retrieve tag with extended information from Bee node
|
|
8
|
-
*
|
|
9
|
-
* @param ky Ky debug instance
|
|
10
|
-
* @param uid UID of tag to be retrieved
|
|
11
|
-
*/
|
|
12
|
-
export async function retrieveExtendedTag(ky: Ky, uid: number): Promise<ExtendedTag> {
|
|
13
|
-
const response = await http<ExtendedTag>(ky, {
|
|
14
|
-
path: `${endpoint}/${uid}`,
|
|
15
|
-
responseType: 'json',
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
return response.data
|
|
19
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Ky, NumberString, TransactionHash, TransactionInfo } from '../../types'
|
|
2
|
-
import { http } from '../../utils/http'
|
|
3
|
-
|
|
4
|
-
const transactionsEndpoint = 'transactions'
|
|
5
|
-
|
|
6
|
-
interface PendingTransactionsResponse {
|
|
7
|
-
pendingTransactions: TransactionInfo[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface TransactionResponse {
|
|
11
|
-
transactionHash: TransactionHash
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get list of all pending transactions
|
|
16
|
-
*
|
|
17
|
-
* @param ky Debug Ky instance
|
|
18
|
-
*/
|
|
19
|
-
export async function getAllTransactions(ky: Ky): Promise<TransactionInfo[]> {
|
|
20
|
-
const response = await http<PendingTransactionsResponse>(ky, {
|
|
21
|
-
path: transactionsEndpoint,
|
|
22
|
-
responseType: 'json',
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
return response.data.pendingTransactions
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Get information for specific pending transactions
|
|
30
|
-
*
|
|
31
|
-
* @param ky Debug Ky instance
|
|
32
|
-
* @param transactionHash Hash of the transaction
|
|
33
|
-
*/
|
|
34
|
-
export async function getTransaction(ky: Ky, transactionHash: TransactionHash): Promise<TransactionInfo> {
|
|
35
|
-
const response = await http<TransactionInfo>(ky, {
|
|
36
|
-
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
37
|
-
responseType: 'json',
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
return response.data
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Rebroadcast existing transaction
|
|
45
|
-
*
|
|
46
|
-
* @param ky Debug Ky instance
|
|
47
|
-
* @param transactionHash Hash of the transaction
|
|
48
|
-
*/
|
|
49
|
-
export async function rebroadcastTransaction(ky: Ky, transactionHash: TransactionHash): Promise<TransactionHash> {
|
|
50
|
-
const response = await http<TransactionResponse>(ky, {
|
|
51
|
-
method: 'post',
|
|
52
|
-
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
53
|
-
responseType: 'json',
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
return response.data.transactionHash
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Cancel existing transaction
|
|
61
|
-
*
|
|
62
|
-
* @param ky Debug Ky instance
|
|
63
|
-
* @param transactionHash Hash of the transaction
|
|
64
|
-
* @param gasPrice Optional gas price
|
|
65
|
-
*/
|
|
66
|
-
export async function cancelTransaction(
|
|
67
|
-
ky: Ky,
|
|
68
|
-
transactionHash: TransactionHash,
|
|
69
|
-
gasPrice?: NumberString,
|
|
70
|
-
): Promise<TransactionHash> {
|
|
71
|
-
const response = await http<TransactionResponse>(ky, {
|
|
72
|
-
method: 'delete',
|
|
73
|
-
headers: { 'gas-price': gasPrice },
|
|
74
|
-
path: `${transactionsEndpoint}/${transactionHash}`,
|
|
75
|
-
responseType: 'json',
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
return response.data.transactionHash
|
|
79
|
-
}
|
package/src/modules/feed.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { BatchId, Ky, Reference, ReferenceResponse, Topic } from '../types'
|
|
2
|
-
import { filterHeaders, http } from '../utils/http'
|
|
3
|
-
import { FeedType } from '../feed/type'
|
|
4
|
-
import { HexEthAddress } from '../utils/eth'
|
|
5
|
-
import { extractUploadHeaders } from '../utils/headers'
|
|
6
|
-
import { BeeError } from '../utils/error'
|
|
7
|
-
|
|
8
|
-
const feedEndpoint = 'feeds'
|
|
9
|
-
|
|
10
|
-
export interface CreateFeedOptions {
|
|
11
|
-
type?: FeedType
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface FeedUpdateOptions {
|
|
15
|
-
/**
|
|
16
|
-
* Specifies the start date as unix time stamp
|
|
17
|
-
*/
|
|
18
|
-
at?: number
|
|
19
|
-
/**
|
|
20
|
-
* Can be 'epoch' or 'sequence' (default: 'sequence')
|
|
21
|
-
*/
|
|
22
|
-
type?: FeedType
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface FeedUpdateHeaders {
|
|
26
|
-
feedIndex: string
|
|
27
|
-
feedIndexNext: string
|
|
28
|
-
}
|
|
29
|
-
export interface FetchFeedUpdateResponse extends ReferenceResponse, FeedUpdateHeaders {}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Create an initial feed root manifest
|
|
33
|
-
*
|
|
34
|
-
* @param ky Ky instance
|
|
35
|
-
* @param owner Owner's ethereum address in hex
|
|
36
|
-
* @param topic Topic in hex
|
|
37
|
-
* @param postageBatchId Postage BatchId to be used to create the Feed Manifest
|
|
38
|
-
* @param options Additional options, like type (default: 'sequence')
|
|
39
|
-
*/
|
|
40
|
-
export async function createFeedManifest(
|
|
41
|
-
ky: Ky,
|
|
42
|
-
owner: HexEthAddress,
|
|
43
|
-
topic: Topic,
|
|
44
|
-
postageBatchId: BatchId,
|
|
45
|
-
options?: CreateFeedOptions,
|
|
46
|
-
): Promise<Reference> {
|
|
47
|
-
const response = await http<ReferenceResponse>(ky, {
|
|
48
|
-
method: 'post',
|
|
49
|
-
responseType: 'json',
|
|
50
|
-
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
51
|
-
searchParams: filterHeaders(options),
|
|
52
|
-
headers: extractUploadHeaders(postageBatchId),
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
return response.data.reference
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function readFeedUpdateHeaders(headers: Headers): FeedUpdateHeaders {
|
|
59
|
-
const feedIndex = headers.get('swarm-feed-index')
|
|
60
|
-
const feedIndexNext = headers.get('swarm-feed-index-next')
|
|
61
|
-
|
|
62
|
-
if (!feedIndex) {
|
|
63
|
-
throw new BeeError('Response did not contain expected swarm-feed-index!')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!feedIndexNext) {
|
|
67
|
-
throw new BeeError('Response did not contain expected swarm-feed-index-next!')
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
feedIndex,
|
|
72
|
-
feedIndexNext,
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Find and retrieve feed update
|
|
78
|
-
*
|
|
79
|
-
* The feed consists of updates. This endpoint looks up an
|
|
80
|
-
* update that matches the provided parameters and returns
|
|
81
|
-
* the reference it contains along with its index and the
|
|
82
|
-
* index of the subsequent update.
|
|
83
|
-
*
|
|
84
|
-
* @param ky Ky instance
|
|
85
|
-
* @param owner Owner's ethereum address in hex
|
|
86
|
-
* @param topic Topic in hex
|
|
87
|
-
* @param options Additional options, like index, at, type
|
|
88
|
-
*/
|
|
89
|
-
export async function fetchFeedUpdate(
|
|
90
|
-
ky: Ky,
|
|
91
|
-
owner: HexEthAddress,
|
|
92
|
-
topic: Topic,
|
|
93
|
-
options?: FeedUpdateOptions,
|
|
94
|
-
): Promise<FetchFeedUpdateResponse> {
|
|
95
|
-
const response = await http<ReferenceResponse>(ky, {
|
|
96
|
-
responseType: 'json',
|
|
97
|
-
path: `${feedEndpoint}/${owner}/${topic}`,
|
|
98
|
-
searchParams: filterHeaders(options),
|
|
99
|
-
})
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
...response.data,
|
|
103
|
-
...readFeedUpdateHeaders(response.headers),
|
|
104
|
-
}
|
|
105
|
-
}
|