Class VoucherLedgerEvent
java.lang.Object
nostr.event.BaseEvent
nostr.event.impl.GenericEvent
xyz.tcheeric.cashu.voucher.nostr.events.VoucherLedgerEvent
- All Implemented Interfaces:
nostr.base.IBech32Encodable,nostr.base.IElement,nostr.base.IEvent,nostr.base.ISignable,nostr.event.Deleteable
public class VoucherLedgerEvent
extends nostr.event.impl.GenericEvent
Nostr event for voucher ledger records (NIP-33 parameterized replaceable).
This class extends GenericEvent to provide type-safe voucher ledger
events. It uses NIP-33 parameterized replaceable events (kind 30078) to ensure
each voucher has a unique, updatable record on the ledger.
Event Structure
{
"kind": 30078,
"pubkey": "<issuer public key>",
"created_at": <issue timestamp>,
"tags": [
["d", "voucher:<voucher-id>"],
["status", "<ISSUED|REDEEMED|REVOKED|EXPIRED>"],
["amount", "<face value>"],
["unit", "<sat|usd|etc>"],
["expiry", "<unix timestamp>"]
],
"content": "<JSON serialized SignedVoucher>"
}
Usage Example
// Create event from domain voucher SignedVoucher voucher = ...; VoucherLedgerEvent event = VoucherLedgerEvent.fromVoucher(voucher, VoucherStatus.ISSUED); // Extract voucher from event SignedVoucher restored = event.toVoucher(); VoucherStatus status = event.getStatus(); String voucherId = event.getVoucherId();
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class nostr.event.impl.GenericEvent
nostr.event.impl.GenericEvent.GenericEventBuilder -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringPrefix for 'd' tag identifiers.static final intEvent kind for voucher ledger (NIP-33 parameterized replaceable).static final StringTag name for face value amount.static final StringTag name for expiry timestamp.static final StringTag name for voucher status.static final StringTag name for currency/unit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic VoucherLedgerEventfromVoucher(SignedVoucher voucher, VoucherStatus status) Creates a VoucherLedgerEvent from a domain voucher and status.Gets the voucher amount from tags.Gets the expiry timestamp from tags.Gets the voucher status from this event's tags.getUnit()Gets the voucher unit from tags.Gets the voucher ID from this event's 'd' tag.booleanisValid()Checks if this event is a valid voucher ledger event.Converts this event back to a domain SignedVoucher.Methods inherited from class nostr.event.impl.GenericEvent
addGenericTag, addStandardTag, addStandardTag, addStringListTag, addTag, builder, canEqual, convert, equals, get_serializedEvent, getByteArraySupplier, getContent, getCreatedAt, getId, getKind, getNip, getPubKey, getSerializedEventCache, getSignature, getSignatureConsumer, getTag, getTags, getTags, hashCode, isAddressable, isEphemeral, isReplaceable, isSigned, requireTag, requireTagInstance, set_serializedEvent, setContent, setCreatedAt, setId, setKind, setNip, setPubKey, setSerializedEventCache, setSignature, setTags, toBech32, toString, update, updateTagsParents, validate, validateContent, validateKind, validateTags
-
Field Details
-
KIND_VOUCHER_LEDGER
public static final int KIND_VOUCHER_LEDGEREvent kind for voucher ledger (NIP-33 parameterized replaceable).- See Also:
-
TAG_STATUS
Tag name for voucher status.- See Also:
-
TAG_AMOUNT
Tag name for face value amount.- See Also:
-
TAG_UNIT
Tag name for currency/unit.- See Also:
-
TAG_EXPIRY
Tag name for expiry timestamp.- See Also:
-
D_TAG_PREFIX
Prefix for 'd' tag identifiers.- See Also:
-
-
Constructor Details
-
VoucherLedgerEvent
public VoucherLedgerEvent()
-
-
Method Details
-
fromVoucher
Creates a VoucherLedgerEvent from a domain voucher and status.- Parameters:
voucher- the signed voucher (must not be null)status- the voucher status (must not be null)- Returns:
- VoucherLedgerEvent ready for publishing
- Throws:
VoucherNostrException- if serialization fails
-
toVoucher
Converts this event back to a domain SignedVoucher.- Returns:
- the signed voucher
- Throws:
VoucherNostrException- if deserialization fails
-
getStatus
Gets the voucher status from this event's tags.- Returns:
- the voucher status
- Throws:
VoucherNostrException- if status tag is missing or invalid
-
getVoucherId
Gets the voucher ID from this event's 'd' tag.- Returns:
- the voucher ID (without prefix)
- Throws:
VoucherNostrException- if 'd' tag is missing or invalid
-
getAmount
Gets the voucher amount from tags.- Returns:
- the amount
-
getUnit
Gets the voucher unit from tags.- Returns:
- the unit
-
getExpiry
Gets the expiry timestamp from tags.- Returns:
- the expiry timestamp, or null if not set
-
isValid
public boolean isValid()Checks if this event is a valid voucher ledger event.- Returns:
- true if valid, false otherwise
-