Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ type EthereumSpecific struct {
GasLimit *big.Int `json:"gasLimit"`
GasUsed *big.Int `json:"gasUsed,omitempty"`
GasPrice *Amount `json:"gasPrice,omitempty"`
L1Fee *big.Int `json:"l1Fee,omitempty"`
L1FeeScalar string `json:"l1FeeScalar,omitempty"`
L1GasPrice *Amount `json:"l1GasPrice,omitempty"`
L1GasUsed *big.Int `json:"l1GasUsed,omitempty"`
Data string `json:"data,omitempty"`
ParsedData *bchain.EthereumParsedInputData `json:"parsedData,omitempty"`
InternalTransfers []EthereumInternalTransfer `json:"internalTransfers,omitempty"`
Expand Down
21 changes: 14 additions & 7 deletions api/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,18 +429,25 @@ func (w *Worker) getTransactionFromBchainTx(bchainTx *bchain.Tx, height int, spe
// mempool txs do not have fees yet
if ethTxData.GasUsed != nil {
feesSat.Mul(ethTxData.GasPrice, ethTxData.GasUsed)
if ethTxData.L1Fee != nil {
feesSat.Add(&feesSat, ethTxData.L1Fee)
}
}
if len(bchainTx.Vout) > 0 {
valOutSat = bchainTx.Vout[0].ValueSat
}
ethSpecific = &EthereumSpecific{
GasLimit: ethTxData.GasLimit,
GasPrice: (*Amount)(ethTxData.GasPrice),
GasUsed: ethTxData.GasUsed,
Nonce: ethTxData.Nonce,
Status: ethTxData.Status,
Data: ethTxData.Data,
ParsedData: parsedInputData,
GasLimit: ethTxData.GasLimit,
GasPrice: (*Amount)(ethTxData.GasPrice),
GasUsed: ethTxData.GasUsed,
L1Fee: ethTxData.L1Fee,
L1FeeScalar: ethTxData.L1FeeScalar,
L1GasPrice: (*Amount)(ethTxData.L1GasPrice),
L1GasUsed: ethTxData.L1GasUsed,
Nonce: ethTxData.Nonce,
Status: ethTxData.Status,
Data: ethTxData.Data,
ParsedData: parsedInputData,
}
if internalData != nil {
ethSpecific.Type = internalData.Type
Expand Down
3 changes: 3 additions & 0 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/trezor/blockbook/bchain/coins/namecoin"
"github.com/trezor/blockbook/bchain/coins/nuls"
"github.com/trezor/blockbook/bchain/coins/omotenashicoin"
"github.com/trezor/blockbook/bchain/coins/optimism"
"github.com/trezor/blockbook/bchain/coins/pivx"
"github.com/trezor/blockbook/bchain/coins/polis"
"github.com/trezor/blockbook/bchain/coins/polygon"
Expand Down Expand Up @@ -138,6 +139,8 @@ func init() {
BlockChainFactories["BNB Smart Chain Archive"] = bsc.NewBNBSmartChainRPC
BlockChainFactories["Polygon"] = polygon.NewPolygonRPC
BlockChainFactories["Polygon Archive"] = polygon.NewPolygonRPC
BlockChainFactories["Optimism"] = optimism.NewOptimismRPC
BlockChainFactories["Optimism Archive"] = optimism.NewOptimismRPC
}

// NewBlockChain creates bchain.BlockChain and bchain.Mempool for the coin passed by the parameter coin
Expand Down
66 changes: 51 additions & 15 deletions bchain/coins/eth/ethparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"strings"

"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/golang/protobuf/proto"
"github.com/juju/errors"
"github.com/trezor/blockbook/bchain"
"golang.org/x/crypto/sha3"
"google.golang.org/protobuf/proto"
)

// EthereumTypeAddressDescriptorLen - the AddressDescriptor of EthereumType has fixed length
Expand Down Expand Up @@ -331,6 +331,24 @@ func (p *EthereumParser) PackTx(tx *bchain.Tx, height uint32, blockTime int64) (

}
pt.Receipt.Log = ptLogs
if r.Receipt.L1Fee != "" {
if pt.Receipt.L1Fee, err = hexDecodeBig(r.Receipt.L1Fee); err != nil {
return nil, errors.Annotatef(err, "L1Fee %v", r.Receipt.L1Fee)
}
}
if r.Receipt.L1FeeScalar != "" {
pt.Receipt.L1FeeScalar = []byte(r.Receipt.L1FeeScalar)
}
if r.Receipt.L1GasPrice != "" {
if pt.Receipt.L1GasPrice, err = hexDecodeBig(r.Receipt.L1GasPrice); err != nil {
return nil, errors.Annotatef(err, "L1GasPrice %v", r.Receipt.L1GasPrice)
}
}
if r.Receipt.L1GasUsed != "" {
if pt.Receipt.L1GasUsed, err = hexDecodeBig(r.Receipt.L1GasUsed); err != nil {
return nil, errors.Annotatef(err, "L1GasUsed %v", r.Receipt.L1GasUsed)
}
}
}
return proto.Marshal(pt)
}
Expand Down Expand Up @@ -359,27 +377,37 @@ func (p *EthereumParser) UnpackTx(buf []byte) (*bchain.Tx, uint32, error) {
}
var rr *bchain.RpcReceipt
if pt.Receipt != nil {
logs := make([]*bchain.RpcLog, len(pt.Receipt.Log))
rr = &bchain.RpcReceipt{
GasUsed: hexEncodeBig(pt.Receipt.GasUsed),
Status: "",
Logs: make([]*bchain.RpcLog, len(pt.Receipt.Log)),
}
for i, l := range pt.Receipt.Log {
topics := make([]string, len(l.Topics))
for j, t := range l.Topics {
topics[j] = hexutil.Encode(t)
}
logs[i] = &bchain.RpcLog{
rr.Logs[i] = &bchain.RpcLog{
Address: EIP55Address(l.Address),
Data: hexutil.Encode(l.Data),
Topics: topics,
}
}
status := ""
// handle a special value []byte{'U'} as unknown state
if len(pt.Receipt.Status) != 1 || pt.Receipt.Status[0] != 'U' {
status = hexEncodeBig(pt.Receipt.Status)
rr.Status = hexEncodeBig(pt.Receipt.Status)
}
rr = &bchain.RpcReceipt{
GasUsed: hexEncodeBig(pt.Receipt.GasUsed),
Status: status,
Logs: logs,
if len(pt.Receipt.L1Fee) > 0 {
rr.L1Fee = hexEncodeBig(pt.Receipt.L1Fee)
}
if len(pt.Receipt.L1FeeScalar) > 0 {
rr.L1FeeScalar = string(pt.Receipt.L1FeeScalar)
}
if len(pt.Receipt.L1GasPrice) > 0 {
rr.L1GasPrice = hexEncodeBig(pt.Receipt.L1GasPrice)
}
if len(pt.Receipt.L1GasUsed) > 0 {
rr.L1GasUsed = hexEncodeBig(pt.Receipt.L1GasUsed)
}
}
// TODO handle internal transactions
Expand Down Expand Up @@ -477,12 +505,16 @@ const (

// EthereumTxData contains ethereum specific transaction data
type EthereumTxData struct {
Status TxStatus `json:"status"` // 1 OK, 0 Fail, -1 pending, -2 unknown
Nonce uint64 `json:"nonce"`
GasLimit *big.Int `json:"gaslimit"`
GasUsed *big.Int `json:"gasused"`
GasPrice *big.Int `json:"gasprice"`
Data string `json:"data"`
Status TxStatus `json:"status"` // 1 OK, 0 Fail, -1 pending, -2 unknown
Nonce uint64 `json:"nonce"`
GasLimit *big.Int `json:"gaslimit"`
GasUsed *big.Int `json:"gasused"`
GasPrice *big.Int `json:"gasprice"`
L1Fee *big.Int `json:"l1Fee,omitempty"`
L1FeeScalar string `json:"l1FeeScalar,omitempty"`
L1GasPrice *big.Int `json:"l1GasPrice,omitempty"`
L1GasUsed *big.Int `json:"L1GasUsed,omitempty"`
Data string `json:"data"`
}

// GetEthereumTxData returns EthereumTxData from bchain.Tx
Expand Down Expand Up @@ -511,6 +543,10 @@ func GetEthereumTxDataFromSpecificData(coinSpecificData interface{}) *EthereumTx
etd.Status = TxStatusFailure
}
etd.GasUsed, _ = hexutil.DecodeBig(csd.Receipt.GasUsed)
etd.L1Fee, _ = hexutil.DecodeBig(csd.Receipt.L1Fee)
etd.L1GasPrice, _ = hexutil.DecodeBig(csd.Receipt.L1GasPrice)
etd.L1GasUsed, _ = hexutil.DecodeBig(csd.Receipt.L1GasUsed)
etd.L1FeeScalar = csd.Receipt.L1FeeScalar
}
}
return &etd
Expand Down
14 changes: 9 additions & 5 deletions bchain/coins/eth/ethrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"math/big"
"net/http"
"strconv"
Expand Down Expand Up @@ -377,7 +377,7 @@ func (b *EthereumRPC) getConsensusVersion() string {
glog.Error("getConsensusVersion ", err)
return ""
}
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
glog.Error("getConsensusVersion ", err)
return ""
Expand Down Expand Up @@ -623,6 +623,9 @@ func (b *EthereumRPC) getCreationContractInfo(contract string, height uint32) *b

func (b *EthereumRPC) processCallTrace(call *rpcCallTrace, d *bchain.EthereumInternalData, contracts []bchain.ContractInfo, blockHeight uint32) []bchain.ContractInfo {
value, err := hexutil.DecodeBig(call.Value)
if err != nil {
value = new(big.Int)
}
if call.Type == "CREATE" || call.Type == "CREATE2" {
d.Transfers = append(d.Transfers, bchain.EthereumInternalTransfer{
Type: bchain.CREATE,
Expand Down Expand Up @@ -834,12 +837,13 @@ func (b *EthereumRPC) GetTransactionForMempool(txid string) (*bchain.Tx, error)
func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) {
ctx, cancel := context.WithTimeout(context.Background(), b.Timeout)
defer cancel()
var tx *bchain.RpcTransaction
tx := &bchain.RpcTransaction{}
hash := ethcommon.HexToHash(txid)
err := b.RPC.CallContext(ctx, &tx, "eth_getTransactionByHash", hash)
err := b.RPC.CallContext(ctx, tx, "eth_getTransactionByHash", hash)
if err != nil {
return nil, err
} else if tx == nil {
}
if *tx == (bchain.RpcTransaction{}) {
if b.mempoolInitialized {
b.Mempool.RemoveTransactionFromMempool(txid)
}
Expand Down
Loading