-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from monadicus/feat-cannon
feat(cannon): transaction cannon!!!
- Loading branch information
Showing
30 changed files
with
1,665 additions
and
192 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,66 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::{ensure, Result}; | ||
use tokio::process::Command; | ||
|
||
#[derive(Clone, Debug)] | ||
pub enum Authorize { | ||
TransferPublic { | ||
private_key: String, | ||
recipient: String, | ||
amount: u64, | ||
priority_fee: u64, | ||
}, | ||
} | ||
|
||
impl Authorize { | ||
pub async fn run(self, bin: &PathBuf) -> Result<serde_json::Value> { | ||
let mut command = Command::new(bin); | ||
command | ||
.stdout(std::io::stdout()) | ||
.stderr(std::io::stderr()) | ||
.arg("authorize"); | ||
|
||
match self { | ||
Self::TransferPublic { | ||
private_key, | ||
recipient, | ||
amount, | ||
priority_fee, | ||
} => { | ||
command | ||
.arg("transfer-public") | ||
.arg("--private-key") | ||
.arg(private_key) | ||
.arg("--recipient") | ||
.arg(recipient) | ||
.arg("--amount") | ||
.arg(amount.to_string()) | ||
.arg("--priority-fee") | ||
.arg(priority_fee.to_string()); | ||
} | ||
} | ||
|
||
command.arg("--broadcast"); | ||
|
||
let res = command.output().await?; | ||
|
||
if !res.status.success() { | ||
return Err(anyhow::anyhow!( | ||
"command failed with status {}: {}", | ||
res.status, | ||
String::from_utf8_lossy(&res.stderr) | ||
)); | ||
} | ||
|
||
let blob: serde_json::Value = serde_json::from_slice(&res.stdout)?; | ||
|
||
ensure!(blob.is_object(), "expected JSON object in response"); | ||
ensure!( | ||
blob.get("function").is_some() && blob.get("broadcast").is_some(), | ||
"expected function, fee, and broadcast fields in response" | ||
); | ||
|
||
Ok(blob) | ||
} | ||
} |
Oops, something went wrong.