Cleanup Submittable interfaces for external use (#755)
* Cleanup Submittable interfaces for external use * Update Struct.ts
This commit is contained in:
@@ -64,6 +64,7 @@ let defaultRegistry: TypeRegistry;
|
||||
export default function getDefaultRegistry () {
|
||||
if (!defaultRegistry) {
|
||||
const defaultTypes = require('../index.types');
|
||||
|
||||
defaultRegistry = new TypeRegistry();
|
||||
defaultRegistry.register({ ...defaultTypes });
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyU8a, Codec, Constructor } from '../types';
|
||||
import { AnyU8a, ArgsDef, Codec, IMethod } from '../types';
|
||||
|
||||
import { assert, isHex, isObject, isU8a, hexToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -11,10 +11,6 @@ import Struct from '../codec/Struct';
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
import { FunctionMetadata, FunctionArgumentMetadata } from '../Metadata/v0/Modules';
|
||||
|
||||
interface ArgsDef {
|
||||
[index: string]: Constructor;
|
||||
}
|
||||
|
||||
interface DecodeMethodInput {
|
||||
args: any;
|
||||
callIndex: MethodIndex | Uint8Array;
|
||||
@@ -66,7 +62,7 @@ export class MethodIndex extends U8aFixed {
|
||||
* Extrinsic function descriptor, as defined in
|
||||
* {@link https://github.com/paritytech/wiki/blob/master/Extrinsic.md#the-extrinsic-format-for-node}.
|
||||
*/
|
||||
export default class Method extends Struct {
|
||||
export default class Method extends Struct implements IMethod {
|
||||
protected _meta: FunctionMetadata;
|
||||
|
||||
constructor (value: any, meta?: FunctionMetadata) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a, Codec, SignatureOptions } from '../types';
|
||||
import { AnyNumber, AnyU8a, ArgsDef, Codec, IExtrinsic, SignatureOptions } from '../types';
|
||||
|
||||
import { isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
@@ -33,7 +33,7 @@ type ExtrinsicValue = {
|
||||
* - signed, to create a transaction
|
||||
* - left as is, to create an inherent
|
||||
*/
|
||||
export default class Extrinsic extends Struct {
|
||||
export default class Extrinsic extends Struct implements IExtrinsic {
|
||||
constructor (value?: ExtrinsicValue | AnyU8a | Method) {
|
||||
super({
|
||||
signature: ExtrinsicSignature,
|
||||
@@ -77,6 +77,13 @@ export default class Extrinsic extends Struct {
|
||||
return this.method.args;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Thge argument defintions, compatible with [[Method]]
|
||||
*/
|
||||
get argsDef (): ArgsDef {
|
||||
return this.method.argsDef;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The actual `[sectionIndex, methodIndex]` as used in the Method
|
||||
*/
|
||||
@@ -109,6 +116,13 @@ export default class Extrinsic extends Struct {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` is method has `Origin` argument (compatibility with [[Method]])
|
||||
*/
|
||||
get hasOrigin (): boolean {
|
||||
return this.method.hasOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` id the extrinsic is signed
|
||||
*/
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, SignatureOptions } from '../types';
|
||||
import { AnyNumber, IExtrinsicSignature, SignatureOptions } from '../types';
|
||||
|
||||
import Struct from '../codec/Struct';
|
||||
import Address from './Address';
|
||||
@@ -26,7 +26,7 @@ const BIT_VERSION = 0b0000001;
|
||||
* @description
|
||||
* A container for the [[Signature]] associated with a specific [[Extrinsic]]
|
||||
*/
|
||||
export default class ExtrinsicSignature extends Struct {
|
||||
export default class ExtrinsicSignature extends Struct implements IExtrinsicSignature {
|
||||
// Signature Information.
|
||||
// 1 byte version: BIT_VERSION | (isSigned ? BIT_SIGNED : BIT_UNSIGNED)
|
||||
// 1/3/5/9/33 bytes: The signing account identity, in Address format
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { IHash } from '../types';
|
||||
import H256 from '../primitive/H256';
|
||||
|
||||
/**
|
||||
@@ -10,5 +11,5 @@ import H256 from '../primitive/H256';
|
||||
* The default hash that is used accross the system. It is basically just a thin
|
||||
* wrapper around [[H256]], representing a 32-byte blake2b (Substrate) value
|
||||
*/
|
||||
export default class Hash extends H256 {
|
||||
export default class Hash extends H256 implements IHash {
|
||||
}
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import BN from 'bn.js';
|
||||
import U8a from './codec/U8a';
|
||||
import Method from './primitive/Method';
|
||||
import Address from './type/Address';
|
||||
import U8a from './codec/U8a';
|
||||
import { FunctionMetadata } from './Metadata/v0/Modules';
|
||||
|
||||
export type CodecArg = Codec | BN | Boolean | String | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;
|
||||
|
||||
@@ -99,15 +100,30 @@ export type SignatureOptions = {
|
||||
version?: RuntimeVersionInterface
|
||||
};
|
||||
|
||||
export interface ArgsDef {
|
||||
[index: string]: Constructor;
|
||||
}
|
||||
|
||||
export interface IHash extends U8a {}
|
||||
|
||||
export interface ISignature extends Codec {}
|
||||
export interface IMethod extends Codec {
|
||||
readonly args: Array<Codec>;
|
||||
readonly argsDef: ArgsDef;
|
||||
readonly callIndex: Uint8Array;
|
||||
readonly data: Uint8Array;
|
||||
readonly hasOrigin: boolean;
|
||||
readonly meta: FunctionMetadata;
|
||||
}
|
||||
|
||||
export interface IExtrinsic extends Codec {
|
||||
export interface IExtrinsicSignature extends Codec {
|
||||
readonly isSigned: boolean;
|
||||
}
|
||||
|
||||
export interface IExtrinsic extends IMethod {
|
||||
hash: IHash;
|
||||
isSigned: boolean;
|
||||
method: Method;
|
||||
signature: ISignature;
|
||||
addSignature (signer: Address | Uint8Array, signature: Uint8Array, nonce: AnyNumber, era?: Uint8Array): this;
|
||||
sign (account: KeyringPair, options: SignatureOptions): this;
|
||||
signature: IExtrinsicSignature;
|
||||
addSignature (signer: Address | Uint8Array, signature: Uint8Array, nonce: AnyNumber, era?: Uint8Array): IExtrinsic;
|
||||
sign (account: KeyringPair, options: SignatureOptions): IExtrinsic;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user