diff --git a/packages/rpc-core/src/index.spec.ts b/packages/rpc-core/src/index.spec.ts index d390caa8d0..0e8d0212e0 100644 --- a/packages/rpc-core/src/index.spec.ts +++ b/packages/rpc-core/src/index.spec.ts @@ -21,7 +21,7 @@ describe('Api', (): void => { Object.keys(rpc).filter((key): boolean => !key.startsWith('_')) ).toEqual([ 'provider', 'mapping', 'sections', - 'account', 'author', 'chain', 'contracts', 'rpc', 'state', 'system' + 'account', 'author', 'chain', 'contracts', 'payment', 'rpc', 'state', 'system' ]); }); diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 5de4a4e7ee..c40a6e21d1 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -86,6 +86,8 @@ export default class Rpc implements RpcInterface { public readonly contracts!: RpcInterface['contracts']; + public readonly payment!: RpcInterface['payment']; + public readonly rpc!: RpcInterface['rpc']; public readonly state!: RpcInterface['state']; diff --git a/packages/rpc-core/src/jsonrpc.types.ts b/packages/rpc-core/src/jsonrpc.types.ts index cc0e5617d8..cabcd26756 100644 --- a/packages/rpc-core/src/jsonrpc.types.ts +++ b/packages/rpc-core/src/jsonrpc.types.ts @@ -6,7 +6,7 @@ import { Vec } from '@polkadot/types/codec'; import { Bytes, Metadata, StorageData, StorageKey, Text, u64 } from '@polkadot/types'; import { AccountId, BlockNumber, Extrinsic, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces/runtime'; import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts'; -import { ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; +import { ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; import { Codec, IExtrinsic } from '@polkadot/types/types'; export interface RpcInterface { @@ -32,6 +32,9 @@ export interface RpcInterface { contracts: { call(callRequest: ContractCallRequest, at?: Hash | Uint8Array | string): Observable; }; + payment: { + queryInfo(extrinsic: Bytes | Uint8Array | string, hash?: Hash | Uint8Array | string): Observable; + }; rpc: { methods(): Observable; }; diff --git a/packages/type-jsonrpc/src/account.ts b/packages/type-jsonrpc/src/account.ts index d14f1bbf5e..d2313f471e 100644 --- a/packages/type-jsonrpc/src/account.ts +++ b/packages/type-jsonrpc/src/account.ts @@ -21,7 +21,7 @@ const nextIndex: RpcMethodOpt = { const section = 'account'; /** - * @summary Calls to retrieve system info. + * @summary Calls to account-specific information. */ export default { isDeprecated: false, diff --git a/packages/type-jsonrpc/src/index.ts b/packages/type-jsonrpc/src/index.ts index dfc157ffdc..fbd5aab83e 100644 --- a/packages/type-jsonrpc/src/index.ts +++ b/packages/type-jsonrpc/src/index.ts @@ -8,6 +8,7 @@ import account from './account'; import author from './author'; import chain from './chain'; import contracts from './contracts'; +import payment from './payment'; import rpc from './rpc'; import state from './state'; import system from './system'; @@ -17,6 +18,7 @@ const interfaces: Record = { author, chain, contracts, + payment, rpc, state, system diff --git a/packages/type-jsonrpc/src/payment.ts b/packages/type-jsonrpc/src/payment.ts new file mode 100644 index 0000000000..ab6190dcd9 --- /dev/null +++ b/packages/type-jsonrpc/src/payment.ts @@ -0,0 +1,34 @@ +// Copyright 2017-2019 @polkadot/jsonrpc authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { RpcMethodOpt } from './types'; + +import createMethod from './create/method'; +import createParam from './create/param'; + +// NOTE order here is the same as in Rust, alphabetical below + +const queryInfo: RpcMethodOpt = { + description: 'Retrieves the fee information for an encoded extrinsic', + params: [ + createParam('extrinsic', 'Bytes'), + createParam('hash', 'Hash', { isOptional: true }) + ], + type: 'RuntimeDispatchInfo' +}; + +const section = 'payment'; + +/** + * @summary Calls to retrieve payment information. + */ +export default { + isDeprecated: false, + isHidden: false, + description: 'Methods that retrieves payment information, e.g. fee calculations', + section, + methods: { + queryInfo: createMethod(section, 'queryInfo', queryInfo) + } +}; diff --git a/packages/types/src/interfaceRegistry.ts b/packages/types/src/interfaceRegistry.ts index fb10b151af..a585843a51 100644 --- a/packages/types/src/interfaceRegistry.ts +++ b/packages/types/src/interfaceRegistry.ts @@ -3,7 +3,7 @@ import { Compact, Option, Vec } from '@polkadot/types/codec'; import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageData, StorageHasher, StorageKey, Text, Type, U256, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from '@polkadot/types/primitive'; -import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, MultiSignature, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; +import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, MultiSignature, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime'; import { InclusionHeight, Uncle, UncleEntryItem } from '@polkadot/types/interfaces/authorship'; import { RawAuraPreDigest } from '@polkadot/types/interfaces/aura'; import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, MaybeVrf, RawBabePreDigest, RawBabePreDigest0to159, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimary0to159, RawBabePreDigestSecondary, RawBabePreDigestSecondary0to159, SlotNumber, VrfData, VrfProof } from '@polkadot/types/interfaces/babe'; @@ -28,7 +28,7 @@ import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/t import { EthereumAddress } from '@polkadot/types/interfaces/claims'; import { AttestedCandidate, AuctionIndex, BalanceUpload, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidatorIndex, ValidityAttestation, ValidityVote, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains'; import { CallMetadataV0, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, ErrorMetadataV8, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, MapTypeV0, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MetadataV0, MetadataV1, ModuleConstantMetadataLatest, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleMetadataV0, ModuleMetadataV1, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, RuntimeModuleMetadataV0, StorageEntryModifierLatest, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageMetadataV0 } from '@polkadot/types/interfaces/metadata'; -import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; +import { ApiId, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, KeyValueOption, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/rpc'; export interface InterfaceRegistry { bool: bool; @@ -164,6 +164,9 @@ export interface InterfaceRegistry { DigestItem: DigestItem; 'Option': Option; 'Vec': Vec; + DispatchClass: DispatchClass; + 'Option': Option; + 'Vec': Vec; Extrinsic: Extrinsic; 'Option': Option; 'Vec': Vec; @@ -1059,6 +1062,9 @@ export interface InterfaceRegistry { RpcMethods: RpcMethods; 'Option': Option; 'Vec': Vec; + RuntimeDispatchInfo: RuntimeDispatchInfo; + 'Option': Option; + 'Vec': Vec; RuntimeVersionApi: RuntimeVersionApi; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/rpc/definitions.ts b/packages/types/src/interfaces/rpc/definitions.ts index 65c4be3eba..c88b2c4bd9 100644 --- a/packages/types/src/interfaces/rpc/definitions.ts +++ b/packages/types/src/interfaces/rpc/definitions.ts @@ -47,6 +47,11 @@ export default { version: 'u32', methods: 'Vec' }, + RuntimeDispatchInfo: { + weight: 'Weight', + class: 'DispatchClass', + partialFee: 'Balance' + }, RuntimeVersionApi: '(ApiId, u32)', RuntimeVersion: { specName: 'Text', diff --git a/packages/types/src/interfaces/rpc/types.ts b/packages/types/src/interfaces/rpc/types.ts index 6b819fc422..f223246ffc 100644 --- a/packages/types/src/interfaces/rpc/types.ts +++ b/packages/types/src/interfaces/rpc/types.ts @@ -4,7 +4,7 @@ import { Codec, ITuple } from '@polkadot/types/types'; import { Enum, Option, Struct, Vec } from '@polkadot/types/codec'; import { Bytes, StorageData, StorageKey, Text, bool, u32, u64, u8 } from '@polkadot/types/primitive'; -import { BlockNumber, Hash } from '@polkadot/types/interfaces/runtime'; +import { Balance, BlockNumber, DispatchClass, Hash, Weight } from '@polkadot/types/interfaces/runtime'; /** Uint8Array, Codec */ export interface ApiId extends Uint8Array, Codec {} @@ -96,6 +96,16 @@ export interface RpcMethods extends Struct { readonly methods: Vec; } +/** Struct */ +export interface RuntimeDispatchInfo extends Struct { + /** Weight */ + readonly weight: Weight; + /** DispatchClass */ + readonly class: DispatchClass; + /** Balance */ + readonly partialFee: Balance; +} + /** Struct */ export interface RuntimeVersion extends Struct { /** Text */ diff --git a/packages/types/src/interfaces/runtime/definitions.ts b/packages/types/src/interfaces/runtime/definitions.ts index 8b17fed4dd..b78f4f95e8 100644 --- a/packages/types/src/interfaces/runtime/definitions.ts +++ b/packages/types/src/interfaces/runtime/definitions.ts @@ -17,6 +17,9 @@ export default { ConsensusEngineId: 'GenericConsensusEngineId', Digest: 'GenericDigest', DigestItem: 'GenericDigestItem', + DispatchClass: { + _enum: ['Normal', 'Operational'] + }, Extrinsic: 'GenericExtrinsic', ExtrinsicEra: 'GenericExtrinsicEra', ExtrinsicPayload: 'GenericExtrinsicPayload', diff --git a/packages/types/src/interfaces/runtime/types.ts b/packages/types/src/interfaces/runtime/types.ts index 0428328860..94cb14ca00 100644 --- a/packages/types/src/interfaces/runtime/types.ts +++ b/packages/types/src/interfaces/runtime/types.ts @@ -47,6 +47,14 @@ export interface Digest extends GenericDigest {} /** GenericDigestItem */ export interface DigestItem extends GenericDigestItem {} +/** Enum */ +export interface DispatchClass extends Enum { + /** 0:: Normal */ + readonly isNormal: boolean; + /** 1:: Operational */ + readonly isOperational: boolean; +} + /** Uint8Array, Codec */ export interface EcdsaSignature extends Uint8Array, Codec {}