From cc4e0c83a38627dadc5439a069453c306f4afc87 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 12 Jul 2019 17:34:15 +0200 Subject: [PATCH] Expose blockNumber to external signers (useful in eras) (#1114) --- packages/api/src/SubmittableExtrinsic.ts | 12 +++++++----- packages/api/src/types.ts | 8 +++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/api/src/SubmittableExtrinsic.ts b/packages/api/src/SubmittableExtrinsic.ts index 7eeaa99a5b..a6afad362a 100644 --- a/packages/api/src/SubmittableExtrinsic.ts +++ b/packages/api/src/SubmittableExtrinsic.ts @@ -6,6 +6,7 @@ import { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types'; import { ApiInterface$Rx, ApiTypes } from './types'; +import BN from 'bn.js'; import { Observable, combineLatest, of } from 'rxjs'; import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators'; import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util'; @@ -38,11 +39,11 @@ type SubmittableResultValue = { status: ExtrinsicStatus; }; -type SignerOptions = { - blockHash: AnyU8a, - era?: IExtrinsicEra | number, - nonce: AnyNumber -}; +interface SignerOptions { + blockHash: AnyU8a; + era?: IExtrinsicEra | number; + nonce: AnyNumber; +} // pick a default - in the case of 4s blocktimes, this translates to 60 seconds const ONE_MINUTE = 15; @@ -254,6 +255,7 @@ export default function createSubmittableExtrinsic ( } else if (api.signer) { updateId = await api.signer.sign(_extrinsic, address, { ...expandOptions({ ...options, ...eraOptions, nonce }), + blockNumber: header ? header.blockNumber : new BN(0), genesisHash: api.genesisHash }); } else { diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 23baf7bf40..ae9282847e 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -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 BN from 'bn.js'; import { Observable } from 'rxjs'; import { DeriveCustom } from '@polkadot/api-derive'; import { Constants } from '@polkadot/api-metadata/consts/fromMetadata/types'; @@ -216,9 +217,10 @@ export type ApiInterface$Events = ProviderInterface$Emitted | 'ready'; export type ApiTypes = 'promise' | 'rxjs'; -export type SignerOptions = SignatureOptions & { - genesisHash: Hash -}; +export interface SignerOptions extends SignatureOptions { + blockNumber: BN; + genesisHash: Hash; +} export interface Signer { /**