forked from MettaChain/PropChain-contract
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlib.rs
More file actions
4767 lines (4285 loc) · 164 KB
/
Copy pathlib.rs
File metadata and controls
4767 lines (4285 loc) · 164 KB
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
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#![allow(clippy::clone_on_copy)] // fires inside ink! generated storage code
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unexpected_cfgs)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![allow(clippy::enum_variant_names)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::arithmetic_side_effects)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::unnecessary_lazy_evaluations)]
#![allow(clippy::unnecessary_cast)]
use ink::prelude::string::String;
use ink::prelude::vec::Vec;
use ink::storage::Mapping;
// Import identity module
use propchain_identity::propchain_identity::IdentityRegistryRef;
// Re-export traits
pub use propchain_traits::*;
// Re-export reentrancy protection
pub use reentrancy_guard::{ReentrancyError, ReentrancyGuard};
// Export error handling utilities
#[cfg(feature = "std")]
pub mod error_handling;
// Audit trail module
pub mod audit;
// Reentrancy protection module
pub mod reentrancy_guard;
#[ink::contract]
pub mod propchain_contracts {
use super::*;
use crate::audit::{AuditRecord, AuditTrail};
/// Error types for contract
#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum Error {
/// Property does not exist in the registry
PropertyNotFound,
/// Caller is not authorized for this operation
Unauthorized,
/// Property metadata is invalid or malformed
InvalidMetadata,
/// Recipient is not compliant with regulatory requirements
NotCompliant,
/// Call to the compliance registry contract failed
ComplianceCheckFailed,
/// An external dependency is currently unavailable due to circuit breaker state
ExternalDependencyUnavailable,
/// Escrow does not exist
EscrowNotFound,
/// Escrow has already been released
EscrowAlreadyReleased,
/// Badge does not exist for this property
BadgeNotFound,
/// Badge type is invalid
InvalidBadgeType,
/// Badge has already been issued to this property
BadgeAlreadyIssued,
/// Caller is not an authorized verifier
NotVerifier,
/// Appeal does not exist
AppealNotFound,
/// Appeal status does not allow this operation
InvalidAppealStatus,
/// Compliance registry contract address has not been configured
ComplianceRegistryNotSet,
/// Oracle contract returned an error
OracleError,
/// Contract is currently paused
ContractPaused,
/// Contract is already paused
AlreadyPaused,
/// Contract is not currently paused
NotPaused,
/// A resume request is already in progress
ResumeRequestAlreadyActive,
/// No active resume request exists
ResumeRequestNotFound,
/// Not enough approvals to complete the operation
InsufficientApprovals,
/// Caller has already approved this operation
AlreadyApproved,
/// Caller is not authorized to pause the contract
NotAuthorizedToPause,
/// Identity verification failed
IdentityVerificationFailed,
/// Insufficient reputation for operation
InsufficientReputation,
/// Identity not found
IdentityNotFound,
/// Identity registry not configured
IdentityRegistryNotSet,
/// Provided address is the zero address (all zeros)
ZeroAddress,
/// Input string exceeds maximum allowed length
StringTooLong,
/// Input string is empty when a value is required
StringEmpty,
/// Numeric value is out of acceptable bounds
ValueOutOfBounds,
/// Input batch exceeds the configured max_batch_size
BatchSizeExceeded,
/// Cannot transfer or approve to yourself
SelfTransferNotAllowed,
/// Range is invalid (min > max)
InvalidRange,
/// Reentrancy guard detected a reentrant call
ReentrantCall,
}
impl From<crate::ReentrancyError> for Error {
fn from(_: crate::ReentrancyError) -> Self {
Error::ReentrantCall
}
}
/// Property Registry contract
#[ink(storage)]
pub struct PropertyRegistry {
/// Mapping from property ID to property information
properties: Mapping<u64, PropertyInfo>,
/// Mapping from owner to their properties
owner_properties: Mapping<AccountId, Vec<u64>>,
/// Reverse mapping: property ID to owner (optimization for faster lookups)
property_owners: Mapping<u64, AccountId>,
/// Mapping from property ID to approved account
approvals: Mapping<u64, AccountId>,
/// Property counter
property_count: u64,
/// Contract version
version: u32,
/// Admin for upgrades (if used directly, or for logic-level auth)
admin: AccountId,
/// Mapping from escrow ID to escrow information
escrows: Mapping<u64, EscrowInfo>,
/// Escrow counter
escrow_count: u64,
/// Gas usage tracking
gas_tracker: GasTracker,
/// Compliance registry contract address (optional)
compliance_registry: Option<AccountId>,
/// Badge storage: (property_id, badge_type) -> Badge
property_badges: Mapping<(u64, BadgeType), Badge>,
/// Authorized badge verifiers
badge_verifiers: Mapping<AccountId, bool>,
/// Verification requests
verification_requests: Mapping<u64, VerificationRequest>,
/// Verification request counter
verification_count: u64,
/// Appeals
appeals: Mapping<u64, Appeal>,
/// Appeal counter
appeal_count: u64,
/// Pause configuration and state
pause_info: PauseInfo,
/// Accounts authorized to pause the contract
pause_guardians: Mapping<AccountId, bool>,
/// Oracle contract address (optional)
oracle: Option<AccountId>,
/// Fee manager contract for dynamic fees and market mechanism (optional)
fee_manager: Option<AccountId>,
/// Fractional properties info
fractional: Mapping<u64, FractionalInfo>,
/// Centralized RBAC and permission audit state
access_control: AccessControl,
/// Identity registry contract address for identity verification
identity_registry: Option<AccountId>,
/// Minimum reputation threshold for property operations
min_reputation_threshold: u32,
/// Batch operation configuration
batch_config: BatchConfig,
/// Batch operation statistics
batch_operation_stats: BatchOperationStats,
/// Comprehensive security audit trail with tamper-evident hash chain
audit_trail: AuditTrail,
/// Cached analytics for efficient aggregate queries
cached_analytics: CachedAnalytics,
/// Load metrics for monitoring
load_metrics: LoadMetrics,
/// Dependency injection container — single source of truth for all
/// injectable service addresses. Supersedes the individual
/// `compliance_registry`, `oracle`, `fee_manager`, and
/// `identity_registry` fields for new code; those fields are kept for
/// backward-compatibility with existing callers.
deps: ContainerConfig,
/// Circuit breaker state per external dependency.
external_call_breakers: Mapping<ExternalDependency, CircuitBreakerState>,
/// Shared external call circuit breaker configuration.
external_call_config: CircuitBreakerConfig,
/// Reentrancy protection guard
reentrancy_guard: ReentrancyGuard,
}
/// Escrow information
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct EscrowInfo {
pub id: u64,
pub property_id: u64,
pub buyer: AccountId,
pub seller: AccountId,
pub amount: u128,
pub released: bool,
}
/// Portfolio summary statistics
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PortfolioSummary {
pub property_count: u64,
pub total_valuation: u128,
pub average_valuation: u128,
pub total_size: u64,
pub average_size: u64,
}
/// Detailed portfolio information
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PortfolioDetails {
pub owner: AccountId,
pub properties: Vec<PortfolioProperty>,
pub total_count: u64,
}
/// Individual property in portfolio
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PortfolioProperty {
pub id: u64,
pub location: String,
pub size: u64,
pub valuation: u128,
pub registered_at: u64,
}
#[derive(
Debug,
Clone,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct FractionalInfo {
pub total_shares: u128,
pub enabled: bool,
pub created_at: u64,
}
/// Health status information for monitoring
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct HealthStatus {
pub is_healthy: bool,
pub is_paused: bool,
pub contract_version: u32,
pub property_count: u64,
pub escrow_count: u64,
pub has_oracle: bool,
pub has_compliance_registry: bool,
pub has_fee_manager: bool,
pub block_number: u32,
pub timestamp: u64,
}
/// Global analytics data
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct GlobalAnalytics {
pub total_properties: u64,
pub total_valuation: u128,
pub average_valuation: u128,
pub total_size: u64,
pub average_size: u64,
pub unique_owners: u64,
}
/// Pagination cursor for efficient cursor-based pagination
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PaginationCursor {
pub last_id: u64,
pub last_valuation: u128,
}
/// Paginated result with metadata
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PaginatedProperties {
pub items: Vec<PortfolioProperty>,
pub next_cursor: Option<PaginationCursor>,
pub has_more: bool,
}
/// Property field selector for selective field loading
#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode, Default)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PropertyFields {
pub include_id: bool,
pub include_owner: bool,
pub include_location: bool,
pub include_size: bool,
pub include_valuation: bool,
pub include_registered_at: bool,
}
impl PropertyFields {
pub fn minimal() -> Self {
Self {
include_id: true,
include_owner: false,
include_location: false,
include_size: false,
include_valuation: false,
include_registered_at: false,
}
}
pub fn standard() -> Self {
Self {
include_id: true,
include_owner: true,
include_location: true,
include_size: true,
include_valuation: true,
include_registered_at: false,
}
}
pub fn full() -> Self {
Self {
include_id: true,
include_owner: true,
include_location: true,
include_size: true,
include_valuation: true,
include_registered_at: true,
}
}
}
/// Lazy property metadata wrapper for on-demand loading
pub struct LazyProperty<'a> {
property_id: u64,
storage: &'a Mapping<u64, PropertyInfo>,
cached: Option<PropertyInfo>,
}
impl<'a> LazyProperty<'a> {
pub fn new(property_id: u64, storage: &'a Mapping<u64, PropertyInfo>) -> Self {
Self {
property_id,
storage,
cached: None,
}
}
pub fn get(&mut self) -> Option<&PropertyInfo> {
if self.cached.is_none() {
self.cached = self.storage.get(self.property_id);
}
self.cached.as_ref()
}
}
/// Cached analytics for efficient aggregate queries
#[derive(
Debug,
Clone,
PartialEq,
Default,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct CachedAnalytics {
pub total_valuation: u128,
pub total_size: u64,
pub property_count: u64,
pub last_updated: u64,
}
/// Load time metrics for monitoring
#[derive(
Debug,
Clone,
PartialEq,
Default,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct LoadMetrics {
pub last_load_time: u64,
pub average_load_time: u64,
pub total_operations: u64,
}
/// Gas metrics for monitoring
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct GasMetrics {
pub last_operation_gas: u64,
pub average_operation_gas: u64,
pub total_operations: u64,
pub min_gas_used: u64,
pub max_gas_used: u64,
}
/// Gas tracker for monitoring usage
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct GasTracker {
pub total_gas_used: u64,
pub operation_count: u64,
pub last_operation_gas: u64,
pub min_gas_used: u64,
pub max_gas_used: u64,
}
/// Configuration for batch operations
#[derive(
Debug,
Clone,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BatchConfig {
/// Maximum number of items in a single batch call.
pub max_batch_size: u32,
/// Stop processing after this many failures.
pub max_failure_threshold: u32,
}
impl Default for BatchConfig {
fn default() -> Self {
Self {
max_batch_size: 50,
max_failure_threshold: 5,
}
}
}
/// Result of a batch operation with partial success support
#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BatchResult {
/// Successfully processed item IDs.
pub successes: Vec<u64>,
/// Per-item failures with index, item ID, and error.
pub failures: Vec<BatchItemFailure>,
/// Batch performance metrics.
pub metrics: BatchMetrics,
}
/// A single item failure within a batch operation
#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BatchItemFailure {
/// Position in the input array.
pub index: u32,
/// Property ID that failed (0 if not yet assigned).
pub item_id: u64,
/// The specific error that occurred.
pub error: Error,
}
/// Metrics for a single batch operation call
#[derive(Debug, Clone, PartialEq, Eq, scale::Encode, scale::Decode)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BatchMetrics {
pub total_items: u32,
pub successful_items: u32,
pub failed_items: u32,
/// True if processing stopped due to failure threshold.
pub early_terminated: bool,
}
/// Historical batch operation statistics (stored on-chain)
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Default,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct BatchOperationStats {
pub total_batches_processed: u64,
pub total_items_processed: u64,
pub total_items_failed: u64,
pub total_early_terminations: u64,
pub largest_batch_processed: u32,
}
// =========================================================================
// CIRCUIT BREAKER TYPES
// =========================================================================
/// Identifies an external contract dependency that can be circuit-broken
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum ExternalDependency {
Oracle,
ComplianceRegistry,
FeeManager,
IdentityRegistry,
}
/// Per-dependency circuit breaker runtime state
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Default,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct CircuitBreakerState {
/// Consecutive failures since last reset
pub failure_count: u8,
/// Lifetime failure counter
pub total_failures: u64,
/// Timestamp of the most recent failure
pub last_failure_at: Option<u64>,
/// If set, the circuit is open until this timestamp
pub open_until: Option<u64>,
}
/// Static configuration for the circuit breaker
#[derive(
Debug,
Clone,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct CircuitBreakerConfig {
/// Number of consecutive failures before opening the circuit
pub failure_threshold: u8,
/// How long (in seconds) the circuit stays open before allowing retries
pub cooldown_period_secs: u64,
}
impl Default for CircuitBreakerConfig {
fn default() -> Self {
Self {
failure_threshold: 3,
cooldown_period_secs: 300,
}
}
}
/// Badge types for property verification
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum BadgeType {
OwnerVerification, // KYC/Identity verified
DocumentVerification, // Legal documents verified
LegalCompliance, // Regulatory compliance verified
PremiumListing, // Premium tier property
}
/// Badge information
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct Badge {
pub badge_type: BadgeType,
pub issued_at: u64,
pub issued_by: AccountId,
pub expires_at: Option<u64>,
pub metadata_url: String,
pub revoked: bool,
pub revoked_at: Option<u64>,
pub revocation_reason: String,
}
/// Verification request for badge
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct VerificationRequest {
pub id: u64,
pub property_id: u64,
pub badge_type: BadgeType,
pub requester: AccountId,
pub requested_at: u64,
pub evidence_url: String,
pub status: VerificationStatus,
pub reviewed_by: Option<AccountId>,
pub reviewed_at: Option<u64>,
}
/// Verification status
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum VerificationStatus {
Pending,
Approved,
Rejected,
}
/// Appeal for badge revocation
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct Appeal {
pub id: u64,
pub property_id: u64,
pub badge_type: BadgeType,
pub appellant: AccountId,
pub reason: String,
pub submitted_at: u64,
pub status: AppealStatus,
pub resolved_by: Option<AccountId>,
pub resolved_at: Option<u64>,
pub resolution: String,
}
/// Appeal status
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
scale::Encode,
scale::Decode,
ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub enum AppealStatus {
Pending,
Approved,
Rejected,
}
/// Pause information
#[derive(
Debug, Clone, PartialEq, scale::Encode, scale::Decode, ink::storage::traits::StorageLayout,
)]
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))]
pub struct PauseInfo {
pub paused: bool,
pub paused_at: Option<u64>,
pub paused_by: Option<AccountId>,
pub reason: Option<String>,
pub auto_resume_at: Option<u64>,
// For Resume Process
pub resume_request_active: bool,
pub resume_requester: Option<AccountId>,
pub resume_approvals: Vec<AccountId>,
pub required_approvals: u32,
}
// ============================================================================
// STRUCTURED EVENT SYSTEM - Version 1.0
// ============================================================================
// All events follow a standardized format with:
// - Indexed fields (topics) for efficient querying
// - Timestamps and block numbers for historical tracking
// - Event versioning for future compatibility
// - Detailed metadata for off-chain indexing
// ============================================================================
/// Event emitted when the contract is initialized
#[ink(event)]
pub struct ContractInitialized {
#[ink(topic)]
admin: AccountId,
#[ink(topic)]
contract_version: u32,
timestamp: u64,
block_number: u32,
}
/// Event emitted when a property is registered
/// Indexed fields: property_id, owner for efficient filtering
#[ink(event)]
pub struct PropertyRegistered {
#[ink(topic)]
property_id: u64,
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
event_version: u8,
location: String,
size: u64,
valuation: u128,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when property ownership is transferred
/// Indexed fields: property_id, from, to for efficient querying
#[ink(event)]
pub struct PropertyTransferred {
#[ink(topic)]
property_id: u64,
#[ink(topic)]
from: AccountId,
#[ink(topic)]
to: AccountId,
#[ink(topic)]
event_version: u8,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
transferred_by: AccountId, // The account that initiated the transfer
}
/// Event emitted when property metadata is updated
/// Indexed fields: property_id, owner for efficient filtering
#[ink(event)]
pub struct PropertyMetadataUpdated {
#[ink(topic)]
property_id: u64,
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
event_version: u8,
old_location: String,
new_location: String,
old_valuation: u128,
new_valuation: u128,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when an account is approved to transfer a property
/// Indexed fields: property_id, owner, approved for efficient querying
#[ink(event)]
pub struct ApprovalGranted {
#[ink(topic)]
property_id: u64,
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
approved: AccountId,
#[ink(topic)]
event_version: u8,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when an approval is cleared/revoked
/// Indexed fields: property_id, owner for efficient querying
#[ink(event)]
pub struct ApprovalCleared {
#[ink(topic)]
property_id: u64,
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
event_version: u8,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when an escrow is created
/// Indexed fields: escrow_id, property_id, buyer, seller for efficient querying
#[ink(event)]
pub struct EscrowCreated {
#[ink(topic)]
escrow_id: u64,
#[ink(topic)]
property_id: u64,
#[ink(topic)]
buyer: AccountId,
#[ink(topic)]
seller: AccountId,
#[ink(topic)]
event_version: u8,
amount: u128,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when escrow is released and property transferred
/// Indexed fields: escrow_id, property_id, buyer for efficient querying
#[ink(event)]
pub struct EscrowReleased {
#[ink(topic)]
escrow_id: u64,
#[ink(topic)]
property_id: u64,
#[ink(topic)]
buyer: AccountId,
#[ink(topic)]
event_version: u8,
amount: u128,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
released_by: AccountId,
}
/// Event emitted when escrow is refunded
/// Indexed fields: escrow_id, property_id, seller for efficient querying
#[ink(event)]
pub struct EscrowRefunded {
#[ink(topic)]
escrow_id: u64,
#[ink(topic)]
property_id: u64,
#[ink(topic)]
seller: AccountId,
#[ink(topic)]
event_version: u8,
amount: u128,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
refunded_by: AccountId,
}
/// Event emitted when admin is changed
/// Indexed fields: old_admin, new_admin for efficient querying
#[ink(event)]
pub struct AdminChanged {
#[ink(topic)]
old_admin: AccountId,
#[ink(topic)]
new_admin: AccountId,
#[ink(topic)]
event_version: u8,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
changed_by: AccountId,
}
/// Event emitted when a batch of properties is registered atomically
/// Indexed fields: owner for efficient filtering
#[ink(event)]
pub struct BatchPropertiesRegistered {
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
event_version: u8,
property_ids: Vec<u64>,
count: u64,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Batch event for multiple property transfers to the same recipient
/// Indexed fields: from, to for efficient querying
#[ink(event)]
pub struct BatchPropertyTransferred {
#[ink(topic)]
from: AccountId,
#[ink(topic)]
to: AccountId,
#[ink(topic)]
event_version: u8,
property_ids: Vec<u64>,
count: u64,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
transferred_by: AccountId,
}
/// Batch event for multiple metadata updates
/// Indexed fields: owner for efficient filtering
#[ink(event)]
pub struct BatchMetadataUpdated {
#[ink(topic)]
owner: AccountId,
#[ink(topic)]
event_version: u8,
property_ids: Vec<u64>,
count: u64,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Batch event for multiple property transfers to different recipients
/// Indexed fields: from for efficient querying
#[ink(event)]
pub struct BatchPropertyTransferredToMultiple {
#[ink(topic)]
from: AccountId,
#[ink(topic)]
event_version: u8,
transfers: Vec<(u64, AccountId)>, // (property_id, to)
count: u64,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
transferred_by: AccountId,
}
/// Event emitted after every batch operation for monitoring
#[ink(event)]
pub struct BatchOperationCompleted {
/// 0=register, 1=transfer, 2=metadata_update, 3=transfer_multiple
operation_code: u8,
#[ink(topic)]
caller: AccountId,
#[ink(topic)]
event_version: u8,
total_items: u32,
successful_items: u32,
failed_items: u32,
early_terminated: bool,
timestamp: u64,
block_number: u32,
transaction_hash: Hash,
}
/// Event emitted when a badge is issued to a property
#[ink(event)]
pub struct BadgeIssued {
#[ink(topic)]
property_id: u64,
#[ink(topic)]