From af11444b72d8931da53fa9522130e8c8f5c13020 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sat, 21 Mar 2020 07:50:56 +0100 Subject: [PATCH] Update RPCs (babe, contracts) (#2074) * Update RPCs (babe, contracts) * Babe in rpc-core --- packages/api/src/augment/rpc.ts | 14 +++++++++++++- packages/rpc-core/src/index.ts | 2 ++ packages/types/src/augment/registry.ts | 5 ++++- packages/types/src/interfaces/babe/definitions.ts | 12 +++++++++++- packages/types/src/interfaces/babe/types.ts | 8 +++++++- .../types/src/interfaces/contracts/definitions.ts | 15 +++++++++++++++ 6 files changed, 52 insertions(+), 4 deletions(-) diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index 2b060856a2..ae564a35f9 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -2,9 +2,11 @@ /* eslint-disable */ import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types'; -import { Option, Vec } from '@polkadot/types/codec'; +import { HashMap, Option, Vec } from '@polkadot/types/codec'; import { Bytes, Null, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primitive'; import { Metadata } from '@polkadot/types'; +import { EpochAuthorship } from '@polkadot/types/interfaces/babe'; +import { AuthorityId } from '@polkadot/types/interfaces/consensus'; import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts'; import { CreatedBlock } from '@polkadot/types/interfaces/engine'; import { Extrinsic } from '@polkadot/types/interfaces/extrinsics'; @@ -56,6 +58,12 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { **/ submitExtrinsic: AugmentedRpc<(extrinsic: IExtrinsic) => Observable>; }; + babe: { + /** + * Returns data about which slots (primary or secondary) can be claimed in the current epoch with the keys in the keystore + **/ + epochAuthorship: AugmentedRpc<() => Observable>>; + }; chain: { /** * Get header and body of a relay chain block @@ -95,6 +103,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Returns the value under a specified storage key in a contract **/ getStorage: AugmentedRpc<(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>>; + /** + * Returns the projected time a given contract will be able to sustain paying its rent + **/ + rentProjection: AugmentedRpc<(address: AccountId | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable>>; }; engine: { /** diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 8112c4c960..2b6fb0b5b2 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -79,6 +79,8 @@ export default class Rpc implements RpcInterface { public readonly author!: RpcInterface['author']; + public readonly babe!: RpcInterface['babe']; + public readonly chain!: RpcInterface['chain']; public readonly contracts!: RpcInterface['contracts']; diff --git a/packages/types/src/augment/registry.ts b/packages/types/src/augment/registry.ts index 16ee10e75e..02053d518b 100644 --- a/packages/types/src/augment/registry.ts +++ b/packages/types/src/augment/registry.ts @@ -6,7 +6,7 @@ import { BitVec, Bytes, Data, Null, StorageKey, Text, Type, U256, Unconstructabl import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/types/interfaces/attestations'; import { RawAuraPreDigest } from '@polkadot/types/interfaces/aura'; import { UncleEntryItem } from '@polkadot/types/interfaces/authorship'; -import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, MaybeVrf, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondary, RawBabePreDigestSecondaryTo159, RawBabePreDigestTo159, SlotNumber, VrfData, VrfProof } from '@polkadot/types/interfaces/babe'; +import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, EpochAuthorship, MaybeVrf, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondary, RawBabePreDigestSecondaryTo159, RawBabePreDigestTo159, SlotNumber, VrfData, VrfProof } from '@polkadot/types/interfaces/babe'; import { AccountData, BalanceLock, BalanceLockTo212, Reasons, ReleasesBalances, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances'; import { EthereumAddress } from '@polkadot/types/interfaces/claims'; import { MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective'; @@ -292,6 +292,9 @@ declare module '@polkadot/types/types/registry' { 'Compact': Compact; 'Option': Option; 'Vec': Vec; + EpochAuthorship: EpochAuthorship; + 'Option': Option; + 'Vec': Vec; RawBabePreDigest: RawBabePreDigest; 'Option': Option; 'Vec': Vec; diff --git a/packages/types/src/interfaces/babe/definitions.ts b/packages/types/src/interfaces/babe/definitions.ts index 3e5021c39c..355e848c5f 100644 --- a/packages/types/src/interfaces/babe/definitions.ts +++ b/packages/types/src/interfaces/babe/definitions.ts @@ -5,13 +5,23 @@ import { Definitions } from '../../types'; export default { - rpc: {}, + rpc: { + epochAuthorship: { + description: 'Returns data about which slots (primary or secondary) can be claimed in the current epoch with the keys in the keystore', + params: [], + type: 'HashMap' + } + }, types: { BabeAuthorityWeight: 'u64', BabeBlockWeight: 'u32', MaybeVrf: 'Option', // TODO Remove as soon as merged and metadata static updated BabeWeight: 'u64', + EpochAuthorship: { + primary: 'Vec', + secondary: 'Vec' + }, RawBabePreDigest: { _enum: { Phantom: 'Null', // index starts at 1... empty slot at 0 diff --git a/packages/types/src/interfaces/babe/types.ts b/packages/types/src/interfaces/babe/types.ts index e052b6243c..df9c047e6a 100644 --- a/packages/types/src/interfaces/babe/types.ts +++ b/packages/types/src/interfaces/babe/types.ts @@ -1,7 +1,7 @@ // Auto-generated via `yarn polkadot-types-from-defs`, do not edit /* eslint-disable */ -import { Enum, Option, Struct, U8aFixed } from '@polkadot/types/codec'; +import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec'; import { u32, u64 } from '@polkadot/types/primitive'; /** @name BabeAuthorityWeight */ @@ -13,6 +13,12 @@ export interface BabeBlockWeight extends u32 {} /** @name BabeWeight */ export interface BabeWeight extends u64 {} +/** @name EpochAuthorship */ +export interface EpochAuthorship extends Struct { + readonly primary: Vec; + readonly secondary: Vec; +} + /** @name MaybeVrf */ export interface MaybeVrf extends Option {} diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index 76408aed0b..0c9126e6dc 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -39,6 +39,21 @@ export default { } ], type: 'Option' + }, + rentProjection: { + description: 'Returns the projected time a given contract will be able to sustain paying its rent', + params: [ + { + name: 'address', + type: 'AccountId' + }, + { + name: 'at', + type: 'BlockHash', + isOptional: true + } + ], + type: 'Option' } }, types: {