Re-export bitcoin and monero types

This commit is contained in:
rishflab 2021-01-08 10:41:25 +11:00
parent c900d12593
commit e7c00d742e
10 changed files with 44 additions and 38 deletions

View File

@ -1,6 +1,11 @@
use ::bitcoin::{
hashes::{hex::ToHex, Hash},
secp256k1,
util::psbt::PartiallySignedTransaction,
SigHash,
};
use anyhow::{anyhow, bail, Result};
use async_trait::async_trait;
use bitcoin::hashes::{hex::ToHex, Hash};
use ecdsa_fun::{adaptor::Adaptor, fun::Point, nonce::Deterministic, ECDSA};
use miniscript::{Descriptor, Segwitv0};
use rand::{CryptoRng, RngCore};
@ -8,11 +13,13 @@ use serde::{Deserialize, Serialize};
use sha2::Sha256;
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::transactions::{TxCancel, TxLock, TxPunish, TxRedeem, TxRefund};
pub use ::bitcoin::{util::psbt::PartiallySignedTransaction, *};
pub use crate::bitcoin::{
timelocks::Timelock,
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 wallet::Wallet;
@ -225,8 +232,8 @@ pub trait GetRawTransaction {
}
#[async_trait]
pub trait Network {
fn get_network(&self) -> bitcoin::Network;
pub trait GetNetwork {
fn get_network(&self) -> Network;
}
pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> {

View File

@ -1,16 +1,16 @@
use anyhow::{bail, Context, Result};
use bitcoin::{
use ::bitcoin::{
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 miniscript::{Descriptor, NullCtx};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::bitcoin::{
build_shared_output_descriptor, timelocks::Timelock, verify_sig, BuildTxLockPsbt, Network,
OutPoint, PublicKey, Txid, TX_FEE,
build_shared_output_descriptor, timelocks::Timelock, verify_sig, Address, Amount,
BuildTxLockPsbt, GetNetwork, PublicKey, Transaction, TX_FEE,
};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
@ -22,7 +22,7 @@ pub struct TxLock {
impl TxLock {
pub async fn new<W>(wallet: &W, amount: Amount, A: PublicKey, B: PublicKey) -> Result<Self>
where
W: BuildTxLockPsbt + Network,
W: BuildTxLockPsbt + GetNetwork,
{
let lock_output_descriptor = build_shared_output_descriptor(A.0, B.0);
let address = lock_output_descriptor

View File

@ -1,4 +1,4 @@
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Address, Amount, Transaction, Txid};
use ::bitcoin::{util::psbt::PartiallySignedTransaction, Txid};
use anyhow::{Context, Result};
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
@ -9,9 +9,9 @@ use tokio::time::interval;
use crate::{
bitcoin::{
timelocks::BlockHeight, BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight,
GetRawTransaction, Network, SignTxLock, TransactionBlockHeight, TxLock,
WaitForTransactionFinality, WatchForRawTransaction,
timelocks::BlockHeight, Address, Amount, BroadcastSignedTransaction, BuildTxLockPsbt,
GetBlockHeight, GetNetwork, GetRawTransaction, SignTxLock, Transaction,
TransactionBlockHeight, TxLock, WaitForTransactionFinality, WatchForRawTransaction,
},
config::Config,
};
@ -194,7 +194,7 @@ impl WaitForTransactionFinality for Wallet {
}
}
impl Network for Wallet {
impl GetNetwork for Wallet {
fn get_network(&self) -> bitcoin::Network {
self.network
}

View File

@ -2,7 +2,7 @@ use libp2p::{core::Multiaddr, PeerId};
use url::Url;
use uuid::Uuid;
use crate::monero;
use crate::{bitcoin, monero};
#[derive(structopt::StructOpt, Debug)]
pub struct Options {
@ -37,7 +37,7 @@ pub enum Command {
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))]
receive_bitcoin: ::bitcoin::Amount,
receive_bitcoin: bitcoin::Amount,
},
BuyXmr {
#[structopt(long = "connect-peer-id")]
@ -59,7 +59,7 @@ pub enum Command {
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))]
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))]
receive_monero: monero::Amount,

View File

@ -1,4 +1,4 @@
use crate::bitcoin::timelocks::Timelock;
use crate::bitcoin::Timelock;
use conquer_once::Lazy;
use std::time::Duration;
@ -11,8 +11,8 @@ pub struct Config {
pub monero_finality_confirmations: u32,
pub bitcoin_cancel_timelock: Timelock,
pub bitcoin_punish_timelock: Timelock,
pub bitcoin_network: ::bitcoin::Network,
pub monero_network: ::monero::Network,
pub bitcoin_network: bitcoin::Network,
pub monero_network: monero::Network,
}
impl Config {
@ -28,8 +28,8 @@ impl Config {
monero_finality_confirmations: mainnet::MONERO_FINALITY_CONFIRMATIONS,
bitcoin_cancel_timelock: mainnet::BITCOIN_CANCEL_TIMELOCK,
bitcoin_punish_timelock: mainnet::BITCOIN_PUNISH_TIMELOCK,
bitcoin_network: ::bitcoin::Network::Bitcoin,
monero_network: ::monero::Network::Mainnet,
bitcoin_network: bitcoin::Network::Bitcoin,
monero_network: monero::Network::Mainnet,
}
}
@ -45,8 +45,8 @@ impl Config {
monero_finality_confirmations: testnet::MONERO_FINALITY_CONFIRMATIONS,
bitcoin_cancel_timelock: testnet::BITCOIN_CANCEL_TIMELOCK,
bitcoin_punish_timelock: testnet::BITCOIN_PUNISH_TIMELOCK,
bitcoin_network: ::bitcoin::Network::Testnet,
monero_network: ::monero::Network::Stagenet,
bitcoin_network: bitcoin::Network::Testnet,
monero_network: monero::Network::Stagenet,
}
}
@ -62,8 +62,8 @@ impl Config {
monero_finality_confirmations: regtest::MONERO_FINALITY_CONFIRMATIONS,
bitcoin_cancel_timelock: regtest::BITCOIN_CANCEL_TIMELOCK,
bitcoin_punish_timelock: regtest::BITCOIN_PUNISH_TIMELOCK,
bitcoin_network: ::bitcoin::Network::Regtest,
monero_network: ::monero::Network::default(),
bitcoin_network: bitcoin::Network::Regtest,
monero_network: monero::Network::default(),
}
}
}

View File

@ -1,4 +1,4 @@
use bitcoin::hashes::core::fmt::Display;
use ::bitcoin::hashes::core::fmt::Display;
use serde::{Deserialize, Serialize};
use crate::{

View File

@ -1,4 +1,4 @@
use bitcoin::hashes::core::fmt::Display;
use ::bitcoin::hashes::core::fmt::Display;
use serde::{Deserialize, Serialize};
use crate::{

View File

@ -17,8 +17,8 @@ use std::{
use crate::{bitcoin, serde::monero_private_key};
pub use ::monero::{Network, PrivateKey, PublicKey};
pub use curve25519_dalek::scalar::Scalar;
pub use monero::*;
pub use wallet::Wallet;
pub const PICONERO_OFFSET: u64 = 1_000_000_000_000;

View File

@ -1,7 +1,7 @@
use ::monero::{Address, Network, PrivateKey, PublicKey};
use anyhow::Result;
use async_trait::async_trait;
use backoff::{backoff::Constant as ConstantBackoff, future::FutureOperation as _};
use monero::{Address, Network, PrivateKey, PublicKey};
use monero_harness::rpc::wallet;
use std::{str::FromStr, time::Duration};
use url::Url;

View File

@ -1,4 +1,3 @@
use ::bitcoin::{Transaction, Txid};
use anyhow::{anyhow, Result};
use ecdsa_fun::{
adaptor::{Adaptor, EncryptedSignature},
@ -12,8 +11,8 @@ use sha2::Sha256;
use crate::{
bitcoin::{
self, current_epoch, timelocks::Timelock, wait_for_cancel_timelock_to_expire,
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, GetRawTransaction, Network,
TransactionBlockHeight, TxCancel, WatchForRawTransaction,
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, GetNetwork, GetRawTransaction,
Transaction, TransactionBlockHeight, TxCancel, Txid, WatchForRawTransaction,
},
monero,
protocol::{alice, bob},
@ -80,7 +79,7 @@ impl State0 {
pub async fn receive<W>(self, wallet: &W, msg: alice::Message0) -> anyhow::Result<State1>
where
W: BuildTxLockPsbt + Network,
W: BuildTxLockPsbt + GetNetwork,
{
msg.dleq_proof_s_a.verify(
msg.S_a_bitcoin.clone().into(),