mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-01 01:45:40 -04:00
Re-export bitcoin and monero types
This commit is contained in:
parent
c900d12593
commit
e7c00d742e
@ -1,6 +1,11 @@
|
|||||||
|
use ::bitcoin::{
|
||||||
|
hashes::{hex::ToHex, Hash},
|
||||||
|
secp256k1,
|
||||||
|
util::psbt::PartiallySignedTransaction,
|
||||||
|
SigHash,
|
||||||
|
};
|
||||||
use anyhow::{anyhow, bail, Result};
|
use anyhow::{anyhow, bail, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use bitcoin::hashes::{hex::ToHex, Hash};
|
|
||||||
use ecdsa_fun::{adaptor::Adaptor, fun::Point, nonce::Deterministic, ECDSA};
|
use ecdsa_fun::{adaptor::Adaptor, fun::Point, nonce::Deterministic, ECDSA};
|
||||||
use miniscript::{Descriptor, Segwitv0};
|
use miniscript::{Descriptor, Segwitv0};
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
@ -8,11 +13,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use crate::{config::Config, ExpiredTimelocks};
|
use crate::{bitcoin::timelocks::BlockHeight, config::Config, ExpiredTimelocks};
|
||||||
|
|
||||||
use crate::bitcoin::timelocks::{BlockHeight, Timelock};
|
pub use crate::bitcoin::{
|
||||||
pub use crate::bitcoin::transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund};
|
timelocks::Timelock,
|
||||||
pub use ::bitcoin::{util::psbt::PartiallySignedTransaction, *};
|
transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund},
|
||||||
|
};
|
||||||
|
pub use ::bitcoin::{util::amount::Amount, Address, Network, Transaction, Txid};
|
||||||
pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature};
|
pub use ecdsa_fun::{adaptor::EncryptedSignature, fun::Scalar, Signature};
|
||||||
pub use wallet::Wallet;
|
pub use wallet::Wallet;
|
||||||
|
|
||||||
@ -225,8 +232,8 @@ pub trait GetRawTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Network {
|
pub trait GetNetwork {
|
||||||
fn get_network(&self) -> bitcoin::Network;
|
fn get_network(&self) -> Network;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> {
|
pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> {
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
use anyhow::{bail, Context, Result};
|
use ::bitcoin::{
|
||||||
use bitcoin::{
|
|
||||||
util::{bip143::SigHashCache, psbt::PartiallySignedTransaction},
|
util::{bip143::SigHashCache, psbt::PartiallySignedTransaction},
|
||||||
Address, Amount, SigHash, SigHashType, Transaction, TxIn, TxOut,
|
OutPoint, SigHash, SigHashType, TxIn, TxOut, Txid,
|
||||||
};
|
};
|
||||||
|
use anyhow::{bail, Context, Result};
|
||||||
use ecdsa_fun::Signature;
|
use ecdsa_fun::Signature;
|
||||||
use miniscript::{Descriptor, NullCtx};
|
use miniscript::{Descriptor, NullCtx};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use crate::bitcoin::{
|
use crate::bitcoin::{
|
||||||
build_shared_output_descriptor, timelocks::Timelock, verify_sig, BuildTxLockPsbt, Network,
|
build_shared_output_descriptor, timelocks::Timelock, verify_sig, Address, Amount,
|
||||||
OutPoint, PublicKey, Txid, TX_FEE,
|
BuildTxLockPsbt, GetNetwork, PublicKey, Transaction, TX_FEE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||||
@ -22,7 +22,7 @@ pub struct TxLock {
|
|||||||
impl TxLock {
|
impl TxLock {
|
||||||
pub async fn new<W>(wallet: &W, amount: Amount, A: PublicKey, B: PublicKey) -> Result<Self>
|
pub async fn new<W>(wallet: &W, amount: Amount, A: PublicKey, B: PublicKey) -> Result<Self>
|
||||||
where
|
where
|
||||||
W: BuildTxLockPsbt + Network,
|
W: BuildTxLockPsbt + GetNetwork,
|
||||||
{
|
{
|
||||||
let lock_output_descriptor = build_shared_output_descriptor(A.0, B.0);
|
let lock_output_descriptor = build_shared_output_descriptor(A.0, B.0);
|
||||||
let address = lock_output_descriptor
|
let address = lock_output_descriptor
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Address, Amount, Transaction, Txid};
|
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
|
||||||
use anyhow::{Context, Result};
|
use anyhow::{Context, Result};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
||||||
@ -9,9 +9,9 @@ use tokio::time::interval;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
timelocks::BlockHeight, BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight,
|
timelocks::BlockHeight, Address, Amount, BroadcastSignedTransaction, BuildTxLockPsbt,
|
||||||
GetRawTransaction, Network, SignTxLock, TransactionBlockHeight, TxLock,
|
GetBlockHeight, GetNetwork, GetRawTransaction, SignTxLock, Transaction,
|
||||||
WaitForTransactionFinality, WatchForRawTransaction,
|
TransactionBlockHeight, TxLock, WaitForTransactionFinality, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
};
|
};
|
||||||
@ -194,7 +194,7 @@ impl WaitForTransactionFinality for Wallet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Network for Wallet {
|
impl GetNetwork for Wallet {
|
||||||
fn get_network(&self) -> bitcoin::Network {
|
fn get_network(&self) -> bitcoin::Network {
|
||||||
self.network
|
self.network
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ use libp2p::{core::Multiaddr, PeerId};
|
|||||||
use url::Url;
|
use url::Url;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::monero;
|
use crate::{bitcoin, monero};
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[derive(structopt::StructOpt, Debug)]
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
@ -37,7 +37,7 @@ pub enum Command {
|
|||||||
send_monero: monero::Amount,
|
send_monero: monero::Amount,
|
||||||
|
|
||||||
#[structopt(long = "receive-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
#[structopt(long = "receive-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
||||||
receive_bitcoin: ::bitcoin::Amount,
|
receive_bitcoin: bitcoin::Amount,
|
||||||
},
|
},
|
||||||
BuyXmr {
|
BuyXmr {
|
||||||
#[structopt(long = "connect-peer-id")]
|
#[structopt(long = "connect-peer-id")]
|
||||||
@ -59,7 +59,7 @@ pub enum Command {
|
|||||||
monero_wallet_rpc_url: Url,
|
monero_wallet_rpc_url: Url,
|
||||||
|
|
||||||
#[structopt(long = "send-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
#[structopt(long = "send-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))]
|
||||||
send_bitcoin: ::bitcoin::Amount,
|
send_bitcoin: bitcoin::Amount,
|
||||||
|
|
||||||
#[structopt(long = "receive-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
#[structopt(long = "receive-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))]
|
||||||
receive_monero: monero::Amount,
|
receive_monero: monero::Amount,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::bitcoin::timelocks::Timelock;
|
use crate::bitcoin::Timelock;
|
||||||
use conquer_once::Lazy;
|
use conquer_once::Lazy;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
@ -11,8 +11,8 @@ pub struct Config {
|
|||||||
pub monero_finality_confirmations: u32,
|
pub monero_finality_confirmations: u32,
|
||||||
pub bitcoin_cancel_timelock: Timelock,
|
pub bitcoin_cancel_timelock: Timelock,
|
||||||
pub bitcoin_punish_timelock: Timelock,
|
pub bitcoin_punish_timelock: Timelock,
|
||||||
pub bitcoin_network: ::bitcoin::Network,
|
pub bitcoin_network: bitcoin::Network,
|
||||||
pub monero_network: ::monero::Network,
|
pub monero_network: monero::Network,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
@ -28,8 +28,8 @@ impl Config {
|
|||||||
monero_finality_confirmations: mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
monero_finality_confirmations: mainnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||||
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
|
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
|
||||||
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
|
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
|
||||||
bitcoin_network: ::bitcoin::Network::Bitcoin,
|
bitcoin_network: bitcoin::Network::Bitcoin,
|
||||||
monero_network: ::monero::Network::Mainnet,
|
monero_network: monero::Network::Mainnet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ impl Config {
|
|||||||
monero_finality_confirmations: testnet::MONERO_FINALITY_CONFIRMATIONS,
|
monero_finality_confirmations: testnet::MONERO_FINALITY_CONFIRMATIONS,
|
||||||
bitcoin_cancel_timelock: testnet::BITCOIN_CANCEL_TIMELOCK,
|
bitcoin_cancel_timelock: testnet::BITCOIN_CANCEL_TIMELOCK,
|
||||||
bitcoin_punish_timelock: testnet::BITCOIN_PUNISH_TIMELOCK,
|
bitcoin_punish_timelock: testnet::BITCOIN_PUNISH_TIMELOCK,
|
||||||
bitcoin_network: ::bitcoin::Network::Testnet,
|
bitcoin_network: bitcoin::Network::Testnet,
|
||||||
monero_network: ::monero::Network::Stagenet,
|
monero_network: monero::Network::Stagenet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,8 +62,8 @@ impl Config {
|
|||||||
monero_finality_confirmations: regtest::MONERO_FINALITY_CONFIRMATIONS,
|
monero_finality_confirmations: regtest::MONERO_FINALITY_CONFIRMATIONS,
|
||||||
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
|
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
|
||||||
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
|
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
|
||||||
bitcoin_network: ::bitcoin::Network::Regtest,
|
bitcoin_network: bitcoin::Network::Regtest,
|
||||||
monero_network: ::monero::Network::default(),
|
monero_network: monero::Network::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use bitcoin::hashes::core::fmt::Display;
|
use ::bitcoin::hashes::core::fmt::Display;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -17,8 +17,8 @@ use std::{
|
|||||||
|
|
||||||
use crate::{bitcoin, serde::monero_private_key};
|
use crate::{bitcoin, serde::monero_private_key};
|
||||||
|
|
||||||
|
pub use ::monero::{Network, PrivateKey, PublicKey};
|
||||||
pub use curve25519_dalek::scalar::Scalar;
|
pub use curve25519_dalek::scalar::Scalar;
|
||||||
pub use monero::*;
|
|
||||||
pub use wallet::Wallet;
|
pub use wallet::Wallet;
|
||||||
|
|
||||||
pub const PICONERO_OFFSET: u64 = 1_000_000_000_000;
|
pub const PICONERO_OFFSET: u64 = 1_000_000_000_000;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
use ::monero::{Address, Network, PrivateKey, PublicKey};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
|
||||||
use monero::{Address, Network, PrivateKey, PublicKey};
|
|
||||||
use monero_harness::rpc::wallet;
|
use monero_harness::rpc::wallet;
|
||||||
use std::{str::FromStr, time::Duration};
|
use std::{str::FromStr, time::Duration};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
use ::bitcoin::{Transaction, Txid};
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use ecdsa_fun::{
|
use ecdsa_fun::{
|
||||||
adaptor::{Adaptor, EncryptedSignature},
|
adaptor::{Adaptor, EncryptedSignature},
|
||||||
@ -12,8 +11,8 @@ use sha2::Sha256;
|
|||||||
use crate::{
|
use crate::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
self, current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire,
|
self, current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire,
|
||||||
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, GetRawTransaction, Network,
|
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, GetNetwork, GetRawTransaction,
|
||||||
TransactionBlockHeight, TxCancel, WatchForRawTransaction,
|
Transaction, TransactionBlockHeight, TxCancel, Txid, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
monero,
|
monero,
|
||||||
protocol::{alice, bob},
|
protocol::{alice, bob},
|
||||||
@ -80,7 +79,7 @@ impl State0 {
|
|||||||
|
|
||||||
pub async fn receive<W>(self, wallet: &W, msg: alice::Message0) -> anyhow::Result<State1>
|
pub async fn receive<W>(self, wallet: &W, msg: alice::Message0) -> anyhow::Result<State1>
|
||||||
where
|
where
|
||||||
W: BuildTxLockPsbt + Network,
|
W: BuildTxLockPsbt + GetNetwork,
|
||||||
{
|
{
|
||||||
msg.dleq_proof_s_a.verify(
|
msg.dleq_proof_s_a.verify(
|
||||||
msg.S_a_bitcoin.clone().into(),
|
msg.S_a_bitcoin.clone().into(),
|
||||||
|
Loading…
Reference in New Issue
Block a user