@ -30,7 +30,7 @@ use swap::asb::config::{
} ;
use swap ::asb ::{ cancel , punish , redeem , refund , safely_abort , EventLoop , Finality , KrakenRate } ;
use swap ::common ::check_latest_version ;
use swap ::database ::open_db ;
use swap ::database ::{ open_db , AccessMode } ;
use swap ::network ::rendezvous ::XmrBtcNamespace ;
use swap ::network ::swarm ;
use swap ::protocol ::alice ::{ run , AliceState } ;
@ -95,13 +95,13 @@ async fn main() -> Result<()> {
) ) ;
}
let db = open_db ( config . data . dir . join ( "sqlite" ) ) . await ? ;
let seed =
Seed ::from_file_or_generate ( & config . data . dir ) . expect ( "Could not retrieve/initialize seed" ) ;
match cmd {
Command ::Start { resume_only } = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
// check and warn for duplicate rendezvous points
let mut rendezvous_addrs = config . network . rendezvous_point . clone ( ) ;
let prev_len = rendezvous_addrs . len ( ) ;
@ -225,6 +225,8 @@ async fn main() -> Result<()> {
event_loop . run ( ) . await ;
}
Command ::History = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadOnly ) . await ? ;
let mut table = Table ::new ( ) ;
table . set_header ( vec! [ "SWAP ID" , "STATE" ] ) ;
@ -270,6 +272,8 @@ async fn main() -> Result<()> {
tracing ::info ! ( % bitcoin_balance , % monero_balance , "Current balance" ) ;
}
Command ::Cancel { swap_id } = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
let bitcoin_wallet = init_bitcoin_wallet ( & config , & seed , env_config ) . await ? ;
let ( txid , _ ) = cancel ( swap_id , Arc ::new ( bitcoin_wallet ) , db ) . await ? ;
@ -277,6 +281,8 @@ async fn main() -> Result<()> {
tracing ::info ! ( "Cancel transaction successfully published with id {}" , txid ) ;
}
Command ::Refund { swap_id } = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
let bitcoin_wallet = init_bitcoin_wallet ( & config , & seed , env_config ) . await ? ;
let monero_wallet = init_monero_wallet ( & config , env_config ) . await ? ;
@ -291,6 +297,8 @@ async fn main() -> Result<()> {
tracing ::info ! ( "Monero successfully refunded" ) ;
}
Command ::Punish { swap_id } = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
let bitcoin_wallet = init_bitcoin_wallet ( & config , & seed , env_config ) . await ? ;
let ( txid , _ ) = punish ( swap_id , Arc ::new ( bitcoin_wallet ) , db ) . await ? ;
@ -298,6 +306,8 @@ async fn main() -> Result<()> {
tracing ::info ! ( "Punish transaction successfully published with id {}" , txid ) ;
}
Command ::SafelyAbort { swap_id } = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
safely_abort ( swap_id , db ) . await ? ;
tracing ::info ! ( "Swap safely aborted" ) ;
@ -306,6 +316,8 @@ async fn main() -> Result<()> {
swap_id ,
do_not_await_finality ,
} = > {
let db = open_db ( config . data . dir . join ( "sqlite" ) , AccessMode ::ReadWrite ) . await ? ;
let bitcoin_wallet = init_bitcoin_wallet ( & config , & seed , env_config ) . await ? ;
let ( txid , _ ) = redeem (