Compact<Index> in extrinsics (#515)
* Basic compact index * Nonce is only used in signatures, alias it * typo * s/NonceCompact/IndexCompact/ * Update tests
This commit is contained in:
@@ -21,7 +21,7 @@ describe('Extrinsic', () => {
|
||||
});
|
||||
|
||||
it('decodes an actual transaction with indexes', () => {
|
||||
const extrinsic = new Extrinsic('0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff604187080100000000000000270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000');
|
||||
const extrinsic = new Extrinsic('0x8110f8e1ebdd3cdef7423d24fe68f3863945ea21c190907d7f3394ddf153f633c77b894af36f7a36e7ec767f4593bfd8d084b66d805605905054327a08ff6041870804270e0200ff0e6422725af0e9aede3bef6eba77bc87afadf60b9735057ae93801f4c472ad7b00407a10f35a00000000000000000000');
|
||||
|
||||
expect(extrinsic.isSigned).toEqual(true);
|
||||
expect(extrinsic.signature.signer.toU8a()).toEqual(new Uint8Array([0x10]));
|
||||
|
||||
@@ -11,7 +11,7 @@ import Struct from './codec/Struct';
|
||||
import Address from './Address';
|
||||
import ExtrinsicEra from './ExtrinsicEra';
|
||||
import Method from './Method';
|
||||
import Nonce from './Nonce';
|
||||
import Nonce from './NonceCompact';
|
||||
import Signature from './Signature';
|
||||
import SignaturePayload from './SignaturePayload';
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// Copyright 2017-2018 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import Compact from './codec/Compact';
|
||||
import Nonce from './Nonce';
|
||||
|
||||
/**
|
||||
* @name Nonce
|
||||
* @description
|
||||
* The Compact<Nonce> or number of transactions sent by a specific account. Generally used
|
||||
* with extrinsics to determine the order of execution.
|
||||
*/
|
||||
export default class NonceCompact extends Compact.with(Nonce) {
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { AnyNumber, AnyU8a } from './types';
|
||||
import Struct from './codec/Struct';
|
||||
import Method from './Method';
|
||||
import Hash from './Hash';
|
||||
import Nonce from './Nonce';
|
||||
import Nonce from './NonceCompact';
|
||||
import ExtrinsicEra from './ExtrinsicEra';
|
||||
|
||||
type SignaturePayloadValue = {
|
||||
|
||||
@@ -52,6 +52,8 @@ export default class Type extends Text {
|
||||
// alias () -> Null
|
||||
Type._alias('\\\(\\\)', 'Null'),
|
||||
// alias Vec<u8> -> Bytes
|
||||
Type._alias('Compact<Index>', 'IndexCompact'),
|
||||
// alias Vec<u8> -> Bytes
|
||||
Type._alias('Vec<u8>', 'Bytes'),
|
||||
// alias RawAddress -> Address
|
||||
Type._alias('RawAddress', 'Address'),
|
||||
|
||||
@@ -21,7 +21,7 @@ import Moment from '../Moment';
|
||||
* a number and making the compact representation thereof
|
||||
*/
|
||||
export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
constructor (Type: Constructor<UInt | Moment>, value: AnyNumber = 0) {
|
||||
constructor (Type: Constructor<UInt | Moment>, value: Compact | AnyNumber = 0) {
|
||||
super(Compact.decodeCompact(Type, value));
|
||||
}
|
||||
|
||||
@@ -48,8 +48,10 @@ export default class Compact extends Base<UInt | Moment> implements Codec {
|
||||
return value;
|
||||
}
|
||||
|
||||
static decodeCompact (Type: Constructor<UInt | Moment>, value: AnyNumber): Moment | UInt {
|
||||
if (isString(value)) {
|
||||
static decodeCompact (Type: Constructor<UInt | Moment>, value: Compact | AnyNumber): Moment | UInt {
|
||||
if (value instanceof Compact) {
|
||||
return new Type(value.raw);
|
||||
} else if (isString(value)) {
|
||||
return new Type(
|
||||
isHex(value)
|
||||
? hexToBn(value)
|
||||
|
||||
@@ -60,6 +60,7 @@ export { default as NewAccountOutcome } from './NewAccountOutcome';
|
||||
export { default as Null } from './Null';
|
||||
// NOTE Nonce is renamed to Index
|
||||
export { default as Index } from './Nonce';
|
||||
export { default as IndexCompact } from './NonceCompact';
|
||||
export { default as Justification } from './Justification';
|
||||
export { default as Origin } from './Origin';
|
||||
export { default as ParaId } from './ParaId';
|
||||
|
||||
Reference in New Issue
Block a user