aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-02-26 18:16:01 +0800
committerobscuren <geffobscura@gmail.com>2015-02-26 19:06:01 +0800
commit49ded3aa7752148ebfbacd4e6ff5f46dc9376f89 (patch)
treeebde269fc7a836b67eb8d7a2a95a90297d8c2435 /rpc
parent5ab0eaa06d2f5879b9b22778988410bd0c73dcc0 (diff)
parent9884eed0cf7c95074fd5b3d5f0f592a423810a8a (diff)
downloaddexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar.gz
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar.bz2
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar.lz
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar.xz
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.tar.zst
dexon-49ded3aa7752148ebfbacd4e6ff5f46dc9376f89.zip
Merge branch 'develop' of github.com-obscure:ethereum/go-ethereum into develop
Conflicts: accounts/account_manager.go
Diffstat (limited to 'rpc')
-rw-r--r--rpc/api.go27
-rw-r--r--rpc/messages.go13
2 files changed, 36 insertions, 4 deletions
diff --git a/rpc/api.go b/rpc/api.go
index f337324d0..3b4a914ef 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -51,6 +51,8 @@ type EthereumApi struct {
register map[string][]*NewTxArgs
db ethutil.Database
+
+ defaultBlockAge int
}
func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
@@ -80,11 +82,9 @@ done:
case ev := <-events.Chan():
switch ev.(type) {
case core.ChainEvent:
- // fixme
- const something = 1337
- if something < 0 {
+ if self.defaultBlockAge < 0 {
chain := self.xeth().Backend().ChainManager()
- block := chain.GetBlockByNumber(chain.CurrentBlock().Number().Uint64() - something)
+ block := chain.GetBlockByNumber(chain.CurrentBlock().Number().Uint64() - uint64(self.defaultBlockAge))
if block != nil {
statedb := state.New(block.Root(), self.db)
self.useState(statedb)
@@ -373,6 +373,17 @@ func (p *EthereumApi) SetMining(shouldmine bool, reply *interface{}) error {
return nil
}
+func (p *EthereumApi) GetDefaultBlockAge(reply *interface{}) error {
+ *reply = p.defaultBlockAge
+ return nil
+}
+
+func (p *EthereumApi) SetDefaultBlockAge(defaultBlockAge int, reply *interface{}) error {
+ p.defaultBlockAge = defaultBlockAge
+ *reply = true
+ return nil
+}
+
func (p *EthereumApi) BlockNumber(reply *interface{}) error {
*reply = p.xeth().Backend().ChainManager().CurrentBlock().Number()
return nil
@@ -513,6 +524,14 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error
return err
}
return p.SetMining(args, reply)
+ case "eth_defaultBlock":
+ return p.GetDefaultBlockAge(reply)
+ case "eth_setDefaultBlock":
+ args, err := req.ToIntArgs()
+ if err != nil {
+ return err
+ }
+ return p.SetDefaultBlockAge(args, reply)
case "eth_peerCount":
return p.GetPeerCount(reply)
case "eth_number":
diff --git a/rpc/messages.go b/rpc/messages.go
index 044f07545..b37d8229d 100644
--- a/rpc/messages.go
+++ b/rpc/messages.go
@@ -210,6 +210,19 @@ func (req *RpcRequest) ToBoolArgs() (bool, error) {
return args, nil
}
+func (req *RpcRequest) ToIntArgs() (int, error) {
+ if len(req.Params) < 1 {
+ return 0, errArguments
+ }
+
+ var args int
+ if err := json.Unmarshal(req.Params[0], &args); err != nil {
+ return 0, errArguments
+ }
+
+ return args, nil
+}
+
func (req *RpcRequest) ToCompileArgs() (string, error) {
if len(req.Params) < 1 {
return "", errArguments