Ycash network

This commit is contained in:
Hanh 2021-08-13 17:25:41 +08:00
parent ab084acde4
commit ce2dcdd3c6
4 changed files with 31 additions and 17 deletions

View File

@ -1,9 +1,29 @@
use zcash_primitives::consensus::Network;
#[path = "generated/cash.z.wallet.sdk.rpc.rs"]
pub mod lw_rpc;
pub const NETWORK: Network = Network::MainNetwork;
#[cfg(feature="ycash")]
mod coin {
use zcash_primitives::consensus::{Network, BranchId};
pub const NETWORK: Network = Network::YCashMainNetwork;
pub const TICKER: &str = "ycash";
pub fn get_branch(_height: u32) -> BranchId {
BranchId::Ycash
}
}
#[cfg(not(feature="ycash"))]
mod coin {
use zcash_primitives::consensus::{Network, BranchId, BlockHeight};
pub const NETWORK: Network = Network::MainNetwork;
pub const TICKER: &str = "zcash";
pub fn get_branch(height: u32) -> BranchId {
BranchId::for_height(&NETWORK, BlockHeight::from_u32(height))
}
}
pub use coin::{NETWORK, TICKER, get_branch};
// Mainnet
// pub const LWD_URL: &str = "https://mainnet.lightwalletd.com:9067";

View File

@ -1,5 +1,6 @@
use chrono::NaiveDateTime;
use std::collections::HashMap;
use crate::TICKER;
const DAY_SEC: i64 = 24*3600;
@ -12,11 +13,9 @@ pub async fn retrieve_historical_prices(timestamps: &[i64], currency: &str) -> a
let client = reqwest::Client::new();
let start = timestamps.first().unwrap();
let end = timestamps.last().unwrap() + DAY_SEC;
println!("{}", end);
let url = "https://api.coingecko.com/api/v3/coins/zcash/market_chart/range";
let url = format!("https://api.coingecko.com/api/v3/coins/{}/market_chart/range", TICKER);
let params = [("from", start.to_string()), ("to", end.to_string()), ("vs_currency", currency.to_string())];
let req = client.get(url).query(&params);
println!("{:?}", req);
let res = req.send().await?;
let r: serde_json::Value = res.json().await?;
let prices = r["prices"].as_array().unwrap();
@ -27,7 +26,6 @@ pub async fn retrieve_historical_prices(timestamps: &[i64], currency: &str) -> a
// rounded to daily
let date = NaiveDateTime::from_timestamp(ts, 0).date().and_hms(0, 0, 0);
let ts = date.timestamp();
println!("{} - {}", date, px);
if let Some(None) = timestamps_map.get(&ts) {
timestamps_map.insert(ts, Some(px));
}

View File

@ -1,8 +1,5 @@
use crate::chain::send_transaction;
use crate::{
connect_lightwalletd, get_latest_height, AddressList, CompactTxStreamerClient, DbAdapter,
GetAddressUtxosArg, NETWORK,
};
use crate::{connect_lightwalletd, get_latest_height, AddressList, CompactTxStreamerClient, DbAdapter, GetAddressUtxosArg, NETWORK, get_branch};
use anyhow::Context;
use bip39::{Language, Mnemonic, Seed};
use ripemd160::{Digest, Ripemd160};
@ -15,7 +12,7 @@ use tonic::Request;
use zcash_client_backend::encoding::{
decode_extended_full_viewing_key, decode_payment_address, encode_transparent_address,
};
use zcash_primitives::consensus::{BlockHeight, BranchId, Parameters};
use zcash_primitives::consensus::{BlockHeight, Parameters};
use zcash_primitives::legacy::{Script, TransparentAddress};
use zcash_primitives::transaction::builder::Builder;
use zcash_primitives::transaction::components::amount::DEFAULT_FEE;
@ -91,7 +88,7 @@ pub async fn shield_taddr(
let ovk = fvk.fvk.ovk;
builder.add_sapling_output(Some(ovk), pa, amount, None)?;
let consensus_branch_id = BranchId::for_height(&NETWORK, BlockHeight::from_u32(last_height));
let consensus_branch_id = get_branch(last_height);
let (tx, _) = builder.build(consensus_branch_id, prover)?;
let mut raw_tx: Vec<u8> = vec![];
tx.write(&mut raw_tx)?;

View File

@ -2,7 +2,7 @@ use crate::chain::send_transaction;
use crate::key::{decode_key, is_valid_key};
use crate::scan::ProgressCallback;
use crate::taddr::{get_taddr_balance, shield_taddr};
use crate::{connect_lightwalletd, get_latest_height, BlockId, CTree, DbAdapter, NETWORK};
use crate::{connect_lightwalletd, get_latest_height, BlockId, CTree, DbAdapter, NETWORK, get_branch};
use bip39::{Language, Mnemonic};
use rand::prelude::SliceRandom;
use rand::rngs::OsRng;
@ -15,7 +15,7 @@ use zcash_client_backend::encoding::{
decode_extended_full_viewing_key, decode_extended_spending_key, encode_payment_address,
};
use zcash_params::{OUTPUT_PARAMS, SPEND_PARAMS};
use zcash_primitives::consensus::{BlockHeight, BranchId, Parameters};
use zcash_primitives::consensus::{BlockHeight, Parameters};
use zcash_primitives::transaction::builder::{Builder, Progress};
use zcash_primitives::transaction::components::amount::MAX_MONEY;
use zcash_primitives::transaction::components::Amount;
@ -280,8 +280,7 @@ impl Wallet {
}
});
let consensus_branch_id =
BranchId::for_height(&NETWORK, BlockHeight::from_u32(last_height));
let consensus_branch_id = get_branch(last_height);
let (tx, _) = builder.build(consensus_branch_id, &self.prover)?;
log::info!("Tx built");
let mut raw_tx: Vec<u8> = vec![];