Skip to content

asanson1404/smartdeploy-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Deploy API / Mercury Client in Rust

This repository contains a Mercury client developped in Rust with Shuttle. It uses the crates axum, reqwest and graphql-client.

More precisely, it requests specific data indexed by Mercury in order to diplay it in the SmartDeploy Dapp. Below is the architecture of the whole system:

System Architecture

What is Mercury?

Mercury is an indexer service for Stellar and Soroban blockchain. Check more in the Mercury Docs Page.

Pre-requisites

  1. You need a Mercury Token access to use the service. See Request Access.
  2. You must have already subscribed to contract events or ledger entries. To understand the purpose of subscriptions, check out that section.
    Struggling to subscribe to contract event or ledger entries? Check out our Javascript implementation.
  3. Install shuttle:
$ cargo install cargo-shuttle

Get started

  1. Set up your Secrets.toml file as following:
MY_JWT_TOKEN = 'your-mercury-jwt-token'
MERCURY_GRAPHQL_ENDPOINT = 'http://ec2-16-170-242-7.eu-north-1.compute.amazonaws.com:5000'

Of course, you will add your Mercury Access Token provided by the team.

  1. If you want to query an event by its topic, you have to know the base64-encoded XDR of that topic and paste it in your GraphQL query (see queries/query_deploy.graphql).
    As an example, if your event topic is symbol_short!("deploy"), you can have its corresponding XDR by running in a node environment:
const sorobanClient = require('soroban-client');

const myTopic = sorobanClient.xdr.ScVal.scvSymbol("deploy").toXDR("base64");
console.log(myTopic);
  1. Define a route to trigger the GraphQL request. In our example, the route is "/get_deploy" and the corresponding handler is the function get_deploy_event (see src/main.rs).

  2. Test locally whether everything is working properly:

$ cargo shuttle run
# or if you want to see the logs
$ RUST_LOG=debug cargo shuttle run

Then, start the http request by accessing http://127.0.0.1:8000/get_deploy.

  1. Deploy your application on Shuttle servers
$ cargo shuttle deploy

Future Work

  1. Decode the XDR data returned by the Indexer and return that decoded data to the Dapp
  2. Add a mutation to renew the Mercury API Token?

About

API using shuttle to request Mercury (a Soroban indexer) database and send back the response

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages