@ethersphere/bee-js 12.3.2-upcoming.116 → 13.0.0-upcoming.gc013bdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/balance.js +24 -0
- package/dist/cjs/api/batches.js +26 -0
- package/dist/cjs/{modules → api}/bytes.js +4 -29
- package/dist/cjs/{modules → api}/bzz.js +6 -34
- package/dist/cjs/{modules/debug → api}/chequebook.js +48 -87
- package/dist/cjs/api/chunk.js +43 -0
- package/dist/cjs/api/connectivity.js +86 -0
- package/dist/cjs/api/consumed.js +24 -0
- package/dist/cjs/{modules → api}/envelope.js +3 -2
- package/dist/cjs/api/feed.js +55 -0
- package/dist/cjs/api/grantee.js +62 -0
- package/dist/cjs/{modules/pinning.js → api/pin.js} +13 -34
- package/dist/cjs/api/pss.js +19 -0
- package/dist/cjs/api/redistributionstate.js +17 -0
- package/dist/cjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/cjs/api/soc.js +34 -0
- package/dist/cjs/{modules/debug → api}/stake.js +15 -43
- package/dist/cjs/{modules/debug/stamps.js → api/stamp.js} +41 -57
- package/dist/cjs/api/status.js +67 -0
- package/dist/cjs/{modules → api}/stewardship.js +1 -6
- package/dist/cjs/api/tag.js +51 -0
- package/dist/cjs/{modules/debug/transactions.js → api/transaction.js} +10 -31
- package/dist/cjs/{modules/debug/states.js → api/wallet.js} +4 -36
- package/dist/cjs/bee.js +115 -1978
- package/dist/cjs/chunk/soc.js +23 -65
- package/dist/cjs/feed/identifier.js +3 -4
- package/dist/cjs/feed/index.js +20 -22
- package/dist/cjs/feed/retrievable.js +3 -3
- package/dist/cjs/index.js +18 -8
- package/dist/cjs/manifest/manifest.js +99 -335
- package/dist/cjs/modules/balance.js +86 -0
- package/dist/cjs/modules/cheque.js +92 -0
- package/dist/cjs/modules/chequebook.js +90 -0
- package/dist/cjs/modules/chunk.js +87 -53
- package/dist/cjs/modules/collection.js +145 -0
- package/dist/cjs/modules/connectivity.js +141 -0
- package/dist/cjs/modules/context.js +2 -0
- package/dist/cjs/modules/data.js +119 -0
- package/dist/cjs/modules/feed.js +94 -70
- package/dist/cjs/modules/file.js +113 -0
- package/dist/cjs/modules/grantee.js +86 -55
- package/dist/cjs/modules/messaging.js +248 -0
- package/dist/cjs/modules/pin.js +100 -0
- package/dist/cjs/modules/settlement.js +67 -0
- package/dist/cjs/modules/soc.js +39 -36
- package/dist/cjs/modules/stake.js +110 -0
- package/dist/cjs/modules/stamp.js +199 -0
- package/dist/cjs/modules/status.js +128 -20
- package/dist/cjs/modules/storage.js +191 -0
- package/dist/cjs/modules/tag.js +97 -71
- package/dist/cjs/modules/transaction.js +92 -0
- package/dist/cjs/modules/wallet.js +82 -0
- package/dist/cjs/types/schema/chequebook.js +5 -5
- package/dist/cjs/types/schema/connectivity.js +5 -5
- package/dist/cjs/types/schema/envelope.js +5 -5
- package/dist/cjs/types/schema/grantee.js +4 -4
- package/dist/cjs/types/schema/stake.js +2 -2
- package/dist/cjs/types/schema/stamps.js +4 -4
- package/dist/cjs/types/schema/states.js +2 -2
- package/dist/cjs/types/schema/transactions.js +3 -3
- package/dist/cjs/types/schema/upload.js +2 -2
- package/dist/cjs/utils/chunk-stream.browser.js +24 -16
- package/dist/cjs/utils/chunk-stream.js +17 -9
- package/dist/cjs/utils/constants.js +3 -3
- package/dist/cjs/utils/expose.js +4 -4
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/pss.js +2 -2
- package/dist/cjs/utils/resource-locator.js +2 -2
- package/dist/cjs/utils/schema.js +4 -4
- package/dist/cjs/utils/stamps.js +15 -130
- package/dist/index.browser.min.js +2 -1
- package/dist/index.browser.min.js.LICENSE.txt +3 -0
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/api/balance.js +20 -0
- package/dist/mjs/api/batches.js +22 -0
- package/dist/mjs/{modules → api}/bytes.js +2 -27
- package/dist/mjs/{modules → api}/bzz.js +2 -30
- package/dist/mjs/{modules/debug → api}/chequebook.js +50 -89
- package/dist/mjs/api/chunk.js +37 -0
- package/dist/mjs/api/connectivity.js +76 -0
- package/dist/mjs/api/consumed.js +20 -0
- package/dist/mjs/{modules → api}/envelope.js +3 -2
- package/dist/mjs/api/feed.js +52 -0
- package/dist/mjs/api/grantee.js +59 -0
- package/dist/mjs/{modules/pinning.js → api/pin.js} +14 -35
- package/dist/mjs/api/pss.js +18 -0
- package/dist/mjs/api/redistributionstate.js +14 -0
- package/dist/mjs/{modules/debug/settlements.js → api/settlement.js} +3 -11
- package/dist/mjs/api/soc.js +31 -0
- package/dist/mjs/{modules/debug → api}/stake.js +14 -41
- package/dist/mjs/{modules/debug/stamps.js → api/stamp.js} +37 -51
- package/dist/mjs/api/status.js +59 -0
- package/dist/mjs/{modules → api}/stewardship.js +1 -6
- package/dist/mjs/api/tag.js +49 -0
- package/dist/mjs/api/transaction.js +41 -0
- package/dist/mjs/api/wallet.js +38 -0
- package/dist/mjs/bee.js +115 -1965
- package/dist/mjs/chunk/soc.js +13 -51
- package/dist/mjs/feed/identifier.js +2 -3
- package/dist/mjs/feed/index.js +9 -11
- package/dist/mjs/feed/retrievable.js +2 -2
- package/dist/mjs/index.js +2 -5
- package/dist/mjs/manifest/manifest.js +97 -341
- package/dist/mjs/modules/balance.js +49 -0
- package/dist/mjs/modules/cheque.js +55 -0
- package/dist/mjs/modules/chequebook.js +65 -0
- package/dist/mjs/modules/chunk.js +52 -49
- package/dist/mjs/modules/collection.js +108 -0
- package/dist/mjs/modules/connectivity.js +102 -0
- package/dist/mjs/modules/context.js +1 -0
- package/dist/mjs/modules/data.js +82 -0
- package/dist/mjs/modules/feed.js +89 -67
- package/dist/mjs/modules/file.js +78 -0
- package/dist/mjs/modules/grantee.js +52 -55
- package/dist/mjs/modules/messaging.js +213 -0
- package/dist/mjs/modules/pin.js +63 -0
- package/dist/mjs/modules/settlement.js +30 -0
- package/dist/mjs/modules/soc.js +36 -34
- package/dist/mjs/modules/stake.js +76 -0
- package/dist/mjs/modules/stamp.js +170 -0
- package/dist/mjs/modules/status.js +98 -18
- package/dist/mjs/modules/storage.js +185 -0
- package/dist/mjs/modules/tag.js +61 -68
- package/dist/mjs/modules/transaction.js +58 -0
- package/dist/mjs/modules/wallet.js +45 -0
- package/dist/mjs/types/schema/chequebook.js +1 -1
- package/dist/mjs/types/schema/connectivity.js +1 -1
- package/dist/mjs/types/schema/envelope.js +5 -5
- package/dist/mjs/types/schema/grantee.js +1 -1
- package/dist/mjs/types/schema/stake.js +1 -1
- package/dist/mjs/types/schema/stamps.js +1 -1
- package/dist/mjs/types/schema/states.js +1 -1
- package/dist/mjs/types/schema/transactions.js +1 -1
- package/dist/mjs/types/schema/upload.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +28 -18
- package/dist/mjs/utils/chunk-stream.js +21 -11
- package/dist/mjs/utils/constants.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +1 -1
- package/dist/mjs/utils/pss.js +1 -1
- package/dist/mjs/utils/resource-locator.js +1 -1
- package/dist/mjs/utils/schema.js +1 -1
- package/dist/mjs/utils/stamps.js +5 -99
- package/dist/types/api/balance.d.ts +7 -0
- package/dist/types/api/batches.d.ts +7 -0
- package/dist/types/api/bytes.d.ts +11 -0
- package/dist/types/api/bzz.d.ts +12 -0
- package/dist/types/api/chequebook.d.ts +21 -0
- package/dist/types/api/chunk.d.ts +7 -0
- package/dist/types/api/connectivity.d.ts +22 -0
- package/dist/types/api/consumed.d.ts +7 -0
- package/dist/types/{modules → api}/envelope.d.ts +1 -1
- package/dist/types/api/feed.d.ts +40 -0
- package/dist/types/api/grantee.d.ts +11 -0
- package/dist/types/api/pin.d.ts +10 -0
- package/dist/types/api/pss.d.ts +6 -0
- package/dist/types/api/redistributionstate.d.ts +5 -0
- package/dist/types/api/settlement.d.ts +7 -0
- package/dist/types/api/soc.d.ts +6 -0
- package/dist/types/api/stake.d.ts +11 -0
- package/dist/types/api/stamp.d.ts +12 -0
- package/dist/types/api/status.d.ts +11 -0
- package/dist/types/api/stewardship.d.ts +7 -0
- package/dist/types/api/tag.d.ts +12 -0
- package/dist/types/api/transaction.d.ts +9 -0
- package/dist/types/api/wallet.d.ts +9 -0
- package/dist/types/bee.d.ts +71 -1199
- package/dist/types/chunk/soc.d.ts +3 -48
- package/dist/types/feed/identifier.d.ts +1 -1
- package/dist/types/feed/index.d.ts +2 -4
- package/dist/types/feed/retrievable.d.ts +1 -1
- package/dist/types/index.d.ts +17 -20
- package/dist/types/manifest/manifest.d.ts +25 -34
- package/dist/types/modules/balance.d.ts +38 -0
- package/dist/types/modules/cheque.d.ts +40 -0
- package/dist/types/modules/chequebook.d.ts +41 -0
- package/dist/types/modules/chunk.d.ts +30 -20
- package/dist/types/modules/collection.d.ts +77 -0
- package/dist/types/modules/connectivity.d.ts +74 -0
- package/dist/types/modules/context.d.ts +24 -0
- package/dist/types/modules/data.d.ts +55 -0
- package/dist/types/modules/feed.d.ts +47 -49
- package/dist/types/modules/file.d.ts +43 -0
- package/dist/types/modules/grantee.d.ts +40 -8
- package/dist/types/modules/messaging.d.ts +79 -0
- package/dist/types/modules/pin.d.ts +47 -0
- package/dist/types/modules/settlement.d.ts +25 -0
- package/dist/types/modules/soc.d.ts +23 -11
- package/dist/types/modules/stake.d.ts +55 -0
- package/dist/types/modules/stamp.d.ts +96 -0
- package/dist/types/modules/status.d.ts +66 -5
- package/dist/types/modules/storage.d.ts +107 -0
- package/dist/types/modules/tag.d.ts +44 -33
- package/dist/types/modules/transaction.d.ts +42 -0
- package/dist/types/modules/wallet.d.ts +35 -0
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +3 -12
- package/dist/types/types/schema/chequebook.d.ts +1 -1
- package/dist/types/types/schema/connectivity.d.ts +1 -1
- package/dist/types/types/schema/grantee.d.ts +1 -1
- package/dist/types/types/schema/stake.d.ts +1 -1
- package/dist/types/types/schema/stamps.d.ts +1 -1
- package/dist/types/types/schema/states.d.ts +1 -1
- package/dist/types/types/schema/transactions.d.ts +1 -1
- package/dist/types/types/schema/upload.d.ts +1 -1
- package/dist/types/utils/chunk-stream.browser.d.ts +1 -1
- package/dist/types/utils/chunk-stream.d.ts +2 -2
- package/dist/types/utils/constants.d.ts +1 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +1 -1
- package/dist/types/utils/pss.d.ts +1 -1
- package/dist/types/utils/resource-locator.d.ts +1 -1
- package/dist/types/utils/schema.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +2 -27
- package/dist/types/utils/tar-uploader.browser.d.ts +1 -1
- package/dist/types/utils/tar-uploader.d.ts +1 -1
- package/package.json +4 -2
- package/dist/cjs/chunk/bmt.js +0 -37
- package/dist/cjs/chunk/cac.js +0 -43
- package/dist/cjs/modules/debug/balance.js +0 -60
- package/dist/cjs/modules/debug/connectivity.js +0 -54
- package/dist/cjs/modules/debug/status.js +0 -104
- package/dist/cjs/modules/gsoc.js +0 -23
- package/dist/cjs/modules/pss.js +0 -48
- package/dist/cjs/stamper/stamper.js +0 -44
- package/dist/cjs/utils/bytes.js +0 -116
- package/dist/cjs/utils/cid.js +0 -37
- package/dist/cjs/utils/redundancy.js +0 -133
- package/dist/cjs/utils/typed-bytes.js +0 -186
- package/dist/mjs/chunk/bmt.js +0 -34
- package/dist/mjs/chunk/cac.js +0 -34
- package/dist/mjs/modules/debug/balance.js +0 -54
- package/dist/mjs/modules/debug/connectivity.js +0 -46
- package/dist/mjs/modules/debug/states.js +0 -68
- package/dist/mjs/modules/debug/status.js +0 -99
- package/dist/mjs/modules/debug/transactions.js +0 -62
- package/dist/mjs/modules/gsoc.js +0 -16
- package/dist/mjs/modules/pss.js +0 -43
- package/dist/mjs/stamper/stamper.js +0 -40
- package/dist/mjs/utils/bytes.js +0 -102
- package/dist/mjs/utils/cid.js +0 -32
- package/dist/mjs/utils/redundancy.js +0 -98
- package/dist/mjs/utils/typed-bytes.js +0 -167
- package/dist/types/chunk/bmt.d.ts +0 -16
- package/dist/types/chunk/cac.d.ts +0 -40
- package/dist/types/modules/bytes.d.ts +0 -35
- package/dist/types/modules/bzz.d.ts +0 -40
- package/dist/types/modules/debug/balance.d.ts +0 -28
- package/dist/types/modules/debug/chequebook.d.ts +0 -60
- package/dist/types/modules/debug/connectivity.d.ts +0 -9
- package/dist/types/modules/debug/settlements.d.ts +0 -15
- package/dist/types/modules/debug/stake.d.ts +0 -30
- package/dist/types/modules/debug/stamps.d.ts +0 -11
- package/dist/types/modules/debug/states.d.ts +0 -23
- package/dist/types/modules/debug/status.d.ts +0 -46
- package/dist/types/modules/debug/transactions.d.ts +0 -30
- package/dist/types/modules/gsoc.d.ts +0 -6
- package/dist/types/modules/pinning.d.ts +0 -30
- package/dist/types/modules/pss.d.ts +0 -22
- package/dist/types/modules/stewardship.d.ts +0 -10
- package/dist/types/stamper/stamper.d.ts +0 -15
- package/dist/types/utils/bytes.d.ts +0 -19
- package/dist/types/utils/cid.d.ts +0 -10
- package/dist/types/utils/redundancy.d.ts +0 -21
- package/dist/types/utils/typed-bytes.d.ts +0 -69
- /package/dist/cjs/{modules → api}/rchash.js +0 -0
- /package/dist/mjs/{modules → api}/rchash.js +0 -0
- /package/dist/types/{modules → api}/rchash.d.ts +0 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.Messaging = void 0;
|
|
40
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
41
|
+
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
42
|
+
const swarm_core_1 = require("swarm-core");
|
|
43
|
+
const pssApi = __importStar(require("../api/pss"));
|
|
44
|
+
const soc_1 = require("../chunk/soc");
|
|
45
|
+
const data_1 = require("../utils/data");
|
|
46
|
+
const error_1 = require("../utils/error");
|
|
47
|
+
const schema_1 = require("../utils/schema");
|
|
48
|
+
const type_1 = require("../utils/type");
|
|
49
|
+
const PSS_ENDPOINT = 'pss';
|
|
50
|
+
const GSOC_ENDPOINT = 'gsoc';
|
|
51
|
+
/**
|
|
52
|
+
* Messaging protocols — PSS (Postal Service for Swarm) and GSOC. Method names keep
|
|
53
|
+
* their `pss`/`gsoc` prefixes to distinguish the two protocols within the namespace.
|
|
54
|
+
*
|
|
55
|
+
* Accessed as `bee.messaging`.
|
|
56
|
+
*/
|
|
57
|
+
class Messaging {
|
|
58
|
+
constructor(context) {
|
|
59
|
+
this.context = context;
|
|
60
|
+
this.cancelled = new WeakSet();
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sends data to a recipient or target with the Postal Service for Swarm.
|
|
64
|
+
*
|
|
65
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
66
|
+
*
|
|
67
|
+
* @param postageBatchId Postage BatchId that will be assigned to the sent message.
|
|
68
|
+
* @param topic Topic name
|
|
69
|
+
* @param target Target message address prefix
|
|
70
|
+
* @param data Message to send
|
|
71
|
+
* @param recipient Optional recipient public key
|
|
72
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
73
|
+
*/
|
|
74
|
+
async pssSend(postageBatchId, topic, target, data, recipient, requestOptions) {
|
|
75
|
+
const batchId = new swarm_core_1.BatchId(postageBatchId);
|
|
76
|
+
(0, type_1.assertData)(data);
|
|
77
|
+
const recipientKey = recipient ? new swarm_core_1.PublicKey(recipient) : undefined;
|
|
78
|
+
await pssApi.send(this.context.getRequestOptionsForCall(requestOptions), batchId, topic, target, data, recipientKey);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Subscribes to messages for the given topic with the Postal Service for Swarm.
|
|
82
|
+
*
|
|
83
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
84
|
+
*
|
|
85
|
+
* @param topic Topic name
|
|
86
|
+
* @param handler Message handler interface
|
|
87
|
+
*/
|
|
88
|
+
pssSubscribe(topic, handler) {
|
|
89
|
+
handler = schema_1.PssMessageHandlerSchema.parse(handler);
|
|
90
|
+
const ws = this.openWebSocket(`${PSS_ENDPOINT}/subscribe/${topic.toHex()}`);
|
|
91
|
+
const cancel = this.makeCancel(ws);
|
|
92
|
+
const subscription = { topic, cancel };
|
|
93
|
+
ws.onmessage = async (event) => {
|
|
94
|
+
const data = await (0, data_1.prepareWebsocketData)(event.data);
|
|
95
|
+
if (data.length) {
|
|
96
|
+
handler.onMessage(new swarm_core_1.Bytes(data), subscription);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
ws.onerror = event => {
|
|
100
|
+
if (!this.isCancelled(ws)) {
|
|
101
|
+
handler.onError(new error_1.BeeError(event.message), subscription);
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
ws.onclose = () => {
|
|
105
|
+
handler.onClose(subscription);
|
|
106
|
+
};
|
|
107
|
+
return subscription;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Receives a single message using the Postal Service for Swarm.
|
|
111
|
+
*
|
|
112
|
+
* **Warning! Only full nodes can accept PSS messages.**
|
|
113
|
+
*
|
|
114
|
+
* @param topic Topic name
|
|
115
|
+
* @param timeoutMsec Timeout in milliseconds
|
|
116
|
+
*/
|
|
117
|
+
async pssReceive(topic, timeoutMsec = 0) {
|
|
118
|
+
if (typeof timeoutMsec !== 'number') {
|
|
119
|
+
throw new TypeError('timeoutMsc parameter has to be a number!');
|
|
120
|
+
}
|
|
121
|
+
return new Promise((resolve, reject) => {
|
|
122
|
+
let timeout;
|
|
123
|
+
const subscription = this.pssSubscribe(topic, {
|
|
124
|
+
onError: error => {
|
|
125
|
+
clearTimeout(timeout);
|
|
126
|
+
subscription.cancel();
|
|
127
|
+
reject(error.message);
|
|
128
|
+
},
|
|
129
|
+
onMessage: message => {
|
|
130
|
+
clearTimeout(timeout);
|
|
131
|
+
subscription.cancel();
|
|
132
|
+
resolve(message);
|
|
133
|
+
},
|
|
134
|
+
onClose: () => {
|
|
135
|
+
clearTimeout(timeout);
|
|
136
|
+
subscription.cancel();
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
if (timeoutMsec > 0) {
|
|
140
|
+
timeout = setTimeout(() => {
|
|
141
|
+
subscription.cancel();
|
|
142
|
+
reject(new error_1.BeeError('pssReceive timeout'));
|
|
143
|
+
}, timeoutMsec);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Mines the signer (a private key) to be used to send GSOC messages to the specific target overlay address.
|
|
149
|
+
*
|
|
150
|
+
* @param targetOverlay
|
|
151
|
+
* @param identifier
|
|
152
|
+
* @param proximity
|
|
153
|
+
*/
|
|
154
|
+
gsocMine(targetOverlay, identifier, proximity = 12) {
|
|
155
|
+
const overlay = new swarm_core_1.PeerAddress(targetOverlay);
|
|
156
|
+
const id = new swarm_core_1.Identifier(identifier);
|
|
157
|
+
const start = 0xb33n;
|
|
158
|
+
for (let i = 0n; i < 0xffffn; i++) {
|
|
159
|
+
const signer = new swarm_core_1.PrivateKey((0, swarm_core_1.numberToUint256)(start + i, 'BE'));
|
|
160
|
+
const socAddress = (0, soc_1.makeSOCAddress)(id, signer.publicKey().address());
|
|
161
|
+
// TODO: test the significance of the hardcoded 256
|
|
162
|
+
const actualProximity = 256 - cafe_utility_1.Binary.proximity(socAddress.toUint8Array(), overlay.toUint8Array());
|
|
163
|
+
if (actualProximity <= 256 - proximity) {
|
|
164
|
+
return signer;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw Error('Could not mine a valid signer');
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Sends a GSOC message with the specified signer and identifier.
|
|
171
|
+
*
|
|
172
|
+
* **Warning! Only full nodes can accept GSOC messages.**
|
|
173
|
+
*
|
|
174
|
+
* @param postageBatchId
|
|
175
|
+
* @param signer
|
|
176
|
+
* @param identifier
|
|
177
|
+
* @param data
|
|
178
|
+
* @param options
|
|
179
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
180
|
+
*/
|
|
181
|
+
async gsocSend(postageBatchId, signer, identifier, data, options, requestOptions) {
|
|
182
|
+
const batchId = new swarm_core_1.BatchId(postageBatchId);
|
|
183
|
+
const key = new swarm_core_1.PrivateKey(signer);
|
|
184
|
+
const id = new swarm_core_1.Identifier(identifier);
|
|
185
|
+
const cac = (0, swarm_core_1.makeContentAddressedChunk)(data);
|
|
186
|
+
const soc = cac.toSingleOwnerChunk(id, key);
|
|
187
|
+
return (0, soc_1.uploadSingleOwnerChunk)(this.context.getRequestOptionsForCall(requestOptions), soc, batchId, options);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Subscribes to GSOC messages for the specified owner (of the signer) and identifier.
|
|
191
|
+
*
|
|
192
|
+
* **Warning! Only full nodes can accept GSOC messages.**
|
|
193
|
+
*
|
|
194
|
+
* @param address
|
|
195
|
+
* @param identifier
|
|
196
|
+
* @param handler
|
|
197
|
+
*/
|
|
198
|
+
gsocSubscribe(address, identifier, handler) {
|
|
199
|
+
const ethAddress = new swarm_core_1.EthAddress(address);
|
|
200
|
+
const id = new swarm_core_1.Identifier(identifier);
|
|
201
|
+
handler = schema_1.GsocMessageHandlerSchema.parse(handler);
|
|
202
|
+
const socAddress = (0, soc_1.makeSOCAddress)(id, ethAddress);
|
|
203
|
+
const ws = this.openWebSocket(`${GSOC_ENDPOINT}/subscribe/${socAddress.toHex()}`);
|
|
204
|
+
const cancel = this.makeCancel(ws);
|
|
205
|
+
const subscription = { address: ethAddress, cancel };
|
|
206
|
+
ws.onmessage = async (event) => {
|
|
207
|
+
const data = await (0, data_1.prepareWebsocketData)(event.data);
|
|
208
|
+
if (data.length) {
|
|
209
|
+
handler.onMessage(new swarm_core_1.Bytes(data), subscription);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
ws.onerror = event => {
|
|
213
|
+
if (!this.isCancelled(ws)) {
|
|
214
|
+
handler.onError(new error_1.BeeError(event.message), subscription);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
ws.onclose = () => {
|
|
218
|
+
handler.onClose(subscription);
|
|
219
|
+
};
|
|
220
|
+
return subscription;
|
|
221
|
+
}
|
|
222
|
+
openWebSocket(path) {
|
|
223
|
+
const wsUrl = this.context.url.replace(/^http/i, 'ws');
|
|
224
|
+
if (cafe_utility_1.System.whereAmI() === 'browser') {
|
|
225
|
+
return new isomorphic_ws_1.default(`${wsUrl}/${path}`);
|
|
226
|
+
}
|
|
227
|
+
return new isomorphic_ws_1.default(`${wsUrl}/${path}`, {
|
|
228
|
+
headers: this.context.getRequestOptionsForCall().headers,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
makeCancel(ws) {
|
|
232
|
+
return () => {
|
|
233
|
+
if (!this.cancelled.has(ws)) {
|
|
234
|
+
this.cancelled.add(ws);
|
|
235
|
+
if (ws.terminate) {
|
|
236
|
+
ws.terminate();
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
ws.close();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
isCancelled(ws) {
|
|
245
|
+
return this.cancelled.has(ws);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
exports.Messaging = Messaging;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Pin = void 0;
|
|
37
|
+
const swarm_core_1 = require("swarm-core");
|
|
38
|
+
const pinApi = __importStar(require("../api/pin"));
|
|
39
|
+
const stewardshipApi = __importStar(require("../api/stewardship"));
|
|
40
|
+
/**
|
|
41
|
+
* Local pinning operations.
|
|
42
|
+
*
|
|
43
|
+
* Accessed as `bee.pin`.
|
|
44
|
+
*/
|
|
45
|
+
class Pin {
|
|
46
|
+
constructor(context) {
|
|
47
|
+
this.context = context;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pins local data with the given reference.
|
|
51
|
+
*
|
|
52
|
+
* @param reference Data reference
|
|
53
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
54
|
+
*/
|
|
55
|
+
async add(reference, requestOptions) {
|
|
56
|
+
const ref = new swarm_core_1.Reference(reference);
|
|
57
|
+
await pinApi.pin(this.context.getRequestOptionsForCall(requestOptions), ref);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Unpins local data with the given reference.
|
|
61
|
+
*
|
|
62
|
+
* @param reference Data reference
|
|
63
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
64
|
+
*/
|
|
65
|
+
async remove(reference, requestOptions) {
|
|
66
|
+
const ref = new swarm_core_1.Reference(reference);
|
|
67
|
+
await pinApi.unpin(this.context.getRequestOptionsForCall(requestOptions), ref);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the list of all locally pinned references.
|
|
71
|
+
*
|
|
72
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
73
|
+
*/
|
|
74
|
+
async getAll(requestOptions) {
|
|
75
|
+
return pinApi.getAllPins(this.context.getRequestOptionsForCall(requestOptions));
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Gets the pinning status of the chunk with the given reference.
|
|
79
|
+
*
|
|
80
|
+
* @param reference Data reference
|
|
81
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
82
|
+
*/
|
|
83
|
+
async get(reference, requestOptions) {
|
|
84
|
+
const ref = new swarm_core_1.Reference(reference);
|
|
85
|
+
return pinApi.getPin(this.context.getRequestOptionsForCall(requestOptions), ref);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Instructs the Bee node to reupload locally pinned data into the network.
|
|
89
|
+
*
|
|
90
|
+
* @param postageBatchId Postage Batch ID that will be used to re-upload the data.
|
|
91
|
+
* @param reference Data reference to be re-uploaded.
|
|
92
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
93
|
+
*/
|
|
94
|
+
async reuploadData(postageBatchId, reference, requestOptions) {
|
|
95
|
+
const batchId = new swarm_core_1.BatchId(postageBatchId);
|
|
96
|
+
const ref = new swarm_core_1.Reference(reference);
|
|
97
|
+
await stewardshipApi.reupload(this.context.getRequestOptionsForCall(requestOptions), batchId, ref);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.Pin = Pin;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Settlement = void 0;
|
|
37
|
+
const swarm_core_1 = require("swarm-core");
|
|
38
|
+
const api = __importStar(require("../api/settlement"));
|
|
39
|
+
/**
|
|
40
|
+
* Settlement operations. Related to the bandwidth incentives and the chequebook.
|
|
41
|
+
*
|
|
42
|
+
* Accessed as `bee.settlement`.
|
|
43
|
+
*/
|
|
44
|
+
class Settlement {
|
|
45
|
+
constructor(context) {
|
|
46
|
+
this.context = context;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the amount of sent and received micropayments from settlements with a peer.
|
|
50
|
+
*
|
|
51
|
+
* @param address Swarm address of peer
|
|
52
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
53
|
+
*/
|
|
54
|
+
async get(address, requestOptions) {
|
|
55
|
+
const peer = new swarm_core_1.PeerAddress(address);
|
|
56
|
+
return api.getSettlements(this.context.getRequestOptionsForCall(requestOptions), peer);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets settlements with all known peers and total amount sent or received.
|
|
60
|
+
*
|
|
61
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
62
|
+
*/
|
|
63
|
+
async getAll(requestOptions) {
|
|
64
|
+
return api.getAllSettlements(this.context.getRequestOptionsForCall(requestOptions));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Settlement = Settlement;
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const headers_1 = require("../utils/headers");
|
|
7
|
-
const http_1 = require("../utils/http");
|
|
8
|
-
const type_1 = require("../utils/type");
|
|
9
|
-
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
10
|
-
const socEndpoint = 'soc';
|
|
3
|
+
exports.Soc = void 0;
|
|
4
|
+
const swarm_core_1 = require("swarm-core");
|
|
5
|
+
const soc_1 = require("../chunk/soc");
|
|
11
6
|
/**
|
|
12
|
-
*
|
|
7
|
+
* Single owner chunk (SOC) reader/writer operations.
|
|
13
8
|
*
|
|
14
|
-
*
|
|
15
|
-
* @param owner Owner's ethereum address in hex
|
|
16
|
-
* @param identifier Arbitrary identifier in hex
|
|
17
|
-
* @param signature Signature in hex
|
|
18
|
-
* @param data Content addressed chunk data to be uploaded
|
|
19
|
-
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
20
|
-
* @param options Additional options like tag, encryption, pinning
|
|
9
|
+
* Accessed as `bee.soc`.
|
|
21
10
|
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
11
|
+
class Soc {
|
|
12
|
+
constructor(context) {
|
|
13
|
+
this.context = context;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns an object for reading single owner chunks.
|
|
17
|
+
*
|
|
18
|
+
* @param ownerAddress The ethereum address of the owner
|
|
19
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
20
|
+
*/
|
|
21
|
+
makeReader(ownerAddress, requestOptions) {
|
|
22
|
+
const owner = new swarm_core_1.EthAddress(ownerAddress);
|
|
23
|
+
return {
|
|
24
|
+
owner,
|
|
25
|
+
download: soc_1.downloadSingleOwnerChunk.bind(null, this.context.getRequestOptionsForCall(requestOptions), owner),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Returns an object for reading and writing single owner chunks.
|
|
30
|
+
*
|
|
31
|
+
* @param signer The signer's private key. Falls back to the Bee instance signer.
|
|
32
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
33
|
+
*/
|
|
34
|
+
makeWriter(signer, requestOptions) {
|
|
35
|
+
const key = signer ? new swarm_core_1.PrivateKey(signer) : this.context.signer;
|
|
36
|
+
if (!key) {
|
|
37
|
+
throw Error('No signer provided');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
...this.makeReader(key.publicKey().address(), requestOptions),
|
|
41
|
+
upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.context.getRequestOptionsForCall(requestOptions), key),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
42
44
|
}
|
|
45
|
+
exports.Soc = Soc;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Stake = void 0;
|
|
37
|
+
const schema_1 = require("../utils/schema");
|
|
38
|
+
const tokens_1 = require("../utils/tokens");
|
|
39
|
+
const type_1 = require("../utils/type");
|
|
40
|
+
const stakeApi = __importStar(require("../api/stake"));
|
|
41
|
+
const redistributionApi = __importStar(require("../api/redistributionstate"));
|
|
42
|
+
/**
|
|
43
|
+
* Staking operations.
|
|
44
|
+
*
|
|
45
|
+
* Accessed as `bee.stake`.
|
|
46
|
+
*/
|
|
47
|
+
class Stake {
|
|
48
|
+
constructor(context) {
|
|
49
|
+
this.context = context;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Gets the amount of staked BZZ.
|
|
53
|
+
*
|
|
54
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
55
|
+
*/
|
|
56
|
+
async get(requestOptions) {
|
|
57
|
+
return stakeApi.getStake(this.context.getRequestOptionsForCall(requestOptions));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the amount of withdrawable staked BZZ.
|
|
61
|
+
*
|
|
62
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
63
|
+
*/
|
|
64
|
+
async getWithdrawable(requestOptions) {
|
|
65
|
+
return stakeApi.getWithdrawableStake(this.context.getRequestOptionsForCall(requestOptions));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stakes the given amount of BZZ. Initial deposit must be at least 10 BZZ.
|
|
69
|
+
*
|
|
70
|
+
* Be aware that staked BZZ tokens can **not** be withdrawn.
|
|
71
|
+
*
|
|
72
|
+
* @param amount Amount of BZZ tokens to be staked. If not providing a `BZZ` instance, the amount is denoted in PLUR.
|
|
73
|
+
* @param options
|
|
74
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
75
|
+
*/
|
|
76
|
+
async deposit(amount, options, requestOptions) {
|
|
77
|
+
const amountString = amount instanceof tokens_1.BZZ ? amount.toPLURString() : (0, type_1.asNumberString)(amount, { min: 1n, name: 'amount' });
|
|
78
|
+
if (options) {
|
|
79
|
+
options = schema_1.TransactionOptionsSchema.parse(options);
|
|
80
|
+
}
|
|
81
|
+
return stakeApi.depositStake(this.context.getRequestOptionsForCall(requestOptions), amountString, options);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Withdraws all surplus staked BZZ to the node wallet.
|
|
85
|
+
*
|
|
86
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
87
|
+
*/
|
|
88
|
+
async withdrawSurplus(requestOptions) {
|
|
89
|
+
return stakeApi.withdrawSurplusStake(this.context.getRequestOptionsForCall(requestOptions));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Withdraws all staked BZZ to the node wallet.
|
|
93
|
+
*
|
|
94
|
+
* **Only available when the staking contract is paused and is in the process of being migrated to a new contract!**
|
|
95
|
+
*
|
|
96
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
97
|
+
*/
|
|
98
|
+
async migrate(requestOptions) {
|
|
99
|
+
return stakeApi.migrateStake(this.context.getRequestOptionsForCall(requestOptions));
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets current status of node in redistribution game.
|
|
103
|
+
*
|
|
104
|
+
* @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
|
|
105
|
+
*/
|
|
106
|
+
async getRedistributionState(requestOptions) {
|
|
107
|
+
return redistributionApi.getRedistributionState(this.context.getRequestOptionsForCall(requestOptions));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.Stake = Stake;
|