Proposal extends Method

This commit is contained in:
Jaco Greeff
2018-10-08 12:15:20 +02:00
parent 4615661d1c
commit 45fe764da4
2 changed files with 51 additions and 7 deletions
-3
View File
@@ -22,9 +22,6 @@ type ExtrinsicValue = {
signature?: ExtrinsicSignature
};
// console.error('ExtrinsicSignature', ExtrinsicSignature);
// console.error('Method', Method);
/**
* Representation of an Extrinsic in the system. It contains the actual call,
* (optional) signature and encodes with an actual length prefix
+51 -4
View File
@@ -2,9 +2,56 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Extrinsic from './Extrinsic';
import hexToU8a from '@polkadot/util/hex/toU8a';
import u8aConcat from '@polkadot/util/u8a/concat';
import u8aToHex from '@polkadot/util/u8a/toHex';
// The Nonce or number of transactiosn sent by a specific account. Generally used
// with extrinsics to determine the order of execution.
export default class Proposal extends Extrinsic {
import Compact from './codec/Compact';
import Method from './Method';
// A proposal in the system. It contains the same data as an extrinsic, but the encoding
// does not allow for signatures or versions, only the callindex & parameters required
export default class Proposal extends Method {
get length (): number {
return this.toU8a(true).length;
}
byteLength (): number {
const length = this.length;
return length + Compact.encode(length).length;
}
fromJSON (input: any): Proposal {
super.fromU8a(hexToU8a(input));
return this;
}
fromU8a (input: Uint8Array): Proposal {
const [offset, length] = Compact.decode(input);
super.fromU8a(input.subarray(offset, offset + length.toNumber()));
return this;
}
toU8a (isBare?: boolean): Uint8Array {
const encoded = super.toU8a();
return isBare
? encoded
: u8aConcat(
Compact.encode(encoded.length),
encoded
);
}
toHex (): string {
return u8aToHex(this.toU8a());
}
toJSON (): any {
return this.toHex();
}
}