Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
601 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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 hexToU8a from '@polkadot/util/hex/toU8a'; | ||
|
||
import Block from './Block'; | ||
|
||
describe('Block', () => { | ||
it('decodes a block properly', () => { | ||
const block = new Block(); | ||
|
||
block.fromU8a(hexToU8a( | ||
'0x' + | ||
// parent_hash | ||
'0900000000000000000000000000000000000000000000000000000000000009' + | ||
// number | ||
'4300000000000000' + | ||
// state_root | ||
'0800000000000000000000000000000000000000000000000000000000000008' + | ||
// transaction_root | ||
'0700000000000000000000000000000000000000000000000000000000000007' + | ||
// digest | ||
'08' + // 2 << 2 | ||
'0401' + | ||
'0402' + | ||
// transactions | ||
'04' + // 1 << 2 | ||
// 111 bytes in compact encoding | ||
'bd01' + | ||
// prefix | ||
'ff' + | ||
'0000000000000000000000000000000000000000000000000000000000000000' + | ||
'00000000' + | ||
'0300' + | ||
'7527000000000000' + | ||
'0000000000000000000000000000000000000000000000000000000000000000' + | ||
'0000000000000000000000000000000000000000000000000000000000000000' | ||
)); | ||
|
||
expect( | ||
block.header.blockNumber.toNumber() | ||
).toEqual(67); | ||
expect( | ||
block.extrinsics.length | ||
).toEqual(1); // eslint-disable-line | ||
expect( | ||
block.extrinsics.at(0).length | ||
).toEqual(111); // eslint-disable-line | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 Struct from './codec/Struct'; | ||
import Vector from './codec/Vector'; | ||
|
||
import Extrinsic from './Extrinsic'; | ||
import Header from './Header'; | ||
|
||
// A block encoded with header and extrinsics | ||
export default class Block extends Struct { | ||
constructor (value?: any) { | ||
super({ | ||
header: Header, | ||
extrinsics: Vector.with(Extrinsic) | ||
}, value); | ||
} | ||
|
||
get extrinsics (): Vector<Extrinsic> { | ||
return this.raw.extrinsics as Vector<Extrinsic>; | ||
} | ||
|
||
get header (): Header { | ||
return this.raw.header as Header; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// 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 blake2Asu8a from '@polkadot/util-crypto/blake2/asU8a'; | ||
|
||
import Bytes from './codec/Bytes'; | ||
|
||
import Hash from './Hash'; | ||
|
||
// Representation of an Extrinsic in the system. | ||
// | ||
// NOTE At this point we are just keeping to a bare-bones Vec<u8> structure, | ||
// this should be expanded to do the automatic decoding of an extrinsic | ||
export default class Extrinsic extends Bytes { | ||
// convernience, encodes the extrinsic and returns the actual hash | ||
get hash (): Hash { | ||
return new Hash( | ||
blake2Asu8a(this.toU8a(), 256) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.