testnet
This commit is contained in:
parent
6e95f609ea
commit
56b70bcceb
|
@ -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);
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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]
|
||||||
|
|
|
@ -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(())
|
||||||
|
}
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,6 +160,7 @@ pub async fn sync_async<'a>(
|
||||||
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.chain.has_unified() {
|
||||||
// Orchard
|
// Orchard
|
||||||
log::info!("Orchard");
|
log::info!("Orchard");
|
||||||
{
|
{
|
||||||
|
@ -175,6 +176,7 @@ pub async fn sync_async<'a>(
|
||||||
synchronizer.initialize(height)?;
|
synchronizer.initialize(height)?;
|
||||||
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
progress.trial_decryptions += synchronizer.process(&blocks.0)? as u64;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let db = db_builder.build()?;
|
let db = db_builder.build()?;
|
||||||
db.store_block_timestamp(last_height, &last_hash, last_timestamp)?;
|
db.store_block_timestamp(last_height, &last_hash, last_timestamp)?;
|
||||||
|
|
Loading…
Reference in New Issue