aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/packages.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-17 23:54:52 +0800
committerobscuren <geffobscura@gmail.com>2015-02-17 23:54:52 +0800
commit13c00afc68652d517f91313bb8c3eeb206d23f22 (patch)
treede9e178987c93a02e2635f5ff8f9ed3424f4c644 /rpc/packages.go
parent5238b9439eae0e60b88c65ef33274200f9c734fb (diff)
downloadgo-tangerine-13c00afc68652d517f91313bb8c3eeb206d23f22.tar.gz
go-tangerine-13c00afc68652d517f91313bb8c3eeb206d23f22.tar.zst
go-tangerine-13c00afc68652d517f91313bb8c3eeb206d23f22.zip
Implement register and watchTx
Diffstat (limited to 'rpc/packages.go')
-rw-r--r--rpc/packages.go60
1 files changed, 58 insertions, 2 deletions
diff --git a/rpc/packages.go b/rpc/packages.go
index ef31ff1e1..0b73d48a7 100644
--- a/rpc/packages.go
+++ b/rpc/packages.go
@@ -55,6 +55,9 @@ type EthereumApi struct {
messagesMut sync.RWMutex
messages map[int][]xeth.WhisperMessage
+ // Register keeps a list of accounts and transaction data
+ regmut sync.Mutex
+ register map[string][]*NewTxArgs
db ethutil.Database
}
@@ -73,6 +76,36 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
return api
}
+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 (self *EthereumApi) NewFilter(args *FilterOptions, reply *interface{}) error {
var id int
filter := core.NewFilter(self.xeth.Backend())
@@ -149,8 +182,13 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
args.GasPrice = defaultGasPrice
}
- result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
- *reply = result
+ // TODO if no_private_key then
+ if _, exists := p.register[args.From]; exists {
+ p.register[args.From] = append(p.register[args.From], args)
+ } else {
+ result, _ := p.xeth.Transact( /* TODO specify account */ args.To, args.Value, args.Gas, args.GasPrice, args.Data)
+ *reply = result
+ }
return nil
}
@@ -424,6 +462,24 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
case "eth_gasPrice":
*reply = defaultGasPrice
return nil
+ case "eth_register":
+ args, err := req.ToRegisterArgs()
+ if err != nil {
+ return err
+ }
+ return p.Register(args, reply)
+ case "eth_unregister":
+ args, err := req.ToRegisterArgs()
+ if err != nil {
+ return err
+ }
+ return p.Unregister(args, reply)
+ case "eth_watchTx":
+ args, err := req.ToWatchTxArgs()
+ if err != nil {
+ return err
+ }
+ return p.WatchTx(args, reply)
case "web3_sha3":
args, err := req.ToSha3Args()
if err != nil {