-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add submitting txs to the cli #159
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c693daf
Write untested cli command: quartz contract tx
253d0ef
Get cli command for tx to work
edb5fc4
Merge branch 'main' into dave/145-query-enclave-directly
c31b6bc
Check for success of txs sent
a4c3625
Merge branch 'main' into dave/145-query-enclave-directly
b1bf035
Add in README instructions to get transfers app up with cli
81bbcd3
Run cargo fmt
dc4d233
Make README instructions more readable
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use async_trait::async_trait; | ||
use cycles_sync::wasmd_client::{CliWasmdClient, WasmdClient}; | ||
use reqwest::Url; | ||
use serde_json::Value; | ||
use tokio::time::{sleep, Duration}; | ||
use tracing::info; | ||
|
||
use super::utils::types::WasmdTxResponse; | ||
use crate::{ | ||
error::Error, | ||
handler::Handler, | ||
request::contract_tx::ContractTxRequest, | ||
response::{contract_tx::ContractTxResponse, Response}, | ||
Config, | ||
}; | ||
|
||
#[async_trait] | ||
impl Handler for ContractTxRequest { | ||
type Error = Error; | ||
type Response = Response; | ||
|
||
async fn handle(self, _: Config) -> Result<Self::Response, Self::Error> { | ||
let tx_hash = tx(self) | ||
.await | ||
.map_err(|e| Error::GenericErr(e.to_string()))?; | ||
|
||
Ok(ContractTxResponse { tx_hash }.into()) | ||
} | ||
} | ||
|
||
async fn tx(args: ContractTxRequest) -> Result<String, anyhow::Error> { | ||
let httpurl = Url::parse(&format!("http://{}", args.node_url))?; | ||
let wasmd_client = CliWasmdClient::new(Url::parse(httpurl.as_str())?); | ||
|
||
info!("🚀 Submitting Tx with msg: {}", args.msg); | ||
|
||
let tx_output: WasmdTxResponse = serde_json::from_str(&wasmd_client.tx_execute( | ||
&args.contract, | ||
&args.chain_id, | ||
args.gas, | ||
&args.sender, | ||
args.msg, | ||
args.amount, | ||
)?)?; | ||
|
||
let hash = tx_output.txhash.to_string(); | ||
info!("🚀 Successfully sent tx with hash {}", hash); | ||
info!("Waiting 5 seconds for tx to be included in block....."); | ||
|
||
// TODO - a more robust timeout mechanism with polling blocks | ||
sleep(Duration::from_secs(5)).await; | ||
|
||
// Query the transaction | ||
let tx_result: Value = wasmd_client.query_tx(&hash)?; | ||
|
||
// Check if the transaction was successful, otherwise return raw log or error | ||
if let Some(code) = tx_result["code"].as_u64() { | ||
if code == 0 { | ||
info!("Transaction was successful!"); | ||
} else { | ||
return Err(anyhow::anyhow!( | ||
"Transaction failed. Inspect raw log: {}", | ||
tx_result["raw_log"] | ||
)); | ||
} | ||
} else { | ||
return Err(anyhow::anyhow!("Unable to determine transaction status")); | ||
} | ||
|
||
Ok(tx_output.txhash.to_string()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use cosmrs::{tendermint::chain::Id as ChainId, AccountId}; | ||
|
||
use crate::request::Request; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct ContractTxRequest { | ||
pub node_url: String, | ||
pub contract: AccountId, | ||
pub chain_id: ChainId, | ||
pub gas: u64, | ||
pub sender: String, | ||
pub msg: String, | ||
pub amount: Option<String>, | ||
} | ||
|
||
impl From<ContractTxRequest> for Request { | ||
fn from(request: ContractTxRequest) -> Self { | ||
Self::ContractTx(request) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use serde::Serialize; | ||
|
||
use crate::response::Response; | ||
|
||
#[derive(Clone, Debug, Serialize, Default)] | ||
pub struct ContractTxResponse { | ||
pub tx_hash: String, | ||
} | ||
|
||
impl From<ContractTxResponse> for Response { | ||
fn from(response: ContractTxResponse) -> Self { | ||
Self::ContractTx(response) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A function with this polling mechanism exists in
handler/utils/helpers.rs
calledblock_tx_commit