mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
d625475a96
Former-commit-id: 5b122d8260ec36d7b9931cd37194993915aeb363 [formerly 2a1376100a61088f5bb455462c782175985c8e6a] Former-commit-id: 157da67786f1b0132625e9c91564399f7afa96a3
55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
package sharding
|
|
|
|
import (
|
|
"math"
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
)
|
|
|
|
type Collation struct {
|
|
header *CollationHeader
|
|
//TODO: Tx to blob
|
|
transactions []*types.Transaction
|
|
}
|
|
|
|
type CollationHeader struct {
|
|
shardID *big.Int //the shard ID of the shard
|
|
parentHash *common.Hash //the hash of the parent collation
|
|
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
|
|
proposerBid *big.Int //the reward from proposer to collator for a winning proposal
|
|
proposerSignature []byte //the proposer's signature as part of a proposal
|
|
}
|
|
|
|
func (c *Collation) Header() *CollationHeader { return c.header }
|
|
func (c *Collation) Transactions() []*types.Transaction { return c.transactions }
|
|
func (c *Collation) ShardID() *big.Int { return c.header.shardID }
|
|
func (c *Collation) ParentHash() *common.Hash { return c.header.parentHash }
|
|
func (c *Collation) Period() *big.Int { return c.header.period }
|
|
func (c *Collation) ProposerAddress() *common.Address { return c.header.proposerAddress }
|
|
func (c *Collation) ProposerBid() *big.Int { return c.header.proposerBid }
|
|
func (c *Collation) ProposerSignature() []byte{ return c.header.proposerSignature }
|
|
|
|
|
|
func (c *Collation) SetHeader(h *CollationHeader) { c.header = h }
|
|
|
|
//TODO: Tx to blob
|
|
func (c *Collation) AddTransaction(tx *types.Transaction) {
|
|
c.transactions = append(c.transactions, tx)
|
|
}
|
|
|
|
func (c *Collation) GasUsed() *big.Int {
|
|
g := uint64(0)
|
|
for _, tx := range c.transactions {
|
|
if g > math.MaxUint64-(g+tx.Gas()) {
|
|
g = math.MaxUint64
|
|
break
|
|
}
|
|
g += tx.Gas()
|
|
}
|
|
return big.NewInt(0).SetUint64(g)
|
|
}
|