diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-23 23:04:21 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-23 23:04:21 +0800 |
commit | 3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa (patch) | |
tree | 6da97d39c03b125d4824c570bede3fb445c756a0 /rpc/api.go | |
parent | dbb2af6016c952b0f49d552a10fc59af0a9f7ce7 (diff) | |
download | dexon-3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa.tar.gz dexon-3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa.tar.zst dexon-3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa.zip |
db_putHex/db_getHex + tests
Diffstat (limited to 'rpc/api.go')
-rw-r--r-- | rpc/api.go | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/rpc/api.go b/rpc/api.go index 427032995..4cd88aa71 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -21,7 +21,10 @@ type EthereumApi struct { func NewEthereumApi(xeth *xeth.XEth, dataDir string) *EthereumApi { // What about when dataDir is empty? - db, _ := ethdb.NewLDBDatabase(path.Join(dataDir, "dapps")) + db, err := ethdb.NewLDBDatabase(path.Join(dataDir, "dapps")) + if err != nil { + panic(err) + } api := &EthereumApi{ eth: xeth, db: db, @@ -361,7 +364,7 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err return err } - api.db.Put([]byte(args.Database+args.Key), []byte(args.Value)) + api.db.Put([]byte(args.Database+args.Key), args.Value) *reply = true case "db_getString": args := new(DbArgs) @@ -375,8 +378,30 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err res, _ := api.db.Get([]byte(args.Database + args.Key)) *reply = string(res) - case "db_putHex", "db_getHex": - return NewNotImplementedError(req.Method) + case "db_putHex": + args := new(DbHexArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + + if err := args.requirements(); err != nil { + return err + } + + api.db.Put([]byte(args.Database+args.Key), args.Value) + *reply = true + case "db_getHex": + args := new(DbHexArgs) + if err := json.Unmarshal(req.Params, &args); err != nil { + return err + } + + if err := args.requirements(); err != nil { + return err + } + + res, _ := api.db.Get([]byte(args.Database + args.Key)) + *reply = common.ToHex(res) case "shh_post": args := new(WhisperMessageArgs) if err := json.Unmarshal(req.Params, &args); err != nil { |