mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
added net api
This commit is contained in:
parent
557ebf9e8e
commit
932485f7e7
6 changed files with 65 additions and 12 deletions
|
|
@ -128,6 +128,11 @@ func (js *jsre) apiBindings(ipcpath string) {
|
|||
utils.Fatalf("Error loading miner.js: %v", err)
|
||||
}
|
||||
|
||||
err = js.re.Compile("net.js", api.Net_JS)
|
||||
if err != nil {
|
||||
utils.Fatalf("Error loading net.js: %v", err)
|
||||
}
|
||||
|
||||
_, err = js.re.Eval("web3.setProvider(jeth)")
|
||||
if err != nil {
|
||||
utils.Fatalf("Error setting web3 provider: %v", err)
|
||||
|
|
@ -136,8 +141,9 @@ func (js *jsre) apiBindings(ipcpath string) {
|
|||
var eth = web3.eth;
|
||||
var shh = web3.shh;
|
||||
var db = web3.db;
|
||||
var net = web3.net;
|
||||
var net = web3.network;
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
utils.Fatalf("Error setting namespaces: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,10 +13,44 @@ const (
|
|||
var (
|
||||
// mapping between methods and handlers
|
||||
AdminMapping = map[string]adminhandler{
|
||||
//"admin_startMiner": (*admin).StartMiner,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StopRPC,
|
||||
// "admin_startRPC": (*admin).NodeInfo,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
// "admin_startRPC": (*admin).StartRPC,
|
||||
}
|
||||
)
|
||||
|
||||
/*
|
||||
addPeer: [Function],
|
||||
startRPC: [Function],
|
||||
stopRPC: [Function],
|
||||
nodeInfo: [Function],
|
||||
peers: [Function],
|
||||
newAccount: [Function],
|
||||
unlock: [Function],
|
||||
import: [Function],
|
||||
export: [Function],
|
||||
verbosity: [Function],
|
||||
progress: [Function],
|
||||
setSolc: [Function],
|
||||
contractInfo: {
|
||||
start: [Function],
|
||||
stop: [Function],
|
||||
newRegistry: [Function],
|
||||
get: [Function],
|
||||
register: [Function],
|
||||
registerUrl: [Function]
|
||||
},
|
||||
*/
|
||||
|
||||
// admin callback handler
|
||||
type adminhandler func(*admin, *shared.Request) (interface{}, error)
|
||||
|
||||
|
|
|
|||
5
rpc/api/admin_js.go
Normal file
5
rpc/api/admin_js.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package api
|
||||
|
||||
const Admin_JS = `
|
||||
|
||||
`
|
||||
|
|
@ -77,7 +77,7 @@ func ParseApiString(apiString string, codec codec.Codec, eth *e.Ethereum) ([]Eth
|
|||
case "miner":
|
||||
apis[i] = NewMiner(eth, codec)
|
||||
case "net":
|
||||
apis[i] = NewNet(xeth, codec)
|
||||
apis[i] = NewNet(xeth, eth, codec)
|
||||
case "web3":
|
||||
apis[i] = NewWeb3(xeth, codec)
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/rpc/codec"
|
||||
"github.com/ethereum/go-ethereum/rpc/shared"
|
||||
"github.com/ethereum/go-ethereum/xeth"
|
||||
e "github.com/ethereum/go-ethereum/eth"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
@ -12,6 +13,7 @@ var (
|
|||
"net_version": (*net).Version,
|
||||
"net_peerCount": (*net).PeerCount,
|
||||
"net_listening": (*net).IsListening,
|
||||
"net_peers": (*net).Peers,
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -21,14 +23,16 @@ type nethandler func(*net, *shared.Request) (interface{}, error)
|
|||
// net api provider
|
||||
type net struct {
|
||||
xeth *xeth.XEth
|
||||
ethereum *e.Ethereum
|
||||
methods map[string]nethandler
|
||||
codec codec.ApiCoder
|
||||
}
|
||||
|
||||
// create a new net api instance
|
||||
func NewNet(xeth *xeth.XEth, coder codec.Codec) *net {
|
||||
func NewNet(xeth *xeth.XEth, eth *e.Ethereum, coder codec.Codec) *net {
|
||||
return &net{
|
||||
xeth: xeth,
|
||||
ethereum: eth,
|
||||
methods: netMapping,
|
||||
codec: coder.New(nil),
|
||||
}
|
||||
|
|
@ -65,9 +69,13 @@ func (self *net) Version(req *shared.Request) (interface{}, error) {
|
|||
|
||||
// Number of connected peers
|
||||
func (self *net) PeerCount(req *shared.Request) (interface{}, error) {
|
||||
return newHexNum(self.xeth.PeerCount()), nil
|
||||
return self.xeth.PeerCount(), nil
|
||||
}
|
||||
|
||||
func (self *net) IsListening(req *shared.Request) (interface{}, error) {
|
||||
return self.xeth.IsListening(), nil
|
||||
}
|
||||
|
||||
func (self *net) Peers(req *shared.Request) (interface{}, error) {
|
||||
return self.ethereum.PeersInfo(), nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package api
|
|||
|
||||
const Net_JS = `
|
||||
web3.extend({
|
||||
property: 'miner',
|
||||
property: 'network',
|
||||
methods:
|
||||
[
|
||||
new web3.extend.Method({
|
||||
|
|
@ -13,18 +13,18 @@ web3.extend({
|
|||
outputFormatter: web3.extend.formatters.formatOutputString
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'stop',
|
||||
call: 'net_getPeerCount',
|
||||
name: 'getPeerCount',
|
||||
call: 'net_peerCount',
|
||||
params: 0,
|
||||
inputFormatter: [],
|
||||
outputFormatter: web3.extend.formatters.formatOutputString
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'stop',
|
||||
call: 'miner_stop',
|
||||
name: 'peers',
|
||||
call: 'net_peers',
|
||||
params: 0,
|
||||
inputFormatter: [],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
outputFormatter: function(obj) { return obj; }
|
||||
})
|
||||
],
|
||||
properties:
|
||||
|
|
@ -36,7 +36,7 @@ web3.extend({
|
|||
}),
|
||||
new web3.extend.Property({
|
||||
name: 'peerCount',
|
||||
getter: 'net_getPeerCount',
|
||||
getter: 'net_peerCount',
|
||||
outputFormatter: web3.extend.utils.toDecimal
|
||||
})
|
||||
]
|
||||
|
|
|
|||
Loading…
Reference in a new issue