Skip to content

Commit 35add89

Browse files
committed
Merge pull request bnb-chain#1397 from tgerring/rpcreceipt
getTransactionReceipt RPC support
2 parents 46e7c85 + 6c7f5e3 commit 35add89

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

‎rpc/api/eth.go‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var (
7777
"eth_submitWork": (*ethApi).SubmitWork,
7878
"eth_resend": (*ethApi).Resend,
7979
"eth_pendingTransactions": (*ethApi).PendingTransactions,
80+
"eth_getTransactionReceipt": (*ethApi).GetTransactionReceipt,
8081
}
8182
)
8283

@@ -596,3 +597,28 @@ func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error
596597

597598
return ltxs, nil
598599
}
600+
601+
func (self *ethApi) GetTransactionReceipt(req *shared.Request) (interface{}, error) {
602+
args := new(HashArgs)
603+
if err := self.codec.Decode(req.Params, &args); err != nil {
604+
return nil, shared.NewDecodeParamError(err.Error())
605+
}
606+
607+
txhash := common.BytesToHash(common.FromHex(args.Hash))
608+
tx, bhash, bnum, txi := self.xeth.EthTransactionByHash(args.Hash)
609+
rec := self.xeth.GetTxReceipt(txhash)
610+
// We could have an error of "not found". Should disambiguate
611+
// if err != nil {
612+
// return err, nil
613+
// }
614+
if rec != nil && tx != nil {
615+
v := NewReceiptRes(rec)
616+
v.BlockHash = newHexData(bhash)
617+
v.BlockNumber = newHexNum(bnum)
618+
v.GasUsed = newHexNum(tx.Gas().Bytes())
619+
v.TransactionIndex = newHexNum(txi)
620+
return v, nil
621+
}
622+
623+
return nil, nil
624+
}

‎rpc/api/parsing.go‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package api
22

33
import (
4+
"bytes"
45
"encoding/binary"
56
"encoding/hex"
67
"encoding/json"
@@ -402,6 +403,38 @@ func NewUncleRes(h *types.Header) *UncleRes {
402403
// WorkProved string `json:"workProved"`
403404
// }
404405

406+
type ReceiptRes struct {
407+
TransactionHash *hexdata `json:transactionHash`
408+
TransactionIndex *hexnum `json:transactionIndex`
409+
BlockNumber *hexnum `json:blockNumber`
410+
BlockHash *hexdata `json:blockHash`
411+
CumulativeGasUsed *hexnum `json:cumulativeGasUsed`
412+
GasUsed *hexnum `json:gasUsed`
413+
ContractAddress *hexdata `json:contractAddress`
414+
Logs *[]interface{} `json:logs`
415+
}
416+
417+
func NewReceiptRes(rec *types.Receipt) *ReceiptRes {
418+
if rec == nil {
419+
return nil
420+
}
421+
422+
var v = new(ReceiptRes)
423+
v.TransactionHash = newHexData(rec.TxHash)
424+
// v.TransactionIndex = newHexNum(input)
425+
// v.BlockNumber = newHexNum(input)
426+
// v.BlockHash = newHexData(input)
427+
v.CumulativeGasUsed = newHexNum(rec.CumulativeGasUsed)
428+
// v.GasUsed = newHexNum(input)
429+
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
430+
if bytes.Compare(rec.ContractAddress.Bytes(), bytes.Repeat([]byte{0}, 20)) != 0 {
431+
v.ContractAddress = newHexData(rec.ContractAddress)
432+
}
433+
// v.Logs = rec.Logs()
434+
435+
return v
436+
}
437+
405438
func numString(raw interface{}) (*big.Int, error) {
406439
var number *big.Int
407440
// Parse as integer

‎rpc/api/utils.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ var (
8686
"submitWork",
8787
"pendingTransactions",
8888
"resend",
89+
"getTransactionReceipt",
8990
},
9091
"miner": []string{
9192
"hashrate",

‎xeth/xeth.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,6 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
969969
if contractCreation {
970970
addr := crypto.CreateAddress(from, nonce)
971971
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
972-
return addr.Hex(), nil
973972
} else {
974973
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
975974
}

0 commit comments

Comments
 (0)