Skip to content

Commit

Permalink
Merge pull request #17 from sCrypt-Inc/verifyBlockHeader
Browse files Browse the repository at this point in the history
Verify block header
  • Loading branch information
zhfnjust authored Mar 7, 2024
2 parents a3a55c5 + cb8b0e0 commit 8b195f9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ tsconfig.json
/artifacts/**/*.scrypt.map
/artifacts/**/*.json
.asm/
tsconfig-scryptTS.json

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scrypt-ts-lib",
"version": "0.1.27",
"version": "0.1.28",
"description": "A collection of smart contract libraries for `scrypt-ts`.",
"types": "dist/index.d.ts",
"main": "dist/index.js",
Expand Down
8 changes: 8 additions & 0 deletions src/blockchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ export class Blockchain extends SmartContractLib {
return bhHash <= target && target <= blockchainTarget
}

@method()
static verifyBlockHeader(bh: BlockHeader): boolean {
const bhHash = Blockchain.blockHeaderHashAsInt(bh)
const target = Blockchain.bits2Target(bh.bits)
// Block hash below target
return bhHash <= target
}

// Is a chain of block headers valid.
// TODO

Expand Down

0 comments on commit 8b195f9

Please sign in to comment.