aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-23 23:04:21 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-23 23:04:21 +0800
commit3f6e1b2fd3cbc6aeb1bbe658dd5b70945a57dffa (patch)
tree6da97d39c03b125d4824c570bede3fb445c756a0 /rpc/api.go
parentdbb2af6016c952b0f49d552a10fc59af0a9f7ce7 (diff)
downloaddexon-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.go33
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 {