mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2025-11-05 11:56:37 +00:00
add initial code to create a pool
This commit is contained in:
parent
e236c502a8
commit
7814f188f3
4 changed files with 146 additions and 9 deletions
36
build.gradle
36
build.gradle
|
|
@ -25,6 +25,7 @@ version '2.2.2'
|
|||
repositories {
|
||||
mavenCentral()
|
||||
maven { url 'https://code.sparrowwallet.com/api/packages/sparrowwallet/maven' }
|
||||
maven { url 'https://jitpack.io' }
|
||||
}
|
||||
|
||||
tasks.withType(AbstractArchiveTask) {
|
||||
|
|
@ -43,6 +44,9 @@ java {
|
|||
|
||||
dependencies {
|
||||
//Any changes to the dependencies must be reflected in the module definitions below!
|
||||
implementation('com.github.tcheeric:nostr-java:v0.007.1-alpha') {
|
||||
exclude group: 'com.github.tcheeric.nostr-java', module: 'nostr-java-test'
|
||||
}
|
||||
implementation(project(':drongo'))
|
||||
implementation(project(':lark'))
|
||||
implementation('com.google.guava:guava:33.0.0-jre')
|
||||
|
|
@ -347,6 +351,38 @@ tasks.register('packageTarDistribution', Tar) {
|
|||
}
|
||||
|
||||
extraJavaModuleInfo {
|
||||
module('com.github.tcheeric:nostr-java', 'nostr.java') {
|
||||
exports('nostr.api')
|
||||
exports('nostr.base')
|
||||
exports('nostr.event')
|
||||
exports('nostr.event.impl')
|
||||
exports('nostr.id')
|
||||
exports('nostr.ws')
|
||||
exports('nostr.ws.listener')
|
||||
exports('nostr.crypto')
|
||||
exports('nostr.util')
|
||||
requires('java.base')
|
||||
requires('java.net.http')
|
||||
}
|
||||
|
||||
module('com.squareup.okio:okio', 'com.squareup.okio') {
|
||||
exports('okio')
|
||||
requires('java.base')
|
||||
requires('org.jetbrains.kotlin.stdlib')
|
||||
}
|
||||
|
||||
module('me.champeau.openbeans:openbeans', 'me.champeau.openbeans') {
|
||||
exports('com.sun.beans')
|
||||
exports('com.sun.beans.decoder')
|
||||
exports('com.sun.beans.editors')
|
||||
exports('com.sun.beans.finder')
|
||||
exports('com.sun.beans.infos')
|
||||
exports('com.sun.beans.util')
|
||||
requires('java.base')
|
||||
requires('java.desktop')
|
||||
}
|
||||
|
||||
|
||||
module('no.tornado:tornadofx-controls', 'tornadofx.controls') {
|
||||
exports('tornadofx.control')
|
||||
requires('javafx.controls')
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import javafx.scene.control.TextField;
|
|||
import javafx.scene.control.Alert;
|
||||
import javafx.scene.control.Alert.AlertType;
|
||||
|
||||
import nostr.event.impl.GenericEvent;
|
||||
|
||||
public class NewPoolController extends JoinstrFormController {
|
||||
@FXML
|
||||
private TextField denominationField;
|
||||
|
|
@ -49,15 +51,18 @@ public class NewPoolController extends JoinstrFormController {
|
|||
return;
|
||||
}
|
||||
|
||||
// TODO: Implement pool creation logic here
|
||||
try {
|
||||
GenericEvent event = NostrPublisher.publishCustomEvent(denomination, peers);
|
||||
|
||||
/*
|
||||
Alert alert = new Alert(AlertType.INFORMATION);
|
||||
alert.setTitle("Success");
|
||||
alert.setHeaderText(null);
|
||||
alert.setContentText("Pool created successfully!");
|
||||
alert.showAndWait();
|
||||
*/
|
||||
Alert alert = new Alert(AlertType.INFORMATION);
|
||||
alert.setHeaderText(null);
|
||||
assert event != null;
|
||||
alert.setContentText("Pool created successfully!\nEvent ID: " + event.getId() +
|
||||
"\nDenomination: " + denomination + "\nPeers: " + peers);
|
||||
alert.showAndWait();
|
||||
} catch (Exception e) {
|
||||
showError("Error: " + e.getMessage());
|
||||
}
|
||||
|
||||
denominationField.clear();
|
||||
peersField.clear();
|
||||
|
|
@ -74,4 +79,4 @@ public class NewPoolController extends JoinstrFormController {
|
|||
alert.setContentText(message);
|
||||
alert.showAndWait();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,91 @@
|
|||
package com.sparrowwallet.sparrow.joinstr;
|
||||
|
||||
import nostr.api.NIP01;
|
||||
import nostr.event.BaseTag;
|
||||
import nostr.event.impl.GenericEvent;
|
||||
import nostr.id.Identity;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class NostrPublisher {
|
||||
|
||||
private static final Identity SENDER = Identity.generateRandomIdentity();
|
||||
|
||||
private static final Map<String, String> RELAYS = Map.of(
|
||||
"nos", "wss://nos.lol"
|
||||
);
|
||||
|
||||
public static void main(String[] args) {
|
||||
String defaultDenomination = "100000";
|
||||
String defaultPeers = "5";
|
||||
GenericEvent event = publishCustomEvent(defaultDenomination, defaultPeers);
|
||||
if (event != null) {
|
||||
System.out.println("Event ID: " + event.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public static GenericEvent publishCustomEvent(String denomination, String peers) {
|
||||
try {
|
||||
System.out.println("Public key: " + SENDER.getPublicKey().toString());
|
||||
System.out.println("Private key: " + SENDER.getPrivateKey().toString());
|
||||
|
||||
Identity poolIdentity = Identity.generateRandomIdentity();
|
||||
|
||||
long timeout = Instant.now().getEpochSecond() + 3600;
|
||||
|
||||
List<BaseTag> tags = new ArrayList<>();
|
||||
String poolId = UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
|
||||
String content = String.format(
|
||||
"{\n" +
|
||||
" \"type\": \"new_pool\",\n" +
|
||||
" \"id\": \"%s\",\n" +
|
||||
" \"public_key\": \"%s\",\n" +
|
||||
" \"denomination\": %s,\n" +
|
||||
" \"peers\": %s,\n" +
|
||||
" \"timeout\": %d,\n" +
|
||||
" \"relay\": \"%s\",\n" +
|
||||
" \"fee_rate\": 1,\n" +
|
||||
" \"transport\": \"tor\",\n" +
|
||||
" \"vpn_gateway\": null\n" +
|
||||
"}",
|
||||
poolId,
|
||||
poolIdentity.getPublicKey().toString(),
|
||||
denomination,
|
||||
peers,
|
||||
timeout,
|
||||
RELAYS.values().iterator().next()
|
||||
);
|
||||
|
||||
NIP01 nip01 = new NIP01(SENDER);
|
||||
|
||||
GenericEvent event = new GenericEvent(
|
||||
SENDER.getPublicKey(),
|
||||
2022,
|
||||
tags,
|
||||
content
|
||||
);
|
||||
|
||||
nip01.setEvent(event);
|
||||
nip01.sign();
|
||||
|
||||
nip01.send(RELAYS);
|
||||
|
||||
if (event != null) {
|
||||
System.out.println("Event ID: " + event.getId());
|
||||
System.out.println("Event: " + event.toString());
|
||||
}
|
||||
|
||||
return event;
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -56,4 +56,9 @@ open module com.sparrowwallet.sparrow {
|
|||
requires com.sparrowwallet.tern;
|
||||
requires com.sparrowwallet.lark;
|
||||
requires com.sun.jna;
|
||||
requires nostr.api;
|
||||
requires nostr.base;
|
||||
requires nostr.event;
|
||||
requires nostr.id;
|
||||
requires nostr.util;
|
||||
}
|
||||
Loading…
Reference in a new issue