Skip to content

Commit 79548e5

Browse files
committed
feat: add source/target to underlying_transaction table
1 parent 3e1fd3f commit 79548e5

File tree

5 files changed

+21
-6
lines changed

5 files changed

+21
-6
lines changed

packages/fasset-indexer-core/src/orm/entities/underlying/transaction.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Entity, ManyToOne, PrimaryKey, Property } from "@mikro-orm/core"
22
import { UnderlyingBlock } from "./block"
33
import { uint256 } from "../../custom/uint"
4+
import { UnderlyingAddress } from "./address"
45

56

67
@Entity()
@@ -18,10 +19,18 @@ export class UnderlyingTransaction {
1819
@Property({ type: new uint256() })
1920
value: bigint
2021

21-
constructor(block: UnderlyingBlock, hash: string, value: bigint) {
22+
@ManyToOne({ entity: () => UnderlyingAddress, nullable: true })
23+
source?: UnderlyingAddress
24+
25+
@ManyToOne({ entity: () => UnderlyingAddress, nullable: true })
26+
target?: UnderlyingAddress
27+
28+
constructor(block: UnderlyingBlock, hash: string, value: bigint, source?: UnderlyingAddress, target?: UnderlyingAddress) {
2229
this.block = block
2330
this.hash = hash
2431
this.value = value
32+
this.source = source
33+
this.target = target
2534
}
2635

2736
}

packages/fasset-indexer-core/src/orm/utils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export async function findOrCreateUnderlyingAddress(em: EntityManager, address:
4848
return underlyingAddress
4949
}
5050

51-
export async function findOrCreateUnderlyingTransaction(em: EntityManager, hash: string, block: UnderlyingBlock, value: bigint): Promise<UnderlyingTransaction> {
51+
export async function findOrCreateUnderlyingTransaction(
52+
em: EntityManager, hash: string, block: UnderlyingBlock, value: bigint,
53+
source: UnderlyingAddress, target?: UnderlyingAddress
54+
): Promise<UnderlyingTransaction> {
5255
let underlyingTransaction = await em.findOne(UnderlyingTransaction, { hash })
5356
if (!underlyingTransaction) {
5457
underlyingTransaction = new UnderlyingTransaction(block, hash, value)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class DogeIndexer {
8888
private async storeVoutReference(
8989
em: EntityManager, reference: string, transaction: IDogeTx, address: UnderlyingAddress, block: UnderlyingBlock
9090
): Promise<UnderlyingVoutReference> {
91-
const tx = await findOrCreateUnderlyingTransaction(em, transaction.hash, block, BigInt(0))
91+
const tx = await findOrCreateUnderlyingTransaction(em, transaction.hash, block, BigInt(0), address, undefined)
9292
const ref = new UnderlyingVoutReference(FAssetType.FDOGE, reference, tx, address, block)
9393
em.persist(ref)
9494
return ref

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export interface IXrpTransaction {
2020
Sequence: number
2121
hash: string
2222
TransactionResult: string
23+
Destination?: string
2324
}
2425

2526
export interface IXrpMemo {

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ export class XrpIndexer {
6767
logger.error(`reference but no account present at index ${block.height}`)
6868
continue
6969
}
70-
const address = await findOrCreateUnderlyingAddress(em, transaction.Account, AddressType.AGENT)
71-
const utransaction = await findOrCreateUnderlyingTransaction(em, transaction.hash, block, BigInt(transaction.Amount!))
72-
await this.storeReference(em, reference, utransaction, address, block)
70+
const source = await findOrCreateUnderlyingAddress(em, transaction.Account, AddressType.AGENT)
71+
const target = transaction.Destination == null ? undefined :
72+
await findOrCreateUnderlyingAddress(em, transaction.Destination, AddressType.USER)
73+
const utransaction = await findOrCreateUnderlyingTransaction(em, transaction.hash, block, BigInt(transaction.Amount!), source, target)
74+
await this.storeReference(em, reference, utransaction, source, block)
7375
break
7476
}
7577
}

0 commit comments

Comments
 (0)