Cater for Check{Spec, Tx}Version extensions (#2270)
* Cater for Check{Spec, Tx}Version extensions
* Fix tests
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
- Ensure metadata is only requested once upon startup (bypass on upgrade subscriptions)
|
||||
- Expand testing around `ExtrinsicEra` construction
|
||||
- Expand `Registry` to direct access to available signed extensions (in addition to types)
|
||||
- Cater for new `CheckSpecVersion` and `CheckTxVersion` signed extensions (with `SignerPayload` adjustments)
|
||||
|
||||
# 1.13.1 May 6, 2020
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ describe('extrinsics', (): void => {
|
||||
implName: 'test',
|
||||
implVersion: new BN(123),
|
||||
specName: 'test',
|
||||
specVersion: new BN(123)
|
||||
specVersion: new BN(123),
|
||||
transactionVersion: new BN(123)
|
||||
}
|
||||
}).toHex()
|
||||
).toEqual(
|
||||
|
||||
@@ -24,6 +24,7 @@ describe('SignerPayload', (): void => {
|
||||
nonce: '0x00001234',
|
||||
specVersion: '0x00000006',
|
||||
tip: '0x00000000000000000000000000005678',
|
||||
transactionVersion: '0x00000007',
|
||||
version: 3
|
||||
};
|
||||
|
||||
@@ -50,6 +51,7 @@ describe('SignerPayload', (): void => {
|
||||
nonce: '0x00001234',
|
||||
specVersion: '0x00000000',
|
||||
tip: '0x00000000000000000000000000005678',
|
||||
transactionVersion: '0x00000000',
|
||||
version: 3
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,7 +49,7 @@ export default class SignerPayload extends _Payload implements ISignerPayload {
|
||||
* @description Creates an representation of the structure as an ISignerPayload JSON
|
||||
*/
|
||||
public toPayload (): SignerPayloadJSON {
|
||||
const { address, blockHash, blockNumber, era, genesisHash, method, nonce, runtimeVersion: { specVersion }, tip, version } = this;
|
||||
const { address, blockHash, blockNumber, era, genesisHash, method, nonce, runtimeVersion: { specVersion, transactionVersion }, tip, version } = this;
|
||||
|
||||
return {
|
||||
address: address.toString(),
|
||||
@@ -61,6 +61,7 @@ export default class SignerPayload extends _Payload implements ISignerPayload {
|
||||
nonce: nonce.toHex(),
|
||||
specVersion: specVersion.toHex(),
|
||||
tip: tip.toHex(),
|
||||
transactionVersion: transactionVersion.toHex(),
|
||||
version: version.toNumber()
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,6 +35,18 @@ export default {
|
||||
nonce: 'Compact<Index>'
|
||||
}
|
||||
},
|
||||
CheckSpecVersion: {
|
||||
extra: {
|
||||
specVersion: 'u32'
|
||||
},
|
||||
types: {}
|
||||
},
|
||||
CheckTxVersion: {
|
||||
extra: {
|
||||
transactionVersion: 'u32'
|
||||
},
|
||||
types: {}
|
||||
},
|
||||
CheckVersion: {
|
||||
extra: {
|
||||
specVersion: 'u32'
|
||||
|
||||
@@ -131,8 +131,10 @@ export default class ExtrinsicSignatureV1 extends Struct implements IExtrinsicSi
|
||||
genesisHash,
|
||||
method: method.toHex(),
|
||||
nonce,
|
||||
specVersion: 0, // unused for v1, added for compat
|
||||
tip: 0
|
||||
// unused for v1, added for compat
|
||||
specVersion: 0,
|
||||
tip: 0,
|
||||
transactionVersion: 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ describe('ExtrinsicV2', (): void => {
|
||||
implName: 'test',
|
||||
implVersion: new BN(123),
|
||||
specName: 'test',
|
||||
specVersion: new BN(123)
|
||||
specVersion: new BN(123),
|
||||
transactionVersion: new BN(123)
|
||||
},
|
||||
tip: 2
|
||||
}).toHex()
|
||||
|
||||
@@ -127,8 +127,10 @@ export default class ExtrinsicSignatureV2 extends Struct implements IExtrinsicSi
|
||||
genesisHash,
|
||||
method: method.toHex(),
|
||||
nonce,
|
||||
specVersion: 0, // unused for v2
|
||||
tip: tip || 0
|
||||
// unused for v2
|
||||
specVersion: 0,
|
||||
tip: tip || 0,
|
||||
transactionVersion: 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ describe('ExtrinsicV3', (): void => {
|
||||
implName: 'test',
|
||||
implVersion: new BN(123),
|
||||
specName: 'test',
|
||||
specVersion: new BN(123)
|
||||
specVersion: new BN(123),
|
||||
transactionVersion: new BN(123)
|
||||
},
|
||||
tip: 2
|
||||
}).toHex()
|
||||
|
||||
@@ -39,7 +39,8 @@ export default class ExtrinsicSignatureV3 extends ExtrinsicSignatureV2 {
|
||||
method: method.toHex(),
|
||||
nonce,
|
||||
specVersion,
|
||||
tip: tip || 0
|
||||
tip: tip || 0,
|
||||
transactionVersion: 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ describe('ExtrinsicV4', (): void => {
|
||||
implName: 'test',
|
||||
implVersion: new BN(123),
|
||||
specName: 'test',
|
||||
specVersion: new BN(123)
|
||||
specVersion: new BN(123),
|
||||
transactionVersion: new BN(123)
|
||||
},
|
||||
tip: 2
|
||||
}).toHex()
|
||||
|
||||
@@ -76,6 +76,13 @@ export default class ExtrinsicPayloadV4 extends Struct {
|
||||
return this.get('tip') as Compact<Balance>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The transactionVersion for this signature
|
||||
*/
|
||||
public get transactionVersion (): u32 {
|
||||
return this.get('transactionVersion') as u32;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Sign the payload with the keypair
|
||||
*/
|
||||
|
||||
@@ -125,7 +125,7 @@ export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSi
|
||||
/**
|
||||
* @description Creates a payload from the supplied options
|
||||
*/
|
||||
public createPayload (method: Call, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion }, tip }: SignatureOptions): ExtrinsicPayloadV4 {
|
||||
public createPayload (method: Call, { blockHash, era, genesisHash, nonce, runtimeVersion: { specVersion, transactionVersion }, tip }: SignatureOptions): ExtrinsicPayloadV4 {
|
||||
return new ExtrinsicPayloadV4(this.registry, {
|
||||
blockHash,
|
||||
era: era || IMMORTAL_ERA,
|
||||
@@ -133,7 +133,8 @@ export default class ExtrinsicSignatureV4 extends Struct implements IExtrinsicSi
|
||||
method: method.toHex(),
|
||||
nonce,
|
||||
specVersion,
|
||||
tip: tip || 0
|
||||
tip: tip || 0,
|
||||
transactionVersion: transactionVersion || 0
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -82,6 +82,7 @@ export interface ExtrinsicPayloadValue {
|
||||
nonce: AnyNumber;
|
||||
specVersion: AnyNumber;
|
||||
tip: AnyNumber;
|
||||
transactionVersion: AnyNumber;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
@@ -165,6 +166,11 @@ export interface SignerPayloadJSON {
|
||||
*/
|
||||
tip: string;
|
||||
|
||||
/**
|
||||
* @description The current transaction version for the runtime
|
||||
*/
|
||||
transactionVersion: string;
|
||||
|
||||
/**
|
||||
* @description The version of the extrinsic we are dealing with
|
||||
*/
|
||||
|
||||
@@ -42,6 +42,7 @@ export interface IRuntimeVersion {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
readonly specName: String;
|
||||
readonly specVersion: BN;
|
||||
readonly transactionVersion: BN;
|
||||
}
|
||||
|
||||
// A type alias for [Type1, Type2] & Codec, representing a tuple (Type1, Type2)
|
||||
|
||||
Reference in New Issue
Block a user