Skip to content

Commit 80fa00b

Browse files
committed
Add is_processed field to grant struct to prevent multiple processing of the same grant
1 parent fffd8f3 commit 80fa00b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

grant_disbursement/src/main.leo

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ program grant_disbursement.aleo {
2222
recipient_principal_key: address, // The address that can withdraw the principal
2323
start_timestamp: u64, // The timestamp at which the grant was created
2424
cliff_timestamp: u64, // The timestamp at which the recipient can start withdrawing principal
25-
fully_vested_timestamp: u64 // The timestamp at which the recipient can withdraw the full principal
25+
fully_vested_timestamp: u64, // The timestamp at which the recipient can withdraw the full principal
26+
is_processed: bool // Whether the grant has been processed
2627
}
2728

2829
mapping grants: u8 => Grant;
@@ -44,7 +45,8 @@ program grant_disbursement.aleo {
4445
recipient_principal_key: GRANTEE_PRINCIPAL_KEY,
4546
start_timestamp: START_TIMESTAMP,
4647
cliff_timestamp: CLIFF_TIMESTAMP,
47-
fully_vested_timestamp: FULLY_VESTED_TIMESTAMP
48+
fully_vested_timestamp: FULLY_VESTED_TIMESTAMP,
49+
is_processed: false
4850
};
4951

5052
// Add the grant to the mapping
@@ -105,6 +107,8 @@ program grant_disbursement.aleo {
105107

106108
// Assert the credits amount is the same
107109
assert_eq(credits_amount, grant.credits_amount);
110+
// Assert that the grant has not been processed
111+
assert(!grant.is_processed);
108112

109113
// Update the grant, with the new paleo amount
110114
let updated_grant: Grant = Grant {
@@ -114,7 +118,8 @@ program grant_disbursement.aleo {
114118
recipient_principal_key: grant.recipient_principal_key,
115119
start_timestamp: grant.start_timestamp,
116120
cliff_timestamp: grant.cliff_timestamp,
117-
fully_vested_timestamp: grant.fully_vested_timestamp
121+
fully_vested_timestamp: grant.fully_vested_timestamp,
122+
is_processed: true
118123
};
119124
grants.set(grant_id, updated_grant);
120125
}
@@ -179,7 +184,8 @@ program grant_disbursement.aleo {
179184
recipient_principal_key: grant.recipient_principal_key,
180185
start_timestamp: grant.start_timestamp,
181186
cliff_timestamp: grant.cliff_timestamp,
182-
fully_vested_timestamp: grant.fully_vested_timestamp
187+
fully_vested_timestamp: grant.fully_vested_timestamp,
188+
is_processed: grant.is_processed
183189
};
184190
grants.set(id, updated_grant);
185191
}
@@ -251,7 +257,8 @@ program grant_disbursement.aleo {
251257
recipient_principal_key: grant.recipient_principal_key,
252258
start_timestamp: grant.start_timestamp,
253259
cliff_timestamp: grant.cliff_timestamp,
254-
fully_vested_timestamp: grant.fully_vested_timestamp
260+
fully_vested_timestamp: grant.fully_vested_timestamp,
261+
is_processed: grant.is_processed
255262
};
256263
grants.set(id, updated_grant);
257264
}

0 commit comments

Comments
 (0)