Skip to content

peshwar9/kryo-workspace

Repository files navigation

Kryo Workspace

A workspace containing Kryo API and State Prover services for handling state transitions and Merkle proofs.

Prerequisites

NATS Server

docker run -d --name nats -p 4222:4222 nats -js

RocksDB Dependencies

Ubuntu/Debian

sudo apt-get install libsnappy-dev

macOS

brew install rocksdb

Starting the Services

  1. Start the Kryo API:
cargo run --bin kryo-api
  1. Start the Kryo State Prover:
cargo run --bin kryo-prover

API Endpoints

1. Submit State Transitions Batch

curl -X POST http://localhost:3000/batch \
  -H "Content-Type: application/json" \
  -d '{
    "transitions": [
      {
        "app_id": "test_app",
        "entity_id": "user1",
        "asset_id": "usdc",
        "delta": 100,
        "tx_id": "tx1"
      },
      {
        "app_id": "test_app",
        "entity_id": "user2",
        "asset_id": "usdc",
        "delta": 50,
        "tx_id": "tx2"
      }
    ]
  }'

Response:

{
  "timestamp": 1234567890,
  "affected_keys": ["test_app/user1/usdc", "test_app/user2/usdc"]
}

2. Get Merkle Proof

curl -X POST http://localhost:3000/proof \
  -H "Content-Type: application/json" \
  -d '{
    "key": "test_app/user1/usdc",
    "timestamp": null
  }'

Response:

{
  "root_hash": "876ed29c8d870f406f0675cd0be84478577cd6b347081261dd482b68909f8c93",
  "timestamp": "2024-03-14T12:34:56Z",
  "proof": [...],
  "balance": 100
}

3. Get Unprocessed Batches

curl http://localhost:3000/unprocessed-batches

4. Mark Batch as Processed

curl -X POST http://localhost:3000/mark-processed \
  -H "Content-Type: application/json" \
  -d '{
    "timestamp": 1748435837
  }'

NATS Integration

Install NATS Tools

brew install nats-io/nats-tools/nats

Subscribe to Transactions

nats sub kryo.transactions

Publish Using Payload File

nats pub state_transitions "$(cat payload.json)"

End-to-End Test Flow

  1. Submit a batch of transitions:
curl -X POST http://localhost:3000/batch \
  -H "Content-Type: application/json" \
  -d '{
    "transitions": [
      {
        "app_id": "test_app",
        "entity_id": "user1",
        "asset_id": "usdc",
        "delta": 100,
        "tx_id": "tx1"
      },
      {
        "app_id": "test_app",
        "entity_id": "user2",
        "asset_id": "usdc",
        "delta": 50,
        "tx_id": "tx2"
      }
    ]
  }'
  1. Check unprocessed batches:
curl http://localhost:3000/unprocessed-batches
  1. Mark a batch as processed:
curl -X POST http://localhost:3000/mark-processed \
  -H "Content-Type: application/json" \
  -d '{
    "timestamp": 1234567890
  }'
  1. Submit another batch:
curl -X POST http://localhost:3000/batch \
  -H "Content-Type: application/json" \
  -d '{
    "transitions": [
      {
        "app_id": "test_app",
        "entity_id": "user1",
        "asset_id": "usdc",
        "delta": -30,
        "tx_id": "tx3"
      }
    ]
  }'
  1. Verify unprocessed batches again:
curl http://localhost:3000/unprocessed-batches

About

Proof engine for vapps

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors