@pezkuwi/api-contract 16.5.5 → 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/Abi/index.d.ts +31 -0
- package/Abi/index.js +359 -0
- package/Abi/toLatestCompatible.d.ts +15 -0
- package/Abi/toLatestCompatible.js +30 -0
- package/Abi/toV1.d.ts +3 -0
- package/Abi/toV1.js +21 -0
- package/Abi/toV2.d.ts +3 -0
- package/Abi/toV2.js +27 -0
- package/Abi/toV3.d.ts +3 -0
- package/Abi/toV3.js +10 -0
- package/Abi/toV4.d.ts +3 -0
- package/Abi/toV4.js +10 -0
- package/LICENSE +201 -0
- package/README.md +1 -1
- package/augment.d.ts +1 -0
- package/augment.js +1 -0
- package/base/Base.d.ts +13 -0
- package/base/Base.js +40 -0
- package/base/Blueprint.d.ts +24 -0
- package/base/Blueprint.js +51 -0
- package/base/Code.d.ts +22 -0
- package/base/Code.js +74 -0
- package/base/Contract.d.ts +25 -0
- package/base/Contract.js +127 -0
- package/base/index.d.ts +3 -0
- package/base/index.js +3 -0
- package/base/mock.d.ts +3 -0
- package/base/mock.js +38 -0
- package/base/types.d.ts +25 -0
- package/base/types.js +1 -0
- package/base/util.d.ts +16 -0
- package/base/util.js +33 -0
- package/build/Abi/index.js +359 -0
- package/build/Abi/toLatestCompatible.js +30 -0
- package/build/Abi/toV1.js +21 -0
- package/build/Abi/toV2.js +27 -0
- package/build/Abi/toV3.js +10 -0
- package/build/Abi/toV4.js +10 -0
- package/build/LICENSE +201 -0
- package/build/README.md +3 -0
- package/build/augment.js +1 -0
- package/build/base/Base.js +40 -0
- package/build/base/Blueprint.js +51 -0
- package/build/base/Code.js +74 -0
- package/build/base/Contract.js +127 -0
- package/build/base/index.js +3 -0
- package/build/base/mock.js +38 -0
- package/build/base/types.js +1 -0
- package/build/base/util.d.ts +1 -1
- package/build/base/util.js +33 -0
- package/build/bundle-pezkuwi-api-contract.js +1238 -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.js +2 -0
- package/build/package.json +408 -0
- package/build/packageDetect.js +5 -0
- package/build/packageInfo.js +1 -0
- package/build/promise/index.js +17 -0
- package/build/promise/types.js +1 -0
- package/build/rx/index.js +17 -0
- package/build/rx/types.js +1 -0
- package/build/types.js +1 -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 +1238 -0
- package/bundle.d.ts +4 -0
- package/bundle.js +4 -0
- package/cjs/Abi/index.d.ts +31 -0
- package/cjs/Abi/index.js +363 -0
- package/cjs/Abi/toLatestCompatible.d.ts +15 -0
- package/cjs/Abi/toLatestCompatible.js +36 -0
- package/cjs/Abi/toV1.d.ts +3 -0
- package/cjs/Abi/toV1.js +24 -0
- package/cjs/Abi/toV2.d.ts +3 -0
- package/cjs/Abi/toV2.js +30 -0
- package/cjs/Abi/toV3.d.ts +3 -0
- package/cjs/Abi/toV3.js +13 -0
- package/cjs/Abi/toV4.d.ts +3 -0
- package/cjs/Abi/toV4.js +13 -0
- package/cjs/augment.d.ts +1 -0
- package/cjs/augment.js +3 -0
- package/cjs/base/Base.d.ts +13 -0
- package/cjs/base/Base.js +44 -0
- package/cjs/base/Blueprint.d.ts +24 -0
- package/cjs/base/Blueprint.js +57 -0
- package/cjs/base/Code.d.ts +22 -0
- package/cjs/base/Code.js +80 -0
- package/cjs/base/Contract.d.ts +25 -0
- package/cjs/base/Contract.js +133 -0
- package/cjs/base/index.d.ts +3 -0
- package/cjs/base/index.js +14 -0
- package/cjs/base/mock.d.ts +3 -0
- package/cjs/base/mock.js +41 -0
- package/cjs/base/types.d.ts +25 -0
- package/cjs/base/types.js +2 -0
- package/cjs/base/util.d.ts +16 -0
- package/cjs/base/util.js +42 -0
- package/cjs/bundle.d.ts +4 -0
- package/cjs/bundle.js +10 -0
- package/cjs/index.d.ts +2 -0
- package/cjs/index.js +5 -0
- package/cjs/package.json +3 -0
- package/cjs/packageDetect.d.ts +1 -0
- package/cjs/packageDetect.js +7 -0
- package/cjs/packageInfo.d.ts +6 -0
- package/cjs/packageInfo.js +4 -0
- package/cjs/promise/index.d.ts +13 -0
- package/cjs/promise/index.js +23 -0
- package/cjs/promise/types.d.ts +3 -0
- package/cjs/promise/types.js +2 -0
- package/cjs/rx/index.d.ts +13 -0
- package/cjs/rx/index.js +23 -0
- package/cjs/rx/types.d.ts +3 -0
- package/cjs/rx/types.js +2 -0
- package/cjs/types.d.ts +79 -0
- package/cjs/types.js +2 -0
- package/cjs/util.d.ts +5 -0
- package/cjs/util.js +13 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +384 -15
- package/packageDetect.d.ts +1 -0
- package/packageDetect.js +5 -0
- package/packageInfo.d.ts +6 -0
- package/packageInfo.js +1 -0
- package/promise/index.d.ts +13 -0
- package/promise/index.js +17 -0
- package/promise/types.d.ts +3 -0
- package/promise/types.js +1 -0
- package/rx/index.d.ts +13 -0
- package/rx/index.js +17 -0
- package/rx/types.d.ts +3 -0
- package/rx/types.js +1 -0
- package/src/Abi/Abi.spec.ts +2 -2
- package/src/Abi/index.ts +1 -1
- package/src/Abi/toLatestCompatible.spec.ts +1 -1
- package/src/Abi/toLatestCompatible.ts +1 -1
- package/src/Abi/toV1.ts +1 -1
- package/src/Abi/toV2.ts +1 -1
- package/src/Abi/toV3.ts +1 -1
- package/src/Abi/toV4.ts +1 -1
- package/src/augment.ts +1 -1
- package/src/base/Base.ts +1 -1
- package/src/base/Blueprint.ts +1 -1
- package/src/base/Code.spec.ts +1 -1
- package/src/base/Code.ts +1 -1
- package/src/base/Contract.ts +1 -1
- package/src/base/index.ts +1 -1
- package/src/base/mock.ts +1 -1
- package/src/base/types.ts +1 -1
- package/src/base/util.ts +1 -1
- package/src/bundle.ts +1 -1
- package/src/checkTypes.manual.ts +4 -4
- package/src/index.ts +1 -1
- package/src/mod.ts +1 -1
- package/src/packageDetect.ts +2 -2
- package/src/packageInfo.ts +3 -3
- package/src/promise/index.ts +1 -1
- package/src/promise/types.ts +1 -1
- package/src/rx/index.ts +1 -1
- package/src/rx/types.ts +1 -1
- package/src/test/contracts/index.ts +1 -1
- package/src/test/contracts/ink/index.ts +1 -1
- package/src/test/contracts/ink/v0/index.ts +1 -1
- package/src/test/contracts/ink/v1/index.ts +1 -1
- package/src/test/contracts/ink/v2/index.ts +1 -1
- package/src/test/contracts/ink/v3/index.ts +1 -1
- package/src/test/contracts/ink/v4/index.ts +1 -1
- package/src/test/contracts/ink/v5/index.ts +1 -1
- package/src/test/contracts/ink/v6/index.ts +1 -1
- package/src/test/contracts/solang/index.ts +1 -1
- package/src/test/contracts/solang/v0/index.ts +1 -1
- package/src/test/contracts/user/index.ts +1 -1
- package/src/test/contracts/user/v0/index.ts +1 -1
- package/src/test/contracts/user/v3/index.ts +1 -1
- package/src/test/contracts/user/v4/index.ts +1 -1
- package/src/test/contracts/util.ts +1 -1
- package/src/types.ts +1 -1
- package/src/util.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.spec.tsbuildinfo +1 -0
- package/types.d.ts +79 -0
- package/types.js +1 -0
- package/util.d.ts +5 -0
- package/util.js +10 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ApiBase } from 'https://deno.land/x/pezkuwi/api/base/index.ts';
|
|
3
|
+
import type { ApiTypes, DecorateMethod } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
4
|
+
import type { WeightV2 } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
5
|
+
import type { Registry } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
|
|
6
|
+
|
|
7
|
+
import { isFunction } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
8
|
+
|
|
9
|
+
import { Abi } from '../Abi/index.ts';
|
|
10
|
+
|
|
11
|
+
export abstract class Base<ApiType extends ApiTypes> {
|
|
12
|
+
readonly abi: Abi;
|
|
13
|
+
readonly api: ApiBase<ApiType>;
|
|
14
|
+
|
|
15
|
+
protected readonly _decorateMethod: DecorateMethod<ApiType>;
|
|
16
|
+
protected readonly _isWeightV1: boolean;
|
|
17
|
+
protected readonly _isRevive: boolean;
|
|
18
|
+
|
|
19
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
|
20
|
+
if (!api || !api.isConnected || !api.tx) {
|
|
21
|
+
throw new Error('Your API has not been initialized correctly and is not connected to a chain');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this.abi = abi instanceof Abi
|
|
25
|
+
? abi
|
|
26
|
+
: new Abi(abi, api.registry.getChainProperties());
|
|
27
|
+
this.api = api;
|
|
28
|
+
this._decorateMethod = decorateMethod;
|
|
29
|
+
this._isWeightV1 = !api.registry.createType<WeightV2>('Weight').proofSize;
|
|
30
|
+
this._isRevive = this.abi.isRevive;
|
|
31
|
+
|
|
32
|
+
if (this._isRevive) {
|
|
33
|
+
if (!api.tx.revive || !isFunction(api.tx.revive.instantiateWithCode) || api.tx.revive.instantiateWithCode.meta.args.length !== 6) {
|
|
34
|
+
throw new Error('The runtime does not expose api.tx.revive.instantiateWithCode with storageDepositLimit');
|
|
35
|
+
} else if (!api.call.reviveApi || !isFunction(api.call.reviveApi.call)) {
|
|
36
|
+
throw new Error('Your runtime does not expose the api.call.reviveApi.call runtime interfaces');
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
|
|
40
|
+
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
|
|
41
|
+
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
|
|
42
|
+
throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public get registry (): Registry {
|
|
48
|
+
return this.api.registry;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ApiBase } from 'https://deno.land/x/pezkuwi/api/base/index.ts';
|
|
3
|
+
import type { SubmittableExtrinsic } from 'https://deno.land/x/pezkuwi/api/submittable/types.ts';
|
|
4
|
+
import type { ApiTypes, DecorateMethod } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
5
|
+
import type { AccountId, EventRecord, Hash } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
6
|
+
import type { ISubmittableResult } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
|
|
7
|
+
import type { Abi } from '../Abi/index.ts';
|
|
8
|
+
import type { AbiConstructor, BlueprintOptions } from '../types.ts';
|
|
9
|
+
import type { MapConstructorExec } from './types.ts';
|
|
10
|
+
|
|
11
|
+
import { SubmittableResult } from 'https://deno.land/x/pezkuwi/api/mod.ts';
|
|
12
|
+
import { BN_ZERO, isUndefined } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
13
|
+
|
|
14
|
+
import { applyOnEvent } from '../util.ts';
|
|
15
|
+
import { Base } from './Base.ts';
|
|
16
|
+
import { Contract } from './Contract.ts';
|
|
17
|
+
import { convertWeight, createBluePrintTx, encodeSalt } from './util.ts';
|
|
18
|
+
|
|
19
|
+
export type BlueprintConstructor<ApiType extends ApiTypes> = new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) => Blueprint<ApiType>;
|
|
20
|
+
|
|
21
|
+
export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
|
22
|
+
readonly contract?: Contract<ApiType> | undefined;
|
|
23
|
+
|
|
24
|
+
constructor (result: ISubmittableResult, contract?: Contract<ApiType>) {
|
|
25
|
+
super(result);
|
|
26
|
+
|
|
27
|
+
this.contract = contract;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
|
32
|
+
/**
|
|
33
|
+
* @description The on-chain code hash for this blueprint
|
|
34
|
+
*/
|
|
35
|
+
readonly codeHash: Hash;
|
|
36
|
+
|
|
37
|
+
readonly #tx: MapConstructorExec<ApiType> = {};
|
|
38
|
+
|
|
39
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
|
40
|
+
super(api, abi, decorateMethod);
|
|
41
|
+
|
|
42
|
+
this.codeHash = this.registry.createType('Hash', codeHash);
|
|
43
|
+
|
|
44
|
+
this.abi.constructors.forEach((c): void => {
|
|
45
|
+
if (isUndefined(this.#tx[c.method])) {
|
|
46
|
+
this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#deploy(c, o, p));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public get tx (): MapConstructorExec<ApiType> {
|
|
52
|
+
return this.#tx;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
|
|
56
|
+
const palletTx = this._isRevive
|
|
57
|
+
? this.api.tx.revive
|
|
58
|
+
: this.api.tx.contracts;
|
|
59
|
+
|
|
60
|
+
return palletTx.instantiate(
|
|
61
|
+
value,
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
63
|
+
// @ts-ignore jiggle v1 weights, metadata points to latest
|
|
64
|
+
this._isWeightV1
|
|
65
|
+
? convertWeight(gasLimit).v1Weight
|
|
66
|
+
: convertWeight(gasLimit).v2Weight,
|
|
67
|
+
storageDepositLimit,
|
|
68
|
+
this.codeHash,
|
|
69
|
+
this.abi.findConstructor(constructorOrId).toU8a(params),
|
|
70
|
+
encodeSalt(salt)
|
|
71
|
+
).withResultTransform((result: ISubmittableResult) =>
|
|
72
|
+
new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
|
|
73
|
+
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod), this._isRevive
|
|
74
|
+
)
|
|
75
|
+
)
|
|
76
|
+
);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function extendBlueprint <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): BlueprintConstructor<ApiType> {
|
|
81
|
+
return class extends Blueprint<ApiType> {
|
|
82
|
+
static __BlueprintType = type;
|
|
83
|
+
|
|
84
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash | Uint8Array) {
|
|
85
|
+
super(api, abi, codeHash, decorateMethod);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import type { ApiBase } from 'https://deno.land/x/pezkuwi/api/base/index.ts';
|
|
5
|
+
import type { SubmittableExtrinsic } from 'https://deno.land/x/pezkuwi/api/submittable/types.ts';
|
|
6
|
+
import type { ApiTypes, DecorateMethod } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
7
|
+
import type { AccountId, EventRecord } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
8
|
+
import type { ISubmittableResult } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
|
|
9
|
+
import type { Codec } from 'https://deno.land/x/pezkuwi/types-codec/types/index.ts';
|
|
10
|
+
import type { Abi } from '../Abi/index.ts';
|
|
11
|
+
import type { AbiConstructor, BlueprintOptions } from '../types.ts';
|
|
12
|
+
import type { MapConstructorExec } from './types.ts';
|
|
13
|
+
|
|
14
|
+
import { SubmittableResult } from 'https://deno.land/x/pezkuwi/api/mod.ts';
|
|
15
|
+
import { BN_ZERO, compactAddLength, isRiscV, isUndefined, isWasm, u8aToU8a } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
16
|
+
|
|
17
|
+
import { applyOnEvent } from '../util.ts';
|
|
18
|
+
import { Base } from './Base.ts';
|
|
19
|
+
import { Blueprint } from './Blueprint.ts';
|
|
20
|
+
import { Contract } from './Contract.ts';
|
|
21
|
+
import { convertWeight, createBluePrintTx, encodeSalt } from './util.ts';
|
|
22
|
+
|
|
23
|
+
export type CodeConstructor<ApiType extends ApiTypes> = new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) => Code<ApiType>;
|
|
24
|
+
|
|
25
|
+
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
|
26
|
+
readonly blueprint?: Blueprint<ApiType> | undefined;
|
|
27
|
+
readonly contract?: Contract<ApiType> | undefined;
|
|
28
|
+
|
|
29
|
+
constructor (result: ISubmittableResult, blueprint?: Blueprint<ApiType> | undefined, contract?: Contract<ApiType> | undefined) {
|
|
30
|
+
super(result);
|
|
31
|
+
|
|
32
|
+
this.blueprint = blueprint;
|
|
33
|
+
this.contract = contract;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function isValidCode (code: Uint8Array): boolean {
|
|
38
|
+
return isWasm(code) || isRiscV(code);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
|
42
|
+
readonly code: Uint8Array;
|
|
43
|
+
|
|
44
|
+
readonly #tx: MapConstructorExec<ApiType> = {};
|
|
45
|
+
|
|
46
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
|
|
47
|
+
super(api, abi, decorateMethod);
|
|
48
|
+
|
|
49
|
+
this.code = isValidCode(this.abi.info.source.wasm)
|
|
50
|
+
? this.abi.info.source.wasm
|
|
51
|
+
: u8aToU8a(wasm);
|
|
52
|
+
|
|
53
|
+
if (!isValidCode(this.code)) {
|
|
54
|
+
throw new Error('Invalid code provided');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
this.abi.constructors.forEach((c): void => {
|
|
58
|
+
if (isUndefined(this.#tx[c.method])) {
|
|
59
|
+
this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#instantiate(c, o, p));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get tx (): MapConstructorExec<ApiType> {
|
|
65
|
+
return this.#tx;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
|
|
69
|
+
const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
|
|
70
|
+
|
|
71
|
+
if (this._isRevive) {
|
|
72
|
+
return palletTx.instantiateWithCode(
|
|
73
|
+
value,
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
75
|
+
// @ts-ignore jiggle v1 weights, metadata points to latest
|
|
76
|
+
this._isWeightV1
|
|
77
|
+
? convertWeight(gasLimit).v1Weight
|
|
78
|
+
: convertWeight(gasLimit).v2Weight,
|
|
79
|
+
storageDepositLimit,
|
|
80
|
+
compactAddLength(this.code),
|
|
81
|
+
this.abi.findConstructor(constructorOrId).toU8a(params),
|
|
82
|
+
encodeSalt(salt)
|
|
83
|
+
).withResultTransform((result: ISubmittableResult) =>
|
|
84
|
+
new CodeSubmittableResult(
|
|
85
|
+
result,
|
|
86
|
+
...(applyOnEvent(result, ['Instantiated'], (records: EventRecord[]) =>
|
|
87
|
+
records.reduce<[Blueprint<ApiType> | undefined, Contract<ApiType> | undefined]>(
|
|
88
|
+
([blueprint, contract], { event }) =>
|
|
89
|
+
this.api.events.revive['Instantiated'].is(event)
|
|
90
|
+
? [
|
|
91
|
+
blueprint,
|
|
92
|
+
new Contract<ApiType>(
|
|
93
|
+
this.api,
|
|
94
|
+
this.abi,
|
|
95
|
+
(event as unknown as { data: [Codec, AccountId] }).data[1],
|
|
96
|
+
this._decorateMethod
|
|
97
|
+
)
|
|
98
|
+
]
|
|
99
|
+
: [blueprint, contract],
|
|
100
|
+
[undefined, undefined]
|
|
101
|
+
), this._isRevive
|
|
102
|
+
) || [undefined, undefined])
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return palletTx.instantiateWithCode(
|
|
108
|
+
value,
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
110
|
+
// @ts-ignore jiggle v1 weights, metadata points to latest
|
|
111
|
+
this._isWeightV1
|
|
112
|
+
? convertWeight(gasLimit).v1Weight
|
|
113
|
+
: convertWeight(gasLimit).v2Weight,
|
|
114
|
+
storageDepositLimit,
|
|
115
|
+
compactAddLength(this.code),
|
|
116
|
+
this.abi.findConstructor(constructorOrId).toU8a(params),
|
|
117
|
+
encodeSalt(salt)
|
|
118
|
+
).withResultTransform((result: ISubmittableResult) =>
|
|
119
|
+
new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
|
|
120
|
+
records.reduce<[Blueprint<ApiType> | undefined, Contract<ApiType> | undefined]>(([blueprint, contract], { event }) =>
|
|
121
|
+
this.api.events.contracts.Instantiated.is(event)
|
|
122
|
+
? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
|
|
123
|
+
: this.api.events.contracts.CodeStored.is(event)
|
|
124
|
+
? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
|
|
125
|
+
: [blueprint, contract],
|
|
126
|
+
[undefined, undefined]), this._isRevive
|
|
127
|
+
) || [undefined, undefined]))
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function extendCode <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType> {
|
|
133
|
+
return class extends Code<ApiType> {
|
|
134
|
+
static __CodeType = type;
|
|
135
|
+
|
|
136
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
|
|
137
|
+
super(api, abi, wasm, decorateMethod);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ApiBase } from 'https://deno.land/x/pezkuwi/api/base/index.ts';
|
|
3
|
+
import type { SubmittableExtrinsic } from 'https://deno.land/x/pezkuwi/api/submittable/types.ts';
|
|
4
|
+
import type { ApiTypes, DecorateMethod } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
5
|
+
import type { AccountId, AccountId20, ContractExecResult, EventRecord, Weight, WeightV2 } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
6
|
+
import type { ISubmittableResult } from 'https://deno.land/x/pezkuwi/types/types/index.ts';
|
|
7
|
+
import type { Abi } from '../Abi/index.ts';
|
|
8
|
+
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll } from '../types.ts';
|
|
9
|
+
import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types.ts';
|
|
10
|
+
|
|
11
|
+
import { map } from 'https://esm.sh/rxjs@7.8.1';
|
|
12
|
+
|
|
13
|
+
import { SubmittableResult } from 'https://deno.land/x/pezkuwi/api/mod.ts';
|
|
14
|
+
import { BN, BN_HUNDRED, BN_ONE, BN_ZERO, isUndefined, logger } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
15
|
+
|
|
16
|
+
import { applyOnEvent } from '../util.ts';
|
|
17
|
+
import { Base } from './Base.ts';
|
|
18
|
+
import { convertWeight, withMeta } from './util.ts';
|
|
19
|
+
|
|
20
|
+
export type ContractConstructor<ApiType extends ApiTypes> = new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) => Contract<ApiType>;
|
|
21
|
+
|
|
22
|
+
const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
|
|
23
|
+
|
|
24
|
+
const l = logger('Contract');
|
|
25
|
+
|
|
26
|
+
function createQuery <ApiType extends ApiTypes> (meta: AbiMessage, fn: (origin: string | AccountId | Uint8Array, options: ContractOptions, params: unknown[]) => ContractCallResult<ApiType, ContractCallOutcome>): ContractQuery<ApiType> {
|
|
27
|
+
return withMeta(meta, (origin: string | AccountId | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome> =>
|
|
28
|
+
fn(origin, options, params)
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function createTx <ApiType extends ApiTypes> (meta: AbiMessage, fn: (options: ContractOptions, params: unknown[]) => SubmittableExtrinsic<ApiType>): ContractTx<ApiType> {
|
|
33
|
+
return withMeta(meta, (options: ContractOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType> =>
|
|
34
|
+
fn(options, params)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export class ContractSubmittableResult extends SubmittableResult {
|
|
39
|
+
readonly contractEvents?: DecodedEvent[] | undefined;
|
|
40
|
+
|
|
41
|
+
constructor (result: ISubmittableResult, contractEvents?: DecodedEvent[]) {
|
|
42
|
+
super(result);
|
|
43
|
+
|
|
44
|
+
this.contractEvents = contractEvents;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
|
49
|
+
/**
|
|
50
|
+
* @description The on-chain address for this contract
|
|
51
|
+
*/
|
|
52
|
+
readonly address: AccountId | AccountId20;
|
|
53
|
+
|
|
54
|
+
readonly #query: MapMessageQuery<ApiType> = {};
|
|
55
|
+
readonly #tx: MapMessageTx<ApiType> = {};
|
|
56
|
+
|
|
57
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20, decorateMethod: DecorateMethod<ApiType>) {
|
|
58
|
+
super(api, abi, decorateMethod);
|
|
59
|
+
|
|
60
|
+
this.address = this.registry.createType(this._isRevive ? 'AccountId20' : 'AccountId', address);
|
|
61
|
+
|
|
62
|
+
this.abi.messages.forEach((m): void => {
|
|
63
|
+
if (isUndefined(this.#tx[m.method])) {
|
|
64
|
+
this.#tx[m.method] = createTx(m, (o, p) => this.#exec(m, o, p));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (isUndefined(this.#query[m.method])) {
|
|
68
|
+
this.#query[m.method] = createQuery(m, (f, o, p) => this.#read(m, o, p).send(f));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public get query (): MapMessageQuery<ApiType> {
|
|
74
|
+
return this.#query;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public get tx (): MapMessageTx<ApiType> {
|
|
78
|
+
return this.#tx;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#getGas = (_gasLimit: bigint | BN | string | number | WeightV2, isCall = false): WeightAll => {
|
|
82
|
+
const weight = convertWeight(_gasLimit);
|
|
83
|
+
|
|
84
|
+
if (weight.v1Weight.gt(BN_ZERO)) {
|
|
85
|
+
return weight;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return convertWeight(
|
|
89
|
+
isCall
|
|
90
|
+
? MAX_CALL_GAS
|
|
91
|
+
: convertWeight(
|
|
92
|
+
this.api.consts.system.blockWeights
|
|
93
|
+
? (this.api.consts.system.blockWeights as unknown as { maxBlock: WeightV2 }).maxBlock
|
|
94
|
+
: this.api.consts.system['maximumBlockWeight'] as Weight
|
|
95
|
+
).v1Weight.muln(64).div(BN_HUNDRED)
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic<ApiType> => {
|
|
100
|
+
const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
|
|
101
|
+
|
|
102
|
+
return palletTx.call(
|
|
103
|
+
this.address,
|
|
104
|
+
value,
|
|
105
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
106
|
+
// @ts-ignore jiggle v1 weights, metadata points to latest
|
|
107
|
+
this._isWeightV1
|
|
108
|
+
? convertWeight(gasLimit).v1Weight
|
|
109
|
+
: convertWeight(gasLimit).v2Weight,
|
|
110
|
+
storageDepositLimit,
|
|
111
|
+
this.abi.findMessage(messageOrId).toU8a(params)
|
|
112
|
+
).withResultTransform((result: ISubmittableResult) =>
|
|
113
|
+
// ContractEmitted is the current generation, ContractExecution is the previous generation
|
|
114
|
+
new ContractSubmittableResult(result, applyOnEvent(result, ['ContractEmitted', 'ContractExecution'], (records: EventRecord[]) =>
|
|
115
|
+
records
|
|
116
|
+
// Filter to only decode events emitted by this specific contract instance.
|
|
117
|
+
.filter((record): boolean => {
|
|
118
|
+
try {
|
|
119
|
+
const contractAddress = record.event.data[0];
|
|
120
|
+
|
|
121
|
+
if (this.address.eq(contractAddress)) {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
l.debug(`Skipping event from different contract ${contractAddress.toString()} (this contract: ${this.address.toString()})`);
|
|
126
|
+
|
|
127
|
+
return false;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
l.warn(`Unable to extract contract address from event: ${(error as Error).message}`);
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
.map((record): DecodedEvent | null => {
|
|
135
|
+
try {
|
|
136
|
+
return this.abi.decodeEvent(record);
|
|
137
|
+
} catch (error) {
|
|
138
|
+
l.error(`Unable to decode contract event: ${(error as Error).message}`);
|
|
139
|
+
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
})
|
|
143
|
+
.filter((decoded): decoded is DecodedEvent => !!decoded), this._isRevive
|
|
144
|
+
))
|
|
145
|
+
);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
#read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): ContractCallSend<ApiType> => {
|
|
149
|
+
const message = this.abi.findMessage(messageOrId);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
153
|
+
send: this._decorateMethod((origin: string | AccountId | Uint8Array) =>
|
|
154
|
+
(this._isRevive
|
|
155
|
+
? this.api.rx.call.reviveApi.call
|
|
156
|
+
: this.api.rx.call.contractsApi.call)<ContractExecResult>(
|
|
157
|
+
origin,
|
|
158
|
+
this.address,
|
|
159
|
+
value,
|
|
160
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
161
|
+
// @ts-ignore jiggle v1 weights, metadata points to latest
|
|
162
|
+
this._isWeightV1
|
|
163
|
+
? this.#getGas(gasLimit, true).v1Weight
|
|
164
|
+
: this.#getGas(gasLimit, true).v2Weight,
|
|
165
|
+
storageDepositLimit,
|
|
166
|
+
message.toU8a(params)
|
|
167
|
+
).pipe(
|
|
168
|
+
map(({ debugMessage, gasConsumed, gasRequired, result, storageDeposit }): ContractCallOutcome => ({
|
|
169
|
+
debugMessage,
|
|
170
|
+
gasConsumed,
|
|
171
|
+
gasRequired: gasRequired && !convertWeight(gasRequired).v1Weight.isZero()
|
|
172
|
+
? gasRequired
|
|
173
|
+
: gasConsumed,
|
|
174
|
+
output: result.isOk && message.returnType
|
|
175
|
+
? this.abi.registry.createTypeUnsafe(message.returnType.lookupName || message.returnType.type, [result.asOk.data.toU8a(true)], { isPedantic: true })
|
|
176
|
+
: null,
|
|
177
|
+
result,
|
|
178
|
+
storageDeposit
|
|
179
|
+
}))
|
|
180
|
+
)
|
|
181
|
+
)
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export function extendContract <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType> {
|
|
187
|
+
return class extends Contract<ApiType> {
|
|
188
|
+
static __ContractType = type;
|
|
189
|
+
|
|
190
|
+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
|
|
191
|
+
super(api, abi, address, decorateMethod);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
import type { ApiBase } from 'https://deno.land/x/pezkuwi/api/base/index.ts';
|
|
3
|
+
|
|
4
|
+
import { TypeRegistry } from 'https://deno.land/x/pezkuwi/types/mod.ts';
|
|
5
|
+
|
|
6
|
+
const registry = new TypeRegistry();
|
|
7
|
+
|
|
8
|
+
const instantiateWithCode = (): never => {
|
|
9
|
+
throw new Error('mock');
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
instantiateWithCode.meta = { args: new Array(6) };
|
|
13
|
+
|
|
14
|
+
export const mockApi = {
|
|
15
|
+
call: {
|
|
16
|
+
contractsApi: {
|
|
17
|
+
call: (): never => {
|
|
18
|
+
throw new Error('mock');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
isConnected: true,
|
|
23
|
+
registry,
|
|
24
|
+
tx: {
|
|
25
|
+
contracts: {
|
|
26
|
+
instantiateWithCode
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
} as unknown as ApiBase<'promise'>;
|
|
30
|
+
|
|
31
|
+
export const mockReviveApi = {
|
|
32
|
+
call: {
|
|
33
|
+
reviveApi: {
|
|
34
|
+
call: (): never => {
|
|
35
|
+
throw new Error('mock');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
isConnected: true,
|
|
40
|
+
registry,
|
|
41
|
+
tx: {
|
|
42
|
+
revive: {
|
|
43
|
+
instantiateWithCode
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
} as unknown as ApiBase<'promise'>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
import type { Observable } from 'https://esm.sh/rxjs@7.8.1';
|
|
3
|
+
import type { SubmittableExtrinsic } from 'https://deno.land/x/pezkuwi/api/submittable/types.ts';
|
|
4
|
+
import type { ApiTypes, ObsInnerType } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
5
|
+
import type { AccountId } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
6
|
+
import type { AbiMessage, BlueprintOptions, ContractCallOutcome, ContractOptions } from '../types.ts';
|
|
7
|
+
|
|
8
|
+
export interface MessageMeta {
|
|
9
|
+
readonly meta: AbiMessage;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface BlueprintDeploy<ApiType extends ApiTypes> extends MessageMeta {
|
|
13
|
+
(options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ContractQuery<ApiType extends ApiTypes> extends MessageMeta {
|
|
17
|
+
(origin: AccountId | string | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface ContractTx<ApiType extends ApiTypes> extends MessageMeta {
|
|
21
|
+
(options: ContractOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type ContractGeneric<O, T> = (messageOrId: AbiMessage | string | number, options: O, ...params: unknown[]) => T;
|
|
25
|
+
|
|
26
|
+
export type ContractCallResult<ApiType extends ApiTypes, T> = ApiType extends 'rxjs'
|
|
27
|
+
? Observable<T>
|
|
28
|
+
: Promise<ObsInnerType<Observable<T>>>;
|
|
29
|
+
|
|
30
|
+
export interface ContractCallSend<ApiType extends ApiTypes> {
|
|
31
|
+
send (account: string | AccountId | Uint8Array): ContractCallResult<ApiType, ContractCallOutcome>;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type MapConstructorExec<ApiType extends ApiTypes> = Record<string, BlueprintDeploy<ApiType>>;
|
|
35
|
+
|
|
36
|
+
export type MapMessageTx<ApiType extends ApiTypes> = Record<string, ContractTx<ApiType>>;
|
|
37
|
+
|
|
38
|
+
export type MapMessageQuery<ApiType extends ApiTypes> = Record<string, ContractQuery<ApiType>>;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
import type { SubmittableResult } from 'https://deno.land/x/pezkuwi/api/mod.ts';
|
|
3
|
+
import type { SubmittableExtrinsic } from 'https://deno.land/x/pezkuwi/api/submittable/types.ts';
|
|
4
|
+
import type { ApiTypes } from 'https://deno.land/x/pezkuwi/api/types/index.ts';
|
|
5
|
+
import type { WeightV1, WeightV2 } from 'https://deno.land/x/pezkuwi/types/interfaces/index.ts';
|
|
6
|
+
import type { BN } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
7
|
+
import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll } from '../types.ts';
|
|
8
|
+
import type { BlueprintDeploy, ContractGeneric } from './types.ts';
|
|
9
|
+
|
|
10
|
+
import { Bytes } from 'https://deno.land/x/pezkuwi/types/mod.ts';
|
|
11
|
+
import { bnToBn, compactAddLength, u8aToU8a } from 'https://deno.land/x/pezkuwi/util/mod.ts';
|
|
12
|
+
import { randomAsU8a } from 'https://deno.land/x/pezkuwi/util-crypto/mod.ts';
|
|
13
|
+
|
|
14
|
+
export const EMPTY_SALT = new Uint8Array();
|
|
15
|
+
|
|
16
|
+
export function withMeta <T extends { meta: AbiMessage }> (meta: AbiMessage, creator: Omit<T, 'meta'>): T {
|
|
17
|
+
(creator as T).meta = meta;
|
|
18
|
+
|
|
19
|
+
return creator as T;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createBluePrintTx <ApiType extends ApiTypes, R extends SubmittableResult> (meta: AbiMessage, fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType> {
|
|
23
|
+
return withMeta(meta, (options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType, R> =>
|
|
24
|
+
fn(options, params)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function createBluePrintWithId <T> (fn: (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: unknown[]) => T): ContractGeneric<BlueprintOptions, T> {
|
|
29
|
+
return (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, ...params: unknown[]): T =>
|
|
30
|
+
fn(constructorOrId, options, params);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function encodeSalt (salt: Uint8Array | string | null = randomAsU8a()): Uint8Array {
|
|
34
|
+
return salt instanceof Bytes
|
|
35
|
+
? salt
|
|
36
|
+
: salt?.length
|
|
37
|
+
? compactAddLength(u8aToU8a(salt))
|
|
38
|
+
: EMPTY_SALT;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function convertWeight (weight: WeightV1 | WeightV2 | bigint | string | number | BN): WeightAll {
|
|
42
|
+
const [refTime, proofSize] = isWeightV2(weight)
|
|
43
|
+
? [weight.refTime.toBn(), weight.proofSize.toBn()]
|
|
44
|
+
: [bnToBn(weight), undefined];
|
|
45
|
+
|
|
46
|
+
return {
|
|
47
|
+
v1Weight: refTime,
|
|
48
|
+
v2Weight: { proofSize, refTime }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function isWeightV2 (weight: WeightV1 | WeightV2 | bigint | string | number | BN): weight is WeightV2 {
|
|
53
|
+
return !!(weight as WeightV2).proofSize;
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import 'https://deno.land/x/pezkuwi/api-augment/mod.ts';
|
|
4
|
+
|
|
5
|
+
import type { TestKeyringMapBizinikiwi } from 'https://deno.land/x/pezkuwi/keyring/testingPairs.ts';
|
|
6
|
+
|
|
7
|
+
import { ApiPromise } from 'https://deno.land/x/pezkuwi/api/mod.ts';
|
|
8
|
+
import { BlueprintPromise, ContractPromise } from 'https://deno.land/x/pezkuwi/api-contract/mod.ts';
|
|
9
|
+
import { createTestPairs } from 'https://deno.land/x/pezkuwi/keyring/testingPairs.ts';
|
|
10
|
+
|
|
11
|
+
import abiIncrementer from './test/contracts/ink/v0/incrementer.json' assert { type: 'json' };
|
|
12
|
+
|
|
13
|
+
async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise<void> {
|
|
14
|
+
const blueprint = new BlueprintPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
|
15
|
+
|
|
16
|
+
await blueprint.tx['new']({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
|
|
17
|
+
await blueprint.tx['new']({ gasLimit: 456, value: 123 }, 42).signAndSend(pairs.bob);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function checkContract (api: ApiPromise, pairs: TestKeyringMapBizinikiwi): Promise<void> {
|
|
21
|
+
const contract = new ContractPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
|
|
22
|
+
|
|
23
|
+
// queries
|
|
24
|
+
await contract.query['get'](pairs.alice.address, {});
|
|
25
|
+
|
|
26
|
+
// execute
|
|
27
|
+
await contract.tx['inc']({ gasLimit: 1234 }, 123).signAndSend(pairs.eve);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function main (): Promise<void> {
|
|
31
|
+
const api = await ApiPromise.create({
|
|
32
|
+
hasher: (data: Uint8Array): Uint8Array => data
|
|
33
|
+
});
|
|
34
|
+
const pairs = createTestPairs();
|
|
35
|
+
|
|
36
|
+
await Promise.all([
|
|
37
|
+
checkBlueprint(api, pairs),
|
|
38
|
+
checkContract(api, pairs)
|
|
39
|
+
]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
main().catch(console.error);
|