github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/app/rpc/types/types.go (about)

     1  package types
     2  
     3  import (
     4  	"fmt"
     5  	"math/big"
     6  	"strings"
     7  
     8  	"github.com/ethereum/go-ethereum/common"
     9  	"github.com/ethereum/go-ethereum/common/hexutil"
    10  	ethtypes "github.com/ethereum/go-ethereum/core/types"
    11  
    12  	watcher "github.com/fibonacci-chain/fbc/x/evm/watcher"
    13  )
    14  
    15  // Copied the Account and StorageResult types since they are registered under an
    16  // internal pkg on geth.
    17  
    18  // AccountResult struct for account proof
    19  type AccountResult struct {
    20  	Address      common.Address  `json:"address"`
    21  	AccountProof []string        `json:"accountProof"`
    22  	Balance      *hexutil.Big    `json:"balance"`
    23  	CodeHash     common.Hash     `json:"codeHash"`
    24  	Nonce        hexutil.Uint64  `json:"nonce"`
    25  	StorageHash  common.Hash     `json:"storageHash"`
    26  	StorageProof []StorageResult `json:"storageProof"`
    27  }
    28  
    29  // StorageResult defines the format for storage proof return
    30  type StorageResult struct {
    31  	Key   string       `json:"key"`
    32  	Value *hexutil.Big `json:"value"`
    33  	Proof []string     `json:"proof"`
    34  }
    35  
    36  // SendTxArgs represents the arguments to submit a new transaction into the transaction pool.
    37  // Duplicate struct definition since geth struct is in internal package
    38  // Ref: https://github.com/ethereum/go-ethereum/blob/release/1.9/internal/ethapi/api.go#L1346
    39  type SendTxArgs struct {
    40  	From     *common.Address `json:"from"`
    41  	To       *common.Address `json:"to"`
    42  	Gas      *hexutil.Uint64 `json:"gas"`
    43  	GasPrice *hexutil.Big    `json:"gasPrice"`
    44  	Value    *hexutil.Big    `json:"value"`
    45  	Nonce    *hexutil.Uint64 `json:"nonce"`
    46  	// We accept "data" and "input" for backwards-compatibility reasons. "input" is the
    47  	// newer name and should be preferred by clients.
    48  	Data  *hexutil.Bytes `json:"data"`
    49  	Input *hexutil.Bytes `json:"input"`
    50  }
    51  
    52  func (ca SendTxArgs) String() string {
    53  	var arg string
    54  	if ca.From != nil {
    55  		arg += fmt.Sprintf("From: %s, ", ca.From.String())
    56  	}
    57  	if ca.To != nil {
    58  		arg += fmt.Sprintf("To: %s, ", ca.To.String())
    59  	}
    60  	if ca.Gas != nil {
    61  		arg += fmt.Sprintf("Gas: %s, ", ca.Gas.String())
    62  	}
    63  	if ca.GasPrice != nil {
    64  		arg += fmt.Sprintf("GasPrice: %s, ", ca.GasPrice.String())
    65  	}
    66  	if ca.Value != nil {
    67  		arg += fmt.Sprintf("Value: %s, ", ca.Value.String())
    68  	}
    69  	if ca.Nonce != nil {
    70  		arg += fmt.Sprintf("Nonce: %s, ", ca.Nonce.String())
    71  	}
    72  	if ca.Data != nil {
    73  		arg += fmt.Sprintf("Data: %s, ", ca.Data.String())
    74  	}
    75  	if ca.Input != nil {
    76  		arg += fmt.Sprintf("Input: %s, ", ca.Input.String())
    77  	}
    78  	return strings.TrimRight(arg, ", ")
    79  }
    80  
    81  // CallArgs represents the arguments for a call.
    82  type CallArgs struct {
    83  	From     *common.Address `json:"from"`
    84  	To       *common.Address `json:"to"`
    85  	Gas      *hexutil.Uint64 `json:"gas"`
    86  	GasPrice *hexutil.Big    `json:"gasPrice"`
    87  	Value    *hexutil.Big    `json:"value"`
    88  	Data     *hexutil.Bytes  `json:"data"`
    89  }
    90  
    91  func (ca CallArgs) String() string {
    92  	var arg string
    93  	if ca.From != nil {
    94  		arg += fmt.Sprintf("From: %s, ", ca.From.String())
    95  	}
    96  	if ca.To != nil {
    97  		arg += fmt.Sprintf("To: %s, ", ca.To.String())
    98  	}
    99  	if ca.Gas != nil {
   100  		arg += fmt.Sprintf("Gas: %s, ", ca.Gas.String())
   101  	}
   102  	if ca.GasPrice != nil {
   103  		arg += fmt.Sprintf("GasPrice: %s, ", ca.GasPrice.String())
   104  	}
   105  	if ca.Value != nil {
   106  		arg += fmt.Sprintf("Value: %s, ", ca.Value.String())
   107  	}
   108  	if ca.Data != nil {
   109  		arg += fmt.Sprintf("Data: %s, ", ca.Data.String())
   110  	}
   111  	return strings.TrimRight(arg, ", ")
   112  }
   113  
   114  // EthHeaderWithBlockHash represents a block header in the Ethereum blockchain with block hash generated from Tendermint Block
   115  type EthHeaderWithBlockHash struct {
   116  	ParentHash  common.Hash         `json:"parentHash"`
   117  	UncleHash   common.Hash         `json:"sha3Uncles"`
   118  	Coinbase    common.Address      `json:"miner"`
   119  	Root        common.Hash         `json:"stateRoot"`
   120  	TxHash      common.Hash         `json:"transactionsRoot"`
   121  	ReceiptHash common.Hash         `json:"receiptsRoot"`
   122  	Bloom       ethtypes.Bloom      `json:"logsBloom"`
   123  	Difficulty  *hexutil.Big        `json:"difficulty"`
   124  	Number      *hexutil.Big        `json:"number"`
   125  	GasLimit    hexutil.Uint64      `json:"gasLimit"`
   126  	GasUsed     hexutil.Uint64      `json:"gasUsed"`
   127  	Time        hexutil.Uint64      `json:"timestamp"`
   128  	Extra       hexutil.Bytes       `json:"extraData"`
   129  	MixDigest   common.Hash         `json:"mixHash"`
   130  	Nonce       ethtypes.BlockNonce `json:"nonce"`
   131  	Hash        common.Hash         `json:"hash"`
   132  }
   133  type FeeHistoryResult struct {
   134  	OldestBlock  *hexutil.Big     `json:"oldestBlock"`
   135  	Reward       [][]*hexutil.Big `json:"reward,omitempty"`
   136  	BaseFee      []*hexutil.Big   `json:"baseFeePerGas,omitempty"`
   137  	GasUsedRatio []float64        `json:"gasUsedRatio"`
   138  }
   139  
   140  // SignTransactionResult represents a RLP encoded signed transaction.
   141  type SignTransactionResult struct {
   142  	Raw hexutil.Bytes        `json:"raw"`
   143  	Tx  *watcher.Transaction `json:"tx"`
   144  }
   145  
   146  type GPIn3Gears struct {
   147  	SafeLow *hexutil.Big `json:"safe_low"`
   148  	Average *hexutil.Big `json:"average"`
   149  	Fastest *hexutil.Big `json:"fastest"`
   150  }
   151  
   152  func NewGPIn3Gears(safelow, avg, fastest *big.Int) GPIn3Gears {
   153  	return GPIn3Gears{
   154  		SafeLow: (*hexutil.Big)(safelow),
   155  		Average: (*hexutil.Big)(avg),
   156  		Fastest: (*hexutil.Big)(fastest),
   157  	}
   158  }