From d092a2bb493b883e0f732c6b1df8ff22c1ec8d7d Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Mon, 28 Jun 2021 10:03:07 +0200 Subject: [PATCH] Fix wallet big int conversion --- eth-node/bridge/geth/keystore.go | 103 ------------------------------ params/config.go | 66 ------------------- peers/peerpool.go | 1 - services/rpcfilters/service.go | 6 +- services/subscriptions/service.go | 6 +- services/wallet/balance.go | 4 +- 6 files changed, 9 insertions(+), 177 deletions(-) delete mode 100644 eth-node/bridge/geth/keystore.go diff --git a/eth-node/bridge/geth/keystore.go b/eth-node/bridge/geth/keystore.go deleted file mode 100644 index a71a5541b..000000000 --- a/eth-node/bridge/geth/keystore.go +++ /dev/null @@ -1,103 +0,0 @@ -package gethbridge - -import ( - "crypto/ecdsa" - "errors" - "strings" - - "github.com/ethereum/go-ethereum/accounts" - "github.com/ethereum/go-ethereum/accounts/keystore" - "github.com/ethereum/go-ethereum/common" - - "github.com/status-im/status-go/eth-node/types" - "github.com/status-im/status-go/extkeys" -) - -type gethKeyStoreAdapter struct { - keystore *keystore.KeyStore -} - -// WrapKeyStore creates a types.KeyStore wrapper over a keystore.KeyStore object -func WrapKeyStore(keystore *keystore.KeyStore) types.KeyStore { - return &gethKeyStoreAdapter{keystore: keystore} -} - -func (k *gethKeyStoreAdapter) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (types.Account, error) { - gethAccount, err := k.keystore.ImportECDSA(priv, passphrase) - return accountFrom(gethAccount), err -} - -func (k *gethKeyStoreAdapter) ImportSingleExtendedKey(extKey *extkeys.ExtendedKey, passphrase string) (types.Account, error) { - gethAccount, err := k.keystore.ImportSingleExtendedKey(extKey, passphrase) - return accountFrom(gethAccount), err -} - -func (k *gethKeyStoreAdapter) ImportExtendedKeyForPurpose(keyPurpose extkeys.KeyPurpose, extKey *extkeys.ExtendedKey, passphrase string) (types.Account, error) { - gethAccount, err := k.keystore.ImportExtendedKeyForPurpose(keyPurpose, extKey, passphrase) - return accountFrom(gethAccount), err -} - -func (k *gethKeyStoreAdapter) AccountDecryptedKey(a types.Account, auth string) (types.Account, *types.Key, error) { - gethAccount, err := gethAccountFrom(a) - if err != nil { - return types.Account{}, nil, err - } - - var gethKey *keystore.Key - gethAccount, gethKey, err = k.keystore.AccountDecryptedKey(gethAccount, auth) - return accountFrom(gethAccount), keyFrom(gethKey), err -} - -func (k *gethKeyStoreAdapter) Delete(a types.Account, auth string) error { - gethAccount, err := gethAccountFrom(a) - if err != nil { - return err - } - - return k.keystore.Delete(gethAccount, auth) -} - -// parseGethURL converts a user supplied URL into the accounts specific structure. -func parseGethURL(url string) (accounts.URL, error) { - parts := strings.Split(url, "://") - if len(parts) != 2 || parts[0] == "" { - return accounts.URL{}, errors.New("protocol scheme missing") - } - return accounts.URL{ - Scheme: parts[0], - Path: parts[1], - }, nil -} - -func gethAccountFrom(account types.Account) (accounts.Account, error) { - var ( - gethAccount accounts.Account - err error - ) - gethAccount.Address = common.Address(account.Address) - if account.URL != "" { - gethAccount.URL, err = parseGethURL(account.URL) - } - return gethAccount, err -} - -func accountFrom(gethAccount accounts.Account) types.Account { - return types.Account{ - Address: types.Address(gethAccount.Address), - URL: gethAccount.URL.String(), - } -} - -func keyFrom(k *keystore.Key) *types.Key { - if k == nil { - return nil - } - - return &types.Key{ - ID: k.Id, - Address: types.Address(k.Address), - PrivateKey: k.PrivateKey, - ExtendedKey: k.ExtendedKey, - SubAccountIndex: k.SubAccountIndex, - } -} diff --git a/params/config.go b/params/config.go index 9f01c0c39..ed880a64a 100644 --- a/params/config.go +++ b/params/config.go @@ -17,36 +17,14 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p/discv5" - "github.com/ethereum/go-ethereum/params" "github.com/status-im/status-go/eth-node/crypto" - "github.com/status-im/status-go/eth-node/types" "github.com/status-im/status-go/protocol/pushnotificationserver" "github.com/status-im/status-go/static" wakucommon "github.com/status-im/status-go/waku/common" wakuv2common "github.com/status-im/status-go/wakuv2/common" ) -// ---------- -// LightEthConfig -// ---------- - -// LightEthConfig holds LES-related configuration -// Status nodes are always lightweight clients (due to mobile platform constraints) -type LightEthConfig struct { - // Enabled flag specifies whether protocol is enabled - Enabled bool - - // DatabaseCache is memory (in MBs) allocated to internal caching (min 16MB / database forced) - DatabaseCache int - - // TrustedNodes is a list of trusted servers - TrustedNodes []string - - //MinTrustedFraction is minimum percentage of connected trusted servers to validate header(1-100) - MinTrustedFraction int -} - // ---------- // DatabaseConfig // ---------- @@ -434,9 +412,6 @@ type NodeConfig struct { // ClusterConfig extra configuration for supporting cluster peers. ClusterConfig ClusterConfig `json:"ClusterConfig," validate:"structonly"` - // LightEthConfig extra configuration for LES - LightEthConfig LightEthConfig `json:"LightEthConfig," validate:"structonly"` - // WakuConfig provides a configuration for Waku subprotocol. WakuConfig WakuConfig `json:"WakuConfig" validate:"structonly"` @@ -730,9 +705,6 @@ func (c *NodeConfig) updatePeerLimits() { if c.NoDiscovery && !c.Rendezvous { return } - if c.LightEthConfig.Enabled { - c.RequireTopics[discv5.Topic(LesTopic(int(c.NetworkID)))] = LesDiscoveryLimits - } } // NewNodeConfig creates new node configuration object with bare-minimum defaults. @@ -767,9 +739,6 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) { UpstreamConfig: UpstreamRPCConfig{ URL: getUpstreamURL(networkID), }, - LightEthConfig: LightEthConfig{ - DatabaseCache: 16, - }, WakuConfig: WakuConfig{ DataDir: wakuDir, MinimumPoW: WakuMinimumPoW, @@ -871,10 +840,6 @@ func (c *NodeConfig) Validate() error { } } - if c.UpstreamConfig.Enabled && c.LightEthConfig.Enabled { - return fmt.Errorf("both UpstreamConfig and LightEthConfig are enabled, but they are mutually exclusive") - } - if err := c.validateChildStructs(validate); err != nil { return err } @@ -924,9 +889,6 @@ func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error { if err := c.ClusterConfig.Validate(validate); err != nil { return err } - if err := c.LightEthConfig.Validate(validate); err != nil { - return err - } if err := c.SwarmConfig.Validate(validate); err != nil { return err } @@ -966,19 +928,6 @@ func (c *ClusterConfig) Validate(validate *validator.Validate) error { return nil } -// Validate validates the LightEthConfig struct and returns an error if inconsistent values are found -func (c *LightEthConfig) Validate(validate *validator.Validate) error { - if !c.Enabled { - return nil - } - - if err := validate.Struct(c); err != nil { - return err - } - - return nil -} - // Validate validates the SwarmConfig struct and returns an error if inconsistent values are found func (c *SwarmConfig) Validate(validate *validator.Validate) error { if !c.Enabled { @@ -1046,18 +995,3 @@ func (c *NodeConfig) FormatAPIModules() []string { func (c *NodeConfig) AddAPIModule(m string) { c.APIModules = fmt.Sprintf("%s,%s", c.APIModules, m) } - -// LesTopic returns discovery v5 topic derived from genesis of the provided network. -// 1 - mainnet, 3 - ropsten, 4 - rinkeby -func LesTopic(netid int) string { - switch netid { - case 1: - return LESDiscoveryIdentifier + types.Bytes2Hex(params.MainnetGenesisHash.Bytes()[:8]) - case 3: - return LESDiscoveryIdentifier + types.Bytes2Hex(params.TestnetGenesisHash.Bytes()[:8]) - case 4: - return LESDiscoveryIdentifier + types.Bytes2Hex(params.RinkebyGenesisHash.Bytes()[:8]) - default: - return "" - } -} diff --git a/peers/peerpool.go b/peers/peerpool.go index 39620212b..4d6e3484d 100644 --- a/peers/peerpool.go +++ b/peers/peerpool.go @@ -6,7 +6,6 @@ import ( "sync" "time" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/p2p" diff --git a/services/rpcfilters/service.go b/services/rpcfilters/service.go index cd599ec83..1dbb75545 100644 --- a/services/rpcfilters/service.go +++ b/services/rpcfilters/service.go @@ -8,8 +8,8 @@ import ( "github.com/status-im/status-go/eth-node/types" ) -// Make sure that Service implements node.Service interface. -var _ node.Service = (*Service)(nil) +// Make sure that Service implements node.Lifecycle interface. +var _ node.Lifecycle = (*Service)(nil) // Service represents out own implementation of personal sign operations. type Service struct { @@ -51,7 +51,7 @@ func (s *Service) APIs() []rpc.API { } // Start is run when a service is started. -func (s *Service) Start(server *p2p.Server) error { +func (s *Service) Start() error { s.quit = make(chan struct{}) err := s.transactionSentToUpstreamEvent.Start() if err != nil { diff --git a/services/subscriptions/service.go b/services/subscriptions/service.go index e24487c9d..3dc5c31c6 100644 --- a/services/subscriptions/service.go +++ b/services/subscriptions/service.go @@ -8,8 +8,8 @@ import ( "github.com/status-im/status-go/rpc" ) -// Make sure that Service implements gethnode.Service interface. -var _ gethnode.Service = (*Service)(nil) +// Make sure that Service implements gethnode.Lifecycle interface. +var _ gethnode.Lifecycle = (*Service)(nil) // Service represents our own implementation of personal sign operations. type Service struct { @@ -41,7 +41,7 @@ func (s *Service) APIs() []gethrpc.API { } // Start is run when a service is started. -func (s *Service) Start(server *p2p.Server) error { +func (s *Service) Start() error { return nil } diff --git a/services/wallet/balance.go b/services/wallet/balance.go index 5312a0d16..e93fb5523 100644 --- a/services/wallet/balance.go +++ b/services/wallet/balance.go @@ -50,7 +50,9 @@ func GetTokensBalances(parent context.Context, client *walletClient, accounts, t if !exist { response[account] = map[common.Address]*hexutil.Big{} } - response[account][token] = balance + b := hexutil.Big(*balance) + + response[account][token] = &b mu.Unlock() return nil })