Skip to content

Commit

Permalink
feat: add deserialize
Browse files Browse the repository at this point in the history
  • Loading branch information
David Case committed Feb 29, 2024
1 parent b1c0fe6 commit d81a17b
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 d81a17b

Please sign in to comment.