mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 13:21:37 +00:00
* rpc: implement full bi-directional communication #18471 * console: handle eth.coinbase throws #19374 * rpc: remove extra debug log message * rpc: add go:build lines #23468
This commit is contained in:
parent
fb300a43fb
commit
1f430bcbb1
5 changed files with 21 additions and 54 deletions
|
|
@ -290,14 +290,22 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
|
|||
// Welcome show summary of current Geth instance and some metadata about the
|
||||
// console's available modules.
|
||||
func (c *Console) Welcome() {
|
||||
message := "Welcome to the XDC JavaScript console!\n\n"
|
||||
|
||||
// Print some generic XDC metadata
|
||||
fmt.Fprintf(c.printer, "Welcome to the XDC JavaScript console!\n\n")
|
||||
c.jsre.Run(`
|
||||
console.log("instance: " + web3.version.node);
|
||||
console.log("coinbase: " + eth.coinbase);
|
||||
console.log("at block: " + eth.blockNumber + " (" + new Date(1000 * eth.getBlock(eth.blockNumber).timestamp) + ")");
|
||||
console.log(" datadir: " + admin.datadir);
|
||||
`)
|
||||
if res, err := c.jsre.Run(`
|
||||
var message = "instance: " + web3.version.node + "\n";
|
||||
try {
|
||||
message += "coinbase: " + eth.coinbase + "\n";
|
||||
} catch (err) {}
|
||||
message += "at block: " + eth.blockNumber + " (" + new Date(1000 * eth.getBlock(eth.blockNumber).timestamp) + ")\n";
|
||||
try {
|
||||
message += " datadir: " + admin.datadir + "\n";
|
||||
} catch (err) {}
|
||||
message
|
||||
`); err == nil {
|
||||
message += res.String()
|
||||
}
|
||||
// List all the supported modules for the user to call
|
||||
if apis, err := c.client.SupportedModules(); err == nil {
|
||||
modules := make([]string, 0, len(apis))
|
||||
|
|
@ -305,9 +313,9 @@ func (c *Console) Welcome() {
|
|||
modules = append(modules, fmt.Sprintf("%s:%s", api, version))
|
||||
}
|
||||
sort.Strings(modules)
|
||||
fmt.Fprintln(c.printer, " modules:", strings.Join(modules, " "))
|
||||
message += " modules: " + strings.Join(modules, " ") + "\n"
|
||||
}
|
||||
fmt.Fprintln(c.printer)
|
||||
fmt.Fprintln(c.printer, message)
|
||||
}
|
||||
|
||||
// Evaluate executes code and pretty prints the result to the specified output
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, er
|
|||
log.Info("IPC registration failed", "namespace", api.Namespace, "error", err)
|
||||
return nil, nil, err
|
||||
}
|
||||
log.Debug("IPC registered", "namespace", api.Namespace)
|
||||
if _, ok := regMap[api.Namespace]; !ok {
|
||||
registered = append(registered, api.Namespace)
|
||||
regMap[api.Namespace] = struct{}{}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
// 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/>.
|
||||
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package rpc
|
||||
|
|
|
|||
|
|
@ -25,7 +25,9 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
func TestNewID2(t *testing.T) {
|
||||
func TestNewID(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
hexchars := "0123456789ABCDEFabcdef"
|
||||
for i := 0; i < 100; i++ {
|
||||
id := string(NewID())
|
||||
|
|
|
|||
|
|
@ -1,43 +0,0 @@
|
|||
// Copyright 2016 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 rpc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewID(t *testing.T) {
|
||||
hexchars := "0123456789ABCDEFabcdef"
|
||||
for i := 0; i < 100; i++ {
|
||||
id := string(NewID())
|
||||
if !strings.HasPrefix(id, "0x") {
|
||||
t.Fatalf("invalid ID prefix, want '0x...', got %s", id)
|
||||
}
|
||||
|
||||
id = id[2:]
|
||||
if len(id) == 0 || len(id) > 32 {
|
||||
t.Fatalf("invalid ID length, want len(id) > 0 && len(id) <= 32), got %d", len(id))
|
||||
}
|
||||
|
||||
for i := 0; i < len(id); i++ {
|
||||
if strings.IndexByte(hexchars, id[i]) == -1 {
|
||||
t.Fatalf("unexpected byte, want any valid hex char, got %c", id[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue