Skip to content

Commit e3c7a75

Browse files
committed
Merge branch 'feat/audit-trails-dev' into feat/record-tags
# Conflicts: # audit-trail-move/sources/audit_trail.move
2 parents fafd749 + 0daa157 commit e3c7a75

4 files changed

Lines changed: 120 additions & 109 deletions

File tree

audit-trail-move/sources/audit_trail.move

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ use audit_trail::{
2121
record::{Self, Record},
2222
record_tags::{Self, RecordTags}
2323
};
24-
use iota::{clock::{Self, Clock}, event, linked_table::{Self, LinkedTable}, vec_map::{Self, VecMap}, vec_set::VecSet};
24+
use iota::{
25+
clock::{Self, Clock},
26+
event,
27+
linked_table::{Self, LinkedTable},
28+
vec_map::{Self, VecMap},
29+
vec_set::VecSet
30+
};
2531
use std::string::String;
2632
use tf_components::{capability::Capability, role_map::{Self, RoleMap}, timelock::TimeLock};
2733

@@ -243,21 +249,21 @@ public fun initial_admin_role_name(): String {
243249

244250
/// Migrate the trail to the latest package version
245251
entry fun migrate<D: store + copy>(
246-
trail: &mut AuditTrail<D>,
252+
self: &mut AuditTrail<D>,
247253
cap: &Capability,
248254
clock: &Clock,
249255
ctx: &TxContext,
250256
) {
251-
assert!(trail.version < PACKAGE_VERSION, EPackageVersionMismatch);
252-
trail
257+
assert!(self.version < PACKAGE_VERSION, EPackageVersionMismatch);
258+
self
253259
.roles
254260
.assert_capability_valid(
255261
cap,
256262
&permission::migrate_audit_trail(),
257263
clock,
258264
ctx,
259265
);
260-
trail.version = PACKAGE_VERSION;
266+
self.version = PACKAGE_VERSION;
261267
}
262268

263269
fun assert_record_tag_allowed<D: store + copy>(
@@ -451,12 +457,14 @@ public fun delete_audit_trail<D: store + copy>(
451457
records,
452458
mut tags,
453459
locking_config: _,
454-
roles: _roles,
460+
roles,
455461
immutable_metadata: _,
456462
updatable_metadata: _,
457463
version: _,
458464
} = self;
459465

466+
roles.destroy();
467+
460468
linked_table::destroy_empty(records);
461469
while (!vec_map::is_empty(&tags)) {
462470
let (_, _) = vec_map::pop(&mut tags);
@@ -771,17 +779,19 @@ public fun new_capability<D: store + copy>(
771779
public fun revoke_capability<D: store + copy>(
772780
self: &mut AuditTrail<D>,
773781
cap: &Capability,
774-
capability_id: ID,
782+
cap_to_revoke: ID,
783+
cap_to_revoke_valid_until: Option<u64>,
775784
clock: &Clock,
776-
ctx: &mut TxContext,
785+
ctx: &TxContext,
777786
) {
778787
assert!(self.version == PACKAGE_VERSION, EPackageVersionMismatch);
779788
role_map::revoke_capability(
780789
self.access_mut(),
781790
cap,
782-
capability_id,
791+
cap_to_revoke,
792+
cap_to_revoke_valid_until,
783793
clock,
784-
ctx,
794+
ctx
785795
);
786796
}
787797

@@ -831,15 +841,49 @@ public fun destroy_initial_admin_capability<D: store + copy>(
831841
public fun revoke_initial_admin_capability<D: store + copy>(
832842
self: &mut AuditTrail<D>,
833843
cap: &Capability,
834-
capability_id: ID,
844+
cap_to_revoke: ID,
845+
cap_to_revoke_valid_until: Option<u64>,
835846
clock: &Clock,
836847
ctx: &mut TxContext,
837848
) {
838849
assert!(self.version == PACKAGE_VERSION, EPackageVersionMismatch);
839850
role_map::revoke_initial_admin_capability(
840851
self.access_mut(),
841852
cap,
842-
capability_id,
853+
cap_to_revoke,
854+
cap_to_revoke_valid_until,
855+
clock,
856+
ctx);
857+
}
858+
859+
/// Remove expired entries from the `revoked_capabilities` denylist.
860+
///
861+
/// Iterates through the revoked capabilities list and removes every entry whose
862+
/// `valid_until` timestamp is **non-zero** and **less than** the current clock time,
863+
/// because those capabilities are already naturally expired and no longer need to
864+
/// occupy space in the denylist.
865+
///
866+
/// Entries with `valid_until == 0` (i.e. capabilities that had no expiry) are kept,
867+
/// since they remain potentially valid and must stay on the denylist.
868+
///
869+
/// Parameters
870+
/// ----------
871+
/// - cap: Reference to the capability used to authorize this operation.
872+
/// Needs to grant the `CapabilityAdminPermissions::revoke` permission.
873+
/// - clock: Reference to a Clock instance for obtaining the current timestamp.
874+
/// - ctx: Reference to the transaction context.
875+
///
876+
/// Errors:
877+
/// - Aborts with any error documented by `assert_capability_valid` if the provided capability fails authorization checks.
878+
public fun cleanup_revoked_capabilities<D: store + copy>(
879+
self: &mut AuditTrail<D>,
880+
cap: &Capability,
881+
clock: &Clock,
882+
ctx: &TxContext,
883+
) {
884+
assert!(self.version == PACKAGE_VERSION, EPackageVersionMismatch);
885+
self.access_mut().cleanup_revoked_capabilities(
886+
cap,
843887
clock,
844888
ctx,
845889
);
@@ -938,13 +982,13 @@ public fun records<D: store + copy>(self: &AuditTrail<D>): &LinkedTable<u64, Rec
938982
}
939983
// ===== Access Control Functions =====
940984

941-
/// Returns the RoleMap managing access for the audit trail.
985+
/// Returns a reference to the RoleMap managing access (roles and capabilities) for the audit trail.
942986
public fun access<D: store + copy>(self: &AuditTrail<D>): &RoleMap<Permission, RecordTags> {
943987
assert!(self.version == PACKAGE_VERSION, EPackageVersionMismatch);
944988
&self.roles
945989
}
946990

947-
/// Returns a mutable reference to the RoleMap managing access for the audit trail.
991+
/// Returns a mutable reference to the RoleMap managing access (roles and capabilities) for the audit trail.
948992
public(package) fun access_mut<D: store + copy>(
949993
self: &mut AuditTrail<D>,
950994
): &mut RoleMap<Permission, RecordTags> {

audit-trail-move/sources/record.move

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ public(package) fun into_record<D: store + copy>(
8989
// ===== Getters =====
9090

9191
/// Get the stored data from a record
92-
public fun data<D: store + copy>(record: &Record<D>): &D {
93-
&record.data
92+
public fun data<D: store + copy>(self: &Record<D>): &D {
93+
&self.data
9494
}
9595

9696
/// Get the record metadata
97-
public fun metadata<D: store + copy>(record: &Record<D>): &Option<String> {
98-
&record.metadata
97+
public fun metadata<D: store + copy>(self: &Record<D>): &Option<String> {
98+
&self.metadata
9999
}
100100

101101
/// Get the optional record tag
@@ -104,27 +104,27 @@ public fun tag<D: store + copy>(record: &Record<D>): &Option<String> {
104104
}
105105

106106
/// Get the record sequence number
107-
public fun sequence_number<D: store + copy>(record: &Record<D>): u64 {
108-
record.sequence_number
107+
public fun sequence_number<D: store + copy>(self: &Record<D>): u64 {
108+
self.sequence_number
109109
}
110110

111111
/// Get who added the record
112-
public fun added_by<D: store + copy>(record: &Record<D>): address {
113-
record.added_by
112+
public fun added_by<D: store + copy>(self: &Record<D>): address {
113+
self.added_by
114114
}
115115

116116
/// Get when the record was added (milliseconds)
117-
public fun added_at<D: store + copy>(record: &Record<D>): u64 {
118-
record.added_at
117+
public fun added_at<D: store + copy>(self: &Record<D>): u64 {
118+
self.added_at
119119
}
120120

121121
/// Get the correction tracker for this record
122-
public fun correction<D: store + copy>(record: &Record<D>): &RecordCorrection {
123-
&record.correction
122+
public fun correction<D: store + copy>(self: &Record<D>): &RecordCorrection {
123+
&self.correction
124124
}
125125

126126
/// Destroy a record
127-
public(package) fun destroy<D: store + copy + drop>(record: Record<D>) {
127+
public(package) fun destroy<D: store + copy + drop>(self: Record<D>) {
128128
let Record {
129129
data: _,
130130
metadata: _,
@@ -133,7 +133,7 @@ public(package) fun destroy<D: store + copy + drop>(record: Record<D>) {
133133
added_by: _,
134134
added_at: _,
135135
correction: _,
136-
} = record;
136+
} = self;
137137
}
138138

139139
/// Bidirectional correction tracking for audit records

0 commit comments

Comments
 (0)