use crate::config::{ClientConfig, WalletConfig};
use crate::get_base_address_macro;
use crate::lightclient::LightClient;
use crate::testutils::lightclient::from_inputs;
use crate::testutils::timed;
use crate::wallet::keys::unified::ReceiverSelection;
#[allow(async_fn_in_trait)]
#[allow(opaque_hidden_inferred_bound)]
pub trait ConductChain {
async fn setup() -> Self;
fn lightserver_uri(&self) -> Option<http::Uri>;
async fn create_faucet(&mut self) -> LightClient;
async fn zingo_config(&mut self) -> crate::config::ClientConfig;
async fn create_client(&mut self) -> LightClient {
let config = timed("create_client::zingo_config", self.zingo_config()).await;
assert!(!matches!(config.wallet_config(), WalletConfig::Read));
let mut lightclient = timed(
"create_client::new_nakednet_consented",
LightClient::new_nakednet_consented(config, false),
)
.await
.unwrap();
timed(
"create_client::generate_unified_address",
lightclient.generate_unified_address(
ReceiverSelection::sapling_only(),
zip32::AccountId::ZERO,
),
)
.await
.unwrap();
lightclient
}
async fn load_client(&mut self, config: ClientConfig) -> LightClient {
assert!(matches!(config.wallet_config(), WalletConfig::Read));
LightClient::new_nakednet_consented(config, false)
.await
.unwrap()
}
async fn increase_chain_height(&mut self);
async fn sync_client_to_tip(&self, client: &mut LightClient) {
client.sync_and_await().await.unwrap();
}
async fn fund_client_orchard(&mut self, value: u64) -> LightClient {
let mut faucet = timed("fund_client_orchard::create_faucet", self.create_faucet()).await;
let mut recipient = timed("fund_client_orchard::create_client", self.create_client()).await;
timed(
"fund_client_orchard::increase_chain_height[pre-send]",
self.increase_chain_height(),
)
.await;
timed(
"fund_client_orchard::sync_faucet_to_tip",
self.sync_client_to_tip(&mut faucet),
)
.await;
let recipient_unified_address =
timed("fund_client_orchard::get_recipient_address", async {
get_base_address_macro!(recipient, "unified")
})
.await;
timed(
"fund_client_orchard::quick_send",
from_inputs::quick_send(
&mut faucet,
vec![(recipient_unified_address.as_str(), value, None)],
),
)
.await
.unwrap();
timed(
"fund_client_orchard::increase_chain_height[post-send]",
self.increase_chain_height(),
)
.await;
timed(
"fund_client_orchard::sync_recipient_to_tip",
self.sync_client_to_tip(&mut recipient),
)
.await;
recipient
}
fn confirmation_patience_blocks(&self) -> usize;
}