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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
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"
|
validator "gopkg.in/go-playground/validator.v9"
|
||||||
|
|
||||||
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"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/ethereum/go-ethereum/params"
|
||||||
|
@ -502,6 +503,11 @@ type NodeConfig struct {
|
||||||
OutputMessageCSVEnabled bool
|
OutputMessageCSVEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TokenOverride struct {
|
||||||
|
Symbol string `json:"symbol"`
|
||||||
|
Address common.Address `json:"address"`
|
||||||
|
}
|
||||||
|
|
||||||
type Network struct {
|
type Network struct {
|
||||||
ChainID uint64 `json:"chainId"`
|
ChainID uint64 `json:"chainId"`
|
||||||
ChainName string `json:"chainName"`
|
ChainName string `json:"chainName"`
|
||||||
|
@ -516,6 +522,7 @@ type Network struct {
|
||||||
Enabled bool `json:"enabled"`
|
Enabled bool `json:"enabled"`
|
||||||
ChainColor string `json:"chainColor"`
|
ChainColor string `json:"chainColor"`
|
||||||
ShortName string `json:"shortName"`
|
ShortName string `json:"shortName"`
|
||||||
|
TokenOverrides []TokenOverride `json:"tokenOverrides"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// WalletConfig extra configuration for wallet.Service.
|
// WalletConfig extra configuration for wallet.Service.
|
||||||
|
|
|
@ -71,6 +71,7 @@ func (nq *networksQuery) exec(db *sql.DB) ([]*params.Network, error) {
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
networks []params.Network
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewManager(db *sql.DB) *Manager {
|
func NewManager(db *sql.DB) *Manager {
|
||||||
|
@ -92,6 +93,7 @@ func (nm *Manager) Init(networks []params.Network) error {
|
||||||
if networks == nil {
|
if networks == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
nm.networks = networks
|
||||||
|
|
||||||
var errors string
|
var errors string
|
||||||
currentNetworks, _ := nm.Get(false)
|
currentNetworks, _ := nm.Get(false)
|
||||||
|
@ -175,3 +177,7 @@ func (nm *Manager) Get(onlyEnabled bool) ([]*params.Network, error) {
|
||||||
|
|
||||||
return query.exec(nm.db)
|
return query.exec(nm.db)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (nm *Manager) GetConfiguredNetworks() []params.Network {
|
||||||
|
return nm.networks
|
||||||
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func NewService(
|
||||||
cryptoOnRampManager := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
cryptoOnRampManager := NewCryptoOnRampManager(&CryptoOnRampOptions{
|
||||||
dataSourceType: DataSourceStatic,
|
dataSourceType: DataSourceStatic,
|
||||||
})
|
})
|
||||||
tokenManager := &TokenManager{db: db, RPCClient: rpcClient, networkManager: rpcClient.NetworkManager}
|
tokenManager := NewTokenManager(db, rpcClient, rpcClient.NetworkManager)
|
||||||
savedAddressesManager := &SavedAddressesManager{db: db}
|
savedAddressesManager := &SavedAddressesManager{db: db}
|
||||||
transactionManager := &TransactionManager{db: db, transactor: transactor, gethManager: gethManager, config: config, accountsDB: accountsDB}
|
transactionManager := &TransactionManager{db: db, transactor: transactor, gethManager: gethManager, config: config, accountsDB: accountsDB}
|
||||||
transferController := transfer.NewTransferController(db, rpcClient, accountFeed)
|
transferController := transfer.NewTransferController(db, rpcClient, accountFeed)
|
||||||
|
|
|
@ -41,6 +41,35 @@ type TokenManager struct {
|
||||||
networkManager *network.Manager
|
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 {
|
func (tm *TokenManager) findSNT(chainID uint64) *Token {
|
||||||
tokensMap, ok := tokenStore[chainID]
|
tokensMap, ok := tokenStore[chainID]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
Loading…
Reference in New Issue