|
|
@ -23,13 +23,19 @@ type Block struct { |
|
|
|
ShardId uint32 |
|
|
|
ShardId uint32 |
|
|
|
Hash [32]byte |
|
|
|
Hash [32]byte |
|
|
|
MerkleRootData []byte |
|
|
|
MerkleRootData []byte |
|
|
|
|
|
|
|
State *State // If present, this block is state block
|
|
|
|
// Signature...
|
|
|
|
// Signature...
|
|
|
|
Bitmap []byte // Contains which validator signed the block.
|
|
|
|
Bitmap []byte // Contains which validator signed the block.
|
|
|
|
Signature [66]byte // Schnorr collective signature
|
|
|
|
Signature [66]byte // Schnorr collective signature
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type State struct { |
|
|
|
|
|
|
|
NumBlocks int32 // Total number of blocks
|
|
|
|
|
|
|
|
NumTransactions int32 // Total number of transactions
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (b *Block) IsStateBlock() bool { |
|
|
|
func (b *Block) IsStateBlock() bool { |
|
|
|
return bytes.Equal(b.PrevBlockHash[:], (&[32]byte{})[:]) // TODO: think of a better indicator to check
|
|
|
|
return b.State != nil && bytes.Equal(b.PrevBlockHash[:], (&[32]byte{})[:]) // TODO: think of a better indicator to check
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Serialize serializes the block
|
|
|
|
// Serialize serializes the block
|
|
|
@ -122,8 +128,9 @@ func NewGenesisBlock(coinbase *Transaction, shardId uint32) *Block { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewStateBlock creates and returns a state Block based on utxo pool.
|
|
|
|
// NewStateBlock creates and returns a state Block based on utxo pool.
|
|
|
|
func NewStateBlock(utxoPool *UTXOPool) *Block { |
|
|
|
func NewStateBlock(utxoPool *UTXOPool, numBlocks, numTxs int32) *Block { |
|
|
|
stateTransactions := []*Transaction{} |
|
|
|
stateTransactions := []*Transaction{} |
|
|
|
|
|
|
|
stateTransactionIds := [][32]byte{} |
|
|
|
for address, txHash2Vout2AmountMap := range utxoPool.UtxoMap { |
|
|
|
for address, txHash2Vout2AmountMap := range utxoPool.UtxoMap { |
|
|
|
stateTransaction := Transaction{} |
|
|
|
stateTransaction := Transaction{} |
|
|
|
for _, vout2AmountMap := range txHash2Vout2AmountMap { |
|
|
|
for _, vout2AmountMap := range txHash2Vout2AmountMap { |
|
|
@ -133,8 +140,11 @@ func NewStateBlock(utxoPool *UTXOPool) *Block { |
|
|
|
} |
|
|
|
} |
|
|
|
if len(stateTransaction.TxOutput) != 0 { |
|
|
|
if len(stateTransaction.TxOutput) != 0 { |
|
|
|
stateTransaction.SetID() |
|
|
|
stateTransaction.SetID() |
|
|
|
|
|
|
|
stateTransactionIds = append(stateTransactionIds, stateTransaction.ID) |
|
|
|
stateTransactions = append(stateTransactions, &stateTransaction) |
|
|
|
stateTransactions = append(stateTransactions, &stateTransaction) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return NewBlock(stateTransactions, [32]byte{}, utxoPool.ShardID) |
|
|
|
newBlock := NewBlock(stateTransactions, [32]byte{}, utxoPool.ShardID) |
|
|
|
|
|
|
|
newBlock.State = &State{NumBlocks: numBlocks, NumTransactions: numTxs} |
|
|
|
|
|
|
|
return newBlock |
|
|
|
} |
|
|
|
} |
|
|
|