Skip to content

Commit

Permalink
fix some bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yoozo committed Jan 15, 2025
1 parent a92680a commit fa7b4ed
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Stellar/soroban-futurenet-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -26,8 +26,8 @@
},
"devDependencies": {
"@subql/cli": "latest",
"@subql/types": "latest",
"@subql/testing": "latest",
"@subql/types": "latest",
"typescript": "^5.2.2"
}
}
4 changes: 2 additions & 2 deletions Stellar/soroban-greeter-contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 3 additions & 2 deletions Stellar/soroban-greeter-contract/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Increment } from "../types";
import { SorobanEvent } from "@subql/types-stellar";

export async function handleEvent(event: SorobanEvent): Promise<void> {
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();
}
}
}
1 change: 1 addition & 0 deletions Stellar/soroban-starter/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions Stellar/soroban-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion Stellar/soroban-starter/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
34 changes: 17 additions & 17 deletions Stellar/soroban-starter/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ 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(
op: StellarOperation<Horizon.HorizonApi.PaymentOperationResponse>
): Promise<void> {
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,
Expand All @@ -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()]);
}

Expand All @@ -39,7 +39,7 @@ export async function handleCredit(

const account = await checkAndGetAccount(
effect.account,
effect.ledger.sequence
effect.ledger!.sequence
);

const credit = Credit.create({
Expand All @@ -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()]);
}

Expand All @@ -59,7 +59,7 @@ export async function handleDebit(

const account = await checkAndGetAccount(
effect.account,
effect.ledger.sequence
effect.ledger!.sequence
);

const debit = Debit.create({
Expand All @@ -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<void> {
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
Expand All @@ -93,26 +93,26 @@ export async function handleEvent(event: SorobanEvent): Promise<void> {

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()]);
}

Expand Down
4 changes: 2 additions & 2 deletions Stellar/soroban-testnet-starter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit fa7b4ed

Please sign in to comment.