calculateTimeToLive method
Set the time range in which this transaction is valid. Time-to-live (TTL) - represents a slot, or deadline by which a transaction must be submitted. The TTL is an absolute slot number, rather than a relative one, which means that the ttl value should be greater than the current slot number. A transaction becomes invalid once its ttl expires. Currently each slot is one second and each epoch currently includes 432,000 slots (5 days).
Implementation
Future<Result<int, String>> calculateTimeToLive() async {
if (isCurrentSlotUnsetOrStale) {
final result = await _blockchainAdapter!.latestBlock();
if (result.isErr()) {
return Err(result.unwrapErr());
} else {
final block = result.unwrap();
_currentSlot = block.slot;
_currentSlotTimestamp = block.time;
}
}
if (_ttl != 0) {
if (_ttl < _currentSlot) {
return Err(
"specified ttl of $_ttl can't be less than current slot: $_currentSlot");
}
return Ok(_ttl);
}
return Ok(_currentSlot + defaultTtlDelta);
}