rebase: minor fixes to integrate with Geth 1.6.1
This commit is contained in:
parent
a0fef0a0b6
commit
ecea845d88
|
@ -199,7 +199,7 @@ func DiscardTransactions(ids *C.char) *C.char {
|
|||
|
||||
//export GenerateConfig
|
||||
func GenerateConfig(datadir *C.char, networkId C.int) *C.char {
|
||||
config, err := params.NewNodeConfig(C.GoString(datadir), int(networkId))
|
||||
config, err := params.NewNodeConfig(C.GoString(datadir), uint64(networkId))
|
||||
if err != nil {
|
||||
return makeJSONErrorResponse(err)
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ var (
|
|||
}
|
||||
LogLevelFlag = cli.StringFlag{
|
||||
Name: "log",
|
||||
Usage: `Log level, one of: ""ERROR", "WARNING", "INFO", "DEBUG", and "DETAIL"`,
|
||||
Usage: `Log level, one of: ""ERROR", "WARNING", "INFO", "DEBUG", and "TRACE"`,
|
||||
Value: "INFO",
|
||||
}
|
||||
)
|
||||
|
@ -121,7 +121,7 @@ func statusd(ctx *cli.Context) error {
|
|||
|
||||
// makeNodeConfig parses incoming CLI options and returns node configuration object
|
||||
func makeNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
||||
nodeConfig, err := params.NewNodeConfig(ctx.GlobalString(DataDirFlag.Name), ctx.GlobalInt(NetworkIdFlag.Name))
|
||||
nodeConfig, err := params.NewNodeConfig(ctx.GlobalString(DataDirFlag.Name), ctx.GlobalUint64(NetworkIdFlag.Name))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/les/status"
|
||||
gethparams "github.com/ethereum/go-ethereum/params"
|
||||
"github.com/status-im/status-go/geth"
|
||||
|
@ -111,7 +112,12 @@ func testGetDefaultConfig(t *testing.T) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
chainConfig := nodeConfig.ChainConfig
|
||||
genesis := new(core.Genesis)
|
||||
if err := json.Unmarshal([]byte(nodeConfig.LightEthConfig.Genesis), genesis); err != nil {
|
||||
t.Error(err)
|
||||
return false
|
||||
}
|
||||
chainConfig := genesis.Config
|
||||
if chainConfig.HomesteadBlock.Cmp(gethparams.MainNetHomesteadBlock) != 0 {
|
||||
t.Error("invalid chainConfig.HomesteadBlock")
|
||||
return false
|
||||
|
@ -153,7 +159,12 @@ func testGetDefaultConfig(t *testing.T) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
chainConfig = nodeConfig.ChainConfig
|
||||
genesis = new(core.Genesis)
|
||||
if err := json.Unmarshal([]byte(nodeConfig.LightEthConfig.Genesis), genesis); err != nil {
|
||||
t.Error(err)
|
||||
return false
|
||||
}
|
||||
chainConfig = genesis.Config
|
||||
refChainConfig := gethparams.TestnetChainConfig
|
||||
|
||||
if chainConfig.HomesteadBlock.Cmp(refChainConfig.HomesteadBlock) != 0 {
|
||||
|
@ -229,7 +240,7 @@ func testStopResumeNode(t *testing.T) bool {
|
|||
t.Logf("account created: {address: %s, key: %s}", address1, pubKey1)
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -246,7 +257,7 @@ func testStopResumeNode(t *testing.T) bool {
|
|||
t.Errorf("could not select account: %v", err)
|
||||
return false
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey1) {
|
||||
if !whisperService.HasKeyPair(pubKey1) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
|
||||
|
@ -295,7 +306,7 @@ func testStopResumeNode(t *testing.T) bool {
|
|||
if err != nil {
|
||||
t.Errorf("whisper service not running: %v", err)
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey1) {
|
||||
if !whisperService.HasKeyPair(pubKey1) {
|
||||
t.Errorf("identity evicted from whisper on node restart: %v", err)
|
||||
}
|
||||
|
||||
|
@ -580,7 +591,7 @@ func testRecoverAccount(t *testing.T) bool {
|
|||
}
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKeyCheck) {
|
||||
if whisperService.HasKeyPair(pubKeyCheck) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
err = geth.SelectAccount(addressCheck, testConfig.Account1.Password)
|
||||
|
@ -588,7 +599,7 @@ func testRecoverAccount(t *testing.T) bool {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return false
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKeyCheck) {
|
||||
if !whisperService.HasKeyPair(pubKeyCheck) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
|
||||
|
@ -618,7 +629,7 @@ func testAccountSelect(t *testing.T) bool {
|
|||
t.Logf("Account created: {address: %s, key: %s}", address2, pubKey2)
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -648,12 +659,12 @@ func testAccountSelect(t *testing.T) bool {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return false
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey1) {
|
||||
if !whisperService.HasKeyPair(pubKey1) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
|
||||
// select another account, make sure that previous account is wiped out from Whisper cache
|
||||
if whisperService.HasIdentity(pubKey2) {
|
||||
if whisperService.HasKeyPair(pubKey2) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -669,10 +680,10 @@ func testAccountSelect(t *testing.T) bool {
|
|||
t.Errorf("Test failed: could not select account: %v", loginResponse.Error)
|
||||
return false
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey2) {
|
||||
if !whisperService.HasKeyPair(pubKey2) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity should be removed, but it is still present in whisper")
|
||||
}
|
||||
|
||||
|
@ -694,7 +705,7 @@ func testAccountLogout(t *testing.T) bool {
|
|||
}
|
||||
|
||||
// make sure that identity doesn't exist (yet) in Whisper
|
||||
if whisperService.HasIdentity(pubKey) {
|
||||
if whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity already present in whisper")
|
||||
return false
|
||||
}
|
||||
|
@ -705,7 +716,7 @@ func testAccountLogout(t *testing.T) bool {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return false
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey) {
|
||||
if !whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity not injected into whisper")
|
||||
return false
|
||||
}
|
||||
|
@ -724,7 +735,7 @@ func testAccountLogout(t *testing.T) bool {
|
|||
}
|
||||
|
||||
// now, logout and check if identity is removed indeed
|
||||
if whisperService.HasIdentity(pubKey) {
|
||||
if whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity not cleared from whisper")
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -50,6 +50,10 @@ var (
|
|||
Usage: "Time to live for messages, in seconds",
|
||||
Value: params.WhisperTTL,
|
||||
}
|
||||
WhisperInjectTestAccounts = cli.BoolTFlag{
|
||||
Name: "injectaccounts",
|
||||
Usage: "Whether test account should be injected or not (default: true)",
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -67,6 +71,7 @@ var (
|
|||
WhisperPoWFlag,
|
||||
WhisperPortFlag,
|
||||
WhisperTTLFlag,
|
||||
WhisperInjectTestAccounts,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
@ -80,20 +85,30 @@ func wnode(ctx *cli.Context) error {
|
|||
|
||||
wnodePrintHeader(config)
|
||||
|
||||
// inject test accounts
|
||||
geth.ImportTestAccount(filepath.Join(config.DataDir, "keystore"), "test-account1.pk")
|
||||
geth.ImportTestAccount(filepath.Join(config.DataDir, "keystore"), "test-account2.pk")
|
||||
// import test accounts
|
||||
if ctx.BoolT(WhisperInjectTestAccounts.Name) {
|
||||
geth.ImportTestAccount(filepath.Join(config.DataDir, "keystore"), "test-account1.pk")
|
||||
geth.ImportTestAccount(filepath.Join(config.DataDir, "keystore"), "test-account2.pk")
|
||||
}
|
||||
|
||||
if err := geth.CreateAndRunNode(config); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// inject test accounts into Whisper
|
||||
if ctx.BoolT(WhisperInjectTestAccounts.Name) {
|
||||
testConfig, _ := geth.LoadTestConfig()
|
||||
injectAccountIntoWhisper(testConfig.Account1.Address, testConfig.Account1.Password)
|
||||
injectAccountIntoWhisper(testConfig.Account2.Address, testConfig.Account2.Password)
|
||||
}
|
||||
|
||||
// wait till node has been stopped
|
||||
geth.NodeManagerInstance().Node().GethStack().Wait()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// wnodePrintHeader prints command header
|
||||
func wnodePrintHeader(nodeConfig *params.NodeConfig) {
|
||||
fmt.Println("Starting Whisper/5 node..")
|
||||
|
||||
|
@ -136,3 +151,31 @@ func makeWhisperNodeConfig(ctx *cli.Context) (*params.NodeConfig, error) {
|
|||
|
||||
return nodeConfig, nil
|
||||
}
|
||||
|
||||
// injectAccountIntoWhisper adds key pair into Whisper. Similar to Select/Login,
|
||||
// but allows multiple accounts to be injected.
|
||||
func injectAccountIntoWhisper(address, password string) error {
|
||||
nodeManager := geth.NodeManagerInstance()
|
||||
keyStore, err := nodeManager.AccountKeyStore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
account, err := geth.ParseAccountString(address)
|
||||
if err != nil {
|
||||
return geth.ErrAddressToAccountMappingFailure
|
||||
}
|
||||
|
||||
account, accountKey, err := keyStore.AccountDecryptedKey(account, password)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", geth.ErrAccountToKeyMappingFailure.Error(), err)
|
||||
}
|
||||
|
||||
whisperService, err := nodeManager.WhisperService()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
whisperService.AddKeyPair(accountKey.PrivateKey)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -149,7 +149,7 @@ func SelectAccount(address, password string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := whisperService.InjectIdentity(accountKey.PrivateKey); err != nil {
|
||||
if err := whisperService.SelectKeyPair(accountKey.PrivateKey); err != nil {
|
||||
return ErrWhisperIdentityInjectionFailure
|
||||
}
|
||||
|
||||
|
@ -181,7 +181,7 @@ func ReSelectAccount() error {
|
|||
return err
|
||||
}
|
||||
|
||||
if err := whisperService.InjectIdentity(selectedAccount.AccountKey.PrivateKey); err != nil {
|
||||
if err := whisperService.SelectKeyPair(selectedAccount.AccountKey.PrivateKey); err != nil {
|
||||
return ErrWhisperIdentityInjectionFailure
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ func Logout() error {
|
|||
return err
|
||||
}
|
||||
|
||||
err = whisperService.ClearIdentities()
|
||||
err = whisperService.DeleteKeyPairs()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %v", ErrWhisperClearIdentitiesFailure, err)
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ func TestAccountsRecoverAccount(t *testing.T) {
|
|||
}
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKeyCheck) {
|
||||
if whisperService.HasKeyPair(pubKeyCheck) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
err = geth.SelectAccount(addressCheck, testConfig.Account1.Password)
|
||||
|
@ -295,7 +295,7 @@ func TestAccountsRecoverAccount(t *testing.T) {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKeyCheck) {
|
||||
if !whisperService.HasKeyPair(pubKeyCheck) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ func TestAccountSelect(t *testing.T) {
|
|||
t.Logf("Account created: {address: %s, key: %s}", address2, pubKey2)
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -345,12 +345,12 @@ func TestAccountSelect(t *testing.T) {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey1) {
|
||||
if !whisperService.HasKeyPair(pubKey1) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
|
||||
// select another account, make sure that previous account is wiped out from Whisper cache
|
||||
if whisperService.HasIdentity(pubKey2) {
|
||||
if whisperService.HasKeyPair(pubKey2) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
err = geth.SelectAccount(address2, testConfig.Account1.Password)
|
||||
|
@ -358,10 +358,10 @@ func TestAccountSelect(t *testing.T) {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey2) {
|
||||
if !whisperService.HasKeyPair(pubKey2) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity should be removed, but it is still present in whisper")
|
||||
}
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ func TestAccountsLogout(t *testing.T) {
|
|||
}
|
||||
|
||||
// make sure that identity doesn't exist (yet) in Whisper
|
||||
if whisperService.HasIdentity(pubKey) {
|
||||
if whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -397,7 +397,7 @@ func TestAccountsLogout(t *testing.T) {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey) {
|
||||
if !whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity not injected into whisper")
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ func TestAccountsLogout(t *testing.T) {
|
|||
}
|
||||
|
||||
// now, logout and check if identity is removed indeed
|
||||
if whisperService.HasIdentity(pubKey) {
|
||||
if whisperService.HasKeyPair(pubKey) {
|
||||
t.Error("identity not cleared from whisper")
|
||||
}
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ func TestAccountsSelectedAccountOnNodeRestart(t *testing.T) {
|
|||
t.Logf("account2 created: {address: %s, key: %s}", address2, pubKey2)
|
||||
|
||||
// make sure that identity is not (yet injected)
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -461,12 +461,12 @@ func TestAccountsSelectedAccountOnNodeRestart(t *testing.T) {
|
|||
t.Errorf("could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey1) {
|
||||
if !whisperService.HasKeyPair(pubKey1) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
|
||||
// select another account, make sure that previous account is wiped out from Whisper cache
|
||||
if whisperService.HasIdentity(pubKey2) {
|
||||
if whisperService.HasKeyPair(pubKey2) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
err = geth.SelectAccount(address2, testConfig.Account1.Password)
|
||||
|
@ -474,10 +474,10 @@ func TestAccountsSelectedAccountOnNodeRestart(t *testing.T) {
|
|||
t.Errorf("Test failed: could not select account: %v", err)
|
||||
return
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey2) {
|
||||
if !whisperService.HasKeyPair(pubKey2) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity should be removed, but it is still present in whisper")
|
||||
}
|
||||
|
||||
|
@ -518,10 +518,10 @@ func TestAccountsSelectedAccountOnNodeRestart(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("whisper service not running: %v", err)
|
||||
}
|
||||
if !whisperService.HasIdentity(pubKey2) {
|
||||
if !whisperService.HasKeyPair(pubKey2) {
|
||||
t.Errorf("identity not injected into whisper: %v", err)
|
||||
}
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity should not be present, but it is still present in whisper")
|
||||
}
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ func TestAccountsNodeRestartWithNoSelectedAccount(t *testing.T) {
|
|||
t.Logf("account1 created: {address: %s, key: %s}", address1, pubKey1)
|
||||
|
||||
// make sure that identity is not present
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity already present in whisper")
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ func TestAccountsNodeRestartWithNoSelectedAccount(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Errorf("whisper service not running: %v", err)
|
||||
}
|
||||
if whisperService.HasIdentity(pubKey1) {
|
||||
if whisperService.HasKeyPair(pubKey1) {
|
||||
t.Error("identity should not be present, but it is present in whisper")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/eapache/go-resiliency/semaphore"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/robertkrimen/otto"
|
||||
"github.com/status-im/status-go/geth"
|
||||
|
@ -323,7 +322,7 @@ func newResultResponse(call otto.FunctionCall, result interface{}) otto.Value {
|
|||
func throwJSException(msg interface{}) otto.Value {
|
||||
val, err := otto.ToValue(msg)
|
||||
if err != nil {
|
||||
glog.V(logger.Error).Infof("Failed to serialize JavaScript exception %v: %v", msg, err)
|
||||
log.Error(fmt.Sprintf("Failed to serialize JavaScript exception %v: %v", msg, err))
|
||||
}
|
||||
panic(val)
|
||||
}
|
||||
|
|
|
@ -783,8 +783,8 @@ func TestJailWhisper(t *testing.T) {
|
|||
}
|
||||
accountKey1Hex := common.ToHex(crypto.FromECDSAPub(&accountKey1.PrivateKey.PublicKey))
|
||||
|
||||
whisperService.AddIdentity(accountKey1.PrivateKey)
|
||||
if ok, err := whisperAPI.HasIdentity(accountKey1Hex); err != nil || !ok {
|
||||
whisperService.AddKeyPair(accountKey1.PrivateKey)
|
||||
if ok, err := whisperAPI.HasKeyPair(accountKey1Hex); err != nil || !ok {
|
||||
t.Fatalf("identity not injected: %v", accountKey1Hex)
|
||||
}
|
||||
|
||||
|
@ -795,8 +795,8 @@ func TestJailWhisper(t *testing.T) {
|
|||
}
|
||||
accountKey2Hex := common.ToHex(crypto.FromECDSAPub(&accountKey2.PrivateKey.PublicKey))
|
||||
|
||||
whisperService.AddIdentity(accountKey2.PrivateKey)
|
||||
if ok, err := whisperAPI.HasIdentity(accountKey2Hex); err != nil || !ok {
|
||||
whisperService.AddKeyPair(accountKey2.PrivateKey)
|
||||
if ok, err := whisperAPI.HasKeyPair(accountKey2Hex); err != nil || !ok {
|
||||
t.Fatalf("identity not injected: %v", accountKey2Hex)
|
||||
}
|
||||
|
||||
|
@ -838,32 +838,35 @@ func TestJailWhisper(t *testing.T) {
|
|||
"test 1: encrypted signed message from us (From != nil && To != nil)",
|
||||
`
|
||||
var identity1 = '` + accountKey1Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity1)) {
|
||||
if (!web3.shh.hasKeyPair(identity1)) {
|
||||
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var identity2 = '` + accountKey2Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity2)) {
|
||||
if (!web3.shh.hasKeyPair(identity2)) {
|
||||
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var topic = 'example1';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage1 + `';
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
from: identity1,
|
||||
to: identity2,
|
||||
topics: [web3.fromAscii(topic)]
|
||||
type: "asym",
|
||||
sig: identity1,
|
||||
key: identity2,
|
||||
topics: [topic]
|
||||
});
|
||||
console.log(JSON.stringify(filter));
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
from: identity1,
|
||||
to: identity2,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
type: "asym",
|
||||
sig: identity1,
|
||||
key: identity2,
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
};
|
||||
var err = shh.post(message)
|
||||
if (err !== null) {
|
||||
|
@ -882,27 +885,29 @@ func TestJailWhisper(t *testing.T) {
|
|||
"test 2: encrypted signed message to yourself (From != nil && To != nil)",
|
||||
`
|
||||
var identity = '` + accountKey1Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity)) {
|
||||
if (!web3.shh.hasKeyPair(identity)) {
|
||||
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var topic = 'example2';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage2 + `';
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
from: identity,
|
||||
to: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
type: "asym",
|
||||
sig: identity,
|
||||
key: identity,
|
||||
topics: [topic],
|
||||
});
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
from: identity,
|
||||
to: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
type: "asym",
|
||||
sig: identity,
|
||||
key: identity,
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
};
|
||||
var err = shh.post(message)
|
||||
if (err !== null) {
|
||||
|
@ -921,33 +926,35 @@ func TestJailWhisper(t *testing.T) {
|
|||
"test 3: signed (known sender) broadcast (From != nil && To == nil)",
|
||||
`
|
||||
var identity = '` + accountKey1Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity)) {
|
||||
if (!web3.shh.hasKeyPair(identity)) {
|
||||
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var topic = 'example3';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage3 + `';
|
||||
|
||||
// generate symmetric key (if doesn't already exist)
|
||||
if (!shh.hasSymKey(topic)) {
|
||||
shh.addSymKey(topic, "0xdeadbeef"); // alternatively: shh.generateSymKey("example3");
|
||||
// to delete key, rely on: shh.deleteSymKey(topic);
|
||||
// generate symmetric key
|
||||
var keyid = shh.generateSymmetricKey();
|
||||
if (!shh.hasSymmetricKey(keyid)) {
|
||||
throw new Error('key not found');
|
||||
}
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
from: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
keyname: topic // you can use some other name for key too
|
||||
type: "sym",
|
||||
sig: identity,
|
||||
topics: [topic],
|
||||
key: keyid
|
||||
});
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
from: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
type: "sym",
|
||||
sig: identity,
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
keyname: topic
|
||||
key: keyid
|
||||
};
|
||||
var err = shh.post(message)
|
||||
if (err !== null) {
|
||||
|
@ -965,27 +972,29 @@ func TestJailWhisper(t *testing.T) {
|
|||
{
|
||||
"test 4: anonymous broadcast (From == nil && To == nil)",
|
||||
`
|
||||
var topic = 'example4';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage4 + `';
|
||||
|
||||
// generate symmetric key (if doesn't already exist)
|
||||
if (!shh.hasSymKey(topic)) {
|
||||
shh.addSymKey(topic, "0xdeadbeef"); // alternatively: shh.generateSymKey("example3");
|
||||
// to delete key, rely on: shh.deleteSymKey(topic);
|
||||
// generate symmetric key
|
||||
var keyid = shh.generateSymmetricKey();
|
||||
if (!shh.hasSymmetricKey(keyid)) {
|
||||
throw new Error('key not found');
|
||||
}
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
topics: [web3.fromAscii(topic)],
|
||||
keyname: topic // you can use some other name for key too
|
||||
type: "sym",
|
||||
topics: [topic],
|
||||
key: keyid
|
||||
});
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
topics: [web3.fromAscii(topic)],
|
||||
type: "sym",
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20,
|
||||
keyname: topic
|
||||
key: keyid
|
||||
};
|
||||
var err = shh.post(message)
|
||||
if (err !== null) {
|
||||
|
@ -1004,23 +1013,25 @@ func TestJailWhisper(t *testing.T) {
|
|||
"test 5: encrypted anonymous message (From == nil && To != nil)",
|
||||
`
|
||||
var identity = '` + accountKey2Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity)) {
|
||||
if (!web3.shh.hasKeyPair(identity)) {
|
||||
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var topic = 'example5';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage5 + `';
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
to: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
type: "asym",
|
||||
key: identity,
|
||||
topics: [topic],
|
||||
});
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
to: identity,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
type: "asym",
|
||||
key: identity,
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20
|
||||
};
|
||||
|
@ -1041,32 +1052,34 @@ func TestJailWhisper(t *testing.T) {
|
|||
"test 6: encrypted signed response to us (From != nil && To != nil)",
|
||||
`
|
||||
var identity1 = '` + accountKey1Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity1)) {
|
||||
if (!web3.shh.hasKeyPair(identity1)) {
|
||||
throw 'idenitity "` + accountKey1Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var identity2 = '` + accountKey2Hex + `';
|
||||
if (!web3.shh.hasIdentity(identity2)) {
|
||||
if (!web3.shh.hasKeyPair(identity2)) {
|
||||
throw 'idenitity "` + accountKey2Hex + `" not found in whisper';
|
||||
}
|
||||
|
||||
var topic = 'example6';
|
||||
var topic = makeTopic();
|
||||
var payload = '` + whisperMessage6 + `';
|
||||
|
||||
// start watching for messages
|
||||
var filter = shh.filter({
|
||||
from: identity2,
|
||||
to: identity1,
|
||||
topics: [web3.fromAscii(topic)]
|
||||
type: "asym",
|
||||
sig: identity2,
|
||||
key: identity1,
|
||||
topics: [topic]
|
||||
});
|
||||
|
||||
// post message
|
||||
var message = {
|
||||
from: identity2,
|
||||
to: identity1,
|
||||
topics: [web3.fromAscii(topic)],
|
||||
payload: payload,
|
||||
ttl: 20
|
||||
type: "asym",
|
||||
sig: identity2,
|
||||
key: identity1,
|
||||
topic: topic,
|
||||
payload: payload,
|
||||
ttl: 20
|
||||
};
|
||||
var err = shh.post(message)
|
||||
if (err !== null) {
|
||||
|
@ -1086,7 +1099,15 @@ func TestJailWhisper(t *testing.T) {
|
|||
for _, testCase := range testCases {
|
||||
t.Log(testCase.name)
|
||||
testCaseKey := crypto.Keccak256Hash([]byte(testCase.name)).Hex()
|
||||
jailInstance.Parse(testCaseKey, `var shh = web3.shh;`)
|
||||
jailInstance.Parse(testCaseKey, `
|
||||
var shh = web3.shh;
|
||||
var makeTopic = function () {
|
||||
var min = 1;
|
||||
var max = Math.pow(16, 8);
|
||||
var randInt = Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
return web3.toHex(randInt);
|
||||
};
|
||||
`)
|
||||
vm, err := jailInstance.GetVM(testCaseKey)
|
||||
if err != nil {
|
||||
t.Errorf("cannot get VM: %v", err)
|
||||
|
@ -1127,7 +1148,7 @@ func TestJailWhisper(t *testing.T) {
|
|||
for testKey, filter := range installedFilters {
|
||||
if filter != "" {
|
||||
t.Logf("filter found: %v", filter)
|
||||
for _, message := range whisperAPI.GetFilterChanges(filter) {
|
||||
for _, message := range whisperAPI.GetSubscriptionMessages(filter) {
|
||||
t.Logf("message found: %s", common.FromHex(message.Payload))
|
||||
passedTests[testKey] = true
|
||||
}
|
||||
|
|
124
geth/node.go
124
geth/node.go
|
@ -1,6 +1,7 @@
|
|||
package geth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
@ -8,21 +9,21 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||
"github.com/ethereum/go-ethereum/les"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
"github.com/ethereum/go-ethereum/p2p/nat"
|
||||
gethparams "github.com/ethereum/go-ethereum/params"
|
||||
whisper "github.com/ethereum/go-ethereum/whisper/whisperv5"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
)
|
||||
|
@ -69,8 +70,6 @@ func MakeNode(config *params.NodeConfig) *Node {
|
|||
}
|
||||
|
||||
// setup logging
|
||||
glog.CopyStandardLogTo("INFO")
|
||||
glog.SetToStderr(true)
|
||||
if _, err := params.SetupLogger(config); err != nil {
|
||||
Fatalf(err)
|
||||
}
|
||||
|
@ -82,24 +81,37 @@ func MakeNode(config *params.NodeConfig) *Node {
|
|||
UseLightweightKDF: true,
|
||||
Name: config.Name,
|
||||
Version: config.Version,
|
||||
NoDiscovery: true,
|
||||
DiscoveryV5: false,
|
||||
DiscoveryV5Addr: ":0",
|
||||
BootstrapNodes: makeBootstrapNodes(),
|
||||
BootstrapNodesV5: makeBootstrapNodesV5(),
|
||||
ListenAddr: ":0",
|
||||
NAT: nat.Any(),
|
||||
MaxPeers: config.MaxPeers,
|
||||
MaxPendingPeers: config.MaxPendingPeers,
|
||||
IPCPath: makeIPCPath(config),
|
||||
HTTPHost: config.HTTPHost,
|
||||
HTTPPort: config.HTTPPort,
|
||||
HTTPCors: "*",
|
||||
HTTPModules: strings.Split(config.APIModules, ","),
|
||||
WSHost: makeWSHost(config),
|
||||
WSPort: config.WSPort,
|
||||
WSOrigins: "*",
|
||||
WSModules: strings.Split(config.APIModules, ","),
|
||||
P2P: p2p.Config{
|
||||
NoDiscovery: true,
|
||||
DiscoveryV5: false,
|
||||
DiscoveryV5Addr: ":0",
|
||||
BootstrapNodes: makeBootstrapNodes(),
|
||||
BootstrapNodesV5: makeBootstrapNodesV5(),
|
||||
ListenAddr: ":0",
|
||||
NAT: nat.Any(),
|
||||
MaxPeers: config.MaxPeers,
|
||||
MaxPendingPeers: config.MaxPendingPeers,
|
||||
},
|
||||
IPCPath: makeIPCPath(config),
|
||||
HTTPHost: config.HTTPHost,
|
||||
HTTPPort: config.HTTPPort,
|
||||
HTTPCors: []string{"*"},
|
||||
HTTPModules: strings.Split(config.APIModules, ","),
|
||||
WSHost: makeWSHost(config),
|
||||
WSPort: config.WSPort,
|
||||
WSOrigins: []string{"*"},
|
||||
WSModules: strings.Split(config.APIModules, ","),
|
||||
}
|
||||
|
||||
if len(config.NodeKeyFile) > 0 {
|
||||
log.Info("Loading private key file", "file", config.NodeKeyFile)
|
||||
pk, err := crypto.LoadECDSA(config.NodeKeyFile)
|
||||
if err != nil {
|
||||
log.Warn(fmt.Sprintf("Failed loading private key file '%s': %v", config.NodeKeyFile, err))
|
||||
}
|
||||
|
||||
// override node's private key
|
||||
stackConfig.P2P.PrivateKey = pk
|
||||
}
|
||||
|
||||
stack, err := node.New(stackConfig)
|
||||
|
@ -128,34 +140,27 @@ func MakeNode(config *params.NodeConfig) *Node {
|
|||
// activateEthService configures and registers the eth.Ethereum service with a given node.
|
||||
func activateEthService(stack *node.Node, config *params.NodeConfig) error {
|
||||
if !config.LightEthConfig.Enabled {
|
||||
glog.V(logger.Info).Infoln("LES protocol is disabled")
|
||||
log.Info("LES protocol is disabled")
|
||||
return nil
|
||||
}
|
||||
|
||||
ethConf := ð.Config{
|
||||
Etherbase: common.Address{},
|
||||
ChainConfig: makeChainConfig(config),
|
||||
FastSync: false,
|
||||
LightMode: true,
|
||||
MaxPeers: config.MaxPeers,
|
||||
DatabaseCache: config.LightEthConfig.DatabaseCache,
|
||||
DatabaseHandles: makeDatabaseHandles(),
|
||||
NetworkId: config.NetworkId,
|
||||
Genesis: config.LightEthConfig.Genesis,
|
||||
MinerThreads: runtime.NumCPU(),
|
||||
GasPrice: params.GasPrice,
|
||||
GpoMinGasPrice: params.GpoMinGasPrice,
|
||||
GpoMaxGasPrice: params.GpoMaxGasPrice,
|
||||
GpoFullBlockRatio: params.GpoFullBlockRatio,
|
||||
GpobaseStepDown: params.GpobaseStepDown,
|
||||
GpobaseStepUp: params.GpobaseStepUp,
|
||||
GpobaseCorrectionFactor: params.GpobaseCorrectionFactor,
|
||||
SolcPath: "solc",
|
||||
AutoDAG: false,
|
||||
var genesis *core.Genesis
|
||||
if config.LightEthConfig.Genesis != "" {
|
||||
genesis = new(core.Genesis)
|
||||
if err := json.Unmarshal([]byte(config.LightEthConfig.Genesis), genesis); err != nil {
|
||||
return fmt.Errorf("invalid genesis spec: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
ethConf := eth.DefaultConfig
|
||||
ethConf.Genesis = genesis
|
||||
ethConf.SyncMode = downloader.LightSync
|
||||
ethConf.NetworkId = config.NetworkId
|
||||
ethConf.DatabaseCache = config.LightEthConfig.DatabaseCache
|
||||
ethConf.MaxPeers = config.MaxPeers
|
||||
ethConf.DatabaseHandles = makeDatabaseHandles()
|
||||
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||
return les.New(ctx, ethConf)
|
||||
return les.New(ctx, ðConf)
|
||||
}); err != nil {
|
||||
return fmt.Errorf("%v: %v", ErrLightEthRegistrationFailure, err)
|
||||
}
|
||||
|
@ -166,7 +171,7 @@ func activateEthService(stack *node.Node, config *params.NodeConfig) error {
|
|||
// activateShhService configures Whisper and adds it to the given node.
|
||||
func activateShhService(stack *node.Node, config *params.NodeConfig) error {
|
||||
if !config.WhisperConfig.Enabled {
|
||||
glog.V(logger.Info).Infoln("SHH protocol is disabled")
|
||||
log.Info("SHH protocol is disabled")
|
||||
return nil
|
||||
}
|
||||
serviceConstructor := func(*node.ServiceContext) (node.Service, error) {
|
||||
|
@ -197,29 +202,6 @@ func makeWSHost(config *params.NodeConfig) string {
|
|||
return config.WSHost
|
||||
}
|
||||
|
||||
// makeChainConfig reads the chain configuration from the database in the datadir.
|
||||
func makeChainConfig(config *params.NodeConfig) *gethparams.ChainConfig {
|
||||
chainConfig := new(gethparams.ChainConfig)
|
||||
|
||||
// Homestead fork
|
||||
chainConfig.HomesteadBlock = config.HomesteadBlock
|
||||
|
||||
// DAO fork
|
||||
chainConfig.DAOForkBlock = config.DAOForkBlock
|
||||
chainConfig.DAOForkSupport = config.DAOForkSupport
|
||||
|
||||
// DoS reprice fork
|
||||
chainConfig.EIP150Block = config.EIP150Block
|
||||
chainConfig.EIP150Hash = config.EIP150Hash
|
||||
|
||||
// DoS state cleanup fork
|
||||
chainConfig.EIP155Block = config.EIP155Block
|
||||
chainConfig.EIP158Block = config.EIP158Block
|
||||
chainConfig.ChainId = config.ChainId
|
||||
|
||||
return chainConfig
|
||||
}
|
||||
|
||||
// makeDatabaseHandles makes sure that enough file descriptors are available to the process
|
||||
// (and returns half of them for node's database to use)
|
||||
func makeDatabaseHandles() int {
|
||||
|
|
|
@ -13,8 +13,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/les"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/node"
|
||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
|
@ -105,13 +104,13 @@ func (m *NodeManager) RunNode() {
|
|||
m.StartNode()
|
||||
|
||||
if _, err := m.AccountManager(); err != nil {
|
||||
glog.V(logger.Warn).Infoln(ErrInvalidAccountManager)
|
||||
log.Warn(ErrInvalidAccountManager.Error())
|
||||
}
|
||||
if err := m.node.geth.Service(&m.services.whisperService); err != nil {
|
||||
glog.V(logger.Warn).Infoln("cannot get whisper service:", err)
|
||||
log.Warn("cannot get whisper service", "error", err)
|
||||
}
|
||||
if err := m.node.geth.Service(&m.services.lightEthereum); err != nil {
|
||||
glog.V(logger.Warn).Infoln("cannot get light ethereum service:", err)
|
||||
log.Warn("cannot get light ethereum service", "error", err)
|
||||
}
|
||||
|
||||
// setup handlers
|
||||
|
@ -124,7 +123,7 @@ func (m *NodeManager) RunNode() {
|
|||
var err error
|
||||
m.services.rpcClient, err = m.node.geth.Attach()
|
||||
if err != nil {
|
||||
glog.V(logger.Warn).Infoln("cannot get RPC client service:", ErrInvalidClient)
|
||||
log.Warn("cannot get RPC client service", "error", ErrInvalidClient)
|
||||
}
|
||||
|
||||
// expose API
|
||||
|
@ -135,7 +134,7 @@ func (m *NodeManager) RunNode() {
|
|||
m.onNodeStarted() // node started, notify listeners
|
||||
m.node.geth.Wait()
|
||||
|
||||
glog.V(logger.Info).Infoln("node stopped")
|
||||
log.Info("node stopped")
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -149,18 +148,24 @@ func (m *NodeManager) StartNode() {
|
|||
panic(fmt.Sprintf("%v: %v", ErrNodeStartFailure, err))
|
||||
}
|
||||
|
||||
if server := m.node.geth.Server(); server != nil {
|
||||
if nodeInfo := server.NodeInfo(); nodeInfo != nil {
|
||||
log.Info(nodeInfo.Enode)
|
||||
}
|
||||
}
|
||||
|
||||
// allow interrupting running nodes
|
||||
go func() {
|
||||
sigc := make(chan os.Signal, 1)
|
||||
signal.Notify(sigc, os.Interrupt)
|
||||
defer signal.Stop(sigc)
|
||||
<-sigc
|
||||
glog.V(logger.Info).Infoln("Got interrupt, shutting down...")
|
||||
log.Info("Got interrupt, shutting down...")
|
||||
go m.node.geth.Stop()
|
||||
for i := 3; i > 0; i-- {
|
||||
<-sigc
|
||||
if i > 1 {
|
||||
glog.V(logger.Info).Infof("Already shutting down, interrupt %d more times for panic.", i-1)
|
||||
log.Info(fmt.Sprintf("Already shutting down, interrupt %d more times for panic.", i-1))
|
||||
}
|
||||
}
|
||||
panic("interrupted!")
|
||||
|
@ -173,7 +178,9 @@ func (m *NodeManager) StopNode() error {
|
|||
return ErrInvalidGethNode
|
||||
}
|
||||
|
||||
m.node.geth.Stop()
|
||||
if err := m.node.geth.Stop(); err != nil {
|
||||
return err
|
||||
}
|
||||
m.node.started = make(chan struct{})
|
||||
return nil
|
||||
}
|
||||
|
@ -222,10 +229,10 @@ func (m *NodeManager) ResetChainData() error {
|
|||
if _, err := os.Stat(chainDataDir); os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.RemoveAll(chainDataDir); err != nil {
|
||||
return err
|
||||
}
|
||||
log.Info("chaindata removed", "dir", chainDataDir)
|
||||
|
||||
if err := m.ResumeNode(); err != nil {
|
||||
return err
|
||||
|
@ -245,8 +252,9 @@ func (m *NodeManager) StartNodeRPCServer() (bool, error) {
|
|||
|
||||
config := m.node.gethConfig
|
||||
modules := strings.Join(config.HTTPModules, ",")
|
||||
cors := strings.Join(config.HTTPCors, ",")
|
||||
|
||||
return m.api.StartRPC(&config.HTTPHost, &config.HTTPPort, &config.HTTPCors, &modules)
|
||||
return m.api.StartRPC(&config.HTTPHost, &config.HTTPPort, &cors, &modules)
|
||||
}
|
||||
|
||||
// StopNodeRPCServer stops HTTP RPC service attached to node
|
||||
|
|
|
@ -31,7 +31,7 @@ func SetupLogger(config *NodeConfig) (*Logger, error) {
|
|||
config: config,
|
||||
origHandler: log.Root().GetHandler(),
|
||||
}
|
||||
nodeLoggerInstance.handler = nodeLoggerInstance.makeLogHandler(log.LvlInfo)
|
||||
nodeLoggerInstance.handler = nodeLoggerInstance.makeLogHandler(parseLogLevel(config.LogLevel))
|
||||
})
|
||||
|
||||
if err := nodeLoggerInstance.Start(); err != nil {
|
||||
|
@ -62,12 +62,14 @@ func (l *Logger) Stop() error {
|
|||
func (l *Logger) makeLogHandler(lvl log.Lvl) log.Handler {
|
||||
var handler log.Handler
|
||||
logFilePath := filepath.Join(l.config.DataDir, l.config.LogFile)
|
||||
fileHandler := log.Must.FileHandler(logFilePath, log.LogfmtFormat())
|
||||
stderrHandler := log.StreamHandler(os.Stderr, log.TerminalFormat(true))
|
||||
if l.config.LogToStderr {
|
||||
handler = log.MultiHandler(
|
||||
log.LvlFilterHandler(lvl, log.StreamHandler(os.Stderr, log.TerminalFormat(true))),
|
||||
log.LvlFilterHandler(lvl, log.Must.FileHandler(logFilePath, log.LogfmtFormat())))
|
||||
log.LvlFilterHandler(lvl, log.CallerFileHandler(log.CallerFuncHandler(stderrHandler))),
|
||||
log.LvlFilterHandler(lvl, fileHandler))
|
||||
} else {
|
||||
handler = log.LvlFilterHandler(lvl, log.Must.FileHandler(logFilePath, log.LogfmtFormat()))
|
||||
handler = log.LvlFilterHandler(lvl, fileHandler)
|
||||
}
|
||||
|
||||
return handler
|
||||
|
|
|
@ -20,8 +20,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/logger"
|
||||
"github.com/ethereum/go-ethereum/logger/glog"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/status-im/status-go/geth/params"
|
||||
"github.com/status-im/status-go/static"
|
||||
)
|
||||
|
@ -59,7 +58,7 @@ func SetDefaultNodeNotificationHandler(fn NodeNotificationHandler) {
|
|||
|
||||
// TriggerDefaultNodeNotificationHandler triggers default notification handler (helpful in tests)
|
||||
func TriggerDefaultNodeNotificationHandler(jsonEvent string) {
|
||||
glog.V(logger.Info).Infof("notification received (default notification handler): %s\n", jsonEvent)
|
||||
log.Info("notification received (default notification handler)", "event", jsonEvent)
|
||||
}
|
||||
|
||||
// SendSignal sends application signal (JSON, normally) upwards to application (via default notification handler)
|
||||
|
@ -164,7 +163,7 @@ func PrepareTestNode() (err error) {
|
|||
|
||||
// prepare node directory
|
||||
if err := os.MkdirAll(filepath.Join(TestDataDir, "keystore"), os.ModePerm); err != nil {
|
||||
glog.V(logger.Warn).Infoln("make node failed:", err)
|
||||
log.Warn("make node failed", "error", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -206,7 +205,7 @@ func PrepareTestNode() (err error) {
|
|||
}
|
||||
|
||||
if syncRequired {
|
||||
glog.V(logger.Warn).Infof("Sync is required, it will take %d seconds", testConfig.Node.SyncSeconds)
|
||||
log.Warn("Sync is required", "duration", testConfig.Node.SyncSeconds)
|
||||
time.Sleep(testConfig.Node.SyncSeconds * time.Second) // LES syncs headers, so that we are up do date when it is done
|
||||
}
|
||||
|
||||
|
@ -216,7 +215,7 @@ func PrepareTestNode() (err error) {
|
|||
func RemoveTestNode() {
|
||||
err := os.RemoveAll(TestDataDir)
|
||||
if err != nil {
|
||||
glog.V(logger.Warn).Infof("could not clean up temporary datadir")
|
||||
log.Warn("could not clean up temporary datadir")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -288,7 +287,7 @@ func ImportTestAccount(keystoreDir, accountFile string) error {
|
|||
if _, err := os.Stat(dst); os.IsNotExist(err) {
|
||||
err = ioutil.WriteFile(dst, static.MustAsset("keys/"+accountFile), 0644)
|
||||
if err != nil {
|
||||
glog.V(logger.Warn).Infof("cannot copy test account PK: %v", err)
|
||||
log.Warn("cannot copy test account PK", "error", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,8 +30,8 @@ func TestWhisperFilterRace(t *testing.T) {
|
|||
}
|
||||
accountKey1Hex := common.ToHex(crypto.FromECDSAPub(&accountKey1.PrivateKey.PublicKey))
|
||||
|
||||
whisperService.AddIdentity(accountKey1.PrivateKey)
|
||||
if ok, err := whisperAPI.HasIdentity(accountKey1Hex); err != nil || !ok {
|
||||
whisperService.AddKeyPair(accountKey1.PrivateKey)
|
||||
if ok, err := whisperAPI.HasKeyPair(accountKey1Hex); err != nil || !ok {
|
||||
t.Fatalf("identity not injected: %v", accountKey1Hex)
|
||||
}
|
||||
|
||||
|
@ -42,8 +42,8 @@ func TestWhisperFilterRace(t *testing.T) {
|
|||
}
|
||||
accountKey2Hex := common.ToHex(crypto.FromECDSAPub(&accountKey2.PrivateKey.PublicKey))
|
||||
|
||||
whisperService.AddIdentity(accountKey2.PrivateKey)
|
||||
if ok, err := whisperAPI.HasIdentity(accountKey2Hex); err != nil || !ok {
|
||||
whisperService.AddKeyPair(accountKey2.PrivateKey)
|
||||
if ok, err := whisperAPI.HasKeyPair(accountKey2Hex); err != nil || !ok {
|
||||
t.Fatalf("identity not injected: %v", accountKey2Hex)
|
||||
}
|
||||
|
||||
|
@ -65,10 +65,10 @@ func TestWhisperFilterRace(t *testing.T) {
|
|||
|
||||
for i := 0; i < 10; i++ {
|
||||
go func() {
|
||||
whisperAPI.NewFilter(whisper.WhisperFilterArgs{
|
||||
From: accountKey1Hex,
|
||||
To: accountKey2Hex,
|
||||
Topics: []whisper.TopicType{
|
||||
whisperAPI.Subscribe(whisper.WhisperFilterArgs{
|
||||
Sig: accountKey1Hex,
|
||||
Key: accountKey2Hex,
|
||||
Topics: [][]byte{
|
||||
{0x4e, 0x03, 0x65, 0x7a}, {0x34, 0x60, 0x7c, 0x9b}, {0x21, 0x41, 0x7d, 0xf9},
|
||||
},
|
||||
})
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -2258,8 +2258,6 @@ var isAddress = function (address) {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks if the given string is a checksummed address
|
||||
*
|
||||
|
@ -2410,6 +2408,38 @@ var isJson = function (str) {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if given string is a valid Ethereum block header bloom.
|
||||
*
|
||||
* @method isBloom
|
||||
* @param {String} hex encoded bloom filter
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isBloom = function (bloom) {
|
||||
if (!/^(0x)?[0-9a-f]{512}$/i.test(bloom)) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{512}$/.test(bloom) || /^(0x)?[0-9A-F]{512}$/.test(bloom)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns true if given string is a valid log topic.
|
||||
*
|
||||
* @method isTopic
|
||||
* @param {String} hex encoded topic
|
||||
* @return {Boolean}
|
||||
*/
|
||||
var isTopic = function (topic) {
|
||||
if (!/^(0x)?[0-9a-f]{64}$/i.test(topic)) {
|
||||
return false;
|
||||
} else if (/^(0x)?[0-9a-f]{64}$/.test(topic) || /^(0x)?[0-9A-F]{64}$/.test(topic)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
padLeft: padLeft,
|
||||
padRight: padRight,
|
||||
|
@ -2438,12 +2468,14 @@ module.exports = {
|
|||
isObject: isObject,
|
||||
isBoolean: isBoolean,
|
||||
isArray: isArray,
|
||||
isJson: isJson
|
||||
isJson: isJson,
|
||||
isBloom: isBloom,
|
||||
isTopic: isTopic,
|
||||
};
|
||||
|
||||
},{"./sha3.js":19,"bignumber.js":"bignumber.js","utf8":85}],21:[function(require,module,exports){
|
||||
module.exports={
|
||||
"version": "0.18.3"
|
||||
"version": "0.18.4"
|
||||
}
|
||||
|
||||
},{}],22:[function(require,module,exports){
|
||||
|
@ -3437,10 +3469,13 @@ var getOptions = function (options) {
|
|||
});
|
||||
|
||||
return {
|
||||
type: options.type,
|
||||
topics: options.topics,
|
||||
from: options.from,
|
||||
sig: options.sig,
|
||||
to: options.to,
|
||||
keyname: options.keyname,
|
||||
key: options.key,
|
||||
minPow: options.minPow,
|
||||
address: options.address,
|
||||
fromBlock: formatters.inputBlockNumberFormatter(options.fromBlock),
|
||||
toBlock: formatters.inputBlockNumberFormatter(options.toBlock)
|
||||
|
@ -3821,21 +3856,15 @@ var outputLogFormatter = function(log) {
|
|||
var inputPostFormatter = function(post) {
|
||||
|
||||
// post.payload = utils.toHex(post.payload);
|
||||
post.ttl = utils.fromDecimal(post.ttl);
|
||||
post.workToProve = utils.fromDecimal(post.workToProve);
|
||||
post.priority = utils.fromDecimal(post.priority);
|
||||
if (post.ttl) post.ttl = utils.fromDecimal(post.ttl);
|
||||
if (post.powTime) post.powTime = utils.fromDecimal(post.powTime);
|
||||
if (post.powTarget) post.powTarget = post.powTarget.toString();
|
||||
|
||||
// fallback
|
||||
if (!utils.isArray(post.topics)) {
|
||||
post.topics = post.topics ? [post.topics] : [];
|
||||
// format the topic
|
||||
if (post.topic) {
|
||||
post.topic = (post.topic.indexOf('0x') === 0) ? post.topic : utils.fromUtf8(post.topic);
|
||||
}
|
||||
|
||||
// format the following options
|
||||
post.topics = post.topics.map(function(topic){
|
||||
// convert only if not hex
|
||||
return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
|
||||
});
|
||||
|
||||
return post;
|
||||
};
|
||||
|
||||
|
@ -3860,16 +3889,37 @@ var outputPostFormatter = function(post){
|
|||
// }
|
||||
|
||||
// format the following options
|
||||
if (!post.topics) {
|
||||
post.topics = [];
|
||||
}
|
||||
post.topics = post.topics.map(function(topic){
|
||||
return utils.toAscii(topic);
|
||||
});
|
||||
// if (!post.topics) {
|
||||
// post.topics = [];
|
||||
// }
|
||||
// post.topics = post.topics.map(function(topic){
|
||||
// return utils.toAscii(topic);
|
||||
// });
|
||||
|
||||
return post;
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the input of a whisper subscribe and converts all values to HEX
|
||||
*
|
||||
* @method inputSubscribeFormatter
|
||||
* @param {Object} filterArgs object
|
||||
* @returns {Object}
|
||||
*/
|
||||
var inputSubscribeFormatter = function(filterArgs) {
|
||||
if (filterArgs.minPow) filterArgs.powTarget = filterArgs.minPow.toString();
|
||||
|
||||
// format topics
|
||||
if (!utils.isArray(filterArgs.topics)) {
|
||||
filterArgs.topics = filterArgs.topics ? [filterArgs.topics] : [];
|
||||
}
|
||||
filterArgs.topics = filterArgs.topics.map(function(topic){
|
||||
return (topic.indexOf('0x') === 0) ? topic : utils.fromUtf8(topic);
|
||||
});
|
||||
|
||||
return filterArgs;
|
||||
};
|
||||
|
||||
var inputAddressFormatter = function (address) {
|
||||
var iban = new Iban(address);
|
||||
if (iban.isValid() && iban.isDirect()) {
|
||||
|
@ -3903,6 +3953,7 @@ module.exports = {
|
|||
inputTransactionFormatter: inputTransactionFormatter,
|
||||
inputAddressFormatter: inputAddressFormatter,
|
||||
inputPostFormatter: inputPostFormatter,
|
||||
inputSubscribeFormatter: inputSubscribeFormatter,
|
||||
outputBigNumberFormatter: outputBigNumberFormatter,
|
||||
outputTransactionFormatter: outputTransactionFormatter,
|
||||
outputTransactionReceiptFormatter: outputTransactionReceiptFormatter,
|
||||
|
@ -4256,6 +4307,7 @@ HttpProvider.prototype.prepareRequest = function (async) {
|
|||
*/
|
||||
HttpProvider.prototype.send = function (payload) {
|
||||
var request = this.prepareRequest(false);
|
||||
// console.log(JSON.stringify(payload));
|
||||
|
||||
try {
|
||||
request.send(JSON.stringify(payload));
|
||||
|
@ -4283,6 +4335,7 @@ HttpProvider.prototype.send = function (payload) {
|
|||
*/
|
||||
HttpProvider.prototype.sendAsync = function (payload, callback) {
|
||||
var request = this.prepareRequest(true);
|
||||
// console.log(JSON.stringify(payload))
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === 4 && request.timeout !== 1) {
|
||||
|
@ -5156,12 +5209,12 @@ function Eth(web3) {
|
|||
|
||||
var self = this;
|
||||
|
||||
methods().forEach(function(method) {
|
||||
methods().forEach(function(method) {
|
||||
method.attachToObject(self);
|
||||
method.setRequestManager(self._requestManager);
|
||||
});
|
||||
|
||||
properties().forEach(function(p) {
|
||||
properties().forEach(function(p) {
|
||||
p.attachToObject(self);
|
||||
p.setRequestManager(self._requestManager);
|
||||
});
|
||||
|
@ -5297,6 +5350,13 @@ var methods = function () {
|
|||
inputFormatter: [formatters.inputTransactionFormatter]
|
||||
});
|
||||
|
||||
var signTransaction = new Method({
|
||||
name: 'signTransaction',
|
||||
call: 'eth_signTransaction',
|
||||
params: 1,
|
||||
inputFormatter: [formatters.inputTransactionFormatter]
|
||||
});
|
||||
|
||||
var sign = new Method({
|
||||
name: 'sign',
|
||||
call: 'eth_sign',
|
||||
|
@ -5365,6 +5425,7 @@ var methods = function () {
|
|||
call,
|
||||
estimateGas,
|
||||
sendRawTransaction,
|
||||
signTransaction,
|
||||
sendTransaction,
|
||||
sign,
|
||||
compileSolidity,
|
||||
|
@ -5440,7 +5501,6 @@ Eth.prototype.isSyncing = function (callback) {
|
|||
|
||||
module.exports = Eth;
|
||||
|
||||
|
||||
},{"../../utils/config":18,"../../utils/utils":20,"../contract":25,"../filter":29,"../formatters":30,"../iban":33,"../method":36,"../namereg":44,"../property":45,"../syncing":48,"../transfer":49,"./watches":43}],39:[function(require,module,exports){
|
||||
/*
|
||||
This file is part of web3.js.
|
||||
|
@ -5623,34 +5683,62 @@ var Shh = function (web3) {
|
|||
|
||||
var self = this;
|
||||
|
||||
methods().forEach(function(method) {
|
||||
methods().forEach(function (method) {
|
||||
method.attachToObject(self);
|
||||
method.setRequestManager(self._requestManager);
|
||||
});
|
||||
};
|
||||
|
||||
Shh.prototype.filter = function (fil, callback) {
|
||||
return new Filter(this._requestManager, fil, watches.shh(), formatters.outputPostFormatter, callback);
|
||||
Shh.prototype.filter = function (fil, callback, filterCreationErrorCallback) {
|
||||
return new Filter(this._requestManager, fil, watches.shh(), formatters.outputPostFormatter, callback, filterCreationErrorCallback);
|
||||
};
|
||||
|
||||
var methods = function () {
|
||||
var methods = function () {
|
||||
var version = new Method({
|
||||
name: 'version',
|
||||
call: 'shh_version'
|
||||
});
|
||||
|
||||
var info = new Method({
|
||||
name: 'info',
|
||||
call: 'shh_info'
|
||||
});
|
||||
|
||||
var setMinimumPoW = new Method({
|
||||
name: 'setMinimumPoW',
|
||||
call: 'shh_setMinimumPoW',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var post = new Method({
|
||||
name: 'post',
|
||||
call: 'shh_post',
|
||||
name: 'post',
|
||||
call: 'shh_post',
|
||||
params: 1,
|
||||
inputFormatter: [formatters.inputPostFormatter]
|
||||
});
|
||||
|
||||
var newIdentity = new Method({
|
||||
name: 'newIdentity',
|
||||
call: 'shh_newIdentity',
|
||||
params: 0
|
||||
var subscribe = new Method({
|
||||
name: 'subscribe',
|
||||
call: 'shh_subscribe',
|
||||
params: 1,
|
||||
inputFormatter: [formatters.inputSubscribeFormatter]
|
||||
});
|
||||
|
||||
var hasIdentity = new Method({
|
||||
name: 'hasIdentity',
|
||||
call: 'shh_hasIdentity',
|
||||
var unsubscribe = new Method({
|
||||
name: 'unsubscribe',
|
||||
call: 'shh_unsubscribe',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var getMessages = new Method({
|
||||
name: 'getMessages',
|
||||
call: 'shh_getMessages',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var getSubscriptionMessages = new Method({
|
||||
name: 'getSubscriptionMessages',
|
||||
call: 'shh_getSubscriptionMessages',
|
||||
params: 1
|
||||
});
|
||||
|
||||
|
@ -5666,40 +5754,92 @@ var methods = function () {
|
|||
params: 0
|
||||
});
|
||||
|
||||
var generateSymKey = new Method({
|
||||
name: 'generateSymKey',
|
||||
call: 'shh_generateSymKey',
|
||||
var newKeyPair = new Method({
|
||||
name: 'newKeyPair',
|
||||
call: 'shh_newKeyPair'
|
||||
});
|
||||
|
||||
var hasKeyPair = new Method({
|
||||
name: 'hasKeyPair',
|
||||
call: 'shh_hasKeyPair',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var hasSymKey = new Method({
|
||||
name: 'hasSymKey',
|
||||
call: 'shh_hasSymKey',
|
||||
var getPublicKey = new Method({
|
||||
name: 'getPublicKey',
|
||||
call: 'shh_getPublicKey',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var deleteSymKey = new Method({
|
||||
name: 'deleteSymKey',
|
||||
call: 'shh_deleteSymKey',
|
||||
var getPrivateKey = new Method({
|
||||
name: 'getPrivateKey',
|
||||
call: 'shh_getPrivateKey',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var addSymKey = new Method({
|
||||
name: 'addSymKey',
|
||||
call: 'shh_addSymKey',
|
||||
params: 2
|
||||
var deleteKeyPair = new Method({
|
||||
name: 'deleteKeyPair',
|
||||
call: 'shh_deleteKeyPair',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var generateSymmetricKey = new Method({
|
||||
name: 'generateSymmetricKey',
|
||||
call: 'shh_generateSymmetricKey'
|
||||
});
|
||||
|
||||
var addSymmetricKeyDirect = new Method({
|
||||
name: 'addSymmetricKeyDirect',
|
||||
call: 'shh_addSymmetricKeyDirect',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var addSymmetricKeyFromPassword = new Method({
|
||||
name: 'addSymmetricKeyFromPassword',
|
||||
call: 'shh_addSymmetricKeyFromPassword',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var hasSymmetricKey = new Method({
|
||||
name: 'hasSymmetricKey',
|
||||
call: 'shh_hasSymmetricKey',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var getSymmetricKey = new Method({
|
||||
name: 'getSymmetricKey',
|
||||
call: 'shh_getSymmetricKey',
|
||||
params: 1
|
||||
});
|
||||
|
||||
var deleteSymmetricKey = new Method({
|
||||
name: 'deleteSymmetricKey',
|
||||
call: 'shh_deleteSymmetricKey',
|
||||
params: 1
|
||||
});
|
||||
|
||||
return [
|
||||
version,
|
||||
info,
|
||||
setMinimumPoW,
|
||||
post,
|
||||
newIdentity,
|
||||
hasIdentity,
|
||||
newGroup,
|
||||
addToGroup,
|
||||
generateSymKey,
|
||||
hasSymKey,
|
||||
deleteSymKey,
|
||||
addSymKey
|
||||
subscribe,
|
||||
unsubscribe,
|
||||
getMessages,
|
||||
getSubscriptionMessages,
|
||||
// asymmetric key management
|
||||
newKeyPair,
|
||||
hasKeyPair,
|
||||
getPublicKey,
|
||||
getPrivateKey,
|
||||
deleteKeyPair,
|
||||
// symmetric key management
|
||||
generateSymmetricKey,
|
||||
addSymmetricKeyDirect,
|
||||
addSymmetricKeyFromPassword,
|
||||
hasSymmetricKey,
|
||||
getSymmetricKey,
|
||||
deleteSymmetricKey
|
||||
];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue