Skip to content

Commit

Permalink
move default network closer to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
staszek-krotki committed Jul 17, 2023
1 parent 64daf03 commit 9f9ecb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
13 changes: 9 additions & 4 deletions core/payment-driver/erc20/src/driver/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use chrono::Utc;

// Workspace uses
use ya_payment_driver::driver::PaymentDriver;
use ya_payment_driver::{
bus,
db::models::Network,
Expand All @@ -32,10 +33,14 @@ pub async fn init(driver: &Erc20Driver, msg: Init) -> Result<(), GenericError> {
driver.is_account_active(&address)?
}

wallet::init_wallet(&msg)
.timeout(Some(30))
.await
.map_err(GenericError::new)??;
wallet::init_wallet(
msg.address(),
msg.network()
.unwrap_or_else(|| driver.get_default_network()),
)
.timeout(Some(30))
.await
.map_err(GenericError::new)??;

let network = network::network_like_to_network(msg.network());
let token = match network::get_network_token(network, msg.token()) {
Expand Down
9 changes: 3 additions & 6 deletions core/payment-driver/erc20/src/erc20/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use web3::types::{H160, H256, U256, U64};
// Workspace uses
use ya_payment_driver::{
db::models::{Network, TransactionEntity, TxType},
model::{GenericError, Init, PaymentDetails},
model::{GenericError, PaymentDetails},
};

// Local uses
Expand All @@ -35,7 +35,6 @@ use crate::{
convert_u256_gas_to_float, str_to_addr, topic_to_str_address, u256_to_big_dec,
},
},
GOERLI_NETWORK,
};
use ya_payment_driver::db::models::TransactionStatus;

Expand Down Expand Up @@ -70,10 +69,8 @@ pub async fn account_gas_balance(
Ok(balance)
}

pub async fn init_wallet(msg: &Init) -> Result<(), GenericError> {
log::debug!("init_wallet. msg={:?}", msg);
let address = msg.address();
let network = msg.network().unwrap_or_default();
pub async fn init_wallet(address: String, network: String) -> Result<(), GenericError> {
log::debug!("init_wallet. address={}, network={}", address, network);
let network = Network::from_str(&network).map_err(GenericError::new)?;

// Validate address and that checking balance of GLM and ETH works.
Expand Down

0 comments on commit 9f9ecb1

Please sign in to comment.