|
|
|
@ -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.
|
|
|
|
|