Commit 7e160a67 authored by obscuren's avatar obscuren

xeth, core, event/filter, rpc: new block and transaction filters

parent 97c37356
...@@ -22,9 +22,9 @@ type Filter struct { ...@@ -22,9 +22,9 @@ type Filter struct {
max int max int
topics [][]common.Hash topics [][]common.Hash
BlockCallback func(*types.Block, state.Logs) BlockCallback func(*types.Block, state.Logs)
PendingCallback func(*types.Transaction) TransactionCallback func(*types.Transaction)
LogsCallback func(state.Logs) LogsCallback func(state.Logs)
} }
// Create a new filter which uses a bloom filter on blocks to figure out whether a particular block // Create a new filter which uses a bloom filter on blocks to figure out whether a particular block
......
...@@ -88,8 +88,8 @@ out: ...@@ -88,8 +88,8 @@ out:
case core.TxPreEvent: case core.TxPreEvent:
self.filterMu.RLock() self.filterMu.RLock()
for _, filter := range self.filters { for _, filter := range self.filters {
if filter.PendingCallback != nil { if filter.TransactionCallback != nil {
filter.PendingCallback(event.Tx) filter.TransactionCallback(event.Tx)
} }
} }
self.filterMu.RUnlock() self.filterMu.RUnlock()
......
...@@ -322,14 +322,13 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err ...@@ -322,14 +322,13 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
return err return err
} }
id := api.xeth().RegisterFilter(args.Earliest, args.Latest, args.Skip, args.Max, args.Address, args.Topics) id := api.xeth().NewLogFilter(args.Earliest, args.Latest, args.Skip, args.Max, args.Address, args.Topics)
*reply = newHexNum(big.NewInt(int64(id)).Bytes()) *reply = newHexNum(big.NewInt(int64(id)).Bytes())
case "eth_newBlockFilter": case "eth_newBlockFilter":
args := new(FilterStringArgs) *reply = newHexNum(api.xeth().NewBlockFilter())
if err := json.Unmarshal(req.Params, &args); err != nil { case "eth_transactionFilter":
return err *reply = newHexNum(api.xeth().NewTransactionFilter())
}
*reply = newHexNum(api.xeth().NewFilterString(args.Word))
case "eth_uninstallFilter": case "eth_uninstallFilter":
args := new(FilterIdArgs) args := new(FilterIdArgs)
if err := json.Unmarshal(req.Params, &args); err != nil { if err := json.Unmarshal(req.Params, &args); err != nil {
...@@ -341,7 +340,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err ...@@ -341,7 +340,17 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
if err := json.Unmarshal(req.Params, &args); err != nil { if err := json.Unmarshal(req.Params, &args); err != nil {
return err return err
} }
*reply = NewLogsRes(api.xeth().FilterChanged(args.Id))
switch api.xeth().GetFilterType(args.Id) {
case xeth.BlockFilterTy:
*reply = NewHashesRes(api.xeth().BlockFilterChanged(args.Id))
case xeth.TransactionFilterTy:
*reply = NewHashesRes(api.xeth().TransactionFilterChanged(args.Id))
case xeth.LogFilterTy:
*reply = NewLogsRes(api.xeth().LogFilterChanged(args.Id))
default:
*reply = []string{} // reply empty string slice
}
case "eth_getFilterLogs": case "eth_getFilterLogs":
args := new(FilterIdArgs) args := new(FilterIdArgs)
if err := json.Unmarshal(req.Params, &args); err != nil { if err := json.Unmarshal(req.Params, &args); err != nil {
......
...@@ -3,6 +3,7 @@ package rpc ...@@ -3,6 +3,7 @@ package rpc
import ( import (
"encoding/json" "encoding/json"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
) )
...@@ -303,3 +304,13 @@ func NewLogsRes(logs state.Logs) (ls []LogRes) { ...@@ -303,3 +304,13 @@ func NewLogsRes(logs state.Logs) (ls []LogRes) {
return return
} }
func NewHashesRes(hs []common.Hash) []string {
hashes := make([]string, len(hs))
for i, hash := range hs {
hashes[i] = hash.Hex()
}
return hashes
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment