cycles-sync: make obligato-url/key CLI configurable & fix wasmd invocations (#7)
This commit is contained in:
parent
cd442db003
commit
d78183b2c8
4 changed files with 19 additions and 13 deletions
|
@ -18,6 +18,17 @@ pub struct Cli {
|
||||||
#[arg(short = 'N', long, default_value = "http://127.0.0.1:26657")]
|
#[arg(short = 'N', long, default_value = "http://127.0.0.1:26657")]
|
||||||
pub node: Url,
|
pub node: Url,
|
||||||
|
|
||||||
|
/// Obligato API server.
|
||||||
|
#[arg(long, default_value = "https://bisenzone.obligato.network")]
|
||||||
|
pub obligato_url: Url,
|
||||||
|
|
||||||
|
/// Obligato key.
|
||||||
|
#[arg(
|
||||||
|
long,
|
||||||
|
default_value = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNhZXNzdGpjdG16bXVqaW55cGJlIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcwMzAxOTE0OSwiZXhwIjoyMDE4NTk1MTQ5fQ.EV6v5J3dz8WHAdTK4_IEisKzF-n1Gqyn4wCce_Zrqf4"
|
||||||
|
)]
|
||||||
|
pub obligato_key: String,
|
||||||
|
|
||||||
/// Path to output CSV file
|
/// Path to output CSV file
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
pub keys_file: PathBuf,
|
pub keys_file: PathBuf,
|
||||||
|
|
|
@ -41,8 +41,6 @@ const MNEMONIC_PHRASE: &str = "clutch debate vintage foster barely primary clown
|
||||||
const ALICE_ID: &str = "7bfad4e8-d898-4ce2-bbac-1beff7182319";
|
const ALICE_ID: &str = "7bfad4e8-d898-4ce2-bbac-1beff7182319";
|
||||||
const BANK_DEBTOR_ID: &str = "3879fa15-d86e-4464-b679-0a3d78cf3dd3";
|
const BANK_DEBTOR_ID: &str = "3879fa15-d86e-4464-b679-0a3d78cf3dd3";
|
||||||
|
|
||||||
const OBLIGATO_URL: &str = "https://bisenzone.obligato.network";
|
|
||||||
|
|
||||||
type Sha256Digest = [u8; 32];
|
type Sha256Digest = [u8; 32];
|
||||||
|
|
||||||
type DynError = Box<dyn Error>;
|
type DynError = Box<dyn Error>;
|
||||||
|
@ -79,7 +77,7 @@ async fn main() -> Result<(), DynError> {
|
||||||
async fn sync_setoffs(cli: Cli) -> Result<(), DynError> {
|
async fn sync_setoffs(cli: Cli) -> Result<(), DynError> {
|
||||||
let wasmd_client = CliWasmdClient::new(cli.node);
|
let wasmd_client = CliWasmdClient::new(cli.node);
|
||||||
let query_result: QueryResult<QueryAllSetoffsResponse> =
|
let query_result: QueryResult<QueryAllSetoffsResponse> =
|
||||||
wasmd_client.query_smart(&cli.contract, json!("get_all_setoffs"), &cli.chain_id)?;
|
wasmd_client.query_smart(&cli.contract, json!("get_all_setoffs"))?;
|
||||||
let setoffs = query_result.data.setoffs;
|
let setoffs = query_result.data.setoffs;
|
||||||
|
|
||||||
// read keys
|
// read keys
|
||||||
|
@ -119,7 +117,7 @@ async fn sync_setoffs(cli: Cli) -> Result<(), DynError> {
|
||||||
debug!("setoffs: {setoffs:?}");
|
debug!("setoffs: {setoffs:?}");
|
||||||
|
|
||||||
// send to Obligato
|
// send to Obligato
|
||||||
let client = HttpClient::new(OBLIGATO_URL.parse().unwrap());
|
let client = HttpClient::new(cli.obligato_url, cli.obligato_key);
|
||||||
client.set_setoffs(setoffs).await?;
|
client.set_setoffs(setoffs).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -127,7 +125,7 @@ async fn sync_setoffs(cli: Cli) -> Result<(), DynError> {
|
||||||
|
|
||||||
async fn sync_obligations(cli: Cli, epoch_pk: &str) -> Result<(), DynError> {
|
async fn sync_obligations(cli: Cli, epoch_pk: &str) -> Result<(), DynError> {
|
||||||
let mut intents = {
|
let mut intents = {
|
||||||
let client = HttpClient::new(OBLIGATO_URL.parse().unwrap());
|
let client = HttpClient::new(cli.obligato_url, cli.obligato_key);
|
||||||
client.get_obligations().await.unwrap()
|
client.get_obligations().await.unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,15 @@ use crate::{
|
||||||
pub struct HttpClient {
|
pub struct HttpClient {
|
||||||
client: reqwest::Client,
|
client: reqwest::Client,
|
||||||
url: Url,
|
url: Url,
|
||||||
|
key: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HttpClient {
|
impl HttpClient {
|
||||||
pub fn new(url: Url) -> Self {
|
pub fn new(url: Url, key: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
client: reqwest::Client::new(),
|
client: reqwest::Client::new(),
|
||||||
url,
|
url,
|
||||||
|
key,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,8 +31,6 @@ impl HttpClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNhZXNzdGpjdG16bXVqaW55cGJlIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDMwMTkxNDksImV4cCI6MjAxODU5NTE0OX0.gQsQ26W2AGfwmncTecfKaenRaxhXwZFqLtmcllD_7Sg
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Client for HttpClient {
|
impl Client for HttpClient {
|
||||||
type Error = reqwest::Error;
|
type Error = reqwest::Error;
|
||||||
|
@ -39,7 +39,7 @@ impl Client for HttpClient {
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.post(self.url_with_path("api/sync/obligations2contract"))
|
.post(self.url_with_path("api/sync/obligations2contract"))
|
||||||
.json(&json!({"denom_id": "1", "key": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImNhZXNzdGpjdG16bXVqaW55cGJlIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcwMzAxOTE0OSwiZXhwIjoyMDE4NTk1MTQ5fQ.EV6v5J3dz8WHAdTK4_IEisKzF-n1Gqyn4wCce_Zrqf4"}))
|
.json(&json!({"denom_id": "1", "key": self.key }))
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.json::<GetObligationsResponse>()
|
.json::<GetObligationsResponse>()
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub trait WasmdClient {
|
||||||
&self,
|
&self,
|
||||||
contract: &Self::Address,
|
contract: &Self::Address,
|
||||||
query: Self::Query,
|
query: Self::Query,
|
||||||
chain_id: &Id,
|
|
||||||
) -> Result<R, Self::Error>;
|
) -> Result<R, Self::Error>;
|
||||||
|
|
||||||
fn tx_execute<M: ToString>(
|
fn tx_execute<M: ToString>(
|
||||||
|
@ -64,7 +63,6 @@ impl WasmdClient for CliWasmdClient {
|
||||||
&self,
|
&self,
|
||||||
contract: &Self::Address,
|
contract: &Self::Address,
|
||||||
query: Self::Query,
|
query: Self::Query,
|
||||||
chain_id: &Id,
|
|
||||||
) -> Result<R, Self::Error> {
|
) -> Result<R, Self::Error> {
|
||||||
let mut wasmd = Command::new("wasmd");
|
let mut wasmd = Command::new("wasmd");
|
||||||
let command = wasmd
|
let command = wasmd
|
||||||
|
@ -72,7 +70,6 @@ impl WasmdClient for CliWasmdClient {
|
||||||
.args(["query", "wasm"])
|
.args(["query", "wasm"])
|
||||||
.args(["contract-state", "smart", contract.as_ref()])
|
.args(["contract-state", "smart", contract.as_ref()])
|
||||||
.arg(query.to_string())
|
.arg(query.to_string())
|
||||||
.args(["--chain-id", chain_id.as_ref()])
|
|
||||||
.args(["--output", "json"]);
|
.args(["--output", "json"]);
|
||||||
|
|
||||||
let output = command.output()?;
|
let output = command.output()?;
|
||||||
|
@ -93,9 +90,9 @@ impl WasmdClient for CliWasmdClient {
|
||||||
let mut wasmd = Command::new("wasmd");
|
let mut wasmd = Command::new("wasmd");
|
||||||
let command = wasmd
|
let command = wasmd
|
||||||
.args(["--node", self.url.as_str()])
|
.args(["--node", self.url.as_str()])
|
||||||
|
.args(["--chain-id", chain_id.as_ref()])
|
||||||
.args(["tx", "wasm"])
|
.args(["tx", "wasm"])
|
||||||
.args(["execute", contract.as_ref(), &msg.to_string()])
|
.args(["execute", contract.as_ref(), &msg.to_string()])
|
||||||
.args(["--chain-id", chain_id.as_ref()])
|
|
||||||
.args(["--gas", &gas.to_string()])
|
.args(["--gas", &gas.to_string()])
|
||||||
.args(["--from", sender.as_ref()])
|
.args(["--from", sender.as_ref()])
|
||||||
.args(["--output", "json"])
|
.args(["--output", "json"])
|
||||||
|
|
Loading…
Reference in a new issue