block_overrides.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package ethapi
  2. import (
  3. "github.com/ethereum/go-ethereum/common"
  4. "github.com/ethereum/go-ethereum/common/hexutil"
  5. "github.com/ethereum/go-ethereum/core/vm"
  6. )
  7. // BlockOverrides is a set of header fields to override.
  8. type BlockOverrides struct {
  9. Number *hexutil.Big
  10. Difficulty *hexutil.Big
  11. Time *hexutil.Big
  12. GasLimit *hexutil.Uint64
  13. Coinbase *common.Address
  14. Random *common.Hash
  15. BaseFee *hexutil.Big
  16. }
  17. // Apply overrides the given header fields into the given block context.
  18. func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
  19. if diff == nil {
  20. return
  21. }
  22. if diff.Number != nil {
  23. blockCtx.BlockNumber = diff.Number.ToInt()
  24. }
  25. if diff.Difficulty != nil {
  26. blockCtx.Difficulty = diff.Difficulty.ToInt()
  27. }
  28. if diff.Time != nil {
  29. blockCtx.Time = diff.Time.ToInt()
  30. }
  31. if diff.GasLimit != nil {
  32. blockCtx.GasLimit = uint64(*diff.GasLimit)
  33. }
  34. if diff.Coinbase != nil {
  35. blockCtx.Coinbase = *diff.Coinbase
  36. }
  37. if diff.Random != nil {
  38. blockCtx.Random = diff.Random
  39. }
  40. if diff.BaseFee != nil {
  41. blockCtx.BaseFee = diff.BaseFee.ToInt()
  42. }
  43. }