From 5d2dd39c163249762e448de480aacce021934aa5 Mon Sep 17 00:00:00 2001 From: Brian Stafford Date: Tue, 31 Jan 2023 07:26:55 -0600 Subject: [PATCH] add supported assets to token info --- client/asset/driver.go | 7 ++++--- client/asset/eth/eth.go | 8 ++++---- client/asset/interface.go | 3 ++- client/webserver/site/src/js/registry.ts | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/client/asset/driver.go b/client/asset/driver.go index 7c00b6be3b..25824f9835 100644 --- a/client/asset/driver.go +++ b/client/asset/driver.go @@ -82,7 +82,7 @@ func Register(assetID uint32, driver Driver) { // RegisterToken should be called to register tokens. If no nets are specified // the token will be registered for all networks. The user must invoke // SetNetwork to enable net-based filtering of package function output. -func RegisterToken(tokenID uint32, token *dex.Token, walletDef *WalletDefinition, nets ...dex.Network) { +func RegisterToken(tokenID uint32, token *dex.Token, walletDef *WalletDefinition, supportedVersions []uint32, nets ...dex.Network) { driversMtx.Lock() defer driversMtx.Unlock() if _, exists := tokens[tokenID]; exists { @@ -94,8 +94,9 @@ func RegisterToken(tokenID uint32, token *dex.Token, walletDef *WalletDefinition } tokens[tokenID] = &nettedToken{ Token: &Token{ - Token: token, - Definition: walletDef, + Token: token, + Definition: walletDef, + SupportedVersions: supportedVersions, }, nets: nets, } diff --git a/client/asset/eth/eth.go b/client/asset/eth/eth.go index f85921064d..7f81774a89 100644 --- a/client/asset/eth/eth.go +++ b/client/asset/eth/eth.go @@ -53,7 +53,7 @@ func registerToken(tokenID uint32, desc string, nets ...dex.Network) { asset.RegisterToken(tokenID, token.Token, &asset.WalletDefinition{ Type: "token", Description: desc, - }, nets...) + }, SupportedTokenVersions, nets...) } func init() { @@ -138,6 +138,8 @@ var ( }, } + SupportedTokenVersions = []uint32{0} // Server versions that we can handle. + chainIDs = map[dex.Network]int64{ dex.Mainnet: 1, dex.Testnet: 5, // Görli @@ -492,11 +494,9 @@ func (w *ETHWallet) Info() *asset.WalletInfo { // Info returns basic information about the wallet and asset. func (w *TokenWallet) Info() *asset.WalletInfo { var bestVer uint32 - var vers []uint32 netToken := w.token.NetTokens[w.net] if netToken != nil { for ver := range netToken.SwapContracts { - vers = append(vers, ver) if ver > bestVer { bestVer = ver } @@ -506,7 +506,7 @@ func (w *TokenWallet) Info() *asset.WalletInfo { return &asset.WalletInfo{ Name: w.token.Name, Version: bestVer, - SupportedVersions: vers, + SupportedVersions: SupportedTokenVersions, UnitInfo: w.token.UnitInfo, MaxSwapsInTx: w.maxSwapsInTx, MaxRedeemsInTx: w.maxRedeemsInTx, diff --git a/client/asset/interface.go b/client/asset/interface.go index 5c1627f864..09fa854275 100644 --- a/client/asset/interface.go +++ b/client/asset/interface.go @@ -198,7 +198,8 @@ type WalletDefinition struct { // Token combines the generic dex.Token with a WalletDefinition. type Token struct { *dex.Token - Definition *WalletDefinition `json:"definition"` + Definition *WalletDefinition `json:"definition"` + SupportedVersions []uint32 `json:"supportedVersions"` } // WalletInfo is auxiliary information about an ExchangeWallet. diff --git a/client/webserver/site/src/js/registry.ts b/client/webserver/site/src/js/registry.ts index 5d9f102627..adb508ae2b 100644 --- a/client/webserver/site/src/js/registry.ts +++ b/client/webserver/site/src/js/registry.ts @@ -167,6 +167,7 @@ export interface Token { name: string unitInfo: UnitInfo definition: WalletDefinition + supportedVersions: number[] } export interface WalletState { @@ -189,7 +190,8 @@ export interface WalletState { export interface WalletInfo { name: string - version: number + version: number // deprecated + versions: number[] // new field for supported server versions availablewallets: WalletDefinition[] emptyidx: number unitinfo: UnitInfo