Skip to content

Commit

Permalink
sdk 0.30.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gianmarco Fraccaroli committed Jan 26, 2024
1 parent 98c740e commit a2db050
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 23 deletions.
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rand = "0.8.5"
rand_chacha = "0.3.1"
dotenvy = "0.15.7"
hex = "0.4.3"
namada_sdk = { git = "https://github.com/anoma/namada", tag = "v0.30.2", default-features = false, features = ["tendermint-rpc", "std", "async-client", "async-send", "download-params"] }
namada_sdk = { git = "https://github.com/anoma/namada", tag = "v0.30.2", default-features = false, features = ["tendermint-rpc", "std", "async-client", "async-send", "download-params", "rand"] }
tendermint-config = "0.34.0"
tendermint-rpc = { version = "0.34.0", features = ["http-client"]}
orion = "0.17.5"
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ use vergen::EmitBuilder;
fn main() -> Result<(), Box<dyn Error>> {
EmitBuilder::builder().all_git().emit()?;
Ok(())
}
}
6 changes: 3 additions & 3 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use axum::{
use lazy_static::lazy_static;
use namada_sdk::{
args::TxBuilder,
core::types::{address::Address, chain::ChainId, key::RefTo},
io::NullIo,
masp::fs::FsShieldedUtils,
types::{address::Address, chain::ChainId, key::RefTo},
wallet::fs::FsWalletUtils,
NamadaImpl,
};
Expand Down Expand Up @@ -75,7 +75,7 @@ impl ApplicationServer {
tracing::info!("Sleeping until: {}", chain_start);
sleep(Duration::from_secs(60)).await;
}
};
}

let url = Url::from_str(&rpc).expect("invalid RPC address");
let http_client = HttpClient::new(url).unwrap();
Expand Down Expand Up @@ -116,7 +116,7 @@ impl ApplicationServer {
difficulty,
chain_id,
chain_start,
withdraw_limit
withdraw_limit,
);

Router::new()
Expand Down
2 changes: 1 addition & 1 deletion src/dto/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,5 @@ pub struct FaucetSettingResponse {
pub chain_id: String,
pub start_at: i64,
pub withdraw_limit: u64,
pub tokens_alias_to_address: HashMap<String, String>
pub tokens_alias_to_address: HashMap<String, String>,
}
2 changes: 1 addition & 1 deletion src/error/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub enum FaucetError {
#[error("Error while sending transfer: {0}")]
SdkError(String),
#[error("Withdraw limit must be less then {0}")]
InvalidWithdrawLimit(u64)
InvalidWithdrawLimit(u64),
}

impl IntoResponse for FaucetError {
Expand Down
25 changes: 16 additions & 9 deletions src/handler/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ use axum::{extract::State, Json};
use axum_macros::debug_handler;
use namada_sdk::{
args::InputAmount,
core::types::{
address::Address,
masp::{TransferSource, TransferTarget},
},
rpc,
signing::default_sign,
tendermint::abci::Code,
tx::data::ResultCode,
types::{
address::Address,
masp::{TransferSource, TransferTarget},
},
Namada,
core::types::transaction::ResultCode
};

use crate::{
dto::faucet::{FaucetRequestDto, FaucetResponseDto, FaucetResponseStatusDto, FaucetSettingResponse},
dto::faucet::{
FaucetRequestDto, FaucetResponseDto, FaucetResponseStatusDto, FaucetSettingResponse,
},
error::{api::ApiError, faucet::FaucetError, validate::ValidatedRequest},
repository::faucet::FaucetRepositoryTrait,
state::faucet::FaucetState,
Expand All @@ -32,7 +34,10 @@ pub async fn faucet_settings(
chain_id: state.chain_id,
start_at: state.chain_start,
withdraw_limit: state.withdraw_limit,
tokens_alias_to_address: HashMap::from([("NAM".to_string(), nam_token_address.to_string())])
tokens_alias_to_address: HashMap::from([(
"NAM".to_string(),
nam_token_address.to_string(),
)]),
};

Ok(Json(response))
Expand All @@ -58,7 +63,7 @@ pub async fn request_transfer(
let auth_key: String = state.auth_key.clone();

if payload.transfer.amount > state.withdraw_limit {
return Err(FaucetError::InvalidWithdrawLimit(state.withdraw_limit).into())
return Err(FaucetError::InvalidWithdrawLimit(state.withdraw_limit).into());
}

let token_address = Address::decode(payload.transfer.token.clone());
Expand Down Expand Up @@ -133,7 +138,9 @@ pub async fn request_transfer(

let (transfer_result, tx_hash) = if let Ok(response) = process_tx_response {
match response {
namada_sdk::tx::ProcessTxResponse::Applied(r) => (r.code.eq(&ResultCode::Ok), Some(r.hash)),
namada_sdk::tx::ProcessTxResponse::Applied(r) => {
(r.code.eq(&ResultCode::Ok), Some(r.hash))
}
namada_sdk::tx::ProcessTxResponse::Broadcast(r) => {
(r.code.eq(&Code::Ok), Some(r.hash.to_string()))
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/namada.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use namada_sdk::{
core::types::key::common::SecretKey,
io::NullIo,
masp::{fs::FsShieldedUtils, ShieldedContext},
types::key::common::SecretKey,
wallet::{fs::FsWalletUtils, Wallet},
NamadaImpl,
};
Expand Down
2 changes: 1 addition & 1 deletion src/sdk/utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::str::FromStr;

use namada_sdk::core::types::{address::Address, key::common::SecretKey};
use namada_sdk::types::{address::Address, key::common::SecretKey};

pub fn sk_from_str(sk: &str) -> SecretKey {
SecretKey::from_str(sk).expect("Should be able to decode secret key.")
Expand Down
10 changes: 5 additions & 5 deletions src/state/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::sync::Arc;
use tokio::sync::RwLock;

use namada_sdk::{
core::types::address::Address, io::NullIo, masp::fs::FsShieldedUtils,
wallet::fs::FsWalletUtils, NamadaImpl,
io::NullIo, masp::fs::FsShieldedUtils, types::address::Address, wallet::fs::FsWalletUtils,
NamadaImpl,
};
use tendermint_rpc::HttpClient;

Expand All @@ -21,7 +21,7 @@ pub struct FaucetState {
pub difficulty: u64,
pub chain_id: String,
pub chain_start: i64,
pub withdraw_limit: u64
pub withdraw_limit: u64,
}

impl FaucetState {
Expand All @@ -33,7 +33,7 @@ impl FaucetState {
difficulty: u64,
chain_id: String,
chain_start: i64,
withdraw_limit: u64
withdraw_limit: u64,
) -> Self {
Self {
faucet_service: FaucetService::new(data),
Expand All @@ -44,7 +44,7 @@ impl FaucetState {
difficulty,
chain_id,
chain_start,
withdraw_limit: withdraw_limit * 10_u64.pow(6)
withdraw_limit: withdraw_limit * 10_u64.pow(6),
}
}
}

0 comments on commit a2db050

Please sign in to comment.