Expand api-codec types (#163)
* Add missing U* (number) types * Missing number types & indexes * Add H256, H512, Hash & Signature * Add Bool, KeyValue & U8a (base) * Fix LengthCompact encoder (with tests) * AccountId * AccountId toU8a * Order imports * Apply type aliasses, PropIndex -> ProposalIndex * Cleanup mappers * Add fromJSON to Type * Spliut with Address, AccountId & AccountIndex * Add some comments around the types * instanceOf check * Address can construct from AccountIndex or AccountId * Remove Address.encode (unused) * Allow instance of class in constructor * Cleanup instanceof (String, Bool, H256, H512) * AccountId/AccountIndex check around CodecU8a * Fix unused imports * Additional in-constructor instanceof constructions * u8a allows hex, string or u8a inputs * Metadata.fromJSON * Add Header * Allow CodecNumber to take hex/string inputs * fromJSON uses decoder * Remove LengthFixed (only compact used), add tests * Some tests around Type * Remove unused package * PR comments * Expand tests (and fix some bug - yay for tests) * Rename /base -> /codec
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Copyright 2017-2018 @polkadot/api-codec authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the ISC license. See the LICENSE file for details.
|
||||
|
||||
import CodecArray from './codec/Array';
|
||||
import CodecBytes from './codec/Bytes';
|
||||
import CodecStruct from './codec/Struct';
|
||||
|
||||
import BlockNumber from './BlockNumber';
|
||||
import Hash from './Hash';
|
||||
|
||||
// A block header digest.
|
||||
export class Digest extends CodecStruct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
logs: CodecArray.with(CodecBytes)
|
||||
}, value);
|
||||
}
|
||||
|
||||
get logs (): CodecArray<CodecBytes> {
|
||||
return this.raw.logs as CodecArray<CodecBytes>;
|
||||
}
|
||||
}
|
||||
|
||||
// A block header.
|
||||
export default class Header extends CodecStruct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
parentHash: Hash,
|
||||
number: BlockNumber,
|
||||
stateRoot: Hash,
|
||||
extrinsicsRoot: Hash,
|
||||
digest: Digest
|
||||
}, value);
|
||||
}
|
||||
|
||||
get blockNumber (): BlockNumber {
|
||||
return this.raw.number as BlockNumber;
|
||||
}
|
||||
|
||||
get digest (): Digest {
|
||||
return this.raw.digest as Digest;
|
||||
}
|
||||
|
||||
get extrinsicsRoot (): Hash {
|
||||
return this.raw.extrinsicsRoot as Hash;
|
||||
}
|
||||
|
||||
get parentHash (): Hash {
|
||||
return this.raw.parentHash as Hash;
|
||||
}
|
||||
|
||||
get stateRoot (): Hash {
|
||||
return this.raw.stateRoot as Hash;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user