@pezkuwi/api-contract 16.5.5 → 16.5.6

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.
Files changed (234) hide show
  1. package/Abi/index.js +359 -0
  2. package/Abi/toLatestCompatible.js +30 -0
  3. package/Abi/toV1.js +21 -0
  4. package/Abi/toV2.js +27 -0
  5. package/Abi/toV3.js +10 -0
  6. package/Abi/toV4.js +10 -0
  7. package/LICENSE +201 -0
  8. package/README.md +1 -1
  9. package/augment.js +1 -0
  10. package/base/Base.js +40 -0
  11. package/base/Blueprint.js +51 -0
  12. package/base/Code.js +74 -0
  13. package/base/Contract.js +127 -0
  14. package/{src/base/index.ts → base/index.js} +0 -3
  15. package/base/mock.js +38 -0
  16. package/{build/base → base}/util.d.ts +1 -1
  17. package/base/util.js +33 -0
  18. package/bundle-pezkuwi-api-contract.js +1238 -0
  19. package/{src/bundle.ts → bundle.js} +0 -6
  20. package/cjs/Abi/index.d.ts +31 -0
  21. package/cjs/Abi/index.js +363 -0
  22. package/cjs/Abi/toLatestCompatible.d.ts +15 -0
  23. package/cjs/Abi/toLatestCompatible.js +36 -0
  24. package/cjs/Abi/toV1.d.ts +3 -0
  25. package/cjs/Abi/toV1.js +24 -0
  26. package/cjs/Abi/toV2.d.ts +3 -0
  27. package/cjs/Abi/toV2.js +30 -0
  28. package/cjs/Abi/toV3.d.ts +3 -0
  29. package/cjs/Abi/toV3.js +13 -0
  30. package/cjs/Abi/toV4.d.ts +3 -0
  31. package/cjs/Abi/toV4.js +13 -0
  32. package/cjs/augment.d.ts +1 -0
  33. package/cjs/augment.js +3 -0
  34. package/cjs/base/Base.d.ts +13 -0
  35. package/cjs/base/Base.js +44 -0
  36. package/cjs/base/Blueprint.d.ts +24 -0
  37. package/cjs/base/Blueprint.js +57 -0
  38. package/cjs/base/Code.d.ts +22 -0
  39. package/cjs/base/Code.js +80 -0
  40. package/cjs/base/Contract.d.ts +25 -0
  41. package/cjs/base/Contract.js +133 -0
  42. package/cjs/base/index.d.ts +3 -0
  43. package/cjs/base/index.js +14 -0
  44. package/cjs/base/mock.d.ts +3 -0
  45. package/cjs/base/mock.js +41 -0
  46. package/{src/base/types.ts → cjs/base/types.d.ts} +6 -21
  47. package/cjs/base/types.js +2 -0
  48. package/cjs/base/util.d.ts +16 -0
  49. package/cjs/base/util.js +42 -0
  50. package/cjs/bundle.d.ts +4 -0
  51. package/cjs/bundle.js +10 -0
  52. package/cjs/index.js +5 -0
  53. package/cjs/package.json +3 -0
  54. package/cjs/packageDetect.d.ts +1 -0
  55. package/cjs/packageDetect.js +7 -0
  56. package/cjs/packageInfo.js +4 -0
  57. package/cjs/promise/index.js +23 -0
  58. package/cjs/promise/types.js +2 -0
  59. package/cjs/rx/index.js +23 -0
  60. package/cjs/rx/types.js +2 -0
  61. package/cjs/types.js +2 -0
  62. package/cjs/util.js +13 -0
  63. package/index.d.ts +2 -0
  64. package/index.js +2 -0
  65. package/package.json +384 -15
  66. package/packageDetect.d.ts +1 -0
  67. package/{src/packageDetect.ts → packageDetect.js} +0 -8
  68. package/packageInfo.d.ts +6 -0
  69. package/packageInfo.js +1 -0
  70. package/promise/index.d.ts +13 -0
  71. package/promise/index.js +17 -0
  72. package/{src/promise/types.ts → promise/types.d.ts} +0 -4
  73. package/promise/types.js +1 -0
  74. package/rx/index.d.ts +13 -0
  75. package/rx/index.js +17 -0
  76. package/{src/rx/types.ts → rx/types.d.ts} +0 -4
  77. package/rx/types.js +1 -0
  78. package/types.d.ts +79 -0
  79. package/types.js +1 -0
  80. package/util.d.ts +5 -0
  81. package/util.js +10 -0
  82. package/src/Abi/Abi.spec.ts +0 -235
  83. package/src/Abi/index.ts +0 -477
  84. package/src/Abi/toLatestCompatible.spec.ts +0 -219
  85. package/src/Abi/toLatestCompatible.ts +0 -52
  86. package/src/Abi/toV1.ts +0 -35
  87. package/src/Abi/toV2.ts +0 -58
  88. package/src/Abi/toV3.ts +0 -18
  89. package/src/Abi/toV4.ts +0 -21
  90. package/src/augment.ts +0 -4
  91. package/src/base/Base.ts +0 -52
  92. package/src/base/Blueprint.ts +0 -90
  93. package/src/base/Code.spec.ts +0 -47
  94. package/src/base/Code.ts +0 -142
  95. package/src/base/Contract.ts +0 -197
  96. package/src/base/mock.ts +0 -48
  97. package/src/base/util.ts +0 -56
  98. package/src/checkTypes.manual.ts +0 -45
  99. package/src/index.ts +0 -6
  100. package/src/mod.ts +0 -4
  101. package/src/packageInfo.ts +0 -6
  102. package/src/promise/index.ts +0 -28
  103. package/src/rx/index.ts +0 -28
  104. package/src/test/compare/ink_v0_delegator.test.json +0 -47
  105. package/src/test/compare/ink_v0_dns.test.json +0 -232
  106. package/src/test/compare/ink_v0_erc20.test.json +0 -253
  107. package/src/test/compare/ink_v0_erc721.test.json +0 -415
  108. package/src/test/compare/ink_v0_flipper.test.json +0 -9
  109. package/src/test/compare/ink_v0_flipperBundle.test.json +0 -9
  110. package/src/test/compare/ink_v0_incrementer.test.json +0 -9
  111. package/src/test/compare/ink_v0_multisigPlain.test.json +0 -562
  112. package/src/test/compare/ink_v1_flipper.test.json +0 -9
  113. package/src/test/compare/ink_v1_psp22.test.json +0 -531
  114. package/src/test/compare/ink_v2_erc20.test.json +0 -205
  115. package/src/test/compare/ink_v2_flipper.test.json +0 -9
  116. package/src/test/compare/ink_v3_flipper.test.json +0 -9
  117. package/src/test/compare/ink_v3_traitErc20.test.json +0 -205
  118. package/src/test/compare/ink_v4_erc20Contract.test.json +0 -253
  119. package/src/test/compare/ink_v4_erc20Metadata.test.json +0 -253
  120. package/src/test/compare/ink_v4_flipperContract.test.json +0 -155
  121. package/src/test/compare/ink_v4_flipperMetadata.test.json +0 -155
  122. package/src/test/compare/ink_v5_erc20.test.json +0 -370
  123. package/src/test/compare/ink_v5_erc20AnonymousTransferMetadata.test.json +0 -370
  124. package/src/test/compare/ink_v5_erc20Contract.test.json +0 -370
  125. package/src/test/compare/ink_v5_erc20Metadata.test.json +0 -370
  126. package/src/test/compare/ink_v5_flipperContract.test.json +0 -174
  127. package/src/test/compare/ink_v5_flipperMetadata.test.json +0 -174
  128. package/src/test/compare/ink_v6_erc20Contract.test.json +0 -418
  129. package/src/test/compare/ink_v6_erc20Metadata.test.json +0 -418
  130. package/src/test/compare/solang_v0_ints256.test.json +0 -9
  131. package/src/test/compare/user_v0_assetTransfer.test.json +0 -54
  132. package/src/test/compare/user_v0_enumExample.test.json +0 -303
  133. package/src/test/compare/user_v0_recursive.test.json +0 -27
  134. package/src/test/compare/user_v0_withString.test.json +0 -260
  135. package/src/test/compare/user_v3_ask.test.json +0 -71
  136. package/src/test/compare/user_v4_events.test.json +0 -1328
  137. package/src/test/contracts/index.ts +0 -20
  138. package/src/test/contracts/ink/index.ts +0 -13
  139. package/src/test/contracts/ink/v0/accumulator.wasm +0 -0
  140. package/src/test/contracts/ink/v0/adder.wasm +0 -0
  141. package/src/test/contracts/ink/v0/delegator.json +0 -252
  142. package/src/test/contracts/ink/v0/delegator.wasm +0 -0
  143. package/src/test/contracts/ink/v0/dns.json +0 -713
  144. package/src/test/contracts/ink/v0/dns.wasm +0 -0
  145. package/src/test/contracts/ink/v0/erc20.json +0 -704
  146. package/src/test/contracts/ink/v0/erc20.wasm +0 -0
  147. package/src/test/contracts/ink/v0/erc721.json +0 -1197
  148. package/src/test/contracts/ink/v0/erc721.wasm +0 -0
  149. package/src/test/contracts/ink/v0/flipper.contract.json +0 -107
  150. package/src/test/contracts/ink/v0/flipper.json +0 -106
  151. package/src/test/contracts/ink/v0/flipper.wasm +0 -0
  152. package/src/test/contracts/ink/v0/incrementer.json +0 -108
  153. package/src/test/contracts/ink/v0/incrementer.wasm +0 -0
  154. package/src/test/contracts/ink/v0/index.ts +0 -11
  155. package/src/test/contracts/ink/v0/multisig_plain.json +0 -1466
  156. package/src/test/contracts/ink/v0/multisig_plain.wasm +0 -0
  157. package/src/test/contracts/ink/v0/subber.wasm +0 -0
  158. package/src/test/contracts/ink/v0/trait-flipper.json +0 -103
  159. package/src/test/contracts/ink/v0/trait-flipper.wasm +0 -0
  160. package/src/test/contracts/ink/v1/flipper.contract.json +0 -111
  161. package/src/test/contracts/ink/v1/index.ts +0 -6
  162. package/src/test/contracts/ink/v1/psp22_minter_pauser.contract.json +0 -1722
  163. package/src/test/contracts/ink/v2/erc20.contract.json +0 -630
  164. package/src/test/contracts/ink/v2/flipper.contract.json +0 -103
  165. package/src/test/contracts/ink/v2/index.ts +0 -5
  166. package/src/test/contracts/ink/v3/flipper.contract.json +0 -105
  167. package/src/test/contracts/ink/v3/index.ts +0 -6
  168. package/src/test/contracts/ink/v3/trait_erc20.contract.json +0 -631
  169. package/src/test/contracts/ink/v4/erc20.contract.json +0 -1
  170. package/src/test/contracts/ink/v4/erc20.json +0 -821
  171. package/src/test/contracts/ink/v4/erc20.wasm +0 -0
  172. package/src/test/contracts/ink/v4/flipper.contract.json +0 -1
  173. package/src/test/contracts/ink/v4/flipper.json +0 -396
  174. package/src/test/contracts/ink/v4/flipper.wasm +0 -0
  175. package/src/test/contracts/ink/v4/index.ts +0 -7
  176. package/src/test/contracts/ink/v5/erc20.contract.json +0 -1
  177. package/src/test/contracts/ink/v5/erc20.json +0 -1025
  178. package/src/test/contracts/ink/v5/erc20.wasm +0 -0
  179. package/src/test/contracts/ink/v5/erc20_anonymous_transfer.json +0 -1025
  180. package/src/test/contracts/ink/v5/flipper.contract.json +0 -1
  181. package/src/test/contracts/ink/v5/flipper.json +0 -420
  182. package/src/test/contracts/ink/v5/flipper.wasm +0 -0
  183. package/src/test/contracts/ink/v5/index.ts +0 -8
  184. package/src/test/contracts/ink/v6/erc20.contract.json +0 -1
  185. package/src/test/contracts/ink/v6/erc20.json +0 -1081
  186. package/src/test/contracts/ink/v6/erc20.polkavm +0 -0
  187. package/src/test/contracts/ink/v6/index.ts +0 -5
  188. package/src/test/contracts/solang/index.ts +0 -7
  189. package/src/test/contracts/solang/v0/index.ts +0 -4
  190. package/src/test/contracts/solang/v0/ints256.json +0 -113
  191. package/src/test/contracts/solang/v0/ints256.sol +0 -13
  192. package/src/test/contracts/solang/v0/ints256.wasm +0 -0
  193. package/src/test/contracts/user/index.ts +0 -9
  194. package/src/test/contracts/user/v0/assetTransfer.json +0 -299
  195. package/src/test/contracts/user/v0/assetTransfer.wasm +0 -0
  196. package/src/test/contracts/user/v0/enumExample.json +0 -528
  197. package/src/test/contracts/user/v0/enumExample.wasm +0 -0
  198. package/src/test/contracts/user/v0/index.ts +0 -7
  199. package/src/test/contracts/user/v0/recursive.contract.json +0 -1
  200. package/src/test/contracts/user/v0/withString.json +0 -777
  201. package/src/test/contracts/user/v3/ask.json +0 -550
  202. package/src/test/contracts/user/v3/index.ts +0 -4
  203. package/src/test/contracts/user/v4/events.contract.json +0 -2990
  204. package/src/test/contracts/user/v4/index.ts +0 -4
  205. package/src/test/contracts/util.ts +0 -14
  206. package/src/types.ts +0 -98
  207. package/src/util.ts +0 -20
  208. package/tsconfig.build.json +0 -22
  209. package/tsconfig.build.tsbuildinfo +0 -1
  210. package/tsconfig.spec.json +0 -26
  211. /package/{build/Abi → Abi}/index.d.ts +0 -0
  212. /package/{build/Abi → Abi}/toLatestCompatible.d.ts +0 -0
  213. /package/{build/Abi → Abi}/toV1.d.ts +0 -0
  214. /package/{build/Abi → Abi}/toV2.d.ts +0 -0
  215. /package/{build/Abi → Abi}/toV3.d.ts +0 -0
  216. /package/{build/Abi → Abi}/toV4.d.ts +0 -0
  217. /package/{build/augment.d.ts → augment.d.ts} +0 -0
  218. /package/{build/base → base}/Base.d.ts +0 -0
  219. /package/{build/base → base}/Blueprint.d.ts +0 -0
  220. /package/{build/base → base}/Code.d.ts +0 -0
  221. /package/{build/base → base}/Contract.d.ts +0 -0
  222. /package/{build/base → base}/index.d.ts +0 -0
  223. /package/{build/base → base}/mock.d.ts +0 -0
  224. /package/{build/base → base}/types.d.ts +0 -0
  225. /package/{build/packageDetect.d.ts → base/types.js} +0 -0
  226. /package/{build/bundle.d.ts → bundle.d.ts} +0 -0
  227. /package/{build → cjs}/index.d.ts +0 -0
  228. /package/{build → cjs}/packageInfo.d.ts +0 -0
  229. /package/{build → cjs}/promise/index.d.ts +0 -0
  230. /package/{build → cjs}/promise/types.d.ts +0 -0
  231. /package/{build → cjs}/rx/index.d.ts +0 -0
  232. /package/{build → cjs}/rx/types.d.ts +0 -0
  233. /package/{build → cjs}/types.d.ts +0 -0
  234. /package/{build → cjs}/util.d.ts +0 -0
package/src/base/Code.ts DELETED
@@ -1,142 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiBase } from '@pezkuwi/api/base';
5
- import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
6
- import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
7
- import type { AccountId, EventRecord } from '@pezkuwi/types/interfaces';
8
- import type { ISubmittableResult } from '@pezkuwi/types/types';
9
- import type { Codec } from '@pezkuwi/types-codec/types';
10
- import type { Abi } from '../Abi/index.js';
11
- import type { AbiConstructor, BlueprintOptions } from '../types.js';
12
- import type { MapConstructorExec } from './types.js';
13
-
14
- import { SubmittableResult } from '@pezkuwi/api';
15
- import { BN_ZERO, compactAddLength, isRiscV, isUndefined, isWasm, u8aToU8a } from '@pezkuwi/util';
16
-
17
- import { applyOnEvent } from '../util.js';
18
- import { Base } from './Base.js';
19
- import { Blueprint } from './Blueprint.js';
20
- import { Contract } from './Contract.js';
21
- import { convertWeight, createBluePrintTx, encodeSalt } from './util.js';
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
- // checks to see if the code (or at least the header)
38
- // is a valid/supported format
39
- function isValidCode (code: Uint8Array): boolean {
40
- return isWasm(code) || isRiscV(code);
41
- }
42
-
43
- export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
44
- readonly code: Uint8Array;
45
-
46
- readonly #tx: MapConstructorExec<ApiType> = {};
47
-
48
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined, decorateMethod: DecorateMethod<ApiType>) {
49
- super(api, abi, decorateMethod);
50
-
51
- this.code = isValidCode(this.abi.info.source.wasm)
52
- ? this.abi.info.source.wasm
53
- : u8aToU8a(wasm);
54
-
55
- if (!isValidCode(this.code)) {
56
- throw new Error('Invalid code provided');
57
- }
58
-
59
- this.abi.constructors.forEach((c): void => {
60
- if (isUndefined(this.#tx[c.method])) {
61
- this.#tx[c.method] = createBluePrintTx(c, (o, p) => this.#instantiate(c, o, p));
62
- }
63
- });
64
- }
65
-
66
- public get tx (): MapConstructorExec<ApiType> {
67
- return this.#tx;
68
- }
69
-
70
- #instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
71
- const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
72
-
73
- if (this._isRevive) {
74
- return palletTx.instantiateWithCode(
75
- value,
76
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
77
- // @ts-ignore jiggle v1 weights, metadata points to latest
78
- this._isWeightV1
79
- ? convertWeight(gasLimit).v1Weight
80
- : convertWeight(gasLimit).v2Weight,
81
- storageDepositLimit,
82
- compactAddLength(this.code),
83
- this.abi.findConstructor(constructorOrId).toU8a(params),
84
- encodeSalt(salt)
85
- ).withResultTransform((result: ISubmittableResult) =>
86
- new CodeSubmittableResult(
87
- result,
88
- ...(applyOnEvent(result, ['Instantiated'], (records: EventRecord[]) =>
89
- records.reduce<[Blueprint<ApiType> | undefined, Contract<ApiType> | undefined]>(
90
- ([blueprint, contract], { event }) =>
91
- this.api.events.revive['Instantiated'].is(event)
92
- ? [
93
- blueprint,
94
- new Contract<ApiType>(
95
- this.api,
96
- this.abi,
97
- (event as unknown as { data: [Codec, AccountId] }).data[1],
98
- this._decorateMethod
99
- )
100
- ]
101
- : [blueprint, contract],
102
- [undefined, undefined]
103
- ), this._isRevive
104
- ) || [undefined, undefined])
105
- )
106
- );
107
- }
108
-
109
- return palletTx.instantiateWithCode(
110
- value,
111
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
112
- // @ts-ignore jiggle v1 weights, metadata points to latest
113
- this._isWeightV1
114
- ? convertWeight(gasLimit).v1Weight
115
- : convertWeight(gasLimit).v2Weight,
116
- storageDepositLimit,
117
- compactAddLength(this.code),
118
- this.abi.findConstructor(constructorOrId).toU8a(params),
119
- encodeSalt(salt)
120
- ).withResultTransform((result: ISubmittableResult) =>
121
- new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
122
- records.reduce<[Blueprint<ApiType> | undefined, Contract<ApiType> | undefined]>(([blueprint, contract], { event }) =>
123
- this.api.events.contracts.Instantiated.is(event)
124
- ? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
125
- : this.api.events.contracts.CodeStored.is(event)
126
- ? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
127
- : [blueprint, contract],
128
- [undefined, undefined]), this._isRevive
129
- ) || [undefined, undefined]))
130
- );
131
- };
132
- }
133
-
134
- export function extendCode <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): CodeConstructor<ApiType> {
135
- return class extends Code<ApiType> {
136
- static __CodeType = type;
137
-
138
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
139
- super(api, abi, wasm, decorateMethod);
140
- }
141
- };
142
- }
@@ -1,197 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiBase } from '@pezkuwi/api/base';
5
- import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
6
- import type { ApiTypes, DecorateMethod } from '@pezkuwi/api/types';
7
- import type { AccountId, AccountId20, ContractExecResult, EventRecord, Weight, WeightV2 } from '@pezkuwi/types/interfaces';
8
- import type { ISubmittableResult } from '@pezkuwi/types/types';
9
- import type { Abi } from '../Abi/index.js';
10
- import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll } from '../types.js';
11
- import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types.js';
12
-
13
- import { map } from 'rxjs';
14
-
15
- import { SubmittableResult } from '@pezkuwi/api';
16
- import { BN, BN_HUNDRED, BN_ONE, BN_ZERO, isUndefined, logger } from '@pezkuwi/util';
17
-
18
- import { applyOnEvent } from '../util.js';
19
- import { Base } from './Base.js';
20
- import { convertWeight, withMeta } from './util.js';
21
-
22
- export type ContractConstructor<ApiType extends ApiTypes> = new(api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) => Contract<ApiType>;
23
-
24
- // As per Rust, 5 * GAS_PER_SEC
25
- const MAX_CALL_GAS = new BN(5_000_000_000_000).isub(BN_ONE);
26
-
27
- const l = logger('Contract');
28
-
29
- function createQuery <ApiType extends ApiTypes> (meta: AbiMessage, fn: (origin: string | AccountId | Uint8Array, options: ContractOptions, params: unknown[]) => ContractCallResult<ApiType, ContractCallOutcome>): ContractQuery<ApiType> {
30
- return withMeta(meta, (origin: string | AccountId | Uint8Array, options: ContractOptions, ...params: unknown[]): ContractCallResult<ApiType, ContractCallOutcome> =>
31
- fn(origin, options, params)
32
- );
33
- }
34
-
35
- function createTx <ApiType extends ApiTypes> (meta: AbiMessage, fn: (options: ContractOptions, params: unknown[]) => SubmittableExtrinsic<ApiType>): ContractTx<ApiType> {
36
- return withMeta(meta, (options: ContractOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType> =>
37
- fn(options, params)
38
- );
39
- }
40
-
41
- export class ContractSubmittableResult extends SubmittableResult {
42
- readonly contractEvents?: DecodedEvent[] | undefined;
43
-
44
- constructor (result: ISubmittableResult, contractEvents?: DecodedEvent[]) {
45
- super(result);
46
-
47
- this.contractEvents = contractEvents;
48
- }
49
- }
50
-
51
- export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
52
- /**
53
- * @description The on-chain address for this contract
54
- */
55
- readonly address: AccountId | AccountId20;
56
-
57
- readonly #query: MapMessageQuery<ApiType> = {};
58
- readonly #tx: MapMessageTx<ApiType> = {};
59
-
60
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20, decorateMethod: DecorateMethod<ApiType>) {
61
- super(api, abi, decorateMethod);
62
-
63
- this.address = this.registry.createType(this._isRevive ? 'AccountId20' : 'AccountId', address);
64
-
65
- this.abi.messages.forEach((m): void => {
66
- if (isUndefined(this.#tx[m.method])) {
67
- this.#tx[m.method] = createTx(m, (o, p) => this.#exec(m, o, p));
68
- }
69
-
70
- if (isUndefined(this.#query[m.method])) {
71
- this.#query[m.method] = createQuery(m, (f, o, p) => this.#read(m, o, p).send(f));
72
- }
73
- });
74
- }
75
-
76
- public get query (): MapMessageQuery<ApiType> {
77
- return this.#query;
78
- }
79
-
80
- public get tx (): MapMessageTx<ApiType> {
81
- return this.#tx;
82
- }
83
-
84
- #getGas = (_gasLimit: bigint | BN | string | number | WeightV2, isCall = false): WeightAll => {
85
- const weight = convertWeight(_gasLimit);
86
-
87
- if (weight.v1Weight.gt(BN_ZERO)) {
88
- return weight;
89
- }
90
-
91
- return convertWeight(
92
- isCall
93
- ? MAX_CALL_GAS
94
- : convertWeight(
95
- this.api.consts.system.blockWeights
96
- ? (this.api.consts.system.blockWeights as unknown as { maxBlock: WeightV2 }).maxBlock
97
- : this.api.consts.system['maximumBlockWeight'] as Weight
98
- ).v1Weight.muln(64).div(BN_HUNDRED)
99
- );
100
- };
101
-
102
- #exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic<ApiType> => {
103
- const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
104
-
105
- return palletTx.call(
106
- this.address,
107
- value,
108
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
109
- // @ts-ignore jiggle v1 weights, metadata points to latest
110
- this._isWeightV1
111
- ? convertWeight(gasLimit).v1Weight
112
- : convertWeight(gasLimit).v2Weight,
113
- storageDepositLimit,
114
- this.abi.findMessage(messageOrId).toU8a(params)
115
- ).withResultTransform((result: ISubmittableResult) =>
116
- // ContractEmitted is the current generation, ContractExecution is the previous generation
117
- new ContractSubmittableResult(result, applyOnEvent(result, ['ContractEmitted', 'ContractExecution'], (records: EventRecord[]) =>
118
- records
119
- // Filter to only decode events emitted by this specific contract instance.
120
- .filter((record): boolean => {
121
- try {
122
- const contractAddress = record.event.data[0];
123
-
124
- if (this.address.eq(contractAddress)) {
125
- return true;
126
- }
127
-
128
- l.debug(`Skipping event from different contract ${contractAddress.toString()} (this contract: ${this.address.toString()})`);
129
-
130
- return false;
131
- } catch (error) {
132
- l.warn(`Unable to extract contract address from event: ${(error as Error).message}`);
133
-
134
- return false;
135
- }
136
- })
137
- .map((record): DecodedEvent | null => {
138
- try {
139
- return this.abi.decodeEvent(record);
140
- } catch (error) {
141
- l.error(`Unable to decode contract event: ${(error as Error).message}`);
142
-
143
- return null;
144
- }
145
- })
146
- .filter((decoded): decoded is DecodedEvent => !!decoded), this._isRevive
147
- ))
148
- );
149
- };
150
-
151
- #read = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): ContractCallSend<ApiType> => {
152
- const message = this.abi.findMessage(messageOrId);
153
-
154
- return {
155
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
156
- send: this._decorateMethod((origin: string | AccountId | Uint8Array) =>
157
- (this._isRevive
158
- ? this.api.rx.call.reviveApi.call
159
- : this.api.rx.call.contractsApi.call)<ContractExecResult>(
160
- origin,
161
- this.address,
162
- value,
163
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
164
- // @ts-ignore jiggle v1 weights, metadata points to latest
165
- this._isWeightV1
166
- ? this.#getGas(gasLimit, true).v1Weight
167
- : this.#getGas(gasLimit, true).v2Weight,
168
- storageDepositLimit,
169
- message.toU8a(params)
170
- ).pipe(
171
- map(({ debugMessage, gasConsumed, gasRequired, result, storageDeposit }): ContractCallOutcome => ({
172
- debugMessage,
173
- gasConsumed,
174
- gasRequired: gasRequired && !convertWeight(gasRequired).v1Weight.isZero()
175
- ? gasRequired
176
- : gasConsumed,
177
- output: result.isOk && message.returnType
178
- ? this.abi.registry.createTypeUnsafe(message.returnType.lookupName || message.returnType.type, [result.asOk.data.toU8a(true)], { isPedantic: true })
179
- : null,
180
- result,
181
- storageDeposit
182
- }))
183
- )
184
- )
185
- };
186
- };
187
- }
188
-
189
- export function extendContract <ApiType extends ApiTypes> (type: ApiType, decorateMethod: DecorateMethod<ApiType>): ContractConstructor<ApiType> {
190
- return class extends Contract<ApiType> {
191
- static __ContractType = type;
192
-
193
- constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
194
- super(api, abi, address, decorateMethod);
195
- }
196
- };
197
- }
package/src/base/mock.ts DELETED
@@ -1,48 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiBase } from '@pezkuwi/api/base';
5
-
6
- import { TypeRegistry } from '@pezkuwi/types';
7
-
8
- const registry = new TypeRegistry();
9
-
10
- const instantiateWithCode = (): never => {
11
- throw new Error('mock');
12
- };
13
-
14
- instantiateWithCode.meta = { args: new Array(6) };
15
-
16
- export const mockApi = {
17
- call: {
18
- contractsApi: {
19
- call: (): never => {
20
- throw new Error('mock');
21
- }
22
- }
23
- },
24
- isConnected: true,
25
- registry,
26
- tx: {
27
- contracts: {
28
- instantiateWithCode
29
- }
30
- }
31
- } as unknown as ApiBase<'promise'>;
32
-
33
- export const mockReviveApi = {
34
- call: {
35
- reviveApi: {
36
- call: (): never => {
37
- throw new Error('mock');
38
- }
39
- }
40
- },
41
- isConnected: true,
42
- registry,
43
- tx: {
44
- revive: {
45
- instantiateWithCode
46
- }
47
- }
48
- } as unknown as ApiBase<'promise'>;
package/src/base/util.ts DELETED
@@ -1,56 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { SubmittableResult } from '@pezkuwi/api';
5
- import type { SubmittableExtrinsic } from '@pezkuwi/api/submittable/types';
6
- import type { ApiTypes } from '@pezkuwi/api/types';
7
- import type { WeightV1, WeightV2 } from '@pezkuwi/types/interfaces';
8
- import type { BN } from '@pezkuwi/util';
9
- import type { AbiConstructor, AbiMessage, BlueprintOptions, WeightAll } from '../types.js';
10
- import type { BlueprintDeploy, ContractGeneric } from './types.js';
11
-
12
- import { Bytes } from '@pezkuwi/types';
13
- import { bnToBn, compactAddLength, u8aToU8a } from '@pezkuwi/util';
14
- import { randomAsU8a } from '@pezkuwi/util-crypto';
15
-
16
- export const EMPTY_SALT = new Uint8Array();
17
-
18
- export function withMeta <T extends { meta: AbiMessage }> (meta: AbiMessage, creator: Omit<T, 'meta'>): T {
19
- (creator as T).meta = meta;
20
-
21
- return creator as T;
22
- }
23
-
24
- export function createBluePrintTx <ApiType extends ApiTypes, R extends SubmittableResult> (meta: AbiMessage, fn: (options: BlueprintOptions, params: unknown[]) => SubmittableExtrinsic<ApiType, R>): BlueprintDeploy<ApiType> {
25
- return withMeta(meta, (options: BlueprintOptions, ...params: unknown[]): SubmittableExtrinsic<ApiType, R> =>
26
- fn(options, params)
27
- );
28
- }
29
-
30
- export function createBluePrintWithId <T> (fn: (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, params: unknown[]) => T): ContractGeneric<BlueprintOptions, T> {
31
- return (constructorOrId: AbiConstructor | string | number, options: BlueprintOptions, ...params: unknown[]): T =>
32
- fn(constructorOrId, options, params);
33
- }
34
-
35
- export function encodeSalt (salt: Uint8Array | string | null = randomAsU8a()): Uint8Array {
36
- return salt instanceof Bytes
37
- ? salt
38
- : salt?.length
39
- ? compactAddLength(u8aToU8a(salt))
40
- : EMPTY_SALT;
41
- }
42
-
43
- export function convertWeight (weight: WeightV1 | WeightV2 | bigint | string | number | BN): WeightAll {
44
- const [refTime, proofSize] = isWeightV2(weight)
45
- ? [weight.refTime.toBn(), weight.proofSize.toBn()]
46
- : [bnToBn(weight), undefined];
47
-
48
- return {
49
- v1Weight: refTime,
50
- v2Weight: { proofSize, refTime }
51
- };
52
- }
53
-
54
- export function isWeightV2 (weight: WeightV1 | WeightV2 | bigint | string | number | BN): weight is WeightV2 {
55
- return !!(weight as WeightV2).proofSize;
56
- }
@@ -1,45 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Simple non-runnable checks to test type definitions in the editor itself
5
-
6
- import '@pezkuwi/api-augment';
7
-
8
- import type { TestKeyringMapSubstrate } from '@pezkuwi/keyring/testingPairs';
9
-
10
- import { ApiPromise } from '@pezkuwi/api';
11
- import { BlueprintPromise, ContractPromise } from '@pezkuwi/api-contract';
12
- import { createTestPairs } from '@pezkuwi/keyring/testingPairs';
13
-
14
- import abiIncrementer from './test/contracts/ink/v0/incrementer.json' assert { type: 'json' };
15
-
16
- async function checkBlueprint (api: ApiPromise, pairs: TestKeyringMapSubstrate): Promise<void> {
17
- const blueprint = new BlueprintPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
18
-
19
- await blueprint.tx['new']({ gasLimit: 456, salt: '0x1234', value: 123 }, 42).signAndSend(pairs.bob);
20
- await blueprint.tx['new']({ gasLimit: 456, value: 123 }, 42).signAndSend(pairs.bob);
21
- }
22
-
23
- async function checkContract (api: ApiPromise, pairs: TestKeyringMapSubstrate): Promise<void> {
24
- const contract = new ContractPromise(api, abiIncrementer as Record<string, unknown>, '0x1234');
25
-
26
- // queries
27
- await contract.query['get'](pairs.alice.address, {});
28
-
29
- // execute
30
- await contract.tx['inc']({ gasLimit: 1234 }, 123).signAndSend(pairs.eve);
31
- }
32
-
33
- async function main (): Promise<void> {
34
- const api = await ApiPromise.create({
35
- hasher: (data: Uint8Array): Uint8Array => data
36
- });
37
- const pairs = createTestPairs();
38
-
39
- await Promise.all([
40
- checkBlueprint(api, pairs),
41
- checkContract(api, pairs)
42
- ]);
43
- }
44
-
45
- main().catch(console.error);
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import './packageDetect.js';
5
-
6
- export * from './bundle.js';
package/src/mod.ts DELETED
@@ -1,4 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- export * from './index.js';
@@ -1,6 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- // Do not edit, auto-generated by @polkadot/dev
5
-
6
- export const packageInfo = { name: '@pezkuwi/api-contract', path: 'auto', type: 'auto', version: '16.5.5' };
@@ -1,28 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiPromise } from '@pezkuwi/api';
5
- import type { AccountId, AccountId20, Hash } from '@pezkuwi/types/interfaces';
6
- import type { Abi } from '../Abi/index.js';
7
-
8
- import { toPromiseMethod } from '@pezkuwi/api';
9
-
10
- import { Blueprint, Code, Contract } from '../base/index.js';
11
-
12
- export class BlueprintPromise extends Blueprint<'promise'> {
13
- constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash) {
14
- super(api, abi, codeHash, toPromiseMethod);
15
- }
16
- }
17
-
18
- export class CodePromise extends Code<'promise'> {
19
- constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
20
- super(api, abi, wasm, toPromiseMethod);
21
- }
22
- }
23
-
24
- export class ContractPromise extends Contract<'promise'> {
25
- constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20) {
26
- super(api, abi, address, toPromiseMethod);
27
- }
28
- }
package/src/rx/index.ts DELETED
@@ -1,28 +0,0 @@
1
- // Copyright 2017-2025 @polkadot/api-contract authors & contributors
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import type { ApiRx } from '@pezkuwi/api';
5
- import type { AccountId, Hash } from '@pezkuwi/types/interfaces';
6
- import type { Abi } from '../Abi/index.js';
7
-
8
- import { toRxMethod } from '@pezkuwi/api';
9
-
10
- import { Blueprint, Code, Contract } from '../base/index.js';
11
-
12
- export class BlueprintRx extends Blueprint<'rxjs'> {
13
- constructor (api: ApiRx, abi: string | Record<string, unknown> | Abi, codeHash: string | Hash) {
14
- super(api, abi, codeHash, toRxMethod);
15
- }
16
- }
17
-
18
- export class CodeRx extends Code<'rxjs'> {
19
- constructor (api: ApiRx, abi: string | Record<string, unknown> | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
20
- super(api, abi, wasm, toRxMethod);
21
- }
22
- }
23
-
24
- export class ContractRx extends Contract<'rxjs'> {
25
- constructor (api: ApiRx, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
26
- super(api, abi, address, toRxMethod);
27
- }
28
- }
@@ -1,47 +0,0 @@
1
- [
2
- {
3
- "info": "Plain",
4
- "lookupIndex": 1,
5
- "type": "AccountId",
6
- "docs": [],
7
- "namespace": "ink_env::types::AccountId",
8
- "lookupNameRoot": "InkEnvAccountId"
9
- },
10
- {
11
- "info": "VecFixed",
12
- "lookupIndex": 2,
13
- "type": "[u8;32]",
14
- "docs": [],
15
- "namespace": "",
16
- "length": 32,
17
- "sub": {
18
- "info": "Plain",
19
- "lookupIndex": 3,
20
- "type": "u8",
21
- "docs": [],
22
- "namespace": ""
23
- }
24
- },
25
- {
26
- "info": "Plain",
27
- "lookupIndex": 3,
28
- "type": "u8",
29
- "docs": [],
30
- "namespace": ""
31
- },
32
- {
33
- "info": "Plain",
34
- "lookupIndex": 4,
35
- "type": "i32",
36
- "docs": [],
37
- "namespace": ""
38
- },
39
- {
40
- "info": "Plain",
41
- "lookupIndex": 5,
42
- "type": "Hash",
43
- "docs": [],
44
- "namespace": "ink_env::types::Hash",
45
- "lookupNameRoot": "InkEnvHash"
46
- }
47
- ]