2018-02-21 04:57:52 +00:00
|
|
|
package sharding
|
|
|
|
|
|
|
|
import (
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
|
|
)
|
|
|
|
|
2018-05-02 15:37:44 +00:00
|
|
|
// Collation base struct
|
2018-02-21 04:57:52 +00:00
|
|
|
type Collation struct {
|
2018-03-21 05:57:35 +00:00
|
|
|
header *CollationHeader
|
2018-02-21 04:57:52 +00:00
|
|
|
transactions []*types.Transaction
|
|
|
|
}
|
|
|
|
|
2018-05-02 15:37:44 +00:00
|
|
|
// CollationHeader base struct
|
2018-02-21 04:57:52 +00:00
|
|
|
type CollationHeader struct {
|
2018-03-21 04:10:41 +00:00
|
|
|
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
|
2018-04-12 16:38:52 +00:00
|
|
|
proposerSignature []byte //the proposer's signature for calculating collation hash
|
2018-02-21 04:57:52 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 15:37:44 +00:00
|
|
|
// Header returns the collation's header
|
|
|
|
func (c *Collation) Header() *CollationHeader { return c.header }
|
|
|
|
|
|
|
|
// Transactions returns an array of tx's in the collation
|
2018-02-22 03:39:51 +00:00
|
|
|
func (c *Collation) Transactions() []*types.Transaction { return c.transactions }
|
|
|
|
|
2018-05-02 15:37:44 +00:00
|
|
|
// 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
|
2018-02-23 14:54:36 +00:00
|
|
|
func (c *Collation) SetHeader(h *CollationHeader) { c.header = h }
|
2018-03-21 04:07:40 +00:00
|
|
|
|
2018-05-02 15:37:44 +00:00
|
|
|
// AddTransaction adds to the collation's body of tx blobs
|
2018-02-22 03:39:51 +00:00
|
|
|
func (c *Collation) AddTransaction(tx *types.Transaction) {
|
2018-05-02 15:37:44 +00:00
|
|
|
// TODO: Include blob serialization instead
|
2018-02-22 03:39:51 +00:00
|
|
|
c.transactions = append(c.transactions, tx)
|
|
|
|
}
|