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
@ -16,12 +16,13 @@ type Block struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type BlockHeader struct {
|
type BlockHeader struct {
|
||||||
Timestamp int64
|
Timestamp int64
|
||||||
Height uint64
|
Height uint64
|
||||||
Hash []byte
|
Hash []byte
|
||||||
LastHash []byte
|
LastHash []byte
|
||||||
Proposer peer.ID
|
LastHashProof *merkletree.Proof
|
||||||
Signature []byte
|
Proposer peer.ID
|
||||||
|
Signature []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func GenesisBlock() *Block {
|
func GenesisBlock() *Block {
|
||||||
@ -63,14 +64,20 @@ func CreateBlock(lastBlockHeader *BlockHeader, txs []*Transaction, wallet *walle
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastHashProof, err := tree.GenerateProof(lastBlockHeader.Hash, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Header: &BlockHeader{
|
Header: &BlockHeader{
|
||||||
Timestamp: timestamp,
|
Timestamp: timestamp,
|
||||||
Height: lastBlockHeader.Height + 1,
|
Height: lastBlockHeader.Height + 1,
|
||||||
Proposer: proposer,
|
Proposer: proposer,
|
||||||
Signature: s.Data,
|
Signature: s.Data,
|
||||||
Hash: blockHash,
|
Hash: blockHash,
|
||||||
LastHash: lastBlockHeader.Hash,
|
LastHash: lastBlockHeader.Hash,
|
||||||
|
LastHashProof: lastHashProof,
|
||||||
},
|
},
|
||||||
Data: txs,
|
Data: txs,
|
||||||
}
|
}
|
||||||
|
@ -5,13 +5,16 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/wealdtech/go-merkletree"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/crypto"
|
"github.com/ethereum/go-ethereum/crypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Transaction struct {
|
type Transaction struct {
|
||||||
Hash []byte
|
Hash []byte
|
||||||
Timestamp time.Time
|
MerkleProof *merkletree.Proof // sets when transaction is added to block
|
||||||
Data []byte
|
Timestamp time.Time
|
||||||
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateTransaction(data []byte) *Transaction {
|
func CreateTransaction(data []byte) *Transaction {
|
||||||
|
Loading…
Reference in New Issue
Block a user