Skip to content

Conversation

@m00npl
Copy link

@m00npl m00npl commented Oct 17, 2025

Summary

This PR introduces a new, more intuitive API for managing entity expiration times while maintaining full backward compatibility with the existing BTL (Block-to-Live) system.

Changes

New ExpirationTime Builder Class

  • Helper class for time-to-blocks conversion
  • Class methods: from_seconds(), from_hours(), from_days(), from_blocks()
  • Automatic conversion: 1 block = 2 seconds

New API Fields

  • expires_in (int | ExpirationTime) replaces btl in ArkivCreate and ArkivUpdate
  • duration (int | ExpirationTime) replaces number_of_blocks in ArkivExtend
  • When using int, it represents duration in seconds (not blocks)

Examples

Simple way - seconds as int:

create = ArkivCreate(
    data=b"Hello",
    expires_in=3600,  # 1 hour in seconds
    string_annotations=[],
    numeric_annotations=[]
)

With builder - more readable:

create = ArkivCreate(
    data=b"Hello",
    expires_in=ExpirationTime.from_hours(24),
    string_annotations=[],
    numeric_annotations=[]
)

Legacy API (deprecated but still works):

create = ArkivCreate(
    data=b"Hello",
    btl=1800,  # blocks - shows deprecation warning
    string_annotations=[],
    numeric_annotations=[]
)

Backward Compatibility

Deprecated but Functional

  • btl field (in ArkivCreate and ArkivUpdate)
  • number_of_blocks field (in ArkivExtend)

Priority System

  • expires_in > btl
  • duration > number_of_blocks
  • Deprecation warnings displayed when using old API

Migration

  • Existing code continues to work without changes
  • Console warnings encourage migration to new API
  • No breaking changes

Technical Details

  • Added resolve_expiration_blocks() for expires_in/btl resolution
  • Added resolve_extension_blocks() for duration/number_of_blocks resolution
  • Updated utils.py to use resolution functions in RLP encoding
  • All conversions handle both int (seconds) and ExpirationTime objects

Migration Guide

Users can migrate gradually:

# Before (still works)
ArkivCreate(data=b"Hello", btl=1800, ...)

# After - Option 1: Direct seconds
ArkivCreate(data=b"Hello", expires_in=3600, ...)

# After - Option 2: With builder
ArkivCreate(data=b"Hello", expires_in=ExpirationTime.from_hours(1), ...)

@m00npl m00npl force-pushed the feature/expires-in-api branch 5 times, most recently from bdee48a to ca14845 Compare October 17, 2025 23:39
@r-vdp r-vdp force-pushed the feature/expires-in-api branch from 840ce98 to 667d09f Compare October 20, 2025 12:09
moonplkr and others added 2 commits October 29, 2025 11:21
This PR introduces a more intuitive API for managing entity expiration times while maintaining full backward compatibility with the existing BTL (Block-to-Live) system.

## Changes

### New ExpirationTime Builder Class
- Helper class for time-to-blocks conversion
- Class methods: from_seconds(), from_hours(), from_days(), from_blocks()
- Automatic conversion: 1 block = 2 seconds

### New API Fields
- **expires_in** (int | ExpirationTime) replaces btl in ArkivCreate and ArkivUpdate
- **duration** (int | ExpirationTime) replaces number_of_blocks in ArkivExtend
- When using int, it represents duration in **seconds** (not blocks)

### Examples

**Simple way - seconds as int:**
```python
create = ArkivCreate(
    data=b"Hello",
    expires_in=3600,  # 1 hour in seconds
    string_annotations=[],
    numeric_annotations=[]
)
```

**With builder - more readable:**
```python
create = ArkivCreate(
    data=b"Hello",
    expires_in=ExpirationTime.from_hours(24),
    string_annotations=[],
    numeric_annotations=[]
)
```

**Legacy API (deprecated but still works):**
```python
create = ArkivCreate(
    data=b"Hello",
    btl=1800,  # blocks - shows deprecation warning
    string_annotations=[],
    numeric_annotations=[]
)
```

## Backward Compatibility

### Deprecated but Functional
- btl field (in ArkivCreate and ArkivUpdate)
- number_of_blocks field (in ArkivExtend)

### Priority System
- expires_in > btl
- duration > number_of_blocks
- Deprecation warnings displayed when using old API

### Migration
- Existing code continues to work without changes
- Console warnings encourage migration to new API
- No breaking changes

## Technical Details

- Added resolve_expiration_blocks() for expires_in/btl resolution
- Added resolve_extension_blocks() for duration/number_of_blocks resolution
- Updated utils.py to use resolution functions in RLP encoding
- All conversions handle both int (seconds) and ExpirationTime objects
@r-vdp r-vdp force-pushed the feature/expires-in-api branch 2 times, most recently from 0733a97 to 7ea4dc7 Compare October 29, 2025 15:39
@r-vdp r-vdp force-pushed the feature/expires-in-api branch from 7ea4dc7 to 2eed942 Compare October 29, 2025 15:41
@r-vdp r-vdp merged commit af9e7b3 into main Oct 29, 2025
1 check passed
@r-vdp r-vdp deleted the feature/expires-in-api branch October 29, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants