Skip to content

Commit 6932ae5

Browse files
committed
feat: add ripple indexer
1 parent 443d145 commit 6932ae5

File tree

24 files changed

+1084
-52
lines changed

24 files changed

+1084
-52
lines changed

compose.yaml

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ x-templates:
55
db-postgres:
66
condition: service_healthy
77
restart: unless-stopped
8+
postgres-env: &postgres-env
9+
DB_TYPE: postgres
10+
DB_HOST: db-postgres
11+
DB_PORT: 5432
12+
DB_NAME: ${POSTGRES_DB}
13+
DB_USER: ${POSTGRES_USER}
14+
DB_PASSWORD: ${POSTGRES_PASSWORD}
815

916
services:
1017
core:
@@ -13,12 +20,7 @@ services:
1320
profiles: ["core"]
1421
command: ["node", "/app/packages/fasset-indexer-core/dist/src/run/run-indexer.js"]
1522
environment:
16-
DB_TYPE: postgres
17-
DB_HOST: db-postgres
18-
DB_PORT: 5432
19-
DB_NAME: ${POSTGRES_DB}
20-
DB_USER: ${POSTGRES_USER}
21-
DB_PASSWORD: ${POSTGRES_PASSWORD}
23+
<<: *postgres-env
2224
CHAIN: ${CHAIN}
2325
RPC_URL: ${RPC_URL}
2426
RPC_API_KEY: ${RPC_API_KEY:-}
@@ -31,12 +33,7 @@ services:
3133
profiles: ["watchdog"]
3234
command: ["node", "/app/packages/fasset-indexer-core/dist/src/run/run-watchdog.js"]
3335
environment:
34-
DB_TYPE: postgres
35-
DB_HOST: db-postgres
36-
DB_PORT: 5432
37-
DB_NAME: ${POSTGRES_DB}
38-
DB_USER: ${POSTGRES_USER}
39-
DB_PASSWORD: ${POSTGRES_PASSWORD}
36+
<<: *postgres-env
4037
CHAIN: ${CHAIN}
4138
RPC_URL: ${RPC_URL}
4239
RPC_API_KEY: ${RPC_API_KEY:-}
@@ -46,40 +43,38 @@ services:
4643
profiles: ["dogecoin"]
4744
command: ["node", "/app/packages/fasset-indexer-doge/dist/src/run/run-indexer.js"]
4845
environment:
49-
DB_TYPE: postgres
50-
DB_HOST: db-postgres
51-
DB_PORT: 5432
52-
DB_NAME: ${POSTGRES_DB}
53-
DB_USER: ${POSTGRES_USER}
54-
DB_PASSWORD: ${POSTGRES_PASSWORD}
46+
<<: *postgres-env
5547
DOGE_RPC_URL: ${DOGE_RPC_URL}
5648
DOGE_RPC_API_KEY: ${DOGE_RPC_API_KEY:-}
5749
DOGE_RPC_USER: ${DOGE_RPC_USER:-}
5850
DOGE_RPC_PASSWORD: ${DOGE_RPC_PASSWORD:-}
5951
DOGE_MIN_BLOCK_NUMBER: ${DOGE_MIN_BLOCK_NUMBER}
52+
ripple:
53+
<<: *base-svc
54+
container_name: ${COMPOSE_PROJECT_NAME}-ripple
55+
profiles: ["ripple"]
56+
command: ["node", "/app/packages/fasset-indexer-xrp/dist/src/run/run-indexer.js"]
57+
environment:
58+
<<: *postgres-env
59+
XRP_RPC_URL: ${XRP_RPC_URL}
60+
XRP_RPC_API_KEY: ${XRP_RPC_API_KEY:-}
61+
XRP_MIN_BLOCK_NUMBER: ${XRP_MIN_BLOCK_NUMBER}
6062
api:
6163
<<: *base-svc
6264
container_name: ${COMPOSE_PROJECT_NAME}-api
6365
profiles: ["api"]
6466
command: ["node", "/app/packages/fasset-indexer-api/dist/src/main"]
6567
environment:
66-
DB_TYPE: postgres
67-
DB_HOST: db-postgres
68-
DB_PORT: 5432
69-
DB_NAME: ${POSTGRES_DB}
70-
DB_USER: ${POSTGRES_USER}
71-
DB_PASSWORD: ${POSTGRES_PASSWORD}
68+
<<: *postgres-env
7269
API_ROOT_PATH: ${API_ROOT_PATH:-}
7370
ports:
7471
- "${API_PORT}:3000"
7572
db-postgres:
7673
image: postgres:16
7774
container_name: ${COMPOSE_PROJECT_NAME}-db
78-
profiles: ["core", "watchdog", "dogecoin", "api"]
75+
profiles: ["core", "watchdog", "api", "ripple", "dogecoin"]
7976
environment:
80-
POSTGRES_DB: ${POSTGRES_DB}
81-
POSTGRES_USER: ${POSTGRES_USER}
82-
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
77+
<<: *postgres-env
8378
volumes:
8479
- 'db_data:/var/lib/postgresql/data'
8580
healthcheck:

fasset-indexer.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"name": "🚀 api",
1313
"path": "packages/fasset-indexer-api"
1414
},
15+
{
16+
"name": "✕ xrp",
17+
"path": "packages/fasset-indexer-xrp"
18+
},
1519
{
1620
"name": "🐶 doge",
1721
"path": "packages/fasset-indexer-doge"

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"run-native-indexer": "yarn build-base && node packages/fasset-indexer-core/dist/src/run/run-indexer.js",
2020
"run-native-indexer-debug": "ts-node packages/fasset-indexer-core/src/run/run-indexer.ts",
2121
"run-native-watchdog": "yarn build-base && node packages/fasset-indexer-core/dist/src/run/run-watchdog.js",
22+
"run-xrp-indexer": "yarn build-base && node packages/fasset-indexer-xrp/dist/src/run/run-indexer.js",
2223
"run-btc-indexer": "yarn build-base && node packages/fasset-indexer-btc/dist/src/run/run-indexer.js",
2324
"run-doge-indexer": "yarn build-base && node packages/fasset-indexer-doge/dist/src/run/run-indexer.js",
2425
"run-api": "yarn build && node packages/fasset-indexer-api/dist/src/main",

packages/fasset-indexer-core/src/orm/entities/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export { AssetManagerSettings } from './state/settings'
4141
// underlying data
4242
export { UnderlyingBlock } from "./underlying/block"
4343
export { UnderlyingAddress } from "./underlying/address"
44-
export { UnderlyingVoutReference } from "./underlying/reference"
44+
export { UnderlyingReference as UnderlyingVoutReference } from "./underlying/reference"
45+
export { UnderlyingTransaction } from "./underlying/transaction"
4546
// building event bound stuff
4647
export { EventBound, FAssetEventBound } from "./events/_bound"

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ import { Entity, ManyToOne, Property, PrimaryKey, Unique, Enum } from "@mikro-or
22
import { UnderlyingBlock } from "./block"
33
import { UnderlyingAddress } from "../underlying/address"
44
import { FAssetType } from "../../../shared"
5+
import { UnderlyingTransaction } from "./transaction"
56

67

78
@Entity()
8-
@Unique({ properties: ['fasset', 'block', 'reference', 'transactionHash'] })
9-
export class UnderlyingVoutReference {
9+
@Unique({ properties: ['fasset', 'block', 'reference', 'transaction'] })
10+
export class UnderlyingReference {
1011

1112
@PrimaryKey({ autoincrement: true, type: 'integer' })
1213
id!: number
@@ -17,19 +18,19 @@ export class UnderlyingVoutReference {
1718
@Property({ type: 'text' })
1819
reference: string
1920

20-
@Property({ type: 'text' })
21-
transactionHash: string
21+
@ManyToOne({ entity: () => UnderlyingTransaction })
22+
transaction: UnderlyingTransaction
2223

2324
@ManyToOne(() => UnderlyingAddress)
2425
address: UnderlyingAddress
2526

2627
@ManyToOne(() => UnderlyingBlock)
2728
block: UnderlyingBlock
2829

29-
constructor(fasset: FAssetType, reference: string, transactionHash: string, address: UnderlyingAddress, block: UnderlyingBlock) {
30+
constructor(fasset: FAssetType, reference: string, transaction: UnderlyingTransaction, address: UnderlyingAddress, block: UnderlyingBlock) {
3031
this.fasset = fasset
3132
this.reference = reference
32-
this.transactionHash = transactionHash
33+
this.transaction = transaction
3334
this.address = address
3435
this.block = block
3536
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Entity, ManyToOne, PrimaryKey, Property } from "@mikro-orm/core"
2+
import { UnderlyingBlock } from "./block"
3+
import { uint256 } from "../../custom/uint"
4+
5+
6+
@Entity()
7+
export class UnderlyingTransaction {
8+
9+
@PrimaryKey({ type: 'integer', autoincrement: true })
10+
id!: number
11+
12+
@ManyToOne({ entity: () => UnderlyingBlock })
13+
block: UnderlyingBlock
14+
15+
@Property({ type: 'text', unique: true })
16+
hash: string
17+
18+
@Property({ type: new uint256() })
19+
value: bigint
20+
21+
constructor(block: UnderlyingBlock, hash: string, value: bigint) {
22+
this.block = block
23+
this.hash = hash
24+
this.value = value
25+
}
26+
27+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ export { createOrm } from "./mikro-orm.config"
22
export { raw } from "@mikro-orm/core"
33
export { EntityManager, SelectQueryBuilder } from "@mikro-orm/knex"
44
export { ZeroAddress } from 'ethers' // for database lookup
5-
export { getVar, setVar, findOrCreateUnderlyingAddress } from "./utils"
5+
export { getVar, setVar, findOrCreateUnderlyingAddress, findOrCreateUnderlyingTransaction } from "./utils"
66
export { OrmOptions, ORM, AddressType } from "./interface"

packages/fasset-indexer-core/src/orm/mikro-orm.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import { FtsoPrice } from "./entities/state/price"
5151
import { TokenBalance } from "./entities/state/balance"
5252
import { UnderlyingBlock } from "./entities/underlying/block"
5353
import { UnderlyingAddress } from "./entities/underlying/address"
54-
import { UnderlyingVoutReference } from "./entities/underlying/reference"
54+
import { UnderlyingReference } from "./entities/underlying/reference"
5555
import { updateSchema } from "./utils"
5656
import { MIN_DATABASE_POOL_CONNECTIONS, MAX_DATABASE_POOL_CONNECTIONS } from "../config/constants"
5757
import type { Options } from "@mikro-orm/core"
@@ -86,7 +86,7 @@ export const ORM_OPTIONS: Options<AbstractSqlDriver> = defineConfig({
8686
EscrowFinished, CoreVaultManagerCustodianAddressUpdated,
8787
AssetManagerSettings, CoreVaultManagerSettings,
8888
// underlying
89-
UnderlyingBlock, UnderlyingVoutReference, UnderlyingAddress
89+
UnderlyingBlock, UnderlyingReference, UnderlyingAddress
9090
],
9191
pool: {
9292
min: MIN_DATABASE_POOL_CONNECTIONS,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Var } from "../orm/entities/state/var"
22
import { UnderlyingAddress } from "../orm/entities/underlying/address"
33
import type { EntityManager } from "@mikro-orm/core"
44
import type { ORM, SchemaUpdate, AddressType } from "./interface"
5+
import { UnderlyingBlock, UnderlyingTransaction } from "./entities";
56

67

78
export async function updateSchema(orm: ORM, update: SchemaUpdate = "full"): Promise<void> {
@@ -45,4 +46,13 @@ export async function findOrCreateUnderlyingAddress(em: EntityManager, address:
4546
em.persist(underlyingAddress)
4647
}
4748
return underlyingAddress
49+
}
50+
51+
export async function findOrCreateUnderlyingTransaction(em: EntityManager, hash: string, block: UnderlyingBlock, value: bigint): Promise<UnderlyingTransaction> {
52+
let underlyingTransaction = await em.findOne(UnderlyingTransaction, { hash })
53+
if (!underlyingTransaction) {
54+
underlyingTransaction = new UnderlyingTransaction(block, hash, value)
55+
em.persist(underlyingTransaction)
56+
}
57+
return underlyingTransaction
4858
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
export namespace PaymentReference {
33
export const TYPE_SHIFT = BigInt(192)
44
export const LOW_BITS_MASK = (BigInt(1) << TYPE_SHIFT) - BigInt(1)
5-
65
// common prefix 0x464250526641 = hex('FBPRfA' - Flare Bridge Payment Reference / fAsset)
76

87
export function isValid(reference: string | null): reference is string {

0 commit comments

Comments
 (0)