Skip to content

Commit

Permalink
Add requires_nota field to swaps data jl777#591
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii235 committed Mar 4, 2020
1 parent afd2148 commit 475bd46
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ impl MarketCoinOps for EthCoin {
&self,
tx: &[u8],
confirmations: u64,
_requires_nota: bool,
wait_until: u64,
check_every: u64,
) -> Box<dyn Future<Item=(), Error=String> + Send> {
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub trait MarketCoinOps {
&self,
tx: &[u8],
confirmations: u64,
requires_nota: bool,
wait_until: u64,
check_every: u64,
) -> Box<dyn Future<Item=(), Error=String> + Send>;
Expand Down
1 change: 1 addition & 0 deletions mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl MarketCoinOps for TestCoin {
&self,
tx: &[u8],
confirmations: u64,
requires_nota: bool,
wait_until: u64,
check_every: u64,
) -> Box<dyn Future<Item=(), Error=String> + Send> {
Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/utxo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1302,14 +1302,15 @@ impl MarketCoinOps for UtxoCoin {
&self,
tx: &[u8],
confirmations: u64,
requires_nota: bool,
wait_until: u64,
check_every: u64,
) -> Box<dyn Future<Item=(), Error=String> + Send> {
let tx: UtxoTx = try_fus!(deserialize(tx).map_err(|e| ERRL!("{:?}", e)));
self.rpc_client.wait_for_confirmations(
&tx,
confirmations as u32,
self.requires_notarization.load(AtomicOrderding::Relaxed),
requires_nota,
wait_until,
check_every,
)
Expand Down
10 changes: 5 additions & 5 deletions mm2src/docker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod docker_tests {
unwrap!(client.import_address(&coin.my_address(), &coin.my_address(), false).wait());
let hash = client.send_to_address(address, &amount.into()).wait().unwrap();
let tx_bytes = client.get_transaction_bytes(hash).wait().unwrap();
unwrap!(coin.wait_for_confirmations(&tx_bytes, 1, timeout, 1).wait());
unwrap!(coin.wait_for_confirmations(&tx_bytes, 1, false, timeout, 1).wait());
log!({ "{:02x}", tx_bytes });
loop {
let unspents = client.list_unspent(0, std::i32::MAX, vec![coin.my_address().into()]).wait().unwrap();
Expand All @@ -221,7 +221,7 @@ mod docker_tests {
1.into(),
).wait().unwrap();

unwrap!(coin.wait_for_confirmations(&tx.tx_hex(), 1, timeout, 1).wait());
unwrap!(coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1).wait());

let refund_tx = coin.send_taker_refunds_payment(
&tx.tx_hex(),
Expand All @@ -230,7 +230,7 @@ mod docker_tests {
&[0; 20],
).wait().unwrap();

unwrap!(coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, timeout, 1).wait());
unwrap!(coin.wait_for_confirmations(&refund_tx.tx_hex(), 1, false, timeout, 1).wait());

let found = unwrap!(unwrap!(coin.search_for_swap_tx_spend_my(
time_lock,
Expand All @@ -256,7 +256,7 @@ mod docker_tests {
1.into(),
).wait().unwrap();

unwrap!(coin.wait_for_confirmations(&tx.tx_hex(), 1, timeout, 1).wait());
unwrap!(coin.wait_for_confirmations(&tx.tx_hex(), 1, false, timeout, 1).wait());

let spend_tx = coin.send_maker_spends_taker_payment(
&tx.tx_hex(),
Expand All @@ -265,7 +265,7 @@ mod docker_tests {
&secret,
).wait().unwrap();

unwrap!(coin.wait_for_confirmations(&spend_tx.tx_hex(), 1, timeout, 1).wait());
unwrap!(coin.wait_for_confirmations(&spend_tx.tx_hex(), 1, false, timeout, 1).wait());

let found = unwrap!(unwrap!(coin.search_for_swap_tx_spend_my(
time_lock,
Expand Down
6 changes: 6 additions & 0 deletions mm2src/lp_swap/maker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ pub struct MakerSwapData {
maker_amount: BigDecimal,
taker_amount: BigDecimal,
maker_payment_confirmations: u64,
maker_payment_requires_nota: Option<bool>,
taker_payment_confirmations: u64,
taker_payment_requires_nota: Option<bool>,
maker_payment_lock: u64,
/// Allows to recognize one SWAP from the other in the logs. #274.
uuid: String,
Expand Down Expand Up @@ -284,7 +286,9 @@ impl MakerSwap {
maker_amount: self.maker_amount.clone(),
taker_amount: self.taker_amount.clone(),
maker_payment_confirmations: self.maker_coin.required_confirmations(),
maker_payment_requires_nota: Some(self.maker_coin.requires_notarization()),
taker_payment_confirmations: self.taker_coin.required_confirmations(),
taker_payment_requires_nota: Some(self.taker_coin.requires_notarization()),
maker_payment_lock: started_at + lock_duration * 2,
my_persistent_pub: self.my_persistent_pub.clone().into(),
uuid: self.uuid.clone(),
Expand Down Expand Up @@ -502,6 +506,7 @@ impl MakerSwap {
let f = self.maker_coin.wait_for_confirmations(
&unwrap!(self.r().maker_payment.clone()).tx_hex,
self.r().data.maker_payment_confirmations,
self.r().data.maker_payment_requires_nota.unwrap_or(false),
maker_payment_wait_confirm,
WAIT_CONFIRM_INTERVAL,
);
Expand Down Expand Up @@ -591,6 +596,7 @@ impl MakerSwap {
let wait_f = self.taker_coin.wait_for_confirmations(
&unwrap!(self.r().taker_payment.clone()).tx_hex,
self.r().data.taker_payment_confirmations,
self.r().data.taker_payment_requires_nota.unwrap_or(false),
wait_taker_payment,
WAIT_CONFIRM_INTERVAL,
).compat();
Expand Down
6 changes: 6 additions & 0 deletions mm2src/lp_swap/taker_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ pub struct TakerSwapData {
maker_amount: BigDecimal,
taker_amount: BigDecimal,
maker_payment_confirmations: u64,
maker_payment_requires_nota: Option<bool>,
taker_payment_confirmations: u64,
taker_payment_requires_nota: Option<bool>,
taker_payment_lock: u64,
/// Allows to recognize one SWAP from the other in the logs. #274.
uuid: String,
Expand Down Expand Up @@ -523,7 +525,9 @@ impl TakerSwap {
maker_amount: self.maker_amount.clone(),
taker_amount: self.taker_amount.clone(),
maker_payment_confirmations: self.maker_coin.required_confirmations(),
maker_payment_requires_nota: Some(self.maker_coin.requires_notarization()),
taker_payment_confirmations: self.taker_coin.required_confirmations(),
taker_payment_requires_nota: Some(self.taker_coin.requires_notarization()),
taker_payment_lock: started_at + lock_duration,
my_persistent_pub: self.my_persistent_pub.clone().into(),
uuid: self.uuid.clone(),
Expand Down Expand Up @@ -726,6 +730,7 @@ impl TakerSwap {
let f = self.maker_coin.wait_for_confirmations(
&unwrap!(self.r().maker_payment.clone()).tx_hex,
self.r().data.maker_payment_confirmations,
self.r().data.maker_payment_requires_nota.unwrap_or(false),
self.r().data.maker_payment_wait,
WAIT_CONFIRM_INTERVAL,
);
Expand Down Expand Up @@ -825,6 +830,7 @@ impl TakerSwap {
let wait_f = self.taker_coin.wait_for_confirmations(
&unwrap!(self.r().taker_payment.clone()).tx_hex,
self.r().data.taker_payment_confirmations,
self.r().data.taker_payment_requires_nota.unwrap_or(false),
wait_taker_payment,
WAIT_CONFIRM_INTERVAL,
).compat();
Expand Down

0 comments on commit 475bd46

Please sign in to comment.