mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-23 12:07:17 +00:00
Get transaction implemented
* Added a GetTransaction to XEth * Implemented the `eth_getTransactionByHash` RPC method
This commit is contained in:
parent
26a5636424
commit
2273155e7e
18
rpc/api.go
18
rpc/api.go
@ -421,6 +421,14 @@ func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *EthereumApi) GetTransactionByHash(hash string, reply *interface{}) error {
|
||||
tx := p.xeth().EthTransactionByHash(hash)
|
||||
if tx != nil {
|
||||
*reply = NewTransactionRes(tx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) {
|
||||
block := p.xeth().EthBlockByHash(blockhash)
|
||||
br := NewBlockRes(block)
|
||||
@ -594,14 +602,18 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
}
|
||||
*reply = v
|
||||
case "eth_getTransactionByHash":
|
||||
return errNotImplemented
|
||||
// HashIndexArgs used, but only the "Hash" part we need.
|
||||
args := new(HashIndexArgs)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
}
|
||||
return p.GetTransactionByHash(args.Hash, reply)
|
||||
case "eth_getTransactionByBlockHashAndIndex":
|
||||
args := new(HashIndexArgs)
|
||||
if err := json.Unmarshal(req.Params, &args); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := p.GetBlockByHash(args.BlockHash, true)
|
||||
v, err := p.GetBlockByHash(args.Hash, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -629,7 +641,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
|
||||
return err
|
||||
}
|
||||
|
||||
v, err := p.GetBlockByHash(args.BlockHash, false)
|
||||
v, err := p.GetBlockByHash(args.Hash, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -280,8 +280,8 @@ func (args *BlockNumIndexArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
}
|
||||
|
||||
type HashIndexArgs struct {
|
||||
BlockHash string
|
||||
Index int64
|
||||
Hash string
|
||||
Index int64
|
||||
}
|
||||
|
||||
func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
@ -299,7 +299,7 @@ func (args *HashIndexArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
if !ok {
|
||||
return errDecodeArgs
|
||||
}
|
||||
args.BlockHash = arg0
|
||||
args.Hash = arg0
|
||||
|
||||
if len(obj) > 1 {
|
||||
arg1, ok := obj[1].(string)
|
||||
|
13
xeth/xeth.go
13
xeth/xeth.go
@ -32,6 +32,7 @@ type Backend interface {
|
||||
Peers() []*p2p.Peer
|
||||
BlockDb() ethutil.Database
|
||||
StateDb() ethutil.Database
|
||||
ExtraDb() ethutil.Database
|
||||
EventMux() *event.TypeMux
|
||||
Whisper() *whisper.Whisper
|
||||
|
||||
@ -127,6 +128,14 @@ func (self *XEth) EthBlockByHash(strHash string) *types.Block {
|
||||
return block
|
||||
}
|
||||
|
||||
func (self *XEth) EthTransactionByHash(hash string) *types.Transaction {
|
||||
data, _ := self.eth.ExtraDb().Get(fromHex(hash))
|
||||
if len(data) != 0 {
|
||||
return types.NewTransactionFromBytes(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *XEth) BlockByNumber(num int64) *Block {
|
||||
if num == -1 {
|
||||
return NewBlock(self.chainManager.CurrentBlock())
|
||||
@ -231,10 +240,6 @@ func (self *XEth) SecretToAddress(key string) string {
|
||||
return toHex(pair.Address())
|
||||
}
|
||||
|
||||
func (self *XEth) Execute(addr, value, gas, price, data string) (string, error) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
type KeyVal struct {
|
||||
Key string `json:"key"`
|
||||
Value string `json:"value"`
|
||||
|
Loading…
Reference in New Issue
Block a user