Skip to content

Commit

Permalink
Change versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
TarikGul committed Sep 20, 2024
1 parent 13b40c5 commit d92fa6e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 93 deletions.
4 changes: 3 additions & 1 deletion packages/types/src/extrinsic/v5/Extrinsic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type { ExtrinsicOptions } from '../types.js';
import { Struct } from '@polkadot/types-codec';
import { isU8a } from '@polkadot/util';

export const EXTRINSIC_VERSION = 5;

export interface ExtrinsicValueV5 {
method?: Call;
signature?: ExtrinsicSignatureV5;
Expand Down Expand Up @@ -74,7 +76,7 @@ export class GenericExtrinsicV5 extends Struct implements IExtrinsicV5Impl {
* @description The version for the signature
*/
public get version (): number {
return this.getT('version');
return EXTRINSIC_VERSION;
}

/**
Expand Down
100 changes: 8 additions & 92 deletions packages/types/src/extrinsic/v5/ExtrinsicPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,25 @@
// SPDX-License-Identifier: Apache-2.0

import type { SignOptions } from '@polkadot/keyring/types';
import type { Hash, MultiLocation } from '@polkadot/types/interfaces';
import type { Bytes } from '@polkadot/types-codec';
import type { Inspect, Registry } from '@polkadot/types-codec/types';
import type { Registry } from '@polkadot/types-codec/types';
import type { HexString } from '@polkadot/util/types';
import type { BlockHash } from '../../interfaces/chain/index.js';
import type { ExtrinsicEra } from '../../interfaces/extrinsics/index.js';
import type { ExtrinsicPayloadValue, ICompact, IKeyringPair, INumber, IOption } from '../../types/index.js';
import type { ExtrinsicPayloadValue, IKeyringPair } from '../../types/index.js';

import { Enum, Struct } from '@polkadot/types-codec';
import { objectSpread } from '@polkadot/util';
import { Enum } from '@polkadot/types-codec';

import { GenericExtrinsicPayloadV4 } from '../v4/ExtrinsicPayload.js';

/**
* @name GenericExtrinsicPayloadV5
* @description
* A signing payload for an [[Extrinsic]]. For the final encoding, it is
* variable length based on the contents included
*/
export class GenericExtrinsicPayloadV5 extends Struct {
export class GenericExtrinsicPayloadV5 extends GenericExtrinsicPayloadV4 {
#signOptions: SignOptions;

constructor (registry: Registry, value?: ExtrinsicPayloadValue | Uint8Array | HexString) {
super(registry, objectSpread(
{ method: 'Bytes' },
registry.getSignedExtensionTypes(),
registry.getSignedExtensionExtra()
), value);
super(registry, value);

// Do detection for the type of extrinsic, in the case of MultiSignature
// this is an enum, in the case of AnySignature, this is a Hash only
Expand All @@ -37,87 +30,10 @@ export class GenericExtrinsicPayloadV5 extends Struct {
};
}

/**
* @description Returns a breakdown of the hex encoding for this Codec
*/
public override inspect (): Inspect {
return super.inspect({ method: true });
}

/**
* @description The block [[BlockHash]] the signature applies to (mortal/immortal)
*/
public get blockHash (): BlockHash {
return this.getT('blockHash');
}

/**
* @description The [[ExtrinsicEra]]
*/
public get era (): ExtrinsicEra {
return this.getT('era');
}

/**
* @description The genesis [[BlockHash]] the signature applies to (mortal/immortal)
*/
public get genesisHash (): BlockHash {
return this.getT('genesisHash');
}

/**
* @description The [[Bytes]] contained in the payload
*/
public get method (): Bytes {
return this.getT('method');
}

/**
* @description The [[Index]]
*/
public get nonce (): ICompact<INumber> {
return this.getT('nonce');
}

/**
* @description The specVersion for this signature
*/
public get specVersion (): INumber {
return this.getT('specVersion');
}

/**
* @description The tip [[Balance]]
*/
public get tip (): ICompact<INumber> {
return this.getT('tip');
}

/**
* @description The transactionVersion for this signature
*/
public get transactionVersion (): INumber {
return this.getT('transactionVersion');
}

/**
* @description The (optional) asset id for this signature for chains that support transaction fees in assets
*/
public get assetId (): IOption<INumber | MultiLocation> {
return this.getT('assetId');
}

/**
* @description The (optional) asset id for this signature for chains that support transaction fees in assets
*/
public get metadataHash (): IOption<Hash> {
return this.getT('metadataHash');
}

/**
* @description Sign the payload with the keypair
*/
public sign (signerPair: IKeyringPair): Uint8Array {
public override sign (signerPair: IKeyringPair): Uint8Array {
// NOTE The `toU8a({ method: true })` argument is absolutely critical, we
// don't want the method (Bytes) to have the length prefix included. This
// means that the data-as-signed is un-decodable, but is also doesn't need
Expand Down

0 comments on commit d92fa6e

Please sign in to comment.