From 6cc02aadbff9c37cc623fadb21029527a11a06f4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 19:58:59 -0400 Subject: Inline getStateWithNum --- rpc/api.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index d00b86ac0..7fc8f32e2 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -81,10 +81,6 @@ func (self *EthereumApi) xethWithStateNum(num int64) *xeth.XEth { return self.xeth().WithState(st) } -func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { - return self.xethWithStateNum(num).State() -} - func (self *EthereumApi) start() { timer := time.NewTicker(filterTickerTime) done: @@ -290,8 +286,7 @@ func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error if err := args.requirements(); err != nil { return err } - state := p.getStateWithNum(args.BlockNumber).SafeGet(args.Address) - *reply = common.ToHex(state.Balance().Bytes()) + *reply = common.ToHex(p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) return nil } @@ -299,7 +294,7 @@ func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error if err := args.requirements(); err != nil { return err } - *reply = p.getStateWithNum(args.BlockNumber).SafeGet(args.Address).Storage() + *reply = p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() return nil } @@ -307,9 +302,10 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e if err := args.requirements(); err != nil { return err } - state := p.getStateWithNum(args.BlockNumber).SafeGet(args.Address) + state := p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address) value := state.StorageString(args.Key) + var hx string if strings.Index(args.Key, "0x") == 0 { hx = string([]byte(args.Key)[2:]) -- cgit From b7745c683529bc60139d4af7fec2bf849928bfe7 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:00:18 -0400 Subject: inline HasWhisperIdentity --- rpc/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 7fc8f32e2..54efd6005 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -416,11 +416,6 @@ func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) return nil } -func (p *EthereumApi) HasWhisperIdentity(args string, reply *interface{}) error { - *reply = p.xeth().Whisper().HasIdentity(args) - return nil -} - func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error { *reply = p.xeth().Whisper().Messages(id) return nil @@ -763,7 +758,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.HasWhisperIdentity(args.Identity, reply) + *reply = p.xeth().Whisper().HasIdentity(args.Identity) case "shh_newGroup", "shh_addToGroup": return NewNotImplementedError(req.Method) case "shh_newFilter": -- cgit From 7562bc1dbc23b0b8a384de29729ea24daa5c45a0 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:00:41 -0400 Subject: inline GetBalance --- rpc/api.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 54efd6005..5654ee3d3 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -282,14 +282,6 @@ func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { return nil } -func (p *EthereumApi) GetBalance(args *GetBalanceArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - *reply = common.ToHex(p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) - return nil -} - func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -506,7 +498,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.GetBalance(args, reply) + + if err := args.requirements(); err != nil { + return err + } + + *reply = common.ToHex(p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) case "eth_getStorage", "eth_storageAt": args := new(GetStorageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 3aea64510671c8f411f2efb0fed09e371027f9e6 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:02:31 -0400 Subject: inline GetStorage --- rpc/api.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 5654ee3d3..d91618671 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -282,14 +282,6 @@ func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { return nil } -func (p *EthereumApi) GetStorage(args *GetStorageArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - *reply = p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() - return nil -} - func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -509,7 +501,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.GetStorage(args, reply) + + if err := args.requirements(); err != nil { + return err + } + + *reply = p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() case "eth_getStorageAt": args := new(GetStorageAtArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From e530c960a4b334815b3c9563b8b0b6809c082548 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:03:27 -0400 Subject: inline GetTxCountAt --- rpc/api.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index d91618671..820bb23b0 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,15 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) GetTxCountAt(args *GetTxCountArgs, reply *interface{}) error { - err := args.requirements() - if err != nil { - return err - } - *reply = p.xethWithStateNum(args.BlockNumber).TxCountAt(args.Address) - return nil -} - func (p *EthereumApi) GetData(args *GetDataArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -518,7 +509,13 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.GetTxCountAt(args, reply) + + err := args.requirements() + if err != nil { + return err + } + + *reply = p.xethWithStateNum(args.BlockNumber).TxCountAt(args.Address) case "eth_getBlockTransactionCountByHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 152b37ee116db8faa4d6dbc254336ba1fa7e94ab Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:04:02 -0400 Subject: inline GetData --- rpc/api.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 820bb23b0..f8ba82276 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,14 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) GetData(args *GetDataArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - *reply = p.xethWithStateNum(args.BlockNumber).CodeAt(args.Address) - return nil -} - func (p *EthereumApi) GetCompilers(reply *interface{}) error { c := []string{""} *reply = c @@ -565,7 +557,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.GetData(args, reply) + if err := args.requirements(); err != nil { + return err + } + *reply = p.xethWithStateNum(args.BlockNumber).CodeAt(args.Address) case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From d28cd0f04086ce618f16b5019d2fd3992469755a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:04:40 -0400 Subject: inline GetCompilers --- rpc/api.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index f8ba82276..432959bc2 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,12 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) GetCompilers(reply *interface{}) error { - c := []string{""} - *reply = c - return nil -} - func (p *EthereumApi) DbPut(args *DbArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -670,7 +664,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } *reply = uncle case "eth_getCompilers": - return p.GetCompilers(reply) + c := []string{""} + *reply = c case "eth_compileSolidity", "eth_compileLLL", "eth_compileSerpent": return NewNotImplementedError(req.Method) case "eth_newFilter": -- cgit From 6fef6168705a9e70f36560b100d276092ecb5bff Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:05:48 -0400 Subject: inline DbPut --- rpc/api.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 432959bc2..62b8199f1 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,16 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) DbPut(args *DbArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - - p.db.Put([]byte(args.Database+args.Key), []byte(args.Value)) - *reply = true - return nil -} - func (p *EthereumApi) DbGet(args *DbArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -711,7 +701,13 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.DbPut(args, reply) + + if err := args.requirements(); err != nil { + return err + } + + p.db.Put([]byte(args.Database+args.Key), []byte(args.Value)) + *reply = true case "db_getString": args := new(DbArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 57f6a3b5c06f1fcb6bfff5741a6f69f6cf55d89d Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:06:35 -0400 Subject: inline DbGet --- rpc/api.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 62b8199f1..e2a18528b 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,16 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) DbGet(args *DbArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - - res, _ := p.db.Get([]byte(args.Database + args.Key)) - *reply = string(res) - return nil -} - func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error { *reply = p.xeth().Whisper().NewIdentity() return nil @@ -713,7 +703,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.DbGet(args, reply) + if err := args.requirements(); err != nil { + return err + } + + res, _ := p.db.Get([]byte(args.Database + args.Key)) + *reply = string(res) case "db_putHex", "db_getHex": return NewNotImplementedError(req.Method) case "shh_post": -- cgit From 85e03217de038fc84f5161c81468ed7f218bd876 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:09:54 -0400 Subject: inline NewWhisperIdentity --- rpc/api.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index e2a18528b..0d67afca0 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,11 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error { - *reply = p.xeth().Whisper().NewIdentity() - return nil -} - // func (p *EthereumApi) RemoveWhisperIdentity(args *WhisperIdentityArgs, reply *interface{}) error { // *reply = p.xeth().Whisper().RemoveIdentity(args.Identity) // return nil @@ -703,6 +698,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } + if err := args.requirements(); err != nil { return err } @@ -718,7 +714,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } return p.WhisperPost(args, reply) case "shh_newIdentity": - return p.NewWhisperIdentity(reply) + *reply = p.xeth().Whisper().NewIdentity() // case "shh_removeIdentity": // args := new(WhisperIdentityArgs) // if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 0eb9572d642ee7fe5d730b6396f5c348c482e7d6 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:10:05 -0400 Subject: inline RemoveWhisperIdentity --- rpc/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 0d67afca0..7ecde4c24 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -303,11 +303,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -// func (p *EthereumApi) RemoveWhisperIdentity(args *WhisperIdentityArgs, reply *interface{}) error { -// *reply = p.xeth().Whisper().RemoveIdentity(args.Identity) -// return nil -// } - func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface{}) error { var id int opts := new(xeth.Options) @@ -720,7 +715,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error // if err := json.Unmarshal(req.Params, &args); err != nil { // return err // } - // return p.RemoveWhisperIdentity(args, reply) + // *reply = p.xeth().Whisper().RemoveIdentity(args.Identity) case "shh_hasIdentity": args := new(WhisperIdentityArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From cc91ba0add5e21a6d2f67a16ee5f08b74b597edd Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:12:12 -0400 Subject: inline GetTransactionByHash --- rpc/api.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 7ecde4c24..ff89bbecf 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -352,14 +352,6 @@ 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) @@ -566,7 +558,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error args := new(HashIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { } - return p.GetTransactionByHash(args.Hash, reply) + tx := p.xeth().EthTransactionByHash(hash) + if tx != nil { + *reply = NewTransactionRes(tx) + } case "eth_getTransactionByBlockHashAndIndex": args := new(HashIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From b28e6d830606346d42d46ab657d3ba2b5b1a994e Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:12:52 -0400 Subject: inline WhisperMessages --- rpc/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index ff89bbecf..2b2467400 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -347,11 +347,6 @@ func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) return nil } -func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error { - *reply = p.xeth().Whisper().Messages(id) - return nil -} - func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) { block := p.xeth().EthBlockByHash(blockhash) br := NewBlockRes(block) @@ -742,7 +737,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.WhisperMessages(args.Id, reply) + *reply = p.xeth().Whisper().Messages(id) // case "eth_register": // args, err := req.ToRegisterArgs() // if err != nil { -- cgit From 22546dcb5528109de910e722cfc1afd5446eb3eb Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:14:27 -0400 Subject: inline UninstallWhisperFilter --- rpc/api.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 2b2467400..cd34934cf 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -320,12 +320,6 @@ func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface return nil } -func (p *EthereumApi) UninstallWhisperFilter(id int, reply *interface{}) error { - delete(p.messages, id) - *reply = true - return nil -} - func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { self.messagesMut.Lock() defer self.messagesMut.Unlock() @@ -725,7 +719,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.UninstallWhisperFilter(args.Id, reply) + + if _, ok := p.messages[args.Id]; ok { + delete(p.messages, args.Id) + } + + *reply = true case "shh_getFilterChanges": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 7e6c8a411d73f1406ec12d6a75225a2a60fdfa45 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:26:09 -0400 Subject: fixes --- rpc/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index cd34934cf..fcab90f3b 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -547,7 +547,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error args := new(HashIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { } - tx := p.xeth().EthTransactionByHash(hash) + tx := p.xeth().EthTransactionByHash(args.Hash) if tx != nil { *reply = NewTransactionRes(tx) } @@ -736,7 +736,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - *reply = p.xeth().Whisper().Messages(id) + *reply = p.xeth().Whisper().Messages(args.Id) // case "eth_register": // args, err := req.ToRegisterArgs() // if err != nil { -- cgit From 216175c265e7c5a82e47df3302f285104593dfa8 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:28:25 -0400 Subject: inline GetBlockUncleCountByNumber --- rpc/api.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index fcab90f3b..acec7f457 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -373,12 +373,6 @@ func (p *EthereumApi) GetBlockUncleCountByHash(blockhash string) (int64, error) return int64(len(br.Uncles)), nil } -func (p *EthereumApi) GetBlockUncleCountByNumber(blocknum int64) (int64, error) { - block := p.xeth().EthBlockByNumber(blocknum) - br := NewBlockRes(block) - return int64(len(br.Uncles)), nil -} - func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Debugf("%s %s", req.Method, req.Params) @@ -492,11 +486,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockUncleCountByNumber(args.BlockNumber) - if err != nil { - return err - } - *reply = common.ToHex(big.NewInt(v).Bytes()) + block := p.xeth().EthBlockByNumber(args.BlockNumber) + br := NewBlockRes(block) + *reply = common.ToHex(big.NewInt(int64(len(br.Uncles))).Bytes()) case "eth_getData", "eth_getCode": args := new(GetDataArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From c57eb286d66c01af0116e12a2476f546727e88ae Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:29:46 -0400 Subject: inline GetBlockUncleCountByHash --- rpc/api.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index acec7f457..b17b51317 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -367,12 +367,6 @@ func (p *EthereumApi) GetBlockTransactionCountByNumber(blocknum int64) (int64, e return int64(len(br.Transactions)), nil } -func (p *EthereumApi) GetBlockUncleCountByHash(blockhash string) (int64, error) { - block := p.xeth().EthBlockByHash(blockhash) - br := NewBlockRes(block) - return int64(len(br.Uncles)), nil -} - func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Debugf("%s %s", req.Method, req.Params) @@ -475,11 +469,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockUncleCountByHash(args.BlockHash) - if err != nil { - return err - } - *reply = common.ToHex(big.NewInt(v).Bytes()) + block := p.xeth().EthBlockByHash(args.BlockHash) + br := NewBlockRes(block) + *reply = common.ToHex(big.NewInt(int64(len(br.Uncles))).Bytes()) case "eth_getUncleCountByBlockNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From ff657edbb6222db826175965f9ec5b26dbf4385e Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:30:42 -0400 Subject: inline GetBlockTransactionCountByNumber --- rpc/api.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index b17b51317..b9e2ca09d 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -361,12 +361,6 @@ func (p *EthereumApi) GetBlockTransactionCountByHash(blockhash string) (int64, e return int64(len(br.Transactions)), nil } -func (p *EthereumApi) GetBlockTransactionCountByNumber(blocknum int64) (int64, error) { - block := p.xeth().EthBlockByNumber(blocknum) - br := NewBlockRes(block) - return int64(len(br.Transactions)), nil -} - func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Debugf("%s %s", req.Method, req.Params) @@ -458,11 +452,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockTransactionCountByNumber(args.BlockNumber) - if err != nil { - return err - } - *reply = common.ToHex(big.NewInt(v).Bytes()) + block := p.xeth().EthBlockByNumber(args.BlockNumber) + br := NewBlockRes(block) + *reply = common.ToHex(big.NewInt(int64(len(br.Transactions))).Bytes()) case "eth_getUncleCountByBlockHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 0895190b64204205ed9cbc52a65b1060db4e43b4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:31:40 -0400 Subject: inline GetBlockTransactionCountByHash --- rpc/api.go | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index b9e2ca09d..ded8b0296 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -355,12 +355,6 @@ func (p *EthereumApi) GetBlockByNumber(blocknum int64, includetx bool) (*BlockRe return br, nil } -func (p *EthereumApi) GetBlockTransactionCountByHash(blockhash string) (int64, error) { - block := p.xeth().EthBlockByHash(blockhash) - br := NewBlockRes(block) - return int64(len(br.Transactions)), nil -} - func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Debugf("%s %s", req.Method, req.Params) @@ -441,11 +435,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockTransactionCountByHash(args.BlockHash) - if err != nil { - return err - } - *reply = common.ToHex(big.NewInt(v).Bytes()) + block := p.xeth().EthBlockByHash(args.BlockHash) + br := NewBlockRes(block) + *reply = common.ToHex(big.NewInt(int64(len(br.Transactions))).Bytes()) case "eth_getBlockTransactionCountByNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From cdfc03dc8e11a1738cad8009095549ea2d4b8287 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 20:40:50 -0400 Subject: inline WhisperPost --- rpc/api.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index ded8b0296..961440493 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -331,16 +331,6 @@ func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { return nil } -func (p *EthereumApi) WhisperPost(args *WhisperMessageArgs, reply *interface{}) error { - err := p.xeth().Whisper().Post(args.Payload, args.To, args.From, args.Topics, args.Priority, args.Ttl) - if err != nil { - return err - } - - *reply = true - return nil -} - func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) { block := p.xeth().EthBlockByHash(blockhash) br := NewBlockRes(block) @@ -659,7 +649,13 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.WhisperPost(args, reply) + + err := p.xeth().Whisper().Post(args.Payload, args.To, args.From, args.Topics, args.Priority, args.Ttl) + if err != nil { + return err + } + + *reply = true case "shh_newIdentity": *reply = p.xeth().Whisper().NewIdentity() // case "shh_removeIdentity": -- cgit From 6c04c19eb4506efa5f6de47561025b3702619f79 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 22:58:07 -0400 Subject: Reorg filter logic to XEth --- rpc/api.go | 191 ++++++++----------------------------------------------------- 1 file changed, 23 insertions(+), 168 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 4f86e703d..85f798c7c 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -7,7 +7,6 @@ import ( "path" "strings" "sync" - "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -15,15 +14,13 @@ import ( "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/event/filter" "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) var ( - defaultGasPrice = big.NewInt(150000000000) - defaultGas = big.NewInt(500000) - filterTickerTime = 5 * time.Minute + defaultGasPrice = big.NewInt(150000000000) + defaultGas = big.NewInt(500000) ) type EthereumApi struct { @@ -31,17 +28,9 @@ type EthereumApi struct { xethMu sync.RWMutex mux *event.TypeMux - quit chan struct{} - filterManager *filter.FilterManager - - logMut sync.RWMutex - logs map[int]*logFilter - - messagesMut sync.RWMutex - messages map[int]*whisperFilter - // Register keeps a list of accounts and transaction data - regmut sync.Mutex - register map[string][]*NewTxArgs + // // Register keeps a list of accounts and transaction data + // regmut sync.Mutex + // register map[string][]*NewTxArgs db common.Database } @@ -49,16 +38,10 @@ type EthereumApi struct { func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi { db, _ := ethdb.NewLDBDatabase(path.Join(dataDir, "dapps")) api := &EthereumApi{ - eth: eth, - mux: eth.Backend().EventMux(), - quit: make(chan struct{}), - filterManager: filter.NewFilterManager(eth.Backend().EventMux()), - logs: make(map[int]*logFilter), - messages: make(map[int]*whisperFilter), - db: db, + eth: eth, + mux: eth.Backend().EventMux(), + db: db, } - go api.filterManager.Start() - go api.start() return api } @@ -85,39 +68,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { return self.xethWithStateNum(num).State() } -func (self *EthereumApi) start() { - timer := time.NewTicker(2 * time.Second) -done: - for { - select { - case <-timer.C: - self.logMut.Lock() - self.messagesMut.Lock() - for id, filter := range self.logs { - if time.Since(filter.timeout) > filterTickerTime { - self.filterManager.UninstallFilter(id) - delete(self.logs, id) - } - } - - for id, filter := range self.messages { - if time.Since(filter.timeout) > filterTickerTime { - self.xeth().Whisper().Unwatch(id) - delete(self.messages, id) - } - } - self.messagesMut.Unlock() - self.logMut.Unlock() - case <-self.quit: - break done - } - } -} - -func (self *EthereumApi) stop() { - close(self.quit) -} - // func (self *EthereumApi) Register(args string, reply *interface{}) error { // self.regmut.Lock() // defer self.regmut.Unlock() @@ -149,91 +99,43 @@ func (self *EthereumApi) stop() { // } func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) error { - var id int - filter := core.NewFilter(self.xeth().Backend()) - filter.SetOptions(toFilterOptions(args)) - filter.LogsCallback = func(logs state.Logs) { - self.logMut.Lock() - defer self.logMut.Unlock() - - self.logs[id].add(logs...) - } - id = self.filterManager.InstallFilter(filter) - self.logs[id] = &logFilter{timeout: time.Now()} - + opts := toFilterOptions(args) + id := self.xeth().RegisterFilter(opts) *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) return nil } func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error { - if _, ok := self.logs[id]; ok { - delete(self.logs, id) - } + *reply = self.xeth().UninstallFilter(id) - self.filterManager.UninstallFilter(id) - *reply = true return nil } func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interface{}) error { - var id int - filter := core.NewFilter(self.xeth().Backend()) - - callback := func(block *types.Block, logs state.Logs) { - self.logMut.Lock() - defer self.logMut.Unlock() - - for _, log := range logs { - self.logs[id].add(log) - } - self.logs[id].add(&state.StateLog{}) - } - - switch args.Word { - case "pending": - filter.PendingCallback = callback - case "latest": - filter.BlockCallback = callback - default: - return NewValidationError("Word", "Must be `latest` or `pending`") + if err := args.requirements(); err != nil { + return err } - id = self.filterManager.InstallFilter(filter) - self.logs[id] = &logFilter{timeout: time.Now()} + id := self.xeth().NewFilterString(args.Word) *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) - return nil } func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error { - self.logMut.Lock() - defer self.logMut.Unlock() - - if self.logs[id] != nil { - *reply = NewLogsRes(self.logs[id].get()) - } - + *reply = NewLogsRes(self.xeth().FilterChanged(id)) return nil } func (self *EthereumApi) Logs(id int, reply *interface{}) error { - self.logMut.Lock() - defer self.logMut.Unlock() - - filter := self.filterManager.GetFilter(id) - if filter != nil { - *reply = NewLogsRes(filter.Find()) - } + *reply = NewLogsRes(self.xeth().Logs(id)) return nil } func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error { - filter := core.NewFilter(self.xeth().Backend()) - filter.SetOptions(toFilterOptions(args)) - - *reply = NewLogsRes(filter.Find()) + opts := toFilterOptions(args) + *reply = NewLogsRes(self.xeth().AllLogs(opts)) return nil } @@ -385,36 +287,22 @@ func (p *EthereumApi) NewWhisperIdentity(reply *interface{}) error { // } func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface{}) error { - var id int opts := new(xeth.Options) opts.From = args.From opts.To = args.To opts.Topics = args.Topics - opts.Fn = func(msg xeth.WhisperMessage) { - p.messagesMut.Lock() - defer p.messagesMut.Unlock() - p.messages[id].add(msg) // = append(p.messages[id], msg) - } - id = p.xeth().Whisper().Watch(opts) - p.messages[id] = &whisperFilter{timeout: time.Now()} + id := p.xeth().NewWhisperFilter(opts) *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) return nil } func (p *EthereumApi) UninstallWhisperFilter(id int, reply *interface{}) error { - delete(p.messages, id) - *reply = true + *reply = p.xeth().UninstallWhisperFilter(id) return nil } func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { - self.messagesMut.Lock() - defer self.messagesMut.Unlock() - - if self.messages[id] != nil { - *reply = self.messages[id].get() - } - + *reply = self.xeth().MessagesChanged(id) return nil } @@ -835,7 +723,7 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -func toFilterOptions(options *FilterOptions) core.FilterOptions { +func toFilterOptions(options *FilterOptions) *core.FilterOptions { var opts core.FilterOptions // Convert optional address slice/string to byte slice @@ -868,38 +756,5 @@ func toFilterOptions(options *FilterOptions) core.FilterOptions { } opts.Topics = topics - return opts -} - -type whisperFilter struct { - messages []xeth.WhisperMessage - timeout time.Time - id int -} - -func (w *whisperFilter) add(msgs ...xeth.WhisperMessage) { - w.messages = append(w.messages, msgs...) -} -func (w *whisperFilter) get() []xeth.WhisperMessage { - w.timeout = time.Now() - tmp := w.messages - w.messages = nil - return tmp -} - -type logFilter struct { - logs state.Logs - timeout time.Time - id int -} - -func (l *logFilter) add(logs ...state.Log) { - l.logs = append(l.logs, logs...) -} - -func (l *logFilter) get() state.Logs { - l.timeout = time.Now() - tmp := l.logs - l.logs = nil - return tmp + return &opts } -- cgit From 4663a55f123c3d4886a0537243d1ad86d2a51f21 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:03:53 -0400 Subject: inline NewFilter --- rpc/api.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 9a994ebbd..495771a59 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,14 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) error { - opts := toFilterOptions(args) - id := self.xeth().RegisterFilter(opts) - *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) - - return nil -} - func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error { *reply = self.xeth().UninstallFilter(id) @@ -491,7 +483,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.NewFilter(args, reply) + + opts := toFilterOptions(args) + id := p.xeth().RegisterFilter(opts) + *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) case "eth_newBlockFilter": args := new(FilterStringArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 84b19971fadaae6d4b77667327d967f62d8726f8 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:05:23 -0400 Subject: inline UninstallFilter --- rpc/api.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 495771a59..2dd171a65 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,12 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error { - *reply = self.xeth().UninstallFilter(id) - - return nil -} - func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -498,7 +492,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.UninstallFilter(args.Id, reply) + *reply = p.xeth().UninstallFilter(args.Id) case "eth_getFilterChanges": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 3e9632e2566d9853e4c12ccd545e818df290219b Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:06:32 -0400 Subject: inline NewFilterString --- rpc/api.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 2dd171a65..39137d8db 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,16 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - - id := self.xeth().NewFilterString(args.Word) - *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) - return nil -} - func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error { *reply = NewLogsRes(self.xeth().FilterChanged(id)) return nil @@ -486,7 +476,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.NewFilterString(args, reply) + if err := args.requirements(); err != nil { + return err + } + + id := p.xeth().NewFilterString(args.Word) + *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) case "eth_uninstallFilter": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From d2e741423057c483522f5eaa1daece72aab2ee43 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:07:25 -0400 Subject: inline FilterChanged --- rpc/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 39137d8db..d6e9dc1b1 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,11 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) FilterChanged(id int, reply *interface{}) error { - *reply = NewLogsRes(self.xeth().FilterChanged(id)) - return nil -} - func (self *EthereumApi) Logs(id int, reply *interface{}) error { *reply = NewLogsRes(self.xeth().Logs(id)) @@ -493,7 +488,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.FilterChanged(args.Id, reply) + *reply = NewLogsRes(p.xeth().FilterChanged(args.Id)) case "eth_getFilterLogs": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 0bda63eb76755574750112252457931719515a71 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:08:26 -0400 Subject: inline Logs --- rpc/api.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index d6e9dc1b1..a472229a4 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,12 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) Logs(id int, reply *interface{}) error { - *reply = NewLogsRes(self.xeth().Logs(id)) - - return nil -} - func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error { opts := toFilterOptions(args) *reply = NewLogsRes(self.xeth().AllLogs(opts)) @@ -494,7 +488,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.Logs(args.Id, reply) + *reply = NewLogsRes(p.xeth().Logs(args.Id)) case "eth_getLogs": args := new(FilterOptions) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 4b5e5926560df601e3055f3cfbf120ff2f4a49cc Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:10:23 -0400 Subject: inline AllLogs --- rpc/api.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index a472229a4..ff2ae6c34 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -98,13 +98,6 @@ func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { // return nil // } -func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error { - opts := toFilterOptions(args) - *reply = NewLogsRes(self.xeth().AllLogs(opts)) - - return nil -} - func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) { // TODO if no_private_key then //if _, exists := p.register[args.From]; exists { @@ -494,7 +487,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.AllLogs(args, reply) + opts := toFilterOptions(args) + *reply = NewLogsRes(p.xeth().AllLogs(opts)) case "eth_getWork", "eth_submitWork": return NewNotImplementedError(req.Method) case "db_putString": -- cgit From 1f9b93647be5badfec854210b6c2b036d8c9aa6c Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:11:52 -0400 Subject: inline NewWhisperFilter --- rpc/api.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index ff2ae6c34..15a9f8b1f 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -175,16 +175,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) NewWhisperFilter(args *WhisperFilterArgs, reply *interface{}) error { - opts := new(xeth.Options) - opts.From = args.From - opts.To = args.To - opts.Topics = args.Topics - id := p.xeth().NewWhisperFilter(opts) - *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) - return nil -} - func (p *EthereumApi) UninstallWhisperFilter(id int, reply *interface{}) error { *reply = p.xeth().UninstallWhisperFilter(id) return nil @@ -550,7 +540,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.NewWhisperFilter(args, reply) + opts := new(xeth.Options) + opts.From = args.From + opts.To = args.To + opts.Topics = args.Topics + id := p.xeth().NewWhisperFilter(opts) + *reply = common.ToHex(big.NewInt(int64(id)).Bytes()) case "shh_uninstallFilter": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 2ef2b9f2e011d482a50456da91ad4b7a4be57841 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:13:52 -0400 Subject: inline UninstallWhisperFilter --- rpc/api.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 15a9f8b1f..1d4e737b5 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -175,11 +175,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) UninstallWhisperFilter(id int, reply *interface{}) error { - *reply = p.xeth().UninstallWhisperFilter(id) - return nil -} - func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { *reply = self.xeth().MessagesChanged(id) return nil @@ -551,8 +546,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - - return p.UninstallWhisperFilter(args.Id, reply) + *reply = p.xeth().UninstallWhisperFilter(args.Id) case "shh_getFilterChanges": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 7b45f3377f3f8d911d7678530138a1249f523155 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:14:55 -0400 Subject: inline MessagesChanged --- rpc/api.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 1d4e737b5..8e3d3cc63 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -175,11 +175,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (self *EthereumApi) MessagesChanged(id int, reply *interface{}) error { - *reply = self.xeth().MessagesChanged(id) - return nil -} - func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) { block := p.xeth().EthBlockByHash(blockhash) br := NewBlockRes(block) @@ -552,7 +547,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.MessagesChanged(args.Id, reply) + *reply = p.xeth().MessagesChanged(args.Id) case "shh_getMessages": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 6669ef5b701f8b060287c8a63e9f3c1116b4b74a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:20:54 -0400 Subject: Rename for clarity --- rpc/api.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 8e3d3cc63..06014c74f 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -46,6 +46,13 @@ func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi { return api } +func (self *EthereumApi) xeth() *xeth.XEth { + self.xethMu.RLock() + defer self.xethMu.RUnlock() + + return self.eth +} + func (self *EthereumApi) xethWithStateNum(num int64) *xeth.XEth { chain := self.xeth().Backend().ChainManager() var block *types.Block @@ -328,7 +335,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByHash(args.BlockHash, args.Transactions) + v, err := p.GetBlockByHash(args.BlockHash, args.IncludeTxs) if err != nil { return err } @@ -339,7 +346,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByNumber(args.BlockNumber, args.Transactions) + v, err := p.GetBlockByNumber(args.BlockNumber, args.IncludeTxs) if err != nil { return err } @@ -580,13 +587,6 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return nil } -func (self *EthereumApi) xeth() *xeth.XEth { - self.xethMu.RLock() - defer self.xethMu.RUnlock() - - return self.eth -} - func toFilterOptions(options *FilterOptions) *core.FilterOptions { var opts core.FilterOptions -- cgit From 19360c00795d356d052a379663c3f36aedba3f9e Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:28:45 -0400 Subject: Move stateAt func to XEth --- rpc/api.go | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 06014c74f..f31b9a344 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -10,11 +10,9 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" - "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/xeth" ) @@ -53,28 +51,6 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -func (self *EthereumApi) xethWithStateNum(num int64) *xeth.XEth { - chain := self.xeth().Backend().ChainManager() - var block *types.Block - - if num < 0 { - num = chain.CurrentBlock().Number().Int64() + num + 1 - } - block = chain.GetBlockByNumber(uint64(num)) - - var st *state.StateDB - if block != nil { - st = state.New(block.Root(), self.xeth().Backend().StateDb()) - } else { - st = chain.State() - } - return self.xeth().WithState(st) -} - -func (self *EthereumApi) getStateWithNum(num int64) *xeth.State { - return self.xethWithStateNum(num).State() -} - // func (self *EthereumApi) Register(args string, reply *interface{}) error { // self.regmut.Lock() // defer self.regmut.Unlock() @@ -152,7 +128,7 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) } func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { - result, err := p.xethWithStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + result, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { return err } @@ -166,7 +142,7 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return err } - state := p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address) + state := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address) value := state.StorageString(args.Key) var hx string @@ -240,7 +216,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = common.ToHex(p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) + *reply = common.ToHex(p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) case "eth_getStorage", "eth_storageAt": args := new(GetStorageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -251,7 +227,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xethWithStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() + *reply = p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() case "eth_getStorageAt": args := new(GetStorageAtArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -269,7 +245,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xethWithStateNum(args.BlockNumber).TxCountAt(args.Address) + *reply = p.xeth().AtStateNum(args.BlockNumber).TxCountAt(args.Address) case "eth_getBlockTransactionCountByHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -314,7 +290,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := args.requirements(); err != nil { return err } - *reply = p.xethWithStateNum(args.BlockNumber).CodeAt(args.Address) + *reply = p.xeth().AtStateNum(args.BlockNumber).CodeAt(args.Address) case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From d791fe4975fa62618f854a86f1648d5fe7081b79 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:34:35 -0400 Subject: Remove unnecessary event mux --- rpc/api.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index f31b9a344..cef5e4689 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -12,7 +12,6 @@ import ( "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/xeth" ) @@ -24,7 +23,6 @@ var ( type EthereumApi struct { eth *xeth.XEth xethMu sync.RWMutex - mux *event.TypeMux // // Register keeps a list of accounts and transaction data // regmut sync.Mutex @@ -34,10 +32,10 @@ type EthereumApi struct { } func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi { + // What about when dataDir is empty? db, _ := ethdb.NewLDBDatabase(path.Join(dataDir, "dapps")) api := &EthereumApi{ eth: eth, - mux: eth.Backend().EventMux(), db: db, } -- cgit From 3cea7d87c1b9fadf19211fad2aece303b1677e27 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 19 Mar 2015 23:55:17 -0400 Subject: Rename FilterOptions to BlockFilterArgs --- rpc/api.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index cef5e4689..9f0b88b48 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -406,7 +406,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "eth_compileSolidity", "eth_compileLLL", "eth_compileSerpent": return NewNotImplementedError(req.Method) case "eth_newFilter": - args := new(FilterOptions) + args := new(BlockFilterArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } @@ -444,7 +444,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } *reply = NewLogsRes(p.xeth().Logs(args.Id)) case "eth_getLogs": - args := new(FilterOptions) + args := new(BlockFilterArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } @@ -561,7 +561,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return nil } -func toFilterOptions(options *FilterOptions) *core.FilterOptions { +func toFilterOptions(options *BlockFilterArgs) *core.FilterOptions { var opts core.FilterOptions // Convert optional address slice/string to byte slice -- cgit From 754160afea7fc230c3236d5494beefeb03b94140 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 00:23:48 -0400 Subject: Move gas defaults to XEth --- rpc/api.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 9f0b88b48..1626fd0af 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -2,7 +2,6 @@ package rpc import ( "encoding/json" - "fmt" "math/big" "path" "strings" @@ -15,11 +14,6 @@ import ( "github.com/ethereum/go-ethereum/xeth" ) -var ( - defaultGasPrice = big.NewInt(150000000000) - defaultGas = big.NewInt(500000) -) - type EthereumApi struct { eth *xeth.XEth xethMu sync.RWMutex @@ -109,16 +103,15 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) // TODO: align default values to have the same type, e.g. not depend on // common.Value conversions later on if args.Gas.Cmp(big.NewInt(0)) == 0 { - args.Gas = defaultGas + args.Gas = p.xeth().DefaultGas() } if args.GasPrice.Cmp(big.NewInt(0)) == 0 { - args.GasPrice = defaultGasPrice + args.GasPrice = p.xeth().DefaultGasPrice() } *reply, err = p.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { - fmt.Println("err:", err) return err } @@ -199,7 +192,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "eth_mining": *reply = p.xeth().IsMining() case "eth_gasPrice": - *reply = common.ToHex(defaultGasPrice.Bytes()) + *reply = common.ToHex(p.xeth().DefaultGas().Bytes()) case "eth_accounts": *reply = p.xeth().Accounts() case "eth_blockNumber": -- cgit From b56e20be2760343147f72ca62a8db8bd216903bf Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 00:24:23 -0400 Subject: Reorg for clarity --- rpc/api.go | 82 +++++++++++++++++++++++--------------------------------------- 1 file changed, 30 insertions(+), 52 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 1626fd0af..fccc7f2a4 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -43,59 +43,7 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -// func (self *EthereumApi) Register(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// if _, ok := self.register[args]; ok { -// self.register[args] = nil // register with empty -// } -// return nil -// } - -// func (self *EthereumApi) Unregister(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// delete(self.register, args) - -// return nil -// } - -// func (self *EthereumApi) WatchTx(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// txs := self.register[args] -// self.register[args] = nil - -// *reply = txs -// return nil -// } - func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) { - // TODO if no_private_key then - //if _, exists := p.register[args.From]; exists { - // p.register[args.From] = append(p.register[args.From], args) - //} else { - /* - account := accounts.Get(common.FromHex(args.From)) - if account != nil { - if account.Unlocked() { - if !unlockAccount(account) { - return - } - } - - result, _ := account.Transact(common.FromHex(args.To), common.FromHex(args.Value), common.FromHex(args.Gas), common.FromHex(args.GasPrice), common.FromHex(args.Data)) - if len(result) > 0 { - *reply = common.ToHex(result) - } - } else if _, exists := p.register[args.From]; exists { - p.register[ags.From] = append(p.register[args.From], args) - } - */ - if err := args.requirements(); err != nil { return err } @@ -163,6 +111,36 @@ func (p *EthereumApi) GetBlockByNumber(blocknum int64, includetx bool) (*BlockRe return br, nil } +// func (self *EthereumApi) Register(args string, reply *interface{}) error { +// self.regmut.Lock() +// defer self.regmut.Unlock() + +// if _, ok := self.register[args]; ok { +// self.register[args] = nil // register with empty +// } +// return nil +// } + +// func (self *EthereumApi) Unregister(args string, reply *interface{}) error { +// self.regmut.Lock() +// defer self.regmut.Unlock() + +// delete(self.register, args) + +// return nil +// } + +// func (self *EthereumApi) WatchTx(args string, reply *interface{}) error { +// self.regmut.Lock() +// defer self.regmut.Unlock() + +// txs := self.register[args] +// self.register[args] = nil + +// *reply = txs +// return nil +// } + func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.Infof("%s %s", req.Method, req.Params) -- cgit From bde161382a0ce4dad9c422870e16169cfba0fcc0 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 06:53:24 +0100 Subject: inline GetBlockByHash --- rpc/api.go | 51 ++++++++++++++++++++------------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index fccc7f2a4..3efb4c55e 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -97,13 +97,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) GetBlockByHash(blockhash string, includetx bool) (*BlockRes, error) { - block := p.xeth().EthBlockByHash(blockhash) - br := NewBlockRes(block) - br.fullTx = includetx - return br, nil -} - func (p *EthereumApi) GetBlockByNumber(blocknum int64, includetx bool) (*BlockRes, error) { block := p.xeth().EthBlockByNumber(blocknum) br := NewBlockRes(block) @@ -280,11 +273,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByHash(args.BlockHash, args.IncludeTxs) - if err != nil { - return err - } - *reply = v + block := p.xeth().EthBlockByHash(args.BlockHash) + br := NewBlockRes(block) + br.fullTx = args.IncludeTxs + + *reply = br case "eth_getBlockByNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -311,14 +304,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByHash(args.Hash, true) - if err != nil { - return err - } - if args.Index > int64(len(v.Transactions)) || args.Index < 0 { + block := p.xeth().EthBlockByHash(args.Hash) + br := NewBlockRes(block) + br.fullTx = true + + if args.Index > int64(len(br.Transactions)) || args.Index < 0 { return NewValidationError("Index", "does not exist") } - *reply = v.Transactions[args.Index] + *reply = br.Transactions[args.Index] case "eth_getTransactionByBlockNumberAndIndex": args := new(BlockNumIndexArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -339,18 +332,15 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByHash(args.Hash, false) - if err != nil { - return err - } - if args.Index > int64(len(v.Uncles)) || args.Index < 0 { + br := NewBlockRes(p.xeth().EthBlockByHash(args.Hash)) + + if args.Index > int64(len(br.Uncles)) || args.Index < 0 { return NewValidationError("Index", "does not exist") } - uncle, err := p.GetBlockByHash(common.ToHex(v.Uncles[args.Index]), false) - if err != nil { - return err - } + uhash := common.ToHex(br.Uncles[args.Index]) + uncle := NewBlockRes(p.xeth().EthBlockByHash(uhash)) + *reply = uncle case "eth_getUncleByBlockNumberAndIndex": args := new(BlockNumIndexArgs) @@ -366,10 +356,9 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return NewValidationError("Index", "does not exist") } - uncle, err := p.GetBlockByHash(common.ToHex(v.Uncles[args.Index]), false) - if err != nil { - return err - } + uhash := common.ToHex(v.Uncles[args.Index]) + uncle := NewBlockRes(p.xeth().EthBlockByHash(uhash)) + *reply = uncle case "eth_getCompilers": c := []string{""} -- cgit From 1d6451f5c390b13deb88d9a3878bb7d26d2797b8 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 06:57:23 +0100 Subject: inline GetBlockByNumber --- rpc/api.go | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 3efb4c55e..63e2a85dd 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -97,13 +97,6 @@ func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) e return nil } -func (p *EthereumApi) GetBlockByNumber(blocknum int64, includetx bool) (*BlockRes, error) { - block := p.xeth().EthBlockByNumber(blocknum) - br := NewBlockRes(block) - br.fullTx = includetx - return br, nil -} - // func (self *EthereumApi) Register(args string, reply *interface{}) error { // self.regmut.Lock() // defer self.regmut.Unlock() @@ -284,11 +277,11 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByNumber(args.BlockNumber, args.IncludeTxs) - if err != nil { - return err - } - *reply = v + block := p.xeth().EthBlockByNumber(args.BlockNumber) + br := NewBlockRes(block) + br.fullTx = args.IncludeTxs + + *reply = br case "eth_getTransactionByHash": // HashIndexArgs used, but only the "Hash" part we need. args := new(HashIndexArgs) @@ -318,10 +311,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByNumber(args.BlockNumber, true) - if err != nil { - return err - } + block := p.xeth().EthBlockByNumber(args.BlockNumber) + v := NewBlockRes(block) + v.fullTx = true + if args.Index > int64(len(v.Transactions)) || args.Index < 0 { return NewValidationError("Index", "does not exist") } @@ -348,10 +341,10 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.GetBlockByNumber(args.BlockNumber, true) - if err != nil { - return err - } + block := p.xeth().EthBlockByNumber(args.BlockNumber) + v := NewBlockRes(block) + v.fullTx = true + if args.Index > int64(len(v.Uncles)) || args.Index < 0 { return NewValidationError("Index", "does not exist") } -- cgit From e038a42d7a0e7e2c6ad7cef6c6446ad1e9454fe5 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 06:58:53 +0100 Subject: inline Call --- rpc/api.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 63e2a85dd..0596aee48 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -66,16 +66,6 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) return nil } -func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error { - result, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) - if err != nil { - return err - } - - *reply = result - return nil -} - func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -257,7 +247,13 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.Call(args, reply) + + result, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + if err != nil { + return err + } + + *reply = result case "eth_flush": return NewNotImplementedError(req.Method) case "eth_getBlockByHash": -- cgit From aa3918efa711a51c241a70d675b27fc0f0c01ec3 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 07:13:29 +0100 Subject: Move transact gas check to XEth --- rpc/api.go | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 0596aee48..20b586686 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -48,16 +48,6 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) return err } - // TODO: align default values to have the same type, e.g. not depend on - // common.Value conversions later on - if args.Gas.Cmp(big.NewInt(0)) == 0 { - args.Gas = p.xeth().DefaultGas() - } - - if args.GasPrice.Cmp(big.NewInt(0)) == 0 { - args.GasPrice = p.xeth().DefaultGasPrice() - } - *reply, err = p.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { return err -- cgit From b3329bc698722881b636af882df67eff79822da4 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 07:15:34 +0100 Subject: inline Transact --- rpc/api.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 20b586686..3b60d661b 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -43,19 +43,6 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) { - if err := args.requirements(); err != nil { - return err - } - - *reply, err = p.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) - if err != nil { - return err - } - - return nil -} - func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) error { if err := args.requirements(); err != nil { return err @@ -231,7 +218,16 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.Transact(args, reply) + + if err := args.requirements(); err != nil { + return err + } + + v, err := p.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + if err != nil { + return err + } + *reply = v case "eth_call": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From 28e5fc83526af17a911eece6befa5fe54578fb55 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 13:37:56 +0100 Subject: Make pretty --- rpc/api.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 3b60d661b..5f29886e0 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -111,7 +111,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "net_listening": *reply = p.xeth().IsListening() case "net_peerCount": - *reply = common.ToHex(big.NewInt(int64(p.xeth().PeerCount())).Bytes()) + v := p.xeth().PeerCount() + *reply = common.ToHex(big.NewInt(int64(v)).Bytes()) case "eth_coinbase": // TODO handling of empty coinbase due to lack of accounts res := p.xeth().Coinbase() @@ -123,11 +124,13 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error case "eth_mining": *reply = p.xeth().IsMining() case "eth_gasPrice": - *reply = common.ToHex(p.xeth().DefaultGas().Bytes()) + v := p.xeth().DefaultGas() + *reply = common.ToHex(v.Bytes()) case "eth_accounts": *reply = p.xeth().Accounts() case "eth_blockNumber": - *reply = common.ToHex(p.xeth().Backend().ChainManager().CurrentBlock().Number().Bytes()) + v := p.xeth().Backend().ChainManager().CurrentBlock().Number() + *reply = common.ToHex(v.Bytes()) case "eth_getBalance": args := new(GetBalanceArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -138,7 +141,8 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = common.ToHex(p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance().Bytes()) + v := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance() + *reply = common.ToHex(v.Bytes()) case "eth_getStorage", "eth_storageAt": args := new(GetStorageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -174,18 +178,16 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - block := p.xeth().EthBlockByHash(args.BlockHash) - br := NewBlockRes(block) - *reply = common.ToHex(big.NewInt(int64(len(br.Transactions))).Bytes()) + block := NewBlockRes(p.xeth().EthBlockByHash(args.BlockHash)) + *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) case "eth_getBlockTransactionCountByNumber": args := new(GetBlockByNumberArgs) if err := json.Unmarshal(req.Params, &args); err != nil { return err } - block := p.xeth().EthBlockByNumber(args.BlockNumber) - br := NewBlockRes(block) - *reply = common.ToHex(big.NewInt(int64(len(br.Transactions))).Bytes()) + block := NewBlockRes(p.xeth().EthBlockByNumber(args.BlockNumber)) + *reply = common.ToHex(big.NewInt(int64(len(block.Transactions))).Bytes()) case "eth_getUncleCountByBlockHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -234,12 +236,12 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - result, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + v, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { return err } - *reply = result + *reply = v case "eth_flush": return NewNotImplementedError(req.Method) case "eth_getBlockByHash": -- cgit From 739c36ad4df63580bef241a4da8d2cc5010eab54 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 13:45:07 +0100 Subject: inline GetStorageAt --- rpc/api.go | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 5f29886e0..4758363d1 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -4,7 +4,6 @@ import ( "encoding/json" "math/big" "path" - "strings" "sync" "github.com/ethereum/go-ethereum/common" @@ -43,27 +42,6 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -func (p *EthereumApi) GetStorageAt(args *GetStorageAtArgs, reply *interface{}) error { - if err := args.requirements(); err != nil { - return err - } - - state := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address) - value := state.StorageString(args.Key) - - var hx string - if strings.Index(args.Key, "0x") == 0 { - hx = string([]byte(args.Key)[2:]) - } else { - // Convert the incoming string (which is a bigint) into hex - i, _ := new(big.Int).SetString(args.Key, 10) - hx = common.Bytes2Hex(i.Bytes()) - } - rpclogger.Debugf("GetStateAt(%s, %s)\n", args.Address, hx) - *reply = map[string]string{args.Key: value.Str()} - return nil -} - // func (self *EthereumApi) Register(args string, reply *interface{}) error { // self.regmut.Lock() // defer self.regmut.Unlock() @@ -159,7 +137,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.GetStorageAt(args, reply) + if err := args.requirements(); err != nil { + return err + } + + state := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address) + value := state.StorageString(args.Key) + + *reply = common.Bytes2Hex(value.Bytes()) case "eth_getTransactionCount": args := new(GetTxCountArgs) if err := json.Unmarshal(req.Params, &args); err != nil { -- cgit From efcc93e7da9f47b99fc9252dc741b20086aeb4b2 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 14:12:07 +0100 Subject: Move Account register to xeth --- rpc/api.go | 58 ++++++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 4758363d1..87cf42ff5 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -16,12 +16,7 @@ import ( type EthereumApi struct { eth *xeth.XEth xethMu sync.RWMutex - - // // Register keeps a list of accounts and transaction data - // regmut sync.Mutex - // register map[string][]*NewTxArgs - - db common.Database + db common.Database } func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi { @@ -42,39 +37,9 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } -// func (self *EthereumApi) Register(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// if _, ok := self.register[args]; ok { -// self.register[args] = nil // register with empty -// } -// return nil -// } - -// func (self *EthereumApi) Unregister(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// delete(self.register, args) - -// return nil -// } - -// func (self *EthereumApi) WatchTx(args string, reply *interface{}) error { -// self.regmut.Lock() -// defer self.regmut.Unlock() - -// txs := self.register[args] -// self.register[args] = nil - -// *reply = txs -// return nil -// } - func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC - rpclogger.Infof("%s %s", req.Method, req.Params) + rpclogger.DebugDetailf("%s %s", req.Method, req.Params) switch req.Method { case "web3_sha3": args := new(Sha3Args) @@ -458,23 +423,24 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } *reply = p.xeth().Whisper().Messages(args.Id) // case "eth_register": - // args, err := req.ToRegisterArgs() - // if err != nil { + // // Placeholder for actual type + // args := new(HashIndexArgs) + // if err := json.Unmarshal(req.Params, &args); err != nil { // return err // } - // return p.Register(args, reply) + // *reply = p.xeth().Register(args.Hash) // case "eth_unregister": - // args, err := req.ToRegisterArgs() - // if err != nil { + // args := new(HashIndexArgs) + // if err := json.Unmarshal(req.Params, &args); err != nil { // return err // } - // return p.Unregister(args, reply) + // *reply = p.xeth().Unregister(args.Hash) // case "eth_watchTx": - // args, err := req.ToWatchTxArgs() - // if err != nil { + // args := new(HashIndexArgs) + // if err := json.Unmarshal(req.Params, &args); err != nil { // return err // } - // return p.WatchTx(args, reply) + // *reply = p.xeth().PullWatchTx(args.Hash) default: return NewNotImplementedError(req.Method) } -- cgit From 0cde7a4d46f68863535fbe470499b9d0dfd6ed7a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Fri, 20 Mar 2015 14:56:55 +0100 Subject: Add xethAtStateNum convenience method --- rpc/api.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'rpc/api.go') diff --git a/rpc/api.go b/rpc/api.go index 87cf42ff5..f318ced76 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -37,6 +37,10 @@ func (self *EthereumApi) xeth() *xeth.XEth { return self.eth } +func (self *EthereumApi) xethAtStateNum(num int64) *xeth.XEth { + return self.xeth().AtStateNum(num) +} + func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.DebugDetailf("%s %s", req.Method, req.Params) @@ -84,7 +88,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance() + v := p.xethAtStateNum(args.BlockNumber).State().SafeGet(args.Address).Balance() *reply = common.ToHex(v.Bytes()) case "eth_getStorage", "eth_storageAt": args := new(GetStorageArgs) @@ -96,7 +100,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() + *reply = p.xethAtStateNum(args.BlockNumber).State().SafeGet(args.Address).Storage() case "eth_getStorageAt": args := new(GetStorageAtArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -106,7 +110,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - state := p.xeth().AtStateNum(args.BlockNumber).State().SafeGet(args.Address) + state := p.xethAtStateNum(args.BlockNumber).State().SafeGet(args.Address) value := state.StorageString(args.Key) *reply = common.Bytes2Hex(value.Bytes()) @@ -121,7 +125,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - *reply = p.xeth().AtStateNum(args.BlockNumber).TxCountAt(args.Address) + *reply = p.xethAtStateNum(args.BlockNumber).TxCountAt(args.Address) case "eth_getBlockTransactionCountByHash": args := new(GetBlockByHashArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -164,7 +168,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := args.requirements(); err != nil { return err } - *reply = p.xeth().AtStateNum(args.BlockNumber).CodeAt(args.Address) + *reply = p.xethAtStateNum(args.BlockNumber).CodeAt(args.Address) case "eth_sendTransaction", "eth_transact": args := new(NewTxArgs) if err := json.Unmarshal(req.Params, &args); err != nil { @@ -186,7 +190,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error return err } - v, err := p.xeth().AtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) + v, err := p.xethAtStateNum(args.BlockNumber).Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data) if err != nil { return err } -- cgit