Skip to content

Commit

Permalink
feat(indy-vdr): ability to refresh the pool manually (openwallet-foun…
Browse files Browse the repository at this point in the history
…dation#1623)

Signed-off-by: wadeking98 <wkingnumber2@gmail.com>
Signed-off-by: Martin Auer <martin.auer97@gmail.com>
  • Loading branch information
wadeking98 authored and auer-martin committed Nov 15, 2023
1 parent ae0f413 commit 8272101
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
15 changes: 15 additions & 0 deletions packages/indy-vdr/src/IndyVdrApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ export class IndyVdrApi {
return signRequest(this.agentContext, pool, request, submitterDid)
}

/**
* This method refreshes the pool connection and ensures the pool is up to date with the ledger.
*/
public refreshPoolConnections() {
return this.indyVdrPoolService.refreshPoolConnections()
}

/**
* This method gets the updated transactions of the pool.
* @returns The transactions of the pool ledger
*/
public getAllPoolTransactions() {
return this.indyVdrPoolService.getAllPoolTransactions()
}

/**
* This method endorses a transaction. The transaction can be either a string or a JSON object.
* If the transaction has a signature, it means the transaction was created by another author and will be endorsed.
Expand Down
2 changes: 1 addition & 1 deletion packages/indy-vdr/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export {
IndyVdrDidCreateResult,
IndyVdrDidCreateOptions,
} from './dids'
export { IndyVdrPoolConfig } from './pool'
export { IndyVdrPoolConfig, IndyVdrPoolService } from './pool'
export * from './IndyVdrModule'
export * from './IndyVdrModuleConfig'
export * from './anoncreds'
16 changes: 16 additions & 0 deletions packages/indy-vdr/src/pool/IndyVdrPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ export class IndyVdrPool {
})
}

/**
* Refreshes the connection to the pool.
*/
public async refreshConnection(): Promise<void> {
if (this._pool) {
await this._pool.refresh()
}
}

/**
* Get the transactions for a pool
*/
public get transactions() {
return this.pool.transactions
}

private get pool(): indyVdrPool {
if (!this._pool) this.connect()
if (!this._pool) throw new IndyVdrError('Pool is not connected.')
Expand Down
14 changes: 14 additions & 0 deletions packages/indy-vdr/src/pool/IndyVdrPoolService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ export class IndyVdrPoolService {
}
}

/**
* Refresh the pool connections asynchronously
*/
public refreshPoolConnections() {
return Promise.allSettled(this.pools.map((pool) => pool.refreshConnection()))
}

/**
* Get all pool transactions
*/
public getAllPoolTransactions() {
return Promise.allSettled(this.pools.map((pool) => pool.transactions))
}

/**
* Get the most appropriate pool for the given indyNamespace
*/
Expand Down

0 comments on commit 8272101

Please sign in to comment.