From 8ad2045ae7c3c5d2c23552c623850d1293ad98f1 Mon Sep 17 00:00:00 2001 From: Carlos Tosta Date: Thu, 12 May 2022 21:18:23 -0300 Subject: [PATCH 1/2] feat: docker-compose file without azure dependencies --- docker-compose-local.yaml | 131 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 docker-compose-local.yaml diff --git a/docker-compose-local.yaml b/docker-compose-local.yaml new file mode 100644 index 0000000..a3e72fd --- /dev/null +++ b/docker-compose-local.yaml @@ -0,0 +1,131 @@ +version: '3.6' +services: + postgres: + image: postgres:13 + restart: always + environment: + - DATABASE_HOST=${DATABASE_HOST} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + ports: + - "5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + - ./docker_postgres_init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql + keycloak: + image: 'quay.io/keycloak/keycloak:15.0.2' + ports: + - "8081:8080" + restart: always + command: + - '-Dkeycloak.profile.feature.upload_scripts=enabled' + - '-Dkeycloak.migration.action=import' + - '-Dkeycloak.migration.provider=singleFile' + - '-Dkeycloak.migration.file=/tmp/master-realm.json' + - '-Dkeycloak.migration.strategy=OVERWRITE_EXISTING' + volumes: + - type: bind + source: './keycloak/master-realm.json' + target: '/tmp/master-realm.json' + environment: + PROXY_ADDRESS_FORWARDING: ${PROXY_ADDRESS_FORWARDING} + DB_VENDOR: ${DB_VENDOR} + DB_ADDR: ${DB_ADDR} + DB_DATABASE: ${DB_DATABASE} + DB_SCHEMA: ${DB_SCHEMA} + DB_USER: ${DB_USER} + DB_PASSWORD: ${DB_PASSWORD} + KEYCLOAK_USER: ${KEYCLOAK_USER} + KEYCLOAK_PASSWORD: ${KEYCLOAK_PASSWORD} + graphql-engine: + image: 'hasura/graphql-engine:v2.6.0.cli-migrations-v3' + ports: + - '8080:8080' + depends_on: + - postgres + restart: always + volumes: + - ./hasura/migrations:/hasura-migrations + - ./hasura/metadata:/hasura-metadata + - ./hasura/seeds:/hasura-seeds + environment: + HASURA_GRAPHQL_DATABASE_URL: ${HASURA_GRAPHQL_DATABASE_URL} + HASURA_GRAPHQL_ENABLE_CONSOLE: "true" + HASURA_GRAPHQL_DEV_MODE: "false" + HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET} + HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup, http-log, webhook-log, websocket-log, query-log" + ACTION_BASE_URL: "http://127.0.0.1:3000" + sf-node-alice: + image: sugarfunge-node:latest + build: + context: https://github.com/SugarFunge/sugarfunge-node.git#main + dockerfile: docker/Dockerfile + restart: always + network_mode: "host" + command: ["--chain=local", "--alice", "--base-path=~/tmp/a" ,"--port=30334", "--ws-port", "9944", "--ws-external", "--rpc-external", "--rpc-cors", "all"] + sf-node-bob: + image: sugarfunge-node:latest + build: + context: https://github.com/SugarFunge/sugarfunge-node.git#main + dockerfile: docker/Dockerfile + restart: always + network_mode: "host" + command: ["--bob", "--base-path=~/tmp/a" ,"--port=30335", "--ws-port", "9945", "--ws-external", "--rpc-external", "--rpc-cors", "all", "--bootnodes", "/ip4/127.0.0.1/tcp/30334/p2p/12D3KooWGzN9EZLNkxEVeApishpq8d3pzChPmw9jQ9kra3csTAhk"] + sf-api: + image: 'sugarfunge-api:latest' + build: + context: https://github.com/SugarFunge/sugarfunge-api.git#main + dockerfile: docker/Dockerfile + restart: always + network_mode: 'host' + command: ["-l", "http://0.0.0.0:4000", "-s", "ws://127.0.0.1:9944"] + sf-status: + image: 'sugarfunge-status:latest' + build: + context: https://github.com/SugarFunge/sf-front-end.git#master + dockerfile: docker/Dockerfile + restart: always + network_mode: 'host' + environment: + PORT: ${PORT} + REACT_APP_PROVIDER_SOCKET: ${REACT_APP_PROVIDER_SOCKET} + sf-explorer: + image: 'sugarfunge-explorer:latest' + build: + context: https://github.com/SugarFunge/sugarfunge-explorer.git#master + dockerfile: docker/Dockerfile + restart: always + network_mode: 'host' + environment: + WS_URL: ${WS_URL} + ipfs: + image: 'ipfs/go-ipfs:master-2021-11-17-0c2f9d5' + restart: always + ports: + - "4001:4001" + - "8001:8080" + - "5001:5001" + volumes: + - ./ipfs:/data/ipfs + appsmith: + image: index.docker.io/appsmith/appsmith-ce + ports: + - "7000:80" + - "443:443" + - "9001:9001" + volumes: + - ./stacks:/appsmith-stacks + labels: + com.centurylinklabs.watchtower.enable: "true" + restart: unless-stopped + extra_hosts: + - "host.docker.internal:host-gateway" + auto_update: + image: containrrr/watchtower:latest-dev + volumes: + - /var/run/docker.sock:/var/run/docker.sock + command: --schedule "0 0 * ? * *" --label-enable --cleanup + restart: unless-stopped +volumes: + postgres_data: From f3d2a59f65cd812de527b8eeb5274ae34bb929c6 Mon Sep 17 00:00:00 2001 From: Carlos Tosta Date: Tue, 24 May 2022 16:39:41 -0600 Subject: [PATCH 2/2] feat: Map sugarfunge-integration api to hasura actions --- README.md | 39 ++++++++++ docker-compose-local.yaml | 5 +- hasura/metadata/actions.graphql | 66 ++++++++++++++++ hasura/metadata/actions.yaml | 134 +++++++++++++++++++++++++++++++- 4 files changed, 239 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9bfcc7c..0770947 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,42 @@ $ docker-compose down --volumes | WS_URL | Node WebSocket url (sf-explorer) | | HASURA_GRAPHQL_DATABASE_URL | Postgres database url | | HASURA_GRAPHQL_ADMIN_SECRET | Hasura admin secret Key | + +## Local Configuration + +It's possible to build the images locally if you don't have access or don't want to use the azure pre-built containers, start docker compose using the following command to get started: + +```bash +docker compose -f docker-compose-local.yaml up -d +``` + +> NOTE: The sugarfunge-node code is pulled directly from github, using the main branch, change to a different one if needed on `docker-compose-local.yaml` file. + +## Sugarfunge ERC1155 Integration + +We have 6 (six) graphql actions on hasura that maps directly to the `sugarfunge-integration` api, these actions aim to act as a bridge for asset conversion between the sugarfunge and ethereum networks. + +To get these actions running you will need to setup the sugarfunge-integration repository on your local machine and configure the API address inside the docker-compose environment settings for graphql-engine: + +```yaml +graphql-engine: + image: 'hasura/graphql-engine:v2.6.0.cli-migrations-v3' + ports: + - '8080:8080' + depends_on: + - postgres + restart: always + volumes: + - ./hasura/migrations:/hasura-migrations + - ./hasura/metadata:/hasura-metadata + - ./hasura/seeds:/hasura-seeds + environment: + HASURA_GRAPHQL_DATABASE_URL: ${HASURA_GRAPHQL_DATABASE_URL} + HASURA_GRAPHQL_ENABLE_CONSOLE: "false" + HASURA_GRAPHQL_DEV_MODE: "true" + HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET} + HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup, http-log, webhook-log, websocket-log, query-log" + ACTION_BASE_URL: "http://127.0.0.1:3000" + # Replace this environment variable with the sugarfunge-integration api address + ACTION_RESOLVER_API_ENDPOINT: "http://172.17.0.1:9000" +``` \ No newline at end of file diff --git a/docker-compose-local.yaml b/docker-compose-local.yaml index a3e72fd..ad3c8dc 100644 --- a/docker-compose-local.yaml +++ b/docker-compose-local.yaml @@ -51,11 +51,12 @@ services: - ./hasura/seeds:/hasura-seeds environment: HASURA_GRAPHQL_DATABASE_URL: ${HASURA_GRAPHQL_DATABASE_URL} - HASURA_GRAPHQL_ENABLE_CONSOLE: "true" - HASURA_GRAPHQL_DEV_MODE: "false" + HASURA_GRAPHQL_ENABLE_CONSOLE: "false" + HASURA_GRAPHQL_DEV_MODE: "true" HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET} HASURA_GRAPHQL_ENABLED_LOG_TYPES: "startup, http-log, webhook-log, websocket-log, query-log" ACTION_BASE_URL: "http://127.0.0.1:3000" + ACTION_RESOLVER_API_ENDPOINT: "http://172.17.0.1:9000" sf-node-alice: image: sugarfunge-node:latest build: diff --git a/hasura/metadata/actions.graphql b/hasura/metadata/actions.graphql index e69de29..c6ac07c 100644 --- a/hasura/metadata/actions.graphql +++ b/hasura/metadata/actions.graphql @@ -0,0 +1,66 @@ +type Mutation { + erc1155_batch_transfer( + from: String! + to: String! + amounts: [Int!] + ids: [Int!] + data: [ERC1155TokenMetadata!] + ): ERC1155TransactionOutput +} + +type Mutation { + erc1155_batch_wrap( + from: String! + amounts: [Int!] + ids: [Int!] + data: [ERC1155TokenMetadata!] + ): ERC1155TransactionOutput +} + +type Mutation { + erc1155_mint( + account: String! + amount: Int! + id: Int! + data: ERC1155TokenMetadata! + ): ERC1155TransactionOutput +} + +type Mutation { + erc1155_transfer( + from: String! + to: String! + amount: Int! + id: Int! + data: ERC1155TokenMetadata! + ): ERC1155TransactionOutput +} + +type Mutation { + erc1155_unwrap( + id: Int! + amount: Int! + recipient_address: String! + data: ERC1155TokenMetadata! + ): ERC1155TransactionOutput +} + +type Mutation { + erc1155_wrap( + from: String! + amount: Int! + id: Int! + data: ERC1155TokenMetadata! + ): ERC1155TransactionOutput +} + +input ERC1155TokenMetadata { + name: String! + symbol: String! + decimals: Int! +} + +type ERC1155TransactionOutput { + tx: String! +} + diff --git a/hasura/metadata/actions.yaml b/hasura/metadata/actions.yaml index 1edb4c2..fd15f60 100644 --- a/hasura/metadata/actions.yaml +++ b/hasura/metadata/actions.yaml @@ -1,6 +1,134 @@ -actions: [] +actions: + - name: erc1155_batch_transfer + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/batch_transfer_nft' + request_transform: + body: + action: transform + template: |- + { + "from": {{$body.input.from}}, + "to": {{$body.input.to}}, + "amounts": {{$body.input.amounts}}, + "ids": {{$body.input.ids}}, + "data": {{$body.input.data}} + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti + - name: erc1155_batch_wrap + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/batch_wrap_1155' + request_transform: + body: + action: transform + template: |- + { + "from": {{$body.input.from}}, + "amounts": {{$body.input.amounts}}, + "ids": {{$body.input.ids}}, + "data": {{$body.input.data}} + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti + - name: erc1155_mint + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/mint_nft' + request_transform: + body: + action: transform + template: |- + { + "account": {{$body.input.account}}, + "amount": {{$body.input.amount}}, + "id": {{$body.input.id}}, + "data": { + "name": {{$body.input.data.name}}, + "symbol": {{$body.input.data.symbol}}, + "decimals": {{$body.input.data.decimals}} + } + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti + - name: erc1155_transfer + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/transfer_nft' + request_transform: + body: + action: transform + template: |- + { + "from": {{$body.input.from}}, + "to": {{$body.input.to}}, + "amount": {{$body.input.amount}}, + "id": {{$body.input.id}}, + "data": { + "name": {{$body.input.data.name}}, + "symbol": {{$body.input.data.symbol}}, + "decimals": {{$body.input.data.decimals}} + } + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti + - name: erc1155_unwrap + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/unwrap_1155' + request_transform: + body: + action: transform + template: |- + { + "id": {{$body.input.id}}, + "amount": {{$body.input.amount}}, + "recipient_address": {{$body.input.recipient_address}}, + "data": { + "name": {{$body.input.data.name}}, + "symbol": {{$body.input.data.symbol}}, + "decimals": {{$body.input.data.decimals}} + } + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti + - name: erc1155_wrap + definition: + kind: synchronous + handler: '{{ACTION_RESOLVER_API_ENDPOINT}}/wrap_1155' + request_transform: + body: + action: transform + template: |- + { + "from": {{$body.input.from}}, + "amount": {{$body.input.amount}}, + "id": {{$body.input.id}}, + "data": { + "name": {{$body.input.data.name}}, + "symbol": {{$body.input.data.symbol}}, + "decimals": {{$body.input.data.decimals}} + } + } + method: POST + version: 2 + query_params: {} + template_engine: Kriti custom_types: enums: [] - input_objects: [] - objects: [] + input_objects: + - name: ERC1155TokenMetadata + objects: + - name: ERC1155TransactionOutput scalars: []