aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/api.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-11 08:08:42 +0800
committerobscuren <geffobscura@gmail.com>2015-03-11 08:08:42 +0800
commit7e0ccc9de53e788ddc1879248bceb33a9ccdbae0 (patch)
tree816ff2e06aaa78721a22eee7f2c8493fbf313fb4 /rpc/api.go
parentce595b9266d658a5eae626d78aec7f47c04222ca (diff)
parenteba4f389a6c494bc3e15b3bbc6516b51a5e61236 (diff)
downloaddexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.gz
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.bz2
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.lz
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.xz
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.tar.zst
dexon-7e0ccc9de53e788ddc1879248bceb33a9ccdbae0.zip
Merge branch 'develop' into rpcfrontier
Conflicts: rpc/api.go rpc/args.go
Diffstat (limited to 'rpc/api.go')
-rw-r--r--rpc/api.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/rpc/api.go b/rpc/api.go
index 38f02a473..04492f27c 100644
--- a/rpc/api.go
+++ b/rpc/api.go
@@ -2,7 +2,9 @@ package rpc
import (
"encoding/json"
+ "fmt"
"math/big"
+ "path"
"strings"
"sync"
"time"
@@ -46,8 +48,8 @@ type EthereumApi struct {
// defaultBlockAge int64
}
-func NewEthereumApi(eth *xeth.XEth) *EthereumApi {
- db, _ := ethdb.NewLDBDatabase("dapps")
+func NewEthereumApi(eth *xeth.XEth, dataDir string) *EthereumApi {
+ db, _ := ethdb.NewLDBDatabase(path.Join(dataDir, "dapps"))
api := &EthereumApi{
eth: eth,
mux: eth.Backend().EventMux(),
@@ -232,15 +234,7 @@ func (self *EthereumApi) AllLogs(args *FilterOptions, reply *interface{}) error
return nil
}
-func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
- if args.Gas == ethutil.Big0 {
- args.Gas = defaultGas
- }
-
- if args.GasPrice == ethutil.Big0 {
- args.GasPrice = defaultGasPrice
- }
-
+func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) (err error) {
// TODO if no_private_key then
//if _, exists := p.register[args.From]; exists {
// p.register[args.From] = append(p.register[args.From], args)
@@ -262,18 +256,28 @@ func (p *EthereumApi) Transact(args *NewTxArgs, reply *interface{}) error {
p.register[ags.From] = append(p.register[args.From], args)
}
*/
- result, err := p.xeth().Transact( /* TODO specify account */ args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+ // TODO: align default values to have the same type, e.g. not depend on
+ // ethutil.Value conversions later on
+ fmt.Println("gas", args.Gas)
+ if args.Gas.Cmp(big.NewInt(0)) == 0 {
+ args.Gas = defaultGas
+ }
+
+ if args.GasPrice.Cmp(big.NewInt(0)) == 0 {
+ args.GasPrice = defaultGasPrice
+ }
+
+ *reply, err = p.xeth().Transact(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil {
+ fmt.Println("err:", err)
return err
}
- *reply = result
- //}
return nil
}
func (p *EthereumApi) Call(args *NewTxArgs, reply *interface{}) error {
- result, err := p.xeth().Call( /* TODO specify account */ args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
+ result, err := p.xeth().Call(args.From, args.To, args.Value.String(), args.Gas.String(), args.GasPrice.String(), args.Data)
if err != nil {
return err
}