Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
a11f1d6a
Commit
a11f1d6a
authored
Mar 09, 2015
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc: add dataDir parameter and JSON-RPC handler
parent
73d1ebe2
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
17 deletions
+64
-17
main.go
cmd/ethereum/main.go
+1
-3
cmd.go
cmd/utils/cmd.go
+0
-12
flags.go
cmd/utils/flags.go
+18
-0
api.go
rpc/api.go
+3
-2
http.go
rpc/http.go
+42
-0
No files found.
cmd/ethereum/main.go
View file @
a11f1d6a
...
...
@@ -170,9 +170,7 @@ func runjs(ctx *cli.Context) {
func
startEth
(
ctx
*
cli
.
Context
,
eth
*
eth
.
Ethereum
)
{
utils
.
StartEthereum
(
eth
)
if
ctx
.
GlobalBool
(
utils
.
RPCEnabledFlag
.
Name
)
{
addr
:=
ctx
.
GlobalString
(
utils
.
RPCListenAddrFlag
.
Name
)
port
:=
ctx
.
GlobalInt
(
utils
.
RPCPortFlag
.
Name
)
utils
.
StartRpc
(
eth
,
addr
,
port
)
utils
.
StartRPC
(
eth
,
ctx
)
}
if
ctx
.
GlobalBool
(
utils
.
MiningEnabledFlag
.
Name
)
{
eth
.
Miner
()
.
Start
()
...
...
cmd/utils/cmd.go
View file @
a11f1d6a
...
...
@@ -34,9 +34,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rlp"
rpchttp
"github.com/ethereum/go-ethereum/rpc/http"
"github.com/ethereum/go-ethereum/state"
"github.com/ethereum/go-ethereum/xeth"
)
var
clilogger
=
logger
.
NewLogger
(
"CLI"
)
...
...
@@ -165,16 +163,6 @@ func KeyTasks(keyManager *crypto.KeyManager, KeyRing string, GenAddr bool, Secre
clilogger
.
Infof
(
"Main address %x
\n
"
,
keyManager
.
Address
())
}
func
StartRpc
(
ethereum
*
eth
.
Ethereum
,
RpcListenAddress
string
,
RpcPort
int
)
{
var
err
error
ethereum
.
RpcServer
,
err
=
rpchttp
.
NewRpcHttpServer
(
xeth
.
New
(
ethereum
),
RpcListenAddress
,
RpcPort
)
if
err
!=
nil
{
clilogger
.
Errorf
(
"Could not start RPC interface (port %v): %v"
,
RpcPort
,
err
)
}
else
{
go
ethereum
.
RpcServer
.
Start
()
}
}
func
FormatTransactionData
(
data
string
)
[]
byte
{
d
:=
ethutil
.
StringToByteFunc
(
data
,
func
(
s
string
)
(
ret
[]
byte
)
{
slice
:=
regexp
.
MustCompile
(
"
\\
n|
\\
s"
)
.
Split
(
s
,
1000000000
)
...
...
cmd/utils/flags.go
View file @
a11f1d6a
...
...
@@ -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
))
}
rpc/api.go
View file @
a11f1d6a
...
...
@@ -11,6 +11,7 @@ package rpc
import
(
"fmt"
"math/big"
"path"
"strings"
"sync"
"time"
...
...
@@ -55,8 +56,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
(),
...
...
rpc/http.go
0 → 100644
View file @
a11f1d6a
package
rpc
import
(
"net/http"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/xeth"
)
var
rpchttplogger
=
logger
.
NewLogger
(
"RPC-HTTP"
)
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
func
JSONRPC
(
pipe
*
xeth
.
XEth
,
dataDir
string
)
http
.
Handler
{
var
json
JsonWrapper
const
jsonrpcver
=
"2.0"
api
:=
NewEthereumApi
(
pipe
,
dataDir
)
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
rpchttplogger
.
DebugDetailln
(
"Handling request"
)
reqParsed
,
reqerr
:=
json
.
ParseRequestBody
(
req
)
if
reqerr
!=
nil
{
jsonerr
:=
&
RpcErrorObject
{
-
32700
,
"Error: Could not parse request"
}
json
.
Send
(
w
,
&
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
nil
,
Error
:
jsonerr
})
return
}
var
response
interface
{}
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
if
reserr
!=
nil
{
rpchttplogger
.
Warnln
(
reserr
)
jsonerr
:=
&
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
json
.
Send
(
w
,
&
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Error
:
jsonerr
})
return
}
rpchttplogger
.
DebugDetailf
(
"Generated response: %T %s"
,
response
,
response
)
json
.
Send
(
w
,
&
RpcSuccessResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Result
:
response
})
})
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment