1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// #![allow(dead_code)]
// #![allow(unused_imports)]
// #![warn(missing_docs)]

//! A library for fast synchronization of y/zcash blockchain
//!
//! - Implements the warp sync algorithm for sapling
//! - Multi Account management

//! # Example
//! ```rust
//! use warp_api_ffi::api::account::{get_backup, new_account};
//! use warp_api_ffi::api::sync::coin_sync;
//! use warp_api_ffi::{CoinConfig, init_coin, set_coin_lwd_url};
//! use lazy_static::lazy_static;
//! use std::sync::Mutex;
//!
//! lazy_static! {
//!     static ref CANCEL: Mutex<bool> = Mutex::new(false);
//! }
//!
//! const FVK: &str = "zxviews1q0duytgcqqqqpqre26wkl45gvwwwd706xw608hucmvfalr759ejwf7qshjf5r9aa7323zulvz6plhttp5mltqcgs9t039cx2d09mgq05ts63n8u35hyv6h9nc9ctqqtue2u7cer2mqegunuulq2luhq3ywjcz35yyljewa4mgkgjzyfwh6fr6jd0dzd44ghk0nxdv2hnv4j5nxfwv24rwdmgllhe0p8568sgqt9ckt02v2kxf5ahtql6s0ltjpkckw8gtymxtxuu9gcr0swvz";
//!
//! #[tokio::main]
//! async fn main() {
//!     env_logger::init();
//!
//!     // Initialize the library for Zcash (coin = 0)
//!     init_coin(0, "./zec.db").unwrap();
//!     set_coin_lwd_url(0, "https://lwdv3.zecwallet.co:443"); // ZecWallet Lightwalletd URL
//!
//!     // Create a new account with the ZEC pages viewing key
//!     let id_account = new_account(0, "test_account", Some(FVK.to_string()),
//!                                  None).unwrap();
//!
//!     // Synchronize
//!     coin_sync(0 /* zcash */,
//!               true /* retrieve tx details */,
//!               0 /* sync to tip */,
//!               100 /* spam filter threshold */, |p| {
//!             log::info!("Progress: {}", p.height);
//!         }, &CANCEL).await.unwrap();
//!
//!     // Grab the database accessor
//!     let cc = &CoinConfig::get(0 /* zcash */);
//!     let db = cc.db.as_ref().unwrap().clone();
//!     let db = db.lock().unwrap();
//!
//!     // Query the account balance
//!     let balance = db.get_balance(id_account).unwrap();
//!
//!     println!("Balance = {}", balance)
//! }
//! ```

#[path = "generated/cash.z.wallet.sdk.rpc.rs"]
pub mod lw_rpc;

use zcash_params::coin::{get_branch, get_coin_type, CoinType};

// Mainnet
const LWD_URL: &str = "https://mainnet.lightwalletd.com:9067";
// pub const LWD_URL: &str = "https://lwdv3.zecwallet.co";
// pub const LWD_URL: &str = "http://lwd.hanh.me:9067";
// pub const LWD_URL: &str = "http://127.0.0.1:9067";

// Testnet
// pub const LWD_URL: &str = "https://testnet.lightwalletd.com:9067";
// pub const LWD_URL: &str = "http://lwd.hanh.me:9067";
// pub const LWD_URL: &str = "http://127.0.0.1:9067";

// YCash
// pub const LWD_URL: &str = "https://lite.ycash.xyz:9067";

mod builder;
mod chain;
mod coinconfig;
mod commitment;
mod contact;
mod db;
mod fountain;
mod hash;
mod key;
mod key2;
mod mempool;
mod misc;
mod pay;
mod prices;
mod print;
mod scan;
mod taddr;
mod transaction;
mod ua;
mod zip32;
// mod wallet;
/// accounts, sync, payments, etc.
pub mod api;

#[cfg(feature = "ledger")]
mod ledger;

#[cfg(not(feature = "ledger"))]
#[allow(dead_code)]
mod ledger {
    pub async fn build_tx_ledger(
        _tx: &mut super::pay::Tx,
        _prover: &impl zcash_primitives::sapling::prover::TxProver,
    ) -> anyhow::Result<Vec<u8>> {
        unreachable!()
    }
}

pub use crate::chain::{
    connect_lightwalletd, get_best_server,
    ChainError,
};
pub use crate::coinconfig::{
    init_coin, set_active, set_active_account, set_coin_lwd_url, CoinConfig,
};
pub use crate::db::{AccountData, AccountInfo, AccountRec, DbAdapter, TxRec};
// pub use crate::fountain::FountainCodes;
pub use crate::hash::Hash;
pub use crate::key::KeyHelpers;
pub use crate::lw_rpc::compact_tx_streamer_client::CompactTxStreamerClient;
pub use crate::lw_rpc::*;
pub use crate::pay::{broadcast_tx, Tx, TxIn, TxOut};
pub use zip32::KeyPack;
// pub use crate::wallet::{decrypt_backup, encrypt_backup, RecipientMemo, Wallet, WalletBalance};

#[cfg(feature = "ledger_sapling")]
pub use crate::ledger::sapling::build_tx_ledger;

#[cfg(feature = "ledger")]
pub use crate::ledger::sweep_ledger;

#[cfg(feature = "nodejs")]
pub mod nodejs;

mod gpu;