Update contract types and rpc (#4541)
* Update contract types and rpc * Corrected InstantiateReturnValue * enum, set fallbacks * set definition * underscore
This commit is contained in:
@@ -17,7 +17,7 @@ import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
|
||||
import type { StatementKind } from '@polkadot/types/interfaces/claims';
|
||||
import type { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
|
||||
import type { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
|
||||
import type { AliveContractInfo, CodeHash, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateReturnValue, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import type { AliveContractInfo, CodeHash, CodeSource, CodeUploadRequest, CodeUploadResult, CodeUploadResultValue, ContractCallFlags, ContractCallRequest, ContractExecResult, ContractExecResultErr, ContractExecResultErrModule, ContractExecResultOk, ContractExecResultResult, ContractExecResultSuccessTo255, ContractExecResultSuccessTo260, ContractExecResultTo255, ContractExecResultTo260, ContractExecResultTo267, ContractInfo, ContractInstantiateResult, ContractInstantiateResultTo267, ContractInstantiateResultTo299, ContractReturnFlags, ContractStorageKey, DeletedContract, ExecReturnValue, Gas, HostFnWeights, HostFnWeightsTo264, InstantiateRequest, InstantiateRequestV1, InstantiateRequestV2, InstantiateReturnValue, InstantiateReturnValueOk, InstantiateReturnValueTo267, InstructionWeights, Limits, LimitsTo264, PrefabWasmModule, RentProjection, Schedule, ScheduleTo212, ScheduleTo258, ScheduleTo264, SeedOf, StorageDeposit, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import type { ContractConstructorSpecLatest, ContractConstructorSpecV0, ContractConstructorSpecV1, ContractConstructorSpecV2, ContractConstructorSpecV3, ContractContractSpecV0, ContractContractSpecV1, ContractContractSpecV2, ContractContractSpecV3, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpecLatest, ContractEventParamSpecV0, ContractEventParamSpecV2, ContractEventSpecLatest, ContractEventSpecV0, ContractEventSpecV1, ContractEventSpecV2, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpecLatest, ContractMessageParamSpecV0, ContractMessageParamSpecV2, ContractMessageSpecLatest, ContractMessageSpecV0, ContractMessageSpecV1, ContractMessageSpecV2, ContractMetadata, ContractMetadataLatest, ContractMetadataV0, ContractMetadataV1, ContractMetadataV2, ContractMetadataV3, ContractProject, ContractProjectContract, ContractProjectInfo, ContractProjectSource, ContractProjectV0, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
|
||||
import type { FundIndex, FundInfo, LastContribution, TrieIndex } from '@polkadot/types/interfaces/crowdloan';
|
||||
import type { ConfigData, MessageId, OverweightIndex, PageCounter, PageIndexData } from '@polkadot/types/interfaces/cumulus';
|
||||
@@ -197,6 +197,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
ClassMetadata: ClassMetadata;
|
||||
CodecHash: CodecHash;
|
||||
CodeHash: CodeHash;
|
||||
CodeSource: CodeSource;
|
||||
CodeUploadRequest: CodeUploadRequest;
|
||||
CodeUploadResult: CodeUploadResult;
|
||||
CodeUploadResultValue: CodeUploadResultValue;
|
||||
@@ -249,6 +250,7 @@ declare module '@polkadot/types/types/registry' {
|
||||
ContractInfo: ContractInfo;
|
||||
ContractInstantiateResult: ContractInstantiateResult;
|
||||
ContractInstantiateResultTo267: ContractInstantiateResultTo267;
|
||||
ContractInstantiateResultTo299: ContractInstantiateResultTo299;
|
||||
ContractLayoutArray: ContractLayoutArray;
|
||||
ContractLayoutCell: ContractLayoutCell;
|
||||
ContractLayoutEnum: ContractLayoutEnum;
|
||||
@@ -525,7 +527,10 @@ declare module '@polkadot/types/types/registry' {
|
||||
InstanceId: InstanceId;
|
||||
InstanceMetadata: InstanceMetadata;
|
||||
InstantiateRequest: InstantiateRequest;
|
||||
InstantiateRequestV1: InstantiateRequestV1;
|
||||
InstantiateRequestV2: InstantiateRequestV2;
|
||||
InstantiateReturnValue: InstantiateReturnValue;
|
||||
InstantiateReturnValueOk: InstantiateReturnValueOk;
|
||||
InstantiateReturnValueTo267: InstantiateReturnValueTo267;
|
||||
InstructionV2: InstructionV2;
|
||||
InstructionWeights: InstructionWeights;
|
||||
|
||||
@@ -39,8 +39,9 @@ function isRustEnum (details: Record<string, string> | Record<string, number>):
|
||||
// { _enum: ['A', 'B', 'C'] }
|
||||
// { _enum: { A: AccountId, B: Balance, C: u32 } }
|
||||
// { _enum: { A: 1, B: 2 } }
|
||||
function _decodeEnum (value: TypeDef, details: string[] | Record<string, string> | Record<string, number>, count: number): TypeDef {
|
||||
function _decodeEnum (value: TypeDef, details: string[] | Record<string, string> | Record<string, number>, count: number, fallbackType?: string): TypeDef {
|
||||
value.info = TypeDefInfo.Enum;
|
||||
value.fallbackType = fallbackType;
|
||||
|
||||
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
||||
if (Array.isArray(details)) {
|
||||
@@ -68,8 +69,9 @@ function _decodeEnum (value: TypeDef, details: string[] | Record<string, string>
|
||||
|
||||
// decode a set of the form
|
||||
// { _set: { A: 0b0001, B: 0b0010, C: 0b0100 } }
|
||||
function _decodeSet (value: TypeDef, details: Record<string, number>): TypeDef {
|
||||
function _decodeSet (value: TypeDef, details: Record<string, number>, fallbackType: string | undefined): TypeDef {
|
||||
value.info = TypeDefInfo.Set;
|
||||
value.fallbackType = fallbackType;
|
||||
value.length = details._bitLength;
|
||||
value.sub = Object
|
||||
.entries(details)
|
||||
@@ -87,19 +89,19 @@ function _decodeSet (value: TypeDef, details: Record<string, number>): TypeDef {
|
||||
// decode a struct, set or enum
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeStruct (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
||||
const parsed = JSON.parse(type) as Record<string, unknown> & { _alias: string };
|
||||
const parsed = JSON.parse(type) as Record<string, unknown> & { _alias: string, _fallback?: string };
|
||||
const keys = Object.keys(parsed);
|
||||
|
||||
if (keys.length === 1 && keys[0] === '_enum') {
|
||||
return _decodeEnum(value, parsed[keys[0]] as string[], count);
|
||||
} else if (keys.length === 1 && keys[0] === '_set') {
|
||||
return _decodeSet(value, parsed[keys[0]] as Record<string, number>);
|
||||
if (keys.includes('_enum')) {
|
||||
return _decodeEnum(value, parsed._enum as string[], count, parsed._fallback);
|
||||
} else if (keys.includes('_set')) {
|
||||
return _decodeSet(value, parsed._set as Record<string, number>, parsed._fallback);
|
||||
}
|
||||
|
||||
value.alias = parsed._alias
|
||||
? new Map(Object.entries(parsed._alias))
|
||||
: undefined;
|
||||
value.fallbackType = parsed._fallback as string | undefined;
|
||||
value.fallbackType = parsed._fallback;
|
||||
value.sub = keys.filter((name) => !KNOWN_INTERNALS.includes(name)).map((name): TypeDef =>
|
||||
getTypeDef(getTypeString(parsed[name]), { name }, count)
|
||||
);
|
||||
|
||||
@@ -23,6 +23,12 @@ export default {
|
||||
_reserved: 'Option<Null>'
|
||||
},
|
||||
CodeHash: 'Hash',
|
||||
CodeSource: {
|
||||
_enum: {
|
||||
Upload: 'Bytes',
|
||||
Existing: 'Hash'
|
||||
}
|
||||
},
|
||||
CodeUploadRequest: {
|
||||
origin: 'AccountId',
|
||||
code: 'Bytes',
|
||||
@@ -234,7 +240,16 @@ export default {
|
||||
hashBlake2128PerByte: 'Weight',
|
||||
rentParams: 'Weight'
|
||||
},
|
||||
InstantiateRequest: {
|
||||
InstantiateRequestV1: {
|
||||
origin: 'AccountId',
|
||||
value: 'Balance',
|
||||
gasLimit: 'Gas',
|
||||
code: 'Bytes',
|
||||
data: 'Bytes',
|
||||
salt: 'Bytes'
|
||||
},
|
||||
InstantiateRequestV2: {
|
||||
_fallback: 'InstantiateRequestV1',
|
||||
origin: 'AccountId',
|
||||
value: 'Balance',
|
||||
gasLimit: 'Gas',
|
||||
@@ -243,28 +258,52 @@ export default {
|
||||
data: 'Bytes',
|
||||
salt: 'Bytes'
|
||||
},
|
||||
InstantiateRequest: {
|
||||
_fallback: 'InstantiateRequestV2',
|
||||
origin: 'AccountId',
|
||||
value: 'Balance',
|
||||
gasLimit: 'Gas',
|
||||
storageDepositLimit: 'Option<Balance>',
|
||||
code: 'CodeSource',
|
||||
data: 'Bytes',
|
||||
salt: 'Bytes'
|
||||
},
|
||||
ContractInstantiateResultTo267: {
|
||||
_enum: {
|
||||
Ok: 'InstantiateReturnValueTo267',
|
||||
Err: 'Null'
|
||||
}
|
||||
},
|
||||
ContractInstantiateResult: {
|
||||
ContractInstantiateResultTo299: {
|
||||
_enum: {
|
||||
Ok: 'InstantiateReturnValue',
|
||||
Err: 'Null'
|
||||
}
|
||||
},
|
||||
_fallback: 'ContractInstantiateResultTo267'
|
||||
},
|
||||
ContractInstantiateResult: {
|
||||
_fallback: 'ContractInstantiateResultTo299',
|
||||
gasConsumed: 'u64',
|
||||
gasRequired: 'u64',
|
||||
storageDeposit: 'StorageDeposit',
|
||||
debugMessage: 'Text',
|
||||
result: 'InstantiateReturnValue'
|
||||
},
|
||||
InstantiateReturnValueTo267: {
|
||||
result: 'ExecReturnValue',
|
||||
accountId: 'AccountId',
|
||||
rentProjection: 'Option<RentProjection>'
|
||||
},
|
||||
InstantiateReturnValue: {
|
||||
_fallback: 'InstantiateReturnValueTo267',
|
||||
InstantiateReturnValueOk: {
|
||||
result: 'ExecReturnValue',
|
||||
accountId: 'AccountId'
|
||||
},
|
||||
InstantiateReturnValue: {
|
||||
_enum: {
|
||||
Ok: 'InstantiateReturnValueOk',
|
||||
Err: 'DispatchError'
|
||||
}
|
||||
},
|
||||
InstructionWeights: {
|
||||
i64const: 'u32',
|
||||
i64load: 'u32',
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
import type { Bytes, Compact, Enum, Null, Option, Raw, Set, Struct, Text, U8aFixed, bool, u32, u64, u8 } from '@polkadot/types-codec';
|
||||
import type { AccountId, Balance, BlockNumber, Hash, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import type { DispatchError } from '@polkadot/types/interfaces/system';
|
||||
|
||||
/** @name AliveContractInfo */
|
||||
export interface AliveContractInfo extends Struct {
|
||||
@@ -20,6 +21,15 @@ export interface AliveContractInfo extends Struct {
|
||||
/** @name CodeHash */
|
||||
export interface CodeHash extends Hash {}
|
||||
|
||||
/** @name CodeSource */
|
||||
export interface CodeSource extends Enum {
|
||||
readonly isUpload: boolean;
|
||||
readonly asUpload: Bytes;
|
||||
readonly isExisting: boolean;
|
||||
readonly asExisting: Hash;
|
||||
readonly type: 'Upload' | 'Existing';
|
||||
}
|
||||
|
||||
/** @name CodeUploadRequest */
|
||||
export interface CodeUploadRequest extends Struct {
|
||||
readonly origin: AccountId;
|
||||
@@ -147,11 +157,12 @@ export interface ContractInfo extends Enum {
|
||||
}
|
||||
|
||||
/** @name ContractInstantiateResult */
|
||||
export interface ContractInstantiateResult extends Enum {
|
||||
readonly isOk: boolean;
|
||||
readonly asOk: InstantiateReturnValue;
|
||||
readonly isErr: boolean;
|
||||
readonly type: 'Ok' | 'Err';
|
||||
export interface ContractInstantiateResult extends Struct {
|
||||
readonly gasConsumed: u64;
|
||||
readonly gasRequired: u64;
|
||||
readonly storageDeposit: StorageDeposit;
|
||||
readonly debugMessage: Text;
|
||||
readonly result: InstantiateReturnValue;
|
||||
}
|
||||
|
||||
/** @name ContractInstantiateResultTo267 */
|
||||
@@ -162,6 +173,14 @@ export interface ContractInstantiateResultTo267 extends Enum {
|
||||
readonly type: 'Ok' | 'Err';
|
||||
}
|
||||
|
||||
/** @name ContractInstantiateResultTo299 */
|
||||
export interface ContractInstantiateResultTo299 extends Enum {
|
||||
readonly isOk: boolean;
|
||||
readonly asOk: InstantiateReturnValue;
|
||||
readonly isErr: boolean;
|
||||
readonly type: 'Ok' | 'Err';
|
||||
}
|
||||
|
||||
/** @name ContractReturnFlags */
|
||||
export interface ContractReturnFlags extends Set {
|
||||
readonly isRevert: boolean;
|
||||
@@ -292,6 +311,27 @@ export interface HostFnWeightsTo264 extends Struct {
|
||||
|
||||
/** @name InstantiateRequest */
|
||||
export interface InstantiateRequest extends Struct {
|
||||
readonly origin: AccountId;
|
||||
readonly value: Balance;
|
||||
readonly gasLimit: Gas;
|
||||
readonly storageDepositLimit: Option<Balance>;
|
||||
readonly code: CodeSource;
|
||||
readonly data: Bytes;
|
||||
readonly salt: Bytes;
|
||||
}
|
||||
|
||||
/** @name InstantiateRequestV1 */
|
||||
export interface InstantiateRequestV1 extends Struct {
|
||||
readonly origin: AccountId;
|
||||
readonly value: Balance;
|
||||
readonly gasLimit: Gas;
|
||||
readonly code: Bytes;
|
||||
readonly data: Bytes;
|
||||
readonly salt: Bytes;
|
||||
}
|
||||
|
||||
/** @name InstantiateRequestV2 */
|
||||
export interface InstantiateRequestV2 extends Struct {
|
||||
readonly origin: AccountId;
|
||||
readonly value: Balance;
|
||||
readonly gasLimit: Gas;
|
||||
@@ -302,7 +342,16 @@ export interface InstantiateRequest extends Struct {
|
||||
}
|
||||
|
||||
/** @name InstantiateReturnValue */
|
||||
export interface InstantiateReturnValue extends Struct {
|
||||
export interface InstantiateReturnValue extends Enum {
|
||||
readonly isOk: boolean;
|
||||
readonly asOk: InstantiateReturnValueOk;
|
||||
readonly isErr: boolean;
|
||||
readonly asErr: DispatchError;
|
||||
readonly type: 'Ok' | 'Err';
|
||||
}
|
||||
|
||||
/** @name InstantiateReturnValueOk */
|
||||
export interface InstantiateReturnValueOk extends Struct {
|
||||
readonly result: ExecReturnValue;
|
||||
readonly accountId: AccountId;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
export type DefinitionTypeType = string;
|
||||
|
||||
export type DefinitionTypeEnum = { _enum: DefinitionTypeType[] } | { _enum: Record<string, DefinitionTypeType | null> };
|
||||
export type DefinitionTypeEnum = { _fallback?: DefinitionTypeType } & ({ _enum: DefinitionTypeType[] } | { _enum: Record<string, DefinitionTypeType | null> });
|
||||
|
||||
export type DefinitionTypeSet = { _set: Record<string, number> };
|
||||
export type DefinitionTypeSet = { _fallback?: DefinitionTypeType, _set: Record<string, number> };
|
||||
|
||||
type DefinitionTypeStructExtra = {
|
||||
_alias?: Record<string, DefinitionTypeType>;
|
||||
|
||||
Reference in New Issue
Block a user