@pezkuwi/api-contract 16.5.6 → 16.5.8
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/build/Abi/index.d.ts +31 -0
- package/build/Abi/index.js +359 -0
- package/build/Abi/toLatestCompatible.d.ts +15 -0
- package/build/Abi/toLatestCompatible.js +30 -0
- package/build/Abi/toV1.d.ts +3 -0
- package/build/Abi/toV1.js +21 -0
- package/build/Abi/toV2.d.ts +3 -0
- package/build/Abi/toV2.js +27 -0
- package/build/Abi/toV3.d.ts +3 -0
- package/build/Abi/toV3.js +10 -0
- package/build/Abi/toV4.d.ts +3 -0
- package/build/Abi/toV4.js +10 -0
- package/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/augment.d.ts +1 -0
- package/build/augment.js +1 -0
- package/build/base/Base.d.ts +13 -0
- package/build/base/Base.js +40 -0
- package/build/base/Blueprint.d.ts +24 -0
- package/build/base/Blueprint.js +51 -0
- package/build/base/Code.d.ts +22 -0
- package/build/base/Code.js +74 -0
- package/build/base/Contract.d.ts +25 -0
- package/build/base/Contract.js +127 -0
- package/build/base/index.d.ts +3 -0
- package/build/base/index.js +3 -0
- package/build/base/mock.d.ts +3 -0
- package/build/base/mock.js +38 -0
- package/build/base/types.d.ts +25 -0
- package/build/base/types.js +1 -0
- package/build/base/util.d.ts +16 -0
- package/build/base/util.js +33 -0
- package/build/bundle-pezkuwi-api-contract.js +1238 -0
- package/build/bundle.d.ts +4 -0
- package/build/bundle.js +4 -0
- package/build/cjs/Abi/index.d.ts +31 -0
- package/build/cjs/Abi/index.js +363 -0
- package/build/cjs/Abi/toLatestCompatible.d.ts +15 -0
- package/build/cjs/Abi/toLatestCompatible.js +36 -0
- package/build/cjs/Abi/toV1.d.ts +3 -0
- package/build/cjs/Abi/toV1.js +24 -0
- package/build/cjs/Abi/toV2.d.ts +3 -0
- package/build/cjs/Abi/toV2.js +30 -0
- package/build/cjs/Abi/toV3.d.ts +3 -0
- package/build/cjs/Abi/toV3.js +13 -0
- package/build/cjs/Abi/toV4.d.ts +3 -0
- package/build/cjs/Abi/toV4.js +13 -0
- package/build/cjs/augment.d.ts +1 -0
- package/build/cjs/augment.js +3 -0
- package/build/cjs/base/Base.d.ts +13 -0
- package/build/cjs/base/Base.js +44 -0
- package/build/cjs/base/Blueprint.d.ts +24 -0
- package/build/cjs/base/Blueprint.js +57 -0
- package/build/cjs/base/Code.d.ts +22 -0
- package/build/cjs/base/Code.js +80 -0
- package/build/cjs/base/Contract.d.ts +25 -0
- package/build/cjs/base/Contract.js +133 -0
- package/build/cjs/base/index.d.ts +3 -0
- package/build/cjs/base/index.js +14 -0
- package/build/cjs/base/mock.d.ts +3 -0
- package/build/cjs/base/mock.js +41 -0
- package/build/cjs/base/types.d.ts +25 -0
- package/build/cjs/base/types.js +2 -0
- package/build/cjs/base/util.d.ts +16 -0
- package/build/cjs/base/util.js +42 -0
- package/build/cjs/bundle.d.ts +4 -0
- package/build/cjs/bundle.js +10 -0
- package/build/cjs/index.d.ts +2 -0
- package/build/cjs/index.js +5 -0
- package/build/cjs/package.json +3 -0
- package/build/cjs/packageDetect.d.ts +1 -0
- package/build/cjs/packageDetect.js +7 -0
- package/build/cjs/packageInfo.d.ts +6 -0
- package/build/cjs/packageInfo.js +4 -0
- package/build/cjs/promise/index.d.ts +13 -0
- package/build/cjs/promise/index.js +23 -0
- package/build/cjs/promise/types.d.ts +3 -0
- package/build/cjs/promise/types.js +2 -0
- package/build/cjs/rx/index.d.ts +13 -0
- package/build/cjs/rx/index.js +23 -0
- package/build/cjs/rx/types.d.ts +3 -0
- package/build/cjs/rx/types.js +2 -0
- package/build/cjs/types.d.ts +79 -0
- package/build/cjs/types.js +2 -0
- package/build/cjs/util.d.ts +5 -0
- package/build/cjs/util.js +13 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/package.json +408 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/packageInfo.js +1 -0
- package/build/promise/index.d.ts +13 -0
- package/build/promise/index.js +17 -0
- package/build/promise/types.d.ts +3 -0
- package/build/promise/types.js +1 -0
- package/build/rx/index.d.ts +13 -0
- package/build/rx/index.js +17 -0
- package/build/rx/types.d.ts +3 -0
- package/build/rx/types.js +1 -0
- package/build/types.d.ts +79 -0
- package/build/types.js +1 -0
- package/build/util.d.ts +5 -0
- package/build/util.js +10 -0
- package/build-deno/Abi/index.ts +475 -0
- package/build-deno/Abi/toLatestCompatible.ts +47 -0
- package/build-deno/Abi/toV1.ts +33 -0
- package/build-deno/Abi/toV2.ts +56 -0
- package/build-deno/Abi/toV3.ts +16 -0
- package/build-deno/Abi/toV4.ts +19 -0
- package/build-deno/README.md +3 -0
- package/build-deno/augment.ts +2 -0
- package/build-deno/base/Base.ts +50 -0
- package/build-deno/base/Blueprint.ts +88 -0
- package/build-deno/base/Code.ts +140 -0
- package/build-deno/base/Contract.ts +194 -0
- package/build-deno/base/index.ts +4 -0
- package/build-deno/base/mock.ts +46 -0
- package/build-deno/base/types.ts +38 -0
- package/build-deno/base/util.ts +54 -0
- package/build-deno/bundle.ts +6 -0
- package/build-deno/checkTypes.manual.ts +42 -0
- package/build-deno/index.ts +4 -0
- package/build-deno/mod.ts +2 -0
- package/build-deno/packageDetect.ts +9 -0
- package/build-deno/packageInfo.ts +3 -0
- package/build-deno/promise/index.ts +28 -0
- package/build-deno/promise/types.ts +5 -0
- package/build-deno/rx/index.ts +28 -0
- package/build-deno/rx/types.ts +5 -0
- package/build-deno/test/contracts/index.ts +18 -0
- package/build-deno/test/contracts/ink/index.ts +11 -0
- package/build-deno/test/contracts/ink/v0/accumulator.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/adder.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/delegator.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/dns.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/erc20.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/erc721.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/flipper.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/incrementer.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/index.ts +9 -0
- package/build-deno/test/contracts/ink/v0/multisig_plain.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/subber.wasm +0 -0
- package/build-deno/test/contracts/ink/v0/trait-flipper.wasm +0 -0
- package/build-deno/test/contracts/ink/v1/index.ts +3 -0
- package/build-deno/test/contracts/ink/v2/index.ts +3 -0
- package/build-deno/test/contracts/ink/v3/index.ts +3 -0
- package/build-deno/test/contracts/ink/v4/erc20.wasm +0 -0
- package/build-deno/test/contracts/ink/v4/flipper.wasm +0 -0
- package/build-deno/test/contracts/ink/v4/index.ts +5 -0
- package/build-deno/test/contracts/ink/v5/erc20.wasm +0 -0
- package/build-deno/test/contracts/ink/v5/flipper.wasm +0 -0
- package/build-deno/test/contracts/ink/v5/index.ts +6 -0
- package/build-deno/test/contracts/ink/v6/erc20.polkavm +0 -0
- package/build-deno/test/contracts/ink/v6/index.ts +3 -0
- package/build-deno/test/contracts/solang/index.ts +5 -0
- package/build-deno/test/contracts/solang/v0/index.ts +2 -0
- package/build-deno/test/contracts/solang/v0/ints256.sol +13 -0
- package/build-deno/test/contracts/solang/v0/ints256.wasm +0 -0
- package/build-deno/test/contracts/user/index.ts +7 -0
- package/build-deno/test/contracts/user/v0/assetTransfer.wasm +0 -0
- package/build-deno/test/contracts/user/v0/enumExample.wasm +0 -0
- package/build-deno/test/contracts/user/v0/index.ts +5 -0
- package/build-deno/test/contracts/user/v3/index.ts +2 -0
- package/build-deno/test/contracts/user/v4/index.ts +2 -0
- package/build-deno/test/contracts/util.ts +12 -0
- package/build-deno/types.ts +95 -0
- package/build-deno/util.ts +18 -0
- package/build-tsc/Abi/index.d.ts +31 -0
- package/build-tsc/Abi/toLatestCompatible.d.ts +15 -0
- package/build-tsc/Abi/toV1.d.ts +3 -0
- package/build-tsc/Abi/toV2.d.ts +3 -0
- package/build-tsc/Abi/toV3.d.ts +3 -0
- package/build-tsc/Abi/toV4.d.ts +3 -0
- package/build-tsc/augment.d.ts +1 -0
- package/build-tsc/base/Base.d.ts +13 -0
- package/build-tsc/base/Blueprint.d.ts +24 -0
- package/build-tsc/base/Code.d.ts +22 -0
- package/build-tsc/base/Contract.d.ts +25 -0
- package/build-tsc/base/index.d.ts +3 -0
- package/build-tsc/base/mock.d.ts +3 -0
- package/build-tsc/base/types.d.ts +25 -0
- package/build-tsc/base/util.d.ts +16 -0
- package/build-tsc/bundle.d.ts +4 -0
- package/build-tsc/index.d.ts +2 -0
- package/build-tsc/packageDetect.d.ts +1 -0
- package/build-tsc/packageInfo.d.ts +6 -0
- package/build-tsc/promise/index.d.ts +13 -0
- package/build-tsc/promise/types.d.ts +3 -0
- package/build-tsc/rx/index.d.ts +13 -0
- package/build-tsc/rx/types.d.ts +3 -0
- package/build-tsc/types.d.ts +79 -0
- package/build-tsc/util.d.ts +5 -0
- package/build-tsc-cjs/Abi/index.js +363 -0
- package/build-tsc-cjs/Abi/toLatestCompatible.js +36 -0
- package/build-tsc-cjs/Abi/toV1.js +24 -0
- package/build-tsc-cjs/Abi/toV2.js +30 -0
- package/build-tsc-cjs/Abi/toV3.js +13 -0
- package/build-tsc-cjs/Abi/toV4.js +13 -0
- package/build-tsc-cjs/augment.js +3 -0
- package/build-tsc-cjs/base/Base.js +44 -0
- package/build-tsc-cjs/base/Blueprint.js +57 -0
- package/build-tsc-cjs/base/Code.js +80 -0
- package/build-tsc-cjs/base/Contract.js +133 -0
- package/build-tsc-cjs/base/index.js +14 -0
- package/build-tsc-cjs/base/mock.js +41 -0
- package/build-tsc-cjs/base/types.js +2 -0
- package/build-tsc-cjs/base/util.js +42 -0
- package/build-tsc-cjs/bundle.js +10 -0
- package/build-tsc-cjs/index.js +5 -0
- package/build-tsc-cjs/packageDetect.js +7 -0
- package/build-tsc-cjs/packageInfo.js +4 -0
- package/build-tsc-cjs/promise/index.js +23 -0
- package/build-tsc-cjs/promise/types.js +2 -0
- package/build-tsc-cjs/rx/index.js +23 -0
- package/build-tsc-cjs/rx/types.js +2 -0
- package/build-tsc-cjs/types.js +2 -0
- package/build-tsc-cjs/util.js +13 -0
- package/build-tsc-esm/Abi/index.js +359 -0
- package/build-tsc-esm/Abi/toLatestCompatible.js +30 -0
- package/build-tsc-esm/Abi/toV1.js +21 -0
- package/build-tsc-esm/Abi/toV2.js +27 -0
- package/build-tsc-esm/Abi/toV3.js +10 -0
- package/build-tsc-esm/Abi/toV4.js +10 -0
- package/build-tsc-esm/augment.js +1 -0
- package/build-tsc-esm/base/Base.js +40 -0
- package/build-tsc-esm/base/Blueprint.js +51 -0
- package/build-tsc-esm/base/Code.js +74 -0
- package/build-tsc-esm/base/Contract.js +127 -0
- package/build-tsc-esm/base/index.js +3 -0
- package/build-tsc-esm/base/mock.js +38 -0
- package/build-tsc-esm/base/types.js +1 -0
- package/build-tsc-esm/base/util.js +33 -0
- package/build-tsc-esm/bundle.js +4 -0
- package/build-tsc-esm/index.js +2 -0
- package/build-tsc-esm/packageDetect.js +5 -0
- package/build-tsc-esm/packageInfo.js +1 -0
- package/build-tsc-esm/promise/index.js +17 -0
- package/build-tsc-esm/promise/types.js +1 -0
- package/build-tsc-esm/rx/index.js +17 -0
- package/build-tsc-esm/rx/types.js +1 -0
- package/build-tsc-esm/types.js +1 -0
- package/build-tsc-esm/util.js +10 -0
- package/bundle-pezkuwi-api-contract.js +1 -1
- package/cjs/packageInfo.js +1 -1
- package/package.json +6 -6
- package/packageInfo.js +1 -1
- package/src/Abi/Abi.spec.ts +235 -0
- package/src/Abi/index.ts +477 -0
- package/src/Abi/toLatestCompatible.spec.ts +219 -0
- package/src/Abi/toLatestCompatible.ts +52 -0
- package/src/Abi/toV1.ts +35 -0
- package/src/Abi/toV2.ts +58 -0
- package/src/Abi/toV3.ts +18 -0
- package/src/Abi/toV4.ts +21 -0
- package/src/augment.ts +4 -0
- package/src/base/Base.ts +52 -0
- package/src/base/Blueprint.ts +90 -0
- package/src/base/Code.spec.ts +47 -0
- package/src/base/Code.ts +142 -0
- package/src/base/Contract.ts +197 -0
- package/src/base/index.ts +6 -0
- package/src/base/mock.ts +48 -0
- package/src/base/types.ts +40 -0
- package/src/base/util.ts +56 -0
- package/src/bundle.ts +10 -0
- package/src/checkTypes.manual.ts +45 -0
- package/src/index.ts +6 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +13 -0
- package/src/packageInfo.ts +6 -0
- package/src/promise/index.ts +28 -0
- package/src/promise/types.ts +7 -0
- package/src/rx/index.ts +28 -0
- package/src/rx/types.ts +7 -0
- package/src/test/compare/ink_v0_delegator.test.json +47 -0
- package/src/test/compare/ink_v0_dns.test.json +232 -0
- package/src/test/compare/ink_v0_erc20.test.json +253 -0
- package/src/test/compare/ink_v0_erc721.test.json +415 -0
- package/src/test/compare/ink_v0_flipper.test.json +9 -0
- package/src/test/compare/ink_v0_flipperBundle.test.json +9 -0
- package/src/test/compare/ink_v0_incrementer.test.json +9 -0
- package/src/test/compare/ink_v0_multisigPlain.test.json +562 -0
- package/src/test/compare/ink_v1_flipper.test.json +9 -0
- package/src/test/compare/ink_v1_psp22.test.json +531 -0
- package/src/test/compare/ink_v2_erc20.test.json +205 -0
- package/src/test/compare/ink_v2_flipper.test.json +9 -0
- package/src/test/compare/ink_v3_flipper.test.json +9 -0
- package/src/test/compare/ink_v3_traitErc20.test.json +205 -0
- package/src/test/compare/ink_v4_erc20Contract.test.json +253 -0
- package/src/test/compare/ink_v4_erc20Metadata.test.json +253 -0
- package/src/test/compare/ink_v4_flipperContract.test.json +155 -0
- package/src/test/compare/ink_v4_flipperMetadata.test.json +155 -0
- package/src/test/compare/ink_v5_erc20.test.json +370 -0
- package/src/test/compare/ink_v5_erc20AnonymousTransferMetadata.test.json +370 -0
- package/src/test/compare/ink_v5_erc20Contract.test.json +370 -0
- package/src/test/compare/ink_v5_erc20Metadata.test.json +370 -0
- package/src/test/compare/ink_v5_flipperContract.test.json +174 -0
- package/src/test/compare/ink_v5_flipperMetadata.test.json +174 -0
- package/src/test/compare/ink_v6_erc20Contract.test.json +418 -0
- package/src/test/compare/ink_v6_erc20Metadata.test.json +418 -0
- package/src/test/compare/solang_v0_ints256.test.json +9 -0
- package/src/test/compare/user_v0_assetTransfer.test.json +54 -0
- package/src/test/compare/user_v0_enumExample.test.json +303 -0
- package/src/test/compare/user_v0_recursive.test.json +27 -0
- package/src/test/compare/user_v0_withString.test.json +260 -0
- package/src/test/compare/user_v3_ask.test.json +71 -0
- package/src/test/compare/user_v4_events.test.json +1328 -0
- package/src/test/contracts/index.ts +20 -0
- package/src/test/contracts/ink/index.ts +13 -0
- package/src/test/contracts/ink/v0/accumulator.wasm +0 -0
- package/src/test/contracts/ink/v0/adder.wasm +0 -0
- package/src/test/contracts/ink/v0/delegator.json +252 -0
- package/src/test/contracts/ink/v0/delegator.wasm +0 -0
- package/src/test/contracts/ink/v0/dns.json +713 -0
- package/src/test/contracts/ink/v0/dns.wasm +0 -0
- package/src/test/contracts/ink/v0/erc20.json +704 -0
- package/src/test/contracts/ink/v0/erc20.wasm +0 -0
- package/src/test/contracts/ink/v0/erc721.json +1197 -0
- package/src/test/contracts/ink/v0/erc721.wasm +0 -0
- package/src/test/contracts/ink/v0/flipper.contract.json +107 -0
- package/src/test/contracts/ink/v0/flipper.json +106 -0
- package/src/test/contracts/ink/v0/flipper.wasm +0 -0
- package/src/test/contracts/ink/v0/incrementer.json +108 -0
- package/src/test/contracts/ink/v0/incrementer.wasm +0 -0
- package/src/test/contracts/ink/v0/index.ts +11 -0
- package/src/test/contracts/ink/v0/multisig_plain.json +1466 -0
- package/src/test/contracts/ink/v0/multisig_plain.wasm +0 -0
- package/src/test/contracts/ink/v0/subber.wasm +0 -0
- package/src/test/contracts/ink/v0/trait-flipper.json +103 -0
- package/src/test/contracts/ink/v0/trait-flipper.wasm +0 -0
- package/src/test/contracts/ink/v1/flipper.contract.json +111 -0
- package/src/test/contracts/ink/v1/index.ts +6 -0
- package/src/test/contracts/ink/v1/psp22_minter_pauser.contract.json +1722 -0
- package/src/test/contracts/ink/v2/erc20.contract.json +630 -0
- package/src/test/contracts/ink/v2/flipper.contract.json +103 -0
- package/src/test/contracts/ink/v2/index.ts +5 -0
- package/src/test/contracts/ink/v3/flipper.contract.json +105 -0
- package/src/test/contracts/ink/v3/index.ts +6 -0
- package/src/test/contracts/ink/v3/trait_erc20.contract.json +631 -0
- package/src/test/contracts/ink/v4/erc20.contract.json +1 -0
- package/src/test/contracts/ink/v4/erc20.json +821 -0
- package/src/test/contracts/ink/v4/erc20.wasm +0 -0
- package/src/test/contracts/ink/v4/flipper.contract.json +1 -0
- package/src/test/contracts/ink/v4/flipper.json +396 -0
- package/src/test/contracts/ink/v4/flipper.wasm +0 -0
- package/src/test/contracts/ink/v4/index.ts +7 -0
- package/src/test/contracts/ink/v5/erc20.contract.json +1 -0
- package/src/test/contracts/ink/v5/erc20.json +1025 -0
- package/src/test/contracts/ink/v5/erc20.wasm +0 -0
- package/src/test/contracts/ink/v5/erc20_anonymous_transfer.json +1025 -0
- package/src/test/contracts/ink/v5/flipper.contract.json +1 -0
- package/src/test/contracts/ink/v5/flipper.json +420 -0
- package/src/test/contracts/ink/v5/flipper.wasm +0 -0
- package/src/test/contracts/ink/v5/index.ts +8 -0
- package/src/test/contracts/ink/v6/erc20.contract.json +1 -0
- package/src/test/contracts/ink/v6/erc20.json +1081 -0
- package/src/test/contracts/ink/v6/erc20.polkavm +0 -0
- package/src/test/contracts/ink/v6/index.ts +5 -0
- package/src/test/contracts/solang/index.ts +7 -0
- package/src/test/contracts/solang/v0/index.ts +4 -0
- package/src/test/contracts/solang/v0/ints256.json +113 -0
- package/src/test/contracts/solang/v0/ints256.sol +13 -0
- package/src/test/contracts/solang/v0/ints256.wasm +0 -0
- package/src/test/contracts/user/index.ts +9 -0
- package/src/test/contracts/user/v0/assetTransfer.json +299 -0
- package/src/test/contracts/user/v0/assetTransfer.wasm +0 -0
- package/src/test/contracts/user/v0/enumExample.json +528 -0
- package/src/test/contracts/user/v0/enumExample.wasm +0 -0
- package/src/test/contracts/user/v0/index.ts +7 -0
- package/src/test/contracts/user/v0/recursive.contract.json +1 -0
- package/src/test/contracts/user/v0/withString.json +777 -0
- package/src/test/contracts/user/v3/ask.json +550 -0
- package/src/test/contracts/user/v3/index.ts +4 -0
- package/src/test/contracts/user/v4/events.contract.json +2990 -0
- package/src/test/contracts/user/v4/index.ts +4 -0
- package/src/test/contracts/util.ts +14 -0
- package/src/types.ts +98 -0
- package/src/util.ts +20 -0
- package/tsconfig.build.json +22 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +26 -0
- package/tsconfig.spec.tsbuildinfo +1 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ApiBase } from '@pezkuwi/api/base';
|
|
2
|
+
import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
|
|
3
|
+
import type { ISubmittableResult } from '@pezkuwi/types/types';
|
|
4
|
+
import type { Abi } from '../Abi/index.js';
|
|
5
|
+
import type { MapConstructorExec } from './types.js';
|
|
6
|
+
import { SubmittableResult } from '@pezkuwi/api';
|
|
7
|
+
import { Base } from './Base.js';
|
|
8
|
+
import { Blueprint } from './Blueprint.js';
|
|
9
|
+
import { Contract } from './Contract.js';
|
|
10
|
+
export type CodeConstructor<ApiType extends ApiTypes> = new (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) => Code<ApiType>;
|
|
11
|
+
export declare class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
|
12
|
+
readonly blueprint?: Blueprint<ApiType> | undefined;
|
|
13
|
+
readonly contract?: Contract<ApiType> | undefined;
|
|
14
|
+
constructor(result: ISubmittableResult, blueprint?: Blueprint<ApiType> | undefined, contract?: Contract<ApiType> | undefined);
|
|
15
|
+
}
|
|
16
|
+
export declare class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
|
17
|
+
#private;
|
|
18
|
+
readonly code: Uint8Array;
|
|
19
|
+
constructor(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>);
|
|
20
|
+
get tx(): MapConstructorExec<ApiType>;
|
|
21
|
+
}
|
|
22
|
+
export declare function extendCode<ApiType extends ApiTypes>(type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ApiBase } from '@pezkuwi/api/base';
|
|
2
|
+
import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
|
|
3
|
+
import type { AccountId, AccountId20 } from '@pezkuwi/types/interfaces';
|
|
4
|
+
import type { ISubmittableResult } from '@pezkuwi/types/types';
|
|
5
|
+
import type { Abi } from '../Abi/index.js';
|
|
6
|
+
import type { DecodedEvent } from '../types.js';
|
|
7
|
+
import type { MapMessageQuery, MapMessageTx } from './types.js';
|
|
8
|
+
import { SubmittableResult } from '@pezkuwi/api';
|
|
9
|
+
import { Base } from './Base.js';
|
|
10
|
+
export type ContractConstructor<ApiType extends ApiTypes> = new (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) => Contract<ApiType>;
|
|
11
|
+
export declare class ContractSubmittableResult extends SubmittableResult {
|
|
12
|
+
readonly contractEvents?: DecodedEvent[] | undefined;
|
|
13
|
+
constructor(result: ISubmittableResult, contractEvents?: DecodedEvent[]);
|
|
14
|
+
}
|
|
15
|
+
export declare class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
|
16
|
+
#private;
|
|
17
|
+
/**
|
|
18
|
+
* @description The on-chain address for this contract
|
|
19
|
+
*/
|
|
20
|
+
readonly address: AccountId | AccountId20;
|
|
21
|
+
constructor(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20, decorateMethod: DecorateMethod<ApiType>);
|
|
22
|
+
get query(): MapMessageQuery<ApiType>;
|
|
23
|
+
get tx(): MapMessageTx<ApiType>;
|
|
24
|
+
}
|
|
25
|
+
export declare function extendContract<ApiType extends ApiTypes>(type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
|
|
3
|
+
import type { ApiTypes, ObsInnerType } from '@pezkuwi/api/types';
|
|
4
|
+
import type { AccountId } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { AbiMessage, BlueprintOptions, ContractCallOutcome, ContractOptions } from '../types.js';
|
|
6
|
+
export interface MessageMeta {
|
|
7
|
+
readonly meta: AbiMessage;
|
|
8
|
+
}
|
|
9
|
+
export interface BlueprintDeploy<ApiType extends ApiTypes> extends MessageMeta {
|
|
10
|
+
(options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
|
|
11
|
+
}
|
|
12
|
+
export interface ContractQuery<ApiType extends ApiTypes> extends MessageMeta {
|
|
13
|
+
(origin: AccountId | string | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome>;
|
|
14
|
+
}
|
|
15
|
+
export interface ContractTx<ApiType extends ApiTypes> extends MessageMeta {
|
|
16
|
+
(options: ContractOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
|
|
17
|
+
}
|
|
18
|
+
export type ContractGeneric<O, T> = (messageOrId: AbiMessage | string | number, options: O, ...params: unknown[]) => T;
|
|
19
|
+
export type ContractCallResult<ApiType extends ApiTypes, T> = ApiType extends 'rxjs' ? Observable<T> : Promise<ObsInnerType<Observable<T>>>;
|
|
20
|
+
export interface ContractCallSend<ApiType extends ApiTypes> {
|
|
21
|
+
send(account: string | AccountId | Uint8Array): ContractCallResult<ApiType, ContractCallOutcome>;
|
|
22
|
+
}
|
|
23
|
+
export type MapConstructorExec<ApiType extends ApiTypes> = Record<string, BlueprintDeploy<ApiType>>;
|
|
24
|
+
export type MapMessageTx<ApiType extends ApiTypes> = Record<string, ContractTx<ApiType>>;
|
|
25
|
+
export type MapMessageQuery<ApiType extends ApiTypes> = Record<string, ContractQuery<ApiType>>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SubmittableResult } from '@pezkuwi/api';
|
|
2
|
+
import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
|
|
3
|
+
import type { ApiTypes } from '@pezkuwi/api/types';
|
|
4
|
+
import type { WeightV1, WeightV2 } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { BN } from '@pezkuwi/util';
|
|
6
|
+
import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll } from '../types.js';
|
|
7
|
+
import type { BlueprintDeploy, ContractGeneric } from './types.js';
|
|
8
|
+
export declare const EMPTY_SALT: Uint8Array;
|
|
9
|
+
export declare function withMeta<T extends {
|
|
10
|
+
meta: AbiMessage;
|
|
11
|
+
}>(meta: AbiMessage, creator: Omit<T, 'meta'>): T;
|
|
12
|
+
export declare function createBluePrintTx<ApiType extends ApiTypes, R extends SubmittableResult>(meta: AbiMessage, fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType>;
|
|
13
|
+
export declare function createBluePrintWithId<T>(fn: (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: unknown[]) => T): ContractGeneric<BlueprintOptions, T>;
|
|
14
|
+
export declare function encodeSalt(salt?: Uint8Array | string | null): Uint8Array;
|
|
15
|
+
export declare function convertWeight(weight: WeightV1 | WeightV2 | bigint | string | number | BN): WeightAll;
|
|
16
|
+
export declare function isWeightV2(weight: WeightV1 | WeightV2 | bigint | string | number | BN): weight is WeightV2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiPromise } from '@pezkuwi/api';
|
|
2
|
+
import type { AccountId, AccountId20, Hash } from '@pezkuwi/types/interfaces';
|
|
3
|
+
import type { Abi } from '../Abi/index.js';
|
|
4
|
+
import { Blueprint, Code, Contract } from '../base/index.js';
|
|
5
|
+
export declare class BlueprintPromise extends Blueprint<'promise'> {
|
|
6
|
+
constructor(api: ApiPromise, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash);
|
|
7
|
+
}
|
|
8
|
+
export declare class CodePromise extends Code<'promise'> {
|
|
9
|
+
constructor(api: ApiPromise, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined);
|
|
10
|
+
}
|
|
11
|
+
export declare class ContractPromise extends Contract<'promise'> {
|
|
12
|
+
constructor(api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20);
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base/index.js';
|
|
2
|
+
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
|
3
|
+
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ApiRx } from '@pezkuwi/api';
|
|
2
|
+
import type { AccountId, Hash } from '@pezkuwi/types/interfaces';
|
|
3
|
+
import type { Abi } from '../Abi/index.js';
|
|
4
|
+
import { Blueprint, Code, Contract } from '../base/index.js';
|
|
5
|
+
export declare class BlueprintRx extends Blueprint<'rxjs'> {
|
|
6
|
+
constructor(api: ApiRx, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash);
|
|
7
|
+
}
|
|
8
|
+
export declare class CodeRx extends Code<'rxjs'> {
|
|
9
|
+
constructor(api: ApiRx, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined);
|
|
10
|
+
}
|
|
11
|
+
export declare class ContractRx extends Contract<'rxjs'> {
|
|
12
|
+
constructor(api: ApiRx, abi: string | Record<string, unknown> | Abi, address: string | AccountId);
|
|
13
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base/index.js';
|
|
2
|
+
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
|
3
|
+
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { ApiBase } from '@pezkuwi/api/base';
|
|
2
|
+
import type { ApiTypes } from '@pezkuwi/api/types';
|
|
3
|
+
import type { Text } from '@pezkuwi/types';
|
|
4
|
+
import type { ContractExecResultResult, ContractSelector, StorageDeposit, Weight, WeightV2 } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { Codec, TypeDef } from '@pezkuwi/types/types';
|
|
6
|
+
import type { BN } from '@pezkuwi/util';
|
|
7
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
8
|
+
import type { Abi } from './index.js';
|
|
9
|
+
export interface ContractBase<ApiType extends ApiTypes> {
|
|
10
|
+
readonly abi: Abi;
|
|
11
|
+
readonly api: ApiBase<ApiType>;
|
|
12
|
+
getMessage: (name: string) => AbiMessage;
|
|
13
|
+
messages: AbiMessage[];
|
|
14
|
+
}
|
|
15
|
+
export interface AbiParam {
|
|
16
|
+
name: string;
|
|
17
|
+
type: TypeDef;
|
|
18
|
+
}
|
|
19
|
+
export type AbiMessageParam = AbiParam;
|
|
20
|
+
export interface AbiEventParam extends AbiParam {
|
|
21
|
+
indexed: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface AbiEvent {
|
|
24
|
+
args: AbiEventParam[];
|
|
25
|
+
docs: string[];
|
|
26
|
+
fromU8a: (data: Uint8Array) => DecodedEvent;
|
|
27
|
+
identifier: string;
|
|
28
|
+
index: number;
|
|
29
|
+
signatureTopic?: HexString | null;
|
|
30
|
+
}
|
|
31
|
+
export interface AbiMessage {
|
|
32
|
+
args: AbiMessageParam[];
|
|
33
|
+
docs: string[];
|
|
34
|
+
fromU8a: (data: Uint8Array) => DecodedMessage;
|
|
35
|
+
identifier: string;
|
|
36
|
+
index: number;
|
|
37
|
+
isConstructor?: boolean;
|
|
38
|
+
isDefault?: boolean;
|
|
39
|
+
isMutating?: boolean;
|
|
40
|
+
isPayable?: boolean;
|
|
41
|
+
method: string;
|
|
42
|
+
path: string[];
|
|
43
|
+
returnType?: TypeDef | null;
|
|
44
|
+
selector: ContractSelector;
|
|
45
|
+
toU8a: (params: unknown[]) => Uint8Array;
|
|
46
|
+
}
|
|
47
|
+
export type AbiConstructor = AbiMessage;
|
|
48
|
+
export type InterfaceContractCalls = Record<string, Function>;
|
|
49
|
+
export interface ContractCallOutcome {
|
|
50
|
+
debugMessage: Text;
|
|
51
|
+
gasConsumed: Weight;
|
|
52
|
+
gasRequired: Weight;
|
|
53
|
+
output: Codec | null;
|
|
54
|
+
result: ContractExecResultResult;
|
|
55
|
+
storageDeposit: StorageDeposit;
|
|
56
|
+
}
|
|
57
|
+
export interface DecodedEvent {
|
|
58
|
+
args: Codec[];
|
|
59
|
+
event: AbiEvent;
|
|
60
|
+
}
|
|
61
|
+
export interface DecodedMessage {
|
|
62
|
+
args: Codec[];
|
|
63
|
+
message: AbiMessage;
|
|
64
|
+
}
|
|
65
|
+
export interface ContractOptions {
|
|
66
|
+
gasLimit?: bigint | string | number | BN | WeightV2;
|
|
67
|
+
storageDepositLimit?: bigint | string | number | BN | null;
|
|
68
|
+
value?: bigint | BN | string | number;
|
|
69
|
+
}
|
|
70
|
+
export interface BlueprintOptions extends ContractOptions {
|
|
71
|
+
salt?: Uint8Array | string | null;
|
|
72
|
+
}
|
|
73
|
+
export interface WeightAll {
|
|
74
|
+
v1Weight: BN;
|
|
75
|
+
v2Weight: {
|
|
76
|
+
refTime: BN;
|
|
77
|
+
proofSize?: BN | undefined;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SubmittableResult } from '@pezkuwi/api';
|
|
2
|
+
import type { EventRecord } from '@pezkuwi/types/interfaces';
|
|
3
|
+
type ContractEvents = 'CodeStored' | 'ContractEmitted' | 'ContractExecution' | 'Instantiated';
|
|
4
|
+
export declare function applyOnEvent<T>(result: SubmittableResult, types: ContractEvents[], fn: (records: EventRecord[]) => T, isRevive: boolean): T | undefined;
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Abi = void 0;
|
|
4
|
+
const types_1 = require("@pezkuwi/types");
|
|
5
|
+
const types_create_1 = require("@pezkuwi/types-create");
|
|
6
|
+
const util_1 = require("@pezkuwi/util");
|
|
7
|
+
const toLatestCompatible_js_1 = require("./toLatestCompatible.js");
|
|
8
|
+
const l = (0, util_1.logger)('Abi');
|
|
9
|
+
const PRIMITIVE_ALWAYS = ['AccountId', 'AccountId20', 'AccountIndex', 'Address', 'Balance'];
|
|
10
|
+
function findMessage(list, messageOrId) {
|
|
11
|
+
const message = (0, util_1.isNumber)(messageOrId)
|
|
12
|
+
? list[messageOrId]
|
|
13
|
+
: (0, util_1.isString)(messageOrId)
|
|
14
|
+
? list.find(({ identifier }) => [identifier, (0, util_1.stringCamelCase)(identifier)].includes(messageOrId.toString()))
|
|
15
|
+
: messageOrId;
|
|
16
|
+
return (0, util_1.assertReturn)(message, () => `Attempted to call an invalid contract interface, ${(0, util_1.stringify)(messageOrId)}`);
|
|
17
|
+
}
|
|
18
|
+
function getMetadata(registry, json) {
|
|
19
|
+
// this is for V1, V2, V3
|
|
20
|
+
const vx = toLatestCompatible_js_1.enumVersions.find((v) => (0, util_1.isObject)(json[v]));
|
|
21
|
+
// this was added in V4
|
|
22
|
+
const jsonVersion = json.version;
|
|
23
|
+
if (!vx && jsonVersion && !toLatestCompatible_js_1.enumVersions.find((v) => v === `V${jsonVersion}`)) {
|
|
24
|
+
throw new Error(`Unable to handle version ${jsonVersion}`);
|
|
25
|
+
}
|
|
26
|
+
const metadata = registry.createType('ContractMetadata', vx
|
|
27
|
+
? { [vx]: json[vx] }
|
|
28
|
+
: jsonVersion
|
|
29
|
+
? { [`V${jsonVersion}`]: json }
|
|
30
|
+
: { V0: json });
|
|
31
|
+
const converter = toLatestCompatible_js_1.convertVersions.find(([v]) => metadata[`is${v}`]);
|
|
32
|
+
if (!converter) {
|
|
33
|
+
throw new Error(`Unable to convert ABI with version ${metadata.type} to a supported version`);
|
|
34
|
+
}
|
|
35
|
+
const upgradedMetadata = converter[1](registry, metadata[`as${converter[0]}`]);
|
|
36
|
+
return upgradedMetadata;
|
|
37
|
+
}
|
|
38
|
+
function isRevive(json) {
|
|
39
|
+
const source = json['source'];
|
|
40
|
+
const version = json['version'];
|
|
41
|
+
const hasContractBinary = typeof source === 'object' &&
|
|
42
|
+
source !== null &&
|
|
43
|
+
'contract_binary' in source;
|
|
44
|
+
const hasVersion = typeof version === 'number' && version >= 6;
|
|
45
|
+
return hasContractBinary || hasVersion;
|
|
46
|
+
}
|
|
47
|
+
function parseJson(json, chainProperties) {
|
|
48
|
+
const registry = new types_1.TypeRegistry();
|
|
49
|
+
const revive = isRevive(json);
|
|
50
|
+
const typeName = revive ? 'ContractReviveProjectInfo' : 'ContractProjectInfo';
|
|
51
|
+
const info = registry.createType(typeName, json);
|
|
52
|
+
const metadata = getMetadata(registry, json);
|
|
53
|
+
const lookup = registry.createType('PortableRegistry', { types: metadata.types }, true);
|
|
54
|
+
// attach the lookup to the registry - now the types are known
|
|
55
|
+
registry.setLookup(lookup);
|
|
56
|
+
if (chainProperties) {
|
|
57
|
+
registry.setChainProperties(chainProperties);
|
|
58
|
+
}
|
|
59
|
+
// warm-up the actual type, pre-use
|
|
60
|
+
lookup.types.forEach(({ id }) => lookup.getTypeDef(id));
|
|
61
|
+
return [json, registry, metadata, info, revive];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @internal
|
|
65
|
+
* Determines if the given input value is a ContractTypeSpec
|
|
66
|
+
*/
|
|
67
|
+
function isTypeSpec(value) {
|
|
68
|
+
return !!value && value instanceof Map && !(0, util_1.isUndefined)(value.type) && !(0, util_1.isUndefined)(value.displayName);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* @internal
|
|
72
|
+
* Determines if the given input value is an Option
|
|
73
|
+
*/
|
|
74
|
+
function isOption(value) {
|
|
75
|
+
return !!value && value instanceof types_1.Option;
|
|
76
|
+
}
|
|
77
|
+
class Abi {
|
|
78
|
+
events;
|
|
79
|
+
constructors;
|
|
80
|
+
info;
|
|
81
|
+
json;
|
|
82
|
+
messages;
|
|
83
|
+
metadata;
|
|
84
|
+
registry;
|
|
85
|
+
environment = new Map();
|
|
86
|
+
isRevive;
|
|
87
|
+
constructor(abiJson, chainProperties) {
|
|
88
|
+
[this.json, this.registry, this.metadata, this.info, this.isRevive] = parseJson((0, util_1.isString)(abiJson)
|
|
89
|
+
? JSON.parse(abiJson)
|
|
90
|
+
: abiJson, chainProperties);
|
|
91
|
+
this.constructors = this.metadata.spec.constructors.map((spec, index) => this.#createMessage(spec, index, {
|
|
92
|
+
isConstructor: true,
|
|
93
|
+
isDefault: spec.default.isTrue,
|
|
94
|
+
isPayable: spec.payable.isTrue,
|
|
95
|
+
returnType: spec.returnType.isSome
|
|
96
|
+
? this.registry.lookup.getTypeDef(spec.returnType.unwrap().type)
|
|
97
|
+
: null
|
|
98
|
+
}));
|
|
99
|
+
this.events = this.metadata.spec.events.map((_, index) => this.#createEvent(index));
|
|
100
|
+
this.messages = this.metadata.spec.messages.map((spec, index) => this.#createMessage(spec, index, {
|
|
101
|
+
isDefault: spec.default.isTrue,
|
|
102
|
+
isMutating: spec.mutates.isTrue,
|
|
103
|
+
isPayable: spec.payable.isTrue,
|
|
104
|
+
returnType: spec.returnType.isSome
|
|
105
|
+
? this.registry.lookup.getTypeDef(spec.returnType.unwrap().type)
|
|
106
|
+
: null
|
|
107
|
+
}));
|
|
108
|
+
// NOTE See the rationale for having Option<...> values in the actual
|
|
109
|
+
// ContractEnvironmentV4 structure definition in interfaces/contractsAbi
|
|
110
|
+
// (Due to conversions, the fields may not exist)
|
|
111
|
+
for (const [key, opt] of this.metadata.spec.environment.entries()) {
|
|
112
|
+
if (isOption(opt)) {
|
|
113
|
+
if (opt.isSome) {
|
|
114
|
+
const value = opt.unwrap();
|
|
115
|
+
if ((0, util_1.isBn)(value)) {
|
|
116
|
+
this.environment.set(key, value);
|
|
117
|
+
}
|
|
118
|
+
else if (isTypeSpec(value)) {
|
|
119
|
+
this.environment.set(key, this.registry.lookup.getTypeDef(value.type));
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
throw new Error(`Invalid environment definition for ${key}:: Expected either Number or ContractTypeSpec`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
throw new Error(`Expected Option<*> definition for ${key} in ContractEnvironment`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Warning: Unstable API, bound to change
|
|
133
|
+
*/
|
|
134
|
+
decodeEvent(record) {
|
|
135
|
+
switch (this.metadata.version.toString()) {
|
|
136
|
+
// earlier version are hoisted to v4
|
|
137
|
+
case '4':
|
|
138
|
+
return this.#decodeEventV4(record);
|
|
139
|
+
case '5':
|
|
140
|
+
return this.#decodeEventV5(record);
|
|
141
|
+
// Latest
|
|
142
|
+
default:
|
|
143
|
+
return this.#decodeEventV6(record);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
#decodeEventV6 = (record) => {
|
|
147
|
+
const topics = record.event.data[2];
|
|
148
|
+
// Try to match by signature topic (first topic)
|
|
149
|
+
const signatureTopic = topics[0];
|
|
150
|
+
const data = record.event.data[1];
|
|
151
|
+
if (signatureTopic) {
|
|
152
|
+
const event = this.events.find((e) => e.signatureTopic !== undefined && e.signatureTopic !== null && e.signatureTopic === signatureTopic.toHex());
|
|
153
|
+
// Early return if event found by signature topic
|
|
154
|
+
if (event) {
|
|
155
|
+
return event.fromU8a(data);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// If no event returned yet, it might be anonymous
|
|
159
|
+
const amountOfTopics = topics.length;
|
|
160
|
+
const potentialEvents = this.events.filter((e) => {
|
|
161
|
+
// event can't have a signature topic
|
|
162
|
+
if (e.signatureTopic !== null && e.signatureTopic !== undefined) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
// event should have same amount of indexed fields as emitted topics
|
|
166
|
+
const amountIndexed = e.args.filter((a) => a.indexed).length;
|
|
167
|
+
if (amountIndexed !== amountOfTopics) {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
// If all conditions met, it's a potential event
|
|
171
|
+
return true;
|
|
172
|
+
});
|
|
173
|
+
if (potentialEvents.length === 1) {
|
|
174
|
+
return potentialEvents[0].fromU8a(data);
|
|
175
|
+
}
|
|
176
|
+
throw new Error('Unable to determine event');
|
|
177
|
+
};
|
|
178
|
+
#decodeEventV5 = (record) => {
|
|
179
|
+
// Find event by first topic, which potentially is the signature_topic
|
|
180
|
+
const signatureTopic = record.topics[0];
|
|
181
|
+
const data = record.event.data[1];
|
|
182
|
+
if (signatureTopic) {
|
|
183
|
+
const event = this.events.find((e) => e.signatureTopic !== undefined && e.signatureTopic !== null && e.signatureTopic === signatureTopic.toHex());
|
|
184
|
+
// Early return if event found by signature topic
|
|
185
|
+
if (event) {
|
|
186
|
+
return event.fromU8a(data);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// If no event returned yet, it might be anonymous
|
|
190
|
+
const amountOfTopics = record.topics.length;
|
|
191
|
+
const potentialEvents = this.events.filter((e) => {
|
|
192
|
+
// event can't have a signature topic
|
|
193
|
+
if (e.signatureTopic !== null && e.signatureTopic !== undefined) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
// event should have same amount of indexed fields as emitted topics
|
|
197
|
+
const amountIndexed = e.args.filter((a) => a.indexed).length;
|
|
198
|
+
if (amountIndexed !== amountOfTopics) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
// If all conditions met, it's a potential event
|
|
202
|
+
return true;
|
|
203
|
+
});
|
|
204
|
+
if (potentialEvents.length === 1) {
|
|
205
|
+
return potentialEvents[0].fromU8a(data);
|
|
206
|
+
}
|
|
207
|
+
throw new Error('Unable to determine event');
|
|
208
|
+
};
|
|
209
|
+
#decodeEventV4 = (record) => {
|
|
210
|
+
const data = record.event.data[1];
|
|
211
|
+
const index = data[0];
|
|
212
|
+
const event = this.events[index];
|
|
213
|
+
if (!event) {
|
|
214
|
+
throw new Error(`Unable to find event with index ${index}`);
|
|
215
|
+
}
|
|
216
|
+
return event.fromU8a(data.subarray(1));
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Warning: Unstable API, bound to change
|
|
220
|
+
*/
|
|
221
|
+
decodeConstructor(data) {
|
|
222
|
+
return this.#decodeMessage('message', this.constructors, data);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Warning: Unstable API, bound to change
|
|
226
|
+
*/
|
|
227
|
+
decodeMessage(data) {
|
|
228
|
+
return this.#decodeMessage('message', this.messages, data);
|
|
229
|
+
}
|
|
230
|
+
findConstructor(constructorOrId) {
|
|
231
|
+
return findMessage(this.constructors, constructorOrId);
|
|
232
|
+
}
|
|
233
|
+
findMessage(messageOrId) {
|
|
234
|
+
return findMessage(this.messages, messageOrId);
|
|
235
|
+
}
|
|
236
|
+
#createArgs = (args, spec) => {
|
|
237
|
+
return args.map(({ label, type }, index) => {
|
|
238
|
+
try {
|
|
239
|
+
if (!(0, util_1.isObject)(type)) {
|
|
240
|
+
throw new Error('Invalid type definition found');
|
|
241
|
+
}
|
|
242
|
+
const displayName = type.displayName.length
|
|
243
|
+
? type.displayName[type.displayName.length - 1].toString()
|
|
244
|
+
: undefined;
|
|
245
|
+
const camelName = (0, util_1.stringCamelCase)(label);
|
|
246
|
+
if (displayName && PRIMITIVE_ALWAYS.includes(displayName)) {
|
|
247
|
+
return {
|
|
248
|
+
name: camelName,
|
|
249
|
+
type: {
|
|
250
|
+
info: types_create_1.TypeDefInfo.Plain,
|
|
251
|
+
type: displayName
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const typeDef = this.registry.lookup.getTypeDef(type.type);
|
|
256
|
+
return {
|
|
257
|
+
name: camelName,
|
|
258
|
+
type: displayName && !typeDef.type.startsWith(displayName)
|
|
259
|
+
? { displayName, ...typeDef }
|
|
260
|
+
: typeDef
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
l.error(`Error expanding argument ${index} in ${(0, util_1.stringify)(spec)}`);
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
};
|
|
269
|
+
#createMessageParams = (args, spec) => {
|
|
270
|
+
return this.#createArgs(args, spec);
|
|
271
|
+
};
|
|
272
|
+
#createEventParams = (args, spec) => {
|
|
273
|
+
const params = this.#createArgs(args, spec);
|
|
274
|
+
return params.map((p, index) => ({ ...p, indexed: args[index].indexed.toPrimitive() }));
|
|
275
|
+
};
|
|
276
|
+
#createEvent = (index) => {
|
|
277
|
+
// TODO TypeScript would narrow this type to the correct version,
|
|
278
|
+
// but version is `Text` so I need to call `toString()` here,
|
|
279
|
+
// which breaks the type inference.
|
|
280
|
+
switch (this.metadata.version.toString()) {
|
|
281
|
+
case '4':
|
|
282
|
+
return this.#createEventV4(this.metadata.spec.events[index], index);
|
|
283
|
+
default:
|
|
284
|
+
return this.#createEventV5(this.metadata.spec.events[index], index);
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
#createEventV5 = (spec, index) => {
|
|
288
|
+
const args = this.#createEventParams(spec.args, spec);
|
|
289
|
+
const event = {
|
|
290
|
+
args,
|
|
291
|
+
docs: spec.docs.map((d) => d.toString()),
|
|
292
|
+
fromU8a: (data) => ({
|
|
293
|
+
args: this.#decodeArgs(args, data),
|
|
294
|
+
event
|
|
295
|
+
}),
|
|
296
|
+
identifier: [spec.module_path, spec.label].join('::'),
|
|
297
|
+
index,
|
|
298
|
+
signatureTopic: spec.signature_topic.isSome ? spec.signature_topic.unwrap().toHex() : null
|
|
299
|
+
};
|
|
300
|
+
return event;
|
|
301
|
+
};
|
|
302
|
+
#createEventV4 = (spec, index) => {
|
|
303
|
+
const args = this.#createEventParams(spec.args, spec);
|
|
304
|
+
const event = {
|
|
305
|
+
args,
|
|
306
|
+
docs: spec.docs.map((d) => d.toString()),
|
|
307
|
+
fromU8a: (data) => ({
|
|
308
|
+
args: this.#decodeArgs(args, data),
|
|
309
|
+
event
|
|
310
|
+
}),
|
|
311
|
+
identifier: spec.label.toString(),
|
|
312
|
+
index
|
|
313
|
+
};
|
|
314
|
+
return event;
|
|
315
|
+
};
|
|
316
|
+
#createMessage = (spec, index, add = {}) => {
|
|
317
|
+
const args = this.#createMessageParams(spec.args, spec);
|
|
318
|
+
const identifier = spec.label.toString();
|
|
319
|
+
const message = {
|
|
320
|
+
...add,
|
|
321
|
+
args,
|
|
322
|
+
docs: spec.docs.map((d) => d.toString()),
|
|
323
|
+
fromU8a: (data) => ({
|
|
324
|
+
args: this.#decodeArgs(args, data),
|
|
325
|
+
message
|
|
326
|
+
}),
|
|
327
|
+
identifier,
|
|
328
|
+
index,
|
|
329
|
+
isDefault: spec.default.isTrue,
|
|
330
|
+
method: (0, util_1.stringCamelCase)(identifier),
|
|
331
|
+
path: identifier.split('::').map((s) => (0, util_1.stringCamelCase)(s)),
|
|
332
|
+
selector: spec.selector,
|
|
333
|
+
toU8a: (params) => this.#encodeMessageArgs(spec, args, params)
|
|
334
|
+
};
|
|
335
|
+
return message;
|
|
336
|
+
};
|
|
337
|
+
#decodeArgs = (args, data) => {
|
|
338
|
+
// for decoding we expect the input to be just the arg data, no selectors
|
|
339
|
+
// no length added (this allows use with events as well)
|
|
340
|
+
let offset = 0;
|
|
341
|
+
return args.map(({ type: { lookupName, type } }) => {
|
|
342
|
+
const value = this.registry.createType(lookupName || type, data.subarray(offset));
|
|
343
|
+
offset += value.encodedLength;
|
|
344
|
+
return value;
|
|
345
|
+
});
|
|
346
|
+
};
|
|
347
|
+
#decodeMessage = (type, list, data) => {
|
|
348
|
+
const [, trimmed] = (0, util_1.compactStripLength)(data);
|
|
349
|
+
const selector = trimmed.subarray(0, 4);
|
|
350
|
+
const message = list.find((m) => m.selector.eq(selector));
|
|
351
|
+
if (!message) {
|
|
352
|
+
throw new Error(`Unable to find ${type} with selector ${(0, util_1.u8aToHex)(selector)}`);
|
|
353
|
+
}
|
|
354
|
+
return message.fromU8a(trimmed.subarray(4));
|
|
355
|
+
};
|
|
356
|
+
#encodeMessageArgs = ({ label, selector }, args, data) => {
|
|
357
|
+
if (data.length !== args.length) {
|
|
358
|
+
throw new Error(`Expected ${args.length} arguments to contract message '${label.toString()}', found ${data.length}`);
|
|
359
|
+
}
|
|
360
|
+
return (0, util_1.compactAddLength)((0, util_1.u8aConcat)(this.registry.createType('ContractSelector', selector).toU8a(), ...args.map(({ type: { lookupName, type } }, index) => this.registry.createType(lookupName || type, data[index]).toU8a())));
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
exports.Abi = Abi;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertVersions = exports.v0ToLatestCompatible = exports.v1ToLatestCompatible = exports.v2ToLatestCompatible = exports.v3ToLatestCompatible = exports.enumVersions = void 0;
|
|
4
|
+
exports.v6ToLatestCompatible = v6ToLatestCompatible;
|
|
5
|
+
exports.v5ToLatestCompatible = v5ToLatestCompatible;
|
|
6
|
+
exports.v4ToLatestCompatible = v4ToLatestCompatible;
|
|
7
|
+
const toV1_js_1 = require("./toV1.js");
|
|
8
|
+
const toV2_js_1 = require("./toV2.js");
|
|
9
|
+
const toV3_js_1 = require("./toV3.js");
|
|
10
|
+
const toV4_js_1 = require("./toV4.js");
|
|
11
|
+
exports.enumVersions = ['V6', 'V5', 'V4', 'V3', 'V2', 'V1'];
|
|
12
|
+
function createConverter(next, step) {
|
|
13
|
+
return (registry, input) => next(registry, step(registry, input));
|
|
14
|
+
}
|
|
15
|
+
function v6ToLatestCompatible(_registry, v6) {
|
|
16
|
+
return v6;
|
|
17
|
+
}
|
|
18
|
+
function v5ToLatestCompatible(_registry, v5) {
|
|
19
|
+
return v5;
|
|
20
|
+
}
|
|
21
|
+
function v4ToLatestCompatible(_registry, v4) {
|
|
22
|
+
return v4;
|
|
23
|
+
}
|
|
24
|
+
exports.v3ToLatestCompatible = createConverter(v4ToLatestCompatible, toV4_js_1.v3ToV4);
|
|
25
|
+
exports.v2ToLatestCompatible = createConverter(exports.v3ToLatestCompatible, toV3_js_1.v2ToV3);
|
|
26
|
+
exports.v1ToLatestCompatible = createConverter(exports.v2ToLatestCompatible, toV2_js_1.v1ToV2);
|
|
27
|
+
exports.v0ToLatestCompatible = createConverter(exports.v1ToLatestCompatible, toV1_js_1.v0ToV1);
|
|
28
|
+
exports.convertVersions = [
|
|
29
|
+
['V6', v6ToLatestCompatible],
|
|
30
|
+
['V5', v5ToLatestCompatible],
|
|
31
|
+
['V4', v4ToLatestCompatible],
|
|
32
|
+
['V3', exports.v3ToLatestCompatible],
|
|
33
|
+
['V2', exports.v2ToLatestCompatible],
|
|
34
|
+
['V1', exports.v1ToLatestCompatible],
|
|
35
|
+
['V0', exports.v0ToLatestCompatible]
|
|
36
|
+
];
|