update to latest develop

* rpc v2 integration
* resurrect ethreg
* relocate registrar api
* delete surreal content in crypto/secp256k1/curve_test.go and eth/downloader/modes.go
This commit is contained in:
zelig 2016-02-01 20:02:49 +08:00
parent 18cac67202
commit 477d498181
14 changed files with 218 additions and 521 deletions

View file

@ -184,13 +184,6 @@ func newJSRE(stack *node.Node, docRoot, corsDomain string, client rpc.Client, in
js.corsDomain = corsDomain js.corsDomain = corsDomain
js.wait = make(chan *big.Int) js.wait = make(chan *big.Int)
js.client = client js.client = client
if clt, ok := js.client.(*comms.InProcClient); ok {
if offeredApis, err := api.ParseApiString(shared.AllApis, codec.JSON, js.xeth, stack); err == nil {
clt.Initialize(api.Merge(offeredApis...))
} else {
utils.Fatalf("Unable to offer apis: %v", err)
}
}
js.re = re.New(docRoot) js.re = re.New(docRoot)
if err := js.apiBindings(); err != nil { if err := js.apiBindings(); err != nil {

View file

@ -89,7 +89,7 @@ func testJEthRE(t *testing.T) (string, *testjethre, *node.Node) {
return testREPL(t, nil) return testREPL(t, nil)
} }
func testREPL(t *testing.T, config func(*node.Node)) (string, *testjethre, *node.Node) { func testREPL(t *testing.T, config func(*eth.Config)) (string, *testjethre, *node.Node) {
tmp, err := ioutil.TempDir("", "geth-test") tmp, err := ioutil.TempDir("", "geth-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -105,14 +105,12 @@ func testREPL(t *testing.T, config func(*node.Node)) (string, *testjethre, *node
db, _ := ethdb.NewMemDatabase() db, _ := ethdb.NewMemDatabase()
core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)}) core.WriteGenesisBlockForTesting(db, core.GenesisAccount{common.HexToAddress(testAddress), common.String2Big(testBalance)})
coinbase := common.HexToAddress(testAddress)
ethConf := &eth.Config{ ethConf := &eth.Config{
TestGenesisState: db, TestGenesisState: db,
AccountManager: accman, AccountManager: accman,
DocRoot: "/", DocRoot: "/",
SolcPath: testSolcPath, SolcPath: testSolcPath,
Etherbase: coinbase,
PowTest: true, PowTest: true,
} }
if config != nil { if config != nil {
@ -135,12 +133,6 @@ func testREPL(t *testing.T, config func(*node.Node)) (string, *testjethre, *node
if err := accman.Unlock(key.Address, ""); err != nil { if err := accman.Unlock(key.Address, ""); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// tests can register services here
if config != nil {
config(stack)
}
// Start the node and assemble the REPL tester // Start the node and assemble the REPL tester
if err := stack.Start(); err != nil { if err := stack.Start(); err != nil {
t.Fatalf("failed to start test stack: %v", err) t.Fatalf("failed to start test stack: %v", err)
@ -276,7 +268,10 @@ func TestSignature(t *testing.T) {
func TestContract(t *testing.T) { func TestContract(t *testing.T) {
t.Skip("contract testing is implemented with mining in ethash test mode. This takes about 7seconds to run. Unskip and run on demand") t.Skip("contract testing is implemented with mining in ethash test mode. This takes about 7seconds to run. Unskip and run on demand")
coinbase := common.HexToAddress(testAddress) coinbase := common.HexToAddress(testAddress)
tmp, repl, ethereum := testREPL(t, nil) tmp, repl, ethereum := testREPL(t, func(conf *eth.Config) {
conf.Etherbase = coinbase
conf.PowTest = true
})
if err := ethereum.Start(); err != nil { if err := ethereum.Start(); err != nil {
t.Errorf("error starting ethereum: %v", err) t.Errorf("error starting ethereum: %v", err)
return return

View file

@ -490,6 +490,11 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Failed to start WS: %v", err) utils.Fatalf("Failed to start WS: %v", err)
} }
} }
// Unlock any account specifically requested
var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil {
utils.Fatalf("ethereum service not running: %v", err)
}
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) { if ctx.GlobalBool(utils.MiningEnabledFlag.Name) {
if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name), ctx.GlobalString(utils.MiningGPUFlag.Name)); err != nil { if err := ethereum.StartMining(ctx.GlobalInt(utils.MinerThreadsFlag.Name), ctx.GlobalString(utils.MiningGPUFlag.Name)); err != nil {
utils.Fatalf("Failed to start mining: %v", err) utils.Fatalf("Failed to start mining: %v", err)

View file

@ -48,12 +48,6 @@ import (
"github.com/ethereum/go-ethereum/p2p/nat" "github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/comms"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/useragent"
rpc "github.com/ethereum/go-ethereum/rpc/v2"
"github.com/ethereum/go-ethereum/swarm" "github.com/ethereum/go-ethereum/swarm"
bzzapi "github.com/ethereum/go-ethereum/swarm/api" bzzapi "github.com/ethereum/go-ethereum/swarm/api"
"github.com/ethereum/go-ethereum/whisper" "github.com/ethereum/go-ethereum/whisper"
@ -366,7 +360,7 @@ var (
// ATM the url is left to the user and deployment to // ATM the url is left to the user and deployment to
JSpathFlag = cli.StringFlag{ JSpathFlag = cli.StringFlag{
Name: "jspath", Name: "jspath",
Usage: "JavaSript root path for `loadScript` and document root for `admin.httpGet`", Usage: "JavaScript root path for `loadScript` and document root for `admin.httpGet`",
Value: ".", Value: ".",
} }
SolcPathFlag = cli.StringFlag{ SolcPathFlag = cli.StringFlag{

View file

@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package ethreg package registrar
import ( import (
"errors" "errors"
@ -30,7 +30,7 @@ import (
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog" "github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/common/registrar" // "github.com/ethereum/go-ethereum/common/registrar"
) )
// registryAPIBackend is a backend for an Ethereum Registry. // registryAPIBackend is a backend for an Ethereum Registry.
@ -41,14 +41,14 @@ type registryAPIBackend struct {
am *accounts.Manager am *accounts.Manager
} }
// PrivateRegistarAPI offers various functions to access the Ethereum registry. // PublicRegistarAPI offers various functions to access the Ethereum registry.
type PrivateRegistarAPI struct { type PublicRegistarAPI struct {
be *registryAPIBackend be *registryAPIBackend
} }
// NewPrivateRegistarAPI creates a new PrivateRegistarAPI instance. // NewPublicRegistarAPI creates a new PublicRegistarAPI instance.
func NewPrivateRegistarAPI(bc *core.BlockChain, chainDb ethdb.Database, txPool *core.TxPool, am *accounts.Manager) *PrivateRegistarAPI { func NewPublicRegistarAPI(bc *core.BlockChain, chainDb ethdb.Database, txPool *core.TxPool, am *accounts.Manager) *PublicRegistarAPI {
return &PrivateRegistarAPI{&registryAPIBackend{bc, chainDb, txPool, am}} return &PublicRegistarAPI{&registryAPIBackend{bc, chainDb, txPool, am}}
} }
// SetGlobalRegistrar allows clients to set the global registry for the node. // SetGlobalRegistrar allows clients to set the global registry for the node.
@ -58,27 +58,27 @@ func NewPrivateRegistarAPI(bc *core.BlockChain, chainDb ethdb.Database, txPool *
// will deploy a new registry on execution. The TX hash is returned. When called // will deploy a new registry on execution. The TX hash is returned. When called
// with namereg '' and the current address is not zero the current global is // with namereg '' and the current address is not zero the current global is
// address is returned.. // address is returned..
func (api *PrivateRegistarAPI) SetGlobalRegistrar(namereg string, from common.Address) (string, error) { func (api *PublicRegistarAPI) SetGlobalRegistrar(namereg string, from common.Address) (string, error) {
return registrar.New(api.be).SetGlobalRegistrar(namereg, from) return New(api.be).SetGlobalRegistrar(namereg, from)
} }
// SetHashReg queries the registry for a hash. // SetHashReg queries the registry for a hash.
func (api *PrivateRegistarAPI) SetHashReg(hashreg string, from common.Address) (string, error) { func (api *PublicRegistarAPI) SetHashReg(hashreg string, from common.Address) (string, error) {
return registrar.New(api.be).SetHashReg(hashreg, from) return New(api.be).SetHashReg(hashreg, from)
} }
// SetUrlHint queries the registry for an url. // SetUrlHint queries the registry for an url.
func (api *PrivateRegistarAPI) SetUrlHint(hashreg string, from common.Address) (string, error) { func (api *PublicRegistarAPI) SetUrlHint(hashreg string, from common.Address) (string, error) {
return registrar.New(api.be).SetUrlHint(hashreg, from) return New(api.be).SetUrlHint(hashreg, from)
} }
// SaveInfo stores contract information on the local file system. // SaveInfo stores contract information on the local file system.
func (api *PrivateRegistarAPI) SaveInfo(info *compiler.ContractInfo, filename string) (contenthash common.Hash, err error) { func (api *PublicRegistarAPI) SaveInfo(info *compiler.ContractInfo, filename string) (contenthash common.Hash, err error) {
return compiler.SaveInfo(info, filename) return compiler.SaveInfo(info, filename)
} }
// Register registers a new content hash in the registry. // Register registers a new content hash in the registry.
func (api *PrivateRegistarAPI) Register(sender common.Address, addr common.Address, contentHashHex string) (bool, error) { func (api *PublicRegistarAPI) Register(sender common.Address, addr common.Address, contentHashHex string) (bool, error) {
block := api.be.bc.CurrentBlock() block := api.be.bc.CurrentBlock()
state, err := state.New(block.Root(), api.be.chainDb) state, err := state.New(block.Root(), api.be.chainDb)
if err != nil { if err != nil {
@ -89,13 +89,13 @@ func (api *PrivateRegistarAPI) Register(sender common.Address, addr common.Addre
codeHash := common.BytesToHash(crypto.Sha3(codeb)) codeHash := common.BytesToHash(crypto.Sha3(codeb))
contentHash := common.HexToHash(contentHashHex) contentHash := common.HexToHash(contentHashHex)
_, err = registrar.New(api.be).SetHashToHash(sender, codeHash, contentHash) _, err = New(api.be).SetHashToHash(sender, codeHash, contentHash)
return err == nil, err return err == nil, err
} }
// RegisterUrl registers a new url in the registry. // RegisterUrl registers a new url in the registry.
func (api *PrivateRegistarAPI) RegisterUrl(sender common.Address, contentHashHex string, url string) (bool, error) { func (api *PublicRegistarAPI) RegisterUrl(sender common.Address, contentHashHex string, url string) (bool, error) {
_, err := registrar.New(api.be).SetUrlToHash(sender, common.HexToHash(contentHashHex), url) _, err := New(api.be).SetUrlToHash(sender, common.HexToHash(contentHashHex), url)
return err == nil, err return err == nil, err
} }
@ -132,7 +132,7 @@ func (m callmsg) Data() []byte {
} }
// Call forms a transaction from the given arguments and tries to execute it on // Call forms a transaction from the given arguments and tries to execute it on
// a private VM with a copy of the state. Any changes are therefore only temporary // a Public VM with a copy of the state. Any changes are therefore only temporary
// and not part of the actual state. This allows for local execution/queries. // and not part of the actual state. This allows for local execution/queries.
func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, string, error) { func (be *registryAPIBackend) Call(fromStr, toStr, valueStr, gasStr, gasPriceStr, dataStr string) (string, string, error) {
block := be.bc.CurrentBlock() block := be.bc.CurrentBlock()
@ -194,7 +194,7 @@ func (be *registryAPIBackend) StorageAt(addr string, storageAddr string) string
} }
// Transact forms a transaction from the given arguments and submits it to the // Transact forms a transaction from the given arguments and submits it to the
// transactio pool for execution. // transaction pool for execution.
func (be *registryAPIBackend) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) { func (be *registryAPIBackend) Transact(fromStr, toStr, nonceStr, valueStr, gasStr, gasPriceStr, codeStr string) (string, error) {
if len(toStr) > 0 && toStr != "0x" && !common.IsHexAddress(toStr) { if len(toStr) > 0 && toStr != "0x" && !common.IsHexAddress(toStr) {
return "", errors.New("invalid address") return "", errors.New("invalid address")

View file

@ -0,0 +1,54 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package ethreg
import (
"math/big"
"github.com/ethereum/go-ethereum/common/registrar"
)
type Backend interface {
registrar.Backend
AtStateNum(int64) registrar.Backend
}
// implements a versioned Registrar on an archiving full node
type EthReg struct {
backend Backend
registry *registrar.Registrar
}
func New(backend Backend) (self *EthReg) {
self = &EthReg{backend: backend}
self.registry = registrar.New(backend)
return
}
func (self *EthReg) Registry() *registrar.Registrar {
return self.registry
}
func (self *EthReg) Resolver(n *big.Int) *registrar.Registrar {
var s registrar.Backend
if n != nil {
s = self.backend.AtStateNum(n.Int64())
} else {
s = registrar.Backend(self.backend)
}
return registrar.New(s)
}

View file

@ -21,8 +21,6 @@ import (
"encoding/hex" "encoding/hex"
"math/big" "math/big"
"testing" "testing"
"github.com/ethereum/go-ethereum/common/registrar"
) )
func TestReadBits(t *testing.T) { func TestReadBits(t *testing.T) {
@ -39,34 +37,3 @@ func TestReadBits(t *testing.T) {
check("0000000000012345000000000000000000000000000000000000FEFCF3F8F0") check("0000000000012345000000000000000000000000000000000000FEFCF3F8F0")
check("18F8F8F1000111000110011100222004330052300000000000000000FEFCF3F8F0") check("18F8F8F1000111000110011100222004330052300000000000000000FEFCF3F8F0")
} }
type Backend interface {
registrar.Backend
AtStateNum(int64) registrar.Backend
}
// implements a versioned Registrar on an archiving full node
type EthReg struct {
backend Backend
registry *registrar.Registrar
}
func New(backend Backend) (self *EthReg) {
self = &EthReg{backend: backend}
self.registry = registrar.New(backend)
return
}
func (self *EthReg) Registry() *registrar.Registrar {
return self.registry
}
func (self *EthReg) Resolver(n *big.Int) *registrar.Registrar {
var s registrar.Backend
if n != nil {
s = self.backend.AtStateNum(n.Int64())
} else {
s = registrar.Backend(self.backend)
}
return registrar.New(s)
}

View file

@ -32,7 +32,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/compiler" "github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/common/httpclient" "github.com/ethereum/go-ethereum/common/httpclient"
"github.com/ethereum/go-ethereum/common/registrar/ethreg" "github.com/ethereum/go-ethereum/common/registrar"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
@ -317,7 +317,11 @@ func (s *Ethereum) APIs() []rpc.API {
}, { }, {
Namespace: "admin", Namespace: "admin",
Version: "1.0", Version: "1.0",
Service: ethreg.NewPrivateRegistarAPI(s.BlockChain(), s.ChainDb(), s.TxPool(), s.AccountManager()), Service: registrar.NewPublicRegistarAPI(s.BlockChain(), s.ChainDb(), s.TxPool(), s.AccountManager()),
}, {
Namespace: "registrar",
Version: "1.0",
Service: registrar.NewPublicRegistarAPI(s.BlockChain(), s.ChainDb(), s.TxPool(), s.AccountManager()),
}, },
} }
} }

View file

@ -23,27 +23,4 @@ const (
FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks
FastSync // Quickly download the headers, full sync only at the chain head FastSync // Quickly download the headers, full sync only at the chain head
LightSync // Download only the headers and terminate afterwards LightSync // Download only the headers and terminate afterwards
AdminApiName = "admin"
BzzApiName = "bzz"
EthApiName = "eth"
DbApiName = "db"
DebugApiName = "debug"
MergedApiName = "merged"
MinerApiName = "miner"
NetApiName = "net"
ShhApiName = "shh"
TxPoolApiName = "txpool"
PersonalApiName = "personal"
Web3ApiName = "web3"
ChequebookApiName = "chequebook"
JsonRpcVersion = "2.0"
)
var (
// All API's
AllApis = strings.Join([]string{
AdminApiName, BzzApiName, ChequebookApiName, DbApiName, EthApiName, DebugApiName, MinerApiName, NetApiName,
ShhApiName, TxPoolApiName, PersonalApiName, Web3ApiName,
}, ",")
) )

View file

@ -1,101 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
package api
const Bzz_JS = `
web3._extend({
property: 'bzz',
methods:
[
new web3._extend.Method({
name: 'deposit',
call: 'bzz_deposit',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'info',
call: 'bzz_info',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'cash',
call: 'bzz_cash',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'issue',
call: 'bzz_issue',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'register',
call: 'bzz_register',
params: 3,
inputFormatter: [null, null, null]
}),
new web3._extend.Method({
name: 'blockNetworkRead',
call: 'bzz_blockNetworkRead',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'resolve',
call: 'bzz_resolve',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'download',
call: 'bzz_download',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'upload',
call: 'bzz_upload',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'get',
call: 'bzz_get',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'put',
call: 'bzz_put',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'modify',
call: 'bzz_modify',
params: 4,
inputFormatter: [null, null, null, null]
})
],
properties:
[
]
});
`

View file

@ -1,50 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of go-ethereum.
//
// go-ethereum is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// go-ethereum is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
package api
const Chequebook_JS = `
web3._extend({
property: 'chequebook',
methods:
[
new web3._extend.Method({
name: 'deposit',
call: 'chequebook_deposit',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'info',
call: 'chequebook_info',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'cash',
call: 'chequebook_cash',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'issue',
call: 'chequebook_issue',
params: 2,
inputFormatter: [null, null]
}),
]
});
`

View file

@ -1,259 +0,0 @@
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package api
import (
"strings"
"fmt"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/xeth"
)
var (
// Mapping between the different methods each api supports
AutoCompletion = map[string][]string{
"admin": []string{
"addPeer",
"datadir",
"enableUserAgent",
"exportChain",
"getContractInfo",
"httpGet",
"importChain",
"nodeInfo",
"peers",
"register",
"registerUrl",
"saveInfo",
"setGlobalRegistrar",
"setHashReg",
"setUrlHint",
"setSolc",
"sleep",
"sleepBlocks",
"startNatSpec",
"startRPC",
"stopNatSpec",
"stopRPC",
"setGlobalRegistrar",
"setHashReg",
"setUrlHint",
"saveInfo",
"getContractInfo",
"sleep",
"httpGet",
"verbosity",
},
"bzz": []string{
"version",
"info",
"register",
"resolve",
"download",
"upload",
"get",
"put",
"modify",
"blockNetworkRead",
},
"chequebook": []string{
"version",
"info",
"issue",
"cash",
"deposit",
},
"db": []string{
"getString",
"putString",
"getHex",
"putHex",
},
"debug": []string{
"dumpBlock",
"getBlockRlp",
"metrics",
"printBlock",
"processBlock",
"seedHash",
"setHead",
},
"eth": []string{
"accounts",
"blockNumber",
"call",
"contract",
"coinbase",
"compile.lll",
"compile.serpent",
"compile.solidity",
"contract",
"defaultAccount",
"defaultBlock",
"estimateGas",
"filter",
"getBalance",
"getBlock",
"getBlockTransactionCount",
"getBlockUncleCount",
"getCode",
"getNatSpec",
"getCompilers",
"gasPrice",
"getStorageAt",
"getTransaction",
"getTransactionCount",
"getTransactionFromBlock",
"getTransactionReceipt",
"getUncle",
"hashrate",
"mining",
"namereg",
"getPendingTransactions",
"resend",
"sendRawTransaction",
"sendTransaction",
"sign",
"syncing",
},
"miner ": []string{
"hashrate",
"makeDAG",
"setEtherbase",
"setExtra",
"setGasPrice",
"startAutoDAG",
"setEtherbase",
"start",
"stopAutoDAG",
"stop",
},
"net": []string{
"peerCount",
"listening",
},
"personal": []string{
"listAccounts",
"newAccount",
"unlockAccount",
},
"shh": []string{
"post",
"newIdentity",
"hasIdentity",
"newGroup",
"addToGroup",
"filter",
},
"txpool": []string{
"status",
},
"web3": []string{
"sha3",
"version",
"fromWei",
"toWei",
"toHex",
"toAscii",
"fromAscii",
"toBigNumber",
"isAddress",
},
}
)
// Parse a comma separated API string to individual api's
func ParseApiString(apistr string, codec codec.Codec, xeth *xeth.XEth, stack *node.Node) ([]shared.EthereumApi, error) {
if len(strings.TrimSpace(apistr)) == 0 {
return nil, fmt.Errorf("Empty apistr provided")
}
names := strings.Split(apistr, ",")
apis := make([]shared.EthereumApi, len(names))
var eth *eth.Ethereum
if stack != nil {
if err := stack.Service(&eth); err != nil {
return nil, err
}
}
for i, name := range names {
switch strings.ToLower(strings.TrimSpace(name)) {
case shared.AdminApiName:
apis[i] = NewAdminApi(xeth, stack, codec)
case shared.BzzApiName:
case shared.ChequebookApiName:
case shared.DebugApiName:
apis[i] = NewDebugApi(xeth, eth, codec)
case shared.DbApiName:
apis[i] = NewDbApi(xeth, eth, codec)
case shared.EthApiName:
apis[i] = NewEthApi(xeth, eth, codec)
case shared.MinerApiName:
apis[i] = NewMinerApi(eth, codec)
case shared.NetApiName:
apis[i] = NewNetApi(xeth, eth, codec)
case shared.ShhApiName:
apis[i] = NewShhApi(xeth, eth, codec)
case shared.TxPoolApiName:
apis[i] = NewTxPoolApi(xeth, eth, codec)
case shared.PersonalApiName:
apis[i] = NewPersonalApi(xeth, eth, codec)
case shared.Web3ApiName:
apis[i] = NewWeb3Api(xeth, codec)
case "rpc": // gives information about the RPC interface
continue
default:
return nil, fmt.Errorf("Unknown API '%s'", name)
}
}
return apis, nil
}
func Javascript(name string) string {
switch strings.ToLower(strings.TrimSpace(name)) {
case shared.AdminApiName:
return Admin_JS
case shared.BzzApiName:
return Bzz_JS
case shared.ChequebookApiName:
return Chequebook_JS
case shared.DebugApiName:
return Debug_JS
case shared.DbApiName:
return Db_JS
case shared.EthApiName:
return Eth_JS
case shared.MinerApiName:
return Miner_JS
case shared.NetApiName:
return Net_JS
case shared.ShhApiName:
return Shh_JS
case shared.TxPoolApiName:
return TxPool_JS
case shared.PersonalApiName:
return Personal_JS
}
return ""
}

View file

@ -19,14 +19,16 @@ package rpc
var ( var (
// Holds geth specific RPC extends which can be used to extend web3 // Holds geth specific RPC extends which can be used to extend web3
WEB3Extensions = map[string]string{ WEB3Extensions = map[string]string{
"personal": Personal_JS, "personal": Personal_JS,
"txpool": TxPool_JS, "txpool": TxPool_JS,
"admin": Admin_JS, "admin": Admin_JS,
"db": Db_JS, "db": Db_JS,
"eth": Eth_JS, "eth": Eth_JS,
"miner": Miner_JS, "miner": Miner_JS,
"debug": Debug_JS, "debug": Debug_JS,
"net": Net_JS, "net": Net_JS,
"bzz": Bzz_JS,
"chequebook": Chequebook_JS,
} }
) )
@ -483,3 +485,119 @@ web3._extend({
] ]
}); });
` `
const Bzz_JS = `
web3._extend({
property: 'bzz',
methods:
[
new web3._extend.Method({
name: 'deposit',
call: 'bzz_deposit',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'info',
call: 'bzz_info',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'cash',
call: 'bzz_cash',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'issue',
call: 'bzz_issue',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'register',
call: 'bzz_register',
params: 3,
inputFormatter: [null, null, null]
}),
new web3._extend.Method({
name: 'blockNetworkRead',
call: 'bzz_blockNetworkRead',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'resolve',
call: 'bzz_resolve',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'download',
call: 'bzz_download',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'upload',
call: 'bzz_upload',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'get',
call: 'bzz_get',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'put',
call: 'bzz_put',
params: 2,
inputFormatter: [null, null]
}),
new web3._extend.Method({
name: 'modify',
call: 'bzz_modify',
params: 4,
inputFormatter: [null, null, null, null]
})
],
properties:
[
]
});
`
const Chequebook_JS = `
web3._extend({
property: 'chequebook',
methods:
[
new web3._extend.Method({
name: 'deposit',
call: 'chequebook_deposit',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'info',
call: 'chequebook_info',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'cash',
call: 'chequebook_cash',
params: 1,
inputFormatter: [null]
}),
new web3._extend.Method({
name: 'issue',
call: 'chequebook_issue',
params: 2,
inputFormatter: [null, null]
}),
]
});
`

View file

@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/discover" "github.com/ethereum/go-ethereum/p2p/discover"
rpc "github.com/ethereum/go-ethereum/rpc/v2" "github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/swarm/api" "github.com/ethereum/go-ethereum/swarm/api"
httpapi "github.com/ethereum/go-ethereum/swarm/api/http" httpapi "github.com/ethereum/go-ethereum/swarm/api/http"
"github.com/ethereum/go-ethereum/swarm/network" "github.com/ethereum/go-ethereum/swarm/network"