prysm-pulse/sharding/collation.go
Raul Jordan b6fe3141da sharding: merge from master and fix collation.go conflicts
Former-commit-id: 1b36c995ff866f71c265c00f12bd67ae4cd9ea7f [formerly 8d527c11b771956e5b8fde3e3edada3a5dcb7777]
Former-commit-id: 90b1e63f696d31757f25dd4a714b89e95b4a3bcf
2018-05-04 14:20:38 -05:00

59 lines
1.9 KiB
Go

package sharding
import (
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/rlp"
)
// Collation base struct.
type Collation struct {
header *CollationHeader
body []byte
transactions []*types.Transaction
}
// CollationHeader base struct.
type CollationHeader struct {
shardID *big.Int //the shard ID of the shard.
chunkRoot *common.Hash //the root of the chunk tree which identifies collation body.
period *big.Int //the period number in which collation to be included.
proposerAddress *common.Address //address of the collation proposer.
proposerSignature []byte //the proposer's signature for calculating collation hash.
}
// Hash takes the keccak256 of the collation header's contents.
func (h *CollationHeader) Hash() (hash common.Hash) {
hw := sha3.NewKeccak256()
rlp.Encode(hw, h)
hw.Sum(hash[:0])
return hash
}
// Header returns the collation's header.
func (c *Collation) Header() *CollationHeader { return c.header }
// Transactions returns an array of tx's in the collation.
func (c *Collation) Transactions() []*types.Transaction { return c.transactions }
// ShardID is the identifier for a shard.
func (c *Collation) ShardID() *big.Int { return c.header.shardID }
// Period the collation corresponds to.
func (c *Collation) Period() *big.Int { return c.header.period }
// ProposerAddress is the coinbase addr of the creator for the collation.
func (c *Collation) ProposerAddress() *common.Address { return c.header.proposerAddress }
// SetHeader updates the collation's header.
func (c *Collation) SetHeader(h *CollationHeader) { c.header = h }
// AddTransaction adds to the collation's body of tx blobs.
func (c *Collation) AddTransaction(tx *types.Transaction) {
// TODO: Include blob serialization instead.
c.transactions = append(c.transactions, tx)
}