Add merkle proof of last block hash to BlockHeader, add merkle proof of tx hash to Transaction
This commit is contained in:
parent
dde32e11dc
commit
fb84ab8ad6
@ -20,6 +20,7 @@ type BlockHeader struct {
|
||||
Height uint64
|
||||
Hash []byte
|
||||
LastHash []byte
|
||||
LastHashProof *merkletree.Proof
|
||||
Proposer peer.ID
|
||||
Signature []byte
|
||||
}
|
||||
@ -63,6 +64,11 @@ func CreateBlock(lastBlockHeader *BlockHeader, txs []*Transaction, wallet *walle
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lastHashProof, err := tree.GenerateProof(lastBlockHeader.Hash, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
block := &Block{
|
||||
Header: &BlockHeader{
|
||||
Timestamp: timestamp,
|
||||
@ -71,6 +77,7 @@ func CreateBlock(lastBlockHeader *BlockHeader, txs []*Transaction, wallet *walle
|
||||
Signature: s.Data,
|
||||
Hash: blockHash,
|
||||
LastHash: lastBlockHeader.Hash,
|
||||
LastHashProof: lastHashProof,
|
||||
},
|
||||
Data: txs,
|
||||
}
|
||||
|
@ -5,11 +5,14 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/wealdtech/go-merkletree"
|
||||
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
)
|
||||
|
||||
type Transaction struct {
|
||||
Hash []byte
|
||||
MerkleProof *merkletree.Proof // sets when transaction is added to block
|
||||
Timestamp time.Time
|
||||
Data []byte
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user