Merge pull request #1397 from tgerring/rpcreceipt

getTransactionReceipt RPC support
pull/1410/head
Jeffrey Wilcke 9 years ago
commit 35add89c87
  1. 26
      rpc/api/eth.go
  2. 33
      rpc/api/parsing.go
  3. 1
      rpc/api/utils.go
  4. 1
      xeth/xeth.go

@ -77,6 +77,7 @@ var (
"eth_submitWork": (*ethApi).SubmitWork,
"eth_resend": (*ethApi).Resend,
"eth_pendingTransactions": (*ethApi).PendingTransactions,
"eth_getTransactionReceipt": (*ethApi).GetTransactionReceipt,
}
)
@ -596,3 +597,28 @@ func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error
return ltxs, nil
}
func (self *ethApi) GetTransactionReceipt(req *shared.Request) (interface{}, error) {
args := new(HashArgs)
if err := self.codec.Decode(req.Params, &args); err != nil {
return nil, shared.NewDecodeParamError(err.Error())
}
txhash := common.BytesToHash(common.FromHex(args.Hash))
tx, bhash, bnum, txi := self.xeth.EthTransactionByHash(args.Hash)
rec := self.xeth.GetTxReceipt(txhash)
// We could have an error of "not found". Should disambiguate
// if err != nil {
// return err, nil
// }
if rec != nil && tx != nil {
v := NewReceiptRes(rec)
v.BlockHash = newHexData(bhash)
v.BlockNumber = newHexNum(bnum)
v.GasUsed = newHexNum(tx.Gas().Bytes())
v.TransactionIndex = newHexNum(txi)
return v, nil
}
return nil, nil
}

@ -1,6 +1,7 @@
package api
import (
"bytes"
"encoding/binary"
"encoding/hex"
"encoding/json"
@ -402,6 +403,38 @@ func NewUncleRes(h *types.Header) *UncleRes {
// WorkProved string `json:"workProved"`
// }
type ReceiptRes struct {
TransactionHash *hexdata `json:transactionHash`
TransactionIndex *hexnum `json:transactionIndex`
BlockNumber *hexnum `json:blockNumber`
BlockHash *hexdata `json:blockHash`
CumulativeGasUsed *hexnum `json:cumulativeGasUsed`
GasUsed *hexnum `json:gasUsed`
ContractAddress *hexdata `json:contractAddress`
Logs *[]interface{} `json:logs`
}
func NewReceiptRes(rec *types.Receipt) *ReceiptRes {
if rec == nil {
return nil
}
var v = new(ReceiptRes)
v.TransactionHash = newHexData(rec.TxHash)
// v.TransactionIndex = newHexNum(input)
// v.BlockNumber = newHexNum(input)
// v.BlockHash = newHexData(input)
v.CumulativeGasUsed = newHexNum(rec.CumulativeGasUsed)
// v.GasUsed = newHexNum(input)
// If the ContractAddress is 20 0x0 bytes, assume it is not a contract creation
if bytes.Compare(rec.ContractAddress.Bytes(), bytes.Repeat([]byte{0}, 20)) != 0 {
v.ContractAddress = newHexData(rec.ContractAddress)
}
// v.Logs = rec.Logs()
return v
}
func numString(raw interface{}) (*big.Int, error) {
var number *big.Int
// Parse as integer

@ -86,6 +86,7 @@ var (
"submitWork",
"pendingTransactions",
"resend",
"getTransactionReceipt",
},
"miner": []string{
"hashrate",

@ -969,7 +969,6 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
if contractCreation {
addr := crypto.CreateAddress(from, nonce)
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
return addr.Hex(), nil
} else {
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
}

Loading…
Cancel
Save