This commit is contained in:
Hanh 2022-06-10 01:05:58 +08:00
parent 5bf0eabca0
commit e8a930c1ef
4 changed files with 70 additions and 4 deletions

View File

@ -10,9 +10,10 @@ edition = "2018"
name = "scan_all"
harness = false
#[[bin]]
#name = "warp-cli"
#path = "src/main/warp_cli.rs"
[[bin]]
name = "warp-rpc"
path = "src/main/rpc.rs"
required-features = ["rpc"]
#[[bin]]
#name = "ledger"
@ -77,11 +78,13 @@ ledger-transport-hid = { version = "0.9", optional = true }
allo-isolate = { version = "0.1", optional = true }
once_cell = { version = "1.8.0", optional = true }
android_logger = { version = "0.10.0", optional = true }
rocket = { version = "0.5.0-rc.2", features = ["json"], optional = true }
[features]
ledger = ["ledger-apdu", "hmac", "ed25519-bip32", "ledger-transport-hid"]
ledger_sapling = ["ledger"]
dart_ffi = ["allo-isolate", "once_cell", "android_logger"]
rpc = ["rocket"]
# librustzcash synced to 35023ed8ca2fb1061e78fd740b640d4eefcc5edd

View File

@ -8,4 +8,5 @@ pub mod payment;
pub mod payment_uri;
pub mod sync;
#[cfg(feature = "dart_ffi")]
pub mod dart_ffi;

View File

@ -37,7 +37,7 @@ mod taddr;
mod transaction;
mod ua;
// mod wallet;
mod api;
pub mod api;
#[cfg(feature = "ledger")]
mod ledger;
@ -59,6 +59,7 @@ pub fn hex_to_hash(hex: &str) -> anyhow::Result<[u8; 32]> {
Ok(hash)
}
pub use crate::coinconfig::{CoinConfig, init_coin, set_active, set_active_account, set_coin_lwd_url};
pub use crate::builder::advance_tree;
pub use crate::chain::{
calculate_tree_state_v2, connect_lightwalletd, download_chain, get_latest_height, sync,

61
src/main/rpc.rs Normal file
View File

@ -0,0 +1,61 @@
#[macro_use]
extern crate rocket;
use rocket::serde::{Deserialize, json::Json};
use warp_api_ffi::CoinConfig;
#[rocket::main]
async fn main() -> anyhow::Result<()> {
warp_api_ffi::init_coin(0, "/tmp/zec.db")?;
let _ = rocket::build()
.mount(
"/",
routes![
set_lwd,
new_account,
sync,
// get_address,
// sync,
// rewind,
// balance,
// pay,
// tx_history
],
)
.launch()
.await?;
Ok(())
}
#[derive(Deserialize)]
#[serde(crate = "rocket::serde")]
pub struct AccountSeed {
coin: u8,
name: String,
key: Option<String>,
index: Option<u32>,
}
#[post("/set_lwd?<coin>&<lwd_url>")]
pub fn set_lwd(coin: u8, lwd_url: String) {
warp_api_ffi::set_coin_lwd_url(coin, &lwd_url);
}
#[post("/new_account", format = "application/json", data="<seed>")]
pub fn new_account(seed: Json<AccountSeed>) -> std::result::Result<String, String> {
let id_account = warp_api_ffi::api::account::new_account(seed.coin, &seed.name, seed.key.clone(), seed.index);
id_account.map(|v| v.to_string()).map_err(|e| e.to_string())
}
#[post("/sync?<offset>")]
pub async fn sync(offset: Option<u32>) {
let coin = CoinConfig::get_active();
let _ = warp_api_ffi::api::sync::coin_sync(coin.coin, true, offset.unwrap_or(0), |_| {}).await;
}
pub fn get_backup(id_account: u32) {
}