diff --git a/blockchain/types/block.go b/blockchain/types/block.go index 99e7e0a..c7e9495 100644 --- a/blockchain/types/block.go +++ b/blockchain/types/block.go @@ -16,12 +16,13 @@ type Block struct { } type BlockHeader struct { - Timestamp int64 - Height uint64 - Hash []byte - LastHash []byte - Proposer peer.ID - Signature []byte + Timestamp int64 + Height uint64 + Hash []byte + LastHash []byte + LastHashProof *merkletree.Proof + Proposer peer.ID + Signature []byte } func GenesisBlock() *Block { @@ -63,14 +64,20 @@ 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, - Height: lastBlockHeader.Height + 1, - Proposer: proposer, - Signature: s.Data, - Hash: blockHash, - LastHash: lastBlockHeader.Hash, + Timestamp: timestamp, + Height: lastBlockHeader.Height + 1, + Proposer: proposer, + Signature: s.Data, + Hash: blockHash, + LastHash: lastBlockHeader.Hash, + LastHashProof: lastHashProof, }, Data: txs, } diff --git a/blockchain/types/transaction.go b/blockchain/types/transaction.go index 6ea276c..3be0e0d 100644 --- a/blockchain/types/transaction.go +++ b/blockchain/types/transaction.go @@ -5,13 +5,16 @@ import ( "fmt" "time" + "github.com/wealdtech/go-merkletree" + "github.com/ethereum/go-ethereum/crypto" ) type Transaction struct { - Hash []byte - Timestamp time.Time - Data []byte + Hash []byte + MerkleProof *merkletree.Proof // sets when transaction is added to block + Timestamp time.Time + Data []byte } func CreateTransaction(data []byte) *Transaction {