-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement cli transfer and withdraw calls
- Loading branch information
1 parent
f78dc5f
commit afafb9f
Showing
6 changed files
with
62 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,49 @@ | ||
use crate::common::args::{AmountArg, PrivateKeyPathArg}; | ||
use crate::client::KairosClientError; | ||
use crate::common::args::{AmountArg, NonceArg, PrivateKeyPathArg}; | ||
use crate::error::CliError; | ||
|
||
use kairos_crypto::error::CryptoError; | ||
use kairos_crypto::implementations::Signer; | ||
use kairos_crypto::SignerFsExtension; | ||
use kairos_crypto::{SignerCore, SignerFsExtension}; | ||
|
||
use clap::Parser; | ||
use kairos_server::routes::transfer::TransferPath; | ||
use kairos_server::routes::withdraw::WithdrawPath; | ||
use kairos_server::routes::PayloadBody; | ||
use kairos_tx::asn::{SigningPayload, Withdrawal}; | ||
use reqwest::Url; | ||
|
||
#[derive(Parser)] | ||
pub struct Args { | ||
#[clap(flatten)] | ||
amount: AmountArg, | ||
#[clap(flatten)] | ||
private_key_path: PrivateKeyPathArg, | ||
#[clap(flatten)] | ||
nonce: NonceArg, | ||
} | ||
|
||
pub fn run(args: Args) -> Result<String, CliError> { | ||
let _amount: u64 = args.amount.field; | ||
let _signer = | ||
pub async fn run(args: Args, kairos_server_address: Url) -> Result<String, CliError> { | ||
let amount: u64 = args.amount.field; | ||
let signer = | ||
Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; | ||
let nonce = args.nonce.val; | ||
|
||
// TODO: Create transaction and sign it with `signer`. | ||
|
||
// TODO: Send transaction to the network, using Rust SDK. | ||
reqwest::Client::new() | ||
.post(kairos_server_address.join(WithdrawPath::PATH).unwrap()) | ||
.json(&PayloadBody { | ||
public_key: signer.to_public_key()?, | ||
payload: SigningPayload::new(nonce, Withdrawal::new(amount)) | ||
.try_into() | ||
.unwrap(), | ||
signature: vec![], | ||
}) | ||
.send() | ||
.await | ||
.map_err(KairosClientError::from)?; | ||
|
||
Ok("ok".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