Skip to content

Commit

Permalink
Values for structures
Browse files Browse the repository at this point in the history
  • Loading branch information
jacogr committed Sep 25, 2018
1 parent 58d1a11 commit 888a4ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 16 additions & 2 deletions packages/api-codec/src/Header.ts
Expand Up @@ -2,18 +2,32 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.

import BN from 'bn.js';
import blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a';

import Bytes from './codec/Bytes';
import Long from './codec/Long';
import Struct from './codec/Struct';
import Vector from './codec/Vector';

import BlockNumber from './BlockNumber';
import Hash from './Hash';

type DigestStruct = {
logs?: Array<Uint8Array | string>
};

type HeaderStruct = {
digest?: DigestStruct,
extrinsicsRoot?: Hash | Uint8Array | string,
number?: Long | BN | number | string,
parentHash?: Hash | Uint8Array | string,
stateRoot?: Hash | Uint8Array | string
};

// A block header digest.
export class Digest extends Struct {
constructor (value?: any) {
constructor (value: DigestStruct = {}) {
super({
logs: Vector.with(Bytes)
}, value);
Expand All @@ -26,7 +40,7 @@ export class Digest extends Struct {

// A block header.
export default class Header extends Struct {
constructor (value?: any) {
constructor (value: HeaderStruct = {}) {
super({
parentHash: Hash,
number: BlockNumber,
Expand Down
6 changes: 3 additions & 3 deletions packages/api-codec/src/KeyValue.ts
Expand Up @@ -6,16 +6,16 @@ import Bytes from './codec/Bytes';
import Struct from './codec/Struct';

type KeyValueStruct = {
key: Uint8Array,
value: Uint8Array
key?: Uint8Array | string,
value?: Uint8Array | string
};

// KeyValue structure. Since most of the keys and resultant values in Subtrate is
// hashed and/or encoded, this does not wrap a Text, but rather a Bytes
// for the keys and values. (Not to be confused with the KeyValue in Metadata, that
// is actually for Maps, whereas this is a representation of actaul storage values)
export default class KeyValue extends Struct {
constructor (value: KeyValueStruct = {} as KeyValueStruct) {
constructor (value: KeyValueStruct = {}) {
super({
key: Bytes,
value: Bytes
Expand Down

0 comments on commit 888a4ea

Please sign in to comment.