@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
package/jest.config.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* For a detailed explanation regarding each configuration property and type check, visit:
|
|
3
|
-
* https://jestjs.io/docs/en/configuration.html
|
|
4
|
-
*/
|
|
5
|
-
import type { Config } from '@jest/types'
|
|
6
|
-
import { glob } from 'glob'
|
|
7
|
-
import * as Path from 'path'
|
|
8
|
-
|
|
9
|
-
export async function getBrowserPathMapping(): Promise<{ [aliasNodeReference: string]: string }> {
|
|
10
|
-
const browserSourceFiles = await new Promise<{ [aliasNodeReference: string]: string }>((resolve, reject) => {
|
|
11
|
-
glob('src/**/*.browser.ts', (err, browserSourceCodes) => {
|
|
12
|
-
if (err) reject(err)
|
|
13
|
-
browserSourceCodes = browserSourceCodes.map(match => Path.resolve(__dirname, match))
|
|
14
|
-
const codePathMapping: { [nodeFullPath: string]: string } = {}
|
|
15
|
-
browserSourceCodes.map(browserFullPath => {
|
|
16
|
-
const filePathArray = browserFullPath.split('.')
|
|
17
|
-
filePathArray.pop()
|
|
18
|
-
filePathArray.pop() //remove 'browser.ts' from '**/*.browser.ts'
|
|
19
|
-
const nodeFullPath = filePathArray.join('.')
|
|
20
|
-
const aliasNodeReference = `/${nodeFullPath.split('/').pop()}$` //keep the last bit of node file referencing e.g. '/file-source$'
|
|
21
|
-
|
|
22
|
-
codePathMapping[aliasNodeReference] = browserFullPath
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
resolve(codePathMapping)
|
|
26
|
-
})
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
return browserSourceFiles
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default async (): Promise<Config.InitialOptions> => {
|
|
33
|
-
return {
|
|
34
|
-
// Indicates whether the coverage information should be collected while executing the test
|
|
35
|
-
// collectCoverage: false,
|
|
36
|
-
|
|
37
|
-
// This will setup the prerequisites for the tests to run
|
|
38
|
-
globalSetup: './tests-setup.ts',
|
|
39
|
-
|
|
40
|
-
// The directory where Jest should output its coverage files
|
|
41
|
-
coverageDirectory: 'coverage',
|
|
42
|
-
|
|
43
|
-
// Custom sequencer that priorities running unit tests before integration tests
|
|
44
|
-
testSequencer: '<rootDir>/test-type-sequencer.js',
|
|
45
|
-
|
|
46
|
-
// An array of regexp pattern strings used to skip coverage collection
|
|
47
|
-
coveragePathIgnorePatterns: ['/node_modules/'],
|
|
48
|
-
|
|
49
|
-
// An array of directory names to be searched recursively up from the requiring module's location
|
|
50
|
-
moduleDirectories: ['node_modules'],
|
|
51
|
-
|
|
52
|
-
// Run tests from one or more projects
|
|
53
|
-
projects: [
|
|
54
|
-
// We don't have any DOM specific tests atm.
|
|
55
|
-
// {
|
|
56
|
-
// displayName: 'dom:unit',
|
|
57
|
-
// testRegex: 'test/unit/.*\\.browser\\.spec\\.ts',
|
|
58
|
-
// moduleNameMapper: await getBrowserPathMapping(),
|
|
59
|
-
// preset: 'jest-puppeteer',
|
|
60
|
-
// },
|
|
61
|
-
{
|
|
62
|
-
displayName: 'node:unit',
|
|
63
|
-
testEnvironment: 'node',
|
|
64
|
-
testRegex: 'test/unit/((?!\\.browser).)*\\.spec\\.ts',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
displayName: 'dom:integration',
|
|
68
|
-
testRegex: 'test/integration/.*\\.browser\\.spec\\.ts',
|
|
69
|
-
moduleNameMapper: await getBrowserPathMapping(),
|
|
70
|
-
preset: 'jest-puppeteer',
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
displayName: 'node:integration',
|
|
74
|
-
testEnvironment: 'node',
|
|
75
|
-
testRegex: 'test/integration/((?!\\.browser).)*\\.spec\\.ts',
|
|
76
|
-
},
|
|
77
|
-
] as unknown[] as string[], // bad types
|
|
78
|
-
|
|
79
|
-
// The root directory that Jest should scan for tests and modules within
|
|
80
|
-
rootDir: 'test',
|
|
81
|
-
|
|
82
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
83
|
-
testPathIgnorePatterns: ['/node_modules/'],
|
|
84
|
-
}
|
|
85
|
-
}
|
package/src/bee-debug.ts
DELETED
|
@@ -1,601 +0,0 @@
|
|
|
1
|
-
import * as connectivity from './modules/debug/connectivity'
|
|
2
|
-
import * as balance from './modules/debug/balance'
|
|
3
|
-
import * as chequebook from './modules/debug/chequebook'
|
|
4
|
-
import * as settlements from './modules/debug/settlements'
|
|
5
|
-
import * as status from './modules/debug/status'
|
|
6
|
-
import * as transactions from './modules/debug/transactions'
|
|
7
|
-
import * as states from './modules/debug/states'
|
|
8
|
-
import type {
|
|
9
|
-
Address,
|
|
10
|
-
Peer,
|
|
11
|
-
BalanceResponse,
|
|
12
|
-
PeerBalance,
|
|
13
|
-
ChequebookAddressResponse,
|
|
14
|
-
ChequebookBalanceResponse,
|
|
15
|
-
LastChequesResponse,
|
|
16
|
-
LastChequesForPeerResponse,
|
|
17
|
-
LastCashoutActionResponse,
|
|
18
|
-
Settlements,
|
|
19
|
-
AllSettlements,
|
|
20
|
-
RemovePeerResponse,
|
|
21
|
-
Topology,
|
|
22
|
-
PingResponse,
|
|
23
|
-
Health,
|
|
24
|
-
NodeAddresses,
|
|
25
|
-
ReserveState,
|
|
26
|
-
ChainState,
|
|
27
|
-
NumberString,
|
|
28
|
-
ExtendedTag,
|
|
29
|
-
PostageBatchBuckets,
|
|
30
|
-
DebugPostageBatch,
|
|
31
|
-
Ky,
|
|
32
|
-
TransactionInfo,
|
|
33
|
-
TransactionHash,
|
|
34
|
-
} from './types'
|
|
35
|
-
import { BeeArgumentError } from './utils/error'
|
|
36
|
-
import { assertBeeUrl, stripLastSlash } from './utils/url'
|
|
37
|
-
import {
|
|
38
|
-
assertAddress,
|
|
39
|
-
assertBatchId,
|
|
40
|
-
assertBoolean,
|
|
41
|
-
assertCashoutOptions,
|
|
42
|
-
assertNonNegativeInteger,
|
|
43
|
-
assertRequestOptions,
|
|
44
|
-
assertTransactionHash,
|
|
45
|
-
isTag,
|
|
46
|
-
} from './utils/type'
|
|
47
|
-
import {
|
|
48
|
-
BatchId,
|
|
49
|
-
BeeOptions,
|
|
50
|
-
CashoutOptions,
|
|
51
|
-
PostageBatchOptions,
|
|
52
|
-
RequestOptions,
|
|
53
|
-
STAMPS_DEPTH_MAX,
|
|
54
|
-
STAMPS_DEPTH_MIN,
|
|
55
|
-
Tag,
|
|
56
|
-
} from './types'
|
|
57
|
-
import * as tag from './modules/debug/tag'
|
|
58
|
-
import * as stamps from './modules/debug/stamps'
|
|
59
|
-
import type { Options as KyOptions } from 'ky-universal'
|
|
60
|
-
import { makeDefaultKy, wrapRequestClosure, wrapResponseClosure } from './utils/http'
|
|
61
|
-
|
|
62
|
-
export class BeeDebug {
|
|
63
|
-
/**
|
|
64
|
-
* URL on which is the Debug API of Bee node exposed
|
|
65
|
-
*/
|
|
66
|
-
public readonly url: string
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Ky instance that defines connection to Bee node
|
|
70
|
-
* @private
|
|
71
|
-
*/
|
|
72
|
-
private readonly ky: Ky
|
|
73
|
-
|
|
74
|
-
constructor(url: string, options?: BeeOptions) {
|
|
75
|
-
assertBeeUrl(url)
|
|
76
|
-
|
|
77
|
-
// Remove last slash if present, as our endpoint strings starts with `/...`
|
|
78
|
-
// which could lead to double slash in URL to which Bee responds with
|
|
79
|
-
// unnecessary redirects.
|
|
80
|
-
this.url = stripLastSlash(url)
|
|
81
|
-
|
|
82
|
-
const kyOptions: KyOptions = {
|
|
83
|
-
prefixUrl: this.url,
|
|
84
|
-
timeout: options?.timeout ?? false,
|
|
85
|
-
retry: options?.retry,
|
|
86
|
-
fetch: options?.fetch,
|
|
87
|
-
hooks: {
|
|
88
|
-
beforeRequest: [],
|
|
89
|
-
afterResponse: [],
|
|
90
|
-
},
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (options?.defaultHeaders) {
|
|
94
|
-
kyOptions.headers = options.defaultHeaders
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (options?.onRequest) {
|
|
98
|
-
kyOptions.hooks!.beforeRequest!.push(wrapRequestClosure(options.onRequest))
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (options?.onResponse) {
|
|
102
|
-
kyOptions.hooks!.afterResponse!.push(wrapResponseClosure(options.onResponse))
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.ky = makeDefaultKy(kyOptions)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
async getNodeAddresses(options?: RequestOptions): Promise<NodeAddresses> {
|
|
109
|
-
assertRequestOptions(options)
|
|
110
|
-
|
|
111
|
-
return connectivity.getNodeAddresses(this.getKy(options))
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
async getBlocklist(options?: RequestOptions): Promise<Peer[]> {
|
|
115
|
-
assertRequestOptions(options)
|
|
116
|
-
|
|
117
|
-
return connectivity.getBlocklist(this.getKy(options))
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Retrieve tag extended information from Bee node
|
|
122
|
-
*
|
|
123
|
-
* @param tagUid UID or tag object to be retrieved
|
|
124
|
-
* @throws TypeError if tagUid is in not correct format
|
|
125
|
-
*
|
|
126
|
-
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
127
|
-
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/debug-api/#tag/Tag)
|
|
128
|
-
*
|
|
129
|
-
*/
|
|
130
|
-
async retrieveExtendedTag(tagUid: number | Tag, options?: RequestOptions): Promise<ExtendedTag> {
|
|
131
|
-
assertRequestOptions(options)
|
|
132
|
-
|
|
133
|
-
if (isTag(tagUid)) {
|
|
134
|
-
tagUid = tagUid.uid
|
|
135
|
-
} else if (typeof tagUid === 'number') {
|
|
136
|
-
assertNonNegativeInteger(tagUid, 'UID')
|
|
137
|
-
} else {
|
|
138
|
-
throw new TypeError('tagUid has to be either Tag or a number (UID)!')
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return tag.retrieveExtendedTag(this.getKy(options), tagUid)
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Get list of peers for this node
|
|
146
|
-
*/
|
|
147
|
-
async getPeers(options?: RequestOptions): Promise<Peer[]> {
|
|
148
|
-
assertRequestOptions(options)
|
|
149
|
-
|
|
150
|
-
return connectivity.getPeers(this.getKy(options))
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async removePeer(peer: string | Address, options?: RequestOptions): Promise<RemovePeerResponse> {
|
|
154
|
-
assertRequestOptions(options)
|
|
155
|
-
assertAddress(peer)
|
|
156
|
-
|
|
157
|
-
return connectivity.removePeer(this.getKy(options), peer)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async getTopology(options?: RequestOptions): Promise<Topology> {
|
|
161
|
-
assertRequestOptions(options)
|
|
162
|
-
|
|
163
|
-
return connectivity.getTopology(this.getKy(options))
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
async pingPeer(peer: string | Address, options?: RequestOptions): Promise<PingResponse> {
|
|
167
|
-
assertRequestOptions(options)
|
|
168
|
-
assertAddress(peer)
|
|
169
|
-
|
|
170
|
-
return connectivity.pingPeer(this.getKy(options), peer)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/*
|
|
174
|
-
* Balance endpoints
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Get the balances with all known peers including prepaid services
|
|
179
|
-
*/
|
|
180
|
-
async getAllBalances(options?: RequestOptions): Promise<BalanceResponse> {
|
|
181
|
-
assertRequestOptions(options)
|
|
182
|
-
|
|
183
|
-
return balance.getAllBalances(this.getKy(options))
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get the balances with a specific peer including prepaid services
|
|
188
|
-
*
|
|
189
|
-
* @param address Swarm address of peer
|
|
190
|
-
*/
|
|
191
|
-
async getPeerBalance(address: Address | string, options?: RequestOptions): Promise<PeerBalance> {
|
|
192
|
-
assertRequestOptions(options)
|
|
193
|
-
assertAddress(address)
|
|
194
|
-
|
|
195
|
-
return balance.getPeerBalance(this.getKy(options), address)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Get the past due consumption balances with all known peers
|
|
200
|
-
*/
|
|
201
|
-
async getPastDueConsumptionBalances(options?: RequestOptions): Promise<BalanceResponse> {
|
|
202
|
-
assertRequestOptions(options)
|
|
203
|
-
|
|
204
|
-
return balance.getPastDueConsumptionBalances(this.getKy(options))
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Get the past due consumption balance with a specific peer
|
|
209
|
-
*
|
|
210
|
-
* @param address Swarm address of peer
|
|
211
|
-
*/
|
|
212
|
-
async getPastDueConsumptionPeerBalance(address: Address | string, options?: RequestOptions): Promise<PeerBalance> {
|
|
213
|
-
assertRequestOptions(options)
|
|
214
|
-
assertAddress(address)
|
|
215
|
-
|
|
216
|
-
return balance.getPastDueConsumptionPeerBalance(this.getKy(options), address)
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/*
|
|
220
|
-
* Chequebook endpoints
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Get the address of the chequebook contract used.
|
|
225
|
-
*
|
|
226
|
-
* **Warning:** The address is returned with 0x prefix unlike all other calls.
|
|
227
|
-
* https://github.com/ethersphere/bee/issues/1443
|
|
228
|
-
*/
|
|
229
|
-
async getChequebookAddress(options?: RequestOptions): Promise<ChequebookAddressResponse> {
|
|
230
|
-
assertRequestOptions(options)
|
|
231
|
-
|
|
232
|
-
return chequebook.getChequebookAddress(this.getKy(options))
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Get the balance of the chequebook
|
|
237
|
-
*/
|
|
238
|
-
async getChequebookBalance(options?: RequestOptions): Promise<ChequebookBalanceResponse> {
|
|
239
|
-
assertRequestOptions(options)
|
|
240
|
-
|
|
241
|
-
return chequebook.getChequebookBalance(this.getKy(options))
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Get last cheques for all peers
|
|
246
|
-
*/
|
|
247
|
-
async getLastCheques(options?: RequestOptions): Promise<LastChequesResponse> {
|
|
248
|
-
assertRequestOptions(options)
|
|
249
|
-
|
|
250
|
-
return chequebook.getLastCheques(this.getKy(options))
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Get last cheques for the peer
|
|
255
|
-
*
|
|
256
|
-
* @param address Swarm address of peer
|
|
257
|
-
*/
|
|
258
|
-
async getLastChequesForPeer(
|
|
259
|
-
address: Address | string,
|
|
260
|
-
options?: RequestOptions,
|
|
261
|
-
): Promise<LastChequesForPeerResponse> {
|
|
262
|
-
assertRequestOptions(options)
|
|
263
|
-
assertAddress(address)
|
|
264
|
-
|
|
265
|
-
return chequebook.getLastChequesForPeer(this.getKy(options), address)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Get last cashout action for the peer
|
|
270
|
-
*
|
|
271
|
-
* @param address Swarm address of peer
|
|
272
|
-
*/
|
|
273
|
-
async getLastCashoutAction(address: Address | string, options?: RequestOptions): Promise<LastCashoutActionResponse> {
|
|
274
|
-
assertRequestOptions(options)
|
|
275
|
-
assertAddress(address)
|
|
276
|
-
|
|
277
|
-
return chequebook.getLastCashoutAction(this.getKy(options), address)
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Cashout the last cheque for the peer
|
|
282
|
-
*
|
|
283
|
-
* @param address Swarm address of peer
|
|
284
|
-
* @param options
|
|
285
|
-
* @param options.gasPrice Gas price for the cashout transaction in WEI
|
|
286
|
-
* @param options.gasLimit Gas limit for the cashout transaction in WEI
|
|
287
|
-
*/
|
|
288
|
-
async cashoutLastCheque(address: string | Address, options?: CashoutOptions): Promise<string> {
|
|
289
|
-
assertCashoutOptions(options)
|
|
290
|
-
assertAddress(address)
|
|
291
|
-
|
|
292
|
-
return chequebook.cashoutLastCheque(this.getKy(options), address, options)
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Deposit tokens from overlay address into chequebook
|
|
297
|
-
*
|
|
298
|
-
* @param amount Amount of tokens to deposit (must be positive integer)
|
|
299
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
300
|
-
* @return string Hash of the transaction
|
|
301
|
-
*/
|
|
302
|
-
async depositTokens(
|
|
303
|
-
amount: number | NumberString,
|
|
304
|
-
gasPrice?: NumberString,
|
|
305
|
-
options?: RequestOptions,
|
|
306
|
-
): Promise<string> {
|
|
307
|
-
assertRequestOptions(options)
|
|
308
|
-
assertNonNegativeInteger(amount)
|
|
309
|
-
|
|
310
|
-
if (gasPrice) {
|
|
311
|
-
assertNonNegativeInteger(gasPrice)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
return chequebook.depositTokens(this.getKy(options), amount, gasPrice)
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Withdraw tokens from the chequebook to the overlay address
|
|
319
|
-
*
|
|
320
|
-
* @param amount Amount of tokens to withdraw (must be positive integer)
|
|
321
|
-
* @param gasPrice Gas Price in WEI for the transaction call
|
|
322
|
-
* @return string Hash of the transaction
|
|
323
|
-
*/
|
|
324
|
-
async withdrawTokens(
|
|
325
|
-
amount: number | NumberString,
|
|
326
|
-
gasPrice?: NumberString,
|
|
327
|
-
options?: RequestOptions,
|
|
328
|
-
): Promise<string> {
|
|
329
|
-
assertRequestOptions(options)
|
|
330
|
-
assertNonNegativeInteger(amount)
|
|
331
|
-
|
|
332
|
-
if (gasPrice) {
|
|
333
|
-
assertNonNegativeInteger(gasPrice)
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
return chequebook.withdrawTokens(this.getKy(options), amount, gasPrice)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
/*
|
|
340
|
-
* Settlements endpoint
|
|
341
|
-
*/
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Get amount of sent and received from settlements with a peer
|
|
345
|
-
*
|
|
346
|
-
* @param address Swarm address of peer
|
|
347
|
-
*/
|
|
348
|
-
async getSettlements(address: Address | string, options?: RequestOptions): Promise<Settlements> {
|
|
349
|
-
assertRequestOptions(options)
|
|
350
|
-
assertAddress(address)
|
|
351
|
-
|
|
352
|
-
return settlements.getSettlements(this.getKy(options), address)
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Get settlements with all known peers and total amount sent or received
|
|
357
|
-
*/
|
|
358
|
-
async getAllSettlements(options?: RequestOptions): Promise<AllSettlements> {
|
|
359
|
-
assertRequestOptions(options)
|
|
360
|
-
|
|
361
|
-
return settlements.getAllSettlements(this.getKy(options))
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Get health of node
|
|
366
|
-
*/
|
|
367
|
-
async getHealth(options?: RequestOptions): Promise<Health> {
|
|
368
|
-
assertRequestOptions(options)
|
|
369
|
-
|
|
370
|
-
return status.getHealth(this.getKy(options))
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/**
|
|
374
|
-
* Connnects to a node and checks if it is a supported Bee version by the bee-js
|
|
375
|
-
*
|
|
376
|
-
* @returns true if the Bee node version is supported
|
|
377
|
-
*/
|
|
378
|
-
async isSupportedVersion(options?: RequestOptions): Promise<boolean> | never {
|
|
379
|
-
assertRequestOptions(options)
|
|
380
|
-
|
|
381
|
-
return status.isSupportedVersion(this.getKy(options))
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Get reserve state
|
|
386
|
-
*/
|
|
387
|
-
async getReserveState(options?: RequestOptions): Promise<ReserveState> {
|
|
388
|
-
assertRequestOptions(options)
|
|
389
|
-
|
|
390
|
-
return states.getReserveState(this.getKy(options))
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
/**
|
|
394
|
-
* Get chain state
|
|
395
|
-
*/
|
|
396
|
-
async getChainState(options?: RequestOptions): Promise<ChainState> {
|
|
397
|
-
assertRequestOptions(options)
|
|
398
|
-
|
|
399
|
-
return states.getChainState(this.getKy(options))
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* Creates new postage batch from the funds that the node has available in its Ethereum account.
|
|
404
|
-
*
|
|
405
|
-
* For better understanding what each parameter means and what are the optimal values please see
|
|
406
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
407
|
-
*
|
|
408
|
-
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
409
|
-
*
|
|
410
|
-
* @param amount Amount that represents the value per chunk, has to be greater or equal zero.
|
|
411
|
-
* @param depth Logarithm of the number of chunks that can be stamped with the batch.
|
|
412
|
-
* @param options Options for creation of postage batch
|
|
413
|
-
* @throws BeeArgumentError when negative amount or depth is specified
|
|
414
|
-
* @throws TypeError if non-integer value is passed to amount or depth
|
|
415
|
-
*
|
|
416
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
417
|
-
* @see [Bee Debug API reference - `POST /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{amount}~1{depth}/post)
|
|
418
|
-
*/
|
|
419
|
-
async createPostageBatch(amount: NumberString, depth: number, options?: PostageBatchOptions): Promise<BatchId> {
|
|
420
|
-
assertRequestOptions(options)
|
|
421
|
-
assertNonNegativeInteger(amount)
|
|
422
|
-
assertNonNegativeInteger(depth)
|
|
423
|
-
|
|
424
|
-
if (depth < STAMPS_DEPTH_MIN) {
|
|
425
|
-
throw new BeeArgumentError(`Depth has to be at least ${STAMPS_DEPTH_MIN}`, depth)
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
if (depth > STAMPS_DEPTH_MAX) {
|
|
429
|
-
throw new BeeArgumentError(`Depth has to be at most ${STAMPS_DEPTH_MAX}`, depth)
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
if (options?.gasPrice) {
|
|
433
|
-
assertNonNegativeInteger(options.gasPrice)
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
if (options?.immutableFlag !== undefined) {
|
|
437
|
-
assertBoolean(options.immutableFlag)
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
return stamps.createPostageBatch(this.getKy(options), amount, depth, options)
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Topup a fresh amount of BZZ to given Postage Batch.
|
|
445
|
-
*
|
|
446
|
-
* For better understanding what each parameter means and what are the optimal values please see
|
|
447
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
448
|
-
*
|
|
449
|
-
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
450
|
-
*
|
|
451
|
-
* @param postageBatchId Batch ID
|
|
452
|
-
* @param amount Amount to be added to the batch
|
|
453
|
-
* @param options Request options
|
|
454
|
-
*
|
|
455
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
456
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
|
|
457
|
-
*/
|
|
458
|
-
async topUpBatch(postageBatchId: BatchId | string, amount: NumberString, options?: RequestOptions): Promise<void> {
|
|
459
|
-
assertRequestOptions(options)
|
|
460
|
-
assertNonNegativeInteger(amount, 'Amount')
|
|
461
|
-
assertBatchId(postageBatchId)
|
|
462
|
-
|
|
463
|
-
await stamps.topUpBatch(this.getKy(options), postageBatchId, amount)
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Dilute given Postage Batch with new depth (that has to be bigger then the original depth), which allows
|
|
468
|
-
* the Postage Batch to be used for more chunks.
|
|
469
|
-
*
|
|
470
|
-
* For better understanding what each parameter means and what are the optimal values please see
|
|
471
|
-
* [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive).
|
|
472
|
-
*
|
|
473
|
-
* **WARNING: THIS CREATES TRANSACTIONS THAT SPENDS MONEY**
|
|
474
|
-
*
|
|
475
|
-
* @param postageBatchId Batch ID
|
|
476
|
-
* @param depth Amount to be added to the batch
|
|
477
|
-
* @param options Request options
|
|
478
|
-
*
|
|
479
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
480
|
-
* @see [Bee Debug API reference - `PATCH /stamps/topup/${id}/${amount}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1topup~1{id}~1{amount}/patch)
|
|
481
|
-
*/
|
|
482
|
-
async diluteBatch(postageBatchId: BatchId | string, depth: number, options?: RequestOptions): Promise<void> {
|
|
483
|
-
assertRequestOptions(options)
|
|
484
|
-
assertNonNegativeInteger(depth, 'Depth')
|
|
485
|
-
assertBatchId(postageBatchId)
|
|
486
|
-
|
|
487
|
-
await stamps.diluteBatch(this.getKy(options), postageBatchId, depth)
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* Return details for specific postage batch.
|
|
492
|
-
*
|
|
493
|
-
* @param postageBatchId Batch ID
|
|
494
|
-
*
|
|
495
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
496
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
|
|
497
|
-
*/
|
|
498
|
-
async getPostageBatch(postageBatchId: BatchId | string, options?: RequestOptions): Promise<DebugPostageBatch> {
|
|
499
|
-
assertRequestOptions(options)
|
|
500
|
-
assertBatchId(postageBatchId)
|
|
501
|
-
|
|
502
|
-
return stamps.getPostageBatch(this.getKy(options), postageBatchId)
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Return detailed information related to buckets for specific postage batch.
|
|
507
|
-
*
|
|
508
|
-
* @param postageBatchId Batch ID
|
|
509
|
-
*
|
|
510
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
511
|
-
* @see [Bee Debug API reference - `GET /stamps/${id}/buckets`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}~1buckets/get)
|
|
512
|
-
*/
|
|
513
|
-
async getPostageBatchBuckets(
|
|
514
|
-
postageBatchId: BatchId | string,
|
|
515
|
-
options?: RequestOptions,
|
|
516
|
-
): Promise<PostageBatchBuckets> {
|
|
517
|
-
assertRequestOptions(options)
|
|
518
|
-
assertBatchId(postageBatchId)
|
|
519
|
-
|
|
520
|
-
return stamps.getPostageBatchBuckets(this.getKy(options), postageBatchId)
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Return all postage batches that has the node available.
|
|
525
|
-
*
|
|
526
|
-
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
|
|
527
|
-
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
528
|
-
*/
|
|
529
|
-
async getAllPostageBatch(options?: RequestOptions): Promise<DebugPostageBatch[]> {
|
|
530
|
-
assertRequestOptions(options)
|
|
531
|
-
|
|
532
|
-
return stamps.getAllPostageBatches(this.getKy(options))
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* Return lists of all current pending transactions that the Bee made
|
|
537
|
-
*/
|
|
538
|
-
async getAllPendingTransactions(options?: RequestOptions): Promise<TransactionInfo[]> {
|
|
539
|
-
assertRequestOptions(options)
|
|
540
|
-
|
|
541
|
-
return transactions.getAllTransactions(this.getKy(options))
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* Return transaction information for specific transaction
|
|
546
|
-
* @param transactionHash
|
|
547
|
-
*/
|
|
548
|
-
async getPendingTransaction(
|
|
549
|
-
transactionHash: TransactionHash | string,
|
|
550
|
-
options?: RequestOptions,
|
|
551
|
-
): Promise<TransactionInfo> {
|
|
552
|
-
assertRequestOptions(options)
|
|
553
|
-
assertTransactionHash(transactionHash)
|
|
554
|
-
|
|
555
|
-
return transactions.getTransaction(this.getKy(options), transactionHash)
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/**
|
|
559
|
-
* Rebroadcast already created transaction.
|
|
560
|
-
* This is mainly needed when your transaction fall off mempool from other reason is not incorporated into block.
|
|
561
|
-
*
|
|
562
|
-
* @param transactionHash
|
|
563
|
-
*/
|
|
564
|
-
async rebroadcastPendingTransaction(
|
|
565
|
-
transactionHash: TransactionHash | string,
|
|
566
|
-
options?: RequestOptions,
|
|
567
|
-
): Promise<TransactionHash> {
|
|
568
|
-
assertRequestOptions(options)
|
|
569
|
-
assertTransactionHash(transactionHash)
|
|
570
|
-
|
|
571
|
-
return transactions.rebroadcastTransaction(this.getKy(options), transactionHash)
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
/**
|
|
575
|
-
* Cancel currently pending transaction
|
|
576
|
-
* @param transactionHash
|
|
577
|
-
* @param gasPrice
|
|
578
|
-
*/
|
|
579
|
-
async cancelPendingTransaction(
|
|
580
|
-
transactionHash: TransactionHash | string,
|
|
581
|
-
gasPrice?: NumberString,
|
|
582
|
-
options?: RequestOptions,
|
|
583
|
-
): Promise<TransactionHash> {
|
|
584
|
-
assertRequestOptions(options)
|
|
585
|
-
assertTransactionHash(transactionHash)
|
|
586
|
-
|
|
587
|
-
if (gasPrice) {
|
|
588
|
-
assertNonNegativeInteger(gasPrice)
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
return transactions.cancelTransaction(this.getKy(options), transactionHash, gasPrice)
|
|
592
|
-
}
|
|
593
|
-
|
|
594
|
-
private getKy(options?: RequestOptions): Ky {
|
|
595
|
-
if (!options) {
|
|
596
|
-
return this.ky
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
return this.ky.extend(options)
|
|
600
|
-
}
|
|
601
|
-
}
|