forked from cerc-io/plugeth
Merge pull request #1397 from tgerring/rpcreceipt
getTransactionReceipt RPC support
This commit is contained in:
commit
35add89c87
@ -77,6 +77,7 @@ var (
|
|||||||
"eth_submitWork": (*ethApi).SubmitWork,
|
"eth_submitWork": (*ethApi).SubmitWork,
|
||||||
"eth_resend": (*ethApi).Resend,
|
"eth_resend": (*ethApi).Resend,
|
||||||
"eth_pendingTransactions": (*ethApi).PendingTransactions,
|
"eth_pendingTransactions": (*ethApi).PendingTransactions,
|
||||||
|
"eth_getTransactionReceipt": (*ethApi).GetTransactionReceipt,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -596,3 +597,28 @@ func (self *ethApi) PendingTransactions(req *shared.Request) (interface{}, error
|
|||||||
|
|
||||||
return ltxs, nil
|
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
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@ -402,6 +403,38 @@ func NewUncleRes(h *types.Header) *UncleRes {
|
|||||||
// WorkProved string `json:"workProved"`
|
// 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) {
|
func numString(raw interface{}) (*big.Int, error) {
|
||||||
var number *big.Int
|
var number *big.Int
|
||||||
// Parse as integer
|
// Parse as integer
|
||||||
|
@ -86,6 +86,7 @@ var (
|
|||||||
"submitWork",
|
"submitWork",
|
||||||
"pendingTransactions",
|
"pendingTransactions",
|
||||||
"resend",
|
"resend",
|
||||||
|
"getTransactionReceipt",
|
||||||
},
|
},
|
||||||
"miner": []string{
|
"miner": []string{
|
||||||
"hashrate",
|
"hashrate",
|
||||||
|
@ -969,7 +969,6 @@ func (self *XEth) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceS
|
|||||||
if contractCreation {
|
if contractCreation {
|
||||||
addr := crypto.CreateAddress(from, nonce)
|
addr := crypto.CreateAddress(from, nonce)
|
||||||
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
|
glog.V(logger.Info).Infof("Tx(%x) created: %x\n", tx.Hash(), addr)
|
||||||
return addr.Hex(), nil
|
|
||||||
} else {
|
} else {
|
||||||
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
|
glog.V(logger.Info).Infof("Tx(%x) to: %x\n", tx.Hash(), tx.To())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user