diff options
Diffstat (limited to 'core/types')
-rw-r--r-- | core/types/block.go | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/core/types/block.go b/core/types/block.go index fd81db04c..7a84045a6 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -117,6 +117,13 @@ func rlpHash(x interface{}) (h common.Hash) { return h } +// Body is a simple (mutable, non-safe) data container for storing and moving +// a block's data contents (transactions and uncles) together. +type Body struct { + Transactions []*Transaction + Uncles []*Header +} + type Block struct { header *Header uncles []*Header @@ -129,12 +136,20 @@ type Block struct { // Td is used by package core to store the total difficulty // of the chain up to and including the block. - Td *big.Int + td *big.Int // ReceivedAt is used by package eth to track block propagation time. ReceivedAt time.Time } +// DeprecatedTd is an old relic for extracting the TD of a block. It is in the +// code solely to facilitate upgrading the database from the old format to the +// new, after which it should be deleted. Do not use! +func (b *Block) DeprecatedTd() *big.Int { + return b.td +} + +// [deprecated by eth/63] // StorageBlock defines the RLP encoding of a Block stored in the // state database. The StorageBlock encoding contains fields that // would otherwise need to be recomputed. @@ -147,6 +162,7 @@ type extblock struct { Uncles []*Header } +// [deprecated by eth/63] // "storage" block encoding. used for database. type storageblock struct { Header *Header @@ -168,7 +184,7 @@ var ( // are ignored and set to values derived from the given txs, uncles // and receipts. func NewBlock(header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt) *Block { - b := &Block{header: copyHeader(header), Td: new(big.Int)} + b := &Block{header: copyHeader(header), td: new(big.Int)} // TODO: panic if len(txs) != len(receipts) if len(txs) == 0 { @@ -268,24 +284,16 @@ func (b *Block) EncodeRLP(w io.Writer) error { }) } +// [deprecated by eth/63] func (b *StorageBlock) DecodeRLP(s *rlp.Stream) error { var sb storageblock if err := s.Decode(&sb); err != nil { return err } - b.header, b.uncles, b.transactions, b.Td = sb.Header, sb.Uncles, sb.Txs, sb.TD + b.header, b.uncles, b.transactions, b.td = sb.Header, sb.Uncles, sb.Txs, sb.TD return nil } -func (b *StorageBlock) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, storageblock{ - Header: b.header, - Txs: b.transactions, - Uncles: b.uncles, - TD: b.Td, - }) -} - // TODO: copies func (b *Block) Uncles() []*Header { return b.uncles } func (b *Block) Transactions() Transactions { return b.transactions } @@ -356,7 +364,6 @@ func (b *Block) WithMiningResult(nonce uint64, mixDigest common.Hash) *Block { transactions: b.transactions, receipts: b.receipts, uncles: b.uncles, - Td: b.Td, } } @@ -386,7 +393,7 @@ func (b *Block) Hash() common.Hash { } func (b *Block) String() string { - str := fmt.Sprintf(`Block(#%v): Size: %v TD: %v { + str := fmt.Sprintf(`Block(#%v): Size: %v { MinerHash: %x %v Transactions: @@ -394,7 +401,7 @@ Transactions: Uncles: %v } -`, b.Number(), b.Size(), b.Td, b.header.HashNoNonce(), b.header, b.transactions, b.uncles) +`, b.Number(), b.Size(), b.header.HashNoNonce(), b.header, b.transactions, b.uncles) return str } |