From fdfe3e02cd0df8c35693d6563a2ca328a13b9bbb Mon Sep 17 00:00:00 2001 From: godlin Date: Sat, 2 Mar 2024 09:52:26 +0100 Subject: [PATCH 1/4] - code formatted - building error removed --- .../soroban-futurenet-starter/package.json | 9 ++- Stellar/soroban-futurenet-starter/project.ts | 4 +- .../src/mappings/mappingHandlers.ts | 41 ++++++++++-- .../src/mappings/mappingHandlers.ts | 64 +++++++++++-------- .../src/mappings/mappingHandlers.ts | 46 +++++++------ 5 files changed, 104 insertions(+), 60 deletions(-) diff --git a/Stellar/soroban-futurenet-starter/package.json b/Stellar/soroban-futurenet-starter/package.json index 2d99d4a..0a8a279 100644 --- a/Stellar/soroban-futurenet-starter/package.json +++ b/Stellar/soroban-futurenet-starter/package.json @@ -1,7 +1,7 @@ { - "name": "soroban-futurenet-starter", + "name": "soroban-testnet-starter", "version": "0.0.1", - "description": "This project can be use as a starting point for developing your new Stellar Soroban Future Network SubQuery project", + "description": "This project can be use as a starting point for developing your new Stellar Soroban Test Network SubQuery project", "main": "dist/index.js", "scripts": { "build": "subql build", @@ -22,13 +22,12 @@ "license": "MIT", "dependencies": { "@subql/common": "latest", - "@subql/types-stellar": "latest", - "stellar-sdk": "^10.4.1" + "@subql/types-stellar": "latest" }, "devDependencies": { "@subql/cli": "latest", - "@subql/testing": "latest", "@subql/types": "latest", + "@subql/testing": "latest", "ethers": "^5.7.2", "typescript": "^5.2.2" } diff --git a/Stellar/soroban-futurenet-starter/project.ts b/Stellar/soroban-futurenet-starter/project.ts index 8793c98..3ff275c 100644 --- a/Stellar/soroban-futurenet-starter/project.ts +++ b/Stellar/soroban-futurenet-starter/project.ts @@ -45,7 +45,7 @@ const project: StellarProject = { dataSources: [ { kind: StellarDatasourceKind.Runtime, - startBlock: 49260759, // Set this as a logical start block, it might be block 1 (genesis) or when your contract was deployed + startBlock: 599994, // Set this as a logical start block, it might be block 1 (genesis) or when your contract was deployed mapping: { file: "./dist/index.js", handlers: [ @@ -53,7 +53,7 @@ const project: StellarProject = { handler: "handleOperation", kind: StellarHandlerKind.Operation, filter: { - type: Horizon.OperationResponseType.payment, + type: Horizon.HorizonApi.OperationResponseType.payment, }, }, { diff --git a/Stellar/soroban-futurenet-starter/src/mappings/mappingHandlers.ts b/Stellar/soroban-futurenet-starter/src/mappings/mappingHandlers.ts index c15f7ee..034d6be 100644 --- a/Stellar/soroban-futurenet-starter/src/mappings/mappingHandlers.ts +++ b/Stellar/soroban-futurenet-starter/src/mappings/mappingHandlers.ts @@ -4,11 +4,16 @@ import { StellarEffect, SorobanEvent, } from "@subql/types-stellar"; -import { AccountCredited, AccountDebited } from "stellar-sdk/lib/types/effects"; +import { + AccountCredited, + AccountDebited, +} from "stellar-sdk/lib/horizon/types/effects"; import { Horizon } from "stellar-sdk"; +import { Address, xdr } from "soroban-client"; +import { logger } from "ethers"; export async function handleOperation( - op: StellarOperation + op: StellarOperation ): Promise { logger.info(`Indexing operation ${op.id}, type: ${op.type}`); @@ -69,7 +74,9 @@ export async function handleDebit( } export async function handleEvent(event: SorobanEvent): Promise { - logger.info(`New transfer event found at block ${event.ledger}`); + logger.info( + `New transfer event found at block ${event.ledger.sequence.toString()}` + ); // Get data from the event // The transfer event has the following payload \[env, from, to\] @@ -78,15 +85,28 @@ export async function handleEvent(event: SorobanEvent): Promise { topic: [env, from, to], } = event; - const fromAccount = await checkAndGetAccount(from, event.ledger.sequence); - const toAccount = await checkAndGetAccount(to, event.ledger.sequence); + try { + decodeAddress(from); + decodeAddress(to); + } catch (e) { + logger.info(`decode address failed`); + } + + const fromAccount = await checkAndGetAccount( + decodeAddress(from), + event.ledger.sequence + ); + const toAccount = await checkAndGetAccount( + decodeAddress(to), + event.ledger.sequence + ); // Create the new transfer entity const transfer = Transfer.create({ id: event.id, ledger: event.ledger.sequence, date: new Date(event.ledgerClosedAt), - contract: event.contractId, + contract: event.contractId?.contractId().toString()!, fromId: fromAccount.id, toId: toAccount.id, value: BigInt(event.value.decoded!), @@ -111,3 +131,12 @@ async function checkAndGetAccount( } return account; } + +// scValToNative not works, temp solution +function decodeAddress(scVal: xdr.ScVal): string { + try { + return Address.account(scVal.address().accountId().ed25519()).toString(); + } catch (e) { + return Address.contract(scVal.address().contractId()).toString(); + } +} diff --git a/Stellar/soroban-starter/src/mappings/mappingHandlers.ts b/Stellar/soroban-starter/src/mappings/mappingHandlers.ts index 45af16f..034d6be 100644 --- a/Stellar/soroban-starter/src/mappings/mappingHandlers.ts +++ b/Stellar/soroban-starter/src/mappings/mappingHandlers.ts @@ -4,13 +4,16 @@ import { StellarEffect, SorobanEvent, } from "@subql/types-stellar"; -import { AccountCredited, AccountDebited } from "stellar-sdk/lib/horizon/types/effects"; -import { Horizon, } from "stellar-sdk"; -import { Address,xdr,} from 'soroban-client'; -import {logger} from "ethers"; +import { + AccountCredited, + AccountDebited, +} from "stellar-sdk/lib/horizon/types/effects"; +import { Horizon } from "stellar-sdk"; +import { Address, xdr } from "soroban-client"; +import { logger } from "ethers"; export async function handleOperation( - op: StellarOperation + op: StellarOperation ): Promise { logger.info(`Indexing operation ${op.id}, type: ${op.type}`); @@ -31,13 +34,13 @@ export async function handleOperation( } export async function handleCredit( - effect: StellarEffect + effect: StellarEffect ): Promise { logger.info(`Indexing effect ${effect.id}, type: ${effect.type}`); const account = await checkAndGetAccount( - effect.account, - effect.ledger.sequence + effect.account, + effect.ledger.sequence ); const credit = Credit.create({ @@ -51,13 +54,13 @@ export async function handleCredit( } export async function handleDebit( - effect: StellarEffect + effect: StellarEffect ): Promise { logger.info(`Indexing effect ${effect.id}, type: ${effect.type}`); const account = await checkAndGetAccount( - effect.account, - effect.ledger.sequence + effect.account, + effect.ledger.sequence ); const debit = Debit.create({ @@ -71,24 +74,32 @@ export async function handleDebit( } export async function handleEvent(event: SorobanEvent): Promise { - logger.info(`New transfer event found at block ${event.ledger.sequence.toString()}`); + logger.info( + `New transfer event found at block ${event.ledger.sequence.toString()}` + ); // Get data from the event // The transfer event has the following payload \[env, from, to\] // logger.info(JSON.stringify(event)); const { - topic: [env, from, to] + topic: [env, from, to], } = event; try { - decodeAddress(from) - decodeAddress(to) - }catch (e) { - logger.info(`decode address failed`) + decodeAddress(from); + decodeAddress(to); + } catch (e) { + logger.info(`decode address failed`); } - const fromAccount = await checkAndGetAccount(decodeAddress(from), event.ledger.sequence); - const toAccount = await checkAndGetAccount(decodeAddress(to), event.ledger.sequence); + const fromAccount = await checkAndGetAccount( + decodeAddress(from), + event.ledger.sequence + ); + const toAccount = await checkAndGetAccount( + decodeAddress(to), + event.ledger.sequence + ); // Create the new transfer entity const transfer = Transfer.create({ @@ -107,8 +118,8 @@ export async function handleEvent(event: SorobanEvent): Promise { } async function checkAndGetAccount( - id: string, - ledgerSequence: number + id: string, + ledgerSequence: number ): Promise { let account = await Account.get(id.toLowerCase()); if (!account) { @@ -122,13 +133,10 @@ async function checkAndGetAccount( } // scValToNative not works, temp solution -function decodeAddress(scVal:xdr.ScVal):string{ +function decodeAddress(scVal: xdr.ScVal): string { try { return Address.account(scVal.address().accountId().ed25519()).toString(); - }catch (e) { - return Address.contract( - scVal.address().contractId()).toString(); + } catch (e) { + return Address.contract(scVal.address().contractId()).toString(); } - - -} \ No newline at end of file +} diff --git a/Stellar/soroban-testnet-starter/src/mappings/mappingHandlers.ts b/Stellar/soroban-testnet-starter/src/mappings/mappingHandlers.ts index 4a6fcaa..034d6be 100644 --- a/Stellar/soroban-testnet-starter/src/mappings/mappingHandlers.ts +++ b/Stellar/soroban-testnet-starter/src/mappings/mappingHandlers.ts @@ -4,10 +4,13 @@ import { StellarEffect, SorobanEvent, } from "@subql/types-stellar"; -import { AccountCredited, AccountDebited } from "stellar-sdk/lib/horizon/types/effects"; -import { Horizon, } from "stellar-sdk"; -import { Address,xdr,} from 'soroban-client'; -import {logger} from "ethers"; +import { + AccountCredited, + AccountDebited, +} from "stellar-sdk/lib/horizon/types/effects"; +import { Horizon } from "stellar-sdk"; +import { Address, xdr } from "soroban-client"; +import { logger } from "ethers"; export async function handleOperation( op: StellarOperation @@ -71,24 +74,32 @@ export async function handleDebit( } export async function handleEvent(event: SorobanEvent): Promise { - logger.info(`New transfer event found at block ${event.ledger.sequence.toString()}`); + logger.info( + `New transfer event found at block ${event.ledger.sequence.toString()}` + ); // Get data from the event // The transfer event has the following payload \[env, from, to\] // logger.info(JSON.stringify(event)); const { - topic: [env, from, to] + topic: [env, from, to], } = event; try { - decodeAddress(from) - decodeAddress(to) - }catch (e) { - logger.info(`decode address failed`) + decodeAddress(from); + decodeAddress(to); + } catch (e) { + logger.info(`decode address failed`); } - const fromAccount = await checkAndGetAccount(decodeAddress(from), event.ledger.sequence); - const toAccount = await checkAndGetAccount(decodeAddress(to), event.ledger.sequence); + const fromAccount = await checkAndGetAccount( + decodeAddress(from), + event.ledger.sequence + ); + const toAccount = await checkAndGetAccount( + decodeAddress(to), + event.ledger.sequence + ); // Create the new transfer entity const transfer = Transfer.create({ @@ -122,13 +133,10 @@ async function checkAndGetAccount( } // scValToNative not works, temp solution -function decodeAddress(scVal:xdr.ScVal):string{ +function decodeAddress(scVal: xdr.ScVal): string { try { return Address.account(scVal.address().accountId().ed25519()).toString(); - }catch (e) { - return Address.contract( - scVal.address().contractId()).toString(); + } catch (e) { + return Address.contract(scVal.address().contractId()).toString(); } - - -} \ No newline at end of file +} From 965424256d5bce710a34d376ee65f5f98ef59ebd Mon Sep 17 00:00:00 2001 From: bgodlin <37313677+bgodlin@users.noreply.github.com> Date: Wed, 6 Mar 2024 03:59:47 +0100 Subject: [PATCH 2/4] soroban greeter starter added (#9) --- .../.github/scripts/publish-deploy.sh | 15 ++++ .../.github/workflows/cli-deploy.yml | 34 ++++++++ .../.github/workflows/pr.yml | 24 ++++++ Stellar/soroban-greeter-contract/.gitignore | 58 ++++++++++++++ Stellar/soroban-greeter-contract/LICENSE | 21 +++++ Stellar/soroban-greeter-contract/README.md | 79 +++++++++++++++++++ .../docker-compose.yml | 65 +++++++++++++++ .../docker/load-extensions.sh | 6 ++ .../docker/pg-Dockerfile | 9 +++ Stellar/soroban-greeter-contract/package.json | 34 ++++++++ Stellar/soroban-greeter-contract/project.ts | 69 ++++++++++++++++ .../soroban-greeter-contract/schema.graphql | 4 + Stellar/soroban-greeter-contract/src/index.ts | 2 + .../src/mappings/mappingHandlers.ts | 16 ++++ .../src/test/mappingHandlers.test.ts | 12 +++ .../soroban-greeter-contract/tsconfig.json | 20 +++++ 16 files changed, 468 insertions(+) create mode 100644 Stellar/soroban-greeter-contract/.github/scripts/publish-deploy.sh create mode 100644 Stellar/soroban-greeter-contract/.github/workflows/cli-deploy.yml create mode 100644 Stellar/soroban-greeter-contract/.github/workflows/pr.yml create mode 100644 Stellar/soroban-greeter-contract/.gitignore create mode 100644 Stellar/soroban-greeter-contract/LICENSE create mode 100644 Stellar/soroban-greeter-contract/README.md create mode 100644 Stellar/soroban-greeter-contract/docker-compose.yml create mode 100644 Stellar/soroban-greeter-contract/docker/load-extensions.sh create mode 100644 Stellar/soroban-greeter-contract/docker/pg-Dockerfile create mode 100644 Stellar/soroban-greeter-contract/package.json create mode 100644 Stellar/soroban-greeter-contract/project.ts create mode 100644 Stellar/soroban-greeter-contract/schema.graphql create mode 100644 Stellar/soroban-greeter-contract/src/index.ts create mode 100644 Stellar/soroban-greeter-contract/src/mappings/mappingHandlers.ts create mode 100644 Stellar/soroban-greeter-contract/src/test/mappingHandlers.test.ts create mode 100644 Stellar/soroban-greeter-contract/tsconfig.json diff --git a/Stellar/soroban-greeter-contract/.github/scripts/publish-deploy.sh b/Stellar/soroban-greeter-contract/.github/scripts/publish-deploy.sh new file mode 100644 index 0000000..3c9dc04 --- /dev/null +++ b/Stellar/soroban-greeter-contract/.github/scripts/publish-deploy.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +while getopts p:o:e: flag +do + case "${flag}" in + e) ENDPOINT=${OPTARG};; + p) PROJECTNAME=${OPTARG};; + o) ORG=${OPTARG};; + *) echo "Usage: $0 [-p projectname] [-o org] [-e endpoint]" && exit 1;; + esac +done + +IPFSCID=$(npx subql publish -o -f .) + +npx subql deployment:deploy -d --ipfsCID="$IPFSCID" --projectName="${PROJECTNAME}" --org="${ORG%/*}" --endpoint="${ENDPOINT}" diff --git a/Stellar/soroban-greeter-contract/.github/workflows/cli-deploy.yml b/Stellar/soroban-greeter-contract/.github/workflows/cli-deploy.yml new file mode 100644 index 0000000..658d2c6 --- /dev/null +++ b/Stellar/soroban-greeter-contract/.github/workflows/cli-deploy.yml @@ -0,0 +1,34 @@ +name: "CLI deploy" + +on: + workflow_dispatch: + inputs: + projectName: + description: "Project name" + required: true + type: string +jobs: + deploy: + name: CLI Deploy + runs-on: ubuntu-latest + environment: + name: DEPLOYMENT + env: + SUBQL_ACCESS_TOKEN: ${{ secrets.SUBQL_ACCESS_TOKEN }} + ENDPOINT: ${{ secrets.ENDPOINT }} + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Version + run: npx subql --version + - name: repo + run: echo ${{github.repository}} + - name: Publish and Deploy + run: | + sh .github/workflows/scripts/publish-deploy.sh -o ${{github.repository}} -p ${{github.event.inputs.projectName}} -e ${{secrets.ENDPOINT}} diff --git a/Stellar/soroban-greeter-contract/.github/workflows/pr.yml b/Stellar/soroban-greeter-contract/.github/workflows/pr.yml new file mode 100644 index 0000000..47e66be --- /dev/null +++ b/Stellar/soroban-greeter-contract/.github/workflows/pr.yml @@ -0,0 +1,24 @@ +name: PR +on: + pull_request: + paths-ignore: + - ".github/workflows/**" +jobs: + pr: + name: pr + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup Node.js environment + uses: actions/setup-node@v2 + with: + node-version: 16 + - run: yarn + - name: Codegen + run: yarn codegen + - name: Build + run: yarn build + - name: Install subql-node-stellar + run: yarn global add @subql/node-stellar + - name: Run tests with Subquery Node + run: subql-node-stellar test -f ${{ github.workspace }} diff --git a/Stellar/soroban-greeter-contract/.gitignore b/Stellar/soroban-greeter-contract/.gitignore new file mode 100644 index 0000000..9615e3c --- /dev/null +++ b/Stellar/soroban-greeter-contract/.gitignore @@ -0,0 +1,58 @@ +# These are some examples of commonly ignored file patterns. +# You should customize this list as applicable to your project. +# Learn more about .gitignore: +# https://www.atlassian.com/git/tutorials/saving-changes/gitignore + +# Node artifact files +node_modules/ +dist/ + +# lock files +yarn.lock +package-lock.json + +# Compiled Java class files +*.class + +# Compiled Python bytecode +*.py[cod] + +# Log files +*.log + +# Package files +*.jar + +# Generated files +target/ +dist/ +src/types +project.yaml + +# JetBrains IDE +.idea/ + +# Unit test reports +TEST*.xml + +# Generated by MacOS +.DS_Store + +# Generated by Windows +Thumbs.db + +# Applications +*.app +*.exe +*.war + +# Large media files +*.mp4 +*.tiff +*.avi +*.flv +*.mov +*.wmv + +.data +.eslintcache diff --git a/Stellar/soroban-greeter-contract/LICENSE b/Stellar/soroban-greeter-contract/LICENSE new file mode 100644 index 0000000..76e70cc --- /dev/null +++ b/Stellar/soroban-greeter-contract/LICENSE @@ -0,0 +1,21 @@ +MIT LICENSE + +Copyright 2020-2021 SubQuery Pte Ltd authors & contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/Stellar/soroban-greeter-contract/README.md b/Stellar/soroban-greeter-contract/README.md new file mode 100644 index 0000000..fc12614 --- /dev/null +++ b/Stellar/soroban-greeter-contract/README.md @@ -0,0 +1,79 @@ +# SubQuery - Example Project for Soroban Greeter + +[SubQuery](https://subquery.network) is a fast, flexible, and reliable open-source data indexer that provides you with custom APIs for your web3 project across all of our supported networks. To learn about how to get started with SubQuery, [visit our docs](https://academy.subquery.network). + +**The sample project logs events related to increments and within the [Soroban greeter contract](https://github.com/stellar/soroban-dapps-challenge/blob/greeter/contracts/hello-world/src/lib.rs).** + +## Start + +First, install SubQuery CLI globally on your terminal by using NPM `npm install -g @subql/cli` + +You can either clone this GitHub repo, or use the `subql` CLI to bootstrap a clean project in the network of your choosing by running `subql init` and following the prompts. + +Don't forget to install dependencies with `npm install` or `yarn install`! + +## Editing your SubQuery project + +Although this is a working example SubQuery project, you can edit the SubQuery project by changing the following files: + +- The project manifest in `project.yaml` defines the key project configuration and mapping handler filters +- The GraphQL Schema (`schema.graphql`) defines the shape of the resulting data that you are using SubQuery to index +- The Mapping functions in `src/mappings/` directory are typescript functions that handle transformation logic + +SubQuery supports various layer-1 blockchain networks and provides [dedicated quick start guides](https://academy.subquery.network/quickstart/quickstart.html) as well as [detailed technical documentation](https://academy.subquery.network/build/introduction.html) for each of them. + +## Run your project + +_If you get stuck, find out how to get help below._ + +The simplest way to run your project is by running `yarn dev` or `npm run-script dev`. This does all of the following: + +1. `yarn codegen` - Generates types from the GraphQL schema definition and contract ABIs and saves them in the `/src/types` directory. This must be done after each change to the `schema.graphql` file or the contract ABIs +2. `yarn build` - Builds and packages the SubQuery project into the `/dist` directory +3. `docker-compose pull && docker-compose up` - Runs a Docker container with an indexer, PostgeSQL DB, and a query service. This requires [Docker to be installed](https://docs.docker.com/engine/install) and running locally. The configuration for this container is set from your `docker-compose.yml` + +You can observe the three services start, and once all are running (it may take a few minutes on your first start), please open your browser and head to [http://localhost:3000](http://localhost:3000) - you should see a GraphQL playground showing with the schemas ready to query. [Read the docs for more information](https://academy.subquery.network/run_publish/run.html) or [explore the possible service configuration for running SubQuery](https://academy.subquery.network/run_publish/references.html). + +## Query your project + +For this project, you can try to query with the following GraphQL code to get a taste of how it works. + +```graphql +query { + increments { + nodes { + id + newValue + } + groupedAggregates(groupBy: [NEW_VALUE]) { + distinctCount { + id + } + keys + } + } +} +``` + +You can explore the different possible queries and entities to help you with GraphQL using the documentation draw on the right. + +## Publish your project + +SubQuery is open-source, meaning you have the freedom to run it in the following three ways: + +- Locally on your own computer (or a cloud provider of your choosing), [view the instructions on how to run SubQuery Locally](https://academy.subquery.network/run_publish/run.html) +- By publishing it to our enterprise-level [Managed Service](https://managedservice.subquery.network), where we'll host your SubQuery project in production ready services for mission critical data with zero-downtime blue/green deployments. We even have a generous free tier. [Find out how](https://academy.subquery.network/run_publish/publish.html) +- [Coming Soon] By publishing it to the decentralised [SubQuery Network](https://subquery.network/network), the most open, performant, reliable, and scalable data service for dApp developers. The SubQuery Network indexes and services data to the global community in an incentivised and verifiable way + +## What Next? + +Take a look at some of our advanced features to take your project to the next level! + +- [**Multi-chain indexing support**](https://academy.subquery.network/build/multi-chain.html) - SubQuery allows you to index data from across different layer-1 networks into the same database, this allows you to query a single endpoint to get data for all supported networks. +- [**Dynamic Data Sources**](https://academy.subquery.network/build/dynamicdatasources.html) - When you want to index factory contracts, for example on a DEX or generative NFT project. +- [**Project Optimisation Advice**](https://academy.subquery.network/build/optimisation.html) - Some common tips on how to tweak your project to maximise performance. +- [**GraphQL Subscriptions**](https://academy.subquery.network/run_publish/subscription.html) - Build more reactive front end applications that subscribe to changes in your SubQuery project. + +## Need Help? + +The fastest way to get support is by [searching our documentation](https://academy.subquery.network), or by [joining our discord](https://discord.com/invite/subquery) and messaging us in the `#technical-support` channel. diff --git a/Stellar/soroban-greeter-contract/docker-compose.yml b/Stellar/soroban-greeter-contract/docker-compose.yml new file mode 100644 index 0000000..31f9912 --- /dev/null +++ b/Stellar/soroban-greeter-contract/docker-compose.yml @@ -0,0 +1,65 @@ +version: "3" + +services: + postgres: + build: + context: . + dockerfile: ./docker/pg-Dockerfile + ports: + - 5432:5432 + volumes: + - .data/postgres:/var/lib/postgresql/data + environment: + POSTGRES_PASSWORD: postgres + healthcheck: + test: ["CMD-SHELL", "pg_isready -U postgres"] + interval: 5s + timeout: 5s + retries: 5 + + subquery-node: + image: subquerynetwork/subql-node-stellar:latest + depends_on: + "postgres": + condition: service_healthy + restart: unless-stopped + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + volumes: + - ./:/app + command: + - ${SUB_COMMAND:-} # set SUB_COMMAND env variable to "test" to run tests + - -f=/app + - --db-schema=app + - --workers=1 # The more the faster + - --batch-size=5 # The higher the faster, set low to avoid rate limit on SDF endpoint + healthcheck: + test: ["CMD", "curl", "-f", "http://subquery-node:3000/ready"] + interval: 3s + timeout: 5s + retries: 10 + + graphql-engine: + image: subquerynetwork/subql-query:latest + ports: + - 3000:3000 + depends_on: + "postgres": + condition: service_healthy + "subquery-node": + condition: service_healthy + restart: always + environment: + DB_USER: postgres + DB_PASS: postgres + DB_DATABASE: postgres + DB_HOST: postgres + DB_PORT: 5432 + command: + - --name=app + - --playground + - --indexer=http://subquery-node:3000 diff --git a/Stellar/soroban-greeter-contract/docker/load-extensions.sh b/Stellar/soroban-greeter-contract/docker/load-extensions.sh new file mode 100644 index 0000000..06ae32d --- /dev/null +++ b/Stellar/soroban-greeter-contract/docker/load-extensions.sh @@ -0,0 +1,6 @@ + +#!/bin/sh + +psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" < { + 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, + newValue: BigInt( + JSON.parse(JSON.stringify(event.value))["_value"].toString() + ), + }); + await increment.save(); + } +} \ No newline at end of file diff --git a/Stellar/soroban-greeter-contract/src/test/mappingHandlers.test.ts b/Stellar/soroban-greeter-contract/src/test/mappingHandlers.test.ts new file mode 100644 index 0000000..42f41c3 --- /dev/null +++ b/Stellar/soroban-greeter-contract/src/test/mappingHandlers.test.ts @@ -0,0 +1,12 @@ +import { subqlTest } from "@subql/testing"; + +/* +// https://academy.subquery.network/build/testing.html +subqlTest( + "testName", // test name + 1000003, // block height to process + [], // dependent entities + [], // expected entities + "handleEvent" //handler name +); +*/ diff --git a/Stellar/soroban-greeter-contract/tsconfig.json b/Stellar/soroban-greeter-contract/tsconfig.json new file mode 100644 index 0000000..f2f0fdb --- /dev/null +++ b/Stellar/soroban-greeter-contract/tsconfig.json @@ -0,0 +1,20 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "esModuleInterop": true, + "declaration": true, + "importHelpers": true, + "resolveJsonModule": true, + "module": "commonjs", + "outDir": "dist", + "rootDir": "src", + "target": "es2017", + "strict": true + }, + "include": [ + "src/**/*", + "node_modules/@subql/types-core/dist/global.d.ts", + "node_modules/@subql/types-stellar/dist/global.d.ts" + ] +} From 863a2fc5e57d3d746d747bd11f8c628474eed2dd Mon Sep 17 00:00:00 2001 From: bgodlin <37313677+bgodlin@users.noreply.github.com> Date: Wed, 6 Mar 2024 08:23:21 +0100 Subject: [PATCH 3/4] Update package.json --- Stellar/soroban-futurenet-starter/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar/soroban-futurenet-starter/package.json b/Stellar/soroban-futurenet-starter/package.json index 0a8a279..19e481e 100644 --- a/Stellar/soroban-futurenet-starter/package.json +++ b/Stellar/soroban-futurenet-starter/package.json @@ -1,5 +1,5 @@ { - "name": "soroban-testnet-starter", + "name": "soroban-futurenet-starter", "version": "0.0.1", "description": "This project can be use as a starting point for developing your new Stellar Soroban Test Network SubQuery project", "main": "dist/index.js", From e87c6f809c6ec3361a732fec6de3dae30e98c7df Mon Sep 17 00:00:00 2001 From: James Bayly Date: Thu, 7 Mar 2024 15:16:22 +0800 Subject: [PATCH 4/4] Update name --- Stellar/soroban-futurenet-starter/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Stellar/soroban-futurenet-starter/package.json b/Stellar/soroban-futurenet-starter/package.json index 19e481e..3c0fd9d 100644 --- a/Stellar/soroban-futurenet-starter/package.json +++ b/Stellar/soroban-futurenet-starter/package.json @@ -1,7 +1,7 @@ { "name": "soroban-futurenet-starter", "version": "0.0.1", - "description": "This project can be use as a starting point for developing your new Stellar Soroban Test Network SubQuery project", + "description": "This project can be use as a starting point for developing your new Stellar Soroban Futurenet SubQuery project", "main": "dist/index.js", "scripts": { "build": "subql build",