prysm-pulse/sharding/collation.go
Preston Van Loon 2afb1e5227 Added collation and collation type. Added GasUsed method
Former-commit-id: 16fa7aea81210b0dbb2f8f2fa560a046ae14fc73 [formerly 5c7fb20b829a2e19b6ea7fbc14cc8284b84658bd]
Former-commit-id: 07c65a1d78fef9b362db229e7266e97af78da6e8
2018-02-20 23:57:52 -05:00

39 lines
793 B
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
transactions []*types.Transaction
}
type CollationHeader struct {
shardID *big.Int
expectedPeriodNumber *big.Int
periodStartPrevHash *common.Hash
parentCollationHash *common.Hash
txListRoot *common.Hash
coinbase *common.Address
postStateRoot *common.Hash
receiptsRoot *common.Hash
sig []byte
}
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)
}