@caict/bop-typescript-sdk 1.0.2 → 1.0.3
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/CHANGELOG.md +34 -0
- package/base.tsconfig.json +14 -0
- package/dist/bop/bop-base/base.d.ts +24 -0
- package/dist/bop/bop-base/base.js +253 -0
- package/dist/bop/bop-base/base.js.map +1 -0
- package/dist/bop/bop-base/index.d.ts +18 -0
- package/dist/bop/bop-base/index.js +69 -0
- package/dist/bop/bop-base/index.js.map +1 -0
- package/dist/bop/bop-base/permit.d.ts +11 -0
- package/dist/bop/bop-base/permit.js +104 -0
- package/dist/bop/bop-base/permit.js.map +1 -0
- package/dist/bop/bop-base/test/base.test.d.ts +1 -0
- package/dist/bop/bop-base/test/base.test.js +772 -0
- package/dist/bop/bop-base/test/base.test.js.map +1 -0
- package/dist/bop/bop-base/test/index.test.d.ts +1 -0
- package/dist/bop/bop-base/test/index.test.js +89 -0
- package/dist/bop/bop-base/test/index.test.js.map +1 -0
- package/dist/bop/bop-base/test/permit.test.d.ts +1 -0
- package/dist/bop/bop-base/test/permit.test.js +140 -0
- package/dist/bop/bop-base/test/permit.test.js.map +1 -0
- package/dist/bop/bop-proto/bop-ws.d.ts +325 -0
- package/dist/bop/bop-proto/bop-ws.js +3599 -0
- package/dist/bop/bop-proto/bop-ws.js.map +1 -0
- package/dist/bop/bop-proto/bop.d.ts +903 -0
- package/dist/bop/bop-proto/bop.js +10421 -0
- package/dist/bop/bop-proto/bop.js.map +1 -0
- package/dist/bop/bop-ws/index.d.ts +43 -0
- package/dist/bop/bop-ws/index.js +265 -0
- package/dist/bop/bop-ws/index.js.map +1 -0
- package/dist/bop/bop-ws/sample/sample.d.ts +1 -0
- package/dist/bop/bop-ws/sample/sample.js +96 -0
- package/dist/bop/bop-ws/sample/sample.js.map +1 -0
- package/dist/bop/index.d.ts +5 -0
- package/dist/bop/index.js +37 -0
- package/dist/bop/index.js.map +1 -0
- package/dist/bop-sdk/index.d.ts +13 -0
- package/dist/bop-sdk/index.js +45 -0
- package/dist/bop-sdk/index.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-account.d.ts +8 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-account.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-account.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-chain.d.ts +5 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-chain.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-chain.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-contract.d.ts +6 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-contract.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-contract.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-ledger.d.ts +8 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-ledger.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-provider.d.ts +12 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-provider.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-provider.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-signer.d.ts +17 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-signer.js +109 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-signer.js.map +1 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-transaction.d.ts +17 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js +7 -0
- package/dist/bop-sdk/interface/abstract-service/abstract-transaction.js.map +1 -0
- package/dist/bop-sdk/interface/provider-ws.d.ts +5 -0
- package/dist/bop-sdk/interface/provider-ws.js +12 -0
- package/dist/bop-sdk/interface/provider-ws.js.map +1 -0
- package/dist/bop-sdk/interface/provider.d.ts +7 -0
- package/dist/bop-sdk/interface/provider.js +23 -0
- package/dist/bop-sdk/interface/provider.js.map +1 -0
- package/dist/bop-sdk/interface/service/3rd.d.ts +12 -0
- package/dist/bop-sdk/interface/service/3rd.js +49 -0
- package/dist/bop-sdk/interface/service/3rd.js.map +1 -0
- package/dist/bop-sdk/interface/service/account.d.ts +12 -0
- package/dist/bop-sdk/interface/service/account.js +98 -0
- package/dist/bop-sdk/interface/service/account.js.map +1 -0
- package/dist/bop-sdk/interface/service/chain.d.ts +9 -0
- package/dist/bop-sdk/interface/service/chain.js +55 -0
- package/dist/bop-sdk/interface/service/chain.js.map +1 -0
- package/dist/bop-sdk/interface/service/contract.d.ts +10 -0
- package/dist/bop-sdk/interface/service/contract.js +67 -0
- package/dist/bop-sdk/interface/service/contract.js.map +1 -0
- package/dist/bop-sdk/interface/service/helper.d.ts +20 -0
- package/dist/bop-sdk/interface/service/helper.js +383 -0
- package/dist/bop-sdk/interface/service/helper.js.map +1 -0
- package/dist/bop-sdk/interface/service/ledger.d.ts +12 -0
- package/dist/bop-sdk/interface/service/ledger.js +89 -0
- package/dist/bop-sdk/interface/service/ledger.js.map +1 -0
- package/dist/bop-sdk/interface/service/offline/check/index.js +138 -0
- package/dist/bop-sdk/interface/service/offline/common/constant.js +6 -0
- package/dist/bop-sdk/interface/service/offline/common/snowFlakeUtils.js +192 -0
- package/dist/bop-sdk/interface/service/offline/common/util.js +511 -0
- package/dist/bop-sdk/interface/service/offline/exception/customErrors.js +29 -0
- package/dist/bop-sdk/interface/service/offline/exception/errors.js +90 -0
- package/dist/bop-sdk/interface/service/offline/exception/index.js +5 -0
- package/dist/bop-sdk/interface/service/offline/operation/accountCreateOperation.js +28 -0
- package/dist/bop-sdk/interface/service/offline/operation/accountSetMetadataOperation.js +44 -0
- package/dist/bop-sdk/interface/service/offline/operation/accountSetPrivilegeOperation.js +49 -0
- package/dist/bop-sdk/interface/service/offline/operation/contractCreateOperation.js +43 -0
- package/dist/bop-sdk/interface/service/offline/operation/contractInvokeOperation.js +42 -0
- package/dist/bop-sdk/interface/service/offline/operation/contractInvokeRequestOperation.js +69 -0
- package/dist/bop-sdk/interface/service/offline/operation/gasSendOperation.js +29 -0
- package/dist/bop-sdk/interface/service/offline/operation/gasSendRequestOperation.js +61 -0
- package/dist/bop-sdk/interface/service/offline/operation/index.js +20 -0
- package/dist/bop-sdk/interface/service/offline/proto/chain_pb.js +12079 -0
- package/dist/bop-sdk/interface/service/offline/proto/common_pb.js +2867 -0
- package/dist/bop-sdk/interface/service/offline/transaction/index.js +988 -0
- package/dist/bop-sdk/interface/service/offline/transaction/operations.js +188 -0
- package/dist/bop-sdk/interface/service/offline/validate/account.js +152 -0
- package/dist/bop-sdk/interface/service/offline/validate/contract.js +101 -0
- package/dist/bop-sdk/interface/service/offline/validate/index.js +10 -0
- package/dist/bop-sdk/interface/service/offline/validate/transaction.js +51 -0
- package/dist/bop-sdk/interface/service/transaction.d.ts +21 -0
- package/dist/bop-sdk/interface/service/transaction.js +591 -0
- package/dist/bop-sdk/interface/service/transaction.js.map +1 -0
- package/dist/bop-sdk/interface/signer.d.ts +12 -0
- package/dist/bop-sdk/interface/signer.js +53 -0
- package/dist/bop-sdk/interface/signer.js.map +1 -0
- package/dist/bop-sdk/interface/test/3rd.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/3rd.test.js +1524 -0
- package/dist/bop-sdk/interface/test/3rd.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/account.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/account.test.js +225 -0
- package/dist/bop-sdk/interface/test/account.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/chain.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/chain.test.js +72 -0
- package/dist/bop-sdk/interface/test/chain.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/contract.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/contract.test.js +266 -0
- package/dist/bop-sdk/interface/test/contract.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/ledger.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/ledger.test.js +167 -0
- package/dist/bop-sdk/interface/test/ledger.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/provider.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/provider.test.js +295 -0
- package/dist/bop-sdk/interface/test/provider.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/signer.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/signer.test.js +87 -0
- package/dist/bop-sdk/interface/test/signer.test.js.map +1 -0
- package/dist/bop-sdk/interface/test/transaction.test.d.ts +1 -0
- package/dist/bop-sdk/interface/test/transaction.test.js +663 -0
- package/dist/bop-sdk/interface/test/transaction.test.js.map +1 -0
- package/dist/bop-sdk/proto/bop-sdk-common.d.ts +225 -0
- package/dist/bop-sdk/proto/bop-sdk-common.js +831 -0
- package/dist/bop-sdk/proto/bop-sdk-common.js.map +1 -0
- package/dist/bop-sdk/proto/bop-sdk-interface.d.ts +623 -0
- package/dist/bop-sdk/proto/bop-sdk-interface.js +8623 -0
- package/dist/bop-sdk/proto/bop-sdk-interface.js.map +1 -0
- package/dist/bop-sdk/proto/bop-sdk-utils.d.ts +107 -0
- package/dist/bop-sdk/proto/bop-sdk-utils.js +1160 -0
- package/dist/bop-sdk/proto/bop-sdk-utils.js.map +1 -0
- package/dist/bop-sdk/utils/abi/abi-coder.d.ts +16 -0
- package/dist/bop-sdk/utils/abi/abi-coder.js +101 -0
- package/dist/bop-sdk/utils/abi/abi-coder.js.map +1 -0
- package/dist/bop-sdk/utils/abi/address.d.ts +8 -0
- package/dist/bop-sdk/utils/abi/address.js +116 -0
- package/dist/bop-sdk/utils/abi/address.js.map +1 -0
- package/dist/bop-sdk/utils/abi/bignumber.d.ts +39 -0
- package/dist/bop-sdk/utils/abi/bignumber.js +316 -0
- package/dist/bop-sdk/utils/abi/bignumber.js.map +1 -0
- package/dist/bop-sdk/utils/abi/bytes.d.ts +41 -0
- package/dist/bop-sdk/utils/abi/bytes.js +423 -0
- package/dist/bop-sdk/utils/abi/bytes.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/abstract-coder.d.ts +52 -0
- package/dist/bop-sdk/utils/abi/coders/abstract-coder.js +164 -0
- package/dist/bop-sdk/utils/abi/coders/abstract-coder.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/address.d.ts +7 -0
- package/dist/bop-sdk/utils/abi/coders/address.js +52 -0
- package/dist/bop-sdk/utils/abi/coders/address.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/anonymous.d.ts +8 -0
- package/dist/bop-sdk/utils/abi/coders/anonymous.js +22 -0
- package/dist/bop-sdk/utils/abi/coders/anonymous.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/array.d.ts +13 -0
- package/dist/bop-sdk/utils/abi/coders/array.js +220 -0
- package/dist/bop-sdk/utils/abi/coders/array.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/boolean.d.ts +7 -0
- package/dist/bop-sdk/utils/abi/coders/boolean.js +20 -0
- package/dist/bop-sdk/utils/abi/coders/boolean.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/bytes.d.ts +11 -0
- package/dist/bop-sdk/utils/abi/coders/bytes.js +33 -0
- package/dist/bop-sdk/utils/abi/coders/bytes.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/fixed-bytes.d.ts +9 -0
- package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js +28 -0
- package/dist/bop-sdk/utils/abi/coders/fixed-bytes.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/null.d.ts +7 -0
- package/dist/bop-sdk/utils/abi/coders/null.js +24 -0
- package/dist/bop-sdk/utils/abi/coders/null.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/number.d.ts +10 -0
- package/dist/bop-sdk/utils/abi/coders/number.js +45 -0
- package/dist/bop-sdk/utils/abi/coders/number.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/string.d.ts +8 -0
- package/dist/bop-sdk/utils/abi/coders/string.js +21 -0
- package/dist/bop-sdk/utils/abi/coders/string.js.map +1 -0
- package/dist/bop-sdk/utils/abi/coders/tuple.d.ts +10 -0
- package/dist/bop-sdk/utils/abi/coders/tuple.js +60 -0
- package/dist/bop-sdk/utils/abi/coders/tuple.js.map +1 -0
- package/dist/bop-sdk/utils/abi/constants/addresses.d.ts +1 -0
- package/dist/bop-sdk/utils/abi/constants/addresses.js +5 -0
- package/dist/bop-sdk/utils/abi/constants/addresses.js.map +1 -0
- package/dist/bop-sdk/utils/abi/constants/bignumbers.d.ts +10 -0
- package/dist/bop-sdk/utils/abi/constants/bignumbers.js +21 -0
- package/dist/bop-sdk/utils/abi/constants/bignumbers.js.map +1 -0
- package/dist/bop-sdk/utils/abi/constants/hashes.d.ts +1 -0
- package/dist/bop-sdk/utils/abi/constants/hashes.js +5 -0
- package/dist/bop-sdk/utils/abi/constants/hashes.js.map +1 -0
- package/dist/bop-sdk/utils/abi/constants/index.d.ts +4 -0
- package/dist/bop-sdk/utils/abi/constants/index.js +19 -0
- package/dist/bop-sdk/utils/abi/constants/index.js.map +1 -0
- package/dist/bop-sdk/utils/abi/constants/strings.d.ts +1 -0
- package/dist/bop-sdk/utils/abi/constants/strings.js +6 -0
- package/dist/bop-sdk/utils/abi/constants/strings.js.map +1 -0
- package/dist/bop-sdk/utils/abi/fragments.d.ts +84 -0
- package/dist/bop-sdk/utils/abi/fragments.js +919 -0
- package/dist/bop-sdk/utils/abi/fragments.js.map +1 -0
- package/dist/bop-sdk/utils/abi/id.d.ts +1 -0
- package/dist/bop-sdk/utils/abi/id.js +10 -0
- package/dist/bop-sdk/utils/abi/id.js.map +1 -0
- package/dist/bop-sdk/utils/abi/index.d.ts +4 -0
- package/dist/bop-sdk/utils/abi/index.js +21 -0
- package/dist/bop-sdk/utils/abi/index.js.map +1 -0
- package/dist/bop-sdk/utils/abi/interface.d.ts +83 -0
- package/dist/bop-sdk/utils/abi/interface.js +663 -0
- package/dist/bop-sdk/utils/abi/interface.js.map +1 -0
- package/dist/bop-sdk/utils/abi/keccak256.d.ts +2 -0
- package/dist/bop-sdk/utils/abi/keccak256.js +13 -0
- package/dist/bop-sdk/utils/abi/keccak256.js.map +1 -0
- package/dist/bop-sdk/utils/abi/properties.d.ts +16 -0
- package/dist/bop-sdk/utils/abi/properties.js +141 -0
- package/dist/bop-sdk/utils/abi/properties.js.map +1 -0
- package/dist/bop-sdk/utils/abi/strings/bytes32.d.ts +3 -0
- package/dist/bop-sdk/utils/abi/strings/bytes32.js +36 -0
- package/dist/bop-sdk/utils/abi/strings/bytes32.js.map +1 -0
- package/dist/bop-sdk/utils/abi/strings/idna.d.ts +4 -0
- package/dist/bop-sdk/utils/abi/strings/idna.js +200 -0
- package/dist/bop-sdk/utils/abi/strings/idna.js.map +1 -0
- package/dist/bop-sdk/utils/abi/strings/index.d.ts +4 -0
- package/dist/bop-sdk/utils/abi/strings/index.js +17 -0
- package/dist/bop-sdk/utils/abi/strings/index.js.map +1 -0
- package/dist/bop-sdk/utils/abi/strings/utf8.d.ts +26 -0
- package/dist/bop-sdk/utils/abi/strings/utf8.js +265 -0
- package/dist/bop-sdk/utils/abi/strings/utf8.js.map +1 -0
- package/dist/bop-sdk/utils/encryption-address.d.ts +25 -0
- package/dist/bop-sdk/utils/encryption-address.js +426 -0
- package/dist/bop-sdk/utils/encryption-address.js.map +1 -0
- package/dist/bop-sdk/utils/encryption-crypto.d.ts +16 -0
- package/dist/bop-sdk/utils/encryption-crypto.js +406 -0
- package/dist/bop-sdk/utils/encryption-crypto.js.map +1 -0
- package/dist/bop-sdk/utils/encryption-mnemonics.d.ts +7 -0
- package/dist/bop-sdk/utils/encryption-mnemonics.js +129 -0
- package/dist/bop-sdk/utils/encryption-mnemonics.js.map +1 -0
- package/dist/bop-sdk/utils/index.d.ts +13 -0
- package/dist/bop-sdk/utils/index.js +22 -0
- package/dist/bop-sdk/utils/index.js.map +1 -0
- package/dist/bop-sdk/utils/logger.d.ts +52 -0
- package/dist/bop-sdk/utils/logger.js +377 -0
- package/dist/bop-sdk/utils/logger.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +92 -88
- package/tsconfig.json +24 -0
|
@@ -0,0 +1,663 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Interface = exports.Indexed = exports.ErrorDescription = exports.TransactionDescription = exports.LogDescription = exports.checkResultErrors = void 0;
|
|
4
|
+
const address_1 = require("./address");
|
|
5
|
+
const bytes_1 = require("./bytes");
|
|
6
|
+
const id_1 = require("./id");
|
|
7
|
+
const keccak256_1 = require("./keccak256");
|
|
8
|
+
const properties_1 = require("./properties");
|
|
9
|
+
const abi_coder_1 = require("./abi-coder");
|
|
10
|
+
const abstract_coder_1 = require("./coders/abstract-coder");
|
|
11
|
+
Object.defineProperty(exports, "checkResultErrors", { enumerable: true, get: function () { return abstract_coder_1.checkResultErrors; } });
|
|
12
|
+
const fragments_1 = require("./fragments");
|
|
13
|
+
const logger_1 = require("../logger");
|
|
14
|
+
const version = "interface/5.7.0";
|
|
15
|
+
const logger = new logger_1.Logger(version);
|
|
16
|
+
class LogDescription extends properties_1.Description {
|
|
17
|
+
}
|
|
18
|
+
exports.LogDescription = LogDescription;
|
|
19
|
+
class TransactionDescription extends properties_1.Description {
|
|
20
|
+
}
|
|
21
|
+
exports.TransactionDescription = TransactionDescription;
|
|
22
|
+
class ErrorDescription extends properties_1.Description {
|
|
23
|
+
}
|
|
24
|
+
exports.ErrorDescription = ErrorDescription;
|
|
25
|
+
class Indexed extends properties_1.Description {
|
|
26
|
+
static isIndexed(value) {
|
|
27
|
+
return !!(value && value._isIndexed);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.Indexed = Indexed;
|
|
31
|
+
const BuiltinErrors = {
|
|
32
|
+
"0x08c379a0": {
|
|
33
|
+
signature: "Error(string)",
|
|
34
|
+
name: "Error",
|
|
35
|
+
inputs: ["string"],
|
|
36
|
+
reason: true,
|
|
37
|
+
},
|
|
38
|
+
"0x4e487b71": {
|
|
39
|
+
signature: "Panic(uint256)",
|
|
40
|
+
name: "Panic",
|
|
41
|
+
inputs: ["uint256"],
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
function wrapAccessError(property, error) {
|
|
45
|
+
const wrap = new Error(`deferred error during ABI decoding triggered accessing ${property}`);
|
|
46
|
+
wrap.error = error;
|
|
47
|
+
return wrap;
|
|
48
|
+
}
|
|
49
|
+
/*
|
|
50
|
+
function checkNames(fragment: Fragment, type: "input" | "output", params: Array<ParamType>): void {
|
|
51
|
+
params.reduce((accum, param) => {
|
|
52
|
+
if (param.name) {
|
|
53
|
+
if (accum[param.name]) {
|
|
54
|
+
logger.throwArgumentError(`duplicate ${ type } parameter ${ JSON.stringify(param.name) } in ${ fragment.format("full") }`, "fragment", fragment);
|
|
55
|
+
}
|
|
56
|
+
accum[param.name] = true;
|
|
57
|
+
}
|
|
58
|
+
return accum;
|
|
59
|
+
}, <{ [ name: string ]: boolean }>{ });
|
|
60
|
+
}
|
|
61
|
+
*/
|
|
62
|
+
class Interface {
|
|
63
|
+
constructor(fragments) {
|
|
64
|
+
let abi = [];
|
|
65
|
+
if (typeof fragments === "string") {
|
|
66
|
+
abi = JSON.parse(fragments);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
abi = fragments;
|
|
70
|
+
}
|
|
71
|
+
(0, properties_1.defineReadOnly)(this, "fragments", abi
|
|
72
|
+
.map((fragment) => {
|
|
73
|
+
return fragments_1.Fragment.from(fragment);
|
|
74
|
+
})
|
|
75
|
+
.filter((fragment) => fragment != null));
|
|
76
|
+
(0, properties_1.defineReadOnly)(this, "_abiCoder", (0, properties_1.getStatic)(new.target, "getAbiCoder")());
|
|
77
|
+
(0, properties_1.defineReadOnly)(this, "functions", {});
|
|
78
|
+
(0, properties_1.defineReadOnly)(this, "errors", {});
|
|
79
|
+
(0, properties_1.defineReadOnly)(this, "events", {});
|
|
80
|
+
(0, properties_1.defineReadOnly)(this, "structs", {});
|
|
81
|
+
// Add all fragments by their signature
|
|
82
|
+
this.fragments.forEach((fragment) => {
|
|
83
|
+
let bucket = null;
|
|
84
|
+
switch (fragment.type) {
|
|
85
|
+
case "constructor":
|
|
86
|
+
if (this.deploy) {
|
|
87
|
+
logger.warn("duplicate definition - constructor");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
//checkNames(fragment, "input", fragment.inputs);
|
|
91
|
+
(0, properties_1.defineReadOnly)(this, "deploy", fragment);
|
|
92
|
+
return;
|
|
93
|
+
case "function":
|
|
94
|
+
//checkNames(fragment, "input", fragment.inputs);
|
|
95
|
+
//checkNames(fragment, "output", (<FunctionFragment>fragment).outputs);
|
|
96
|
+
bucket = this.functions;
|
|
97
|
+
break;
|
|
98
|
+
case "event":
|
|
99
|
+
//checkNames(fragment, "input", fragment.inputs);
|
|
100
|
+
bucket = this.events;
|
|
101
|
+
break;
|
|
102
|
+
case "error":
|
|
103
|
+
bucket = this.errors;
|
|
104
|
+
break;
|
|
105
|
+
default:
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
let signature = fragment.format();
|
|
109
|
+
if (bucket[signature]) {
|
|
110
|
+
logger.warn("duplicate definition - " + signature);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
bucket[signature] = fragment;
|
|
114
|
+
});
|
|
115
|
+
// If we do not have a constructor add a default
|
|
116
|
+
if (!this.deploy) {
|
|
117
|
+
(0, properties_1.defineReadOnly)(this, "deploy", fragments_1.ConstructorFragment.from({
|
|
118
|
+
payable: false,
|
|
119
|
+
type: "constructor",
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
(0, properties_1.defineReadOnly)(this, "_isInterface", true);
|
|
123
|
+
}
|
|
124
|
+
format(format) {
|
|
125
|
+
if (!format) {
|
|
126
|
+
format = fragments_1.FormatTypes.full;
|
|
127
|
+
}
|
|
128
|
+
if (format === fragments_1.FormatTypes.sighash) {
|
|
129
|
+
logger.throwArgumentError("interface does not support formatting sighash", "format", format);
|
|
130
|
+
}
|
|
131
|
+
const abi = this.fragments.map((fragment) => fragment.format(format));
|
|
132
|
+
// We need to re-bundle the JSON fragments a bit
|
|
133
|
+
if (format === fragments_1.FormatTypes.json) {
|
|
134
|
+
return JSON.stringify(abi.map((j) => JSON.parse(j)));
|
|
135
|
+
}
|
|
136
|
+
return abi;
|
|
137
|
+
}
|
|
138
|
+
// Sub-classes can override these to handle other blockchains
|
|
139
|
+
static getAbiCoder() {
|
|
140
|
+
return abi_coder_1.defaultAbiCoder;
|
|
141
|
+
}
|
|
142
|
+
static getAddress(address) {
|
|
143
|
+
return (0, address_1.getAddress)(address);
|
|
144
|
+
}
|
|
145
|
+
static getSighash(fragment) {
|
|
146
|
+
return (0, bytes_1.hexDataSlice)((0, id_1.id)(fragment.format()), 0, 4);
|
|
147
|
+
}
|
|
148
|
+
static getEventTopic(eventFragment) {
|
|
149
|
+
return (0, id_1.id)(eventFragment.format());
|
|
150
|
+
}
|
|
151
|
+
// Find a function definition by any means necessary (unless it is ambiguous)
|
|
152
|
+
getFunction(nameOrSignatureOrSighash) {
|
|
153
|
+
if ((0, bytes_1.isHexString)(nameOrSignatureOrSighash)) {
|
|
154
|
+
for (const name in this.functions) {
|
|
155
|
+
if (nameOrSignatureOrSighash === this.getSighash(name)) {
|
|
156
|
+
return this.functions[name];
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
logger.throwArgumentError("no matching function", "sighash", nameOrSignatureOrSighash);
|
|
160
|
+
}
|
|
161
|
+
// It is a bare name, look up the function (will return null if ambiguous)
|
|
162
|
+
if (nameOrSignatureOrSighash.indexOf("(") === -1) {
|
|
163
|
+
const name = nameOrSignatureOrSighash.trim();
|
|
164
|
+
const matching = Object.keys(this.functions).filter((f) => f.split("(" /* fix:) */)[0] === name);
|
|
165
|
+
if (matching.length === 0) {
|
|
166
|
+
logger.throwArgumentError("no matching function", "name", name);
|
|
167
|
+
}
|
|
168
|
+
else if (matching.length > 1) {
|
|
169
|
+
logger.throwArgumentError("multiple matching functions", "name", name);
|
|
170
|
+
}
|
|
171
|
+
return this.functions[matching[0]];
|
|
172
|
+
}
|
|
173
|
+
// Normalize the signature and lookup the function
|
|
174
|
+
const result = this.functions[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
|
|
175
|
+
if (!result) {
|
|
176
|
+
logger.throwArgumentError("no matching function", "signature", nameOrSignatureOrSighash);
|
|
177
|
+
}
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
// Find an event definition by any means necessary (unless it is ambiguous)
|
|
181
|
+
getEvent(nameOrSignatureOrTopic) {
|
|
182
|
+
if ((0, bytes_1.isHexString)(nameOrSignatureOrTopic)) {
|
|
183
|
+
const topichash = nameOrSignatureOrTopic.toLowerCase();
|
|
184
|
+
for (const name in this.events) {
|
|
185
|
+
if (topichash === this.getEventTopic(name)) {
|
|
186
|
+
return this.events[name];
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
logger.throwArgumentError("no matching event", "topichash", topichash);
|
|
190
|
+
}
|
|
191
|
+
// It is a bare name, look up the function (will return null if ambiguous)
|
|
192
|
+
if (nameOrSignatureOrTopic.indexOf("(") === -1) {
|
|
193
|
+
const name = nameOrSignatureOrTopic.trim();
|
|
194
|
+
const matching = Object.keys(this.events).filter((f) => f.split("(" /* fix:) */)[0] === name);
|
|
195
|
+
if (matching.length === 0) {
|
|
196
|
+
logger.throwArgumentError("no matching event", "name", name);
|
|
197
|
+
}
|
|
198
|
+
else if (matching.length > 1) {
|
|
199
|
+
logger.throwArgumentError("multiple matching events", "name", name);
|
|
200
|
+
}
|
|
201
|
+
return this.events[matching[0]];
|
|
202
|
+
}
|
|
203
|
+
// Normalize the signature and lookup the function
|
|
204
|
+
const result = this.events[fragments_1.EventFragment.fromString(nameOrSignatureOrTopic).format()];
|
|
205
|
+
if (!result) {
|
|
206
|
+
logger.throwArgumentError("no matching event", "signature", nameOrSignatureOrTopic);
|
|
207
|
+
}
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
// Find a function definition by any means necessary (unless it is ambiguous)
|
|
211
|
+
getError(nameOrSignatureOrSighash) {
|
|
212
|
+
if ((0, bytes_1.isHexString)(nameOrSignatureOrSighash)) {
|
|
213
|
+
const getSighash = (0, properties_1.getStatic)(this.constructor, "getSighash");
|
|
214
|
+
for (const name in this.errors) {
|
|
215
|
+
const error = this.errors[name];
|
|
216
|
+
if (nameOrSignatureOrSighash === getSighash(error)) {
|
|
217
|
+
return this.errors[name];
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
logger.throwArgumentError("no matching error", "sighash", nameOrSignatureOrSighash);
|
|
221
|
+
}
|
|
222
|
+
// It is a bare name, look up the function (will return null if ambiguous)
|
|
223
|
+
if (nameOrSignatureOrSighash.indexOf("(") === -1) {
|
|
224
|
+
const name = nameOrSignatureOrSighash.trim();
|
|
225
|
+
const matching = Object.keys(this.errors).filter((f) => f.split("(" /* fix:) */)[0] === name);
|
|
226
|
+
if (matching.length === 0) {
|
|
227
|
+
logger.throwArgumentError("no matching error", "name", name);
|
|
228
|
+
}
|
|
229
|
+
else if (matching.length > 1) {
|
|
230
|
+
logger.throwArgumentError("multiple matching errors", "name", name);
|
|
231
|
+
}
|
|
232
|
+
return this.errors[matching[0]];
|
|
233
|
+
}
|
|
234
|
+
// Normalize the signature and lookup the function
|
|
235
|
+
const result = this.errors[fragments_1.FunctionFragment.fromString(nameOrSignatureOrSighash).format()];
|
|
236
|
+
if (!result) {
|
|
237
|
+
logger.throwArgumentError("no matching error", "signature", nameOrSignatureOrSighash);
|
|
238
|
+
}
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
// Get the sighash (the bytes4 selector) used by Solidity to identify a function
|
|
242
|
+
getSighash(fragment) {
|
|
243
|
+
if (typeof fragment === "string") {
|
|
244
|
+
try {
|
|
245
|
+
fragment = this.getFunction(fragment);
|
|
246
|
+
}
|
|
247
|
+
catch (error) {
|
|
248
|
+
try {
|
|
249
|
+
fragment = this.getError(fragment);
|
|
250
|
+
}
|
|
251
|
+
catch (_) {
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return (0, properties_1.getStatic)(this.constructor, "getSighash")(fragment);
|
|
257
|
+
}
|
|
258
|
+
// Get the topic (the bytes32 hash) used by Solidity to identify an event
|
|
259
|
+
getEventTopic(eventFragment) {
|
|
260
|
+
if (typeof eventFragment === "string") {
|
|
261
|
+
eventFragment = this.getEvent(eventFragment);
|
|
262
|
+
}
|
|
263
|
+
return (0, properties_1.getStatic)(this.constructor, "getEventTopic")(eventFragment);
|
|
264
|
+
}
|
|
265
|
+
_decodeParams(params, data) {
|
|
266
|
+
return this._abiCoder.decode(params, data);
|
|
267
|
+
}
|
|
268
|
+
_encodeParams(params, values) {
|
|
269
|
+
logger.debug(`_encodeParams:${JSON.stringify(params)}, values:${JSON.stringify(values)}`);
|
|
270
|
+
return this._abiCoder.encode(params, values);
|
|
271
|
+
}
|
|
272
|
+
encodeDeploy(values) {
|
|
273
|
+
return this._encodeParams(this.deploy.inputs, values || []);
|
|
274
|
+
}
|
|
275
|
+
decodeErrorResult(fragment, data) {
|
|
276
|
+
if (typeof fragment === "string") {
|
|
277
|
+
fragment = this.getError(fragment);
|
|
278
|
+
}
|
|
279
|
+
const bytes = (0, bytes_1.arrayify)(data);
|
|
280
|
+
if ((0, bytes_1.hexlify)(bytes.slice(0, 4)) !== this.getSighash(fragment)) {
|
|
281
|
+
logger.throwArgumentError(`data signature does not match error ${fragment.name}.`, "data", (0, bytes_1.hexlify)(bytes));
|
|
282
|
+
}
|
|
283
|
+
return this._decodeParams(fragment.inputs, bytes.slice(4));
|
|
284
|
+
}
|
|
285
|
+
encodeErrorResult(fragment, values) {
|
|
286
|
+
if (typeof fragment === "string") {
|
|
287
|
+
fragment = this.getError(fragment);
|
|
288
|
+
}
|
|
289
|
+
return (0, bytes_1.hexlify)((0, bytes_1.concat)([
|
|
290
|
+
this.getSighash(fragment),
|
|
291
|
+
this._encodeParams(fragment.inputs, values || []),
|
|
292
|
+
]));
|
|
293
|
+
}
|
|
294
|
+
// Decode the data for a function call (e.g. tx.data)
|
|
295
|
+
decodeFunctionData(functionFragment, data) {
|
|
296
|
+
if (typeof functionFragment === "string") {
|
|
297
|
+
functionFragment = this.getFunction(functionFragment);
|
|
298
|
+
}
|
|
299
|
+
const bytes = (0, bytes_1.arrayify)(data);
|
|
300
|
+
if ((0, bytes_1.hexlify)(bytes.slice(0, 4)) !== this.getSighash(functionFragment)) {
|
|
301
|
+
logger.throwArgumentError(`data signature does not match function ${functionFragment.name}.`, "data", (0, bytes_1.hexlify)(bytes));
|
|
302
|
+
}
|
|
303
|
+
return this._decodeParams(functionFragment.inputs, bytes.slice(4));
|
|
304
|
+
}
|
|
305
|
+
// Encode the data for a function call (e.g. tx.data)
|
|
306
|
+
encodeFunctionData(functionFragment, values) {
|
|
307
|
+
if (typeof functionFragment === "string") {
|
|
308
|
+
functionFragment = this.getFunction(functionFragment);
|
|
309
|
+
}
|
|
310
|
+
return (0, bytes_1.hexlify)((0, bytes_1.concat)([
|
|
311
|
+
this.getSighash(functionFragment),
|
|
312
|
+
this._encodeParams(functionFragment.inputs, values || []),
|
|
313
|
+
]));
|
|
314
|
+
}
|
|
315
|
+
// Decode the result from a function call (e.g. from eth_call)
|
|
316
|
+
decodeFunctionResult(functionFragment, data) {
|
|
317
|
+
if (typeof functionFragment === "string") {
|
|
318
|
+
functionFragment = this.getFunction(functionFragment);
|
|
319
|
+
}
|
|
320
|
+
let bytes = (0, bytes_1.arrayify)(data);
|
|
321
|
+
let reason = null;
|
|
322
|
+
let message = "";
|
|
323
|
+
let errorArgs = null;
|
|
324
|
+
let errorName = null;
|
|
325
|
+
let errorSignature = null;
|
|
326
|
+
switch (bytes.length % this._abiCoder._getWordSize()) {
|
|
327
|
+
case 0:
|
|
328
|
+
try {
|
|
329
|
+
return this._abiCoder.decode(functionFragment.outputs, bytes);
|
|
330
|
+
}
|
|
331
|
+
catch (error) { }
|
|
332
|
+
break;
|
|
333
|
+
case 4: {
|
|
334
|
+
const selector = (0, bytes_1.hexlify)(bytes.slice(0, 4));
|
|
335
|
+
const builtin = BuiltinErrors[selector];
|
|
336
|
+
if (builtin) {
|
|
337
|
+
errorArgs = this._abiCoder.decode(builtin.inputs, bytes.slice(4));
|
|
338
|
+
errorName = builtin.name;
|
|
339
|
+
errorSignature = builtin.signature;
|
|
340
|
+
if (builtin.reason) {
|
|
341
|
+
reason = errorArgs[0];
|
|
342
|
+
}
|
|
343
|
+
if (errorName === "Error") {
|
|
344
|
+
message = `; VM Exception while processing transaction: reverted with reason string ${JSON.stringify(errorArgs[0])}`;
|
|
345
|
+
}
|
|
346
|
+
else if (errorName === "Panic") {
|
|
347
|
+
message = `; VM Exception while processing transaction: reverted with panic code ${errorArgs[0]}`;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
try {
|
|
352
|
+
const error = this.getError(selector);
|
|
353
|
+
errorArgs = this._abiCoder.decode(error.inputs, bytes.slice(4));
|
|
354
|
+
errorName = error.name;
|
|
355
|
+
errorSignature = error.format();
|
|
356
|
+
}
|
|
357
|
+
catch (error) { }
|
|
358
|
+
}
|
|
359
|
+
break;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return logger.throwError("call revert exception" + message, logger_1.Logger.errors.CALL_EXCEPTION, {
|
|
363
|
+
method: functionFragment.format(),
|
|
364
|
+
data: (0, bytes_1.hexlify)(data),
|
|
365
|
+
errorArgs,
|
|
366
|
+
errorName,
|
|
367
|
+
errorSignature,
|
|
368
|
+
reason,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
// Encode the result for a function call (e.g. for eth_call)
|
|
372
|
+
encodeFunctionResult(functionFragment, values) {
|
|
373
|
+
if (typeof functionFragment === "string") {
|
|
374
|
+
functionFragment = this.getFunction(functionFragment);
|
|
375
|
+
}
|
|
376
|
+
return (0, bytes_1.hexlify)(this._abiCoder.encode(functionFragment.outputs, values || []));
|
|
377
|
+
}
|
|
378
|
+
// Create the filter for the event with search criteria (e.g. for eth_filterLog)
|
|
379
|
+
// encodeFilterTopics(
|
|
380
|
+
// eventFragment: EventFragment | string,
|
|
381
|
+
// values: ReadonlyArray<any>,
|
|
382
|
+
// ): Array<string | Array<string>> {
|
|
383
|
+
// if (typeof eventFragment === "string") {
|
|
384
|
+
// eventFragment = this.getEvent(eventFragment);
|
|
385
|
+
// }
|
|
386
|
+
// if (values.length > eventFragment.inputs.length) {
|
|
387
|
+
// logger.throwError(
|
|
388
|
+
// "too many arguments for " + eventFragment.format(),
|
|
389
|
+
// Logger.errors.UNEXPECTED_ARGUMENT,
|
|
390
|
+
// {
|
|
391
|
+
// argument: "values",
|
|
392
|
+
// value: values,
|
|
393
|
+
// },
|
|
394
|
+
// );
|
|
395
|
+
// }
|
|
396
|
+
// let topics: Array<string | Array<string>> = [];
|
|
397
|
+
// if (!eventFragment.anonymous) {
|
|
398
|
+
// topics.push(this.getEventTopic(eventFragment));
|
|
399
|
+
// }
|
|
400
|
+
// const encodeTopic = (param: ParamType, value: any): string => {
|
|
401
|
+
// if (param.type === "string") {
|
|
402
|
+
// return id(value);
|
|
403
|
+
// } else if (param.type === "bytes") {
|
|
404
|
+
// return keccak256(hexlify(value));
|
|
405
|
+
// }
|
|
406
|
+
// if (param.type === "bool" && typeof value === "boolean") {
|
|
407
|
+
// value = value ? "0x01" : "0x00";
|
|
408
|
+
// }
|
|
409
|
+
// if (param.type.match(/^u?int/)) {
|
|
410
|
+
// value = BigNumber.from(value).toHexString();
|
|
411
|
+
// }
|
|
412
|
+
// // Check addresses are valid
|
|
413
|
+
// if (param.type === "address") {
|
|
414
|
+
// value = this._abiCoder.encode(["address"], [value]);
|
|
415
|
+
// }
|
|
416
|
+
// logger.debug(
|
|
417
|
+
// `encodeTopic: param:${JSON.stringify(param)}, value:${JSON.stringify(value)}`,
|
|
418
|
+
// );
|
|
419
|
+
// return hexZeroPad(hexlify(value), 32);
|
|
420
|
+
// };
|
|
421
|
+
// values.forEach((value, index) => {
|
|
422
|
+
// let param = (<EventFragment>eventFragment).inputs[index];
|
|
423
|
+
// if (!param.indexed) {
|
|
424
|
+
// if (value != null) {
|
|
425
|
+
// logger.throwArgumentError(
|
|
426
|
+
// "cannot filter non-indexed parameters; must be null",
|
|
427
|
+
// "contract." + param.name,
|
|
428
|
+
// value,
|
|
429
|
+
// );
|
|
430
|
+
// }
|
|
431
|
+
// return;
|
|
432
|
+
// }
|
|
433
|
+
// if (value == null) {
|
|
434
|
+
// topics.push(null);
|
|
435
|
+
// } else if (param.baseType === "array" || param.baseType === "tuple") {
|
|
436
|
+
// logger.throwArgumentError(
|
|
437
|
+
// "filtering with tuples or arrays not supported",
|
|
438
|
+
// "contract." + param.name,
|
|
439
|
+
// value,
|
|
440
|
+
// );
|
|
441
|
+
// } else if (Array.isArray(value)) {
|
|
442
|
+
// topics.push(value.map((value) => encodeTopic(param, value)));
|
|
443
|
+
// } else {
|
|
444
|
+
// topics.push(encodeTopic(param, value));
|
|
445
|
+
// }
|
|
446
|
+
// });
|
|
447
|
+
// // Trim off trailing nulls
|
|
448
|
+
// while (topics.length && topics[topics.length - 1] === null) {
|
|
449
|
+
// topics.pop();
|
|
450
|
+
// }
|
|
451
|
+
// return topics;
|
|
452
|
+
// }
|
|
453
|
+
encodeEventLog(eventFragment, values) {
|
|
454
|
+
if (typeof eventFragment === "string") {
|
|
455
|
+
eventFragment = this.getEvent(eventFragment);
|
|
456
|
+
}
|
|
457
|
+
const topics = [];
|
|
458
|
+
const dataTypes = [];
|
|
459
|
+
const dataValues = [];
|
|
460
|
+
if (!eventFragment.anonymous) {
|
|
461
|
+
topics.push(this.getEventTopic(eventFragment));
|
|
462
|
+
}
|
|
463
|
+
if (values.length !== eventFragment.inputs.length) {
|
|
464
|
+
logger.throwArgumentError("event arguments/values mismatch", "values", values);
|
|
465
|
+
}
|
|
466
|
+
eventFragment.inputs.forEach((param, index) => {
|
|
467
|
+
const value = values[index];
|
|
468
|
+
if (param.indexed) {
|
|
469
|
+
if (param.type === "string") {
|
|
470
|
+
topics.push((0, id_1.id)(value));
|
|
471
|
+
}
|
|
472
|
+
else if (param.type === "bytes") {
|
|
473
|
+
topics.push((0, keccak256_1.keccak256)(value));
|
|
474
|
+
}
|
|
475
|
+
else if (param.baseType === "tuple" || param.baseType === "array") {
|
|
476
|
+
// @TODO
|
|
477
|
+
throw new Error("not implemented");
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
topics.push(this._abiCoder.encode([param.type], [value]));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
dataTypes.push(param);
|
|
485
|
+
dataValues.push(value);
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
return {
|
|
489
|
+
data: this._abiCoder.encode(dataTypes, dataValues),
|
|
490
|
+
topics: topics,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
// Decode a filter for the event and the search criteria
|
|
494
|
+
decodeEventLog(eventFragment, data, topics) {
|
|
495
|
+
if (typeof eventFragment === "string") {
|
|
496
|
+
eventFragment = this.getEvent(eventFragment);
|
|
497
|
+
}
|
|
498
|
+
if (topics != null && !eventFragment.anonymous) {
|
|
499
|
+
let topicHash = this.getEventTopic(eventFragment);
|
|
500
|
+
if (!(0, bytes_1.isHexString)(topics[0], 32) ||
|
|
501
|
+
topics[0].toLowerCase() !== topicHash) {
|
|
502
|
+
logger.throwError("fragment/topic mismatch", logger_1.Logger.errors.INVALID_ARGUMENT, { argument: "topics[0]", expected: topicHash, value: topics[0] });
|
|
503
|
+
}
|
|
504
|
+
topics = topics.slice(1);
|
|
505
|
+
}
|
|
506
|
+
let indexed = [];
|
|
507
|
+
let nonIndexed = [];
|
|
508
|
+
let dynamic = [];
|
|
509
|
+
eventFragment.inputs.forEach((param, index) => {
|
|
510
|
+
if (param.indexed) {
|
|
511
|
+
if (param.type === "string" ||
|
|
512
|
+
param.type === "bytes" ||
|
|
513
|
+
param.baseType === "tuple" ||
|
|
514
|
+
param.baseType === "array") {
|
|
515
|
+
indexed.push(fragments_1.ParamType.fromObject({ type: "bytes32", name: param.name }));
|
|
516
|
+
dynamic.push(true);
|
|
517
|
+
}
|
|
518
|
+
else {
|
|
519
|
+
indexed.push(param);
|
|
520
|
+
dynamic.push(false);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
nonIndexed.push(param);
|
|
525
|
+
dynamic.push(false);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
let resultIndexed = topics != null ? this._abiCoder.decode(indexed, (0, bytes_1.concat)(topics)) : null;
|
|
529
|
+
let resultNonIndexed = this._abiCoder.decode(nonIndexed, data, true);
|
|
530
|
+
let result = [];
|
|
531
|
+
let nonIndexedIndex = 0, indexedIndex = 0;
|
|
532
|
+
eventFragment.inputs.forEach((param, index) => {
|
|
533
|
+
if (param.indexed) {
|
|
534
|
+
if (resultIndexed == null) {
|
|
535
|
+
result[index] = new Indexed({ _isIndexed: true, hash: null });
|
|
536
|
+
}
|
|
537
|
+
else if (dynamic[index]) {
|
|
538
|
+
result[index] = new Indexed({
|
|
539
|
+
_isIndexed: true,
|
|
540
|
+
hash: resultIndexed[indexedIndex++],
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
try {
|
|
545
|
+
result[index] = resultIndexed[indexedIndex++];
|
|
546
|
+
}
|
|
547
|
+
catch (error) {
|
|
548
|
+
result[index] = error;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
try {
|
|
554
|
+
result[index] = resultNonIndexed[nonIndexedIndex++];
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
result[index] = error;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
// Add the keyword argument if named and safe
|
|
561
|
+
if (param.name && result[param.name] == null) {
|
|
562
|
+
const value = result[index];
|
|
563
|
+
// Make error named values throw on access
|
|
564
|
+
if (value instanceof Error) {
|
|
565
|
+
Object.defineProperty(result, param.name, {
|
|
566
|
+
enumerable: true,
|
|
567
|
+
get: () => {
|
|
568
|
+
throw wrapAccessError(`property ${JSON.stringify(param.name)}`, value);
|
|
569
|
+
},
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
result[param.name] = value;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
// Make all error indexed values throw on access
|
|
578
|
+
for (let i = 0; i < result.length; i++) {
|
|
579
|
+
const value = result[i];
|
|
580
|
+
if (value instanceof Error) {
|
|
581
|
+
Object.defineProperty(result, i, {
|
|
582
|
+
enumerable: true,
|
|
583
|
+
get: () => {
|
|
584
|
+
throw wrapAccessError(`index ${i}`, value);
|
|
585
|
+
},
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return Object.freeze(result);
|
|
590
|
+
}
|
|
591
|
+
// Given a transaction, find the matching function fragment (if any) and
|
|
592
|
+
// determine all its properties and call parameters
|
|
593
|
+
// parseTransaction(tx: {
|
|
594
|
+
// data: string;
|
|
595
|
+
// value?: BigNumberish;
|
|
596
|
+
// }): TransactionDescription {
|
|
597
|
+
// let fragment = this.getFunction(tx.data.substring(0, 10).toLowerCase());
|
|
598
|
+
// if (!fragment) {
|
|
599
|
+
// return null;
|
|
600
|
+
// }
|
|
601
|
+
// return new TransactionDescription({
|
|
602
|
+
// args: this._abiCoder.decode(
|
|
603
|
+
// fragment.inputs,
|
|
604
|
+
// "0x" + tx.data.substring(10),
|
|
605
|
+
// ),
|
|
606
|
+
// functionFragment: fragment,
|
|
607
|
+
// name: fragment.name,
|
|
608
|
+
// signature: fragment.format(),
|
|
609
|
+
// sighash: this.getSighash(fragment),
|
|
610
|
+
// value: BigNumber.from(tx.value || "0"),
|
|
611
|
+
// });
|
|
612
|
+
// }
|
|
613
|
+
// @TODO
|
|
614
|
+
//parseCallResult(data: BytesLike): ??
|
|
615
|
+
// Given an event log, find the matching event fragment (if any) and
|
|
616
|
+
// determine all its properties and values
|
|
617
|
+
parseLog(log) {
|
|
618
|
+
let fragment = this.getEvent(log.topics[0]);
|
|
619
|
+
if (!fragment || fragment.anonymous) {
|
|
620
|
+
return null;
|
|
621
|
+
}
|
|
622
|
+
// @TODO: If anonymous, and the only method, and the input count matches, should we parse?
|
|
623
|
+
// Probably not, because just because it is the only event in the ABI does
|
|
624
|
+
// not mean we have the full ABI; maybe just a fragment?
|
|
625
|
+
return new LogDescription({
|
|
626
|
+
eventFragment: fragment,
|
|
627
|
+
name: fragment.name,
|
|
628
|
+
signature: fragment.format(),
|
|
629
|
+
topic: this.getEventTopic(fragment),
|
|
630
|
+
args: this.decodeEventLog(fragment, log.data, log.topics),
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
parseError(data) {
|
|
634
|
+
const hexData = (0, bytes_1.hexlify)(data);
|
|
635
|
+
let fragment = this.getError(hexData.substring(0, 10).toLowerCase());
|
|
636
|
+
if (!fragment) {
|
|
637
|
+
return null;
|
|
638
|
+
}
|
|
639
|
+
return new ErrorDescription({
|
|
640
|
+
args: this._abiCoder.decode(fragment.inputs, "0x" + hexData.substring(10)),
|
|
641
|
+
errorFragment: fragment,
|
|
642
|
+
name: fragment.name,
|
|
643
|
+
signature: fragment.format(),
|
|
644
|
+
sighash: this.getSighash(fragment),
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
/*
|
|
648
|
+
static from(value: Array<Fragment | string | JsonAbi> | string | Interface) {
|
|
649
|
+
if (Interface.isInterface(value)) {
|
|
650
|
+
return value;
|
|
651
|
+
}
|
|
652
|
+
if (typeof(value) === "string") {
|
|
653
|
+
return new Interface(JSON.parse(value));
|
|
654
|
+
}
|
|
655
|
+
return new Interface(value);
|
|
656
|
+
}
|
|
657
|
+
*/
|
|
658
|
+
static isInterface(value) {
|
|
659
|
+
return !!(value && value._isInterface);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
exports.Interface = Interface;
|
|
663
|
+
//# sourceMappingURL=interface.js.map
|