Filtering

This commit is contained in:
obscuren 2015-02-04 15:05:47 -08:00
parent b1870631a4
commit 65158d39b0
13 changed files with 1146 additions and 661 deletions

View File

@ -21,7 +21,7 @@
}]; }];
var address = web3.eth.transact({ var address = web3.eth.transact({
data: "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056", data: "0x603880600c6000396000f3006001600060e060020a600035048063c6888fa114601857005b6021600435602b565b8060005260206000f35b600081600702905091905056",
gasprice: "1000000000000000", gasPrice: "1000000000000000",
gas: "10000", gas: "10000",
}); });
var contract = web3.eth.contract(address, desc); var contract = web3.eth.contract(address, desc);

View File

@ -32,17 +32,19 @@
web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080')); web3.setProvider(new web3.providers.HttpSyncProvider('http://localhost:8080'));
var desc = [{ var desc = [{
"name": "balance(address)", "name": "balance(address)",
"type": "function",
"inputs": [{ "inputs": [{
"name": "who", "name": "who",
"type": "address" "type": "address"
}], }],
"const": true, "constant": true,
"outputs": [{ "outputs": [{
"name": "value", "name": "value",
"type": "uint256" "type": "uint256"
}] }]
}, { }, {
"name": "send(address,uint256)", "name": "send(address,uint256)",
"type": "function",
"inputs": [{ "inputs": [{
"name": "to", "name": "to",
"type": "address" "type": "address"
@ -51,21 +53,31 @@
"type": "uint256" "type": "uint256"
}], }],
"outputs": [] "outputs": []
}, {
"name":"Changed",
"type":"event",
"inputs": [
{"name":"to","type":"address","indexed":false},
{"name":"amount","type":"uint256","indexed":true},
],
}]; }];
var address = web3.db.get("jevcoin", "address"); var address = "";//web3.db.get("jevcoin", "address");
if( address.length == 0 ) { if( address.length == 0 ) {
var code = "0x60056011565b60ae8060356000396000f35b64174876e800600033600160a060020a031660005260205260406000208190555056006001600060e060020a600035048063d0679d34146022578063e3d670d714603457005b602e6004356024356047565b60006000f35b603d600435608d565b8060005260206000f35b80600083600160a060020a0316600052602052604060002090815401908190555080600033600160a060020a031660005260205260406000209081540390819055505050565b6000600082600160a060020a0316600052602052604060002054905091905056"; var code = "0x60056011565b60b88060356000396000f35b64e8d4a51000600033600160a060020a0316600052602052604060002081905550560060e060020a6000350480637bb98a68146028578063d0679d34146034578063e3d670d714604657005b602e60b3565b60006000f35b60406004356024356059565b60006000f35b604f6004356091565b8060005260206000f35b8060005281600160a060020a03167fb52dda022b6c1a1f40905a85f257f689aa5d69d850e49cf939d688fbe5af594660206000a25050565b6000600082600160a060020a03166000526020526040600020549050919050565b5b60008156";
address = web3.eth.transact({ address = web3.eth.transact({
data: code, data: code,
gasprice: "1000000000000000", gasPrice: "1000000000000000",
gas: "10000", gas: "10000",
}); });
web3.db.put("jevcoin", "address", address); web3.db.put("jevcoin", "address", address);
} }
var contract = web3.eth.contract(address, desc); var contract = web3.eth.contract(address, desc);
contract.Changed({to: "0xaabb"}).changed(function(e) {
console.log("e: " + JSON.stringify(e));
});
contract.transact({gas: "10000", gasprice: eth.gasPrice}).send( "0xaa", 10000 );
function reflesh() { function reflesh() {
document.querySelector("#balance").innerHTML = contract.call().balance(eth.coinbase); document.querySelector("#balance").innerHTML = contract.call().balance(eth.coinbase);

View File

@ -30,6 +30,10 @@
<td id="accounts"></td> <td id="accounts"></td>
</tr> </tr>
<tr>
<td>Balance</td>
<td id="balance"></td>
<tr> <tr>
<td>Gas price</td> <td>Gas price</td>
<td id="gas_price"></td> <td id="gas_price"></td>
@ -63,6 +67,7 @@
document.querySelector("#peer_count").innerHTML = eth.peerCount; document.querySelector("#peer_count").innerHTML = eth.peerCount;
document.querySelector("#default_block").innerHTML = eth.defaultBlock; document.querySelector("#default_block").innerHTML = eth.defaultBlock;
document.querySelector("#accounts").innerHTML = eth.accounts; document.querySelector("#accounts").innerHTML = eth.accounts;
document.querySelector("#balance").innerHTML = web3.toEth(eth.balanceAt(eth.accounts[0]));
document.querySelector("#gas_price").innerHTML = eth.gasPrice; document.querySelector("#gas_price").innerHTML = eth.gasPrice;
document.querySelector("#mining").innerHTML = eth.mining; document.querySelector("#mining").innerHTML = eth.mining;
document.querySelector("#listening").innerHTML = eth.listening; document.querySelector("#listening").innerHTML = eth.listening;

File diff suppressed because it is too large Load Diff

View File

@ -110,6 +110,8 @@ func (self *BlockProcessor) ApplyTransaction(coinbase *state.StateObject, state
go self.eventMux.Post(TxPostEvent{tx}) go self.eventMux.Post(TxPostEvent{tx})
} }
go self.eventMux.Post(state.Logs())
return receipt, txGas, err return receipt, txGas, err
} }
@ -155,25 +157,25 @@ done:
return receipts, handled, unhandled, erroneous, err return receipts, handled, unhandled, erroneous, err
} }
func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, msgs state.Messages, err error) { func (sm *BlockProcessor) Process(block *types.Block) (td *big.Int, err error) {
// Processing a blocks may never happen simultaneously // Processing a blocks may never happen simultaneously
sm.mutex.Lock() sm.mutex.Lock()
defer sm.mutex.Unlock() defer sm.mutex.Unlock()
header := block.Header() header := block.Header()
if sm.bc.HasBlock(header.Hash()) { if sm.bc.HasBlock(header.Hash()) {
return nil, nil, &KnownBlockError{header.Number, header.Hash()} return nil, &KnownBlockError{header.Number, header.Hash()}
} }
if !sm.bc.HasBlock(header.ParentHash) { if !sm.bc.HasBlock(header.ParentHash) {
return nil, nil, ParentError(header.ParentHash) return nil, ParentError(header.ParentHash)
} }
parent := sm.bc.GetBlock(header.ParentHash) parent := sm.bc.GetBlock(header.ParentHash)
return sm.ProcessWithParent(block, parent) return sm.ProcessWithParent(block, parent)
} }
func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, messages state.Messages, err error) { func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big.Int, err error) {
sm.lastAttemptedBlock = block sm.lastAttemptedBlock = block
state := state.New(parent.Root(), sm.db) state := state.New(parent.Root(), sm.db)
@ -227,7 +229,6 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
state.Sync() state.Sync()
// Set the block hashes for the current messages // Set the block hashes for the current messages
state.Manifest().SetHash(block.Hash()) state.Manifest().SetHash(block.Hash())
messages = state.Manifest().Messages
// Reset the manifest XXX We need this? // Reset the manifest XXX We need this?
state.Manifest().Reset() state.Manifest().Reset()
// Remove transactions from the pool // Remove transactions from the pool
@ -235,7 +236,7 @@ func (sm *BlockProcessor) ProcessWithParent(block, parent *types.Block) (td *big
chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4]) chainlogger.Infof("processed block #%d (%x...)\n", header.Number, block.Hash()[0:4])
return td, messages, nil return td, nil
} }
// Validates the current block. Returns an error if the block was invalid, // Validates the current block. Returns an error if the block was invalid,

View File

@ -359,7 +359,7 @@ func (bc *ChainManager) Stop() {
func (self *ChainManager) InsertChain(chain types.Blocks) error { func (self *ChainManager) InsertChain(chain types.Blocks) error {
for _, block := range chain { for _, block := range chain {
td, messages, err := self.processor.Process(block) td, err := self.processor.Process(block)
if err != nil { if err != nil {
if IsKnownBlockErr(err) { if IsKnownBlockErr(err) {
continue continue
@ -391,7 +391,6 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
self.mu.Unlock() self.mu.Unlock()
self.eventMux.Post(NewBlockEvent{block}) self.eventMux.Post(NewBlockEvent{block})
self.eventMux.Post(messages)
} }
return nil return nil

View File

@ -2,6 +2,7 @@ package core
import ( import (
"bytes" "bytes"
"fmt"
"math" "math"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -130,6 +131,7 @@ func (self *Filter) Find() state.Logs {
func includes(addresses [][]byte, a []byte) (found bool) { func includes(addresses [][]byte, a []byte) (found bool) {
for _, addr := range addresses { for _, addr := range addresses {
fmt.Println("INCLUDES", addr, a)
if bytes.Compare(addr, a) == 0 { if bytes.Compare(addr, a) == 0 {
return true return true
} }
@ -139,20 +141,25 @@ func includes(addresses [][]byte, a []byte) (found bool) {
} }
func (self *Filter) FilterLogs(logs state.Logs) state.Logs { func (self *Filter) FilterLogs(logs state.Logs) state.Logs {
fmt.Println("FILTER LOGS", self.topics)
var ret state.Logs var ret state.Logs
// Filter the logs for interesting stuff // Filter the logs for interesting stuff
for _, log := range logs { for _, log := range logs {
fmt.Println(log)
if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) { if len(self.address) > 0 && !bytes.Equal(self.address, log.Address()) {
continue continue
} }
for _, topic := range self.topics { for _, topic := range self.topics {
fmt.Println("TOPIC:", topic)
if !includes(log.Topics(), topic) { if !includes(log.Topics(), topic) {
continue continue
} }
} }
fmt.Println("APPENDED")
ret = append(ret, log) ret = append(ret, log)
} }

View File

@ -1,11 +1,7 @@
package types package types
import ( import "math/big"
"math/big"
"github.com/ethereum/go-ethereum/state"
)
type BlockProcessor interface { type BlockProcessor interface {
Process(*Block) (*big.Int, state.Messages, error) Process(*Block) (*big.Int, error)
} }

View File

@ -59,7 +59,7 @@ func (self *FilterManager) GetFilter(id int) *core.Filter {
func (self *FilterManager) filterLoop() { func (self *FilterManager) filterLoop() {
// Subscribe to events // Subscribe to events
events := self.eventMux.Subscribe(core.NewBlockEvent{}, state.Messages(nil)) events := self.eventMux.Subscribe(core.NewBlockEvent{}, state.Logs(nil))
out: out:
for { for {

View File

@ -41,6 +41,10 @@ func env(block *types.Block, eth *eth.Ethereum) *environment {
return env return env
} }
type Agent interface {
Comms() chan<- *types.Block
}
type worker struct { type worker struct {
agents []chan<- *types.Block agents []chan<- *types.Block
mux *event.TypeMux mux *event.TypeMux
@ -68,11 +72,12 @@ out:
case event := <-events.Chan(): case event := <-events.Chan():
switch event := event.(type) { switch event := event.(type) {
case core.NewBlockEvent: case core.NewBlockEvent:
block := event.Block if self.eth.ChainManager().HasBlock(event.Block.Hash()) {
if self.eth.ChainManager().HasBlock(block.Hash()) { }
} else if true { case core.TxPreEvent:
if err := self.commitTransaction(event.Tx); err != nil {
self.commit()
} }
case core.TxPreEvent, *LocalTx:
} }
case <-self.quit: case <-self.quit:
break out break out

View File

@ -87,7 +87,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) { fn := func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Access-Control-Allow-Origin", "*")
rpchttplogger.Debugln("Handling request") rpchttplogger.DebugDetailln("Handling request")
reqParsed, reqerr := JSON.ParseRequestBody(req) reqParsed, reqerr := JSON.ParseRequestBody(req)
if reqerr != nil { if reqerr != nil {
@ -103,7 +103,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
return return
} }
rpchttplogger.Debugf("Generated response: %T %s", response, response) rpchttplogger.DebugDetailf("Generated response: %T %s", response, response)
JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response}) JSON.Send(w, &rpc.RpcSuccessResponse{JsonRpc: reqParsed.JsonRpc, ID: reqParsed.ID, Error: false, Result: response})
} }

View File

@ -206,6 +206,7 @@ func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) {
if len(req.Params) < 1 { if len(req.Params) < 1 {
return nil, NewErrorResponse(ErrorArguments) return nil, NewErrorResponse(ErrorArguments)
} }
fmt.Println("filter params", req.Params)
args := new(FilterOptions) args := new(FilterOptions)
r := bytes.NewReader(req.Params[0]) r := bytes.NewReader(req.Params[0])

View File

@ -18,10 +18,11 @@ package rpc
import ( import (
"encoding/json" "encoding/json"
"github.com/ethereum/go-ethereum/logger"
"io" "io"
"net/http" "net/http"
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/state"
) )
@ -36,7 +37,7 @@ func (self JsonWrapper) Send(writer io.Writer, v interface{}) (n int, err error)
rpclogger.Fatalln("Error marshalling JSON", err) rpclogger.Fatalln("Error marshalling JSON", err)
return 0, err return 0, err
} }
rpclogger.Infof("Sending payload: %s", payload) rpclogger.DebugDetailf("Sending payload: %s", payload)
return writer.Write(payload) return writer.Write(payload)
} }