Skip to content

Commit

Permalink
feat(zcoin): allow ARRR/ZCOIN to compile in wasm (#1805)
Browse files Browse the repository at this point in the history
This commit refactors ARRR/ZCOIN code to be compiled in WebAssembly (WASM). It paves the way for subsequent implementation of the empty/todo functions related to WASM storage and other functionalities.

---------
Signed-off-by: borngraced <[email protected]>
  • Loading branch information
borngraced authored Jun 9, 2023
1 parent 2789a1b commit e876ee7
Show file tree
Hide file tree
Showing 12 changed files with 977 additions and 299 deletions.
6 changes: 3 additions & 3 deletions mm2src/coins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] }
# We don't need the default web3 features at all since we added our own web3 transport using shared HYPER instance.
web3 = { git = "https://github.com/KomodoPlatform/rust-web3", tag = "v0.19.0", default-features = false }
zbase32 = "0.1.2"
zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
zcash_primitives = { features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }

[target.'cfg(all(not(target_os = "ios"), not(target_os = "android"), not(target_arch = "wasm32")))'.dependencies]
bincode = { version = "1.3.3", default-features = false, optional = true }
Expand Down Expand Up @@ -140,10 +143,7 @@ tokio = { version = "1.20" }
tokio-rustls = { version = "0.23" }
tonic = { version = "0.7", features = ["tls", "tls-webpki-roots", "compression"] }
webpki-roots = { version = "0.22" }
zcash_client_backend = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
zcash_client_sqlite = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
zcash_primitives = { features = ["transparent-inputs"], git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }
zcash_proofs = { git = "https://github.com/KomodoPlatform/librustzcash.git", tag = "k-1.3.0" }

[target.'cfg(windows)'.dependencies]
winapi = "0.3"
Expand Down
16 changes: 3 additions & 13 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ use std::sync::atomic::Ordering as AtomicOrdering;
use std::sync::Arc;
use std::time::Duration;
use utxo_signer::with_key_pair::UtxoSignWithKeyPairError;
use zcash_primitives::transaction::Transaction as ZTransaction;

cfg_native! {
use crate::lightning::LightningCoin;
Expand All @@ -91,8 +92,6 @@ cfg_native! {
use lightning_invoice::{Invoice, ParseOrSemanticError};
use std::io;
use std::path::PathBuf;
use zcash_primitives::transaction::Transaction as ZTransaction;
use z_coin::ZcoinProtocolInfo;
}

cfg_wasm32! {
Expand Down Expand Up @@ -287,8 +286,8 @@ use utxo::{BlockchainNetwork, GenerateTxError, UtxoFeeDetails, UtxoTx};
pub mod nft;
use nft::nft_errors::GetNftInfoError;

#[cfg(not(target_arch = "wasm32"))] pub mod z_coin;
#[cfg(not(target_arch = "wasm32"))] use z_coin::ZCoin;
pub mod z_coin;
use z_coin::{ZCoin, ZcoinProtocolInfo};

pub type TransactionFut = Box<dyn Future<Item = TransactionEnum, Error = TransactionErr> + Send>;
pub type BalanceResult<T> = Result<T, MmError<BalanceError>>;
Expand Down Expand Up @@ -467,7 +466,6 @@ pub trait Transaction: fmt::Debug + 'static {
pub enum TransactionEnum {
UtxoTx(UtxoTx),
SignedEthTx(SignedEthTx),
#[cfg(not(target_arch = "wasm32"))]
ZTransaction(ZTransaction),
CosmosTransaction(CosmosTransaction),
#[cfg(not(target_arch = "wasm32"))]
Expand All @@ -476,7 +474,6 @@ pub enum TransactionEnum {

ifrom!(TransactionEnum, UtxoTx);
ifrom!(TransactionEnum, SignedEthTx);
#[cfg(not(target_arch = "wasm32"))]
ifrom!(TransactionEnum, ZTransaction);
#[cfg(not(target_arch = "wasm32"))]
ifrom!(TransactionEnum, LightningPayment);
Expand All @@ -496,7 +493,6 @@ impl Deref for TransactionEnum {
match self {
TransactionEnum::UtxoTx(ref t) => t,
TransactionEnum::SignedEthTx(ref t) => t,
#[cfg(not(target_arch = "wasm32"))]
TransactionEnum::ZTransaction(ref t) => t,
TransactionEnum::CosmosTransaction(ref t) => t,
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -2341,7 +2337,6 @@ pub enum MmCoinEnum {
QtumCoin(QtumCoin),
Qrc20Coin(Qrc20Coin),
EthCoin(EthCoin),
#[cfg(not(target_arch = "wasm32"))]
ZCoin(ZCoin),
Bch(BchCoin),
SlpToken(SlpToken),
Expand Down Expand Up @@ -2427,7 +2422,6 @@ impl From<LightningCoin> for MmCoinEnum {
fn from(c: LightningCoin) -> MmCoinEnum { MmCoinEnum::LightningCoin(c) }
}

#[cfg(not(target_arch = "wasm32"))]
impl From<ZCoin> for MmCoinEnum {
fn from(c: ZCoin) -> MmCoinEnum { MmCoinEnum::ZCoin(c) }
}
Expand All @@ -2447,7 +2441,6 @@ impl Deref for MmCoinEnum {
MmCoinEnum::TendermintToken(ref c) => c,
#[cfg(not(target_arch = "wasm32"))]
MmCoinEnum::LightningCoin(ref c) => c,
#[cfg(not(target_arch = "wasm32"))]
MmCoinEnum::ZCoin(ref c) => c,
MmCoinEnum::Test(ref c) => c,
#[cfg(all(
Expand Down Expand Up @@ -2840,7 +2833,6 @@ pub enum CoinProtocol {
token_contract_address: String,
decimals: u8,
},
#[cfg(not(target_arch = "wasm32"))]
ZHTLC(ZcoinProtocolInfo),
}

Expand Down Expand Up @@ -3093,7 +3085,6 @@ pub async fn lp_coininit(ctx: &MmArc, ticker: &str, req: &Json) -> Result<MmCoin
},
CoinProtocol::TENDERMINT { .. } => return ERR!("TENDERMINT protocol is not supported by lp_coininit"),
CoinProtocol::TENDERMINTTOKEN(_) => return ERR!("TENDERMINTTOKEN protocol is not supported by lp_coininit"),
#[cfg(not(target_arch = "wasm32"))]
CoinProtocol::ZHTLC { .. } => return ERR!("ZHTLC protocol is not supported by lp_coininit"),
#[cfg(not(target_arch = "wasm32"))]
CoinProtocol::LIGHTNING { .. } => return ERR!("Lightning protocol is not supported by lp_coininit"),
Expand Down Expand Up @@ -3686,7 +3677,6 @@ pub fn address_by_coin_conf_and_pubkey_str(
CoinProtocol::SOLANA | CoinProtocol::SPLTOKEN { .. } => {
ERR!("Solana pubkey is the public address - you do not need to use this rpc call.")
},
#[cfg(not(target_arch = "wasm32"))]
CoinProtocol::ZHTLC { .. } => ERR!("address_by_coin_conf_and_pubkey_str is not supported for ZHTLC protocol!"),
}
}
Expand Down
Loading

0 comments on commit e876ee7

Please sign in to comment.