Skip to content

Commit 1542bfd

Browse files
committed
docs(soroban): add extendInstanceTtl builtin documentation
Signed-off-by: Tarek <tareknaser360@gmail.com>
1 parent d5bd638 commit 1542bfd

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

docs/language/builtins.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,6 @@ Assuming `arg1` is 512 and `arg2` is 196, the output to the log will be ``foo en
667667
Be mindful this will increase the gas cost. Larger values will incur a higher gas cost.
668668
Alternatively, use a hexadecimal ``{:x}`` format specifier to reduce the cost.
669669

670-
.. _extendPersistentTtl:
671670

672671
extendTtl(uint32 threshold, uint32 extend_to)
673672
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
@@ -694,3 +693,20 @@ TTL = live_until_ledger_seq - current_ledger
694693
695694
696695
For more details on managing contract data TTLs in Soroban, refer to the docs for `TTL <https://developers.stellar.org/docs/build/smart-contracts/getting-started/storing-data#managing-contract-data-ttls-with-extend_ttl>`_.
696+
697+
extendInstanceTtl(uint32 threshold, uint32 extend_to)
698+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++
699+
700+
The extendInstanceTtl() function extends the time-to-live (TTL) of contract instance storage.
701+
702+
If the TTL for the current contract instance and code (if applicable) is below threshold ledgers, this function extends ``live_until_ledger_seq`` such that TTL equals ``extend_to``.
703+
704+
.. note:: This is a global function, not a method, and is only available on the Soroban target
705+
706+
.. code-block:: solidity
707+
708+
/// Extends the TTL for the contract instance storage to 10000 ledgers
709+
/// if the current TTL is smaller than 2000 ledgers
710+
function extendInstanceTtl() public view returns (int64) {
711+
return extendInstanceTtl(2000, 10000);
712+
}

src/sema/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub static BUILTIN_FUNCTIONS: Lazy<[Prototype; 28]> = Lazy::new(|| {
4242
builtin: Builtin::ExtendInstanceTtl,
4343
namespace: None,
4444
method: vec![],
45-
name: "extend_instance_ttl",
45+
name: "extendInstanceTtl",
4646
params: vec![Type::Uint(32), Type::Uint(32)],
4747
ret: vec![Type::Int(64)],
4848
target: vec![Target::Soroban],

tests/soroban_testcases/ttl.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn ttl_instance_wrong() {
131131
r#"contract instance_counter {
132132
uint64 instance instanceCount = 3;
133133
134-
function extend_instance_ttl() public view returns (int64) {
134+
function extendInstanceTtl() public view returns (int64) {
135135
return instanceCount.extendTtl(700, 3000);
136136
}
137137
}"#,
@@ -152,8 +152,8 @@ fn ttl_instance_correct() {
152152
153153
/// Extends the TTL for the instance storage to 10000 ledgers
154154
/// if the current TTL is smaller than 2000 ledgers
155-
function extend_instance_ttl() public view returns (int64) {
156-
return extend_instance_ttl(2000, 10000);
155+
function extendInstanceTtl() public view returns (int64) {
156+
return extendInstanceTtl(2000, 10000);
157157
}
158158
}"#,
159159
|env| {
@@ -185,7 +185,7 @@ fn ttl_instance_correct() {
185185
});
186186

187187
// Extend instance TTL to 10000 ledgers
188-
runtime.invoke_contract(addr, "extend_instance_ttl", vec![]);
188+
runtime.invoke_contract(addr, "extendInstanceTtl", vec![]);
189189
runtime.env.as_contract(addr, || {
190190
assert_eq!(runtime.env.storage().instance().get_ttl(), 10000);
191191
});
@@ -210,8 +210,8 @@ fn ttl_combined() {
210210
return tCount.extendTtl(3000, 7000);
211211
}
212212
213-
function extend_instance_ttl() public view returns (int64) {
214-
return extend_instance_ttl(2000, 10000);
213+
function extendInstanceTtl() public view returns (int64) {
214+
return extendInstanceTtl(2000, 10000);
215215
}
216216
}"#,
217217
|env| {
@@ -264,7 +264,7 @@ fn ttl_combined() {
264264
});
265265

266266
// Extend instance storage TTL
267-
runtime.invoke_contract(addr, "extend_instance_ttl", vec![]);
267+
runtime.invoke_contract(addr, "extendInstanceTtl", vec![]);
268268
runtime.env.as_contract(addr, || {
269269
assert_eq!(runtime.env.storage().instance().get_ttl(), 10000);
270270
});
@@ -313,7 +313,7 @@ fn ttl_combined() {
313313

314314
// Re-extend all TTLs
315315
runtime.invoke_contract(addr, "extend_persistent_ttl", vec![]);
316-
runtime.invoke_contract(addr, "extend_instance_ttl", vec![]);
316+
runtime.invoke_contract(addr, "extendInstanceTtl", vec![]);
317317
runtime.invoke_contract(addr, "extend_temp_ttl", vec![]);
318318

319319
// Final TTL verification
@@ -352,8 +352,8 @@ fn test_persistent_entry_archival() {
352352
return pCount.extendTtl(1000, 10000);
353353
}
354354
355-
function extend_instance_ttl() public view returns (int64) {
356-
return extend_instance_ttl(2000, 10000);
355+
function extendInstanceTtl() public view returns (int64) {
356+
return extendInstanceTtl(2000, 10000);
357357
}
358358
}"#,
359359
|env| {
@@ -369,7 +369,7 @@ fn test_persistent_entry_archival() {
369369
let addr = runtime.contracts.last().unwrap();
370370

371371
// Extend instance TTL
372-
runtime.invoke_contract(addr, "extend_instance_ttl", vec![]);
372+
runtime.invoke_contract(addr, "extendInstanceTtl", vec![]);
373373

374374
// Bump ledger sequence by 10001 (one past persistent TTL)
375375
runtime.env.ledger().with_mut(|li| {

0 commit comments

Comments
 (0)