@ethersphere/bee-js 5.1.1 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/modules/bzz.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
|
|
13
4
|
const headers_1 = require("../utils/headers");
|
|
@@ -21,9 +12,9 @@ const type_1 = require("../utils/type");
|
|
|
21
12
|
const bzzEndpoint = 'bzz';
|
|
22
13
|
function extractFileUploadHeaders(postageBatchId, options) {
|
|
23
14
|
const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
|
|
24
|
-
if (options
|
|
15
|
+
if (options?.size)
|
|
25
16
|
headers['content-length'] = String(options.size);
|
|
26
|
-
if (options
|
|
17
|
+
if (options?.contentType)
|
|
27
18
|
headers['content-type'] = options.contentType;
|
|
28
19
|
return headers;
|
|
29
20
|
}
|
|
@@ -36,96 +27,100 @@ function extractFileUploadHeaders(postageBatchId, options) {
|
|
|
36
27
|
* @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
|
|
37
28
|
* @param options
|
|
38
29
|
*/
|
|
39
|
-
function uploadFile(
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return {
|
|
55
|
-
reference: response.data.reference,
|
|
56
|
-
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
57
|
-
};
|
|
30
|
+
async function uploadFile(kyOptions, data, postageBatchId, name, options) {
|
|
31
|
+
if ((0, stream_1.isReadable)(data) && !options?.contentType) {
|
|
32
|
+
if (!options)
|
|
33
|
+
options = {};
|
|
34
|
+
options.contentType = 'application/octet-stream';
|
|
35
|
+
}
|
|
36
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
37
|
+
method: 'post',
|
|
38
|
+
path: bzzEndpoint,
|
|
39
|
+
body: await (0, data_1.prepareData)(data),
|
|
40
|
+
headers: {
|
|
41
|
+
...extractFileUploadHeaders(postageBatchId, options),
|
|
42
|
+
},
|
|
43
|
+
searchParams: { name },
|
|
44
|
+
responseType: 'json',
|
|
58
45
|
});
|
|
46
|
+
return {
|
|
47
|
+
reference: response.parsedData.reference,
|
|
48
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
49
|
+
};
|
|
59
50
|
}
|
|
60
51
|
exports.uploadFile = uploadFile;
|
|
61
52
|
/**
|
|
62
53
|
* Download single file as a buffer
|
|
63
54
|
*
|
|
64
|
-
* @param
|
|
55
|
+
* @param kyOptions Ky Options for making requests
|
|
65
56
|
* @param hash Bee file or collection hash
|
|
66
57
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
67
58
|
*/
|
|
68
|
-
function downloadFile(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
74
|
-
});
|
|
75
|
-
const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data)) });
|
|
76
|
-
return file;
|
|
59
|
+
async function downloadFile(kyOptions, hash, path = '') {
|
|
60
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
61
|
+
method: 'GET',
|
|
62
|
+
responseType: 'arraybuffer',
|
|
63
|
+
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
77
64
|
});
|
|
65
|
+
const file = {
|
|
66
|
+
...(0, headers_1.readFileHeaders)(response.headers),
|
|
67
|
+
data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData)),
|
|
68
|
+
};
|
|
69
|
+
return file;
|
|
78
70
|
}
|
|
79
71
|
exports.downloadFile = downloadFile;
|
|
80
72
|
/**
|
|
81
73
|
* Download single file as a readable stream
|
|
82
74
|
*
|
|
83
|
-
* @param
|
|
75
|
+
* @param kyOptions Ky Options for making requests
|
|
84
76
|
* @param hash Bee file or collection hash
|
|
85
77
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
86
78
|
*/
|
|
87
|
-
function downloadFileReadable(
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
93
|
-
});
|
|
94
|
-
const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: response.data });
|
|
95
|
-
return file;
|
|
79
|
+
async function downloadFileReadable(kyOptions, hash, path = '') {
|
|
80
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
81
|
+
method: 'GET',
|
|
82
|
+
responseType: 'stream',
|
|
83
|
+
path: `${bzzEndpoint}/${hash}/${path}`,
|
|
96
84
|
});
|
|
85
|
+
const file = {
|
|
86
|
+
...(0, headers_1.readFileHeaders)(response.headers),
|
|
87
|
+
data: response.parsedData,
|
|
88
|
+
};
|
|
89
|
+
return file;
|
|
97
90
|
}
|
|
98
91
|
exports.downloadFileReadable = downloadFileReadable;
|
|
99
92
|
function extractCollectionUploadHeaders(postageBatchId, options) {
|
|
100
93
|
const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
|
|
101
|
-
if (options
|
|
94
|
+
if (options?.indexDocument)
|
|
102
95
|
headers['swarm-index-document'] = options.indexDocument;
|
|
103
|
-
if (options
|
|
96
|
+
if (options?.errorDocument)
|
|
104
97
|
headers['swarm-error-document'] = options.errorDocument;
|
|
105
98
|
return headers;
|
|
106
99
|
}
|
|
107
100
|
/**
|
|
108
101
|
* Upload collection
|
|
109
|
-
* @param
|
|
102
|
+
* @param kyOptions Ky Options for making requests
|
|
110
103
|
* @param collection Collection of Uint8Array buffers to upload
|
|
111
104
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
112
105
|
* @param options
|
|
113
106
|
*/
|
|
114
|
-
function uploadCollection(
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
128
|
-
};
|
|
107
|
+
async function uploadCollection(kyOptions, collection, postageBatchId, options) {
|
|
108
|
+
(0, collection_1.assertCollection)(collection);
|
|
109
|
+
const tarData = (0, tar_1.makeTar)(collection);
|
|
110
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
111
|
+
method: 'post',
|
|
112
|
+
path: bzzEndpoint,
|
|
113
|
+
body: tarData,
|
|
114
|
+
responseType: 'json',
|
|
115
|
+
headers: {
|
|
116
|
+
'content-type': 'application/x-tar',
|
|
117
|
+
'swarm-collection': 'true',
|
|
118
|
+
...extractCollectionUploadHeaders(postageBatchId, options),
|
|
119
|
+
},
|
|
129
120
|
});
|
|
121
|
+
return {
|
|
122
|
+
reference: response.parsedData.reference,
|
|
123
|
+
tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
|
|
124
|
+
};
|
|
130
125
|
}
|
|
131
126
|
exports.uploadCollection = uploadCollection;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.download = exports.upload = void 0;
|
|
13
4
|
const headers_1 = require("../utils/headers");
|
|
@@ -26,33 +17,32 @@ const endpoint = 'chunks';
|
|
|
26
17
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
27
18
|
* @param options Additional options like tag, encryption, pinning
|
|
28
19
|
*/
|
|
29
|
-
function upload(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
20
|
+
async function upload(kyOptions, data, postageBatchId, options) {
|
|
21
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
22
|
+
method: 'post',
|
|
23
|
+
path: `${endpoint}`,
|
|
24
|
+
body: data,
|
|
25
|
+
headers: {
|
|
26
|
+
'content-type': 'application/octet-stream',
|
|
27
|
+
...(0, headers_1.extractUploadHeaders)(postageBatchId, options),
|
|
28
|
+
},
|
|
29
|
+
responseType: 'json',
|
|
39
30
|
});
|
|
31
|
+
return response.parsedData.reference;
|
|
40
32
|
}
|
|
41
33
|
exports.upload = upload;
|
|
42
34
|
/**
|
|
43
35
|
* Download chunk data as a byte array
|
|
44
36
|
*
|
|
45
|
-
* @param
|
|
37
|
+
* @param kyOptions Ky Options for making requests
|
|
46
38
|
* @param hash Bee content reference
|
|
47
39
|
*
|
|
48
40
|
*/
|
|
49
|
-
function download(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
path: `${endpoint}/${hash}`,
|
|
54
|
-
});
|
|
55
|
-
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
|
|
41
|
+
async function download(kyOptions, hash) {
|
|
42
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
43
|
+
responseType: 'arraybuffer',
|
|
44
|
+
path: `${endpoint}/${hash}`,
|
|
56
45
|
});
|
|
46
|
+
return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.parsedData));
|
|
57
47
|
}
|
|
58
48
|
exports.download = download;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getPastDueConsumptionPeerBalance = exports.getPastDueConsumptionBalances = exports.getPeerBalance = exports.getAllBalances = void 0;
|
|
13
4
|
const http_1 = require("../../utils/http");
|
|
@@ -16,62 +7,54 @@ const consumedEndpoint = 'consumed';
|
|
|
16
7
|
/**
|
|
17
8
|
* Get the balances with all known peers including prepaid services
|
|
18
9
|
*
|
|
19
|
-
* @param
|
|
10
|
+
* @param kyOptions Ky Options for making requests
|
|
20
11
|
*/
|
|
21
|
-
function getAllBalances(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
responseType: 'json',
|
|
26
|
-
});
|
|
27
|
-
return response.data;
|
|
12
|
+
async function getAllBalances(kyOptions) {
|
|
13
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
14
|
+
path: balancesEndpoint,
|
|
15
|
+
responseType: 'json',
|
|
28
16
|
});
|
|
17
|
+
return response.parsedData;
|
|
29
18
|
}
|
|
30
19
|
exports.getAllBalances = getAllBalances;
|
|
31
20
|
/**
|
|
32
21
|
* Get the balances with a specific peer including prepaid services
|
|
33
22
|
*
|
|
34
|
-
* @param
|
|
23
|
+
* @param kyOptions Ky Options for making requests
|
|
35
24
|
* @param address Swarm address of peer
|
|
36
25
|
*/
|
|
37
|
-
function getPeerBalance(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
responseType: 'json',
|
|
42
|
-
});
|
|
43
|
-
return response.data;
|
|
26
|
+
async function getPeerBalance(kyOptions, address) {
|
|
27
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
28
|
+
path: `${balancesEndpoint}/${address}`,
|
|
29
|
+
responseType: 'json',
|
|
44
30
|
});
|
|
31
|
+
return response.parsedData;
|
|
45
32
|
}
|
|
46
33
|
exports.getPeerBalance = getPeerBalance;
|
|
47
34
|
/**
|
|
48
35
|
* Get the past due consumption balances with all known peers
|
|
49
36
|
*
|
|
50
|
-
* @param
|
|
37
|
+
* @param kyOptions Ky Options for making requests
|
|
51
38
|
*/
|
|
52
|
-
function getPastDueConsumptionBalances(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
responseType: 'json',
|
|
57
|
-
});
|
|
58
|
-
return response.data;
|
|
39
|
+
async function getPastDueConsumptionBalances(kyOptions) {
|
|
40
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
41
|
+
path: consumedEndpoint,
|
|
42
|
+
responseType: 'json',
|
|
59
43
|
});
|
|
44
|
+
return response.parsedData;
|
|
60
45
|
}
|
|
61
46
|
exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
|
|
62
47
|
/**
|
|
63
48
|
* Get the past due consumption balance with a specific peer
|
|
64
49
|
*
|
|
65
|
-
* @param
|
|
50
|
+
* @param kyOptions Ky Options for making requests
|
|
66
51
|
* @param address Swarm address of peer
|
|
67
52
|
*/
|
|
68
|
-
function getPastDueConsumptionPeerBalance(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
responseType: 'json',
|
|
73
|
-
});
|
|
74
|
-
return response.data;
|
|
53
|
+
async function getPastDueConsumptionPeerBalance(kyOptions, address) {
|
|
54
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
55
|
+
path: `${consumedEndpoint}/${address}`,
|
|
56
|
+
responseType: 'json',
|
|
75
57
|
});
|
|
58
|
+
return response.parsedData;
|
|
76
59
|
}
|
|
77
60
|
exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.withdrawTokens = exports.depositTokens = exports.getLastCheques = exports.getLastChequesForPeer = exports.cashoutLastCheque = exports.getLastCashoutAction = exports.getChequebookBalance = exports.getChequebookAddress = void 0;
|
|
13
4
|
const http_1 = require("../../utils/http");
|
|
@@ -15,153 +6,137 @@ const chequebookEndpoint = 'chequebook';
|
|
|
15
6
|
/**
|
|
16
7
|
* Get the address of the chequebook contract used
|
|
17
8
|
*
|
|
18
|
-
* @param
|
|
9
|
+
* @param kyOptions Ky Options for making requests
|
|
19
10
|
*/
|
|
20
|
-
function getChequebookAddress(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
responseType: 'json',
|
|
25
|
-
});
|
|
26
|
-
return response.data;
|
|
11
|
+
async function getChequebookAddress(kyOptions) {
|
|
12
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
13
|
+
path: chequebookEndpoint + '/address',
|
|
14
|
+
responseType: 'json',
|
|
27
15
|
});
|
|
16
|
+
return response.parsedData;
|
|
28
17
|
}
|
|
29
18
|
exports.getChequebookAddress = getChequebookAddress;
|
|
30
19
|
/**
|
|
31
20
|
* Get the balance of the chequebook
|
|
32
21
|
*
|
|
33
|
-
* @param
|
|
22
|
+
* @param kyOptions Ky Options for making requests
|
|
34
23
|
*/
|
|
35
|
-
function getChequebookBalance(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
responseType: 'json',
|
|
40
|
-
});
|
|
41
|
-
return response.data;
|
|
24
|
+
async function getChequebookBalance(kyOptions) {
|
|
25
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
26
|
+
path: chequebookEndpoint + '/balance',
|
|
27
|
+
responseType: 'json',
|
|
42
28
|
});
|
|
29
|
+
return response.parsedData;
|
|
43
30
|
}
|
|
44
31
|
exports.getChequebookBalance = getChequebookBalance;
|
|
45
32
|
/**
|
|
46
33
|
* Get last cashout action for the peer
|
|
47
34
|
*
|
|
48
|
-
* @param
|
|
35
|
+
* @param kyOptions Ky Options for making requests
|
|
49
36
|
* @param peer Swarm address of peer
|
|
50
37
|
*/
|
|
51
|
-
function getLastCashoutAction(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
responseType: 'json',
|
|
56
|
-
});
|
|
57
|
-
return response.data;
|
|
38
|
+
async function getLastCashoutAction(kyOptions, peer) {
|
|
39
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
40
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
41
|
+
responseType: 'json',
|
|
58
42
|
});
|
|
43
|
+
return response.parsedData;
|
|
59
44
|
}
|
|
60
45
|
exports.getLastCashoutAction = getLastCashoutAction;
|
|
61
46
|
/**
|
|
62
47
|
* Cashout the last cheque for the peer
|
|
63
48
|
*
|
|
64
|
-
* @param
|
|
49
|
+
* @param kyOptions Ky Options for making requests
|
|
65
50
|
* @param peer Swarm address of peer
|
|
66
51
|
* @param options
|
|
67
52
|
*/
|
|
68
|
-
function cashoutLastCheque(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
headers,
|
|
82
|
-
});
|
|
83
|
-
return response.data.transactionHash;
|
|
53
|
+
async function cashoutLastCheque(kyOptions, peer, options) {
|
|
54
|
+
const headers = {};
|
|
55
|
+
if (options?.gasPrice) {
|
|
56
|
+
headers['gas-price'] = options.gasPrice.toString();
|
|
57
|
+
}
|
|
58
|
+
if (options?.gasLimit) {
|
|
59
|
+
headers['gas-limit'] = options.gasLimit.toString();
|
|
60
|
+
}
|
|
61
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
62
|
+
method: 'post',
|
|
63
|
+
path: chequebookEndpoint + `/cashout/${peer}`,
|
|
64
|
+
responseType: 'json',
|
|
65
|
+
headers,
|
|
84
66
|
});
|
|
67
|
+
return response.parsedData.transactionHash;
|
|
85
68
|
}
|
|
86
69
|
exports.cashoutLastCheque = cashoutLastCheque;
|
|
87
70
|
/**
|
|
88
71
|
* Get last cheques for the peer
|
|
89
72
|
*
|
|
90
|
-
* @param
|
|
73
|
+
* @param kyOptions Ky Options for making requests
|
|
91
74
|
* @param peer Swarm address of peer
|
|
92
75
|
*/
|
|
93
|
-
function getLastChequesForPeer(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
responseType: 'json',
|
|
98
|
-
});
|
|
99
|
-
return response.data;
|
|
76
|
+
async function getLastChequesForPeer(kyOptions, peer) {
|
|
77
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
78
|
+
path: chequebookEndpoint + `/cheque/${peer}`,
|
|
79
|
+
responseType: 'json',
|
|
100
80
|
});
|
|
81
|
+
return response.parsedData;
|
|
101
82
|
}
|
|
102
83
|
exports.getLastChequesForPeer = getLastChequesForPeer;
|
|
103
84
|
/**
|
|
104
85
|
* Get last cheques for all peers
|
|
105
86
|
*
|
|
106
|
-
* @param
|
|
87
|
+
* @param kyOptions Ky Options for making requests
|
|
107
88
|
*/
|
|
108
|
-
function getLastCheques(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
responseType: 'json',
|
|
113
|
-
});
|
|
114
|
-
return response.data;
|
|
89
|
+
async function getLastCheques(kyOptions) {
|
|
90
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
91
|
+
path: chequebookEndpoint + '/cheque',
|
|
92
|
+
responseType: 'json',
|
|
115
93
|
});
|
|
94
|
+
return response.parsedData;
|
|
116
95
|
}
|
|
117
96
|
exports.getLastCheques = getLastCheques;
|
|
118
97
|
/**
|
|
119
98
|
* Deposit tokens from overlay address into chequebook
|
|
120
99
|
*
|
|
121
|
-
* @param
|
|
100
|
+
* @param kyOptions Ky Options for making requests
|
|
122
101
|
* @param amount Amount of tokens to deposit
|
|
123
102
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
124
103
|
* @return string Hash of the transaction
|
|
125
104
|
*/
|
|
126
|
-
function depositTokens(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
headers,
|
|
138
|
-
});
|
|
139
|
-
return response.data.transactionHash;
|
|
105
|
+
async function depositTokens(kyOptions, amount, gasPrice) {
|
|
106
|
+
const headers = {};
|
|
107
|
+
if (gasPrice) {
|
|
108
|
+
headers['gas-price'] = gasPrice.toString();
|
|
109
|
+
}
|
|
110
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
111
|
+
method: 'post',
|
|
112
|
+
path: chequebookEndpoint + '/deposit',
|
|
113
|
+
responseType: 'json',
|
|
114
|
+
searchParams: { amount: amount.toString(10) },
|
|
115
|
+
headers,
|
|
140
116
|
});
|
|
117
|
+
return response.parsedData.transactionHash;
|
|
141
118
|
}
|
|
142
119
|
exports.depositTokens = depositTokens;
|
|
143
120
|
/**
|
|
144
121
|
* Withdraw tokens from the chequebook to the overlay address
|
|
145
122
|
*
|
|
146
|
-
* @param
|
|
123
|
+
* @param kyOptions Ky Options for making requests
|
|
147
124
|
* @param amount Amount of tokens to withdraw
|
|
148
125
|
* @param gasPrice Gas Price in WEI for the transaction call
|
|
149
126
|
* @return string Hash of the transaction
|
|
150
127
|
*/
|
|
151
|
-
function withdrawTokens(
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
headers,
|
|
163
|
-
});
|
|
164
|
-
return response.data.transactionHash;
|
|
128
|
+
async function withdrawTokens(kyOptions, amount, gasPrice) {
|
|
129
|
+
const headers = {};
|
|
130
|
+
if (gasPrice) {
|
|
131
|
+
headers['gas-price'] = gasPrice.toString();
|
|
132
|
+
}
|
|
133
|
+
const response = await (0, http_1.http)(kyOptions, {
|
|
134
|
+
method: 'post',
|
|
135
|
+
path: chequebookEndpoint + '/withdraw',
|
|
136
|
+
responseType: 'json',
|
|
137
|
+
searchParams: { amount: amount.toString(10) },
|
|
138
|
+
headers,
|
|
165
139
|
});
|
|
140
|
+
return response.parsedData.transactionHash;
|
|
166
141
|
}
|
|
167
142
|
exports.withdrawTokens = withdrawTokens;
|