mirror of
https://github.com/talaia-labs/rust-teos.git
synced 2026-08-14 12:43:21 +02:00
Merge pull request #67 from sr-gi/56-fix-blockchain-generate
Makes sure generated blocks have valid pow
This commit is contained in:
commit
f30ee8a294
1 changed files with 12 additions and 11 deletions
|
|
@ -200,19 +200,20 @@ impl Blockchain {
|
|||
None => vec![],
|
||||
};
|
||||
let hashes = txdata.iter().map(|obj| obj.txid().as_hash());
|
||||
|
||||
let block = Block {
|
||||
header: BlockHeader {
|
||||
version: 0,
|
||||
prev_blockhash,
|
||||
merkle_root: bitcoin_merkle_root(hashes).into(),
|
||||
time,
|
||||
bits,
|
||||
nonce: 0,
|
||||
},
|
||||
txdata,
|
||||
let mut header = BlockHeader {
|
||||
version: 0,
|
||||
prev_blockhash,
|
||||
merkle_root: bitcoin_merkle_root(hashes).into(),
|
||||
time,
|
||||
bits,
|
||||
nonce: 0,
|
||||
};
|
||||
|
||||
while header.validate_pow(&header.target()).is_err() {
|
||||
header.nonce += 1;
|
||||
}
|
||||
|
||||
let block = Block { header, txdata };
|
||||
self.blocks.push(block.clone());
|
||||
|
||||
block
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue