-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmodels.rs
714 lines (638 loc) · 20.2 KB
/
models.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
use crate::enums::{
BatchMintState, ChainMutability, FailedBatchMintState, OwnerType, PersistingBatchMintState,
RoyaltyTargetType, SpecificationAssetClass, SpecificationVersions, TaskStatus,
TokenMetadataEdition, TokenStandard, UnprocessedAccount, UseMethod,
};
use base64::engine::general_purpose;
use base64::Engine;
use blockbuster::programs::mpl_core_program::MplCoreAccountData;
use blockbuster::programs::token_extensions::MintAccountExtensions;
use libreplex_inscriptions::Inscription;
use mpl_token_metadata::accounts::Metadata;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use solana_sdk::{hash::Hash, pubkey::Pubkey, signature::Signature};
use sqlx::types::chrono;
use std::{
cmp::Ordering,
collections::{HashMap, HashSet},
};
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default, Eq, Hash)]
pub struct UrlWithStatus {
pub metadata_url: String,
pub is_downloaded: bool,
}
impl UrlWithStatus {
pub fn new(metadata_url: &str, is_downloaded: bool) -> Self {
Self {
metadata_url: metadata_url.trim().replace('\0', "").to_string(),
is_downloaded,
}
}
pub fn get_metadata_id(&self) -> Vec<u8> {
let mut hasher = Sha256::new();
// triming the url to remove any leading or trailing whitespaces,
// as some of the legacy versions of the database have contained the urls with whitespaces
let url = self.metadata_url.trim();
hasher.update(url);
hasher.finalize().to_vec()
}
}
// AssetIndex is the struct that is stored in the postgres database and is used to query the asset pubkeys.
// Contains values that from multiple tables
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct AssetIndex {
// immutable fields
pub pubkey: Pubkey,
pub specification_version: SpecificationVersions,
pub specification_asset_class: SpecificationAssetClass,
pub royalty_target_type: RoyaltyTargetType,
pub slot_created: i64,
// mutable fields
pub owner_type: Option<OwnerType>,
pub owner: Option<Pubkey>,
pub delegate: Option<Pubkey>,
pub authority: Option<Pubkey>,
pub collection: Option<Pubkey>,
pub is_collection_verified: Option<bool>,
pub creators: Vec<Creator>,
pub royalty_amount: i64,
pub is_burnt: bool,
pub is_compressible: bool,
pub is_compressed: bool,
pub is_frozen: bool,
pub supply: Option<i64>,
pub metadata_url: Option<UrlWithStatus>,
pub update_authority: Option<Pubkey>,
pub slot_updated: i64,
pub fungible_asset_mint: Option<Pubkey>,
pub fungible_asset_balance: Option<u64>,
}
/// FungibleAssetIndex is the struct that is stored in the postgres, and is used to query the fungible asset pubkeys.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Default)]
pub struct FungibleAssetIndex {
pub pubkey: Pubkey,
pub owner: Option<Pubkey>,
pub slot_updated: i64,
pub fungible_asset_mint: Option<Pubkey>,
pub fungible_asset_balance: Option<u64>,
}
/// FungibleToken is associated token account
/// owned by some user
/// key - token account's pubkey
/// owner - user owned this account
/// asset - mint this account associated with
#[derive(Serialize, Deserialize, Clone, Copy, PartialEq, Debug)]
pub struct FungibleToken {
pub key: Pubkey,
pub owner: Pubkey,
pub asset: Pubkey,
pub balance: i64,
pub slot_updated: i64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct Creator {
pub creator: Pubkey,
pub creator_verified: bool,
// In percentages, NOT basis points
pub creator_share: u8,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct OffChainData {
pub url: String,
pub metadata: String,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct CompleteAssetDetails {
// From AssetStaticDetails
pub pubkey: Pubkey,
pub specification_asset_class: SpecificationAssetClass,
pub royalty_target_type: RoyaltyTargetType,
pub slot_created: u64,
pub edition_address: Option<Pubkey>,
// From AssetDynamicDetails as Tuples
pub is_compressible: Updated<bool>,
pub is_compressed: Updated<bool>,
pub is_frozen: Updated<bool>,
pub supply: Option<Updated<u64>>,
pub seq: Option<Updated<u64>>,
pub is_burnt: Updated<bool>,
pub was_decompressed: Updated<bool>,
pub onchain_data: Option<Updated<ChainDataV1>>,
pub creators: Updated<Vec<Creator>>,
pub royalty_amount: Updated<u16>,
pub url: Updated<String>,
pub chain_mutability: Option<Updated<ChainMutability>>,
pub lamports: Option<Updated<u64>>,
pub executable: Option<Updated<bool>>,
pub metadata_owner: Option<Updated<String>>,
pub raw_name: Option<Updated<String>>,
pub mpl_core_plugins: Option<Updated<String>>,
pub mpl_core_unknown_plugins: Option<Updated<String>>,
pub rent_epoch: Option<Updated<u64>>,
pub num_minted: Option<Updated<u32>>,
pub current_size: Option<Updated<u32>>,
pub plugins_json_version: Option<Updated<u32>>,
pub mpl_core_external_plugins: Option<Updated<String>>,
pub mpl_core_unknown_external_plugins: Option<Updated<String>>,
pub mint_extensions: Option<Updated<String>>,
// From AssetAuthority as Tuple
pub authority: Updated<Pubkey>,
// From AssetOwner as Tuples
pub owner: Updated<Option<Pubkey>>,
pub delegate: Updated<Option<Pubkey>>,
pub owner_type: Updated<OwnerType>,
pub owner_delegate_seq: Updated<Option<u64>>,
// Separate fields
pub asset_leaf: Option<Updated<AssetLeaf>>,
pub collection: Option<AssetCollection>,
// Cl elements
pub cl_leaf: Option<ClLeaf>,
pub cl_items: Vec<ClItem>,
// TokenMetadataEdition
pub edition: Option<EditionV1>,
pub master_edition: Option<MasterEdition>,
// OffChainData
pub offchain_data: Option<OffChainData>,
// SplMint
pub spl_mint: Option<SplMint>,
}
/// Leaf information about compressed asset
/// Nonce - is basically the leaf index. It takes from tree supply.
/// NOTE: leaf index is not the same as node index. Leaf index is specifically the index of the leaf in the tree.
#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct AssetLeaf {
pub tree_id: Pubkey,
pub leaf: Option<Vec<u8>>,
pub nonce: Option<u64>,
pub data_hash: Option<Hash>,
pub creator_hash: Option<Hash>,
pub leaf_seq: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Uses {
pub use_method: UseMethod,
pub remaining: u64,
pub total: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ChainDataV1 {
pub name: String,
pub symbol: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub edition_nonce: Option<u8>,
pub primary_sale_happened: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub token_standard: Option<TokenStandard>,
#[serde(skip_serializing_if = "Option::is_none")]
pub uses: Option<Uses>,
}
impl ChainDataV1 {
pub fn sanitize(&mut self) {
self.name = self.name.trim().replace('\0', "");
self.symbol = self.symbol.trim().replace('\0', "");
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AssetCollection {
pub collection: Updated<Pubkey>,
pub is_collection_verified: Updated<bool>,
pub authority: Updated<Option<Pubkey>>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct ClItem {
pub cli_node_idx: u64,
pub cli_tree_key: Pubkey,
pub cli_leaf_idx: Option<u64>,
pub cli_seq: u64,
pub cli_level: u64,
pub cli_hash: Vec<u8>,
pub slot_updated: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct ClLeaf {
pub cli_leaf_idx: u64,
pub cli_tree_key: Pubkey,
pub cli_node_idx: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub enum UpdateVersion {
Sequence(u64),
WriteVersion(u64),
}
impl PartialOrd for UpdateVersion {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) {
(UpdateVersion::Sequence(x), UpdateVersion::Sequence(y)) => x.partial_cmp(y),
(UpdateVersion::WriteVersion(x), UpdateVersion::WriteVersion(y)) => x.partial_cmp(y),
// this is asset decompress case. Update with write version field is always most recent
(UpdateVersion::Sequence(_), UpdateVersion::WriteVersion(_)) => Some(Ordering::Less),
(UpdateVersion::WriteVersion(_), UpdateVersion::Sequence(_)) => None,
}
}
}
impl UpdateVersion {
pub fn get_seq(&self) -> Option<u64> {
match self {
Self::Sequence(seq) => Some(*seq),
_ => None,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct Updated<T> {
pub slot_updated: u64,
pub update_version: Option<UpdateVersion>,
pub value: T,
}
impl<T> Updated<T> {
pub fn new(slot_updated: u64, update_version: Option<UpdateVersion>, value: T) -> Self {
Self {
slot_updated,
update_version,
value,
}
}
pub fn get_upd_ver_seq(&self) -> Option<u64> {
if let Some(upd_ver) = &self.update_version {
upd_ver.get_seq()
} else {
None
}
}
}
#[derive(Clone, Default, PartialEq, Debug)]
pub struct BufferedTransaction {
pub transaction: Vec<u8>,
// this flag tells if the transaction should be mapped from extrnode flatbuffer to mplx flatbuffer structure
// data from geyser should be mapped and data from BG should not
pub map_flatbuffer: bool,
}
#[derive(Debug, Clone, PartialEq, Default, Copy)]
pub struct SignatureWithSlot {
pub signature: Signature,
pub slot: u64,
}
#[derive(Default)]
pub struct TreeState {
pub tree: Pubkey,
pub seq: u64,
pub slot: u64,
}
#[derive(Clone, Debug, PartialEq)]
pub struct EditionData {
pub key: Pubkey,
pub supply: u64,
pub max_supply: Option<u64>,
pub edition_number: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct MasterEdition {
pub key: Pubkey,
pub supply: u64,
pub max_supply: Option<u64>,
pub write_version: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct EditionV1 {
pub key: Pubkey,
pub parent: Pubkey,
pub edition: u64,
pub write_version: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct PubkeyWithSlot {
pub pubkey: Pubkey,
pub slot: u64,
}
#[derive(Default)]
pub struct ForkedItem {
pub tree: Pubkey,
pub seq: u64,
pub node_idx: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AssetSignatureKey {
pub tree: Pubkey,
pub leaf_idx: u64,
pub seq: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AssetSignature {
pub tx: String,
pub instruction: String,
pub slot: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone, Default)]
pub struct AssetSignatureWithPagination {
pub asset_signatures: Vec<AssetSignature>,
pub before: Option<u64>,
pub after: Option<u64>,
}
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq)]
pub struct TokenAccountOwnerIdxKey {
pub owner: Pubkey,
pub token_account: Pubkey,
}
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Eq, PartialEq)]
pub struct TokenAccountMintOwnerIdxKey {
pub mint: Pubkey,
pub owner: Pubkey,
pub token_account: Pubkey,
}
#[derive(Debug, Clone)]
pub struct TokenAccountIterableIdx {
pub mint: Option<Pubkey>,
pub owner: Pubkey,
pub token_account: Pubkey,
pub is_zero_balance: bool,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default, JsonSchema)]
#[serde(default)]
pub struct ResponseTokenAccount {
pub address: String,
pub mint: String,
pub owner: String,
pub amount: u64,
pub delegated_amount: u64,
pub frozen: bool,
#[serde(skip_serializing_if = "Option::is_none")]
pub token_extensions: Option<serde_json::Value>,
}
pub struct TokenAccResponse {
pub token_acc: ResponseTokenAccount,
pub sorting_id: String,
}
#[derive(Debug, Clone, Default)]
pub struct Task {
pub ofd_metadata_url: String,
pub ofd_locked_until: Option<chrono::DateTime<chrono::Utc>>,
pub ofd_attempts: i32,
pub ofd_max_attempts: i32,
pub ofd_error: Option<String>,
pub ofd_status: TaskStatus,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct RawBlock {
pub slot: u64,
pub block: solana_transaction_status::UiConfirmedBlock,
}
#[derive(Debug, Clone)]
pub struct JsonDownloadTask {
pub metadata_url: String,
pub status: TaskStatus,
pub attempts: i16,
pub max_attempts: i16,
}
#[derive(Debug, Clone)]
pub struct BatchMintWithState {
pub file_name: String,
pub state: BatchMintState,
pub error: Option<String>,
pub url: Option<String>,
pub created_at: u64,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BatchMintToVerify {
pub file_hash: String,
pub url: String,
pub created_at_slot: u64,
pub signature: Signature,
pub download_attempts: u8,
pub persisting_state: PersistingBatchMintState,
pub staker: Pubkey,
pub collection_mint: Option<Pubkey>,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct FailedBatchMint {
pub status: FailedBatchMintState,
pub file_hash: String,
pub url: String,
pub created_at_slot: u64,
pub signature: Signature,
pub download_attempts: u8,
pub staker: Pubkey,
}
impl Default for JsonDownloadTask {
fn default() -> Self {
Self {
metadata_url: "".to_string(),
status: TaskStatus::Pending,
attempts: 1,
max_attempts: 10,
}
}
}
pub struct CoreFee {
pub pubkey: Pubkey,
pub is_paid: bool,
pub current_balance: u64,
pub minimum_rent: u64,
pub slot_updated: u64,
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Default, JsonSchema)]
#[serde(default)]
pub struct CoreFeesAccount {
pub address: String,
pub current_balance: i64,
pub minimum_rent: i64,
}
#[derive(Debug, Clone)]
pub struct CoreFeesAccountWithSortingID {
pub sorting_id: String,
pub fees_account: CoreFeesAccount,
}
impl From<(&[u8], i64, CoreFeesAccount)> for CoreFeesAccountWithSortingID {
fn from((pubkey, slot, value): (&[u8], i64, CoreFeesAccount)) -> Self {
let mut key = slot.to_be_bytes().to_vec();
key.extend_from_slice(pubkey);
let sorting_id = general_purpose::STANDARD_NO_PAD.encode(key);
Self {
sorting_id,
fees_account: value,
}
}
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct LeafSignatureAllData {
pub tree: Pubkey,
pub signature: Signature,
pub leaf_idx: u64,
pub slot_sequences: HashMap<u64, HashSet<u64>>,
}
#[derive(Clone)]
pub struct MetadataInfo {
pub metadata: Metadata,
pub slot_updated: u64,
pub write_version: u64,
pub lamports: u64,
pub rent_epoch: u64,
pub executable: bool,
pub metadata_owner: Option<String>,
pub data_hash: u64,
}
#[derive(Clone)]
pub struct EditionMetadata {
pub edition: TokenMetadataEdition,
pub write_version: u64,
pub slot_updated: u64,
pub data_hash: u64,
}
#[derive(Clone, Debug)]
pub struct BurntMetadataSlot {
pub slot_updated: u64,
pub write_version: u64,
pub data_hash: u64,
}
#[derive(Clone)]
pub struct IndexableAssetWithAccountInfo {
pub indexable_asset: MplCoreAccountData,
pub lamports: u64,
pub executable: bool,
pub slot_updated: u64,
pub write_version: u64,
pub rent_epoch: u64,
pub data_hash: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TokenAccount {
pub pubkey: Pubkey,
pub mint: Pubkey,
pub delegate: Option<Pubkey>,
pub owner: Pubkey,
pub extensions: Option<String>,
pub frozen: bool,
pub delegated_amount: i64,
pub slot_updated: i64,
pub amount: i64,
pub write_version: u64,
pub data_hash: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Mint {
pub pubkey: Pubkey,
pub slot_updated: i64,
pub supply: i64,
pub decimals: i32,
pub mint_authority: Option<Pubkey>,
pub freeze_authority: Option<Pubkey>,
pub token_program: Pubkey,
pub extensions: Option<MintAccountExtensions>,
pub write_version: u64,
pub data_hash: u64,
}
pub struct InscriptionInfo {
pub inscription: Inscription,
pub write_version: u64,
pub slot_updated: u64,
pub data_hash: u64,
}
#[derive(Clone)]
pub struct InscriptionDataInfo {
pub inscription_data: Vec<u8>,
pub write_version: u64,
pub slot_updated: u64,
pub data_hash: u64,
}
#[derive(Clone)]
pub struct CoreAssetFee {
pub indexable_asset: MplCoreAccountData,
pub data: Vec<u8>,
pub lamports: u64,
pub rent_epoch: u64,
pub slot_updated: u64,
pub write_version: u64,
pub data_hash: u64,
}
pub struct UnprocessedAccountMessage {
pub account: UnprocessedAccount,
pub key: Pubkey,
pub id: String,
}
impl UnprocessedAccountMessage {
pub fn solana_change_info(&self) -> (Pubkey, u64, u64, u64) {
let (slot, write_version, data_hash) = match &self.account {
UnprocessedAccount::MetadataInfo(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::Token(v) => (v.slot_updated as u64, v.write_version, v.data_hash),
UnprocessedAccount::Mint(v) => (v.slot_updated as u64, v.write_version, v.data_hash),
UnprocessedAccount::Edition(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::BurnMetadata(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::BurnMplCore(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::MplCore(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::Inscription(v) => (v.slot_updated, v.write_version, v.data_hash),
UnprocessedAccount::InscriptionData(v) => {
(v.slot_updated, v.write_version, v.data_hash)
}
UnprocessedAccount::MplCoreFee(v) => (v.slot_updated, v.write_version, v.data_hash),
};
(self.key, slot, write_version, data_hash)
}
}
pub struct BufferedTxWithID {
pub tx: BufferedTransaction,
pub id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SplMint {
pub pubkey: Pubkey,
pub supply: i64,
pub decimals: i32,
pub mint_authority: Option<Pubkey>,
pub freeze_authority: Option<Pubkey>,
pub token_program: Pubkey,
pub slot_updated: i64,
pub write_version: u64,
}
impl From<&Mint> for SplMint {
fn from(value: &Mint) -> Self {
Self {
pubkey: value.pubkey,
supply: value.supply,
decimals: value.decimals,
mint_authority: value.mint_authority,
freeze_authority: value.freeze_authority,
token_program: value.token_program,
slot_updated: value.slot_updated,
write_version: value.write_version,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_url_with_status() {
let url = "http://example.com".to_string();
let url_with_status = UrlWithStatus {
metadata_url: url,
is_downloaded: false,
};
let metadata_id = url_with_status.get_metadata_id();
assert_eq!(metadata_id.len(), 32);
assert_eq!(
hex::encode(metadata_id),
"f0e6a6a97042a4f1f1c87f5f7d44315b2d852c2df5c7991cc66241bf7072d1c4"
);
}
#[test]
fn test_url_with_status_trimmed_on_untrimmed_data() {
let url = " http://example.com ".to_string();
let url_with_status = UrlWithStatus {
metadata_url: url,
is_downloaded: false,
};
let metadata_id = url_with_status.get_metadata_id();
assert_eq!(metadata_id.len(), 32);
assert_eq!(
hex::encode(metadata_id),
"f0e6a6a97042a4f1f1c87f5f7d44315b2d852c2df5c7991cc66241bf7072d1c4"
);
}
#[test]
fn test_new_url_with_status_trimmes_url() {
let url = " http://example.com ".to_string();
let url_with_status: UrlWithStatus = UrlWithStatus::new(&url, false);
assert_eq!(url_with_status.metadata_url, "http://example.com");
}
}