From c73ba009031126e16da6999468851b33f93e8005 Mon Sep 17 00:00:00 2001 From: Determinant Date: Mon, 3 Aug 2020 17:16:53 -0400 Subject: allow using extra binary data in a block for state transition --- core/types/block.go | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) (limited to 'core/types/block.go') diff --git a/core/types/block.go b/core/types/block.go index fcbd8ab..6fa710a 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -150,6 +150,7 @@ type Block struct { header *Header uncles []*Header transactions Transactions + version uint32 extdata []byte // caches @@ -187,11 +188,11 @@ type extblock struct { } type myextblock struct { - Header *Header - Txs []*Transaction - Uncles []*Header - VersionNumber uint32 - ExtData []byte + Header *Header + Txs []*Transaction + Uncles []*Header + Version uint32 + ExtData []byte `rlp:"nil"` } // [deprecated by eth/63] @@ -291,10 +292,22 @@ func (b *Block) DecodeRLP(s *rlp.Stream) error { return nil } -func (b *Block) RawExtraData() []byte { +func (b *Block) SetExtraData(data []byte) { + b.extdata = data +} + +func (b *Block) ExtraData() []byte { return b.extdata } +func (b *Block) SetVersion(ver uint32) { + b.version = ver +} + +func (b *Block) Version() uint32 { + return b.version +} + // EncodeRLPEth serializes b into the Ethereum RLP block format. func (b *Block) EncodeRLPEth(w io.Writer) error { return rlp.Encode(w, extblock{ @@ -304,25 +317,24 @@ func (b *Block) EncodeRLPEth(w io.Writer) error { }) } -func (b *Block) EncodeRLPTest(w io.Writer, ver uint32, data []byte) error { +func (b *Block) EncodeRLPTest(w io.Writer, ver uint32) error { return rlp.Encode(w, myextblock{ - Header: b.header, - Txs: b.transactions, - Uncles: b.uncles, - VersionNumber: ver, - ExtData: data, + Header: b.header, + Txs: b.transactions, + Uncles: b.uncles, + Version: ver, + ExtData: b.extdata, }) } // EncodeRLP serializes b into an extended format. func (b *Block) EncodeRLP(w io.Writer) error { return rlp.Encode(w, myextblock{ - Header: b.header, - Txs: b.transactions, - Uncles: b.uncles, - VersionNumber: 0, - // TODO: add actual extra data for the current version - ExtData: []byte{}, + Header: b.header, + Txs: b.transactions, + Uncles: b.uncles, + Version: b.version, + ExtData: b.extdata, }) } -- cgit v1.2.3