Skip to content

Commit 9d5beeb

Browse files
committed
Merge remote-tracking branch 'origin/dev' into fix-tpu-v2-wait-for-payment-spend
# Conflicts: # mm2src/coins/eth/eth_tests.rs
2 parents 9007f12 + 0b090de commit 9d5beeb

File tree

26 files changed

+153
-115
lines changed

26 files changed

+153
-115
lines changed

mm2src/adex_cli/src/scenarios/init_mm2_cfg.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl Mm2Cfg {
107107

108108
self.dbdir = CustomType::<InquireOption<String>>::new("What is dbdir")
109109
.with_placeholder(DEFAULT_OPTION_PLACEHOLDER)
110-
.with_help_message("AtomicDEX API database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary")
110+
.with_help_message("Komodo DeFi Framework database path. Optional, defaults to a subfolder named DB in the path of your mm2 binary")
111111
.with_validator(is_reachable_dir)
112112
.prompt()
113113
.map_err(|error|
@@ -128,7 +128,7 @@ impl Mm2Cfg {
128128
fn inquire_net_id(&mut self) -> Result<()> {
129129
self.netid = CustomType::<u16>::new("What is the network `mm2` is going to be a part, netid:")
130130
.with_default(DEFAULT_NET_ID)
131-
.with_help_message(r#"Network ID number, telling the AtomicDEX API which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades"#)
131+
.with_help_message(r#"Network ID number, telling the Komodo DeFi Framework which network to join. 8762 is the current main network, though alternative netids can be used for testing or "private" trades"#)
132132
.with_placeholder(format!("{DEFAULT_NET_ID}").as_str())
133133
.prompt()
134134
.map_err(|error|
@@ -268,7 +268,7 @@ impl Mm2Cfg {
268268
.with_formatter(DEFAULT_OPTION_BOOL_FORMATTER)
269269
.with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER)
270270
.with_default(InquireOption::None)
271-
.with_help_message("If false the AtomicDEX API will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.")
271+
.with_help_message("If false the Komodo DeFi Framework will allow rpc methods sent from external IP addresses. Optional, defaults to true. Warning: Only use this if you know what you are doing, and have put the appropriate security measures in place.")
272272
.prompt()
273273
.map_err(|error|
274274
error_anyhow!("Failed to get rpc_local_only: {error}")
@@ -283,7 +283,7 @@ impl Mm2Cfg {
283283
.with_formatter(DEFAULT_OPTION_BOOL_FORMATTER)
284284
.with_default_value_formatter(DEFAULT_DEFAULT_OPTION_BOOL_FORMATTER)
285285
.with_default(InquireOption::None)
286-
.with_help_message("Runs AtomicDEX API as a seed node mode (acting as a relay for AtomicDEX API clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other AtomicDEX API clients using the same netID.")
286+
.with_help_message("Runs Komodo DeFi Framework as a seed node mode (acting as a relay for Komodo DeFi Framework clients). Optional, defaults to false. Use of this mode is not reccomended on the main network (8762) as it could result in a pubkey ban if non-compliant. on alternative testing or private networks, at least one seed node is required to relay information to other Komodo DeFi Framework clients using the same netID.")
287287
.prompt()
288288
.map_err(|error|
289289
error_anyhow!("Failed to get i_am_a_seed: {error}")

mm2src/coins/eth/eth_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use super::*;
22
use crate::IguanaPrivKey;
3-
use common::{block_on, block_on_f01};
3+
use common::block_on;
44
use futures_util::future;
55
use mm2_core::mm_ctx::MmCtxBuilder;
66

77
cfg_native!(
88
use crate::eth::for_tests::{eth_coin_for_test, eth_coin_from_keypair};
99
use crate::DexFee;
1010

11-
use common::now_sec;
11+
use common::{now_sec, block_on_f01};
1212
use ethkey::{Generator, Random};
1313
use mm2_test_helpers::for_tests::{ETH_MAINNET_CHAIN_ID, ETH_MAINNET_NODE, ETH_SEPOLIA_CHAIN_ID, ETH_SEPOLIA_NODES,
1414
ETH_SEPOLIA_TOKEN_CONTRACT};

mm2src/coins/hd_wallet/storage/sqlite_storage.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl HDWalletStorageInternalOps for HDWalletSqliteStorage {
101101
where
102102
Self: Sized,
103103
{
104-
let shared = ctx.shared_sqlite_conn.as_option().or_mm_err(|| {
104+
let shared = ctx.shared_sqlite_conn.get().or_mm_err(|| {
105105
HDWalletStorageError::Internal("'MmCtx::shared_sqlite_conn' is not initialized".to_owned())
106106
})?;
107107
let storage = HDWalletSqliteStorage {

mm2src/coins/lightning/ln_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub async fn init_db(ctx: &MmArc, ticker: String) -> EnableLightningResult<Sqlit
8787
let db = SqliteLightningDB::new(
8888
ticker,
8989
ctx.sqlite_connection
90+
.get()
9091
.ok_or(MmError::new(EnableLightningError::DbError(
9192
"sqlite_connection is not initialized".into(),
9293
)))?

mm2src/coins/nft/nft_structs.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -734,14 +734,15 @@ impl NftCtx {
734734
/// If an `NftCtx` instance doesn't already exist in the MM context, it gets created and cached for subsequent use.
735735
#[cfg(not(target_arch = "wasm32"))]
736736
pub(crate) fn from_ctx(ctx: &MmArc) -> Result<Arc<NftCtx>, String> {
737-
Ok(try_s!(from_ctx(&ctx.nft_ctx, move || {
737+
from_ctx(&ctx.nft_ctx, move || {
738738
let async_sqlite_connection = ctx
739739
.async_sqlite_connection
740+
.get()
740741
.ok_or("async_sqlite_connection is not initialized".to_owned())?;
741742
Ok(NftCtx {
742743
nft_cache_db: async_sqlite_connection.clone(),
743744
})
744-
})))
745+
})
745746
}
746747

747748
#[cfg(target_arch = "wasm32")]

mm2src/coins/tx_history_storage/sql_tx_history_storage_v2.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,12 @@ pub struct SqliteTxHistoryStorage(Arc<Mutex<Connection>>);
376376

377377
impl SqliteTxHistoryStorage {
378378
pub fn new(ctx: &MmArc) -> Result<Self, MmError<CreateTxHistoryStorageError>> {
379-
let sqlite_connection = ctx
380-
.sqlite_connection
381-
.ok_or(MmError::new(CreateTxHistoryStorageError::Internal(
382-
"sqlite_connection is not initialized".to_owned(),
383-
)))?;
379+
let sqlite_connection =
380+
ctx.sqlite_connection
381+
.get()
382+
.ok_or(MmError::new(CreateTxHistoryStorageError::Internal(
383+
"sqlite_connection is not initialized".to_owned(),
384+
)))?;
384385
Ok(SqliteTxHistoryStorage(sqlite_connection.clone()))
385386
}
386387
}

mm2src/coins/utxo/utxo_block_header_storage/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl Debug for BlockHeaderStorage {
2727
impl BlockHeaderStorage {
2828
#[cfg(all(not(test), not(target_arch = "wasm32")))]
2929
pub(crate) fn new_from_ctx(ctx: MmArc, ticker: String) -> Result<Self, BlockHeaderStorageError> {
30-
let sqlite_connection = ctx.sqlite_connection.ok_or(BlockHeaderStorageError::Internal(
30+
let sqlite_connection = ctx.sqlite_connection.get().ok_or(BlockHeaderStorageError::Internal(
3131
"sqlite_connection is not initialized".to_owned(),
3232
))?;
3333
Ok(BlockHeaderStorage {
@@ -50,8 +50,11 @@ impl BlockHeaderStorage {
5050
use db_common::sqlite::rusqlite::Connection;
5151
use std::sync::{Arc, Mutex};
5252

53-
let conn = Arc::new(Mutex::new(Connection::open_in_memory().unwrap()));
54-
let conn = ctx.sqlite_connection.clone_or(conn);
53+
let conn = ctx
54+
.sqlite_connection
55+
.get()
56+
.cloned()
57+
.unwrap_or_else(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap())));
5558

5659
Ok(BlockHeaderStorage {
5760
inner: Box::new(SqliteBlockHeadersStorage { ticker, conn }),

mm2src/coins/z_coin/storage/blockdb/blockdb_sql_storage.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,9 @@ impl BlockDbImpl {
4949
async_blocking(move || {
5050
let conn = Connection::open(path).map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?;
5151
let conn = Arc::new(Mutex::new(conn));
52-
let conn_clone = conn.clone();
53-
let conn_clone = conn_clone.lock().unwrap();
54-
run_optimization_pragmas(&conn_clone).map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?;
55-
conn_clone
52+
let conn_lock = conn.lock().unwrap();
53+
run_optimization_pragmas(&conn_lock).map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?;
54+
conn_lock
5655
.execute(
5756
"CREATE TABLE IF NOT EXISTS compactblocks (
5857
height INTEGER PRIMARY KEY,
@@ -61,6 +60,7 @@ impl BlockDbImpl {
6160
[],
6261
)
6362
.map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?;
63+
drop(conn_lock);
6464

6565
Ok(Self { db: conn, ticker })
6666
})
@@ -73,11 +73,12 @@ impl BlockDbImpl {
7373
async_blocking(move || {
7474
let conn = ctx
7575
.sqlite_connection
76-
.clone_or(Arc::new(Mutex::new(Connection::open_in_memory().unwrap())));
77-
let conn_clone = conn.clone();
78-
let conn_clone = conn_clone.lock().unwrap();
79-
run_optimization_pragmas(&conn_clone).map_err(|err| ZcoinStorageError::DbError(err.to_string()))?;
80-
conn_clone
76+
.get()
77+
.cloned()
78+
.unwrap_or_else(|| Arc::new(Mutex::new(Connection::open_in_memory().unwrap())));
79+
let conn_lock = conn.lock().unwrap();
80+
run_optimization_pragmas(&conn_lock).map_err(|err| ZcoinStorageError::DbError(err.to_string()))?;
81+
conn_lock
8182
.execute(
8283
"CREATE TABLE IF NOT EXISTS compactblocks (
8384
height INTEGER PRIMARY KEY,
@@ -86,6 +87,7 @@ impl BlockDbImpl {
8687
[],
8788
)
8889
.map_to_mm(|err| ZcoinStorageError::DbError(err.to_string()))?;
90+
drop(conn_lock);
8991

9092
Ok(BlockDbImpl { db: conn, ticker })
9193
})

mm2src/crypto/src/crypto_ctx.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,12 @@ impl CryptoCtx {
316316
*ctx_field = Some(result.clone());
317317
drop(ctx_field);
318318

319-
ctx.rmd160.pin(rmd160).map_to_mm(CryptoInitError::Internal)?;
319+
ctx.rmd160
320+
.set(rmd160)
321+
.map_to_mm(|_| CryptoInitError::Internal("Already Initialized".to_string()))?;
320322
ctx.shared_db_id
321-
.pin(shared_db_id)
322-
.map_to_mm(CryptoInitError::Internal)?;
323+
.set(shared_db_id)
324+
.map_to_mm(|_| CryptoInitError::Internal("Already Initialized".to_string()))?;
323325

324326
info!("Public key hash: {rmd160}");
325327
info!("Shared Database ID: {shared_db_id}");

mm2src/mm2_bin_lib/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn mm2_status() -> MainStatus {
4141
Err(_) => return MainStatus::NoRpc,
4242
};
4343

44-
if ctx.rpc_started.copy_or(false) {
44+
if *ctx.rpc_started.get().unwrap_or(&false) {
4545
MainStatus::RpcIsUp
4646
} else {
4747
MainStatus::NoRpc

mm2src/mm2_bin_lib/src/mm2_wasm_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ pub async fn mm2_rpc(payload: JsValue) -> Result<JsValue, JsValue> {
216216
Err(_) => return Err(Mm2RpcErr::NotRunning.into()),
217217
};
218218

219-
let wasm_rpc = ctx.wasm_rpc.ok_or(JsValue::from(Mm2RpcErr::NotRunning))?;
219+
let wasm_rpc = ctx.wasm_rpc.get().ok_or(JsValue::from(Mm2RpcErr::NotRunning))?;
220220
let response: Mm2RpcResponse = wasm_rpc.request(request_json).await.into();
221221

222222
serialize_to_js(&response).map_err(|e| {

mm2src/mm2_bitcoin/rpc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
extern crate core;
21
#[cfg(test)] extern crate lazy_static;
32
extern crate log;
43
extern crate rustc_hex as hex;

mm2src/mm2_bitcoin/rpc/src/v1/types/bytes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ impl ops::Deref for Bytes {
8585
fn deref(&self) -> &Self::Target { &self.0 }
8686
}
8787

88-
impl ::core::fmt::LowerHex for Bytes {
89-
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
88+
impl ::std::fmt::LowerHex for Bytes {
89+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
9090
for i in &self.0[..] {
9191
write!(f, "{:02x}", i)?;
9292
}

mm2src/mm2_bitcoin/rpc/src/v1/types/hash.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ macro_rules! impl_hash {
147147
}
148148
}
149149

150-
impl ::core::fmt::LowerHex for $name {
151-
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
150+
impl ::std::fmt::LowerHex for $name {
151+
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
152152
for i in &self.0[..] {
153153
write!(f, "{:02x}", i)?;
154154
}

mm2src/mm2_core/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ common = { path = "../common" }
1515
db_common = { path = "../db_common" }
1616
derive_more = "0.99"
1717
futures = { version = "0.3", package = "futures", features = ["compat", "async-await", "thread-pool"] }
18+
gstuff = { version = "0.7", features = ["nightly"] }
1819
hex = "0.4.2"
1920
lazy_static = "1.4"
2021
libp2p = { git = "https://github.com/KomodoPlatform/rust-libp2p.git", tag = "k-0.52.4", default-features = false, features = ["identify"] }
@@ -31,13 +32,11 @@ shared_ref_counter = { path = "../common/shared_ref_counter" }
3132
uuid = { version = "1.2.2", features = ["fast-rng", "serde", "v4"] }
3233

3334
[target.'cfg(target_arch = "wasm32")'.dependencies]
34-
gstuff = { version = "0.7", features = ["nightly"] }
3535
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
3636
mm2_rpc = { path = "../mm2_rpc", features = [ "rpc_facilities" ] }
3737
wasm-bindgen-test = { version = "0.3.2" }
3838

3939
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4040
rustls = { version = "0.21", default-features = false }
41-
gstuff = { version = "0.7", features = ["nightly"] }
4241
instant = "0.1.12"
4342
tokio = { version = "1.20", features = ["io-util", "rt-multi-thread", "net"] }

0 commit comments

Comments
 (0)