Skip to content

Commit

Permalink
Cater for Check{Spec, Tx}Version extensions (#2270)
Browse files Browse the repository at this point in the history
* Cater for Check{Spec, Tx}Version extensions

* Fix tests
  • Loading branch information
jacogr authored May 12, 2020
1 parent 6b8a65e commit c9921f0
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion packages/metadata/src/Decorated/extrinsics/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/extrinsic/SignerPayload.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('SignerPayload', (): void => {
nonce: '0x00001234',
specVersion: '0x00000006',
tip: '0x00000000000000000000000000005678',
transactionVersion: '0x00000007',
version: 3
};

Expand All @@ -50,6 +51,7 @@ describe('SignerPayload', (): void => {
nonce: '0x00001234',
specVersion: '0x00000000',
tip: '0x00000000000000000000000000005678',
transactionVersion: '0x00000000',
version: 3
});
});
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/extrinsic/SignerPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()
};
}
Expand Down
12 changes: 12 additions & 0 deletions packages/types/src/extrinsic/signedExtensions/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export default {
nonce: 'Compact<Index>'
}
},
CheckSpecVersion: {
extra: {
specVersion: 'u32'
},
types: {}
},
CheckTxVersion: {
extra: {
transactionVersion: 'u32'
},
types: {}
},
CheckVersion: {
extra: {
specVersion: 'u32'
Expand Down
6 changes: 4 additions & 2 deletions packages/types/src/extrinsic/v1/ExtrinsicSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/extrinsic/v2/Extrinsic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions packages/types/src/extrinsic/v2/ExtrinsicSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/extrinsic/v3/Extrinsic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/extrinsic/v3/ExtrinsicSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default class ExtrinsicSignatureV3 extends ExtrinsicSignatureV2 {
method: method.toHex(),
nonce,
specVersion,
tip: tip || 0
tip: tip || 0,
transactionVersion: 0
});
}

Expand Down
3 changes: 2 additions & 1 deletion packages/types/src/extrinsic/v4/Extrinsic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions packages/types/src/extrinsic/v4/ExtrinsicPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions packages/types/src/extrinsic/v4/ExtrinsicSignature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ 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,
genesisHash,
method: method.toHex(),
nonce,
specVersion,
tip: tip || 0
tip: tip || 0,
transactionVersion: transactionVersion || 0
});
}

Expand Down
6 changes: 6 additions & 0 deletions packages/types/src/types/extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export interface ExtrinsicPayloadValue {
nonce: AnyNumber;
specVersion: AnyNumber;
tip: AnyNumber;
transactionVersion: AnyNumber;
}

// eslint-disable-next-line @typescript-eslint/interface-name-prefix
Expand Down Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/types/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c9921f0

Please sign in to comment.