Make era required on raw signature injection (#1135)
This commit is contained in:
@@ -2,7 +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 { AnyNumber, AnyU8a, ArgsDef, Codec, IExtrinsic, IKeyringPair, SignatureOptions } from '../types';
|
||||
import { AnyNumber, AnyU8a, ArgsDef, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '../types';
|
||||
|
||||
import { assert, isHex, isU8a, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -179,7 +179,7 @@ export default class Extrinsic extends Base<ExtrinsicV1> implements IExtrinsic,
|
||||
/**
|
||||
* @description Add an [[ExtrinsicSignature]] to the extrinsic (already generated)
|
||||
*/
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era?: Uint8Array): Extrinsic {
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era: Uint8Array | IExtrinsicEra): Extrinsic {
|
||||
this.raw.addSignature(signer, signature, nonce, era);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -62,6 +62,10 @@ export class MortalEra extends Tuple {
|
||||
} else if (Array.isArray(value)) {
|
||||
return MortalEra.decodeMortalEra(new Uint8Array(value));
|
||||
} else if (isU8a(value)) {
|
||||
if (value.length === 0) {
|
||||
return [new U64(), new U64()];
|
||||
}
|
||||
|
||||
const first = u8aToBn(value.subarray(0, 1)).toNumber();
|
||||
const second = u8aToBn(value.subarray(1, 2)).toNumber();
|
||||
const encoded: number = first + (second << 8);
|
||||
|
||||
@@ -2,7 +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 { AnyNumber, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../types';
|
||||
import { AnyNumber, IExtrinsicEra, IExtrinsicSignature, IKeyringPair, SignatureOptions } from '../types';
|
||||
|
||||
import Struct from '../codec/Struct';
|
||||
import Address from '../primitive/Address';
|
||||
@@ -134,7 +134,7 @@ export default class ExtrinsicSignature extends Struct implements IExtrinsicSign
|
||||
/**
|
||||
* @description Adds a raw signature
|
||||
*/
|
||||
public addSignature (_signer: Address | Uint8Array | string, _signature: Uint8Array | string, _nonce: AnyNumber, _era: Uint8Array | ExtrinsicEra = IMMORTAL_ERA): ExtrinsicSignature {
|
||||
public addSignature (_signer: Address | Uint8Array | string, _signature: Uint8Array | string, _nonce: AnyNumber, _era: Uint8Array | IExtrinsicEra): ExtrinsicSignature {
|
||||
const signer = new Address(_signer);
|
||||
const nonce = new Nonce(_nonce);
|
||||
const era = new ExtrinsicEra(_era);
|
||||
|
||||
@@ -2,7 +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 { AnyNumber, ArgsDef, Codec, IExtrinsic, IKeyringPair, SignatureOptions } from '../types';
|
||||
import { AnyNumber, ArgsDef, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '../types';
|
||||
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
@@ -124,7 +124,7 @@ export default class ExtrinsicV1 extends Struct implements IExtrinsic {
|
||||
/**
|
||||
* @description Add an [[ExtrinsicSignature]] to the extrinsic (already generated)
|
||||
*/
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era?: Uint8Array): ExtrinsicV1 {
|
||||
public addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era: Uint8Array | IExtrinsicEra): ExtrinsicV1 {
|
||||
this.signature.addSignature(signer, signature, nonce, era);
|
||||
|
||||
return this;
|
||||
|
||||
@@ -24,7 +24,7 @@ export { default as ContractStorageKey } from './ContractStorageKey';
|
||||
export { default as EraIndex } from './EraIndex';
|
||||
export { default as Exposure } from './Exposure';
|
||||
export { default as Extrinsic } from './Extrinsic';
|
||||
export { default as ExtrinsicEra } from './ExtrinsicEra';
|
||||
export { default as ExtrinsicEra, MortalEra, ImmortalEra } from './ExtrinsicEra';
|
||||
export { default as ExtrinsicSignature } from './ExtrinsicSignature';
|
||||
// NOTE Only used internally, exported as PendingExtrinsics
|
||||
// export { default as Extrinsics } from './Extrinsics';
|
||||
|
||||
@@ -161,6 +161,6 @@ export interface IExtrinsic extends IMethod {
|
||||
isSigned: boolean;
|
||||
method: Method;
|
||||
signature: IExtrinsicSignature;
|
||||
addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era?: Uint8Array): IExtrinsic;
|
||||
addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, nonce: AnyNumber, era: Uint8Array | IExtrinsicEra): IExtrinsic;
|
||||
sign (account: IKeyringPair, options: SignatureOptions): IExtrinsic;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user