forked from Qortal/qortal
Compare commits
20 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ce33abcade | ||
|
6c5fedd456 | ||
|
afc2884707 | ||
|
18f15d8122 | ||
|
9710d67cce | ||
|
b2ef503fa7 | ||
|
a497edc488 | ||
|
185f3f515b | ||
|
a445fdc8f2 | ||
|
61e57f9672 | ||
|
fabfed552e | ||
|
c79a830f2e | ||
|
1d9347ed23 | ||
|
c4908678be | ||
|
706dc03b3e | ||
|
f0d4c1e8de | ||
|
32460a1b45 | ||
|
4df05364f5 | ||
|
9f3c1f1cf1 | ||
|
0c8c722097 |
35
README.md
35
README.md
@ -1,19 +1,4 @@
|
||||
# Qortal Project - Qortal Core - Primary Repository
|
||||
The Qortal Core is the blockchain and node component of the overall project. It contains the primary API, and ability to make calls to create transactions, and interact with the Qortal Blockchain Network.
|
||||
|
||||
In order to run the Qortal Core, a machine with java 11+ installed is required. Minimum RAM specs will vary depending on settings, but as low as 4GB of RAM should be acceptable in most scenarios.
|
||||
|
||||
Qortal is a complete infrastructure platform with a blockchain backend, it is capable of indefinite web and application hosting with no continual fees, replacement of DNS and centralized name systems and communications systems, and is the foundation of the next generation digital infrastructure of the world. Qortal is unique in nearly every way, and was written from scratch to address as many concerns from both the existing 'blockchain space' and the 'typical internet' as possible, while maintaining a system that is easy to use and able to run on 'any' computer.
|
||||
|
||||
Qortal contains extensive functionality geared toward complete decentralization of the digital world. Removal of 'middlemen' of any kind from all transactions, and ability to publish websites and applications that require no continual fees, on a name that is truly owned by the account that registered it, or purchased it from another. A single name on Qortal is capable of being both a namespace and a 'username'. That single name can have an application, website, public and private data, communications, authentication, the namespace itself and more, which can subsequently be sold to anyone else without the need to change any type of 'hosting' or DNS entries that do not exist, email that doesn't exist, etc. Maintaining the same functionality as those replaced features of web 2.0.
|
||||
|
||||
Over time Qortal has progressed into a fully featured environment catering to any and all types of people and organizations, and will continue to advance as time goes on. Brining more features, capability, device support, and availale replacements for web2.0. Ultimately building a new, completely user-controlled digital world without limits.
|
||||
|
||||
Qortal has no owner, no company on top of it, and is completely community built, run, and funded. A community-established and run group of developers known as the 'dev-group' or Qortal Development Group, make group_approval based decisions for the project's future. If you are a developer interested in assisting with the project, you meay reach out to the Qortal Development Group in any of the available Qortal community locations. Either on the Qortal network itself, or on one of the temporary centralized social media locations.
|
||||
|
||||
Building the future one block at a time. Welcome to Qortal.
|
||||
|
||||
# Building the Qortal Core from Source
|
||||
# Qortal Project - Official Repo
|
||||
|
||||
## Build / run
|
||||
|
||||
@ -25,21 +10,3 @@ Building the future one block at a time. Welcome to Qortal.
|
||||
- Run JAR in same working directory as *settings.json*: `java -jar target/qortal-1.0.jar`
|
||||
- Wrap in shell script, add JVM flags, redirection, backgrounding, etc. as necessary.
|
||||
- Or use supplied example shell script: *start.sh*
|
||||
|
||||
# Using a pre-built Qortal 'jar' binary
|
||||
|
||||
If you would prefer to utilize a released version of Qortal, you may do so by downloading one of the available releases from the releases page, that are also linked on https://qortal.org and https://qortal.dev.
|
||||
|
||||
# Learning Q-App Development
|
||||
|
||||
https://qortal.dev contains dev documentation for building JS/React (and other client-side languages) applications or 'Q-Apps' on Qortal. Q-Apps are published on Registered Qortal Names, and aside from a single Name Registration fee, and a fraction of QORT for a publish transaction, require zero continual costs. These applications get more redundant with each new access from a new Qortal Node, making your application faster for the next user to download, and stronger as time goes on. Q-Apps live indefinitely in the history of the blockchain-secured Qortal Data Network (QDN).
|
||||
|
||||
# How to learn more
|
||||
|
||||
If the project interests you, you may learn more from the various web2 and QDN based websites focused on introductory information.
|
||||
|
||||
https://qortal.org - primary internet presence
|
||||
https://qortal.dev - secondary and development focused website with links to many new developments and documentation
|
||||
https://wiki.qortal.org - community built and managed wiki with detailed information regarding the project
|
||||
|
||||
links to telegram and discord communities are at the top of https://qortal.org as well.
|
||||
|
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata modelVersion="1.1.0">
|
||||
<groupId>io.reticulum</groupId>
|
||||
<artifactId>reticulum-network-stack</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<versioning>
|
||||
<snapshot>
|
||||
<localCopy>true</localCopy>
|
||||
</snapshot>
|
||||
<lastUpdated>20240814140435</lastUpdated>
|
||||
<snapshotVersions>
|
||||
<snapshotVersion>
|
||||
<extension>jar</extension>
|
||||
<value>1.0-SNAPSHOT</value>
|
||||
<updated>20240814140435</updated>
|
||||
</snapshotVersion>
|
||||
<snapshotVersion>
|
||||
<extension>pom</extension>
|
||||
<value>1.0-SNAPSHOT</value>
|
||||
<updated>20240324170649</updated>
|
||||
</snapshotVersion>
|
||||
</snapshotVersions>
|
||||
</versioning>
|
||||
</metadata>
|
Binary file not shown.
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>io.reticulum</groupId>
|
||||
<artifactId>reticulum-network-stack</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<description>POM was created from install:install-file</description>
|
||||
</project>
|
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<metadata>
|
||||
<groupId>io.reticulum</groupId>
|
||||
<artifactId>reticulum-network-stack</artifactId>
|
||||
<versioning>
|
||||
<versions>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</versions>
|
||||
<lastUpdated>20240814140435</lastUpdated>
|
||||
</versioning>
|
||||
</metadata>
|
220
pom.xml
220
pom.xml
@ -3,12 +3,11 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.qortal</groupId>
|
||||
<artifactId>qortal</artifactId>
|
||||
<version>4.6.6</version>
|
||||
<version>4.5.2</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<skipTests>true</skipTests>
|
||||
|
||||
<altcoinj.version>7dc8c6f</altcoinj.version>
|
||||
<bitcoinj.version>0.15.10</bitcoinj.version>
|
||||
<bouncycastle.version>1.70</bouncycastle.version>
|
||||
@ -16,26 +15,26 @@
|
||||
<ciyam-at.version>1.4.2</ciyam-at.version>
|
||||
<commons-net.version>3.8.0</commons-net.version>
|
||||
<commons-text.version>1.12.0</commons-text.version>
|
||||
<commons-io.version>2.18.0</commons-io.version>
|
||||
<commons-compress.version>1.27.1</commons-compress.version>
|
||||
<commons-lang3.version>3.17.0</commons-lang3.version>
|
||||
<commons-io.version>2.16.1</commons-io.version>
|
||||
<commons-compress.version>1.26.2</commons-compress.version>
|
||||
<commons-lang3.version>3.14.0</commons-lang3.version>
|
||||
<dagger.version>1.2.2</dagger.version>
|
||||
<extendedset.version>0.12.3</extendedset.version>
|
||||
<git-commit-id-plugin.version>4.9.10</git-commit-id-plugin.version>
|
||||
<grpc.version>1.68.1</grpc.version>
|
||||
<guava.version>33.3.1-jre</guava.version>
|
||||
<grpc.version>1.65.0</grpc.version>
|
||||
<guava.version>33.2.1-jre</guava.version>
|
||||
<hamcrest-library.version>2.2</hamcrest-library.version>
|
||||
<homoglyph.version>1.2.1</homoglyph.version>
|
||||
<hsqldb.version>2.7.4</hsqldb.version>
|
||||
<icu4j.version>76.1</icu4j.version>
|
||||
<java-diff-utils.version>4.15</java-diff-utils.version>
|
||||
<hsqldb.version>2.5.1</hsqldb.version>
|
||||
<icu4j.version>75.1</icu4j.version>
|
||||
<java-diff-utils.version>4.12</java-diff-utils.version>
|
||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||
<jaxb-runtime.version>2.3.9</jaxb-runtime.version>
|
||||
<jersey.version>2.42</jersey.version>
|
||||
<jetty.version>9.4.56.v20240826</jetty.version>
|
||||
<jetty.version>9.4.54.v20240208</jetty.version>
|
||||
<json-simple.version>1.1.1</json-simple.version>
|
||||
<json.version>20240303</json.version>
|
||||
<jsoup.version>1.18.1</jsoup.version>
|
||||
<jsoup.version>1.17.2</jsoup.version>
|
||||
<junit-jupiter-engine.version>5.11.0-M2</junit-jupiter-engine.version>
|
||||
<lifecycle-mapping.version>1.0.0</lifecycle-mapping.version>
|
||||
<log4j.version>2.23.1</log4j.version>
|
||||
@ -45,19 +44,24 @@
|
||||
<maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version>
|
||||
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
|
||||
<maven-package-info-plugin.version>1.1.0</maven-package-info-plugin.version>
|
||||
<maven-plugin.version>2.18.0</maven-plugin.version>
|
||||
<maven-reproducible-build-plugin.version>0.17</maven-reproducible-build-plugin.version>
|
||||
<!--<maven-plugin.version>2.16.2</maven-plugin.version>-->
|
||||
<maven-plugin.version>3.12.1</maven-plugin.version>
|
||||
<maven-reproducible-build-plugin.version>0.16</maven-reproducible-build-plugin.version>
|
||||
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
|
||||
<maven-shade-plugin.version>3.6.0</maven-shade-plugin.version>
|
||||
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
|
||||
<maven-surefire-plugin.version>3.3.0</maven-surefire-plugin.version>
|
||||
<protobuf.version>3.25.3</protobuf.version>
|
||||
<replacer.version>1.5.3</replacer.version>
|
||||
<simplemagic.version>1.17</simplemagic.version>
|
||||
<slf4j.version>1.7.36</slf4j.version>
|
||||
<swagger-api.version>2.0.10</swagger-api.version>
|
||||
<swagger-ui.version>5.18.2</swagger-ui.version>
|
||||
<swagger-ui.version>5.17.14</swagger-ui.version>
|
||||
<upnp.version>1.2</upnp.version>
|
||||
<xz.version>1.10</xz.version>
|
||||
<xz.version>1.9</xz.version>
|
||||
<lombok.version>1.18.30</lombok.version>
|
||||
<jackson.version>2.16.1</jackson.version>
|
||||
<slf4j.version>2.0.12</slf4j.version>
|
||||
<nitrite.version>4.3.0</nitrite.version>
|
||||
<junit.version>5.9.2</junit.version>
|
||||
</properties>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@ -426,13 +430,41 @@
|
||||
<id>project.local</id>
|
||||
<name>project</name>
|
||||
<url>file:${project.basedir}/lib</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
<!-- jitpack for build-on-demand of altcoinj -->
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
</snapshots>
|
||||
</repository>
|
||||
</repositories>
|
||||
<!--
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.dizitart</groupId>
|
||||
<artifactId>nitrite-bom</artifactId>
|
||||
<version>${nitrite.version}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-bom</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
-->
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/org.codehaus.mojo/build-helper-maven-plugin -->
|
||||
<dependency>
|
||||
@ -558,7 +590,17 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<!-- Logging: log4j2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
@ -569,24 +611,11 @@
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<!-- redirect slf4j to log4j2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<!-- redirect java.utils.logging to log4j2 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-jul</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<!-- Logging: slf4j used by Jetty/Jersey -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<!-- Servlet related -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
@ -728,6 +757,11 @@
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bctls-jdk15on</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency><!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15to18 -->
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcprov-jdk15to18</artifactId>
|
||||
<version>${bouncycastle.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
@ -770,5 +804,129 @@
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>${jaxb-runtime.version}</version>
|
||||
</dependency>
|
||||
<!-- reticulum_network_stack -->
|
||||
<dependency>
|
||||
<groupId>io.reticulum</groupId>
|
||||
<artifactId>reticulum-network-stack</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.16.1</version>
|
||||
</dependency>
|
||||
<!-- already declared earlier
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.14.0</version>
|
||||
</dependency>
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
<version>4.4</version>
|
||||
</dependency>
|
||||
<!-- already declared earlier
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.26.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
-->
|
||||
<!-- note: covered ? -->
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.yaml</groupId>
|
||||
<artifactId>snakeyaml</artifactId>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.msgpack</groupId>
|
||||
<artifactId>jackson-dataformat-msgpack</artifactId>
|
||||
<version>0.9.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bouncycastle</groupId>
|
||||
<artifactId>bcpkix-jdk15on</artifactId>
|
||||
<version>1.70</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.macasaet.fernet</groupId>
|
||||
<artifactId>fernet-java8</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.igormaznitsa</groupId>
|
||||
<artifactId>jbbp</artifactId>
|
||||
<version>2.0.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<!--<version>4.1.106.Final</version>-->
|
||||
<version>5.0.0.Alpha2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.seancfoley</groupId>
|
||||
<artifactId>ipaddress</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- Nitrite Modules -->
|
||||
<dependency>
|
||||
<groupId>org.dizitart</groupId>
|
||||
<artifactId>nitrite</artifactId>
|
||||
<version>${nitrite.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dizitart</groupId>
|
||||
<artifactId>nitrite-mvstore-adapter</artifactId>
|
||||
<version>${nitrite.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>2.3.230</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2-mvstore</artifactId>
|
||||
<version>2.3.230</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<version>5.10.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -1,17 +1,14 @@
|
||||
package org.qortal;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
|
||||
import org.qortal.api.ApiKey;
|
||||
import org.qortal.api.ApiRequest;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.controller.RestartNode;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.nio.file.Files;
|
||||
@ -19,8 +16,6 @@ import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.Security;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.qortal.controller.RestartNode.AGENTLIB_JVM_HOLDER_ARG;
|
||||
@ -43,7 +38,7 @@ public class ApplyRestart {
|
||||
private static final String JAVA_TOOL_OPTIONS_NAME = "JAVA_TOOL_OPTIONS";
|
||||
private static final String JAVA_TOOL_OPTIONS_VALUE = "";
|
||||
|
||||
private static final long CHECK_INTERVAL = 30 * 1000L; // ms
|
||||
private static final long CHECK_INTERVAL = 10 * 1000L; // ms
|
||||
private static final int MAX_ATTEMPTS = 12;
|
||||
|
||||
public static void main(String[] args) {
|
||||
@ -56,38 +51,21 @@ public class ApplyRestart {
|
||||
else
|
||||
Settings.getInstance();
|
||||
|
||||
LOGGER.info("Applying restart this can take up to 5 minutes...");
|
||||
LOGGER.info("Applying restart...");
|
||||
|
||||
// Shutdown node using API
|
||||
if (!shutdownNode())
|
||||
return;
|
||||
|
||||
try {
|
||||
// Give some time for shutdown
|
||||
TimeUnit.SECONDS.sleep(60);
|
||||
|
||||
// Remove blockchain lock if exist
|
||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||
if (blockchainLock.isLocked())
|
||||
blockchainLock.unlock();
|
||||
|
||||
// Remove blockchain lock file if still exist
|
||||
TimeUnit.SECONDS.sleep(60);
|
||||
deleteLock();
|
||||
|
||||
// Restart node
|
||||
TimeUnit.SECONDS.sleep(15);
|
||||
restartNode(args);
|
||||
|
||||
LOGGER.info("Restarting...");
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("Unable to restart", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shutdownNode() {
|
||||
String baseUri = "http://localhost:" + Settings.getInstance().getApiPort() + "/";
|
||||
LOGGER.debug(() -> String.format("Shutting down node using API via %s", baseUri));
|
||||
LOGGER.info(() -> String.format("Shutting down node using API via %s", baseUri));
|
||||
|
||||
// The /admin/stop endpoint requires an API key, which may or may not be already generated
|
||||
boolean apiKeyNewlyGenerated = false;
|
||||
@ -117,17 +95,10 @@ public class ApplyRestart {
|
||||
String response = ApiRequest.perform(baseUri + "admin/stop", params);
|
||||
if (response == null) {
|
||||
// No response - consider node shut down
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(30);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (apiKeyNewlyGenerated) {
|
||||
// API key was newly generated for restarting node, so we need to remove it
|
||||
ApplyRestart.removeGeneratedApiKey();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -163,22 +134,7 @@ public class ApplyRestart {
|
||||
apiKey.delete();
|
||||
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error loading or deleting API key: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteLock() {
|
||||
// Get the repository path from settings
|
||||
String repositoryPath = Settings.getInstance().getRepositoryPath();
|
||||
LOGGER.debug(String.format("Repository path is: %s", repositoryPath));
|
||||
|
||||
try {
|
||||
Path root = Paths.get(repositoryPath);
|
||||
File lockFile = new File(root.resolve("blockchain.lck").toUri());
|
||||
LOGGER.debug("Lockfile is: {}", lockFile);
|
||||
FileUtils.forceDelete(FileUtils.getFile(lockFile));
|
||||
} catch (IOException e) {
|
||||
LOGGER.debug("Error deleting blockchain lock file: {}", e.getMessage());
|
||||
LOGGER.info("Error loading or deleting API key: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,10 +150,9 @@ public class ApplyRestart {
|
||||
|
||||
List<String> javaCmd;
|
||||
if (Files.exists(exeLauncher)) {
|
||||
javaCmd = List.of(exeLauncher.toString());
|
||||
javaCmd = Arrays.asList(exeLauncher.toString());
|
||||
} else {
|
||||
javaCmd = new ArrayList<>();
|
||||
|
||||
// Java runtime binary itself
|
||||
javaCmd.add(javaBinary.toString());
|
||||
|
||||
|
@ -7,10 +7,7 @@ import org.qortal.controller.LiteNode;
|
||||
import org.qortal.data.account.AccountBalanceData;
|
||||
import org.qortal.data.account.AccountData;
|
||||
import org.qortal.data.account.RewardShareData;
|
||||
import org.qortal.data.naming.NameData;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.GroupRepository;
|
||||
import org.qortal.repository.NameRepository;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.Base58;
|
||||
@ -18,8 +15,6 @@ import org.qortal.utils.Base58;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.qortal.utils.Amounts.prettyAmount;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.NONE) // Stops JAX-RS errors when unmarshalling blockchain config
|
||||
@ -198,76 +193,27 @@ public class Account {
|
||||
|
||||
/** Returns whether account can be considered a "minting account".
|
||||
* <p>
|
||||
* To be considered a "minting account", the account needs to pass some of these tests:<br>
|
||||
* To be considered a "minting account", the account needs to pass at least one of these tests:<br>
|
||||
* <ul>
|
||||
* <li>account's level is at least <tt>minAccountLevelToMint</tt> from blockchain config</li>
|
||||
* <li>account's address has registered a name</li>
|
||||
* <li>account's address is a member of the minter group</li>
|
||||
* <li>account has 'founder' flag set</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param isGroupValidated true if this account has already been validated for MINTER Group membership
|
||||
* @return true if account can be considered "minting account"
|
||||
* @throws DataException
|
||||
*/
|
||||
public boolean canMint(boolean isGroupValidated) throws DataException {
|
||||
public boolean canMint() throws DataException {
|
||||
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
||||
NameRepository nameRepository = this.repository.getNameRepository();
|
||||
GroupRepository groupRepository = this.repository.getGroupRepository();
|
||||
String myAddress = accountData.getAddress();
|
||||
if (accountData == null)
|
||||
return false;
|
||||
|
||||
int blockchainHeight = this.repository.getBlockRepository().getBlockchainHeight();
|
||||
int levelToMint = BlockChain.getInstance().getMinAccountLevelToMint();
|
||||
int level = accountData.getLevel();
|
||||
int groupIdToMint = BlockChain.getInstance().getMintingGroupId();
|
||||
int nameCheckHeight = BlockChain.getInstance().getOnlyMintWithNameHeight();
|
||||
int groupCheckHeight = BlockChain.getInstance().getGroupMemberCheckHeight();
|
||||
int removeNameCheckHeight = BlockChain.getInstance().getRemoveOnlyMintWithNameHeight();
|
||||
Integer level = accountData.getLevel();
|
||||
if (level != null && level >= BlockChain.getInstance().getMinAccountLevelToMint())
|
||||
return true;
|
||||
|
||||
// Can only mint if:
|
||||
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||
if (blockchainHeight < nameCheckHeight) {
|
||||
if (Account.isFounder(accountData.getFlags())) {
|
||||
return accountData.getBlocksMintedPenalty() == 0;
|
||||
} else {
|
||||
return level >= levelToMint;
|
||||
}
|
||||
}
|
||||
|
||||
// Can only mint on onlyMintWithNameHeight from blockchain config if:
|
||||
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||
// Account's address has registered a name
|
||||
if (blockchainHeight >= nameCheckHeight && blockchainHeight < groupCheckHeight) {
|
||||
List<NameData> myName = nameRepository.getNamesByOwner(myAddress);
|
||||
if (Account.isFounder(accountData.getFlags())) {
|
||||
return accountData.getBlocksMintedPenalty() == 0 && !myName.isEmpty();
|
||||
} else {
|
||||
return level >= levelToMint && !myName.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
// Can only mint on groupMemberCheckHeight from blockchain config if:
|
||||
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||
// Account's address has registered a name
|
||||
// Account's address is a member of the minter group
|
||||
if (blockchainHeight >= groupCheckHeight && blockchainHeight < removeNameCheckHeight) {
|
||||
List<NameData> myName = nameRepository.getNamesByOwner(myAddress);
|
||||
if (Account.isFounder(accountData.getFlags())) {
|
||||
return accountData.getBlocksMintedPenalty() == 0 && !myName.isEmpty() && (isGroupValidated || groupRepository.memberExists(groupIdToMint, myAddress));
|
||||
} else {
|
||||
return level >= levelToMint && !myName.isEmpty() && (isGroupValidated || groupRepository.memberExists(groupIdToMint, myAddress));
|
||||
}
|
||||
}
|
||||
|
||||
// Can only mint on removeOnlyMintWithNameHeight from blockchain config if:
|
||||
// Account's level is at least minAccountLevelToMint from blockchain config
|
||||
// Account's address is a member of the minter group
|
||||
if (blockchainHeight >= removeNameCheckHeight) {
|
||||
if (Account.isFounder(accountData.getFlags())) {
|
||||
return accountData.getBlocksMintedPenalty() == 0 && (isGroupValidated || groupRepository.memberExists(groupIdToMint, myAddress));
|
||||
} else {
|
||||
return level >= levelToMint && (isGroupValidated || groupRepository.memberExists(groupIdToMint, myAddress));
|
||||
}
|
||||
}
|
||||
// Founders can always mint, unless they have a penalty
|
||||
if (Account.isFounder(accountData.getFlags()) && accountData.getBlocksMintedPenalty() == 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -282,6 +228,7 @@ public class Account {
|
||||
return this.repository.getAccountRepository().getBlocksMintedPenaltyCount(this.address);
|
||||
}
|
||||
|
||||
|
||||
/** Returns whether account can build reward-shares.
|
||||
* <p>
|
||||
* To be able to create reward-shares, the account needs to pass at least one of these tests:<br>
|
||||
@ -295,7 +242,6 @@ public class Account {
|
||||
*/
|
||||
public boolean canRewardShare() throws DataException {
|
||||
AccountData accountData = this.repository.getAccountRepository().getAccount(this.address);
|
||||
|
||||
if (accountData == null)
|
||||
return false;
|
||||
|
||||
@ -348,24 +294,6 @@ public class Account {
|
||||
return accountData.getLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns reward-share minting address, or unknown if reward-share does not exist.
|
||||
*
|
||||
* @param repository
|
||||
* @param rewardSharePublicKey
|
||||
* @return address or unknown
|
||||
* @throws DataException
|
||||
*/
|
||||
public static String getRewardShareMintingAddress(Repository repository, byte[] rewardSharePublicKey) throws DataException {
|
||||
// Find actual minter address
|
||||
RewardShareData rewardShareData = repository.getAccountRepository().getRewardShare(rewardSharePublicKey);
|
||||
|
||||
if (rewardShareData == null)
|
||||
return "Unknown";
|
||||
|
||||
return rewardShareData.getMinter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'effective' minting level, or zero if reward-share does not exist.
|
||||
*
|
||||
@ -383,7 +311,6 @@ public class Account {
|
||||
Account rewardShareMinter = new Account(repository, rewardShareData.getMinter());
|
||||
return rewardShareMinter.getEffectiveMintingLevel();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns 'effective' minting level, with a fix for the zero level.
|
||||
* <p>
|
||||
|
@ -1,13 +1,7 @@
|
||||
package org.qortal.api.model;
|
||||
|
||||
import org.qortal.account.Account;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.repository.Repository;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
// All properties to be converted to JSON via JAXB
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@ -53,31 +47,4 @@ public class ApiOnlineAccount {
|
||||
return this.recipientAddress;
|
||||
}
|
||||
|
||||
public int getMinterLevelFromPublicKey() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return Account.getRewardShareEffectiveMintingLevel(repository, this.rewardSharePublicKey);
|
||||
} catch (DataException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getIsMember() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return repository.getGroupRepository().memberExists(694, getMinterAddress());
|
||||
} catch (DataException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// JAXB special
|
||||
|
||||
@XmlElement(name = "minterLevel")
|
||||
protected int getMinterLevel() {
|
||||
return getMinterLevelFromPublicKey();
|
||||
}
|
||||
|
||||
@XmlElement(name = "isMinterMember")
|
||||
protected boolean getMinterMember() {
|
||||
return getIsMember();
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import java.math.BigInteger;
|
||||
public class BlockMintingInfo {
|
||||
|
||||
public byte[] minterPublicKey;
|
||||
public String minterAddress;
|
||||
public int minterLevel;
|
||||
public int onlineAccountsCount;
|
||||
public BigDecimal maxDistance;
|
||||
@ -20,4 +19,5 @@ public class BlockMintingInfo {
|
||||
|
||||
public BlockMintingInfo() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,692 +0,0 @@
|
||||
package org.qortal.api.model.crosschain;
|
||||
|
||||
import org.qortal.crosschain.ServerInfo;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Arrays;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class BitcoinyTBDRequest {
|
||||
|
||||
/**
|
||||
* Target Timespan
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* consensus.nPowTargetTimespan
|
||||
*/
|
||||
private int targetTimespan;
|
||||
|
||||
/**
|
||||
* Target Spacing
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* consensus.nPowTargetSpacing
|
||||
*/
|
||||
private int targetSpacing;
|
||||
|
||||
/**
|
||||
* Packet Magic
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* Concatenate the 4 values in pchMessageStart, then convert the hex to decimal.
|
||||
*
|
||||
* Ex. litecoin
|
||||
* pchMessageStart[0] = 0xfb;
|
||||
* pchMessageStart[1] = 0xc0;
|
||||
* pchMessageStart[2] = 0xb6;
|
||||
* pchMessageStart[3] = 0xdb;
|
||||
* packetMagic = 0xfbc0b6db = 4223710939
|
||||
*/
|
||||
private long packetMagic;
|
||||
|
||||
/**
|
||||
* Port
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* nDefaultPort
|
||||
*/
|
||||
private int port;
|
||||
|
||||
/**
|
||||
* Address Header
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* base58Prefixes[PUBKEY_ADDRESS] from Main Network
|
||||
*/
|
||||
private int addressHeader;
|
||||
|
||||
/**
|
||||
* P2sh Header
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* base58Prefixes[SCRIPT_ADDRESS] from Main Network
|
||||
*/
|
||||
private int p2shHeader;
|
||||
|
||||
/**
|
||||
* Segwit Address Hrp
|
||||
*
|
||||
* HRP -> Human Readable Parts
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* bech32_hrp
|
||||
*/
|
||||
private String segwitAddressHrp;
|
||||
|
||||
/**
|
||||
* Dumped Private Key Header
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* base58Prefixes[SECRET_KEY] from Main Network
|
||||
* This is usually, but not always ... addressHeader + 128
|
||||
*/
|
||||
private int dumpedPrivateKeyHeader;
|
||||
|
||||
/**
|
||||
* Subsidy Decreased Block Count
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* consensus.nSubsidyHalvingInterval
|
||||
*
|
||||
* Digibyte does not support this, because they do halving differently.
|
||||
*/
|
||||
private int subsidyDecreaseBlockCount;
|
||||
|
||||
/**
|
||||
* Expected Genesis Hash
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* consensus.hashGenesisBlock
|
||||
* Remove '0x' prefix
|
||||
*/
|
||||
private String expectedGenesisHash;
|
||||
|
||||
/**
|
||||
* Common Script Pub Key
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* This is the key commonly used to sign alerts for altcoins. Bitcoin and Digibyte are know exceptions.
|
||||
*/
|
||||
public static final String SCRIPT_PUB_KEY = "040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9";
|
||||
|
||||
/**
|
||||
* The Script Pub Key
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* The key to sign alerts.
|
||||
*
|
||||
* const CScript genesisOutputScript = CScript() << ParseHex("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9") << OP_CHECKSIG;
|
||||
*
|
||||
* ie LTC = 040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9
|
||||
*
|
||||
* this may be the same value as scripHex
|
||||
*/
|
||||
private String pubKey;
|
||||
|
||||
/**
|
||||
* DNS Seeds
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* vSeeds
|
||||
*/
|
||||
private String[] dnsSeeds;
|
||||
|
||||
/**
|
||||
* BIP32 Header P2PKH Pub
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* Concatenate the 4 values in base58Prefixes[EXT_PUBLIC_KEY]
|
||||
* base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E} = 0x0488B21E
|
||||
*/
|
||||
private int bip32HeaderP2PKHpub;
|
||||
|
||||
/**
|
||||
* BIP32 Header P2PKH Priv
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* Concatenate the 4 values in base58Prefixes[EXT_SECRET_KEY]
|
||||
* base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4} = 0x0488ADE4
|
||||
*/
|
||||
private int bip32HeaderP2PKHpriv;
|
||||
|
||||
/**
|
||||
* Address Header (Testnet)
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* base58Prefixes[PUBKEY_ADDRESS] from Testnet
|
||||
*/
|
||||
private int addressHeaderTestnet;
|
||||
|
||||
/**
|
||||
* BIP32 Header P2PKH Pub (Testnet)
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* Concatenate the 4 values in base58Prefixes[EXT_PUBLIC_KEY]
|
||||
* base58Prefixes[EXT_PUBLIC_KEY] = {0x04, 0x88, 0xB2, 0x1E} = 0x0488B21E
|
||||
*/
|
||||
private int bip32HeaderP2PKHpubTestnet;
|
||||
|
||||
/**
|
||||
* BIP32 Header P2PKH Priv (Testnet)
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* Concatenate the 4 values in base58Prefixes[EXT_SECRET_KEY]
|
||||
* base58Prefixes[EXT_SECRET_KEY] = {0x04, 0x88, 0xAD, 0xE4} = 0x0488ADE4
|
||||
*/
|
||||
private int bip32HeaderP2PKHprivTestnet;
|
||||
|
||||
/**
|
||||
* Id
|
||||
*
|
||||
* "org.litecoin.production" for LTC
|
||||
* I'm guessing this just has to match others for trading purposes.
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Majority Enforce Block Upgrade
|
||||
*
|
||||
* All coins are setting this to 750, except DOGE is setting this to 1500.
|
||||
*/
|
||||
private int majorityEnforceBlockUpgrade;
|
||||
|
||||
/**
|
||||
* Majority Reject Block Outdated
|
||||
*
|
||||
* All coins are setting this to 950, except DOGE is setting this to 1900.
|
||||
*/
|
||||
private int majorityRejectBlockOutdated;
|
||||
|
||||
/**
|
||||
* Majority Window
|
||||
*
|
||||
* All coins are setting this to 1000, except DOGE is setting this to 2000.
|
||||
*/
|
||||
private int majorityWindow;
|
||||
|
||||
/**
|
||||
* Code
|
||||
*
|
||||
* "LITE" for LTC
|
||||
* Currency code for full unit.
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* mCode
|
||||
*
|
||||
* "mLITE" for LTC
|
||||
* Currency code for milli unit.
|
||||
*/
|
||||
private String mCode;
|
||||
|
||||
/**
|
||||
* Base Code
|
||||
*
|
||||
* "Liteoshi" for LTC
|
||||
* Currency code for base unit.
|
||||
*/
|
||||
private String baseCode;
|
||||
|
||||
/**
|
||||
* Min Non Dust Output
|
||||
*
|
||||
* 100000 for LTC, web search for minimum transaction fee per kB
|
||||
*/
|
||||
private int minNonDustOutput;
|
||||
|
||||
/**
|
||||
* URI Scheme
|
||||
*
|
||||
* uriScheme = "litecoin" for LTC
|
||||
* Do a web search to find this value.
|
||||
*/
|
||||
private String uriScheme;
|
||||
|
||||
/**
|
||||
* Protocol Version Minimum
|
||||
*
|
||||
* 70002 for LTC
|
||||
* extracted from /src/protocol.h class
|
||||
*/
|
||||
private int protocolVersionMinimum;
|
||||
|
||||
/**
|
||||
* Protocol Version Current
|
||||
*
|
||||
* 70003 for LTC
|
||||
* extracted from /src/protocol.h class
|
||||
*/
|
||||
private int protocolVersionCurrent;
|
||||
|
||||
/**
|
||||
* Has Max Money
|
||||
*
|
||||
* false for DOGE, true for BTC and LTC
|
||||
*/
|
||||
private boolean hasMaxMoney;
|
||||
|
||||
/**
|
||||
* Max Money
|
||||
*
|
||||
* 84000000 for LTC, 21000000 for BTC
|
||||
* extracted from src/amount.h class
|
||||
*/
|
||||
private long maxMoney;
|
||||
|
||||
/**
|
||||
* Currency Code
|
||||
*
|
||||
* The trading symbol, ie LTC, BTC, DOGE
|
||||
*/
|
||||
private String currencyCode;
|
||||
|
||||
/**
|
||||
* Minimum Order Amount
|
||||
*
|
||||
* web search, LTC minimumOrderAmount = 1000000, 0.01 LTC minimum order to avoid dust errors
|
||||
*/
|
||||
private long minimumOrderAmount;
|
||||
|
||||
/**
|
||||
* Fee Per Kb
|
||||
*
|
||||
* web search, LTC feePerKb = 10000, 0.0001 LTC per 1000 bytes
|
||||
*/
|
||||
private long feePerKb;
|
||||
|
||||
/**
|
||||
* Network Name
|
||||
*
|
||||
* ie Litecoin-MAIN
|
||||
*/
|
||||
private String networkName;
|
||||
|
||||
/**
|
||||
* Fee Ceiling
|
||||
*
|
||||
* web search, LTC fee ceiling = 1000L
|
||||
*/
|
||||
private long feeCeiling;
|
||||
|
||||
/**
|
||||
* Extended Public Key
|
||||
*
|
||||
* xpub for operations that require wallet watching
|
||||
*/
|
||||
private String extendedPublicKey;
|
||||
|
||||
/**
|
||||
* Send Amount
|
||||
*
|
||||
* The amount to send in base units. Also, requires sending fee per byte, receiving address and sender's extended private key.
|
||||
*/
|
||||
private long sendAmount;
|
||||
|
||||
/**
|
||||
* Sending Fee Per Byte
|
||||
*
|
||||
* The fee to include on a send request in base units. Also, requires receiving address, sender's extended private key and send amount.
|
||||
*/
|
||||
private long sendingFeePerByte;
|
||||
|
||||
/**
|
||||
* Receiving Address
|
||||
*
|
||||
* The receiving address for a send request. Also, requires send amount, sender's extended private key and sending fee per byte.
|
||||
*/
|
||||
private String receivingAddress;
|
||||
|
||||
/**
|
||||
* Extended Private Key
|
||||
*
|
||||
* xpriv address for a send request. Also, requires receiving address, send amount and sending fee per byte.
|
||||
*/
|
||||
private String extendedPrivateKey;
|
||||
|
||||
/**
|
||||
* Server Info
|
||||
*
|
||||
* For adding, removing, setting current server requests.
|
||||
*/
|
||||
private ServerInfo serverInfo;
|
||||
|
||||
/**
|
||||
* Script Sig
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* pszTimestamp
|
||||
*
|
||||
* transform this value - https://bitcoin.stackexchange.com/questions/13122/scriptsig-coinbase-structure-of-the-genesis-block
|
||||
* ie LTC = 04ffff001d0104404e592054696d65732030352f4f63742f32303131205374657665204a6f62732c204170706c65e280997320566973696f6e6172792c2044696573206174203536
|
||||
* ie DOGE = 04ffff001d0104084e696e746f6e646f
|
||||
*/
|
||||
private String scriptSig;
|
||||
|
||||
/**
|
||||
* Script Hex
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* genesisOutputScript
|
||||
*
|
||||
* ie LTC = 040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9
|
||||
*
|
||||
* this may be the same value as pubKey
|
||||
*/
|
||||
private String scriptHex;
|
||||
|
||||
/**
|
||||
* Reward
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* CreateGenesisBlock(..., [reward] * COIN)
|
||||
*
|
||||
* ie LTC = 50, BTC = 50, DOGE = 88
|
||||
*/
|
||||
private int reward;
|
||||
|
||||
/**
|
||||
* Genesis Creation Version
|
||||
*/
|
||||
private int genesisCreationVersion;
|
||||
|
||||
/**
|
||||
* Genesis Block Version
|
||||
*/
|
||||
private long genesisBlockVersion;
|
||||
|
||||
/**
|
||||
* Genesis Time
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* CreateGenesisBlock(nTime, ...)
|
||||
*
|
||||
* ie LTC = 1317972665
|
||||
*/
|
||||
private long genesisTime;
|
||||
|
||||
/**
|
||||
* Difficulty Target
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* CreateGenesisBlock(genesisTime, nonce, difficultyTarget, 1, reward * COIN);
|
||||
*
|
||||
* convert from hex to decimal
|
||||
*
|
||||
* ie LTC = 0x1e0ffff0 = 504365040
|
||||
*/
|
||||
private long difficultyTarget;
|
||||
|
||||
/**
|
||||
* Merkle Hex
|
||||
*/
|
||||
private String merkleHex;
|
||||
|
||||
/**
|
||||
* Nonce
|
||||
*
|
||||
* extracted from /src/chainparams.cpp class
|
||||
* CreateGenesisBlock(genesisTime, nonce, difficultyTarget, 1, reward * COIN);
|
||||
*
|
||||
* ie LTC = 2084524493
|
||||
*/
|
||||
private long nonce;
|
||||
|
||||
|
||||
public int getTargetTimespan() {
|
||||
return targetTimespan;
|
||||
}
|
||||
|
||||
public int getTargetSpacing() {
|
||||
return targetSpacing;
|
||||
}
|
||||
|
||||
public long getPacketMagic() {
|
||||
return packetMagic;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public int getAddressHeader() {
|
||||
return addressHeader;
|
||||
}
|
||||
|
||||
public int getP2shHeader() {
|
||||
return p2shHeader;
|
||||
}
|
||||
|
||||
public String getSegwitAddressHrp() {
|
||||
return segwitAddressHrp;
|
||||
}
|
||||
|
||||
public int getDumpedPrivateKeyHeader() {
|
||||
return dumpedPrivateKeyHeader;
|
||||
}
|
||||
|
||||
public int getSubsidyDecreaseBlockCount() {
|
||||
return subsidyDecreaseBlockCount;
|
||||
}
|
||||
|
||||
public String getExpectedGenesisHash() {
|
||||
return expectedGenesisHash;
|
||||
}
|
||||
|
||||
public String getPubKey() {
|
||||
return pubKey;
|
||||
}
|
||||
|
||||
public String[] getDnsSeeds() {
|
||||
return dnsSeeds;
|
||||
}
|
||||
|
||||
public int getBip32HeaderP2PKHpub() {
|
||||
return bip32HeaderP2PKHpub;
|
||||
}
|
||||
|
||||
public int getBip32HeaderP2PKHpriv() {
|
||||
return bip32HeaderP2PKHpriv;
|
||||
}
|
||||
|
||||
public int getAddressHeaderTestnet() {
|
||||
return addressHeaderTestnet;
|
||||
}
|
||||
|
||||
public int getBip32HeaderP2PKHpubTestnet() {
|
||||
return bip32HeaderP2PKHpubTestnet;
|
||||
}
|
||||
|
||||
public int getBip32HeaderP2PKHprivTestnet() {
|
||||
return bip32HeaderP2PKHprivTestnet;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public int getMajorityEnforceBlockUpgrade() {
|
||||
return this.majorityEnforceBlockUpgrade;
|
||||
}
|
||||
|
||||
public int getMajorityRejectBlockOutdated() {
|
||||
return this.majorityRejectBlockOutdated;
|
||||
}
|
||||
|
||||
public int getMajorityWindow() {
|
||||
return this.majorityWindow;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getmCode() {
|
||||
return this.mCode;
|
||||
}
|
||||
|
||||
public String getBaseCode() {
|
||||
return this.baseCode;
|
||||
}
|
||||
|
||||
public int getMinNonDustOutput() {
|
||||
return this.minNonDustOutput;
|
||||
}
|
||||
|
||||
public String getUriScheme() {
|
||||
return this.uriScheme;
|
||||
}
|
||||
|
||||
public int getProtocolVersionMinimum() {
|
||||
return this.protocolVersionMinimum;
|
||||
}
|
||||
|
||||
public int getProtocolVersionCurrent() {
|
||||
return this.protocolVersionCurrent;
|
||||
}
|
||||
|
||||
public boolean isHasMaxMoney() {
|
||||
return this.hasMaxMoney;
|
||||
}
|
||||
|
||||
public long getMaxMoney() {
|
||||
return this.maxMoney;
|
||||
}
|
||||
|
||||
public String getCurrencyCode() {
|
||||
return this.currencyCode;
|
||||
}
|
||||
|
||||
public long getMinimumOrderAmount() {
|
||||
return this.minimumOrderAmount;
|
||||
}
|
||||
|
||||
public long getFeePerKb() {
|
||||
return this.feePerKb;
|
||||
}
|
||||
|
||||
public String getNetworkName() {
|
||||
return this.networkName;
|
||||
}
|
||||
|
||||
public long getFeeCeiling() {
|
||||
return this.feeCeiling;
|
||||
}
|
||||
|
||||
public String getExtendedPublicKey() {
|
||||
return this.extendedPublicKey;
|
||||
}
|
||||
|
||||
public long getSendAmount() {
|
||||
return this.sendAmount;
|
||||
}
|
||||
|
||||
public long getSendingFeePerByte() {
|
||||
return this.sendingFeePerByte;
|
||||
}
|
||||
|
||||
public String getReceivingAddress() {
|
||||
return this.receivingAddress;
|
||||
}
|
||||
|
||||
public String getExtendedPrivateKey() {
|
||||
return this.extendedPrivateKey;
|
||||
}
|
||||
|
||||
public ServerInfo getServerInfo() {
|
||||
return this.serverInfo;
|
||||
}
|
||||
|
||||
public String getScriptSig() {
|
||||
return this.scriptSig;
|
||||
}
|
||||
|
||||
public String getScriptHex() {
|
||||
return this.scriptHex;
|
||||
}
|
||||
|
||||
public int getReward() {
|
||||
return this.reward;
|
||||
}
|
||||
|
||||
public int getGenesisCreationVersion() {
|
||||
return this.genesisCreationVersion;
|
||||
}
|
||||
|
||||
public long getGenesisBlockVersion() {
|
||||
return this.genesisBlockVersion;
|
||||
}
|
||||
|
||||
public long getGenesisTime() {
|
||||
return this.genesisTime;
|
||||
}
|
||||
|
||||
public long getDifficultyTarget() {
|
||||
return this.difficultyTarget;
|
||||
}
|
||||
|
||||
public String getMerkleHex() {
|
||||
return this.merkleHex;
|
||||
}
|
||||
|
||||
public long getNonce() {
|
||||
return this.nonce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BitcoinyTBDRequest{" +
|
||||
"targetTimespan=" + targetTimespan +
|
||||
", targetSpacing=" + targetSpacing +
|
||||
", packetMagic=" + packetMagic +
|
||||
", port=" + port +
|
||||
", addressHeader=" + addressHeader +
|
||||
", p2shHeader=" + p2shHeader +
|
||||
", segwitAddressHrp='" + segwitAddressHrp + '\'' +
|
||||
", dumpedPrivateKeyHeader=" + dumpedPrivateKeyHeader +
|
||||
", subsidyDecreaseBlockCount=" + subsidyDecreaseBlockCount +
|
||||
", expectedGenesisHash='" + expectedGenesisHash + '\'' +
|
||||
", pubKey='" + pubKey + '\'' +
|
||||
", dnsSeeds=" + Arrays.toString(dnsSeeds) +
|
||||
", bip32HeaderP2PKHpub=" + bip32HeaderP2PKHpub +
|
||||
", bip32HeaderP2PKHpriv=" + bip32HeaderP2PKHpriv +
|
||||
", addressHeaderTestnet=" + addressHeaderTestnet +
|
||||
", bip32HeaderP2PKHpubTestnet=" + bip32HeaderP2PKHpubTestnet +
|
||||
", bip32HeaderP2PKHprivTestnet=" + bip32HeaderP2PKHprivTestnet +
|
||||
", id='" + id + '\'' +
|
||||
", majorityEnforceBlockUpgrade=" + majorityEnforceBlockUpgrade +
|
||||
", majorityRejectBlockOutdated=" + majorityRejectBlockOutdated +
|
||||
", majorityWindow=" + majorityWindow +
|
||||
", code='" + code + '\'' +
|
||||
", mCode='" + mCode + '\'' +
|
||||
", baseCode='" + baseCode + '\'' +
|
||||
", minNonDustOutput=" + minNonDustOutput +
|
||||
", uriScheme='" + uriScheme + '\'' +
|
||||
", protocolVersionMinimum=" + protocolVersionMinimum +
|
||||
", protocolVersionCurrent=" + protocolVersionCurrent +
|
||||
", hasMaxMoney=" + hasMaxMoney +
|
||||
", maxMoney=" + maxMoney +
|
||||
", currencyCode='" + currencyCode + '\'' +
|
||||
", minimumOrderAmount=" + minimumOrderAmount +
|
||||
", feePerKb=" + feePerKb +
|
||||
", networkName='" + networkName + '\'' +
|
||||
", feeCeiling=" + feeCeiling +
|
||||
", extendedPublicKey='" + extendedPublicKey + '\'' +
|
||||
", sendAmount=" + sendAmount +
|
||||
", sendingFeePerByte=" + sendingFeePerByte +
|
||||
", receivingAddress='" + receivingAddress + '\'' +
|
||||
", extendedPrivateKey='" + extendedPrivateKey + '\'' +
|
||||
", serverInfo=" + serverInfo +
|
||||
", scriptSig='" + scriptSig + '\'' +
|
||||
", scriptHex='" + scriptHex + '\'' +
|
||||
", reward=" + reward +
|
||||
", genesisCreationVersion=" + genesisCreationVersion +
|
||||
", genesisBlockVersion=" + genesisBlockVersion +
|
||||
", genesisTime=" + genesisTime +
|
||||
", difficultyTarget=" + difficultyTarget +
|
||||
", merkleHex='" + merkleHex + '\'' +
|
||||
", nonce=" + nonce +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
package org.qortal.api.model.crosschain;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class TradeBotRespondRequests {
|
||||
|
||||
@Schema(description = "Foreign blockchain private key, e.g. BIP32 'm' key for Bitcoin/Litecoin starting with 'xprv'",
|
||||
example = "xprv___________________________________________________________________________________________________________")
|
||||
public String foreignKey;
|
||||
|
||||
@Schema(description = "List of address matches")
|
||||
@XmlElement(name = "addresses")
|
||||
public List<String> addresses;
|
||||
|
||||
@Schema(description = "Qortal address for receiving QORT from AT", example = "Qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq")
|
||||
public String receivingAddress;
|
||||
|
||||
public TradeBotRespondRequests() {
|
||||
}
|
||||
|
||||
public TradeBotRespondRequests(String foreignKey, List<String> addresses, String receivingAddress) {
|
||||
this.foreignKey = foreignKey;
|
||||
this.addresses = addresses;
|
||||
this.receivingAddress = receivingAddress;
|
||||
}
|
||||
|
||||
@Schema(description = "Address Match")
|
||||
// All properties to be converted to JSON via JAX-RS
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public static class AddressMatch {
|
||||
@Schema(description = "AT Address")
|
||||
public String atAddress;
|
||||
|
||||
@Schema(description = "Receiving Address")
|
||||
public String receivingAddress;
|
||||
|
||||
// For JAX-RS
|
||||
protected AddressMatch() {
|
||||
}
|
||||
|
||||
public AddressMatch(String atAddress, String receivingAddress) {
|
||||
this.atAddress = atAddress;
|
||||
this.receivingAddress = receivingAddress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AddressMatch{" +
|
||||
"atAddress='" + atAddress + '\'' +
|
||||
", receivingAddress='" + receivingAddress + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TradeBotRespondRequests{" +
|
||||
"foreignKey='" + foreignKey + '\'' +
|
||||
", addresses=" + addresses +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -20,7 +20,9 @@ import org.qortal.asset.Asset;
|
||||
import org.qortal.controller.LiteNode;
|
||||
import org.qortal.controller.OnlineAccountsManager;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.account.*;
|
||||
import org.qortal.data.account.AccountData;
|
||||
import org.qortal.data.account.AccountPenaltyData;
|
||||
import org.qortal.data.account.RewardShareData;
|
||||
import org.qortal.data.network.OnlineAccountData;
|
||||
import org.qortal.data.network.OnlineAccountLevel;
|
||||
import org.qortal.data.transaction.PublicizeTransactionData;
|
||||
@ -50,7 +52,6 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Path("/addresses")
|
||||
@ -326,8 +327,11 @@ public class AddressesResource {
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_PUBLIC_KEY, ApiError.REPOSITORY_ISSUE})
|
||||
@ApiErrors({ApiError.INVALID_PUBLIC_KEY, ApiError.NON_PRODUCTION, ApiError.REPOSITORY_ISSUE})
|
||||
public String fromPublicKey(@PathParam("publickey") String publicKey58) {
|
||||
if (Settings.getInstance().isApiRestricted())
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.NON_PRODUCTION);
|
||||
|
||||
// Decode public key
|
||||
byte[] publicKey;
|
||||
try {
|
||||
@ -626,160 +630,4 @@ public class AddressesResource {
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/sponsorship/{address}")
|
||||
@Operation(
|
||||
summary = "Returns sponsorship statistics for an account",
|
||||
description = "Returns sponsorship statistics for an account, excluding the recipients that get real reward shares",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = SponsorshipReport.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public SponsorshipReport getSponsorshipReport(
|
||||
@PathParam("address") String address,
|
||||
@QueryParam(("realRewardShareRecipient")) String[] realRewardShareRecipients) {
|
||||
if (!Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(address, realRewardShareRecipients);
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
return report;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/sponsorship/{address}/sponsor")
|
||||
@Operation(
|
||||
summary = "Returns sponsorship statistics for an account's sponsor",
|
||||
description = "Returns sponsorship statistics for an account's sponsor, excluding the recipients that get real reward shares",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = SponsorshipReport.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public SponsorshipReport getSponsorshipReportForSponsor(
|
||||
@PathParam("address") String address,
|
||||
@QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients) {
|
||||
if (!Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
// get sponsor
|
||||
Optional<String> sponsor = repository.getAccountRepository().getSponsor(address);
|
||||
|
||||
// if there is not sponsor, throw error
|
||||
if(sponsor.isEmpty()) throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
// get report for sponsor
|
||||
SponsorshipReport report = repository.getAccountRepository().getSponsorshipReport(sponsor.get(), realRewardShareRecipients);
|
||||
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
return report;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/mintership/{address}")
|
||||
@Operation(
|
||||
summary = "Returns mintership statistics for an account",
|
||||
description = "Returns mintership statistics for an account",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "the statistics",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = MintershipReport.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_ADDRESS, ApiError.ADDRESS_UNKNOWN, ApiError.REPOSITORY_ISSUE})
|
||||
public MintershipReport getMintershipReport(@PathParam("address") String address,
|
||||
@QueryParam("realRewardShareRecipient") String[] realRewardShareRecipients ) {
|
||||
if (!Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
// get sponsorship report for minter, fetch a list of one minter
|
||||
SponsorshipReport report = repository.getAccountRepository().getMintershipReport(address, account -> List.of(account));
|
||||
|
||||
// Not found?
|
||||
if (report == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.ADDRESS_UNKNOWN);
|
||||
|
||||
// since the report is for one minter, must get sponsee count separately
|
||||
int sponseeCount = repository.getAccountRepository().getSponseeAddresses(address, realRewardShareRecipients).size();
|
||||
|
||||
// since the report is for one minter, must get the first name from a array of names that should be size 1
|
||||
String name = report.getNames().length > 0 ? report.getNames()[0] : null;
|
||||
|
||||
// transform sponsorship report to mintership report
|
||||
MintershipReport mintershipReport
|
||||
= new MintershipReport(
|
||||
report.getAddress(),
|
||||
report.getLevel(),
|
||||
report.getBlocksMinted(),
|
||||
report.getAdjustments(),
|
||||
report.getPenalties(),
|
||||
report.isTransfer(),
|
||||
name,
|
||||
sponseeCount,
|
||||
report.getAvgBalance(),
|
||||
report.getArbitraryCount(),
|
||||
report.getTransferAssetCount(),
|
||||
report.getTransferPrivsCount(),
|
||||
report.getSellCount(),
|
||||
report.getSellAmount(),
|
||||
report.getBuyCount(),
|
||||
report.getBuyAmount()
|
||||
);
|
||||
|
||||
return mintershipReport;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/levels/{minLevel}")
|
||||
@Operation(
|
||||
summary = "Return accounts with levels greater than or equal to input",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "online accounts",
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, array = @ArraySchema(schema = @Schema(implementation = AddressLevelPairing.class)))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||
|
||||
public List<AddressLevelPairing> getAddressLevelPairings(@PathParam("minLevel") int minLevel) {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
// get the level address pairings
|
||||
List<AddressLevelPairing> pairings = repository.getAccountRepository().getAddressLevelPairings(minLevel);
|
||||
|
||||
return pairings;
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
}
|
@ -227,49 +227,6 @@ public class ArbitraryResource {
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/resources/searchsimple")
|
||||
@Operation(
|
||||
summary = "Search arbitrary resources available on chain, optionally filtered by service.",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(implementation = ArbitraryResourceData.class))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE})
|
||||
public List<ArbitraryResourceData> searchResourcesSimple(
|
||||
@QueryParam("service") Service service,
|
||||
@Parameter(description = "Identifier (searches identifier field only)") @QueryParam("identifier") String identifier,
|
||||
@Parameter(description = "Name (searches name field only)") @QueryParam("name") List<String> names,
|
||||
@Parameter(description = "Prefix only (if true, only the beginning of fields are matched)") @QueryParam("prefix") Boolean prefixOnly,
|
||||
@Parameter(description = "Case insensitive (ignore leter case on search)") @QueryParam("caseInsensitive") Boolean caseInsensitive,
|
||||
@Parameter(description = "Creation date before timestamp") @QueryParam("before") Long before,
|
||||
@Parameter(description = "Creation date after timestamp") @QueryParam("after") Long after,
|
||||
@Parameter(ref = "limit") @QueryParam("limit") Integer limit,
|
||||
@Parameter(ref = "offset") @QueryParam("offset") Integer offset,
|
||||
@Parameter(ref = "reverse") @QueryParam("reverse") Boolean reverse) {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
boolean usePrefixOnly = Boolean.TRUE.equals(prefixOnly);
|
||||
boolean ignoreCase = Boolean.TRUE.equals(caseInsensitive);
|
||||
|
||||
List<ArbitraryResourceData> resources = repository.getArbitraryRepository()
|
||||
.searchArbitraryResourcesSimple(service, identifier, names, usePrefixOnly,
|
||||
before, after, limit, offset, reverse, ignoreCase);
|
||||
|
||||
if (resources == null) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return resources;
|
||||
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/resource/status/{service}/{name}")
|
||||
@Operation(
|
||||
|
@ -542,7 +542,6 @@ public class BlocksResource {
|
||||
}
|
||||
}
|
||||
|
||||
String minterAddress = Account.getRewardShareMintingAddress(repository, blockData.getMinterPublicKey());
|
||||
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, blockData.getMinterPublicKey());
|
||||
if (minterLevel == 0)
|
||||
// This may be unavailable when requesting a trimmed block
|
||||
@ -555,7 +554,6 @@ public class BlocksResource {
|
||||
|
||||
BlockMintingInfo blockMintingInfo = new BlockMintingInfo();
|
||||
blockMintingInfo.minterPublicKey = blockData.getMinterPublicKey();
|
||||
blockMintingInfo.minterAddress = minterAddress;
|
||||
blockMintingInfo.minterLevel = minterLevel;
|
||||
blockMintingInfo.onlineAccountsCount = blockData.getOnlineAccountsCount();
|
||||
blockMintingInfo.maxDistance = new BigDecimal(block.MAX_DISTANCE);
|
||||
@ -889,4 +887,5 @@ public class BlocksResource {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -234,16 +234,12 @@ public class ChatResource {
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_CRITERIA, ApiError.INVALID_ADDRESS, ApiError.REPOSITORY_ISSUE})
|
||||
public ActiveChats getActiveChats(
|
||||
@PathParam("address") String address,
|
||||
@QueryParam("encoding") Encoding encoding,
|
||||
@QueryParam("haschatreference") Boolean hasChatReference
|
||||
) {
|
||||
public ActiveChats getActiveChats(@PathParam("address") String address, @QueryParam("encoding") Encoding encoding) {
|
||||
if (address == null || !Crypto.isValidAddress(address))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return repository.getChatRepository().getActiveChats(address, encoding, hasChatReference);
|
||||
return repository.getChatRepository().getActiveChats(address, encoding);
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.REPOSITORY_ISSUE, e);
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public class CrossChainHtlcResource {
|
||||
htlcStatus.bitcoinP2shAddress = p2shAddress;
|
||||
htlcStatus.bitcoinP2shBalance = BigDecimal.valueOf(p2shBalance, 8);
|
||||
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddress.toString(), false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddress.toString());
|
||||
|
||||
if (p2shBalance > 0L && !fundingOutputs.isEmpty()) {
|
||||
htlcStatus.canRedeem = now >= medianBlockTime * 1000L;
|
||||
@ -401,7 +401,7 @@ public class CrossChainHtlcResource {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(decodedTradePrivateKey);
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(bitcoiny.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, decodedSecret, foreignBlockchainReceivingAccountInfo);
|
||||
@ -664,7 +664,7 @@ public class CrossChainHtlcResource {
|
||||
// ElectrumX coins
|
||||
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoiny.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Validate the destination foreign blockchain address
|
||||
Address receiving = Address.fromString(bitcoiny.getNetworkParameters(), receiveAddress);
|
||||
|
@ -17,16 +17,13 @@ import org.qortal.api.ApiExceptionFactory;
|
||||
import org.qortal.api.Security;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.model.crosschain.TradeBotRespondRequest;
|
||||
import org.qortal.api.model.crosschain.TradeBotRespondRequests;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.controller.tradebot.AcctTradeBot;
|
||||
import org.qortal.controller.tradebot.TradeBot;
|
||||
import org.qortal.crosschain.ACCT;
|
||||
import org.qortal.crosschain.AcctMode;
|
||||
import org.qortal.crosschain.Bitcoiny;
|
||||
import org.qortal.crosschain.ForeignBlockchain;
|
||||
import org.qortal.crosschain.PirateChain;
|
||||
import org.qortal.crosschain.SupportedBlockchain;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.at.ATData;
|
||||
@ -45,10 +42,8 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Path("/crosschain/tradebot")
|
||||
@ -192,39 +187,6 @@ public class CrossChainTradeBotResource {
|
||||
public String tradeBotResponder(@HeaderParam(Security.API_KEY_HEADER) String apiKey, TradeBotRespondRequest tradeBotRespondRequest) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
return createTradeBotResponse(tradeBotRespondRequest);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/respondmultiple")
|
||||
@Operation(
|
||||
summary = "Respond to multiple trade offers. NOTE: WILL SPEND FUNDS!)",
|
||||
description = "Start a new trade-bot entry to respond to chosen trade offers. Pirate Chain is not supported and will throw an invalid criteria error.",
|
||||
requestBody = @RequestBody(
|
||||
required = true,
|
||||
content = @Content(
|
||||
mediaType = MediaType.APPLICATION_JSON,
|
||||
schema = @Schema(
|
||||
implementation = TradeBotRespondRequests.class
|
||||
)
|
||||
)
|
||||
),
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string"))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.INVALID_PRIVATE_KEY, ApiError.INVALID_ADDRESS, ApiError.INVALID_CRITERIA, ApiError.FOREIGN_BLOCKCHAIN_BALANCE_ISSUE, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE, ApiError.REPOSITORY_ISSUE})
|
||||
@SuppressWarnings("deprecation")
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public String tradeBotResponderMultiple(@HeaderParam(Security.API_KEY_HEADER) String apiKey, TradeBotRespondRequests tradeBotRespondRequest) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
return createTradeBotResponseMultiple(tradeBotRespondRequest);
|
||||
}
|
||||
|
||||
private String createTradeBotResponse(TradeBotRespondRequest tradeBotRespondRequest) {
|
||||
final String atAddress = tradeBotRespondRequest.atAddress;
|
||||
|
||||
// We prefer foreignKey to deprecated xprv58
|
||||
@ -295,99 +257,6 @@ public class CrossChainTradeBotResource {
|
||||
}
|
||||
}
|
||||
|
||||
private String createTradeBotResponseMultiple(TradeBotRespondRequests respondRequests) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
if (respondRequests.foreignKey == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
|
||||
|
||||
List<CrossChainTradeData> crossChainTradeDataList = new ArrayList<>(respondRequests.addresses.size());
|
||||
Optional<ACCT> acct = Optional.empty();
|
||||
|
||||
for(String atAddress : respondRequests.addresses ) {
|
||||
|
||||
if (atAddress == null || !Crypto.isValidAtAddress(atAddress))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
if (respondRequests.receivingAddress == null || !Crypto.isValidAddress(respondRequests.receivingAddress))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
final Long minLatestBlockTimestamp = NTP.getTime() - (60 * 60 * 1000L);
|
||||
if (!Controller.getInstance().isUpToDate(minLatestBlockTimestamp))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCKCHAIN_NEEDS_SYNC);
|
||||
|
||||
// Extract data from cross-chain trading AT
|
||||
ATData atData = fetchAtDataWithChecking(repository, atAddress);
|
||||
|
||||
// TradeBot uses AT's code hash to map to ACCT
|
||||
ACCT acctUsingAtData = TradeBot.getInstance().getAcctUsingAtData(atData);
|
||||
if (acctUsingAtData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
// if the optional is empty,
|
||||
// then ensure the ACCT blockchain is a Bitcoiny blockchain, but not Pirate Chain and fill the optional
|
||||
// Even though the Pirate Chain protocol does support multi send,
|
||||
// the Pirate Chain API we are using does not support multi send
|
||||
else if( acct.isEmpty() ) {
|
||||
if( !(acctUsingAtData.getBlockchain() instanceof Bitcoiny) ||
|
||||
acctUsingAtData.getBlockchain() instanceof PirateChain )
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
acct = Optional.of(acctUsingAtData);
|
||||
}
|
||||
// if the optional is filled, then ensure it is equal to the AT in this iteration
|
||||
else if( !acctUsingAtData.getCodeBytesHash().equals(acct.get().getCodeBytesHash()) )
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
|
||||
if (!acctUsingAtData.getBlockchain().isValidWalletKey(respondRequests.foreignKey))
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_PRIVATE_KEY);
|
||||
|
||||
CrossChainTradeData crossChainTradeData = acctUsingAtData.populateTradeData(repository, atData);
|
||||
if (crossChainTradeData == null)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_ADDRESS);
|
||||
|
||||
if (crossChainTradeData.mode != AcctMode.OFFERING)
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.INVALID_CRITERIA);
|
||||
|
||||
// Check if there is a buy or a cancel request in progress for this trade
|
||||
List<Transaction.TransactionType> txTypes = List.of(Transaction.TransactionType.MESSAGE);
|
||||
List<TransactionData> unconfirmed = repository.getTransactionRepository().getUnconfirmedTransactions(txTypes, null, 0, 0, false);
|
||||
for (TransactionData transactionData : unconfirmed) {
|
||||
MessageTransactionData messageTransactionData = (MessageTransactionData) transactionData;
|
||||
if (Objects.equals(messageTransactionData.getRecipient(), atAddress)) {
|
||||
// There is a pending request for this trade, so block this buy attempt to reduce the risk of refunds
|
||||
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.INVALID_CRITERIA, "Trade has an existing buy request or is pending cancellation.");
|
||||
}
|
||||
}
|
||||
|
||||
crossChainTradeDataList.add(crossChainTradeData);
|
||||
}
|
||||
|
||||
AcctTradeBot.ResponseResult result
|
||||
= TradeBot.getInstance().startResponseMultiple(
|
||||
repository,
|
||||
acct.get(),
|
||||
crossChainTradeDataList,
|
||||
respondRequests.receivingAddress,
|
||||
respondRequests.foreignKey,
|
||||
(Bitcoiny) acct.get().getBlockchain());
|
||||
|
||||
switch (result) {
|
||||
case OK:
|
||||
return "true";
|
||||
|
||||
case BALANCE_ISSUE:
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.FOREIGN_BLOCKCHAIN_BALANCE_ISSUE);
|
||||
|
||||
case NETWORK_ISSUE:
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.FOREIGN_BLOCKCHAIN_NETWORK_ISSUE);
|
||||
|
||||
default:
|
||||
return "false";
|
||||
}
|
||||
} catch (DataException e) {
|
||||
throw ApiExceptionFactory.INSTANCE.createCustomException(request, ApiError.REPOSITORY_ISSUE, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Operation(
|
||||
summary = "Delete completed trade",
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.qortal.api.resource;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bitcoinj.core.Address;
|
||||
@ -8,15 +7,11 @@ import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.script.Script;
|
||||
import org.bitcoinj.script.ScriptBuilder;
|
||||
|
||||
import org.bouncycastle.util.Strings;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.qortal.api.model.crosschain.BitcoinyTBDRequest;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.data.at.ATData;
|
||||
import org.qortal.data.crosschain.*;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.utils.BitTwiddling;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -550,86 +545,4 @@ public class CrossChainUtils {
|
||||
server.getConnectionType().toString(),
|
||||
false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Bitcoiny TBD (To Be Determined)
|
||||
*
|
||||
* @param bitcoinyTBDRequest the parameters for the Bitcoiny TBD
|
||||
* @return the Bitcoiny TBD
|
||||
* @throws DataException
|
||||
*/
|
||||
public static BitcoinyTBD getBitcoinyTBD(BitcoinyTBDRequest bitcoinyTBDRequest) throws DataException {
|
||||
|
||||
try {
|
||||
DeterminedNetworkParams networkParams = new DeterminedNetworkParams(bitcoinyTBDRequest);
|
||||
|
||||
BitcoinyTBD bitcoinyTBD
|
||||
= BitcoinyTBD.getInstance(bitcoinyTBDRequest.getCode())
|
||||
.orElse(BitcoinyTBD.buildInstance(
|
||||
bitcoinyTBDRequest,
|
||||
networkParams)
|
||||
);
|
||||
|
||||
return bitcoinyTBD;
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Version Decimal
|
||||
*
|
||||
* @param jsonObject the JSON object with the version attribute
|
||||
* @param attribute the attribute that hold the version value
|
||||
* @return the version as a decimal number, discarding
|
||||
* @throws NumberFormatException
|
||||
*/
|
||||
public static double getVersionDecimal(JSONObject jsonObject, String attribute) throws NumberFormatException {
|
||||
String versionString = (String) jsonObject.get(attribute);
|
||||
return Double.parseDouble(reduceDelimeters(versionString, 1, '.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduce Delimeters
|
||||
*
|
||||
* @param value the raw string
|
||||
* @param max the max number of the delimeter
|
||||
* @param delimeter the delimeter
|
||||
* @return the processed value with the max number of delimeters
|
||||
*/
|
||||
public static String reduceDelimeters(String value, int max, char delimeter) {
|
||||
|
||||
if( max < 1 ) return value;
|
||||
|
||||
String[] splits = Strings.split(value, delimeter);
|
||||
|
||||
StringBuffer buffer = new StringBuffer(splits[0]);
|
||||
|
||||
int limit = Math.min(max + 1, splits.length);
|
||||
|
||||
for( int index = 1; index < limit; index++) {
|
||||
buffer.append(delimeter);
|
||||
buffer.append(splits[index]);
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/** Returns
|
||||
|
||||
|
||||
/**
|
||||
* Build Offer Message
|
||||
*
|
||||
* @param partnerBitcoinPKH
|
||||
* @param hashOfSecretA
|
||||
* @param lockTimeA
|
||||
* @return 'offer' MESSAGE payload for trade partner to send to AT creator's trade address
|
||||
*/
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
}
|
@ -35,7 +35,6 @@ import org.qortal.data.account.RewardShareData;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.Peer;
|
||||
import org.qortal.network.PeerAddress;
|
||||
import org.qortal.repository.ReindexManager;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
@ -459,7 +458,7 @@ public class AdminResource {
|
||||
|
||||
// Qortal: check reward-share's minting account is still allowed to mint
|
||||
Account rewardShareMintingAccount = new Account(repository, rewardShareData.getMinter());
|
||||
if (!rewardShareMintingAccount.canMint(false))
|
||||
if (!rewardShareMintingAccount.canMint())
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.CANNOT_MINT);
|
||||
|
||||
MintingAccountData mintingAccountData = new MintingAccountData(mintingAccount.getPrivateKey(), mintingAccount.getPublicKey());
|
||||
@ -895,50 +894,6 @@ public class AdminResource {
|
||||
}
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/repository/reindex")
|
||||
@Operation(
|
||||
summary = "Reindex repository",
|
||||
description = "Rebuilds all transactions and balances from archived blocks. Warning: takes around 1 week, and the core will not function normally during this time. If 'false' is returned, the database may be left in an inconsistent state, requiring another reindex or a bootstrap to correct it.",
|
||||
responses = {
|
||||
@ApiResponse(
|
||||
description = "\"true\"",
|
||||
content = @Content(mediaType = MediaType.TEXT_PLAIN, schema = @Schema(type = "string"))
|
||||
)
|
||||
}
|
||||
)
|
||||
@ApiErrors({ApiError.REPOSITORY_ISSUE, ApiError.BLOCKCHAIN_NEEDS_SYNC})
|
||||
@SecurityRequirement(name = "apiKey")
|
||||
public String reindex(@HeaderParam(Security.API_KEY_HEADER) String apiKey) {
|
||||
Security.checkApiCallAllowed(request);
|
||||
|
||||
if (Synchronizer.getInstance().isSynchronizing())
|
||||
throw ApiExceptionFactory.INSTANCE.createException(request, ApiError.BLOCKCHAIN_NEEDS_SYNC);
|
||||
|
||||
try {
|
||||
ReentrantLock blockchainLock = Controller.getInstance().getBlockchainLock();
|
||||
|
||||
blockchainLock.lockInterruptibly();
|
||||
|
||||
try {
|
||||
ReindexManager reindexManager = new ReindexManager();
|
||||
reindexManager.reindex();
|
||||
return "true";
|
||||
|
||||
} catch (DataException e) {
|
||||
LOGGER.info("DataException when reindexing: {}", e.getMessage());
|
||||
|
||||
} finally {
|
||||
blockchainLock.unlock();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
// We couldn't lock blockchain to perform reindex
|
||||
return "false";
|
||||
}
|
||||
|
||||
return "false";
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/repository")
|
||||
@Operation(
|
||||
@ -1011,6 +966,8 @@ public class AdminResource {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@POST
|
||||
@Path("/apikey/generate")
|
||||
@Operation(
|
||||
|
@ -77,9 +77,7 @@ public class ActiveChatsWebSocket extends ApiWebSocket {
|
||||
}
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
Boolean hasChatReference = getHasChatReference(session);
|
||||
|
||||
ActiveChats activeChats = repository.getChatRepository().getActiveChats(ourAddress, getTargetEncoding(session), hasChatReference);
|
||||
ActiveChats activeChats = repository.getChatRepository().getActiveChats(ourAddress, getTargetEncoding(session));
|
||||
|
||||
StringWriter stringWriter = new StringWriter();
|
||||
|
||||
@ -105,20 +103,4 @@ public class ActiveChatsWebSocket extends ApiWebSocket {
|
||||
return Encoding.valueOf(encoding);
|
||||
}
|
||||
|
||||
private Boolean getHasChatReference(Session session) {
|
||||
Map<String, List<String>> queryParams = session.getUpgradeRequest().getParameterMap();
|
||||
List<String> hasChatReferenceList = queryParams.get("haschatreference");
|
||||
|
||||
// Return null if not specified
|
||||
if (hasChatReferenceList != null && hasChatReferenceList.size() == 1) {
|
||||
String value = hasChatReferenceList.get(0).toLowerCase();
|
||||
if (value.equals("true")) {
|
||||
return true;
|
||||
} else if (value.equals("false")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return null; // Ignored if not present
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ public class ArbitraryDataRenderer {
|
||||
byte[] data = Files.readAllBytes(filePath); // TODO: limit file size that can be read into memory
|
||||
HTMLParser htmlParser = new HTMLParser(resourceId, inPath, prefix, includeResourceIdInPrefix, data, qdnContext, service, identifier, theme, usingCustomRouting);
|
||||
htmlParser.addAdditionalHeaderTags();
|
||||
response.addHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval'; font-src 'self' data:; media-src 'self' data: blob:; img-src 'self' data: blob:; connect-src 'self' wss:;");
|
||||
response.addHeader("Content-Security-Policy", "default-src 'self' 'unsafe-inline' 'unsafe-eval'; media-src 'self' data: blob:; img-src 'self' data: blob:;");
|
||||
response.setContentType(context.getMimeType(filename));
|
||||
response.setContentLength(htmlParser.getData().length);
|
||||
response.getOutputStream().write(htmlParser.getData());
|
||||
|
@ -167,7 +167,7 @@ public enum Service {
|
||||
COMMENT(1800, true, 500*1024L, true, false, null),
|
||||
CHAIN_COMMENT(1810, true, 239L, true, false, null),
|
||||
MAIL(1900, true, 1024*1024L, true, false, null),
|
||||
MAIL_PRIVATE(1901, true, 5*1024*1024L, true, true, null),
|
||||
MAIL_PRIVATE(1901, true, 1024*1024L, true, true, null),
|
||||
MESSAGE(1910, true, 1024*1024L, true, false, null),
|
||||
MESSAGE_PRIVATE(1911, true, 1024*1024L, true, true, null);
|
||||
|
||||
|
@ -25,8 +25,10 @@ import org.qortal.data.block.BlockSummaryData;
|
||||
import org.qortal.data.block.BlockTransactionData;
|
||||
import org.qortal.data.network.OnlineAccountData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
import org.qortal.repository.*;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.repository.ATRepository;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.TransactionRepository;
|
||||
import org.qortal.transaction.AtTransaction;
|
||||
import org.qortal.transaction.Transaction;
|
||||
import org.qortal.transaction.Transaction.ApprovalStatus;
|
||||
@ -102,7 +104,6 @@ public class Block {
|
||||
protected Repository repository;
|
||||
protected BlockData blockData;
|
||||
protected PublicKeyAccount minter;
|
||||
boolean isTestnet = Settings.getInstance().isTestNet();
|
||||
|
||||
// Other properties
|
||||
private static final Logger LOGGER = LogManager.getLogger(Block.class);
|
||||
@ -141,13 +142,10 @@ public class Block {
|
||||
private final Account mintingAccount;
|
||||
private final AccountData mintingAccountData;
|
||||
private final boolean isMinterFounder;
|
||||
private final boolean isMinterMember;
|
||||
|
||||
private final Account recipientAccount;
|
||||
private final AccountData recipientAccountData;
|
||||
|
||||
final BlockChain blockChain = BlockChain.getInstance();
|
||||
|
||||
ExpandedAccount(Repository repository, RewardShareData rewardShareData) throws DataException {
|
||||
this.rewardShareData = rewardShareData;
|
||||
this.sharePercent = this.rewardShareData.getSharePercent();
|
||||
@ -157,7 +155,6 @@ public class Block {
|
||||
this.isMinterFounder = Account.isFounder(mintingAccountData.getFlags());
|
||||
|
||||
this.isRecipientAlsoMinter = this.rewardShareData.getRecipient().equals(this.mintingAccount.getAddress());
|
||||
this.isMinterMember = repository.getGroupRepository().memberExists(BlockChain.getInstance().getMintingGroupId(), this.mintingAccount.getAddress());
|
||||
|
||||
if (this.isRecipientAlsoMinter) {
|
||||
// Self-share: minter is also recipient
|
||||
@ -193,12 +190,8 @@ public class Block {
|
||||
if (accountLevel <= 0)
|
||||
return null; // level 0 isn't included in any share bins
|
||||
|
||||
if (blockHeight >= blockChain.getFixBatchRewardHeight()) {
|
||||
if (!this.isMinterMember)
|
||||
return null; // not member of minter group isn't included in any share bins
|
||||
}
|
||||
|
||||
// Select the correct set of share bins based on block height
|
||||
final BlockChain blockChain = BlockChain.getInstance();
|
||||
final AccountLevelShareBin[] shareBinsByLevel = (blockHeight >= blockChain.getSharesByLevelV2Height()) ?
|
||||
blockChain.getShareBinsByAccountLevelV2() : blockChain.getShareBinsByAccountLevelV1();
|
||||
|
||||
@ -414,21 +407,6 @@ public class Block {
|
||||
});
|
||||
}
|
||||
|
||||
// After feature trigger, remove any online accounts that are not minter group member
|
||||
if (height >= BlockChain.getInstance().getGroupMemberCheckHeight()) {
|
||||
onlineAccounts.removeIf(a -> {
|
||||
try {
|
||||
int groupId = BlockChain.getInstance().getMintingGroupId();
|
||||
String address = Account.getRewardShareMintingAddress(repository, a.getPublicKey());
|
||||
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);
|
||||
return !isMinterGroupMember;
|
||||
} catch (DataException e) {
|
||||
// Something went wrong, so remove the account
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (onlineAccounts.isEmpty()) {
|
||||
LOGGER.debug("No online accounts - not even our own?");
|
||||
return null;
|
||||
@ -735,20 +713,10 @@ public class Block {
|
||||
|
||||
List<ExpandedAccount> expandedAccounts = new ArrayList<>();
|
||||
|
||||
for (RewardShareData rewardShare : this.cachedOnlineRewardShares) {
|
||||
int groupId = BlockChain.getInstance().getMintingGroupId();
|
||||
String address = rewardShare.getMinter();
|
||||
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);
|
||||
|
||||
if (this.getBlockData().getHeight() < BlockChain.getInstance().getFixBatchRewardHeight())
|
||||
for (RewardShareData rewardShare : this.cachedOnlineRewardShares)
|
||||
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
|
||||
|
||||
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight() && isMinterGroupMember)
|
||||
expandedAccounts.add(new ExpandedAccount(repository, rewardShare));
|
||||
}
|
||||
|
||||
this.cachedExpandedAccounts = expandedAccounts;
|
||||
LOGGER.trace(() -> String.format("Online reward-shares after expanded accounts %s", this.cachedOnlineRewardShares));
|
||||
|
||||
return this.cachedExpandedAccounts;
|
||||
}
|
||||
@ -1158,17 +1126,8 @@ public class Block {
|
||||
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getOnlineAccountMinterLevelValidationHeight()) {
|
||||
List<ExpandedAccount> expandedAccounts = this.getExpandedAccounts();
|
||||
for (ExpandedAccount account : expandedAccounts) {
|
||||
int groupId = BlockChain.getInstance().getMintingGroupId();
|
||||
String address = account.getMintingAccount().getAddress();
|
||||
boolean isMinterGroupMember = repository.getGroupRepository().memberExists(groupId, address);
|
||||
|
||||
if (account.getMintingAccount().getEffectiveMintingLevel() == 0)
|
||||
return ValidationResult.ONLINE_ACCOUNTS_INVALID;
|
||||
|
||||
if (this.getBlockData().getHeight() >= BlockChain.getInstance().getFixBatchRewardHeight()) {
|
||||
if (!isMinterGroupMember)
|
||||
return ValidationResult.ONLINE_ACCOUNTS_INVALID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1297,7 +1256,6 @@ public class Block {
|
||||
|
||||
// Online Accounts
|
||||
ValidationResult onlineAccountsResult = this.areOnlineAccountsValid();
|
||||
LOGGER.trace("Accounts valid = {}", onlineAccountsResult);
|
||||
if (onlineAccountsResult != ValidationResult.OK)
|
||||
return onlineAccountsResult;
|
||||
|
||||
@ -1323,20 +1281,13 @@ public class Block {
|
||||
// Create repository savepoint here so we can rollback to it after testing transactions
|
||||
repository.setSavepoint();
|
||||
|
||||
if (!isTestnet) {
|
||||
if (this.blockData.getHeight() == 212937) {
|
||||
// Apply fix for block 212937 but fix will be rolled back before we exit method
|
||||
Block212937.processFix(this);
|
||||
} else if (this.blockData.getHeight() == 1333492) {
|
||||
// Apply fix for block 1333492 but fix will be rolled back before we exit method
|
||||
Block1333492.processFix(this);
|
||||
} else if (InvalidNameRegistrationBlocks.isAffectedBlock(this.blockData.getHeight())) {
|
||||
}
|
||||
else if (InvalidNameRegistrationBlocks.isAffectedBlock(this.blockData.getHeight())) {
|
||||
// Apply fix for affected name registration blocks, but fix will be rolled back before we exit method
|
||||
InvalidNameRegistrationBlocks.processFix(this);
|
||||
} else if (InvalidBalanceBlocks.isAffectedBlock(this.blockData.getHeight())) {
|
||||
// Apply fix for affected balance blocks, but fix will be rolled back before we exit method
|
||||
InvalidBalanceBlocks.processFix(this);
|
||||
}
|
||||
}
|
||||
|
||||
for (Transaction transaction : this.getTransactions()) {
|
||||
@ -1386,7 +1337,7 @@ public class Block {
|
||||
// Check transaction can even be processed
|
||||
validationResult = transaction.isProcessable();
|
||||
if (validationResult != Transaction.ValidationResult.OK) {
|
||||
LOGGER.debug(String.format("Error during transaction validation, tx %s: %s", Base58.encode(transactionData.getSignature()), validationResult.name()));
|
||||
LOGGER.info(String.format("Error during transaction validation, tx %s: %s", Base58.encode(transactionData.getSignature()), validationResult.name()));
|
||||
return ValidationResult.TRANSACTION_INVALID;
|
||||
}
|
||||
|
||||
@ -1558,7 +1509,7 @@ public class Block {
|
||||
return false;
|
||||
|
||||
Account mintingAccount = new PublicKeyAccount(this.repository, rewardShareData.getMinterPublicKey());
|
||||
return mintingAccount.canMint(false);
|
||||
return mintingAccount.canMint();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1587,7 +1538,6 @@ public class Block {
|
||||
this.blockData.setHeight(blockchainHeight + 1);
|
||||
|
||||
LOGGER.trace(() -> String.format("Processing block %d", this.blockData.getHeight()));
|
||||
LOGGER.trace(() -> String.format("Online Reward Shares in process %s", this.cachedOnlineRewardShares));
|
||||
|
||||
if (this.blockData.getHeight() > 1) {
|
||||
|
||||
@ -1600,23 +1550,21 @@ public class Block {
|
||||
processBlockRewards();
|
||||
}
|
||||
|
||||
if (!isTestnet) {
|
||||
if (this.blockData.getHeight() == 212937) {
|
||||
// Apply fix for block 212937
|
||||
Block212937.processFix(this);
|
||||
} else if (this.blockData.getHeight() == 1333492) {
|
||||
// Apply fix for block 1333492
|
||||
Block1333492.processFix(this);
|
||||
} else if (InvalidBalanceBlocks.isAffectedBlock(this.blockData.getHeight())) {
|
||||
// Apply fix for affected balance blocks
|
||||
InvalidBalanceBlocks.processFix(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV1Height()) {
|
||||
SelfSponsorshipAlgoV1Block.processAccountPenalties(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV2Height()) {
|
||||
SelfSponsorshipAlgoV2Block.processAccountPenalties(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV3Height()) {
|
||||
SelfSponsorshipAlgoV3Block.processAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV1Height()) {
|
||||
SelfSponsorshipAlgoV1Block.processAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV2Height()) {
|
||||
SelfSponsorshipAlgoV2Block.processAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV3Height()) {
|
||||
SelfSponsorshipAlgoV3Block.processAccountPenalties(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1902,23 +1850,21 @@ public class Block {
|
||||
// Invalidate expandedAccounts as they may have changed due to orphaning TRANSFER_PRIVS transactions, etc.
|
||||
this.cachedExpandedAccounts = null;
|
||||
|
||||
if (!isTestnet) {
|
||||
if (this.blockData.getHeight() == 212937) {
|
||||
// Revert fix for block 212937
|
||||
Block212937.orphanFix(this);
|
||||
} else if (this.blockData.getHeight() == 1333492) {
|
||||
// Revert fix for block 1333492
|
||||
Block1333492.orphanFix(this);
|
||||
} else if (InvalidBalanceBlocks.isAffectedBlock(this.blockData.getHeight())) {
|
||||
// Revert fix for affected balance blocks
|
||||
InvalidBalanceBlocks.orphanFix(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV1Height()) {
|
||||
SelfSponsorshipAlgoV1Block.orphanAccountPenalties(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV2Height()) {
|
||||
SelfSponsorshipAlgoV2Block.orphanAccountPenalties(this);
|
||||
} else if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV3Height()) {
|
||||
SelfSponsorshipAlgoV3Block.orphanAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV1Height()) {
|
||||
SelfSponsorshipAlgoV1Block.orphanAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV2Height()) {
|
||||
SelfSponsorshipAlgoV2Block.orphanAccountPenalties(this);
|
||||
}
|
||||
|
||||
if (this.blockData.getHeight() == BlockChain.getInstance().getSelfSponsorshipAlgoV3Height()) {
|
||||
SelfSponsorshipAlgoV3Block.orphanAccountPenalties(this);
|
||||
}
|
||||
|
||||
// Account levels and block rewards are only processed/orphaned on block reward distribution blocks
|
||||
@ -2254,7 +2200,6 @@ public class Block {
|
||||
List<AccountBalanceData> accountBalanceDeltas = balanceChanges.entrySet().stream()
|
||||
.map(entry -> new AccountBalanceData(entry.getKey(), Asset.QORT, entry.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
LOGGER.trace("Account Balance Deltas: {}", accountBalanceDeltas);
|
||||
this.repository.getAccountRepository().modifyAssetBalances(accountBalanceDeltas);
|
||||
}
|
||||
|
||||
@ -2306,6 +2251,7 @@ public class Block {
|
||||
// Select the correct set of share bins based on block height
|
||||
List<AccountLevelShareBin> accountLevelShareBinsForBlock = (this.blockData.getHeight() >= BlockChain.getInstance().getSharesByLevelV2Height()) ?
|
||||
BlockChain.getInstance().getAccountLevelShareBinsV2() : BlockChain.getInstance().getAccountLevelShareBinsV1();
|
||||
|
||||
// Determine reward candidates based on account level
|
||||
// This needs a deep copy, so the shares can be modified when tiers aren't activated yet
|
||||
List<AccountLevelShareBin> accountLevelShareBins = new ArrayList<>();
|
||||
@ -2595,11 +2541,9 @@ public class Block {
|
||||
return;
|
||||
|
||||
int minterLevel = Account.getRewardShareEffectiveMintingLevel(this.repository, this.getMinter().getPublicKey());
|
||||
String minterAddress = Account.getRewardShareMintingAddress(this.repository, this.getMinter().getPublicKey());
|
||||
|
||||
LOGGER.debug(String.format("======= BLOCK %d (%.8s) =======", this.getBlockData().getHeight(), Base58.encode(this.getSignature())));
|
||||
LOGGER.debug(String.format("Timestamp: %d", this.getBlockData().getTimestamp()));
|
||||
LOGGER.debug(String.format("Minter address: %s", minterAddress));
|
||||
LOGGER.debug(String.format("Minter level: %d", minterLevel));
|
||||
LOGGER.debug(String.format("Online accounts: %d", this.getBlockData().getOnlineAccountsCount()));
|
||||
LOGGER.debug(String.format("AT count: %d", this.getBlockData().getATCount()));
|
||||
|
@ -1,101 +0,0 @@
|
||||
package org.qortal.block;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.eclipse.persistence.jaxb.JAXBContextFactory;
|
||||
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
|
||||
import org.qortal.data.account.AccountBalanceData;
|
||||
import org.qortal.repository.DataException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.UnmarshalException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Block 1333492
|
||||
* <p>
|
||||
* As described in InvalidBalanceBlocks.java, legacy bugs caused a small drift in account balances.
|
||||
* This block adjusts any remaining differences between a clean reindex/resync and a recent bootstrap.
|
||||
* <p>
|
||||
* The block height 1333492 isn't significant - it's simply the height of a recent bootstrap at the
|
||||
* time of development, so that the account balances could be accessed and compared against the same
|
||||
* block in a reindexed db.
|
||||
* <p>
|
||||
* As with InvalidBalanceBlocks, the discrepancies are insignificant, except for a single
|
||||
* account which has a 3.03 QORT discrepancy. This was due to the account being the first recipient
|
||||
* of a name sale and encountering an early bug in this area.
|
||||
* <p>
|
||||
* The total offset for this block is 3.02816514 QORT.
|
||||
*/
|
||||
public final class Block1333492 {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(Block1333492.class);
|
||||
private static final String ACCOUNT_DELTAS_SOURCE = "block-1333492-deltas.json";
|
||||
|
||||
private static final List<AccountBalanceData> accountDeltas = readAccountDeltas();
|
||||
|
||||
private Block1333492() {
|
||||
/* Do not instantiate */
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<AccountBalanceData> readAccountDeltas() {
|
||||
Unmarshaller unmarshaller;
|
||||
|
||||
try {
|
||||
// Create JAXB context aware of classes we need to unmarshal
|
||||
JAXBContext jc = JAXBContextFactory.createContext(new Class[] {
|
||||
AccountBalanceData.class
|
||||
}, null);
|
||||
|
||||
// Create unmarshaller
|
||||
unmarshaller = jc.createUnmarshaller();
|
||||
|
||||
// Set the unmarshaller media type to JSON
|
||||
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
|
||||
|
||||
// Tell unmarshaller that there's no JSON root element in the JSON input
|
||||
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
|
||||
} catch (JAXBException e) {
|
||||
String message = "Failed to setup unmarshaller to read block 1333492 deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
|
||||
ClassLoader classLoader = BlockChain.class.getClassLoader();
|
||||
InputStream in = classLoader.getResourceAsStream(ACCOUNT_DELTAS_SOURCE);
|
||||
StreamSource jsonSource = new StreamSource(in);
|
||||
|
||||
try {
|
||||
// Attempt to unmarshal JSON stream to BlockChain config
|
||||
return (List<AccountBalanceData>) unmarshaller.unmarshal(jsonSource, AccountBalanceData.class).getValue();
|
||||
} catch (UnmarshalException e) {
|
||||
String message = "Failed to parse block 1333492 deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
} catch (JAXBException e) {
|
||||
String message = "Unexpected JAXB issue while processing block 1333492 deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void processFix(Block block) throws DataException {
|
||||
block.repository.getAccountRepository().modifyAssetBalances(accountDeltas);
|
||||
}
|
||||
|
||||
public static void orphanFix(Block block) throws DataException {
|
||||
// Create inverse deltas
|
||||
List<AccountBalanceData> inverseDeltas = accountDeltas.stream()
|
||||
.map(delta -> new AccountBalanceData(delta.getAddress(), delta.getAssetId(), 0 - delta.getBalance()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
block.repository.getAccountRepository().modifyAssetBalances(inverseDeltas);
|
||||
}
|
||||
|
||||
}
|
@ -71,7 +71,6 @@ public class BlockChain {
|
||||
transactionV6Timestamp,
|
||||
disableReferenceTimestamp,
|
||||
increaseOnlineAccountsDifficultyTimestamp,
|
||||
decreaseOnlineAccountsDifficultyTimestamp,
|
||||
onlineAccountMinterLevelValidationHeight,
|
||||
selfSponsorshipAlgoV1Height,
|
||||
selfSponsorshipAlgoV2Height,
|
||||
@ -81,14 +80,7 @@ public class BlockChain {
|
||||
arbitraryOptionalFeeTimestamp,
|
||||
unconfirmableRewardSharesHeight,
|
||||
disableTransferPrivsTimestamp,
|
||||
enableTransferPrivsTimestamp,
|
||||
cancelSellNameValidationTimestamp,
|
||||
disableRewardshareHeight,
|
||||
enableRewardshareHeight,
|
||||
onlyMintWithNameHeight,
|
||||
removeOnlyMintWithNameHeight,
|
||||
groupMemberCheckHeight,
|
||||
fixBatchRewardHeight
|
||||
enableTransferPrivsTimestamp
|
||||
}
|
||||
|
||||
// Custom transaction fees
|
||||
@ -208,7 +200,6 @@ public class BlockChain {
|
||||
private int minAccountLevelToRewardShare;
|
||||
private int maxRewardSharesPerFounderMintingAccount;
|
||||
private int founderEffectiveMintingLevel;
|
||||
private int mintingGroupId;
|
||||
|
||||
/** Minimum time to retain online account signatures (ms) for block validity checks. */
|
||||
private long onlineAccountSignaturesMinLifetime;
|
||||
@ -220,10 +211,6 @@ public class BlockChain {
|
||||
* featureTriggers because unit tests need to set this value via Reflection. */
|
||||
private long onlineAccountsModulusV2Timestamp;
|
||||
|
||||
/** Feature trigger timestamp for ONLINE_ACCOUNTS_MODULUS time interval decrease. Can't use
|
||||
* featureTriggers because unit tests need to set this value via Reflection. */
|
||||
private long onlineAccountsModulusV3Timestamp;
|
||||
|
||||
/** Snapshot timestamp for self sponsorship algo V1 */
|
||||
private long selfSponsorshipAlgoV1SnapshotTimestamp;
|
||||
|
||||
@ -410,9 +397,6 @@ public class BlockChain {
|
||||
return this.onlineAccountsModulusV2Timestamp;
|
||||
}
|
||||
|
||||
public long getOnlineAccountsModulusV3Timestamp() {
|
||||
return this.onlineAccountsModulusV3Timestamp;
|
||||
}
|
||||
|
||||
/* Block reward batching */
|
||||
public long getBlockRewardBatchStartHeight() {
|
||||
@ -540,10 +524,6 @@ public class BlockChain {
|
||||
return this.onlineAccountSignaturesMaxLifetime;
|
||||
}
|
||||
|
||||
public int getMintingGroupId() {
|
||||
return this.mintingGroupId;
|
||||
}
|
||||
|
||||
public CiyamAtSettings getCiyamAtSettings() {
|
||||
return this.ciyamAtSettings;
|
||||
}
|
||||
@ -590,10 +570,6 @@ public class BlockChain {
|
||||
return this.featureTriggers.get(FeatureTrigger.increaseOnlineAccountsDifficultyTimestamp.name()).longValue();
|
||||
}
|
||||
|
||||
public long getDecreaseOnlineAccountsDifficultyTimestamp() {
|
||||
return this.featureTriggers.get(FeatureTrigger.decreaseOnlineAccountsDifficultyTimestamp.name()).longValue();
|
||||
}
|
||||
|
||||
public int getSelfSponsorshipAlgoV1Height() {
|
||||
return this.featureTriggers.get(FeatureTrigger.selfSponsorshipAlgoV1Height.name()).intValue();
|
||||
}
|
||||
@ -634,34 +610,6 @@ public class BlockChain {
|
||||
return this.featureTriggers.get(FeatureTrigger.enableTransferPrivsTimestamp.name()).longValue();
|
||||
}
|
||||
|
||||
public long getCancelSellNameValidationTimestamp() {
|
||||
return this.featureTriggers.get(FeatureTrigger.cancelSellNameValidationTimestamp.name()).longValue();
|
||||
}
|
||||
|
||||
public int getDisableRewardshareHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.disableRewardshareHeight.name()).intValue();
|
||||
}
|
||||
|
||||
public int getEnableRewardshareHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.enableRewardshareHeight.name()).intValue();
|
||||
}
|
||||
|
||||
public int getOnlyMintWithNameHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.onlyMintWithNameHeight.name()).intValue();
|
||||
}
|
||||
|
||||
public int getRemoveOnlyMintWithNameHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.removeOnlyMintWithNameHeight.name()).intValue();
|
||||
}
|
||||
|
||||
public int getGroupMemberCheckHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.groupMemberCheckHeight.name()).intValue();
|
||||
}
|
||||
|
||||
public int getFixBatchRewardHeight() {
|
||||
return this.featureTriggers.get(FeatureTrigger.fixBatchRewardHeight.name()).intValue();
|
||||
}
|
||||
|
||||
// More complex getters for aspects that change by height or timestamp
|
||||
|
||||
public long getRewardAtHeight(int ourHeight) {
|
||||
@ -857,12 +805,10 @@ public class BlockChain {
|
||||
boolean isLite = Settings.getInstance().isLite();
|
||||
boolean canBootstrap = Settings.getInstance().getBootstrap();
|
||||
boolean needsArchiveRebuild = false;
|
||||
int checkHeight = 0;
|
||||
BlockData chainTip;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
chainTip = repository.getBlockRepository().getLastBlock();
|
||||
checkHeight = repository.getBlockRepository().getBlockchainHeight();
|
||||
|
||||
// Ensure archive is (at least partially) intact, and force a bootstrap if it isn't
|
||||
if (!isTopOnly && archiveEnabled && canBootstrap) {
|
||||
@ -878,17 +824,6 @@ public class BlockChain {
|
||||
}
|
||||
}
|
||||
|
||||
if (!canBootstrap) {
|
||||
if (checkHeight > 2) {
|
||||
LOGGER.info("Retrieved block 2 from archive. Syncing from genesis block resumed!");
|
||||
} else {
|
||||
needsArchiveRebuild = (repository.getBlockArchiveRepository().fromHeight(2) == null);
|
||||
if (needsArchiveRebuild) {
|
||||
LOGGER.info("Couldn't retrieve block 2 from archive. Bootstrapping is disabled. Syncing from genesis block!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Validate checkpoints
|
||||
// Limited to topOnly nodes for now, in order to reduce risk, and to solve a real-world problem with divergent topOnly nodes
|
||||
// TODO: remove the isTopOnly conditional below once this feature has had more testing time
|
||||
@ -921,14 +856,13 @@ public class BlockChain {
|
||||
|
||||
// Check first block is Genesis Block
|
||||
if (!isGenesisBlockValid() || needsArchiveRebuild) {
|
||||
if (checkHeight < 3) {
|
||||
try {
|
||||
rebuildBlockchain();
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new DataException(String.format("Interrupted when trying to rebuild blockchain: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We need to create a new connection, as the previous repository and its connections may be been
|
||||
// closed by rebuildBlockchain() if a bootstrap was applied
|
||||
@ -1067,4 +1001,5 @@ public class BlockChain {
|
||||
blockchainLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,134 +0,0 @@
|
||||
package org.qortal.block;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.eclipse.persistence.jaxb.JAXBContextFactory;
|
||||
import org.eclipse.persistence.jaxb.UnmarshallerProperties;
|
||||
import org.qortal.data.account.AccountBalanceData;
|
||||
import org.qortal.repository.DataException;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.UnmarshalException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
* Due to various bugs - which have been fixed - a small amount of balance drift occurred
|
||||
* in the chainstate of running nodes and bootstraps, when compared with a clean sync from genesis.
|
||||
* This resulted in a significant number of invalid transactions in the chain history due to
|
||||
* subtle balance discrepancies. The sum of all discrepancies that resulted in an invalid
|
||||
* transaction is 0.00198322 QORT, so despite the large quantity of transactions, they
|
||||
* represent an insignificant amount when summed.
|
||||
* <p>
|
||||
* This class is responsible for retroactively fixing all the past transactions which
|
||||
* are invalid due to the balance discrepancies.
|
||||
*/
|
||||
|
||||
|
||||
public final class InvalidBalanceBlocks {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(InvalidBalanceBlocks.class);
|
||||
|
||||
private static final String ACCOUNT_DELTAS_SOURCE = "invalid-transaction-balance-deltas.json";
|
||||
|
||||
private static final List<AccountBalanceData> accountDeltas = readAccountDeltas();
|
||||
private static final List<Integer> affectedHeights = getAffectedHeights();
|
||||
|
||||
private InvalidBalanceBlocks() {
|
||||
/* Do not instantiate */
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<AccountBalanceData> readAccountDeltas() {
|
||||
Unmarshaller unmarshaller;
|
||||
|
||||
try {
|
||||
// Create JAXB context aware of classes we need to unmarshal
|
||||
JAXBContext jc = JAXBContextFactory.createContext(new Class[] {
|
||||
AccountBalanceData.class
|
||||
}, null);
|
||||
|
||||
// Create unmarshaller
|
||||
unmarshaller = jc.createUnmarshaller();
|
||||
|
||||
// Set the unmarshaller media type to JSON
|
||||
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
|
||||
|
||||
// Tell unmarshaller that there's no JSON root element in the JSON input
|
||||
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
|
||||
} catch (JAXBException e) {
|
||||
String message = "Failed to setup unmarshaller to read block 212937 deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
|
||||
ClassLoader classLoader = BlockChain.class.getClassLoader();
|
||||
InputStream in = classLoader.getResourceAsStream(ACCOUNT_DELTAS_SOURCE);
|
||||
StreamSource jsonSource = new StreamSource(in);
|
||||
|
||||
try {
|
||||
// Attempt to unmarshal JSON stream to BlockChain config
|
||||
return (List<AccountBalanceData>) unmarshaller.unmarshal(jsonSource, AccountBalanceData.class).getValue();
|
||||
} catch (UnmarshalException e) {
|
||||
String message = "Failed to parse balance deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
} catch (JAXBException e) {
|
||||
String message = "Unexpected JAXB issue while processing balance deltas";
|
||||
LOGGER.error(message, e);
|
||||
throw new RuntimeException(message, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Integer> getAffectedHeights() {
|
||||
List<Integer> heights = new ArrayList<>();
|
||||
for (AccountBalanceData accountBalanceData : accountDeltas) {
|
||||
if (!heights.contains(accountBalanceData.getHeight())) {
|
||||
heights.add(accountBalanceData.getHeight());
|
||||
}
|
||||
}
|
||||
return heights;
|
||||
}
|
||||
|
||||
private static List<AccountBalanceData> getAccountDeltasAtHeight(int height) {
|
||||
return accountDeltas.stream().filter(a -> a.getHeight() == height).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static boolean isAffectedBlock(int height) {
|
||||
return affectedHeights.contains(Integer.valueOf(height));
|
||||
}
|
||||
|
||||
public static void processFix(Block block) throws DataException {
|
||||
Integer blockHeight = block.getBlockData().getHeight();
|
||||
List<AccountBalanceData> deltas = getAccountDeltasAtHeight(blockHeight);
|
||||
if (deltas == null) {
|
||||
throw new DataException(String.format("Unable to lookup invalid balance data for block height %d", blockHeight));
|
||||
}
|
||||
|
||||
block.repository.getAccountRepository().modifyAssetBalances(deltas);
|
||||
|
||||
LOGGER.info("Applied balance patch for block {}", blockHeight);
|
||||
}
|
||||
|
||||
public static void orphanFix(Block block) throws DataException {
|
||||
Integer blockHeight = block.getBlockData().getHeight();
|
||||
List<AccountBalanceData> deltas = getAccountDeltasAtHeight(blockHeight);
|
||||
if (deltas == null) {
|
||||
throw new DataException(String.format("Unable to lookup invalid balance data for block height %d", blockHeight));
|
||||
}
|
||||
|
||||
// Create inverse delta(s)
|
||||
for (AccountBalanceData accountBalanceData : deltas) {
|
||||
AccountBalanceData inverseBalanceData = new AccountBalanceData(accountBalanceData.getAddress(), accountBalanceData.getAssetId(), -accountBalanceData.getBalance());
|
||||
block.repository.getAccountRepository().modifyAssetBalances(List.of(inverseBalanceData));
|
||||
}
|
||||
|
||||
LOGGER.info("Reverted balance patch for block {}", blockHeight);
|
||||
}
|
||||
|
||||
}
|
@ -64,7 +64,6 @@ public class BlockMinter extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("BlockMinter");
|
||||
Thread.currentThread().setPriority(MAX_PRIORITY);
|
||||
|
||||
if (Settings.getInstance().isTopOnly() || Settings.getInstance().isLite()) {
|
||||
// Top only and lite nodes do not sign blocks
|
||||
@ -97,27 +96,21 @@ public class BlockMinter extends Thread {
|
||||
|
||||
final boolean isSingleNodeTestnet = Settings.getInstance().isSingleNodeTestnet();
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
// Going to need this a lot...
|
||||
BlockRepository blockRepository = repository.getBlockRepository();
|
||||
|
||||
// Flags for tracking change in whether minting is possible,
|
||||
// so we can notify Controller, and further update SysTray, etc.
|
||||
boolean isMintingPossible = false;
|
||||
boolean wasMintingPossible = isMintingPossible;
|
||||
try {
|
||||
while (running) {
|
||||
// recreate repository for new loop iteration
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
// Going to need this a lot...
|
||||
BlockRepository blockRepository = repository.getBlockRepository();
|
||||
|
||||
if (isMintingPossible != wasMintingPossible)
|
||||
Controller.getInstance().onMintingPossibleChange(isMintingPossible);
|
||||
|
||||
wasMintingPossible = isMintingPossible;
|
||||
|
||||
try {
|
||||
// reset the repository, to the repository recreated for this loop iteration
|
||||
for( Block newBlock : newBlocks ) newBlock.setRepository(repository);
|
||||
|
||||
// Free up any repository locks
|
||||
repository.discardChanges();
|
||||
|
||||
@ -154,7 +147,7 @@ public class BlockMinter extends Thread {
|
||||
}
|
||||
|
||||
Account mintingAccount = new Account(repository, rewardShareData.getMinter());
|
||||
if (!mintingAccount.canMint(true)) {
|
||||
if (!mintingAccount.canMint()) {
|
||||
// Minting-account component of reward-share can no longer mint - disregard
|
||||
madi.remove();
|
||||
continue;
|
||||
@ -389,7 +382,7 @@ public class BlockMinter extends Thread {
|
||||
// Add unconfirmed transactions
|
||||
addUnconfirmedTransactions(repository, newBlock);
|
||||
|
||||
LOGGER.info(String.format("Adding %d unconfirmed transactions took %d ms", newBlock.getTransactions().size(), (NTP.getTime() - unconfirmedStartTime)));
|
||||
LOGGER.info(String.format("Adding %d unconfirmed transactions took %d ms", newBlock.getTransactions().size(), (NTP.getTime()-unconfirmedStartTime)));
|
||||
|
||||
// Sign to create block's signature
|
||||
newBlock.sign();
|
||||
@ -458,14 +451,9 @@ public class BlockMinter extends Thread {
|
||||
// We've been interrupted - time to exit
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn("Repository issue while running block minter - NO LONGER MINTING", e);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,6 @@ import org.qortal.block.Block;
|
||||
import org.qortal.block.BlockChain;
|
||||
import org.qortal.block.BlockChain.BlockTimingByHeight;
|
||||
import org.qortal.controller.arbitrary.*;
|
||||
import org.qortal.controller.hsqldb.HSQLDBBalanceRecorder;
|
||||
import org.qortal.controller.hsqldb.HSQLDBDataCacheManager;
|
||||
import org.qortal.controller.repository.NamesDatabaseIntegrityCheck;
|
||||
import org.qortal.controller.repository.PruneManager;
|
||||
import org.qortal.controller.tradebot.TradeBot;
|
||||
@ -33,8 +31,8 @@ import org.qortal.globalization.Translator;
|
||||
import org.qortal.gui.Gui;
|
||||
import org.qortal.gui.SysTray;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.RNSNetwork;
|
||||
import org.qortal.network.Peer;
|
||||
import org.qortal.network.PeerAddress;
|
||||
import org.qortal.network.message.*;
|
||||
import org.qortal.repository.*;
|
||||
import org.qortal.repository.hsqldb.HSQLDBRepositoryFactory;
|
||||
@ -51,11 +49,8 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.Security;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
@ -73,8 +68,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Controller extends Thread {
|
||||
|
||||
public static HSQLDBRepositoryFactory REPOSITORY_FACTORY;
|
||||
|
||||
static {
|
||||
// This must go before any calls to LogManager/Logger
|
||||
System.setProperty("log4j2.formatMsgNoLookups", "true");
|
||||
@ -103,7 +96,7 @@ public class Controller extends Thread {
|
||||
private final long buildTimestamp; // seconds
|
||||
private final String[] savedArgs;
|
||||
|
||||
private ExecutorService callbackExecutor = Executors.newFixedThreadPool(4);
|
||||
private ExecutorService callbackExecutor = Executors.newFixedThreadPool(3);
|
||||
private volatile boolean notifyGroupMembershipChange = false;
|
||||
|
||||
/** Latest blocks on our chain. Note: tail/last is the latest block. */
|
||||
@ -123,6 +116,7 @@ public class Controller extends Thread {
|
||||
private long repositoryCheckpointTimestamp = startTime; // ms
|
||||
private long prunePeersTimestamp = startTime; // ms
|
||||
private long ntpCheckTimestamp = startTime; // ms
|
||||
private long pruneRNSPeersTimestamp = startTime; // ms
|
||||
private long deleteExpiredTimestamp = startTime + DELETE_EXPIRED_INTERVAL; // ms
|
||||
|
||||
/** Whether we can mint new blocks, as reported by BlockMinter. */
|
||||
@ -405,38 +399,14 @@ public class Controller extends Thread {
|
||||
|
||||
LOGGER.info("Starting repository");
|
||||
try {
|
||||
REPOSITORY_FACTORY = new HSQLDBRepositoryFactory(getRepositoryUrl());
|
||||
RepositoryManager.setRepositoryFactory(REPOSITORY_FACTORY);
|
||||
RepositoryFactory repositoryFactory = new HSQLDBRepositoryFactory(getRepositoryUrl());
|
||||
RepositoryManager.setRepositoryFactory(repositoryFactory);
|
||||
RepositoryManager.setRequestedCheckpoint(Boolean.TRUE);
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
// RepositoryManager.rebuildTransactionSequences(repository);
|
||||
RepositoryManager.rebuildTransactionSequences(repository);
|
||||
ArbitraryDataCacheManager.getInstance().buildArbitraryResourcesCache(repository, false);
|
||||
}
|
||||
|
||||
if( Settings.getInstance().isDbCacheEnabled() ) {
|
||||
LOGGER.info("Db Cache Starting ...");
|
||||
HSQLDBDataCacheManager hsqldbDataCacheManager = new HSQLDBDataCacheManager();
|
||||
hsqldbDataCacheManager.start();
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Db Cache Disabled");
|
||||
}
|
||||
|
||||
if( Settings.getInstance().isBalanceRecorderEnabled() ) {
|
||||
Optional<HSQLDBBalanceRecorder> recorder = HSQLDBBalanceRecorder.getInstance();
|
||||
|
||||
if( recorder.isPresent() ) {
|
||||
LOGGER.info("Balance Recorder Starting ...");
|
||||
recorder.get().start();
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Balance Recorder won't start.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Balance Recorder Disabled");
|
||||
}
|
||||
} catch (DataException e) {
|
||||
// If exception has no cause or message then repository is in use by some other process.
|
||||
if (e.getCause() == null && e.getMessage() == null) {
|
||||
@ -513,10 +483,20 @@ public class Controller extends Thread {
|
||||
return; // Not System.exit() so that GUI can display error
|
||||
}
|
||||
|
||||
LOGGER.info("Starting Reticulum");
|
||||
try {
|
||||
RNSNetwork rns = RNSNetwork.getInstance();
|
||||
rns.start();
|
||||
LOGGER.debug("Reticulum instance: {}", rns.toString());
|
||||
} catch (IOException | DataException e) {
|
||||
LOGGER.error("Unable to start Reticulum", e);
|
||||
}
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Shutdown hook");
|
||||
|
||||
Controller.getInstance().shutdown();
|
||||
}
|
||||
});
|
||||
@ -596,33 +576,10 @@ public class Controller extends Thread {
|
||||
// If GUI is enabled, we're no longer starting up but actually running now
|
||||
Gui.getInstance().notifyRunning();
|
||||
|
||||
if (Settings.getInstance().isAutoRestartEnabled()) {
|
||||
// Check every 10 minutes if we have enough connected peers
|
||||
Timer checkConnectedPeers = new Timer();
|
||||
|
||||
checkConnectedPeers.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Get the connected peers
|
||||
int myConnectedPeers = Network.getInstance().getImmutableHandshakedPeers().size();
|
||||
LOGGER.debug("Node have {} connected peers", myConnectedPeers);
|
||||
if (myConnectedPeers == 0) {
|
||||
// Restart node if we have 0 peers
|
||||
LOGGER.info("Node have no connected peers, restarting node");
|
||||
try {
|
||||
RestartNode.attemptToRestart();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Unable to restart the node", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 10*60*1000, 10*60*1000);
|
||||
}
|
||||
|
||||
// Check every 10 minutes to see if the block minter is running
|
||||
Timer checkBlockMinter = new Timer();
|
||||
Timer timer = new Timer();
|
||||
|
||||
checkBlockMinter.schedule(new TimerTask() {
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (blockMinter.isAlive()) {
|
||||
@ -646,71 +603,6 @@ public class Controller extends Thread {
|
||||
}
|
||||
}
|
||||
}, 10*60*1000, 10*60*1000);
|
||||
|
||||
// Check if we need sync from genesis and start syncing
|
||||
Timer syncFromGenesis = new Timer();
|
||||
syncFromGenesis.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
LOGGER.debug("Start sync from genesis check.");
|
||||
boolean canBootstrap = Settings.getInstance().getBootstrap();
|
||||
boolean needsArchiveRebuild = false;
|
||||
int checkHeight = 0;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()){
|
||||
needsArchiveRebuild = (repository.getBlockArchiveRepository().fromHeight(2) == null);
|
||||
checkHeight = repository.getBlockRepository().getBlockchainHeight();
|
||||
} catch (DataException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (canBootstrap || !needsArchiveRebuild || checkHeight > 3) {
|
||||
LOGGER.debug("Bootstrapping is enabled or we have more than 2 blocks, cancel sync from genesis check.");
|
||||
syncFromGenesis.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (needsArchiveRebuild && !canBootstrap) {
|
||||
LOGGER.info("Start syncing from genesis!");
|
||||
List<Peer> seeds = new ArrayList<>(Network.getInstance().getImmutableHandshakedPeers());
|
||||
|
||||
// Check if have a qualified peer to sync
|
||||
if (seeds.isEmpty()) {
|
||||
LOGGER.info("No connected peers, will try again later.");
|
||||
return;
|
||||
}
|
||||
|
||||
int index = new SecureRandom().nextInt(seeds.size());
|
||||
String syncNode = String.valueOf(seeds.get(index));
|
||||
PeerAddress peerAddress = PeerAddress.fromString(syncNode);
|
||||
InetSocketAddress resolvedAddress = null;
|
||||
|
||||
try {
|
||||
resolvedAddress = peerAddress.toSocketAddress();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
InetSocketAddress finalResolvedAddress = resolvedAddress;
|
||||
Peer targetPeer = seeds.stream().filter(peer -> peer.getResolvedAddress().equals(finalResolvedAddress)).findFirst().orElse(null);
|
||||
Synchronizer.SynchronizationResult syncResult;
|
||||
|
||||
try {
|
||||
do {
|
||||
try {
|
||||
syncResult = Synchronizer.getInstance().actuallySynchronize(targetPeer, true);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
while (syncResult == Synchronizer.SynchronizationResult.OK);
|
||||
} finally {
|
||||
// We are syncing now, so can cancel the check
|
||||
syncFromGenesis.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 3*60*1000, 3*60*1000);
|
||||
}
|
||||
|
||||
/** Called by AdvancedInstaller's launch EXE in single-instance mode, when an instance is already running. */
|
||||
@ -728,6 +620,8 @@ public class Controller extends Thread {
|
||||
final long repositoryCheckpointInterval = Settings.getInstance().getRepositoryCheckpointInterval();
|
||||
long repositoryMaintenanceInterval = getRandomRepositoryMaintenanceInterval();
|
||||
final long prunePeersInterval = 5 * 60 * 1000L; // Every 5 minutes
|
||||
//final long pruneRNSPeersInterval = 5 * 60 * 1000L; // Every 5 minutes
|
||||
final long pruneRNSPeersInterval = 1 * 60 * 1000L; // Every 1 minute (during development)
|
||||
|
||||
// Start executor service for trimming or pruning
|
||||
PruneManager.getInstance().start();
|
||||
@ -836,6 +730,18 @@ public class Controller extends Thread {
|
||||
}
|
||||
}
|
||||
|
||||
// Q: Do we need global pruning?
|
||||
if (now >= pruneRNSPeersTimestamp + pruneRNSPeersInterval) {
|
||||
pruneRNSPeersTimestamp = now + pruneRNSPeersInterval;
|
||||
|
||||
try {
|
||||
LOGGER.debug("Pruning Reticulum peers...");
|
||||
RNSNetwork.getInstance().prunePeers();
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(String.format("Repository issue when trying to prune Reticulum peers: %s", e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
// Delete expired transactions
|
||||
if (now >= deleteExpiredTimestamp) {
|
||||
deleteExpiredTimestamp = now + DELETE_EXPIRED_INTERVAL;
|
||||
@ -1134,6 +1040,9 @@ public class Controller extends Thread {
|
||||
LOGGER.info("Shutting down networking");
|
||||
Network.getInstance().shutdown();
|
||||
|
||||
LOGGER.info("Shutting down Reticulum");
|
||||
RNSNetwork.getInstance().shutdown();
|
||||
|
||||
LOGGER.info("Shutting down controller");
|
||||
this.interrupt();
|
||||
try {
|
||||
|
@ -13,7 +13,6 @@ import org.qortal.crypto.MemoryPoW;
|
||||
import org.qortal.crypto.Qortal25519Extras;
|
||||
import org.qortal.data.account.MintingAccountData;
|
||||
import org.qortal.data.account.RewardShareData;
|
||||
import org.qortal.data.group.GroupMemberData;
|
||||
import org.qortal.data.network.OnlineAccountData;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.Peer;
|
||||
@ -45,7 +44,6 @@ public class OnlineAccountsManager {
|
||||
*/
|
||||
private static final long ONLINE_TIMESTAMP_MODULUS_V1 = 5 * 60 * 1000L;
|
||||
private static final long ONLINE_TIMESTAMP_MODULUS_V2 = 30 * 60 * 1000L;
|
||||
private static final long ONLINE_TIMESTAMP_MODULUS_V3 = 10 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* How many 'current' timestamp-sets of online accounts we cache.
|
||||
@ -69,13 +67,12 @@ public class OnlineAccountsManager {
|
||||
private static final long ONLINE_ACCOUNTS_COMPUTE_INITIAL_SLEEP_INTERVAL = 30 * 1000L; // ms
|
||||
|
||||
// MemoryPoW - mainnet
|
||||
public static final int POW_BUFFER_SIZE = 1024 * 1024; // bytes
|
||||
public static final int POW_BUFFER_SIZE = 1 * 1024 * 1024; // bytes
|
||||
public static final int POW_DIFFICULTY_V1 = 18; // leading zero bits
|
||||
public static final int POW_DIFFICULTY_V2 = 19; // leading zero bits
|
||||
public static final int POW_DIFFICULTY_V3 = 6; // leading zero bits
|
||||
|
||||
// MemoryPoW - testnet
|
||||
public static final int POW_BUFFER_SIZE_TESTNET = 1024 * 1024; // bytes
|
||||
public static final int POW_BUFFER_SIZE_TESTNET = 1 * 1024 * 1024; // bytes
|
||||
public static final int POW_DIFFICULTY_TESTNET = 5; // leading zero bits
|
||||
|
||||
// IMPORTANT: if we ever need to dynamically modify the buffer size using a feature trigger, the
|
||||
@ -83,7 +80,7 @@ public class OnlineAccountsManager {
|
||||
// one for the transition period.
|
||||
private static long[] POW_VERIFY_WORK_BUFFER = new long[getPoWBufferSize() / 8];
|
||||
|
||||
private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(4, new NamedThreadFactory("OnlineAccounts", Thread.NORM_PRIORITY));
|
||||
private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(4, new NamedThreadFactory("OnlineAccounts"));
|
||||
private volatile boolean isStopping = false;
|
||||
|
||||
private final Set<OnlineAccountData> onlineAccountsImportQueue = ConcurrentHashMap.newKeySet();
|
||||
@ -109,15 +106,11 @@ public class OnlineAccountsManager {
|
||||
|
||||
public static long getOnlineTimestampModulus() {
|
||||
Long now = NTP.getTime();
|
||||
if (now != null && now >= BlockChain.getInstance().getOnlineAccountsModulusV2Timestamp() && now < BlockChain.getInstance().getOnlineAccountsModulusV3Timestamp()) {
|
||||
if (now != null && now >= BlockChain.getInstance().getOnlineAccountsModulusV2Timestamp()) {
|
||||
return ONLINE_TIMESTAMP_MODULUS_V2;
|
||||
}
|
||||
if (now != null && now >= BlockChain.getInstance().getOnlineAccountsModulusV3Timestamp()) {
|
||||
return ONLINE_TIMESTAMP_MODULUS_V3;
|
||||
}
|
||||
return ONLINE_TIMESTAMP_MODULUS_V1;
|
||||
}
|
||||
|
||||
public static Long getCurrentOnlineAccountTimestamp() {
|
||||
Long now = NTP.getTime();
|
||||
if (now == null)
|
||||
@ -142,12 +135,9 @@ public class OnlineAccountsManager {
|
||||
if (Settings.getInstance().isTestNet())
|
||||
return POW_DIFFICULTY_TESTNET;
|
||||
|
||||
if (timestamp >= BlockChain.getInstance().getIncreaseOnlineAccountsDifficultyTimestamp() && timestamp < BlockChain.getInstance().getDecreaseOnlineAccountsDifficultyTimestamp())
|
||||
if (timestamp >= BlockChain.getInstance().getIncreaseOnlineAccountsDifficultyTimestamp())
|
||||
return POW_DIFFICULTY_V2;
|
||||
|
||||
if (timestamp >= BlockChain.getInstance().getDecreaseOnlineAccountsDifficultyTimestamp())
|
||||
return POW_DIFFICULTY_V3;
|
||||
|
||||
return POW_DIFFICULTY_V1;
|
||||
}
|
||||
|
||||
@ -225,12 +215,6 @@ public class OnlineAccountsManager {
|
||||
Set<OnlineAccountData> onlineAccountsToAdd = new HashSet<>();
|
||||
Set<OnlineAccountData> onlineAccountsToRemove = new HashSet<>();
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
List<String> mintingGroupMemberAddresses
|
||||
= repository.getGroupRepository()
|
||||
.getGroupMembers(BlockChain.getInstance().getMintingGroupId()).stream()
|
||||
.map(GroupMemberData::getMember)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (OnlineAccountData onlineAccountData : this.onlineAccountsImportQueue) {
|
||||
if (isStopping)
|
||||
return;
|
||||
@ -243,7 +227,7 @@ public class OnlineAccountsManager {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isValid = this.isValidCurrentAccount(repository, mintingGroupMemberAddresses, onlineAccountData);
|
||||
boolean isValid = this.isValidCurrentAccount(repository, onlineAccountData);
|
||||
if (isValid)
|
||||
onlineAccountsToAdd.add(onlineAccountData);
|
||||
|
||||
@ -322,7 +306,7 @@ public class OnlineAccountsManager {
|
||||
return inplaceArray;
|
||||
}
|
||||
|
||||
private static boolean isValidCurrentAccount(Repository repository, List<String> mintingGroupMemberAddresses, OnlineAccountData onlineAccountData) throws DataException {
|
||||
private static boolean isValidCurrentAccount(Repository repository, OnlineAccountData onlineAccountData) throws DataException {
|
||||
final Long now = NTP.getTime();
|
||||
if (now == null)
|
||||
return false;
|
||||
@ -357,14 +341,9 @@ public class OnlineAccountsManager {
|
||||
LOGGER.trace(() -> String.format("Rejecting unknown online reward-share public key %s", Base58.encode(rewardSharePublicKey)));
|
||||
return false;
|
||||
}
|
||||
// reject account address that are not in the MINTER Group
|
||||
else if( !mintingGroupMemberAddresses.contains(rewardShareData.getMinter())) {
|
||||
LOGGER.trace(() -> String.format("Rejecting online reward-share that is not in MINTER Group, account %s", rewardShareData.getMinter()));
|
||||
return false;
|
||||
}
|
||||
|
||||
Account mintingAccount = new Account(repository, rewardShareData.getMinter());
|
||||
if (!mintingAccount.canMint(true)) { // group validation is a few lines above
|
||||
if (!mintingAccount.canMint()) {
|
||||
// Minting-account component of reward-share can no longer mint - disregard
|
||||
LOGGER.trace(() -> String.format("Rejecting online reward-share with non-minting account %s", mintingAccount.getAddress()));
|
||||
return false;
|
||||
@ -551,7 +530,7 @@ public class OnlineAccountsManager {
|
||||
}
|
||||
|
||||
Account mintingAccount = new Account(repository, rewardShareData.getMinter());
|
||||
if (!mintingAccount.canMint(true)) {
|
||||
if (!mintingAccount.canMint()) {
|
||||
// Minting-account component of reward-share can no longer mint - disregard
|
||||
iterator.remove();
|
||||
continue;
|
||||
|
@ -65,7 +65,6 @@ public class PirateChainWalletController extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Pirate Chain Wallet Controller");
|
||||
Thread.currentThread().setPriority(MIN_PRIORITY);
|
||||
|
||||
try {
|
||||
while (running && !Controller.isStopping()) {
|
||||
|
@ -118,12 +118,8 @@ public class Synchronizer extends Thread {
|
||||
}
|
||||
|
||||
public static Synchronizer getInstance() {
|
||||
if (instance == null) {
|
||||
if (instance == null)
|
||||
instance = new Synchronizer();
|
||||
instance.setPriority(Settings.getInstance().getSynchronizerThreadPriority());
|
||||
|
||||
LOGGER.info("thread priority = " + instance.getPriority());
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
@ -14,7 +14,6 @@ import java.io.IOException;
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
|
||||
import static java.lang.Thread.NORM_PRIORITY;
|
||||
import static org.qortal.data.arbitrary.ArbitraryResourceStatus.Status.NOT_PUBLISHED;
|
||||
|
||||
|
||||
@ -29,7 +28,6 @@ public class ArbitraryDataBuilderThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Builder Thread");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
ArbitraryDataBuildManager buildManager = ArbitraryDataBuildManager.getInstance();
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
|
@ -41,7 +41,6 @@ public class ArbitraryDataCacheManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Cache Manager");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
try {
|
||||
while (!Controller.isStopping()) {
|
||||
|
@ -71,7 +71,6 @@ public class ArbitraryDataCleanupManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Cleanup Manager");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
// Paginate queries when fetching arbitrary transactions
|
||||
final int limit = 100;
|
||||
|
@ -17,8 +17,6 @@ import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
|
||||
import static java.lang.Thread.NORM_PRIORITY;
|
||||
|
||||
public class ArbitraryDataFileRequestThread implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(ArbitraryDataFileRequestThread.class);
|
||||
@ -30,7 +28,6 @@ public class ArbitraryDataFileRequestThread implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data File Request Thread");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
try {
|
||||
while (!Controller.isStopping()) {
|
||||
|
@ -91,7 +91,6 @@ public class ArbitraryDataManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Manager");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
// Create data directory in case it doesn't exist yet
|
||||
this.createDataDirectory();
|
||||
|
@ -36,7 +36,6 @@ public class ArbitraryDataRenderManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Render Manager");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
try {
|
||||
while (!isStopping) {
|
||||
|
@ -72,8 +72,6 @@ public class ArbitraryDataStorageManager extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Arbitrary Data Storage Manager");
|
||||
Thread.currentThread().setPriority(NORM_PRIORITY);
|
||||
|
||||
try {
|
||||
while (!isStopping) {
|
||||
Thread.sleep(1000);
|
||||
|
@ -1,117 +0,0 @@
|
||||
package org.qortal.controller.hsqldb;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.data.account.AccountBalanceData;
|
||||
import org.qortal.repository.hsqldb.HSQLDBCacheUtils;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HSQLDBBalanceRecorder extends Thread{
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(HSQLDBBalanceRecorder.class);
|
||||
|
||||
private static HSQLDBBalanceRecorder SINGLETON = null;
|
||||
|
||||
private ConcurrentHashMap<Integer, List<AccountBalanceData>> balancesByHeight = new ConcurrentHashMap<>();
|
||||
|
||||
private ConcurrentHashMap<String, List<AccountBalanceData>> balancesByAddress = new ConcurrentHashMap<>();
|
||||
|
||||
private int priorityRequested;
|
||||
private int frequency;
|
||||
private int capacity;
|
||||
|
||||
private HSQLDBBalanceRecorder( int priorityRequested, int frequency, int capacity) {
|
||||
|
||||
super("Balance Recorder");
|
||||
|
||||
this.priorityRequested = priorityRequested;
|
||||
this.frequency = frequency;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public static Optional<HSQLDBBalanceRecorder> getInstance() {
|
||||
|
||||
if( SINGLETON == null ) {
|
||||
|
||||
SINGLETON
|
||||
= new HSQLDBBalanceRecorder(
|
||||
Settings.getInstance().getBalanceRecorderPriority(),
|
||||
Settings.getInstance().getBalanceRecorderFrequency(),
|
||||
Settings.getInstance().getBalanceRecorderCapacity()
|
||||
);
|
||||
|
||||
}
|
||||
else if( SINGLETON == null ) {
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
return Optional.of(SINGLETON);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Thread.currentThread().setName("Balance Recorder");
|
||||
|
||||
HSQLDBCacheUtils.startRecordingBalances(this.balancesByHeight, this.balancesByAddress, this.priorityRequested, this.frequency, this.capacity);
|
||||
}
|
||||
|
||||
public List<AccountBalanceData> getLatestRecordings(int limit, long offset) {
|
||||
ArrayList<AccountBalanceData> data;
|
||||
|
||||
Optional<Integer> lastHeight = getLastHeight();
|
||||
|
||||
if(lastHeight.isPresent() ) {
|
||||
List<AccountBalanceData> latest = this.balancesByHeight.get(lastHeight.get());
|
||||
|
||||
if( latest != null ) {
|
||||
data = new ArrayList<>(latest.size());
|
||||
data.addAll(
|
||||
latest.stream()
|
||||
.sorted(Comparator.comparingDouble(AccountBalanceData::getBalance).reversed())
|
||||
.skip(offset)
|
||||
.limit(limit)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
else {
|
||||
data = new ArrayList<>(0);
|
||||
}
|
||||
}
|
||||
else {
|
||||
data = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private Optional<Integer> getLastHeight() {
|
||||
return this.balancesByHeight.keySet().stream().sorted(Comparator.reverseOrder()).findFirst();
|
||||
}
|
||||
|
||||
public List<Integer> getBlocksRecorded() {
|
||||
|
||||
return this.balancesByHeight.keySet().stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<AccountBalanceData> getAccountBalanceRecordings(String address) {
|
||||
return this.balancesByAddress.get(address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "HSQLDBBalanceRecorder{" +
|
||||
"priorityRequested=" + priorityRequested +
|
||||
", frequency=" + frequency +
|
||||
", capacity=" + capacity +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package org.qortal.controller.hsqldb;
|
||||
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceCache;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.repository.hsqldb.HSQLDBCacheUtils;
|
||||
import org.qortal.repository.hsqldb.HSQLDBRepository;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
public class HSQLDBDataCacheManager extends Thread{
|
||||
|
||||
public HSQLDBDataCacheManager() {}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Thread.currentThread().setName("HSQLDB Data Cache Manager");
|
||||
|
||||
HSQLDBCacheUtils.startCaching(
|
||||
Settings.getInstance().getDbCacheThreadPriority(),
|
||||
Settings.getInstance().getDbCacheFrequency()
|
||||
);
|
||||
}
|
||||
}
|
@ -11,8 +11,6 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import static java.lang.Thread.MIN_PRIORITY;
|
||||
|
||||
public class AtStatesPruner implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(AtStatesPruner.class);
|
||||
@ -39,25 +37,15 @@ public class AtStatesPruner implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
int pruneStartHeight;
|
||||
int maxLatestAtStatesHeight;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
pruneStartHeight = repository.getATRepository().getAtPruneHeight();
|
||||
maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
||||
int pruneStartHeight = repository.getATRepository().getAtPruneHeight();
|
||||
int maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
||||
|
||||
repository.discardChanges();
|
||||
repository.getATRepository().rebuildLatestAtStates(maxLatestAtStatesHeight);
|
||||
repository.saveChanges();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("AT States Pruning is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
try {
|
||||
repository.discardChanges();
|
||||
|
||||
Thread.sleep(Settings.getInstance().getAtStatesPruneInterval());
|
||||
@ -87,7 +75,7 @@ public class AtStatesPruner implements Runnable {
|
||||
if (pruneStartHeight >= upperPruneHeight)
|
||||
continue;
|
||||
|
||||
LOGGER.info(String.format("Pruning AT states between blocks %d and %d...", pruneStartHeight, upperPruneHeight));
|
||||
LOGGER.debug(String.format("Pruning AT states between blocks %d and %d...", pruneStartHeight, upperPruneHeight));
|
||||
|
||||
int numAtStatesPruned = repository.getATRepository().pruneAtStates(pruneStartHeight, upperPruneHeight);
|
||||
repository.saveChanges();
|
||||
@ -97,7 +85,7 @@ public class AtStatesPruner implements Runnable {
|
||||
|
||||
if (numAtStatesPruned > 0 || numAtStateDataRowsTrimmed > 0) {
|
||||
final int finalPruneStartHeight = pruneStartHeight;
|
||||
LOGGER.info(() -> String.format("Pruned %d AT state%s between blocks %d and %d",
|
||||
LOGGER.debug(() -> String.format("Pruned %d AT state%s between blocks %d and %d",
|
||||
numAtStatesPruned, (numAtStatesPruned != 1 ? "s" : ""),
|
||||
finalPruneStartHeight, upperPruneHeight));
|
||||
} else {
|
||||
@ -110,26 +98,21 @@ public class AtStatesPruner implements Runnable {
|
||||
repository.saveChanges();
|
||||
|
||||
final int finalPruneStartHeight = pruneStartHeight;
|
||||
LOGGER.info(() -> String.format("Bumping AT state base prune height to %d", finalPruneStartHeight));
|
||||
} else {
|
||||
LOGGER.debug(() -> String.format("Bumping AT state base prune height to %d", finalPruneStartHeight));
|
||||
}
|
||||
else {
|
||||
// We've pruned up to the upper prunable height
|
||||
// Back off for a while to save CPU for syncing
|
||||
repository.discardChanges();
|
||||
Thread.sleep(5 * 60 * 1000L);
|
||||
Thread.sleep(5*60*1000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(String.format("Repository issue trying to prune AT states: %s", e.getMessage()));
|
||||
} catch (InterruptedException e) {
|
||||
if (Controller.isStopping()) {
|
||||
LOGGER.info("AT States Pruning Shutting Down");
|
||||
} else {
|
||||
LOGGER.warn("AT States Pruning interrupted. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("AT States Pruning stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch(Exception e){
|
||||
LOGGER.error("AT States Pruning is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
}
|
||||
// Time to exit
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import static java.lang.Thread.MIN_PRIORITY;
|
||||
|
||||
public class AtStatesTrimmer implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(AtStatesTrimmer.class);
|
||||
@ -26,24 +24,15 @@ public class AtStatesTrimmer implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
int trimStartHeight;
|
||||
int maxLatestAtStatesHeight;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
trimStartHeight = repository.getATRepository().getAtTrimHeight();
|
||||
maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
||||
int trimStartHeight = repository.getATRepository().getAtTrimHeight();
|
||||
int maxLatestAtStatesHeight = PruneManager.getMaxHeightForLatestAtStates(repository);
|
||||
|
||||
repository.discardChanges();
|
||||
repository.getATRepository().rebuildLatestAtStates(maxLatestAtStatesHeight);
|
||||
repository.saveChanges();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("AT States Trimming is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
try {
|
||||
repository.discardChanges();
|
||||
|
||||
Thread.sleep(Settings.getInstance().getAtStatesTrimInterval());
|
||||
@ -74,7 +63,7 @@ public class AtStatesTrimmer implements Runnable {
|
||||
|
||||
if (numAtStatesTrimmed > 0) {
|
||||
final int finalTrimStartHeight = trimStartHeight;
|
||||
LOGGER.info(() -> String.format("Trimmed %d AT state%s between blocks %d and %d",
|
||||
LOGGER.debug(() -> String.format("Trimmed %d AT state%s between blocks %d and %d",
|
||||
numAtStatesTrimmed, (numAtStatesTrimmed != 1 ? "s" : ""),
|
||||
finalTrimStartHeight, upperTrimHeight));
|
||||
} else {
|
||||
@ -87,22 +76,14 @@ public class AtStatesTrimmer implements Runnable {
|
||||
repository.saveChanges();
|
||||
|
||||
final int finalTrimStartHeight = trimStartHeight;
|
||||
LOGGER.info(() -> String.format("Bumping AT state base trim height to %d", finalTrimStartHeight));
|
||||
LOGGER.debug(() -> String.format("Bumping AT state base trim height to %d", finalTrimStartHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(String.format("Repository issue trying to trim AT states: %s", e.getMessage()));
|
||||
} catch (InterruptedException e) {
|
||||
if(Controller.isStopping()) {
|
||||
LOGGER.info("AT States Trimming Shutting Down");
|
||||
}
|
||||
else {
|
||||
LOGGER.warn("AT States Trimming interrupted. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("AT States Trimming stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("AT States Trimming is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
}
|
||||
// Time to exit
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,11 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static java.lang.Thread.NORM_PRIORITY;
|
||||
|
||||
public class BlockArchiver implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(BlockArchiver.class);
|
||||
|
||||
private static final long INITIAL_SLEEP_PERIOD = 15 * 60 * 1000L; // ms
|
||||
private static final long INITIAL_SLEEP_PERIOD = 5 * 60 * 1000L + 1234L; // ms
|
||||
|
||||
public void run() {
|
||||
Thread.currentThread().setName("Block archiver");
|
||||
@ -30,13 +28,11 @@ public class BlockArchiver implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
int startHeight;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
// Don't even start building until initial rush has ended
|
||||
Thread.sleep(INITIAL_SLEEP_PERIOD);
|
||||
|
||||
startHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight();
|
||||
int startHeight = repository.getBlockArchiveRepository().getBlockArchiveHeight();
|
||||
|
||||
// Don't attempt to archive if we have no ATStatesHeightIndex, as it will be too slow
|
||||
boolean hasAtStatesHeightIndex = repository.getATRepository().hasAtStatesHeightIndex();
|
||||
@ -45,17 +41,10 @@ public class BlockArchiver implements Runnable {
|
||||
repository.discardChanges();
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Block Archiving is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Starting block archiver from height {}...", startHeight);
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
try {
|
||||
repository.discardChanges();
|
||||
|
||||
Thread.sleep(Settings.getInstance().getArchiveInterval());
|
||||
@ -76,6 +65,7 @@ public class BlockArchiver implements Runnable {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Build cache of blocks
|
||||
try {
|
||||
final int maximumArchiveHeight = BlockArchiveWriter.getMaxArchiveHeight(repository);
|
||||
@ -98,7 +88,7 @@ public class BlockArchiver implements Runnable {
|
||||
// We didn't reach our file size target, so that must mean that we don't have enough blocks
|
||||
// yet or something went wrong. Sleep for a while and then try again.
|
||||
repository.discardChanges();
|
||||
Thread.sleep(2 * 60 * 60 * 1000L); // 1 hour
|
||||
Thread.sleep(60 * 60 * 1000L); // 1 hour
|
||||
break;
|
||||
|
||||
case BLOCK_NOT_FOUND:
|
||||
@ -107,25 +97,21 @@ public class BlockArchiver implements Runnable {
|
||||
LOGGER.info("Error: block not found when building archive. If this error persists, " +
|
||||
"a bootstrap or re-sync may be needed.");
|
||||
repository.discardChanges();
|
||||
Thread.sleep(60 * 1000L); // 1 minute
|
||||
Thread.sleep( 60 * 1000L); // 1 minute
|
||||
break;
|
||||
}
|
||||
|
||||
} catch (IOException | TransformationException e) {
|
||||
LOGGER.info("Caught exception when creating block cache", e);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.info("Caught exception when creating block cache", e);
|
||||
} catch (InterruptedException e) {
|
||||
if (Controller.isStopping()) {
|
||||
LOGGER.info("Block Archiving Shutting Down");
|
||||
} else {
|
||||
LOGGER.warn("Block Archiving interrupted. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Block Archiving stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch(Exception e){
|
||||
LOGGER.error("Block Archiving is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
}
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import static java.lang.Thread.NORM_PRIORITY;
|
||||
|
||||
public class BlockPruner implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(BlockPruner.class);
|
||||
@ -39,10 +37,8 @@ public class BlockPruner implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
int pruneStartHeight;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
pruneStartHeight = repository.getBlockRepository().getBlockPruneHeight();
|
||||
int pruneStartHeight = repository.getBlockRepository().getBlockPruneHeight();
|
||||
|
||||
// Don't attempt to prune if we have no ATStatesHeightIndex, as it will be too slow
|
||||
boolean hasAtStatesHeightIndex = repository.getATRepository().hasAtStatesHeightIndex();
|
||||
@ -50,16 +46,8 @@ public class BlockPruner implements Runnable {
|
||||
LOGGER.info("Unable to start block pruner due to missing ATStatesHeightIndex. Bootstrapping is recommended.");
|
||||
return;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Block Pruning is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
return;
|
||||
}
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
try {
|
||||
repository.discardChanges();
|
||||
|
||||
Thread.sleep(Settings.getInstance().getBlockPruneInterval());
|
||||
@ -95,20 +83,20 @@ public class BlockPruner implements Runnable {
|
||||
continue;
|
||||
}
|
||||
|
||||
LOGGER.info(String.format("Pruning blocks between %d and %d...", pruneStartHeight, upperPruneHeight));
|
||||
LOGGER.debug(String.format("Pruning blocks between %d and %d...", pruneStartHeight, upperPruneHeight));
|
||||
|
||||
int numBlocksPruned = repository.getBlockRepository().pruneBlocks(pruneStartHeight, upperPruneHeight);
|
||||
repository.saveChanges();
|
||||
|
||||
if (numBlocksPruned > 0) {
|
||||
LOGGER.info(String.format("Pruned %d block%s between %d and %d",
|
||||
LOGGER.debug(String.format("Pruned %d block%s between %d and %d",
|
||||
numBlocksPruned, (numBlocksPruned != 1 ? "s" : ""),
|
||||
pruneStartHeight, upperPruneHeight));
|
||||
} else {
|
||||
final int nextPruneHeight = upperPruneHeight + 1;
|
||||
repository.getBlockRepository().setBlockPruneHeight(nextPruneHeight);
|
||||
repository.saveChanges();
|
||||
LOGGER.info(String.format("Bumping block base prune height to %d", pruneStartHeight));
|
||||
LOGGER.debug(String.format("Bumping block base prune height to %d", pruneStartHeight));
|
||||
|
||||
// Can we move onto next batch?
|
||||
if (upperPrunableHeight > nextPruneHeight) {
|
||||
@ -121,19 +109,12 @@ public class BlockPruner implements Runnable {
|
||||
Thread.sleep(10*60*1000L);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(String.format("Repository issue trying to prune blocks: %s", e.getMessage()));
|
||||
} catch (InterruptedException e) {
|
||||
if(Controller.isStopping()) {
|
||||
LOGGER.info("Block Pruning Shutting Down");
|
||||
}
|
||||
else {
|
||||
LOGGER.warn("Block Pruning interrupted. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Block Pruning stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch(Exception e){
|
||||
LOGGER.error("Block Pruning is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
}
|
||||
// Time to exit
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,8 +12,6 @@ import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import static java.lang.Thread.NORM_PRIORITY;
|
||||
|
||||
public class OnlineAccountsSignaturesTrimmer implements Runnable {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(OnlineAccountsSignaturesTrimmer.class);
|
||||
@ -28,22 +26,13 @@ public class OnlineAccountsSignaturesTrimmer implements Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
int trimStartHeight;
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
// Don't even start trimming until initial rush has ended
|
||||
Thread.sleep(INITIAL_SLEEP_PERIOD);
|
||||
|
||||
trimStartHeight = repository.getBlockRepository().getOnlineAccountsSignaturesTrimHeight();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Online Accounts Signatures Trimming is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
return;
|
||||
}
|
||||
int trimStartHeight = repository.getBlockRepository().getOnlineAccountsSignaturesTrimHeight();
|
||||
|
||||
while (!Controller.isStopping()) {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
|
||||
try {
|
||||
repository.discardChanges();
|
||||
|
||||
Thread.sleep(Settings.getInstance().getOnlineSignaturesTrimInterval());
|
||||
@ -71,7 +60,7 @@ public class OnlineAccountsSignaturesTrimmer implements Runnable {
|
||||
|
||||
if (numSigsTrimmed > 0) {
|
||||
final int finalTrimStartHeight = trimStartHeight;
|
||||
LOGGER.info(() -> String.format("Trimmed %d online accounts signature%s between blocks %d and %d",
|
||||
LOGGER.debug(() -> String.format("Trimmed %d online accounts signature%s between blocks %d and %d",
|
||||
numSigsTrimmed, (numSigsTrimmed != 1 ? "s" : ""),
|
||||
finalTrimStartHeight, upperTrimHeight));
|
||||
} else {
|
||||
@ -83,22 +72,15 @@ public class OnlineAccountsSignaturesTrimmer implements Runnable {
|
||||
repository.saveChanges();
|
||||
|
||||
final int finalTrimStartHeight = trimStartHeight;
|
||||
LOGGER.info(() -> String.format("Bumping online accounts signatures base trim height to %d", finalTrimStartHeight));
|
||||
LOGGER.debug(() -> String.format("Bumping online accounts signatures base trim height to %d", finalTrimStartHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(String.format("Repository issue trying to trim online accounts signatures: %s", e.getMessage()));
|
||||
} catch (InterruptedException e) {
|
||||
if(Controller.isStopping()) {
|
||||
LOGGER.info("Online Accounts Signatures Trimming Shutting Down");
|
||||
}
|
||||
else {
|
||||
LOGGER.warn("Online Accounts Signatures Trimming interrupted. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.warn("Online Accounts Signatures Trimming stopped working. Trying again. Report this error immediately to the developers.", e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Online Accounts Signatures Trimming is not working! Not trying again. Restart ASAP. Report this error immediately to the developers.", e);
|
||||
}
|
||||
// Time to exit
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class PruneManager {
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.executorService = Executors.newCachedThreadPool(new DaemonThreadFactory(Settings.getInstance().getPruningThreadPriority()));
|
||||
this.executorService = Executors.newCachedThreadPool(new DaemonThreadFactory());
|
||||
|
||||
if (Settings.getInstance().isTopOnly()) {
|
||||
// Top-only-sync
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -528,7 +527,7 @@ public class BitcoinACCTv1TradeBot implements AcctTradeBot {
|
||||
// P2SH-A funding confirmed
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = BitcoinACCTv1.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -894,7 +893,7 @@ public class BitcoinACCTv1TradeBot implements AcctTradeBot {
|
||||
// Redeem P2SH-B using secret-B
|
||||
Coin redeemAmount = Coin.valueOf(P2SH_B_OUTPUT_AMOUNT); // An actual amount to avoid dust filter, remaining used as fees. The real funds are in P2SH-A.
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressB, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressB);
|
||||
byte[] receivingAccountInfo = tradeBotData.getReceivingAccountInfo();
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(bitcoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
@ -1064,7 +1063,7 @@ public class BitcoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount - P2SH_B_OUTPUT_AMOUNT);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(bitcoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -1136,7 +1135,7 @@ public class BitcoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(P2SH_B_OUTPUT_AMOUNT); // An actual amount to avoid dust filter, remaining used as fees.
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressB, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressB);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = bitcoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
@ -1202,7 +1201,7 @@ public class BitcoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount - P2SH_B_OUTPUT_AMOUNT);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = bitcoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,9 +7,7 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.at.ATData;
|
||||
@ -32,8 +30,12 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
* <p>
|
||||
@ -48,6 +50,45 @@ public class BitcoinACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(BitcoinACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -272,7 +313,7 @@ public class BitcoinACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = BitcoinACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -752,7 +793,7 @@ public class BitcoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(bitcoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -816,7 +857,7 @@ public class BitcoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = bitcoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = bitcoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -31,9 +30,11 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
@ -49,6 +50,45 @@ public class DigibyteACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DigibyteACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -273,7 +313,7 @@ public class DigibyteACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = DigibyteACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -753,7 +793,7 @@ public class DigibyteACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = digibyte.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = digibyte.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(digibyte.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -817,7 +857,7 @@ public class DigibyteACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = digibyte.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = digibyte.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = digibyte.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -314,7 +313,7 @@ public class DogecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = DogecoinACCTv1.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -794,7 +793,7 @@ public class DogecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(dogecoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -858,7 +857,7 @@ public class DogecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = dogecoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -31,9 +30,11 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
@ -49,6 +50,45 @@ public class DogecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DogecoinACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -273,7 +313,7 @@ public class DogecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = DogecoinACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -753,7 +793,7 @@ public class DogecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(dogecoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -817,7 +857,7 @@ public class DogecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = dogecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = dogecoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -313,7 +312,7 @@ public class LitecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = LitecoinACCTv1.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -757,7 +756,7 @@ public class LitecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(litecoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -821,7 +820,7 @@ public class LitecoinACCTv1TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = litecoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -31,9 +30,12 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
* <p>
|
||||
@ -48,6 +50,45 @@ public class LitecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(LitecoinACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -272,7 +313,7 @@ public class LitecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = LitecoinACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -752,7 +793,7 @@ public class LitecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(litecoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -816,7 +857,7 @@ public class LitecoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = litecoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = litecoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -9,7 +9,6 @@ import org.bitcoinj.core.Coin;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -33,9 +32,11 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
@ -51,6 +52,45 @@ public class PirateChainACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(PirateChainACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -277,7 +317,7 @@ public class PirateChainACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKey(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = PirateChainACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKey(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
|
@ -7,7 +7,6 @@ import org.bitcoinj.script.Script.ScriptType;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.account.PublicKeyAccount;
|
||||
import org.qortal.api.model.crosschain.TradeBotCreateRequest;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.crosschain.*;
|
||||
import org.qortal.crypto.Crypto;
|
||||
@ -31,9 +30,11 @@ import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
/**
|
||||
* Performing cross-chain trading steps on behalf of user.
|
||||
@ -49,6 +50,45 @@ public class RavencoinACCTv3TradeBot implements AcctTradeBot {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(RavencoinACCTv3TradeBot.class);
|
||||
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
|
||||
/** Maximum time Bob waits for his AT creation transaction to be confirmed into a block. (milliseconds) */
|
||||
private static final long MAX_AT_CONFIRMATION_PERIOD = 24 * 60 * 60 * 1000L; // ms
|
||||
|
||||
@ -273,7 +313,7 @@ public class RavencoinACCTv3TradeBot implements AcctTradeBot {
|
||||
}
|
||||
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
byte[] messageData = RavencoinACCTv3.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
@ -753,7 +793,7 @@ public class RavencoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED: {
|
||||
Coin redeemAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = ravencoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = ravencoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
Transaction p2shRedeemTransaction = BitcoinyHTLC.buildRedeemTransaction(ravencoin.getNetworkParameters(), redeemAmount, redeemKey,
|
||||
fundingOutputs, redeemScriptA, secretA, receivingAccountInfo);
|
||||
@ -817,7 +857,7 @@ public class RavencoinACCTv3TradeBot implements AcctTradeBot {
|
||||
case FUNDED:{
|
||||
Coin refundAmount = Coin.valueOf(crossChainTradeData.expectedForeignAmount);
|
||||
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
|
||||
List<TransactionOutput> fundingOutputs = ravencoin.getUnspentOutputs(p2shAddressA, false);
|
||||
List<TransactionOutput> fundingOutputs = ravencoin.getUnspentOutputs(p2shAddressA);
|
||||
|
||||
// Determine receive address for refund
|
||||
String receiveAddress = ravencoin.getUnusedReceiveAddress(tradeBotData.getForeignKey());
|
||||
|
@ -215,41 +215,6 @@ public class TradeBot implements Listener {
|
||||
return acctTradeBot.startResponse(repository, atData, acct, crossChainTradeData, foreignKey, receivingAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a trade-bot entries from the 'Alice' viewpoint,
|
||||
* i.e. matching foreign blockchain currency to existing QORT offers.
|
||||
* <p>
|
||||
* Requires chosen trade offers from Bob, passed by <tt>crossChainTradeData</tt>
|
||||
* and access to a foreign blockchain wallet via <tt>foreignKey</tt>.
|
||||
* <p>
|
||||
* @param repository
|
||||
* @param crossChainTradeDataList chosen trade OFFERs that Alice wants to match
|
||||
* @param receiveAddress Alice's Qortal address to receive her QORT
|
||||
* @param foreignKey foreign blockchain wallet key
|
||||
* @param bitcoiny
|
||||
* @throws DataException
|
||||
*/
|
||||
public ResponseResult startResponseMultiple(
|
||||
Repository repository,
|
||||
ACCT acct,
|
||||
List<CrossChainTradeData> crossChainTradeDataList,
|
||||
String receiveAddress,
|
||||
String foreignKey,
|
||||
Bitcoiny bitcoiny) throws DataException {
|
||||
AcctTradeBot acctTradeBot = findTradeBotForAcct(acct);
|
||||
if (acctTradeBot == null) {
|
||||
LOGGER.debug(() -> String.format("Couldn't find ACCT trade-bot for %s", acct.getBlockchain()));
|
||||
return ResponseResult.NETWORK_ISSUE;
|
||||
}
|
||||
|
||||
for( CrossChainTradeData tradeData : crossChainTradeDataList) {
|
||||
// Check Alice doesn't already have an existing, on-going trade-bot entry for this AT.
|
||||
if (repository.getCrossChainRepository().existsTradeWithAtExcludingStates(tradeData.qortalAtAddress, acctTradeBot.getEndStates()))
|
||||
return ResponseResult.TRADE_ALREADY_EXISTS;
|
||||
}
|
||||
return TradeBotUtils.startResponseMultiple(repository, acct, crossChainTradeDataList, receiveAddress, foreignKey, bitcoiny);
|
||||
}
|
||||
|
||||
public boolean deleteEntry(Repository repository, byte[] tradePrivateKey) throws DataException {
|
||||
TradeBotData tradeBotData = repository.getCrossChainRepository().getTradeBotData(tradePrivateKey);
|
||||
if (tradeBotData == null)
|
||||
|
@ -1,217 +0,0 @@
|
||||
package org.qortal.controller.tradebot;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.qortal.account.PrivateKeyAccount;
|
||||
import org.qortal.api.resource.CrossChainUtils;
|
||||
import org.qortal.crosschain.ACCT;
|
||||
import org.qortal.crosschain.Bitcoiny;
|
||||
import org.qortal.crosschain.BitcoinyHTLC;
|
||||
import org.qortal.crosschain.ForeignBlockchainException;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.data.crosschain.CrossChainTradeData;
|
||||
import org.qortal.data.crosschain.TradeBotData;
|
||||
import org.qortal.data.transaction.MessageTransactionData;
|
||||
import org.qortal.group.Group;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.transaction.MessageTransaction;
|
||||
import org.qortal.utils.Base58;
|
||||
import org.qortal.utils.NTP;
|
||||
import org.qortal.transaction.Transaction.ValidationResult;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.qortal.controller.tradebot.TradeStates.State;
|
||||
|
||||
public class TradeBotUtils {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(TradeBotUtils.class);
|
||||
/**
|
||||
* Creates trade-bot entries from the 'Alice' viewpoint, i.e. matching Bitcoiny coin to existing offers.
|
||||
* <p>
|
||||
* Requires chosen trade offers from Bob, passed by <tt>crossChainTradeData</tt>
|
||||
* and access to a Blockchain wallet via <tt>foreignKey</tt>.
|
||||
* <p>
|
||||
* The <tt>crossChainTradeData</tt> contains the current trade offers state
|
||||
* as extracted from the AT's data segment.
|
||||
* <p>
|
||||
* Access to a funded wallet is via a Blockchain BIP32 hierarchical deterministic key,
|
||||
* passed via <tt>foreignKey</tt>.
|
||||
* <b>This key will be stored in your node's database</b>
|
||||
* to allow trade-bot to create/fund the necessary P2SH transactions!
|
||||
* However, due to the nature of BIP32 keys, it is possible to give the trade-bot
|
||||
* only a subset of wallet access (see BIP32 for more details).
|
||||
* <p>
|
||||
* As an example, the foreignKey can be extract from a <i>legacy, password-less</i>
|
||||
* Electrum wallet by going to the console tab and entering:<br>
|
||||
* <tt>wallet.keystore.xprv</tt><br>
|
||||
* which should result in a base58 string starting with either 'xprv' (for Blockchain main-net)
|
||||
* or 'tprv' for (Blockchain test-net).
|
||||
* <p>
|
||||
* It is envisaged that the value in <tt>foreignKey</tt> will actually come from a Qortal-UI-managed wallet.
|
||||
* <p>
|
||||
* If sufficient funds are available, <b>this method will actually fund the P2SH-A</b>
|
||||
* with the Blockchain amount expected by 'Bob'.
|
||||
* <p>
|
||||
* If the Blockchain transaction is successfully broadcast to the network then
|
||||
* we also send a MESSAGE to Bob's trade-bot to let them know; one message for each trade.
|
||||
* <p>
|
||||
* The trade-bot entries are saved to the repository and the cross-chain trading process commences.
|
||||
* <p>
|
||||
*
|
||||
* @param repository for backing up the trade bot data
|
||||
* @param crossChainTradeDataList chosen trade OFFERs that Alice wants to match
|
||||
* @param receiveAddress Alice's Qortal address
|
||||
* @param foreignKey funded wallet xprv in base58
|
||||
* @param bitcoiny the bitcoiny chain to match the sell offer with
|
||||
* @return true if P2SH-A funding transaction successfully broadcast to Blockchain network, false otherwise
|
||||
* @throws DataException
|
||||
*/
|
||||
public static AcctTradeBot.ResponseResult startResponseMultiple(
|
||||
Repository repository,
|
||||
ACCT acct,
|
||||
List<CrossChainTradeData> crossChainTradeDataList,
|
||||
String receiveAddress,
|
||||
String foreignKey,
|
||||
Bitcoiny bitcoiny) throws DataException {
|
||||
|
||||
// Check we have enough funds via foreignKey to fund P2SH to cover expectedForeignAmount
|
||||
long now = NTP.getTime();
|
||||
long p2shFee;
|
||||
try {
|
||||
p2shFee = bitcoiny.getP2shFee(now);
|
||||
} catch (ForeignBlockchainException e) {
|
||||
LOGGER.debug("Couldn't estimate blockchain transaction fees?");
|
||||
return AcctTradeBot.ResponseResult.NETWORK_ISSUE;
|
||||
}
|
||||
|
||||
Map<String, Long> valueByP2shAddress = new HashMap<>(crossChainTradeDataList.size());
|
||||
|
||||
class DataCombiner{
|
||||
CrossChainTradeData crossChainTradeData;
|
||||
TradeBotData tradeBotData;
|
||||
String p2shAddress;
|
||||
|
||||
public DataCombiner(CrossChainTradeData crossChainTradeData, TradeBotData tradeBotData, String p2shAddress) {
|
||||
this.crossChainTradeData = crossChainTradeData;
|
||||
this.tradeBotData = tradeBotData;
|
||||
this.p2shAddress = p2shAddress;
|
||||
}
|
||||
}
|
||||
|
||||
List<DataCombiner> dataToProcess = new ArrayList<>();
|
||||
|
||||
for(CrossChainTradeData crossChainTradeData : crossChainTradeDataList) {
|
||||
byte[] tradePrivateKey = TradeBot.generateTradePrivateKey();
|
||||
byte[] secretA = TradeBot.generateSecret();
|
||||
byte[] hashOfSecretA = Crypto.hash160(secretA);
|
||||
|
||||
byte[] tradeNativePublicKey = TradeBot.deriveTradeNativePublicKey(tradePrivateKey);
|
||||
byte[] tradeNativePublicKeyHash = Crypto.hash160(tradeNativePublicKey);
|
||||
String tradeNativeAddress = Crypto.toAddress(tradeNativePublicKey);
|
||||
|
||||
byte[] tradeForeignPublicKey = TradeBot.deriveTradeForeignPublicKey(tradePrivateKey);
|
||||
byte[] tradeForeignPublicKeyHash = Crypto.hash160(tradeForeignPublicKey);
|
||||
// We need to generate lockTime-A: add tradeTimeout to now
|
||||
int lockTimeA = (crossChainTradeData.tradeTimeout * 60) + (int) (now / 1000L);
|
||||
byte[] receivingPublicKeyHash = Base58.decode(receiveAddress); // Actually the whole address, not just PKH
|
||||
|
||||
TradeBotData tradeBotData = new TradeBotData(tradePrivateKey, acct.getClass().getSimpleName(),
|
||||
State.ALICE_WAITING_FOR_AT_LOCK.name(), State.ALICE_WAITING_FOR_AT_LOCK.value,
|
||||
receiveAddress,
|
||||
crossChainTradeData.qortalAtAddress,
|
||||
now,
|
||||
crossChainTradeData.qortAmount,
|
||||
tradeNativePublicKey, tradeNativePublicKeyHash, tradeNativeAddress,
|
||||
secretA, hashOfSecretA,
|
||||
crossChainTradeData.foreignBlockchain,
|
||||
tradeForeignPublicKey, tradeForeignPublicKeyHash,
|
||||
crossChainTradeData.expectedForeignAmount,
|
||||
foreignKey, null, lockTimeA, receivingPublicKeyHash);
|
||||
|
||||
// Attempt to backup the trade bot data
|
||||
// Include tradeBotData as an additional parameter, since it's not in the repository yet
|
||||
TradeBot.backupTradeBotData(repository, Arrays.asList(tradeBotData));
|
||||
|
||||
// Fee for redeem/refund is subtracted from P2SH-A balance.
|
||||
// Do not include fee for funding transaction as this is covered by buildSpend()
|
||||
long amountA = crossChainTradeData.expectedForeignAmount + p2shFee /*redeeming/refunding P2SH-A*/;
|
||||
|
||||
// P2SH-A to be funded
|
||||
byte[] redeemScriptBytes = BitcoinyHTLC.buildScript(tradeForeignPublicKeyHash, lockTimeA, crossChainTradeData.creatorForeignPKH, hashOfSecretA);
|
||||
String p2shAddress = bitcoiny.deriveP2shAddress(redeemScriptBytes);
|
||||
|
||||
valueByP2shAddress.put(p2shAddress, amountA);
|
||||
|
||||
dataToProcess.add(new DataCombiner(crossChainTradeData, tradeBotData, p2shAddress));
|
||||
}
|
||||
|
||||
// Build transaction for funding P2SH-A
|
||||
Transaction p2shFundingTransaction = bitcoiny.buildSpendMultiple(foreignKey, valueByP2shAddress, null);
|
||||
if (p2shFundingTransaction == null) {
|
||||
LOGGER.debug("Unable to build P2SH-A funding transaction - lack of funds?");
|
||||
return AcctTradeBot.ResponseResult.BALANCE_ISSUE;
|
||||
}
|
||||
|
||||
try {
|
||||
bitcoiny.broadcastTransaction(p2shFundingTransaction);
|
||||
} catch (ForeignBlockchainException e) {
|
||||
// We couldn't fund P2SH-A at this time
|
||||
LOGGER.debug("Couldn't broadcast P2SH-A funding transaction?");
|
||||
return AcctTradeBot.ResponseResult.NETWORK_ISSUE;
|
||||
}
|
||||
|
||||
for(DataCombiner datumToProcess : dataToProcess ) {
|
||||
// Attempt to send MESSAGE to Bob's Qortal trade address
|
||||
TradeBotData tradeBotData = datumToProcess.tradeBotData;
|
||||
|
||||
byte[] messageData = CrossChainUtils.buildOfferMessage(tradeBotData.getTradeForeignPublicKeyHash(), tradeBotData.getHashOfSecret(), tradeBotData.getLockTimeA());
|
||||
CrossChainTradeData crossChainTradeData = datumToProcess.crossChainTradeData;
|
||||
String messageRecipient = crossChainTradeData.qortalCreatorTradeAddress;
|
||||
|
||||
boolean isMessageAlreadySent = repository.getMessageRepository().exists(tradeBotData.getTradeNativePublicKey(), messageRecipient, messageData);
|
||||
if (!isMessageAlreadySent) {
|
||||
// Do this in a new thread so caller doesn't have to wait for computeNonce()
|
||||
// In the unlikely event that the transaction doesn't validate then the buy won't happen and eventually Alice's AT will be refunded
|
||||
new Thread(() -> {
|
||||
try (final Repository threadsRepository = RepositoryManager.getRepository()) {
|
||||
PrivateKeyAccount sender = new PrivateKeyAccount(threadsRepository, tradeBotData.getTradePrivateKey());
|
||||
MessageTransaction messageTransaction = MessageTransaction.build(threadsRepository, sender, Group.NO_GROUP, messageRecipient, messageData, false, false);
|
||||
|
||||
LOGGER.info("Computing nonce at difficulty {} for AT {} and recipient {}", messageTransaction.getPoWDifficulty(), tradeBotData.getAtAddress(), messageRecipient);
|
||||
messageTransaction.computeNonce();
|
||||
MessageTransactionData newMessageTransactionData = (MessageTransactionData) messageTransaction.getTransactionData();
|
||||
LOGGER.info("Computed nonce {} at difficulty {}", newMessageTransactionData.getNonce(), messageTransaction.getPoWDifficulty());
|
||||
messageTransaction.sign(sender);
|
||||
|
||||
// reset repository state to prevent deadlock
|
||||
threadsRepository.discardChanges();
|
||||
|
||||
if (messageTransaction.isSignatureValid()) {
|
||||
ValidationResult result = messageTransaction.importAsUnconfirmed();
|
||||
|
||||
if (result != ValidationResult.OK) {
|
||||
LOGGER.warn(() -> String.format("Unable to send MESSAGE to Bob's trade-bot %s: %s", messageRecipient, result.name()));
|
||||
}
|
||||
} else {
|
||||
LOGGER.warn(() -> String.format("Unable to send MESSAGE to Bob's trade-bot %s: signature invalid", messageRecipient));
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.warn(() -> String.format("Unable to send MESSAGE to Bob's trade-bot %s: %s", messageRecipient, e.getMessage()));
|
||||
}
|
||||
}, "TradeBot response").start();
|
||||
}
|
||||
|
||||
TradeBot.updateTradeBotState(repository, tradeBotData, () -> String.format("Funding P2SH-A %s. Messaged Bob. Waiting for AT-lock", datumToProcess.p2shAddress));
|
||||
}
|
||||
|
||||
return AcctTradeBot.ResponseResult.OK;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package org.qortal.controller.tradebot;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
public class TradeStates {
|
||||
public enum State implements TradeBot.StateNameAndValueSupplier {
|
||||
BOB_WAITING_FOR_AT_CONFIRM(10, false, false),
|
||||
BOB_WAITING_FOR_MESSAGE(15, true, true),
|
||||
BOB_WAITING_FOR_AT_REDEEM(25, true, true),
|
||||
BOB_DONE(30, false, false),
|
||||
BOB_REFUNDED(35, false, false),
|
||||
|
||||
ALICE_WAITING_FOR_AT_LOCK(85, true, true),
|
||||
ALICE_DONE(95, false, false),
|
||||
ALICE_REFUNDING_A(105, true, true),
|
||||
ALICE_REFUNDED(110, false, false);
|
||||
|
||||
private static final Map<Integer, State> map = stream(State.values()).collect(toMap(state -> state.value, state -> state));
|
||||
|
||||
public final int value;
|
||||
public final boolean requiresAtData;
|
||||
public final boolean requiresTradeData;
|
||||
|
||||
State(int value, boolean requiresAtData, boolean requiresTradeData) {
|
||||
this.value = value;
|
||||
this.requiresAtData = requiresAtData;
|
||||
this.requiresTradeData = requiresTradeData;
|
||||
}
|
||||
|
||||
public static State valueOf(int value) {
|
||||
return map.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getState() {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStateValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
}
|
@ -802,6 +802,12 @@ public class BitcoinACCTv1 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -751,6 +751,12 @@ public class BitcoinACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -55,13 +55,6 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
|
||||
protected Coin feePerKb;
|
||||
|
||||
/**
|
||||
* Blockchain Cache
|
||||
*
|
||||
* To store blockchain data and reduce redundant RPCs to the ElectrumX servers
|
||||
*/
|
||||
private final BlockchainCache blockchainCache = new BlockchainCache();
|
||||
|
||||
// Constructors and instance
|
||||
|
||||
protected Bitcoiny(BitcoinyBlockchainProvider blockchainProvider, Context bitcoinjContext, String currencyCode, Coin feePerKb) {
|
||||
@ -215,8 +208,8 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
* @throws ForeignBlockchainException if there was an error.
|
||||
*/
|
||||
// TODO: don't return bitcoinj-based objects like TransactionOutput, use BitcoinyTransaction.Output instead
|
||||
public List<TransactionOutput> getUnspentOutputs(String base58Address, boolean includeUnconfirmed) throws ForeignBlockchainException {
|
||||
List<UnspentOutput> unspentOutputs = this.blockchainProvider.getUnspentOutputs(addressToScriptPubKey(base58Address), includeUnconfirmed);
|
||||
public List<TransactionOutput> getUnspentOutputs(String base58Address) throws ForeignBlockchainException {
|
||||
List<UnspentOutput> unspentOutputs = this.blockchainProvider.getUnspentOutputs(addressToScriptPubKey(base58Address), false);
|
||||
|
||||
List<TransactionOutput> unspentTransactionOutputs = new ArrayList<>();
|
||||
for (UnspentOutput unspentOutput : unspentOutputs) {
|
||||
@ -350,45 +343,6 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns bitcoinj transaction sending the recipient's amount to each recipient given.
|
||||
*
|
||||
*
|
||||
* @param xprv58 the private master key
|
||||
* @param amountByRecipient each amount to send indexed by the recipient to send to
|
||||
* @param feePerByte the satoshis per byte
|
||||
*
|
||||
* @return the completed transaction, ready to broadcast
|
||||
*/
|
||||
public Transaction buildSpendMultiple(String xprv58, Map<String, Long> amountByRecipient, Long feePerByte) {
|
||||
Context.propagate(bitcoinjContext);
|
||||
|
||||
Wallet wallet = Wallet.fromSpendingKeyB58(this.params, xprv58, DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS);
|
||||
wallet.setUTXOProvider(new WalletAwareUTXOProvider(this, wallet));
|
||||
|
||||
Transaction transaction = new Transaction(this.params);
|
||||
|
||||
for(Map.Entry<String, Long> amountForRecipient : amountByRecipient.entrySet()) {
|
||||
Address destination = Address.fromString(this.params, amountForRecipient.getKey());
|
||||
transaction.addOutput(Coin.valueOf(amountForRecipient.getValue()), destination);
|
||||
}
|
||||
|
||||
SendRequest sendRequest = SendRequest.forTx(transaction);
|
||||
|
||||
if (feePerByte != null)
|
||||
sendRequest.feePerKb = Coin.valueOf(feePerByte * 1000L); // Note: 1000 not 1024
|
||||
else
|
||||
// Allow override of default for TestNet3, etc.
|
||||
sendRequest.feePerKb = this.getFeePerKb();
|
||||
|
||||
try {
|
||||
wallet.completeTx(sendRequest);
|
||||
return sendRequest.tx;
|
||||
} catch (InsufficientMoneyException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Spending Candidate Addresses
|
||||
*
|
||||
@ -437,7 +391,7 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
List<TransactionOutput> allUnspentOutputs = new ArrayList<>();
|
||||
Set<String> walletAddresses = this.getWalletAddresses(key58);
|
||||
for (String address : walletAddresses) {
|
||||
allUnspentOutputs.addAll(this.getUnspentOutputs(address, true));
|
||||
allUnspentOutputs.addAll(this.getUnspentOutputs(address));
|
||||
}
|
||||
for (TransactionOutput output : allUnspentOutputs) {
|
||||
if (!output.isAvailableForSpending()) {
|
||||
@ -511,27 +465,13 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
byte[] script = ScriptBuilder.createOutputScript(address).getProgram();
|
||||
|
||||
// Ask for transaction history - if it's empty then key has never been used
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, true);
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, false);
|
||||
|
||||
if (!historicTransactionHashes.isEmpty()) {
|
||||
areAllKeysUnused = false;
|
||||
|
||||
for (TransactionHash transactionHash : historicTransactionHashes) {
|
||||
|
||||
Optional<BitcoinyTransaction> walletTransaction
|
||||
= this.blockchainCache.getTransactionByHash( transactionHash.txHash );
|
||||
|
||||
// if the wallet transaction is already cached
|
||||
if(walletTransaction.isPresent() ) {
|
||||
walletTransactions.add( walletTransaction.get() );
|
||||
}
|
||||
// otherwise get the transaction from the blockchain server
|
||||
else {
|
||||
BitcoinyTransaction transaction = getTransaction(transactionHash.txHash);
|
||||
walletTransactions.add( transaction );
|
||||
this.blockchainCache.addTransactionByHash(transactionHash.txHash, transaction);
|
||||
}
|
||||
}
|
||||
for (TransactionHash transactionHash : historicTransactionHashes)
|
||||
walletTransactions.add(this.getTransaction(transactionHash.txHash));
|
||||
}
|
||||
}
|
||||
|
||||
@ -623,24 +563,16 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
for (; ki < keys.size(); ++ki) {
|
||||
DeterministicKey dKey = keys.get(ki);
|
||||
|
||||
// Check for transactions
|
||||
Address address = Address.fromKey(this.params, dKey, ScriptType.P2PKH);
|
||||
keySet.add(address.toString());
|
||||
|
||||
// if the key already has a verified transaction history
|
||||
if( this.blockchainCache.keyHasHistory( dKey ) ){
|
||||
areAllKeysUnused = false;
|
||||
}
|
||||
else {
|
||||
// Check for transactions
|
||||
byte[] script = ScriptBuilder.createOutputScript(address).getProgram();
|
||||
|
||||
// Ask for transaction history - if it's empty then key has never been used
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, true);
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, false);
|
||||
|
||||
if (!historicTransactionHashes.isEmpty()) {
|
||||
areAllKeysUnused = false;
|
||||
this.blockchainCache.addKeyWithHistory(dKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -696,25 +628,18 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
do {
|
||||
boolean areAllKeysUnused = true;
|
||||
|
||||
for (; areAllKeysUnused && ki < keys.size(); ++ki) {
|
||||
for (; ki < keys.size(); ++ki) {
|
||||
DeterministicKey dKey = keys.get(ki);
|
||||
|
||||
// if the key already has a verified transaction history
|
||||
if( this.blockchainCache.keyHasHistory(dKey)) {
|
||||
areAllKeysUnused = false;
|
||||
}
|
||||
else {
|
||||
// Check for transactions
|
||||
Address address = Address.fromKey(this.params, dKey, ScriptType.P2PKH);
|
||||
byte[] script = ScriptBuilder.createOutputScript(address).getProgram();
|
||||
|
||||
// Ask for transaction history - if it's empty then key has never been used
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, true);
|
||||
List<TransactionHash> historicTransactionHashes = this.getAddressTransactions(script, false);
|
||||
|
||||
if (!historicTransactionHashes.isEmpty()) {
|
||||
areAllKeysUnused = false;
|
||||
this.blockchainCache.addKeyWithHistory(dKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -878,7 +803,7 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
|
||||
List<UnspentOutput> unspentOutputs;
|
||||
try {
|
||||
unspentOutputs = this.bitcoiny.blockchainProvider.getUnspentOutputs(script, true);
|
||||
unspentOutputs = this.bitcoiny.blockchainProvider.getUnspentOutputs(script, false);
|
||||
} catch (ForeignBlockchainException e) {
|
||||
throw new UTXOProviderException(String.format("Unable to fetch unspent outputs for %s", address));
|
||||
}
|
||||
@ -968,7 +893,7 @@ public abstract class Bitcoiny implements ForeignBlockchain {
|
||||
}
|
||||
|
||||
private Long summingUnspentOutputs(String walletAddress) throws ForeignBlockchainException {
|
||||
return this.getUnspentOutputs(walletAddress, true).stream()
|
||||
return this.getUnspentOutputs(walletAddress).stream()
|
||||
.map(TransactionOutput::getValue)
|
||||
.mapToLong(Coin::longValue)
|
||||
.sum();
|
||||
|
@ -1,151 +0,0 @@
|
||||
package org.qortal.crosschain;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.core.Context;
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
import org.qortal.api.model.crosschain.BitcoinyTBDRequest;
|
||||
import org.qortal.crosschain.ChainableServer.ConnectionType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BitcoinyTBD extends Bitcoiny {
|
||||
|
||||
private static HashMap<String, BitcoinyTBDRequest> requestsById = new HashMap<>();
|
||||
|
||||
private long minimumOrderAmount;
|
||||
|
||||
private static Map<String, BitcoinyTBD> instanceByCode = new HashMap<>();
|
||||
|
||||
private final NetTBD netTBD;
|
||||
|
||||
/**
|
||||
* Default ElectrumX Ports
|
||||
*
|
||||
* These are the defualts for all Bitcoin forks.
|
||||
*/
|
||||
private static final Map<ConnectionType, Integer> DEFAULT_ELECTRUMX_PORTS = new EnumMap<>(ConnectionType.class);
|
||||
static {
|
||||
DEFAULT_ELECTRUMX_PORTS.put(ConnectionType.TCP, 50001);
|
||||
DEFAULT_ELECTRUMX_PORTS.put(ConnectionType.SSL, 50002);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param netTBD network access to the blockchain provider
|
||||
* @param blockchain blockchain provider
|
||||
* @param bitcoinjContext
|
||||
* @param currencyCode the trading symbol, ie LTC
|
||||
* @param minimumOrderAmount web search, LTC minimumOrderAmount = 1000000, 0.01 LTC minimum order to avoid dust errors
|
||||
* @param feePerKb web search, LTC feePerKb = 10000, 0.0001 LTC per 1000 bytes
|
||||
*/
|
||||
private BitcoinyTBD(
|
||||
NetTBD netTBD,
|
||||
BitcoinyBlockchainProvider blockchain,
|
||||
Context bitcoinjContext,
|
||||
String currencyCode,
|
||||
long minimumOrderAmount,
|
||||
long feePerKb) {
|
||||
|
||||
super(blockchain, bitcoinjContext, currencyCode, Coin.valueOf( feePerKb));
|
||||
|
||||
this.netTBD = netTBD;
|
||||
this.minimumOrderAmount = minimumOrderAmount;
|
||||
|
||||
LOGGER.info(() -> String.format("Starting BitcoinyTBD support using %s", this.netTBD.getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Instance
|
||||
*
|
||||
* @param currencyCode the trading symbol, ie LTC
|
||||
*
|
||||
* @return the instance
|
||||
*/
|
||||
public static synchronized Optional<BitcoinyTBD> getInstance(String currencyCode) {
|
||||
|
||||
return Optional.ofNullable(instanceByCode.get(currencyCode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Instance
|
||||
*
|
||||
* @param bitcoinyTBDRequest
|
||||
* @param networkParams
|
||||
* @return the instance
|
||||
*/
|
||||
public static synchronized BitcoinyTBD buildInstance(
|
||||
BitcoinyTBDRequest bitcoinyTBDRequest,
|
||||
NetworkParameters networkParams
|
||||
) {
|
||||
|
||||
NetTBD netTBD
|
||||
= new NetTBD(
|
||||
bitcoinyTBDRequest.getNetworkName(),
|
||||
bitcoinyTBDRequest.getFeeCeiling(),
|
||||
networkParams,
|
||||
Collections.emptyList(),
|
||||
bitcoinyTBDRequest.getExpectedGenesisHash()
|
||||
);
|
||||
|
||||
BitcoinyBlockchainProvider electrumX = new ElectrumX(netTBD.getName(), netTBD.getGenesisHash(), netTBD.getServers(), DEFAULT_ELECTRUMX_PORTS);
|
||||
Context bitcoinjContext = new Context(netTBD.getParams());
|
||||
|
||||
BitcoinyTBD instance
|
||||
= new BitcoinyTBD(
|
||||
netTBD,
|
||||
electrumX,
|
||||
bitcoinjContext,
|
||||
bitcoinyTBDRequest.getCurrencyCode(),
|
||||
bitcoinyTBDRequest.getMinimumOrderAmount(),
|
||||
bitcoinyTBDRequest.getFeePerKb());
|
||||
electrumX.setBlockchain(instance);
|
||||
|
||||
instanceByCode.put(bitcoinyTBDRequest.getCurrencyCode(), instance);
|
||||
requestsById.put(bitcoinyTBDRequest.getId(), bitcoinyTBDRequest);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static List<BitcoinyTBDRequest> getRequests() {
|
||||
|
||||
Collection<BitcoinyTBDRequest> requests = requestsById.values();
|
||||
|
||||
List<BitcoinyTBDRequest> list = new ArrayList<>( requests.size() );
|
||||
|
||||
list.addAll( requests );
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMinimumOrderAmount() {
|
||||
|
||||
return minimumOrderAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getP2shFee(Long timestamp) throws ForeignBlockchainException {
|
||||
|
||||
return this.netTBD.getFeeCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFeeCeiling() {
|
||||
|
||||
return this.netTBD.getFeeCeiling();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFeeCeiling(long fee) {
|
||||
|
||||
this.netTBD.setFeeCeiling( fee );
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ public class BitcoinyUTXOProvider implements UTXOProvider {
|
||||
byte[] script = ScriptBuilder.createOutputScript(address).getProgram();
|
||||
|
||||
// collection UTXO's for all confirmed unspent outputs
|
||||
for (UnspentOutput output : this.bitcoiny.blockchainProvider.getUnspentOutputs(script, true)) {
|
||||
for (UnspentOutput output : this.bitcoiny.blockchainProvider.getUnspentOutputs(script, false)) {
|
||||
utxos.add(toUTXO(output));
|
||||
}
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
package org.qortal.crosschain;
|
||||
|
||||
import org.bitcoinj.crypto.DeterministicKey;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||
|
||||
/**
|
||||
* Class BlockchainCache
|
||||
*
|
||||
* Cache blockchain information to reduce redundant RPCs to the ElectrumX servers.
|
||||
*/
|
||||
public class BlockchainCache {
|
||||
|
||||
/**
|
||||
* Keys With History
|
||||
*
|
||||
* Deterministic Keys with any transaction history.
|
||||
*/
|
||||
private Queue<DeterministicKey> keysWithHistory = new ConcurrentLinkedDeque<>();
|
||||
|
||||
/**
|
||||
* Transactions By Hash
|
||||
*
|
||||
* Transaction Hash -> Transaction
|
||||
*/
|
||||
private ConcurrentHashMap<String, BitcoinyTransaction> transactionByHash = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Cache Limit
|
||||
*
|
||||
* If this limit is reached, the cache will be cleared or reduced.
|
||||
*/
|
||||
private static final int CACHE_LIMIT = Settings.getInstance().getBlockchainCacheLimit();
|
||||
|
||||
/**
|
||||
* Add Key With History
|
||||
*
|
||||
* @param key a deterministic key with a verified history
|
||||
*/
|
||||
public void addKeyWithHistory(DeterministicKey key) {
|
||||
|
||||
if( this.keysWithHistory.size() > CACHE_LIMIT ) {
|
||||
this.keysWithHistory.remove();
|
||||
}
|
||||
|
||||
this.keysWithHistory.add(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Key Has History?
|
||||
*
|
||||
* @param key the deterministic key
|
||||
*
|
||||
* @return true if the key has a history, otherwise false
|
||||
*/
|
||||
public boolean keyHasHistory( DeterministicKey key ) {
|
||||
return this.keysWithHistory.contains(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add Transaction By Hash
|
||||
*
|
||||
* @param hash the transaction hash
|
||||
* @param transaction the transaction
|
||||
*/
|
||||
public void addTransactionByHash( String hash, BitcoinyTransaction transaction ) {
|
||||
|
||||
if( this.transactionByHash.size() > CACHE_LIMIT ) {
|
||||
this.transactionByHash.clear();
|
||||
}
|
||||
|
||||
this.transactionByHash.put(hash, transaction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Transaction By Hash
|
||||
*
|
||||
* @param hash the transaction hash
|
||||
*
|
||||
* @return the transaction, empty if the hash is not in the cache
|
||||
*/
|
||||
public Optional<BitcoinyTransaction> getTransactionByHash( String hash ) {
|
||||
return Optional.ofNullable( this.transactionByHash.get(hash) );
|
||||
}
|
||||
}
|
@ -1,387 +0,0 @@
|
||||
package org.qortal.crosschain;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.bitcoinj.core.*;
|
||||
import org.bitcoinj.store.BlockStore;
|
||||
import org.bitcoinj.store.BlockStoreException;
|
||||
import org.bitcoinj.utils.MonetaryFormat;
|
||||
import org.bouncycastle.util.encoders.Hex;
|
||||
import org.libdohj.core.AltcoinNetworkParameters;
|
||||
import org.libdohj.core.AltcoinSerializer;
|
||||
import org.qortal.api.model.crosschain.BitcoinyTBDRequest;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import java.math.BigInteger;
|
||||
|
||||
import static org.bitcoinj.core.Coin.COIN;
|
||||
|
||||
/**
|
||||
* Common parameters Bitcoin fork networks.
|
||||
*/
|
||||
public class DeterminedNetworkParams extends NetworkParameters implements AltcoinNetworkParameters {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(DeterminedNetworkParams.class);
|
||||
|
||||
public static final long MAX_TARGET_COMPACT_BITS = 0x1e0fffffL;
|
||||
/**
|
||||
* Standard format for the LITE denomination.
|
||||
*/
|
||||
private MonetaryFormat fullUnit;
|
||||
|
||||
/**
|
||||
* Standard format for the mLITE denomination.
|
||||
* */
|
||||
private MonetaryFormat mUnit;
|
||||
|
||||
/**
|
||||
* Base Unit
|
||||
*
|
||||
* The equivalent for Satoshi for Bitcoin
|
||||
*/
|
||||
private MonetaryFormat baseUnit;
|
||||
|
||||
/**
|
||||
* The maximum money to be generated
|
||||
*/
|
||||
public final Coin maxMoney;
|
||||
|
||||
/**
|
||||
* Currency code for full unit.
|
||||
* */
|
||||
private String code = "LITE";
|
||||
|
||||
/**
|
||||
* Currency code for milli Unit.
|
||||
* */
|
||||
private String mCode = "mLITE";
|
||||
|
||||
/**
|
||||
* Currency code for base unit.
|
||||
* */
|
||||
private String baseCode = "Liteoshi";
|
||||
|
||||
|
||||
private int protocolVersionMinimum;
|
||||
private int protocolVersionCurrent;
|
||||
|
||||
private static final Coin BASE_SUBSIDY = COIN.multiply(50);
|
||||
|
||||
protected Logger log = LoggerFactory.getLogger(DeterminedNetworkParams.class);
|
||||
|
||||
private int minNonDustOutput;
|
||||
|
||||
private String uriScheme;
|
||||
|
||||
private boolean hasMaxMoney;
|
||||
|
||||
public DeterminedNetworkParams( BitcoinyTBDRequest request ) throws DataException {
|
||||
super();
|
||||
|
||||
if( request.getTargetTimespan() > 0 && request.getTargetSpacing() > 0 )
|
||||
this.interval = request.getTargetTimespan() / request.getTargetSpacing();
|
||||
|
||||
this.targetTimespan = request.getTargetTimespan();
|
||||
|
||||
// this compact value is used for every Bitcoin fork for no documented reason
|
||||
this.maxTarget = Utils.decodeCompactBits(MAX_TARGET_COMPACT_BITS);
|
||||
|
||||
this.packetMagic = request.getPacketMagic();
|
||||
|
||||
this.id = request.getId();
|
||||
this.port = request.getPort();
|
||||
this.addressHeader = request.getAddressHeader();
|
||||
this.p2shHeader = request.getP2shHeader();
|
||||
this.segwitAddressHrp = request.getSegwitAddressHrp();
|
||||
|
||||
this.dumpedPrivateKeyHeader = request.getDumpedPrivateKeyHeader();
|
||||
|
||||
LOGGER.info( "Creating Genesis Block ...");
|
||||
|
||||
//this.genesisBlock = CoinParamsUtil.createGenesisBlockFromRequest(this, request);
|
||||
|
||||
LOGGER.info("Created Genesis Block: genesisBlock = " + genesisBlock );
|
||||
|
||||
// this is 100 for each coin from what I can tell
|
||||
this.spendableCoinbaseDepth = 100;
|
||||
|
||||
this.subsidyDecreaseBlockCount = request.getSubsidyDecreaseBlockCount();
|
||||
|
||||
// String genesisHash = genesisBlock.getHashAsString();
|
||||
//
|
||||
// LOGGER.info("genesisHash = " + genesisHash);
|
||||
//
|
||||
// LOGGER.info("request = " + request);
|
||||
//
|
||||
// checkState(genesisHash.equals(request.getExpectedGenesisHash()));
|
||||
this.alertSigningKey = Hex.decode(request.getPubKey());
|
||||
|
||||
this.majorityEnforceBlockUpgrade = request.getMajorityEnforceBlockUpgrade();
|
||||
this.majorityRejectBlockOutdated = request.getMajorityRejectBlockOutdated();
|
||||
this.majorityWindow = request.getMajorityWindow();
|
||||
|
||||
this.dnsSeeds = request.getDnsSeeds();
|
||||
|
||||
this.bip32HeaderP2PKHpub = request.getBip32HeaderP2PKHpub();
|
||||
this.bip32HeaderP2PKHpriv = request.getBip32HeaderP2PKHpriv();
|
||||
|
||||
this.code = request.getCode();
|
||||
this.mCode = request.getmCode();
|
||||
this.baseCode = request.getBaseCode();
|
||||
|
||||
this.fullUnit = MonetaryFormat.BTC.noCode()
|
||||
.code(0, this.code)
|
||||
.code(3, this.mCode)
|
||||
.code(7, this.baseCode);
|
||||
this.mUnit = fullUnit.shift(3).minDecimals(2).optionalDecimals(2);
|
||||
this.baseUnit = fullUnit.shift(7).minDecimals(0).optionalDecimals(2);
|
||||
|
||||
this.protocolVersionMinimum = request.getProtocolVersionMinimum();
|
||||
this.protocolVersionCurrent = request.getProtocolVersionCurrent();
|
||||
|
||||
this.minNonDustOutput = request.getMinNonDustOutput();
|
||||
|
||||
this.uriScheme = request.getUriScheme();
|
||||
|
||||
this.hasMaxMoney = request.isHasMaxMoney();
|
||||
|
||||
this.maxMoney = COIN.multiply(request.getMaxMoney());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coin getBlockSubsidy(final int height) {
|
||||
// return BASE_SUBSIDY.shiftRight(height / getSubsidyDecreaseBlockCount());
|
||||
// return something concerning Digishield for Dogecoin
|
||||
// return something different for Digibyte validation.cpp::GetBlockSubsidy
|
||||
// we may not need to support this
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hash to use for a block.
|
||||
*/
|
||||
@Override
|
||||
public Sha256Hash getBlockDifficultyHash(Block block) {
|
||||
|
||||
return ((AltcoinBlock) block).getScryptHash();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTestNet() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public MonetaryFormat getMonetaryFormat() {
|
||||
|
||||
return this.fullUnit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coin getMaxMoney() {
|
||||
|
||||
return this.maxMoney;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coin getMinNonDustOutput() {
|
||||
|
||||
return Coin.valueOf(this.minNonDustOutput);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUriScheme() {
|
||||
|
||||
return this.uriScheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMaxMoney() {
|
||||
|
||||
return this.hasMaxMoney;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getPaymentProtocolId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void checkDifficultyTransitions(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore)
|
||||
throws VerificationException, BlockStoreException {
|
||||
try {
|
||||
final long newTargetCompact = calculateNewDifficultyTarget(storedPrev, nextBlock, blockStore);
|
||||
final long receivedTargetCompact = nextBlock.getDifficultyTarget();
|
||||
|
||||
if (newTargetCompact != receivedTargetCompact)
|
||||
throw new VerificationException("Network provided difficulty bits do not match what was calculated: " +
|
||||
newTargetCompact + " vs " + receivedTargetCompact);
|
||||
} catch (CheckpointEncounteredException ex) {
|
||||
// Just have to take it on trust then
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the difficulty target expected for the next block. This includes all
|
||||
* the weird cases for Litecoin such as testnet blocks which can be maximum
|
||||
* difficulty if the block interval is high enough.
|
||||
*
|
||||
* @throws CheckpointEncounteredException if a checkpoint is encountered while
|
||||
* calculating difficulty target, and therefore no conclusive answer can
|
||||
* be provided.
|
||||
*/
|
||||
public long calculateNewDifficultyTarget(StoredBlock storedPrev, Block nextBlock, BlockStore blockStore)
|
||||
throws VerificationException, BlockStoreException, CheckpointEncounteredException {
|
||||
final Block prev = storedPrev.getHeader();
|
||||
final int previousHeight = storedPrev.getHeight();
|
||||
final int retargetInterval = this.getInterval();
|
||||
|
||||
// Is this supposed to be a difficulty transition point?
|
||||
if ((storedPrev.getHeight() + 1) % retargetInterval != 0) {
|
||||
if (this.allowMinDifficultyBlocks()) {
|
||||
// Special difficulty rule for testnet:
|
||||
// If the new block's timestamp is more than 5 minutes
|
||||
// then allow mining of a min-difficulty block.
|
||||
if (nextBlock.getTimeSeconds() > prev.getTimeSeconds() + getTargetSpacing() * 2) {
|
||||
return Utils.encodeCompactBits(maxTarget);
|
||||
} else {
|
||||
// Return the last non-special-min-difficulty-rules-block
|
||||
StoredBlock cursor = storedPrev;
|
||||
|
||||
while (cursor.getHeight() % retargetInterval != 0
|
||||
&& cursor.getHeader().getDifficultyTarget() == Utils.encodeCompactBits(this.getMaxTarget())) {
|
||||
StoredBlock prevCursor = cursor.getPrev(blockStore);
|
||||
if (prevCursor == null) {
|
||||
break;
|
||||
}
|
||||
cursor = prevCursor;
|
||||
}
|
||||
|
||||
return cursor.getHeader().getDifficultyTarget();
|
||||
}
|
||||
}
|
||||
|
||||
// No ... so check the difficulty didn't actually change.
|
||||
return prev.getDifficultyTarget();
|
||||
}
|
||||
|
||||
// We need to find a block far back in the chain. It's OK that this is expensive because it only occurs every
|
||||
// two weeks after the initial block chain download.
|
||||
StoredBlock cursor = storedPrev;
|
||||
int goBack = retargetInterval - 1;
|
||||
|
||||
// Litecoin: This fixes an issue where a 51% attack can change difficulty at will.
|
||||
// Go back the full period unless it's the first retarget after genesis.
|
||||
// Code based on original by Art Forz
|
||||
if (cursor.getHeight()+1 != retargetInterval)
|
||||
goBack = retargetInterval;
|
||||
|
||||
for (int i = 0; i < goBack; i++) {
|
||||
if (cursor == null) {
|
||||
// This should never happen. If it does, it means we are following an incorrect or busted chain.
|
||||
throw new VerificationException(
|
||||
"Difficulty transition point but we did not find a way back to the genesis block.");
|
||||
}
|
||||
cursor = blockStore.get(cursor.getHeader().getPrevBlockHash());
|
||||
}
|
||||
|
||||
//We used checkpoints...
|
||||
if (cursor == null) {
|
||||
log.debug("Difficulty transition: Hit checkpoint!");
|
||||
throw new CheckpointEncounteredException();
|
||||
}
|
||||
|
||||
Block blockIntervalAgo = cursor.getHeader();
|
||||
return this.calculateNewDifficultyTargetInner(previousHeight, prev.getTimeSeconds(),
|
||||
prev.getDifficultyTarget(), blockIntervalAgo.getTimeSeconds(),
|
||||
nextBlock.getDifficultyTarget());
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the difficulty target expected for the next block after a normal
|
||||
* recalculation interval. Does not handle special cases such as testnet blocks
|
||||
* being setting the target to maximum for blocks after a long interval.
|
||||
*
|
||||
* @param previousHeight height of the block immediately before the retarget.
|
||||
* @param prev the block immediately before the retarget block.
|
||||
* @param nextBlock the block the retarget happens at.
|
||||
* @param blockIntervalAgo The last retarget block.
|
||||
* @return New difficulty target as compact bytes.
|
||||
*/
|
||||
protected long calculateNewDifficultyTargetInner(int previousHeight, final Block prev,
|
||||
final Block nextBlock, final Block blockIntervalAgo) {
|
||||
return this.calculateNewDifficultyTargetInner(previousHeight, prev.getTimeSeconds(),
|
||||
prev.getDifficultyTarget(), blockIntervalAgo.getTimeSeconds(),
|
||||
nextBlock.getDifficultyTarget());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param previousHeight Height of the block immediately previous to the one we're calculating difficulty of.
|
||||
* @param previousBlockTime Time of the block immediately previous to the one we're calculating difficulty of.
|
||||
* @param lastDifficultyTarget Compact difficulty target of the last retarget block.
|
||||
* @param lastRetargetTime Time of the last difficulty retarget.
|
||||
* @param nextDifficultyTarget The expected difficulty target of the next
|
||||
* block, used for determining precision of the result.
|
||||
* @return New difficulty target as compact bytes.
|
||||
*/
|
||||
protected long calculateNewDifficultyTargetInner(int previousHeight, long previousBlockTime,
|
||||
final long lastDifficultyTarget, final long lastRetargetTime,
|
||||
final long nextDifficultyTarget) {
|
||||
final int retargetTimespan = this.getTargetTimespan();
|
||||
int actualTime = (int) (previousBlockTime - lastRetargetTime);
|
||||
final int minTimespan = retargetTimespan / 4;
|
||||
final int maxTimespan = retargetTimespan * 4;
|
||||
|
||||
actualTime = Math.min(maxTimespan, Math.max(minTimespan, actualTime));
|
||||
|
||||
BigInteger newTarget = Utils.decodeCompactBits(lastDifficultyTarget);
|
||||
newTarget = newTarget.multiply(BigInteger.valueOf(actualTime));
|
||||
newTarget = newTarget.divide(BigInteger.valueOf(retargetTimespan));
|
||||
|
||||
if (newTarget.compareTo(this.getMaxTarget()) > 0) {
|
||||
log.info("Difficulty hit proof of work limit: {}", newTarget.toString(16));
|
||||
newTarget = this.getMaxTarget();
|
||||
}
|
||||
|
||||
int accuracyBytes = (int) (nextDifficultyTarget >>> 24) - 3;
|
||||
|
||||
// The calculated difficulty is to a higher precision than received, so reduce here.
|
||||
BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8);
|
||||
newTarget = newTarget.and(mask);
|
||||
return Utils.encodeCompactBits(newTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AltcoinSerializer getSerializer(boolean parseRetain) {
|
||||
return new AltcoinSerializer(this, parseRetain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getProtocolVersionNum(final ProtocolVersion version) {
|
||||
switch (version) {
|
||||
case PONG:
|
||||
case BLOOM_FILTER:
|
||||
return version.getBitcoinProtocolVersion();
|
||||
case CURRENT:
|
||||
return protocolVersionCurrent;
|
||||
case MINIMUM:
|
||||
default:
|
||||
return protocolVersionMinimum;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this network has special rules to enable minimum difficulty blocks
|
||||
* after a long interval between two blocks (i.e. testnet).
|
||||
*/
|
||||
public boolean allowMinDifficultyBlocks() {
|
||||
return this.isTestNet();
|
||||
}
|
||||
|
||||
public int getTargetSpacing() {
|
||||
return this.getTargetTimespan() / this.getInterval();
|
||||
}
|
||||
|
||||
private static class CheckpointEncounteredException extends Exception { }
|
||||
}
|
@ -751,6 +751,12 @@ public class DigibyteACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -748,6 +748,12 @@ public class DogecoinACCTv1 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -751,6 +751,12 @@ public class DogecoinACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -46,7 +46,7 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
|
||||
private static final int RESPONSE_TIME_READINGS = 5;
|
||||
private static final long MAX_AVG_RESPONSE_TIME = 2000L; // ms
|
||||
public static final String MISSING_FEATURES_ERROR = "MISSING FEATURES ERROR";
|
||||
public static final String MINIMUM_VERSION_ERROR = "MINIMUM VERSION ERROR";
|
||||
public static final String EXPECTED_GENESIS_ERROR = "EXPECTED GENESIS ERROR";
|
||||
|
||||
private ChainableServerConnectionRecorder recorder = new ChainableServerConnectionRecorder(100);
|
||||
@ -721,19 +721,8 @@ public class ElectrumX extends BitcoinyBlockchainProvider {
|
||||
// Check connection is suitable by asking for server features, including genesis block hash
|
||||
JSONObject featuresJson = (JSONObject) this.connectedRpc("server.features");
|
||||
|
||||
if (featuresJson == null )
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy, true, false, MISSING_FEATURES_ERROR) );
|
||||
|
||||
try {
|
||||
double protocol_min = CrossChainUtils.getVersionDecimal(featuresJson, "protocol_min");
|
||||
|
||||
if (protocol_min < MIN_PROTOCOL_VERSION)
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy, true, false, "old version: protocol_min = " + protocol_min + " < MIN_PROTOCOL_VERSION = " + MIN_PROTOCOL_VERSION) );
|
||||
} catch (NumberFormatException e) {
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy,true, false,featuresJson.get("protocol_min").toString() + " is not a valid version"));
|
||||
} catch (NullPointerException e) {
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy,true, false,"server version not available: protocol_min"));
|
||||
}
|
||||
if (featuresJson == null || Double.parseDouble((String) featuresJson.get("protocol_min")) < MIN_PROTOCOL_VERSION)
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy, true, false, MINIMUM_VERSION_ERROR) );
|
||||
|
||||
if (this.expectedGenesisHash != null && !((String) featuresJson.get("genesis_hash")).equals(this.expectedGenesisHash))
|
||||
return Optional.of( recorder.recordConnection(server, requestedBy, true, false, EXPECTED_GENESIS_ERROR) );
|
||||
|
@ -741,6 +741,12 @@ public class LitecoinACCTv1 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -744,6 +744,12 @@ public class LitecoinACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -1,52 +0,0 @@
|
||||
package org.qortal.crosschain;
|
||||
|
||||
import org.bitcoinj.core.NetworkParameters;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class NetTBD {
|
||||
|
||||
private String name;
|
||||
private long feeCeiling;
|
||||
private NetworkParameters params;
|
||||
private Collection<ElectrumX.Server> servers;
|
||||
private String genesisHash;
|
||||
|
||||
public NetTBD(String name, long feeCeiling, NetworkParameters params, Collection<ElectrumX.Server> servers, String genesisHash) {
|
||||
this.name = name;
|
||||
this.feeCeiling = feeCeiling;
|
||||
this.params = params;
|
||||
this.servers = servers;
|
||||
this.genesisHash = genesisHash;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public long getFeeCeiling() {
|
||||
|
||||
return feeCeiling;
|
||||
}
|
||||
|
||||
public void setFeeCeiling(long feeCeiling) {
|
||||
|
||||
this.feeCeiling = feeCeiling;
|
||||
}
|
||||
|
||||
public NetworkParameters getParams() {
|
||||
|
||||
return this.params;
|
||||
}
|
||||
|
||||
public Collection<ElectrumX.Server> getServers() {
|
||||
|
||||
return this.servers;
|
||||
}
|
||||
|
||||
public String getGenesisHash() {
|
||||
|
||||
return this.genesisHash;
|
||||
}
|
||||
}
|
@ -768,6 +768,12 @@ public class PirateChainACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPublicKey, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPublicKey, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -751,6 +751,12 @@ public class RavencoinACCTv3 implements ACCT {
|
||||
return tradeData;
|
||||
}
|
||||
|
||||
/** Returns 'offer' MESSAGE payload for trade partner to send to AT creator's trade address. */
|
||||
public static byte[] buildOfferMessage(byte[] partnerBitcoinPKH, byte[] hashOfSecretA, int lockTimeA) {
|
||||
byte[] lockTimeABytes = BitTwiddling.toBEByteArray((long) lockTimeA);
|
||||
return Bytes.concat(partnerBitcoinPKH, hashOfSecretA, lockTimeABytes);
|
||||
}
|
||||
|
||||
/** Returns info extracted from 'offer' MESSAGE payload sent by trade partner to AT creator's trade address, or null if not valid. */
|
||||
public static OfferMessageData extractOfferMessageData(byte[] messageData) {
|
||||
if (messageData == null || messageData.length != OFFER_MESSAGE_LENGTH)
|
||||
|
@ -1,44 +0,0 @@
|
||||
package org.qortal.data.account;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Arrays;
|
||||
|
||||
// All properties to be converted to JSON via JAXB
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class AddressLevelPairing {
|
||||
|
||||
private String address;
|
||||
|
||||
private int level;
|
||||
|
||||
// Constructors
|
||||
|
||||
// For JAXB
|
||||
protected AddressLevelPairing() {
|
||||
}
|
||||
|
||||
public AddressLevelPairing(String address, int level) {
|
||||
this.address = address;
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AddressLevelPairing{" +
|
||||
"address='" + address + '\'' +
|
||||
", level=" + level +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,156 +0,0 @@
|
||||
package org.qortal.data.account;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Arrays;
|
||||
|
||||
// All properties to be converted to JSON via JAXB
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class MintershipReport {
|
||||
|
||||
private String address;
|
||||
|
||||
private int level;
|
||||
|
||||
private int blocksMinted;
|
||||
|
||||
private int adjustments;
|
||||
|
||||
private int penalties;
|
||||
|
||||
private boolean transfer;
|
||||
|
||||
private String name;
|
||||
|
||||
private int sponseeCount;
|
||||
|
||||
private int balance;
|
||||
|
||||
private int arbitraryCount;
|
||||
|
||||
private int transferAssetCount;
|
||||
|
||||
private int transferPrivsCount;
|
||||
|
||||
private int sellCount;
|
||||
|
||||
private int sellAmount;
|
||||
|
||||
private int buyCount;
|
||||
|
||||
private int buyAmount;
|
||||
|
||||
// Constructors
|
||||
|
||||
// For JAXB
|
||||
protected MintershipReport() {
|
||||
}
|
||||
|
||||
public MintershipReport(String address, int level, int blocksMinted, int adjustments, int penalties, boolean transfer, String name, int sponseeCount, int balance, int arbitraryCount, int transferAssetCount, int transferPrivsCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
||||
this.address = address;
|
||||
this.level = level;
|
||||
this.blocksMinted = blocksMinted;
|
||||
this.adjustments = adjustments;
|
||||
this.penalties = penalties;
|
||||
this.transfer = transfer;
|
||||
this.name = name;
|
||||
this.sponseeCount = sponseeCount;
|
||||
this.balance = balance;
|
||||
this.arbitraryCount = arbitraryCount;
|
||||
this.transferAssetCount = transferAssetCount;
|
||||
this.transferPrivsCount = transferPrivsCount;
|
||||
this.sellCount = sellCount;
|
||||
this.sellAmount = sellAmount;
|
||||
this.buyCount = buyCount;
|
||||
this.buyAmount = buyAmount;
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getBlocksMinted() {
|
||||
return blocksMinted;
|
||||
}
|
||||
|
||||
public int getAdjustments() {
|
||||
return adjustments;
|
||||
}
|
||||
|
||||
public int getPenalties() {
|
||||
return penalties;
|
||||
}
|
||||
|
||||
public boolean isTransfer() {
|
||||
return transfer;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getSponseeCount() {
|
||||
return sponseeCount;
|
||||
}
|
||||
|
||||
public int getBalance() {
|
||||
return balance;
|
||||
}
|
||||
|
||||
public int getArbitraryCount() {
|
||||
return arbitraryCount;
|
||||
}
|
||||
|
||||
public int getTransferAssetCount() {
|
||||
return transferAssetCount;
|
||||
}
|
||||
|
||||
public int getTransferPrivsCount() {
|
||||
return transferPrivsCount;
|
||||
}
|
||||
|
||||
public int getSellCount() {
|
||||
return sellCount;
|
||||
}
|
||||
|
||||
public int getSellAmount() {
|
||||
return sellAmount;
|
||||
}
|
||||
|
||||
public int getBuyCount() {
|
||||
return buyCount;
|
||||
}
|
||||
|
||||
public int getBuyAmount() {
|
||||
return buyAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MintershipReport{" +
|
||||
"address='" + address + '\'' +
|
||||
", level=" + level +
|
||||
", blocksMinted=" + blocksMinted +
|
||||
", adjustments=" + adjustments +
|
||||
", penalties=" + penalties +
|
||||
", transfer=" + transfer +
|
||||
", name='" + name + '\'' +
|
||||
", sponseeCount=" + sponseeCount +
|
||||
", balance=" + balance +
|
||||
", arbitraryCount=" + arbitraryCount +
|
||||
", transferAssetCount=" + transferAssetCount +
|
||||
", transferPrivsCount=" + transferPrivsCount +
|
||||
", sellCount=" + sellCount +
|
||||
", sellAmount=" + sellAmount +
|
||||
", buyCount=" + buyCount +
|
||||
", buyAmount=" + buyAmount +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
package org.qortal.data.account;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import java.util.Arrays;
|
||||
|
||||
// All properties to be converted to JSON via JAXB
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class SponsorshipReport {
|
||||
|
||||
private String address;
|
||||
|
||||
private int level;
|
||||
|
||||
private int blocksMinted;
|
||||
|
||||
private int adjustments;
|
||||
|
||||
private int penalties;
|
||||
|
||||
private boolean transfer;
|
||||
|
||||
private String[] names;
|
||||
|
||||
private int sponseeCount;
|
||||
|
||||
private int nonRegisteredCount;
|
||||
|
||||
private int avgBalance;
|
||||
|
||||
private int arbitraryCount;
|
||||
|
||||
private int transferAssetCount;
|
||||
|
||||
private int transferPrivsCount;
|
||||
|
||||
private int sellCount;
|
||||
|
||||
private int sellAmount;
|
||||
|
||||
private int buyCount;
|
||||
|
||||
private int buyAmount;
|
||||
|
||||
// Constructors
|
||||
|
||||
// For JAXB
|
||||
protected SponsorshipReport() {
|
||||
}
|
||||
|
||||
public SponsorshipReport(String address, int level, int blocksMinted, int adjustments, int penalties, boolean transfer, String[] names, int sponseeCount, int nonRegisteredCount, int avgBalance, int arbitraryCount, int transferAssetCount, int transferPrivsCount, int sellCount, int sellAmount, int buyCount, int buyAmount) {
|
||||
this.address = address;
|
||||
this.level = level;
|
||||
this.blocksMinted = blocksMinted;
|
||||
this.adjustments = adjustments;
|
||||
this.penalties = penalties;
|
||||
this.transfer = transfer;
|
||||
this.names = names;
|
||||
this.sponseeCount = sponseeCount;
|
||||
this.nonRegisteredCount = nonRegisteredCount;
|
||||
this.avgBalance = avgBalance;
|
||||
this.arbitraryCount = arbitraryCount;
|
||||
this.transferAssetCount = transferAssetCount;
|
||||
this.transferPrivsCount = transferPrivsCount;
|
||||
this.sellCount = sellCount;
|
||||
this.sellAmount = sellAmount;
|
||||
this.buyCount = buyCount;
|
||||
this.buyAmount = buyAmount;
|
||||
}
|
||||
|
||||
// Getters / setters
|
||||
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getBlocksMinted() {
|
||||
return blocksMinted;
|
||||
}
|
||||
|
||||
public int getAdjustments() {
|
||||
return adjustments;
|
||||
}
|
||||
|
||||
public int getPenalties() {
|
||||
return penalties;
|
||||
}
|
||||
|
||||
public boolean isTransfer() {
|
||||
return transfer;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
return names;
|
||||
}
|
||||
|
||||
public int getSponseeCount() {
|
||||
return sponseeCount;
|
||||
}
|
||||
|
||||
public int getNonRegisteredCount() {
|
||||
return nonRegisteredCount;
|
||||
}
|
||||
|
||||
public int getAvgBalance() {
|
||||
return avgBalance;
|
||||
}
|
||||
|
||||
public int getArbitraryCount() {
|
||||
return arbitraryCount;
|
||||
}
|
||||
|
||||
public int getTransferAssetCount() {
|
||||
return transferAssetCount;
|
||||
}
|
||||
|
||||
public int getTransferPrivsCount() {
|
||||
return transferPrivsCount;
|
||||
}
|
||||
|
||||
public int getSellCount() {
|
||||
return sellCount;
|
||||
}
|
||||
|
||||
public int getSellAmount() {
|
||||
return sellAmount;
|
||||
}
|
||||
|
||||
public int getBuyCount() {
|
||||
return buyCount;
|
||||
}
|
||||
|
||||
public int getBuyAmount() {
|
||||
return buyAmount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MintershipReport{" +
|
||||
"address='" + address + '\'' +
|
||||
", level=" + level +
|
||||
", blocksMinted=" + blocksMinted +
|
||||
", adjustments=" + adjustments +
|
||||
", penalties=" + penalties +
|
||||
", transfer=" + transfer +
|
||||
", names=" + Arrays.toString(names) +
|
||||
", sponseeCount=" + sponseeCount +
|
||||
", nonRegisteredCount=" + nonRegisteredCount +
|
||||
", avgBalance=" + avgBalance +
|
||||
", arbitraryCount=" + arbitraryCount +
|
||||
", transferAssetCount=" + transferAssetCount +
|
||||
", transferPrivsCount=" + transferPrivsCount +
|
||||
", sellCount=" + sellCount +
|
||||
", sellAmount=" + sellAmount +
|
||||
", buyCount=" + buyCount +
|
||||
", buyAmount=" + buyAmount +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package org.qortal.data.arbitrary;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ArbitraryResourceCache {
|
||||
private ConcurrentHashMap<Integer, List<ArbitraryResourceData>> dataByService = new ConcurrentHashMap<>();
|
||||
private ConcurrentHashMap<String, Integer> levelByName = new ConcurrentHashMap<>();
|
||||
|
||||
private ArbitraryResourceCache() {}
|
||||
|
||||
private static ArbitraryResourceCache SINGLETON = new ArbitraryResourceCache();
|
||||
|
||||
public static ArbitraryResourceCache getInstance(){
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<String, Integer> getLevelByName() {
|
||||
return levelByName;
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<Integer, List<ArbitraryResourceData>> getDataByService() {
|
||||
return this.dataByService;
|
||||
}
|
||||
}
|
@ -1,11 +1,8 @@
|
||||
package org.qortal.data.block;
|
||||
|
||||
import com.google.common.primitives.Bytes;
|
||||
import org.qortal.account.Account;
|
||||
import org.qortal.block.BlockChain;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.repository.Repository;
|
||||
import org.qortal.repository.RepositoryManager;
|
||||
import org.qortal.crypto.Crypto;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
@ -235,31 +232,11 @@ public class BlockData implements Serializable {
|
||||
return blockTimestamp < onlineAccountSignaturesTrimmedTimestamp && blockTimestamp < currentTrimmableTimestamp;
|
||||
}
|
||||
|
||||
public String getMinterAddressFromPublicKey() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return Account.getRewardShareMintingAddress(repository, this.minterPublicKey);
|
||||
} catch (DataException e) {
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
public int getMinterLevelFromPublicKey() {
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
return Account.getRewardShareEffectiveMintingLevel(repository, this.minterPublicKey);
|
||||
} catch (DataException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// JAXB special
|
||||
|
||||
@XmlElement(name = "minterAddress")
|
||||
protected String getMinterAddress() {
|
||||
return getMinterAddressFromPublicKey();
|
||||
return Crypto.toAddress(this.minterPublicKey);
|
||||
}
|
||||
|
||||
@XmlElement(name = "minterLevel")
|
||||
protected int getMinterLevel() {
|
||||
return getMinterLevelFromPublicKey();
|
||||
}
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public enum Handshake {
|
||||
private static final int POW_DIFFICULTY_POST_131 = 2; // leading zero bits
|
||||
|
||||
|
||||
private static final ExecutorService responseExecutor = Executors.newFixedThreadPool(Settings.getInstance().getNetworkPoWComputePoolSize(), new DaemonThreadFactory("Network-PoW", Settings.getInstance().getHandshakeThreadPriority()));
|
||||
private static final ExecutorService responseExecutor = Executors.newFixedThreadPool(Settings.getInstance().getNetworkPoWComputePoolSize(), new DaemonThreadFactory("Network-PoW"));
|
||||
|
||||
private static final byte[] ZERO_CHALLENGE = new byte[ChallengeMessage.CHALLENGE_LENGTH];
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class Network {
|
||||
/**
|
||||
* How long between informational broadcasts to all connected peers, in milliseconds.
|
||||
*/
|
||||
private static final long BROADCAST_INTERVAL = 30 * 1000L; // ms
|
||||
private static final long BROADCAST_INTERVAL = 60 * 1000L; // ms
|
||||
/**
|
||||
* Maximum time since last successful connection for peer info to be propagated, in milliseconds.
|
||||
*/
|
||||
@ -83,12 +83,12 @@ public class Network {
|
||||
"node6.qortalnodes.live", "node7.qortalnodes.live", "node8.qortalnodes.live"
|
||||
};
|
||||
|
||||
private static final long NETWORK_EPC_KEEPALIVE = 5L; // seconds
|
||||
private static final long NETWORK_EPC_KEEPALIVE = 10L; // seconds
|
||||
|
||||
public static final int MAX_SIGNATURES_PER_REPLY = 500;
|
||||
public static final int MAX_BLOCK_SUMMARIES_PER_REPLY = 500;
|
||||
|
||||
private static final long DISCONNECTION_CHECK_INTERVAL = 20 * 1000L; // milliseconds
|
||||
private static final long DISCONNECTION_CHECK_INTERVAL = 10 * 1000L; // milliseconds
|
||||
|
||||
private static final int BROADCAST_CHAIN_TIP_DEPTH = 7; // Just enough to fill a SINGLE TCP packet (~1440 bytes)
|
||||
|
||||
@ -164,11 +164,11 @@ public class Network {
|
||||
maxPeers = Settings.getInstance().getMaxPeers();
|
||||
|
||||
// We'll use a cached thread pool but with more aggressive timeout.
|
||||
ExecutorService networkExecutor = new ThreadPoolExecutor(2,
|
||||
ExecutorService networkExecutor = new ThreadPoolExecutor(1,
|
||||
Settings.getInstance().getMaxNetworkThreadPoolSize(),
|
||||
NETWORK_EPC_KEEPALIVE, TimeUnit.SECONDS,
|
||||
new SynchronousQueue<Runnable>(),
|
||||
new NamedThreadFactory("Network-EPC", Settings.getInstance().getNetworkThreadPriority()));
|
||||
new NamedThreadFactory("Network-EPC"));
|
||||
networkEPC = new NetworkProcessor(networkExecutor);
|
||||
}
|
||||
|
||||
|
23
src/main/java/org/qortal/network/RNSCommon.java
Normal file
23
src/main/java/org/qortal/network/RNSCommon.java
Normal file
@ -0,0 +1,23 @@
|
||||
package org.qortal.network;
|
||||
|
||||
public class RNSCommon {
|
||||
|
||||
/**
|
||||
* Destination application name
|
||||
*/
|
||||
public static String APP_NAME = "qortal";
|
||||
|
||||
/**
|
||||
* Configuration path relative to the Qortal launch directory
|
||||
*/
|
||||
public static String defaultRNSConfigPath = new String(".reticulum");
|
||||
|
||||
///**
|
||||
// * Qortal RNS Destinations
|
||||
// */
|
||||
//public enum RNSDestinations {
|
||||
// BASE,
|
||||
// QDN;
|
||||
//}
|
||||
|
||||
}
|
637
src/main/java/org/qortal/network/RNSNetwork.java
Normal file
637
src/main/java/org/qortal/network/RNSNetwork.java
Normal file
@ -0,0 +1,637 @@
|
||||
package org.qortal.network;
|
||||
|
||||
import io.reticulum.Reticulum;
|
||||
import io.reticulum.Transport;
|
||||
import io.reticulum.interfaces.ConnectionInterface;
|
||||
import io.reticulum.destination.Destination;
|
||||
import io.reticulum.destination.DestinationType;
|
||||
import io.reticulum.destination.Direction;
|
||||
import io.reticulum.destination.ProofStrategy;
|
||||
import io.reticulum.identity.Identity;
|
||||
import io.reticulum.link.Link;
|
||||
import io.reticulum.link.LinkStatus;
|
||||
//import io.reticulum.constant.LinkConstant;
|
||||
import io.reticulum.packet.Packet;
|
||||
import io.reticulum.packet.PacketReceipt;
|
||||
import io.reticulum.packet.PacketReceiptStatus;
|
||||
import io.reticulum.transport.AnnounceHandler;
|
||||
import static io.reticulum.link.TeardownSession.DESTINATION_CLOSED;
|
||||
import static io.reticulum.link.TeardownSession.INITIATOR_CLOSED;
|
||||
import static io.reticulum.link.TeardownSession.TIMEOUT;
|
||||
import static io.reticulum.link.LinkStatus.ACTIVE;
|
||||
import static io.reticulum.link.LinkStatus.STALE;
|
||||
import static io.reticulum.link.LinkStatus.PENDING;
|
||||
import static io.reticulum.link.LinkStatus.HANDSHAKE;
|
||||
//import static io.reticulum.packet.PacketContextType.LINKCLOSE;
|
||||
import static io.reticulum.identity.IdentityKnownDestination.recall;
|
||||
import static io.reticulum.utils.IdentityUtils.concatArrays;
|
||||
//import static io.reticulum.constant.ReticulumConstant.TRUNCATED_HASHLENGTH;
|
||||
import static io.reticulum.constant.ReticulumConstant.CONFIG_FILE_NAME;
|
||||
import lombok.Data;
|
||||
//import lombok.Setter;
|
||||
//import lombok.Getter;
|
||||
import lombok.Synchronized;
|
||||
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.settings.Settings;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.WRITE;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
//import static java.util.Objects.isNull;
|
||||
//import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
//import static org.apache.commons.lang3.BooleanUtils.isFalse;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
//import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
|
||||
// logging
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
public class RNSNetwork {
|
||||
|
||||
Reticulum reticulum;
|
||||
//private static final String APP_NAME = "qortal";
|
||||
static final String APP_NAME = RNSCommon.APP_NAME;
|
||||
static final String defaultConfigPath = new String(".reticulum"); // if empty will look in Reticulums default paths
|
||||
//static final String defaultConfigPath = RNSCommon.defaultRNSConfigPath;
|
||||
//private final String defaultConfigPath = Settings.getInstance().getDefaultRNSConfigPathForReticulum();
|
||||
private static Integer MAX_PEERS = 12;
|
||||
//private final Integer MAX_PEERS = Settings.getInstance().getMaxReticulumPeers();
|
||||
private static Integer MIN_DESIRED_PEERS = 3;
|
||||
//private final Integer MIN_DESIRED_PEERS = Settings.getInstance().getMinDesiredPeers();
|
||||
Identity serverIdentity;
|
||||
public Destination baseDestination;
|
||||
private volatile boolean isShuttingDown = false;
|
||||
private final List<RNSPeer> linkedPeers = Collections.synchronizedList(new ArrayList<>());
|
||||
private final List<Link> incomingLinks = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
////private final ExecuteProduceConsume rnsNetworkEPC;
|
||||
//private static final long NETWORK_EPC_KEEPALIVE = 1000L; // 1 second
|
||||
//private volatile boolean isShuttingDown = false;
|
||||
//private int totalThreadCount = 0;
|
||||
//// TODO: settings - MaxReticulumPeers, MaxRNSNetworkThreadPoolSize (if needed)
|
||||
|
||||
//private static final Logger logger = LoggerFactory.getLogger(RNSNetwork.class);
|
||||
|
||||
// Constructor
|
||||
private RNSNetwork () {
|
||||
log.info("RNSNetwork constructor");
|
||||
try {
|
||||
//String configPath = new java.io.File(defaultConfigPath).getCanonicalPath();
|
||||
log.info("creating config from {}", defaultConfigPath);
|
||||
initConfig(defaultConfigPath);
|
||||
//reticulum = new Reticulum(configPath);
|
||||
reticulum = new Reticulum(defaultConfigPath);
|
||||
var identitiesPath = reticulum.getStoragePath().resolve("identities");
|
||||
if (Files.notExists(identitiesPath)) {
|
||||
Files.createDirectories(identitiesPath);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("unable to create Reticulum network", e);
|
||||
}
|
||||
log.info("reticulum instance created");
|
||||
log.info("reticulum instance created: {}", reticulum);
|
||||
|
||||
// Settings.getInstance().getMaxRNSNetworkThreadPoolSize(), // statically set to 5 below
|
||||
//ExecutorService RNSNetworkExecutor = new ThreadPoolExecutor(1,
|
||||
// 5,
|
||||
// NETWORK_EPC_KEEPALIVE, TimeUnit.SECONDS,
|
||||
// new SynchronousQueue<Runnable>(),
|
||||
// new NamedThreadFactory("RNSNetwork-EPC"));
|
||||
//rnsNetworkEPC = new RNSNetworkProcessor(RNSNetworkExecutor);
|
||||
}
|
||||
|
||||
// Note: potentially create persistent serverIdentity (utility rnid) and load it from file
|
||||
public void start() throws IOException, DataException {
|
||||
|
||||
// create identity either from file or new (creating new keys)
|
||||
var serverIdentityPath = reticulum.getStoragePath().resolve("identities/"+APP_NAME);
|
||||
if (Files.isReadable(serverIdentityPath)) {
|
||||
serverIdentity = Identity.fromFile(serverIdentityPath);
|
||||
log.info("server identity loaded from file {}", serverIdentityPath.toString());
|
||||
} else {
|
||||
serverIdentity = new Identity();
|
||||
log.info("APP_NAME: {}, storage path: {}", APP_NAME, serverIdentityPath);
|
||||
log.info("new server identity created dynamically.");
|
||||
// save it back to file by default for next start (possibly add setting to override)
|
||||
try {
|
||||
Files.write(serverIdentityPath, serverIdentity.getPrivateKey(), CREATE, WRITE);
|
||||
log.info("serverIdentity written back to file");
|
||||
} catch (IOException e) {
|
||||
log.error("Error while saving serverIdentity to {}", serverIdentityPath, e);
|
||||
}
|
||||
}
|
||||
log.debug("Server Identity: {}", serverIdentity.toString());
|
||||
|
||||
// show the ifac_size of the configured interfaces (debug code)
|
||||
for (ConnectionInterface i: Transport.getInstance().getInterfaces() ) {
|
||||
log.info("interface {}, length: {}", i.getInterfaceName(), i.getIfacSize());
|
||||
}
|
||||
|
||||
baseDestination = new Destination(
|
||||
serverIdentity,
|
||||
Direction.IN,
|
||||
DestinationType.SINGLE,
|
||||
APP_NAME,
|
||||
"core"
|
||||
);
|
||||
//// idea for other entry point
|
||||
//dataDestination = new Destination(
|
||||
// serverIdentity,
|
||||
// Direction.IN,
|
||||
// DestinationType.SINGLE,
|
||||
// APP_NAME,
|
||||
// "core",
|
||||
// "qdn"
|
||||
//);
|
||||
log.info("Destination "+Hex.encodeHexString(baseDestination.getHash())+" "+baseDestination.getName()+" running.");
|
||||
|
||||
baseDestination.setProofStrategy(ProofStrategy.PROVE_ALL);
|
||||
baseDestination.setAcceptLinkRequests(true);
|
||||
|
||||
baseDestination.setLinkEstablishedCallback(this::clientConnected);
|
||||
|
||||
Transport.getInstance().registerAnnounceHandler(new QAnnounceHandler());
|
||||
log.debug("announceHandlers: {}", Transport.getInstance().getAnnounceHandlers());
|
||||
|
||||
// do a first announce
|
||||
baseDestination.announce();
|
||||
log.debug("Sent initial announce from {} ({})", Hex.encodeHexString(baseDestination.getHash()), baseDestination.getName());
|
||||
|
||||
// Start up first networking thread (the "server loop")
|
||||
//rnsNetworkEPC.start();
|
||||
}
|
||||
|
||||
private void initConfig(String configDir) throws IOException {
|
||||
File configDir1 = new File(defaultConfigPath);
|
||||
if (!configDir1.exists()) {
|
||||
configDir1.mkdir();
|
||||
}
|
||||
var configPath = Path.of(configDir1.getAbsolutePath());
|
||||
Path configFile = configPath.resolve(CONFIG_FILE_NAME);
|
||||
|
||||
if (Files.notExists(configFile)) {
|
||||
var defaultConfig = this.getClass().getClassLoader().getResourceAsStream("reticulum_default_config.yml");
|
||||
Files.copy(defaultConfig, configFile, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
isShuttingDown = true;
|
||||
log.info("shutting down Reticulum");
|
||||
|
||||
// Stop processing threads (the "server loop")
|
||||
//try {
|
||||
// if (!this.rnsNetworkEPC.shutdown(5000)) {
|
||||
// logger.warn("RNSNetwork threads failed to terminate");
|
||||
// }
|
||||
//} catch (InterruptedException e) {
|
||||
// logger.warn("Interrupted while waiting for RNS networking threads to terminate");
|
||||
//}
|
||||
|
||||
// Disconnect peers gracefully and terminate Reticulum
|
||||
for (RNSPeer p: linkedPeers) {
|
||||
log.info("shutting down peer: {}", Hex.encodeHexString(p.getDestinationHash()));
|
||||
log.debug("peer: {}", p);
|
||||
p.shutdown();
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(1); // allow for peers to disconnect gracefully
|
||||
} catch (InterruptedException e) {
|
||||
log.error("exception: {}", e);
|
||||
}
|
||||
}
|
||||
// gracefully close links of peers that point to us
|
||||
for (Link l: incomingLinks) {
|
||||
sendCloseToRemote(l);
|
||||
}
|
||||
// Note: we still need to get the packet timeout callback to work...
|
||||
reticulum.exitHandler();
|
||||
}
|
||||
|
||||
public void sendCloseToRemote(Link link) {
|
||||
if (nonNull(link)) {
|
||||
var data = concatArrays("close::".getBytes(UTF_8),link.getDestination().getHash());
|
||||
Packet closePacket = new Packet(link, data);
|
||||
var packetReceipt = closePacket.send();
|
||||
packetReceipt.setDeliveryCallback(this::closePacketDelivered);
|
||||
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
||||
} else {
|
||||
log.debug("can't send to null link");
|
||||
}
|
||||
}
|
||||
|
||||
public void closePacketDelivered(PacketReceipt receipt) {
|
||||
var rttString = new String("");
|
||||
if (receipt.getStatus() == PacketReceiptStatus.DELIVERED) {
|
||||
var rtt = receipt.getRtt(); // rtt (Java) is in miliseconds
|
||||
//log.info("qqp - packetDelivered - rtt: {}", rtt);
|
||||
if (rtt >= 1000) {
|
||||
rtt = Math.round(rtt / 1000);
|
||||
rttString = String.format("%d seconds", rtt);
|
||||
} else {
|
||||
rttString = String.format("%d miliseconds", rtt);
|
||||
}
|
||||
log.info("Shutdown packet confirmation received from {}, round-trip time is {}",
|
||||
Hex.encodeHexString(receipt.getDestination().getHash()), rttString);
|
||||
}
|
||||
}
|
||||
|
||||
public void packetTimedOut(PacketReceipt receipt) {
|
||||
log.info("packet timed out, receipt status: {}", receipt.getStatus());
|
||||
}
|
||||
|
||||
public void clientConnected(Link link) {
|
||||
link.setLinkClosedCallback(this::clientDisconnected);
|
||||
link.setPacketCallback(this::serverPacketReceived);
|
||||
var peer = findPeerByLink(link);
|
||||
if (nonNull(peer)) {
|
||||
log.info("initiator peer {} opened link (link lookup: {}), link destination hash: {}",
|
||||
Hex.encodeHexString(peer.getDestinationHash()), link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
// make sure the peerLink is actvive.
|
||||
peer.getOrInitPeerLink();
|
||||
} else {
|
||||
log.info("non-initiator closed link (link lookup: {}), link destination hash (initiator): {}",
|
||||
peer, link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
}
|
||||
incomingLinks.add(link);
|
||||
log.info("***> Client connected, link: {}", link);
|
||||
}
|
||||
|
||||
public void clientDisconnected(Link link) {
|
||||
var peer = findPeerByLink(link);
|
||||
if (nonNull(peer)) {
|
||||
log.info("initiator peer {} closed link (link lookup: {}), link destination hash: {}",
|
||||
Hex.encodeHexString(peer.getDestinationHash()), link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
} else {
|
||||
log.info("non-initiator closed link (link lookup: {}), link destination hash (initiator): {}",
|
||||
peer, link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
}
|
||||
// if we have a peer pointing to that destination, we can close and remove it
|
||||
peer = findPeerByDestinationHash(link.getDestination().getHash());
|
||||
if (nonNull(peer)) {
|
||||
// Note: no shutdown as the remobe peer could be only rebooting.
|
||||
// keep it to reopen link later if possible.
|
||||
peer.getPeerLink().teardown();
|
||||
}
|
||||
incomingLinks.remove(link);
|
||||
log.info("***> Client disconnected");
|
||||
}
|
||||
|
||||
public void serverPacketReceived(byte[] message, Packet packet) {
|
||||
var msgText = new String(message, StandardCharsets.UTF_8);
|
||||
log.info("Received data on link - message: {}, destinationHash: {}", msgText, Hex.encodeHexString(packet.getDestinationHash()));
|
||||
//var peer = findPeerByDestinationHash(packet.getDestinationHash());
|
||||
//if (msgText.equals("ping")) {
|
||||
// log.info("received ping");
|
||||
// //if (nonNull(peer)) {
|
||||
// // String replyText = "pong";
|
||||
// // byte[] replyData = replyText.getBytes(StandardCharsets.UTF_8);
|
||||
// // Packet reply = new Packet(peer.getPeerLink(), replyData);
|
||||
// //}
|
||||
//}
|
||||
//if (msgText.equals("shutdown")) {
|
||||
// log.info("shutdown packet received");
|
||||
// var link = recall(packet.getDestinationHash());
|
||||
// log.info("recalled destinationHash: {}", link);
|
||||
// //...
|
||||
//}
|
||||
// TODO: process packet....
|
||||
}
|
||||
|
||||
//public void announceBaseDestination () {
|
||||
// getBaseDestination().announce();
|
||||
//}
|
||||
|
||||
//@Slf4j
|
||||
private class QAnnounceHandler implements AnnounceHandler {
|
||||
@Override
|
||||
public String getAspectFilter() {
|
||||
// handle all announces
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Synchronized
|
||||
public void receivedAnnounce(byte[] destinationHash, Identity announcedIdentity, byte[] appData) {
|
||||
var peerExists = false;
|
||||
var activePeerCount = 0;
|
||||
|
||||
log.info("Received an announce from {}", Hex.encodeHexString(destinationHash));
|
||||
|
||||
if (nonNull(appData)) {
|
||||
log.debug("The announce contained the following app data: {}", new String(appData, UTF_8));
|
||||
}
|
||||
|
||||
// add to peer list if we can use more peers
|
||||
//synchronized (this) {
|
||||
var lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||
for (RNSPeer p: lps) {
|
||||
var pl = p.getPeerLink();
|
||||
if ((nonNull(pl) && (pl.getStatus() == ACTIVE))) {
|
||||
activePeerCount = activePeerCount + 1;
|
||||
}
|
||||
}
|
||||
if (activePeerCount < MAX_PEERS) {
|
||||
//if (!peerExists) {
|
||||
//var peer = findPeerByDestinationHash(destinationHash);
|
||||
for (RNSPeer p: lps) {
|
||||
if (Arrays.equals(p.getDestinationHash(), destinationHash)) {
|
||||
log.info("QAnnounceHandler - peer exists - found peer matching destinationHash");
|
||||
if (nonNull(p.getPeerLink())) {
|
||||
log.info("peer link: {}, status: {}", p.getPeerLink(), p.getPeerLink().getStatus());
|
||||
}
|
||||
peerExists = true;
|
||||
if (p.getPeerLink().getStatus() != ACTIVE) {
|
||||
p.getOrInitPeerLink();
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (nonNull(p.getPeerLink())) {
|
||||
log.info("QAnnounceHandler - other peer - link: {}, status: {}", p.getPeerLink(), p.getPeerLink().getStatus());
|
||||
} else {
|
||||
log.info("QAnnounceHandler - null link peer - link: {}", p.getPeerLink());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!peerExists) {
|
||||
RNSPeer newPeer = new RNSPeer(destinationHash);
|
||||
newPeer.setServerIdentity(announcedIdentity);
|
||||
newPeer.setIsInitiator(true);
|
||||
lps.add(newPeer);
|
||||
log.info("added new RNSPeer, destinationHash: {}", Hex.encodeHexString(destinationHash));
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
// Main thread
|
||||
//class RNSNetworkProcessor extends ExecuteProduceConsume {
|
||||
//
|
||||
// //private final Logger logger = LoggerFactory.getLogger(RNSNetworkProcessor.class);
|
||||
//
|
||||
// private final AtomicLong nextConnectTaskTimestamp = new AtomicLong(0L); // ms - try first connect once NTP syncs
|
||||
// private final AtomicLong nextBroadcastTimestamp = new AtomicLong(0L); // ms - try first broadcast once NTP syncs
|
||||
//
|
||||
// private Iterator<SelectionKey> channelIterator = null;
|
||||
//
|
||||
// RNSNetworkProcessor(ExecutorService executor) {
|
||||
// super(executor);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected void onSpawnFailure() {
|
||||
// // For debugging:
|
||||
// // ExecutorDumper.dump(this.executor, 3, ExecuteProduceConsume.class);
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected Task produceTask(boolean canBlock) throws InterruptedException {
|
||||
// Task task;
|
||||
//
|
||||
// //task = maybeProducePeerMessageTask();
|
||||
// //if (task != null) {
|
||||
// // return task;
|
||||
// //}
|
||||
// //
|
||||
// //final Long now = NTP.getTime();
|
||||
// //
|
||||
// //task = maybeProducePeerPingTask(now);
|
||||
// //if (task != null) {
|
||||
// // return task;
|
||||
// //}
|
||||
// //
|
||||
// //task = maybeProduceConnectPeerTask(now);
|
||||
// //if (task != null) {
|
||||
// // return task;
|
||||
// //}
|
||||
// //
|
||||
// //task = maybeProduceBroadcastTask(now);
|
||||
// //if (task != null) {
|
||||
// // return task;
|
||||
// //}
|
||||
// //
|
||||
// // Only this method can block to reduce CPU spin
|
||||
// //return maybeProduceChannelTask(canBlock);
|
||||
//
|
||||
// // TODO: flesh out the tasks handled by Reticulum
|
||||
// return null;
|
||||
// }
|
||||
// //...TODO: implement abstract methods...
|
||||
//}
|
||||
|
||||
|
||||
// getter / setter
|
||||
private static class SingletonContainer {
|
||||
private static final RNSNetwork INSTANCE = new RNSNetwork();
|
||||
}
|
||||
|
||||
public static RNSNetwork getInstance() {
|
||||
return SingletonContainer.INSTANCE;
|
||||
}
|
||||
|
||||
public Identity getServerIdentity() {
|
||||
return this.serverIdentity;
|
||||
}
|
||||
|
||||
public Reticulum getReticulum() {
|
||||
return this.reticulum;
|
||||
}
|
||||
|
||||
public List<RNSPeer> getLinkedPeers() {
|
||||
synchronized(this.linkedPeers) {
|
||||
//return new ArrayList<>(this.linkedPeers);
|
||||
return this.linkedPeers;
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getTotalPeers() {
|
||||
synchronized (this) {
|
||||
return linkedPeers.size();
|
||||
}
|
||||
}
|
||||
|
||||
public Destination getBaseDestination() {
|
||||
return baseDestination;
|
||||
}
|
||||
|
||||
// maintenance
|
||||
//public void removePeer(RNSPeer peer) {
|
||||
// synchronized(this) {
|
||||
// List<RNSPeer> peerList = this.linkedPeers;
|
||||
// log.info("removing peer {} on peer shutdown", peer);
|
||||
// peerList.remove(peer);
|
||||
// }
|
||||
//}
|
||||
|
||||
//public void pingPeer(RNSPeer peer) {
|
||||
// if (nonNull(peer)) {
|
||||
// peer.pingRemote();
|
||||
// } else {
|
||||
// log.error("peer argument is null");
|
||||
// }
|
||||
//}
|
||||
|
||||
@Synchronized
|
||||
public void prunePeers() throws DataException {
|
||||
// run periodically (by the Controller)
|
||||
//List<Link> linkList = getLinkedPeers();
|
||||
var peerList = getLinkedPeers();
|
||||
log.info("number of links (linkedPeers) before prunig: {}", peerList.size());
|
||||
Link pLink;
|
||||
LinkStatus lStatus;
|
||||
for (RNSPeer p: peerList) {
|
||||
pLink = p.getPeerLink();
|
||||
log.info("prunePeers - pLink: {}, destinationHash: {}",
|
||||
pLink, Hex.encodeHexString(p.getDestinationHash()));
|
||||
log.debug("peer: {}", p);
|
||||
if (nonNull(pLink)) {
|
||||
if (p.getPeerTimedOut()) {
|
||||
// close peer link for now
|
||||
pLink.teardown();
|
||||
}
|
||||
lStatus = pLink.getStatus();
|
||||
log.info("Link {} status: {}", pLink, lStatus);
|
||||
// lStatus in: PENDING, HANDSHAKE, ACTIVE, STALE, CLOSED
|
||||
if ((lStatus == STALE) || (pLink.getTeardownReason() == TIMEOUT) || (p.getDeleteMe())) {
|
||||
p.shutdown();
|
||||
peerList.remove(p);
|
||||
} else if (lStatus == HANDSHAKE) {
|
||||
// stuck in handshake state (do we need to shutdown/remove it?)
|
||||
log.info("peer status HANDSHAKE");
|
||||
p.shutdown();
|
||||
peerList.remove(p);
|
||||
}
|
||||
} else {
|
||||
peerList.remove(p);
|
||||
}
|
||||
}
|
||||
//removeExpiredPeers(this.linkedPeers);
|
||||
log.info("number of links (linkedPeers) after prunig: {}", peerList.size());
|
||||
//log.info("we have {} non-initiator links, list: {}", incomingLinks.size(), incomingLinks);
|
||||
var activePeerCount = 0;
|
||||
var lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||
for (RNSPeer p: lps) {
|
||||
pLink = p.getPeerLink();
|
||||
p.pingRemote();
|
||||
try {
|
||||
TimeUnit.SECONDS.sleep(2); // allow for peers to disconnect gracefully
|
||||
} catch (InterruptedException e) {
|
||||
log.error("exception: {}", e);
|
||||
}
|
||||
if ((nonNull(pLink) && (pLink.getStatus() == ACTIVE))) {
|
||||
activePeerCount = activePeerCount + 1;
|
||||
}
|
||||
}
|
||||
log.info("we have {} active peers", activePeerCount);
|
||||
maybeAnnounce(getBaseDestination());
|
||||
}
|
||||
|
||||
//public void removeExpiredPeers(List<RNSPeer> peerList) {
|
||||
// //List<RNSPeer> peerList = this.linkedPeers;
|
||||
// for (RNSPeer p: peerList) {
|
||||
// if (p.getPeerLink() == null) {
|
||||
// peerList.remove(p);
|
||||
// } else if (p.getPeerLink().getStatus() == STALE) {
|
||||
// peerList.remove(p);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
public void maybeAnnounce(Destination d) {
|
||||
if (getLinkedPeers().size() < MIN_DESIRED_PEERS) {
|
||||
d.announce();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper methods
|
||||
*/
|
||||
|
||||
//@Synchronized
|
||||
//public RNSPeer getPeerIfExists(RNSPeer peer) {
|
||||
// List<RNSPeer> lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||
// RNSPeer result = null;
|
||||
// for (RNSPeer p: lps) {
|
||||
// if (nonNull(p.getDestinationHash()) && Arrays.equals(p.getDestinationHash(), peer.getDestinationHash())) {
|
||||
// log.info("found match by destinationHash");
|
||||
// result = p;
|
||||
// //break;
|
||||
// }
|
||||
// if (nonNull(p.getPeerDestinationHash()) && Arrays.equals(p.getPeerDestinationHash(), peer.getPeerDestinationHash())) {
|
||||
// log.info("found match by peerDestinationHash");
|
||||
// result = p;
|
||||
// //break;
|
||||
// }
|
||||
// if (nonNull(p.getPeerBaseDestinationHash()) && Arrays.equals(p.getPeerBaseDestinationHash(), peer.getPeerBaseDestinationHash())) {
|
||||
// log.info("found match by peerBaseDestinationHash");
|
||||
// result = p;
|
||||
// //break;
|
||||
// }
|
||||
// if (nonNull(p.getRemoteTestHash()) && Arrays.equals(p.getRemoteTestHash(), peer.getRemoteTestHash())) {
|
||||
// log.info("found match by remoteTestHash");
|
||||
// result = p;
|
||||
// //break;
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
public RNSPeer findPeerByLink(Link link) {
|
||||
List<RNSPeer> lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||
RNSPeer peer = null;
|
||||
for (RNSPeer p : lps) {
|
||||
var pLink = p.getPeerLink();
|
||||
if (nonNull(pLink)) {
|
||||
if (Arrays.equals(pLink.getDestination().getHash(),link.getDestination().getHash())) {
|
||||
log.info("found peer matching destinationHash: {}", Hex.encodeHexString(link.getDestination().getHash()));
|
||||
peer = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return peer;
|
||||
}
|
||||
|
||||
public RNSPeer findPeerByDestinationHash(byte[] dhash) {
|
||||
List<RNSPeer> lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||
RNSPeer peer = null;
|
||||
for (RNSPeer p : lps) {
|
||||
if (Arrays.equals(p.getDestinationHash(), dhash)) {
|
||||
log.info("found peer matching destinationHash: {}", Hex.encodeHexString(dhash));
|
||||
peer = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return peer;
|
||||
}
|
||||
|
||||
public void removePeer(RNSPeer peer) {
|
||||
List<RNSPeer> peerList = this.linkedPeers;
|
||||
if (nonNull(peer)) {
|
||||
peerList.remove(peer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
284
src/main/java/org/qortal/network/RNSPeer.java
Normal file
284
src/main/java/org/qortal/network/RNSPeer.java
Normal file
@ -0,0 +1,284 @@
|
||||
package org.qortal.network;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
import static java.util.Objects.nonNull;
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
|
||||
import io.reticulum.Reticulum;
|
||||
import org.qortal.network.RNSNetwork;
|
||||
import io.reticulum.link.Link;
|
||||
import io.reticulum.link.RequestReceipt;
|
||||
import io.reticulum.packet.PacketReceiptStatus;
|
||||
import io.reticulum.packet.Packet;
|
||||
import io.reticulum.packet.PacketReceipt;
|
||||
import io.reticulum.identity.Identity;
|
||||
import io.reticulum.channel.Channel;
|
||||
import io.reticulum.destination.Destination;
|
||||
import io.reticulum.destination.DestinationType;
|
||||
import io.reticulum.destination.Direction;
|
||||
import io.reticulum.destination.ProofStrategy;
|
||||
import io.reticulum.resource.Resource;
|
||||
import static io.reticulum.link.TeardownSession.INITIATOR_CLOSED;
|
||||
import static io.reticulum.link.TeardownSession.DESTINATION_CLOSED;
|
||||
import static io.reticulum.link.TeardownSession.TIMEOUT;
|
||||
import static io.reticulum.link.LinkStatus.ACTIVE;
|
||||
import static io.reticulum.link.LinkStatus.CLOSED;
|
||||
import static io.reticulum.identity.IdentityKnownDestination.recall;
|
||||
//import static io.reticulum.identity.IdentityKnownDestination.recallAppData;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import static org.apache.commons.lang3.ArrayUtils.subarray;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.Setter;
|
||||
import lombok.Data;
|
||||
import lombok.AccessLevel;
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
public class RNSPeer {
|
||||
|
||||
//static final String APP_NAME = "qortal";
|
||||
static final String APP_NAME = RNSCommon.APP_NAME;
|
||||
//static final String defaultConfigPath = new String(".reticulum");
|
||||
static final String defaultConfigPath = RNSCommon.defaultRNSConfigPath;
|
||||
|
||||
private byte[] destinationHash; // remote destination hash
|
||||
Destination peerDestination; // OUT destination created for this
|
||||
private Identity serverIdentity;
|
||||
@Setter(AccessLevel.PACKAGE) private Instant creationTimestamp;
|
||||
private Instant lastAccessTimestamp;
|
||||
Link peerLink;
|
||||
private Boolean isInitiator;
|
||||
private Boolean deleteMe = false;
|
||||
|
||||
private Double requestResponseProgress;
|
||||
@Setter(AccessLevel.PACKAGE) private Boolean peerTimedOut = false;
|
||||
|
||||
public RNSPeer(byte[] dhash) {
|
||||
destinationHash = dhash;
|
||||
serverIdentity = recall(dhash);
|
||||
initPeerLink();
|
||||
//setCreationTimestamp(System.currentTimeMillis());
|
||||
creationTimestamp = Instant.now();
|
||||
}
|
||||
|
||||
public void initPeerLink() {
|
||||
peerDestination = new Destination(
|
||||
this.serverIdentity,
|
||||
Direction.OUT,
|
||||
DestinationType.SINGLE,
|
||||
RNSNetwork.APP_NAME,
|
||||
"core"
|
||||
);
|
||||
peerDestination.setProofStrategy(ProofStrategy.PROVE_ALL);
|
||||
|
||||
lastAccessTimestamp = Instant.now();
|
||||
isInitiator = true;
|
||||
|
||||
peerLink = new Link(peerDestination);
|
||||
|
||||
this.peerLink.setLinkEstablishedCallback(this::linkEstablished);
|
||||
this.peerLink.setLinkClosedCallback(this::linkClosed);
|
||||
this.peerLink.setPacketCallback(this::linkPacketReceived);
|
||||
}
|
||||
|
||||
public Link getOrInitPeerLink() {
|
||||
if (this.peerLink.getStatus() == ACTIVE) {
|
||||
lastAccessTimestamp = Instant.now();
|
||||
return this.peerLink;
|
||||
} else {
|
||||
initPeerLink();
|
||||
}
|
||||
return this.peerLink;
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if (nonNull(peerLink)) {
|
||||
log.info("shutdown - peerLink: {}, status: {}", peerLink, peerLink.getStatus());
|
||||
if (peerLink.getStatus() == ACTIVE) {
|
||||
peerLink.teardown();
|
||||
}
|
||||
this.peerLink = null;
|
||||
}
|
||||
this.deleteMe = true;
|
||||
}
|
||||
|
||||
public Channel getChannel() {
|
||||
if (isNull(getPeerLink())) {
|
||||
log.warn("link is null.");
|
||||
return null;
|
||||
}
|
||||
setLastAccessTimestamp(Instant.now());
|
||||
return getPeerLink().getChannel();
|
||||
}
|
||||
|
||||
/** Link callbacks */
|
||||
public void linkEstablished(Link link) {
|
||||
link.setLinkClosedCallback(this::linkClosed);
|
||||
log.info("peerLink {} established (link: {}) with peer: hash - {}, link destination hash: {}",
|
||||
peerLink, link, Hex.encodeHexString(destinationHash),
|
||||
Hex.encodeHexString(link.getDestination().getHash()));
|
||||
}
|
||||
|
||||
public void linkClosed(Link link) {
|
||||
if (link.getTeardownReason() == TIMEOUT) {
|
||||
log.info("The link timed out");
|
||||
this.peerTimedOut = true;
|
||||
} else if (link.getTeardownReason() == INITIATOR_CLOSED) {
|
||||
log.info("Link closed callback: The initiator closed the link");
|
||||
log.info("peerLink {} closed (link: {}), link destination hash: {}",
|
||||
peerLink, link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
} else if (link.getTeardownReason() == DESTINATION_CLOSED) {
|
||||
log.info("Link closed callback: The link was closed by the peer, removing peer");
|
||||
log.info("peerLink {} closed (link: {}), link destination hash: {}",
|
||||
peerLink, link, Hex.encodeHexString(link.getDestination().getHash()));
|
||||
} else {
|
||||
log.info("Link closed callback");
|
||||
}
|
||||
}
|
||||
|
||||
public void linkPacketReceived(byte[] message, Packet packet) {
|
||||
var msgText = new String(message, StandardCharsets.UTF_8);
|
||||
if (msgText.equals("ping")) {
|
||||
log.info("received ping on link");
|
||||
} else if (msgText.startsWith("close::")) {
|
||||
var targetPeerHash = subarray(message, 7, message.length);
|
||||
log.info("peer dest hash: {}, target hash: {}",
|
||||
Hex.encodeHexString(destinationHash),
|
||||
Hex.encodeHexString(targetPeerHash));
|
||||
if (Arrays.equals(destinationHash, targetPeerHash)) {
|
||||
log.info("closing link: {}", peerLink.getDestination().getHexHash());
|
||||
peerLink.teardown();
|
||||
}
|
||||
} else if (msgText.startsWith("open::")) {
|
||||
var targetPeerHash = subarray(message, 7, message.length);
|
||||
log.info("peer dest hash: {}, target hash: {}",
|
||||
Hex.encodeHexString(destinationHash),
|
||||
Hex.encodeHexString(targetPeerHash));
|
||||
if (Arrays.equals(destinationHash, targetPeerHash)) {
|
||||
log.info("closing link: {}", peerLink.getDestination().getHexHash());
|
||||
getOrInitPeerLink();
|
||||
}
|
||||
}
|
||||
// TODO: process incoming packet....
|
||||
}
|
||||
|
||||
|
||||
/** PacketReceipt callbacks */
|
||||
public void packetDelivered(PacketReceipt receipt) {
|
||||
var rttString = new String("");
|
||||
//log.info("packet delivered callback, receipt: {}", receipt);
|
||||
if (receipt.getStatus() == PacketReceiptStatus.DELIVERED) {
|
||||
var rtt = receipt.getRtt(); // rtt (Java) is in miliseconds
|
||||
//log.info("qqp - packetDelivered - rtt: {}", rtt);
|
||||
if (rtt >= 1000) {
|
||||
rtt = Math.round(rtt / 1000);
|
||||
rttString = String.format("%d seconds", rtt);
|
||||
} else {
|
||||
rttString = String.format("%d miliseconds", rtt);
|
||||
}
|
||||
log.info("Valid reply received from {}, round-trip time is {}",
|
||||
Hex.encodeHexString(receipt.getDestination().getHash()), rttString);
|
||||
}
|
||||
}
|
||||
|
||||
public void packetTimedOut(PacketReceipt receipt) {
|
||||
log.info("packet timed out, receipt status: {}", receipt.getStatus());
|
||||
if (receipt.getStatus() == PacketReceiptStatus.FAILED) {
|
||||
this.peerTimedOut = true;
|
||||
this.peerLink.teardown();
|
||||
}
|
||||
}
|
||||
|
||||
/** Link Request callbacks */
|
||||
public void linkRequestResponseReceived(RequestReceipt rr) {
|
||||
log.info("Response received");
|
||||
}
|
||||
|
||||
public void linkRequestResponseProgress(RequestReceipt rr) {
|
||||
this.requestResponseProgress = rr.getProgress();
|
||||
log.debug("Response progress set");
|
||||
}
|
||||
|
||||
public void linkRequestFailed(RequestReceipt rr) {
|
||||
log.error("Request failed");
|
||||
}
|
||||
|
||||
/** Link Resource callbacks */
|
||||
// Resource: allow arbitrary amounts of data to be passed over a link with
|
||||
// sequencing, compression, coordination and checksumming handled automatically
|
||||
//public Boolean linkResourceAdvertised(Resource resource) {
|
||||
// log.debug("Resource advertised");
|
||||
//}
|
||||
public void linkResourceTransferStarted(Resource resource) {
|
||||
log.debug("Resource transfer started");
|
||||
}
|
||||
public void linkResourceTransferComcluded(Resource resource) {
|
||||
log.debug("Resource transfer complete");
|
||||
}
|
||||
|
||||
/** Utility methods */
|
||||
public void pingRemote() {
|
||||
var link = this.peerLink;
|
||||
if (nonNull(link)) {
|
||||
if (peerLink.getStatus() == ACTIVE) {
|
||||
log.info("pinging remote: {}", link);
|
||||
var data = "ping".getBytes(UTF_8);
|
||||
link.setPacketCallback(this::linkPacketReceived);
|
||||
Packet pingPacket = new Packet(link, data);
|
||||
PacketReceipt packetReceipt = pingPacket.send();
|
||||
// Note: don't setTimeout, we want it to timeout with FAIL if not deliverable
|
||||
//packetReceipt.setTimeout(5000L);
|
||||
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
||||
packetReceipt.setDeliveryCallback(this::packetDelivered);
|
||||
} else {
|
||||
log.info("can't send ping to a peer {} with (link) status: {}",
|
||||
Hex.encodeHexString(peerLink.getDestination().getHash()), peerLink.getStatus());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//public void shutdownLink(Link link) {
|
||||
// var data = "shutdown".getBytes(UTF_8);
|
||||
// Packet shutdownPacket = new Packet(link, data);
|
||||
// PacketReceipt packetReceipt = shutdownPacket.send();
|
||||
// packetReceipt.setTimeout(2000L);
|
||||
// packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
||||
// packetReceipt.setDeliveryCallback(this::shutdownPacketDelivered);
|
||||
//}
|
||||
|
||||
///** check if a link is available (ACTIVE)
|
||||
// * link: a certain peer link, or null (default link == link to Qortal node RNS baseDestination)
|
||||
// */
|
||||
//public Boolean peerLinkIsAlive(Link link) {
|
||||
// var result = false;
|
||||
// if (isNull(link)) {
|
||||
// // default link
|
||||
// var defaultLink = getLink();
|
||||
// if (nonNull(defaultLink) && defaultLink.getStatus() == ACTIVE) {
|
||||
// result = true;
|
||||
// log.info("Default link is available");
|
||||
// } else {
|
||||
// log.info("Default link {} is not available, status: {}", defaultLink, defaultLink.getStatus());
|
||||
// }
|
||||
// } else {
|
||||
// // other link (future where we have multiple destinations...)
|
||||
// if (link.getStatus() == ACTIVE) {
|
||||
// result = true;
|
||||
// log.info("Link {} is available (status: {})", link, link.getStatus());
|
||||
// } else {
|
||||
// log.info("Link {} is not available, status: {}", link, link.getStatus());
|
||||
// }
|
||||
// }
|
||||
// return result;
|
||||
//}
|
||||
|
||||
}
|
@ -4,15 +4,10 @@ import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.network.Network;
|
||||
import org.qortal.network.Peer;
|
||||
import org.qortal.utils.DaemonThreadFactory;
|
||||
import org.qortal.utils.ExecuteProduceConsume.Task;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class PeerConnectTask implements Task {
|
||||
private static final Logger LOGGER = LogManager.getLogger(PeerConnectTask.class);
|
||||
private static final ExecutorService connectionExecutor = Executors.newCachedThreadPool(new DaemonThreadFactory(8));
|
||||
|
||||
private final Peer peer;
|
||||
private final String name;
|
||||
@ -29,24 +24,6 @@ public class PeerConnectTask implements Task {
|
||||
|
||||
@Override
|
||||
public void perform() throws InterruptedException {
|
||||
// Submit connection task to a dedicated thread pool for non-blocking I/O
|
||||
connectionExecutor.submit(() -> {
|
||||
try {
|
||||
connectPeerAsync(peer);
|
||||
} catch (InterruptedException e) {
|
||||
LOGGER.error("Connection attempt interrupted for peer {}", peer, e);
|
||||
Thread.currentThread().interrupt(); // Reset interrupt flag
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void connectPeerAsync(Peer peer) throws InterruptedException {
|
||||
// Perform peer connection in a separate thread to avoid blocking main task execution
|
||||
try {
|
||||
Network.getInstance().connectPeer(peer);
|
||||
LOGGER.trace("Successfully connected to peer {}", peer);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Error connecting to peer {}", peer, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,7 @@ package org.qortal.repository;
|
||||
import org.qortal.data.account.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public interface AccountRepository {
|
||||
|
||||
@ -133,41 +131,6 @@ public interface AccountRepository {
|
||||
/** Returns all account balances for given assetID, optionally excluding zero balances. */
|
||||
public List<AccountBalanceData> getAssetBalances(long assetId, Boolean excludeZero) throws DataException;
|
||||
|
||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsorship Report
|
||||
*
|
||||
* @param address the account address
|
||||
* @param addressFetcher fetches the addresses that this method will aggregate
|
||||
* @return the report
|
||||
* @throws DataException
|
||||
*/
|
||||
public SponsorshipReport getMintershipReport(String address, Function<String, List<String>> addressFetcher) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsee Addresses
|
||||
*
|
||||
* @param account the sponsor's account address
|
||||
* @param realRewardShareRecipients the recipients that get real reward shares, not sponsorship
|
||||
* @return the sponsee addresses
|
||||
* @throws DataException
|
||||
*/
|
||||
public List<String> getSponseeAddresses(String account, String[] realRewardShareRecipients) throws DataException;
|
||||
|
||||
/**
|
||||
* Get Sponsor
|
||||
*
|
||||
* @param address the address of the account
|
||||
*
|
||||
* @return the address of accounts sponsor, empty if not sponsored
|
||||
*
|
||||
* @throws DataException
|
||||
*/
|
||||
public Optional<String> getSponsor(String address) throws DataException;
|
||||
|
||||
public List<AddressLevelPairing> getAddressLevelPairings(int minLevel) throws DataException;
|
||||
|
||||
/** How to order results when fetching asset balances. */
|
||||
public enum BalanceOrdering {
|
||||
/** assetID first, then balance, then account address */
|
||||
|
@ -44,17 +44,6 @@ public interface ArbitraryRepository {
|
||||
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, boolean prefixOnly, List<String> namesFilter, boolean defaultResource, SearchMode mode, Integer minLevel, Boolean followedOnly, Boolean excludeBlocked, Boolean includeMetadata, Boolean includeStatus, Long before, Long after, Integer limit, Integer offset, Boolean reverse) throws DataException;
|
||||
|
||||
List<ArbitraryResourceData> searchArbitraryResourcesSimple(
|
||||
Service service,
|
||||
String identifier,
|
||||
List<String> names,
|
||||
boolean prefixOnly,
|
||||
Long before,
|
||||
Long after,
|
||||
Integer limit,
|
||||
Integer offset,
|
||||
Boolean reverse,
|
||||
Boolean caseInsensitive) throws DataException;
|
||||
|
||||
// Arbitrary resources cache save/load
|
||||
|
||||
|
@ -153,16 +153,13 @@ public class BlockArchiveWriter {
|
||||
int i = 0;
|
||||
while (headerBytes.size() + bytes.size() < this.fileSizeTarget) {
|
||||
|
||||
// pause, since this can be a long process and other processes need to execute
|
||||
Thread.sleep(Settings.getInstance().getArchivingPause());
|
||||
|
||||
if (Controller.isStopping()) {
|
||||
return BlockArchiveWriteResult.STOPPING;
|
||||
}
|
||||
|
||||
// wait until the Synchronizer stops
|
||||
if( Synchronizer.getInstance().isSynchronizing() )
|
||||
if (Synchronizer.getInstance().isSynchronizing()) {
|
||||
Thread.sleep(1000L);
|
||||
continue;
|
||||
}
|
||||
|
||||
int currentHeight = startHeight + i;
|
||||
if (currentHeight > endHeight) {
|
||||
|
@ -22,6 +22,6 @@ public interface ChatRepository {
|
||||
|
||||
public ChatMessage toChatMessage(ChatTransactionData chatTransactionData, Encoding encoding) throws DataException;
|
||||
|
||||
public ActiveChats getActiveChats(String address, Encoding encoding, Boolean hasChatReference) throws DataException;
|
||||
public ActiveChats getActiveChats(String address, Encoding encoding) throws DataException;
|
||||
|
||||
}
|
||||
|
@ -1,213 +0,0 @@
|
||||
package org.qortal.repository;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.block.Block;
|
||||
import org.qortal.block.GenesisBlock;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.data.block.BlockArchiveData;
|
||||
import org.qortal.data.block.BlockData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.transaction.Transaction;
|
||||
import org.qortal.transform.block.BlockTransformation;
|
||||
import org.qortal.utils.Base58;
|
||||
import org.qortal.utils.NTP;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
public class ReindexManager {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(ReindexManager.class);
|
||||
|
||||
private Repository repository;
|
||||
|
||||
private final int pruneAndTrimBlockInterval = 2000;
|
||||
private final int maintenanceBlockInterval = 50000;
|
||||
|
||||
private boolean resume = false;
|
||||
|
||||
public ReindexManager() {
|
||||
|
||||
}
|
||||
|
||||
public void reindex() throws DataException {
|
||||
try {
|
||||
this.runPreChecks();
|
||||
this.rebuildRepository();
|
||||
|
||||
try (final Repository repository = RepositoryManager.getRepository()) {
|
||||
this.repository = repository;
|
||||
this.requestCheckpoint();
|
||||
this.processGenesisBlock();
|
||||
this.processBlocks();
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
throw new DataException("Interrupted before complete");
|
||||
}
|
||||
}
|
||||
|
||||
private void runPreChecks() throws DataException, InterruptedException {
|
||||
LOGGER.info("Running pre-checks...");
|
||||
if (Settings.getInstance().isTopOnly()) {
|
||||
throw new DataException("Reindexing not supported in top-only mode. Please bootstrap or resync from genesis.");
|
||||
}
|
||||
if (Settings.getInstance().isLite()) {
|
||||
throw new DataException("Reindexing not supported in lite mode.");
|
||||
}
|
||||
|
||||
while (NTP.getTime() == null) {
|
||||
LOGGER.info("Waiting for NTP...");
|
||||
Thread.sleep(5000L);
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildRepository() throws DataException {
|
||||
if (resume) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Rebuilding repository...");
|
||||
RepositoryManager.rebuild();
|
||||
}
|
||||
|
||||
private void requestCheckpoint() {
|
||||
RepositoryManager.setRequestedCheckpoint(Boolean.TRUE);
|
||||
}
|
||||
|
||||
private void processGenesisBlock() throws DataException, InterruptedException {
|
||||
if (resume) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOGGER.info("Processing genesis block...");
|
||||
|
||||
GenesisBlock genesisBlock = GenesisBlock.getInstance(repository);
|
||||
|
||||
// Add Genesis Block to blockchain
|
||||
genesisBlock.process();
|
||||
|
||||
this.repository.saveChanges();
|
||||
}
|
||||
|
||||
private void processBlocks() throws DataException {
|
||||
LOGGER.info("Processing blocks...");
|
||||
|
||||
int height = this.repository.getBlockRepository().getBlockchainHeight();
|
||||
while (true) {
|
||||
height++;
|
||||
|
||||
boolean processed = this.processBlock(height);
|
||||
if (!processed) {
|
||||
LOGGER.info("Block {} couldn't be processed. If this is the last archived block, then the process is complete.", height);
|
||||
break; // TODO: check if complete
|
||||
}
|
||||
|
||||
// Prune and trim regularly, leaving a buffer
|
||||
if (height >= pruneAndTrimBlockInterval*2 && height % pruneAndTrimBlockInterval == 0) {
|
||||
int startHeight = Math.max(height - pruneAndTrimBlockInterval*2, 2);
|
||||
int endHeight = height - pruneAndTrimBlockInterval;
|
||||
LOGGER.info("Pruning and trimming blocks {} to {}...", startHeight, endHeight);
|
||||
this.repository.getATRepository().rebuildLatestAtStates(height - 250);
|
||||
this.repository.saveChanges();
|
||||
this.prune(startHeight, endHeight);
|
||||
this.trim(startHeight, endHeight);
|
||||
}
|
||||
|
||||
// Run repository maintenance regularly, to keep blockchain.data size down
|
||||
if (height % maintenanceBlockInterval == 0) {
|
||||
this.runRepositoryMaintenance();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean processBlock(int height) throws DataException {
|
||||
Block block = this.fetchBlock(height);
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Transactions are stored without approval status so determine that now
|
||||
for (Transaction transaction : block.getTransactions())
|
||||
transaction.setInitialApprovalStatus();
|
||||
|
||||
// It's best not to run preProcess() until there is a reason to
|
||||
// block.preProcess();
|
||||
|
||||
Block.ValidationResult validationResult = block.isValid();
|
||||
if (validationResult != Block.ValidationResult.OK) {
|
||||
throw new DataException(String.format("Invalid block at height %d: %s", height, validationResult));
|
||||
}
|
||||
|
||||
// Save transactions attached to this block
|
||||
for (Transaction transaction : block.getTransactions()) {
|
||||
TransactionData transactionData = transaction.getTransactionData();
|
||||
this.repository.getTransactionRepository().save(transactionData);
|
||||
}
|
||||
|
||||
block.process();
|
||||
|
||||
LOGGER.info(String.format("Reindexed block height %d, sig %.8s", block.getBlockData().getHeight(), Base58.encode(block.getBlockData().getSignature())));
|
||||
|
||||
// Add to block archive table, since this originated from the archive but the chainstate has to be rebuilt
|
||||
this.addToBlockArchive(block.getBlockData());
|
||||
|
||||
this.repository.saveChanges();
|
||||
|
||||
Controller.getInstance().onNewBlock(block.getBlockData());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Block fetchBlock(int height) {
|
||||
BlockTransformation b = BlockArchiveReader.getInstance().fetchBlockAtHeight(height);
|
||||
if (b != null) {
|
||||
if (b.getAtStatesHash() != null) {
|
||||
return new Block(this.repository, b.getBlockData(), b.getTransactions(), b.getAtStatesHash());
|
||||
}
|
||||
else {
|
||||
return new Block(this.repository, b.getBlockData(), b.getTransactions(), b.getAtStates());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addToBlockArchive(BlockData blockData) throws DataException {
|
||||
// Write the signature and height into the BlockArchive table
|
||||
BlockArchiveData blockArchiveData = new BlockArchiveData(blockData);
|
||||
this.repository.getBlockArchiveRepository().save(blockArchiveData);
|
||||
this.repository.getBlockArchiveRepository().setBlockArchiveHeight(blockData.getHeight()+1);
|
||||
this.repository.saveChanges();
|
||||
}
|
||||
|
||||
private void prune(int startHeight, int endHeight) throws DataException {
|
||||
this.repository.getBlockRepository().pruneBlocks(startHeight, endHeight);
|
||||
this.repository.getATRepository().pruneAtStates(startHeight, endHeight);
|
||||
this.repository.getATRepository().setAtPruneHeight(endHeight+1);
|
||||
this.repository.saveChanges();
|
||||
}
|
||||
|
||||
private void trim(int startHeight, int endHeight) throws DataException {
|
||||
this.repository.getBlockRepository().trimOldOnlineAccountsSignatures(startHeight, endHeight);
|
||||
|
||||
int count = 1; // Any number greater than 0
|
||||
while (count > 0) {
|
||||
count = this.repository.getATRepository().trimAtStates(startHeight, endHeight, Settings.getInstance().getAtStatesTrimLimit());
|
||||
}
|
||||
|
||||
this.repository.getBlockRepository().setBlockPruneHeight(endHeight+1);
|
||||
this.repository.getATRepository().setAtTrimHeight(endHeight+1);
|
||||
this.repository.saveChanges();
|
||||
}
|
||||
|
||||
private void runRepositoryMaintenance() throws DataException {
|
||||
try {
|
||||
this.repository.performPeriodicMaintenance(1000L);
|
||||
} catch (TimeoutException e) {
|
||||
LOGGER.info("Timed out waiting for repository before running maintenance");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
package org.qortal.repository.hsqldb;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.data.account.*;
|
||||
import org.qortal.repository.AccountRepository;
|
||||
@ -10,28 +8,20 @@ import org.qortal.repository.DataException;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.qortal.utils.Amounts.prettyAmount;
|
||||
|
||||
public class HSQLDBAccountRepository implements AccountRepository {
|
||||
|
||||
public static final String SELL = "sell";
|
||||
public static final String BUY = "buy";
|
||||
protected HSQLDBRepository repository;
|
||||
|
||||
public HSQLDBAccountRepository(HSQLDBRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
protected static final Logger LOGGER = LogManager.getLogger(HSQLDBAccountRepository.class);
|
||||
// General account
|
||||
|
||||
@Override
|
||||
@ -1157,389 +1147,4 @@ public class HSQLDBAccountRepository implements AccountRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SponsorshipReport getSponsorshipReport(String address, String[] realRewardShareRecipients) throws DataException {
|
||||
|
||||
List<String> sponsees = getSponseeAddresses(address, realRewardShareRecipients);
|
||||
|
||||
return getMintershipReport(address, account -> sponsees);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SponsorshipReport getMintershipReport(String account, Function<String, List<String>> addressFetcher) throws DataException {
|
||||
|
||||
try {
|
||||
ResultSet accountResultSet = getAccountResultSet(account);
|
||||
|
||||
if( accountResultSet == null ) throw new DataException("Unable to fetch account info from repository");
|
||||
|
||||
int level = accountResultSet.getInt(2);
|
||||
int blocksMinted = accountResultSet.getInt(3);
|
||||
int adjustments = accountResultSet.getInt(4);
|
||||
int penalties = accountResultSet.getInt(5);
|
||||
boolean transferPrivs = accountResultSet.getBoolean(6);
|
||||
|
||||
List<String> sponseeAddresses = addressFetcher.apply(account);
|
||||
|
||||
if( sponseeAddresses.isEmpty() ){
|
||||
return new SponsorshipReport(account, level, blocksMinted, adjustments, penalties, transferPrivs, new String[0], 0, 0,0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
else {
|
||||
return produceSponsorShipReport(account, level, blocksMinted, adjustments, penalties, sponseeAddresses, transferPrivs);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
throw new DataException("Unable to fetch account info from repository", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSponseeAddresses(String account, String[] realRewardShareRecipients) throws DataException {
|
||||
StringBuffer sponseeSql = new StringBuffer();
|
||||
|
||||
sponseeSql.append( "SELECT DISTINCT t.recipient sponsees " );
|
||||
sponseeSql.append( "FROM REWARDSHARETRANSACTIONS t ");
|
||||
sponseeSql.append( "INNER JOIN ACCOUNTS a on t.minter_public_key = a.public_key ");
|
||||
sponseeSql.append( "WHERE account = ? and t.recipient != a.account");
|
||||
|
||||
try {
|
||||
ResultSet sponseeResultSet;
|
||||
|
||||
// if there are real reward share recipeints to exclude
|
||||
if (realRewardShareRecipients != null && realRewardShareRecipients.length > 0) {
|
||||
|
||||
// add constraint to where clause
|
||||
sponseeSql.append(" and t.recipient NOT IN (");
|
||||
sponseeSql.append(String.join(", ", Collections.nCopies(realRewardShareRecipients.length, "?")));
|
||||
sponseeSql.append(")");
|
||||
|
||||
// Create a new array to hold both
|
||||
Object[] combinedArray = new Object[realRewardShareRecipients.length + 1];
|
||||
|
||||
// Add the single string to the first position
|
||||
combinedArray[0] = account;
|
||||
|
||||
// Copy the elements from realRewardShareRecipients to the combinedArray starting from index 1
|
||||
System.arraycopy(realRewardShareRecipients, 0, combinedArray, 1, realRewardShareRecipients.length);
|
||||
|
||||
sponseeResultSet = this.repository.checkedExecute(sponseeSql.toString(), combinedArray);
|
||||
}
|
||||
else {
|
||||
sponseeResultSet = this.repository.checkedExecute(sponseeSql.toString(), account);
|
||||
}
|
||||
|
||||
List<String> sponseeAddresses;
|
||||
|
||||
if( sponseeResultSet == null ) {
|
||||
sponseeAddresses = new ArrayList<>(0);
|
||||
}
|
||||
else {
|
||||
sponseeAddresses = new ArrayList<>();
|
||||
|
||||
do {
|
||||
sponseeAddresses.add(sponseeResultSet.getString(1));
|
||||
} while (sponseeResultSet.next());
|
||||
}
|
||||
|
||||
return sponseeAddresses;
|
||||
}
|
||||
catch (SQLException e) {
|
||||
throw new DataException("can't get sponsees from blockchain data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getSponsor(String address) throws DataException {
|
||||
|
||||
StringBuffer sponsorSql = new StringBuffer();
|
||||
|
||||
sponsorSql.append( "SELECT DISTINCT account, level, blocks_minted, blocks_minted_adjustment, blocks_minted_penalty ");
|
||||
sponsorSql.append( "FROM REWARDSHARETRANSACTIONS t ");
|
||||
sponsorSql.append( "INNER JOIN ACCOUNTS a on a.public_key = t.minter_public_key ");
|
||||
sponsorSql.append( "WHERE recipient = ? and recipient != account ");
|
||||
|
||||
try {
|
||||
ResultSet sponseeResultSet = this.repository.checkedExecute(sponsorSql.toString(), address);
|
||||
|
||||
if( sponseeResultSet == null ){
|
||||
return Optional.empty();
|
||||
}
|
||||
else {
|
||||
return Optional.ofNullable( sponseeResultSet.getString(1));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("can't get sponsor from blockchain data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AddressLevelPairing> getAddressLevelPairings(int minLevel) throws DataException {
|
||||
|
||||
StringBuffer accLevelSql = new StringBuffer(51);
|
||||
|
||||
accLevelSql.append( "SELECT account,level FROM ACCOUNTS WHERE level >= ?" );
|
||||
|
||||
try {
|
||||
ResultSet accountLevelResultSet = this.repository.checkedExecute(accLevelSql.toString(),minLevel);
|
||||
|
||||
List<AddressLevelPairing> addressLevelPairings;
|
||||
|
||||
if( accountLevelResultSet == null ) {
|
||||
addressLevelPairings = new ArrayList<>(0);
|
||||
}
|
||||
else {
|
||||
addressLevelPairings = new ArrayList<>();
|
||||
|
||||
do {
|
||||
AddressLevelPairing pairing
|
||||
= new AddressLevelPairing(
|
||||
accountLevelResultSet.getString(1),
|
||||
accountLevelResultSet.getInt(2)
|
||||
);
|
||||
addressLevelPairings.add(pairing);
|
||||
} while (accountLevelResultSet.next());
|
||||
}
|
||||
return addressLevelPairings;
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("Can't get addresses for this level from blockchain data", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce Sponsorship Report
|
||||
*
|
||||
* @param address the account address for the sponsor
|
||||
* @param level the sponsor's level
|
||||
* @param blocksMinted the blocks minted by the sponsor
|
||||
* @param blocksMintedAdjustment
|
||||
* @param blocksMintedPenalty
|
||||
* @param sponseeAddresses
|
||||
* @param transferPrivs true if this account was involved in a TRANSFER_PRIVS transaction
|
||||
* @return the report
|
||||
* @throws SQLException
|
||||
*/
|
||||
private SponsorshipReport produceSponsorShipReport(
|
||||
String address,
|
||||
int level,
|
||||
int blocksMinted,
|
||||
int blocksMintedAdjustment,
|
||||
int blocksMintedPenalty,
|
||||
List<String> sponseeAddresses,
|
||||
boolean transferPrivs) throws SQLException, DataException {
|
||||
|
||||
int sponseeCount = sponseeAddresses.size();
|
||||
|
||||
// get the registered names of the sponsees
|
||||
ResultSet namesResultSet = getNamesResultSet(sponseeAddresses, sponseeCount);
|
||||
|
||||
List<String> sponseeNames;
|
||||
|
||||
if( namesResultSet != null ) {
|
||||
sponseeNames = getNames(namesResultSet, sponseeCount);
|
||||
}
|
||||
else {
|
||||
sponseeNames = new ArrayList<>(0);
|
||||
}
|
||||
|
||||
// get the average balance of the sponsees
|
||||
ResultSet avgBalanceResultSet = getAverageBalanceResultSet(sponseeAddresses, sponseeCount);
|
||||
int avgBalance = avgBalanceResultSet.getInt(1);
|
||||
|
||||
// count the arbitrary and transfer asset transactions for all sponsees
|
||||
ResultSet txTypeResultSet = getTxTypeResultSet(sponseeAddresses, sponseeCount);
|
||||
|
||||
int arbitraryCount;
|
||||
int transferAssetCount;
|
||||
int transferPrivsCount;
|
||||
|
||||
if( txTypeResultSet != null) {
|
||||
|
||||
Map<Integer, Integer> countsByType = new HashMap<>(2);
|
||||
|
||||
do{
|
||||
Integer type = txTypeResultSet.getInt(1);
|
||||
|
||||
if( type != null ) {
|
||||
countsByType.put(type, txTypeResultSet.getInt(2));
|
||||
}
|
||||
} while( txTypeResultSet.next());
|
||||
|
||||
arbitraryCount = countsByType.getOrDefault(10, 0);
|
||||
transferAssetCount = countsByType.getOrDefault(12, 0);
|
||||
transferPrivsCount = countsByType.getOrDefault(40, 0);
|
||||
}
|
||||
// no rows -> no counts
|
||||
else {
|
||||
arbitraryCount = 0;
|
||||
transferAssetCount = 0;
|
||||
transferPrivsCount = 0;
|
||||
}
|
||||
|
||||
ResultSet sellResultSet = getSellResultSet(sponseeAddresses, sponseeCount);
|
||||
|
||||
int sellCount;
|
||||
int sellAmount;
|
||||
|
||||
// if there are sell results, then fill in the sell amount/counts
|
||||
if( sellResultSet != null ) {
|
||||
sellCount = sellResultSet.getInt(1);
|
||||
sellAmount = sellResultSet.getInt(2);
|
||||
}
|
||||
// no rows -> no counts/amounts
|
||||
else {
|
||||
sellCount = 0;
|
||||
sellAmount = 0;
|
||||
}
|
||||
|
||||
ResultSet buyResultSet = getBuyResultSet(sponseeAddresses, sponseeCount);
|
||||
|
||||
int buyCount;
|
||||
int buyAmount;
|
||||
|
||||
// if there are buy results, then fill in the buy amount/counts
|
||||
if( buyResultSet != null ) {
|
||||
buyCount = buyResultSet.getInt(1);
|
||||
buyAmount = buyResultSet.getInt(2);
|
||||
}
|
||||
// no rows -> no counts/amounts
|
||||
else {
|
||||
buyCount = 0;
|
||||
buyAmount = 0;
|
||||
}
|
||||
|
||||
return new SponsorshipReport(
|
||||
address,
|
||||
level,
|
||||
blocksMinted,
|
||||
blocksMintedAdjustment,
|
||||
blocksMintedPenalty,
|
||||
transferPrivs,
|
||||
sponseeNames.toArray(new String[sponseeNames.size()]),
|
||||
sponseeCount,
|
||||
sponseeCount - sponseeNames.size(),
|
||||
avgBalance,
|
||||
arbitraryCount,
|
||||
transferAssetCount,
|
||||
transferPrivsCount,
|
||||
sellCount,
|
||||
sellAmount,
|
||||
buyCount,
|
||||
buyAmount);
|
||||
}
|
||||
|
||||
private ResultSet getBuyResultSet(List<String> addresses, int addressCount) throws SQLException {
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT COUNT(*) count, SUM(amount)/100000000 amount ");
|
||||
sql.append("FROM ACCOUNTS a ");
|
||||
sql.append("INNER JOIN ATTRANSACTIONS tx ON tx.recipient = a.account ");
|
||||
sql.append("INNER JOIN ATS ats ON ats.at_address = tx.at_address ");
|
||||
sql.append("WHERE a.account IN ( ");
|
||||
sql.append(String.join(", ", Collections.nCopies(addressCount, "?")));
|
||||
sql.append(") ");
|
||||
sql.append("AND a.account = tx.recipient AND a.public_key != ats.creator AND asset_id = 0 ");
|
||||
Object[] sponsees = addresses.toArray(new Object[addressCount]);
|
||||
ResultSet buySellResultSet = this.repository.checkedExecute(sql.toString(), sponsees);
|
||||
|
||||
return buySellResultSet;
|
||||
}
|
||||
|
||||
private ResultSet getSellResultSet(List<String> addresses, int addressCount) throws SQLException {
|
||||
|
||||
StringBuffer sql = new StringBuffer();
|
||||
sql.append("SELECT COUNT(*) count, SUM(amount)/100000000 amount ");
|
||||
sql.append("FROM ATS ats ");
|
||||
sql.append("INNER JOIN ACCOUNTS a ON a.public_key = ats.creator ");
|
||||
sql.append("INNER JOIN ATTRANSACTIONS tx ON tx.at_address = ats.at_address ");
|
||||
sql.append("WHERE a.account IN ( ");
|
||||
sql.append(String.join(", ", Collections.nCopies(addressCount, "?")));
|
||||
sql.append(") ");
|
||||
sql.append("AND a.account != tx.recipient AND asset_id = 0 ");
|
||||
Object[] sponsees = addresses.toArray(new Object[addressCount]);
|
||||
|
||||
return this.repository.checkedExecute(sql.toString(), sponsees);
|
||||
}
|
||||
|
||||
private ResultSet getAccountResultSet(String account) throws SQLException {
|
||||
|
||||
StringBuffer accountSql = new StringBuffer();
|
||||
|
||||
accountSql.append( "SELECT DISTINCT a.account, a.level, a.blocks_minted, a.blocks_minted_adjustment, a.blocks_minted_penalty, tx.sender IS NOT NULL as transfer ");
|
||||
accountSql.append( "FROM ACCOUNTS a ");
|
||||
accountSql.append( "LEFT JOIN TRANSFERPRIVSTRANSACTIONS tx on a.public_key = tx.sender or a.account = tx.recipient ");
|
||||
accountSql.append( "WHERE account = ? ");
|
||||
|
||||
ResultSet accountResultSet = this.repository.checkedExecute( accountSql.toString(), account);
|
||||
|
||||
return accountResultSet;
|
||||
}
|
||||
|
||||
|
||||
private ResultSet getTxTypeResultSet(List<String> sponseeAddresses, int sponseeCount) throws SQLException {
|
||||
StringBuffer txTypeTotalsSql = new StringBuffer();
|
||||
// Transaction Types, int values
|
||||
// ARBITRARY = 10
|
||||
// TRANSFER_ASSET = 12
|
||||
// txTypeTotalsSql.append("
|
||||
txTypeTotalsSql.append("SELECT type, count(*) ");
|
||||
txTypeTotalsSql.append("FROM TRANSACTIONPARTICIPANTS ");
|
||||
txTypeTotalsSql.append("INNER JOIN TRANSACTIONS USING (signature) ");
|
||||
txTypeTotalsSql.append("where participant in ( ");
|
||||
txTypeTotalsSql.append(String.join(", ", Collections.nCopies(sponseeCount, "?")));
|
||||
txTypeTotalsSql.append(") and type in (10, 12, 40) ");
|
||||
txTypeTotalsSql.append("group by type order by type");
|
||||
|
||||
Object[] sponsees = sponseeAddresses.toArray(new Object[sponseeCount]);
|
||||
ResultSet txTypeResultSet = this.repository.checkedExecute(txTypeTotalsSql.toString(), sponsees);
|
||||
return txTypeResultSet;
|
||||
}
|
||||
|
||||
private ResultSet getAverageBalanceResultSet(List<String> sponseeAddresses, int sponseeCount) throws SQLException {
|
||||
StringBuffer avgBalanceSql = new StringBuffer();
|
||||
avgBalanceSql.append("SELECT avg(balance)/100000000 FROM ACCOUNTBALANCES ");
|
||||
avgBalanceSql.append("WHERE account in (");
|
||||
avgBalanceSql.append(String.join(", ", Collections.nCopies(sponseeCount, "?")));
|
||||
avgBalanceSql.append(") and ASSET_ID = 0");
|
||||
|
||||
Object[] sponsees = sponseeAddresses.toArray(new Object[sponseeCount]);
|
||||
return this.repository.checkedExecute(avgBalanceSql.toString(), sponsees);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Names
|
||||
*
|
||||
* @param namesResultSet the result set to get the names from, can't be null
|
||||
* @param count the number of potential names
|
||||
*
|
||||
* @return the names
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
private static List<String> getNames(ResultSet namesResultSet, int count) throws SQLException {
|
||||
|
||||
List<String> names = new ArrayList<>(count);
|
||||
|
||||
do{
|
||||
String name = namesResultSet.getString(1);
|
||||
|
||||
if( name != null ) {
|
||||
names.add(name);
|
||||
}
|
||||
} while( namesResultSet.next() );
|
||||
|
||||
return names;
|
||||
}
|
||||
|
||||
private ResultSet getNamesResultSet(List<String> sponseeAddresses, int sponseeCount) throws SQLException {
|
||||
StringBuffer namesSql = new StringBuffer();
|
||||
namesSql.append("SELECT name FROM NAMES ");
|
||||
namesSql.append("WHERE owner in (");
|
||||
namesSql.append(String.join(", ", Collections.nCopies(sponseeCount, "?")));
|
||||
namesSql.append(")");
|
||||
|
||||
Object[] sponsees = sponseeAddresses.toArray(new Object[sponseeCount]);
|
||||
ResultSet namesResultSet = this.repository.checkedExecute(namesSql.toString(), sponsees);
|
||||
return namesResultSet;
|
||||
}
|
||||
}
|
@ -7,8 +7,6 @@ import org.qortal.arbitrary.ArbitraryDataFile;
|
||||
import org.qortal.arbitrary.metadata.ArbitraryDataTransactionMetadata;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.arbitrary.ArbitraryDataManager;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceCache;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceData;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceMetadata;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
@ -20,7 +18,6 @@ import org.qortal.data.transaction.BaseTransactionData;
|
||||
import org.qortal.data.transaction.TransactionData;
|
||||
import org.qortal.repository.ArbitraryRepository;
|
||||
import org.qortal.repository.DataException;
|
||||
import org.qortal.settings.Settings;
|
||||
import org.qortal.transaction.ArbitraryTransaction;
|
||||
import org.qortal.transaction.Transaction.ApprovalStatus;
|
||||
import org.qortal.utils.Base58;
|
||||
@ -31,7 +28,6 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
|
||||
@ -727,50 +723,6 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
public List<ArbitraryResourceData> searchArbitraryResources(Service service, String query, String identifier, List<String> names, String title, String description, boolean prefixOnly,
|
||||
List<String> exactMatchNames, boolean defaultResource, SearchMode mode, Integer minLevel, Boolean followedOnly, Boolean excludeBlocked,
|
||||
Boolean includeMetadata, Boolean includeStatus, Long before, Long after, Integer limit, Integer offset, Boolean reverse) throws DataException {
|
||||
|
||||
if(Settings.getInstance().isDbCacheEnabled()) {
|
||||
|
||||
List<ArbitraryResourceData> list
|
||||
= HSQLDBCacheUtils.callCache(
|
||||
ArbitraryResourceCache.getInstance(),
|
||||
service, query, identifier, names, title, description, prefixOnly, exactMatchNames,
|
||||
defaultResource, mode, minLevel, followedOnly, excludeBlocked, includeMetadata, includeStatus,
|
||||
before, after, limit, offset, reverse);
|
||||
|
||||
if( !list.isEmpty() ) {
|
||||
List<ArbitraryResourceData> results
|
||||
= HSQLDBCacheUtils.filterList(
|
||||
list,
|
||||
ArbitraryResourceCache.getInstance().getLevelByName(),
|
||||
Optional.ofNullable(mode),
|
||||
Optional.ofNullable(service),
|
||||
Optional.ofNullable(query),
|
||||
Optional.ofNullable(identifier),
|
||||
Optional.ofNullable(names),
|
||||
Optional.ofNullable(title),
|
||||
Optional.ofNullable(description),
|
||||
prefixOnly,
|
||||
Optional.ofNullable(exactMatchNames),
|
||||
defaultResource,
|
||||
Optional.ofNullable(minLevel),
|
||||
Optional.ofNullable(() -> ListUtils.followedNames()),
|
||||
Optional.ofNullable(ListUtils::blockedNames),
|
||||
Optional.ofNullable(includeMetadata),
|
||||
Optional.ofNullable(includeStatus),
|
||||
Optional.ofNullable(before),
|
||||
Optional.ofNullable(after),
|
||||
Optional.ofNullable(limit),
|
||||
Optional.ofNullable(offset),
|
||||
Optional.ofNullable(reverse)
|
||||
);
|
||||
|
||||
return results;
|
||||
}
|
||||
else {
|
||||
LOGGER.info("Db Enabled Cache has zero candidates.");
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
List<Object> bindParams = new ArrayList<>();
|
||||
|
||||
@ -1002,128 +954,6 @@ public class HSQLDBArbitraryRepository implements ArbitraryRepository {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArbitraryResourceData> searchArbitraryResourcesSimple(
|
||||
Service service,
|
||||
String identifier,
|
||||
List<String> names,
|
||||
boolean prefixOnly,
|
||||
Long before,
|
||||
Long after,
|
||||
Integer limit,
|
||||
Integer offset,
|
||||
Boolean reverse,
|
||||
Boolean caseInsensitive) throws DataException {
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
List<Object> bindParams = new ArrayList<>();
|
||||
|
||||
sql.append("SELECT name, service, identifier, size, status, created_when, updated_when ");
|
||||
sql.append("FROM ArbitraryResourcesCache ");
|
||||
sql.append("WHERE name IS NOT NULL");
|
||||
|
||||
if (service != null) {
|
||||
sql.append(" AND service = ?");
|
||||
bindParams.add(service.value);
|
||||
}
|
||||
|
||||
// Handle identifier matches
|
||||
if (identifier != null) {
|
||||
if(caseInsensitive || prefixOnly) {
|
||||
// Search anywhere in the identifier, unless "prefixOnly" has been requested
|
||||
String queryWildcard = getQueryWildcard(identifier, prefixOnly, caseInsensitive);
|
||||
sql.append(caseInsensitive ? " AND LCASE(identifier) LIKE ?" : " AND identifier LIKE ?");
|
||||
bindParams.add(queryWildcard);
|
||||
}
|
||||
else {
|
||||
sql.append(" AND identifier = ?");
|
||||
bindParams.add(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle name searches
|
||||
if (names != null && !names.isEmpty()) {
|
||||
sql.append(" AND (");
|
||||
|
||||
if( caseInsensitive || prefixOnly ) {
|
||||
for (int i = 0; i < names.size(); ++i) {
|
||||
// Search anywhere in the name, unless "prefixOnly" has been requested
|
||||
String queryWildcard = getQueryWildcard(names.get(i), prefixOnly, caseInsensitive);
|
||||
if (i > 0) sql.append(" OR ");
|
||||
sql.append(caseInsensitive ? "LCASE(name) LIKE ?" : "name LIKE ?");
|
||||
bindParams.add(queryWildcard);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < names.size(); ++i) {
|
||||
if (i > 0) sql.append(" OR ");
|
||||
sql.append("name = ?");
|
||||
bindParams.add(names.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
sql.append(")");
|
||||
}
|
||||
|
||||
// Timestamp range
|
||||
if (before != null) {
|
||||
sql.append(" AND created_when < ?");
|
||||
bindParams.add(before);
|
||||
}
|
||||
if (after != null) {
|
||||
sql.append(" AND created_when > ?");
|
||||
bindParams.add(after);
|
||||
}
|
||||
|
||||
sql.append(" ORDER BY created_when");
|
||||
|
||||
if (reverse != null && reverse) {
|
||||
sql.append(" DESC");
|
||||
}
|
||||
|
||||
HSQLDBRepository.limitOffsetSql(sql, limit, offset);
|
||||
|
||||
List<ArbitraryResourceData> arbitraryResources = new ArrayList<>();
|
||||
|
||||
try (ResultSet resultSet = this.repository.checkedExecute(sql.toString(), bindParams.toArray())) {
|
||||
if (resultSet == null)
|
||||
return arbitraryResources;
|
||||
|
||||
do {
|
||||
String nameResult = resultSet.getString(1);
|
||||
Service serviceResult = Service.valueOf(resultSet.getInt(2));
|
||||
String identifierResult = resultSet.getString(3);
|
||||
Integer sizeResult = resultSet.getInt(4);
|
||||
Integer status = resultSet.getInt(5);
|
||||
Long created = resultSet.getLong(6);
|
||||
Long updated = resultSet.getLong(7);
|
||||
|
||||
if (Objects.equals(identifierResult, "default")) {
|
||||
// Map "default" back to null. This is optional but probably less confusing than returning "default".
|
||||
identifierResult = null;
|
||||
}
|
||||
|
||||
ArbitraryResourceData arbitraryResourceData = new ArbitraryResourceData();
|
||||
arbitraryResourceData.name = nameResult;
|
||||
arbitraryResourceData.service = serviceResult;
|
||||
arbitraryResourceData.identifier = identifierResult;
|
||||
arbitraryResourceData.size = sizeResult;
|
||||
arbitraryResourceData.created = created;
|
||||
arbitraryResourceData.updated = (updated == 0) ? null : updated;
|
||||
|
||||
arbitraryResources.add(arbitraryResourceData);
|
||||
} while (resultSet.next());
|
||||
|
||||
return arbitraryResources;
|
||||
} catch (SQLException e) {
|
||||
throw new DataException("Unable to fetch simple arbitrary resources from repository", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getQueryWildcard(String value, boolean prefixOnly, boolean caseInsensitive) {
|
||||
String valueToUse = caseInsensitive ? value.toLowerCase() : value;
|
||||
return prefixOnly ? String.format("%s%%", valueToUse) : valueToUse;
|
||||
}
|
||||
|
||||
|
||||
// Arbitrary resources cache save/load
|
||||
|
||||
|
@ -1,692 +0,0 @@
|
||||
package org.qortal.repository.hsqldb;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.qortal.api.SearchMode;
|
||||
import org.qortal.arbitrary.misc.Category;
|
||||
import org.qortal.arbitrary.misc.Service;
|
||||
import org.qortal.controller.Controller;
|
||||
import org.qortal.data.account.AccountBalanceData;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceCache;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceData;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceMetadata;
|
||||
import org.qortal.data.arbitrary.ArbitraryResourceStatus;
|
||||
import org.qortal.repository.DataException;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLNonTransientConnectionException;
|
||||
import java.sql.Statement;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.qortal.api.SearchMode.LATEST;
|
||||
|
||||
public class HSQLDBCacheUtils {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(HSQLDBCacheUtils.class);
|
||||
private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
|
||||
private static final Comparator<? super ArbitraryResourceData> CREATED_WHEN_COMPARATOR = new Comparator<ArbitraryResourceData>() {
|
||||
@Override
|
||||
public int compare(ArbitraryResourceData data1, ArbitraryResourceData data2) {
|
||||
|
||||
Long a = data1.created;
|
||||
Long b = data2.created;
|
||||
|
||||
return Long.compare(a != null ? a : Long.MIN_VALUE, b != null ? b : Long.MIN_VALUE);
|
||||
}
|
||||
};
|
||||
private static final String DEFAULT_IDENTIFIER = "default";
|
||||
private static final int ZERO = 0;
|
||||
public static final String DB_CACHE_TIMER = "DB Cache Timer";
|
||||
public static final String DB_CACHE_TIMER_TASK = "DB Cache Timer Task";
|
||||
public static final String BALANCE_RECORDER_TIMER = "Balance Recorder Timer";
|
||||
public static final String BALANCE_RECORDER_TIMER_TASK = "Balance Recorder Timer Task";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param cache
|
||||
* @param service the service to filter
|
||||
* @param query query for name, identifier, title or description match
|
||||
* @param identifier the identifier to match
|
||||
* @param names the names to match, ignored if there are exact names
|
||||
* @param title the title to match for
|
||||
* @param description the description to match for
|
||||
* @param prefixOnly true to match on prefix only, false for match anywhere in string
|
||||
* @param exactMatchNames names to match exactly, overrides names
|
||||
* @param defaultResource true to query filter identifier on the default identifier and use the query terms to match candidates names only
|
||||
* @param mode LATEST or ALL
|
||||
* @param minLevel the minimum account level for resource creators
|
||||
* @param includeOnly names to retain, exclude all others
|
||||
* @param exclude names to exclude, retain all others
|
||||
* @param includeMetadata true to include resource metadata in the results, false to exclude metadata
|
||||
* @param includeStatus true to include resource status in the results, false to exclude status
|
||||
* @param before the latest creation timestamp for any candidate
|
||||
* @param after the earliest creation timestamp for any candidate
|
||||
* @param limit the maximum number of resource results to return
|
||||
* @param offset the number of resource results to skip after the results have been retained, filtered and sorted
|
||||
* @param reverse true to reverse the sort order, false to order in chronological order
|
||||
*
|
||||
* @return the resource results
|
||||
*/
|
||||
public static List<ArbitraryResourceData> callCache(
|
||||
ArbitraryResourceCache cache,
|
||||
Service service,
|
||||
String query,
|
||||
String identifier,
|
||||
List<String> names,
|
||||
String title,
|
||||
String description,
|
||||
boolean prefixOnly,
|
||||
List<String> exactMatchNames,
|
||||
boolean defaultResource,
|
||||
SearchMode mode,
|
||||
Integer minLevel,
|
||||
Boolean followedOnly,
|
||||
Boolean excludeBlocked,
|
||||
Boolean includeMetadata,
|
||||
Boolean includeStatus,
|
||||
Long before,
|
||||
Long after,
|
||||
Integer limit,
|
||||
Integer offset,
|
||||
Boolean reverse) {
|
||||
|
||||
List<ArbitraryResourceData> candidates = new ArrayList<>();
|
||||
|
||||
// cache all results for requested service
|
||||
if( service != null ) {
|
||||
candidates.addAll(cache.getDataByService().getOrDefault(service.value, new ArrayList<>(0)));
|
||||
}
|
||||
// if no requested, then empty cache
|
||||
|
||||
return candidates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter candidates
|
||||
*
|
||||
* @param candidates the candidates, they may be preprocessed
|
||||
* @param levelByName name -> level map
|
||||
* @param mode LATEST or ALL
|
||||
* @param service the service to filter
|
||||
* @param query query for name, identifier, title or description match
|
||||
* @param identifier the identifier to match
|
||||
* @param names the names to match, ignored if there are exact names
|
||||
* @param title the title to match for
|
||||
* @param description the description to match for
|
||||
* @param prefixOnly true to match on prefix only, false for match anywhere in string
|
||||
* @param exactMatchNames names to match exactly, overrides names
|
||||
* @param defaultResource true to query filter identifier on the default identifier and use the query terms to match candidates names only
|
||||
* @param minLevel the minimum account level for resource creators
|
||||
* @param includeOnly names to retain, exclude all others
|
||||
* @param exclude names to exclude, retain all others
|
||||
* @param includeMetadata true to include resource metadata in the results, false to exclude metadata
|
||||
* @param includeStatus true to include resource status in the results, false to exclude status
|
||||
* @param before the latest creation timestamp for any candidate
|
||||
* @param after the earliest creation timestamp for any candidate
|
||||
* @param limit the maximum number of resource results to return
|
||||
* @param offset the number of resource results to skip after the results have been retained, filtered and sorted
|
||||
* @param reverse true to reverse the sort order, false to order in chronological order
|
||||
*
|
||||
* @return the resource results
|
||||
*/
|
||||
public static List<ArbitraryResourceData> filterList(
|
||||
List<ArbitraryResourceData> candidates,
|
||||
Map<String, Integer> levelByName,
|
||||
Optional<SearchMode> mode,
|
||||
Optional<Service> service,
|
||||
Optional<String> query,
|
||||
Optional<String> identifier,
|
||||
Optional<List<String>> names,
|
||||
Optional<String> title,
|
||||
Optional<String> description,
|
||||
boolean prefixOnly,
|
||||
Optional<List<String>> exactMatchNames,
|
||||
boolean defaultResource,
|
||||
Optional<Integer> minLevel,
|
||||
Optional<Supplier<List<String>>> includeOnly,
|
||||
Optional<Supplier<List<String>>> exclude,
|
||||
Optional<Boolean> includeMetadata,
|
||||
Optional<Boolean> includeStatus,
|
||||
Optional<Long> before,
|
||||
Optional<Long> after,
|
||||
Optional<Integer> limit,
|
||||
Optional<Integer> offset,
|
||||
Optional<Boolean> reverse) {
|
||||
|
||||
// retain only candidates with names
|
||||
Stream<ArbitraryResourceData> stream = candidates.stream().filter(candidate -> candidate.name != null);
|
||||
|
||||
// filter by service
|
||||
if( service.isPresent() )
|
||||
stream = stream.filter(candidate -> candidate.service.equals(service.get()));
|
||||
|
||||
// filter by query (either identifier, name, title or description)
|
||||
if (query.isPresent()) {
|
||||
|
||||
Predicate<String> predicate
|
||||
= prefixOnly ? getPrefixPredicate(query.get()) : getContainsPredicate(query.get());
|
||||
|
||||
if (defaultResource) {
|
||||
stream = stream.filter( candidate -> DEFAULT_IDENTIFIER.equals( candidate.identifier ) && predicate.test(candidate.name));
|
||||
} else {
|
||||
stream = stream.filter( candidate -> passQuery(predicate, candidate));
|
||||
}
|
||||
}
|
||||
|
||||
// filter for identifier, title and description
|
||||
stream = filterTerm(identifier, data -> data.identifier, prefixOnly, stream);
|
||||
stream = filterTerm(title, data -> data.metadata != null ? data.metadata.getTitle() : null, prefixOnly, stream);
|
||||
stream = filterTerm(description, data -> data.metadata != null ? data.metadata.getDescription() : null, prefixOnly, stream);
|
||||
|
||||
// if exact names is set, retain resources with exact names
|
||||
if( exactMatchNames.isPresent() && !exactMatchNames.get().isEmpty()) {
|
||||
|
||||
// key the data by lower case name
|
||||
Map<String, List<ArbitraryResourceData>> dataByName
|
||||
= stream.collect(Collectors.groupingBy(data -> data.name.toLowerCase()));
|
||||
|
||||
// lower the case of the exact names
|
||||
// retain the lower case names of the data above
|
||||
List<String> exactNamesToSearch
|
||||
= exactMatchNames.get().stream()
|
||||
.map(String::toLowerCase)
|
||||
.collect(Collectors.toList());
|
||||
exactNamesToSearch.retainAll(dataByName.keySet());
|
||||
|
||||
// get the data for the names retained and
|
||||
// set them to the stream
|
||||
stream
|
||||
= dataByName.entrySet().stream()
|
||||
.filter(entry -> exactNamesToSearch.contains(entry.getKey())).flatMap(entry -> entry.getValue().stream());
|
||||
}
|
||||
// if exact names is not set, retain resources that match
|
||||
else if( names.isPresent() && !names.get().isEmpty() ) {
|
||||
|
||||
stream = retainTerms(names.get(), data -> data.name, prefixOnly, stream);
|
||||
}
|
||||
|
||||
// filter for minimum account level
|
||||
if(minLevel.isPresent())
|
||||
stream = stream.filter( candidate -> levelByName.getOrDefault(candidate.name, 0) >= minLevel.get() );
|
||||
|
||||
// if latest mode or empty
|
||||
if( LATEST.equals( mode.orElse( LATEST ) ) ) {
|
||||
|
||||
// Include latest item only for a name/service combination
|
||||
stream
|
||||
= stream.filter(candidate -> candidate.service != null && candidate.created != null ).collect(
|
||||
Collectors.groupingBy(
|
||||
data -> new AbstractMap.SimpleEntry<>(data.name, data.service), // name, service combination
|
||||
Collectors.maxBy(Comparator.comparingLong(data -> data.created)) // latest data item
|
||||
)).values().stream().filter(Optional::isPresent).map(Optional::get); // if there is a value for the group, then retain it
|
||||
}
|
||||
|
||||
// sort
|
||||
if( reverse.isPresent() && reverse.get())
|
||||
stream = stream.sorted(CREATED_WHEN_COMPARATOR.reversed());
|
||||
else
|
||||
stream = stream.sorted(CREATED_WHEN_COMPARATOR);
|
||||
|
||||
// skip to offset
|
||||
if( offset.isPresent() ) stream = stream.skip(offset.get());
|
||||
|
||||
// truncate to limit
|
||||
if( limit.isPresent() && limit.get() > 0 ) stream = stream.limit(limit.get());
|
||||
|
||||
// include metadata
|
||||
if( includeMetadata.isEmpty() || !includeMetadata.get() )
|
||||
stream = stream.peek( candidate -> candidate.metadata = null );
|
||||
|
||||
// include status
|
||||
if( includeStatus.isEmpty() || !includeStatus.get() )
|
||||
stream = stream.peek( candidate -> candidate.status = null);
|
||||
|
||||
return stream.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter Terms
|
||||
*
|
||||
* @param term the term to filter
|
||||
* @param stringSupplier the string of interest from the resource candidates
|
||||
* @param prefixOnly true if prexif only, false for contains
|
||||
* @param stream the stream of candidates
|
||||
*
|
||||
* @return the stream that filtered the term
|
||||
*/
|
||||
private static Stream<ArbitraryResourceData> filterTerm(
|
||||
Optional<String> term,
|
||||
Function<ArbitraryResourceData,String> stringSupplier,
|
||||
boolean prefixOnly,
|
||||
Stream<ArbitraryResourceData> stream) {
|
||||
|
||||
if(term.isPresent()){
|
||||
Predicate<String> predicate
|
||||
= prefixOnly ? getPrefixPredicate(term.get()): getContainsPredicate(term.get());
|
||||
stream = stream.filter(candidate -> predicate.test(stringSupplier.apply(candidate)));
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retain Terms
|
||||
*
|
||||
* Retain resources that satisfy terms given.
|
||||
*
|
||||
* @param terms the terms to retain
|
||||
* @param stringSupplier the string of interest from the resource candidates
|
||||
* @param prefixOnly true if prexif only, false for contains
|
||||
* @param stream the stream of candidates
|
||||
*
|
||||
* @return the stream that retained the terms
|
||||
*/
|
||||
private static Stream<ArbitraryResourceData> retainTerms(
|
||||
List<String> terms,
|
||||
Function<ArbitraryResourceData,String> stringSupplier,
|
||||
boolean prefixOnly,
|
||||
Stream<ArbitraryResourceData> stream) {
|
||||
|
||||
// collect the data to process, start the data to retain
|
||||
List<ArbitraryResourceData> toProcess = stream.collect(Collectors.toList());
|
||||
List<ArbitraryResourceData> toRetain = new ArrayList<>();
|
||||
|
||||
// for each term, get the predicate, get a new stream process and
|
||||
// apply the predicate to each data item in the stream
|
||||
for( String term : terms ) {
|
||||
Predicate<String> predicate
|
||||
= prefixOnly ? getPrefixPredicate(term) : getContainsPredicate(term);
|
||||
toRetain.addAll(
|
||||
toProcess.stream()
|
||||
.filter(candidate -> predicate.test(stringSupplier.apply(candidate)))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
return toRetain.stream();
|
||||
}
|
||||
|
||||
private static Predicate<String> getContainsPredicate(String term) {
|
||||
return value -> value != null && value.toLowerCase().contains(term.toLowerCase());
|
||||
}
|
||||
|
||||
private static Predicate<String> getPrefixPredicate(String term) {
|
||||
return value -> value != null && value.toLowerCase().startsWith(term.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass Query
|
||||
*
|
||||
* Compare name, identifier, title and description
|
||||
*
|
||||
* @param predicate the string comparison predicate
|
||||
* @param candidate the candiddte to compare
|
||||
*
|
||||
* @return true if there is a match, otherwise false
|
||||
*/
|
||||
private static boolean passQuery(Predicate<String> predicate, ArbitraryResourceData candidate) {
|
||||
|
||||
if( predicate.test(candidate.name) ) return true;
|
||||
|
||||
if( predicate.test(candidate.identifier) ) return true;
|
||||
|
||||
if( candidate.metadata != null ) {
|
||||
|
||||
if( predicate.test(candidate.metadata.getTitle() )) return true;
|
||||
if( predicate.test(candidate.metadata.getDescription())) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Caching
|
||||
*
|
||||
* @param priorityRequested the thread priority to fill cache in
|
||||
* @param frequency the frequency to fill the cache (in seconds)
|
||||
*
|
||||
* @return the data cache
|
||||
*/
|
||||
public static void startCaching(int priorityRequested, int frequency) {
|
||||
|
||||
Timer timer = buildTimer(DB_CACHE_TIMER, priorityRequested);
|
||||
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Thread.currentThread().setName(DB_CACHE_TIMER_TASK);
|
||||
|
||||
try (final HSQLDBRepository respository = (HSQLDBRepository) Controller.REPOSITORY_FACTORY.getRepository()) {
|
||||
fillCache(ArbitraryResourceCache.getInstance(), respository);
|
||||
}
|
||||
catch( DataException e ) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// delay 1 second
|
||||
timer.scheduleAtFixedRate(task, 1000, frequency * 1000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start Recording Balances
|
||||
*
|
||||
* @param queue the queue to add to, remove oldest data if necssary
|
||||
* @param repository the db repsoitory
|
||||
* @param priorityRequested the requested thread priority
|
||||
* @param frequency the recording frequencies, in minutes
|
||||
*/
|
||||
public static void startRecordingBalances(
|
||||
final ConcurrentHashMap<Integer, List<AccountBalanceData>> balancesByHeight,
|
||||
final ConcurrentHashMap<String, List<AccountBalanceData>> balancesByAddress,
|
||||
int priorityRequested,
|
||||
int frequency,
|
||||
int capacity) {
|
||||
|
||||
Timer timer = buildTimer(BALANCE_RECORDER_TIMER, priorityRequested);
|
||||
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Thread.currentThread().setName(BALANCE_RECORDER_TIMER_TASK);
|
||||
|
||||
try (final HSQLDBRepository repository = (HSQLDBRepository) Controller.REPOSITORY_FACTORY.getRepository()) {
|
||||
while (balancesByHeight.size() > capacity + 1) {
|
||||
Optional<Integer> firstHeight = balancesByHeight.keySet().stream().sorted().findFirst();
|
||||
|
||||
if (firstHeight.isPresent()) balancesByHeight.remove(firstHeight.get());
|
||||
}
|
||||
|
||||
// get current balances
|
||||
List<AccountBalanceData> accountBalances = getAccountBalances(repository);
|
||||
|
||||
// get anyone of the balances
|
||||
Optional<AccountBalanceData> data = accountBalances.stream().findAny();
|
||||
|
||||
// if there are any balances, then record them
|
||||
if (data.isPresent()) {
|
||||
// map all new balances to the current height
|
||||
balancesByHeight.put(data.get().getHeight(), accountBalances);
|
||||
|
||||
// for each new balance, map to address
|
||||
for (AccountBalanceData accountBalance : accountBalances) {
|
||||
|
||||
// get recorded balances for this address
|
||||
List<AccountBalanceData> establishedBalances
|
||||
= balancesByAddress.getOrDefault(accountBalance.getAddress(), new ArrayList<>(0));
|
||||
|
||||
// start a new list of recordings for this address, add the new balance and add the established
|
||||
// balances
|
||||
List<AccountBalanceData> balances = new ArrayList<>(establishedBalances.size() + 1);
|
||||
balances.add(accountBalance);
|
||||
balances.addAll(establishedBalances);
|
||||
|
||||
// reset tha balances for this address
|
||||
balancesByAddress.put(accountBalance.getAddress(), balances);
|
||||
|
||||
// TODO: reduce account balances to capacity
|
||||
}
|
||||
|
||||
// reduce height balances to capacity
|
||||
while( balancesByHeight.size() > capacity ) {
|
||||
Optional<Integer> lowestHeight
|
||||
= balancesByHeight.entrySet().stream()
|
||||
.min(Comparator.comparingInt(Map.Entry::getKey))
|
||||
.map(Map.Entry::getKey);
|
||||
|
||||
if (lowestHeight.isPresent()) balancesByHeight.entrySet().remove(lowestHeight);
|
||||
}
|
||||
}
|
||||
} catch (DataException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// wait 5 minutes
|
||||
timer.scheduleAtFixedRate(task, 300_000, frequency * 60_000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Timer
|
||||
*
|
||||
* Build a timer for scheduling a timer task.
|
||||
*
|
||||
* @param name the name for the thread running the timer task
|
||||
* @param priorityRequested the priority for the thread running the timer task
|
||||
*
|
||||
* @return a timer for scheduling a timer task
|
||||
*/
|
||||
private static Timer buildTimer( final String name, int priorityRequested) {
|
||||
// ensure priority is in between 1-10
|
||||
final int priority = Math.max(0, Math.min(10, priorityRequested));
|
||||
|
||||
// Create a custom Timer with updated priority threads
|
||||
Timer timer = new Timer(true) { // 'true' to make the Timer daemon
|
||||
@Override
|
||||
public void schedule(TimerTask task, long delay) {
|
||||
Thread thread = new Thread(task, name) {
|
||||
@Override
|
||||
public void run() {
|
||||
this.setPriority(priority);
|
||||
super.run();
|
||||
}
|
||||
};
|
||||
thread.setPriority(priority);
|
||||
thread.start();
|
||||
}
|
||||
};
|
||||
return timer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill Cache
|
||||
*
|
||||
* @param cache the cache to fill
|
||||
* @param repository the data source to fill the cache with
|
||||
*/
|
||||
public static void fillCache(ArbitraryResourceCache cache, HSQLDBRepository repository) {
|
||||
|
||||
try {
|
||||
// ensure all data is committed in, before we query it
|
||||
repository.saveChanges();
|
||||
|
||||
List<ArbitraryResourceData> resources = getResources(repository);
|
||||
|
||||
Map<Integer, List<ArbitraryResourceData>> dataByService
|
||||
= resources.stream()
|
||||
.collect(Collectors.groupingBy(data -> data.service.value));
|
||||
|
||||
// lock, clear and refill
|
||||
synchronized (cache.getDataByService()) {
|
||||
cache.getDataByService().clear();
|
||||
cache.getDataByService().putAll(dataByService);
|
||||
}
|
||||
|
||||
fillNamepMap(cache.getLevelByName(), repository);
|
||||
}
|
||||
catch (SQLNonTransientConnectionException e ) {
|
||||
LOGGER.warn("Connection problems. Retry later.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill Name Map
|
||||
*
|
||||
* Name -> Level
|
||||
*
|
||||
* @param levelByName the map to fill
|
||||
* @param repository the data source
|
||||
*
|
||||
* @throws SQLException
|
||||
*/
|
||||
private static void fillNamepMap(ConcurrentHashMap<String, Integer> levelByName, HSQLDBRepository repository ) throws SQLException {
|
||||
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
|
||||
sql.append("SELECT name, level ");
|
||||
sql.append("FROM NAMES ");
|
||||
sql.append("INNER JOIN ACCOUNTS on owner = account ");
|
||||
|
||||
Statement statement = repository.connection.createStatement();
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(sql.toString());
|
||||
|
||||
if (resultSet == null)
|
||||
return;
|
||||
|
||||
if (!resultSet.next())
|
||||
return;
|
||||
|
||||
do {
|
||||
levelByName.put(resultSet.getString(1), resultSet.getInt(2));
|
||||
} while(resultSet.next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Resource
|
||||
*
|
||||
* @param repository source data
|
||||
*
|
||||
* @return the resources
|
||||
* @throws SQLException
|
||||
*/
|
||||
private static List<ArbitraryResourceData> getResources( HSQLDBRepository repository) throws SQLException {
|
||||
|
||||
List<ArbitraryResourceData> resources = new ArrayList<>();
|
||||
|
||||
StringBuilder sql = new StringBuilder(512);
|
||||
|
||||
sql.append("SELECT name, service, identifier, size, status, created_when, updated_when, ");
|
||||
sql.append("title, description, category, tag1, tag2, tag3, tag4, tag5 ");
|
||||
sql.append("FROM ArbitraryResourcesCache ");
|
||||
sql.append("LEFT JOIN ArbitraryMetadataCache USING (service, name, identifier) WHERE name IS NOT NULL");
|
||||
|
||||
List<ArbitraryResourceData> arbitraryResources = new ArrayList<>();
|
||||
Statement statement = repository.connection.createStatement();
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(sql.toString());
|
||||
|
||||
if (resultSet == null)
|
||||
return resources;
|
||||
|
||||
if (!resultSet.next())
|
||||
return resources;
|
||||
|
||||
do {
|
||||
String nameResult = resultSet.getString(1);
|
||||
int serviceResult = resultSet.getInt(2);
|
||||
String identifierResult = resultSet.getString(3);
|
||||
Integer sizeResult = resultSet.getInt(4);
|
||||
Integer status = resultSet.getInt(5);
|
||||
Long created = resultSet.getLong(6);
|
||||
Long updated = resultSet.getLong(7);
|
||||
|
||||
String titleResult = resultSet.getString(8);
|
||||
String descriptionResult = resultSet.getString(9);
|
||||
String category = resultSet.getString(10);
|
||||
String tag1 = resultSet.getString(11);
|
||||
String tag2 = resultSet.getString(12);
|
||||
String tag3 = resultSet.getString(13);
|
||||
String tag4 = resultSet.getString(14);
|
||||
String tag5 = resultSet.getString(15);
|
||||
|
||||
if (Objects.equals(identifierResult, "default")) {
|
||||
// Map "default" back to null. This is optional but probably less confusing than returning "default".
|
||||
identifierResult = null;
|
||||
}
|
||||
|
||||
ArbitraryResourceData arbitraryResourceData = new ArbitraryResourceData();
|
||||
arbitraryResourceData.name = nameResult;
|
||||
arbitraryResourceData.service = Service.valueOf(serviceResult);
|
||||
arbitraryResourceData.identifier = identifierResult;
|
||||
arbitraryResourceData.size = sizeResult;
|
||||
arbitraryResourceData.created = created;
|
||||
arbitraryResourceData.updated = (updated == 0) ? null : updated;
|
||||
|
||||
arbitraryResourceData.setStatus(ArbitraryResourceStatus.Status.valueOf(status));
|
||||
|
||||
ArbitraryResourceMetadata metadata = new ArbitraryResourceMetadata();
|
||||
metadata.setTitle(titleResult);
|
||||
metadata.setDescription(descriptionResult);
|
||||
metadata.setCategory(Category.uncategorizedValueOf(category));
|
||||
|
||||
List<String> tags = new ArrayList<>();
|
||||
if (tag1 != null) tags.add(tag1);
|
||||
if (tag2 != null) tags.add(tag2);
|
||||
if (tag3 != null) tags.add(tag3);
|
||||
if (tag4 != null) tags.add(tag4);
|
||||
if (tag5 != null) tags.add(tag5);
|
||||
metadata.setTags(!tags.isEmpty() ? tags : null);
|
||||
|
||||
if (metadata.hasMetadata()) {
|
||||
arbitraryResourceData.metadata = metadata;
|
||||
}
|
||||
|
||||
resources.add( arbitraryResourceData );
|
||||
} while (resultSet.next());
|
||||
|
||||
return resources;
|
||||
}
|
||||
|
||||
public static List<AccountBalanceData> getAccountBalances(HSQLDBRepository repository) {
|
||||
|
||||
StringBuilder sql = new StringBuilder();
|
||||
|
||||
sql.append("SELECT account, balance, height ");
|
||||
sql.append("FROM ACCOUNTBALANCES as balances ");
|
||||
sql.append("JOIN (SELECT height FROM BLOCKS ORDER BY height DESC LIMIT 1) AS max_height ON true ");
|
||||
sql.append("WHERE asset_id=0");
|
||||
|
||||
List<AccountBalanceData> data = new ArrayList<>();
|
||||
|
||||
LOGGER.info( "Getting account balances ...");
|
||||
|
||||
try {
|
||||
Statement statement = repository.connection.createStatement();
|
||||
|
||||
ResultSet resultSet = statement.executeQuery(sql.toString());
|
||||
|
||||
if (resultSet == null || !resultSet.next())
|
||||
return new ArrayList<>(0);
|
||||
|
||||
do {
|
||||
String account = resultSet.getString(1);
|
||||
long balance = resultSet.getLong(2);
|
||||
int height = resultSet.getInt(3);
|
||||
|
||||
data.add(new AccountBalanceData(account, ZERO, balance, height));
|
||||
} while (resultSet.next());
|
||||
} catch (SQLException e) {
|
||||
LOGGER.warn(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
|
||||
LOGGER.info("Retrieved account balances: count = " + data.size());
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
@ -176,14 +176,14 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActiveChats getActiveChats(String address, Encoding encoding, Boolean hasChatReference) throws DataException {
|
||||
List<GroupChat> groupChats = getActiveGroupChats(address, encoding, hasChatReference);
|
||||
List<DirectChat> directChats = getActiveDirectChats(address, hasChatReference);
|
||||
public ActiveChats getActiveChats(String address, Encoding encoding) throws DataException {
|
||||
List<GroupChat> groupChats = getActiveGroupChats(address, encoding);
|
||||
List<DirectChat> directChats = getActiveDirectChats(address);
|
||||
|
||||
return new ActiveChats(groupChats, directChats);
|
||||
}
|
||||
|
||||
private List<GroupChat> getActiveGroupChats(String address, Encoding encoding, Boolean hasChatReference) throws DataException {
|
||||
private List<GroupChat> getActiveGroupChats(String address, Encoding encoding) throws DataException {
|
||||
// Find groups where address is a member and potential latest message details
|
||||
String groupsSql = "SELECT group_id, group_name, latest_timestamp, sender, sender_name, signature, data "
|
||||
+ "FROM GroupMembers "
|
||||
@ -194,16 +194,8 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
+ "JOIN Transactions USING (signature) "
|
||||
+ "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
|
||||
// NOTE: We need to qualify "Groups.group_id" here to avoid "General error" bug in HSQLDB v2.5.0
|
||||
+ "WHERE tx_group_id = Groups.group_id AND type = " + TransactionType.CHAT.value + " ";
|
||||
|
||||
if (hasChatReference != null) {
|
||||
if (hasChatReference) {
|
||||
groupsSql += "AND chat_reference IS NOT NULL ";
|
||||
} else {
|
||||
groupsSql += "AND chat_reference IS NULL ";
|
||||
}
|
||||
}
|
||||
groupsSql += "ORDER BY created_when DESC "
|
||||
+ "WHERE tx_group_id = Groups.group_id AND type = " + TransactionType.CHAT.value + " "
|
||||
+ "ORDER BY created_when DESC "
|
||||
+ "LIMIT 1"
|
||||
+ ") AS LatestMessages ON TRUE "
|
||||
+ "WHERE address = ?";
|
||||
@ -238,16 +230,8 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
+ "JOIN Transactions USING (signature) "
|
||||
+ "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
|
||||
+ "WHERE tx_group_id = 0 "
|
||||
+ "AND recipient IS NULL ";
|
||||
|
||||
if (hasChatReference != null) {
|
||||
if (hasChatReference) {
|
||||
grouplessSql += "AND chat_reference IS NOT NULL ";
|
||||
} else {
|
||||
grouplessSql += "AND chat_reference IS NULL ";
|
||||
}
|
||||
}
|
||||
grouplessSql += "ORDER BY created_when DESC "
|
||||
+ "AND recipient IS NULL "
|
||||
+ "ORDER BY created_when DESC "
|
||||
+ "LIMIT 1";
|
||||
|
||||
try (ResultSet resultSet = this.repository.checkedExecute(grouplessSql)) {
|
||||
@ -275,7 +259,7 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
return groupChats;
|
||||
}
|
||||
|
||||
private List<DirectChat> getActiveDirectChats(String address, Boolean hasChatReference) throws DataException {
|
||||
private List<DirectChat> getActiveDirectChats(String address) throws DataException {
|
||||
// Find chat messages involving address
|
||||
String directSql = "SELECT other_address, name, latest_timestamp, sender, sender_name "
|
||||
+ "FROM ("
|
||||
@ -291,18 +275,8 @@ public class HSQLDBChatRepository implements ChatRepository {
|
||||
+ "NATURAL JOIN Transactions "
|
||||
+ "LEFT OUTER JOIN Names AS SenderNames ON SenderNames.owner = sender "
|
||||
+ "WHERE (sender = other_address AND recipient = ?) "
|
||||
+ "OR (sender = ? AND recipient = other_address) ";
|
||||
|
||||
// Apply hasChatReference filter
|
||||
if (hasChatReference != null) {
|
||||
if (hasChatReference) {
|
||||
directSql += "AND chat_reference IS NOT NULL ";
|
||||
} else {
|
||||
directSql += "AND chat_reference IS NULL ";
|
||||
}
|
||||
}
|
||||
|
||||
directSql += "ORDER BY created_when DESC "
|
||||
+ "OR (sender = ? AND recipient = other_address) "
|
||||
+ "ORDER BY created_when DESC "
|
||||
+ "LIMIT 1"
|
||||
+ ") AS LatestMessages "
|
||||
+ "LEFT OUTER JOIN Names ON owner = other_address";
|
||||
|
@ -454,41 +454,40 @@ public class HSQLDBDatabaseUpdates {
|
||||
|
||||
case 12:
|
||||
// Groups
|
||||
// NOTE: We need to set Groups to `Groups` here to avoid SQL Standard Keywords in HSQLDB v2.7.4
|
||||
stmt.execute("CREATE TABLE `Groups` (group_id GroupID, owner QortalAddress NOT NULL, group_name GroupName NOT NULL, "
|
||||
stmt.execute("CREATE TABLE Groups (group_id GroupID, owner QortalAddress NOT NULL, group_name GroupName NOT NULL, "
|
||||
+ "created_when EpochMillis NOT NULL, updated_when EpochMillis, is_open BOOLEAN NOT NULL, "
|
||||
+ "approval_threshold TINYINT NOT NULL, min_block_delay INTEGER NOT NULL, max_block_delay INTEGER NOT NULL, "
|
||||
+ "reference Signature, creation_group_id GroupID, reduced_group_name GroupName NOT NULL, "
|
||||
+ "description GenericDescription NOT NULL, PRIMARY KEY (group_id))");
|
||||
// For finding groups by name
|
||||
stmt.execute("CREATE INDEX GroupNameIndex on `Groups` (group_name)");
|
||||
stmt.execute("CREATE INDEX GroupNameIndex on Groups (group_name)");
|
||||
// For finding groups by reduced name
|
||||
stmt.execute("CREATE INDEX GroupReducedNameIndex on `Groups` (reduced_group_name)");
|
||||
stmt.execute("CREATE INDEX GroupReducedNameIndex on Groups (reduced_group_name)");
|
||||
// For finding groups by owner
|
||||
stmt.execute("CREATE INDEX GroupOwnerIndex ON `Groups` (owner)");
|
||||
stmt.execute("CREATE INDEX GroupOwnerIndex ON Groups (owner)");
|
||||
|
||||
// We need a corresponding trigger to make sure new group_id values are assigned sequentially starting from 1
|
||||
stmt.execute("CREATE TRIGGER Group_ID_Trigger BEFORE INSERT ON `Groups` "
|
||||
stmt.execute("CREATE TRIGGER Group_ID_Trigger BEFORE INSERT ON Groups "
|
||||
+ "REFERENCING NEW ROW AS new_row FOR EACH ROW WHEN (new_row.group_id IS NULL) "
|
||||
+ "SET new_row.group_id = (SELECT IFNULL(MAX(group_id) + 1, 1) FROM `Groups`)");
|
||||
+ "SET new_row.group_id = (SELECT IFNULL(MAX(group_id) + 1, 1) FROM Groups)");
|
||||
|
||||
// Admins
|
||||
stmt.execute("CREATE TABLE GroupAdmins (group_id GroupID, admin QortalAddress, reference Signature NOT NULL, "
|
||||
+ "PRIMARY KEY (group_id, admin), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||
+ "PRIMARY KEY (group_id, admin), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
||||
// For finding groups by admin address
|
||||
stmt.execute("CREATE INDEX GroupAdminIndex ON GroupAdmins (admin)");
|
||||
|
||||
// Members
|
||||
stmt.execute("CREATE TABLE GroupMembers (group_id GroupID, address QortalAddress, "
|
||||
+ "joined_when EpochMillis NOT NULL, reference Signature NOT NULL, "
|
||||
+ "PRIMARY KEY (group_id, address), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||
+ "PRIMARY KEY (group_id, address), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
||||
// For finding groups by member address
|
||||
stmt.execute("CREATE INDEX GroupMemberIndex ON GroupMembers (address)");
|
||||
|
||||
// Invites
|
||||
stmt.execute("CREATE TABLE GroupInvites (group_id GroupID, inviter QortalAddress, invitee QortalAddress, "
|
||||
+ "expires_when EpochMillis, reference Signature, "
|
||||
+ "PRIMARY KEY (group_id, invitee), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||
+ "PRIMARY KEY (group_id, invitee), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
||||
// For finding invites sent by inviter
|
||||
stmt.execute("CREATE INDEX GroupInviteInviterIndex ON GroupInvites (inviter)");
|
||||
// For finding invites by group
|
||||
@ -504,7 +503,7 @@ public class HSQLDBDatabaseUpdates {
|
||||
// NULL expires_when means does not expire!
|
||||
stmt.execute("CREATE TABLE GroupBans (group_id GroupID, offender QortalAddress, admin QortalAddress NOT NULL, "
|
||||
+ "banned_when EpochMillis NOT NULL, reason GenericDescription NOT NULL, expires_when EpochMillis, reference Signature NOT NULL, "
|
||||
+ "PRIMARY KEY (group_id, offender), FOREIGN KEY (group_id) REFERENCES `Groups` (group_id) ON DELETE CASCADE)");
|
||||
+ "PRIMARY KEY (group_id, offender), FOREIGN KEY (group_id) REFERENCES Groups (group_id) ON DELETE CASCADE)");
|
||||
// For expiry maintenance
|
||||
stmt.execute("CREATE INDEX GroupBanExpiryIndex ON GroupBans (expires_when)");
|
||||
break;
|
||||
|
@ -114,8 +114,6 @@ public class Settings {
|
||||
|
||||
/** Whether we check, fetch and install auto-updates */
|
||||
private boolean autoUpdateEnabled = true;
|
||||
/** Whether we check, restart node without connected peers */
|
||||
private boolean autoRestartEnabled = false;
|
||||
/** How long between repository backups (ms), or 0 if disabled. */
|
||||
private long repositoryBackupInterval = 0; // ms
|
||||
/** Whether to show a notification when we backup repository. */
|
||||
@ -199,32 +197,32 @@ public class Settings {
|
||||
/** Target number of outbound connections to peers we should make. */
|
||||
private int minOutboundPeers = 32;
|
||||
/** Maximum number of peer connections we allow. */
|
||||
private int maxPeers = 64;
|
||||
private int maxPeers = 60;
|
||||
/** Number of slots to reserve for short-lived QDN data transfers */
|
||||
private int maxDataPeers = 5;
|
||||
/** Maximum number of threads for network engine. */
|
||||
private int maxNetworkThreadPoolSize = 512;
|
||||
private int maxNetworkThreadPoolSize = 620;
|
||||
/** Maximum number of threads for network proof-of-work compute, used during handshaking. */
|
||||
private int networkPoWComputePoolSize = 4;
|
||||
private int networkPoWComputePoolSize = 2;
|
||||
/** Maximum number of retry attempts if a peer fails to respond with the requested data */
|
||||
private int maxRetries = 3;
|
||||
private int maxRetries = 2;
|
||||
|
||||
/** The number of seconds of no activity before recovery mode begins */
|
||||
public long recoveryModeTimeout = 9999999999999L;
|
||||
|
||||
/** Minimum peer version number required in order to sync with them */
|
||||
private String minPeerVersion = "4.6.5";
|
||||
private String minPeerVersion = "4.5.1";
|
||||
/** Whether to allow connections with peers below minPeerVersion
|
||||
* If true, we won't sync with them but they can still sync with us, and will show in the peers list
|
||||
* If false, sync will be blocked both ways, and they will not appear in the peers list */
|
||||
private boolean allowConnectionsWithOlderPeerVersions = true;
|
||||
|
||||
/** Minimum time (in seconds) that we should attempt to remain connected to a peer for */
|
||||
private int minPeerConnectionTime = 2 * 60 * 60; // seconds
|
||||
private int minPeerConnectionTime = 60 * 60; // seconds
|
||||
/** Maximum time (in seconds) that we should attempt to remain connected to a peer for */
|
||||
private int maxPeerConnectionTime = 6 * 60 * 60; // seconds
|
||||
private int maxPeerConnectionTime = 4 * 60 * 60; // seconds
|
||||
/** Maximum time (in seconds) that a peer should remain connected when requesting QDN data */
|
||||
private int maxDataPeerConnectionTime = 30 * 60; // seconds
|
||||
private int maxDataPeerConnectionTime = 2 * 60; // seconds
|
||||
|
||||
/** Whether to sync multiple blocks at once in normal operation */
|
||||
private boolean fastSyncEnabled = true;
|
||||
@ -274,17 +272,13 @@ public class Settings {
|
||||
private String[] bootstrapHosts = new String[] {
|
||||
"http://bootstrap.qortal.org",
|
||||
"http://bootstrap2.qortal.org",
|
||||
"http://bootstrap3.qortal.org",
|
||||
"http://bootstrap4.qortal.org"
|
||||
"http://bootstrap3.qortal.org"
|
||||
};
|
||||
|
||||
// Auto-update sources
|
||||
private String[] autoUpdateRepos = new String[] {
|
||||
"https://github.com/Qortal/qortal/raw/%s/qortal.update",
|
||||
"https://raw.githubusercontent.com@151.101.16.133/Qortal/qortal/%s/qortal.update",
|
||||
"https://qortal.link/Auto-Update/%s/qortal.update",
|
||||
"https://qortal.name/auto-Update/%s/qortal.update",
|
||||
"https://gitea.qortal.link/qortal/qortal/raw/%s/qortal.update"
|
||||
"https://raw.githubusercontent.com@151.101.16.133/Qortal/qortal/%s/qortal.update"
|
||||
};
|
||||
|
||||
// Lists
|
||||
@ -329,14 +323,11 @@ public class Settings {
|
||||
/* Foreign chains */
|
||||
|
||||
/** The number of consecutive empty addresses required before treating a wallet's transaction set as complete */
|
||||
private int gapLimit = 3;
|
||||
private int gapLimit = 24;
|
||||
|
||||
/** How many wallet keys to generate when using bitcoinj as the blockchain interface (e.g. when sending coins) */
|
||||
private int bitcoinjLookaheadSize = 50;
|
||||
|
||||
/** How many units of data to be kept in a blockchain cache before the cache should be reduced or cleared. */
|
||||
private int blockchainCacheLimit = 1000;
|
||||
|
||||
// Data storage (QDN)
|
||||
|
||||
/** Data storage enabled/disabled*/
|
||||
@ -383,74 +374,6 @@ public class Settings {
|
||||
* Exclude from settings.json to disable this warning. */
|
||||
private Integer threadCountPerMessageTypeWarningThreshold = null;
|
||||
|
||||
/**
|
||||
* DB Cache Enabled?
|
||||
*/
|
||||
private boolean dbCacheEnabled = false;
|
||||
|
||||
/**
|
||||
* DB Cache Thread Priority
|
||||
*
|
||||
* If DB Cache is disabled, then this is ignored. If value is lower then 1, than 1 is used. If value is higher
|
||||
* than 10,, then 10 is used.
|
||||
*/
|
||||
private int dbCacheThreadPriority = 1;
|
||||
|
||||
/**
|
||||
* DB Cache Frequency
|
||||
*
|
||||
* The number of seconds in between DB cache updates. If DB Cache is disabled, then this is ignored.
|
||||
*/
|
||||
private int dbCacheFrequency = 120;
|
||||
|
||||
/**
|
||||
* Network Thread Priority
|
||||
*
|
||||
* The Network Thread Priority
|
||||
*
|
||||
* The thread priority (1 is lowest, 10 is highest) of the threads used for network peer connections. This is the
|
||||
* main thread connecting to a peer in the network.
|
||||
*/
|
||||
private int networkThreadPriority = 7;
|
||||
|
||||
/**
|
||||
* The Handshake Thread Priority
|
||||
*
|
||||
* The thread priority (1 i slowest, 10 is highest) of the threads used for peer handshake messaging. This is a
|
||||
* secondary thread to exchange status messaging to a peer in the network.
|
||||
*/
|
||||
private int handshakeThreadPriority = 7;
|
||||
|
||||
/**
|
||||
* Pruning Thread Priority
|
||||
*
|
||||
* The thread priority (1 is lowest, 10 is highest) of the threads used for database pruning and trimming.
|
||||
*/
|
||||
private int pruningThreadPriority = 2;
|
||||
|
||||
/**
|
||||
* Sychronizer Thread Priority
|
||||
*
|
||||
* The thread priority (1 is lowest, 10 is highest) of the threads used for synchronizing with the others peers.
|
||||
*/
|
||||
private int synchronizerThreadPriority = 10;
|
||||
|
||||
/**
|
||||
* Archiving Pause
|
||||
*
|
||||
* In milliseconds
|
||||
*
|
||||
* The pause in between archiving blocks to allow other processes to execute.
|
||||
*/
|
||||
private long archivingPause = 3000;
|
||||
|
||||
private boolean balanceRecorderEnabled = false;
|
||||
|
||||
private int balanceRecorderPriority = 1;
|
||||
|
||||
private int balanceRecorderFrequency = 2*60*1000;
|
||||
|
||||
private int balanceRecorderCapacity = 1000;
|
||||
|
||||
// Domain mapping
|
||||
public static class ThreadLimit {
|
||||
@ -986,10 +909,6 @@ public class Settings {
|
||||
return this.autoUpdateEnabled;
|
||||
}
|
||||
|
||||
public boolean isAutoRestartEnabled() {
|
||||
return this.autoRestartEnabled;
|
||||
}
|
||||
|
||||
public String[] getAutoUpdateRepos() {
|
||||
return this.autoUpdateRepos;
|
||||
}
|
||||
@ -1130,9 +1049,6 @@ public class Settings {
|
||||
return bitcoinjLookaheadSize;
|
||||
}
|
||||
|
||||
public int getBlockchainCacheLimit() {
|
||||
return blockchainCacheLimit;
|
||||
}
|
||||
|
||||
public boolean isQdnEnabled() {
|
||||
return this.qdnEnabled;
|
||||
@ -1209,52 +1125,4 @@ public class Settings {
|
||||
public Integer getThreadCountPerMessageTypeWarningThreshold() {
|
||||
return this.threadCountPerMessageTypeWarningThreshold;
|
||||
}
|
||||
|
||||
public boolean isDbCacheEnabled() {
|
||||
return dbCacheEnabled;
|
||||
}
|
||||
|
||||
public int getDbCacheThreadPriority() {
|
||||
return dbCacheThreadPriority;
|
||||
}
|
||||
|
||||
public int getDbCacheFrequency() {
|
||||
return dbCacheFrequency;
|
||||
}
|
||||
|
||||
public int getNetworkThreadPriority() {
|
||||
return networkThreadPriority;
|
||||
}
|
||||
|
||||
public int getHandshakeThreadPriority() {
|
||||
return handshakeThreadPriority;
|
||||
}
|
||||
|
||||
public int getPruningThreadPriority() {
|
||||
return pruningThreadPriority;
|
||||
}
|
||||
|
||||
public int getSynchronizerThreadPriority() {
|
||||
return synchronizerThreadPriority;
|
||||
}
|
||||
|
||||
public long getArchivingPause() {
|
||||
return archivingPause;
|
||||
}
|
||||
|
||||
public int getBalanceRecorderPriority() {
|
||||
return balanceRecorderPriority;
|
||||
}
|
||||
|
||||
public int getBalanceRecorderFrequency() {
|
||||
return balanceRecorderFrequency;
|
||||
}
|
||||
|
||||
public int getBalanceRecorderCapacity() {
|
||||
return balanceRecorderCapacity;
|
||||
}
|
||||
|
||||
public boolean isBalanceRecorderEnabled() {
|
||||
return balanceRecorderEnabled;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package org.qortal.transaction;
|
||||
import com.google.common.base.Utf8;
|
||||
import org.qortal.account.Account;
|
||||
import org.qortal.asset.Asset;
|
||||
import org.qortal.block.BlockChain;
|
||||
import org.qortal.controller.repository.NamesDatabaseIntegrityCheck;
|
||||
import org.qortal.data.naming.NameData;
|
||||
import org.qortal.data.transaction.CancelSellNameTransactionData;
|
||||
@ -64,11 +63,8 @@ public class CancelSellNameTransaction extends Transaction {
|
||||
return ValidationResult.NAME_DOES_NOT_EXIST;
|
||||
|
||||
// Check name is currently for sale
|
||||
if (!nameData.isForSale()) {
|
||||
// Only validate after feature-trigger timestamp, due to a small number of double cancelations in the chain history
|
||||
if (this.cancelSellNameTransactionData.getTimestamp() > BlockChain.getInstance().getCancelSellNameValidationTimestamp())
|
||||
if (!nameData.isForSale())
|
||||
return ValidationResult.NAME_NOT_FOR_SALE;
|
||||
}
|
||||
|
||||
// Check transaction creator matches name's current owner
|
||||
Account owner = getOwner();
|
||||
|
@ -98,14 +98,6 @@ public class RewardShareTransaction extends Transaction {
|
||||
|
||||
@Override
|
||||
public ValidationResult isValid() throws DataException {
|
||||
final int disableRs = BlockChain.getInstance().getDisableRewardshareHeight();
|
||||
final int enableRs = BlockChain.getInstance().getEnableRewardshareHeight();
|
||||
int blockchainHeight = this.repository.getBlockRepository().getBlockchainHeight();
|
||||
|
||||
// Check if reward share is disabled.
|
||||
if (blockchainHeight >= disableRs && blockchainHeight < enableRs)
|
||||
return ValidationResult.GENERAL_TEMPORARY_DISABLED;
|
||||
|
||||
// Check reward share given to recipient. Negative is potentially OK to end a current reward-share. Zero also fine.
|
||||
if (this.rewardShareTransactionData.getSharePercent() > MAX_SHARE)
|
||||
return ValidationResult.INVALID_REWARD_SHARE_PERCENT;
|
||||
@ -123,7 +115,7 @@ public class RewardShareTransaction extends Transaction {
|
||||
final boolean isCancellingSharePercent = this.rewardShareTransactionData.getSharePercent() < 0;
|
||||
|
||||
// Creator themselves needs to be allowed to mint (unless cancelling)
|
||||
if (!isCancellingSharePercent && !creator.canMint(false))
|
||||
if (!isCancellingSharePercent && !creator.canMint())
|
||||
return ValidationResult.NOT_MINTING_ACCOUNT;
|
||||
|
||||
// Qortal: special rules in play depending whether recipient is also minter
|
||||
|
@ -249,7 +249,6 @@ public abstract class Transaction {
|
||||
ACCOUNT_NOT_TRANSFERABLE(99),
|
||||
TRANSFER_PRIVS_DISABLED(100),
|
||||
TEMPORARY_DISABLED(101),
|
||||
GENERAL_TEMPORARY_DISABLED(102),
|
||||
INVALID_BUT_OK(999),
|
||||
NOT_YET_RELEASED(1000),
|
||||
NOT_SUPPORTED(1001);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user