@@ -63,12 +63,20 @@ impl Database {
63
63
impl < ' a > DatabaseTx < ' a > {
64
64
pub async fn nft_collections_visible_named (
65
65
& mut self ,
66
- offset : u32 ,
67
66
limit : u32 ,
67
+ offset : u32 ,
68
68
) -> Result < Vec < NftCollectionRow > > {
69
69
nft_collections_visible_named ( & mut * self . tx , offset, limit) . await
70
70
}
71
71
72
+ pub async fn nft_collections_named (
73
+ & mut self ,
74
+ limit : u32 ,
75
+ offset : u32 ,
76
+ ) -> Result < Vec < NftCollectionRow > > {
77
+ nft_collections_named ( & mut * self . tx , offset, limit) . await
78
+ }
79
+
72
80
pub async fn insert_nft_coin (
73
81
& mut self ,
74
82
coin_id : Bytes32 ,
@@ -102,6 +110,18 @@ impl<'a> DatabaseTx<'a> {
102
110
nfts_visible_named ( & mut * self . tx , limit, offset) . await
103
111
}
104
112
113
+ pub async fn nfts_visible_recent ( & mut self , limit : u32 , offset : u32 ) -> Result < Vec < NftRow > > {
114
+ nfts_visible_recent ( & mut * self . tx , limit, offset) . await
115
+ }
116
+
117
+ pub async fn nfts_named ( & mut self , limit : u32 , offset : u32 ) -> Result < Vec < NftRow > > {
118
+ nfts_named ( & mut * self . tx , limit, offset) . await
119
+ }
120
+
121
+ pub async fn nfts_recent ( & mut self , limit : u32 , offset : u32 ) -> Result < Vec < NftRow > > {
122
+ nfts_recent ( & mut * self . tx , limit, offset) . await
123
+ }
124
+
105
125
pub async fn nft_count ( & mut self ) -> Result < u32 > {
106
126
nft_count ( & mut * self . tx ) . await
107
127
}
@@ -165,6 +185,10 @@ impl<'a> DatabaseTx<'a> {
165
185
pub async fn nft_launcher_id ( & mut self , coin_id : Bytes32 ) -> Result < Option < Bytes32 > > {
166
186
nft_launcher_id ( & mut * self . tx , coin_id) . await
167
187
}
188
+
189
+ pub async fn nft_collection_name ( & mut self , collection_id : Bytes32 ) -> Result < Option < String > > {
190
+ nft_collection_name ( & mut * self . tx , collection_id) . await
191
+ }
168
192
}
169
193
170
194
async fn insert_nft_collection ( conn : impl SqliteExecutor < ' _ > , row : NftCollectionRow ) -> Result < ( ) > {
@@ -198,6 +222,22 @@ async fn insert_nft_collection(conn: impl SqliteExecutor<'_>, row: NftCollection
198
222
Ok ( ( ) )
199
223
}
200
224
225
+ async fn nft_collection_name (
226
+ conn : impl SqliteExecutor < ' _ > ,
227
+ collection_id : Bytes32 ,
228
+ ) -> Result < Option < String > > {
229
+ let collection_id = collection_id. as_ref ( ) ;
230
+
231
+ let row = sqlx:: query!(
232
+ "SELECT `name` FROM `nft_collections` WHERE `collection_id` = ?" ,
233
+ collection_id
234
+ )
235
+ . fetch_one ( conn)
236
+ . await ?;
237
+
238
+ Ok ( row. name )
239
+ }
240
+
201
241
async fn nft_collections_visible_named (
202
242
conn : impl SqliteExecutor < ' _ > ,
203
243
offset : u32 ,
@@ -239,6 +279,46 @@ async fn nft_collections_visible_named(
239
279
Ok ( collections)
240
280
}
241
281
282
+ async fn nft_collections_named (
283
+ conn : impl SqliteExecutor < ' _ > ,
284
+ offset : u32 ,
285
+ limit : u32 ,
286
+ ) -> Result < Vec < NftCollectionRow > > {
287
+ let rows = sqlx:: query!(
288
+ "
289
+ SELECT
290
+ `collection_id`,
291
+ `did_id`,
292
+ `metadata_collection_id`,
293
+ `visible`,
294
+ `name`,
295
+ `icon`
296
+ FROM `nft_collections` INDEXED BY `col_named`
297
+ ORDER BY `visible` DESC, `is_named` DESC, `name` ASC, `collection_id` ASC
298
+ LIMIT ? OFFSET ?
299
+ " ,
300
+ limit,
301
+ offset
302
+ )
303
+ . fetch_all ( conn)
304
+ . await ?;
305
+
306
+ let mut collections = Vec :: new ( ) ;
307
+
308
+ for row in rows {
309
+ collections. push ( NftCollectionRow {
310
+ collection_id : to_bytes32 ( & row. collection_id ) ?,
311
+ did_id : to_bytes32 ( & row. did_id ) ?,
312
+ metadata_collection_id : row. metadata_collection_id ,
313
+ visible : row. visible ,
314
+ name : row. name ,
315
+ icon : row. icon ,
316
+ } ) ;
317
+ }
318
+
319
+ Ok ( collections)
320
+ }
321
+
242
322
async fn nft_collection_count ( conn : impl SqliteExecutor < ' _ > ) -> Result < u32 > {
243
323
let row = sqlx:: query!(
244
324
"
@@ -631,6 +711,141 @@ async fn nfts_visible_named(
631
711
Ok ( nfts)
632
712
}
633
713
714
+ async fn nfts_visible_recent (
715
+ conn : impl SqliteExecutor < ' _ > ,
716
+ limit : u32 ,
717
+ offset : u32 ,
718
+ ) -> Result < Vec < NftRow > > {
719
+ let rows = sqlx:: query!(
720
+ "
721
+ SELECT
722
+ `launcher_id`,
723
+ `collection_id`,
724
+ `minter_did`,
725
+ `owner_did`,
726
+ `visible`,
727
+ `sensitive_content`,
728
+ `name`,
729
+ `created_height`,
730
+ `metadata_hash`
731
+ FROM `nfts` INDEXED BY `nft_recent`
732
+ WHERE `visible` = 1
733
+ ORDER BY `is_pending` DESC, `created_height` DESC, `launcher_id` ASC
734
+ LIMIT ? OFFSET ?
735
+ " ,
736
+ limit,
737
+ offset
738
+ )
739
+ . fetch_all ( conn)
740
+ . await ?;
741
+
742
+ let mut nfts = Vec :: new ( ) ;
743
+
744
+ for row in rows {
745
+ nfts. push ( NftRow {
746
+ launcher_id : to_bytes32 ( & row. launcher_id ) ?,
747
+ collection_id : row. collection_id . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
748
+ minter_did : row. minter_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
749
+ owner_did : row. owner_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
750
+ visible : row. visible ,
751
+ sensitive_content : row. sensitive_content ,
752
+ name : row. name ,
753
+ created_height : row. created_height . map ( TryInto :: try_into) . transpose ( ) ?,
754
+ metadata_hash : row. metadata_hash . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
755
+ } ) ;
756
+ }
757
+
758
+ Ok ( nfts)
759
+ }
760
+
761
+ async fn nfts_named ( conn : impl SqliteExecutor < ' _ > , limit : u32 , offset : u32 ) -> Result < Vec < NftRow > > {
762
+ let rows = sqlx:: query!(
763
+ "
764
+ SELECT
765
+ `launcher_id`,
766
+ `collection_id`,
767
+ `minter_did`,
768
+ `owner_did`,
769
+ `visible`,
770
+ `sensitive_content`,
771
+ `name`,
772
+ `created_height`,
773
+ `metadata_hash`
774
+ FROM `nfts` INDEXED BY `nft_named`
775
+ ORDER BY `visible` DESC, `is_named` DESC, `name` ASC, `launcher_id` ASC
776
+ LIMIT ? OFFSET ?
777
+ " ,
778
+ limit,
779
+ offset
780
+ )
781
+ . fetch_all ( conn)
782
+ . await ?;
783
+
784
+ let mut nfts = Vec :: new ( ) ;
785
+
786
+ for row in rows {
787
+ nfts. push ( NftRow {
788
+ launcher_id : to_bytes32 ( & row. launcher_id ) ?,
789
+ collection_id : row. collection_id . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
790
+ minter_did : row. minter_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
791
+ owner_did : row. owner_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
792
+ visible : row. visible ,
793
+ sensitive_content : row. sensitive_content ,
794
+ name : row. name ,
795
+ created_height : row. created_height . map ( TryInto :: try_into) . transpose ( ) ?,
796
+ metadata_hash : row. metadata_hash . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
797
+ } ) ;
798
+ }
799
+
800
+ Ok ( nfts)
801
+ }
802
+
803
+ async fn nfts_recent (
804
+ conn : impl SqliteExecutor < ' _ > ,
805
+ limit : u32 ,
806
+ offset : u32 ,
807
+ ) -> Result < Vec < NftRow > > {
808
+ let rows = sqlx:: query!(
809
+ "
810
+ SELECT
811
+ `launcher_id`,
812
+ `collection_id`,
813
+ `minter_did`,
814
+ `owner_did`,
815
+ `visible`,
816
+ `sensitive_content`,
817
+ `name`,
818
+ `created_height`,
819
+ `metadata_hash`
820
+ FROM `nfts` INDEXED BY `nft_recent`
821
+ ORDER BY `visible` DESC, `is_pending` DESC, `created_height` DESC, `launcher_id` ASC
822
+ LIMIT ? OFFSET ?
823
+ " ,
824
+ limit,
825
+ offset
826
+ )
827
+ . fetch_all ( conn)
828
+ . await ?;
829
+
830
+ let mut nfts = Vec :: new ( ) ;
831
+
832
+ for row in rows {
833
+ nfts. push ( NftRow {
834
+ launcher_id : to_bytes32 ( & row. launcher_id ) ?,
835
+ collection_id : row. collection_id . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
836
+ minter_did : row. minter_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
837
+ owner_did : row. owner_did . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
838
+ visible : row. visible ,
839
+ sensitive_content : row. sensitive_content ,
840
+ name : row. name ,
841
+ created_height : row. created_height . map ( TryInto :: try_into) . transpose ( ) ?,
842
+ metadata_hash : row. metadata_hash . as_deref ( ) . map ( to_bytes32) . transpose ( ) ?,
843
+ } ) ;
844
+ }
845
+
846
+ Ok ( nfts)
847
+ }
848
+
634
849
async fn insert_nft_coin (
635
850
conn : impl SqliteExecutor < ' _ > ,
636
851
coin_id : Bytes32 ,
0 commit comments