Expose blockNumber to external signers (useful in eras) (#1114)

This commit is contained in:
Jaco Greeff
2019-07-12 17:34:15 +02:00
committed by GitHub
parent bda0815411
commit cc4e0c83a3
2 changed files with 12 additions and 8 deletions
+7 -5
View File
@@ -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<ApiType> (
} 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 {
+5 -3
View File
@@ -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 {
/**