Rename inner to client

This commit is contained in:
Philipp Hoenisch 2020-11-03 11:49:53 +11:00
parent f0fbe785c8
commit 1a38bf57f2
No known key found for this signature in database
GPG Key ID: E5F8E74C672BC666
5 changed files with 17 additions and 19 deletions

View File

@ -245,8 +245,6 @@ impl MonerodArgs {
args.push(format!("--log-level {}", self.log_level));
}
// args.push(format!("--disable-rpc-login"));
args.join(" ")
}
}

View File

@ -119,7 +119,7 @@ impl<'c> Monero {
// generate the first 70 as bulk
let monerod = &self.monerod;
let block = monerod.inner().generate_blocks(70, &miner_address).await?;
let block = monerod.client().generate_blocks(70, &miner_address).await?;
tracing::info!("Generated {:?} blocks", block);
miner_wallet.refresh().await?;
@ -129,7 +129,7 @@ impl<'c> Monero {
let address = wallet.address().await?.address;
miner_wallet.transfer(&address, *amount).await?;
tracing::info!("Funded {} wallet with {}", wallet.name, amount);
monerod.inner().generate_blocks(10, &miner_address).await?;
monerod.client().generate_blocks(10, &miner_address).await?;
wallet.refresh().await?;
}
}
@ -137,7 +137,7 @@ impl<'c> Monero {
monerod.start_miner(&miner_address).await?;
tracing::info!("Waiting for miner wallet to catch up...");
let block_height = monerod.inner().get_block_count().await?;
let block_height = monerod.client().get_block_count().await?;
miner_wallet
.wait_for_wallet_height(block_height)
.await
@ -190,14 +190,14 @@ impl<'c> Monerod {
))
}
pub fn inner(&self) -> monerod::Client {
pub fn client(&self) -> monerod::Client {
monerod::Client::localhost(self.rpc_port)
}
/// Spawns a task to mine blocks in a regular interval to the provided
/// address
pub async fn start_miner(&self, miner_wallet_address: &str) -> Result<()> {
let monerod = self.inner();
let monerod = self.client();
let _ = tokio::spawn(mine(monerod, miner_wallet_address.to_string()));
Ok(())
}
@ -242,14 +242,14 @@ impl<'c> MoneroWalletRpc {
))
}
pub fn inner(&self) -> wallet::Client {
pub fn client(&self) -> wallet::Client {
wallet::Client::localhost(self.rpc_port)
}
// It takes a little while for the wallet to sync with monerod.
pub async fn wait_for_wallet_height(&self, height: u32) -> Result<()> {
let mut retry: u8 = 0;
while self.inner().block_height().await?.height < height {
while self.client().block_height().await?.height < height {
if retry >= 30 {
// ~30 seconds
bail!("Wallet could not catch up with monerod after 30 retries.")
@ -262,20 +262,20 @@ impl<'c> MoneroWalletRpc {
/// Sends amount to address
pub async fn transfer(&self, address: &str, amount: u64) -> Result<Transfer> {
self.inner().transfer(0, amount, address).await
self.client().transfer(0, amount, address).await
}
pub async fn address(&self) -> Result<GetAddress> {
self.inner().get_address(0).await
self.client().get_address(0).await
}
pub async fn balance(&self) -> Result<u64> {
self.inner().refresh().await?;
self.inner().get_balance(0).await
self.client().refresh().await?;
self.client().get_balance(0).await
}
pub async fn refresh(&self) -> Result<Refreshed> {
self.inner().refresh().await
self.client().refresh().await
}
}
/// Mine a block ever BLOCK_TIME_SECS seconds.

View File

@ -20,7 +20,7 @@ async fn init_miner_and_mine_to_miner_address() {
time::delay_for(Duration::from_millis(1010)).await;
// after a bit more than 1 sec another block should have been mined
let block_height = monerod.inner().get_block_count().await.unwrap();
let block_height = monerod.client().get_block_count().await.unwrap();
assert_that(&block_height).is_greater_than(70);
}

View File

@ -41,7 +41,7 @@ async fn fund_transfer_and_check_tx_key() {
monero
.monerod()
.inner()
.client()
.generate_blocks(10, &miner_address)
.await
.unwrap();
@ -54,7 +54,7 @@ async fn fund_transfer_and_check_tx_key() {
let tx_id = transfer.tx_hash;
let tx_key = transfer.tx_key;
let res = bob_wallet
.inner()
.client()
.check_tx_key(&tx_id, &tx_key, &bob_address)
.await
.expect("failed to check tx by key");

View File

@ -135,8 +135,8 @@ pub async fn init_test(
.await
.unwrap();
let alice_monero_wallet = wallet::monero::Wallet(monero.wallet("alice").unwrap().inner());
let bob_monero_wallet = wallet::monero::Wallet(monero.wallet("bob").unwrap().inner());
let alice_monero_wallet = wallet::monero::Wallet(monero.wallet("alice").unwrap().client());
let bob_monero_wallet = wallet::monero::Wallet(monero.wallet("bob").unwrap().client());
let alice_btc_wallet = wallet::bitcoin::Wallet::new("alice", &bitcoind.node_url)
.await