Skip to content
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

Format code using 'cargo fmt' #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ fn main() {
let out_dir = std::env::var("OUT_DIR").unwrap();

let _ = fs::remove_file(format!("{}/xpring.js", out_dir));

tonic_build::compile_protos("lib/protos/rippled/xrp_ledger.proto").unwrap();
tonic_build::configure()
.build_server(false)
.compile(
&[
"lib/protos/ilp/ilp_over_http_service.proto",
"lib/protos/ilp/balance_service.proto"
"lib/protos/ilp/balance_service.proto",
],
&["lib/protos/ilp/"],
).unwrap();

)
.unwrap();

fs::copy("js/dist/xpring.js", format!("{}/xpring.js", out_dir)).expect("Unable to copy file");
}
12 changes: 2 additions & 10 deletions examples/ilp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,10 @@ fn main() {
let mut ilp = Ilp::new("http://hermes-grpc.ilpv4.dev", "sdk_account1", "password")?;

// Get Balance
let balance =
ilp.get_balance()?;
let balance = ilp.get_balance()?;
println!("Get Balance {:#?}", balance);

// Send Payment
let payment =
ilp.send_to(
"$money.ilpv4.dev/sdk_account2",
13,
10
)?;
let payment = ilp.send_to("$money.ilpv4.dev/sdk_account2", 13, 10)?;
println!("\nILP Payment {:#?}", payment);


}
7 changes: 2 additions & 5 deletions examples/xrpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use xpring::Xrpl;

#[throws(_)]
fn main() {

// Xrpl instance (TestNet)
let mut xrpl = Xrpl::new("http://test.xrp.xpring.io:50051", false)?;

Expand Down Expand Up @@ -43,8 +42,7 @@ fn main() {
println!("\nRandom Wallet {}", random_wallet.wallet.public_key);

// // Generate a Wallet from a seed
let wallet_from_seed =
xrpl.wallet_from_seed("snYP7oArxKepd3GPDcrjMsJYiJeJB", None)?;
let wallet_from_seed = xrpl.wallet_from_seed("snYP7oArxKepd3GPDcrjMsJYiJeJB", None)?;
println!("\nWallet from seed {:#?}", wallet_from_seed);

// Generate a Wallet from mnemonic
Expand Down Expand Up @@ -78,8 +76,7 @@ fn main() {

//Send Payment
println!("\nSending payment...");
let sending_wallet =
xrpl.wallet_from_seed("shKtxFAYfNUHYayYMYkp3KjQQX2UY", None)?;
let sending_wallet = xrpl.wallet_from_seed("shKtxFAYfNUHYayYMYkp3KjQQX2UY", None)?;
println!("sending_wallet {:?}", sending_wallet);
let payment = xrpl.send(
12.12,
Expand Down
12 changes: 3 additions & 9 deletions src/address.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::javascript::{JavaScript, JsCall};
use anyhow::Error;
use fehler::throws;
use serde::{Deserialize, Serialize};
use anyhow::Error;

#[derive(Debug, Serialize)]
struct XAddressOptions {
Expand Down Expand Up @@ -31,10 +31,7 @@ impl<'a> XAddressOptions {
}
}

pub(crate) fn classic_address(
&'a mut self,
classic_addres: String,
) -> &'a mut XAddressOptions {
pub(crate) fn classic_address(&'a mut self, classic_addres: String) -> &'a mut XAddressOptions {
self.classic_address = Some(classic_addres);
self
}
Expand Down Expand Up @@ -85,10 +82,7 @@ pub(crate) fn is_valid_classic_address(jscontext: &mut JavaScript, address: &str
}

#[throws(_)]
pub(crate) fn decode_x_address(
jscontext: &mut JavaScript,
x_address: &str,
) -> XClassicAddress {
pub(crate) fn decode_x_address(jscontext: &mut JavaScript, x_address: &str) -> XClassicAddress {
let mut address = XAddressOptions::new(false);
address.x_address(x_address.to_owned());
let result = js!(jscontext.utils.decodeXAddress::<XClassicAddress>(address))?;
Expand Down
54 changes: 29 additions & 25 deletions src/ilpclient.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::i::prelude::*;
use anyhow::{bail, Error};
use fehler::throws;
use tokio::runtime::{Builder, Runtime};
use tonic::{metadata::MetadataValue, transport::Channel, Request};
use anyhow::{bail, Error};

#[derive(PartialEq, Debug)]
pub enum IlpPaymentStatus {
Expand Down Expand Up @@ -33,7 +33,7 @@ pub struct IlpClient {
rt: Runtime,
ilp_client: IlpOverHttpServiceClient<tonic::transport::Channel>,
balance_client: BalanceServiceClient<tonic::transport::Channel>,
account_id: &'static str
account_id: &'static str,
}

impl IlpClient {
Expand All @@ -44,25 +44,36 @@ impl IlpClient {
.enable_all()
.build()
.unwrap();
if token.is_empty() {
bail!("token cannot be empty");
}
if token.is_empty() {
bail!("token cannot be empty");
}
let channel = rt.block_on(Channel::from_static(url).connect())?;
let bearer = format!("Bearer {}", token);
//TODO is there a better way than creating two clients?
let bal_token = MetadataValue::from_str(&bearer)?;
let ilp_token = MetadataValue::from_str(&bearer)?;
let ilp_client =
IlpOverHttpServiceClient::with_interceptor(channel.clone(), move |mut ilp_req: Request<()>| {
ilp_req.metadata_mut().insert("authorization", ilp_token.clone());
let ilp_client = IlpOverHttpServiceClient::with_interceptor(
channel.clone(),
move |mut ilp_req: Request<()>| {
ilp_req
.metadata_mut()
.insert("authorization", ilp_token.clone());
Ok(ilp_req)
});
},
);
let balance_client =
BalanceServiceClient::with_interceptor(channel, move |mut balance_req: Request<()>| {
balance_req.metadata_mut().insert("authorization", bal_token.clone());
balance_req
.metadata_mut()
.insert("authorization", bal_token.clone());
Ok(balance_req)
});
Self { rt, ilp_client, balance_client, account_id }
Self {
rt,
ilp_client,
balance_client,
account_id,
}
}

#[throws(_)]
Expand All @@ -82,20 +93,20 @@ impl IlpClient {
prepaid_amount: result.prepaid_amount,
clearing_balance: result.clearing_balance,
}
},
}
Err(error) => {
// error returned is Unknown, not a lot of information...
bail!(format!("balance request failed: {:?}", error.code()));
}
}
}
}

#[throws(_)]
pub(crate) fn send(
&mut self,
destination_payment_pointer: String,
amount: u64,
timeout_seconds: u64
timeout_seconds: u64,
) -> IlpSendResponse {
let request = tonic::Request::new(SendPaymentRequest {
destination_payment_pointer,
Expand All @@ -118,12 +129,12 @@ impl IlpClient {
amount_delivered: result.amount_delivered,
amount_sent: result.amount_sent,
}
},
}
Err(_error) => {
// error returned is Unknown, not a lot of information...
bail!("payment send failed");
}
}
}
}
}

Expand All @@ -142,10 +153,7 @@ mod tests {
assert!(false);
}
Err(error) => {
assert_eq!(
"token cannot be empty",
error.to_string()
);
assert_eq!("token cannot be empty", error.to_string());
}
}
}
Expand Down Expand Up @@ -206,11 +214,7 @@ mod tests {
fn test_send_wrong_account() {
let mut client = IlpClient::connect(DEFAULT_SERVER_URL, "test.foo.bar", "password")?;
let original_amount = 12;
match client.send(
"$money/baz".to_owned(),
original_amount.clone(),
10,
) {
match client.send("$money/baz".to_owned(), original_amount.clone(), 10) {
Ok(_result) => {
assert!(false);
}
Expand Down
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@ mod i {
tonic::include_proto!("org.interledger.stream.proto");
pub mod prelude {
pub use super::{
ilp_over_http_service_client::IlpOverHttpServiceClient, SendPaymentRequest,
SendPaymentResponse, balance_service_client::BalanceServiceClient, GetBalanceRequest, GetBalanceResponse
balance_service_client::BalanceServiceClient,
ilp_over_http_service_client::IlpOverHttpServiceClient, GetBalanceRequest,
GetBalanceResponse, SendPaymentRequest, SendPaymentResponse,
};
}
}

// Public modules
pub mod address;
pub mod ilpclient;
pub mod transaction;
pub mod wallet;
pub mod xrplclient;
pub mod ilpclient;

pub use crate::xpring::{Xrpl, Ilp};
pub use crate::xpring::{Ilp, Xrpl};
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::address;
use crate::address::XClassicAddress;
use crate::javascript::JavaScript;
use anyhow::Error;
use fehler::throws;
use std::str;
use anyhow::Error;

// Address

Expand Down
2 changes: 1 addition & 1 deletion src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::javascript::{JavaScript, JsCall};
use anyhow::Error;
use fehler::throws;
use serde::{Deserialize, Serialize};
use anyhow::Error;

#[derive(Debug, Serialize)]
struct XGenerateWalletOptions {
Expand Down
Loading