1
+ use crate :: rpc:: ServerInfo ;
2
+ use crate :: wallets:: { ListSpacesResponse , TxInfo , TxResponse , WalletResponse } ;
1
3
use clap:: ValueEnum ;
2
4
use colored:: { Color , Colorize } ;
3
5
use jsonrpsee:: core:: Serialize ;
6
+ use protocol:: {
7
+ bitcoin:: { Amount , Network , OutPoint } ,
8
+ Covenant ,
9
+ } ;
4
10
use serde:: Deserialize ;
5
11
use tabled:: { Table , Tabled } ;
6
- use protocol:: bitcoin:: { Amount , Network , OutPoint } ;
7
- use protocol:: { Covenant } ;
8
12
use wallet:: address:: SpaceAddress ;
9
- use wallet:: { Balance , DoubleUtxo , WalletInfo , WalletOutput } ;
10
13
use wallet:: bdk_wallet:: KeychainKind ;
11
14
use wallet:: bitcoin:: { Address , Txid } ;
12
- use wallet:: tx_event:: { BidEventDetails , BidoutEventDetails , OpenEventDetails , SendEventDetails , TransferEventDetails , TxEventKind } ;
13
- use crate :: rpc:: ServerInfo ;
14
- use crate :: wallets:: { ListSpacesResponse , TxInfo , TxResponse , WalletResponse } ;
15
+ use wallet:: tx_event:: {
16
+ BidEventDetails , BidoutEventDetails , OpenEventDetails , SendEventDetails , TransferEventDetails ,
17
+ TxEventKind ,
18
+ } ;
19
+ use wallet:: { Balance , DoubleUtxo , WalletInfo , WalletOutput } ;
15
20
16
21
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Debug , ValueEnum , Serialize , Deserialize ) ]
17
22
#[ serde( rename_all = "lowercase" ) ]
@@ -56,7 +61,7 @@ struct RegisteredSpaces {
56
61
#[ tabled( rename = "DAYS LEFT" ) ]
57
62
days_left : String ,
58
63
#[ tabled( rename = "UTXO" ) ]
59
- utxo : OutPoint
64
+ utxo : OutPoint ,
60
65
}
61
66
62
67
#[ derive( Tabled ) ]
@@ -91,17 +96,19 @@ fn format_days_left(current_block: u32, claim_height: Option<u32>) -> String {
91
96
pub fn print_list_bidouts ( bidouts : Vec < DoubleUtxo > , format : Format ) {
92
97
match format {
93
98
Format :: Text => {
94
- let all : Vec < _ > = bidouts. into_iter ( ) . map ( |out| Bidout {
95
- txid : out. spend . outpoint . txid ,
96
- vout_1 : out. spend . outpoint . vout ,
97
- vout_2 : out. auction . outpoint . vout ,
98
- confirmed : out. confirmed ,
99
- } ) . collect ( ) ;
99
+ let all: Vec < _ > = bidouts
100
+ . into_iter ( )
101
+ . map ( |out| Bidout {
102
+ txid : out. spend . outpoint . txid ,
103
+ vout_1 : out. spend . outpoint . vout ,
104
+ vout_2 : out. auction . outpoint . vout ,
105
+ confirmed : out. confirmed ,
106
+ } )
107
+ . collect ( ) ;
100
108
println ! ( "{}" , ascii_table( all) ) ;
101
109
}
102
110
Format :: Json => {
103
111
println ! ( "{}" , serde_json:: to_string_pretty( & bidouts) . unwrap( ) ) ;
104
-
105
112
}
106
113
}
107
114
}
@@ -117,17 +124,18 @@ pub fn print_list_transactions(txs: Vec<TxInfo>, format: Format) {
117
124
}
118
125
}
119
126
120
-
121
-
122
127
pub fn print_list_unspent ( utxos : Vec < WalletOutput > , format : Format ) {
123
128
match format {
124
129
Format :: Text => {
125
- let utxos : Vec < _ > = utxos. iter ( ) . map ( |utxo| UnspentOutput {
126
- outpoint : utxo. output . outpoint ,
127
- confirmed : utxo. output . chain_position . is_confirmed ( ) ,
128
- value : utxo. output . txout . value ,
129
- external : utxo. output . keychain == KeychainKind :: External ,
130
- } ) . collect ( ) ;
130
+ let utxos: Vec < _ > = utxos
131
+ . iter ( )
132
+ . map ( |utxo| UnspentOutput {
133
+ outpoint : utxo. output . outpoint ,
134
+ confirmed : utxo. output . chain_position . is_confirmed ( ) ,
135
+ value : utxo. output . txout . value ,
136
+ external : utxo. output . keychain == KeychainKind :: External ,
137
+ } )
138
+ . collect ( ) ;
131
139
println ! ( "{}" , ascii_table( utxos) )
132
140
}
133
141
Format :: Json => {
@@ -153,10 +161,7 @@ pub fn print_wallet_info(info: WalletInfo, format: Format) {
153
161
match format {
154
162
Format :: Text => {
155
163
println ! ( "WALLET: {}" , info. label) ;
156
- println ! ( " Tip {}\n Birthday {}" ,
157
- info. tip,
158
- info. start_block
159
- ) ;
164
+ println ! ( " Tip {}\n Birthday {}" , info. tip, info. start_block) ;
160
165
161
166
println ! ( " Public descriptors" ) ;
162
167
for desc in info. descriptors {
@@ -184,9 +189,18 @@ pub fn print_wallet_balance_response(balance: Balance, format: Format) {
184
189
match format {
185
190
Format :: Text => {
186
191
println ! ( "Balance: {}" , balance. balance. to_sat( ) ) ;
187
- println ! ( " Confirmed {:>14}" , balance. details. balance. confirmed. to_sat( ) ) ;
188
- println ! ( " Trusted pending {:>14}" , balance. details. balance. trusted_pending. to_sat( ) ) ;
189
- println ! ( " Untrusted pending {:>14}" , balance. details. balance. untrusted_pending. to_sat( ) ) ;
192
+ println ! (
193
+ " Confirmed {:>14}" ,
194
+ balance. details. balance. confirmed. to_sat( )
195
+ ) ;
196
+ println ! (
197
+ " Trusted pending {:>14}" ,
198
+ balance. details. balance. trusted_pending. to_sat( )
199
+ ) ;
200
+ println ! (
201
+ " Untrusted pending {:>14}" ,
202
+ balance. details. balance. untrusted_pending. to_sat( )
203
+ ) ;
190
204
println ! ( " Dust & in-auction {:>14}" , balance. details. dust. to_sat( ) ) ;
191
205
}
192
206
Format :: Json => {
@@ -195,7 +209,11 @@ pub fn print_wallet_balance_response(balance: Balance, format: Format) {
195
209
}
196
210
}
197
211
198
- pub fn print_list_spaces_response ( current_block : u32 , response : ListSpacesResponse , format : Format ) {
212
+ pub fn print_list_spaces_response (
213
+ current_block : u32 ,
214
+ response : ListSpacesResponse ,
215
+ format : Format ,
216
+ ) {
199
217
match format {
200
218
Format :: Text => {
201
219
let mut outbids = Vec :: new ( ) ;
@@ -209,7 +227,11 @@ pub fn print_list_spaces_response(current_block: u32, response: ListSpacesRespon
209
227
days_left : "" . to_string ( ) ,
210
228
} ;
211
229
match space. covenant {
212
- Covenant :: Bid { total_burned, claim_height, .. } => {
230
+ Covenant :: Bid {
231
+ total_burned,
232
+ claim_height,
233
+ ..
234
+ } => {
213
235
outbid. last_confirmed_bid = total_burned. to_sat ( ) ;
214
236
outbid. days_left = format_days_left ( current_block, claim_height) ;
215
237
}
@@ -227,9 +249,15 @@ pub fn print_list_spaces_response(current_block: u32, response: ListSpacesRespon
227
249
claim_at : "--" . to_string ( ) ,
228
250
} ;
229
251
match space. covenant {
230
- Covenant :: Bid { total_burned, claim_height, .. } => {
252
+ Covenant :: Bid {
253
+ total_burned,
254
+ claim_height,
255
+ ..
256
+ } => {
231
257
winning. bid = total_burned. to_sat ( ) ;
232
- winning. claim_at = claim_height. map ( |h| h. to_string ( ) ) . unwrap_or ( "--" . to_string ( ) ) ;
258
+ winning. claim_at = claim_height
259
+ . map ( |h| h. to_string ( ) )
260
+ . unwrap_or ( "--" . to_string ( ) ) ;
233
261
winning. days_left = format_days_left ( current_block, claim_height) ;
234
262
if winning. days_left == "0.00" {
235
263
winning. days_left = "Ready to claim" . to_string ( ) ;
@@ -250,28 +278,36 @@ pub fn print_list_spaces_response(current_block: u32, response: ListSpacesRespon
250
278
match & space. covenant {
251
279
Covenant :: Transfer { expire_height, .. } => {
252
280
registered. expire_at = * expire_height as _ ;
253
- registered. days_left = format_days_left ( current_block, Some ( * expire_height) ) ;
281
+ registered. days_left =
282
+ format_days_left ( current_block, Some ( * expire_height) ) ;
254
283
}
255
284
_ => { }
256
285
}
257
286
owned. push ( registered) ;
258
287
}
259
288
260
-
261
289
if !outbids. is_empty ( ) {
262
290
println ! ( "⚠️ OUTBID ({} spaces): " , outbids. len( ) . to_string( ) . bold( ) ) ;
263
291
let table = ascii_table ( outbids) ;
264
292
println ! ( "{}" , table) ;
265
293
}
266
294
267
295
if !winnings. is_empty ( ) {
268
- println ! ( "{} WINNING ({} spaces):" , "✓" . color( Color :: Green ) , winnings. len( ) . to_string( ) . bold( ) ) ;
296
+ println ! (
297
+ "{} WINNING ({} spaces):" ,
298
+ "✓" . color( Color :: Green ) ,
299
+ winnings. len( ) . to_string( ) . bold( )
300
+ ) ;
269
301
let table = ascii_table ( winnings) ;
270
302
println ! ( "{}" , table) ;
271
303
}
272
304
273
305
if !owned. is_empty ( ) {
274
- println ! ( "{} ({} spaces): " , "🔑 OWNED" , owned. len( ) . to_string( ) . bold( ) ) ;
306
+ println ! (
307
+ "{} ({} spaces): " ,
308
+ "🔑 OWNED" ,
309
+ owned. len( ) . to_string( ) . bold( )
310
+ ) ;
275
311
let table = ascii_table ( owned) ;
276
312
println ! ( "{}" , table) ;
277
313
}
@@ -292,13 +328,19 @@ pub fn print_wallet_response_text(network: Network, response: WalletResponse) {
292
328
293
329
for tx in response. result {
294
330
if tx. events . iter ( ) . any ( |event| match event. kind {
295
- TxEventKind :: Open | TxEventKind :: Bid | TxEventKind :: Register |
296
- TxEventKind :: Transfer | TxEventKind :: Send | TxEventKind :: Renew | TxEventKind :: Buy
297
- => true ,
331
+ TxEventKind :: Open
332
+ | TxEventKind :: Bid
333
+ | TxEventKind :: Register
334
+ | TxEventKind :: Transfer
335
+ | TxEventKind :: Send
336
+ | TxEventKind :: Renew
337
+ | TxEventKind :: Buy => true ,
298
338
_ => false ,
299
339
} ) {
300
340
main_txs. push ( tx) ;
301
- } else { secondary_txs. push ( tx) ; }
341
+ } else {
342
+ secondary_txs. push ( tx) ;
343
+ }
302
344
}
303
345
304
346
for tx in main_txs {
@@ -328,7 +370,7 @@ pub fn print_error_rpc_response(code: i32, message: String, format: Format) {
328
370
fn print_tx_response ( network : Network , response : TxResponse ) {
329
371
match response. error {
330
372
None => {
331
- println ! ( "{} Transaction {}" , "✓" . color( Color :: Green ) , response. txid) ;
373
+ println ! ( "{} Transaction {}" , "✓" . color( Color :: Green ) , response. txid) ;
332
374
}
333
375
Some ( errors) => {
334
376
println ! ( "⚠️ Transaction failed to broadcast" ) ;
@@ -341,51 +383,57 @@ fn print_tx_response(network: Network, response: TxResponse) {
341
383
}
342
384
343
385
for event in response. events {
344
- println ! ( " - {} {}" , capitalize( event. kind. to_string( ) ) , event. space. unwrap_or( "" . to_string( ) ) ) ;
386
+ println ! (
387
+ " - {} {}" ,
388
+ capitalize( event. kind. to_string( ) ) ,
389
+ event. space. unwrap_or( "" . to_string( ) )
390
+ ) ;
345
391
346
392
match event. kind {
347
393
TxEventKind :: Open => {
348
- let open_details: OpenEventDetails = serde_json :: from_value (
349
- event. details . expect ( "details" ) )
350
- . expect ( "deserialize open event" ) ;
394
+ let open_details: OpenEventDetails =
395
+ serde_json :: from_value ( event. details . expect ( "details" ) )
396
+ . expect ( "deserialize open event" ) ;
351
397
352
398
println ! ( " Initial bid: {}" , open_details. initial_bid. to_sat( ) ) ;
353
399
}
354
400
TxEventKind :: Bid => {
355
- let bid_details: BidEventDetails = serde_json:: from_value (
356
- event. details . expect ( "details" ) )
357
- . expect ( "deserialize bid event" ) ;
358
- println ! ( " New bid: {} (previous {})" ,
359
- bid_details. current_bid. to_sat( ) ,
360
- bid_details. previous_bid. to_sat( )
401
+ let bid_details: BidEventDetails =
402
+ serde_json:: from_value ( event. details . expect ( "details" ) )
403
+ . expect ( "deserialize bid event" ) ;
404
+ println ! (
405
+ " New bid: {} (previous {})" ,
406
+ bid_details. current_bid. to_sat( ) ,
407
+ bid_details. previous_bid. to_sat( )
361
408
) ;
362
409
}
363
410
TxEventKind :: Send => {
364
- let send_details: SendEventDetails = serde_json :: from_value (
365
- event. details . expect ( "details" ) )
366
- . expect ( "deserialize send event" ) ;
411
+ let send_details: SendEventDetails =
412
+ serde_json :: from_value ( event. details . expect ( "details" ) )
413
+ . expect ( "deserialize send event" ) ;
367
414
368
- let addr = Address :: from_script ( send_details. recipient_script_pubkey . as_script ( ) , network)
369
- . expect ( "valid address" ) ;
415
+ let addr =
416
+ Address :: from_script ( send_details. recipient_script_pubkey . as_script ( ) , network)
417
+ . expect ( "valid address" ) ;
370
418
371
419
println ! ( " Amount: {}" , send_details. amount. to_sat( ) ) ;
372
420
println ! ( " Recipient: {}" , addr) ;
373
421
}
374
422
TxEventKind :: Transfer => {
375
- let transfer_details: TransferEventDetails = serde_json :: from_value (
376
- event. details . expect ( "details" ) )
377
- . expect ( "deserialize transfer event" ) ;
423
+ let transfer_details: TransferEventDetails =
424
+ serde_json :: from_value ( event. details . expect ( "details" ) )
425
+ . expect ( "deserialize transfer event" ) ;
378
426
379
427
let addr = SpaceAddress (
380
428
Address :: from_script ( transfer_details. script_pubkey . as_script ( ) , network)
381
- . expect ( "valid address" )
429
+ . expect ( "valid address" ) ,
382
430
) ;
383
431
println ! ( " Recipient: {}" , addr) ;
384
432
}
385
433
TxEventKind :: Bidout => {
386
- let bidout: BidoutEventDetails = serde_json :: from_value (
387
- event. details . expect ( "details" ) )
388
- . expect ( "deserialize bidout event" ) ;
434
+ let bidout: BidoutEventDetails =
435
+ serde_json :: from_value ( event. details . expect ( "details" ) )
436
+ . expect ( "deserialize bidout event" ) ;
389
437
println ! ( " Count: {}" , bidout. count) ;
390
438
}
391
439
_ => { }
0 commit comments