diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-10 06:00:27 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-10 06:08:46 +0800 |
commit | a11f1d6a7ec2eaa1a348776072c49019368a5ef3 (patch) | |
tree | cd2d7e9c3ade2ea02462436a908ca1caf9c06de3 /cmd/utils/flags.go | |
parent | 73d1ebe244644c2d74a1c0c38a3b339e72140886 (diff) | |
download | dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar.gz dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar.bz2 dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar.lz dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar.xz dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.tar.zst dexon-a11f1d6a7ec2eaa1a348776072c49019368a5ef3.zip |
rpc: add dataDir parameter and JSON-RPC handler
Diffstat (limited to 'cmd/utils/flags.go')
-rw-r--r-- | cmd/utils/flags.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 2156963c4..2995ebad8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2,6 +2,10 @@ package utils import ( "crypto/ecdsa" + "fmt" + "net" + "net/http" + "os" "path" "runtime" "time" @@ -17,6 +21,8 @@ import ( "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p/nat" + "github.com/ethereum/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/xeth" ) // NewApp creates an app with sane defaults. @@ -183,3 +189,15 @@ func GetAccountManager(ctx *cli.Context) *accounts.Manager { ks := crypto.NewKeyStorePassphrase(path.Join(dataDir, "keys")) return accounts.NewManager(ks, 300*time.Second) } + +func StartRPC(eth *eth.Ethereum, ctx *cli.Context) { + addr := ctx.GlobalString(RPCListenAddrFlag.Name) + port := ctx.GlobalInt(RPCPortFlag.Name) + dataDir := ctx.GlobalString(DataDirFlag.Name) + + l, err := net.Listen("tcp", fmt.Sprintf("%s:%d", addr, port)) + if err != nil { + Fatalf("Can't listen on %s:%d: %v", addr, port, err) + } + go http.Serve(l, rpc.JSONRPC(xeth.New(eth), dataDir)) +} |