diff options
author | zelig <viktor.tron@gmail.com> | 2015-06-23 22:48:33 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-07 16:43:31 +0800 |
commit | 83ee39448e0f23d42dff27bccde27f828afa3707 (patch) | |
tree | 429fa8f20a4bc017a58ffc4c7c0ed8596d1d206f /rpc/api/admin.go | |
parent | d764bd058457cd9eb91d205d1ac187d40c4866d6 (diff) | |
download | go-tangerine-83ee39448e0f23d42dff27bccde27f828afa3707.tar.gz go-tangerine-83ee39448e0f23d42dff27bccde27f828afa3707.tar.zst go-tangerine-83ee39448e0f23d42dff27bccde27f828afa3707.zip |
Registrar and contractInfo handling
* resolver -> common/registrar
* global registrar name registry interface
* add Call to resolver backend interface
* the hashReg and UrlHing contracts now initialised from global registry
* initialization of contracts uniform
* improve errors and more econsistent method names
* common/registrar/ethreg: versioned registrar
* integrate new naming and registrar in natspec
* js console api: setGlobalRegistrar, setHashReg, setUrlHint
* js test TestContract uses mining - tests fixed all pass
* eth/backend: allow PoW test mode (small ethash DAG)
* console jsre refers to resolver.abi/addr,
* cmd/geth/contracts.go moved to common/registrar
Diffstat (limited to 'rpc/api/admin.go')
-rw-r--r-- | rpc/api/admin.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go index b27482cfe..78c75a60b 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -3,7 +3,9 @@ package api import ( "fmt" "io" + "math/big" "os" + "time" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -244,3 +246,49 @@ func (self *adminApi) StopRPC(req *shared.Request) (interface{}, error) { comms.StopHttp() return true, nil } + +func (self *adminApi) SleepBlocks(req *shared.Request) (interface{}, error) { + args := new(SleepBlocksArgs) + if err := self.coder.Decode(req.Params, &args); err != nil { + return nil, shared.NewDecodeParamError(err.Error()) + } + var timer <-chan time.Time + var height *big.Int + var err error + if args.Timeout > 0 { + timer = time.NewTimer(time.Duration(args.Timeout) * time.Second).C + } + + height = new(big.Int).Add(self.xeth.CurrentBlock().Number(), big.NewInt(args.N)) + height, err = sleepBlocks(self.xeth.UpdateState(), height, timer) + if err != nil { + return nil, err + } + return height.Uint64(), nil +} + +func sleepBlocks(wait chan *big.Int, height *big.Int, timer <-chan time.Time) (newHeight *big.Int, err error) { + wait <- height + select { + case <-timer: + // if times out make sure the xeth loop does not block + go func() { + select { + case wait <- nil: + case <-wait: + } + }() + return nil, fmt.Errorf("timeout") + case newHeight = <-wait: + } + return +} + +// sec, err := call.Argument(0).ToInteger() +// if err != nil { +// fmt.Println(err) +// return otto.FalseValue() +// } +// time.Sleep(time.Duration(sec) * time.Second) +// return otto.UndefinedValue() +// } |