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

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Prefix for 'd' tag identifiers.
    static final int
    Event kind for voucher ledger (NIP-33 parameterized replaceable).
    static final String
    Tag name for face value amount.
    static final String
    Tag name for expiry timestamp.
    static final String
    Tag name for voucher status.
    static final String
    Tag name for currency/unit.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    Gets the voucher unit from tags.
    Gets the voucher ID from this event's 'd' tag.
    boolean
    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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • VoucherLedgerEvent

      public VoucherLedgerEvent()
  • Method Details

    • fromVoucher

      public static VoucherLedgerEvent fromVoucher(SignedVoucher voucher, VoucherStatus status)
      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

      public SignedVoucher toVoucher()
      Converts this event back to a domain SignedVoucher.
      Returns:
      the signed voucher
      Throws:
      VoucherNostrException - if deserialization fails
    • getStatus

      public VoucherStatus getStatus()
      Gets the voucher status from this event's tags.
      Returns:
      the voucher status
      Throws:
      VoucherNostrException - if status tag is missing or invalid
    • getVoucherId

      public String 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

      public Long getAmount()
      Gets the voucher amount from tags.
      Returns:
      the amount
    • getUnit

      public String getUnit()
      Gets the voucher unit from tags.
      Returns:
      the unit
    • getExpiry

      public Long 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