-
Notifications
You must be signed in to change notification settings - Fork 12
feat(wallet-gateway-remote): added connectivity status to login #1003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
5bb518a
9d76728
9f85ed2
e3400ed
0935ba2
3a573d0
e98fbc1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ | |
| "title": "networks", | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/Network" | ||
| "$ref": "#/components/schemas/VerifiedNetwork" | ||
| } | ||
| } | ||
| }, | ||
|
|
@@ -553,6 +553,28 @@ | |
| "type": "string", | ||
| "description": "The unique identifier of the command associated with the transaction." | ||
| }, | ||
| "VerifiedNetwork": { | ||
| "title": "VerifiedNetwork", | ||
| "description": "Structure representing the Networks with connectivity verification", | ||
| "allOf": [ | ||
| { | ||
| "$ref": "#/components/schemas/Network" | ||
| }, | ||
| { | ||
| "title": "VerifiedNetworkProperties", | ||
| "description": "holder for boolean verified property", | ||
| "type": "object", | ||
| "properties": { | ||
| "verified": { | ||
| "title": "verified", | ||
| "description": "true if we could succesfully call the ledger version endpoint", | ||
| "type": "boolean" | ||
| } | ||
| }, | ||
| "required": ["verified"] | ||
| } | ||
| ] | ||
| }, | ||
|
Comment on lines
+556
to
+577
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this need a separate schema, rather than adding an optional "verified" to Network itself? |
||
| "Network": { | ||
| "title": "Network", | ||
| "type": "object", | ||
|
|
@@ -591,8 +613,16 @@ | |
| }, | ||
| "ledgerApi": { | ||
| "title": "ledgerApi", | ||
| "type": "string", | ||
| "description": "Ledger api url" | ||
| "type": "object", | ||
| "description": "Ledger api url", | ||
| "properties": { | ||
| "baseUrl": { | ||
| "title": "baseUrl", | ||
| "type": "string", | ||
| "description": "Ledger api url" | ||
| } | ||
| }, | ||
| "required": ["baseUrl"] | ||
| } | ||
| }, | ||
| "required": [ | ||
|
|
@@ -609,7 +639,7 @@ | |
| "title": "Idp", | ||
| "description": "Structure representing the Identity Providers", | ||
| "type": "object", | ||
| "properties": { | ||
|
Check failure on line 642 in api-specs/openrpc-user-api.json
|
||
| "id": { | ||
| "title": "id", | ||
| "type": "string", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,11 @@ export const storeConfigSchema = z.object({ | |
| networks: z.array(networkSchema), | ||
| }) | ||
|
|
||
| export const verifiedNetworkSchema = networkSchema.extend({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, I don't think this has anything to do with the |
||
| verified: z.boolean(), | ||
| }) | ||
|
|
||
| export type StoreConfig = z.infer<typeof storeConfigSchema> | ||
| export type Network = z.infer<typeof networkSchema> | ||
| export type VerifiedNetwork = z.infer<typeof verifiedNetworkSchema> | ||
| export type LedgerApi = z.infer<typeof ledgerApiSchema> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ | |
| "title": "networks", | ||
| "type": "array", | ||
| "items": { | ||
| "$ref": "#/components/schemas/Network" | ||
| "$ref": "#/components/schemas/VerifiedNetwork" | ||
| } | ||
| } | ||
| }, | ||
|
|
@@ -553,6 +553,28 @@ | |
| "type": "string", | ||
| "description": "The unique identifier of the command associated with the transaction." | ||
| }, | ||
| "VerifiedNetwork": { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The term
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hahaha, I just had the same comment. Didn't think about EDIT: or plain |
||
| "title": "VerifiedNetwork", | ||
| "description": "Structure representing the Networks with connectivity verification", | ||
| "allOf": [ | ||
| { | ||
| "$ref": "#/components/schemas/Network" | ||
| }, | ||
| { | ||
| "title": "VerifiedNetworkProperties", | ||
| "description": "holder for boolean verified property", | ||
| "type": "object", | ||
| "properties": { | ||
| "verified": { | ||
| "title": "verified", | ||
| "description": "true if we could succesfully call the ledger version endpoint", | ||
| "type": "boolean" | ||
| } | ||
| }, | ||
| "required": ["verified"] | ||
| } | ||
| ] | ||
| }, | ||
| "Network": { | ||
| "title": "Network", | ||
| "type": "object", | ||
|
|
@@ -591,8 +613,16 @@ | |
| }, | ||
| "ledgerApi": { | ||
| "title": "ledgerApi", | ||
| "type": "string", | ||
| "description": "Ledger api url" | ||
| "type": "object", | ||
| "description": "Ledger api url", | ||
| "properties": { | ||
| "baseUrl": { | ||
| "title": "baseUrl", | ||
| "type": "string", | ||
| "description": "Ledger api url" | ||
| } | ||
| }, | ||
| "required": ["baseUrl"] | ||
| } | ||
| }, | ||
| "required": [ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { LedgerClient } from '@canton-network/core-ledger-client' | ||
| import { Logger } from 'pino' | ||
| import { NetworkCacheStore } from '../cache/network-cache.js' | ||
|
|
||
| export async function startLedgerConnectivityTester( | ||
| networkCacheStore: NetworkCacheStore, | ||
| logger: Logger | ||
| ) { | ||
| const networks = await networkCacheStore.getStore().listNetworks() | ||
|
|
||
| networks.map(async (network) => { | ||
| try { | ||
| logger.debug( | ||
| `Testing connectivity for network ${network.name} (${network.id})...` | ||
| ) | ||
|
|
||
| //connectivity test | ||
| const ledgerClient = new LedgerClient({ | ||
| baseUrl: new URL(network.ledgerApi.baseUrl), | ||
| logger: logger, | ||
| }) | ||
| let connectivityCheck = false | ||
|
|
||
| try { | ||
| const version = await ledgerClient.get('/v2/version') | ||
| if (version.version) { | ||
| connectivityCheck = true | ||
| } | ||
| } catch (error) { | ||
| logger.debug( | ||
| `Failed to connect to ledger at ${network.name}(${network.ledgerApi.baseUrl}): ${JSON.stringify(error)}` | ||
| ) | ||
| } | ||
|
|
||
| networkCacheStore.getCache().set(network.id, { | ||
| ...network, | ||
| verified: connectivityCheck, | ||
| }) | ||
| logger.info( | ||
| connectivityCheck | ||
| ? `Network ${network.name} (${network.id}) verified successfully.` | ||
| : `Network ${network.name} (${network.id}) verification failed.` | ||
| ) | ||
| } catch (error) { | ||
| logger.error( | ||
| `Failed to verify network ${network.name} (${network.id}): ${error}` | ||
| ) | ||
| } | ||
| }) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { LRUCache } from 'typescript-lru-cache' | ||
| import { | ||
| Store, | ||
| Network, | ||
| VerifiedNetwork, | ||
| } from '@canton-network/core-wallet-store' | ||
| import { Logger } from 'pino' | ||
|
|
||
| export const DEFAULT_MAX_CACHE_SIZE = 100 | ||
| export const DEFAULT_ENTRY_EXPIRATION_TIME = 10 * 60 * 1000 | ||
|
|
||
| const NetworkCache = new LRUCache<string, VerifiedNetwork>({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not simply cache the status for each network With This way, when listing existing networks, nothing needs to change, except for an additional cache lookup to get the status. |
||
| maxSize: DEFAULT_MAX_CACHE_SIZE, | ||
| entryExpirationTimeInMS: DEFAULT_ENTRY_EXPIRATION_TIME, | ||
| }) | ||
|
|
||
| export class NetworkCacheStore { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see the benefit of this. I'd separate concerns and only cache the |
||
| constructor( | ||
| private readonly store: Store, | ||
| private readonly logger: Logger | ||
| ) {} | ||
|
Comment on lines
+20
to
+24
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need all this? I'm wondering why not decouple the cache from the underlying store? The network cache can just store In the controller you retrieve the network from the store directly, and merge based on ID to include the verified status
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we wanted to go all out, we might even feel inclined to design a |
||
|
|
||
| getCache() { | ||
| return NetworkCache | ||
| } | ||
|
|
||
| getStore() { | ||
| return this.store | ||
| } | ||
|
|
||
| async getNetwork(networkId: string): Promise<VerifiedNetwork> { | ||
| const cachedNetwork = NetworkCache.get(networkId) | ||
| if (cachedNetwork) { | ||
| return cachedNetwork | ||
| } | ||
| return await this.store.getNetwork(networkId) | ||
| } | ||
|
|
||
| getCurrentNetwork(): Promise<VerifiedNetwork> { | ||
| return this.store.getCurrentNetwork() | ||
| } | ||
|
|
||
| listNetworks(): Promise<Array<VerifiedNetwork>> { | ||
| if (NetworkCache.size !== 0) { | ||
| return Promise.resolve(NetworkCache.values().toArray()) | ||
| } | ||
| return this.store.listNetworks() | ||
| } | ||
|
|
||
| updateNetwork(network: Network): Promise<void> { | ||
| NetworkCache.set(network.id, { | ||
| ...network, | ||
| verified: false, | ||
| }) | ||
|
|
||
| return this.store.updateNetwork(network) | ||
| } | ||
|
|
||
| addNetwork(network: Network): Promise<void> { | ||
| NetworkCache.set(network.id, { | ||
| ...network, | ||
| verified: false, | ||
| }) | ||
|
|
||
| return this.store.addNetwork(network) | ||
| } | ||
| removeNetwork(networkId: string): Promise<void> { | ||
| NetworkCache.delete(networkId) | ||
|
|
||
| return this.store.removeNetwork(networkId) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.