@@ -24,13 +24,13 @@ use sage_api::{
2424 GetSpendableCoinCountResponse , GetSyncStatus , GetSyncStatusResponse , GetToken ,
2525 GetTokenResponse , GetTransaction , GetTransactionResponse , GetTransactions ,
2626 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 ,
3030} ;
3131use sage_database:: {
32- AssetFilter , CoinFilterMode , CoinSortMode , NftGroupSearch , NftRow , NftSortMode , Transaction ,
33- TransactionCoin ,
32+ AssetFilter , CoinFilterMode , CoinSortMode , NftGroupSearch , NftRow , NftSortMode , OptionSortMode ,
33+ Transaction , TransactionCoin ,
3434} ;
3535use sage_wallet:: WalletError ;
3636
@@ -400,12 +400,30 @@ impl Sage {
400400 Ok ( GetMinterDidIdsResponse { did_ids, total } )
401401 }
402402
403- pub async fn get_options ( & self , _req : GetOptions ) -> Result < GetOptionsResponse > {
403+ pub async fn get_options ( & self , req : GetOptions ) -> Result < GetOptionsResponse > {
404404 let wallet = self . wallet ( ) ?;
405405
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+
406412 let mut options = Vec :: new ( ) ;
407413
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 {
409427 options. push ( OptionRecord {
410428 launcher_id : Address :: new ( row. asset . hash , "option" . to_string ( ) ) . encode ( ) ?,
411429 name : row. asset . name ,
@@ -416,14 +434,16 @@ impl Sage {
416434 amount : Amount :: u64 ( row. coin_row . coin . amount ) ,
417435 underlying_asset : self . encode_asset ( row. underlying_asset ) ?,
418436 underlying_amount : Amount :: u64 ( row. underlying_amount ) ,
437+ underlying_coin_id : hex:: encode ( row. underlying_coin_id ) ,
419438 strike_asset : self . encode_asset ( row. strike_asset ) ?,
420439 strike_amount : Amount :: u64 ( row. strike_amount ) ,
421440 expiration_seconds : row. expiration_seconds ,
422441 created_height : row. coin_row . created_height ,
442+ created_timestamp : row. coin_row . created_timestamp ,
423443 } ) ;
424444 }
425445
426- Ok ( GetOptionsResponse { options } )
446+ Ok ( GetOptionsResponse { options, total } )
427447 }
428448
429449 pub async fn get_option ( & self , req : GetOption ) -> Result < GetOptionResponse > {
@@ -446,10 +466,12 @@ impl Sage {
446466 amount : Amount :: u64 ( row. coin_row . coin . amount ) ,
447467 underlying_asset : self . encode_asset ( row. underlying_asset ) ?,
448468 underlying_amount : Amount :: u64 ( row. underlying_amount ) ,
469+ underlying_coin_id : hex:: encode ( row. underlying_coin_id ) ,
449470 strike_asset : self . encode_asset ( row. strike_asset ) ?,
450471 strike_amount : Amount :: u64 ( row. strike_amount ) ,
451472 expiration_seconds : row. expiration_seconds ,
452473 created_height : row. coin_row . created_height ,
474+ created_timestamp : row. coin_row . created_timestamp ,
453475 } ;
454476
455477 Ok ( GetOptionResponse {
@@ -820,6 +842,7 @@ impl Sage {
820842 edition_number : metadata. as_ref ( ) . map ( |m| m. edition_number as u32 ) ,
821843 edition_total : metadata. as_ref ( ) . map ( |m| m. edition_total as u32 ) ,
822844 created_height : row. coin_row . created_height ,
845+ created_timestamp : row. coin_row . created_timestamp ,
823846 icon_url : row. asset . icon_url ,
824847 } )
825848 }
0 commit comments