aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api/admin.go
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-06-23 22:48:33 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-07-07 16:43:31 +0800
commit27392337198b9287e9f6fe615510a1f30099e3d7 (patch)
treef1136c71d2af0e72dbf41621b161dbaff019aad9 /rpc/api/admin.go
parent83ee39448e0f23d42dff27bccde27f828afa3707 (diff)
downloaddexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar.gz
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar.bz2
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar.lz
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar.xz
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.tar.zst
dexon-27392337198b9287e9f6fe615510a1f30099e3d7.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.go185
1 files changed, 174 insertions, 11 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go
index 78c75a60b..40199caa9 100644
--- a/rpc/api/admin.go
+++ b/rpc/api/admin.go
@@ -7,8 +7,14 @@ import (
"os"
"time"
+ "github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/common/compiler"
+ "github.com/ethereum/go-ethereum/common/docserver"
+ "github.com/ethereum/go-ethereum/common/natspec"
+ "github.com/ethereum/go-ethereum/common/registrar"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rlp"
@@ -26,17 +32,27 @@ const (
var (
// mapping between methods and handlers
AdminMapping = map[string]adminhandler{
- "admin_addPeer": (*adminApi).AddPeer,
- "admin_peers": (*adminApi).Peers,
- "admin_nodeInfo": (*adminApi).NodeInfo,
- "admin_exportChain": (*adminApi).ExportChain,
- "admin_importChain": (*adminApi).ImportChain,
- "admin_verbosity": (*adminApi).Verbosity,
- "admin_chainSyncStatus": (*adminApi).ChainSyncStatus,
- "admin_setSolc": (*adminApi).SetSolc,
- "admin_datadir": (*adminApi).DataDir,
- "admin_startRPC": (*adminApi).StartRPC,
- "admin_stopRPC": (*adminApi).StopRPC,
+ "admin_addPeer": (*adminApi).AddPeer,
+ "admin_peers": (*adminApi).Peers,
+ "admin_nodeInfo": (*adminApi).NodeInfo,
+ "admin_exportChain": (*adminApi).ExportChain,
+ "admin_importChain": (*adminApi).ImportChain,
+ "admin_verbosity": (*adminApi).Verbosity,
+ "admin_chainSyncStatus": (*adminApi).ChainSyncStatus,
+ "admin_setSolc": (*adminApi).SetSolc,
+ "admin_datadir": (*adminApi).DataDir,
+ "admin_startRPC": (*adminApi).StartRPC,
+ "admin_stopRPC": (*adminApi).StopRPC,
+ "admin_setGlobalRegistrar": (*adminApi).SetGlobalRegistrar,
+ "admin_setHashReg": (*adminApi).SetHashReg,
+ "admin_setUrlHint": (*adminApi).SetUrlHint,
+ "admin_saveInfo": (*adminApi).SaveInfo,
+ "admin_register": (*adminApi).Register,
+ "admin_registerUrl": (*adminApi).RegisterUrl,
+ "admin_startNatSpec": (*adminApi).StartNatSpec,
+ "admin_stopNatSpec": (*adminApi).StopNatSpec,
+ "admin_getContractInfo": (*adminApi).GetContractInfo,
+ "admin_httpGet": (*adminApi).HttpGet,
}
)
@@ -49,6 +65,7 @@ type adminApi struct {
ethereum *eth.Ethereum
codec codec.Codec
coder codec.ApiCoder
+ ds *docserver.DocServer
}
// create a new admin api instance
@@ -58,6 +75,7 @@ func NewAdminApi(xeth *xeth.XEth, ethereum *eth.Ethereum, codec codec.Codec) *ad
ethereum: ethereum,
codec: codec,
coder: codec.New(nil),
+ ds: docserver.New("/"),
}
}
@@ -292,3 +310,148 @@ func sleepBlocks(wait chan *big.Int, height *big.Int, timer <-chan time.Time) (n
// time.Sleep(time.Duration(sec) * time.Second)
// return otto.UndefinedValue()
// }
+func (self *adminApi) SetGlobalRegistrar(req *shared.Request) (interface{}, error) {
+ args := new(SetGlobalRegistrarArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ sender := common.HexToAddress(args.ContractAddress)
+
+ reg := registrar.New(self.xeth)
+ err := reg.SetGlobalRegistrar(args.NameReg, sender)
+ if err != nil {
+ return false, err
+ }
+
+ return registrar.GlobalRegistrarAddr, nil
+}
+
+func (self *adminApi) SetHashReg(req *shared.Request) (interface{}, error) {
+ args := new(SetHashRegArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ reg := registrar.New(self.xeth)
+ sender := common.HexToAddress(args.Sender)
+ err := reg.SetHashReg(args.HashReg, sender)
+ if err != nil {
+ return false, err
+ }
+
+ return registrar.HashRegAddr, nil
+}
+
+func (self *adminApi) SetUrlHint(req *shared.Request) (interface{}, error) {
+ args := new(SetUrlHintArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ urlHint := args.UrlHint
+ sender := common.HexToAddress(args.Sender)
+
+ reg := registrar.New(self.xeth)
+ err := reg.SetUrlHint(urlHint, sender)
+ if err != nil {
+ return nil, err
+ }
+
+ return registrar.UrlHintAddr, nil
+}
+
+func (self *adminApi) SaveInfo(req *shared.Request) (interface{}, error) {
+ args := new(SaveInfoArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ contenthash, err := compiler.SaveInfo(&args.ContractInfo, args.Filename)
+ if err != nil {
+ return nil, err
+ }
+
+ return contenthash.Hex(), nil
+}
+
+func (self *adminApi) Register(req *shared.Request) (interface{}, error) {
+ args := new(RegisterArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ sender := common.HexToAddress(args.Sender)
+ // sender and contract address are passed as hex strings
+ codeb := self.xeth.CodeAtBytes(args.Address)
+ codeHash := common.BytesToHash(crypto.Sha3(codeb))
+ contentHash := common.HexToHash(args.ContentHashHex)
+ registry := registrar.New(self.xeth)
+
+ _, err := registry.SetHashToHash(sender, codeHash, contentHash)
+ if err != nil {
+ return false, err
+ }
+
+ return true, nil
+}
+
+func (self *adminApi) RegisterUrl(req *shared.Request) (interface{}, error) {
+ args := new(RegisterUrlArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ sender := common.HexToAddress(args.Sender)
+ registry := registrar.New(self.xeth)
+ _, err := registry.SetUrlToHash(sender, common.HexToHash(args.ContentHash), args.Url)
+ if err != nil {
+ return false, err
+ }
+
+ return true, nil
+}
+
+func (self *adminApi) StartNatSpec(req *shared.Request) (interface{}, error) {
+ self.ethereum.NatSpec = true
+ return true, nil
+}
+
+func (self *adminApi) StopNatSpec(req *shared.Request) (interface{}, error) {
+ self.ethereum.NatSpec = false
+ return true, nil
+}
+
+func (self *adminApi) GetContractInfo(req *shared.Request) (interface{}, error) {
+ args := new(GetContractInfoArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ infoDoc, err := natspec.FetchDocsForContract(args.Contract, self.xeth, self.ds)
+ if err != nil {
+ return nil, err
+ }
+
+ var info interface{}
+ err = self.coder.Decode(infoDoc, &info)
+ if err != nil {
+ return nil, err
+ }
+
+ return info, nil
+}
+
+func (self *adminApi) HttpGet(req *shared.Request) (interface{}, error) {
+ args := new(HttpGetArgs)
+ if err := self.coder.Decode(req.Params, &args); err != nil {
+ return nil, shared.NewDecodeParamError(err.Error())
+ }
+
+ resp, err := self.ds.Get(args.Uri, args.Path)
+ if err != nil {
+ return nil, err
+ }
+
+ return string(resp), nil
+}