getTyped to cleanup this.get('...') (#4334)

* getTyped to cleanup this.get('...')

* shorten

* Adjust
This commit is contained in:
Jaco
2021-12-16 07:51:52 +02:00
committed by GitHub
parent 1113f6cfdd
commit 5c8bad5bb9
15 changed files with 77 additions and 74 deletions
+1 -5
View File
@@ -32,10 +32,6 @@ export class GenericEthereumAccountId extends U8aFixed {
super(registry, decodeAccountId(value), 160);
}
public static encode (value: Uint8Array): string {
return ethereumEncode(value);
}
/**
* @description Compares the value of the input to see if there is a match
*/
@@ -61,7 +57,7 @@ export class GenericEthereumAccountId extends U8aFixed {
* @description Returns the string representation of the value
*/
public override toString (): string {
return GenericEthereumAccountId.encode(this);
return ethereumEncode(this);
}
/**
+13 -14
View File
@@ -41,6 +41,18 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericEthereum
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length), true)]);
}
function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
return value instanceof GenericEthereumLookupSource
? value.inner
: value instanceof GenericEthereumAccountId || value instanceof GenericAccountIndex
? value
: isU8a(value) || Array.isArray(value) || isHex(value)
? decodeU8a(registry, u8aToU8a(value))
: isBn(value) || isNumber(value) || isBigInt(value)
? registry.createTypeUnsafe('AccountIndex', [value])
: decodeString(registry, value);
}
/**
* @name GenericEthereumLookupSource
* @description
@@ -51,20 +63,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericEthereum
*/
export class GenericEthereumLookupSource extends Base<GenericEthereumAccountId | GenericAccountIndex> {
constructor (registry: CodecRegistry, value: AnyAddress = new Uint8Array()) {
super(registry, GenericEthereumLookupSource._decodeAddress(registry, value));
}
/** @internal */
private static _decodeAddress (registry: CodecRegistry, value: AnyAddress): GenericEthereumAccountId | GenericAccountIndex {
return value instanceof GenericEthereumLookupSource
? value.inner
: value instanceof GenericEthereumAccountId || value instanceof GenericAccountIndex
? value
: isU8a(value) || Array.isArray(value) || isHex(value)
? decodeU8a(registry, u8aToU8a(value))
: isBn(value) || isNumber(value) || isBigInt(value)
? registry.createTypeUnsafe('AccountIndex', [value])
: decodeString(registry, value);
super(registry, decodeAddressOrIndex(registry, value));
}
/**
+11 -11
View File
@@ -64,47 +64,47 @@ export class GenericSignerPayload extends Struct implements ISignerPayload, Sign
}
get address (): Address {
return this.get('address') as Address;
return this.getT('address');
}
get blockHash (): Hash {
return this.get('blockHash') as Hash;
return this.getT('blockHash');
}
get blockNumber (): BlockNumber {
return this.get('blockNumber') as BlockNumber;
return this.getT('blockNumber');
}
get era (): ExtrinsicEra {
return this.get('era') as ExtrinsicEra;
return this.getT('era');
}
get genesisHash (): Hash {
return this.get('genesisHash') as Hash;
return this.getT('genesisHash');
}
get method (): Call {
return this.get('method') as Call;
return this.getT('method');
}
get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
return this.getT('nonce');
}
get runtimeVersion (): RuntimeVersion {
return this.get('runtimeVersion') as RuntimeVersion;
return this.getT('runtimeVersion');
}
get signedExtensions (): Vec<Text> {
return this.get('signedExtensions') as Vec<Text>;
return this.getT('signedExtensions');
}
get tip (): Compact<Balance> {
return this.get('tip') as Compact<Balance>;
return this.getT('tip');
}
get version (): u8 {
return this.get('version') as u8;
return this.getT('version');
}
/**
+2 -2
View File
@@ -63,14 +63,14 @@ export class GenericExtrinsicV4 extends Struct implements IExtrinsicImpl {
* @description The [[Call]] this extrinsic wraps
*/
public get method (): Call {
return this.get('method') as Call;
return this.getT('method');
}
/**
* @description The [[ExtrinsicSignatureV4]]
*/
public get signature (): ExtrinsicSignatureV4 {
return this.get('signature') as ExtrinsicSignatureV4;
return this.getT('signature');
}
/**
@@ -41,56 +41,56 @@ export class GenericExtrinsicPayloadV4 extends Struct {
* @description The block [[Hash]] the signature applies to (mortal/immortal)
*/
public get blockHash (): Hash {
return this.get('blockHash') as Hash;
return this.getT('blockHash');
}
/**
* @description The [[ExtrinsicEra]]
*/
public get era (): ExtrinsicEra {
return this.get('era') as ExtrinsicEra;
return this.getT('era');
}
/**
* @description The genesis [[Hash]] the signature applies to (mortal/immortal)
*/
public get genesisHash (): Hash {
return this.get('genesisHash') as Hash;
return this.getT('genesisHash');
}
/**
* @description The [[Bytes]] contained in the payload
*/
public get method (): Bytes {
return this.get('method') as Bytes;
return this.getT('method');
}
/**
* @description The [[Index]]
*/
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
return this.getT('nonce');
}
/**
* @description The specVersion for this signature
*/
public get specVersion (): u32 {
return this.get('specVersion') as u32;
return this.getT('specVersion');
}
/**
* @description The tip [[Balance]]
*/
public get tip (): Compact<Balance> {
return this.get('tip') as Compact<Balance>;
return this.getT('tip');
}
/**
* @description The transactionVersion for this signature
*/
public get transactionVersion (): u32 {
return this.get('transactionVersion') as u32;
return this.getT('transactionVersion');
}
/**
@@ -98,7 +98,7 @@ export class GenericExtrinsicPayloadV4 extends Struct {
* The (optional) asset id for this signature for chains that support transaction fees in assets
*/
public get assetId (): Option<AssetId> {
return this.get('assetId') as Option<AssetId>;
return this.getT('assetId');
}
/**
@@ -80,14 +80,14 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
* @description The [[ExtrinsicEra]] (mortal or immortal) this signature applies to
*/
public get era (): ExtrinsicEra {
return this.get('era') as ExtrinsicEra;
return this.getT('era');
}
/**
* @description The [[Index]] for the signature
*/
public get nonce (): Compact<Index> {
return this.get('nonce') as Compact<Index>;
return this.getT('nonce');
}
/**
@@ -102,21 +102,21 @@ export class GenericExtrinsicSignatureV4 extends Struct implements IExtrinsicSig
* @description The raw [[ExtrinsicSignature]]
*/
public get multiSignature (): ExtrinsicSignature {
return this.get('signature') as ExtrinsicSignature;
return this.getT('signature');
}
/**
* @description The [[Address]] that signed
*/
public get signer (): Address {
return this.get('signer') as Address;
return this.getT('signer');
}
/**
* @description The [[Balance]] tip
*/
public get tip (): Compact<Balance> {
return this.get('tip') as Compact<Balance>;
return this.getT('tip');
}
protected _injectSignature (signer: Address, signature: ExtrinsicSignature, payload: GenericExtrinsicPayloadV4): IExtrinsicSignature {
+2 -2
View File
@@ -47,7 +47,7 @@ export class GenericBlock extends Struct {
* @description The [[Extrinsic]] contained in the block
*/
public get extrinsics (): Vec<GenericExtrinsic> {
return this.get('extrinsics') as Vec<GenericExtrinsic>;
return this.getT('extrinsics');
}
/**
@@ -61,6 +61,6 @@ export class GenericBlock extends Struct {
* @description The [[Header]] of the block
*/
public get header (): Header {
return this.get('header') as Header;
return this.getT('header');
}
}
+4 -4
View File
@@ -144,7 +144,7 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
* @description The arguments for the function call
*/
public get args (): A {
return [...(this.get('args') as Struct).values()] as A;
return [...this.getT<Struct>('args').values()] as A;
}
/**
@@ -158,21 +158,21 @@ export class GenericCall<A extends AnyTuple = AnyTuple> extends Struct implement
* @description The argument entries
*/
public get argsEntries (): [string, Codec][] {
return [...(this.get('args') as Struct).entries()];
return [...this.getT<Struct>('args').entries()];
}
/**
* @description The encoded `[sectionIndex, methodIndex]` identifier
*/
public get callIndex (): Uint8Array {
return (this.get('callIndex') as GenericCallIndex).toU8a();
return this.getT<GenericCallIndex>('callIndex').toU8a();
}
/**
* @description The encoded data
*/
public get data (): Uint8Array {
return (this.get('args') as Struct).toU8a();
return this.getT<Struct>('args').toU8a();
}
/**
@@ -63,20 +63,20 @@ export class GenericChainProperties extends Json {
* @description The chain ss58Format
*/
public get ss58Format (): Option<u32> {
return this.get('ss58Format') as Option<u32>;
return this.getT('ss58Format');
}
/**
* @description The decimals for each of the tokens
*/
public get tokenDecimals (): Option<Vec<u32>> {
return this.get('tokenDecimals') as Option<Vec<u32>>;
return this.getT('tokenDecimals');
}
/**
* @description The symbols for the tokens
*/
public get tokenSymbol (): Option<Vec<Text>> {
return this.get('tokenSymbol') as Option<Vec<Text>>;
return this.getT('tokenSymbol');
}
}
+2 -2
View File
@@ -112,14 +112,14 @@ export class GenericEvent extends Struct implements IEvent<Codec[]> {
* @description The wrapped [[EventData]]
*/
public get data (): GenericEventData {
return this.get('data') as GenericEventData;
return this.getT('data');
}
/**
* @description The [[EventId]], identifying the raw event
*/
public get index (): EventId {
return this.get('index') as EventId;
return this.getT('index');
}
/**
+14 -14
View File
@@ -41,6 +41,19 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericAccountI
return registry.createTypeUnsafe('AccountIndex', [u8aToBn(value.subarray(offset, offset + length), true)]);
}
/** @internal */
function decodeAddressOrIndex (registry: CodecRegistry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
return value instanceof GenericLookupSource
? value.inner
: value instanceof GenericAccountId || value instanceof GenericAccountIndex
? value
: isBn(value) || isNumber(value) || isBigInt(value)
? registry.createTypeUnsafe('AccountIndex', [value])
: Array.isArray(value) || isHex(value) || isU8a(value)
? decodeU8a(registry, u8aToU8a(value))
: decodeString(registry, value);
}
/**
* @name LookupSource
* @description
@@ -51,20 +64,7 @@ function decodeU8a (registry: CodecRegistry, value: Uint8Array): GenericAccountI
*/
export class GenericLookupSource extends Base<GenericAccountId | GenericAccountIndex> {
constructor (registry: CodecRegistry, value: AnyAddress = new Uint8Array()) {
super(registry, GenericLookupSource._decodeAddress(registry, value));
}
/** @internal */
private static _decodeAddress (registry: CodecRegistry, value: AnyAddress): GenericAccountId | GenericAccountIndex {
return value instanceof GenericLookupSource
? value.inner
: value instanceof GenericAccountId || value instanceof GenericAccountIndex
? value
: isBn(value) || isNumber(value) || isBigInt(value)
? registry.createTypeUnsafe('AccountIndex', [value])
: Array.isArray(value) || isHex(value) || isU8a(value)
? decodeU8a(registry, u8aToU8a(value))
: decodeString(registry, value);
super(registry, decodeAddressOrIndex(registry, value));
}
/**
@@ -69,7 +69,7 @@ export class MetadataVersioned extends Struct {
* @description the metadata wrapped
*/
#metadata = (): MetadataAll => {
return this.get('metadata') as MetadataAll;
return this.getT('metadata');
};
/**
@@ -137,7 +137,7 @@ export class MetadataVersioned extends Struct {
* @description The magicNumber for the Metadata (known constant)
*/
public get magicNumber (): MagicNumber {
return this.get('magicNumber') as MagicNumber;
return this.getT('magicNumber');
}
/**
@@ -352,7 +352,7 @@ export class PortableRegistry extends Struct implements ILookup {
* @description The types of the registry
*/
public get types (): Vec<PortableType> {
return this.get('types') as Vec<PortableType>;
return this.getT('types');
}
/**