Add Ethereum Classic specific handling in GetTransaction

ethereum
Martin Boehm 2018-11-30 11:39:28 +01:00
parent 61177c3750
commit c96c357013
3 changed files with 26 additions and 14 deletions

View File

@ -8,7 +8,6 @@ import (
"strconv"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/golang/glog"
"github.com/golang/protobuf/proto"
"github.com/juju/errors"
)
@ -76,6 +75,12 @@ type rpcReceipt struct {
Logs []*rpcLog `json:"logs"`
}
type rpcEtcReceipt struct {
GasUsed string `json:"gasUsed"`
Status int `json:"status"`
Logs []*rpcLog `json:"logs"`
}
type completeTransaction struct {
Tx *rpcTransaction `json:"tx"`
Receipt *rpcReceipt `json:"receipt,omitempty"`
@ -178,14 +183,8 @@ func (p *EthereumParser) GetAddrDescFromAddress(address string) (bchain.AddressD
address = address[2:]
}
if len(address) != EthereumTypeAddressDescriptorLen*2 {
if len(address) != 0 {
glog.Warning("Ignoring address ", address)
}
return nil, bchain.ErrAddressMissing
}
if len(address)&1 == 1 {
address = "0" + address
}
return hex.DecodeString(address)
}

View File

@ -529,7 +529,7 @@ func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) {
return nil, errors.Annotatef(err, "txid %v", txid)
}
} else {
// non mempool tx - we must read the block header to get the block time
// non mempool tx - read the block header to get the block time
raw, err := b.getBlockRaw(tx.BlockHash, 0, false)
if err != nil {
return nil, err
@ -545,9 +545,24 @@ func (b *EthereumRPC) GetTransaction(txid string) (*bchain.Tx, error) {
return nil, errors.Annotatef(err, "txid %v", txid)
}
var receipt rpcReceipt
err = b.rpc.CallContext(ctx, &receipt, "eth_getTransactionReceipt", hash)
if err != nil {
return nil, errors.Annotatef(err, "txid %v", txid)
if b.isETC {
var etcReceipt rpcEtcReceipt
err = b.rpc.CallContext(ctx, &etcReceipt, "eth_getTransactionReceipt", hash)
if err != nil {
return nil, errors.Annotatef(err, "txid %v", txid)
}
receipt.GasUsed = etcReceipt.GasUsed
receipt.Logs = etcReceipt.Logs
if etcReceipt.Status == 0 {
receipt.Status = "0x0"
} else {
receipt.Status = "0x1"
}
} else {
err = b.rpc.CallContext(ctx, &receipt, "eth_getTransactionReceipt", hash)
if err != nil {
return nil, errors.Annotatef(err, "txid %v", txid)
}
}
n, err := ethNumber(tx.BlockNumber)
if err != nil {

View File

@ -72,9 +72,7 @@ func (d *RocksDB) GetAddrDescContracts(addrDesc bchain.AddressDescriptor) (*Addr
})
buf = buf[eth.EthereumTypeAddressDescriptorLen+l:]
}
return &AddrContracts{
EthTxs: et,
Contracts: c}, nil
return &AddrContracts{EthTxs: et, Contracts: c}, nil
}
func findContractInAddressContracts(contract bchain.AddressDescriptor, contracts []AddrContract) (int, bool) {