This commit is contained in:
Hanh 2022-11-13 17:00:21 +08:00
parent 6e95f609ea
commit 56b70bcceb
9 changed files with 66 additions and 64 deletions

View File

@ -86,12 +86,6 @@ struct CResult_____c_char new_diversified_address(void);
struct CResult_u32 get_latest_height(void); struct CResult_u32 get_latest_height(void);
struct CResult_____c_char send_multi_payment(uint8_t coin,
uint32_t account,
char *recipients_json,
uint32_t anchor_offset,
int64_t port);
void skip_to_last_height(uint8_t coin); void skip_to_last_height(uint8_t coin);
struct CResult_u32 rewind_to(uint32_t height); struct CResult_u32 rewind_to(uint32_t height);

View File

@ -1,6 +1,6 @@
//! Contact Address book //! Contact Address book
use crate::api::payment_v2::build_sign_send_multi_payment; use crate::api::payment_v2::{build_tx_plan, sign_and_broadcast};
use crate::api::recipient::RecipientMemo; use crate::api::recipient::RecipientMemo;
use crate::api::sync::get_latest_height; use crate::api::sync::get_latest_height;
use crate::coinconfig::CoinConfig; use crate::coinconfig::CoinConfig;
@ -50,14 +50,14 @@ async fn save_contacts_tx(memos: &[Memo], anchor_offset: u32) -> anyhow::Result<
}) })
.collect(); .collect();
let tx_id = build_sign_send_multi_payment( let tx_plan = build_tx_plan(
c.coin, c.coin,
c.id_account, c.id_account,
last_height, last_height,
&recipients, &recipients,
anchor_offset, anchor_offset,
Box::new(|_| {}),
) )
.await?; .await?;
let tx_id = sign_and_broadcast(c.coin, c.id_account, &tx_plan).await?;
Ok(tx_id) Ok(tx_id)
} }

View File

@ -99,7 +99,7 @@ pub struct CResult<T> {
pub unsafe extern "C" fn init_wallet(db_path: *mut c_char) { pub unsafe extern "C" fn init_wallet(db_path: *mut c_char) {
try_init_logger(); try_init_logger();
from_c_str!(db_path); from_c_str!(db_path);
let _ = init_coin(0, &format!("{}/zec.db", &db_path)); let _ = init_coin(0, &format!("{}/zec-test.db", &db_path));
let _ = init_coin(1, &format!("{}/yec.db", &db_path)); let _ = init_coin(1, &format!("{}/yec.db", &db_path));
let _ = init_coin(2, &format!("{}/arrr.db", &db_path)); let _ = init_coin(2, &format!("{}/arrr.db", &db_path));
} }
@ -295,34 +295,34 @@ fn report_progress(progress: Progress, port: i64) {
} }
} }
#[tokio::main] // #[tokio::main]
#[no_mangle] // #[no_mangle]
pub async unsafe extern "C" fn send_multi_payment( // pub async unsafe extern "C" fn send_multi_payment(
coin: u8, // coin: u8,
account: u32, // account: u32,
recipients_json: *mut c_char, // recipients_json: *mut c_char,
anchor_offset: u32, // anchor_offset: u32,
port: i64, // port: i64,
) -> CResult<*mut c_char> { // ) -> CResult<*mut c_char> {
from_c_str!(recipients_json); // from_c_str!(recipients_json);
let res = async move { // let res = async move {
let height = crate::api::sync::get_latest_height().await?; // let height = crate::api::sync::get_latest_height().await?;
let recipients = crate::api::recipient::parse_recipients(&recipients_json)?; // let recipients = crate::api::recipient::parse_recipients(&recipients_json)?;
let res = crate::api::payment_v2::build_sign_send_multi_payment( // let res = crate::api::payment_v2::build_sign_send_multi_payment(
coin, // coin,
account, // account,
height, // height,
&recipients, // &recipients,
anchor_offset, // anchor_offset,
Box::new(move |progress| { // Box::new(move |progress| {
report_progress(progress, port); // report_progress(progress, port);
}), // }),
) // )
.await?; // .await?;
Ok(res) // Ok(res)
}; // };
to_cresult_str(res.await) // to_cresult_str(res.await)
} // }
#[tokio::main] #[tokio::main]
#[no_mangle] #[no_mangle]

View File

@ -87,20 +87,15 @@ pub async fn sign_and_broadcast(
) -> anyhow::Result<String> { ) -> anyhow::Result<String> {
let tx = sign_plan(coin, account, tx_plan)?; let tx = sign_plan(coin, account, tx_plan)?;
let txid = broadcast_tx(&tx).await?; let txid = broadcast_tx(&tx).await?;
let id_notes: Vec<_> = tx_plan
.spends
.iter()
.filter_map(|n| if n.id != 0 { Some(n.id) } else { None })
.collect();
mark_spent(coin, &id_notes)?;
Ok(txid) Ok(txid)
} }
pub async fn build_sign_send_multi_payment(
coin: u8,
account: u32,
last_height: u32,
recipients: &[RecipientMemo],
confirmations: u32,
progress_callback: PaymentProgressCallback,
) -> anyhow::Result<String> {
todo!()
}
/// Make a transaction that shields the transparent balance /// Make a transaction that shields the transparent balance
pub async fn shield_taddr(coin: u8, account: u32) -> anyhow::Result<String> { pub async fn shield_taddr(coin: u8, account: u32) -> anyhow::Result<String> {
// let last_height = get_latest_height().await?; // let last_height = get_latest_height().await?;
@ -108,3 +103,10 @@ pub async fn shield_taddr(coin: u8, account: u32) -> anyhow::Result<String> {
// Ok(tx_id) // Ok(tx_id)
todo!() todo!()
} }
fn mark_spent(coin: u8, ids: &[u32]) -> anyhow::Result<()> {
let c = CoinConfig::get(coin);
let mut db = c.db()?;
db.tx_mark_spend(ids)?;
Ok(())
}

View File

@ -577,6 +577,7 @@ impl DbAdapter {
witness, witness,
}; };
Ok(UTXO { Ok(UTXO {
id: id_note,
source, source,
amount: amount as u64, amount: amount as u64,
}) })
@ -606,6 +607,7 @@ impl DbAdapter {
witness, witness,
}; };
Ok(UTXO { Ok(UTXO {
id: id_note,
source, source,
amount: amount as u64, amount: amount as u64,
}) })

View File

@ -4,7 +4,7 @@ pub use crate::note_selection::types::{
}; };
pub use crate::note_selection::TransactionBuilderError::TxTooComplex; pub use crate::note_selection::TransactionBuilderError::TxTooComplex;
pub use builder::{build_tx, get_secret_keys, TxBuilderContext}; pub use builder::{build_tx, get_secret_keys, TxBuilderContext};
pub use fee::{FeeCalculator, FeeZIP327}; pub use fee::{FeeCalculator, FeeFlat, FeeZIP327};
pub use optimize::build_tx_plan; pub use optimize::build_tx_plan;
use std::str::FromStr; use std::str::FromStr;
pub use utxo::fetch_utxos; pub use utxo::fetch_utxos;

View File

@ -94,6 +94,7 @@ pub struct PoolAllocation(pub [u64; 3]);
#[derive(Clone, Serialize, Deserialize, Debug)] #[derive(Clone, Serialize, Deserialize, Debug)]
pub struct UTXO { pub struct UTXO {
pub id: u32,
pub source: Source, pub source: Source,
pub amount: u64, pub amount: u64,
} }

View File

@ -39,6 +39,7 @@ async fn get_transparent_utxos(coin: u8, account: u32) -> anyhow::Result<Vec<UTX
index: utxo.index as u32, index: utxo.index as u32,
}; };
UTXO { UTXO {
id: 0,
source, source,
amount: utxo.value_zat as u64, amount: utxo.value_zat as u64,
} }

View File

@ -160,20 +160,22 @@ pub async fn sync_async<'a>(
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64; progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
} }
// Orchard if c.chain.has_unified() {
log::info!("Orchard"); // Orchard
{ log::info!("Orchard");
let decrypter = OrchardDecrypter::new(network); {
let warper = WarpProcessor::new(OrchardHasher::new()); let decrypter = OrchardDecrypter::new(network);
let mut synchronizer = OrchardSynchronizer::new( let warper = WarpProcessor::new(OrchardHasher::new());
decrypter, let mut synchronizer = OrchardSynchronizer::new(
warper, decrypter,
orchard_vks.clone(), warper,
db_builder.clone(), orchard_vks.clone(),
"orchard".to_string(), db_builder.clone(),
); "orchard".to_string(),
synchronizer.initialize(height)?; );
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64; synchronizer.initialize(height)?;
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
}
} }
let db = db_builder.build()?; let db = db_builder.build()?;