move SignerPayload to @polkadot/types (#1360)
* move SignerPayload to @polkadot/types * fix errors * update changelog * improve naming and code style
This commit is contained in:
+4
-1
@@ -2,7 +2,10 @@
|
||||
|
||||
- The `getRuntimeVersion` and `subscribeRuntimeVersion` RPCs are now only available on the `rpc.state.*` endpoints. This aligns with the Substrate implementation.
|
||||
- Support for extrinsics with versions that is not in the base Substrate implementation (V1-V3) can now be done by providing an implementation for `ExtrinsicUnknown`
|
||||
|
||||
- **Breaking change** SignerPayload is registered and can be overrode now.
|
||||
- SignerPayload is renamed to SignerPayloadJSON
|
||||
- SignerPayloadJSON, SignerPayloadRawBase and SignerPayloadRaw are all moved to `@polkadot/types`
|
||||
|
||||
|
||||
# 0.90.1
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { CallFunction, RegistryTypes } from '@polkadot/types/types';
|
||||
import { ApiOptions, ApiTypes, DecoratedRpc, DecorateMethod, QueryableStorage, QueryableStorageMulti, SignerPayloadRawBase, SubmittableExtrinsics, Signer } from '../types';
|
||||
import { CallFunction, RegistryTypes, SignerPayloadRawBase } from '@polkadot/types/types';
|
||||
import { ApiOptions, ApiTypes, DecoratedRpc, DecorateMethod, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics, Signer } from '../types';
|
||||
|
||||
import { Constants } from '@polkadot/api-metadata/consts/types';
|
||||
import { GenericCall, Metadata, getTypeRegistry } from '@polkadot/types';
|
||||
|
||||
@@ -15,7 +15,6 @@ import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import { filterEvents, isKeyringPair } from '../util';
|
||||
import ApiBase from '../base';
|
||||
import SignerPayload from '../SignerPayload';
|
||||
import SubmittableResult from './Result';
|
||||
|
||||
type Creator<ApiType> = (extrinsic: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
||||
@@ -130,13 +129,13 @@ class Submittable<ApiType> extends _Extrinsic implements SubmittableExtrinsic<Ap
|
||||
return [options, statusCb];
|
||||
}
|
||||
|
||||
private async _signViaSigner (address: string, eraOptions: SignatureOptions, header: Header | null): Promise<number> {
|
||||
private async _signViaSigner (address: string, optionsWithEra: SignatureOptions, header: Header | null): Promise<number> {
|
||||
if (!this._api.signer) {
|
||||
throw new Error('no signer attached');
|
||||
}
|
||||
|
||||
const payload = new SignerPayload({
|
||||
...eraOptions,
|
||||
const payload = createType('SignerPayload', {
|
||||
...optionsWithEra,
|
||||
address,
|
||||
method: this.method,
|
||||
blockNumber: header ? header.number : 0
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { AnyFunction, Callback, CallFunction, Codec, CodecArg, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
import { AnyFunction, Callback, CallFunction, Codec, CodecArg, RegistryTypes, SignatureOptions, SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
|
||||
import { SubmittableResultImpl, SubmittableExtrinsic } from './submittable/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -222,82 +222,6 @@ export interface SignerOptions extends SignatureOptions {
|
||||
genesisHash: Hash;
|
||||
}
|
||||
|
||||
export interface SignerPayload {
|
||||
/**
|
||||
* @description The ss-58 encoded address
|
||||
*/
|
||||
address: string;
|
||||
|
||||
/**
|
||||
* @description The checkpoint hash of the block, in hex
|
||||
*/
|
||||
blockHash: string;
|
||||
|
||||
/**
|
||||
* @description The checkpoint block number, in hex
|
||||
*/
|
||||
blockNumber: string;
|
||||
|
||||
/**
|
||||
* @description The era for this transaction, in hex
|
||||
*/
|
||||
era: string;
|
||||
|
||||
/**
|
||||
* @description The genesis hash of the chain, in hex
|
||||
*/
|
||||
genesisHash: string;
|
||||
|
||||
/**
|
||||
* @description The encoded method (with arguments) in hex
|
||||
*/
|
||||
method: string;
|
||||
|
||||
/**
|
||||
* @description The nonce for this transaction, in hex
|
||||
*/
|
||||
nonce: string;
|
||||
|
||||
/**
|
||||
* @description The current spec version for the runtime
|
||||
*/
|
||||
specVersion: string;
|
||||
|
||||
/**
|
||||
* @description The tip for this transaction, in hex
|
||||
*/
|
||||
tip: string;
|
||||
|
||||
/**
|
||||
* @description The version of the extrinsic we are dealing with
|
||||
*/
|
||||
version: number;
|
||||
}
|
||||
|
||||
export interface SignerPayloadRawBase {
|
||||
/**
|
||||
* @description The hex-encoded data for this request
|
||||
*/
|
||||
data: string;
|
||||
|
||||
/**
|
||||
* @description The type of the contained data
|
||||
*/
|
||||
type?: 'bytes' | 'payload';
|
||||
}
|
||||
|
||||
export interface SignerPayloadRaw extends SignerPayloadRawBase {
|
||||
/**
|
||||
* @description The ss-58 encoded address
|
||||
*/
|
||||
address: string;
|
||||
|
||||
/**
|
||||
* @description The type of the contained data
|
||||
*/
|
||||
type: 'bytes' | 'payload';
|
||||
}
|
||||
|
||||
export interface SignerResult {
|
||||
/**
|
||||
* @description The id for this request
|
||||
@@ -314,7 +238,7 @@ export interface Signer {
|
||||
/**
|
||||
* @description signs an extrinsic payload from a serialized form
|
||||
*/
|
||||
signPayload?: (payload: SignerPayload) => Promise<SignerResult>;
|
||||
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
|
||||
|
||||
/**
|
||||
* @description signs a raw payload, only the bytes data as supplied
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Signer, SignerPayload, SignerResult, SignerPayloadRaw } from '@polkadot/api/types';
|
||||
import { Signer, SignerResult } from '@polkadot/api/types';
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
||||
import { SignerPayloadJSON, SignerPayloadRaw } from '@polkadot/types/types';
|
||||
|
||||
let id = 0;
|
||||
|
||||
@@ -20,7 +21,7 @@ export class SingleAccountSigner implements Signer {
|
||||
this.signDelay = signDelay;
|
||||
}
|
||||
|
||||
public async signPayload (payload: SignerPayload): Promise<SignerResult> {
|
||||
public async signPayload (payload: SignerPayloadJSON): Promise<SignerResult> {
|
||||
if (payload.address !== this.keyringPair.address) {
|
||||
throw new Error('does not have the keyringPair');
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageData, StorageHasher, StorageKey, Text, Type, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { InclusionHeight, Uncle, UncleEntryItem } from './interfaces/authorship';
|
||||
import { RawAuraPreDigest } from './interfaces/aura';
|
||||
import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, RawBabePreDigest, RawBabePreDigestPrimary, RawBabePreDigestSecondary, SlotNumber } from './interfaces/babe';
|
||||
@@ -241,6 +241,9 @@ export interface InterfaceRegistry {
|
||||
SignedBlock: SignedBlock;
|
||||
'Option<SignedBlock>': Option<SignedBlock>;
|
||||
'Vec<SignedBlock>': Vec<SignedBlock>;
|
||||
SignerPayload: SignerPayload;
|
||||
'Option<SignerPayload>': Option<SignerPayload>;
|
||||
'Vec<SignerPayload>': Vec<SignerPayload>;
|
||||
ValidatorId: ValidatorId;
|
||||
'Option<ValidatorId>': Option<ValidatorId>;
|
||||
'Vec<ValidatorId>': Vec<ValidatorId>;
|
||||
|
||||
@@ -52,6 +52,7 @@ export default {
|
||||
block: 'Block',
|
||||
justification: 'Justification'
|
||||
},
|
||||
SignerPayload: 'GenericSignerPayload',
|
||||
ValidatorId: 'AccountId',
|
||||
Weight: 'u32',
|
||||
WeightMultiplier: 'Fixed64',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import { Codec } from '../../types';
|
||||
import { Compact, Struct } from '../../codec';
|
||||
import { Bytes, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericCall, GenericConsensusEngineId, GenericDigest, GenericDigestItem, GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericExtrinsicPayloadUnknown, GenericExtrinsicPayloadV1, GenericExtrinsicPayloadV2, GenericExtrinsicPayloadV3, GenericExtrinsicUnknown, GenericExtrinsicV1, GenericExtrinsicV2, GenericExtrinsicV3, GenericImmortalEra, GenericMortalEra, GenericOrigin, H256, H512, Null, StorageData, StorageKey, u128, u32, u64 } from '../../primitive';
|
||||
import { Bytes, Fixed64, GenericAccountId, GenericAccountIndex, GenericAddress, GenericBlock, GenericCall, GenericConsensusEngineId, GenericDigest, GenericDigestItem, GenericExtrinsic, GenericExtrinsicEra, GenericExtrinsicPayload, GenericExtrinsicPayloadUnknown, GenericExtrinsicPayloadV1, GenericExtrinsicPayloadV2, GenericExtrinsicPayloadV3, GenericExtrinsicUnknown, GenericExtrinsicV1, GenericExtrinsicV2, GenericExtrinsicV3, GenericImmortalEra, GenericMortalEra, GenericOrigin, GenericSignerPayload, H256, H512, Null, StorageData, StorageKey, u128, u32, u64 } from '../../primitive';
|
||||
|
||||
/** GenericAccountId */
|
||||
export type AccountId = GenericAccountId;
|
||||
@@ -159,6 +159,9 @@ export interface SignedBlock extends Struct {
|
||||
readonly justification: Justification;
|
||||
}
|
||||
|
||||
/** GenericSignerPayload */
|
||||
export type SignerPayload = GenericSignerPayload;
|
||||
|
||||
/** Signature */
|
||||
export type Sr25519Signature = Signature;
|
||||
|
||||
|
||||
+10
-9
@@ -2,13 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Address, Balance, BlockNumber, Call, ExtrinsicEra, Hash, Index, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { Constructor } from '@polkadot/types/types';
|
||||
import { SignerPayload, SignerPayloadRaw } from './types';
|
||||
import { Address, Balance, BlockNumber, Call, ExtrinsicEra, Hash, Index, RuntimeVersion } from '../../interfaces';
|
||||
import Compact from '../../codec/Compact';
|
||||
import Struct from '../../codec/Struct';
|
||||
import { createType } from '../../codec';
|
||||
import { Codec, Constructor, ISignerPayload, SignerPayloadJSON, SignerPayloadRaw } from '../../types';
|
||||
import u8 from '../U8';
|
||||
|
||||
import { createType, Compact, Struct, u8 } from '@polkadot/types';
|
||||
|
||||
export interface SignerPayloadType {
|
||||
export interface SignerPayloadType extends Codec {
|
||||
address: Address;
|
||||
blockHash: Hash;
|
||||
blockNumber: BlockNumber;
|
||||
@@ -33,14 +34,14 @@ const _Payload: Constructor<SignerPayloadType> = Struct.with({
|
||||
nonce: 'Compact<Index>',
|
||||
runtimeVersion: 'RuntimeVersion',
|
||||
tip: 'Compact<Balance>',
|
||||
version: u8
|
||||
version: 'u8'
|
||||
}) as any;
|
||||
|
||||
export default class Payload extends _Payload {
|
||||
export default class SignerPayload extends _Payload implements ISignerPayload {
|
||||
/**
|
||||
* @description Creates an representation of the structure as an ISignerPayload JSON
|
||||
*/
|
||||
public toPayload (): SignerPayload {
|
||||
public toPayload (): SignerPayloadJSON {
|
||||
const { address, blockHash, blockNumber, era, genesisHash, method, nonce, runtimeVersion: { specVersion }, tip, version } = this;
|
||||
|
||||
return {
|
||||
@@ -13,3 +13,4 @@ export { default as GenericExtrinsicV2 } from './v2/Extrinsic';
|
||||
export { default as GenericExtrinsicPayloadV2 } from './v2/ExtrinsicPayload';
|
||||
export { default as GenericExtrinsicV3 } from './v3/Extrinsic';
|
||||
export { default as GenericExtrinsicPayloadV3 } from './v3/ExtrinsicPayload';
|
||||
export { default as GenericSignerPayload } from './SignerPayload';
|
||||
|
||||
@@ -216,3 +216,85 @@ export interface IExtrinsic extends IExtrinsicSignable<IExtrinsic>, ExtrinsicSig
|
||||
readonly type: number;
|
||||
readonly version: number;
|
||||
}
|
||||
|
||||
export interface SignerPayloadJSON {
|
||||
/**
|
||||
* @description The ss-58 encoded address
|
||||
*/
|
||||
address: string;
|
||||
|
||||
/**
|
||||
* @description The checkpoint hash of the block, in hex
|
||||
*/
|
||||
blockHash: string;
|
||||
|
||||
/**
|
||||
* @description The checkpoint block number, in hex
|
||||
*/
|
||||
blockNumber: string;
|
||||
|
||||
/**
|
||||
* @description The era for this transaction, in hex
|
||||
*/
|
||||
era: string;
|
||||
|
||||
/**
|
||||
* @description The genesis hash of the chain, in hex
|
||||
*/
|
||||
genesisHash: string;
|
||||
|
||||
/**
|
||||
* @description The encoded method (with arguments) in hex
|
||||
*/
|
||||
method: string;
|
||||
|
||||
/**
|
||||
* @description The nonce for this transaction, in hex
|
||||
*/
|
||||
nonce: string;
|
||||
|
||||
/**
|
||||
* @description The current spec version for the runtime
|
||||
*/
|
||||
specVersion: string;
|
||||
|
||||
/**
|
||||
* @description The tip for this transaction, in hex
|
||||
*/
|
||||
tip: string;
|
||||
|
||||
/**
|
||||
* @description The version of the extrinsic we are dealing with
|
||||
*/
|
||||
version: number;
|
||||
}
|
||||
|
||||
export interface SignerPayloadRawBase {
|
||||
/**
|
||||
* @description The hex-encoded data for this request
|
||||
*/
|
||||
data: string;
|
||||
|
||||
/**
|
||||
* @description The type of the contained data
|
||||
*/
|
||||
type?: 'bytes' | 'payload';
|
||||
}
|
||||
|
||||
export interface SignerPayloadRaw extends SignerPayloadRawBase {
|
||||
/**
|
||||
* @description The ss-58 encoded address
|
||||
*/
|
||||
address: string;
|
||||
|
||||
/**
|
||||
* @description The type of the contained data
|
||||
*/
|
||||
type: 'bytes' | 'payload';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface ISignerPayload {
|
||||
toPayload (): SignerPayloadJSON;
|
||||
toRaw (): SignerPayloadRaw;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user