Skip to content

Commit

Permalink
Use .await instead of blocking .wait() in utxo get_tx_details_by_hash.
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii235 committed Mar 4, 2020
1 parent aaf0180 commit e373916
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,7 @@ impl MmCoin for UtxoCoin {
let hash = H256Json::from(hash);
let selfi = self.clone();
let fut = async move {
let verbose_tx = try_s!(selfi.rpc_client.get_verbose_transaction(hash).wait());
let verbose_tx = try_s!(selfi.rpc_client.get_verbose_transaction(hash).compat().await);
let tx: UtxoTx = try_s!(deserialize(verbose_tx.hex.as_slice()).map_err(|e| ERRL!("{:?}", e)));
let mut input_transactions: HashMap<&H256, UtxoTx> = HashMap::new();
let mut input_amount = 0;
Expand All @@ -1633,7 +1633,7 @@ impl MmCoin for UtxoCoin {
let input_tx = match input_transactions.entry(&input.previous_output.hash) {
Entry::Vacant(e) => {
let prev_hash = input.previous_output.hash.reversed();
let prev: BytesJson = try_s!(selfi.rpc_client.get_transaction_bytes(prev_hash.clone().into()).wait());
let prev: BytesJson = try_s!(selfi.rpc_client.get_transaction_bytes(prev_hash.clone().into()).compat().await);
let prev_tx: UtxoTx = try_s!(deserialize(prev.as_slice()).map_err(|e| ERRL!("{:?}, tx: {:?}", e, prev_hash)));
e.insert(prev_tx)
},
Expand Down
4 changes: 2 additions & 2 deletions mm2src/coins/utxo/rpc_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use bytes::{BytesMut};
use chain::{OutPoint, Transaction as UtxoTx};
use common::{StringError};
use common::wio::{slurp_req};
use common::executor::{spawn_electrum as spawn_electrum_fut, Timer};
use common::executor::{spawn, Timer};
use common::custom_futures::{join_all_sequential, select_ok_sequential};
use common::jsonrpc_client::{JsonRpcClient, JsonRpcResponseFut, JsonRpcRequest, JsonRpcResponse, RpcRes};
use futures01::{Future, Poll, Sink, Stream};
Expand Down Expand Up @@ -1328,7 +1328,7 @@ fn electrum_connect(
);

let connect_loop = select_func(connect_loop.boxed(), shutdown_rx.compat());
spawn_electrum_fut(connect_loop.map(|_| ()));
spawn(connect_loop.map(|_| ()));
ElectrumConnection {
addr,
config,
Expand Down
6 changes: 0 additions & 6 deletions mm2src/common/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ pub mod wio {
lazy_static! {
/// Shared asynchronous reactor.
pub static ref CORE: Mutex<Runtime> = Mutex::new (start_core_thread());
pub static ref ELECTRUM_CORE: Mutex<Runtime> = Mutex::new (start_core_thread());
/// Shared CPU pool to run intensive/sleeping requests on a separate thread.
///
/// Deprecated, prefer the futures 0.3 `POOL` instead.
Expand Down Expand Up @@ -797,11 +796,6 @@ pub mod executor {
unwrap! (crate::wio::CORE.lock()) .spawn (f);
}

pub fn spawn_electrum (future: impl Future03<Output = ()> + Send + 'static) {
let f = future.unit_error().boxed().compat();
unwrap! (crate::wio::ELECTRUM_CORE.lock()) .spawn (f);
}

/// Schedule the given `future` to be executed shortly after the given `utc` time is reached.
pub fn spawn_after (utc: f64, future: impl Future03<Output = ()> + Send + 'static) {
use crossbeam::channel;
Expand Down

0 comments on commit e373916

Please sign in to comment.