Skip to content

Commit d664dce

Browse files
committed
feat: automatically track core vault xrp transactions
1 parent 62be3f6 commit d664dce

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

packages/fasset-indexer-xrp/src/indexer/xrp-indexer.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { XrpContext } from "../context"
1010

1111
export class XrpIndexer {
1212
private tracked = new Set<string>()
13+
private coreVaultLoaded: boolean = false
1314

1415
constructor(
1516
public readonly context: XrpContext,
@@ -26,14 +27,6 @@ export class XrpIndexer {
2627
return this.runHistoric(startBlock)
2728
}
2829

29-
async updateTrackedAddresses(): Promise<void> {
30-
const agents = await this.context.orm.em.fork().findAll(
31-
Entities.AgentVault, { populate: [ 'underlyingAddress' ] })
32-
for (const agent of agents) {
33-
this.tracked.add(agent.underlyingAddress.text)
34-
}
35-
}
36-
3730
async runHistoric(startBlock?: number, endBlock?: number): Promise<void> {
3831
const firstUnhandledBlock = await this.firstUnhandledBlock(startBlock)
3932
if (startBlock === undefined || firstUnhandledBlock > startBlock) {
@@ -78,6 +71,12 @@ export class XrpIndexer {
7871
await setVar(em, this.firstUnhandledBlockDbKey, block.toString())
7972
}
8073

74+
protected async updateTrackedAddresses(): Promise<void> {
75+
const em = this.context.orm.em.fork()
76+
await this.updateCoreVaultTracking(em)
77+
await this.updateAgentVaultTracking(em)
78+
}
79+
8180
protected async processBlock(block: IXrpBlock): Promise<void> {
8281
await this.context.orm.em.transactional(async em => {
8382
let blockEnt = await em.findOne(Entities.UnderlyingBlock, { hash: block.ledger_hash })
@@ -136,6 +135,25 @@ export class XrpIndexer {
136135
})
137136
}
138137

138+
private async updateCoreVaultTracking(em: EntityManager): Promise<void> {
139+
if (this.coreVaultLoaded) return
140+
const settings = await em.findOne(Entities.CoreVaultManagerSettings,
141+
{ fasset: FAssetType.FXRP }, { populate: ['coreVault'] }
142+
)
143+
if (settings != null && settings.coreVault != null) {
144+
this.tracked.add(settings.coreVault.text)
145+
this.coreVaultLoaded = true
146+
}
147+
}
148+
149+
private async updateAgentVaultTracking(em: EntityManager): Promise<void> {
150+
const agents = await em.findAll(
151+
Entities.AgentVault, { populate: [ 'underlyingAddress' ] })
152+
for (const agent of agents) {
153+
this.tracked.add(agent.underlyingAddress.text)
154+
}
155+
}
156+
139157
private async storeXrpBlock(em: EntityManager, xrpBlock: IXrpBlock): Promise<Entities.UnderlyingBlock> {
140158
return em.create(Entities.UnderlyingBlock, {
141159
hash: xrpBlock.ledger_hash, height: xrpBlock.ledger_index,

0 commit comments

Comments
 (0)