koilib 5.3.1 → 5.5.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 +85 -4
- package/dist/koinos.js +15717 -2629
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +49 -5
- package/lib/Contract.js +168 -98
- package/lib/Contract.js.map +1 -1
- package/lib/Serializer.d.ts +36 -15
- package/lib/Serializer.js +82 -16
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.js +1 -1
- package/lib/Signer.js.map +1 -1
- package/lib/Transaction.d.ts +109 -0
- package/lib/Transaction.js +184 -0
- package/lib/Transaction.js.map +1 -0
- package/lib/browser/Contract.d.ts +49 -5
- package/lib/browser/Contract.js +168 -98
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Serializer.d.ts +36 -15
- package/lib/browser/Serializer.js +82 -16
- package/lib/browser/Serializer.js.map +1 -1
- package/lib/browser/Signer.js +1 -1
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/Transaction.d.ts +109 -0
- package/lib/browser/Transaction.js +184 -0
- package/lib/browser/Transaction.js.map +1 -0
- package/lib/browser/index.d.ts +1 -0
- package/lib/browser/index.js +1 -0
- package/lib/browser/index.js.map +1 -1
- package/lib/browser/index2.js +2 -0
- package/lib/browser/index2.js.map +1 -1
- package/lib/browser/interface.d.ts +188 -86
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/index2.js +2 -0
- package/lib/index2.js.map +1 -1
- package/lib/interface.d.ts +188 -86
- package/package.json +3 -1
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 { TransactionJsonWait, Abi,
|
|
4
|
+
import { TransactionJsonWait, Abi, CallContractOptions, DecodedOperationJson, OperationJson, DeployOptions, TransactionReceipt, EventData, DecodedEventData } 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
|
|
@@ -63,7 +63,7 @@ export declare class Contract {
|
|
|
63
63
|
/**
|
|
64
64
|
* Contract ID
|
|
65
65
|
*/
|
|
66
|
-
id
|
|
66
|
+
id: Uint8Array;
|
|
67
67
|
/**
|
|
68
68
|
* Set of functions to interact with the smart
|
|
69
69
|
* contract. These functions are automatically generated
|
|
@@ -95,7 +95,7 @@ export declare class Contract {
|
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
97
|
functions: {
|
|
98
|
-
[x: string]: <T = Record<string, unknown>>(args?: unknown, opts?:
|
|
98
|
+
[x: string]: <T = Record<string, unknown>>(args?: unknown, opts?: CallContractOptions) => Promise<{
|
|
99
99
|
operation: OperationJson;
|
|
100
100
|
transaction?: TransactionJsonWait;
|
|
101
101
|
result?: T;
|
|
@@ -127,12 +127,12 @@ export declare class Contract {
|
|
|
127
127
|
* By default it set rc_limit to 1e8, sendTransaction true,
|
|
128
128
|
* sendAbis true, and nonce undefined (to get it from the blockchain)
|
|
129
129
|
*/
|
|
130
|
-
options:
|
|
130
|
+
options: CallContractOptions;
|
|
131
131
|
constructor(c: {
|
|
132
132
|
id?: string;
|
|
133
133
|
abi?: Abi;
|
|
134
134
|
bytecode?: Uint8Array;
|
|
135
|
-
options?:
|
|
135
|
+
options?: CallContractOptions;
|
|
136
136
|
signer?: Signer;
|
|
137
137
|
provider?: Provider;
|
|
138
138
|
/**
|
|
@@ -147,6 +147,18 @@ export declare class Contract {
|
|
|
147
147
|
* Get contract Id
|
|
148
148
|
*/
|
|
149
149
|
getId(): string;
|
|
150
|
+
/**
|
|
151
|
+
* Fetch the ABI from the contract meta store. The provider must
|
|
152
|
+
* have contract_meta_store microservice enabled.
|
|
153
|
+
*/
|
|
154
|
+
fetcthAbi(opts?: {
|
|
155
|
+
updateFunctions: boolean;
|
|
156
|
+
updateSerializer: boolean;
|
|
157
|
+
}): Promise<Abi | undefined>;
|
|
158
|
+
/**
|
|
159
|
+
* Create the contract functions based on the ABI
|
|
160
|
+
*/
|
|
161
|
+
updateFunctionsFromAbi(): boolean;
|
|
150
162
|
/**
|
|
151
163
|
* Function to deploy a new smart contract.
|
|
152
164
|
* The Bytecode must be defined in the constructor of the class
|
|
@@ -246,5 +258,37 @@ export declare class Contract {
|
|
|
246
258
|
* ```
|
|
247
259
|
*/
|
|
248
260
|
decodeOperation(op: OperationJson): Promise<DecodedOperationJson>;
|
|
261
|
+
/**
|
|
262
|
+
* Decode an event received in a receipt
|
|
263
|
+
*
|
|
264
|
+
* @example
|
|
265
|
+
* ```ts
|
|
266
|
+
* const contract = new Contract({
|
|
267
|
+
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
268
|
+
* abi: utils.tokenAbi,
|
|
269
|
+
* });
|
|
270
|
+
* const event = {
|
|
271
|
+
* sequence: 1,
|
|
272
|
+
* source: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
273
|
+
* name: "koinos.contracts.token.mint_event",
|
|
274
|
+
* data: "ChkAxjdqxuwS-B50lPQ-lqhRBA3bf2b2ooAHENrw3Ek=",
|
|
275
|
+
* impacted: ["1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J"],
|
|
276
|
+
* };
|
|
277
|
+
* const eventDecoded = await contract.decodeEvent(event);
|
|
278
|
+
* console.log(eventDecoded);
|
|
279
|
+
* // {
|
|
280
|
+
* // sequence: 1,
|
|
281
|
+
* // source: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
282
|
+
* // name: "koinos.contracts.token.mint_event",
|
|
283
|
+
* // data: "ChkAxjdqxuwS-B50lPQ-lqhRBA3bf2b2ooAHENrw3Ek=",
|
|
284
|
+
* // impacted: ["1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J"],
|
|
285
|
+
* // args: {
|
|
286
|
+
* // to: "1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J",
|
|
287
|
+
* // value: "154613850",
|
|
288
|
+
* // },
|
|
289
|
+
* // }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
decodeEvent(event: EventData): Promise<DecodedEventData>;
|
|
249
293
|
}
|
|
250
294
|
export default Contract;
|
package/lib/Contract.js
CHANGED
|
@@ -63,9 +63,14 @@ const utils_1 = require("./utils");
|
|
|
63
63
|
class Contract {
|
|
64
64
|
constructor(c) {
|
|
65
65
|
var _a;
|
|
66
|
+
this.signer = c.signer;
|
|
66
67
|
if (c.id)
|
|
67
68
|
this.id = (0, utils_1.decodeBase58)(c.id);
|
|
68
|
-
|
|
69
|
+
else {
|
|
70
|
+
if (!this.signer)
|
|
71
|
+
throw new Error("at least signer or contract id must be defined");
|
|
72
|
+
this.id = (0, utils_1.decodeBase58)(this.signer.getAddress());
|
|
73
|
+
}
|
|
69
74
|
this.provider = c.provider || ((_a = c.signer) === null || _a === void 0 ? void 0 : _a.provider);
|
|
70
75
|
this.abi = c.abi;
|
|
71
76
|
this.bytecode = c.bytecode;
|
|
@@ -75,6 +80,9 @@ class Contract {
|
|
|
75
80
|
else if (c.abi && c.abi.koilib_types) {
|
|
76
81
|
this.serializer = new Serializer_1.Serializer(c.abi.koilib_types);
|
|
77
82
|
}
|
|
83
|
+
else if (c.abi && c.abi.types) {
|
|
84
|
+
this.serializer = new Serializer_1.Serializer(c.abi.types);
|
|
85
|
+
}
|
|
78
86
|
this.options = {
|
|
79
87
|
signTransaction: true,
|
|
80
88
|
sendTransaction: true,
|
|
@@ -83,94 +91,123 @@ class Contract {
|
|
|
83
91
|
...c.options,
|
|
84
92
|
};
|
|
85
93
|
this.functions = {};
|
|
86
|
-
|
|
87
|
-
Object.keys(this.abi.methods).forEach((name) => {
|
|
88
|
-
this.functions[name] = async (argu = {}, options) => {
|
|
89
|
-
if (!this.provider)
|
|
90
|
-
throw new Error("provider not found");
|
|
91
|
-
if (!this.abi || !this.abi.methods)
|
|
92
|
-
throw new Error("Methods are not defined");
|
|
93
|
-
if (!this.abi.methods[name])
|
|
94
|
-
throw new Error(`Method ${name} not defined in the ABI`);
|
|
95
|
-
const opts = {
|
|
96
|
-
...this.options,
|
|
97
|
-
...options,
|
|
98
|
-
};
|
|
99
|
-
const { read_only: readOnly, return: output, default_output: defaultOutput, preformat_argument: preformatArgument, preformat_return: preformatReturn, } = this.abi.methods[name];
|
|
100
|
-
let args;
|
|
101
|
-
if (typeof preformatArgument === "function") {
|
|
102
|
-
args = preformatArgument(argu);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
args = argu;
|
|
106
|
-
}
|
|
107
|
-
const operation = await this.encodeOperation({ name, args });
|
|
108
|
-
if (opts.onlyOperation) {
|
|
109
|
-
return { operation };
|
|
110
|
-
}
|
|
111
|
-
if (readOnly) {
|
|
112
|
-
if (!output)
|
|
113
|
-
throw new Error(`No output defined for ${name}`);
|
|
114
|
-
// read contract
|
|
115
|
-
const { result: resultEncoded } = await this.provider.readContract(operation.call_contract);
|
|
116
|
-
let result = defaultOutput;
|
|
117
|
-
if (resultEncoded) {
|
|
118
|
-
result = await this.serializer.deserialize(resultEncoded, output);
|
|
119
|
-
}
|
|
120
|
-
if (typeof preformatReturn === "function") {
|
|
121
|
-
result = preformatReturn(result);
|
|
122
|
-
}
|
|
123
|
-
return { operation, result };
|
|
124
|
-
}
|
|
125
|
-
// write contract (sign and send)
|
|
126
|
-
if (!this.signer)
|
|
127
|
-
throw new Error("signer not found");
|
|
128
|
-
let tx = await this.signer.prepareTransaction({
|
|
129
|
-
header: {
|
|
130
|
-
...(opts.chainId && { chain_id: opts.chainId }),
|
|
131
|
-
...(opts.rcLimit && { rc_limit: opts.rcLimit }),
|
|
132
|
-
...(opts.nonce && { nonce: opts.nonce }),
|
|
133
|
-
...(opts.payer && { payer: opts.payer }),
|
|
134
|
-
...(opts.payee && { payee: opts.payee }),
|
|
135
|
-
},
|
|
136
|
-
operations: [
|
|
137
|
-
...(opts.previousOperations ? opts.previousOperations : []),
|
|
138
|
-
operation,
|
|
139
|
-
...(opts.nextOperations ? opts.nextOperations : []),
|
|
140
|
-
],
|
|
141
|
-
});
|
|
142
|
-
const optsSend = {
|
|
143
|
-
broadcast: opts.broadcast,
|
|
144
|
-
beforeSend: opts.beforeSend,
|
|
145
|
-
};
|
|
146
|
-
if (opts.sendAbis) {
|
|
147
|
-
optsSend.abis = {};
|
|
148
|
-
const contractId = (0, utils_1.encodeBase58)(this.id);
|
|
149
|
-
optsSend.abis[contractId] = this.abi;
|
|
150
|
-
}
|
|
151
|
-
// return result if the transaction will not be broadcasted
|
|
152
|
-
if (!opts.sendTransaction) {
|
|
153
|
-
const noWait = () => {
|
|
154
|
-
throw new Error("This transaction was not broadcasted");
|
|
155
|
-
};
|
|
156
|
-
if (opts.signTransaction)
|
|
157
|
-
tx = await this.signer.signTransaction(tx, optsSend.abis);
|
|
158
|
-
return { operation, transaction: { ...tx, wait: noWait } };
|
|
159
|
-
}
|
|
160
|
-
const { transaction, receipt } = await this.signer.sendTransaction(tx, optsSend);
|
|
161
|
-
return { operation, transaction, receipt };
|
|
162
|
-
};
|
|
163
|
-
});
|
|
164
|
-
}
|
|
94
|
+
this.updateFunctionsFromAbi();
|
|
165
95
|
}
|
|
166
96
|
/**
|
|
167
97
|
* Get contract Id
|
|
168
98
|
*/
|
|
169
99
|
getId() {
|
|
170
|
-
if (!this.id)
|
|
171
|
-
throw new Error("id is not defined");
|
|
172
100
|
return (0, utils_1.encodeBase58)(this.id);
|
|
173
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Fetch the ABI from the contract meta store. The provider must
|
|
104
|
+
* have contract_meta_store microservice enabled.
|
|
105
|
+
*/
|
|
106
|
+
async fetcthAbi(opts = {
|
|
107
|
+
updateFunctions: true,
|
|
108
|
+
updateSerializer: true,
|
|
109
|
+
}) {
|
|
110
|
+
if (!this.provider)
|
|
111
|
+
throw new Error("provider not found");
|
|
112
|
+
const response = await this.provider.call("contract_meta_store.get_contract_meta", {
|
|
113
|
+
contract_id: this.getId(),
|
|
114
|
+
});
|
|
115
|
+
if (!response.meta || !response.meta.abi)
|
|
116
|
+
return undefined;
|
|
117
|
+
this.abi = JSON.parse(response.meta.abi);
|
|
118
|
+
if (opts.updateFunctions)
|
|
119
|
+
this.updateFunctionsFromAbi();
|
|
120
|
+
if (opts.updateSerializer) {
|
|
121
|
+
if (this.abi.koilib_types)
|
|
122
|
+
this.serializer = new Serializer_1.Serializer(this.abi.koilib_types);
|
|
123
|
+
else if (this.abi.types)
|
|
124
|
+
this.serializer = new Serializer_1.Serializer(this.abi.types);
|
|
125
|
+
}
|
|
126
|
+
return this.abi;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Create the contract functions based on the ABI
|
|
130
|
+
*/
|
|
131
|
+
updateFunctionsFromAbi() {
|
|
132
|
+
if (!this.abi || !this.abi.methods)
|
|
133
|
+
return false;
|
|
134
|
+
Object.keys(this.abi.methods).forEach((name) => {
|
|
135
|
+
this.functions[name] = async (argu = {}, options) => {
|
|
136
|
+
if (!this.provider)
|
|
137
|
+
throw new Error("provider not found");
|
|
138
|
+
if (!this.abi || !this.abi.methods)
|
|
139
|
+
throw new Error("Methods are not defined");
|
|
140
|
+
if (!this.abi.methods[name])
|
|
141
|
+
throw new Error(`Method ${name} not defined in the ABI`);
|
|
142
|
+
const opts = {
|
|
143
|
+
...this.options,
|
|
144
|
+
...options,
|
|
145
|
+
};
|
|
146
|
+
const { read_only: readOnly, return: output, default_output: defaultOutput, preformat_argument: preformatArgument, preformat_return: preformatReturn, } = this.abi.methods[name];
|
|
147
|
+
let args;
|
|
148
|
+
if (typeof preformatArgument === "function") {
|
|
149
|
+
args = preformatArgument(argu);
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
args = argu;
|
|
153
|
+
}
|
|
154
|
+
const operation = await this.encodeOperation({ name, args });
|
|
155
|
+
if (opts.onlyOperation) {
|
|
156
|
+
return { operation };
|
|
157
|
+
}
|
|
158
|
+
if (readOnly) {
|
|
159
|
+
if (!output)
|
|
160
|
+
throw new Error(`No output defined for ${name}`);
|
|
161
|
+
// read contract
|
|
162
|
+
const { result: resultEncoded } = await this.provider.readContract(operation.call_contract);
|
|
163
|
+
let result = defaultOutput;
|
|
164
|
+
if (resultEncoded) {
|
|
165
|
+
result = await this.serializer.deserialize(resultEncoded, output);
|
|
166
|
+
}
|
|
167
|
+
if (typeof preformatReturn === "function") {
|
|
168
|
+
result = preformatReturn(result);
|
|
169
|
+
}
|
|
170
|
+
return { operation, result };
|
|
171
|
+
}
|
|
172
|
+
// write contract (sign and send)
|
|
173
|
+
if (!this.signer)
|
|
174
|
+
throw new Error("signer not found");
|
|
175
|
+
let tx = await this.signer.prepareTransaction({
|
|
176
|
+
header: {
|
|
177
|
+
...(opts.chainId && { chain_id: opts.chainId }),
|
|
178
|
+
...(opts.rcLimit && { rc_limit: opts.rcLimit }),
|
|
179
|
+
...(opts.nonce && { nonce: opts.nonce }),
|
|
180
|
+
...(opts.payer && { payer: opts.payer }),
|
|
181
|
+
...(opts.payee && { payee: opts.payee }),
|
|
182
|
+
},
|
|
183
|
+
operations: [
|
|
184
|
+
...(opts.previousOperations ? opts.previousOperations : []),
|
|
185
|
+
operation,
|
|
186
|
+
...(opts.nextOperations ? opts.nextOperations : []),
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
if (opts.sendAbis) {
|
|
190
|
+
if (!opts.abis)
|
|
191
|
+
opts.abis = {};
|
|
192
|
+
const contractId = this.getId();
|
|
193
|
+
if (!opts.abis[contractId])
|
|
194
|
+
opts.abis[contractId] = this.abi;
|
|
195
|
+
}
|
|
196
|
+
// return result if the transaction will not be broadcasted
|
|
197
|
+
if (!opts.sendTransaction) {
|
|
198
|
+
const noWait = () => {
|
|
199
|
+
throw new Error("This transaction was not broadcasted");
|
|
200
|
+
};
|
|
201
|
+
if (opts.signTransaction)
|
|
202
|
+
tx = await this.signer.signTransaction(tx, opts.sendAbis ? opts.abis : undefined);
|
|
203
|
+
return { operation, transaction: { ...tx, wait: noWait } };
|
|
204
|
+
}
|
|
205
|
+
const { transaction, receipt } = await this.signer.sendTransaction(tx, opts);
|
|
206
|
+
return { operation, transaction, receipt };
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
174
211
|
/**
|
|
175
212
|
* Function to deploy a new smart contract.
|
|
176
213
|
* The Bytecode must be defined in the constructor of the class
|
|
@@ -224,9 +261,7 @@ class Contract {
|
|
|
224
261
|
...this.options,
|
|
225
262
|
...options,
|
|
226
263
|
};
|
|
227
|
-
const contractId = this.
|
|
228
|
-
? (0, utils_1.encodeBase58)(this.id)
|
|
229
|
-
: this.signer.getAddress();
|
|
264
|
+
const contractId = this.getId();
|
|
230
265
|
const operation = {
|
|
231
266
|
upload_contract: {
|
|
232
267
|
contract_id: contractId,
|
|
@@ -260,20 +295,16 @@ class Contract {
|
|
|
260
295
|
...(opts.nextOperations ? opts.nextOperations : []),
|
|
261
296
|
],
|
|
262
297
|
});
|
|
263
|
-
const optsSend = {
|
|
264
|
-
broadcast: opts.broadcast,
|
|
265
|
-
beforeSend: opts.beforeSend,
|
|
266
|
-
};
|
|
267
298
|
// return result if the transaction will not be broadcasted
|
|
268
299
|
if (!opts.sendTransaction) {
|
|
269
300
|
const noWait = () => {
|
|
270
301
|
throw new Error("This transaction was not broadcasted");
|
|
271
302
|
};
|
|
272
303
|
if (opts.signTransaction)
|
|
273
|
-
tx = await this.signer.signTransaction(tx);
|
|
304
|
+
tx = await this.signer.signTransaction(tx, opts.sendAbis ? opts.abis : undefined);
|
|
274
305
|
return { operation, transaction: { ...tx, wait: noWait } };
|
|
275
306
|
}
|
|
276
|
-
const { transaction, receipt } = await this.signer.sendTransaction(tx,
|
|
307
|
+
const { transaction, receipt } = await this.signer.sendTransaction(tx, opts);
|
|
277
308
|
return { operation, transaction, receipt };
|
|
278
309
|
}
|
|
279
310
|
/**
|
|
@@ -307,8 +338,6 @@ class Contract {
|
|
|
307
338
|
throw new Error(`Operation ${op.name} unknown`);
|
|
308
339
|
if (!this.serializer)
|
|
309
340
|
throw new Error("Serializer is not defined");
|
|
310
|
-
if (!this.id)
|
|
311
|
-
throw new Error("Contract id is not defined");
|
|
312
341
|
const method = this.abi.methods[op.name];
|
|
313
342
|
let bufferArguments = new Uint8Array(0);
|
|
314
343
|
if (method.argument) {
|
|
@@ -318,7 +347,7 @@ class Contract {
|
|
|
318
347
|
}
|
|
319
348
|
return {
|
|
320
349
|
call_contract: {
|
|
321
|
-
contract_id:
|
|
350
|
+
contract_id: this.getId(),
|
|
322
351
|
entry_point: method.entry_point,
|
|
323
352
|
args: (0, utils_1.encodeBase64url)(bufferArguments),
|
|
324
353
|
},
|
|
@@ -347,16 +376,14 @@ class Contract {
|
|
|
347
376
|
* ```
|
|
348
377
|
*/
|
|
349
378
|
async decodeOperation(op) {
|
|
350
|
-
if (!this.id)
|
|
351
|
-
throw new Error("Contract id is not defined");
|
|
352
379
|
if (!this.abi || !this.abi.methods)
|
|
353
380
|
throw new Error("Methods are not defined");
|
|
354
381
|
if (!this.serializer)
|
|
355
382
|
throw new Error("Serializer is not defined");
|
|
356
383
|
if (!op.call_contract)
|
|
357
384
|
throw new Error("Operation is not CallContractOperation");
|
|
358
|
-
if (op.call_contract.contract_id !==
|
|
359
|
-
throw new Error(`Invalid contract id. Expected: ${
|
|
385
|
+
if (op.call_contract.contract_id !== this.getId())
|
|
386
|
+
throw new Error(`Invalid contract id. Expected: ${this.getId()}. Received: ${op.call_contract.contract_id}`);
|
|
360
387
|
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
361
388
|
const opName = Object.keys(this.abi.methods)[i];
|
|
362
389
|
const method = this.abi.methods[opName];
|
|
@@ -371,6 +398,49 @@ class Contract {
|
|
|
371
398
|
}
|
|
372
399
|
throw new Error(`Unknown method id ${op.call_contract.entry_point}`);
|
|
373
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* Decode an event received in a receipt
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* ```ts
|
|
406
|
+
* const contract = new Contract({
|
|
407
|
+
* id: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
408
|
+
* abi: utils.tokenAbi,
|
|
409
|
+
* });
|
|
410
|
+
* const event = {
|
|
411
|
+
* sequence: 1,
|
|
412
|
+
* source: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
413
|
+
* name: "koinos.contracts.token.mint_event",
|
|
414
|
+
* data: "ChkAxjdqxuwS-B50lPQ-lqhRBA3bf2b2ooAHENrw3Ek=",
|
|
415
|
+
* impacted: ["1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J"],
|
|
416
|
+
* };
|
|
417
|
+
* const eventDecoded = await contract.decodeEvent(event);
|
|
418
|
+
* console.log(eventDecoded);
|
|
419
|
+
* // {
|
|
420
|
+
* // sequence: 1,
|
|
421
|
+
* // source: "19JntSm8pSNETT9aHTwAUHC5RMoaSmgZPJ",
|
|
422
|
+
* // name: "koinos.contracts.token.mint_event",
|
|
423
|
+
* // data: "ChkAxjdqxuwS-B50lPQ-lqhRBA3bf2b2ooAHENrw3Ek=",
|
|
424
|
+
* // impacted: ["1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J"],
|
|
425
|
+
* // args: {
|
|
426
|
+
* // to: "1K55BRw87nd64a7aiRarp6DLGRzYvoJo8J",
|
|
427
|
+
* // value: "154613850",
|
|
428
|
+
* // },
|
|
429
|
+
* // }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
async decodeEvent(event) {
|
|
433
|
+
if (!this.serializer)
|
|
434
|
+
throw new Error("Serializer is not defined");
|
|
435
|
+
let typeName = event.name;
|
|
436
|
+
if (this.abi && this.abi.events && this.abi.events[event.name]) {
|
|
437
|
+
typeName = this.abi.events[event.name].argument;
|
|
438
|
+
}
|
|
439
|
+
const args = typeName
|
|
440
|
+
? await this.serializer.deserialize(event.data, typeName)
|
|
441
|
+
: {};
|
|
442
|
+
return { ...event, args };
|
|
443
|
+
}
|
|
374
444
|
}
|
|
375
445
|
exports.Contract = Contract;
|
|
376
446
|
exports.default = Contract;
|
package/lib/Contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":";;;AAGA,6CAA0C;AAW1C,mCAAsE;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDG;AACH,MAAa,QAAQ;IAgFnB,YAAY,CAcX;;QACC,IAAI,CAAC,CAAC,EAAE;YAAE,IAAI,CAAC,EAAE,GAAG,IAAA,oBAAY,EAAC,CAAC,CAAC,EAAE,CAAC,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,KAAI,MAAA,CAAC,CAAC,MAAM,0CAAE,QAAQ,CAAA,CAAC;QACjD,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3B,IAAI,CAAC,CAAC,UAAU,EAAE;YAChB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;SAChC;aAAM,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,YAAY,EAAE;YACtC,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;SACtD;QACD,IAAI,CAAC,OAAO,GAAG;YACb,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,IAAI;YACrB,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,IAAI;YACd,GAAG,CAAC,CAAC,OAAO;SACb,CAAC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AI,CAAC,EAAE;YAC9D,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,QAAkB,CAAC;SAC3D;QACD,MAAM,IAAI,GAAG,QAAQ;YACnB,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;YACzD,CAAC,CAAC,EAAE,CAAC;QACP,OAAO,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE,CAAC;IAC5B,CAAC;CACF;AAnhBD,4BAmhBC;AAED,kBAAe,QAAQ,CAAC"}
|
package/lib/Serializer.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Root, Type, INamespace } from "protobufjs
|
|
1
|
+
import { Root, Type, INamespace } from "protobufjs";
|
|
2
2
|
/**
|
|
3
3
|
* The serializer class serialize and deserialize data using
|
|
4
|
-
* protocol buffers.
|
|
4
|
+
* protocol buffers. It accepts the descriptor in JSON or binary format
|
|
5
5
|
*
|
|
6
|
-
* NOTE: This class uses the [protobufjs
|
|
6
|
+
* NOTE: This class uses the [protobufjs](https://www.npmjs.com/package/protobufjs)
|
|
7
7
|
* library internally, which uses reflection (use of _eval_
|
|
8
8
|
* and _new Function_) for the construction of the types.
|
|
9
9
|
* This could cause issues in environments where _eval_ is not
|
|
@@ -15,23 +15,44 @@ import { Root, Type, INamespace } from "protobufjs/light";
|
|
|
15
15
|
* @example
|
|
16
16
|
*
|
|
17
17
|
* ```ts
|
|
18
|
+
* // using descriptor JSON
|
|
18
19
|
* const descriptorJson = {
|
|
19
20
|
* nested: {
|
|
20
21
|
* awesomepackage: {
|
|
21
22
|
* nested: {
|
|
22
23
|
* AwesomeMessage: {
|
|
23
24
|
* fields: {
|
|
24
|
-
*
|
|
25
|
+
* awesome_field: {
|
|
25
26
|
* type: "string",
|
|
26
|
-
* id: 1
|
|
27
|
-
* }
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
* }
|
|
32
|
-
* }
|
|
33
|
-
* }
|
|
34
|
-
* const
|
|
27
|
+
* id: 1,
|
|
28
|
+
* },
|
|
29
|
+
* },
|
|
30
|
+
* },
|
|
31
|
+
* },
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* };
|
|
35
|
+
* const serializer1 = new Serializer(descriptorJson);
|
|
36
|
+
* const message1 = await serializer1.deserialize(
|
|
37
|
+
* "CgZrb2lub3M=",
|
|
38
|
+
* "AwesomeMessage"
|
|
39
|
+
* );
|
|
40
|
+
* console.log(message1);
|
|
41
|
+
* // { awesome_field: 'koinos' }
|
|
42
|
+
*
|
|
43
|
+
* // using descriptor binary
|
|
44
|
+
* const descriptorBinary =
|
|
45
|
+
* "Cl4KDWF3ZXNvbWUucHJvdG8SDmF3ZXNvbWVwYWN" +
|
|
46
|
+
* "rYWdlIjUKDkF3ZXNvbWVNZXNzYWdlEiMKDWF3ZX" +
|
|
47
|
+
* "NvbWVfZmllbGQYASABKAlSDGF3ZXNvbWVGaWVsZ" +
|
|
48
|
+
* "GIGcHJvdG8z";
|
|
49
|
+
* const serializer2 = new Serializer(descriptorBinary);
|
|
50
|
+
* const message2 = await serializer2.deserialize(
|
|
51
|
+
* "CgZrb2lub3M=",
|
|
52
|
+
* "AwesomeMessage"
|
|
53
|
+
* );
|
|
54
|
+
* console.log(message2);
|
|
55
|
+
* // { awesome_field: 'koinos' }
|
|
35
56
|
* ```
|
|
36
57
|
*/
|
|
37
58
|
export declare class Serializer {
|
|
@@ -39,7 +60,7 @@ export declare class Serializer {
|
|
|
39
60
|
* Protobuffers descriptor in JSON format.
|
|
40
61
|
* See https://www.npmjs.com/package/protobufjs#using-json-descriptors
|
|
41
62
|
*/
|
|
42
|
-
types: INamespace;
|
|
63
|
+
types: INamespace | string;
|
|
43
64
|
/**
|
|
44
65
|
* Protobuffer definitions
|
|
45
66
|
*/
|
|
@@ -60,7 +81,7 @@ export declare class Serializer {
|
|
|
60
81
|
serialize: boolean;
|
|
61
82
|
deserialize: boolean;
|
|
62
83
|
};
|
|
63
|
-
constructor(types: INamespace, opts?: {
|
|
84
|
+
constructor(types: INamespace | string, opts?: {
|
|
64
85
|
/**
|
|
65
86
|
* Default type name. Use this option when you
|
|
66
87
|
* always want to serialize/deserialize the same type
|