wip, updates

This commit is contained in:
Martin Holst Swende 2018-08-15 11:06:48 +02:00
parent 0c8f2376fa
commit 1220efc349
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
13 changed files with 40 additions and 54 deletions

View file

@ -591,7 +591,7 @@ func testExternalUI(api *core.SignerAPI) {
checkErr("SignTransaction", err)
_, err = api.Sign(ctx, common.MixedcaseAddress{}, common.Hex2Bytes("01020304"))
checkErr("Sign", err)
_, err = api.List(ctx)
_, err = api.ListAccounts(ctx)
checkErr("List", err)
_, err = api.New(ctx)
checkErr("New", err)

View file

@ -152,9 +152,7 @@ func enableWhisper(ctx *cli.Context) bool {
func makeFullNode(ctx *cli.Context) *node.Node {
stack, cfg := makeConfigNode(ctx)
utils.RegisterEthService(stack, &cfg.Eth)
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit)
}

View file

@ -66,6 +66,7 @@ var (
utils.EthashDatasetDirFlag,
utils.EthashDatasetsInMemoryFlag,
utils.EthashDatasetsOnDiskFlag,
utils.ExternalSignerFlag,
utils.TxPoolNoLocalsFlag,
utils.TxPoolJournalFlag,
utils.TxPoolRejournalFlag,
@ -258,12 +259,8 @@ func geth(ctx *cli.Context) error {
func startNode(ctx *cli.Context, stack *node.Node) {
debug.Memsize.Add("node", stack)
// Start up the node itself
utils.StartNode(stack)
// Start account management
if ctx.IsSet(utils.ExternalSignerFlag.Name){
extEndpoint := ctx.GlobalString(utils.ExternalSignerFlag.Name)
if extEndpoint := ctx.GlobalString(utils.ExternalSignerFlag.Name); extEndpoint != ""{
extApi, err := ethapi.NewExternalSigner(extEndpoint)
if err != nil{
utils.Fatalf("Could not connect to external signer at %v: %v" , extEndpoint, err)
@ -271,6 +268,10 @@ func startNode(ctx *cli.Context, stack *node.Node) {
log.Info("External signer connected", "url", extEndpoint)
stack.SetExternalAPI(extApi)
}
// Start up the node itself
utils.StartNode(stack)
// Start auxiliary services if enabled
if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) {
// Mining only makes sense if a full Ethereum node is running

View file

@ -1121,7 +1121,7 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
})
} else {
err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
fullNode, err := eth.New(ctx, cfg)
fullNode, err := eth.New(ctx, cfg, stack.ExternalSignerAPI())
if fullNode != nil && cfg.LightServ > 0 {
ls, _ := les.NewLesServer(fullNode, cfg)
fullNode.AddLesServer(ls)

View file

@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/internal/ethapi"
)
// EthAPIBackend implements ethapi.Backend for full nodes
@ -226,7 +227,7 @@ func (b *EthAPIBackend) ServiceFilter(ctx context.Context, session *bloombits.Ma
go session.Multiplex(bloomRetrievalBatch, bloomRetrievalWait, b.eth.bloomRequests)
}
}
func (b *EthAPIBackend) ExternalSigner() string {
func (b *EthAPIBackend) ExternalSigner() *ethapi.ExternalSignerAPI {
return b.eth.externalSigner
}

View file

@ -76,7 +76,7 @@ type Ethereum struct {
eventMux *event.TypeMux
engine consensus.Engine
externalSigner string
externalSigner *ethapi.ExternalSignerAPI
bloomRequests chan chan *bloombits.Retrieval // Channel receiving bloom data retrieval requests
bloomIndexer *core.ChainIndexer // Bloom indexer operating during block imports
@ -100,7 +100,7 @@ func (s *Ethereum) AddLesServer(ls LesServer) {
// New creates a new Ethereum object (including the
// initialisation of the common Ethereum object)
func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
func New(ctx *node.ServiceContext, config *Config, api *ethapi.ExternalSignerAPI) (*Ethereum, error) {
if config.SyncMode == downloader.LightSync {
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
}
@ -119,6 +119,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
eth := &Ethereum{
config: config,
externalSigner: api,
chainDb: chainDb,
chainConfig: chainConfig,
eventMux: ctx.EventMux,
@ -331,7 +332,6 @@ func (s *Ethereum) StartMining(local bool) error {
log.Error("Etherbase account unavailable locally", "err", err)
return fmt.Errorf("signer not configured: %v", err)
}
if local {
// If local (CPU) mining is started, we can disable the transaction rejection
@ -357,7 +357,7 @@ func (s *Ethereum) IsListening() bool { return true } // Always
func (s *Ethereum) EthVersion() int { return int(s.protocolManager.SubProtocols[0].Version) }
func (s *Ethereum) NetVersion() uint64 { return s.networkID }
func (s *Ethereum) Downloader() *downloader.Downloader { return s.protocolManager.downloader }
func (s *Ethereum) ExternalSigner() string { return s.externalSigner }
func (s *Ethereum) ExternalSigner() *ethapi.ExternalSignerAPI { return s.externalSigner }
// Protocols implements node.Service, returning all the currently configured
// network protocols to start.

View file

@ -191,14 +191,7 @@ func NewPrivateAccountAPI(b Backend, nonceLock *AddrLocker) *PrivateAccountAPI {
p := &PrivateAccountAPI{
nonceLock: nonceLock,
b: b,
}
if b.ExternalSigner() != "" {
extapi, err := NewExternalSigner(b.ExternalSigner())
if err == nil {
p.extapi = extapi
} else {
log.Error("Error initializing external signer", "url", b.ExternalSigner(), "error", err)
}
extapi: b.ExternalSigner(),
}
return p
}
@ -818,18 +811,7 @@ type PublicTransactionPoolAPI struct {
// NewPublicTransactionPoolAPI creates a new RPC service with methods specific for the transaction pool.
func NewPublicTransactionPoolAPI(b Backend, nonceLock *AddrLocker) *PublicTransactionPoolAPI {
var (
extapi *ExternalSignerAPI
err error
)
if b.ExternalSigner() != "" {
extapi, err = NewExternalSigner(b.ExternalSigner())
if err != nil {
log.Error("Error initializing external signer", "url", b.ExternalSigner(), "error", err)
}
}
return &PublicTransactionPoolAPI{b, nonceLock, extapi}
return &PublicTransactionPoolAPI{b, nonceLock, b.ExternalSigner()}
}
// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.

View file

@ -42,7 +42,7 @@ type Backend interface {
SuggestPrice(ctx context.Context) (*big.Int, error)
ChainDb() ethdb.Database
EventMux() *event.TypeMux
ExternalSigner() string
ExternalSigner() *ExternalSignerAPI
// BlockChain API
SetHead(number uint64)

View file

@ -35,6 +35,7 @@ import (
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/internal/ethapi"
)
type LesApiBackend struct {
@ -182,7 +183,7 @@ func (b *LesApiBackend) EventMux() *event.TypeMux {
return b.eth.eventMux
}
func (b *LesApiBackend) ExternalSigner() string {
func (b *LesApiBackend) ExternalSigner() *ethapi.ExternalSignerAPI{
return b.eth.externalSigner
}

View file

@ -71,7 +71,7 @@ type LightEthereum struct {
eventMux *event.TypeMux
engine consensus.Engine
externalSigner string
externalSigner *ethapi.ExternalSignerAPI
networkId uint64
netRPCService *ethapi.PublicNetAPI

View file

@ -558,6 +558,9 @@ func (n *Node) SetExternalAPI(api *ethapi.ExternalSignerAPI){
n.extapi = api
}
func (n *Node) ExternalSignerAPI() *ethapi.ExternalSignerAPI{
return n.extapi
}
// apis returns the collection of RPC descriptors this node offers.
func (n *Node) apis() []rpc.API {
return []rpc.API{

View file

@ -109,17 +109,17 @@ func (ui *CommandlineUI) ApproveTx(request *SignTxRequest) (SignTxResponse, erro
fmt.Printf("\nWARNING: Invalid checksum on to-address!\n\n")
}
} else {
fmt.Printf("to: <contact creation>\n")
fmt.Printf("To: <contact creation>\n")
}
fmt.Printf("from: %v\n", request.Transaction.From.String())
fmt.Printf("value: %v wei\n", weival)
fmt.Printf("gas: %v\n", request.Transaction.Gas)
fmt.Printf("gasprice: %v wei\n", request.Transaction.GasPrice)
fmt.Printf("nonce: %v\n", request.Transaction.Nonce)
fmt.Printf("Trom: %v\n", request.Transaction.From.String())
fmt.Printf("Value: %v wei\n", weival)
fmt.Printf("Gas: %v\n", request.Transaction.Gas)
fmt.Printf("Gasprice: %v wei\n", request.Transaction.GasPrice.ToInt())
fmt.Printf("Nonce: %v\n", request.Transaction.Nonce)
if request.Transaction.Data != nil {
d := *request.Transaction.Data
if len(d) > 0 {
fmt.Printf("data: %v\n", common.Bytes2Hex(d))
fmt.Printf("Data: %v\n", common.Bytes2Hex(d))
}
}
if request.Callinfo != nil {

View file

@ -194,7 +194,7 @@ func (r *rulesetUI) ApproveImport(request *core.ImportRequest) (core.ImportRespo
return r.next.ApproveImport(request)
}
func (r *rulesetUI) ApproveListing(request *core.ListRequest) (core.ListAccountsResponse, error) {
func (r *rulesetUI) ApproveListing(request *core.ListAccountsRequest) (core.ListAccountsResponse, error) {
jsonreq, err := json.Marshal(request)
approved, err := r.checkApproval("ApproveListing", jsonreq, err)
if err != nil {