@@ -24,13 +24,13 @@ use sage_api::{
24
24
GetSpendableCoinCountResponse , GetSyncStatus , GetSyncStatusResponse , GetToken ,
25
25
GetTokenResponse , GetTransaction , GetTransactionResponse , GetTransactions ,
26
26
GetTransactionsResponse , GetVersion , GetVersionResponse , NftCollectionRecord , NftData ,
27
- NftRecord , NftSortMode as ApiNftSortMode , OptionRecord , PendingTransactionRecord ,
28
- PerformDatabaseMaintenance , PerformDatabaseMaintenanceResponse , TokenRecord ,
29
- TransactionCoinRecord , TransactionRecord ,
27
+ NftRecord , NftSortMode as ApiNftSortMode , OptionRecord , OptionSortMode as ApiOptionSortMode ,
28
+ PendingTransactionRecord , PerformDatabaseMaintenance , PerformDatabaseMaintenanceResponse ,
29
+ TokenRecord , TransactionCoinRecord , TransactionRecord ,
30
30
} ;
31
31
use sage_database:: {
32
- AssetFilter , CoinFilterMode , CoinSortMode , NftGroupSearch , NftRow , NftSortMode , Transaction ,
33
- TransactionCoin ,
32
+ AssetFilter , CoinFilterMode , CoinSortMode , NftGroupSearch , NftRow , NftSortMode , OptionSortMode ,
33
+ Transaction , TransactionCoin ,
34
34
} ;
35
35
use sage_wallet:: WalletError ;
36
36
@@ -400,12 +400,30 @@ impl Sage {
400
400
Ok ( GetMinterDidIdsResponse { did_ids, total } )
401
401
}
402
402
403
- pub async fn get_options ( & self , _req : GetOptions ) -> Result < GetOptionsResponse > {
403
+ pub async fn get_options ( & self , req : GetOptions ) -> Result < GetOptionsResponse > {
404
404
let wallet = self . wallet ( ) ?;
405
405
406
+ let sort_mode = match req. sort_mode {
407
+ ApiOptionSortMode :: Name => OptionSortMode :: Name ,
408
+ ApiOptionSortMode :: CreatedHeight => OptionSortMode :: CreatedHeight ,
409
+ ApiOptionSortMode :: ExpirationSeconds => OptionSortMode :: ExpirationSeconds ,
410
+ } ;
411
+
406
412
let mut options = Vec :: new ( ) ;
407
413
408
- for row in wallet. db . owned_options ( ) . await ? {
414
+ let ( rows, total) = wallet
415
+ . db
416
+ . owned_options (
417
+ req. limit ,
418
+ req. offset ,
419
+ sort_mode,
420
+ req. ascending ,
421
+ req. find_value ,
422
+ req. include_hidden ,
423
+ )
424
+ . await ?;
425
+
426
+ for row in rows {
409
427
options. push ( OptionRecord {
410
428
launcher_id : Address :: new ( row. asset . hash , "option" . to_string ( ) ) . encode ( ) ?,
411
429
name : row. asset . name ,
@@ -416,14 +434,16 @@ impl Sage {
416
434
amount : Amount :: u64 ( row. coin_row . coin . amount ) ,
417
435
underlying_asset : self . encode_asset ( row. underlying_asset ) ?,
418
436
underlying_amount : Amount :: u64 ( row. underlying_amount ) ,
437
+ underlying_coin_id : hex:: encode ( row. underlying_coin_id ) ,
419
438
strike_asset : self . encode_asset ( row. strike_asset ) ?,
420
439
strike_amount : Amount :: u64 ( row. strike_amount ) ,
421
440
expiration_seconds : row. expiration_seconds ,
422
441
created_height : row. coin_row . created_height ,
442
+ created_timestamp : row. coin_row . created_timestamp ,
423
443
} ) ;
424
444
}
425
445
426
- Ok ( GetOptionsResponse { options } )
446
+ Ok ( GetOptionsResponse { options, total } )
427
447
}
428
448
429
449
pub async fn get_option ( & self , req : GetOption ) -> Result < GetOptionResponse > {
@@ -446,10 +466,12 @@ impl Sage {
446
466
amount : Amount :: u64 ( row. coin_row . coin . amount ) ,
447
467
underlying_asset : self . encode_asset ( row. underlying_asset ) ?,
448
468
underlying_amount : Amount :: u64 ( row. underlying_amount ) ,
469
+ underlying_coin_id : hex:: encode ( row. underlying_coin_id ) ,
449
470
strike_asset : self . encode_asset ( row. strike_asset ) ?,
450
471
strike_amount : Amount :: u64 ( row. strike_amount ) ,
451
472
expiration_seconds : row. expiration_seconds ,
452
473
created_height : row. coin_row . created_height ,
474
+ created_timestamp : row. coin_row . created_timestamp ,
453
475
} ;
454
476
455
477
Ok ( GetOptionResponse {
@@ -820,6 +842,7 @@ impl Sage {
820
842
edition_number : metadata. as_ref ( ) . map ( |m| m. edition_number as u32 ) ,
821
843
edition_total : metadata. as_ref ( ) . map ( |m| m. edition_total as u32 ) ,
822
844
created_height : row. coin_row . created_height ,
845
+ created_timestamp : row. coin_row . created_timestamp ,
823
846
icon_url : row. asset . icon_url ,
824
847
} )
825
848
}
0 commit comments