Skip to content

Commit 3284e71

Browse files
api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 16.2.1
1 parent 22c5a87 commit 3284e71

File tree

28 files changed

+212
-45
lines changed

28 files changed

+212
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master
44

5+
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 16.2.1
56
- phishing 0.25.12
67
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 16.1.2
78
- api, api-{augment, base, contract, derive}, rpc-{augment, core, provider}, types, types-{augment, codec, create, known} 16.1.1

api-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/api-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

api-base/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/api-base', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

api-contract/Abi/index.ts

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
import type { Bytes, Vec } from 'https://deno.land/x/polkadot/types/mod.ts';
3-
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventParamSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadata, ContractMetadataV4, ContractMetadataV5, ContractProjectInfo, ContractTypeSpec, EventRecord } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
3+
import type { ChainProperties, ContractConstructorSpecLatest, ContractEventParamSpecLatest, ContractMessageParamSpecLatest, ContractMessageSpecLatest, ContractMetadata, ContractMetadataV4, ContractMetadataV5, ContractMetadataV6, ContractProjectInfo, ContractTypeSpec, EventRecord } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
44
import type { Codec, Registry, TypeDef } from 'https://deno.land/x/polkadot/types/types/index.ts';
55
import type { AbiConstructor, AbiEvent, AbiEventParam, AbiMessage, AbiMessageParam, AbiParam, DecodedEvent, DecodedMessage } from '../types.ts';
66

@@ -17,12 +17,12 @@ interface AbiJson {
1717
}
1818

1919
type EventOf<M> = M extends {spec: { events: Vec<infer E>}} ? E : never
20-
export type ContractMetadataSupported = ContractMetadataV4 | ContractMetadataV5;
20+
export type ContractMetadataSupported = ContractMetadataV4 | ContractMetadataV5 | ContractMetadataV6;
2121
type ContractEventSupported = EventOf<ContractMetadataSupported>;
2222

2323
const l = logger('Abi');
2424

25-
const PRIMITIVE_ALWAYS = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
25+
const PRIMITIVE_ALWAYS = ['AccountId', 'AccountId20', 'AccountIndex', 'Address', 'Balance'];
2626

2727
function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string | number): T {
2828
const message = isNumber(messageOrId)
@@ -64,9 +64,28 @@ function getMetadata (registry: Registry, json: AbiJson): ContractMetadataSuppor
6464
return upgradedMetadata;
6565
}
6666

67-
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataSupported, ContractProjectInfo] {
67+
function isRevive (json: Record<string, unknown>): boolean {
68+
const source = json['source'];
69+
const version = json['version'];
70+
71+
const hasContractBinary =
72+
typeof source === 'object' &&
73+
source !== null &&
74+
'contract_binary' in source;
75+
76+
const hasVersion =
77+
typeof version === 'number' && version >= 6;
78+
79+
return hasContractBinary || hasVersion;
80+
}
81+
82+
function parseJson (json: Record<string, unknown>, chainProperties?: ChainProperties): [Record<string, unknown>, Registry, ContractMetadataSupported, ContractProjectInfo, boolean] {
6883
const registry = new TypeRegistry();
69-
const info = registry.createType('ContractProjectInfo', json) as unknown as ContractProjectInfo;
84+
85+
const revive = isRevive(json);
86+
const typeName = revive ? 'ContractReviveProjectInfo' : 'ContractProjectInfo';
87+
88+
const info = registry.createType(typeName, json) as unknown as ContractProjectInfo;
7089
const metadata = getMetadata(registry, json as unknown as AbiJson);
7190
const lookup = registry.createType('PortableRegistry', { types: metadata.types }, true);
7291

@@ -82,7 +101,7 @@ function parseJson (json: Record<string, unknown>, chainProperties?: ChainProper
82101
lookup.getTypeDef(id)
83102
);
84103

85-
return [json, registry, metadata, info];
104+
return [json, registry, metadata, info, revive];
86105
}
87106

88107
/**
@@ -110,9 +129,10 @@ export class Abi {
110129
readonly metadata: ContractMetadataSupported;
111130
readonly registry: Registry;
112131
readonly environment = new Map<string, TypeDef | Codec>();
132+
readonly isRevive: boolean;
113133

114134
constructor (abiJson: Record<string, unknown> | string, chainProperties?: ChainProperties) {
115-
[this.json, this.registry, this.metadata, this.info] = parseJson(
135+
[this.json, this.registry, this.metadata, this.info, this.isRevive] = parseJson(
116136
isString(abiJson)
117137
? JSON.parse(abiJson) as Record<string, unknown>
118138
: abiJson,

api-contract/Abi/toLatestCompatible.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import type { ContractMetadataV4, ContractMetadataV5 } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
2+
import type { ContractMetadataV4, ContractMetadataV5, ContractMetadataV6 } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
33
import type { Registry } from 'https://deno.land/x/polkadot/types/types/index.ts';
44
import type { ContractMetadataSupported } from './index.ts';
55

@@ -8,7 +8,7 @@ import { v1ToV2 } from './toV2.ts';
88
import { v2ToV3 } from './toV3.ts';
99
import { v3ToV4 } from './toV4.ts';
1010

11-
export const enumVersions = ['V5', 'V4', 'V3', 'V2', 'V1'] as const;
11+
export const enumVersions = ['V6', 'V5', 'V4', 'V3', 'V2', 'V1'] as const;
1212

1313
type Versions = typeof enumVersions[number] | 'V0';
1414

@@ -19,6 +19,10 @@ function createConverter <I, O> (next: (registry: Registry, input: O) => Contrac
1919
next(registry, step(registry, input));
2020
}
2121

22+
export function v6ToLatestCompatible (_registry: Registry, v6: ContractMetadataV6): ContractMetadataV6 {
23+
return v6;
24+
}
25+
2226
export function v5ToLatestCompatible (_registry: Registry, v5: ContractMetadataV5): ContractMetadataV5 {
2327
return v5;
2428
}
@@ -33,6 +37,7 @@ export const v1ToLatestCompatible = /*#__PURE__*/ createConverter(v2ToLatestComp
3337
export const v0ToLatestCompatible = /*#__PURE__*/ createConverter(v1ToLatestCompatible, v0ToV1);
3438

3539
export const convertVersions: [Versions, Converter][] = [
40+
['V6', v6ToLatestCompatible],
3641
['V5', v5ToLatestCompatible],
3742
['V4', v4ToLatestCompatible],
3843
['V3', v3ToLatestCompatible],

api-contract/base/Base.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ export abstract class Base<ApiType extends ApiTypes> {
1414

1515
protected readonly _decorateMethod: DecorateMethod<ApiType>;
1616
protected readonly _isWeightV1: boolean;
17+
protected readonly _isRevive: boolean;
1718

1819
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, decorateMethod: DecorateMethod<ApiType>) {
1920
if (!api || !api.isConnected || !api.tx) {
2021
throw new Error('Your API has not been initialized correctly and is not connected to a chain');
21-
} else if (!api.tx.contracts || !isFunction(api.tx.contracts.instantiateWithCode) || api.tx.contracts.instantiateWithCode.meta.args.length !== 6) {
22-
throw new Error('The runtime does not expose api.tx.contracts.instantiateWithCode with storageDepositLimit');
23-
} else if (!api.call.contractsApi || !isFunction(api.call.contractsApi.call)) {
24-
throw new Error('Your runtime does not expose the api.call.contractsApi.call runtime interfaces');
2522
}
2623

2724
this.abi = abi instanceof Abi
@@ -30,6 +27,21 @@ export abstract class Base<ApiType extends ApiTypes> {
3027
this.api = api;
3128
this._decorateMethod = decorateMethod;
3229
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+
}
3345
}
3446

3547
public get registry (): Registry {

api-contract/base/Blueprint.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
5353
}
5454

5555
#deploy = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
56-
return this.api.tx.contracts.instantiate(
56+
const palletTx = this._isRevive
57+
? this.api.tx.revive
58+
: this.api.tx.contracts;
59+
60+
return palletTx.instantiate(
5761
value,
5862
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
5963
// @ts-ignore jiggle v1 weights, metadata points to latest
@@ -65,9 +69,23 @@ export class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
6569
this.abi.findConstructor(constructorOrId).toU8a(params),
6670
encodeSalt(salt)
6771
).withResultTransform((result: ISubmittableResult) =>
68-
new BlueprintSubmittableResult(result, applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
69-
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
70-
))
72+
new BlueprintSubmittableResult(result,
73+
this._isRevive
74+
? (
75+
(result.status.isInBlock || result.status.isFinalized)
76+
? new Contract<ApiType>(
77+
this.api,
78+
this.abi,
79+
// your fixed address for revive deployments
80+
this.registry.createType('AccountId', '0x'),
81+
this._decorateMethod
82+
)
83+
: undefined
84+
)
85+
: applyOnEvent(result, ['Instantiated'], ([record]: EventRecord[]) =>
86+
new Contract<ApiType>(this.api, this.abi, record.event.data[1] as AccountId, this._decorateMethod)
87+
)
88+
)
7189
);
7290
};
7391
}

api-contract/base/Code.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,30 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
6666
}
6767

6868
#instantiate = (constructorOrId: AbiConstructor | string | number, { gasLimit = BN_ZERO, salt, storageDepositLimit = null, value = BN_ZERO }: BlueprintOptions, params: unknown[]): SubmittableExtrinsic<ApiType, CodeSubmittableResult<ApiType>> => {
69-
return this.api.tx.contracts.instantiateWithCode(
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+
new Blueprint<ApiType>(this.api, this.abi, this.abi.info.source.hash, this._decorateMethod),
87+
new Contract<ApiType>(this.api, this.abi, '0x', this._decorateMethod)
88+
)
89+
);
90+
}
91+
92+
return palletTx.instantiateWithCode(
7093
value,
7194
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7295
// @ts-ignore jiggle v1 weights, metadata points to latest

api-contract/base/Contract.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type { ApiBase } from 'https://deno.land/x/polkadot/api/base/index.ts';
33
import type { SubmittableExtrinsic } from 'https://deno.land/x/polkadot/api/submittable/types.ts';
44
import type { ApiTypes, DecorateMethod } from 'https://deno.land/x/polkadot/api/types/index.ts';
5-
import type { AccountId, ContractExecResult, EventRecord, Weight, WeightV2 } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
5+
import type { AccountId, AccountId20, ContractExecResult, EventRecord, Weight, WeightV2 } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
66
import type { ISubmittableResult } from 'https://deno.land/x/polkadot/types/types/index.ts';
77
import type { Abi } from '../Abi/index.ts';
88
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent, WeightAll } from '../types.ts';
@@ -49,15 +49,15 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
4949
/**
5050
* @description The on-chain address for this contract
5151
*/
52-
readonly address: AccountId;
52+
readonly address: AccountId | AccountId20;
5353

5454
readonly #query: MapMessageQuery<ApiType> = {};
5555
readonly #tx: MapMessageTx<ApiType> = {};
5656

57-
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
57+
constructor (api: ApiBase<ApiType>, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20, decorateMethod: DecorateMethod<ApiType>) {
5858
super(api, abi, decorateMethod);
5959

60-
this.address = this.registry.createType('AccountId', address);
60+
this.address = this.registry.createType(this._isRevive ? 'AccountId20' : 'AccountId', address);
6161

6262
this.abi.messages.forEach((m): void => {
6363
if (isUndefined(this.#tx[m.method])) {
@@ -97,7 +97,9 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
9797
};
9898

9999
#exec = (messageOrId: AbiMessage | string | number, { gasLimit = BN_ZERO, storageDepositLimit = null, value = BN_ZERO }: ContractOptions, params: unknown[]): SubmittableExtrinsic<ApiType> => {
100-
return this.api.tx.contracts.call(
100+
const palletTx = this._isRevive ? this.api.tx.revive : this.api.tx.contracts;
101+
102+
return palletTx.call(
101103
this.address,
102104
value,
103105
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
@@ -131,7 +133,9 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
131133
return {
132134
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
133135
send: this._decorateMethod((origin: string | AccountId | Uint8Array) =>
134-
this.api.rx.call.contractsApi.call<ContractExecResult>(
136+
(this._isRevive
137+
? this.api.rx.call.reviveApi.call
138+
: this.api.rx.call.contractsApi.call)<ContractExecResult>(
135139
origin,
136140
this.address,
137141
value,

api-contract/base/mock.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,20 @@ export const mockApi = {
2727
}
2828
}
2929
} 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'>;

api-contract/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/api-contract', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

api-contract/promise/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Buffer } from 'node:buffer';
22

33

44
import type { ApiPromise } from 'https://deno.land/x/polkadot/api/mod.ts';
5-
import type { AccountId, Hash } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
5+
import type { AccountId, AccountId20, Hash } from 'https://deno.land/x/polkadot/types/interfaces/index.ts';
66
import type { Abi } from '../Abi/index.ts';
77

88
import { toPromiseMethod } from 'https://deno.land/x/polkadot/api/mod.ts';
@@ -22,7 +22,7 @@ export class CodePromise extends Code<'promise'> {
2222
}
2323

2424
export class ContractPromise extends Contract<'promise'> {
25-
constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId) {
25+
constructor (api: ApiPromise, abi: string | Record<string, unknown> | Abi, address: string | AccountId | AccountId20) {
2626
super(api, abi, address, toPromiseMethod);
2727
}
2828
}

api-contract/test/contracts/ink/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import * as v2 from './v2/index.ts';
66
import * as v3 from './v3/index.ts';
77
import * as v4 from './v4/index.ts';
88
import * as v5 from './v5/index.ts';
9+
import * as v6 from './v6/index.ts';
910

10-
export default createVersionedExport({ v0, v1, v2, v3, v4, v5 });
11+
export default createVersionedExport({ v0, v1, v2, v3, v4, v5, v6 });
9.22 KB
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
export { default as erc20Contract } from './erc20.contract.json' assert { type: 'json' };
3+
export { default as erc20Metadata } from './erc20.json' assert { type: 'json' };

api-derive/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/api-derive', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

api/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/api', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

rpc-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

rpc-core/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-core', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

rpc-provider/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/rpc-provider', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/rpc-provider', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

types-augment/packageInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

22

3-
export const packageInfo = { name: '@polkadot/types-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.1.2' };
3+
export const packageInfo = { name: '@polkadot/types-augment', path: new URL(import.meta.url).pathname, type: 'deno', version: '16.2.1' };

0 commit comments

Comments
 (0)