koilib 3.1.1 → 4.0.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 +23 -20
- package/dist/koinos.js +56 -51
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +6 -6
- package/lib/Contract.js +22 -22
- package/lib/Contract.js.map +1 -1
- package/lib/Signer.js +1 -1
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +6 -6
- package/lib/browser/Contract.js +22 -22
- package/lib/browser/Contract.js.map +1 -1
- package/lib/browser/Signer.js +1 -1
- package/lib/browser/Signer.js.map +1 -1
- package/lib/browser/interface.d.ts +24 -24
- package/lib/browser/utils.js +33 -28
- package/lib/browser/utils.js.map +1 -1
- package/lib/interface.d.ts +24 -24
- package/lib/utils.js +33 -28
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -99,10 +99,12 @@ a transaction, and read contracts.
|
|
|
99
99
|
const koin = koinContract.functions;
|
|
100
100
|
|
|
101
101
|
// optional: preformat input/output
|
|
102
|
-
koinContract.abi.methods.balanceOf.
|
|
103
|
-
|
|
102
|
+
koinContract.abi.methods.balanceOf.preformat_argument = (owner) => ({
|
|
103
|
+
owner,
|
|
104
|
+
});
|
|
105
|
+
koinContract.abi.methods.balanceOf.preformat_return = (res) =>
|
|
104
106
|
utils.formatUnits(res.value, 8);
|
|
105
|
-
koinContract.abi.methods.transfer.
|
|
107
|
+
koinContract.abi.methods.transfer.preformat_argument = (input) => ({
|
|
106
108
|
from: signer.getAddress(),
|
|
107
109
|
to: input.to,
|
|
108
110
|
value: utils.parseUnits(input.value, 8),
|
|
@@ -222,28 +224,28 @@ const tokenJson = require("./token-proto.json");
|
|
|
222
224
|
const abiToken = {
|
|
223
225
|
methods: {
|
|
224
226
|
balanceOf: {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
227
|
+
entry_point: 0x5c721497,
|
|
228
|
+
argument: "balance_of_arguments",
|
|
229
|
+
return: "balance_of_result",
|
|
230
|
+
read_only: true,
|
|
231
|
+
default_output: { value: "0" },
|
|
230
232
|
},
|
|
231
233
|
transfer: {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
entry_point: 0x27f576ca,
|
|
235
|
+
argument: "transfer_arguments",
|
|
236
|
+
return: "transfer_result",
|
|
235
237
|
},
|
|
236
238
|
mint: {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
entry_point: 0xdc6f17bb,
|
|
240
|
+
argument: "mint_argumnets",
|
|
241
|
+
return: "mint_result",
|
|
240
242
|
},
|
|
241
243
|
},
|
|
242
|
-
|
|
244
|
+
koilib_types: tokenJson,
|
|
243
245
|
};
|
|
244
246
|
```
|
|
245
247
|
|
|
246
|
-
Note that this example uses "
|
|
248
|
+
Note that this example uses "default_output" for the method
|
|
247
249
|
"balanceOf". This is used when the smart contract returns an
|
|
248
250
|
empty response (for instance when there are no balance records
|
|
249
251
|
for a specific address) and you require a default output in
|
|
@@ -267,13 +269,14 @@ such cases.
|
|
|
267
269
|
For the ABI you need the .proto file and the library
|
|
268
270
|
[protobufjs](https://www.npmjs.com/package/protobufjs). Then follow the format
|
|
269
271
|
for the ABI as described in the previous section. It's important to note that
|
|
270
|
-
this ABI
|
|
271
|
-
In particular,
|
|
272
|
-
|
|
272
|
+
this ABI has a diffence with respect to the ABI used in [koinos-cli](https://docs.koinos.io/architecture/contract-abi.html).
|
|
273
|
+
In particular, koilib takes the descriptor from `koilib_types`, which is a
|
|
274
|
+
descriptor in json format, while the ABI in koinos-cli takes the descriptor from
|
|
275
|
+
`types`, which is a descriptor in binary format.
|
|
273
276
|
|
|
274
277
|
4. Can this library be used to interact with smart contracts?
|
|
275
278
|
|
|
276
|
-
Yes. You can use it to call
|
|
279
|
+
Yes. You can use it to call read_only functions, or send transactions
|
|
277
280
|
to the contract by calling write functions.
|
|
278
281
|
|
|
279
282
|
## Documentation
|
package/dist/koinos.js
CHANGED
|
@@ -9791,15 +9791,15 @@ const utils_1 = __webpack_require__(8593);
|
|
|
9791
9791
|
* });
|
|
9792
9792
|
* const koin = koinContract.functions;
|
|
9793
9793
|
*
|
|
9794
|
-
* // optional: preformat
|
|
9795
|
-
* koinContract.abi.methods.balanceOf.
|
|
9794
|
+
* // optional: preformat argument/return
|
|
9795
|
+
* koinContract.abi.methods.balanceOf.preformat_argument = (owner) =>
|
|
9796
9796
|
* ({ owner });
|
|
9797
|
-
* koinContract.abi.methods.balanceOf.
|
|
9797
|
+
* koinContract.abi.methods.balanceOf.preformat_return = (res) =>
|
|
9798
9798
|
* utils.formatUnits(res.value, 8);
|
|
9799
|
-
* koinContract.abi.methods.transfer.
|
|
9799
|
+
* koinContract.abi.methods.transfer.preformat_argument = (arg) => ({
|
|
9800
9800
|
* from: signer.getAddress(),
|
|
9801
|
-
* to:
|
|
9802
|
-
* value: utils.parseUnits(
|
|
9801
|
+
* to: arg.to,
|
|
9802
|
+
* value: utils.parseUnits(arg.value, 8),
|
|
9803
9803
|
* });
|
|
9804
9804
|
*
|
|
9805
9805
|
* async funtion main() {
|
|
@@ -9839,8 +9839,8 @@ class Contract {
|
|
|
9839
9839
|
if (c.serializer) {
|
|
9840
9840
|
this.serializer = c.serializer;
|
|
9841
9841
|
}
|
|
9842
|
-
else if (c.abi && c.abi.
|
|
9843
|
-
this.serializer = new Serializer_1.Serializer(c.abi.
|
|
9842
|
+
else if (c.abi && c.abi.koilib_types) {
|
|
9843
|
+
this.serializer = new Serializer_1.Serializer(c.abi.koilib_types);
|
|
9844
9844
|
}
|
|
9845
9845
|
this.options = {
|
|
9846
9846
|
signTransaction: true,
|
|
@@ -9866,10 +9866,10 @@ class Contract {
|
|
|
9866
9866
|
...this.options,
|
|
9867
9867
|
...options,
|
|
9868
9868
|
};
|
|
9869
|
-
const { readOnly, output, defaultOutput,
|
|
9869
|
+
const { read_only: readOnly, return: output, default_output: defaultOutput, preformat_argument: preformatArgument, preformat_return: preformatReturn, } = this.abi.methods[name];
|
|
9870
9870
|
let args;
|
|
9871
|
-
if (typeof
|
|
9872
|
-
args =
|
|
9871
|
+
if (typeof preformatArgument === "function") {
|
|
9872
|
+
args = preformatArgument(argu);
|
|
9873
9873
|
}
|
|
9874
9874
|
else {
|
|
9875
9875
|
args = argu;
|
|
@@ -9884,8 +9884,8 @@ class Contract {
|
|
|
9884
9884
|
if (resultEncoded) {
|
|
9885
9885
|
result = await this.serializer.deserialize(resultEncoded, output);
|
|
9886
9886
|
}
|
|
9887
|
-
if (typeof
|
|
9888
|
-
result =
|
|
9887
|
+
if (typeof preformatReturn === "function") {
|
|
9888
|
+
result = preformatReturn(result);
|
|
9889
9889
|
}
|
|
9890
9890
|
return { operation, result };
|
|
9891
9891
|
}
|
|
@@ -10061,17 +10061,17 @@ class Contract {
|
|
|
10061
10061
|
if (!this.id)
|
|
10062
10062
|
throw new Error("Contract id is not defined");
|
|
10063
10063
|
const method = this.abi.methods[op.name];
|
|
10064
|
-
let
|
|
10065
|
-
if (method.
|
|
10064
|
+
let bufferArguments = new Uint8Array(0);
|
|
10065
|
+
if (method.argument) {
|
|
10066
10066
|
if (!op.args)
|
|
10067
|
-
throw new Error(`No arguments defined for type '${method.
|
|
10068
|
-
|
|
10067
|
+
throw new Error(`No arguments defined for type '${method.argument}'`);
|
|
10068
|
+
bufferArguments = await this.serializer.serialize(op.args, method.argument);
|
|
10069
10069
|
}
|
|
10070
10070
|
return {
|
|
10071
10071
|
call_contract: {
|
|
10072
10072
|
contract_id: (0, utils_1.encodeBase58)(this.id),
|
|
10073
|
-
entry_point: method.
|
|
10074
|
-
args: (0, utils_1.encodeBase64url)(
|
|
10073
|
+
entry_point: method.entry_point,
|
|
10074
|
+
args: (0, utils_1.encodeBase64url)(bufferArguments),
|
|
10075
10075
|
},
|
|
10076
10076
|
};
|
|
10077
10077
|
}
|
|
@@ -10111,12 +10111,12 @@ class Contract {
|
|
|
10111
10111
|
for (let i = 0; i < Object.keys(this.abi.methods).length; i += 1) {
|
|
10112
10112
|
const opName = Object.keys(this.abi.methods)[i];
|
|
10113
10113
|
const method = this.abi.methods[opName];
|
|
10114
|
-
if (op.call_contract.entry_point === method.
|
|
10115
|
-
if (!method.
|
|
10114
|
+
if (op.call_contract.entry_point === method.entry_point) {
|
|
10115
|
+
if (!method.argument)
|
|
10116
10116
|
return { name: opName };
|
|
10117
10117
|
return {
|
|
10118
10118
|
name: opName,
|
|
10119
|
-
args: await this.serializer.deserialize(op.call_contract.args, method.
|
|
10119
|
+
args: await this.serializer.deserialize(op.call_contract.args, method.argument),
|
|
10120
10120
|
};
|
|
10121
10121
|
}
|
|
10122
10122
|
}
|
|
@@ -10868,7 +10868,7 @@ class Signer {
|
|
|
10868
10868
|
* // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
|
|
10869
10869
|
* ```
|
|
10870
10870
|
*/
|
|
10871
|
-
getPrivateKey(format = "hex", compressed) {
|
|
10871
|
+
getPrivateKey(format = "hex", compressed = false) {
|
|
10872
10872
|
let stringPrivateKey;
|
|
10873
10873
|
if (this.privateKey instanceof Uint8Array) {
|
|
10874
10874
|
stringPrivateKey = (0, utils_1.toHexString)(this.privateKey);
|
|
@@ -11695,48 +11695,53 @@ exports.btypeEncode = btypeEncode;
|
|
|
11695
11695
|
exports.tokenAbi = {
|
|
11696
11696
|
methods: {
|
|
11697
11697
|
name: {
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11698
|
+
entry_point: 0x82a3537f,
|
|
11699
|
+
argument: "name_arguments",
|
|
11700
|
+
return: "name_result",
|
|
11701
|
+
read_only: true,
|
|
11702
11702
|
},
|
|
11703
11703
|
symbol: {
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
|
|
11707
|
-
|
|
11704
|
+
entry_point: 0xb76a7ca1,
|
|
11705
|
+
argument: "symbol_arguments",
|
|
11706
|
+
return: "symbol_result",
|
|
11707
|
+
read_only: true,
|
|
11708
11708
|
},
|
|
11709
11709
|
decimals: {
|
|
11710
|
-
|
|
11711
|
-
|
|
11712
|
-
|
|
11713
|
-
|
|
11710
|
+
entry_point: 0xee80fd2f,
|
|
11711
|
+
argument: "decimals_arguments",
|
|
11712
|
+
return: "decimals_result",
|
|
11713
|
+
read_only: true,
|
|
11714
11714
|
},
|
|
11715
11715
|
totalSupply: {
|
|
11716
|
-
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
|
|
11716
|
+
entry_point: 0xb0da3934,
|
|
11717
|
+
argument: "total_supply_arguments",
|
|
11718
|
+
return: "total_supply_result",
|
|
11719
|
+
read_only: true,
|
|
11720
11720
|
},
|
|
11721
11721
|
balanceOf: {
|
|
11722
|
-
|
|
11723
|
-
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11722
|
+
entry_point: 0x5c721497,
|
|
11723
|
+
argument: "balance_of_arguments",
|
|
11724
|
+
return: "balance_of_result",
|
|
11725
|
+
read_only: true,
|
|
11726
|
+
default_output: { value: "0" },
|
|
11727
11727
|
},
|
|
11728
11728
|
transfer: {
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
11729
|
+
entry_point: 0x27f576ca,
|
|
11730
|
+
argument: "transfer_arguments",
|
|
11731
|
+
return: "transfer_result",
|
|
11732
11732
|
},
|
|
11733
11733
|
mint: {
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11734
|
+
entry_point: 0xdc6f17bb,
|
|
11735
|
+
argument: "mint_arguments",
|
|
11736
|
+
return: "mint_result",
|
|
11737
|
+
},
|
|
11738
|
+
burn: {
|
|
11739
|
+
entry_point: 0x859facc5,
|
|
11740
|
+
argument: "burn_arguments",
|
|
11741
|
+
return: "burn_result",
|
|
11737
11742
|
},
|
|
11738
11743
|
},
|
|
11739
|
-
|
|
11744
|
+
koilib_types: token_proto_json_1.default,
|
|
11740
11745
|
};
|
|
11741
11746
|
//export const ProtocolTypes = protocolJson;
|
|
11742
11747
|
|