mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
web3 upgrade + integration of miner api in console
This commit is contained in:
parent
b036853917
commit
13390cb78b
7 changed files with 8449 additions and 25 deletions
|
|
@ -107,9 +107,14 @@ func (js *jsre) apiBindings(ipcpath string) {
|
|||
utils.Fatalf("Error loading bignumber.js: %v", err)
|
||||
}
|
||||
|
||||
err = js.re.Compile("ethereum.js", re.Ethereum_JS)
|
||||
// err = js.re.Compile("ethereum.js", re.Ethereum_JS)
|
||||
// if err != nil {
|
||||
// utils.Fatalf("Error loading ethereum.js: %v", err)
|
||||
// }
|
||||
|
||||
err = js.re.Compile("ethereum.js", re.Web3_JS)
|
||||
if err != nil {
|
||||
utils.Fatalf("Error loading ethereum.js: %v", err)
|
||||
utils.Fatalf("Error loading web3.js: %v", err)
|
||||
}
|
||||
|
||||
_, err = js.re.Eval("var web3 = require('web3');")
|
||||
|
|
@ -117,6 +122,11 @@ func (js *jsre) apiBindings(ipcpath string) {
|
|||
utils.Fatalf("Error requiring web3: %v", err)
|
||||
}
|
||||
|
||||
err = js.re.Compile("miner.js", re.Miner_JS)
|
||||
if err != nil {
|
||||
utils.Fatalf("Error loading miner.js: %v", err)
|
||||
}
|
||||
|
||||
_, err = js.re.Eval("web3.setProvider(jeth)")
|
||||
if err != nil {
|
||||
utils.Fatalf("Error setting web3 provider: %v", err)
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ var (
|
|||
IPCApiFlag = cli.StringFlag{
|
||||
Name: "ipcapi",
|
||||
Usage: "Specify the API's which are offered over this interface",
|
||||
Value: api.DEFAULT_IPC_APIS,
|
||||
Value: api.DefaultIpcApis,
|
||||
}
|
||||
IPCPathFlag = cli.StringFlag{
|
||||
Name: "ipcpath",
|
||||
|
|
@ -393,7 +393,7 @@ func StartIPC(eth *eth.Ethereum, ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
|
||||
glog.V(logger.Error).Infof("IPC api's: %s", ctx.GlobalString(IPCApiFlag.Name))
|
||||
glog.V(logger.Debug).Infof("IPC api's: %s", ctx.GlobalString(IPCApiFlag.Name))
|
||||
|
||||
cfg := comms.IpcConfig{
|
||||
Endpoint: ctx.GlobalString(IPCPathFlag.Name),
|
||||
|
|
|
|||
74
jsre/miner_js.go
Normal file
74
jsre/miner_js.go
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
package jsre
|
||||
|
||||
const Miner_JS = `
|
||||
web3.extend({
|
||||
property: 'miner',
|
||||
methods:
|
||||
[
|
||||
new web3.extend.Method({
|
||||
name: 'start',
|
||||
call: 'miner_start',
|
||||
params: 1,
|
||||
inputFormatter: [web3.extend.formatters.formatInputInt],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'stop',
|
||||
call: 'miner_stop',
|
||||
params: 1,
|
||||
inputFormatter: [web3.extend.formatters.formatInputInt],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'getHashrate',
|
||||
call: 'miner_hashrate',
|
||||
params: 0,
|
||||
inputFormatter: [],
|
||||
outputFormatter: web3.extend.utils.toDecimal
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'setExtra',
|
||||
call: 'miner_setExtra',
|
||||
params: 1,
|
||||
inputFormatter: [web3.extend.utils.formatInputString],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'setGasPrice',
|
||||
call: 'miner_setGasPrice',
|
||||
params: 1,
|
||||
inputFormatter: [web3.extend.utils.formatInputString],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'startAutoDAG',
|
||||
call: 'miner_startAutoDAG',
|
||||
params: 0,
|
||||
inputFormatter: [],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'stopAutoDAG',
|
||||
call: 'miner_stopAutoDAG',
|
||||
params: 0,
|
||||
inputFormatter: [],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
}),
|
||||
new web3.extend.Method({
|
||||
name: 'makeDAG',
|
||||
call: 'miner_makeDAG',
|
||||
params: 1,
|
||||
inputFormatter: [web3.extend.formatters.inputDefaultBlockNumberFormatter],
|
||||
outputFormatter: web3.extend.formatters.formatOutputBool
|
||||
})
|
||||
],
|
||||
properties:
|
||||
[
|
||||
new web3.extend.Property({
|
||||
name: 'hashrate',
|
||||
getter: 'miner_hashrate',
|
||||
outputFormatter: web3.extend.utils.toDecimal
|
||||
})
|
||||
]
|
||||
});
|
||||
`
|
||||
8290
jsre/web3_js.go
Normal file
8290
jsre/web3_js.go
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -11,8 +11,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
DEFAULT_IPC_APIS = "admin,debug,eth,miner,net,web3"
|
||||
DEFAULT_HTTP_APIS = "web3,eth"
|
||||
DefaultIpcApis = "admin,debug,eth,miner,net,web3"
|
||||
DefaultHttpApiS = "web3,eth"
|
||||
)
|
||||
|
||||
// Descriptor for all API implementations
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ func (self *miner) StartMiner(req *shared.Request) (interface{}, error) {
|
|||
if err := self.codec.Decode(req.Params, &args); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if args.Threads == -1 { // (-1 is set in unmarshalljson when not specified in req)
|
||||
if args.Threads == -1 { // (not specified by user, use default)
|
||||
args.Threads = self.ethereum.MinerThreads
|
||||
}
|
||||
|
||||
|
|
@ -111,21 +111,21 @@ func (self *miner) SetExtra(req *shared.Request) (interface{}, error) {
|
|||
func (self *miner) SetGasPrice(req *shared.Request) (interface{}, error) {
|
||||
args := new(GasPriceArgs)
|
||||
if err := self.codec.Decode(req.Params, &args); err != nil {
|
||||
return nil, err
|
||||
return false, err
|
||||
}
|
||||
|
||||
self.ethereum.Miner().SetGasPrice(common.String2Big(args.Price))
|
||||
return nil, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *miner) StartAutoDAG(req *shared.Request) (interface{}, error) {
|
||||
self.ethereum.StartAutoDAG()
|
||||
return nil, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *miner) StopAutoDAG(req *shared.Request) (interface{}, error) {
|
||||
self.ethereum.StopAutoDAG()
|
||||
return nil, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (self *miner) MakeDAG(req *shared.Request) (interface{}, error) {
|
||||
|
|
@ -134,7 +134,11 @@ func (self *miner) MakeDAG(req *shared.Request) (interface{}, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
err := ethash.MakeDAG(args.BlockNumber, "")
|
||||
if args.BlockNumber < 0 {
|
||||
return false, shared.NewValidationError("BlockNumber", "BlockNumber must be positive")
|
||||
}
|
||||
|
||||
err := ethash.MakeDAG(uint64(args.BlockNumber), "")
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@ package api
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/rpc/shared"
|
||||
)
|
||||
|
||||
type StartMinerArgs struct {
|
||||
Threads int `json:"threads"`
|
||||
Threads int
|
||||
}
|
||||
|
||||
func (args *StartMinerArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
|
|
@ -17,31 +18,76 @@ func (args *StartMinerArgs) UnmarshalJSON(b []byte) (err error) {
|
|||
return shared.NewDecodeParamError(err.Error())
|
||||
}
|
||||
|
||||
if len(obj) == 0 {
|
||||
if len(obj) == 0 || obj[0] == nil {
|
||||
args.Threads = -1
|
||||
return nil
|
||||
}
|
||||
|
||||
var arg0 *big.Int
|
||||
if arg0, err = numString(obj[0]); err != nil {
|
||||
var num *big.Int
|
||||
if num, err = numString(obj[0]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if arg0.Int64() >= 0 && arg0.Int64() <= 256 {
|
||||
args.Threads = int(arg0.Int64())
|
||||
}
|
||||
|
||||
return shared.NewValidationError("threads", "must be in range [0...256]")
|
||||
args.Threads = int(num.Int64())
|
||||
return nil
|
||||
}
|
||||
|
||||
type SetExtraArgs struct {
|
||||
Data string `json:"data"`
|
||||
Data string
|
||||
}
|
||||
|
||||
func (args *SetExtraArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
var obj []interface{}
|
||||
if err := json.Unmarshal(b, &obj); err != nil {
|
||||
return shared.NewDecodeParamError(err.Error())
|
||||
}
|
||||
|
||||
extrastr, ok := obj[0].(string)
|
||||
if !ok {
|
||||
return shared.NewInvalidTypeError("Price", "not a string")
|
||||
}
|
||||
args.Data = extrastr
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type GasPriceArgs struct {
|
||||
Price string `json:"price"`
|
||||
Price string
|
||||
}
|
||||
|
||||
func (args *GasPriceArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
var obj []interface{}
|
||||
if err := json.Unmarshal(b, &obj); err != nil {
|
||||
return shared.NewDecodeParamError(err.Error())
|
||||
}
|
||||
|
||||
pricestr, ok := obj[0].(string)
|
||||
if !ok {
|
||||
return shared.NewInvalidTypeError("Price", "not a string")
|
||||
}
|
||||
args.Price = pricestr
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type MakeDAGArgs struct {
|
||||
BlockNumber uint64 `json:"blockNumber"`
|
||||
BlockNumber int64
|
||||
}
|
||||
|
||||
func (args *MakeDAGArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
args.BlockNumber = -1
|
||||
var obj []interface{}
|
||||
|
||||
if err := json.Unmarshal(b, &obj); err != nil {
|
||||
return shared.NewDecodeParamError(err.Error())
|
||||
}
|
||||
|
||||
if len(obj) < 1 {
|
||||
return shared.NewInsufficientParamsError(len(obj), 1)
|
||||
}
|
||||
|
||||
if err := blockHeight(obj[0], &args.BlockNumber); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue