diff --git a/Cargo.lock b/Cargo.lock index ebadbe32c2..89785ae520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7115,25 +7115,33 @@ dependencies = [ name = "sia-rust" version = "0.1.0" dependencies = [ + "async-trait", "base64 0.21.7", "blake2b_simd", "chrono", "common", "derive_more", "ed25519-dalek", + "futures 0.3.28", "getrandom 0.2.9", "hex", "http 0.2.12", + "js-sys", "mm2_net", "nom", "once_cell", + "percent-encoding", "reqwest", "rustc-hex", "serde", + "serde-wasm-bindgen", "serde_json", "serde_with", + "thiserror", + "tokio", "url", "wasm-bindgen", + "wasm-bindgen-futures", "wasm-bindgen-test", "web-sys", ] diff --git a/mm2src/coins/sia-rust b/mm2src/coins/sia-rust index 8038a4b652..0e5ec03623 160000 --- a/mm2src/coins/sia-rust +++ b/mm2src/coins/sia-rust @@ -1 +1 @@ -Subproject commit 8038a4b652a100dd86d46d2449460db9e7fea757 +Subproject commit 0e5ec036237aa0b188f3a3ef3c0b19ef331e9c99 diff --git a/mm2src/coins/siacoin.rs b/mm2src/coins/siacoin.rs index 5d6c9c7bea..f02a541e55 100644 --- a/mm2src/coins/siacoin.rs +++ b/mm2src/coins/siacoin.rs @@ -28,8 +28,8 @@ use mm2_number::{BigDecimal, BigInt, MmNumber}; use num_traits::ToPrimitive; use rpc::v1::types::{Bytes as BytesJson, H256 as H256Json}; use serde_json::Value as Json; -use sia_rust::http::client::{SiaApiClient, SiaApiClientError, SiaHttpConf}; -use sia_rust::http::endpoints::{AddressUtxosRequest, AddressUtxosResponse, AddressesEventsRequest, +use sia_rust::http::client::{ApiClientHelpers, ApiClient as SiaApiClient, ApiClientError as SiaApiClientError, ClientConf}; +use sia_rust::http::endpoints::{GetAddressUtxosRequest, GetAddressUtxosResponse, AddressesEventsRequest, TxpoolBroadcastRequest}; use sia_rust::spend_policy::SpendPolicy; use sia_rust::transaction::{V1Transaction, V2Transaction}; @@ -41,6 +41,12 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::{Arc, Mutex}; +#[cfg(not(target_arch = "wasm32"))] +use sia_rust::http::client::native::NativeClient as SiaClientType; + +#[cfg(target_arch = "wasm32")] +use sia_rust::http::client::WasmClient as SiaClientType; + pub mod sia_hd_wallet; mod sia_withdraw; @@ -72,7 +78,7 @@ pub struct SiaCoinActivationParams { pub tx_history: bool, pub required_confirmations: Option, pub gap_limit: Option, - pub http_conf: SiaHttpConf, + pub http_conf: ClientConf, } pub struct SiaConfBuilder<'a> { @@ -94,12 +100,12 @@ impl<'a> SiaConfBuilder<'a> { // TODO see https://github.com/KomodoPlatform/komodo-defi-framework/pull/2086#discussion_r1521668313 // for additional fields needed -pub struct SiaCoinFields { +pub struct SiaCoinFieldsGeneric { /// SIA coin config pub conf: SiaCoinConf, pub priv_key_policy: PrivKeyPolicy, /// HTTP(s) client - pub http_client: SiaApiClient, + pub http_client: T, // FIXME replace this with a generic that impls ApiClient trait /// State of the transaction history loop (enabled, started, in progress, etc.) pub history_sync_state: Mutex, /// This abortable system is used to spawn coin's related futures that should be aborted on coin deactivation @@ -107,6 +113,8 @@ pub struct SiaCoinFields { pub abortable_system: AbortableQueue, } +pub type SiaCoinFields = SiaCoinFieldsGeneric; + pub async fn sia_coin_from_conf_and_params( ctx: &MmArc, ticker: &str, @@ -943,14 +951,14 @@ pub enum SiaTransactionTypes { } impl SiaCoin { - async fn get_unspent_outputs(&self, address: Address) -> Result> { - let request = AddressUtxosRequest { address }; + async fn get_unspent_outputs(&self, address: Address) -> Result> { + let request = GetAddressUtxosRequest { address , limit: None, offset: None}; let res = self.0.http_client.dispatcher(request).await?; Ok(res) } async fn get_address_events(&self, address: Address) -> Result, MmError> { - let request = AddressesEventsRequest { address }; + let request = AddressesEventsRequest { address , limit: None, offset: None }; let res = self.0.http_client.dispatcher(request).await?; Ok(res) } diff --git a/mm2src/coins/siacoin/sia_withdraw.rs b/mm2src/coins/siacoin/sia_withdraw.rs index 8aa75bed9c..5d84249771 100644 --- a/mm2src/coins/siacoin/sia_withdraw.rs +++ b/mm2src/coins/siacoin/sia_withdraw.rs @@ -5,7 +5,7 @@ use crate::{MarketCoinOps, PrivKeyPolicy, TransactionData, TransactionDetails, T use common::now_sec; use mm2_err_handle::mm_error::MmError; use mm2_err_handle::prelude::*; -use sia_rust::http::endpoints::AddressUtxosResponse; +use sia_rust::http::endpoints::GetAddressUtxosResponse; use sia_rust::spend_policy::SpendPolicy; use sia_rust::transaction::{SiacoinOutput, V2TransactionBuilder}; use sia_rust::types::{Address, Currency}; @@ -46,9 +46,9 @@ impl<'a> SiaWithdrawBuilder<'a> { #[allow(clippy::result_large_err)] fn select_outputs( &self, - mut unspent_outputs: AddressUtxosResponse, + mut unspent_outputs: GetAddressUtxosResponse, total_amount: u128, - ) -> Result> { + ) -> Result> { // Sort outputs from largest to smallest unspent_outputs.sort_by(|a, b| b.siacoin_output.value.0.cmp(&a.siacoin_output.value.0));