From fa7b4edb917b2e3bdd0b99ca04ea5d4db9b41f3b Mon Sep 17 00:00:00 2001 From: Tate Date: Wed, 15 Jan 2025 03:47:44 +0000 Subject: [PATCH] fix some bug --- .../soroban-futurenet-starter/package.json | 6 ++-- Stellar/soroban-greeter-contract/package.json | 4 +-- Stellar/soroban-greeter-contract/project.ts | 5 +-- .../src/mappings/mappingHandlers.ts | 6 ++-- Stellar/soroban-starter/docker-compose.yml | 1 + Stellar/soroban-starter/package.json | 9 ++--- Stellar/soroban-starter/project.ts | 2 +- .../src/mappings/mappingHandlers.ts | 34 +++++++++---------- Stellar/soroban-testnet-starter/package.json | 4 +-- 9 files changed, 37 insertions(+), 34 deletions(-) diff --git a/Stellar/soroban-futurenet-starter/package.json b/Stellar/soroban-futurenet-starter/package.json index 2e75aae..5e6c8ad 100644 --- a/Stellar/soroban-futurenet-starter/package.json +++ b/Stellar/soroban-futurenet-starter/package.json @@ -6,8 +6,8 @@ "scripts": { "build": "subql build", "codegen": "subql codegen", - "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "start:docker": "docker compose pull && docker compose up --remove-orphans", + "dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-stellar test" }, @@ -26,8 +26,8 @@ }, "devDependencies": { "@subql/cli": "latest", - "@subql/types": "latest", "@subql/testing": "latest", + "@subql/types": "latest", "typescript": "^5.2.2" } } diff --git a/Stellar/soroban-greeter-contract/package.json b/Stellar/soroban-greeter-contract/package.json index a0fbb03..887c4cd 100644 --- a/Stellar/soroban-greeter-contract/package.json +++ b/Stellar/soroban-greeter-contract/package.json @@ -6,8 +6,8 @@ "scripts": { "build": "subql build", "codegen": "subql codegen", - "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "start:docker": "docker compose pull && docker compose up --remove-orphans", + "dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-stellar test" }, diff --git a/Stellar/soroban-greeter-contract/project.ts b/Stellar/soroban-greeter-contract/project.ts index 718bfbf..7647f28 100644 --- a/Stellar/soroban-greeter-contract/project.ts +++ b/Stellar/soroban-greeter-contract/project.ts @@ -56,8 +56,9 @@ const project: StellarProject = { topics: [ "COUNT", // Topic signature(s) for the events, there can be up to 4 ], - contractId: "CAQFKAS47DF6RBKABRLDZ5O4XJIH2DQ3RMNHFPOSGLFI6KMSSIUIGQJ6" - } + contractId: + "CAQFKAS47DF6RBKABRLDZ5O4XJIH2DQ3RMNHFPOSGLFI6KMSSIUIGQJ6", + }, }, ], }, diff --git a/Stellar/soroban-greeter-contract/src/mappings/mappingHandlers.ts b/Stellar/soroban-greeter-contract/src/mappings/mappingHandlers.ts index c2a1328..43b7ee5 100644 --- a/Stellar/soroban-greeter-contract/src/mappings/mappingHandlers.ts +++ b/Stellar/soroban-greeter-contract/src/mappings/mappingHandlers.ts @@ -2,15 +2,15 @@ import { Increment } from "../types"; import { SorobanEvent } from "@subql/types-stellar"; export async function handleEvent(event: SorobanEvent): Promise { - logger.info(`Transaction hash: ${event.transaction.hash.toString()}`); + logger.info(`Transaction hash: ${event.transaction!.hash.toString()}`); if (event.type.toString() == "contract") { logger.info(`Event value: ${JSON.stringify(event.value)}`); const increment = Increment.create({ - id: event.transaction.hash, + id: event.transaction!.hash, newValue: BigInt( JSON.parse(JSON.stringify(event.value))["_value"].toString() ), }); await increment.save(); } -} \ No newline at end of file +} diff --git a/Stellar/soroban-starter/docker-compose.yml b/Stellar/soroban-starter/docker-compose.yml index 31f9912..769eab5 100644 --- a/Stellar/soroban-starter/docker-compose.yml +++ b/Stellar/soroban-starter/docker-compose.yml @@ -35,6 +35,7 @@ services: - ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests - -f=/app - --db-schema=app + - --unsafe - --workers=1 # The more the faster - --batch-size=5 # The higher the faster, set low to avoid rate limit on SDF endpoint healthcheck: diff --git a/Stellar/soroban-starter/package.json b/Stellar/soroban-starter/package.json index f64d8ec..01d3a3b 100644 --- a/Stellar/soroban-starter/package.json +++ b/Stellar/soroban-starter/package.json @@ -6,8 +6,8 @@ "scripts": { "build": "subql build", "codegen": "subql codegen", - "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "start:docker": "docker compose pull && docker compose up --remove-orphans", + "dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-stellar test" }, @@ -22,12 +22,13 @@ "license": "MIT", "dependencies": { "@subql/common": "latest", - "@subql/types-stellar": "latest" + "@subql/types-stellar": "latest", + "soroban-client": "^1.0.1" }, "devDependencies": { "@subql/cli": "latest", - "@subql/types": "latest", "@subql/testing": "latest", + "@subql/types": "latest", "typescript": "^5.2.2" } } diff --git a/Stellar/soroban-starter/project.ts b/Stellar/soroban-starter/project.ts index a48efa2..6fb3b67 100644 --- a/Stellar/soroban-starter/project.ts +++ b/Stellar/soroban-starter/project.ts @@ -3,7 +3,7 @@ import { StellarHandlerKind, StellarProject, } from "@subql/types-stellar"; -import { Horizon } from "stellar-sdk"; +import { Horizon } from "@stellar/stellar-sdk"; /* This is your project configuration */ const project: StellarProject = { diff --git a/Stellar/soroban-starter/src/mappings/mappingHandlers.ts b/Stellar/soroban-starter/src/mappings/mappingHandlers.ts index 0efb4fc..93c459d 100644 --- a/Stellar/soroban-starter/src/mappings/mappingHandlers.ts +++ b/Stellar/soroban-starter/src/mappings/mappingHandlers.ts @@ -7,8 +7,8 @@ import { import { AccountCredited, AccountDebited, -} from "stellar-sdk/lib/horizon/types/effects"; -import { Horizon } from "stellar-sdk"; +} from "@stellar/stellar-sdk/lib/horizon/types/effects"; +import { Horizon } from "@stellar/stellar-sdk"; import { Address, xdr } from "soroban-client"; export async function handleOperation( @@ -16,8 +16,8 @@ export async function handleOperation( ): Promise { logger.info(`Indexing operation ${op.id}, type: ${op.type}`); - const fromAccount = await checkAndGetAccount(op.from, op.ledger.sequence); - const toAccount = await checkAndGetAccount(op.to, op.ledger.sequence); + const fromAccount = await checkAndGetAccount(op.from, op.ledger!.sequence); + const toAccount = await checkAndGetAccount(op.to, op.ledger!.sequence); const payment = Payment.create({ id: op.id, @@ -27,8 +27,8 @@ export async function handleOperation( amount: op.amount, }); - fromAccount.lastSeenLedger = op.ledger.sequence; - toAccount.lastSeenLedger = op.ledger.sequence; + fromAccount.lastSeenLedger = op.ledger!.sequence; + toAccount.lastSeenLedger = op.ledger!.sequence; await Promise.all([fromAccount.save(), toAccount.save(), payment.save()]); } @@ -39,7 +39,7 @@ export async function handleCredit( const account = await checkAndGetAccount( effect.account, - effect.ledger.sequence + effect.ledger!.sequence ); const credit = Credit.create({ @@ -48,7 +48,7 @@ export async function handleCredit( amount: effect.amount, }); - account.lastSeenLedger = effect.ledger.sequence; + account.lastSeenLedger = effect.ledger!.sequence; await Promise.all([account.save(), credit.save()]); } @@ -59,7 +59,7 @@ export async function handleDebit( const account = await checkAndGetAccount( effect.account, - effect.ledger.sequence + effect.ledger!.sequence ); const debit = Debit.create({ @@ -68,13 +68,13 @@ export async function handleDebit( amount: effect.amount, }); - account.lastSeenLedger = effect.ledger.sequence; + account.lastSeenLedger = effect.ledger!.sequence; await Promise.all([account.save(), debit.save()]); } export async function handleEvent(event: SorobanEvent): Promise { logger.info( - `New transfer event found at block ${event.ledger.sequence.toString()}` + `New transfer event found at block ${event.ledger!.sequence.toString()}` ); // Get data from the event @@ -93,26 +93,26 @@ export async function handleEvent(event: SorobanEvent): Promise { const fromAccount = await checkAndGetAccount( decodeAddress(from), - event.ledger.sequence + event.ledger!.sequence ); const toAccount = await checkAndGetAccount( decodeAddress(to), - event.ledger.sequence + event.ledger!.sequence ); // Create the new transfer entity const transfer = Transfer.create({ id: event.id, - ledger: event.ledger.sequence, + ledger: event.ledger!.sequence, date: new Date(event.ledgerClosedAt), contract: event.contractId?.contractId().toString()!, fromId: fromAccount.id, toId: toAccount.id, - value: BigInt(event.value.decoded!), + value: BigInt(event.value.i64().toString()), }); - fromAccount.lastSeenLedger = event.ledger.sequence; - toAccount.lastSeenLedger = event.ledger.sequence; + fromAccount.lastSeenLedger = event.ledger!.sequence; + toAccount.lastSeenLedger = event.ledger!.sequence; await Promise.all([fromAccount.save(), toAccount.save(), transfer.save()]); } diff --git a/Stellar/soroban-testnet-starter/package.json b/Stellar/soroban-testnet-starter/package.json index b1e67e6..acefa76 100644 --- a/Stellar/soroban-testnet-starter/package.json +++ b/Stellar/soroban-testnet-starter/package.json @@ -6,8 +6,8 @@ "scripts": { "build": "subql build", "codegen": "subql codegen", - "start:docker": "docker-compose pull && docker-compose up --remove-orphans", - "dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans", + "start:docker": "docker compose pull && docker compose up --remove-orphans", + "dev": "subql codegen && subql build && docker compose pull && docker compose up --remove-orphans", "prepack": "rm -rf dist && npm run build", "test": "subql build && subql-node-stellar test" },