koilib 2.5.0 → 2.7.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 +6 -6
- package/dist/koinos.js +2986 -4607
- package/dist/koinos.min.js +1 -1
- package/dist/koinos.min.js.LICENSE.txt +2 -2
- package/lib/Contract.d.ts +9 -11
- package/lib/Contract.js +20 -20
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +24 -17
- package/lib/Provider.js +99 -105
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.js +9 -9
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +9 -9
- package/lib/Signer.js +30 -22
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +200 -0
- package/lib/browser/Contract.js +298 -0
- package/lib/browser/Contract.js.map +1 -0
- package/lib/browser/Provider.d.ts +160 -0
- package/lib/browser/Provider.js +246 -0
- package/lib/browser/Provider.js.map +1 -0
- package/lib/browser/Serializer.d.ts +81 -0
- package/lib/browser/Serializer.js +169 -0
- package/lib/browser/Serializer.js.map +1 -0
- package/lib/browser/Signer.d.ts +296 -0
- package/lib/browser/Signer.js +429 -0
- package/lib/browser/Signer.js.map +1 -0
- package/lib/browser/index.d.ts +7 -0
- package/lib/browser/index.js +34 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/index2.d.ts +2 -0
- package/lib/browser/index2.js +33 -0
- package/lib/browser/index2.js.map +1 -0
- package/lib/browser/interface.d.ts +279 -0
- package/lib/browser/interface.js +3 -0
- package/lib/browser/interface.js.map +1 -0
- package/lib/browser/jsonDescriptors/krc20-proto.json +183 -0
- package/lib/browser/jsonDescriptors/protocol-proto.json +246 -0
- package/lib/browser/utils.d.ts +326 -0
- package/lib/browser/utils.js +252 -0
- package/lib/browser/utils.js.map +1 -0
- package/lib/interface.d.ts +24 -25
- package/lib/utils.d.ts +12 -8
- package/lib/utils.js +7 -7
- package/lib/utils.js.map +1 -1
- package/package.json +34 -31
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
|
|
2
2
|
|
|
3
|
-
/*! noble-hashes - MIT License (c)
|
|
3
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
4
4
|
|
|
5
|
-
/*! noble-secp256k1 - MIT License (c) Paul Miller (paulmillr.com) */
|
|
5
|
+
/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
package/lib/Contract.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Signer, SignerInterface } from "./Signer";
|
|
2
2
|
import { Provider } from "./Provider";
|
|
3
3
|
import { Serializer } from "./Serializer";
|
|
4
|
-
import { CallContractOperationNested, UploadContractOperationNested,
|
|
4
|
+
import { CallContractOperationNested, UploadContractOperationNested, TransactionJsonWait, Abi, TransactionOptions, DecodedOperationJson } from "./interface";
|
|
5
5
|
/**
|
|
6
6
|
* The contract class contains the contract ID and contract entries
|
|
7
7
|
* definition needed to encode/decode operations during the
|
|
@@ -40,15 +40,15 @@ import { CallContractOperationNested, UploadContractOperationNested, Transaction
|
|
|
40
40
|
* console.log(result)
|
|
41
41
|
*
|
|
42
42
|
* // Transfer
|
|
43
|
-
* const { transaction
|
|
43
|
+
* const { transaction } = await koin.transfer({
|
|
44
44
|
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
45
45
|
* value: "10.0001",
|
|
46
46
|
* });
|
|
47
47
|
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
48
48
|
*
|
|
49
49
|
* // wait to be mined
|
|
50
|
-
* const
|
|
51
|
-
* console.log(`Transaction mined. Block
|
|
50
|
+
* const blockNumber = await transaction.wait();
|
|
51
|
+
* console.log(`Transaction mined. Block number: ${blockNumber}`);
|
|
52
52
|
* }
|
|
53
53
|
*
|
|
54
54
|
* main();
|
|
@@ -73,8 +73,7 @@ export declare class Contract {
|
|
|
73
73
|
functions: {
|
|
74
74
|
[x: string]: <T = Record<string, unknown>>(args?: unknown, opts?: TransactionOptions) => Promise<{
|
|
75
75
|
operation: CallContractOperationNested;
|
|
76
|
-
transaction?:
|
|
77
|
-
transactionResponse?: SendTransactionResponse;
|
|
76
|
+
transaction?: TransactionJsonWait;
|
|
78
77
|
result?: T;
|
|
79
78
|
}>;
|
|
80
79
|
};
|
|
@@ -137,16 +136,15 @@ export declare class Contract {
|
|
|
137
136
|
* const signer = new Signer({ privateKey, provider });
|
|
138
137
|
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
139
138
|
* const contract = new Contract({ signer, provider, bytecode });
|
|
140
|
-
* const {
|
|
139
|
+
* const { transaction } = await contract.deploy();
|
|
141
140
|
* // wait to be mined
|
|
142
|
-
* const
|
|
143
|
-
* console.log(`Contract uploaded in block
|
|
141
|
+
* const blockNumber = await transaction.wait();
|
|
142
|
+
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
144
143
|
* ```
|
|
145
144
|
*/
|
|
146
145
|
deploy(options?: TransactionOptions): Promise<{
|
|
147
146
|
operation: UploadContractOperationNested;
|
|
148
|
-
transaction?:
|
|
149
|
-
transactionResponse?: SendTransactionResponse;
|
|
147
|
+
transaction?: TransactionJsonWait;
|
|
150
148
|
}>;
|
|
151
149
|
/**
|
|
152
150
|
* Encondes a contract operation using Koinos serialization
|
package/lib/Contract.js
CHANGED
|
@@ -41,15 +41,15 @@ const utils_1 = require("./utils");
|
|
|
41
41
|
* console.log(result)
|
|
42
42
|
*
|
|
43
43
|
* // Transfer
|
|
44
|
-
* const { transaction
|
|
44
|
+
* const { transaction } = await koin.transfer({
|
|
45
45
|
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
46
46
|
* value: "10.0001",
|
|
47
47
|
* });
|
|
48
48
|
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
49
49
|
*
|
|
50
50
|
* // wait to be mined
|
|
51
|
-
* const
|
|
52
|
-
* console.log(`Transaction mined. Block
|
|
51
|
+
* const blockNumber = await transaction.wait();
|
|
52
|
+
* console.log(`Transaction mined. Block number: ${blockNumber}`);
|
|
53
53
|
* }
|
|
54
54
|
*
|
|
55
55
|
* main();
|
|
@@ -59,7 +59,7 @@ class Contract {
|
|
|
59
59
|
constructor(c) {
|
|
60
60
|
var _a;
|
|
61
61
|
if (c.id)
|
|
62
|
-
this.id = utils_1.decodeBase58(c.id);
|
|
62
|
+
this.id = (0, utils_1.decodeBase58)(c.id);
|
|
63
63
|
this.signer = c.signer;
|
|
64
64
|
this.provider = c.provider || ((_a = c.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
|
65
65
|
this.abi = c.abi;
|
|
@@ -108,9 +108,9 @@ class Contract {
|
|
|
108
108
|
throw new Error(`No output defined for ${name}`);
|
|
109
109
|
// read contract
|
|
110
110
|
const { result: resultEncoded } = await this.provider.readContract({
|
|
111
|
-
contract_id: utils_1.encodeBase58(operation.call_contract.contract_id),
|
|
111
|
+
contract_id: (0, utils_1.encodeBase58)(operation.call_contract.contract_id),
|
|
112
112
|
entry_point: operation.call_contract.entry_point,
|
|
113
|
-
args: utils_1.encodeBase64(operation.call_contract.args),
|
|
113
|
+
args: (0, utils_1.encodeBase64)(operation.call_contract.args),
|
|
114
114
|
});
|
|
115
115
|
let result = defaultOutput;
|
|
116
116
|
if (resultEncoded) {
|
|
@@ -127,17 +127,17 @@ class Contract {
|
|
|
127
127
|
// write contract (sign and send)
|
|
128
128
|
if (!this.signer)
|
|
129
129
|
throw new Error("signer not found");
|
|
130
|
-
const
|
|
130
|
+
const tx = await this.signer.encodeTransaction({
|
|
131
131
|
...opts,
|
|
132
132
|
operations: [operation],
|
|
133
133
|
});
|
|
134
134
|
const abis = {};
|
|
135
135
|
if (opts === null || opts === void 0 ? void 0 : opts.sendAbis) {
|
|
136
|
-
const contractId = utils_1.encodeBase58(this.id);
|
|
136
|
+
const contractId = (0, utils_1.encodeBase58)(this.id);
|
|
137
137
|
abis[contractId] = this.abi;
|
|
138
138
|
}
|
|
139
|
-
const
|
|
140
|
-
return { operation, transaction
|
|
139
|
+
const transaction = await this.signer.sendTransaction(tx, abis);
|
|
140
|
+
return { operation, transaction };
|
|
141
141
|
};
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -146,7 +146,7 @@ class Contract {
|
|
|
146
146
|
* Compute contract Id
|
|
147
147
|
*/
|
|
148
148
|
static computeContractId(address) {
|
|
149
|
-
return utils_1.decodeBase58(address);
|
|
149
|
+
return (0, utils_1.decodeBase58)(address);
|
|
150
150
|
}
|
|
151
151
|
/**
|
|
152
152
|
* Get contract Id
|
|
@@ -154,7 +154,7 @@ class Contract {
|
|
|
154
154
|
getId() {
|
|
155
155
|
if (!this.id)
|
|
156
156
|
throw new Error("id is not defined");
|
|
157
|
-
return utils_1.encodeBase58(this.id);
|
|
157
|
+
return (0, utils_1.encodeBase58)(this.id);
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
160
|
* Function to deploy a new smart contract.
|
|
@@ -166,10 +166,10 @@ class Contract {
|
|
|
166
166
|
* const signer = new Signer({ privateKey, provider });
|
|
167
167
|
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
168
168
|
* const contract = new Contract({ signer, provider, bytecode });
|
|
169
|
-
* const {
|
|
169
|
+
* const { transaction } = await contract.deploy();
|
|
170
170
|
* // wait to be mined
|
|
171
|
-
* const
|
|
172
|
-
* console.log(`Contract uploaded in block
|
|
171
|
+
* const blockNumber = await transaction.wait();
|
|
172
|
+
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
async deploy(options) {
|
|
@@ -190,12 +190,12 @@ class Contract {
|
|
|
190
190
|
// return operation if send is false
|
|
191
191
|
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
192
192
|
return { operation };
|
|
193
|
-
const
|
|
193
|
+
const tx = await this.signer.encodeTransaction({
|
|
194
194
|
...opts,
|
|
195
195
|
operations: [operation],
|
|
196
196
|
});
|
|
197
|
-
const
|
|
198
|
-
return { operation, transaction
|
|
197
|
+
const transaction = await this.signer.sendTransaction(tx);
|
|
198
|
+
return { operation, transaction };
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Encondes a contract operation using Koinos serialization
|
|
@@ -276,8 +276,8 @@ class Contract {
|
|
|
276
276
|
throw new Error("Serializer is not defined");
|
|
277
277
|
if (!op.call_contract)
|
|
278
278
|
throw new Error("Operation is not CallContractOperation");
|
|
279
|
-
if (op.call_contract.contract_id !== this.id)
|
|
280
|
-
throw new Error(`Invalid contract id. Expected: ${utils_1.encodeBase58(this.id)}. Received: ${utils_1.encodeBase58(op.call_contract.contract_id)}`);
|
|
279
|
+
if ((0, utils_1.encodeBase58)(op.call_contract.contract_id) !== (0, utils_1.encodeBase58)(this.id))
|
|
280
|
+
throw new Error(`Invalid contract id. Expected: ${(0, utils_1.encodeBase58)(this.id)}. Received: ${(0, utils_1.encodeBase58)(op.call_contract.contract_id)}`);
|
|
281
281
|
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
282
282
|
const opName = Object.keys(this.abi.methods)[i];
|
|
283
283
|
const method = this.abi.methods[opName];
|
package/lib/Contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":";;;AAGA,6CAA0C;
|
|
1
|
+
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":";;;AAGA,6CAA0C;AAS1C,mCAAmE;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAa,QAAQ;IA4DnB,YAAY,CAcX;;QACC,IAAI,CAAC,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,GAAG,IAAA,oBAAY,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvC,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@@
|
|
|
1
|
-
import { BlockJson, TransactionJson, CallContractOperationJson
|
|
1
|
+
import { BlockJson, TransactionJson, CallContractOperationJson } from "./interface";
|
|
2
2
|
/**
|
|
3
3
|
* Class to connect with the RPC node
|
|
4
4
|
*/
|
|
@@ -119,27 +119,34 @@ export declare class Provider {
|
|
|
119
119
|
};
|
|
120
120
|
}>;
|
|
121
121
|
/**
|
|
122
|
-
* Function to
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
122
|
+
* Function to wait for a transaction to be mined.
|
|
123
|
+
* @param txId - transaction id
|
|
124
|
+
* @param type - Type must be "byBlock" (default) or "byTransactionId".
|
|
125
|
+
* _byBlock_ will query the blockchain to get blocks and search for the
|
|
126
|
+
* transaction there. _byTransactionId_ will query the "transaction store"
|
|
127
|
+
* microservice to search the transaction by its id. If non of them is
|
|
128
|
+
* specified the function will use "byBlock" (as "byTransactionId"
|
|
129
|
+
* requires the transaction store, which is an optional microservice).
|
|
130
|
+
*
|
|
131
|
+
* When _byBlock_ is used it returns the block number.
|
|
132
|
+
*
|
|
133
|
+
* When _byTransactionId_ is used it returns the block id.
|
|
134
|
+
*
|
|
135
|
+
* @param timeout - Timeout in milliseconds. By default it is 30000
|
|
127
136
|
* @example
|
|
128
137
|
* ```ts
|
|
129
|
-
* const
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* signatureData: "...",
|
|
133
|
-
* });
|
|
134
|
-
* console.log("Transaction submitted to the mempool");
|
|
135
|
-
* // wait to be mined
|
|
136
|
-
* const blockNumber = await transactionResponse.wait();
|
|
137
|
-
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
138
|
-
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
138
|
+
* const blockNumber = await provider.wait(txId);
|
|
139
|
+
* // const blockNumber = await provider.wait(txId, "byBlock", 30000);
|
|
140
|
+
* // const blockId = await provider.wait(txId, "byTransactionId", 30000);
|
|
139
141
|
* console.log("Transaction mined")
|
|
140
142
|
* ```
|
|
141
143
|
*/
|
|
142
|
-
|
|
144
|
+
wait(txId: string, type?: "byTransactionId" | "byBlock", timeout?: number): Promise<string | number>;
|
|
145
|
+
/**
|
|
146
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
147
|
+
* transaction to the blockchain.
|
|
148
|
+
*/
|
|
149
|
+
sendTransaction(transaction: TransactionJson): Promise<{}>;
|
|
143
150
|
/**
|
|
144
151
|
* Function to call "chain.read_contract" to read a contract.
|
|
145
152
|
* This function is used by [[Contract]] class when read methods
|
package/lib/Provider.js
CHANGED
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Provider = void 0;
|
|
7
|
-
const
|
|
7
|
+
const cross_fetch_1 = __importDefault(require("cross-fetch"));
|
|
8
8
|
async function sleep(ms) {
|
|
9
9
|
return new Promise((r) => setTimeout(r, ms));
|
|
10
10
|
}
|
|
@@ -39,16 +39,9 @@ class Provider {
|
|
|
39
39
|
* @returns Result of jsonrpc response
|
|
40
40
|
*/
|
|
41
41
|
async call(method, params) {
|
|
42
|
-
let response = {
|
|
43
|
-
data: {},
|
|
44
|
-
status: 0,
|
|
45
|
-
statusText: "",
|
|
46
|
-
headers: {},
|
|
47
|
-
config: {},
|
|
48
|
-
};
|
|
49
|
-
let success = false;
|
|
50
42
|
/* eslint-disable no-await-in-loop */
|
|
51
|
-
|
|
43
|
+
// eslint-disable-next-line no-constant-condition
|
|
44
|
+
while (true) {
|
|
52
45
|
try {
|
|
53
46
|
const data = {
|
|
54
47
|
id: Math.round(Math.random() * 1000),
|
|
@@ -57,16 +50,20 @@ class Provider {
|
|
|
57
50
|
params,
|
|
58
51
|
};
|
|
59
52
|
const url = this.rpcNodes[this.currentNodeId];
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
body: JSON.stringify(data),
|
|
53
|
+
const response = await (0, cross_fetch_1.default)(url, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
body: JSON.stringify(data),
|
|
64
56
|
});
|
|
65
|
-
const json = await response.json();
|
|
66
|
-
if (json.error && json.error.message)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
57
|
+
const json = (await response.json());
|
|
58
|
+
if (json.error && json.error.message) {
|
|
59
|
+
const error = new Error(json.error.message);
|
|
60
|
+
error.request = {
|
|
61
|
+
method,
|
|
62
|
+
params,
|
|
63
|
+
};
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
return json.result;
|
|
70
67
|
}
|
|
71
68
|
catch (e) {
|
|
72
69
|
const currentNode = this.rpcNodes[this.currentNodeId];
|
|
@@ -77,12 +74,6 @@ class Provider {
|
|
|
77
74
|
throw e;
|
|
78
75
|
}
|
|
79
76
|
}
|
|
80
|
-
if (response.data.error)
|
|
81
|
-
throw new Error(JSON.stringify({
|
|
82
|
-
error: response.data.error,
|
|
83
|
-
request: { method, params },
|
|
84
|
-
}));
|
|
85
|
-
return response.data.result;
|
|
86
77
|
}
|
|
87
78
|
/**
|
|
88
79
|
* Function to call "chain.get_account_nonce" to return the number of
|
|
@@ -155,92 +146,95 @@ class Provider {
|
|
|
155
146
|
return (await this.getBlocks(height, 1))[0];
|
|
156
147
|
}
|
|
157
148
|
/**
|
|
158
|
-
* Function to
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
149
|
+
* Function to wait for a transaction to be mined.
|
|
150
|
+
* @param txId - transaction id
|
|
151
|
+
* @param type - Type must be "byBlock" (default) or "byTransactionId".
|
|
152
|
+
* _byBlock_ will query the blockchain to get blocks and search for the
|
|
153
|
+
* transaction there. _byTransactionId_ will query the "transaction store"
|
|
154
|
+
* microservice to search the transaction by its id. If non of them is
|
|
155
|
+
* specified the function will use "byBlock" (as "byTransactionId"
|
|
156
|
+
* requires the transaction store, which is an optional microservice).
|
|
157
|
+
*
|
|
158
|
+
* When _byBlock_ is used it returns the block number.
|
|
159
|
+
*
|
|
160
|
+
* When _byTransactionId_ is used it returns the block id.
|
|
161
|
+
*
|
|
162
|
+
* @param timeout - Timeout in milliseconds. By default it is 30000
|
|
163
163
|
* @example
|
|
164
164
|
* ```ts
|
|
165
|
-
* const
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* signatureData: "...",
|
|
169
|
-
* });
|
|
170
|
-
* console.log("Transaction submitted to the mempool");
|
|
171
|
-
* // wait to be mined
|
|
172
|
-
* const blockNumber = await transactionResponse.wait();
|
|
173
|
-
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
174
|
-
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
165
|
+
* const blockNumber = await provider.wait(txId);
|
|
166
|
+
* // const blockNumber = await provider.wait(txId, "byBlock", 30000);
|
|
167
|
+
* // const blockId = await provider.wait(txId, "byTransactionId", 30000);
|
|
175
168
|
* console.log("Transaction mined")
|
|
176
169
|
* ```
|
|
177
170
|
*/
|
|
178
|
-
async
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (tx)
|
|
208
|
-
bNum = Number(block.block_height);
|
|
209
|
-
});
|
|
210
|
-
let lastId = blocks[blocks.length - 1].block_id;
|
|
211
|
-
return [bNum, lastId];
|
|
212
|
-
};
|
|
213
|
-
let blockNumber = 0;
|
|
214
|
-
let iniBlock = 0;
|
|
215
|
-
let previousId = "";
|
|
216
|
-
while (Date.now() < iniTime + timeout) {
|
|
217
|
-
await sleep(1000);
|
|
218
|
-
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
219
|
-
if (blockNumber === 0) {
|
|
220
|
-
blockNumber = Number(headTopology.height);
|
|
221
|
-
iniBlock = blockNumber;
|
|
222
|
-
}
|
|
223
|
-
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
224
|
-
previousId &&
|
|
225
|
-
previousId !== headTopology.id) {
|
|
226
|
-
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
227
|
-
if (bNum)
|
|
228
|
-
return bNum;
|
|
229
|
-
previousId = lastId;
|
|
230
|
-
blockNumber = Number(headTopology.height) + 1;
|
|
231
|
-
}
|
|
232
|
-
if (blockNumber > Number(headTopology.height))
|
|
233
|
-
continue;
|
|
234
|
-
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
235
|
-
if (bNum)
|
|
236
|
-
return bNum;
|
|
237
|
-
if (!previousId)
|
|
238
|
-
previousId = lastId;
|
|
239
|
-
blockNumber += 1;
|
|
240
|
-
}
|
|
241
|
-
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
242
|
-
},
|
|
171
|
+
async wait(txId, type = "byBlock", timeout = 30000) {
|
|
172
|
+
const iniTime = Date.now();
|
|
173
|
+
if (type === "byTransactionId") {
|
|
174
|
+
while (Date.now() < iniTime + timeout) {
|
|
175
|
+
await sleep(1000);
|
|
176
|
+
const { transactions } = await this.getTransactionsById([txId]);
|
|
177
|
+
if (transactions &&
|
|
178
|
+
transactions[0] &&
|
|
179
|
+
transactions[0].containing_blocks)
|
|
180
|
+
return transactions[0].containing_blocks[0];
|
|
181
|
+
}
|
|
182
|
+
throw new Error(`Transaction not mined after ${timeout} ms`);
|
|
183
|
+
}
|
|
184
|
+
// byBlock
|
|
185
|
+
const findTxInBlocks = async (ini, numBlocks, idRef) => {
|
|
186
|
+
const blocks = await this.getBlocks(ini, numBlocks, idRef);
|
|
187
|
+
let bNum = 0;
|
|
188
|
+
blocks.forEach((block) => {
|
|
189
|
+
if (!block ||
|
|
190
|
+
!block.block ||
|
|
191
|
+
!block.block_id ||
|
|
192
|
+
!block.block.transactions)
|
|
193
|
+
return;
|
|
194
|
+
const tx = block.block.transactions.find((t) => t.id === txId);
|
|
195
|
+
if (tx)
|
|
196
|
+
bNum = Number(block.block_height);
|
|
197
|
+
});
|
|
198
|
+
const lastId = blocks[blocks.length - 1].block_id;
|
|
199
|
+
return [bNum, lastId];
|
|
243
200
|
};
|
|
201
|
+
let blockNumber = 0;
|
|
202
|
+
let iniBlock = 0;
|
|
203
|
+
let previousId = "";
|
|
204
|
+
while (Date.now() < iniTime + timeout) {
|
|
205
|
+
await sleep(1000);
|
|
206
|
+
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
207
|
+
if (blockNumber === 0) {
|
|
208
|
+
blockNumber = Number(headTopology.height);
|
|
209
|
+
iniBlock = blockNumber;
|
|
210
|
+
}
|
|
211
|
+
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
212
|
+
previousId &&
|
|
213
|
+
previousId !== headTopology.id) {
|
|
214
|
+
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
215
|
+
if (bNum)
|
|
216
|
+
return bNum;
|
|
217
|
+
previousId = lastId;
|
|
218
|
+
blockNumber = Number(headTopology.height) + 1;
|
|
219
|
+
}
|
|
220
|
+
// eslint-disable-next-line no-continue
|
|
221
|
+
if (blockNumber > Number(headTopology.height))
|
|
222
|
+
continue;
|
|
223
|
+
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
224
|
+
if (bNum)
|
|
225
|
+
return bNum;
|
|
226
|
+
if (!previousId)
|
|
227
|
+
previousId = lastId;
|
|
228
|
+
blockNumber += 1;
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
234
|
+
* transaction to the blockchain.
|
|
235
|
+
*/
|
|
236
|
+
async sendTransaction(transaction) {
|
|
237
|
+
return this.call("chain.submit_transaction", { transaction });
|
|
244
238
|
}
|
|
245
239
|
/**
|
|
246
240
|
* Function to call "chain.read_contract" to read a contract.
|
package/lib/Provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":";;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAOhC,KAAK,UAAU,KAAK,CAAC,EAAU;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAa,QAAQ;IAwCnB;;;;;;;;;;;OAWG;IACH,YAAY,QAA2B;QACrC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;;YACjD,IAAI,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAc,MAAc,EAAE,MAAe;QACrD,qCAAqC;QACrC,iDAAiD;QACjD,OAAO,IAAI,EAAE;YACX,IAAI;gBACF,MAAM,IAAI,GAAG;oBACX,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAA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,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,QAAQ,GAAG,CAAC,EAC1C,YAAY,CAAC,EAAE,CAChB,CAAC;gBACF,IAAI,IAAI;oBAAE,OAAO,IAAI,CAAC;gBACtB,UAAU,GAAG,MAAM,CAAC;gBACpB,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC/C;YACD,uCAAuC;YACvC,IAAI,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;gBAAE,SAAS;YACxD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,cAAc,CACzC,WAAW,EACX,CAAC,EACD,YAAY,CAAC,EAAE,CAChB,CAAC;YACF,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;YACtB,IAAI,CAAC,UAAU;gBAAE,UAAU,GAAG,MAAM,CAAC;YACrC,WAAW,IAAI,CAAC,CAAC;SAClB;QACD,MAAM,IAAI,KAAK,CACb,+BAA+B,OAAO,4BAA4B,QAAQ,OAAO,WAAW,EAAE,CAC/F,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,WAA4B;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,SAAoC;QAIrD,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;CACF;AArXD,4BAqXC;AAED,kBAAe,QAAQ,CAAC"}
|
package/lib/Serializer.js
CHANGED
|
@@ -87,7 +87,7 @@ class Serializer {
|
|
|
87
87
|
}
|
|
88
88
|
// Default byte conversion
|
|
89
89
|
if (!options || !options[OP_BYTES]) {
|
|
90
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
90
|
+
object[name] = (0, utils_1.decodeBase64)(valueDecoded[name]);
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
// Specific byte conversion
|
|
@@ -95,15 +95,15 @@ class Serializer {
|
|
|
95
95
|
case "BASE58":
|
|
96
96
|
case "CONTRACT_ID":
|
|
97
97
|
case "ADDRESS":
|
|
98
|
-
object[name] = utils_1.decodeBase58(valueDecoded[name]);
|
|
98
|
+
object[name] = (0, utils_1.decodeBase58)(valueDecoded[name]);
|
|
99
99
|
break;
|
|
100
100
|
case "BASE64":
|
|
101
|
-
object[name] = utils_1.decodeBase64(valueDecoded[name]);
|
|
101
|
+
object[name] = (0, utils_1.decodeBase64)(valueDecoded[name]);
|
|
102
102
|
break;
|
|
103
103
|
case "HEX":
|
|
104
104
|
case "BLOCK_ID":
|
|
105
105
|
case "TRANSACTION_ID":
|
|
106
|
-
object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
|
|
106
|
+
object[name] = (0, utils_1.toUint8Array)(valueDecoded[name].replace("0x", ""));
|
|
107
107
|
break;
|
|
108
108
|
default:
|
|
109
109
|
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|
|
@@ -124,7 +124,7 @@ class Serializer {
|
|
|
124
124
|
*/
|
|
125
125
|
async deserialize(valueEncoded, typeName) {
|
|
126
126
|
const valueBuffer = typeof valueEncoded === "string"
|
|
127
|
-
? utils_1.decodeBase64(valueEncoded)
|
|
127
|
+
? (0, utils_1.decodeBase64)(valueEncoded)
|
|
128
128
|
: valueEncoded;
|
|
129
129
|
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
130
130
|
const message = protobufType.decode(valueBuffer);
|
|
@@ -139,7 +139,7 @@ class Serializer {
|
|
|
139
139
|
return;
|
|
140
140
|
// Default byte conversion
|
|
141
141
|
if (!options || !options[OP_BYTES]) {
|
|
142
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
142
|
+
object[name] = (0, utils_1.encodeBase64)(object[name]);
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
// Specific byte conversion
|
|
@@ -147,15 +147,15 @@ class Serializer {
|
|
|
147
147
|
case "BASE58":
|
|
148
148
|
case "CONTRACT_ID":
|
|
149
149
|
case "ADDRESS":
|
|
150
|
-
object[name] = utils_1.encodeBase58(object[name]);
|
|
150
|
+
object[name] = (0, utils_1.encodeBase58)(object[name]);
|
|
151
151
|
break;
|
|
152
152
|
case "BASE64":
|
|
153
|
-
object[name] = utils_1.encodeBase64(object[name]);
|
|
153
|
+
object[name] = (0, utils_1.encodeBase64)(object[name]);
|
|
154
154
|
break;
|
|
155
155
|
case "HEX":
|
|
156
156
|
case "BLOCK_ID":
|
|
157
157
|
case "TRANSACTION_ID":
|
|
158
|
-
object[name] = `0x${utils_1.toHexString(object[name])}`;
|
|
158
|
+
object[name] = `0x${(0, utils_1.toHexString)(object[name])}`;
|
|
159
159
|
break;
|
|
160
160
|
default:
|
|
161
161
|
throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
|