use bitcoin::{bip32::Xpriv, block::Header, Address, Block, BlockHash, Network, Transaction, Txid};
use corepc_types::model::{
GetAddressInfo, GetBlockchainInfo, GetMempoolInfo, GetRawMempool, GetRawMempoolVerbose,
GetRawTransaction, GetRawTransactionVerbose, GetTransaction, GetTxOut, ListTransactions,
ListUnspent, PsbtBumpFee, SignRawTransactionWithWallet, SubmitPackage, TestMempoolAccept,
WalletCreateFundedPsbt, WalletProcessPsbt,
};
use corepc_types::v29::ImportDescriptors;
use std::future::Future;
use crate::types::{ImportDescriptorInput, SighashType};
use crate::{
types::{
CreateRawTransactionArguments, CreateRawTransactionInput, CreateRawTransactionOutput,
ListUnspentQueryOptions, PreviousTransactionOutput, PsbtBumpFeeOptions,
WalletCreateFundedPsbtOptions,
},
ClientResult,
};
pub trait Reader {
fn estimate_smart_fee(
&self,
conf_target: u16,
) -> impl Future<Output = ClientResult<u64>> + Send;
fn get_block_header(
&self,
hash: &BlockHash,
) -> impl Future<Output = ClientResult<Header>> + Send;
fn get_block(&self, hash: &BlockHash) -> impl Future<Output = ClientResult<Block>> + Send;
fn get_block_height(&self, hash: &BlockHash) -> impl Future<Output = ClientResult<u64>> + Send;
fn get_block_header_at(&self, height: u64)
-> impl Future<Output = ClientResult<Header>> + Send;
fn get_block_at(&self, height: u64) -> impl Future<Output = ClientResult<Block>> + Send;
fn get_block_count(&self) -> impl Future<Output = ClientResult<u64>> + Send;
fn get_block_hash(&self, height: u64) -> impl Future<Output = ClientResult<BlockHash>> + Send;
fn get_blockchain_info(&self) -> impl Future<Output = ClientResult<GetBlockchainInfo>> + Send;
fn get_current_timestamp(&self) -> impl Future<Output = ClientResult<u32>> + Send;
fn get_raw_mempool(&self) -> impl Future<Output = ClientResult<GetRawMempool>> + Send;
fn get_raw_mempool_verbose(
&self,
) -> impl Future<Output = ClientResult<GetRawMempoolVerbose>> + Send;
fn get_mempool_info(&self) -> impl Future<Output = ClientResult<GetMempoolInfo>> + Send;
fn get_raw_transaction_verbosity_zero(
&self,
txid: &Txid,
) -> impl Future<Output = ClientResult<GetRawTransaction>> + Send;
fn get_raw_transaction_verbosity_one(
&self,
txid: &Txid,
) -> impl Future<Output = ClientResult<GetRawTransactionVerbose>> + Send;
fn get_tx_out(
&self,
txid: &Txid,
vout: u32,
include_mempool: bool,
) -> impl Future<Output = ClientResult<GetTxOut>> + Send;
fn network(&self) -> impl Future<Output = ClientResult<Network>> + Send;
}
pub trait Broadcaster {
fn send_raw_transaction(
&self,
tx: &Transaction,
) -> impl Future<Output = ClientResult<Txid>> + Send;
fn test_mempool_accept(
&self,
tx: &Transaction,
) -> impl Future<Output = ClientResult<TestMempoolAccept>> + Send;
fn submit_package(
&self,
txs: &[Transaction],
) -> impl Future<Output = ClientResult<SubmitPackage>> + Send;
}
pub trait Wallet {
fn get_new_address(&self) -> impl Future<Output = ClientResult<Address>> + Send;
fn get_transaction(
&self,
txid: &Txid,
) -> impl Future<Output = ClientResult<GetTransaction>> + Send;
fn list_transactions(
&self,
count: Option<usize>,
) -> impl Future<Output = ClientResult<ListTransactions>> + Send;
fn list_wallets(&self) -> impl Future<Output = ClientResult<Vec<String>>> + Send;
fn create_raw_transaction(
&self,
raw_tx: CreateRawTransactionArguments,
) -> impl Future<Output = ClientResult<Transaction>> + Send;
fn wallet_create_funded_psbt(
&self,
inputs: &[CreateRawTransactionInput],
outputs: &[CreateRawTransactionOutput],
locktime: Option<u32>,
options: Option<WalletCreateFundedPsbtOptions>,
bip32_derivs: Option<bool>,
) -> impl Future<Output = ClientResult<WalletCreateFundedPsbt>> + Send;
fn get_address_info(
&self,
address: &Address,
) -> impl Future<Output = ClientResult<GetAddressInfo>> + Send;
fn list_unspent(
&self,
min_conf: Option<u32>,
max_conf: Option<u32>,
addresses: Option<&[Address]>,
include_unsafe: Option<bool>,
query_options: Option<ListUnspentQueryOptions>,
) -> impl Future<Output = ClientResult<ListUnspent>> + Send;
}
pub trait Signer {
fn sign_raw_transaction_with_wallet(
&self,
tx: &Transaction,
prev_outputs: Option<Vec<PreviousTransactionOutput>>,
) -> impl Future<Output = ClientResult<SignRawTransactionWithWallet>> + Send;
fn get_xpriv(&self) -> impl Future<Output = ClientResult<Option<Xpriv>>> + Send;
fn import_descriptors(
&self,
descriptors: Vec<ImportDescriptorInput>,
wallet_name: String,
) -> impl Future<Output = ClientResult<ImportDescriptors>> + Send;
fn wallet_process_psbt(
&self,
psbt: &str,
sign: Option<bool>,
sighashtype: Option<SighashType>,
bip32_derivs: Option<bool>,
) -> impl Future<Output = ClientResult<WalletProcessPsbt>> + Send;
fn psbt_bump_fee(
&self,
txid: &Txid,
options: Option<PsbtBumpFeeOptions>,
) -> impl Future<Output = ClientResult<PsbtBumpFee>> + Send;
}