Skip to content

Commit 964c0dc

Browse files
committed
feat: update storage access to use persistent storage and extend TTL for escrow data
1 parent c7f1ec4 commit 964c0dc

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

contracts/escrow/src/contract.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::events::handler::{
66
ChgEsc, DisEsc, DisputeResolved, EscrowDisputed, ExtTtlEvt, FundEsc, InitEsc,
77
MilestoneApproved, MilestoneStatusChanged, WithdrawEvt,
88
};
9-
use crate::storage::types::{AddressBalance, Escrow, MilestoneUpdate};
9+
use crate::storage::types::{AddressBalance, DataKey, Escrow, MilestoneUpdate};
1010

1111
#[contract]
1212
pub struct EscrowContract;
@@ -131,10 +131,10 @@ impl EscrowContract {
131131
return Err(ContractError::OnlyPlatformAddressExecuteThisFunction);
132132
}
133133

134-
let min_ledgers = 1u32;
134+
let min_ledgers = 17280u32;
135135
e.storage()
136-
.instance()
137-
.extend_ttl(min_ledgers, ledgers_to_extend);
136+
.persistent()
137+
.extend_ttl(&DataKey::Escrow, min_ledgers, ledgers_to_extend);
138138

139139
ExtTtlEvt {
140140
platform: platform_address,

contracts/escrow/src/core/dispute.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,10 @@ impl DisputeManager {
8686
}
8787
}
8888

89-
e.storage().instance().set(&DataKey::Escrow, &escrow);
89+
e.storage().persistent().set(&DataKey::Escrow, &escrow);
90+
e.storage()
91+
.persistent()
92+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
9093

9194
Ok(escrow)
9295
}
@@ -175,7 +178,10 @@ impl DisputeManager {
175178
);
176179
escrow.milestones = updated_milestones;
177180

178-
e.storage().instance().set(&DataKey::Escrow, &escrow);
181+
e.storage().persistent().set(&DataKey::Escrow, &escrow);
182+
e.storage()
183+
.persistent()
184+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
179185

180186
Ok(escrow)
181187
}
@@ -200,7 +206,10 @@ impl DisputeManager {
200206
.ok_or(ContractError::InvalidMileStoneIndex)?;
201207
target.flags.disputed = true;
202208
escrow.milestones.set(idx, target);
203-
e.storage().instance().set(&DataKey::Escrow, &escrow);
209+
e.storage().persistent().set(&DataKey::Escrow, &escrow);
210+
e.storage()
211+
.persistent()
212+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
204213

205214
Ok(escrow)
206215
}

contracts/escrow/src/core/escrow.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ impl EscrowManager {
2222
let escrow_balance = token_client.balance(&e.current_contract_address());
2323
validate_initialize_escrow_conditions(e, escrow_properties.clone(), escrow_balance)?;
2424
e.storage()
25-
.instance()
25+
.persistent()
2626
.set(&DataKey::Escrow, &escrow_properties);
27+
e.storage()
28+
.persistent()
29+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
2730
Ok(escrow_properties)
2831
}
2932

@@ -61,7 +64,10 @@ impl EscrowManager {
6164
to_update.flags.released = true;
6265
escrow.milestones.set(milestone_index, to_update);
6366

64-
e.storage().instance().set(&DataKey::Escrow, &escrow);
67+
e.storage().persistent().set(&DataKey::Escrow, &escrow);
68+
e.storage()
69+
.persistent()
70+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
6571

6672
let contract_address = e.current_contract_address();
6773
let token_client = TokenClient::new(&e, &escrow.trustline.address);
@@ -121,8 +127,11 @@ impl EscrowManager {
121127
)?;
122128

123129
e.storage()
124-
.instance()
130+
.persistent()
125131
.set(&DataKey::Escrow, &escrow_properties);
132+
e.storage()
133+
.persistent()
134+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
126135
Ok(escrow_properties)
127136
}
128137

@@ -163,7 +172,7 @@ impl EscrowManager {
163172

164173
pub fn get_escrow(e: &Env) -> Result<Escrow, ContractError> {
165174
e.storage()
166-
.instance()
175+
.persistent()
167176
.get(&DataKey::Escrow)
168177
.ok_or(ContractError::EscrowNotFound)?
169178
}

contracts/escrow/src/core/milestone.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ impl MilestoneManager {
4848
.set(idx, milestone_to_update);
4949
}
5050

51-
e.storage().instance().set(&DataKey::Escrow, &existing_escrow);
51+
e.storage().persistent().set(&DataKey::Escrow, &existing_escrow);
52+
e.storage()
53+
.persistent()
54+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
5255

5356
Ok(existing_escrow)
5457
}
@@ -76,7 +79,10 @@ impl MilestoneManager {
7679
existing_escrow
7780
.milestones
7881
.set(milestone_index, milestone_to_update);
79-
e.storage().instance().set(&DataKey::Escrow, &existing_escrow);
82+
e.storage().persistent().set(&DataKey::Escrow, &existing_escrow);
83+
e.storage()
84+
.persistent()
85+
.extend_ttl(&DataKey::Escrow, 17280, 31536000);
8086

8187
Ok(existing_escrow)
8288
}

contracts/escrow/src/core/validators/escrow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub fn validate_initialize_escrow_conditions(
160160
escrow_properties: Escrow,
161161
escrow_balance: i128,
162162
) -> Result<(), ContractError> {
163-
if e.storage().instance().has(&DataKey::Escrow) {
163+
if e.storage().persistent().has(&DataKey::Escrow) {
164164
return Err(ContractError::EscrowAlreadyInitialized);
165165
}
166166

0 commit comments

Comments
 (0)