Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb6166e65f | ||
|
|
dec82380c3 | ||
|
|
a980d4ae11 | ||
|
|
5c194b6f5f | ||
|
|
c4662e6fd8 | ||
|
|
995de2012e | ||
|
|
b1a8c011f4 | ||
|
|
86cd550ad3 | ||
|
|
57529998f9 | ||
|
|
0e0d733e65 | ||
|
|
773618acfb | ||
|
|
c5fcb0d06b | ||
|
|
e25272c986 | ||
|
|
d389c6737e | ||
|
|
9e1313f140 | ||
|
|
d2a2887d32 | ||
|
|
b3d9549c0b | ||
|
|
240cadd045 | ||
|
|
d47faa4687 | ||
|
|
393c677a16 | ||
|
|
074ddd8632 | ||
|
|
a8a10aec0c | ||
|
|
fed93e2459 | ||
|
|
374df23011 | ||
|
|
9c098c3fbf | ||
|
|
4e799858ad | ||
|
|
ee6924324f | ||
|
|
75f86bb43e | ||
|
|
bfd3113a55 | ||
|
|
8d8d5bd7d7 |
+23
-3
@@ -1,6 +1,25 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 2.2.1 Oct 13, 2020
|
||||
## 2.3.1 Oct 19, 2020
|
||||
|
||||
Upgrade priority: Low. Recommended for `api-contracts` developers and those using large messages via Node.js WS.
|
||||
|
||||
Contributed:
|
||||
|
||||
- Adjust frame size for Node.js WebSockets (Thanks to https://github.com/mnaamani)
|
||||
- Update warnings to reflect new docs URLs (Thanks to https://github.com/aphelionz)
|
||||
|
||||
Changes:
|
||||
|
||||
- Expose `dispatch{Error, Info}` on all `.tx` results (less boilerplate on info checks)
|
||||
- Add missing primitive types inside contracts type parsing
|
||||
- Adjust api-contract to expose `Contract.{query, tx}.<message>` and `Blueprint.tx.<constructor>`
|
||||
- Rework contracts registry to be generic to all scale-info definitions
|
||||
- Allow for auto-max weight on contract read/exec (useful in estimation)
|
||||
- Fix memoization where `BigInt` params are passed
|
||||
|
||||
|
||||
## 2.2.1 Oct 12, 2020
|
||||
|
||||
Upgrade priority: Low.
|
||||
|
||||
@@ -14,10 +33,11 @@ Contributed:
|
||||
Changes:
|
||||
|
||||
- Introduce `OriginCaller` type (& apply to scheduler types)
|
||||
- Adjust `ContractInfo` struct to cater for latest Substrate
|
||||
- Adjust `ContractInfo` type for latest Substrate (contracts)
|
||||
- Adjust `Schedule` type for latest Substrate (contracts)
|
||||
- Allow snake_case to be handled transparently in structs
|
||||
- Full new api-contract developer interfaces (Code, Blueprint, Contract)
|
||||
- Rework Abi & Abi Registry use & parse (on-top-of-contributed) for efficiency & non-global clobber
|
||||
- Rework Abi & Abi Registry use & parse (based on contributed) for efficiency & non-global clobber
|
||||
- Allow `null` input on `Text` values in addition to existing `undefined`
|
||||
- Remove all documentation after move to https://github.com/polkadot-js/docs repo
|
||||
- Adjust type encoding from TypeDef, s/encodeType/encodeTypeDef/
|
||||
|
||||
+6
-10
@@ -24,18 +24,14 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@babel/register": "^7.11.5",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/dev": "^0.58.1",
|
||||
"@babel/core": "^7.12.3",
|
||||
"@babel/register": "^7.12.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/dev": "^0.58.3",
|
||||
"@polkadot/ts": "^0.3.49",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.14",
|
||||
"@vuepress/plugin-search": "^1.6.0",
|
||||
"copyfiles": "^2.4.0",
|
||||
"typedoc": "^0.19.2",
|
||||
"typedoc-plugin-markdown": "^3.0.7",
|
||||
"typedoc-plugin-no-inherit": "^1.2.0"
|
||||
"copyfiles": "^2.4.0"
|
||||
},
|
||||
"version": "2.2.1"
|
||||
"version": "2.3.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,11 +26,11 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "2.2.1",
|
||||
"@polkadot/rpc-core": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/api": "2.3.1",
|
||||
"@polkadot/rpc-core": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"rxjs": "^6.6.3"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import * as testContracts from '../test/contracts';
|
||||
|
||||
const abis: Record<string, any> = { ...testContracts };
|
||||
|
||||
function compare (name: string, messageIds: string[]): void {
|
||||
function compareInterface (name: string, messageIds: string[]): void {
|
||||
try {
|
||||
const inkAbi = new Abi(abis[name]);
|
||||
|
||||
@@ -22,15 +22,15 @@ function compare (name: string, messageIds: string[]): void {
|
||||
describe('Abi', (): void => {
|
||||
describe('construction', (): void => {
|
||||
it('initializes from a contract ABI (flipper)', (): void => {
|
||||
compare('flipper', ['flip', 'get']);
|
||||
compareInterface('flipper', ['flip', 'get']);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (incrementer)', (): void => {
|
||||
compare('incrementer', ['inc', 'get']);
|
||||
compareInterface('incrementer', ['inc', 'get']);
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc20)', (): void => {
|
||||
compare('erc20', [
|
||||
compareInterface('erc20', [
|
||||
'total_supply',
|
||||
'balance_of',
|
||||
'allowance',
|
||||
@@ -41,7 +41,7 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (delegator)', (): void => {
|
||||
compare('delegator', [
|
||||
compareInterface('delegator', [
|
||||
'get',
|
||||
'change',
|
||||
'switch'
|
||||
@@ -49,7 +49,7 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (dns)', (): void => {
|
||||
compare('dns', [
|
||||
compareInterface('dns', [
|
||||
'register',
|
||||
'set_address',
|
||||
'transfer',
|
||||
@@ -58,7 +58,7 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc721)', (): void => {
|
||||
compare('erc721', [
|
||||
compareInterface('erc721', [
|
||||
'balance_of',
|
||||
'owner_of',
|
||||
'get_approved',
|
||||
@@ -73,7 +73,7 @@ describe('Abi', (): void => {
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (multisig_plain)', (): void => {
|
||||
compare('multisigPlain', [
|
||||
compareInterface('multisigPlain', [
|
||||
'add_owner',
|
||||
'remove_owner',
|
||||
'replace_owner',
|
||||
@@ -87,8 +87,4 @@ describe('Abi', (): void => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it('stores base project as JSON', (): void => {
|
||||
expect(new Abi(abis.dns).json).toEqual(abis.dns);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { AnyJson } from '@polkadot/types/types';
|
||||
import { ChainProperties, InkConstructorSpec, InkMessageSpec } from '@polkadot/types/interfaces';
|
||||
import { ChainProperties, ContractConstructorSpec, ContractMessageSpec, ContractProject } from '@polkadot/types/interfaces';
|
||||
import { AbiConstructor, AbiMessage, AbiMessageParam } from './types';
|
||||
|
||||
import { assert, isNumber, isObject, isString, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import ContractRegistry from './ContractRegistry';
|
||||
import MetaRegistry from './MetaRegistry';
|
||||
|
||||
function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string | number): T {
|
||||
const message = isNumber(messageOrId)
|
||||
@@ -21,13 +21,17 @@ function findMessage <T extends AbiMessage> (list: T[], messageOrId: T | string
|
||||
return message;
|
||||
}
|
||||
|
||||
export default class Abi extends ContractRegistry {
|
||||
export default class Abi {
|
||||
public readonly constructors: AbiConstructor[];
|
||||
|
||||
public readonly json: AnyJson;
|
||||
|
||||
public readonly messages: AbiMessage[];
|
||||
|
||||
public readonly project: ContractProject;
|
||||
|
||||
public readonly registry: MetaRegistry;
|
||||
|
||||
constructor (abiJson: AnyJson, chainProperties?: ChainProperties) {
|
||||
const json = isString(abiJson)
|
||||
? JSON.parse(abiJson) as AnyJson
|
||||
@@ -35,22 +39,26 @@ export default class Abi extends ContractRegistry {
|
||||
|
||||
assert(isObject(json) && !Array.isArray(json) && json.metadataVersion && isObject(json.spec) && !Array.isArray(json.spec) && Array.isArray(json.spec.constructors) && Array.isArray(json.spec.messages), 'Invalid JSON ABI structure supplied, expected a recent metadata version');
|
||||
|
||||
super(json, chainProperties);
|
||||
|
||||
this.json = json;
|
||||
this.constructors = this.project.spec.constructors.map((spec: InkConstructorSpec, index) =>
|
||||
this._createBase(spec, index, {
|
||||
this.registry = new MetaRegistry(chainProperties);
|
||||
this.project = this.registry.createType('ContractProject', json);
|
||||
|
||||
this.registry.setMetaTypes(this.project.types);
|
||||
|
||||
this.project.types.forEach((_, index) => this.registry.getMetaTypeDef(this.registry.createType('SiLookupTypeId', index + 1)));
|
||||
this.constructors = this.project.spec.constructors.map((spec: ContractConstructorSpec, index) =>
|
||||
this.#createBase(spec, index, {
|
||||
isConstructor: true
|
||||
})
|
||||
);
|
||||
this.messages = this.project.spec.messages.map((spec: InkMessageSpec, index): AbiMessage => {
|
||||
this.messages = this.project.spec.messages.map((spec: ContractMessageSpec, index): AbiMessage => {
|
||||
const typeSpec = spec.returnType.unwrapOr(null);
|
||||
|
||||
return this._createBase(spec, index, {
|
||||
return this.#createBase(spec, index, {
|
||||
isMutating: spec.mutates.isTrue,
|
||||
isPayable: spec.payable.isTrue,
|
||||
returnType: typeSpec
|
||||
? this.typeDefAt(typeSpec.type, { displayName: typeSpec.displayName.map((s) => s.toString()).join('::') || undefined })
|
||||
? this.registry.getMetaTypeDef(typeSpec.type)
|
||||
: null
|
||||
});
|
||||
});
|
||||
@@ -64,7 +72,7 @@ export default class Abi extends ContractRegistry {
|
||||
return findMessage(this.messages, messageOrId);
|
||||
}
|
||||
|
||||
private _createBase (spec: InkMessageSpec | InkConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage {
|
||||
#createBase = (spec: ContractMessageSpec | ContractConstructorSpec, index: number, add: Partial<AbiMessage> = {}): AbiMessage => {
|
||||
const identifier = spec.name.toString();
|
||||
const args = spec.args.map((arg, index): AbiMessageParam => {
|
||||
try {
|
||||
@@ -72,7 +80,7 @@ export default class Abi extends ContractRegistry {
|
||||
|
||||
return {
|
||||
name: stringCamelCase(arg.name.toString()),
|
||||
type: this.typeDefAt(arg.type.type)
|
||||
type: this.registry.getMetaTypeDef(arg.type.type)
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`Error expanding argument ${index} in ${JSON.stringify(spec)}`);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import ContractRegistry from './ContractRegistry';
|
||||
|
||||
import * as testContracts from '../test/contracts';
|
||||
|
||||
const abis: Record<string, any> = { ...testContracts };
|
||||
|
||||
function compare (name: string): void {
|
||||
const inkRegistry = new ContractRegistry(abis[name]);
|
||||
|
||||
try {
|
||||
const cmpPath = path.join(__dirname, `../test/compare/${name}.test.json`);
|
||||
|
||||
if (!fs.existsSync(cmpPath)) {
|
||||
fs.writeFileSync(cmpPath, JSON.stringify(inkRegistry.typeDefs, null, 2), { flag: 'w' });
|
||||
}
|
||||
|
||||
expect(inkRegistry.typeDefs).toEqual(require(cmpPath));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(inkRegistry.typeDefs));
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
describe('ContractRegistry', (): void => {
|
||||
describe('construction', (): void => {
|
||||
it('initializes from a contract ABI (flipper)', (): void => {
|
||||
compare('flipper');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (incrementer)', (): void => {
|
||||
compare('incrementer');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc20)', (): void => {
|
||||
compare('erc20');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (dns)', (): void => {
|
||||
compare('dns');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc721)', (): void => {
|
||||
compare('erc721');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (multisig_plain)', (): void => {
|
||||
compare('multisigPlain');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,226 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ChainProperties, InkProject, MtField, MtLookupTypeId, MtType, MtTypeDefArray, MtTypeDefVariant, MtTypeDefSequence, MtTypeDefTuple, MtVariant } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Registry, TypeDef, TypeDefInfo } from '@polkadot/types/types';
|
||||
|
||||
import { assert, isUndefined } from '@polkadot/util';
|
||||
import { TypeRegistry, withTypeString } from '@polkadot/types';
|
||||
|
||||
// convert the offset into project-specific, index-1
|
||||
export function getRegistryOffset (id: MtLookupTypeId): number {
|
||||
return id.toNumber() - 1;
|
||||
}
|
||||
|
||||
export default class ContractRegistry {
|
||||
public readonly typeDefs: TypeDef[] = [];
|
||||
|
||||
public readonly registry: Registry;
|
||||
|
||||
public readonly project: InkProject;
|
||||
|
||||
constructor (json: Record<string, AnyJson>, chainProperties?: ChainProperties) {
|
||||
this.registry = new TypeRegistry();
|
||||
|
||||
if (chainProperties) {
|
||||
this.registry.setChainProperties(chainProperties);
|
||||
}
|
||||
|
||||
this.project = this.registry.createType('InkProject', json);
|
||||
|
||||
// Generate TypeDefs for each provided registry type
|
||||
this.project.types.forEach((_, index) => this.setTypeDef(this.registry.createType('MtLookupTypeId', index + 1)));
|
||||
}
|
||||
|
||||
public getAbiType (id: MtLookupTypeId): MtType {
|
||||
const offset = getRegistryOffset(id);
|
||||
const type = this.project.types[offset];
|
||||
|
||||
assert(!isUndefined(type), `getAbiType:: Unable to find ${id.toNumber()} in type values`);
|
||||
|
||||
return this.registry.createType('MtType', type);
|
||||
}
|
||||
|
||||
public typeDefAt (id: MtLookupTypeId, extra: Pick<TypeDef, never> = {}): TypeDef {
|
||||
if (!this.typeDefs[getRegistryOffset(id)]) {
|
||||
this.setTypeDef(id);
|
||||
}
|
||||
|
||||
return {
|
||||
...this.typeDefs[getRegistryOffset(id)],
|
||||
...extra
|
||||
};
|
||||
}
|
||||
|
||||
public setTypeDef (id: MtLookupTypeId): void {
|
||||
const typeDef = this.extractType(this.getAbiType(id), id) as TypeDef;
|
||||
|
||||
this.typeDefs[getRegistryOffset(id)] = typeDef;
|
||||
|
||||
// We have a displayName for non-primitives and non-results
|
||||
// FIXME here we protect against "Option: 'Option<...something...>' definitions (same with result)
|
||||
if (typeDef.displayName && typeDef.info !== TypeDefInfo.Plain && !typeDef.type.startsWith(typeDef.displayName)) {
|
||||
this.registry.register({ [typeDef.displayName]: typeDef.type });
|
||||
}
|
||||
}
|
||||
|
||||
private extractType (inkType: MtType, id: MtLookupTypeId): Pick<TypeDef, never> {
|
||||
const path = [...inkType.path];
|
||||
let typeDef;
|
||||
|
||||
if (inkType.path.join('::').startsWith('ink_env::types::') || inkType.def.isPrimitive) {
|
||||
typeDef = this.extractPrimitive(inkType);
|
||||
} else if (inkType.def.isComposite) {
|
||||
typeDef = this.extractFields(inkType.def.asComposite.fields);
|
||||
} else if (inkType.def.isVariant) {
|
||||
typeDef = this.extractVariant(inkType.def.asVariant, id);
|
||||
} else if (inkType.def.isArray) {
|
||||
typeDef = this.extractArray(inkType.def.asArray);
|
||||
} else if (inkType.def.isSequence) {
|
||||
typeDef = this.extractSequence(inkType.def.asSequence, id);
|
||||
} else if (inkType.def.isTuple) {
|
||||
typeDef = this.extractTuple(inkType.def.asTuple);
|
||||
} else {
|
||||
throw new Error(`Invalid ink! type at index ${id.toString()}`);
|
||||
}
|
||||
|
||||
const displayName = path.pop()?.toString();
|
||||
|
||||
return withTypeString({
|
||||
...(displayName
|
||||
? { displayName }
|
||||
: {}
|
||||
),
|
||||
...(path.length > 1
|
||||
? { namespace: path.map((segment) => segment.toString()).join('::') }
|
||||
: {}
|
||||
),
|
||||
...(inkType.params.length > 0
|
||||
? { params: inkType.params.map((id) => this.typeDefAt(id)) }
|
||||
: {}
|
||||
),
|
||||
...typeDef
|
||||
});
|
||||
}
|
||||
|
||||
private extractVariant ({ variants }: MtTypeDefVariant, id: MtLookupTypeId): Pick<TypeDef, never> {
|
||||
const { params, path } = this.getAbiType(id);
|
||||
const specialVariant = path[0].toString();
|
||||
|
||||
if (specialVariant === 'Option') {
|
||||
return {
|
||||
info: TypeDefInfo.Option,
|
||||
sub: this.typeDefAt(params[0])
|
||||
};
|
||||
} else if (specialVariant === 'Result') {
|
||||
return {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map((param, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...this.typeDefAt(param)
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: this.extractVariantSub(variants)
|
||||
};
|
||||
}
|
||||
|
||||
private extractVariantSub (variants: MtVariant[]): Pick<TypeDef, any>[] {
|
||||
const isAllUnitVariants = variants.every(({ fields }) => fields.length === 0);
|
||||
|
||||
if (isAllUnitVariants) {
|
||||
return variants.map(({ discriminant, name }) => ({
|
||||
...(
|
||||
discriminant.isSome
|
||||
? { ext: { discriminant: discriminant.unwrap().toNumber() } }
|
||||
: {}
|
||||
),
|
||||
info: TypeDefInfo.Plain,
|
||||
name: name.toString(),
|
||||
type: 'Null'
|
||||
}));
|
||||
}
|
||||
|
||||
return variants.map(({ fields, name }) => ({
|
||||
...this.extractFields(fields),
|
||||
name: name.toString()
|
||||
}));
|
||||
}
|
||||
|
||||
private extractFields (fields: MtField[]): Pick<TypeDef, any> {
|
||||
const [isStruct, isTuple] = fields.reduce(([isAllNamed, isAllUnnamed], { name }) => ([
|
||||
isAllNamed && name.isSome,
|
||||
isAllUnnamed && name.isNone
|
||||
]),
|
||||
[true, true]);
|
||||
|
||||
let info;
|
||||
|
||||
// check for tuple first (no fields may be available)
|
||||
if (isTuple) {
|
||||
info = TypeDefInfo.Tuple;
|
||||
} else if (isStruct) {
|
||||
info = TypeDefInfo.Struct;
|
||||
} else {
|
||||
throw new Error('Invalid fields type detected, expected either Tuple or Struct');
|
||||
}
|
||||
|
||||
const sub = fields.map(({ name, type }) => {
|
||||
return {
|
||||
...this.typeDefAt(type),
|
||||
...(name.isSome ? { name: name.unwrap().toString() } : {})
|
||||
};
|
||||
});
|
||||
|
||||
return isTuple && sub.length === 1
|
||||
? sub[0]
|
||||
: { info, sub };
|
||||
}
|
||||
|
||||
private extractArray ({ len: length, type }: MtTypeDefArray): Pick<TypeDef, never> {
|
||||
assert(!length || length.toNumber() <= 256, 'ContractRegistry: Only support for [Type; <length>], where length > 256');
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.VecFixed,
|
||||
length: length.toNumber(),
|
||||
sub: this.typeDefAt(type)
|
||||
};
|
||||
}
|
||||
|
||||
private extractSequence ({ type }: MtTypeDefSequence, id: MtLookupTypeId): Pick<TypeDef, never> {
|
||||
assert(!!type, `ContractRegistry: Invalid sequence type found at id ${id.toString()}`);
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Vec,
|
||||
sub: this.typeDefAt(type)
|
||||
};
|
||||
}
|
||||
|
||||
private extractTuple (ids: MtTypeDefTuple): Pick<TypeDef, never> {
|
||||
return ids.length === 1
|
||||
? this.typeDefAt(ids[0])
|
||||
: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
sub: ids.map((id) => this.typeDefAt(id))
|
||||
};
|
||||
}
|
||||
|
||||
private extractPrimitive (inkType: MtType): Pick<TypeDef, never> {
|
||||
if (inkType.def.isPrimitive) {
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: inkType.def.asPrimitive.type.toLowerCase()
|
||||
};
|
||||
} else if (inkType.path.length > 1) {
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: inkType.path[inkType.path.length - 1].toString()
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error('Invalid primitive type');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import Abi from './Abi';
|
||||
|
||||
import * as testContracts from '../test/contracts';
|
||||
import * as userContracts from '../test/contracts/user';
|
||||
|
||||
const abis: Record<string, any> = { ...testContracts };
|
||||
const userAbis: Record<string, any> = { ...userContracts };
|
||||
|
||||
function compareTypes (name: string): void {
|
||||
const abi = new Abi(abis[name] || userAbis[name]);
|
||||
|
||||
try {
|
||||
const cmpPath = path.join(__dirname, `../test/compare/${name}.test.json`);
|
||||
|
||||
if (!fs.existsSync(cmpPath)) {
|
||||
fs.writeFileSync(cmpPath, JSON.stringify(abi.registry.metaTypeDefs, null, 2), { flag: 'w' });
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
expect(abi.registry.metaTypeDefs).toEqual(require(cmpPath));
|
||||
} catch (error) {
|
||||
console.error(JSON.stringify(abi.registry.metaTypeDefs));
|
||||
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
describe('MetaRegistry', (): void => {
|
||||
describe('types', (): void => {
|
||||
it('initializes from a contract ABI (flipper)', (): void => {
|
||||
compareTypes('flipper');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (incrementer)', (): void => {
|
||||
compareTypes('incrementer');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc20)', (): void => {
|
||||
compareTypes('erc20');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (dns)', (): void => {
|
||||
compareTypes('dns');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (erc721)', (): void => {
|
||||
compareTypes('erc721');
|
||||
});
|
||||
|
||||
it('initializes from a contract ABI (multisig_plain)', (): void => {
|
||||
compareTypes('multisigPlain');
|
||||
});
|
||||
});
|
||||
|
||||
describe('user ABIs', (): void => {
|
||||
it('initializes from a contract ABI (withString)', (): void => {
|
||||
compareTypes('withString');
|
||||
});
|
||||
});
|
||||
|
||||
it('stores base project as JSON', (): void => {
|
||||
expect(new Abi(abis.dns).json).toEqual(abis.dns);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,230 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ChainProperties, SiField, SiLookupTypeId, SiType, SiTypeDefArray, SiTypeDefVariant, SiTypeDefSequence, SiTypeDefTuple, SiVariant } from '@polkadot/types/interfaces';
|
||||
import { InterfaceTypes, TypeDef, TypeDefInfo } from '@polkadot/types/types';
|
||||
|
||||
import { assert, isUndefined } from '@polkadot/util';
|
||||
import { TypeRegistry, withTypeString } from '@polkadot/types';
|
||||
|
||||
// convert the offset into project-specific, index-1
|
||||
export function getRegistryOffset (id: SiLookupTypeId): number {
|
||||
return id.toNumber() - 1;
|
||||
}
|
||||
|
||||
const PRIMITIVE_ALIAS: Record<string, keyof InterfaceTypes> = {
|
||||
Char: 'u32', // Rust char is 4-bytes
|
||||
Str: 'Text'
|
||||
};
|
||||
|
||||
export default class MetaRegistry extends TypeRegistry {
|
||||
public readonly metaTypeDefs: TypeDef[] = [];
|
||||
|
||||
#siTypes: SiType[] = [];
|
||||
|
||||
constructor (chainProperties?: ChainProperties) {
|
||||
super();
|
||||
|
||||
if (chainProperties) {
|
||||
this.setChainProperties(chainProperties);
|
||||
}
|
||||
}
|
||||
|
||||
public setMetaTypes (metaTypes: SiType[]): void {
|
||||
this.#siTypes = metaTypes;
|
||||
}
|
||||
|
||||
public getMetaTypeDef (id: SiLookupTypeId): TypeDef {
|
||||
const offset = getRegistryOffset(id);
|
||||
let typeDef = this.metaTypeDefs[offset];
|
||||
|
||||
if (!typeDef) {
|
||||
typeDef = this.#extract(this.#getMetaType(id), id);
|
||||
|
||||
this.metaTypeDefs[offset] = typeDef;
|
||||
|
||||
// Here we protect against the following cases
|
||||
// - No displayName present, these are generally known primitives
|
||||
// - displayName === type, these generate circular references
|
||||
// - displayName Option & type Option<...something...>
|
||||
if (typeDef.displayName && !(typeDef.type === typeDef.displayName || typeDef.type.startsWith(`${typeDef.displayName}<`))) {
|
||||
this.register({ [typeDef.displayName]: typeDef.type });
|
||||
}
|
||||
}
|
||||
|
||||
return typeDef;
|
||||
}
|
||||
|
||||
#getMetaType = (id: SiLookupTypeId): SiType => {
|
||||
const type = this.#siTypes[getRegistryOffset(id)];
|
||||
|
||||
assert(!isUndefined(type), `getMetaType:: Unable to find ${id.toNumber()} in type values`);
|
||||
|
||||
return this.createType('SiType', type);
|
||||
}
|
||||
|
||||
#extract = (type: SiType, id: SiLookupTypeId): TypeDef => {
|
||||
const path = [...type.path];
|
||||
let typeDef: Omit<TypeDef, 'type'>;
|
||||
|
||||
// TODO solang?
|
||||
if (type.path.join('::').startsWith('ink_env::types::')) {
|
||||
typeDef = this.#extractPrimitivePath(type);
|
||||
} else if (type.def.isPrimitive) {
|
||||
typeDef = this.#extractPrimitive(type);
|
||||
} else if (type.def.isComposite) {
|
||||
typeDef = this.#extractFields(type.def.asComposite.fields);
|
||||
} else if (type.def.isVariant) {
|
||||
typeDef = this.#extractVariant(type.def.asVariant, id);
|
||||
} else if (type.def.isArray) {
|
||||
typeDef = this.#extractArray(type.def.asArray);
|
||||
} else if (type.def.isSequence) {
|
||||
typeDef = this.#extractSequence(type.def.asSequence, id);
|
||||
} else if (type.def.isTuple) {
|
||||
typeDef = this.#extractTuple(type.def.asTuple);
|
||||
} else {
|
||||
throw new Error(`Invalid ink! type at index ${id.toString()}`);
|
||||
}
|
||||
|
||||
const displayName = path.pop()?.toString();
|
||||
|
||||
return withTypeString({
|
||||
...(displayName
|
||||
? { displayName }
|
||||
: {}
|
||||
),
|
||||
...(path.length > 1
|
||||
? { namespace: path.map((segment) => segment.toString()).join('::') }
|
||||
: {}
|
||||
),
|
||||
...(type.params.length > 0
|
||||
? { params: type.params.map((id) => this.getMetaTypeDef(id)) }
|
||||
: {}
|
||||
),
|
||||
...typeDef
|
||||
});
|
||||
}
|
||||
|
||||
#extractArray = ({ len: length, type }: SiTypeDefArray): Omit<TypeDef, 'type'> => {
|
||||
assert(!length || length.toNumber() <= 256, 'MetaRegistry: Only support for [Type; <length>], where length > 256');
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.VecFixed,
|
||||
length: length.toNumber(),
|
||||
sub: this.getMetaTypeDef(type)
|
||||
};
|
||||
}
|
||||
|
||||
#extractFields = (fields: SiField[]): Omit<TypeDef, 'type'> => {
|
||||
const [isStruct, isTuple] = fields.reduce(([isAllNamed, isAllUnnamed], { name }) => ([
|
||||
isAllNamed && name.isSome,
|
||||
isAllUnnamed && name.isNone
|
||||
]),
|
||||
[true, true]);
|
||||
|
||||
let info;
|
||||
|
||||
// check for tuple first (no fields may be available)
|
||||
if (isTuple) {
|
||||
info = TypeDefInfo.Tuple;
|
||||
} else if (isStruct) {
|
||||
info = TypeDefInfo.Struct;
|
||||
} else {
|
||||
throw new Error('Invalid fields type detected, expected either Tuple or Struct');
|
||||
}
|
||||
|
||||
const sub = fields.map(({ name, type }) => {
|
||||
return {
|
||||
...this.getMetaTypeDef(type),
|
||||
...(name.isSome ? { name: name.unwrap().toString() } : {})
|
||||
};
|
||||
});
|
||||
|
||||
return isTuple && sub.length === 1
|
||||
? sub[0]
|
||||
: { info, sub };
|
||||
}
|
||||
|
||||
#extractPrimitive = (type: SiType): TypeDef => {
|
||||
const typeStr = type.def.asPrimitive.type.toString();
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: PRIMITIVE_ALIAS[typeStr] || typeStr.toLowerCase()
|
||||
};
|
||||
}
|
||||
|
||||
#extractPrimitivePath = (type: SiType): TypeDef => {
|
||||
return {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: type.path[type.path.length - 1].toString()
|
||||
};
|
||||
}
|
||||
|
||||
#extractSequence = ({ type }: SiTypeDefSequence, id: SiLookupTypeId): Omit<TypeDef, 'type'> => {
|
||||
assert(!!type, `ContractRegistry: Invalid sequence type found at id ${id.toString()}`);
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Vec,
|
||||
sub: this.getMetaTypeDef(type)
|
||||
};
|
||||
}
|
||||
|
||||
#extractTuple = (ids: SiTypeDefTuple): Omit<TypeDef, 'type'> => {
|
||||
return ids.length === 1
|
||||
? this.getMetaTypeDef(ids[0])
|
||||
: {
|
||||
info: TypeDefInfo.Tuple,
|
||||
sub: ids.map((id) => this.getMetaTypeDef(id))
|
||||
};
|
||||
}
|
||||
|
||||
#extractVariant = ({ variants }: SiTypeDefVariant, id: SiLookupTypeId): Omit<TypeDef, 'type'> => {
|
||||
const { params, path } = this.#getMetaType(id);
|
||||
const specialVariant = path[0].toString();
|
||||
|
||||
if (specialVariant === 'Option') {
|
||||
return {
|
||||
info: TypeDefInfo.Option,
|
||||
sub: this.getMetaTypeDef(params[0])
|
||||
};
|
||||
} else if (specialVariant === 'Result') {
|
||||
return {
|
||||
info: TypeDefInfo.Result,
|
||||
sub: params.map((param, index) => ({
|
||||
name: ['Ok', 'Error'][index],
|
||||
...this.getMetaTypeDef(param)
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
info: TypeDefInfo.Enum,
|
||||
sub: this.#extractVariantSub(variants)
|
||||
};
|
||||
}
|
||||
|
||||
#extractVariantSub = (variants: SiVariant[]): TypeDef[] => {
|
||||
const isAllUnitVariants = variants.every(({ fields }) => fields.length === 0);
|
||||
|
||||
if (isAllUnitVariants) {
|
||||
return variants.map(({ discriminant, name }) => ({
|
||||
...(
|
||||
discriminant.isSome
|
||||
? { ext: { discriminant: discriminant.unwrap().toNumber() } }
|
||||
: {}
|
||||
),
|
||||
info: TypeDefInfo.Plain,
|
||||
name: name.toString(),
|
||||
type: 'Null'
|
||||
}));
|
||||
}
|
||||
|
||||
return variants.map(({ fields, name }) =>
|
||||
withTypeString({
|
||||
...this.#extractFields(fields),
|
||||
name: name.toString()
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,12 @@ import { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import { AccountId, EventRecord, Hash } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, CodecArg, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { AbiConstructor } from '../types';
|
||||
import { MapConstructorExec } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import ApiBase from '@polkadot/api/base';
|
||||
import { isUndefined, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import { applyOnEvent, encodeMessage } from '../util';
|
||||
@@ -29,13 +31,28 @@ export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends Submit
|
||||
export default class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
public readonly codeHash: Hash;
|
||||
|
||||
readonly #tx: MapConstructorExec<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, codeHash: string | Hash | Uint8Array, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.codeHash = this.registry.createType('Hash', codeHash);
|
||||
|
||||
this.abi.constructors.forEach((c): void => {
|
||||
const messageName = stringCamelCase(c.identifier);
|
||||
|
||||
if (isUndefined(this.#tx[messageName])) {
|
||||
this.#tx[messageName] = (endowment: BigInt | string | number | BN, gasLimit: BigInt | string | number | BN, ...params: CodecArg[]) =>
|
||||
this.#deploy(c, endowment, gasLimit, params);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public createContract (constructorOrId: AbiConstructor | string| number, endowment: BigInt | string | number | BN, gasLimit: BigInt | string | number | BN, ...params: CodecArg[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> {
|
||||
public get tx (): MapConstructorExec<ApiType> {
|
||||
return this.#tx;
|
||||
}
|
||||
|
||||
#deploy = (constructorOrId: AbiConstructor | string| number, endowment: BigInt | string | number | BN, gasLimit: BigInt | string | number | BN, params: CodecArg[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> => {
|
||||
return this.api.tx.contracts
|
||||
.instantiate(endowment, gasLimit, this.codeHash, encodeMessage(this.registry, this.abi.findConstructor(constructorOrId), params))
|
||||
.withResultTransform((result: ISubmittableResult) =>
|
||||
@@ -44,4 +61,8 @@ export default class Blueprint<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
public createContract (constructorOrId: AbiConstructor | string| number, endowment: BigInt | string | number | BN, gasLimit: BigInt | string | number | BN, ...params: CodecArg[]): SubmittableExtrinsic<ApiType, BlueprintSubmittableResult<ApiType>> {
|
||||
return this.#deploy(constructorOrId, endowment, gasLimit, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +1,90 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes, DecorateMethod, ObsInnerType } from '@polkadot/api/types';
|
||||
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
|
||||
import { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import { AccountId, ContractExecResult } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, CodecArg, IKeyringPair } from '@polkadot/types/types';
|
||||
import { AnyJson, CodecArg } from '@polkadot/types/types';
|
||||
import { AbiMessage, ContractCallOutcome } from '../types';
|
||||
import { ContractCallResult, ContractRead, MapMessageExec, MapMessageRead } from './types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import ApiBase from '@polkadot/api/base';
|
||||
import { assert, isFunction } from '@polkadot/util';
|
||||
import { assert, bnToBn, isFunction, isUndefined, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import { encodeMessage, formatData } from '../util';
|
||||
import Base from './Base';
|
||||
|
||||
type ContractCallTypes = 'tx' | 'rpc';
|
||||
|
||||
type ContractCallResultSubscription<ApiType extends ApiTypes, CallType extends ContractCallTypes> = ApiType extends 'rxjs'
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
? Observable<ContractCallResult<CallType>>
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
: Promise<ObsInnerType<ContractCallResult<CallType>>>;
|
||||
|
||||
export interface ContractRead<ApiType extends ApiTypes> {
|
||||
send (account: IKeyringPair | string | AccountId): ContractCallResultSubscription<ApiType, 'rpc'>;
|
||||
}
|
||||
|
||||
export type ContractCallResult<CallType extends ContractCallTypes> = CallType extends 'rpc'
|
||||
? Observable<ContractCallOutcome>
|
||||
: Observable<SubmittableResult>;
|
||||
const ERROR_NO_CALL = 'Your node does not expose the contracts.call RPC. This is most probably due to a runtime configuration.';
|
||||
|
||||
export default class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
public readonly address: AccountId;
|
||||
|
||||
readonly #tx: MapMessageExec<ApiType> = {};
|
||||
|
||||
readonly #query: MapMessageRead<ApiType> = {};
|
||||
|
||||
constructor (api: ApiBase<ApiType>, abi: AnyJson | Abi, address: string | AccountId, decorateMethod: DecorateMethod<ApiType>) {
|
||||
super(api, abi, decorateMethod);
|
||||
|
||||
this.address = this.registry.createType('AccountId', address);
|
||||
|
||||
this.abi.messages.forEach((m): void => {
|
||||
const messageName = stringCamelCase(m.identifier);
|
||||
|
||||
if (isUndefined(this.#tx[messageName])) {
|
||||
this.#tx[messageName] = (value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]) =>
|
||||
this.#exec(m, value, gasLimit, params);
|
||||
}
|
||||
|
||||
if (isUndefined(this.#query[messageName])) {
|
||||
this.#query[messageName] = (origin: string | AccountId | Uint8Array, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]) =>
|
||||
this.#read(m, value, gasLimit, params).send(origin);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public get hasRpcContractsCall (): boolean {
|
||||
return isFunction(this.api.rx.rpc.contracts?.call);
|
||||
}
|
||||
|
||||
public exec (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]): SubmittableExtrinsic<ApiType> {
|
||||
return this.api.tx.contracts.call(this.address, value, gasLimit, encodeMessage(this.registry, this.abi.findMessage(messageOrId), params));
|
||||
public get query (): MapMessageRead<ApiType> {
|
||||
assert(this.hasRpcContractsCall, ERROR_NO_CALL);
|
||||
|
||||
return this.#query;
|
||||
}
|
||||
|
||||
public read (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]): ContractRead<ApiType> {
|
||||
assert(this.hasRpcContractsCall, 'Your node does not support contract RPC read calls');
|
||||
public get tx (): MapMessageExec<ApiType> {
|
||||
return this.#tx;
|
||||
}
|
||||
|
||||
#getGas = (_gasLimit: BigInt | BN | string | number): BN => {
|
||||
const gasLimit = bnToBn(_gasLimit);
|
||||
|
||||
return gasLimit.lten(0)
|
||||
? this.api.consts.system.maximumBlockWeight.muln(64).divn(100)
|
||||
: gasLimit;
|
||||
}
|
||||
|
||||
#exec = (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, params: CodecArg[]): SubmittableExtrinsic<ApiType> => {
|
||||
return this.api.tx.contracts.call(this.address, value, this.#getGas(gasLimit), encodeMessage(this.registry, this.abi.findMessage(messageOrId), params));
|
||||
}
|
||||
|
||||
#read = (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, params: CodecArg[]): ContractRead<ApiType> => {
|
||||
assert(this.hasRpcContractsCall, ERROR_NO_CALL);
|
||||
|
||||
const message = this.abi.findMessage(messageOrId);
|
||||
|
||||
return {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
send: this._decorateMethod((account: string | AccountId | Uint8Array): ContractCallResult<'rpc'> =>
|
||||
send: this._decorateMethod((origin: string | AccountId | Uint8Array): ContractCallResult<'rpc'> =>
|
||||
this.api.rx.rpc.contracts.call({
|
||||
dest: this.address,
|
||||
gasLimit,
|
||||
gasLimit: this.#getGas(gasLimit),
|
||||
inputData: encodeMessage(this.registry, message, params),
|
||||
origin: account,
|
||||
origin,
|
||||
value
|
||||
}).pipe(
|
||||
map((result: ContractExecResult): ContractCallOutcome => ({
|
||||
@@ -76,4 +97,12 @@ export default class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
public exec (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]): SubmittableExtrinsic<ApiType> {
|
||||
return this.#exec(messageOrId, value, gasLimit, params);
|
||||
}
|
||||
|
||||
public read (messageOrId: AbiMessage | string | number, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]): ContractRead<ApiType> {
|
||||
return this.#read(messageOrId, value, gasLimit, params);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as Blueprint } from './Blueprint';
|
||||
export { default as Code } from './Code';
|
||||
export { default as Blueprint, BlueprintSubmittableResult } from './Blueprint';
|
||||
export { default as Code, CodeSubmittableResult } from './Code';
|
||||
export { default as Contract } from './Contract';
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { SubmittableResult } from '@polkadot/api';
|
||||
import { ApiTypes, ObsInnerType } from '@polkadot/api/types';
|
||||
import { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { CodecArg } from '@polkadot/types/types';
|
||||
import { ContractCallOutcome } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
type ContractCallTypes = 'tx' | 'rpc';
|
||||
|
||||
type ContractCallResultSubscription<ApiType extends ApiTypes, CallType extends ContractCallTypes> = ApiType extends 'rxjs'
|
||||
? Observable<ContractCallResult<CallType>>
|
||||
: Promise<ObsInnerType<ContractCallResult<CallType>>>;
|
||||
|
||||
export interface ContractRead<ApiType extends ApiTypes> {
|
||||
send (account: string | AccountId | Uint8Array): ContractCallResultSubscription<ApiType, 'rpc'>;
|
||||
}
|
||||
|
||||
export type ContractCallResult<CallType extends ContractCallTypes> = CallType extends 'rpc'
|
||||
? Observable<ContractCallOutcome>
|
||||
: Observable<SubmittableResult>;
|
||||
|
||||
export interface MapConstructorExec<ApiType extends ApiTypes> {
|
||||
[message: string]: (endowment: BigInt | string | number | BN, gasLimit: BigInt | string | number | BN, ...params: CodecArg[]) => SubmittableExtrinsic<ApiType>;
|
||||
}
|
||||
|
||||
export interface MapMessageExec<ApiType extends ApiTypes> {
|
||||
[message: string]: (value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]) => SubmittableExtrinsic<ApiType>;
|
||||
}
|
||||
|
||||
export interface MapMessageRead<ApiType extends ApiTypes> {
|
||||
[message: string]: (origin: AccountId | string | Uint8Array, value: BigInt | BN | string | number, gasLimit: BigInt | BN | string | number, ...params: CodecArg[]) => ContractCallResultSubscription<ApiType, 'rpc'>;
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { CodeSubmittableResult } from './base/Code';
|
||||
export { BlueprintSubmittableResult } from './base/Blueprint';
|
||||
|
||||
export { default as Abi } from './Abi';
|
||||
|
||||
export * from './rx';
|
||||
export * from './promise';
|
||||
export { Blueprint as BlueprintRx, Code as CodeRx, Contract as ContractRx } from './rx';
|
||||
export { Blueprint as BlueprintPromise, Code as CodePromise, Contract as ContractPromise } from './promise';
|
||||
|
||||
+2
-2
@@ -8,9 +8,9 @@ import { ApiPromise } from '@polkadot/api';
|
||||
import { decorateMethod } from '@polkadot/api/promise';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Blueprint from '../base/Blueprint';
|
||||
import BaseBlueprint from '../base/Blueprint';
|
||||
|
||||
export default class PromiseBlueprint extends Blueprint<'promise'> {
|
||||
export default class Blueprint extends BaseBlueprint<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, decorateMethod);
|
||||
}
|
||||
+2
-2
@@ -6,9 +6,9 @@ import { decorateMethod } from '@polkadot/api/promise';
|
||||
import { AnyJson } from '@polkadot/types/types';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Code from '../base/Code';
|
||||
import BaseCode from '../base/Code';
|
||||
|
||||
export default class PromiseCode extends Code<'promise'> {
|
||||
export default class Code extends BaseCode<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer) {
|
||||
super(api, abi, wasm, decorateMethod);
|
||||
}
|
||||
+2
-2
@@ -8,9 +8,9 @@ import { ApiPromise } from '@polkadot/api';
|
||||
import { decorateMethod } from '@polkadot/api/promise';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Contract from '../base/Contract';
|
||||
import BaseContract from '../base/Contract';
|
||||
|
||||
export default class PromiseContract extends Contract<'promise'> {
|
||||
export default class Contract extends BaseContract<'promise'> {
|
||||
constructor (api: ApiPromise, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethod);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as BlueprintPromise } from './PromiseBlueprint';
|
||||
export { default as CodePromise } from './PromiseCode';
|
||||
export { default as ContractPromise } from './PromiseContract';
|
||||
export { default as Blueprint } from './Blueprint';
|
||||
export { default as Code } from './Code';
|
||||
export { default as Contract } from './Contract';
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
|
||||
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
||||
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
||||
+2
-2
@@ -8,9 +8,9 @@ import { ApiRx } from '@polkadot/api';
|
||||
import { decorateMethod } from '@polkadot/api/rx';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Blueprint from '../base/Blueprint';
|
||||
import BaseBlueprint from '../base/Blueprint';
|
||||
|
||||
export default class RxBlueprint extends Blueprint<'rxjs'> {
|
||||
export default class Blueprint extends BaseBlueprint<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, codeHash: string | Hash) {
|
||||
super(api, abi, codeHash, decorateMethod);
|
||||
}
|
||||
@@ -7,9 +7,9 @@ import { ApiRx } from '@polkadot/api';
|
||||
import { decorateMethod } from '@polkadot/api/rx';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Code from '../base/Code';
|
||||
import BaseCode from '../base/Code';
|
||||
|
||||
export default class RxCode extends Code<'rxjs'> {
|
||||
export default class Code extends BaseCode<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer) {
|
||||
super(api, abi, wasm, decorateMethod);
|
||||
}
|
||||
+2
-2
@@ -8,9 +8,9 @@ import { ApiRx } from '@polkadot/api';
|
||||
import { decorateMethod } from '@polkadot/api/rx';
|
||||
|
||||
import Abi from '../Abi';
|
||||
import Contract from '../base/Contract';
|
||||
import BaseContract from '../base/Contract';
|
||||
|
||||
export default class RxContract extends Contract<'rxjs'> {
|
||||
export default class Contract extends BaseContract<'rxjs'> {
|
||||
constructor (api: ApiRx, abi: AnyJson | Abi, address: string | AccountId) {
|
||||
super(api, abi, address, decorateMethod);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as BlueprintRx } from './RxBlueprint';
|
||||
export { default as CodeRx } from './RxCode';
|
||||
export { default as ContractRx } from './RxContract';
|
||||
export { default as Blueprint } from './Blueprint';
|
||||
export { default as Code } from './Code';
|
||||
export { default as Contract } from './Contract';
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { BlueprintSubmittableResult as BaseBlueprintSubmittableResult, CodeSubmittableResult as BaseCodeSubmittableResult } from '../base';
|
||||
|
||||
export type BlueprintSubmittableResult = BaseBlueprintSubmittableResult<'promise'>;
|
||||
export type CodeSubmittableResult = BaseCodeSubmittableResult<'promise'>;
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ApiTypes } from '@polkadot/api/types';
|
||||
import { ContractExecResult, InkSelector } from '@polkadot/types/interfaces';
|
||||
import { ContractExecResult, ContractSelector } from '@polkadot/types/interfaces';
|
||||
import { Codec, TypeDef } from '@polkadot/types/types';
|
||||
|
||||
import ApiBase from '@polkadot/api/base';
|
||||
@@ -30,7 +30,7 @@ export interface AbiMessage {
|
||||
isMutating?: boolean;
|
||||
isPayable?: boolean;
|
||||
returnType?: TypeDef | null;
|
||||
selector: InkSelector;
|
||||
selector: ContractSelector;
|
||||
}
|
||||
|
||||
export type AbiConstructor = AbiMessage;
|
||||
|
||||
@@ -35,7 +35,7 @@ export function encodeMessage (registry: Registry, message: AbiMessage | AbiCons
|
||||
r[name] = type.displayName || encodeTypeDef(type);
|
||||
|
||||
return r;
|
||||
}, { __selector: 'InkSelector' })
|
||||
}, { __selector: 'ContractSelector' })
|
||||
));
|
||||
|
||||
return compactAddLength(new Clazz(registry, message.args.reduce((r: Record<string, CodecArg>, { name }, index): Record<string, CodecArg> => {
|
||||
|
||||
@@ -488,7 +488,8 @@
|
||||
{
|
||||
"info": 10,
|
||||
"sub": [],
|
||||
"name": "Confirmed"
|
||||
"name": "Confirmed",
|
||||
"type": "()"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
@@ -509,7 +510,8 @@
|
||||
{
|
||||
"info": 10,
|
||||
"sub": [],
|
||||
"name": "Confirmed"
|
||||
"name": "Confirmed",
|
||||
"type": "()"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
@@ -677,4 +679,4 @@
|
||||
},
|
||||
"type": "Option<Vec<u8>>"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
[
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u128"
|
||||
},
|
||||
{
|
||||
"displayName": "Header",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"info": 9,
|
||||
"sub": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "last_vacant"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "len"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "len_entries"
|
||||
}
|
||||
],
|
||||
"type": "{\"last_vacant\":\"u32\",\"len\":\"u32\",\"len_entries\":\"u32\"}"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32"
|
||||
},
|
||||
{
|
||||
"displayName": "Entry",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"params": [
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"sub": [
|
||||
{
|
||||
"displayName": "VacantEntry",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"info": 9,
|
||||
"sub": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "next"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "prev"
|
||||
}
|
||||
],
|
||||
"type": "{\"next\":\"u32\",\"prev\":\"u32\"}",
|
||||
"name": "Vacant"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"AccountId\"}}"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
{
|
||||
"info": 12,
|
||||
"length": 32,
|
||||
"sub": {
|
||||
"info": 6,
|
||||
"type": "u8"
|
||||
},
|
||||
"type": "[u8;32]"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u8"
|
||||
},
|
||||
{
|
||||
"displayName": "VacantEntry",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"info": 9,
|
||||
"sub": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "next"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "prev"
|
||||
}
|
||||
],
|
||||
"type": "{\"next\":\"u32\",\"prev\":\"u32\"}"
|
||||
},
|
||||
{
|
||||
"displayName": "ValueEntry",
|
||||
"namespace": "ink_storage::collections::hashmap",
|
||||
"params": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u128"
|
||||
}
|
||||
],
|
||||
"info": 9,
|
||||
"sub": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u128",
|
||||
"name": "value"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "key_index"
|
||||
}
|
||||
],
|
||||
"type": "{\"value\":\"u128\",\"key_index\":\"u32\"}"
|
||||
},
|
||||
{
|
||||
"displayName": "Entry",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"params": [
|
||||
{
|
||||
"info": 10,
|
||||
"sub": [
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)"
|
||||
}
|
||||
],
|
||||
"info": 3,
|
||||
"sub": [
|
||||
{
|
||||
"displayName": "VacantEntry",
|
||||
"namespace": "ink_storage::collections::stash",
|
||||
"info": 9,
|
||||
"sub": [
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "next"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "u32",
|
||||
"name": "prev"
|
||||
}
|
||||
],
|
||||
"type": "{\"next\":\"u32\",\"prev\":\"u32\"}",
|
||||
"name": "Vacant"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
"sub": [
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)",
|
||||
"name": "Occupied"
|
||||
}
|
||||
],
|
||||
"type": "{\"_enum\":{\"Vacant\":\"VacantEntry\",\"Occupied\":\"(AccountId, AccountId)\"}}"
|
||||
},
|
||||
{
|
||||
"info": 10,
|
||||
"sub": [
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"type": "(AccountId, AccountId)"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "Text"
|
||||
},
|
||||
{
|
||||
"info": 6,
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"displayName": "Option",
|
||||
"params": [
|
||||
{
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
}
|
||||
],
|
||||
"info": 5,
|
||||
"sub": {
|
||||
"displayName": "AccountId",
|
||||
"namespace": "ink_env::types",
|
||||
"info": 6,
|
||||
"type": "AccountId"
|
||||
},
|
||||
"type": "Option<AccountId>"
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { default as withString } from './withString.json';
|
||||
@@ -0,0 +1,777 @@
|
||||
{
|
||||
"metadataVersion": "0.1.0",
|
||||
"source": {
|
||||
"hash": "0xafcd0acf1a747cca1febe5bad81a6c0244a381ceb02635ab1069a1a396adda3f",
|
||||
"language": "ink! 3.0.0-rc1",
|
||||
"compiler": "rustc 1.49.0-nightly"
|
||||
},
|
||||
"contract": {
|
||||
"name": "erc20",
|
||||
"version": "0.1.0",
|
||||
"authors": [
|
||||
"[your_name] <[your_email]>"
|
||||
]
|
||||
},
|
||||
"spec": {
|
||||
"constructors": [
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "initial_supply",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "_name",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"String"
|
||||
],
|
||||
"type": 12
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "_symbol",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"String"
|
||||
],
|
||||
"type": 12
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"name": [
|
||||
"new"
|
||||
],
|
||||
"selector": "0xd183512b"
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"events": [
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "from",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Option"
|
||||
],
|
||||
"type": 14
|
||||
}
|
||||
},
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "to",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Option"
|
||||
],
|
||||
"type": 14
|
||||
}
|
||||
},
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "value",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"name": "Transfer"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "owner",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "spender",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"docs": [],
|
||||
"indexed": true,
|
||||
"name": "value",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"name": "Approval"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"args": [],
|
||||
"docs": [],
|
||||
"mutates": false,
|
||||
"name": [
|
||||
"total_supply"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
},
|
||||
"selector": "0xdcb736b5"
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"docs": [],
|
||||
"mutates": false,
|
||||
"name": [
|
||||
"name"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"String"
|
||||
],
|
||||
"type": 12
|
||||
},
|
||||
"selector": "0xa0a95494"
|
||||
},
|
||||
{
|
||||
"args": [],
|
||||
"docs": [],
|
||||
"mutates": false,
|
||||
"name": [
|
||||
"symbol"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"String"
|
||||
],
|
||||
"type": 12
|
||||
},
|
||||
"selector": "0x57178a4a"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"mutates": false,
|
||||
"name": [
|
||||
"balance_of"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
},
|
||||
"selector": "0x56e929b2"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "owner",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "spender",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"mutates": false,
|
||||
"name": [
|
||||
"allowance"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
},
|
||||
"selector": "0xf3cfff66"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "to",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"mutates": true,
|
||||
"name": [
|
||||
"transfer"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"bool"
|
||||
],
|
||||
"type": 13
|
||||
},
|
||||
"selector": "0xfae3a09d"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "spender",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"mutates": true,
|
||||
"name": [
|
||||
"approve"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"bool"
|
||||
],
|
||||
"type": 13
|
||||
},
|
||||
"selector": "0x03d0e114"
|
||||
},
|
||||
{
|
||||
"args": [
|
||||
{
|
||||
"name": "from",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "to",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"AccountId"
|
||||
],
|
||||
"type": 5
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "value",
|
||||
"type": {
|
||||
"displayName": [
|
||||
"Balance"
|
||||
],
|
||||
"type": 1
|
||||
}
|
||||
}
|
||||
],
|
||||
"docs": [],
|
||||
"mutates": true,
|
||||
"name": [
|
||||
"transfer_from"
|
||||
],
|
||||
"payable": false,
|
||||
"returnType": {
|
||||
"displayName": [
|
||||
"bool"
|
||||
],
|
||||
"type": 13
|
||||
},
|
||||
"selector": "0xfcfb2ccd"
|
||||
}
|
||||
]
|
||||
},
|
||||
"storage": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 1
|
||||
}
|
||||
},
|
||||
"name": "total_supply"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0100000000000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 2
|
||||
}
|
||||
},
|
||||
"name": "header"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0200000000000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 3
|
||||
}
|
||||
},
|
||||
"name": "len"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"array": {
|
||||
"cellsPerElem": 1,
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0200000001000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 4
|
||||
}
|
||||
},
|
||||
"len": 4294967295,
|
||||
"offset": "0x0300000000000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
"name": "elems"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "entries"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "keys"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"hash": {
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0300000001000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 9
|
||||
}
|
||||
},
|
||||
"offset": "0x0200000001000000000000000000000000000000000000000000000000000000",
|
||||
"strategy": {
|
||||
"hasher": "Blake2x256",
|
||||
"postfix": "",
|
||||
"prefix": "0x696e6b20686173686d6170"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": "values"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "balances"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0300000001000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 2
|
||||
}
|
||||
},
|
||||
"name": "header"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"struct": {
|
||||
"fields": [
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0400000001000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 3
|
||||
}
|
||||
},
|
||||
"name": "len"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"array": {
|
||||
"cellsPerElem": 1,
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0400000002000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 10
|
||||
}
|
||||
},
|
||||
"len": 4294967295,
|
||||
"offset": "0x0500000001000000000000000000000000000000000000000000000000000000"
|
||||
}
|
||||
},
|
||||
"name": "elems"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "entries"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "keys"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"hash": {
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0500000002000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 9
|
||||
}
|
||||
},
|
||||
"offset": "0x0400000002000000000000000000000000000000000000000000000000000000",
|
||||
"strategy": {
|
||||
"hasher": "Blake2x256",
|
||||
"postfix": "",
|
||||
"prefix": "0x696e6b20686173686d6170"
|
||||
}
|
||||
}
|
||||
},
|
||||
"name": "values"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"name": "allowances"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0500000002000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 12
|
||||
}
|
||||
},
|
||||
"name": "name"
|
||||
},
|
||||
{
|
||||
"layout": {
|
||||
"cell": {
|
||||
"key": "0x0600000002000000000000000000000000000000000000000000000000000000",
|
||||
"ty": 12
|
||||
}
|
||||
},
|
||||
"name": "symbol"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"types": [
|
||||
{
|
||||
"def": {
|
||||
"primitive": "u128"
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "last_vacant",
|
||||
"type": 3
|
||||
},
|
||||
{
|
||||
"name": "len",
|
||||
"type": 3
|
||||
},
|
||||
{
|
||||
"name": "len_entries",
|
||||
"type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"path": [
|
||||
"ink_storage",
|
||||
"collections",
|
||||
"stash",
|
||||
"Header"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"primitive": "u32"
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"variant": {
|
||||
"variants": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": 8
|
||||
}
|
||||
],
|
||||
"name": "Vacant"
|
||||
},
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": 5
|
||||
}
|
||||
],
|
||||
"name": "Occupied"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
5
|
||||
],
|
||||
"path": [
|
||||
"ink_storage",
|
||||
"collections",
|
||||
"stash",
|
||||
"Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"type": 6
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"path": [
|
||||
"ink_env",
|
||||
"types",
|
||||
"AccountId"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"array": {
|
||||
"len": 32,
|
||||
"type": 7
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"primitive": "u8"
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "next",
|
||||
"type": 3
|
||||
},
|
||||
{
|
||||
"name": "prev",
|
||||
"type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"path": [
|
||||
"ink_storage",
|
||||
"collections",
|
||||
"stash",
|
||||
"VacantEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"composite": {
|
||||
"fields": [
|
||||
{
|
||||
"name": "value",
|
||||
"type": 1
|
||||
},
|
||||
{
|
||||
"name": "key_index",
|
||||
"type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
1
|
||||
],
|
||||
"path": [
|
||||
"ink_storage",
|
||||
"collections",
|
||||
"hashmap",
|
||||
"ValueEntry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"variant": {
|
||||
"variants": [
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": 8
|
||||
}
|
||||
],
|
||||
"name": "Vacant"
|
||||
},
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": 11
|
||||
}
|
||||
],
|
||||
"name": "Occupied"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
11
|
||||
],
|
||||
"path": [
|
||||
"ink_storage",
|
||||
"collections",
|
||||
"stash",
|
||||
"Entry"
|
||||
]
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"tuple": [
|
||||
5,
|
||||
5
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"primitive": "str"
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"primitive": "bool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"def": {
|
||||
"variant": {
|
||||
"variants": [
|
||||
{
|
||||
"name": "None"
|
||||
},
|
||||
{
|
||||
"fields": [
|
||||
{
|
||||
"type": 5
|
||||
}
|
||||
],
|
||||
"name": "Some"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"params": [
|
||||
5
|
||||
],
|
||||
"path": [
|
||||
"Option"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,18 +27,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "2.2.1",
|
||||
"@polkadot/rpc-core": "2.2.1",
|
||||
"@polkadot/rpc-provider": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@polkadot/util-crypto": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/api": "2.3.1",
|
||||
"@polkadot/rpc-core": "2.3.1",
|
||||
"@polkadot/rpc-provider": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"@polkadot/util-crypto": "^3.6.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1"
|
||||
"@polkadot/keyring": "^3.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import createMemo from 'memoizee';
|
||||
import { Observable, Observer, TeardownLogic } from 'rxjs';
|
||||
import { drr } from '@polkadot/rpc-core/rxjs';
|
||||
import normalizer from '@polkadot/rpc-core/normalizer';
|
||||
|
||||
type ObsFn <T> = (...params: any[]) => Observable<T>;
|
||||
|
||||
@@ -24,8 +25,7 @@ export function memo <T> (instanceId: string, inner: ObsFn<T>): ObsFn<T> {
|
||||
}).pipe(drr()),
|
||||
{
|
||||
// Normalize via JSON.stringify, allow e.g. AccountId -> ss58
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
normalizer: (args) => instanceId + JSON.stringify(args)
|
||||
normalizer: normalizer(instanceId)
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
+12
-12
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,21 +26,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api-derive": "2.2.1",
|
||||
"@polkadot/keyring": "^3.5.1",
|
||||
"@polkadot/metadata": "2.2.1",
|
||||
"@polkadot/rpc-core": "2.2.1",
|
||||
"@polkadot/rpc-provider": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/types-known": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@polkadot/util-crypto": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/api-derive": "2.3.1",
|
||||
"@polkadot/keyring": "^3.6.1",
|
||||
"@polkadot/metadata": "2.3.1",
|
||||
"@polkadot/rpc-core": "2.3.1",
|
||||
"@polkadot/rpc-provider": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/types-known": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"@polkadot/util-crypto": "^3.6.1",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.7",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1"
|
||||
"@polkadot/keyring": "^3.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import { Balance, Header, Index } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Balance, Header, Index } from '@polkadot/types/interfaces';
|
||||
import { IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
@@ -71,6 +71,20 @@ async function query (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
|
||||
|
||||
console.log(multiRes);
|
||||
|
||||
// events destructing
|
||||
await api.query.system.events((records): void => {
|
||||
records.forEach(({ event, phase }): void => {
|
||||
if (phase.isApplyExtrinsic) {
|
||||
// Dunno... this should work
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
const [accountId, value]: [AccountId, Balance] = event.data;
|
||||
|
||||
console.log(`${accountId.toString()} has ${value.toHuman()}`);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// at queries
|
||||
const events = await api.query.system.events.at('0x12345');
|
||||
|
||||
|
||||
@@ -1,16 +1,44 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { ExtrinsicStatus, EventRecord } from '@polkadot/types/interfaces';
|
||||
import { DispatchError, DispatchInfo, ExtrinsicStatus, EventRecord } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { SubmittableResultValue } from './types';
|
||||
|
||||
const recordIdentity = (record: EventRecord) => record;
|
||||
|
||||
function filterAndApply <T> (events: EventRecord[], section: string, methods: string[], onFound: (record: EventRecord) => T): T[] {
|
||||
return events
|
||||
.filter(({ event }) => section === event.section && methods.includes(event.method))
|
||||
.map((record) => onFound(record));
|
||||
}
|
||||
|
||||
function extractError (events: EventRecord[] = []): DispatchError | undefined {
|
||||
return filterAndApply(events, 'system', ['ExtrinsicFailed'], ({ event: { data } }) =>
|
||||
data[0] as DispatchError
|
||||
)[0];
|
||||
}
|
||||
|
||||
function extractInfo (events: EventRecord[] = []): DispatchInfo | undefined {
|
||||
return filterAndApply(events, 'system', ['ExtrinsicFailed', 'ExtrinsicSuccess'], ({ event: { data, method } }) =>
|
||||
method === 'ExtrinsicSuccess'
|
||||
? data[0] as DispatchInfo
|
||||
: data[1] as DispatchInfo
|
||||
)[0];
|
||||
}
|
||||
|
||||
export default class SubmittableResult implements ISubmittableResult {
|
||||
public readonly dispatchError?: DispatchError;
|
||||
|
||||
public readonly dispatchInfo?: DispatchInfo;
|
||||
|
||||
public readonly events: EventRecord[];
|
||||
|
||||
public readonly status: ExtrinsicStatus;
|
||||
|
||||
constructor ({ events, status }: SubmittableResultValue) {
|
||||
constructor ({ dispatchError, dispatchInfo, events, status }: SubmittableResultValue) {
|
||||
this.dispatchError = dispatchError || extractError(events);
|
||||
this.dispatchInfo = dispatchInfo || extractInfo(events);
|
||||
this.events = events || [];
|
||||
this.status = status;
|
||||
}
|
||||
@@ -39,18 +67,14 @@ export default class SubmittableResult implements ISubmittableResult {
|
||||
* @description Filters EventRecords for the specified method & section (there could be multiple)
|
||||
*/
|
||||
public filterRecords (section: string, method: string): EventRecord[] {
|
||||
return this.events.filter(({ event }): boolean =>
|
||||
event.section === section && event.method === method
|
||||
);
|
||||
return filterAndApply(this.events, section, [method], recordIdentity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Finds an EventRecord for the specified method & section
|
||||
*/
|
||||
public findRecord (section: string, method: string): EventRecord | undefined {
|
||||
return this.events.find(({ event }): boolean =>
|
||||
event.section === section && event.method === method
|
||||
);
|
||||
return this.filterRecords(section, method)[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,6 +82,8 @@ export default class SubmittableResult implements ISubmittableResult {
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return {
|
||||
dispatchError: this.dispatchError?.toHuman(),
|
||||
dispatchInfo: this.dispatchInfo?.toHuman(),
|
||||
events: this.events.map((event) => event.toHuman(isExtended)),
|
||||
status: this.status.toHuman(isExtended)
|
||||
};
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { AccountId, Address, Extrinsic, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { AccountId, Address, DispatchError, DispatchInfo, Extrinsic, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, Callback, Codec, IExtrinsicEra, IKeyringPair, Signer, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { ApiTypes } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export interface SubmittableResultValue {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
events?: EventRecord[];
|
||||
status: ExtrinsicStatus;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Helpers to extract information from runtime metadata",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
@@ -26,14 +26,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/types-known": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@polkadot/util-crypto": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/types-known": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"@polkadot/util-crypto": "^3.6.1",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1"
|
||||
"@polkadot/keyring": "^3.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-core",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,15 +26,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "2.2.1",
|
||||
"@polkadot/rpc-provider": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/metadata": "2.3.1",
|
||||
"@polkadot/rpc-provider": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1"
|
||||
"@polkadot/keyring": "^3.6.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
|
||||
import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import normalizer from './normalizer';
|
||||
import { drr, refCountDelay } from './rxjs';
|
||||
|
||||
interface StorageChangeSetJSON {
|
||||
@@ -267,7 +268,7 @@ export default class Rpc implements RpcInterface {
|
||||
|
||||
memoized = memoizee(this._createMethodWithRaw(creator), {
|
||||
length: false,
|
||||
normalizer: (args) => this.#instanceId + JSON.stringify(args)
|
||||
normalizer: normalizer(this.#instanceId)
|
||||
});
|
||||
|
||||
return memoized;
|
||||
@@ -355,8 +356,7 @@ export default class Rpc implements RpcInterface {
|
||||
// Normalize args so that different args that should be cached
|
||||
// together are cached together.
|
||||
// E.g.: `query.my.method('abc') === query.my.method(createType('AccountId', 'abc'));`
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
normalizer: (args) => this.#instanceId + JSON.stringify(args)
|
||||
normalizer: normalizer(this.#instanceId)
|
||||
});
|
||||
|
||||
return memoized;
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import normalizer from './normalizer';
|
||||
|
||||
describe('normalizer', (): void => {
|
||||
it('works when BigInt is in the data (object)', (): void => {
|
||||
expect(
|
||||
normalizer('instance')({ a: 'bar', b: 1234567890987654321n, c: 123 })
|
||||
).toEqual('instance{"a":"bar","b":"1234567890987654321","c":123}');
|
||||
});
|
||||
|
||||
it('works when BigInt is in the data (array)', (): void => {
|
||||
expect(
|
||||
normalizer('instance')(['bar', 1234567890987654321n, 123])
|
||||
).toEqual('instance["bar","1234567890987654321",123]');
|
||||
});
|
||||
|
||||
it('works when BigInt is in the data (single)', (): void => {
|
||||
expect(
|
||||
normalizer('instance')(1234567890987654321n)
|
||||
).toEqual('instance"1234567890987654321"');
|
||||
});
|
||||
|
||||
it('works when BigInt is in the data (nested)', (): void => {
|
||||
expect(
|
||||
normalizer('instance')({ a: 'bar', b: { foo: 1234567890987654321n }, c: 123 })
|
||||
).toEqual('instance{"a":"bar","b":{"foo":"1234567890987654321"},"c":123}');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { isBigInt } from '@polkadot/util';
|
||||
|
||||
export default function normalizer (instanceId: string): (value: unknown) => string {
|
||||
return (value: unknown) =>
|
||||
instanceId + JSON.stringify(value, (_, value: unknown) =>
|
||||
isBigInt(value)
|
||||
? value.toString()
|
||||
: value
|
||||
);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Transport providers for the API",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,18 +26,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@polkadot/util-crypto": "^3.5.1",
|
||||
"@polkadot/x-fetch": "^0.3.2",
|
||||
"@polkadot/x-ws": "^0.3.2",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/metadata": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"@polkadot/util-crypto": "^3.6.1",
|
||||
"@polkadot/x-fetch": "^0.3.3",
|
||||
"@polkadot/x-ws": "^0.3.3",
|
||||
"bn.js": "^5.1.3",
|
||||
"eventemitter3": "^4.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1",
|
||||
"@polkadot/keyring": "^3.6.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.4"
|
||||
}
|
||||
|
||||
@@ -150,7 +150,12 @@ export default class WsProvider implements ProviderInterface {
|
||||
? new WS(this.#endpoints[this.#endpointIndex])
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - WS may be an instance of w3cwebsocket, which supports headers
|
||||
: new WS(this.#endpoints[this.#endpointIndex], undefined, undefined, this.#headers);
|
||||
: new WS(this.#endpoints[this.#endpointIndex], undefined, undefined, this.#headers, undefined, {
|
||||
// default: true
|
||||
fragmentOutgoingMessages: true,
|
||||
// default: 16K
|
||||
fragmentationThreshold: 256 * 1024
|
||||
});
|
||||
|
||||
this.#websocket.onclose = this.#onSocketClose;
|
||||
this.#websocket.onerror = this.#onSocketError;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -33,20 +33,20 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.11.6",
|
||||
"@babel/register": "^7.11.5",
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/api": "2.2.1",
|
||||
"@polkadot/metadata": "2.2.1",
|
||||
"@polkadot/rpc-provider": "2.2.1",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@babel/core": "^7.12.3",
|
||||
"@babel/register": "^7.12.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/api": "2.3.1",
|
||||
"@polkadot/metadata": "2.3.1",
|
||||
"@polkadot/rpc-provider": "2.3.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"handlebars": "^4.7.6",
|
||||
"websocket": "^1.0.32",
|
||||
"yargs": "^16.0.3"
|
||||
"yargs": "^16.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/websocket": "^1.0.1",
|
||||
"@types/yargs": "^15.0.7"
|
||||
"@types/yargs": "^15.0.9"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types-known",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,9 +26,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/types": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/types": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"bn.js": "^5.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -13,7 +13,7 @@ const upgrades: ChainUpgradesRaw = {
|
||||
[1472960, 1052], [1475648, 1053], [1491596, 1054], [1574408, 1055], [2064961, 1058],
|
||||
[2201991, 1062], [2671528, 2005], [2704202, 2007], [2728002, 2008], [2832534, 2011],
|
||||
[2962294, 2012], [3240000, 2013], [3274408, 2015], [3323565, 2019], [3534175, 2022],
|
||||
[3860281, 2023], [4143129, 2024]
|
||||
[3860281, 2023], [4143129, 2024], [4401242, 2025]
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ const upgrades: ChainUpgradesRaw = {
|
||||
[0, 0], [29231, 1], [188836, 5], [199405, 6], [214264, 7],
|
||||
[244358, 8], [303079, 9], [314201, 10], [342400, 11], [443963, 12],
|
||||
[528470, 13], [687751, 14], [746085, 15], [787923, 16], [799302, 17],
|
||||
[1205128, 18], [1603423, 23], [1733218, 24]
|
||||
[1205128, 18], [1603423, 23], [1733218, 24], [2005673, 25]
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,8 @@ const upgrades: ChainUpgradesRaw = {
|
||||
[214356, 4], [392764, 7], [409740, 8], [809976, 20], [877581, 24],
|
||||
[879238, 25], [889472, 26], [902937, 27], [932751, 28], [991142, 29],
|
||||
[1030162, 31], [1119657, 32], [1199282, 33], [1342534, 34], [1392263, 35],
|
||||
[1431703, 36], [1433369, 37], [1490972, 41], [2087397, 43], [2316688, 44]
|
||||
[1431703, 36], [1433369, 37], [1490972, 41], [2087397, 43], [2316688, 44],
|
||||
[2549864, 45]
|
||||
]
|
||||
};
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ const warnings: Record<string, string[]> = {
|
||||
'You are using the node-template, depending on your config and age of the template, you may',
|
||||
'have some unexpected results without applying the correct config for your node type:',
|
||||
'',
|
||||
'- If you have trouble sending txs, apply https://polkadot.js.org/api/start/FAQ.html#i-cannot-send-transactions-from-my-node-template-based-chain',
|
||||
'- If you have trouble parsing events, apply https://polkadot.js.org/api/start/FAQ.html#using-a-non-current-master-node-i-have-issues-parsing-events',
|
||||
'- If you have trouble sending txs, apply https://polkadot.js.org/docs/api/FAQ#i-cannot-send-transactions-from-my-node-template-based-chain',
|
||||
'- If you have trouble parsing events, apply https://polkadot.js.org/docs/api/FAQ#using-a-non-current-master-node-i-have-issues-parsing-events',
|
||||
''
|
||||
]
|
||||
};
|
||||
|
||||
@@ -1,66 +1,3 @@
|
||||
# @polkadot/types
|
||||
|
||||
Implementation of the types and their (de-)serialisation via SCALE codec.<br>
|
||||
On the Rust side, the codec types and primitive types are implemented via the [parity-codec](https://github.com/paritytech/parity-codec).
|
||||
|
||||
|
||||
## Codec types
|
||||
|
||||
These are the base types of the codec. They are typically not used directly, but rather inherited from to create specific types. They are the building blocks for declaring custom types:
|
||||
|
||||
| **Types** | |
|
||||
| --- | --- |
|
||||
| [[Compact]] | A compact length-encoding codec wrapper. Mostly used by other types to add length-prefixed encoding |
|
||||
| [[Enum]] | A codec wrapper for an enum. Enums are encoded as a single byte, where the byte is a zero-indexed value |
|
||||
| [[Int]] | A generic signed integer codec |
|
||||
| [[Option]] | An Option is an optional field. The first byte indicates that there is a value to follow |
|
||||
| [[Set]] | An Set is an array of string values, represented an an encoded type by a bitwise representation of the values |
|
||||
| [[Struct]] | A Struct defines an Object with key-value pairs - where the values are Codec values. |
|
||||
| [[Tuple]] | A Tuple defines an anonymous fixed-length array, where each element has its own type |
|
||||
| [[Raw]] | A basic wrapper around Uint8Array. It will consume the full Uint8Array as passed to it |
|
||||
| [[U8aFixed]] | A U8a that manages a a sequence of bytes up to the specified bitLength |
|
||||
| [[UInt]] | A generic unsigned integer codec. It handles the encoding and decoding of Little Endian encoded numbers in Substrate |
|
||||
| [[Vec]] | This manages codec arrays. Internally it keeps track of the length (as decoded) |
|
||||
| [[VecAny]] | This manages codec arrays, assuming that the inputs are already of type Codec |
|
||||
|
||||
|
||||
## Primitive types
|
||||
|
||||
These primitive types are available:
|
||||
|
||||
| **Types** | |
|
||||
| --- | --- |
|
||||
| [[AccountId]] | A wrapper around an AccountId/PublicKey representation |
|
||||
| [[AccountIndex]] | A wrapper around an AccountIndex, which is a shortened, variable-length encoding for an Account |
|
||||
| [[Address]] | A wrapper around an AccountId and/or AccountIndex that is encoded with a prefix |
|
||||
| [[bool]] | Representation for a boolean value in the system |
|
||||
| [[Bytes]] | A Bytes wrapper for `Vec<u8>` |
|
||||
| [[Call]] | Extrinsic function descriptor, as defined in [the extrinsic format for a node](https://github.com/paritytech/wiki/blob/master/Extrinsic.md#the-extrinsic-format-for-node) |
|
||||
| [[Event]] | Wrapper for the actual data that forms part of an [[Event]] |
|
||||
| [[EventRecord]] | A record for an [[Event]] (as specified by [[Metadata]]) with the specific [[Phase]] of application |
|
||||
| [[Extrinsic]] | Representation of an Extrinsic in the system |
|
||||
| [[ExtrinsicEra]] | The era for an extrinsic, indicating either a mortal or immortal extrinsic |
|
||||
| [[ExtrinsicPayload]] | A signing payload for an [[Extrinsic]]. For the final encoding, it is variable length based on the contents included |
|
||||
| [[H160]] | Hash containing 160 bits (20 bytes), typically used in blocks, extrinsics and as a sane default |
|
||||
| [[H256]] | Hash containing 256 bits (32 bytes), typically used in blocks, extrinsics and as a sane default |
|
||||
| [[H512]] | Hash containing 512 bits (64 bytes), typically used for signatures |
|
||||
| [[Hash]] | The default hash that is used accross the system. It is just a thin wrapper around [[H256]]
|
||||
| [[i8]] | An 8-bit signed integer |
|
||||
| [[i16]] | A 16-bit signed integer |
|
||||
| [[i32]] | A 32-bit signed integer |
|
||||
| [[i64]] | A 64-bit signed integer |
|
||||
| [[i128]] | A 128-bit signed integer |
|
||||
| [[i256]] | A 256-bit signed integer |
|
||||
| [[Moment]] | A wrapper around seconds/timestamps. Internally the representation only has second precicion (aligning with Rust) |
|
||||
| [[Null]] | Implements a type that does not contain anything (apart from `null`) |
|
||||
| [[Signature]] | The default signature that is used accross the system |
|
||||
| [[StorageData]] | Data retrieved via Storage queries and data for key-value pairs |
|
||||
| [[StorageKey]] | A representation of a storage key (typically hashed) in the system |
|
||||
| [[Text]] | This is a string wrapper, along with the length. |
|
||||
| [[Type]] | This is a extended version of String, specifically to handle types |
|
||||
| [[u8]] | An 8-bit unsigned integer |
|
||||
| [[u16]] | A 16-bit unsigned integer |
|
||||
| [[u32]] | A 32-bit unsigned integer |
|
||||
| [[u64]] | A 64-bit unsigned integer |
|
||||
| [[u128]] | A 128-bit unsigned integer |
|
||||
| [[u256]] | A 256-bit unsigned integer |
|
||||
Implementation of the types and their (de-)serialisation via SCALE codec. On the Rust side, the codec types and primitive types are implemented via the [parity-codec](https://github.com/paritytech/parity-codec).
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "2.2.1",
|
||||
"version": "2.3.1",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,17 +26,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.11.2",
|
||||
"@polkadot/metadata": "2.2.1",
|
||||
"@polkadot/util": "^3.5.1",
|
||||
"@polkadot/util-crypto": "^3.5.1",
|
||||
"@babel/runtime": "^7.12.1",
|
||||
"@polkadot/metadata": "2.3.1",
|
||||
"@polkadot/util": "^3.6.1",
|
||||
"@polkadot/util-crypto": "^3.6.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.3",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^3.5.1",
|
||||
"@polkadot/keyring": "^3.6.1",
|
||||
"@types/memoizee": "^0.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import { EthereumAddress, StatementKind } from '@polkadot/types/interfaces/claim
|
||||
import { CollectiveOrigin, MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
|
||||
import { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultSuccess, ContractExecResultSuccessTo255, ContractExecResultTo255, ContractInfo, ContractStorageKey, Gas, HostFnWeights, InstructionWeights, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, ScheduleTo212, ScheduleTo258, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import { InkConstructorSpec, InkContractSpec, InkCryptoHasher, InkDiscriminant, InkDisplayName, InkEventParamSpec, InkEventSpec, InkLayoutArray, InkLayoutCell, InkLayoutEnum, InkLayoutHash, InkLayoutHashingStrategy, InkLayoutKey, InkLayoutStruct, InkLayoutStructField, InkMessageParamSpec, InkMessageSpec, InkProject, InkProjectContract, InkProjectSource, InkSelector, InkStorageLayout, InkTypeSpec, MtField, MtLookupTypeId, MtPath, MtType, MtTypeDef, MtTypeDefArray, MtTypeDefComposite, MtTypeDefPrimitive, MtTypeDefSequence, MtTypeDefTuple, MtTypeDefVariant, MtVariant } from '@polkadot/types/interfaces/contractsAbi';
|
||||
import { ContractConstructorSpec, ContractContractSpec, ContractCryptoHasher, ContractDiscriminant, ContractDisplayName, ContractEventParamSpec, ContractEventSpec, ContractLayoutArray, ContractLayoutCell, ContractLayoutEnum, ContractLayoutHash, ContractLayoutHashingStrategy, ContractLayoutKey, ContractLayoutStruct, ContractLayoutStructField, ContractMessageParamSpec, ContractMessageSpec, ContractProject, ContractProjectContract, ContractProjectSource, ContractSelector, ContractStorageLayout, ContractTypeSpec } from '@polkadot/types/interfaces/contractsAbi';
|
||||
import { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
|
||||
import { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections';
|
||||
import { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
|
||||
@@ -37,6 +37,7 @@ import { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purch
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, CallHash, CallHashOf, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, ExtrinsicsWeight, Fixed128, Fixed64, FixedI128, FixedI64, FixedU128, FixedU64, GenericAddress, H160, H256, H512, Hash, Header, I32F32, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, OpaqueCall, Origin, OriginCaller, PalletVersion, PalletsOrigin, Pays, PerU16, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, TransactionPriority, U32F32, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { SiField, SiLookupTypeId, SiPath, SiType, SiTypeDef, SiTypeDefArray, SiTypeDefComposite, SiTypeDefPrimitive, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '@polkadot/types/interfaces/scaleInfo';
|
||||
import { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, ScheduledTo254, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import { FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, ValidatorCount } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
@@ -529,113 +530,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
TrieId: TrieId;
|
||||
'Option<TrieId>': Option<TrieId>;
|
||||
'Vec<TrieId>': Vec<TrieId>;
|
||||
InkCryptoHasher: InkCryptoHasher;
|
||||
'Option<InkCryptoHasher>': Option<InkCryptoHasher>;
|
||||
'Vec<InkCryptoHasher>': Vec<InkCryptoHasher>;
|
||||
InkDiscriminant: InkDiscriminant;
|
||||
'Compact<InkDiscriminant>': Compact<InkDiscriminant>;
|
||||
'Option<InkDiscriminant>': Option<InkDiscriminant>;
|
||||
'Vec<InkDiscriminant>': Vec<InkDiscriminant>;
|
||||
InkLayoutArray: InkLayoutArray;
|
||||
'Option<InkLayoutArray>': Option<InkLayoutArray>;
|
||||
'Vec<InkLayoutArray>': Vec<InkLayoutArray>;
|
||||
InkLayoutCell: InkLayoutCell;
|
||||
'Option<InkLayoutCell>': Option<InkLayoutCell>;
|
||||
'Vec<InkLayoutCell>': Vec<InkLayoutCell>;
|
||||
InkLayoutEnum: InkLayoutEnum;
|
||||
'Option<InkLayoutEnum>': Option<InkLayoutEnum>;
|
||||
'Vec<InkLayoutEnum>': Vec<InkLayoutEnum>;
|
||||
InkLayoutHash: InkLayoutHash;
|
||||
'Option<InkLayoutHash>': Option<InkLayoutHash>;
|
||||
'Vec<InkLayoutHash>': Vec<InkLayoutHash>;
|
||||
InkLayoutHashingStrategy: InkLayoutHashingStrategy;
|
||||
'Option<InkLayoutHashingStrategy>': Option<InkLayoutHashingStrategy>;
|
||||
'Vec<InkLayoutHashingStrategy>': Vec<InkLayoutHashingStrategy>;
|
||||
InkLayoutKey: InkLayoutKey;
|
||||
'Option<InkLayoutKey>': Option<InkLayoutKey>;
|
||||
'Vec<InkLayoutKey>': Vec<InkLayoutKey>;
|
||||
InkLayoutStruct: InkLayoutStruct;
|
||||
'Option<InkLayoutStruct>': Option<InkLayoutStruct>;
|
||||
'Vec<InkLayoutStruct>': Vec<InkLayoutStruct>;
|
||||
InkLayoutStructField: InkLayoutStructField;
|
||||
'Option<InkLayoutStructField>': Option<InkLayoutStructField>;
|
||||
'Vec<InkLayoutStructField>': Vec<InkLayoutStructField>;
|
||||
InkStorageLayout: InkStorageLayout;
|
||||
'Option<InkStorageLayout>': Option<InkStorageLayout>;
|
||||
'Vec<InkStorageLayout>': Vec<InkStorageLayout>;
|
||||
MtField: MtField;
|
||||
'Option<MtField>': Option<MtField>;
|
||||
'Vec<MtField>': Vec<MtField>;
|
||||
MtLookupTypeId: MtLookupTypeId;
|
||||
'Compact<MtLookupTypeId>': Compact<MtLookupTypeId>;
|
||||
'Option<MtLookupTypeId>': Option<MtLookupTypeId>;
|
||||
'Vec<MtLookupTypeId>': Vec<MtLookupTypeId>;
|
||||
MtPath: MtPath;
|
||||
'Option<MtPath>': Option<MtPath>;
|
||||
'Vec<MtPath>': Vec<MtPath>;
|
||||
MtType: MtType;
|
||||
'Option<MtType>': Option<MtType>;
|
||||
'Vec<MtType>': Vec<MtType>;
|
||||
MtTypeDef: MtTypeDef;
|
||||
'Option<MtTypeDef>': Option<MtTypeDef>;
|
||||
'Vec<MtTypeDef>': Vec<MtTypeDef>;
|
||||
MtTypeDefArray: MtTypeDefArray;
|
||||
'Option<MtTypeDefArray>': Option<MtTypeDefArray>;
|
||||
'Vec<MtTypeDefArray>': Vec<MtTypeDefArray>;
|
||||
MtTypeDefComposite: MtTypeDefComposite;
|
||||
'Option<MtTypeDefComposite>': Option<MtTypeDefComposite>;
|
||||
'Vec<MtTypeDefComposite>': Vec<MtTypeDefComposite>;
|
||||
MtTypeDefVariant: MtTypeDefVariant;
|
||||
'Option<MtTypeDefVariant>': Option<MtTypeDefVariant>;
|
||||
'Vec<MtTypeDefVariant>': Vec<MtTypeDefVariant>;
|
||||
MtTypeDefPrimitive: MtTypeDefPrimitive;
|
||||
'Option<MtTypeDefPrimitive>': Option<MtTypeDefPrimitive>;
|
||||
'Vec<MtTypeDefPrimitive>': Vec<MtTypeDefPrimitive>;
|
||||
MtTypeDefSequence: MtTypeDefSequence;
|
||||
'Option<MtTypeDefSequence>': Option<MtTypeDefSequence>;
|
||||
'Vec<MtTypeDefSequence>': Vec<MtTypeDefSequence>;
|
||||
MtTypeDefTuple: MtTypeDefTuple;
|
||||
'Option<MtTypeDefTuple>': Option<MtTypeDefTuple>;
|
||||
'Vec<MtTypeDefTuple>': Vec<MtTypeDefTuple>;
|
||||
MtVariant: MtVariant;
|
||||
'Option<MtVariant>': Option<MtVariant>;
|
||||
'Vec<MtVariant>': Vec<MtVariant>;
|
||||
InkConstructorSpec: InkConstructorSpec;
|
||||
'Option<InkConstructorSpec>': Option<InkConstructorSpec>;
|
||||
'Vec<InkConstructorSpec>': Vec<InkConstructorSpec>;
|
||||
InkContractSpec: InkContractSpec;
|
||||
'Option<InkContractSpec>': Option<InkContractSpec>;
|
||||
'Vec<InkContractSpec>': Vec<InkContractSpec>;
|
||||
InkDisplayName: InkDisplayName;
|
||||
'Option<InkDisplayName>': Option<InkDisplayName>;
|
||||
'Vec<InkDisplayName>': Vec<InkDisplayName>;
|
||||
InkEventParamSpec: InkEventParamSpec;
|
||||
'Option<InkEventParamSpec>': Option<InkEventParamSpec>;
|
||||
'Vec<InkEventParamSpec>': Vec<InkEventParamSpec>;
|
||||
InkEventSpec: InkEventSpec;
|
||||
'Option<InkEventSpec>': Option<InkEventSpec>;
|
||||
'Vec<InkEventSpec>': Vec<InkEventSpec>;
|
||||
InkMessageParamSpec: InkMessageParamSpec;
|
||||
'Option<InkMessageParamSpec>': Option<InkMessageParamSpec>;
|
||||
'Vec<InkMessageParamSpec>': Vec<InkMessageParamSpec>;
|
||||
InkMessageSpec: InkMessageSpec;
|
||||
'Option<InkMessageSpec>': Option<InkMessageSpec>;
|
||||
'Vec<InkMessageSpec>': Vec<InkMessageSpec>;
|
||||
InkSelector: InkSelector;
|
||||
'Option<InkSelector>': Option<InkSelector>;
|
||||
'Vec<InkSelector>': Vec<InkSelector>;
|
||||
InkTypeSpec: InkTypeSpec;
|
||||
'Option<InkTypeSpec>': Option<InkTypeSpec>;
|
||||
'Vec<InkTypeSpec>': Vec<InkTypeSpec>;
|
||||
InkProject: InkProject;
|
||||
'Option<InkProject>': Option<InkProject>;
|
||||
'Vec<InkProject>': Vec<InkProject>;
|
||||
InkProjectContract: InkProjectContract;
|
||||
'Option<InkProjectContract>': Option<InkProjectContract>;
|
||||
'Vec<InkProjectContract>': Vec<InkProjectContract>;
|
||||
InkProjectSource: InkProjectSource;
|
||||
'Option<InkProjectSource>': Option<InkProjectSource>;
|
||||
'Vec<InkProjectSource>': Vec<InkProjectSource>;
|
||||
AccountVote: AccountVote;
|
||||
'Option<AccountVote>': Option<AccountVote>;
|
||||
'Vec<AccountVote>': Vec<AccountVote>;
|
||||
@@ -1503,6 +1397,113 @@ declare module '@polkadot/types/types/registry' {
|
||||
AccountValidity: AccountValidity;
|
||||
'Option<AccountValidity>': Option<AccountValidity>;
|
||||
'Vec<AccountValidity>': Vec<AccountValidity>;
|
||||
ContractCryptoHasher: ContractCryptoHasher;
|
||||
'Option<ContractCryptoHasher>': Option<ContractCryptoHasher>;
|
||||
'Vec<ContractCryptoHasher>': Vec<ContractCryptoHasher>;
|
||||
ContractDiscriminant: ContractDiscriminant;
|
||||
'Compact<ContractDiscriminant>': Compact<ContractDiscriminant>;
|
||||
'Option<ContractDiscriminant>': Option<ContractDiscriminant>;
|
||||
'Vec<ContractDiscriminant>': Vec<ContractDiscriminant>;
|
||||
ContractLayoutArray: ContractLayoutArray;
|
||||
'Option<ContractLayoutArray>': Option<ContractLayoutArray>;
|
||||
'Vec<ContractLayoutArray>': Vec<ContractLayoutArray>;
|
||||
ContractLayoutCell: ContractLayoutCell;
|
||||
'Option<ContractLayoutCell>': Option<ContractLayoutCell>;
|
||||
'Vec<ContractLayoutCell>': Vec<ContractLayoutCell>;
|
||||
ContractLayoutEnum: ContractLayoutEnum;
|
||||
'Option<ContractLayoutEnum>': Option<ContractLayoutEnum>;
|
||||
'Vec<ContractLayoutEnum>': Vec<ContractLayoutEnum>;
|
||||
ContractLayoutHash: ContractLayoutHash;
|
||||
'Option<ContractLayoutHash>': Option<ContractLayoutHash>;
|
||||
'Vec<ContractLayoutHash>': Vec<ContractLayoutHash>;
|
||||
ContractLayoutHashingStrategy: ContractLayoutHashingStrategy;
|
||||
'Option<ContractLayoutHashingStrategy>': Option<ContractLayoutHashingStrategy>;
|
||||
'Vec<ContractLayoutHashingStrategy>': Vec<ContractLayoutHashingStrategy>;
|
||||
ContractLayoutKey: ContractLayoutKey;
|
||||
'Option<ContractLayoutKey>': Option<ContractLayoutKey>;
|
||||
'Vec<ContractLayoutKey>': Vec<ContractLayoutKey>;
|
||||
ContractLayoutStruct: ContractLayoutStruct;
|
||||
'Option<ContractLayoutStruct>': Option<ContractLayoutStruct>;
|
||||
'Vec<ContractLayoutStruct>': Vec<ContractLayoutStruct>;
|
||||
ContractLayoutStructField: ContractLayoutStructField;
|
||||
'Option<ContractLayoutStructField>': Option<ContractLayoutStructField>;
|
||||
'Vec<ContractLayoutStructField>': Vec<ContractLayoutStructField>;
|
||||
ContractStorageLayout: ContractStorageLayout;
|
||||
'Option<ContractStorageLayout>': Option<ContractStorageLayout>;
|
||||
'Vec<ContractStorageLayout>': Vec<ContractStorageLayout>;
|
||||
ContractConstructorSpec: ContractConstructorSpec;
|
||||
'Option<ContractConstructorSpec>': Option<ContractConstructorSpec>;
|
||||
'Vec<ContractConstructorSpec>': Vec<ContractConstructorSpec>;
|
||||
ContractContractSpec: ContractContractSpec;
|
||||
'Option<ContractContractSpec>': Option<ContractContractSpec>;
|
||||
'Vec<ContractContractSpec>': Vec<ContractContractSpec>;
|
||||
ContractDisplayName: ContractDisplayName;
|
||||
'Option<ContractDisplayName>': Option<ContractDisplayName>;
|
||||
'Vec<ContractDisplayName>': Vec<ContractDisplayName>;
|
||||
ContractEventParamSpec: ContractEventParamSpec;
|
||||
'Option<ContractEventParamSpec>': Option<ContractEventParamSpec>;
|
||||
'Vec<ContractEventParamSpec>': Vec<ContractEventParamSpec>;
|
||||
ContractEventSpec: ContractEventSpec;
|
||||
'Option<ContractEventSpec>': Option<ContractEventSpec>;
|
||||
'Vec<ContractEventSpec>': Vec<ContractEventSpec>;
|
||||
ContractMessageParamSpec: ContractMessageParamSpec;
|
||||
'Option<ContractMessageParamSpec>': Option<ContractMessageParamSpec>;
|
||||
'Vec<ContractMessageParamSpec>': Vec<ContractMessageParamSpec>;
|
||||
ContractMessageSpec: ContractMessageSpec;
|
||||
'Option<ContractMessageSpec>': Option<ContractMessageSpec>;
|
||||
'Vec<ContractMessageSpec>': Vec<ContractMessageSpec>;
|
||||
ContractSelector: ContractSelector;
|
||||
'Option<ContractSelector>': Option<ContractSelector>;
|
||||
'Vec<ContractSelector>': Vec<ContractSelector>;
|
||||
ContractTypeSpec: ContractTypeSpec;
|
||||
'Option<ContractTypeSpec>': Option<ContractTypeSpec>;
|
||||
'Vec<ContractTypeSpec>': Vec<ContractTypeSpec>;
|
||||
ContractProject: ContractProject;
|
||||
'Option<ContractProject>': Option<ContractProject>;
|
||||
'Vec<ContractProject>': Vec<ContractProject>;
|
||||
ContractProjectContract: ContractProjectContract;
|
||||
'Option<ContractProjectContract>': Option<ContractProjectContract>;
|
||||
'Vec<ContractProjectContract>': Vec<ContractProjectContract>;
|
||||
ContractProjectSource: ContractProjectSource;
|
||||
'Option<ContractProjectSource>': Option<ContractProjectSource>;
|
||||
'Vec<ContractProjectSource>': Vec<ContractProjectSource>;
|
||||
SiField: SiField;
|
||||
'Option<SiField>': Option<SiField>;
|
||||
'Vec<SiField>': Vec<SiField>;
|
||||
SiLookupTypeId: SiLookupTypeId;
|
||||
'Compact<SiLookupTypeId>': Compact<SiLookupTypeId>;
|
||||
'Option<SiLookupTypeId>': Option<SiLookupTypeId>;
|
||||
'Vec<SiLookupTypeId>': Vec<SiLookupTypeId>;
|
||||
SiPath: SiPath;
|
||||
'Option<SiPath>': Option<SiPath>;
|
||||
'Vec<SiPath>': Vec<SiPath>;
|
||||
SiType: SiType;
|
||||
'Option<SiType>': Option<SiType>;
|
||||
'Vec<SiType>': Vec<SiType>;
|
||||
SiTypeDef: SiTypeDef;
|
||||
'Option<SiTypeDef>': Option<SiTypeDef>;
|
||||
'Vec<SiTypeDef>': Vec<SiTypeDef>;
|
||||
SiTypeDefArray: SiTypeDefArray;
|
||||
'Option<SiTypeDefArray>': Option<SiTypeDefArray>;
|
||||
'Vec<SiTypeDefArray>': Vec<SiTypeDefArray>;
|
||||
SiTypeDefComposite: SiTypeDefComposite;
|
||||
'Option<SiTypeDefComposite>': Option<SiTypeDefComposite>;
|
||||
'Vec<SiTypeDefComposite>': Vec<SiTypeDefComposite>;
|
||||
SiTypeDefVariant: SiTypeDefVariant;
|
||||
'Option<SiTypeDefVariant>': Option<SiTypeDefVariant>;
|
||||
'Vec<SiTypeDefVariant>': Vec<SiTypeDefVariant>;
|
||||
SiTypeDefPrimitive: SiTypeDefPrimitive;
|
||||
'Option<SiTypeDefPrimitive>': Option<SiTypeDefPrimitive>;
|
||||
'Vec<SiTypeDefPrimitive>': Vec<SiTypeDefPrimitive>;
|
||||
SiTypeDefSequence: SiTypeDefSequence;
|
||||
'Option<SiTypeDefSequence>': Option<SiTypeDefSequence>;
|
||||
'Vec<SiTypeDefSequence>': Vec<SiTypeDefSequence>;
|
||||
SiTypeDefTuple: SiTypeDefTuple;
|
||||
'Option<SiTypeDefTuple>': Option<SiTypeDefTuple>;
|
||||
'Vec<SiTypeDefTuple>': Vec<SiTypeDefTuple>;
|
||||
SiVariant: SiVariant;
|
||||
'Option<SiVariant>': Option<SiVariant>;
|
||||
'Vec<SiVariant>': Vec<SiVariant>;
|
||||
EthereumAccountId: EthereumAccountId;
|
||||
'Option<EthereumAccountId>': Option<EthereumAccountId>;
|
||||
'Vec<EthereumAccountId>': Vec<EthereumAccountId>;
|
||||
|
||||
@@ -5,11 +5,9 @@ import { TypeDef, TypeDefInfo } from '../../create/types';
|
||||
|
||||
import { assert, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
export const SPECIAL_TYPES = ['AccountId', 'AccountIndex', 'Address', 'Balance'];
|
||||
const stringIdentity = <T extends { toString: () => string }> (value: T): string => value.toString();
|
||||
|
||||
const identity = <T> (value: T): T => value;
|
||||
|
||||
export function paramsNotation (outer: string, inner?: string | any[], transform: (_: any) => string = identity): string {
|
||||
export function paramsNotation <T> (outer: string, inner?: T | T[], transform: (_: T) => string = stringIdentity): string {
|
||||
return `${outer}${
|
||||
inner
|
||||
? `<${(Array.isArray(inner) ? inner : [inner]).map(transform).join(', ')}>`
|
||||
@@ -18,7 +16,7 @@ export function paramsNotation (outer: string, inner?: string | any[], transform
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
function encodeWithParams (typeDef: Pick<TypeDef, any>, outer = typeDef.displayName || typeDef.type): string {
|
||||
function encodeWithParams (typeDef: TypeDef, outer = typeDef.displayName || typeDef.type): string {
|
||||
const { info, params, sub } = typeDef;
|
||||
|
||||
switch (info) {
|
||||
@@ -34,7 +32,6 @@ function encodeWithParams (typeDef: Pick<TypeDef, any>, outer = typeDef.displayN
|
||||
return paramsNotation(outer, params || sub, (param) => encodeTypeDef(param));
|
||||
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return outer;
|
||||
}
|
||||
}
|
||||
@@ -57,10 +54,10 @@ function encodeSubTypes (sub: TypeDef[], asEnum?: boolean): string {
|
||||
);
|
||||
}
|
||||
|
||||
function encodeEnum (typeDef: Pick<TypeDef, any>): string {
|
||||
function encodeEnum (typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Enum type');
|
||||
|
||||
const sub = typeDef.sub as TypeDef[];
|
||||
const sub = typeDef.sub;
|
||||
|
||||
// c-like enums have all Null entries
|
||||
// TODO We need to take the disciminant into account and auto-add empty entries
|
||||
@@ -69,29 +66,28 @@ function encodeEnum (typeDef: Pick<TypeDef, any>): string {
|
||||
: encodeSubTypes(sub, true);
|
||||
}
|
||||
|
||||
function encodeStruct (typeDef: Pick<TypeDef, any>): string {
|
||||
function encodeStruct (typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Struct type');
|
||||
|
||||
return encodeSubTypes(typeDef.sub as TypeDef[]);
|
||||
return encodeSubTypes(typeDef.sub);
|
||||
}
|
||||
|
||||
function encodeTuple (typeDef: Pick<TypeDef, any>): string {
|
||||
function encodeTuple (typeDef: TypeDef): string {
|
||||
assert(typeDef.sub && Array.isArray(typeDef.sub), 'Unable to encode Tuple type');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
return `(${(typeDef.sub as TypeDef[]).map((type) => encodeTypeDef(type)).join(', ')})`;
|
||||
return `(${typeDef.sub.map((type) => encodeTypeDef(type)).join(', ')})`;
|
||||
}
|
||||
|
||||
function encodeUInt ({ length }: Pick<TypeDef, any>, type: 'Int' | 'UInt'): string {
|
||||
function encodeUInt ({ length }: TypeDef, type: 'Int' | 'UInt'): string {
|
||||
assert(isNumber(length), 'Unable to encode VecFixed type');
|
||||
|
||||
return `${type}<${length}>`;
|
||||
}
|
||||
|
||||
function encodeVecFixed ({ length, sub }: Pick<TypeDef, any>): string {
|
||||
assert(isNumber(length) && !isUndefined(sub), 'Unable to encode VecFixed type');
|
||||
function encodeVecFixed ({ length, sub }: TypeDef): string {
|
||||
assert(isNumber(length) && !isUndefined(sub) && !Array.isArray(sub), 'Unable to encode VecFixed type');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
|
||||
return `[${sub.type};${length}]`;
|
||||
}
|
||||
|
||||
@@ -119,15 +115,15 @@ const encoders: Record<TypeDefInfo, (typeDef: TypeDef) => string> = {
|
||||
[TypeDefInfo.VecFixed]: (typeDef: TypeDef): string => encodeVecFixed(typeDef)
|
||||
};
|
||||
|
||||
function encodeType (typeDef: Pick<TypeDef, any>): string {
|
||||
const encoder = encoders[(typeDef as TypeDef).info];
|
||||
function encodeType (typeDef:TypeDef): string {
|
||||
const encoder = encoders[typeDef.info];
|
||||
|
||||
assert(encoder, `Cannot encode type: ${JSON.stringify(typeDef)}`);
|
||||
|
||||
return encoder(typeDef as TypeDef);
|
||||
return encoder(typeDef);
|
||||
}
|
||||
|
||||
export function encodeTypeDef (typeDef: Pick<TypeDef, any>): string {
|
||||
export function encodeTypeDef (typeDef: TypeDef): string {
|
||||
assert(!isUndefined(typeDef.info), `Invalid type definition with no instance info, ${JSON.stringify(typeDef)}`);
|
||||
|
||||
return typeDef.displayName || [TypeDefInfo.Enum, TypeDefInfo.Struct].includes(typeDef.info)
|
||||
@@ -135,11 +131,9 @@ export function encodeTypeDef (typeDef: Pick<TypeDef, any>): string {
|
||||
: encodeType(typeDef);
|
||||
}
|
||||
|
||||
export function withTypeString (typeDef: Pick<TypeDef, any>): Pick<TypeDef, any> {
|
||||
export function withTypeString (typeDef: Omit<TypeDef, 'type'>): TypeDef {
|
||||
return {
|
||||
...typeDef,
|
||||
type: SPECIAL_TYPES.includes(typeDef.displayName)
|
||||
? typeDef.displayName as string
|
||||
: encodeType(typeDef)
|
||||
type: encodeType(typeDef as TypeDef)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -114,8 +114,7 @@ export class CallIndex extends U8aFixed {
|
||||
/**
|
||||
* @name Call
|
||||
* @description
|
||||
* Extrinsic function descriptor, as defined in
|
||||
* {@link https://github.com/paritytech/wiki/blob/master/Extrinsic.md#the-extrinsic-format-for-node}.
|
||||
* Extrinsic function descriptor
|
||||
*/
|
||||
export default class Call extends Struct implements IMethod {
|
||||
protected _meta: FunctionMetadataLatest;
|
||||
|
||||
@@ -7,142 +7,95 @@ import { Definitions } from '../../types';
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
const layout = {
|
||||
InkCryptoHasher: {
|
||||
ContractCryptoHasher: {
|
||||
_enum: ['Blake2x256', 'Sha2x256', 'Keccak256']
|
||||
},
|
||||
InkDiscriminant: 'u32',
|
||||
InkLayoutArray: {
|
||||
offset: 'InkLayoutKey',
|
||||
ContractDiscriminant: 'u32',
|
||||
ContractLayoutArray: {
|
||||
offset: 'ContractLayoutKey',
|
||||
len: 'u32',
|
||||
cellsPerElem: 'u64',
|
||||
layout: 'InkStorageLayout'
|
||||
layout: 'ContractStorageLayout'
|
||||
},
|
||||
InkLayoutCell: {
|
||||
key: 'InkLayoutKey',
|
||||
ty: 'MtLookupTypeId'
|
||||
ContractLayoutCell: {
|
||||
key: 'ContractLayoutKey',
|
||||
ty: 'SiLookupTypeId'
|
||||
},
|
||||
InkLayoutEnum: {
|
||||
dispatchKey: 'InkLayoutKey',
|
||||
variants: 'BTreeMap<InkDiscriminant, InkLayoutStruct>'
|
||||
ContractLayoutEnum: {
|
||||
dispatchKey: 'ContractLayoutKey',
|
||||
variants: 'BTreeMap<ContractDiscriminant, ContractLayoutStruct>'
|
||||
},
|
||||
InkLayoutHash: {
|
||||
offset: 'InkLayoutKey',
|
||||
strategy: 'InkLayoutHashingStrategy',
|
||||
layout: 'InkStorageLayout'
|
||||
ContractLayoutHash: {
|
||||
offset: 'ContractLayoutKey',
|
||||
strategy: 'ContractLayoutHashingStrategy',
|
||||
layout: 'ContractStorageLayout'
|
||||
},
|
||||
InkLayoutHashingStrategy: {
|
||||
hasher: 'InkCryptoHasher',
|
||||
ContractLayoutHashingStrategy: {
|
||||
hasher: 'ContractCryptoHasher',
|
||||
postfix: 'Vec<u8>',
|
||||
prefix: 'Vec<u8>'
|
||||
},
|
||||
InkLayoutKey: '[u8; 32]',
|
||||
InkLayoutStruct: {
|
||||
fields: 'Vec<InkLayoutStructField>'
|
||||
ContractLayoutKey: '[u8; 32]',
|
||||
ContractLayoutStruct: {
|
||||
fields: 'Vec<ContractLayoutStructField>'
|
||||
},
|
||||
InkLayoutStructField: {
|
||||
layout: 'InkStorageLayout',
|
||||
ContractLayoutStructField: {
|
||||
layout: 'ContractStorageLayout',
|
||||
name: 'Text'
|
||||
},
|
||||
InkStorageLayout: {
|
||||
ContractStorageLayout: {
|
||||
_enum: {
|
||||
Cell: 'InkLayoutCell',
|
||||
Hash: 'InkLayoutHash',
|
||||
Array: 'InkLayoutArray',
|
||||
Struct: 'InkLayoutStruct',
|
||||
Enum: 'InkLayoutEnum'
|
||||
Cell: 'ContractLayoutCell',
|
||||
Hash: 'ContractLayoutHash',
|
||||
Array: 'ContractLayoutArray',
|
||||
Struct: 'ContractLayoutStruct',
|
||||
Enum: 'ContractLayoutEnum'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const spec = {
|
||||
InkConstructorSpec: {
|
||||
ContractConstructorSpec: {
|
||||
name: 'Text',
|
||||
selector: 'InkSelector',
|
||||
args: 'Vec<InkMessageParamSpec>',
|
||||
selector: 'ContractSelector',
|
||||
args: 'Vec<ContractMessageParamSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
InkContractSpec: {
|
||||
constructors: 'Vec<InkConstructorSpec>',
|
||||
messages: 'Vec<InkMessageSpec>',
|
||||
events: 'Vec<InkEventSpec>',
|
||||
ContractContractSpec: {
|
||||
constructors: 'Vec<ContractConstructorSpec>',
|
||||
messages: 'Vec<ContractMessageSpec>',
|
||||
events: 'Vec<ContractEventSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
InkDisplayName: 'MtPath',
|
||||
InkEventParamSpec: {
|
||||
ContractDisplayName: 'SiPath',
|
||||
ContractEventParamSpec: {
|
||||
name: 'Text',
|
||||
indexed: 'bool',
|
||||
type: 'InkTypeSpec',
|
||||
type: 'ContractTypeSpec',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
InkEventSpec: {
|
||||
ContractEventSpec: {
|
||||
name: 'Text',
|
||||
args: 'Vec<InkEventParamSpec>',
|
||||
args: 'Vec<ContractEventParamSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
InkMessageParamSpec: {
|
||||
ContractMessageParamSpec: {
|
||||
name: 'Text',
|
||||
type: 'InkTypeSpec'
|
||||
type: 'ContractTypeSpec'
|
||||
},
|
||||
InkMessageSpec: {
|
||||
ContractMessageSpec: {
|
||||
name: 'Text',
|
||||
selector: 'InkSelector',
|
||||
selector: 'ContractSelector',
|
||||
mutates: 'bool',
|
||||
payable: 'bool',
|
||||
args: 'Vec<InkMessageParamSpec>',
|
||||
returnType: 'Option<InkTypeSpec>',
|
||||
args: 'Vec<ContractMessageParamSpec>',
|
||||
returnType: 'Option<ContractTypeSpec>',
|
||||
docs: 'Vec<Text>'
|
||||
},
|
||||
InkSelector: '[u8; 4]',
|
||||
InkTypeSpec: {
|
||||
type: 'MtLookupTypeId',
|
||||
displayName: 'InkDisplayName'
|
||||
}
|
||||
};
|
||||
|
||||
const registry = {
|
||||
MtField: {
|
||||
name: 'Option<Text>',
|
||||
type: 'MtLookupTypeId'
|
||||
},
|
||||
MtLookupTypeId: 'u32',
|
||||
MtPath: 'Vec<Text>',
|
||||
MtType: {
|
||||
path: 'MtPath',
|
||||
params: 'Vec<MtLookupTypeId>',
|
||||
def: 'MtTypeDef'
|
||||
},
|
||||
MtTypeDef: {
|
||||
_enum: {
|
||||
Composite: 'MtTypeDefComposite',
|
||||
Variant: 'MtTypeDefVariant',
|
||||
Sequence: 'MtTypeDefSequence',
|
||||
Array: 'MtTypeDefArray',
|
||||
Tuple: 'MtTypeDefTuple',
|
||||
Primitive: 'MtTypeDefPrimitive'
|
||||
}
|
||||
},
|
||||
MtTypeDefArray: {
|
||||
len: 'u16',
|
||||
type: 'MtLookupTypeId'
|
||||
},
|
||||
MtTypeDefComposite: {
|
||||
fields: 'Vec<MtField>'
|
||||
},
|
||||
MtTypeDefVariant: {
|
||||
variants: 'Vec<MtVariant>'
|
||||
},
|
||||
MtTypeDefPrimitive: {
|
||||
// this enum definition is mapped in api-contracts/inkTypes.ts
|
||||
_enum: ['Bool', 'Char', 'Str', 'U8', 'U16', 'U32', 'U64', 'U128', 'I8', 'I16', 'I32', 'I64', 'I128']
|
||||
},
|
||||
MtTypeDefSequence: {
|
||||
type: 'MtLookupTypeId'
|
||||
},
|
||||
MtTypeDefTuple: 'Vec<MtLookupTypeId>',
|
||||
MtVariant: {
|
||||
name: 'Text',
|
||||
fields: 'Vec<MtField>',
|
||||
discriminant: 'Option<u64>'
|
||||
ContractSelector: '[u8; 4]',
|
||||
ContractTypeSpec: {
|
||||
type: 'SiLookupTypeId',
|
||||
displayName: 'ContractDisplayName'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,20 +103,19 @@ export default {
|
||||
rpc: {},
|
||||
types: {
|
||||
...layout,
|
||||
...registry,
|
||||
...spec,
|
||||
InkProject: {
|
||||
ContractProject: {
|
||||
// added by ABI serialization
|
||||
metadataVersion: 'Text',
|
||||
source: 'InkProjectSource',
|
||||
contract: 'InkProjectContract',
|
||||
source: 'ContractProjectSource',
|
||||
contract: 'ContractProjectContract',
|
||||
// expanded scale registry: RegistryReadOnly
|
||||
types: 'Vec<MtType>',
|
||||
types: 'Vec<SiType>',
|
||||
// renamed from layout (ignored for now, incomplete)
|
||||
// storage: 'InkStorageLayout',
|
||||
spec: 'InkContractSpec'
|
||||
// storage: 'ContractStorageLayout',
|
||||
spec: 'ContractContractSpec'
|
||||
},
|
||||
InkProjectContract: {
|
||||
ContractProjectContract: {
|
||||
name: 'Text',
|
||||
version: 'Text',
|
||||
authors: 'Vec<Text>',
|
||||
@@ -173,7 +125,7 @@ export default {
|
||||
homepage: 'Option<Text>',
|
||||
license: 'Option<Text>'
|
||||
},
|
||||
InkProjectSource: {
|
||||
ContractProjectSource: {
|
||||
hash: '[u8; 32]',
|
||||
language: 'Text',
|
||||
compiler: 'Text'
|
||||
|
||||
@@ -2,128 +2,129 @@
|
||||
/* eslint-disable */
|
||||
|
||||
import { BTreeMap, Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, Text, bool, u16, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { Bytes, Text, bool, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { SiLookupTypeId, SiPath, SiType } from '@polkadot/types/interfaces/scaleInfo';
|
||||
|
||||
/** @name InkConstructorSpec */
|
||||
export interface InkConstructorSpec extends Struct {
|
||||
/** @name ContractConstructorSpec */
|
||||
export interface ContractConstructorSpec extends Struct {
|
||||
readonly name: Text;
|
||||
readonly selector: InkSelector;
|
||||
readonly args: Vec<InkMessageParamSpec>;
|
||||
readonly selector: ContractSelector;
|
||||
readonly args: Vec<ContractMessageParamSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name InkContractSpec */
|
||||
export interface InkContractSpec extends Struct {
|
||||
readonly constructors: Vec<InkConstructorSpec>;
|
||||
readonly messages: Vec<InkMessageSpec>;
|
||||
readonly events: Vec<InkEventSpec>;
|
||||
/** @name ContractContractSpec */
|
||||
export interface ContractContractSpec extends Struct {
|
||||
readonly constructors: Vec<ContractConstructorSpec>;
|
||||
readonly messages: Vec<ContractMessageSpec>;
|
||||
readonly events: Vec<ContractEventSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name InkCryptoHasher */
|
||||
export interface InkCryptoHasher extends Enum {
|
||||
/** @name ContractCryptoHasher */
|
||||
export interface ContractCryptoHasher extends Enum {
|
||||
readonly isBlake2X256: boolean;
|
||||
readonly isSha2X256: boolean;
|
||||
readonly isKeccak256: boolean;
|
||||
}
|
||||
|
||||
/** @name InkDiscriminant */
|
||||
export interface InkDiscriminant extends u32 {}
|
||||
/** @name ContractDiscriminant */
|
||||
export interface ContractDiscriminant extends u32 {}
|
||||
|
||||
/** @name InkDisplayName */
|
||||
export interface InkDisplayName extends MtPath {}
|
||||
/** @name ContractDisplayName */
|
||||
export interface ContractDisplayName extends SiPath {}
|
||||
|
||||
/** @name InkEventParamSpec */
|
||||
export interface InkEventParamSpec extends Struct {
|
||||
/** @name ContractEventParamSpec */
|
||||
export interface ContractEventParamSpec extends Struct {
|
||||
readonly name: Text;
|
||||
readonly indexed: bool;
|
||||
readonly type: InkTypeSpec;
|
||||
readonly type: ContractTypeSpec;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name InkEventSpec */
|
||||
export interface InkEventSpec extends Struct {
|
||||
/** @name ContractEventSpec */
|
||||
export interface ContractEventSpec extends Struct {
|
||||
readonly name: Text;
|
||||
readonly args: Vec<InkEventParamSpec>;
|
||||
readonly args: Vec<ContractEventParamSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name InkLayoutArray */
|
||||
export interface InkLayoutArray extends Struct {
|
||||
readonly offset: InkLayoutKey;
|
||||
/** @name ContractLayoutArray */
|
||||
export interface ContractLayoutArray extends Struct {
|
||||
readonly offset: ContractLayoutKey;
|
||||
readonly len: u32;
|
||||
readonly cellsPerElem: u64;
|
||||
readonly layout: InkStorageLayout;
|
||||
readonly layout: ContractStorageLayout;
|
||||
}
|
||||
|
||||
/** @name InkLayoutCell */
|
||||
export interface InkLayoutCell extends Struct {
|
||||
readonly key: InkLayoutKey;
|
||||
readonly ty: MtLookupTypeId;
|
||||
/** @name ContractLayoutCell */
|
||||
export interface ContractLayoutCell extends Struct {
|
||||
readonly key: ContractLayoutKey;
|
||||
readonly ty: SiLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name InkLayoutEnum */
|
||||
export interface InkLayoutEnum extends Struct {
|
||||
readonly dispatchKey: InkLayoutKey;
|
||||
readonly variants: BTreeMap<InkDiscriminant, InkLayoutStruct>;
|
||||
/** @name ContractLayoutEnum */
|
||||
export interface ContractLayoutEnum extends Struct {
|
||||
readonly dispatchKey: ContractLayoutKey;
|
||||
readonly variants: BTreeMap<ContractDiscriminant, ContractLayoutStruct>;
|
||||
}
|
||||
|
||||
/** @name InkLayoutHash */
|
||||
export interface InkLayoutHash extends Struct {
|
||||
readonly offset: InkLayoutKey;
|
||||
readonly strategy: InkLayoutHashingStrategy;
|
||||
readonly layout: InkStorageLayout;
|
||||
/** @name ContractLayoutHash */
|
||||
export interface ContractLayoutHash extends Struct {
|
||||
readonly offset: ContractLayoutKey;
|
||||
readonly strategy: ContractLayoutHashingStrategy;
|
||||
readonly layout: ContractStorageLayout;
|
||||
}
|
||||
|
||||
/** @name InkLayoutHashingStrategy */
|
||||
export interface InkLayoutHashingStrategy extends Struct {
|
||||
readonly hasher: InkCryptoHasher;
|
||||
/** @name ContractLayoutHashingStrategy */
|
||||
export interface ContractLayoutHashingStrategy extends Struct {
|
||||
readonly hasher: ContractCryptoHasher;
|
||||
readonly postfix: Bytes;
|
||||
readonly prefix: Bytes;
|
||||
}
|
||||
|
||||
/** @name InkLayoutKey */
|
||||
export interface InkLayoutKey extends U8aFixed {}
|
||||
/** @name ContractLayoutKey */
|
||||
export interface ContractLayoutKey extends U8aFixed {}
|
||||
|
||||
/** @name InkLayoutStruct */
|
||||
export interface InkLayoutStruct extends Struct {
|
||||
readonly fields: Vec<InkLayoutStructField>;
|
||||
/** @name ContractLayoutStruct */
|
||||
export interface ContractLayoutStruct extends Struct {
|
||||
readonly fields: Vec<ContractLayoutStructField>;
|
||||
}
|
||||
|
||||
/** @name InkLayoutStructField */
|
||||
export interface InkLayoutStructField extends Struct {
|
||||
readonly layout: InkStorageLayout;
|
||||
/** @name ContractLayoutStructField */
|
||||
export interface ContractLayoutStructField extends Struct {
|
||||
readonly layout: ContractStorageLayout;
|
||||
readonly name: Text;
|
||||
}
|
||||
|
||||
/** @name InkMessageParamSpec */
|
||||
export interface InkMessageParamSpec extends Struct {
|
||||
/** @name ContractMessageParamSpec */
|
||||
export interface ContractMessageParamSpec extends Struct {
|
||||
readonly name: Text;
|
||||
readonly type: InkTypeSpec;
|
||||
readonly type: ContractTypeSpec;
|
||||
}
|
||||
|
||||
/** @name InkMessageSpec */
|
||||
export interface InkMessageSpec extends Struct {
|
||||
/** @name ContractMessageSpec */
|
||||
export interface ContractMessageSpec extends Struct {
|
||||
readonly name: Text;
|
||||
readonly selector: InkSelector;
|
||||
readonly selector: ContractSelector;
|
||||
readonly mutates: bool;
|
||||
readonly payable: bool;
|
||||
readonly args: Vec<InkMessageParamSpec>;
|
||||
readonly returnType: Option<InkTypeSpec>;
|
||||
readonly args: Vec<ContractMessageParamSpec>;
|
||||
readonly returnType: Option<ContractTypeSpec>;
|
||||
readonly docs: Vec<Text>;
|
||||
}
|
||||
|
||||
/** @name InkProject */
|
||||
export interface InkProject extends Struct {
|
||||
/** @name ContractProject */
|
||||
export interface ContractProject extends Struct {
|
||||
readonly metadataVersion: Text;
|
||||
readonly source: InkProjectSource;
|
||||
readonly contract: InkProjectContract;
|
||||
readonly types: Vec<MtType>;
|
||||
readonly spec: InkContractSpec;
|
||||
readonly source: ContractProjectSource;
|
||||
readonly contract: ContractProjectContract;
|
||||
readonly types: Vec<SiType>;
|
||||
readonly spec: ContractContractSpec;
|
||||
}
|
||||
|
||||
/** @name InkProjectContract */
|
||||
export interface InkProjectContract extends Struct {
|
||||
/** @name ContractProjectContract */
|
||||
export interface ContractProjectContract extends Struct {
|
||||
readonly name: Text;
|
||||
readonly version: Text;
|
||||
readonly authors: Vec<Text>;
|
||||
@@ -134,117 +135,34 @@ export interface InkProjectContract extends Struct {
|
||||
readonly license: Option<Text>;
|
||||
}
|
||||
|
||||
/** @name InkProjectSource */
|
||||
export interface InkProjectSource extends Struct {
|
||||
/** @name ContractProjectSource */
|
||||
export interface ContractProjectSource extends Struct {
|
||||
readonly hash: U8aFixed;
|
||||
readonly language: Text;
|
||||
readonly compiler: Text;
|
||||
}
|
||||
|
||||
/** @name InkSelector */
|
||||
export interface InkSelector extends U8aFixed {}
|
||||
/** @name ContractSelector */
|
||||
export interface ContractSelector extends U8aFixed {}
|
||||
|
||||
/** @name InkStorageLayout */
|
||||
export interface InkStorageLayout extends Enum {
|
||||
/** @name ContractStorageLayout */
|
||||
export interface ContractStorageLayout extends Enum {
|
||||
readonly isCell: boolean;
|
||||
readonly asCell: InkLayoutCell;
|
||||
readonly asCell: ContractLayoutCell;
|
||||
readonly isHash: boolean;
|
||||
readonly asHash: InkLayoutHash;
|
||||
readonly asHash: ContractLayoutHash;
|
||||
readonly isArray: boolean;
|
||||
readonly asArray: InkLayoutArray;
|
||||
readonly asArray: ContractLayoutArray;
|
||||
readonly isStruct: boolean;
|
||||
readonly asStruct: InkLayoutStruct;
|
||||
readonly asStruct: ContractLayoutStruct;
|
||||
readonly isEnum: boolean;
|
||||
readonly asEnum: InkLayoutEnum;
|
||||
readonly asEnum: ContractLayoutEnum;
|
||||
}
|
||||
|
||||
/** @name InkTypeSpec */
|
||||
export interface InkTypeSpec extends Struct {
|
||||
readonly type: MtLookupTypeId;
|
||||
readonly displayName: InkDisplayName;
|
||||
}
|
||||
|
||||
/** @name MtField */
|
||||
export interface MtField extends Struct {
|
||||
readonly name: Option<Text>;
|
||||
readonly type: MtLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name MtLookupTypeId */
|
||||
export interface MtLookupTypeId extends u32 {}
|
||||
|
||||
/** @name MtPath */
|
||||
export interface MtPath extends Vec<Text> {}
|
||||
|
||||
/** @name MtType */
|
||||
export interface MtType extends Struct {
|
||||
readonly path: MtPath;
|
||||
readonly params: Vec<MtLookupTypeId>;
|
||||
readonly def: MtTypeDef;
|
||||
}
|
||||
|
||||
/** @name MtTypeDef */
|
||||
export interface MtTypeDef extends Enum {
|
||||
readonly isComposite: boolean;
|
||||
readonly asComposite: MtTypeDefComposite;
|
||||
readonly isVariant: boolean;
|
||||
readonly asVariant: MtTypeDefVariant;
|
||||
readonly isSequence: boolean;
|
||||
readonly asSequence: MtTypeDefSequence;
|
||||
readonly isArray: boolean;
|
||||
readonly asArray: MtTypeDefArray;
|
||||
readonly isTuple: boolean;
|
||||
readonly asTuple: MtTypeDefTuple;
|
||||
readonly isPrimitive: boolean;
|
||||
readonly asPrimitive: MtTypeDefPrimitive;
|
||||
}
|
||||
|
||||
/** @name MtTypeDefArray */
|
||||
export interface MtTypeDefArray extends Struct {
|
||||
readonly len: u16;
|
||||
readonly type: MtLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name MtTypeDefComposite */
|
||||
export interface MtTypeDefComposite extends Struct {
|
||||
readonly fields: Vec<MtField>;
|
||||
}
|
||||
|
||||
/** @name MtTypeDefPrimitive */
|
||||
export interface MtTypeDefPrimitive extends Enum {
|
||||
readonly isBool: boolean;
|
||||
readonly isChar: boolean;
|
||||
readonly isStr: boolean;
|
||||
readonly isU8: boolean;
|
||||
readonly isU16: boolean;
|
||||
readonly isU32: boolean;
|
||||
readonly isU64: boolean;
|
||||
readonly isU128: boolean;
|
||||
readonly isI8: boolean;
|
||||
readonly isI16: boolean;
|
||||
readonly isI32: boolean;
|
||||
readonly isI64: boolean;
|
||||
readonly isI128: boolean;
|
||||
}
|
||||
|
||||
/** @name MtTypeDefSequence */
|
||||
export interface MtTypeDefSequence extends Struct {
|
||||
readonly type: MtLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name MtTypeDefTuple */
|
||||
export interface MtTypeDefTuple extends Vec<MtLookupTypeId> {}
|
||||
|
||||
/** @name MtTypeDefVariant */
|
||||
export interface MtTypeDefVariant extends Struct {
|
||||
readonly variants: Vec<MtVariant>;
|
||||
}
|
||||
|
||||
/** @name MtVariant */
|
||||
export interface MtVariant extends Struct {
|
||||
readonly name: Text;
|
||||
readonly fields: Vec<MtField>;
|
||||
readonly discriminant: Option<u64>;
|
||||
/** @name ContractTypeSpec */
|
||||
export interface ContractTypeSpec extends Struct {
|
||||
readonly type: SiLookupTypeId;
|
||||
readonly displayName: ContractDisplayName;
|
||||
}
|
||||
|
||||
export type PHANTOM_CONTRACTSABI = 'contractsAbi';
|
||||
|
||||
@@ -12,7 +12,6 @@ export { default as balances } from './balances/definitions';
|
||||
export { default as collective } from './collective/definitions';
|
||||
export { default as consensus } from './consensus/definitions';
|
||||
export { default as contracts } from './contracts/definitions';
|
||||
export { default as contractsAbi } from './contractsAbi/definitions';
|
||||
export { default as democracy } from './democracy/definitions';
|
||||
export { default as elections } from './elections/definitions';
|
||||
export { default as engine } from './engine/definitions';
|
||||
@@ -43,6 +42,10 @@ export { default as parachains } from './parachains/definitions';
|
||||
export { default as poll } from './poll/definitions';
|
||||
export { default as purchase } from './purchase/definitions';
|
||||
|
||||
// scale-info & contracts
|
||||
export { default as contractsAbi } from './contractsAbi/definitions';
|
||||
export { default as scaleInfo } from './scaleInfo/definitions';
|
||||
|
||||
// other useful types
|
||||
export { default as ethereum } from './ethereum/definitions';
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { Definitions } from '../../types';
|
||||
|
||||
// order important in structs... :)
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
export default {
|
||||
rpc: {},
|
||||
types: {
|
||||
SiField: {
|
||||
name: 'Option<Text>',
|
||||
type: 'SiLookupTypeId'
|
||||
},
|
||||
SiLookupTypeId: 'u32',
|
||||
SiPath: 'Vec<Text>',
|
||||
SiType: {
|
||||
path: 'SiPath',
|
||||
params: 'Vec<SiLookupTypeId>',
|
||||
def: 'SiTypeDef'
|
||||
},
|
||||
SiTypeDef: {
|
||||
_enum: {
|
||||
Composite: 'SiTypeDefComposite',
|
||||
Variant: 'SiTypeDefVariant',
|
||||
Sequence: 'SiTypeDefSequence',
|
||||
Array: 'SiTypeDefArray',
|
||||
Tuple: 'SiTypeDefTuple',
|
||||
Primitive: 'SiTypeDefPrimitive'
|
||||
}
|
||||
},
|
||||
SiTypeDefArray: {
|
||||
len: 'u16',
|
||||
type: 'SiLookupTypeId'
|
||||
},
|
||||
SiTypeDefComposite: {
|
||||
fields: 'Vec<SiField>'
|
||||
},
|
||||
SiTypeDefVariant: {
|
||||
variants: 'Vec<SiVariant>'
|
||||
},
|
||||
SiTypeDefPrimitive: {
|
||||
_enum: ['Bool', 'Char', 'Str', 'U8', 'U16', 'U32', 'U64', 'U128', 'I8', 'I16', 'I32', 'I64', 'I128']
|
||||
},
|
||||
SiTypeDefSequence: {
|
||||
type: 'SiLookupTypeId'
|
||||
},
|
||||
SiTypeDefTuple: 'Vec<SiLookupTypeId>',
|
||||
SiVariant: {
|
||||
name: 'Text',
|
||||
fields: 'Vec<SiField>',
|
||||
discriminant: 'Option<u64>'
|
||||
}
|
||||
}
|
||||
} as Definitions;
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,90 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
import { Enum, Option, Struct, Vec } from '@polkadot/types/codec';
|
||||
import { Text, u16, u32, u64 } from '@polkadot/types/primitive';
|
||||
|
||||
/** @name SiField */
|
||||
export interface SiField extends Struct {
|
||||
readonly name: Option<Text>;
|
||||
readonly type: SiLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name SiLookupTypeId */
|
||||
export interface SiLookupTypeId extends u32 {}
|
||||
|
||||
/** @name SiPath */
|
||||
export interface SiPath extends Vec<Text> {}
|
||||
|
||||
/** @name SiType */
|
||||
export interface SiType extends Struct {
|
||||
readonly path: SiPath;
|
||||
readonly params: Vec<SiLookupTypeId>;
|
||||
readonly def: SiTypeDef;
|
||||
}
|
||||
|
||||
/** @name SiTypeDef */
|
||||
export interface SiTypeDef extends Enum {
|
||||
readonly isComposite: boolean;
|
||||
readonly asComposite: SiTypeDefComposite;
|
||||
readonly isVariant: boolean;
|
||||
readonly asVariant: SiTypeDefVariant;
|
||||
readonly isSequence: boolean;
|
||||
readonly asSequence: SiTypeDefSequence;
|
||||
readonly isArray: boolean;
|
||||
readonly asArray: SiTypeDefArray;
|
||||
readonly isTuple: boolean;
|
||||
readonly asTuple: SiTypeDefTuple;
|
||||
readonly isPrimitive: boolean;
|
||||
readonly asPrimitive: SiTypeDefPrimitive;
|
||||
}
|
||||
|
||||
/** @name SiTypeDefArray */
|
||||
export interface SiTypeDefArray extends Struct {
|
||||
readonly len: u16;
|
||||
readonly type: SiLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name SiTypeDefComposite */
|
||||
export interface SiTypeDefComposite extends Struct {
|
||||
readonly fields: Vec<SiField>;
|
||||
}
|
||||
|
||||
/** @name SiTypeDefPrimitive */
|
||||
export interface SiTypeDefPrimitive extends Enum {
|
||||
readonly isBool: boolean;
|
||||
readonly isChar: boolean;
|
||||
readonly isStr: boolean;
|
||||
readonly isU8: boolean;
|
||||
readonly isU16: boolean;
|
||||
readonly isU32: boolean;
|
||||
readonly isU64: boolean;
|
||||
readonly isU128: boolean;
|
||||
readonly isI8: boolean;
|
||||
readonly isI16: boolean;
|
||||
readonly isI32: boolean;
|
||||
readonly isI64: boolean;
|
||||
readonly isI128: boolean;
|
||||
}
|
||||
|
||||
/** @name SiTypeDefSequence */
|
||||
export interface SiTypeDefSequence extends Struct {
|
||||
readonly type: SiLookupTypeId;
|
||||
}
|
||||
|
||||
/** @name SiTypeDefTuple */
|
||||
export interface SiTypeDefTuple extends Vec<SiLookupTypeId> {}
|
||||
|
||||
/** @name SiTypeDefVariant */
|
||||
export interface SiTypeDefVariant extends Struct {
|
||||
readonly variants: Vec<SiVariant>;
|
||||
}
|
||||
|
||||
/** @name SiVariant */
|
||||
export interface SiVariant extends Struct {
|
||||
readonly name: Text;
|
||||
readonly fields: Vec<SiField>;
|
||||
readonly discriminant: Option<u64>;
|
||||
}
|
||||
|
||||
export type PHANTOM_SCALEINFO = 'scaleInfo';
|
||||
@@ -13,7 +13,7 @@ const ACTUAL = '0x' +
|
||||
// votes 3
|
||||
'3c3a000000b90062690301b9713b004d000000d100d4437d00ef9ad800ca000000fd003ebd4c006c100a00ea00000021009a58de00e3773a00ed0000008c0098bdc200861fc1000a0100005800b2197b00fb721900290100005b00a19ee900c13cdd009001000098005a4c28006d5e670091010000d300b642da002664d800b40100009400ec48b0001c2e1a00cc0100008700492fd4002d3d3700960200003200d5bef600412e4000be0200003c00066689005968d100c6020000f90058a36a00f20cbc00cb02000076006ec96e00472aa30034ac0000000000152502005ed6050034000900ec000000fc0081398300b14adc001a55a2001c0100006a001e4d7e00b33c4f006e3d82007701000031006a48be009d308c00bf3d040081010000ff009151af00925129009151b200a101000087007583760005135d00f6028e00a8010000fe000d209f00295c1800314c2700b801000062006725e4004c73c000c80c4d00d00100000d003e47bb003b444c00be4af2004e0200006e0077651200b9588300ff0cf8005c0200002200ec25f0006e4b4300e652c4008b020000e200832b6300869a5100c408b20093020000c500e1506200fc0f47004e5eb0001803000000c200ff32410040334e003c3353004033b100060000001d00463b43008b1e060155481300bd493b00140100001c002127d400dd4958009f1ab700cd2bfa003b010000b000812e1e008722710040480800962f95008c0100001100b5240201f31634007d3bb50002490500e0010000b6001d102b0096367c007b3ed700514c210018da0000009b00ea397300655744005b2e78005c2654003f0d5c00f80000006200ed26e000b5176b009e14e800a54ae600334f6000300100002500c42fa900c22fac00592c7900c02f88005e2f490048010000f300640cee00cb3b4a000c304b00bf36e1007e3ad3007c010000a300192e5600b42e8100b82e1b00cc2ef5004c2e490006020000dd0097200700a340ab00c46e1600d60c4600eb0af40004fe000000fd00d207f3001f383e00da242400f51dbd00a82b6c00dc36970004910200009500a40cb600ed302700a711d9001e4050000d48f000ba1f9800cd07be000000085900000066005b172f00f01d0e005b172d00dc0f70005a1772005a1786005a178a005a173d005a17ca0059172e003e010000c800020e0c003d223f00302306001d116800931e9600511a1400cc18a1006e0ac700231d05014b02f80000000000001beab9a3ce0000000000000000000000c9d6650d1fd62e310000000000000000c54b85db547a2f52a47bb9a03a091300d4020000';
|
||||
|
||||
describe('CompactAssignmentScaleCompact', (): void => {
|
||||
describe('CompactAssignmentSiCompact', (): void => {
|
||||
// generate_solution_type!(#[compact] pub struct InnerTestSolutionCompact::<_, _, _>(..));
|
||||
// let compact = InnerTestSolution {
|
||||
// votes1: vec![(2, 20), (4, 40)],
|
||||
@@ -99,7 +99,7 @@ describe('CompactAssignmentScaleCompact', (): void => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('CompactAssignmentScaleNormal', (): void => {
|
||||
describe('CompactAssignmentSiNormal', (): void => {
|
||||
// generate_solution_type!(pub struct InnerTestSolutionCompact::<_, _, _>(..));
|
||||
// let compact = InnerTestSolution {
|
||||
// votes1: vec![(2, 20), (4, 40)],
|
||||
|
||||
@@ -9,7 +9,6 @@ export * from './balances/types';
|
||||
export * from './collective/types';
|
||||
export * from './consensus/types';
|
||||
export * from './contracts/types';
|
||||
export * from './contractsAbi/types';
|
||||
export * from './democracy/types';
|
||||
export * from './elections/types';
|
||||
export * from './engine/types';
|
||||
@@ -37,6 +36,8 @@ export * from './claims/types';
|
||||
export * from './parachains/types';
|
||||
export * from './poll/types';
|
||||
export * from './purchase/types';
|
||||
export * from './contractsAbi/types';
|
||||
export * from './scaleInfo/types';
|
||||
export * from './ethereum/types';
|
||||
export * from './metadata/types';
|
||||
export * from './rpc/types';
|
||||
|
||||
-18
@@ -1,18 +0,0 @@
|
||||
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
module.exports = {
|
||||
exclude: '**/*+(index|e2e|spec|types).ts',
|
||||
excludeExternals: true,
|
||||
excludeNotExported: true,
|
||||
excludePrivate: true,
|
||||
excludeProtected: true,
|
||||
hideGenerator: true,
|
||||
includeDeclarations: false,
|
||||
module: 'commonjs',
|
||||
moduleResolution: 'node',
|
||||
name: 'Polkadot JS API',
|
||||
out: 'docs',
|
||||
stripInternal: 'true',
|
||||
theme: 'markdown'
|
||||
};
|
||||
Reference in New Issue
Block a user