Switch mortal default to 5mins (defaults) (#1112)

* Switch mortal default to 5mins (defaults)

* Expose era on raw payload
This commit is contained in:
Jaco Greeff
2019-07-12 15:49:43 +02:00
committed by GitHub
parent 4b0d727e56
commit 271691a52a
2 changed files with 25 additions and 17 deletions
+8 -7
View File
@@ -4,11 +4,11 @@
import { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Header, Index, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
import { ApiInterface$Rx, ApiTypes, Signer } from './types';
import { ApiInterface$Rx, ApiTypes } from './types';
import { Observable, combineLatest, of } from 'rxjs';
import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';
import { assert, isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
import ApiBase from './Base';
import filterEvents from './util/filterEvents';
@@ -45,7 +45,8 @@ type SignerOptions = {
};
// pick a default - in the case of 4s blocktimes, this translates to 60 seconds
const DEFAULT_MORTAL_LENGTH = 15;
const ONE_MINUTE = 15;
const DEFAULT_MORTAL_LENGTH = 5 * ONE_MINUTE;
export class SubmittableResult implements ISubmittableResult {
readonly events: Array<EventRecord>;
@@ -250,13 +251,13 @@ export default function createSubmittableExtrinsic<ApiType> (
if (isKeyringPair) {
this.sign(account as IKeyringPair, { ...options, ...eraOptions, nonce });
} else {
assert(api.signer, 'no signer exists');
updateId = await (api.signer as Signer).sign(_extrinsic, address, {
} else if (api.signer) {
updateId = await api.signer.sign(_extrinsic, address, {
...expandOptions({ ...options, ...eraOptions, nonce }),
genesisHash: api.genesisHash
});
} else {
throw new Error('no signer exists');
}
}),
switchMap(() => {
+17 -10
View File
@@ -44,7 +44,7 @@ function sign (signerPair: IKeyringPair, u8a: Uint8Array): Uint8Array {
export default class SignaturePayload extends Struct {
protected _signature?: Uint8Array;
constructor (value?: SignaturePayloadValue | Uint8Array) {
public constructor (value?: SignaturePayloadValue | Uint8Array) {
super({
nonce: Nonce,
method: Method,
@@ -56,42 +56,42 @@ export default class SignaturePayload extends Struct {
/**
* @description `true` if the payload refers to a valid signature
*/
get isSigned (): boolean {
public get isSigned (): boolean {
return !!(this._signature && this._signature.length === 64);
}
/**
* @description The block [[Hash]] the signature applies to (mortal/immortal)
*/
get blockHash (): Hash {
public get blockHash (): Hash {
return this.get('blockHash') as Hash;
}
/**
* @description The [[Method]] contained in the payload
*/
get method (): Method {
public get method (): Method {
return this.get('method') as Method;
}
/**
* @description The [[ExtrinsicEra]]
*/
get era (): ExtrinsicEra {
public get era (): ExtrinsicEra {
return this.get('era') as ExtrinsicEra;
}
/**
* @description The [[Nonce]]
*/
get nonce (): Nonce {
public get nonce (): Nonce {
return this.get('nonce') as Nonce;
}
/**
* @description The raw signature as a `Uint8Array`
*/
get signature (): Uint8Array {
public get signature (): Uint8Array {
if (!this.isSigned) {
throw new Error('Transaction is not signed');
}
@@ -102,7 +102,7 @@ export default class SignaturePayload extends Struct {
/**
* @description Sign the payload with the keypair
*/
sign (signerPair: IKeyringPair, version?: RuntimeVersion): Uint8Array {
public sign (signerPair: IKeyringPair, version?: RuntimeVersion): Uint8Array {
this._signature = sign(signerPair, this.toU8a());
return this._signature;
@@ -115,7 +115,7 @@ export default class SignaturePayload extends Struct {
* A version of [[SignaturePayload]] where it does not rely on [[Method]] being initalized with metadata. When constructing, it treats the [[Method]] as a raw stream of bytes, so will always apply the signature over this without any additional checking. Unlike the [[SignaturePayload]], it assumed that you will only construct and sign, thereby providing no insigt into constructed values
*/
export class SignaturePayloadRaw extends Struct {
constructor (value?: any) {
public constructor (value?: any) {
super({
nonce: Nonce,
method: U8a,
@@ -124,10 +124,17 @@ export class SignaturePayloadRaw extends Struct {
}, value);
}
/**
* @description The [[ExtrinsicEra]]
*/
public get era (): ExtrinsicEra {
return this.get('era') as ExtrinsicEra;
}
/**
* @description Sign the payload with the keypair
*/
sign (signerPair: IKeyringPair): Uint8Array {
public sign (signerPair: IKeyringPair): Uint8Array {
return sign(signerPair, this.toU8a());
}
}