Class StoredVoucher
java.lang.Object
xyz.tcheeric.cashu.voucher.app.dto.StoredVoucher
DTO for storing voucher metadata in wallet state.
This DTO extends the basic SignedVoucher with additional metadata useful for wallet management, such as when the voucher was added, last backup time, etc.
Usage Example
// Convert from SignedVoucher to StoredVoucher
StoredVoucher stored = StoredVoucher.from(signedVoucher);
// Store in wallet
walletState.addVoucher(stored);
// Check if backup needed
if (stored.needsBackup()) {
backupService.backup(stored.getVoucher());
stored.markBackedUp();
}
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StoredVoucherfrom(SignedVoucher voucher) Creates a StoredVoucher from a SignedVoucher with current timestamp.static StoredVoucherfrom(SignedVoucher voucher, String label) Creates a StoredVoucher with a user label.Convenience accessor for face value.Convenience accessor for expiry.getUnit()Convenience accessor for unit.Convenience accessor for voucher ID.booleanChecks if the voucher is expired.booleanisStatusStale(long thresholdSeconds) Checks if the cached status is stale (older than threshold).voidMarks the voucher as backed up (sets lastBackupAt to now).booleanChecks if the voucher needs backup.voidupdateStatus(VoucherStatus status) Updates the cached status and timestamp.
-
Constructor Details
-
StoredVoucher
public StoredVoucher()
-
-
Method Details
-
from
Creates a StoredVoucher from a SignedVoucher with current timestamp. -
from
Creates a StoredVoucher with a user label. -
markBackedUp
public void markBackedUp()Marks the voucher as backed up (sets lastBackupAt to now). -
updateStatus
Updates the cached status and timestamp. -
needsBackup
public boolean needsBackup()Checks if the voucher needs backup. Returns true if never backed up, or if added more recently than last backup. -
isStatusStale
public boolean isStatusStale(long thresholdSeconds) Checks if the cached status is stale (older than threshold).- Parameters:
thresholdSeconds- how many seconds before status is considered stale- Returns:
- true if status should be refreshed
-
getVoucherId
Convenience accessor for voucher ID. -
getAmount
Convenience accessor for face value. -
getUnit
Convenience accessor for unit. -
getExpiresAt
Convenience accessor for expiry. -
isExpired
public boolean isExpired()Checks if the voucher is expired.
-