feat(token): enable changing token address from the node config (#2848)
Co-authored-by: Jonathan Rainville <rainville.jonathan@gmail.com>
This commit is contained in:
parent
9ea2344647
commit
cdca3d86e2
|
@ -655,7 +655,7 @@ func (b *GethStatusBackend) StartNodeWithAccountAndInitialConfig(
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.StartNodeWithAccount(account, password, nil)
|
||||
return b.StartNodeWithAccount(account, password, nodecfg)
|
||||
}
|
||||
|
||||
func (b *GethStatusBackend) saveAccountsAndSettings(settings settings.Settings, nodecfg *params.NodeConfig, subaccs []*accounts.Account) error {
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
validator "gopkg.in/go-playground/validator.v9"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
@ -502,20 +503,26 @@ type NodeConfig struct {
|
|||
OutputMessageCSVEnabled bool
|
||||
}
|
||||
|
||||
type TokenOverride struct {
|
||||
Symbol string `json:"symbol"`
|
||||
Address common.Address `json:"address"`
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
ChainID uint64 `json:"chainId"`
|
||||
ChainName string `json:"chainName"`
|
||||
RPCURL string `json:"rpcUrl"`
|
||||
BlockExplorerURL string `json:"blockExplorerUrl,omitempty"`
|
||||
IconURL string `json:"iconUrl,omitempty"`
|
||||
NativeCurrencyName string `json:"nativeCurrencyName,omitempty"`
|
||||
NativeCurrencySymbol string `json:"nativeCurrencySymbol,omitempty"`
|
||||
NativeCurrencyDecimals uint64 `json:"nativeCurrencyDecimals"`
|
||||
IsTest bool `json:"isTest"`
|
||||
Layer uint64 `json:"layer"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ChainColor string `json:"chainColor"`
|
||||
ShortName string `json:"shortName"`
|
||||
ChainID uint64 `json:"chainId"`
|
||||
ChainName string `json:"chainName"`
|
||||
RPCURL string `json:"rpcUrl"`
|
||||
BlockExplorerURL string `json:"blockExplorerUrl,omitempty"`
|
||||
IconURL string `json:"iconUrl,omitempty"`
|
||||
NativeCurrencyName string `json:"nativeCurrencyName,omitempty"`
|
||||
NativeCurrencySymbol string `json:"nativeCurrencySymbol,omitempty"`
|
||||
NativeCurrencyDecimals uint64 `json:"nativeCurrencyDecimals"`
|
||||
IsTest bool `json:"isTest"`
|
||||
Layer uint64 `json:"layer"`
|
||||
Enabled bool `json:"enabled"`
|
||||
ChainColor string `json:"chainColor"`
|
||||
ShortName string `json:"shortName"`
|
||||
TokenOverrides []TokenOverride `json:"tokenOverrides"`
|
||||
}
|
||||
|
||||
// WalletConfig extra configuration for wallet.Service.
|
||||
|
|
|
@ -70,7 +70,8 @@ func (nq *networksQuery) exec(db *sql.DB) ([]*params.Network, error) {
|
|||
}
|
||||
|
||||
type Manager struct {
|
||||
db *sql.DB
|
||||
db *sql.DB
|
||||
networks []params.Network
|
||||
}
|
||||
|
||||
func NewManager(db *sql.DB) *Manager {
|
||||
|
@ -92,6 +93,7 @@ func (nm *Manager) Init(networks []params.Network) error {
|
|||
if networks == nil {
|
||||
return nil
|
||||
}
|
||||
nm.networks = networks
|
||||
|
||||
var errors string
|
||||
currentNetworks, _ := nm.Get(false)
|
||||
|
@ -175,3 +177,7 @@ func (nm *Manager) Get(onlyEnabled bool) ([]*params.Network, error) {
|
|||
|
||||
return query.exec(nm.db)
|
||||
}
|
||||
|
||||
func (nm *Manager) GetConfiguredNetworks() []params.Network {
|
||||
return nm.networks
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ func NewService(
|
|||
cryptoOnRampManager := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
||||
dataSourceType: DataSourceStatic,
|
||||
})
|
||||
tokenManager := &TokenManager{db: db, RPCClient: rpcClient, networkManager: rpcClient.NetworkManager}
|
||||
tokenManager := NewTokenManager(db, rpcClient, rpcClient.NetworkManager)
|
||||
savedAddressesManager := &SavedAddressesManager{db: db}
|
||||
transactionManager := &TransactionManager{db: db, transactor: transactor, gethManager: gethManager, config: config, accountsDB: accountsDB}
|
||||
transferController := transfer.NewTransferController(db, rpcClient, accountFeed)
|
||||
|
|
|
@ -41,6 +41,35 @@ type TokenManager struct {
|
|||
networkManager *network.Manager
|
||||
}
|
||||
|
||||
func NewTokenManager(
|
||||
db *sql.DB,
|
||||
RPCClient *rpc.Client,
|
||||
networkManager *network.Manager,
|
||||
) *TokenManager {
|
||||
tokenManager := &TokenManager{db, RPCClient, networkManager}
|
||||
|
||||
// Check the networks' custom tokens to see if we must update the tokenStore
|
||||
networks := networkManager.GetConfiguredNetworks()
|
||||
for _, network := range networks {
|
||||
if len(network.TokenOverrides) == 0 {
|
||||
continue
|
||||
}
|
||||
for _, overrideToken := range network.TokenOverrides {
|
||||
tokensMap, ok := tokenStore[network.ChainID]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, token := range tokensMap {
|
||||
if token.Symbol == overrideToken.Symbol {
|
||||
token.Address = overrideToken.Address
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tokenManager
|
||||
}
|
||||
|
||||
func (tm *TokenManager) findSNT(chainID uint64) *Token {
|
||||
tokensMap, ok := tokenStore[chainID]
|
||||
if !ok {
|
||||
|
|
Loading…
Reference in New Issue