Skip to content

Commit

Permalink
Merge pull request #16 from shruggr/deserialize
Browse files Browse the repository at this point in the history
feat: Blockchain.deserialize
  • Loading branch information
xhliu authored Feb 29, 2024
2 parents b1c0fe6 + d81a17b commit a3a55c5
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@ export class Blockchain extends SmartContractLib {
)
}

@method()
static deserialize(bh: ByteString): BlockHeader {
return {
version: slice(bh, 0n, 4n),
prevBlockHash: Sha256(slice(bh, 4n, 36n)),
merkleRoot: Sha256(slice(bh, 36n, 68n)),
time: Utils.fromLEUnsigned(slice(bh, 68n, 72n)),
bits: slice(bh, 72n, 76n),
nonce: Utils.fromLEUnsigned(slice(bh, 76n, 80n)),
}
}

// Block header hash.
@method()
static blockHeaderHash(bh: BlockHeader): Sha256 {
Expand Down

0 comments on commit a3a55c5

Please sign in to comment.