forked from bitcoin-teleport/teleport-transactions
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic refactor to introduce new maker structure.
- configs separated. - New Error structure for Maker defined. - Handler functions in its own module. - New Maker structure to manage states. - Collateral changes in all other modules.
- Loading branch information
1 parent
2c7cd7f
commit f0befb1
Showing
23 changed files
with
1,811 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#[derive(Debug, Clone)] | ||
pub struct MakerConfig { | ||
pub port: u16, | ||
pub heart_beat_interval_secs: u64, | ||
pub rpc_ping_interval_secs: u64, | ||
pub watchtower_ping_interval_secs: u64, | ||
pub directory_servers_refresh_interval_secs: u64, | ||
pub idle_connection_timeout: u64, | ||
pub onion_addrs: String, | ||
pub absolute_fee_sats: u64, | ||
pub amount_relative_fee_ppb: u64, | ||
pub time_relative_fee_ppb: u64, | ||
pub required_confirms: u64, | ||
// Minimum reaction time between contract transaction of two hops | ||
pub min_contract_reaction_time: u16, | ||
pub min_size: u64, | ||
} | ||
|
||
impl MakerConfig { | ||
/// Init a default configuration with given port and address | ||
pub fn init(port: u16, onion_addrs: String) -> Self { | ||
Self { | ||
port, | ||
heart_beat_interval_secs: 3, | ||
rpc_ping_interval_secs: 60, | ||
watchtower_ping_interval_secs: 300, | ||
directory_servers_refresh_interval_secs: 60 * 60 * 12, //12 Hours | ||
idle_connection_timeout: 300, | ||
onion_addrs, | ||
absolute_fee_sats: 1000, | ||
amount_relative_fee_ppb: 10_000_000, | ||
time_relative_fee_ppb: 100_000, | ||
required_confirms: 1, | ||
min_contract_reaction_time: 48, | ||
min_size: 10_000, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use std::sync::{PoisonError, RwLockReadGuard, RwLockWriteGuard}; | ||
|
||
use bitcoin::secp256k1; | ||
|
||
use crate::{ | ||
protocol::error::ContractError, | ||
wallet::{Wallet, WalletError}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub enum MakerError { | ||
IO(std::io::Error), | ||
Json(serde_json::Error), | ||
UnexpectedMessage { expected: String, got: String }, | ||
General(&'static str), | ||
MutexWallet, | ||
Secp(secp256k1::Error), | ||
ContractError(ContractError), | ||
Wallet(WalletError), | ||
} | ||
|
||
impl From<std::io::Error> for MakerError { | ||
fn from(value: std::io::Error) -> Self { | ||
Self::IO(value) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for MakerError { | ||
fn from(value: serde_json::Error) -> Self { | ||
Self::Json(value) | ||
} | ||
} | ||
|
||
impl<'a> From<PoisonError<RwLockReadGuard<'a, Wallet>>> for MakerError { | ||
fn from(_: PoisonError<RwLockReadGuard<'a, Wallet>>) -> Self { | ||
Self::MutexWallet | ||
} | ||
} | ||
|
||
impl<'a> From<PoisonError<RwLockWriteGuard<'a, Wallet>>> for MakerError { | ||
fn from(_: PoisonError<RwLockWriteGuard<'a, Wallet>>) -> Self { | ||
Self::MutexWallet | ||
} | ||
} | ||
|
||
impl From<secp256k1::Error> for MakerError { | ||
fn from(value: secp256k1::Error) -> Self { | ||
Self::Secp(value) | ||
} | ||
} | ||
|
||
impl From<ContractError> for MakerError { | ||
fn from(value: ContractError) -> Self { | ||
Self::ContractError(value) | ||
} | ||
} | ||
|
||
impl From<WalletError> for MakerError { | ||
fn from(value: WalletError) -> Self { | ||
Self::Wallet(value) | ||
} | ||
} |
Oops, something went wrong.