-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
align types/block.go with subnet-evm (#463)
* align types/block.go with addative upstream * align with subnet-evm for now * add copyright header * rename to WithExtData
- Loading branch information
Showing
18 changed files
with
97 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// (c) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package types | ||
|
||
import ( | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
func (b *Block) WithExtData(version uint32, extdata *[]byte) *Block { | ||
b.version = version | ||
b.setExtDataHelper(extdata, false) | ||
return b | ||
} | ||
|
||
func (b *Block) setExtDataHelper(data *[]byte, recalc bool) { | ||
if data == nil { | ||
b.setExtData(nil, recalc) | ||
return | ||
} | ||
b.setExtData(*data, recalc) | ||
} | ||
|
||
func (b *Block) setExtData(data []byte, recalc bool) { | ||
_data := make([]byte, len(data)) | ||
b.extdata = &_data | ||
copy(*b.extdata, data) | ||
if recalc { | ||
b.header.ExtDataHash = CalcExtDataHash(*b.extdata) | ||
} | ||
} | ||
|
||
func (b *Block) ExtData() []byte { | ||
if b.extdata == nil { | ||
return nil | ||
} | ||
return *b.extdata | ||
} | ||
|
||
func (b *Block) Version() uint32 { | ||
return b.version | ||
} | ||
|
||
func (b *Block) ExtDataGasUsed() *big.Int { | ||
if b.header.ExtDataGasUsed == nil { | ||
return nil | ||
} | ||
return new(big.Int).Set(b.header.ExtDataGasUsed) | ||
} | ||
|
||
func CalcExtDataHash(extdata []byte) common.Hash { | ||
if len(extdata) == 0 { | ||
return EmptyExtDataHash | ||
} | ||
return rlpHash(extdata) | ||
} | ||
|
||
func NewBlockWithExtData( | ||
header *Header, txs []*Transaction, uncles []*Header, receipts []*Receipt, | ||
hasher TrieHasher, extdata []byte, recalc bool, | ||
) *Block { | ||
b := NewBlock(header, txs, uncles, receipts, hasher) | ||
b.setExtData(extdata, recalc) | ||
return b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.