Skip to content

safetrustcr/backend-SafeTrust

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

603 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CodeRabbit Pull Request Reviews

SafeTrust Description:

SafeTrust is a decentralized platform designed to revolutionize P2P transactions, providing secure deposits and payments powered by blockchain and trustless technologies. 🌐✨ Experience transparency and reliability in every cryptocurrency transaction. πŸ’ΈπŸ”’


Why Choose SafeTrust?

πŸ” Trustless Technology: Secure and block deposits without intermediaries.
πŸ’Ύ Blockchain-Powered Transparency: Immutable, auditable, and verifiable transactions.
πŸ’± Crypto-Payment Support: Manage cryptocurrency payments safely and efficiently.
βœ… Automated Refunds: Streamlined processes ensure refunds and payment releases happen automatically.


Key Features

πŸ› οΈ Trustless Escrow:
Funds are securely held in blockchain-based escrow accounts until all terms are met.

πŸ”Ž Blockchain Transparency:
Every transaction is logged on the blockchain for full visibility and accountability. πŸ“œ

πŸ’° Crypto Payments:
Supports irreversible and secure cryptocurrency payments while reducing risks of fraud or disputes.

πŸ”— Trustline Process:
Verified trustlines between parties add an extra layer of transaction security. πŸ”’

πŸ“€ Automated Refund System:
Ensures funds are automatically released based on the terms of the agreement, with no manual intervention required.


πŸ“‹ Getting Started

Prerequisites

Tool Version Notes
Docker & Docker Compose β‰₯ 24 Required
Hasura CLI β‰₯ 2.x Required for migrations & seeds
curl any Used by health-check loop

One-command setup

cp .env.example .env   # fill in your values, then:
bin/dc_prep            # starts all containers, runs migrations, seeds, and metadata

Once bin/dc_prep completes, open the Hasura console in a separate terminal:

bin/dc_prep performs the following steps automatically, in order:

Step Action
1 Start postgres, graphql-engine, and webhook via Docker Compose (waits for healthy)
2 Poll GET /healthz until Hasura is ready (up to 3 min)
3 Build and deploy tenant metadata for all tenants (metadata/setup-tenant.sh)
4 Apply all database migrations (hasura migrate apply)
5 Reload Hasura metadata
6 Apply seed data (hasura seed apply)

Environment variables

Copy .env.example to .env and fill in the required values before running bin/dc_prep:

POSTGRES_PASSWORD=your_postgres_password

# Must be valid JSON with a minimum 32-character key for HS256
HASURA_GRAPHQL_JWT_SECRET={"type":"HS256","key":"replace-with-min-32-char-secret-here"}

HASURA_EVENT_SECRET=your_event_secret

Windows users: Run bin/dc_prep and bin/dc_console inside WSL (Ubuntu) or Git Bash, as they are Bash scripts targeting a Linux container environment.


πŸ—‚οΈ Metadata Architecture

The metadata/ folder contains the Hasura GraphQL Engine configuration per tenant.

backend/
└── metadata/
    β”œβ”€β”€ base/
    β”‚   β”œβ”€β”€ actions.graphql
    β”‚   β”œβ”€β”€ actions.yaml
    β”‚   β”œβ”€β”€ allow_list.yaml
    β”‚   β”œβ”€β”€ api_limits.yaml
    β”‚   β”œβ”€β”€ backend_configs.yaml
    β”‚   β”œβ”€β”€ cron_triggers.yaml
    β”‚   β”œβ”€β”€ graphql_schema_introspection.yaml
    β”‚   β”œβ”€β”€ inherited_roles.yaml
    β”‚   β”œβ”€β”€ metrics_config.yaml
    β”‚   β”œβ”€β”€ network.yaml
    β”‚   β”œβ”€β”€ opentelemetry.yaml
    β”‚   β”œβ”€β”€ query_collections.yaml
    β”‚   β”œβ”€β”€ remote_schemas.yaml
    β”‚   β”œβ”€β”€ rest_endpoints.yaml
    β”‚   └── version.yaml
    β”œβ”€β”€ build/
    β”‚   └── tenant_a/
    β”‚   └── tenant_b/
    β”‚   └── ...
    β”œβ”€β”€ tenants/
    β”‚   β”œβ”€β”€ safetrust/
    β”‚   β”‚   β”œβ”€β”€ databases/
    β”‚   β”‚   β”œβ”€β”€ tables/
    β”‚   β”‚   β”œβ”€β”€ functions/
    β”‚   β”‚   └── databases.yaml
    β”‚   └── hotel_industry/
    β”‚       β”œβ”€β”€ databases/
    β”‚       β”œβ”€β”€ tables/
    β”‚       β”œβ”€β”€ functions/
    β”‚       └── databases.yaml
    β”œβ”€β”€ build-metadata.sh
    β”œβ”€β”€ deploy-tenant.sh
    └── setup-tenant.sh

Folder guide:

  • base/ β€” Hasura base configuration and GraphQL dependencies shared across all tenants
  • build/ β€” Generated output: tenants merged with base dependencies, ready to deploy
  • tenants/ β€” Tenant-specific database files, tables, functions, relations, and triggers
  • build-metadata.sh β€” Prepares a tenant by merging it with base configurations
  • deploy-tenant.sh β€” Deploys a built tenant to Hasura (tracks tables and relationships)
  • setup-tenant.sh β€” Runs both steps above in one command βœ…

πŸš€ Steps to execute the metadata manually

Tip: bin/dc_prep handles metadata setup automatically. Use the steps below only for targeted tenant work.

Option A β€” Single command (recommended)

cd metadata
./setup-tenant.sh <tenant_name> [--admin-secret SECRET] [--endpoint URL]

Example:

./setup-tenant.sh safetrust --endpoint http://localhost:8080

Default values: --admin-secret myadminsecretkey Β· --endpoint http://localhost:8080

Option B β€” Step by step (manual)

  1. Build the tenant:
./build-metadata.sh <tenant_name> --admin-secret myadminsecretkey --endpoint <endpoint>
  1. Verify the build/ folder contains the correct tenant data.

  2. Deploy the tenant:

./deploy-tenant.sh <tenant_name> --admin-secret myadminsecretkey --endpoint <endpoint>

πŸ—ƒοΈ Steps to execute the migrations manually

Tip: bin/dc_prep handles migrations automatically. Use the manual steps below only for targeted work.

From the project root:

hasura migrate apply \
  --database-name safetrust \
  --endpoint http://localhost:8080 \
  --admin-secret myadminsecretkey

To apply a single version:

hasura migrate apply \
  --database-name safetrust \
  --version <timestamp> \
  --type up

🌱 Steps to execute the seeds manually

Tip: bin/dc_prep applies seeds automatically. Use the manual step below when you need to re-seed.

From the project root:

hasura seed apply \
  --database-name safetrust \
  --endpoint http://localhost:8080 \
  --admin-secret myadminsecretkey

πŸ§ͺ Backend Tests

This project uses the Karate framework for API testing. Tests run in a Docker environment.

Running Tests

docker compose -f docker-compose-test.yml run --rm --build karate

This command will:

  1. Build the test container
  2. Start PostgreSQL and Hasura containers
  3. Run all Karate tests
  4. Show test results in the console
  5. Generate HTML reports in target/karate-reports/

Test Reports

After running the tests, find the HTML reports at:

  • Summary: tests/results/karate-summary.html
  • Detailed: tests/results/karate-tags.html

Adding New Tests

  1. Create new .feature files in tests/karate/features/
  2. Follow the Karate DSL syntax
  3. Tests are automatically picked up when running the test command

Configuration

  • Main config: tests/karate/src/test/resources/karate-config.js
  • Database config: docker-compose-test.yml
  • Test environment: Dockerfile.test

About

Supports a decentralized platform for secure and trusted P2P cryptocurrency transactions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors