Fix wallet big int conversion
This commit is contained in:
parent
d30df5a6fd
commit
d092a2bb49
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -17,36 +17,14 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
"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/crypto"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
|
||||||
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
"github.com/status-im/status-go/protocol/pushnotificationserver"
|
||||||
"github.com/status-im/status-go/static"
|
"github.com/status-im/status-go/static"
|
||||||
wakucommon "github.com/status-im/status-go/waku/common"
|
wakucommon "github.com/status-im/status-go/waku/common"
|
||||||
wakuv2common "github.com/status-im/status-go/wakuv2/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
|
// DatabaseConfig
|
||||||
// ----------
|
// ----------
|
||||||
|
@ -434,9 +412,6 @@ type NodeConfig struct {
|
||||||
// ClusterConfig extra configuration for supporting cluster peers.
|
// ClusterConfig extra configuration for supporting cluster peers.
|
||||||
ClusterConfig ClusterConfig `json:"ClusterConfig," validate:"structonly"`
|
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 provides a configuration for Waku subprotocol.
|
||||||
WakuConfig WakuConfig `json:"WakuConfig" validate:"structonly"`
|
WakuConfig WakuConfig `json:"WakuConfig" validate:"structonly"`
|
||||||
|
|
||||||
|
@ -730,9 +705,6 @@ func (c *NodeConfig) updatePeerLimits() {
|
||||||
if c.NoDiscovery && !c.Rendezvous {
|
if c.NoDiscovery && !c.Rendezvous {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if c.LightEthConfig.Enabled {
|
|
||||||
c.RequireTopics[discv5.Topic(LesTopic(int(c.NetworkID)))] = LesDiscoveryLimits
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNodeConfig creates new node configuration object with bare-minimum defaults.
|
// NewNodeConfig creates new node configuration object with bare-minimum defaults.
|
||||||
|
@ -767,9 +739,6 @@ func NewNodeConfig(dataDir string, networkID uint64) (*NodeConfig, error) {
|
||||||
UpstreamConfig: UpstreamRPCConfig{
|
UpstreamConfig: UpstreamRPCConfig{
|
||||||
URL: getUpstreamURL(networkID),
|
URL: getUpstreamURL(networkID),
|
||||||
},
|
},
|
||||||
LightEthConfig: LightEthConfig{
|
|
||||||
DatabaseCache: 16,
|
|
||||||
},
|
|
||||||
WakuConfig: WakuConfig{
|
WakuConfig: WakuConfig{
|
||||||
DataDir: wakuDir,
|
DataDir: wakuDir,
|
||||||
MinimumPoW: WakuMinimumPoW,
|
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 {
|
if err := c.validateChildStructs(validate); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -924,9 +889,6 @@ func (c *NodeConfig) validateChildStructs(validate *validator.Validate) error {
|
||||||
if err := c.ClusterConfig.Validate(validate); err != nil {
|
if err := c.ClusterConfig.Validate(validate); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.LightEthConfig.Validate(validate); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.SwarmConfig.Validate(validate); err != nil {
|
if err := c.SwarmConfig.Validate(validate); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -966,19 +928,6 @@ func (c *ClusterConfig) Validate(validate *validator.Validate) error {
|
||||||
return nil
|
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
|
// Validate validates the SwarmConfig struct and returns an error if inconsistent values are found
|
||||||
func (c *SwarmConfig) Validate(validate *validator.Validate) error {
|
func (c *SwarmConfig) Validate(validate *validator.Validate) error {
|
||||||
if !c.Enabled {
|
if !c.Enabled {
|
||||||
|
@ -1046,18 +995,3 @@ func (c *NodeConfig) FormatAPIModules() []string {
|
||||||
func (c *NodeConfig) AddAPIModule(m string) {
|
func (c *NodeConfig) AddAPIModule(m string) {
|
||||||
c.APIModules = fmt.Sprintf("%s,%s", c.APIModules, m)
|
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 ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Make sure that Service implements node.Service interface.
|
// Make sure that Service implements node.Lifecycle interface.
|
||||||
var _ node.Service = (*Service)(nil)
|
var _ node.Lifecycle = (*Service)(nil)
|
||||||
|
|
||||||
// Service represents out own implementation of personal sign operations.
|
// Service represents out own implementation of personal sign operations.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
@ -51,7 +51,7 @@ func (s *Service) APIs() []rpc.API {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is run when a service is started.
|
// 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{})
|
s.quit = make(chan struct{})
|
||||||
err := s.transactionSentToUpstreamEvent.Start()
|
err := s.transactionSentToUpstreamEvent.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"github.com/status-im/status-go/rpc"
|
"github.com/status-im/status-go/rpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Make sure that Service implements gethnode.Service interface.
|
// Make sure that Service implements gethnode.Lifecycle interface.
|
||||||
var _ gethnode.Service = (*Service)(nil)
|
var _ gethnode.Lifecycle = (*Service)(nil)
|
||||||
|
|
||||||
// Service represents our own implementation of personal sign operations.
|
// Service represents our own implementation of personal sign operations.
|
||||||
type Service struct {
|
type Service struct {
|
||||||
|
@ -41,7 +41,7 @@ func (s *Service) APIs() []gethrpc.API {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is run when a service is started.
|
// Start is run when a service is started.
|
||||||
func (s *Service) Start(server *p2p.Server) error {
|
func (s *Service) Start() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,9 @@ func GetTokensBalances(parent context.Context, client *walletClient, accounts, t
|
||||||
if !exist {
|
if !exist {
|
||||||
response[account] = map[common.Address]*hexutil.Big{}
|
response[account] = map[common.Address]*hexutil.Big{}
|
||||||
}
|
}
|
||||||
response[account][token] = balance
|
b := hexutil.Big(*balance)
|
||||||
|
|
||||||
|
response[account][token] = &b
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue