Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2fc49a4
continuing NIP57 implementation:
avlo May 18, 2024
abe441a
culled unused abstract class NIP57Event constructors
avlo May 19, 2024
889b31c
implemented proper RelaysTag/RelaysTags methods
avlo May 19, 2024
9ce2b82
removed NIP57Event @NoArgsConstructor as it curcumvents necessary NIP…
avlo May 19, 2024
6f3df78
completed ZapReqestEvent factory. ZapResponseEvent coming next
avlo May 19, 2024
bae8b39
NIP57 & NIP57Impl updated to accomodate required NIP57 receipt parame…
avlo May 19, 2024
9254903
cleanup
avlo May 19, 2024
5b9a6fa
NIP57 createZapRequestEvent unit tests
avlo May 19, 2024
5b0fa3f
NIP57 createZapReceiptEvent unit tests
avlo May 19, 2024
9e3380e
cleaned up redundancies
avlo May 19, 2024
b622737
NIP57Impl ZapRequestEventFactory unit tests
avlo May 19, 2024
81fce07
parameter name fixes
avlo May 19, 2024
2a982a3
Merge branch 'upstream-develop' into nip57
avlo May 19, 2024
a1788db
cleanup
avlo May 20, 2024
3ec8b65
RelaysTag now uses List<Relay> rather than List<String>
avlo May 21, 2024
f92b56d
added direct ZapRequestEvent and ZapReceiptEvent tests
avlo May 21, 2024
43c1dd6
proper Json annotations added to PriceTag
avlo May 21, 2024
beb3d3c
added PriceTagSerializer unit tests
avlo May 21, 2024
85a1323
working snapshot
avlo May 22, 2024
cb48cf2
ongoing
avlo May 22, 2024
e145247
fixed serializer
avlo May 22, 2024
cf36d76
ClassifiedListing class moved out of ClassifiedListingEvent class
avlo May 22, 2024
af61ac0
ZapRequest moved to its own class
avlo May 22, 2024
a31f246
.
avlo May 22, 2024
96c4cc9
ongoing
avlo May 22, 2024
69026e4
ongoing
avlo May 23, 2024
2502507
ZapReceipt moved into impl
avlo May 23, 2024
dfbd091
serializer refactor
avlo May 23, 2024
045a4d8
ClassifiedListing removed from ClassifiedListingEvent
avlo May 23, 2024
b44dc02
added ClassifiedListing BaseTag filtering (if matches previously/alre…
avlo May 24, 2024
460ccc2
quickfix
avlo May 24, 2024
801abce
NIP99Event refactor & unit tests
avlo May 24, 2024
0424fcd
no longer require explicit ClassifiedListing seriaizliers, removed
avlo May 24, 2024
932de6d
cleanup
avlo May 24, 2024
892d1ba
reintro serializers
avlo May 25, 2024
15c2ef7
merge local branch
avlo May 26, 2024
5a08cb1
NIP57Impl PublicKey field changed to PubKeyTag
avlo May 26, 2024
d8253fd
maintain eric's tab/space usage in existing files
avlo May 26, 2024
beb67c1
maintain import policy
avlo May 26, 2024
306a64a
maintain import policy
avlo May 26, 2024
82a3414
cleanup
avlo May 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions nostr-java-api/src/main/java/nostr/api/NIP01.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,9 @@ public NIP01<T> createTextNoteEvent(@NonNull Identity sender, @NonNull String co
* @param content the content of the note
* @return a text note event
*/
public NIP01<T> createTextNoteEvent(@NonNull List<BaseTag> tags, @NonNull String content) {
var sender = getSender();
var factory = (sender!=null) ? new TextNoteEventFactory(sender, tags, content) : new TextNoteEventFactory(sender, tags, content);
var event = factory.create();
setEvent((T) event);

return this;
public NIP01<T> createTextNoteEvent(@NonNull List<BaseTag> tags, @NonNull String content) {
setEvent((T) new TextNoteEventFactory(getSender(), tags, content).create());
return this;
}

public NIP01<T> createMetadataEvent(@NonNull UserProfile profile) {
Expand Down
123 changes: 49 additions & 74 deletions nostr-java-api/src/main/java/nostr/api/NIP57.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package nostr.api;

import lombok.NonNull;
import nostr.api.factory.TagFactory;
import nostr.api.factory.impl.GenericEventFactory;
import nostr.api.factory.impl.NIP57Impl.ZapReceiptEventFactory;
import nostr.api.factory.impl.NIP57Impl.ZapRequestEventFactory;
import nostr.base.ElementAttribute;
import nostr.base.PublicKey;
import nostr.base.Relay;
import nostr.event.BaseTag;
import nostr.event.impl.GenericEvent;
import nostr.event.impl.GenericTag;
import nostr.event.tag.EventTag;
import nostr.event.impl.ZapRequest;
import nostr.event.tag.*;
import nostr.id.Identity;

import java.util.ArrayList;
Expand All @@ -22,10 +21,6 @@
* @author eric
*/
public class NIP57<T extends GenericEvent> extends EventNostr<T> {


private static final int ZAP_EVENT_KIND = 9734;
private static final int ZAP_RECEIPT_EVENT_KIND = 9735;
private static final String LNURL_TAG_NAME = "lnurl";
private static final String BOLT11_TAG_NAME = "bolt11";
private static final String PREIMAGE_TAG_NAME = "preimage";
Expand All @@ -37,66 +32,35 @@ public NIP57(@NonNull Identity sender) {
setSender(sender);
}

/**
* @param content
*/
public NIP57<T> createZapEvent(String content) {
var factory = new GenericEventFactory(getSender(), ZAP_EVENT_KIND, content);
var event = factory.create();
setEvent((T) event);

public NIP57<T> createZapRequestEvent(@NonNull PublicKey recipientPubKey, @NonNull List<BaseTag> baseTags, String content, @NonNull ZapRequest zapRequest) {
setEvent((T) new ZapRequestEventFactory(getSender(), recipientPubKey, baseTags, content, zapRequest).create());
return this;
}

/**
* @param amount
* @param lnurl
* @param relay
* @param recipient
* @param eventTag
* @param content
*/
public NIP57<T> createZapEvent(@NonNull Integer amount, @NonNull String lnurl, Relay relay, @NonNull PublicKey recipient, EventTag eventTag, String content) {
var factory = new GenericEventFactory(getSender(), ZAP_EVENT_KIND, content);
var event = factory.create();
setEvent((T) event);
public NIP57<T> createZapRequestEvent(@NonNull PublicKey recipientPubKey, @NonNull List<BaseTag> baseTags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull RelaysTag relaysTags) {
return createZapRequestEvent(recipientPubKey, baseTags, content, new ZapRequest(relaysTags, amount, lnUrl));
}

return this.addAmountTag(amount)
.addLnurlTag(lnurl)
.addRelayTag(relay)
.addRecipientTag(recipient)
.addEventTag(eventTag);
public NIP57<T> createZapRequestEventFromList(@NonNull PublicKey recipientPubKey, @NonNull List<BaseTag> baseTags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull List<Relay> relays) {
return createZapRequestEvent(recipientPubKey, baseTags, content, amount, lnUrl, new RelaysTag(relays));
}

/**
*
*/
public NIP57<T> createZapReceiptEvent() {
var factory = new GenericEventFactory(getSender(), ZAP_RECEIPT_EVENT_KIND, "");
var event = factory.create();
setEvent((T) event);
public NIP57<T> createZapRequestEvent(@NonNull PublicKey recipientPubKey, @NonNull List<BaseTag> baseTags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull List<String> relays) {
return createZapRequestEventFromList(recipientPubKey, baseTags, content, amount, lnUrl, relays.stream().map(Relay::new).toList());
}

return this;
public NIP57<T> createZapRequestEvent(@NonNull PublicKey recipientPubKey, @NonNull List<BaseTag> baseTags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull String... relaysTags) {
return createZapRequestEvent(recipientPubKey, baseTags, content, amount, lnUrl, List.of(relaysTags));
}

/**
* @param zapEvent
* @param bolt11
* @param preimage
* @param recipient
* @param eventTag
* @return
*/
public NIP57<T> createZapReceiptEvent(@NonNull GenericEvent zapEvent, @NonNull String bolt11, @NonNull String preimage, @NonNull PublicKey recipient, @NonNull EventTag eventTag) {
var factory = new GenericEventFactory(getSender(), ZAP_RECEIPT_EVENT_KIND, "");
var event = factory.create();
setEvent((T) event);
public NIP57<T> createZapReceiptEvent(@NonNull PubKeyTag zapRequestPubKeyTag, List<BaseTag> baseTags, EventTag zapRequestEventTag, AddressTag zapRequestAddressTag, @NonNull String bolt11,
@NonNull String descriptionSha256, @NonNull String preimage) {
setEvent((T) new ZapReceiptEventFactory(getSender(), baseTags, zapRequestPubKeyTag, zapRequestEventTag, zapRequestAddressTag, bolt11, descriptionSha256, preimage).create());
return this;
}

return this.addBolt11Tag(bolt11)
.addDescriptionTag(Nostr.Json.encode(zapEvent))
.addPreImageTag(preimage)
.addRecipientTag(recipient)
.addEventTag(eventTag);
public NIP57<T> createZapReceiptEvent(@NonNull String zapRequestPubKeyTag, List<BaseTag> baseTags, String zapRequestEventTag, String zapReceiptAddressTag, String zapReceiptIdentifier, String zapReceiptRelayUri, String bolt11, String descriptionSha256, String preimage) {
return createZapReceiptEvent(new PubKeyTag(new PublicKey(zapRequestPubKeyTag)), baseTags, new EventTag(zapRequestEventTag), new AddressTag(null, new PublicKey(zapReceiptAddressTag), new IdentifierTag(zapReceiptIdentifier), new Relay(zapReceiptRelayUri)), bolt11, descriptionSha256, preimage);
}

public NIP57<T> addLnurlTag(@NonNull String lnurl) {
Expand Down Expand Up @@ -134,21 +98,33 @@ public NIP57<T> addRecipientTag(@NonNull PublicKey recipient) {
return this;
}

public NIP57<T> addZapTag(@NonNull PublicKey receiver, @NonNull Relay relay, Integer weight) {
getEvent().addTag(createZapTag(receiver, relay, weight));
public NIP57<T> addZapTag(@NonNull PublicKey receiver, @NonNull List<Relay> relays, Integer weight) {
getEvent().addTag(createZapTag(receiver, relays, weight));
return this;
}

public NIP57<T> addZapTag(@NonNull PublicKey receiver, @NonNull Relay relay) {
getEvent().addTag(createZapTag(receiver, relay));
public NIP57<T> addZapTag(@NonNull PublicKey receiver, @NonNull List<Relay> relays) {
getEvent().addTag(createZapTag(receiver, relays));
return this;
}

public NIP57<T> addRelayTag(@NonNull Relay relay) {
getEvent().addTag(NIP42.createRelayTag(relay));
public NIP57<T> addRelaysTag(@NonNull RelaysTag relaysTag) {
getEvent().addTag(relaysTag);
return this;
}

public NIP57<T> addRelaysList(@NonNull List<Relay> relays) {
return addRelaysTag(new RelaysTag(relays));
}

public NIP57<T> addRelays(@NonNull List<String> relays) {
return addRelaysList(relays.stream().map(Relay::new).toList());
}

public NIP57<T> addRelays(@NonNull String... relays) {
return addRelays(List.of(relays));
}

/**
* @param lnurl
* @return
Expand Down Expand Up @@ -188,29 +164,28 @@ public static GenericTag createAmountTag(@NonNull Integer amount) {

/**
* @param receiver
* @param relay
* @param relays
* @param weight
*/
public static GenericTag createZapTag(@NonNull PublicKey receiver, @NonNull Relay relay, Integer weight) {
public static GenericTag createZapTag(@NonNull PublicKey receiver, @NonNull List<Relay> relays, Integer weight) {
List<ElementAttribute> attributes = new ArrayList<>();
var receiverAttr = new ElementAttribute("receiver", receiver.toString(), 57);
var relayAttr = new ElementAttribute("relay", relay.getUri(), 57);
var relayAttrs = relays.stream().map(relay -> new ElementAttribute("relay", relay.getUri(), 57)).toList();
if (weight != null) {
var weightAttr = new ElementAttribute("weight", weight, 57);
attributes.add(weightAttr);
}

attributes.add(receiverAttr);
attributes.add(relayAttr);

attributes.addAll(relayAttrs);
return new GenericTag(ZAP_TAG_NAME, 57, attributes);
}

/**
* @param receiver
* @param relay
* @param relays
*/
public static GenericTag createZapTag(@NonNull PublicKey receiver, @NonNull Relay relay) {
return createZapTag(receiver, relay, null);
public static GenericTag createZapTag(@NonNull PublicKey receiver, @NonNull List<Relay> relays) {
return createZapTag(receiver, relays, null);
}
}
7 changes: 3 additions & 4 deletions nostr-java-api/src/main/java/nostr/api/NIP99.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import nostr.api.factory.impl.NIP99Impl.ClassifiedListingEventFactory;
import nostr.event.BaseTag;
import nostr.event.NIP99Event;
import nostr.event.impl.ClassifiedListingEvent.ClassifiedListing;
import nostr.event.impl.ClassifiedListing;
import nostr.id.Identity;

import java.util.List;
Expand All @@ -14,9 +14,8 @@ public NIP99(@NonNull Identity sender) {
setSender(sender);
}

public NIP99<T> createClassifiedListingEvent(@NonNull List<BaseTag> baseTags, @NonNull String content, @NonNull ClassifiedListing classifiedListing) {
var event = new ClassifiedListingEventFactory(getSender(), baseTags, content, classifiedListing).create();
setEvent((T) event);
public NIP99<T> createClassifiedListingEvent(@NonNull List<BaseTag> baseTags, String content, @NonNull ClassifiedListing classifiedListing) {
setEvent((T) new ClassifiedListingEventFactory(getSender(), baseTags, content, classifiedListing).create());
return this;
}
}
80 changes: 80 additions & 0 deletions nostr-java-api/src/main/java/nostr/api/factory/impl/NIP57Impl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package nostr.api.factory.impl;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import nostr.api.factory.EventFactory;
import nostr.base.PublicKey;
import nostr.base.Relay;
import nostr.event.BaseTag;
import nostr.event.impl.ZapReceipt;
import nostr.event.impl.ZapReceiptEvent;
import nostr.event.impl.ZapRequest;
import nostr.event.impl.ZapRequestEvent;
import nostr.event.tag.AddressTag;
import nostr.event.tag.EventTag;
import nostr.event.tag.PubKeyTag;
import nostr.event.tag.RelaysTag;
import nostr.id.Identity;

import java.util.List;
import java.util.stream.Stream;

public class NIP57Impl {

@Data
@EqualsAndHashCode(callSuper = false)
public static class ZapRequestEventFactory extends EventFactory<ZapRequestEvent> {
private final ZapRequest zapRequest;
private final PubKeyTag recipientKey;

public ZapRequestEventFactory(@NonNull Identity sender, @NonNull PublicKey recipientPubKey, List<BaseTag> tags, String content, @NonNull ZapRequest zapRequest) {
super(sender, tags, content);
this.zapRequest = zapRequest;
this.recipientKey = new PubKeyTag(recipientPubKey);
}

public ZapRequestEventFactory(@NonNull Identity sender, @NonNull PublicKey recipientPubKey, List<BaseTag> tags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull RelaysTag relaysTag) {
this(sender, recipientPubKey, tags, content, new ZapRequest(relaysTag, amount, lnUrl));
}

public ZapRequestEventFactory(@NonNull Identity sender, @NonNull PublicKey recipientPubKey, List<BaseTag> tags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull List<Relay> relays) {
this(sender, recipientPubKey, tags, content, amount, lnUrl, new RelaysTag(relays));
}

public ZapRequestEventFactory(@NonNull Identity sender, @NonNull PublicKey recipientPubKey, List<BaseTag> tags, String content, @NonNull Long amount, @NonNull String lnUrl, @NonNull String... relaysTags) {
this(sender, recipientPubKey, tags, content, amount, lnUrl, Stream.of(relaysTags).map(Relay::new).toList());
}

@Override
public ZapRequestEvent create() {
return new ZapRequestEvent(getSender(), recipientKey, getTags(), getContent(), zapRequest);
}
}

@Data
@EqualsAndHashCode(callSuper = false)
public static class ZapReceiptEventFactory extends EventFactory<ZapReceiptEvent> {
private final ZapReceipt zapReceipt;
private final PubKeyTag zapRequestPubKeyTag;
private final EventTag zapReceiptEventTag;
private final AddressTag zapRequestAddressTag;

public ZapReceiptEventFactory(@NonNull Identity sender, List<BaseTag> tags, @NonNull PubKeyTag zapRequestPubKeyTag, EventTag zapReceiptEventTag, AddressTag zapReceiptAddressTag, ZapReceipt zapReceipt) {
super(sender, tags, null);
this.zapReceipt = zapReceipt;
this.zapRequestPubKeyTag = zapRequestPubKeyTag;
this.zapReceiptEventTag = zapReceiptEventTag;
this.zapRequestAddressTag = zapReceiptAddressTag;
}

public ZapReceiptEventFactory(@NonNull Identity sender, List<BaseTag> tags, @NonNull PubKeyTag zapRequestPubKeyTag, EventTag zapReceiptEventTag, AddressTag zapReceiptAddressTag, @NonNull String bolt11, @NonNull String descriptionSha256, @NonNull String preimage) {
this(sender, tags, zapRequestPubKeyTag, zapReceiptEventTag, zapReceiptAddressTag, new ZapReceipt(bolt11, descriptionSha256, preimage));
}

@Override
public ZapReceiptEvent create() {
return new ZapReceiptEvent(getSender(), zapRequestPubKeyTag, zapReceiptEventTag, zapRequestAddressTag, zapReceipt);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import nostr.api.factory.EventFactory;
import nostr.event.BaseTag;
import nostr.event.Kind;
import nostr.event.impl.ClassifiedListing;
import nostr.event.impl.ClassifiedListingEvent;
import nostr.event.impl.ClassifiedListingEvent.ClassifiedListing;
import nostr.id.Identity;

import java.util.List;
Expand All @@ -19,11 +20,11 @@ public static class ClassifiedListingEventFactory extends EventFactory<Classifie
private final ClassifiedListing classifiedListing;
private final Kind kind;

public ClassifiedListingEventFactory(Identity sender, List<BaseTag> baseTags, String content, ClassifiedListing classifiedListing) {
public ClassifiedListingEventFactory(@NonNull Identity sender, List<BaseTag> baseTags, String content, @NonNull ClassifiedListing classifiedListing) {
this(sender, Kind.CLASSIFIED_LISTING, baseTags, content, classifiedListing);
}

public ClassifiedListingEventFactory(Identity sender, Kind kind, List<BaseTag> baseTags, String content, ClassifiedListing classifiedListing) {
public ClassifiedListingEventFactory(@NonNull Identity sender, @NonNull Kind kind, List<BaseTag> baseTags, String content, @NonNull ClassifiedListing classifiedListing) {
super(sender, baseTags, content);
this.kind = kind;
this.classifiedListing = classifiedListing;
Expand Down
2 changes: 2 additions & 0 deletions nostr-java-event/src/main/java/nostr/event/Kind.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public enum Kind {
CHANNEL_MESSAGE(42, "channel_message"),
HIDE_MESSAGE(43, "hide_message"),
MUTE_USER(44, "mute_user"),
ZAP_REQUEST(9734, "zap_request"),
ZAP_RECEIPT(9735, "zap_receipt"),
REPLACEABLE_EVENT(10_000, "replaceable_event"),
EPHEMEREAL_EVENT(20_000, "ephemereal_event"),
CLIENT_AUTH(22_242, "authentication_of_clients_to_relays"),
Expand Down
14 changes: 5 additions & 9 deletions nostr-java-event/src/main/java/nostr/event/NIP99Event.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package nostr.event;

import lombok.NoArgsConstructor;
import lombok.NonNull;
import nostr.base.PublicKey;
import nostr.event.impl.GenericEvent;

import java.util.List;

@NoArgsConstructor
public abstract class NIP99Event extends GenericEvent {

public NIP99Event(PublicKey pubKey, Kind kind, List<BaseTag> tags) {
super(pubKey, kind, tags);
}

public NIP99Event(PublicKey pubKey, Kind kind, List<BaseTag> tags, String content) {
super(pubKey, kind, tags, content);
public NIP99Event(@NonNull PublicKey pubKey, Kind kind, List<BaseTag> baseTags) {
this(pubKey, kind, baseTags, null);
}

public NIP99Event(PublicKey sender, Integer kind, List<BaseTag> tags, String content) {
super(sender, kind, tags, content);
public NIP99Event(@NonNull PublicKey pubKey, Kind kind, List<BaseTag> baseTags, String content) {
super(pubKey, kind, baseTags, content);
}
}
Loading