You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds support for `extendPersistentTtl()` method in Soroban,
along with a test and documentation. Also, the Soroban testing
infrastructure has been refactored to allow more flexible environment
manipulation.
[Documentation for
`extend_ttl`](https://developers.stellar.org/docs/build/smart-contracts/getting-started/storing-data#managing-contract-data-ttls-with-extend_ttl)
Fixes#1669
#### Changes
- Added support for `extendPersistentTtl` as a method on `uint64` for
the Soroban target.
- In the Soroban SDK, `extend_ttl` is a generic function (`IntoVal<Env,
Val>`)
```rust
pub fn extend_ttl<K>(&self, key: &K, threshold: u32, extend_to: u32)
where
K: IntoVal<Env, Val>,
```
but Solidity does not support that, so it's implemented as a method
instead.
- One assertion in the `different_storage_types` test is affected due to
changes in diagnostic capture. A follow-up PR will address this.
---------
Signed-off-by: Tarek <tareknaser360@gmail.com>
The ``extendTtl()`` method allows extending the time-to-live (TTL) of a contract storage entry.
675
+
676
+
If the entry's TTL is below threshold ledgers, this function updates ``live_until_ledger_seq`` such that TTL equals ``extend_to``. The TTL is defined as:
677
+
678
+
.. math::
679
+
680
+
TTL = live_until_ledger_seq - current_ledger
681
+
682
+
683
+
.. note:: This method is only available on the Soroban target
684
+
685
+
.. code-block:: solidity
686
+
687
+
/// Extends the TTL for the `count` persistent key to 5000 ledgers
688
+
/// if the current TTL is smaller than 1000 ledgers
689
+
function extend_ttl() public view returns (int64) {
690
+
return count.extendTtl(1000, 5000);
691
+
}
692
+
693
+
694
+
695
+
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>`_.
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) {
// ;; If the entry's TTL is below `threshold` ledgers, extend `live_until_ledger_seq` such that TTL == `extend_to`, where TTL is defined as live_until_ledger_seq - current ledger.
// ;; If the TTL for the current contract instance and code (if applicable) is below `threshold` ledgers, extend `live_until_ledger_seq` such that TTL == `extend_to`, where TTL is defined as live_until_ledger_seq - current ledger.
0 commit comments