├── LICENSE.md
├── README.md
├── jminer.default.properties
├── libShabal
├── libshabal.dll
├── libshabal.dylib
└── libshabal.so
├── pom.xml
├── run.bat
└── src
└── main
├── java
├── burstcoin
│ └── jminer
│ │ ├── JMinerApplication.java
│ │ ├── JMinerCommandLine.java
│ │ └── core
│ │ ├── CoreConfig.java
│ │ ├── CoreProperties.java
│ │ ├── checker
│ │ ├── Checker.java
│ │ ├── event
│ │ │ └── CheckerResultEvent.java
│ │ └── util
│ │ │ ├── OCLChecker.java
│ │ │ ├── ShaLibChecker.java
│ │ │ ├── calcdeadlines.cl
│ │ │ └── package-info.java
│ │ ├── network
│ │ ├── Network.java
│ │ ├── event
│ │ │ ├── NetworkBlocksEvent.java
│ │ │ ├── NetworkLastWinnerEvent.java
│ │ │ ├── NetworkPoolInfoEvent.java
│ │ │ ├── NetworkQualityChangeEvent.java
│ │ │ ├── NetworkResultConfirmedEvent.java
│ │ │ ├── NetworkResultErrorEvent.java
│ │ │ └── NetworkStateChangeEvent.java
│ │ ├── model
│ │ │ ├── Account.java
│ │ │ ├── Accounts.java
│ │ │ ├── Base.java
│ │ │ ├── Block.java
│ │ │ ├── BlockchainStatus.java
│ │ │ ├── Blocks.java
│ │ │ ├── MiningInfo.java
│ │ │ ├── ResponseError.java
│ │ │ ├── RewardRecipient.java
│ │ │ └── SubmitResult.java
│ │ └── task
│ │ │ ├── NetworkRequestAccountBlocksTask.java
│ │ │ ├── NetworkRequestLastWinnerTask.java
│ │ │ ├── NetworkRequestMiningInfoTask.java
│ │ │ ├── NetworkRequestPoolInfoTask.java
│ │ │ ├── NetworkSubmitPoolNonceTask.java
│ │ │ └── NetworkSubmitSoloNonceTask.java
│ │ ├── reader
│ │ ├── Reader.java
│ │ ├── data
│ │ │ ├── PlotDrive.java
│ │ │ ├── PlotFile.java
│ │ │ ├── Plots.java
│ │ │ └── PocVersion.java
│ │ ├── event
│ │ │ ├── ReaderCorruptFileEvent.java
│ │ │ ├── ReaderDriveFinishEvent.java
│ │ │ ├── ReaderDriveInterruptedEvent.java
│ │ │ ├── ReaderLoadedPartEvent.java
│ │ │ └── ReaderProgressChangedEvent.java
│ │ └── task
│ │ │ ├── ReaderConvertLoadDriveTask.java
│ │ │ └── ReaderLoadDriveTask.java
│ │ └── round
│ │ ├── Round.java
│ │ └── event
│ │ ├── RoundFinishedEvent.java
│ │ ├── RoundGenSigAlreadyMinedEvent.java
│ │ ├── RoundGenSigUpdatedEvent.java
│ │ ├── RoundSingleResultEvent.java
│ │ ├── RoundSingleResultSkippedEvent.java
│ │ ├── RoundStartedEvent.java
│ │ └── RoundStoppedEvent.java
├── nxt
│ ├── crypto
│ │ ├── Crypto.java
│ │ ├── Curve25519.java
│ │ ├── ReedSolomon.java
│ │ └── XoredData.java
│ └── util
│ │ └── Convert.java
├── org
│ └── jocl
│ │ └── utils
│ │ ├── CommandQueueInfos.java
│ │ ├── CommandQueues.java
│ │ ├── ContextInfos.java
│ │ ├── Contexts.java
│ │ ├── DeviceInfos.java
│ │ ├── Devices.java
│ │ ├── EventInfos.java
│ │ ├── EventProfilingInfos.java
│ │ ├── Events.java
│ │ ├── Infos.java
│ │ ├── KernelInfos.java
│ │ ├── Kernels.java
│ │ ├── MemInfos.java
│ │ ├── Mems.java
│ │ ├── PlatformInfos.java
│ │ ├── Platforms.java
│ │ ├── PointerUtils.java
│ │ ├── ProgramInfos.java
│ │ └── Programs.java
└── pocminer
│ └── generate
│ └── MiningPlot.java
└── resources
└── application.properties
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015-2019 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/libShabal/libshabal.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/de-luxe/burstcoin-jminer/30a20332a8974a13dc6f38f316fe7cbfaa90d42e/libShabal/libshabal.dll
--------------------------------------------------------------------------------
/libShabal/libshabal.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/de-luxe/burstcoin-jminer/30a20332a8974a13dc6f38f316fe7cbfaa90d42e/libShabal/libshabal.dylib
--------------------------------------------------------------------------------
/libShabal/libshabal.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/de-luxe/burstcoin-jminer/30a20332a8974a13dc6f38f316fe7cbfaa90d42e/libShabal/libshabal.so
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | burstcoin
6 | burstcoin-jminer
7 | 0.6.0-RELEASE
8 | jar
9 |
10 | burstcoin-jminer
11 |
12 | Burstcoin (BURST) - GPU assisted PoC-Miner
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 2.1.3.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | burstcoin.jminer.JMinerApplication
24 | 1.8
25 | 1.5.0
26 | 3.0.5
27 | 1.61
28 |
29 |
30 |
31 |
32 |
33 | org.springframework.boot
34 | spring-boot-starter
35 |
36 |
37 |
38 | org.springframework.boot
39 | spring-boot-starter-jetty
40 |
41 |
42 |
43 | org.jocl
44 | jocl-blast
45 | ${jocl-blast.version}
46 |
47 |
48 |
49 | de.sfuhrm
50 | saphir-hash-core
51 | ${saphir-hash.version}
52 |
53 |
54 |
55 | org.bouncycastle
56 | bcprov-jdk15on
57 | ${bcprov-jdk15on.version}
58 |
59 |
60 |
61 | com.fasterxml.jackson.core
62 | jackson-core
63 |
64 |
65 |
66 | com.fasterxml.jackson.core
67 | jackson-databind
68 |
69 |
70 |
71 | com.fasterxml.jackson.core
72 | jackson-annotations
73 |
74 |
75 |
76 | net.java.dev.jna
77 | jna
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | src/main/java
87 |
88 | burstcoin/jminer/core/**/*.cl
89 |
90 |
91 |
92 | src/main/resources
93 |
94 | **/*.txt
95 | **/*.properties
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 | org.springframework.boot
105 | spring-boot-maven-plugin
106 |
107 |
108 |
109 | org.apache.maven.plugins
110 | maven-antrun-plugin
111 | 1.8
112 |
113 |
114 | ant-clear
115 | prepare-package
116 |
117 | run
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | ant-zip
130 | package
131 |
132 | run
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
--------------------------------------------------------------------------------
/run.bat:
--------------------------------------------------------------------------------
1 | java -jar -d64 -XX:+UseG1GC burstcoin-jminer-0.6.0-RELEASE.jar
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/JMinerApplication.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 | import org.springframework.boot.Banner;
29 | import org.springframework.boot.CommandLineRunner;
30 | import org.springframework.boot.autoconfigure.SpringBootApplication;
31 | import org.springframework.boot.builder.SpringApplicationBuilder;
32 | import org.springframework.context.ConfigurableApplicationContext;
33 | import org.springframework.context.annotation.Bean;
34 |
35 | import java.util.HashMap;
36 | import java.util.Map;
37 |
38 | @SpringBootApplication
39 | public class JMinerApplication
40 | {
41 | private static final Logger LOG = LoggerFactory.getLogger(JMinerApplication.class);
42 |
43 | private static double JAVA_VERSION;
44 |
45 | static
46 | {
47 | String version = System.getProperty("java.version");
48 | int pos = version.indexOf('.');
49 | pos = version.indexOf('.', pos + 1);
50 | JAVA_VERSION = Double.parseDouble(version.substring(0, pos));
51 | }
52 |
53 | public static void main(String[] args)
54 | {
55 | // inform users with java9, that jminer will not function with it.
56 | if(1.8d != JAVA_VERSION)
57 | {
58 | LOG.error("jminer needs Java8 (1.8)");
59 | LOG.error("java version '" + JAVA_VERSION + "' is not supported!");
60 | LOG.error("Uninstall your java '" + JAVA_VERSION + "' and install Java8!");
61 | }
62 | else
63 | {
64 | LOG.info("Starting the engines ... please wait!");
65 |
66 | // overwritten by application.properties
67 | Map properties = new HashMap<>();
68 | if(CoreProperties.isWriteLogFile())
69 | {
70 | properties.put("logging.file", CoreProperties.getLogFilePath());
71 | }
72 | properties.put("logging.level.burstcoin.jminer", CoreProperties.isDebug() ? "DEBUG" : "INFO");
73 | if(CoreProperties.getLogPatternConsole() != null)
74 | {
75 | properties.put("logging.pattern.console", CoreProperties.getLogPatternConsole());
76 | }
77 | if(CoreProperties.getLogPatternFile() != null)
78 | {
79 | properties.put("logging.pattern.file", CoreProperties.getLogPatternFile());
80 | }
81 |
82 | new SpringApplicationBuilder(JMinerApplication.class)
83 | .bannerMode(Banner.Mode.OFF) // turn off spring boot banner
84 | .logStartupInfo(false)
85 | .properties(properties) // add application.properties
86 | .build(args)
87 | .run();
88 | }
89 | }
90 |
91 | @Bean
92 | public CommandLineRunner getCommandLineRunner(ConfigurableApplicationContext context)
93 | {
94 | return new JMinerCommandLine(context);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/CoreConfig.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core;
24 |
25 | import com.fasterxml.jackson.databind.ObjectMapper;
26 | import org.eclipse.jetty.client.HttpClient;
27 | import org.eclipse.jetty.util.ssl.SslContextFactory;
28 | import org.slf4j.Logger;
29 | import org.slf4j.LoggerFactory;
30 | import org.springframework.context.annotation.Bean;
31 | import org.springframework.context.annotation.ComponentScan;
32 | import org.springframework.context.annotation.Configuration;
33 | import org.springframework.core.task.SimpleAsyncTaskExecutor;
34 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
35 |
36 | /**
37 | * The type Core config.
38 | */
39 | @Configuration
40 | @ComponentScan(basePackages = {"burstcoin.jminer.core"})
41 | public class CoreConfig
42 | {
43 | private static final Logger LOG = LoggerFactory.getLogger(CoreConfig.class);
44 |
45 | @Bean(name = "readerPool")
46 | public ThreadPoolTaskExecutor readerPool()
47 | {
48 | ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
49 | pool.setThreadPriority(Thread.MIN_PRIORITY);
50 | // false-> triggers interrupt exception at shutdown
51 | pool.setWaitForTasksToCompleteOnShutdown(true);
52 | pool.initialize();
53 | return pool;
54 | }
55 |
56 | @Bean(name = "networkPool")
57 | public SimpleAsyncTaskExecutor networkPool()
58 | {
59 | SimpleAsyncTaskExecutor pool = new SimpleAsyncTaskExecutor();
60 | pool.setThreadPriority(Thread.NORM_PRIORITY);
61 | return pool;
62 | }
63 |
64 | @Bean
65 | public HttpClient httpClient()
66 | {
67 | SslContextFactory sslContextFactory = new SslContextFactory(null);
68 | sslContextFactory.setEndpointIdentificationAlgorithm("none");
69 |
70 | HttpClient client = new HttpClient(sslContextFactory);
71 | try
72 | {
73 | client.start();
74 | }
75 | catch(Exception e)
76 | {
77 | e.printStackTrace();
78 | }
79 | return client;
80 | }
81 |
82 | @Bean
83 | public ObjectMapper objectMapper()
84 | {
85 | return new ObjectMapper();
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/checker/Checker.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.checker;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.checker.event.CheckerResultEvent;
27 | import burstcoin.jminer.core.checker.util.OCLChecker;
28 | import burstcoin.jminer.core.reader.event.ReaderLoadedPartEvent;
29 | import org.slf4j.Logger;
30 | import org.slf4j.LoggerFactory;
31 | import org.springframework.beans.factory.annotation.Autowired;
32 | import org.springframework.context.ApplicationEventPublisher;
33 | import org.springframework.context.annotation.Scope;
34 | import org.springframework.context.event.EventListener;
35 | import org.springframework.stereotype.Component;
36 |
37 | import java.util.Arrays;
38 | import java.util.concurrent.atomic.AtomicLong;
39 |
40 | /**
41 | * The type Checker.
42 | */
43 | @Component
44 | @Scope("singleton")
45 | public class Checker
46 | {
47 | private static final Logger LOG = LoggerFactory.getLogger(Checker.class);
48 |
49 | private final ApplicationEventPublisher publisher;
50 | private final OCLChecker oclChecker;
51 |
52 | // data
53 | private volatile AtomicLong blockNumber;
54 | private volatile byte[] generationSignature;
55 |
56 | @Autowired
57 | public Checker(ApplicationEventPublisher publisher, OCLChecker oclChecker)
58 | {
59 | this.publisher = publisher;
60 | this.oclChecker = oclChecker;
61 |
62 | blockNumber = new AtomicLong();
63 | }
64 |
65 | public void reconfigure(long blockNumber, byte[] generationSignature)
66 | {
67 | this.blockNumber.set(blockNumber);
68 | this.generationSignature = generationSignature;
69 | }
70 |
71 | @EventListener
72 | public void handleMessage(ReaderLoadedPartEvent event)
73 | {
74 | if(CoreProperties.isUseOpenCl() && blockNumber.get() == event.getBlockNumber() && Arrays.equals(generationSignature, event.getGenerationSignature()))
75 | {
76 | int lowestNonce;
77 | synchronized(oclChecker)
78 | {
79 | lowestNonce = oclChecker.findLowest(event.getGenerationSignature(), event.getScoops());
80 | }
81 | if(blockNumber.get() == event.getBlockNumber() && Arrays.equals(generationSignature, event.getGenerationSignature()))
82 | {
83 | publisher.publishEvent(new CheckerResultEvent(blockNumber.get(), generationSignature, event.getChunkPartStartNonce(), lowestNonce,
84 | event.getPlotFilePath(), event.getScoops()));
85 | }
86 | else
87 | {
88 | LOG.trace("skipped handle result ... outdated mining info...");
89 | }
90 | }
91 | else
92 | {
93 | LOG.trace("skipped check scoop ... outdated mining info...");
94 | }
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/checker/event/CheckerResultEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.checker.event;
24 |
25 | import java.math.BigInteger;
26 |
27 | /**
28 | * fired if chunk-part checked
29 | */
30 | public class CheckerResultEvent
31 | {
32 | private byte[] generationSignature;
33 | private BigInteger chunkPartStartNonce;
34 |
35 | private long blockNumber;
36 | private BigInteger result;
37 | private String plotFilePath;
38 | private byte[] scoops;
39 | private int lowestNonce;
40 |
41 | public CheckerResultEvent(long blockNumber, byte[] generationSignature, BigInteger chunkPartStartNonce, int lowestNonce, String plotFilePath, byte[] scoops)
42 | {
43 | this.generationSignature = generationSignature;
44 | this.chunkPartStartNonce = chunkPartStartNonce;
45 | this.blockNumber = blockNumber;
46 | this.lowestNonce = lowestNonce;
47 | this.plotFilePath = plotFilePath;
48 | this.scoops = scoops;
49 | }
50 |
51 | public String getPlotFilePath()
52 | {
53 | return plotFilePath;
54 | }
55 |
56 | public long getBlockNumber()
57 | {
58 | return blockNumber;
59 | }
60 |
61 | public BigInteger getResult()
62 | {
63 | return result;
64 | }
65 |
66 | public void setResult(BigInteger result)
67 | {
68 | this.result = result;
69 | }
70 |
71 | public byte[] getScoops()
72 | {
73 | return scoops;
74 | }
75 |
76 | public int getLowestNonce()
77 | {
78 | return lowestNonce;
79 | }
80 |
81 | public BigInteger getChunkPartStartNonce()
82 | {
83 | return chunkPartStartNonce;
84 | }
85 |
86 | public byte[] getGenerationSignature()
87 | {
88 | return generationSignature;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/checker/util/ShaLibChecker.java:
--------------------------------------------------------------------------------
1 | package burstcoin.jminer.core.checker.util;
2 |
3 | import com.sun.jna.Library;
4 | import com.sun.jna.Native;
5 | import pocminer.generate.MiningPlot;
6 |
7 | public class ShaLibChecker {
8 |
9 | private final ShabalLibrary shabalLibrary;
10 |
11 | public ShaLibChecker() {
12 | shabalLibrary = Native.loadLibrary("libshabal", ShabalLibrary.class);
13 | shabalLibrary.shabal_init();
14 | }
15 |
16 | private interface ShabalLibrary extends Library {
17 | long shabal_findBestDeadline(byte[] scoops, long numScoops, byte[] gensig);
18 | void shabal_init();
19 | }
20 |
21 | public int findLowest(byte[] gensig, byte[] data) {
22 | return (int) shabalLibrary.shabal_findBestDeadline(data, data.length / MiningPlot.SCOOP_SIZE, gensig);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/checker/util/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Org. OCLChecker code and the used openCL kernels are provided by 'burst dev'.
3 | *
4 | * Please donate: BURST-QHCJ-9HB5-PTGC-5Q8J9
5 | */
6 | package burstcoin.jminer.core.checker.util;
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/Network.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkStateChangeEvent;
27 | import burstcoin.jminer.core.network.task.NetworkRequestLastWinnerTask;
28 | import burstcoin.jminer.core.network.task.NetworkRequestMiningInfoTask;
29 | import burstcoin.jminer.core.network.task.NetworkRequestPoolInfoTask;
30 | import burstcoin.jminer.core.network.task.NetworkSubmitPoolNonceTask;
31 | import burstcoin.jminer.core.network.task.NetworkSubmitSoloNonceTask;
32 | import burstcoin.jminer.core.reader.Reader;
33 | import burstcoin.jminer.core.reader.data.Plots;
34 | import org.slf4j.Logger;
35 | import org.slf4j.LoggerFactory;
36 | import org.springframework.beans.factory.annotation.Autowired;
37 | import org.springframework.beans.factory.annotation.Qualifier;
38 | import org.springframework.context.ApplicationContext;
39 | import org.springframework.context.annotation.Scope;
40 | import org.springframework.context.event.EventListener;
41 | import org.springframework.core.task.SimpleAsyncTaskExecutor;
42 | import org.springframework.stereotype.Component;
43 | import org.springframework.util.StringUtils;
44 |
45 | import javax.annotation.PostConstruct;
46 | import java.math.BigInteger;
47 | import java.net.InetAddress;
48 | import java.net.NetworkInterface;
49 | import java.util.Timer;
50 | import java.util.TimerTask;
51 |
52 | @Component
53 | @Scope("singleton")
54 | public class Network
55 | {
56 | private static final Logger LOG = LoggerFactory.getLogger(Network.class);
57 |
58 | private final ApplicationContext context;
59 | private final SimpleAsyncTaskExecutor networkPool;
60 |
61 | private long blockNumber;
62 | private Timer timer;
63 | private byte[] generationSignature;
64 | private String mac; // unique system id
65 | private Plots plots;
66 |
67 | @Autowired
68 | public Network(ApplicationContext context, @Qualifier(value = "networkPool") SimpleAsyncTaskExecutor networkPool)
69 | {
70 | this.context = context;
71 | this.networkPool = networkPool;
72 | }
73 |
74 | @PostConstruct
75 | protected void postConstruct()
76 | {
77 | // init drives/plotfiles ... ensure miner starts after that
78 | Reader reader = context.getBean(Reader.class);
79 | plots = reader.getPlots();
80 |
81 | mac = getMac();
82 | timer = new Timer();
83 |
84 | if(CoreProperties.isPoolMining() && (StringUtils.isEmpty(CoreProperties.getPoolServer()) || StringUtils.isEmpty(CoreProperties.getNumericAccountId())))
85 | {
86 | LOG.error("init pool network failed!");
87 | LOG.error("jminer.properties: 'poolServer' or 'numericAccountId' is missing?!");
88 | }
89 | if(!CoreProperties.isPoolMining() && (StringUtils.isEmpty(CoreProperties.getSoloServer()) || StringUtils.isEmpty(CoreProperties.getPassPhrase())))
90 | {
91 | LOG.error("init solo network failed!");
92 | LOG.error("jminer.properties: 'soloServer' or 'passPhrase' is missing?!");
93 | }
94 | }
95 |
96 | private String getMac()
97 | {
98 | InetAddress ip;
99 | StringBuilder sb = new StringBuilder();
100 | try
101 | {
102 | ip = InetAddress.getLocalHost();
103 | NetworkInterface network = NetworkInterface.getByInetAddress(ip);
104 | byte[] mac = network.getHardwareAddress();
105 | sb = new StringBuilder();
106 | for(int i = 0; i < mac.length; i++)
107 | {
108 | sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
109 | }
110 | }
111 | catch(Exception e)
112 | {
113 | LOG.debug("Could not create MAC address as unique id for mining system. Fallback capacity used.");
114 | }
115 | return sb.toString();
116 | }
117 |
118 | @EventListener
119 | public void handleMessage(NetworkStateChangeEvent event)
120 | {
121 | blockNumber = event.getBlockNumber();
122 | generationSignature = event.getGenerationSignature();
123 | }
124 |
125 | private void checkNetworkState()
126 | {
127 | String server = CoreProperties.isPoolMining() ? CoreProperties.getPoolServer() : CoreProperties.getSoloServer();
128 | if(!StringUtils.isEmpty(server))
129 | {
130 | NetworkRequestMiningInfoTask networkRequestMiningInfoTask = context.getBean(NetworkRequestMiningInfoTask.class);
131 | networkRequestMiningInfoTask.init(server, blockNumber, generationSignature, plots.getSize());
132 | networkPool.execute(networkRequestMiningInfoTask);
133 | }
134 | }
135 |
136 | public void checkLastWinner(long blockNumber)
137 | {
138 | // find winner of lastBlock on new round, if server available
139 | String server = !CoreProperties.isPoolMining() ? CoreProperties.getSoloServer() : CoreProperties.getWalletServer();
140 | if(!StringUtils.isEmpty(server))
141 | {
142 | NetworkRequestLastWinnerTask networkRequestLastWinnerTask = context.getBean(NetworkRequestLastWinnerTask.class);
143 | networkRequestLastWinnerTask.init(server, blockNumber);
144 | networkPool.execute(networkRequestLastWinnerTask);
145 | }
146 | }
147 |
148 | public void checkPoolInfo()
149 | {
150 | if(CoreProperties.isPoolMining() && CoreProperties.getWalletServer() != null)
151 | {
152 | networkPool.execute(context.getBean(NetworkRequestPoolInfoTask.class));
153 | }
154 | }
155 |
156 | public void commitResult(long blockNumber, long calculatedDeadline, BigInteger nonce, BigInteger chunkPartStartNonce, long totalCapacity,
157 | BigInteger result, String plotFilePath)
158 | {
159 | if(CoreProperties.isPoolMining())
160 | {
161 | NetworkSubmitPoolNonceTask networkSubmitPoolNonceTask = context.getBean(NetworkSubmitPoolNonceTask.class);
162 | networkSubmitPoolNonceTask.init(blockNumber, generationSignature, nonce, chunkPartStartNonce, calculatedDeadline,
163 | totalCapacity, result, plotFilePath, mac);
164 | networkPool.execute(networkSubmitPoolNonceTask);
165 | }
166 | else
167 | {
168 | NetworkSubmitSoloNonceTask networkSubmitSoloNonceTask = context.getBean(NetworkSubmitSoloNonceTask.class);
169 | networkSubmitSoloNonceTask.init(blockNumber, generationSignature, nonce, chunkPartStartNonce, calculatedDeadline, result);
170 | networkPool.execute(networkSubmitSoloNonceTask);
171 | }
172 | }
173 |
174 | public void startMining()
175 | {
176 | timer.schedule(new TimerTask()
177 | {
178 | @Override
179 | public void run()
180 | {
181 | checkNetworkState();
182 | }
183 | }, 1000, CoreProperties.getRefreshInterval());
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkBlocksEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import burstcoin.jminer.core.network.model.Blocks;
26 |
27 | public class NetworkBlocksEvent
28 | {
29 | private Blocks blocks;
30 |
31 | public NetworkBlocksEvent(Blocks blocks)
32 | {
33 | this.blocks = blocks;
34 | }
35 |
36 | public Blocks getBlocks()
37 | {
38 | return blocks;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkLastWinnerEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | /**
28 | * fired if last winner was found
29 | */
30 | public class NetworkLastWinnerEvent
31 | extends ApplicationEvent
32 | {
33 | private long lastBlockNumber;
34 | private String winner;
35 |
36 | /**
37 | * Instantiates a new Network last winner event.
38 | *
39 | * @param source the source
40 | * @param lastBlockNumber the last block number
41 | * @param winner the winner
42 | */
43 | public NetworkLastWinnerEvent(Object source, long lastBlockNumber, String winner)
44 | {
45 | super(source);
46 | this.lastBlockNumber = lastBlockNumber;
47 | this.winner = winner;
48 | }
49 |
50 | /**
51 | * Gets last block number.
52 | *
53 | * @return the last block number
54 | */
55 | public long getLastBlockNumber()
56 | {
57 | return lastBlockNumber;
58 | }
59 |
60 | /**
61 | * Gets winner.
62 | *
63 | * @return the winner
64 | */
65 | public String getWinner()
66 | {
67 | return winner;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkPoolInfoEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 |
28 | public class NetworkPoolInfoEvent
29 | extends ApplicationEvent
30 | {
31 | private String poolAccountRS;
32 | private String poolBalanceNQT;
33 | private String poolForgedBalanceNQT;
34 | private int poolNumberOfMiningAccounts; // todo find active
35 |
36 | public NetworkPoolInfoEvent(String poolAccountRS, String poolBalanceNQT, String poolForgedBalanceNQT, int poolNumberOfMiningAccounts)
37 | {
38 | super(poolAccountRS);
39 |
40 | this.poolAccountRS = poolAccountRS;
41 | this.poolBalanceNQT = poolBalanceNQT;
42 | this.poolForgedBalanceNQT = poolForgedBalanceNQT;
43 | this.poolNumberOfMiningAccounts = poolNumberOfMiningAccounts;
44 | }
45 |
46 | public String getPoolAccountRS()
47 | {
48 | return poolAccountRS;
49 | }
50 |
51 | public String getPoolBalanceNQT()
52 | {
53 | return poolBalanceNQT;
54 | }
55 |
56 | public String getPoolForgedBalanceNQT()
57 | {
58 | return poolForgedBalanceNQT;
59 | }
60 |
61 | public int getPoolNumberOfMiningAccounts()
62 | {
63 | return poolNumberOfMiningAccounts;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkQualityChangeEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2018 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import java.io.Serializable;
26 |
27 | /* just for statistics of network quality, information on succeeded or not succeeded requests*/
28 | public class NetworkQualityChangeEvent
29 | implements Serializable
30 | {
31 | private boolean success;
32 |
33 | public NetworkQualityChangeEvent(boolean success)
34 | {
35 | this.success = success;
36 | }
37 |
38 | public boolean isSuccess()
39 | {
40 | return success;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkResultConfirmedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 |
26 | import org.springframework.context.ApplicationEvent;
27 |
28 | import java.math.BigInteger;
29 |
30 | /**
31 | * fired if calculatedDeadline was confirmed by server
32 | */
33 | public class NetworkResultConfirmedEvent
34 | extends ApplicationEvent
35 | {
36 | private long blockNumber;
37 | private byte[] generationSignature;
38 | private long deadline;
39 | private BigInteger nonce;
40 |
41 | private BigInteger chunkPartStartNonce;
42 | private BigInteger result;
43 |
44 | /**
45 | * Instantiates a new Network result confirmed event.
46 | *
47 | * @param blockNumber the block number
48 | * @param deadline the deadline
49 | * @param nonce the nonce
50 | * @param chunkPartStartNonce the chunk part start nonce
51 | */
52 | public NetworkResultConfirmedEvent(long blockNumber, byte[] generationSignature, long deadline, BigInteger nonce, BigInteger chunkPartStartNonce, BigInteger result)
53 | {
54 | super(blockNumber);
55 |
56 | this.blockNumber = blockNumber;
57 | this.generationSignature = generationSignature;
58 | this.deadline = deadline;
59 | this.nonce = nonce;
60 |
61 | this.chunkPartStartNonce = chunkPartStartNonce;
62 | this.result = result;
63 | }
64 |
65 | /**
66 | * Gets chunk part start nonce.
67 | *
68 | * @return the chunk part start nonce
69 | */
70 | public BigInteger getChunkPartStartNonce()
71 | {
72 | return chunkPartStartNonce;
73 | }
74 |
75 | /**
76 | * Gets block number.
77 | *
78 | * @return the block number
79 | */
80 | public long getBlockNumber()
81 | {
82 | return blockNumber;
83 | }
84 |
85 | /**
86 | * Gets deadline.
87 | *
88 | * @return the deadline
89 | */
90 | public long getDeadline()
91 | {
92 | return deadline;
93 | }
94 |
95 | /**
96 | * Gets nonce.
97 | *
98 | * @return the nonce
99 | */
100 | public BigInteger getNonce()
101 | {
102 | return nonce;
103 | }
104 |
105 | public BigInteger getResult()
106 | {
107 | return result;
108 | }
109 |
110 | public byte[] getGenerationSignature()
111 | {
112 | return generationSignature;
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkResultErrorEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | import java.math.BigInteger;
28 |
29 | /**
30 | * fired if server response deadline does not match calculated deadline.
31 | */
32 | public class NetworkResultErrorEvent
33 | extends ApplicationEvent
34 | {
35 | private long blockNumber;
36 | private byte[] generationSignature;
37 | private BigInteger nonce;
38 |
39 | private long calculatedDeadline;
40 | private long strangeDeadline;
41 |
42 | private BigInteger chunkPartStartNonce;
43 | private BigInteger result;
44 |
45 | /**
46 | * Instantiates a new Network result error event.
47 | *
48 | * @param blockNumber the block number
49 | * @param nonce the nonce
50 | * @param calculatedDeadline the calculated deadline
51 | * @param strangeDeadline the strange deadline
52 | * @param chunkPartStartNonce the chunk part start nonce
53 | */
54 | public NetworkResultErrorEvent(long blockNumber, byte[] generationSignature, BigInteger nonce, long calculatedDeadline, long strangeDeadline, BigInteger chunkPartStartNonce, BigInteger result)
55 | {
56 | super(blockNumber);
57 |
58 | this.blockNumber = blockNumber;
59 | this.generationSignature = generationSignature;
60 | this.nonce = nonce;
61 | this.calculatedDeadline = calculatedDeadline;
62 | this.strangeDeadline = strangeDeadline;
63 |
64 | this.chunkPartStartNonce = chunkPartStartNonce;
65 | this.result = result;
66 | }
67 |
68 | /**
69 | * Gets chunk part start nonce.
70 | *
71 | * @return the chunk part start nonce
72 | */
73 | public BigInteger getChunkPartStartNonce()
74 | {
75 | return chunkPartStartNonce;
76 | }
77 |
78 | /**
79 | * Gets block number.
80 | *
81 | * @return the block number
82 | */
83 | public long getBlockNumber()
84 | {
85 | return blockNumber;
86 | }
87 |
88 | /**
89 | * Gets nonce.
90 | *
91 | * @return the nonce
92 | */
93 | public BigInteger getNonce()
94 | {
95 | return nonce;
96 | }
97 |
98 | /**
99 | * Gets calculated deadline.
100 | *
101 | * @return the calculated deadline
102 | */
103 | public long getCalculatedDeadline()
104 | {
105 | return calculatedDeadline;
106 | }
107 |
108 | /**
109 | * Gets strange deadline.
110 | *
111 | * @return the strange deadline
112 | */
113 | public long getStrangeDeadline()
114 | {
115 | return strangeDeadline;
116 | }
117 |
118 | public BigInteger getResult()
119 | {
120 | return result;
121 | }
122 |
123 | public byte[] getGenerationSignature()
124 | {
125 | return generationSignature;
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/event/NetworkStateChangeEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | /**
28 | * The type Network state change event.
29 | */
30 | /* fired if a new block has started */
31 | public class NetworkStateChangeEvent
32 | extends ApplicationEvent
33 | {
34 | private long blockNumber;
35 | private byte[] generationSignature;
36 | private long baseTarget;
37 |
38 | // targetDeadline provided via property or server in miningInfo (depends on solo/pool mining)
39 | private long targetDeadline;
40 |
41 | /**
42 | * Instantiates a new Network state change event.
43 | *
44 | * @param blockNumber the block number
45 | * @param baseTarget the base target
46 | * @param generationSignature the generation signature
47 | * @param targetDeadline the target deadline
48 | */
49 | public NetworkStateChangeEvent(long blockNumber, long baseTarget, byte[] generationSignature, long targetDeadline)
50 | {
51 | super(blockNumber);
52 |
53 | this.blockNumber = blockNumber;
54 | this.baseTarget = baseTarget;
55 | this.generationSignature = generationSignature;
56 | this.targetDeadline = targetDeadline;
57 | }
58 |
59 | /**
60 | * Gets block number.
61 | *
62 | * @return the block number
63 | */
64 | public long getBlockNumber()
65 | {
66 | return blockNumber;
67 | }
68 |
69 | /**
70 | * Get generation signature.
71 | *
72 | * @return the byte [ ]
73 | */
74 | public byte[] getGenerationSignature()
75 | {
76 | return generationSignature;
77 | }
78 |
79 | /**
80 | * Gets target deadline.
81 | *
82 | * @return the target deadline
83 | */
84 | public long getTargetDeadline()
85 | {
86 | return targetDeadline;
87 | }
88 |
89 | /**
90 | * Gets base target.
91 | *
92 | * @return the base target
93 | */
94 | public long getBaseTarget()
95 | {
96 | return baseTarget;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/Account.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
26 |
27 | @JsonIgnoreProperties(ignoreUnknown = true)
28 | public class Account
29 | extends Base
30 | {
31 | private String accountRS;
32 | private String balanceNQT;
33 | private String forgedBalanceNQT;
34 |
35 | public String getAccountRS()
36 | {
37 | return accountRS;
38 | }
39 |
40 | public String getBalanceNQT()
41 | {
42 | return balanceNQT;
43 | }
44 |
45 | public String getForgedBalanceNQT()
46 | {
47 | return forgedBalanceNQT;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/Accounts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 |
26 | import java.util.List;
27 |
28 | public class Accounts
29 | extends Base
30 | {
31 | private List accounts;
32 |
33 | public List getAccounts()
34 | {
35 | return accounts;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/Base.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2019 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import java.io.Serializable;
26 |
27 | public class Base
28 | implements Serializable
29 | {
30 | private long requestProcessingTime;
31 |
32 | public long getRequestProcessingTime()
33 | {
34 | return requestProcessingTime;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/Block.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import java.util.List;
26 |
27 |
28 | public class Block
29 | extends Base
30 | {
31 | private String previousBlockHash;
32 | private int payloadLength;
33 | private String totalAmountNQT;
34 | private String generationSignature;
35 | private String generator;
36 | private String generatorPublicKey;
37 | private String baseTarget;
38 | private String payloadHash;
39 | private String generatorRS;
40 | private String blockReward;
41 | private int scoopNum;
42 | private long numberOfTransactions;
43 | private String blockSignature;
44 | private List transactions;
45 | private String nonce;
46 | private String version;
47 | private String totalFeeNQT;
48 | private String nextBlock;
49 | private String previousBlock;
50 | private String block;
51 | private long height;
52 | private int timestamp;
53 |
54 | public String getPreviousBlockHash()
55 | {
56 | return previousBlockHash;
57 | }
58 |
59 | public int getPayloadLength()
60 | {
61 | return payloadLength;
62 | }
63 |
64 | public String getTotalAmountNQT()
65 | {
66 | return totalAmountNQT;
67 | }
68 |
69 | public String getGenerationSignature()
70 | {
71 | return generationSignature;
72 | }
73 |
74 | public String getGenerator()
75 | {
76 | return generator;
77 | }
78 |
79 | public String getGeneratorPublicKey()
80 | {
81 | return generatorPublicKey;
82 | }
83 |
84 | public String getBaseTarget()
85 | {
86 | return baseTarget;
87 | }
88 |
89 | public String getPayloadHash()
90 | {
91 | return payloadHash;
92 | }
93 |
94 | public String getGeneratorRS()
95 | {
96 | return generatorRS;
97 | }
98 |
99 | public String getBlockReward()
100 | {
101 | return blockReward;
102 | }
103 |
104 | public int getScoopNum()
105 | {
106 | return scoopNum;
107 | }
108 |
109 | public long getNumberOfTransactions()
110 | {
111 | return numberOfTransactions;
112 | }
113 |
114 | public String getBlockSignature()
115 | {
116 | return blockSignature;
117 | }
118 |
119 | public List getTransactions()
120 | {
121 | return transactions;
122 | }
123 |
124 | public String getNonce()
125 | {
126 | return nonce;
127 | }
128 |
129 | public String getVersion()
130 | {
131 | return version;
132 | }
133 |
134 | public String getTotalFeeNQT()
135 | {
136 | return totalFeeNQT;
137 | }
138 |
139 | public String getNextBlock()
140 | {
141 | return nextBlock;
142 | }
143 |
144 | public String getPreviousBlock()
145 | {
146 | return previousBlock;
147 | }
148 |
149 | public String getBlock()
150 | {
151 | return block;
152 | }
153 |
154 | public long getHeight()
155 | {
156 | return height;
157 | }
158 |
159 | public int getTimestamp()
160 | {
161 | return timestamp;
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/BlockchainStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import java.io.Serializable;
26 |
27 | /**
28 | * The type Blockchain status.
29 | */
30 | public class BlockchainStatus
31 | implements Serializable
32 | {
33 | private String lastBlock;
34 | private String application;
35 | private Boolean isScanning;
36 | private String cumulativeDifficulty;
37 | private int lastBlockchainFeederHeight;
38 | private int numberOfBlocks;
39 | private long time;
40 | private int requestProcessingTime;
41 | private String version;
42 | private String lastBlockchainFeeder;
43 |
44 | /**
45 | * Instantiates a new Blockchain status.
46 | */
47 | public BlockchainStatus()
48 | {
49 | }
50 |
51 | /**
52 | * Gets last block.
53 | *
54 | * @return the last block
55 | */
56 | public String getLastBlock()
57 | {
58 | return lastBlock;
59 | }
60 |
61 | /**
62 | * Sets last block.
63 | *
64 | * @param lastBlock the last block
65 | */
66 | public void setLastBlock(String lastBlock)
67 | {
68 | this.lastBlock = lastBlock;
69 | }
70 |
71 | /**
72 | * Gets application.
73 | *
74 | * @return the application
75 | */
76 | public String getApplication()
77 | {
78 | return application;
79 | }
80 |
81 | /**
82 | * Sets application.
83 | *
84 | * @param application the application
85 | */
86 | public void setApplication(String application)
87 | {
88 | this.application = application;
89 | }
90 |
91 | /**
92 | * Gets is scanning.
93 | *
94 | * @return the is scanning
95 | */
96 | public Boolean getIsScanning()
97 | {
98 | return isScanning;
99 | }
100 |
101 | /**
102 | * Sets is scanning.
103 | *
104 | * @param isScanning the is scanning
105 | */
106 | public void setIsScanning(Boolean isScanning)
107 | {
108 | this.isScanning = isScanning;
109 | }
110 |
111 | /**
112 | * Gets cumulative difficulty.
113 | *
114 | * @return the cumulative difficulty
115 | */
116 | public String getCumulativeDifficulty()
117 | {
118 | return cumulativeDifficulty;
119 | }
120 |
121 | /**
122 | * Sets cumulative difficulty.
123 | *
124 | * @param cumulativeDifficulty the cumulative difficulty
125 | */
126 | public void setCumulativeDifficulty(String cumulativeDifficulty)
127 | {
128 | this.cumulativeDifficulty = cumulativeDifficulty;
129 | }
130 |
131 | /**
132 | * Gets last blockchain feeder height.
133 | *
134 | * @return the last blockchain feeder height
135 | */
136 | public int getLastBlockchainFeederHeight()
137 | {
138 | return lastBlockchainFeederHeight;
139 | }
140 |
141 | /**
142 | * Sets last blockchain feeder height.
143 | *
144 | * @param lastBlockchainFeederHeight the last blockchain feeder height
145 | */
146 | public void setLastBlockchainFeederHeight(int lastBlockchainFeederHeight)
147 | {
148 | this.lastBlockchainFeederHeight = lastBlockchainFeederHeight;
149 | }
150 |
151 | /**
152 | * Gets number of blocks.
153 | *
154 | * @return the number of blocks
155 | */
156 | public int getNumberOfBlocks()
157 | {
158 | return numberOfBlocks;
159 | }
160 |
161 | /**
162 | * Sets number of blocks.
163 | *
164 | * @param numberOfBlocks the number of blocks
165 | */
166 | public void setNumberOfBlocks(int numberOfBlocks)
167 | {
168 | this.numberOfBlocks = numberOfBlocks;
169 | }
170 |
171 | /**
172 | * Gets time.
173 | *
174 | * @return the time
175 | */
176 | public long getTime()
177 | {
178 | return time;
179 | }
180 |
181 | /**
182 | * Sets time.
183 | *
184 | * @param time the time
185 | */
186 | public void setTime(long time)
187 | {
188 | this.time = time;
189 | }
190 |
191 | /**
192 | * Gets request processing time.
193 | *
194 | * @return the request processing time
195 | */
196 | public int getRequestProcessingTime()
197 | {
198 | return requestProcessingTime;
199 | }
200 |
201 | /**
202 | * Sets request processing time.
203 | *
204 | * @param requestProcessingTime the request processing time
205 | */
206 | public void setRequestProcessingTime(int requestProcessingTime)
207 | {
208 | this.requestProcessingTime = requestProcessingTime;
209 | }
210 |
211 | /**
212 | * Gets version.
213 | *
214 | * @return the version
215 | */
216 | public String getVersion()
217 | {
218 | return version;
219 | }
220 |
221 | /**
222 | * Sets version.
223 | *
224 | * @param version the version
225 | */
226 | public void setVersion(String version)
227 | {
228 | this.version = version;
229 | }
230 |
231 | /**
232 | * Gets last blockchain feeder.
233 | *
234 | * @return the last blockchain feeder
235 | */
236 | public String getLastBlockchainFeeder()
237 | {
238 | return lastBlockchainFeeder;
239 | }
240 |
241 | /**
242 | * Sets last blockchain feeder.
243 | *
244 | * @param lastBlockchainFeeder the last blockchain feeder
245 | */
246 | public void setLastBlockchainFeeder(String lastBlockchainFeeder)
247 | {
248 | this.lastBlockchainFeeder = lastBlockchainFeeder;
249 | }
250 |
251 | }
252 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/Blocks.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import java.util.List;
26 |
27 | public class Blocks
28 | extends Base
29 | {
30 | private List blocks;
31 |
32 | public List getBlocks()
33 | {
34 | return blocks;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/MiningInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | public class MiningInfo
26 | extends Base
27 | {
28 | private String generationSignature;
29 | private String baseTarget;
30 | private String height;
31 |
32 | // only if pool
33 | private long targetDeadline;
34 |
35 | public String getGenerationSignature()
36 | {
37 | return generationSignature;
38 | }
39 |
40 | public String getBaseTarget()
41 | {
42 | return baseTarget;
43 | }
44 |
45 | public String getHeight()
46 | {
47 | return height;
48 | }
49 |
50 | public long getTargetDeadline()
51 | {
52 | return targetDeadline;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/ResponseError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 |
26 | public class ResponseError
27 | extends Base
28 | {
29 | private int errorCode;
30 | private String errorDescription;
31 |
32 | public int getErrorCode()
33 | {
34 | return errorCode;
35 | }
36 |
37 | public String getErrorDescription()
38 | {
39 | return errorDescription;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/RewardRecipient.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | public class RewardRecipient
26 | extends Base
27 | {
28 | // accountId of reward recipient
29 | private String rewardRecipient;
30 |
31 | public String getRewardRecipient()
32 | {
33 | return rewardRecipient;
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/model/SubmitResult.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.model;
24 |
25 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
26 |
27 | @JsonIgnoreProperties(ignoreUnknown = true) // prevent future incompatible values
28 | public class SubmitResult
29 | extends Base
30 | {
31 | private String result;
32 | private long deadline;
33 |
34 | // pool response
35 | private long block;
36 |
37 | // one or the other is used
38 | private String deadlineString;
39 | private String deadlineText;
40 |
41 | private long targetDeadline;
42 |
43 | public String getResult()
44 | {
45 | return result;
46 | }
47 |
48 | public long getDeadline()
49 | {
50 | return deadline;
51 | }
52 |
53 | public long getBlock()
54 | {
55 | return block;
56 | }
57 |
58 | public String getDeadlineString()
59 | {
60 | return deadlineString;
61 | }
62 |
63 | public String getDeadlineText()
64 | {
65 | return deadlineText;
66 | }
67 |
68 | public long getTargetDeadline()
69 | {
70 | return targetDeadline;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/task/NetworkRequestAccountBlocksTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.task;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkBlocksEvent;
27 | import burstcoin.jminer.core.network.model.Blocks;
28 | import com.fasterxml.jackson.databind.ObjectMapper;
29 | import org.eclipse.jetty.client.HttpClient;
30 | import org.eclipse.jetty.client.api.Request;
31 | import org.eclipse.jetty.client.api.Response;
32 | import org.eclipse.jetty.client.util.InputStreamResponseListener;
33 | import org.slf4j.Logger;
34 | import org.slf4j.LoggerFactory;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.ApplicationEventPublisher;
37 | import org.springframework.context.annotation.Scope;
38 | import org.springframework.stereotype.Component;
39 |
40 | import java.io.InputStream;
41 | import java.util.concurrent.TimeUnit;
42 |
43 | @Component
44 | @Scope("prototype")
45 | public class NetworkRequestAccountBlocksTask
46 | implements Runnable
47 | {
48 | private static final Logger LOG = LoggerFactory.getLogger(NetworkRequestLastWinnerTask.class);
49 |
50 | private final HttpClient httpClient;
51 | private final ObjectMapper objectMapper;
52 | private final ApplicationEventPublisher publisher;
53 |
54 | // data
55 | private String accountId;
56 | private String server;
57 |
58 | @Autowired
59 | public NetworkRequestAccountBlocksTask(HttpClient httpClient, ObjectMapper objectMapper, ApplicationEventPublisher publisher)
60 | {
61 | this.httpClient = httpClient;
62 | this.objectMapper = objectMapper;
63 | this.publisher = publisher;
64 | }
65 |
66 | public void init(String accountId, String server)
67 | {
68 | this.accountId = accountId;
69 | this.server = server;
70 | }
71 |
72 | @Override
73 | public void run()
74 | {
75 | Blocks accountBlocks = getAccountBlocks(accountId);
76 | publisher.publishEvent(new NetworkBlocksEvent(accountBlocks));
77 | }
78 |
79 | private Blocks getAccountBlocks(String accountId)
80 | {
81 | LOG.info("Requesting mined blocks from wallet ...");
82 | Blocks blocks = null;
83 | try
84 | {
85 | long connectionTimeout = CoreProperties.getConnectionTimeout() * 3;
86 | InputStreamResponseListener listener = new InputStreamResponseListener();
87 |
88 | Request request = httpClient.newRequest(server + "/burst");
89 | request.param("requestType", "getAccountBlocks");
90 | request.param("account", accountId);
91 | request.timeout(connectionTimeout, TimeUnit.MILLISECONDS);
92 | request.send(listener);
93 | Response response = listener.get(connectionTimeout, TimeUnit.MILLISECONDS);
94 |
95 | // Look at the response
96 | if(response.getStatus() == 200)
97 | {
98 | // Use try-with-resources to close input stream.
99 | try (InputStream responseContent = listener.getInputStream())
100 | {
101 | blocks = objectMapper.readValue(responseContent, Blocks.class);
102 |
103 | LOG.info("Total mined blocks: '" + blocks.getBlocks().size() + "', received in '" + blocks.getRequestProcessingTime() + "' ms");
104 | }
105 | catch(Exception e)
106 | {
107 | LOG.error("Failed to receive account blocks.", e);
108 | }
109 | }
110 | }
111 | catch(Exception e)
112 | {
113 | LOG.warn("Error: Failed to 'getAccountBlocks': " + e.getMessage());
114 | }
115 | return blocks;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/task/NetworkRequestLastWinnerTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.task;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkLastWinnerEvent;
27 | import burstcoin.jminer.core.network.model.Block;
28 | import burstcoin.jminer.core.network.model.BlockchainStatus;
29 | import com.fasterxml.jackson.databind.ObjectMapper;
30 | import org.eclipse.jetty.client.HttpClient;
31 | import org.eclipse.jetty.client.api.ContentResponse;
32 | import org.slf4j.Logger;
33 | import org.slf4j.LoggerFactory;
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.context.ApplicationEventPublisher;
36 | import org.springframework.context.annotation.Scope;
37 | import org.springframework.stereotype.Component;
38 |
39 | import java.util.concurrent.TimeUnit;
40 |
41 | @Component
42 | @Scope("prototype")
43 | public class NetworkRequestLastWinnerTask
44 | implements Runnable
45 | {
46 | private static final Logger LOG = LoggerFactory.getLogger(NetworkRequestLastWinnerTask.class);
47 |
48 | private final HttpClient httpClient;
49 | private final ObjectMapper objectMapper;
50 | private final ApplicationEventPublisher publisher;
51 |
52 | // data
53 | private long blockNumber; // updated on new round
54 | private String server;
55 |
56 | @Autowired
57 | public NetworkRequestLastWinnerTask(HttpClient httpClient, ObjectMapper objectMapper, ApplicationEventPublisher publisher)
58 | {
59 | this.httpClient = httpClient;
60 | this.objectMapper = objectMapper;
61 | this.publisher = publisher;
62 | }
63 |
64 | public void init(String server, long blockNumber)
65 | {
66 | this.server = server;
67 | this.blockNumber = blockNumber;
68 | }
69 |
70 | @Override
71 | public void run()
72 | {
73 | Block lastBlock = getLastBlock();
74 | if(lastBlock != null)
75 | {
76 | publisher.publishEvent(new NetworkLastWinnerEvent(this, lastBlock.getHeight(), lastBlock.getGeneratorRS()));
77 | }
78 | else
79 | {
80 | // todo event
81 | LOG.info(" last winner 'N/A', walletServer out of sync.");
82 | }
83 | }
84 |
85 | private Block getLastBlock()
86 | {
87 | Block lastBlock = null;
88 | BlockchainStatus blockChainStatus = getBlockChainStatus();
89 | int retries = 0;
90 | if(blockChainStatus != null)
91 | {
92 | lastBlock = getBlock(blockChainStatus.getLastBlock());
93 | if(lastBlock != null)
94 | {
95 | while(blockNumber - 1 /*from pool*/ != lastBlock.getHeight() /* from walletServer*/ && retries < CoreProperties.getWinnerRetriesOnAsync())
96 | {
97 | retries++;
98 |
99 | if(retries == CoreProperties.getWinnerRetriesOnAsync())
100 | {
101 | LOG.debug("lastBlock from walletServer outdated, last retry in " + CoreProperties.getWinnerRetryIntervalInMs() + "ms");
102 | }
103 | else
104 | {
105 | LOG.debug("lastBlock from walletServer outdated, retry-" + retries + " in " + CoreProperties.getWinnerRetryIntervalInMs() + "ms");
106 | }
107 |
108 | try
109 | {
110 | Thread.sleep(CoreProperties.getWinnerRetryIntervalInMs());
111 | }
112 | catch(InterruptedException e)
113 | {
114 | e.printStackTrace();
115 | }
116 | blockChainStatus = getBlockChainStatus();
117 | lastBlock = getBlock(blockChainStatus.getLastBlock());
118 | }
119 | }
120 | }
121 |
122 | return retries > 0 && CoreProperties.getWinnerRetriesOnAsync() == retries ? null : lastBlock;
123 | }
124 |
125 | private BlockchainStatus getBlockChainStatus()
126 | {
127 | BlockchainStatus blockchainStatus = null;
128 | try
129 | {
130 | ContentResponse response = httpClient.newRequest(server + "/burst?requestType=getBlockchainStatus")
131 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
132 | .send();
133 |
134 | blockchainStatus = objectMapper.readValue(response.getContentAsString(), BlockchainStatus.class);
135 |
136 | }
137 | catch(Exception e)
138 | {
139 | LOG.warn("Error: Failed to 'getBlockchainStatus' from 'walletServer' to find last winner.");
140 | }
141 | return blockchainStatus;
142 | }
143 |
144 | private Block getBlock(String blockId)
145 | {
146 | Block block = null;
147 | try
148 | {
149 | ContentResponse response = httpClient.newRequest(server + "/burst?requestType=getBlock&block=" + blockId)
150 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
151 | .send();
152 |
153 | String contentAsString = response.getContentAsString();
154 |
155 | block = objectMapper.readValue(contentAsString, Block.class);
156 | }
157 | catch(Exception e)
158 | {
159 | LOG.warn("Error: Failed to 'getBlock' to find last winner.");
160 | }
161 | return block;
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/task/NetworkRequestMiningInfoTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.task;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkQualityChangeEvent;
27 | import burstcoin.jminer.core.network.event.NetworkStateChangeEvent;
28 | import burstcoin.jminer.core.network.model.MiningInfo;
29 | import com.fasterxml.jackson.databind.ObjectMapper;
30 | import nxt.util.Convert;
31 | import org.eclipse.jetty.client.HttpClient;
32 | import org.eclipse.jetty.client.api.ContentResponse;
33 | import org.slf4j.Logger;
34 | import org.slf4j.LoggerFactory;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.ApplicationEventPublisher;
37 | import org.springframework.context.annotation.Scope;
38 | import org.springframework.stereotype.Component;
39 |
40 | import java.io.EOFException;
41 | import java.net.ConnectException;
42 | import java.util.Arrays;
43 | import java.util.concurrent.TimeUnit;
44 | import java.util.concurrent.TimeoutException;
45 |
46 | /**
47 | * The type Network request mining info task.
48 | */
49 | @Component
50 | @Scope("prototype")
51 | public class NetworkRequestMiningInfoTask
52 | implements Runnable
53 | {
54 | private static final Logger LOG = LoggerFactory.getLogger(NetworkRequestMiningInfoTask.class);
55 |
56 | private final HttpClient httpClient;
57 | private final ObjectMapper objectMapper;
58 | private final ApplicationEventPublisher publisher;
59 |
60 | private byte[] generationSignature;
61 | private long blockNumber;
62 | private String server;
63 |
64 | private long plotSizeInByte;
65 |
66 | private boolean success;
67 |
68 | @Autowired
69 | public NetworkRequestMiningInfoTask(HttpClient httpClient, ObjectMapper objectMapper, ApplicationEventPublisher publisher)
70 | {
71 | this.httpClient = httpClient;
72 | this.objectMapper = objectMapper;
73 | this.publisher = publisher;
74 | }
75 |
76 | public void init(String server, long blockNumber, byte[] generationSignature, long plotSizeInByte)
77 | {
78 | this.server = server;
79 | this.generationSignature = generationSignature;
80 | this.blockNumber = blockNumber;
81 | this.plotSizeInByte = plotSizeInByte;
82 |
83 | success = false;
84 | }
85 |
86 | @Override
87 | public void run()
88 | {
89 | LOG.trace("start check network state");
90 |
91 | MiningInfo result = null;
92 | try
93 | {
94 | ContentResponse response = httpClient.newRequest(server + "/burst?requestType=getMiningInfo")
95 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
96 | .send();
97 |
98 | // do not parse result if status code is error
99 | if(response.getStatus() >= 400)
100 | {
101 | LOG.debug("Unable to parse mining info, received http status code " + response.getStatus());
102 | }
103 | else
104 | {
105 | result = objectMapper.readValue(response.getContentAsString(), MiningInfo.class);
106 | }
107 |
108 | if(result != null)
109 | {
110 | success = true;
111 | long newBlockNumber = Convert.parseUnsignedLong(result.getHeight());
112 | byte[] newGenerationSignature = Convert.parseHexString(result.getGenerationSignature());
113 |
114 | // higher block 'or' same block with other generationSignature
115 | if(!Arrays.equals(newGenerationSignature, generationSignature))
116 | {
117 | long baseTarget = Convert.parseUnsignedLong(result.getBaseTarget());
118 | long targetDeadline = getTargetDeadline(result.getTargetDeadline(), baseTarget);
119 | publisher.publishEvent(new NetworkStateChangeEvent(newBlockNumber, baseTarget, newGenerationSignature, targetDeadline));
120 | }
121 | else
122 | {
123 | LOG.trace("not publish NetworkStateChangeEvent ... '" + newBlockNumber + " <= " + blockNumber + "'");
124 | }
125 | }
126 | else
127 | {
128 | LOG.debug("Unable to parse mining info: " + response.getContentAsString());
129 | }
130 | }
131 | catch(TimeoutException timeoutException)
132 | {
133 | LOG.debug("Unable to get mining info from wallet, caused by connectionTimeout, currently '"
134 | + (CoreProperties.getConnectionTimeout() / 1000) + " sec.' try increasing it!");
135 | }
136 | catch(Exception e)
137 | {
138 | if(e instanceof ConnectException)
139 | {
140 | LOG.debug("Unable to get mining info from wallet due ConnectException.");
141 | LOG.trace("Unable to get mining info from wallet due ConnectException:" + e.getMessage(), e);
142 | }
143 | else if(e instanceof EOFException)
144 | {
145 | LOG.debug("Unable to get mining info from wallet due EOFException.");
146 | LOG.trace("Unable to get mining info from wallet due EOFException:" + e.getMessage(), e);
147 | }
148 | else
149 | {
150 | LOG.debug("Unable to get mining info from wallet.");
151 | LOG.trace("Unable to get mining info from wallet: " + e.getMessage(), e);
152 | }
153 | }
154 | publisher.publishEvent(new NetworkQualityChangeEvent(success));
155 | }
156 |
157 | private long getTargetDeadline(long deadlineProvidedByPool, long baseTarget)
158 | {
159 | long targetDeadline;
160 | long defaultTargetDeadline = CoreProperties.getTargetDeadline();
161 | // ensure default is not 0
162 | defaultTargetDeadline = defaultTargetDeadline > 0 ? defaultTargetDeadline : Long.MAX_VALUE;
163 |
164 | // 'poolMining' and dynamic deadline
165 | if(CoreProperties.isPoolMining() && CoreProperties.isDynamicTargetDeadline())
166 | {
167 | // please give feedback, in case this is not optimal
168 | long netDiff = 18325193796L / baseTarget;
169 | float plotSizeInTiB = plotSizeInByte / 1024 / 1024 / 1024 / 1024;
170 | targetDeadline = (long) (720 * netDiff / (plotSizeInTiB > 1.0 ? plotSizeInTiB : 1.0));
171 | }
172 | // 'soloMining' or 'poolMining and force local deadline'
173 | else if(!CoreProperties.isPoolMining() || CoreProperties.isForceLocalTargetDeadline())
174 | {
175 | targetDeadline = defaultTargetDeadline;
176 | }
177 | // 'poolMining'
178 | else
179 | {
180 | targetDeadline = deadlineProvidedByPool > 0 ? deadlineProvidedByPool : defaultTargetDeadline;
181 | }
182 | return targetDeadline;
183 | }
184 | }
185 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/task/NetworkRequestPoolInfoTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.task;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkPoolInfoEvent;
27 | import burstcoin.jminer.core.network.model.Account;
28 | import burstcoin.jminer.core.network.model.Accounts;
29 | import burstcoin.jminer.core.network.model.RewardRecipient;
30 | import com.fasterxml.jackson.databind.ObjectMapper;
31 | import org.eclipse.jetty.client.HttpClient;
32 | import org.eclipse.jetty.client.api.ContentResponse;
33 | import org.slf4j.Logger;
34 | import org.slf4j.LoggerFactory;
35 | import org.springframework.beans.factory.annotation.Autowired;
36 | import org.springframework.context.ApplicationEventPublisher;
37 | import org.springframework.context.annotation.Scope;
38 | import org.springframework.stereotype.Component;
39 |
40 | import java.util.List;
41 | import java.util.concurrent.TimeUnit;
42 |
43 | @Component
44 | @Scope("prototype")
45 | public class NetworkRequestPoolInfoTask
46 | implements Runnable
47 | {
48 | private static final Logger LOG = LoggerFactory.getLogger(NetworkRequestMiningInfoTask.class);
49 |
50 | private final HttpClient httpClient;
51 | private final ObjectMapper objectMapper;
52 | private final ApplicationEventPublisher publisher;
53 |
54 | @Autowired
55 | public NetworkRequestPoolInfoTask(HttpClient httpClient, ObjectMapper objectMapper, ApplicationEventPublisher publisher)
56 | {
57 | this.httpClient = httpClient;
58 | this.objectMapper = objectMapper;
59 | this.publisher = publisher;
60 | }
61 |
62 | @Override
63 | public void run()
64 | {
65 | String rewardRecipientAccountId = getRewardRecipientAccountId(CoreProperties.getNumericAccountId());
66 | if(rewardRecipientAccountId != null)
67 | {
68 | // number of registered miner accounts
69 | List accountIdsOfRewardRecipient = getAccountIdsOfRewardRecipient(rewardRecipientAccountId);
70 | Account account = getAccount(rewardRecipientAccountId);
71 | if(account != null)
72 | {
73 | publisher.publishEvent(new NetworkPoolInfoEvent(account.getAccountRS(), account.getBalanceNQT(), account.getForgedBalanceNQT(),
74 | accountIdsOfRewardRecipient != null ? accountIdsOfRewardRecipient.size() : 0));
75 | }
76 | }
77 | }
78 |
79 | private String getRewardRecipientAccountId(String accountId)
80 | {
81 | RewardRecipient rewardRecipient = null;
82 | try
83 | {
84 | ContentResponse response = httpClient.newRequest(CoreProperties.getWalletServer() + "/burst?requestType=getRewardRecipient&account=" + accountId)
85 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
86 | .send();
87 |
88 | String contentAsString = response.getContentAsString();
89 |
90 | if(!contentAsString.contains("error"))
91 | {
92 | rewardRecipient = objectMapper.readValue(contentAsString, RewardRecipient.class);
93 | }
94 | else
95 | {
96 | LOG.warn("Error: Failed to 'getRewardRecipient' for pool info: " + contentAsString);
97 | }
98 | }
99 | catch(Exception e)
100 | {
101 | LOG.warn("Error: Failed to 'getRewardRecipient' for pool info: " + e.getMessage());
102 | }
103 | return rewardRecipient != null ? rewardRecipient.getRewardRecipient() : null;
104 | }
105 |
106 | private List getAccountIdsOfRewardRecipient(String rewardRecipientAccountId)
107 | {
108 | Accounts accounts = null;
109 | try
110 | {
111 | String requestUri = CoreProperties.getWalletServer() + "/burst?requestType=getAccountsWithRewardRecipient&account=" + rewardRecipientAccountId;
112 | ContentResponse response = httpClient.newRequest(requestUri)
113 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
114 | .send();
115 |
116 | String contentAsString = response.getContentAsString();
117 |
118 | if(!contentAsString.contains("error"))
119 | {
120 | accounts = objectMapper.readValue(contentAsString, Accounts.class);
121 | }
122 | else
123 | {
124 | LOG.warn("Error: Failed to 'getAccountIdsOfRewardRecipient' for pool info: " + contentAsString);
125 | }
126 | }
127 | catch(Exception e)
128 | {
129 | LOG.warn("Error: Failed to 'getAccountIdsOfRewardRecipient' for pool info: " + e.getMessage());
130 | }
131 | return accounts != null ? accounts.getAccounts() : null;
132 | }
133 |
134 | private Account getAccount(String accountId)
135 | {
136 | Account account = null;
137 | try
138 | {
139 | ContentResponse response = httpClient.newRequest(CoreProperties.getWalletServer() + "/burst?requestType=getAccount&account=" + accountId)
140 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
141 | .send();
142 |
143 | String contentAsString = response.getContentAsString();
144 |
145 | if(!contentAsString.contains("error"))
146 | {
147 | account = objectMapper.readValue(contentAsString, Account.class);
148 | }
149 | else
150 | {
151 | LOG.warn("Error: Failed to 'getAccount' for pool info: " + contentAsString);
152 | }
153 | }
154 | catch(Exception e)
155 | {
156 | LOG.warn("Error: Failed to 'getAccount' for pool info: " + e.getMessage());
157 | }
158 | return account;
159 | }
160 | }
161 |
162 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/network/task/NetworkSubmitSoloNonceTask.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.network.task;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import burstcoin.jminer.core.network.event.NetworkResultConfirmedEvent;
27 | import burstcoin.jminer.core.network.event.NetworkResultErrorEvent;
28 | import burstcoin.jminer.core.network.model.SubmitResult;
29 | import com.fasterxml.jackson.databind.ObjectMapper;
30 | import org.eclipse.jetty.client.HttpClient;
31 | import org.eclipse.jetty.client.api.ContentResponse;
32 | import org.slf4j.Logger;
33 | import org.slf4j.LoggerFactory;
34 | import org.springframework.beans.factory.annotation.Autowired;
35 | import org.springframework.context.ApplicationEventPublisher;
36 | import org.springframework.context.annotation.Scope;
37 | import org.springframework.stereotype.Component;
38 |
39 | import java.math.BigInteger;
40 | import java.util.concurrent.TimeUnit;
41 | import java.util.concurrent.TimeoutException;
42 |
43 | /**
44 | * The type Network submit solo nonce task.
45 | */
46 | @Component
47 | @Scope("prototype")
48 | public class NetworkSubmitSoloNonceTask
49 | implements Runnable
50 | {
51 | private static final Logger LOG = LoggerFactory.getLogger(NetworkSubmitSoloNonceTask.class);
52 |
53 | private final ApplicationEventPublisher publisher;
54 | private final HttpClient httpClient;
55 | private final ObjectMapper objectMapper;
56 |
57 | private BigInteger nonce;
58 | private long blockNumber;
59 | private BigInteger chunkPartStartNonce;
60 | private long calculatedDeadline;
61 | private BigInteger result;
62 | private byte[] generationSignature;
63 |
64 | @Autowired
65 | public NetworkSubmitSoloNonceTask(ApplicationEventPublisher publisher, HttpClient httpClient, ObjectMapper objectMapper)
66 | {
67 | this.publisher = publisher;
68 | this.httpClient = httpClient;
69 | this.objectMapper = objectMapper;
70 | }
71 |
72 | public void init(long blockNumber, byte[] generationSignature, BigInteger nonce, BigInteger chunkPartStartNonce, long calculatedDeadline, BigInteger result)
73 | {
74 | this.generationSignature = generationSignature;
75 | this.nonce = nonce;
76 | this.blockNumber = blockNumber;
77 | this.chunkPartStartNonce = chunkPartStartNonce;
78 | this.calculatedDeadline = calculatedDeadline;
79 | this.result = result;
80 | }
81 |
82 | @Override
83 | public void run()
84 | {
85 | try
86 | {
87 | ContentResponse response = httpClient.POST(CoreProperties.getSoloServer() + "/burst")
88 | .param("requestType", "submitNonce")
89 | .param("secretPhrase", CoreProperties.getPassPhrase())
90 | .param("nonce", nonce.toString())
91 | .timeout(CoreProperties.getConnectionTimeout(), TimeUnit.MILLISECONDS)
92 | .send();
93 |
94 | SubmitResult result = objectMapper.readValue(response.getContentAsString(), SubmitResult.class);
95 |
96 | if(result.getResult().equals("success"))
97 | {
98 | if(calculatedDeadline == result.getDeadline())
99 | {
100 | publisher
101 | .publishEvent(new NetworkResultConfirmedEvent(blockNumber, generationSignature, result.getDeadline(), nonce, chunkPartStartNonce, this.result));
102 | }
103 | else
104 | {
105 | publisher.publishEvent(
106 | new NetworkResultErrorEvent(blockNumber, generationSignature, nonce, calculatedDeadline, result.getDeadline(), chunkPartStartNonce, this.result));
107 | }
108 | }
109 | else
110 | {
111 | LOG.warn("Error: Submit solo nonce not successful: " + response.getContentAsString());
112 | }
113 | }
114 | catch(TimeoutException timeoutException)
115 | {
116 | LOG.warn("Unable to commit solo nonce, caused by connectionTimeout, currently '"
117 | + (CoreProperties.getConnectionTimeout() / 1000) + " sec.' try increasing it!");
118 | }
119 | catch(Exception e)
120 | {
121 | LOG.warn("Error: Failed to submit solo nonce: " + e.getMessage());
122 | }
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/data/PlotDrive.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.data;
24 |
25 |
26 | import org.slf4j.Logger;
27 | import org.slf4j.LoggerFactory;
28 |
29 | import java.math.BigInteger;
30 | import java.nio.file.Path;
31 | import java.util.Collection;
32 | import java.util.HashMap;
33 | import java.util.HashSet;
34 | import java.util.Map;
35 |
36 | /**
37 | * The type Plot drive.
38 | */
39 | public class PlotDrive
40 | {
41 | private static final Logger LOG = LoggerFactory.getLogger(PlotDrive.class);
42 |
43 | private Collection plotFiles;
44 | private String directory;
45 |
46 | PlotDrive(String directory, Collection plotFilePaths, Long chunkPartNonces)
47 | {
48 | this.directory = directory;
49 |
50 | plotFiles = new HashSet<>();
51 | for(Path path : plotFilePaths)
52 | {
53 | PlotFile plotFile = new PlotFile(path, chunkPartNonces);
54 | plotFiles.add(plotFile);
55 |
56 | if(plotFile.getStaggeramt() % plotFile.getNumberOfParts() != 0)
57 | {
58 | LOG.error("could not calculate valid numberOfParts: " + plotFile.getFilePath());
59 | }
60 | }
61 | }
62 |
63 | public Collection getPlotFiles()
64 | {
65 | return plotFiles;
66 | }
67 |
68 | public String getDirectory()
69 | {
70 | return directory;
71 | }
72 |
73 | /* Collects chunk part start nonces.*/
74 | Map collectChunkPartStartNonces()
75 | {
76 | Map chunkPartStartNonces = new HashMap<>();
77 | for(PlotFile plotFile : plotFiles)
78 | {
79 | int expectedSize = chunkPartStartNonces.size() + plotFile.getChunkPartStartNonces().size();
80 | chunkPartStartNonces.putAll(plotFile.getChunkPartStartNonces());
81 | if(expectedSize != chunkPartStartNonces.size())
82 | {
83 | LOG.warn("possible overlapping plot-file '" + plotFile.getFilePath() + "', please check your plots.");
84 | }
85 | }
86 | return chunkPartStartNonces;
87 | }
88 |
89 | /* returns total number of bytes of all plotFiles */
90 | public long getSize()
91 | {
92 | long size = 0;
93 | for(PlotFile plotFile : plotFiles)
94 | {
95 | size += plotFile.getSize();
96 | }
97 | return size;
98 | }
99 |
100 | /* returns null if drive has mixed poc versions */
101 | public PocVersion getDrivePocVersion()
102 | {
103 | PocVersion drivePocVersion = null;
104 | for(PlotFile plotFile : plotFiles)
105 | {
106 | if(drivePocVersion == null)
107 | {
108 | drivePocVersion = plotFile.getPocVersion();
109 | }
110 | else if(!drivePocVersion.equals(plotFile.getPocVersion()))
111 | {
112 | return null;
113 | }
114 | }
115 | return drivePocVersion;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/data/PlotFile.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.data;
24 |
25 | import burstcoin.jminer.core.CoreProperties;
26 | import nxt.util.Convert;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 | import pocminer.generate.MiningPlot;
30 |
31 | import java.math.BigInteger;
32 | import java.nio.file.Path;
33 | import java.util.HashMap;
34 | import java.util.Map;
35 |
36 | public class PlotFile
37 | {
38 | private static final Logger LOG = LoggerFactory.getLogger(PlotFile.class);
39 |
40 | // key -> size
41 | private Map chunkPartStartNonces;
42 |
43 | private Path filePath;
44 | private Long chunkPartNonces;
45 | private int numberOfParts;
46 | private long numberOfChunks;
47 |
48 | private String filename;
49 | private long address;
50 | private BigInteger startnonce;
51 | private long plots;
52 | private long staggeramt;
53 |
54 | private long size;
55 |
56 | private PocVersion pocVersion;
57 |
58 | PlotFile(Path filePath, Long chunkPartNonces)
59 | {
60 | this.filePath = filePath;
61 | this.chunkPartNonces = chunkPartNonces;
62 | this.filename = getFilename(filePath);
63 | String[] parts = filename.split("_");
64 | this.address = Convert.parseUnsignedLong(parts[0]);
65 | this.startnonce = new BigInteger(parts[1]);
66 | this.plots = Long.valueOf(parts[2]);
67 |
68 | // todo this may be weak, requires that poc2 file names do not have staggersize
69 | if(parts.length > 3)
70 | {
71 | pocVersion = PocVersion.POC_1;
72 | staggeramt = Long.valueOf(parts[3]);
73 | this.numberOfParts = calculateNumberOfParts(staggeramt);
74 | this.numberOfChunks = plots / staggeramt;
75 | }
76 | else
77 | {
78 | pocVersion = PocVersion.POC_2;
79 | staggeramt = plots;
80 | this.numberOfParts = calculateNumberOfParts(staggeramt);
81 | this.numberOfChunks = 1;
82 | }
83 |
84 | chunkPartStartNonces = new HashMap<>();
85 |
86 | size = numberOfChunks * staggeramt * MiningPlot.PLOT_SIZE;
87 |
88 | if(LOG.isDebugEnabled())
89 | {
90 | long fileSize = filePath.toFile().length();
91 | if(fileSize != size)
92 | {
93 | LOG.debug("incomplete plotFile: " + filePath.toString() + " specified size '" + size + " bytes', size '" + fileSize + " bytes'.");
94 | }
95 | }
96 |
97 | long chunkPartSize = this.size / numberOfChunks / numberOfParts;
98 | for(int chunkNumber = 0; chunkNumber < numberOfChunks; chunkNumber++)
99 | {
100 | for(int partNumber = 0; partNumber < numberOfParts; partNumber++)
101 | {
102 | // register a unique key for identification
103 | BigInteger chunkPartStartNonce = startnonce.add(BigInteger.valueOf(chunkNumber * staggeramt + partNumber * (staggeramt / numberOfParts)));
104 | Long key = chunkPartStartNonces.put(chunkPartStartNonce, chunkPartSize);
105 | if(key != null)
106 | {
107 | LOG.warn("possible overlapping plot-file '" + filePath + "', please check your plots.");
108 | }
109 | }
110 | }
111 | }
112 |
113 | private String getFilename(Path filePath)
114 | {
115 | String fn = filePath.getFileName().toString();
116 | // remove file-extension like e.g. '.plotting'
117 | if(fn.contains("."))
118 | {
119 | fn = fn.substring(0, fn.indexOf("."));
120 |
121 | if(!CoreProperties.isScanPathsEveryRound())
122 | {
123 | LOG.info("extension like '.plotting' was found, consider setting 'scanPathsEveryRound=true' "
124 | + "to ensure file gets detected after filename changed. (e.g. finished plotting)");
125 | }
126 | }
127 | return fn;
128 | }
129 |
130 | public long getSize()
131 | {
132 | return size;
133 | }
134 |
135 | public Path getFilePath()
136 | {
137 | return filePath;
138 | }
139 |
140 | String getFilename()
141 | {
142 | return filename;
143 | }
144 |
145 | public long getAddress()
146 | {
147 | return address;
148 | }
149 |
150 | public BigInteger getStartnonce()
151 | {
152 | return startnonce;
153 | }
154 |
155 | public long getPlots()
156 | {
157 | return plots;
158 | }
159 |
160 | public long getStaggeramt()
161 | {
162 | return staggeramt;
163 | }
164 |
165 | public long getNumberOfChunks()
166 | {
167 | return numberOfChunks;
168 | }
169 |
170 | public int getNumberOfParts()
171 | {
172 | return numberOfParts;
173 | }
174 |
175 | public void setNumberOfParts(int numberOfParts)
176 | {
177 | this.numberOfParts = numberOfParts;
178 | }
179 |
180 | Map getChunkPartStartNonces()
181 | {
182 | return chunkPartStartNonces;
183 | }
184 |
185 | public PocVersion getPocVersion()
186 | {
187 | return pocVersion;
188 | }
189 |
190 | // splitting into parts is not needed, but it seams to improve speed and enables us
191 | // to have steps of nearly same size
192 | private int calculateNumberOfParts(long staggeramt)
193 | {
194 | int maxNumberOfParts = 100;
195 |
196 | long targetNoncesPerPart = chunkPartNonces != null ? chunkPartNonces : 960000;
197 |
198 | // for CPU it should be much lower, ensures less idle.
199 | targetNoncesPerPart = !CoreProperties.isUseOpenCl() ? targetNoncesPerPart / 10 : targetNoncesPerPart;
200 |
201 | // calculate numberOfParts based on target
202 | int suggestedNumberOfParts = (int) (staggeramt / targetNoncesPerPart) + 1;
203 |
204 | // ensure stagger is dividable by numberOfParts, if not adjust numberOfParts
205 | while(staggeramt % suggestedNumberOfParts != 0 && suggestedNumberOfParts < maxNumberOfParts)
206 | {
207 | suggestedNumberOfParts += 1;
208 | }
209 |
210 | // fallback if number of parts could not be calculated in acceptable range
211 | if(suggestedNumberOfParts >= maxNumberOfParts)
212 | {
213 | suggestedNumberOfParts = (int) Math.floor(Math.sqrt(staggeramt));
214 | while(staggeramt % suggestedNumberOfParts != 0)
215 | {
216 | suggestedNumberOfParts--;
217 | }
218 | }
219 | return suggestedNumberOfParts;
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/data/Plots.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.data;
24 |
25 |
26 | import burstcoin.jminer.core.CoreProperties;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import java.io.IOException;
31 | import java.math.BigInteger;
32 | import java.nio.file.DirectoryIteratorException;
33 | import java.nio.file.DirectoryStream;
34 | import java.nio.file.Files;
35 | import java.nio.file.Path;
36 | import java.nio.file.Paths;
37 | import java.util.ArrayList;
38 | import java.util.Collection;
39 | import java.util.HashMap;
40 | import java.util.HashSet;
41 | import java.util.List;
42 | import java.util.Map;
43 |
44 | public class Plots
45 | {
46 | private static final Logger LOG = LoggerFactory.getLogger(Plots.class);
47 |
48 | private Collection plotDrives;
49 | private Map chunkPartStartNonces;
50 |
51 | public Plots(String numericAccountId)
52 | {
53 | plotDrives = new HashSet<>();
54 | chunkPartStartNonces = new HashMap<>();
55 | Map> plotFilesLookup = collectPlotFiles(CoreProperties.getPlotPaths(), numericAccountId);
56 | for(Map.Entry> entry : plotFilesLookup.entrySet())
57 | {
58 | PlotDrive plotDrive = new PlotDrive(entry.getKey(), entry.getValue(), CoreProperties.getChunkPartNonces());
59 | if(!plotDrive.getPlotFiles().isEmpty())
60 | {
61 | plotDrives.add(plotDrive);
62 |
63 | int expectedSize = chunkPartStartNonces.size() + plotDrive.collectChunkPartStartNonces().size();
64 | chunkPartStartNonces.putAll(plotDrive.collectChunkPartStartNonces());
65 | if(expectedSize != chunkPartStartNonces.size())
66 | {
67 | LOG.error("possible duplicate/overlapping plot-file on drive '" + plotDrive.getDirectory() + "' please check your plots.");
68 | }
69 | }
70 | else
71 | {
72 | LOG.info("No plotfiles found at '" + plotDrive.getDirectory() + "' ... will be ignored.");
73 | }
74 | }
75 | }
76 |
77 | public Collection getPlotDrives()
78 | {
79 | return plotDrives;
80 | }
81 |
82 | private static Map> collectPlotFiles(List plotDirectories, String numericAccountId)
83 | {
84 | Map> plotFilesLookup = new HashMap<>();
85 | for(String plotDirectory : plotDirectories)
86 | {
87 | Path folderPath = Paths.get(plotDirectory);
88 | try (DirectoryStream plotFilesStream = Files.newDirectoryStream(folderPath))
89 | {
90 | List plotFilePaths = new ArrayList<>();
91 | for(Path plotFilePath : plotFilesStream)
92 | {
93 | if(plotFilePath.toString().contains(numericAccountId))
94 | {
95 | plotFilePaths.add(plotFilePath);
96 | }
97 | }
98 | plotFilesLookup.put(plotDirectory, plotFilePaths);
99 | }
100 | catch(IOException | DirectoryIteratorException e)
101 | {
102 | LOG.error(e.getMessage());
103 | }
104 | }
105 | return plotFilesLookup;
106 | }
107 |
108 | /* total number of bytes of all plotFiles */
109 | public long getSize()
110 | {
111 | long size = 0;
112 | for(PlotDrive plotDrive : plotDrives)
113 | {
114 | size += plotDrive.getSize();
115 | }
116 | return size;
117 | }
118 |
119 | public void printPlotFiles()
120 | {
121 | for(PlotDrive plotDrive : getPlotDrives())
122 | {
123 | for(PlotFile plotFile : plotDrive.getPlotFiles())
124 | {
125 | System.out.println(plotFile.getFilePath());
126 | }
127 | }
128 | }
129 |
130 | /* gets plot file by plot file start nonce. */
131 | public PlotFile getPlotFileByPlotFileStartNonce(long plotFileStartNonce)
132 | {
133 | for(PlotDrive plotDrive : getPlotDrives())
134 | {
135 | for(PlotFile plotFile : plotDrive.getPlotFiles())
136 | {
137 | if(plotFile.getFilename().contains(String.valueOf(plotFileStartNonce)))
138 | {
139 | return plotFile;
140 | }
141 | }
142 | }
143 | return null;
144 | }
145 |
146 | /* gets chunk part start nonces. */
147 | public Map getChunkPartStartNonces()
148 | {
149 | return chunkPartStartNonces;
150 | }
151 |
152 | /* gets plot file by chunk part start nonce. */
153 | public PlotFile getPlotFileByChunkPartStartNonce(BigInteger chunkPartStartNonce)
154 | {
155 | for(PlotDrive plotDrive : getPlotDrives())
156 | {
157 | for(PlotFile plotFile : plotDrive.getPlotFiles())
158 | {
159 | if(plotFile.getChunkPartStartNonces().containsKey(chunkPartStartNonce))
160 | {
161 | return plotFile;
162 | }
163 | }
164 | }
165 | return null;
166 | }
167 | }
168 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/data/PocVersion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2018 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.data;
24 |
25 | public enum PocVersion
26 | {
27 | POC_1,
28 | POC_2
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/event/ReaderCorruptFileEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.event;
24 |
25 | import burstcoin.jminer.core.reader.Reader;
26 | import org.springframework.context.ApplicationEvent;
27 |
28 | /**
29 | * fired on NetworkResultErrorEvent, if a calculated deadline was not matching server result, to deliver affected plot file
30 | */
31 | public class ReaderCorruptFileEvent
32 | extends ApplicationEvent
33 | {
34 | private long blockNumber;
35 | private String filePath;
36 | private long numberOfChunks;
37 | private int numberOfParts;
38 |
39 | /**
40 | * Instantiates a new Reader corrupt file event.
41 | *
42 | * @param source the source
43 | * @param blockNumber the block number
44 | * @param filePath the file path
45 | * @param numberOfChunks the number of chunks
46 | * @param numberOfParts the number of parts
47 | */
48 | public ReaderCorruptFileEvent(Reader source, long blockNumber, String filePath, long numberOfChunks, int numberOfParts)
49 | {
50 | super(source);
51 | this.blockNumber = blockNumber;
52 |
53 | this.filePath = filePath;
54 | this.numberOfChunks = numberOfChunks;
55 | this.numberOfParts = numberOfParts;
56 | }
57 |
58 | /**
59 | * Gets block number.
60 | *
61 | * @return the block number
62 | */
63 | public long getBlockNumber()
64 | {
65 | return blockNumber;
66 | }
67 |
68 | /**
69 | * Gets file path.
70 | *
71 | * @return the file path
72 | */
73 | public String getFilePath()
74 | {
75 | return filePath;
76 | }
77 |
78 | /**
79 | * Gets number of chunks.
80 | *
81 | * @return the number of chunks
82 | */
83 | public long getNumberOfChunks()
84 | {
85 | return numberOfChunks;
86 | }
87 |
88 | /**
89 | * Gets number of parts.
90 | *
91 | * @return the number of parts
92 | */
93 | public int getNumberOfParts()
94 | {
95 | return numberOfParts;
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/event/ReaderDriveFinishEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.event;
24 |
25 |
26 | import org.springframework.context.ApplicationEvent;
27 |
28 | public class ReaderDriveFinishEvent
29 | extends ApplicationEvent
30 | {
31 | private String directory;
32 | private long size;
33 | private long time;
34 | private long blockNumber;
35 |
36 | public ReaderDriveFinishEvent(String directory, long size, long time, long blockNumber)
37 | {
38 | super(directory);
39 |
40 | this.directory = directory;
41 | this.size = size;
42 | this.time = time;
43 | this.blockNumber = blockNumber;
44 | }
45 |
46 | public long getTime()
47 | {
48 | return time;
49 | }
50 |
51 | public String getDirectory()
52 | {
53 | return directory;
54 | }
55 |
56 | public long getSize()
57 | {
58 | return size;
59 | }
60 |
61 | public long getBlockNumber()
62 | {
63 | return blockNumber;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/event/ReaderDriveInterruptedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | /**
28 | * fired if read is interrupted on shutdown threadPool
29 | */
30 | public class ReaderDriveInterruptedEvent
31 | extends ApplicationEvent
32 | {
33 | private long blockNumber;
34 | private String directory;
35 |
36 | public ReaderDriveInterruptedEvent(long blockNumber, String directory)
37 | {
38 | super(blockNumber);
39 |
40 | this.blockNumber = blockNumber;
41 | this.directory = directory;
42 | }
43 |
44 | public long getBlockNumber()
45 | {
46 | return blockNumber;
47 | }
48 |
49 | public String getDirectory()
50 | {
51 | return directory;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/event/ReaderLoadedPartEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.event;
24 |
25 |
26 | import java.math.BigInteger;
27 |
28 | public class ReaderLoadedPartEvent
29 | {
30 | private byte[] generationSignature;
31 | private BigInteger chunkPartStartNonce;
32 | private long blockNumber;
33 |
34 | private byte[] scoops;
35 | private String plotFilePath;
36 |
37 | public ReaderLoadedPartEvent(long blockNumber, byte[] generationSignature, byte[] scoops, BigInteger chunkPartStartNonce, String plotFilePath)
38 | {
39 | this.generationSignature = generationSignature;
40 | this.chunkPartStartNonce = chunkPartStartNonce;
41 | this.blockNumber = blockNumber;
42 | this.scoops = scoops;
43 | this.plotFilePath = plotFilePath;
44 | }
45 |
46 | public String getPlotFilePath()
47 | {
48 | return plotFilePath;
49 | }
50 |
51 | public long getBlockNumber()
52 | {
53 | return blockNumber;
54 | }
55 |
56 | public byte[] getScoops()
57 | {
58 | return scoops;
59 | }
60 |
61 | public BigInteger getChunkPartStartNonce()
62 | {
63 | return chunkPartStartNonce;
64 | }
65 |
66 | public byte[] getGenerationSignature()
67 | {
68 | return generationSignature;
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/reader/event/ReaderProgressChangedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.reader.event;
24 |
25 | import burstcoin.jminer.core.reader.Reader;
26 | import org.springframework.context.ApplicationEvent;
27 |
28 | /**
29 | * The type Reader progress changed event.
30 | */
31 | public class ReaderProgressChangedEvent
32 | extends ApplicationEvent
33 | {
34 | private long blockNumber;
35 | private long capacity;
36 | private long remainingCapacity;
37 | private long realCapacity;
38 | private long realRemainingCapacity;
39 | private long elapsedTime;
40 |
41 | public ReaderProgressChangedEvent(Reader source, long blockNumber, long capacity, long remainingCapacity,long realCapacity, long realRemainingCapacity,
42 | long elapsedTime)
43 | {
44 | super(source);
45 |
46 | this.blockNumber = blockNumber;
47 | this.capacity = capacity;
48 | this.remainingCapacity = remainingCapacity;
49 | this.realCapacity = realCapacity;
50 | this.realRemainingCapacity = realRemainingCapacity;
51 | this.elapsedTime = elapsedTime;
52 | }
53 |
54 | public long getBlockNumber()
55 | {
56 | return blockNumber;
57 | }
58 |
59 | public long getRemainingCapacity()
60 | {
61 | return remainingCapacity;
62 | }
63 |
64 | public long getCapacity()
65 | {
66 | return capacity;
67 | }
68 |
69 | public long getElapsedTime()
70 | {
71 | return elapsedTime;
72 | }
73 |
74 | public long getRealCapacity()
75 | {
76 | return realCapacity;
77 | }
78 |
79 | public long getRealRemainingCapacity()
80 | {
81 | return realRemainingCapacity;
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundFinishedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | /**
28 | * The type Round finished event.
29 | */
30 | public class RoundFinishedEvent
31 | extends ApplicationEvent
32 | {
33 | private long blockNumber;
34 | private long bestCommittedDeadline;
35 | private long roundTime;
36 |
37 | private int networkQuality;
38 |
39 | public RoundFinishedEvent(long blockNumber, long bestCommittedDeadline, long roundTime, int networkQuality)
40 | {
41 | super(blockNumber);
42 | this.blockNumber = blockNumber;
43 | this.bestCommittedDeadline = bestCommittedDeadline;
44 | this.roundTime = roundTime;
45 | this.networkQuality = networkQuality;
46 | }
47 |
48 | public long getBlockNumber()
49 | {
50 | return blockNumber;
51 | }
52 |
53 | public long getBestCommittedDeadline()
54 | {
55 | return bestCommittedDeadline;
56 | }
57 |
58 | public long getRoundTime()
59 | {
60 | return roundTime;
61 | }
62 |
63 | public int getNetworkQuality()
64 | {
65 | return networkQuality;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundGenSigAlreadyMinedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 |
28 | public class RoundGenSigAlreadyMinedEvent
29 | extends ApplicationEvent
30 | {
31 | private byte[] generationSignature;
32 | private long blockNumber;
33 |
34 | public RoundGenSigAlreadyMinedEvent(long blockNumber, byte[] generationSignature)
35 | {
36 | super(blockNumber);
37 |
38 | this.blockNumber = blockNumber;
39 | this.generationSignature = generationSignature;
40 | }
41 |
42 | public long getBlockNumber()
43 | {
44 | return blockNumber;
45 | }
46 |
47 | public byte[] getGenerationSignature()
48 | {
49 | return generationSignature;
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundGenSigUpdatedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2017 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | // fired if generationSignature for current block has changed
28 | public class RoundGenSigUpdatedEvent
29 | extends ApplicationEvent
30 | {
31 | private byte[] generationSignature;
32 | private long blockNumber;
33 |
34 | public RoundGenSigUpdatedEvent(long blockNumber, byte[] generationSignature)
35 | {
36 | super(blockNumber);
37 |
38 | this.blockNumber = blockNumber;
39 | this.generationSignature = generationSignature;
40 | }
41 |
42 | public long getBlockNumber()
43 | {
44 | return blockNumber;
45 | }
46 |
47 | public byte[] getGenerationSignature()
48 | {
49 | return generationSignature;
50 | }
51 | }
52 |
53 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundSingleResultEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | import java.math.BigInteger;
28 |
29 | /**
30 | * fired on new best deadline below targetDeadline (not confirmed)
31 | */
32 | public class RoundSingleResultEvent
33 | extends ApplicationEvent
34 | {
35 | private long blockNumber;
36 | private BigInteger nonce;
37 | private BigInteger chunkPartStartNonce;
38 |
39 | private long calculatedDeadline;
40 | private boolean poolMining;
41 |
42 | /**
43 | * Instantiates a new Round single result event.
44 | *
45 | * @param blockNumber the block number
46 | * @param nonce the nonce
47 | * @param chunkPartStartNonce the chunk part start nonce
48 | * @param calculatedDeadline the calculated deadline
49 | * @param poolMining the pool mining
50 | */
51 | public RoundSingleResultEvent(long blockNumber, BigInteger nonce, BigInteger chunkPartStartNonce, long calculatedDeadline, boolean poolMining)
52 | {
53 | super(blockNumber);
54 |
55 | this.nonce = nonce;
56 | this.blockNumber = blockNumber;
57 | this.chunkPartStartNonce = chunkPartStartNonce;
58 | this.calculatedDeadline = calculatedDeadline;
59 | this.poolMining = poolMining;
60 | }
61 |
62 | /**
63 | * Gets block number.
64 | *
65 | * @return the block number
66 | */
67 | public long getBlockNumber()
68 | {
69 | return blockNumber;
70 | }
71 |
72 | /**
73 | * Gets nonce.
74 | *
75 | * @return the nonce
76 | */
77 | public BigInteger getNonce()
78 | {
79 | return nonce;
80 | }
81 |
82 | /**
83 | * Gets chunk part start nonce.
84 | *
85 | * @return the chunk part start nonce
86 | */
87 | public BigInteger getChunkPartStartNonce()
88 | {
89 | return chunkPartStartNonce;
90 | }
91 |
92 | /**
93 | * Gets calculated deadline.
94 | *
95 | * @return the calculated deadline
96 | */
97 | public long getCalculatedDeadline()
98 | {
99 | return calculatedDeadline;
100 | }
101 |
102 | /**
103 | * Is pool mining.
104 | *
105 | * @return the boolean
106 | */
107 | public boolean isPoolMining()
108 | {
109 | return poolMining;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundSingleResultSkippedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | import java.math.BigInteger;
28 |
29 | /**
30 | * fired if deadline is skipped cause of targetDeadline
31 | */
32 | public class RoundSingleResultSkippedEvent
33 | extends ApplicationEvent
34 | {
35 | private long blockNumber;
36 | private BigInteger nonce;
37 | private BigInteger chunkPartStartNonce;
38 |
39 | private long calculatedDeadline;
40 | private long targetDeadline;
41 | private boolean poolMining;
42 |
43 | /**
44 | * Instantiates a new Round single result skipped event.
45 | *
46 | * @param blockNumber the block number
47 | * @param nonce the nonce
48 | * @param chunkPartStartNonce the chunk part start nonce
49 | * @param calculatedDeadline the calculated deadline
50 | * @param targetDeadline the target deadline
51 | * @param poolMining the pool mining
52 | */
53 | public RoundSingleResultSkippedEvent(long blockNumber, BigInteger nonce, BigInteger chunkPartStartNonce, long calculatedDeadline, long targetDeadline,
54 | boolean poolMining)
55 | {
56 | super(blockNumber);
57 |
58 | this.nonce = nonce;
59 | this.blockNumber = blockNumber;
60 | this.chunkPartStartNonce = chunkPartStartNonce;
61 |
62 | this.calculatedDeadline = calculatedDeadline;
63 | this.targetDeadline = targetDeadline;
64 | this.poolMining = poolMining;
65 | }
66 |
67 | /**
68 | * Gets block number.
69 | *
70 | * @return the block number
71 | */
72 | public long getBlockNumber()
73 | {
74 | return blockNumber;
75 | }
76 |
77 | /**
78 | * Gets nonce.
79 | *
80 | * @return the nonce
81 | */
82 | public BigInteger getNonce()
83 | {
84 | return nonce;
85 | }
86 |
87 | /**
88 | * Gets chunk part start nonce.
89 | *
90 | * @return the chunk part start nonce
91 | */
92 | public BigInteger getChunkPartStartNonce()
93 | {
94 | return chunkPartStartNonce;
95 | }
96 |
97 | /**
98 | * Gets calculated deadline.
99 | *
100 | * @return the calculated deadline
101 | */
102 | public long getCalculatedDeadline()
103 | {
104 | return calculatedDeadline;
105 | }
106 |
107 | /**
108 | * Gets target deadline.
109 | *
110 | * @return the target deadline
111 | */
112 | public long getTargetDeadline()
113 | {
114 | return targetDeadline;
115 | }
116 |
117 | /**
118 | * Is pool mining.
119 | *
120 | * @return the boolean
121 | */
122 | public boolean isPoolMining()
123 | {
124 | return poolMining;
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundStartedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 |
26 | import org.springframework.context.ApplicationEvent;
27 |
28 | /**
29 | * fired after mining started
30 | */
31 | public class RoundStartedEvent
32 | extends ApplicationEvent
33 | {
34 | private long scoopNumber;
35 | private long capacity;
36 | private long targetDeadline;
37 | private long baseTarget;
38 | private byte[] generationSignature;
39 | private boolean restart;
40 | private long blockNumber;
41 |
42 | /**
43 | * Instantiates a new Round started event.
44 | * @param blockNumber the block number
45 | * @param scoopNumber the scoop number
46 | * @param capacity the capacity
47 | * @param targetDeadline the target deadline
48 | * @param baseTarget the base target
49 | * @param generationSignature
50 | */
51 | public RoundStartedEvent(boolean restart, long blockNumber, long scoopNumber, long capacity, long targetDeadline, long baseTarget, byte[] generationSignature)
52 | {
53 | super(blockNumber);
54 |
55 | this.restart = restart;
56 | this.blockNumber = blockNumber;
57 | this.scoopNumber = scoopNumber;
58 | this.capacity = capacity;
59 | this.targetDeadline = targetDeadline;
60 | this.baseTarget = baseTarget;
61 | this.generationSignature = generationSignature;
62 | }
63 |
64 | public byte[] getGenerationSignature()
65 | {
66 | return generationSignature;
67 | }
68 |
69 | public boolean isRestart()
70 | {
71 | return restart;
72 | }
73 |
74 | /**
75 | * Gets capacity.
76 | *
77 | * @return the capacity
78 | */
79 | public long getCapacity()
80 | {
81 | return capacity;
82 | }
83 |
84 | /**
85 | * Gets block number.
86 | *
87 | * @return the block number
88 | */
89 | public long getBlockNumber()
90 | {
91 | return blockNumber;
92 | }
93 |
94 | /**
95 | * Gets scoop number.
96 | *
97 | * @return the scoop number
98 | */
99 | public long getScoopNumber()
100 | {
101 | return scoopNumber;
102 | }
103 |
104 | /**
105 | * Gets target deadline.
106 | *
107 | * @return the target deadline
108 | */
109 | public long getTargetDeadline()
110 | {
111 | return targetDeadline;
112 | }
113 |
114 | /**
115 | * Gets base target.
116 | *
117 | * @return the base target
118 | */
119 | public long getBaseTarget()
120 | {
121 | return baseTarget;
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/burstcoin/jminer/core/round/event/RoundStoppedEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package burstcoin.jminer.core.round.event;
24 |
25 | import org.springframework.context.ApplicationEvent;
26 |
27 | /**
28 | * The type Round stopped event.
29 | */
30 | public class RoundStoppedEvent
31 | extends ApplicationEvent
32 | {
33 | private long blockNumber;
34 | private long bestCommittedDeadline;
35 |
36 | private long capacity;
37 | private long remainingCapacity;
38 | private long elapsedTime;
39 | private int networkQuality;
40 |
41 | public RoundStoppedEvent(long blockNumber, long bestCommittedDeadline, long capacity, long remainingCapacity, long elapsedTime, int networkQuality)
42 | {
43 | super(blockNumber);
44 |
45 | this.blockNumber = blockNumber;
46 | this.bestCommittedDeadline = bestCommittedDeadline;
47 | this.capacity = capacity;
48 | this.remainingCapacity = remainingCapacity;
49 | this.elapsedTime = elapsedTime;
50 | this.networkQuality = networkQuality;
51 | }
52 |
53 | public long getBlockNumber()
54 | {
55 | return blockNumber;
56 | }
57 |
58 | public long getBestCommittedDeadline()
59 | {
60 | return bestCommittedDeadline;
61 | }
62 |
63 | public long getCapacity()
64 | {
65 | return capacity;
66 | }
67 |
68 | public long getRemainingCapacity()
69 | {
70 | return remainingCapacity;
71 | }
72 |
73 | public long getElapsedTime()
74 | {
75 | return elapsedTime;
76 | }
77 |
78 | public int getNetworkQuality()
79 | {
80 | return networkQuality;
81 | }
82 | }
83 |
84 |
--------------------------------------------------------------------------------
/src/main/java/nxt/crypto/XoredData.java:
--------------------------------------------------------------------------------
1 | package nxt.crypto;
2 |
3 | public final class XoredData {
4 |
5 | private final byte[] data;
6 | private final byte[] nonce;
7 |
8 | public XoredData(byte[] data, byte[] nonce) {
9 | this.data = data;
10 | this.nonce = nonce;
11 | }
12 |
13 | public static XoredData encrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey) {
14 | byte[] nonce = Crypto.xorEncrypt(plaintext, 0, plaintext.length, myPrivateKey, theirPublicKey);
15 | return new XoredData(plaintext, nonce);
16 | }
17 |
18 | public byte[] decrypt(byte[] myPrivateKey, byte[] theirPublicKey) {
19 | byte[] ciphertext = new byte[getData().length];
20 | System.arraycopy(getData(), 0, ciphertext, 0, ciphertext.length);
21 | Crypto.xorDecrypt(ciphertext, 0, ciphertext.length, myPrivateKey, theirPublicKey, getNonce());
22 | return ciphertext;
23 | }
24 |
25 | public byte[] getData() {
26 | return data;
27 | }
28 |
29 | public byte[] getNonce() {
30 | return nonce;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/nxt/util/Convert.java:
--------------------------------------------------------------------------------
1 | package nxt.util;
2 |
3 | import nxt.crypto.Crypto;
4 |
5 | import java.math.BigInteger;
6 | import java.util.Arrays;
7 |
8 | public final class Convert {
9 |
10 | private static final char[] hexChars = { '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' };
11 | private static final long[] multipliers = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
12 |
13 | public static final BigInteger two64 = new BigInteger("18446744073709551616");
14 |
15 | private Convert() {} //never
16 |
17 | public static byte[] parseHexString(String hex) {
18 | byte[] bytes = new byte[hex.length() / 2];
19 | for (int i = 0; i < bytes.length; i++) {
20 | int char1 = hex.charAt(i * 2);
21 | char1 = char1 > 0x60 ? char1 - 0x57 : char1 - 0x30;
22 | int char2 = hex.charAt(i * 2 + 1);
23 | char2 = char2 > 0x60 ? char2 - 0x57 : char2 - 0x30;
24 | if (char1 < 0 || char2 < 0 || char1 > 15 || char2 > 15) {
25 | throw new NumberFormatException("Invalid hex number: " + hex);
26 | }
27 | bytes[i] = (byte)((char1 << 4) + char2);
28 | }
29 | return bytes;
30 | }
31 |
32 | public static String toHexString(byte[] bytes) {
33 | char[] chars = new char[bytes.length * 2];
34 | for (int i = 0; i < bytes.length; i++) {
35 | chars[i * 2] = hexChars[((bytes[i] >> 4) & 0xF)];
36 | chars[i * 2 + 1] = hexChars[(bytes[i] & 0xF)];
37 | }
38 | return String.valueOf(chars);
39 | }
40 |
41 | public static String toUnsignedLong(long objectId) {
42 | if (objectId >= 0) {
43 | return String.valueOf(objectId);
44 | }
45 | BigInteger id = BigInteger.valueOf(objectId).add(two64);
46 | return id.toString();
47 | }
48 |
49 | public static String toUnsignedLong(Long objectId) {
50 | return toUnsignedLong(nullToZero(objectId));
51 | }
52 |
53 | public static Long parseUnsignedLong(String number) {
54 | if (number == null) {
55 | return null;
56 | }
57 | BigInteger bigInt = new BigInteger(number.trim());
58 | if (bigInt.signum() < 0 || bigInt.compareTo(two64) != -1) {
59 | throw new IllegalArgumentException("overflow: " + number);
60 | }
61 | return zeroToNull(bigInt.longValue());
62 | }
63 |
64 | public static Long parseAccountId(String account) {
65 | if (account == null) {
66 | return null;
67 | }
68 | account = account.toUpperCase();
69 | if (account.startsWith("NXT-")) {
70 | return zeroToNull(Crypto.rsDecode(account.substring(4)));
71 | } else {
72 | return parseUnsignedLong(account);
73 | }
74 | }
75 |
76 | public static String rsAccount(Long accountId) {
77 | return "NXT-" + Crypto.rsEncode(nullToZero(accountId));
78 | }
79 |
80 | public static Long fullHashToId(byte[] hash) {
81 | if (hash == null || hash.length < 8) {
82 | throw new IllegalArgumentException("Invalid hash: " + Arrays.toString(hash));
83 | }
84 | BigInteger bigInteger = new BigInteger(1, new byte[] {hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]});
85 | return bigInteger.longValue();
86 | }
87 |
88 | public static Long fullHashToId(String hash) {
89 | if (hash == null) {
90 | return null;
91 | }
92 | return fullHashToId(Convert.parseHexString(hash));
93 | }
94 |
95 | public static Long zeroToNull(long l) {
96 | return l == 0 ? null : l;
97 | }
98 |
99 | public static long nullToZero(Long l) {
100 | return l == null ? 0 : l;
101 | }
102 |
103 | public static int nullToZero(Integer i) {
104 | return i == null ? 0 : i;
105 | }
106 |
107 | public static String emptyToNull(String s) {
108 | return s == null || s.length() == 0 ? null : s;
109 | }
110 |
111 | public static String nullToEmpty(String s) {
112 | return s == null ? "" : s;
113 | }
114 |
115 | public static byte[] emptyToNull(byte[] bytes) {
116 | if (bytes == null) {
117 | return null;
118 | }
119 | for (byte b : bytes) {
120 | if (b != 0) {
121 | return bytes;
122 | }
123 | }
124 | return null;
125 | }
126 |
127 | public static String truncate(String s, String replaceNull, int limit, boolean dots) {
128 | return s == null ? replaceNull : s.length() > limit ? (s.substring(0, dots ? limit - 3 : limit) + (dots ? "..." : "")) : s;
129 | }
130 |
131 | private static long parseStringFraction(String value, int decimals, long maxValue) {
132 | String[] s = value.trim().split("\\.");
133 | if (s.length == 0 || s.length > 2) {
134 | throw new NumberFormatException("Invalid number: " + value);
135 | }
136 | long wholePart = Long.parseLong(s[0]);
137 | if (wholePart > maxValue) {
138 | throw new IllegalArgumentException("Whole part of value exceeds maximum possible");
139 | }
140 | if (s.length == 1) {
141 | return wholePart * multipliers[decimals];
142 | }
143 | long fractionalPart = Long.parseLong(s[1]);
144 | if (fractionalPart >= multipliers[decimals] || s[1].length() > decimals) {
145 | throw new IllegalArgumentException("Fractional part exceeds maximum allowed divisibility");
146 | }
147 | for (int i = s[1].length(); i < decimals; i++) {
148 | fractionalPart *= 10;
149 | }
150 | return wholePart * multipliers[decimals] + fractionalPart;
151 | }
152 |
153 | // overflow checking based on https://www.securecoding.cert.org/confluence/display/java/NUM00-J.+Detect+or+prevent+integer+overflow
154 | public static long safeAdd(long left, long right)
155 | throws ArithmeticException {
156 | if (right > 0 ? left > Long.MAX_VALUE - right
157 | : left < Long.MIN_VALUE - right) {
158 | throw new ArithmeticException("Integer overflow");
159 | }
160 | return left + right;
161 | }
162 |
163 | public static long safeSubtract(long left, long right)
164 | throws ArithmeticException {
165 | if (right > 0 ? left < Long.MIN_VALUE + right
166 | : left > Long.MAX_VALUE + right) {
167 | throw new ArithmeticException("Integer overflow");
168 | }
169 | return left - right;
170 | }
171 |
172 | public static long safeMultiply(long left, long right)
173 | throws ArithmeticException {
174 | if (right > 0 ? left > Long.MAX_VALUE/right
175 | || left < Long.MIN_VALUE/right
176 | : (right < -1 ? left > Long.MIN_VALUE/right
177 | || left < Long.MAX_VALUE/right
178 | : right == -1
179 | && left == Long.MIN_VALUE) ) {
180 | throw new ArithmeticException("Integer overflow");
181 | }
182 | return left * right;
183 | }
184 |
185 | public static long safeDivide(long left, long right)
186 | throws ArithmeticException {
187 | if ((left == Long.MIN_VALUE) && (right == -1)) {
188 | throw new ArithmeticException("Integer overflow");
189 | }
190 | return left / right;
191 | }
192 |
193 | public static long safeNegate(long a) throws ArithmeticException {
194 | if (a == Long.MIN_VALUE) {
195 | throw new ArithmeticException("Integer overflow");
196 | }
197 | return -a;
198 | }
199 |
200 | public static long safeAbs(long a) throws ArithmeticException {
201 | if (a == Long.MIN_VALUE) {
202 | throw new ArithmeticException("Integer overflow");
203 | }
204 | return Math.abs(a);
205 | }
206 |
207 | }
208 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/CommandQueueInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.cl_command_queue;
31 | import org.jocl.cl_context;
32 | import org.jocl.cl_device_id;
33 |
34 | import static org.jocl.CL.*;
35 |
36 | /**
37 | * Utility methods for obtaining information about cl_command_queue objects
38 | */
39 | public class CommandQueueInfos
40 | {
41 | /**
42 | * The context that this command queue belongs to
43 | *
44 | * @param commandQueue The command queue
45 | *
46 | * @return The value
47 | */
48 | public static cl_context getContext(cl_command_queue commandQueue)
49 | {
50 | cl_context result = new cl_context();
51 | Infos.getPointer(Infos.FOR_COMMAND_QUEUE, commandQueue,
52 | CL_QUEUE_CONTEXT, result);
53 | if(result.equals(new cl_context()))
54 | {
55 | return null;
56 | }
57 | return result;
58 | }
59 |
60 | /**
61 | * The device that this command queue belongs to
62 | *
63 | * @param commandQueue The command queue
64 | *
65 | * @return The value
66 | */
67 | public static cl_device_id getDevice(cl_command_queue commandQueue)
68 | {
69 | cl_device_id result = new cl_device_id();
70 | Infos.getPointer(Infos.FOR_COMMAND_QUEUE, commandQueue,
71 | CL_QUEUE_CONTEXT, result);
72 | if(result.equals(new cl_device_id()))
73 | {
74 | return null;
75 | }
76 | return result;
77 | }
78 |
79 | /**
80 | * The reference count. Only intended for identifying memory leaks.
81 | *
82 | * @param commandQueue The command queue
83 | *
84 | * @return The value
85 | */
86 | public static int getReferenceCount(cl_command_queue commandQueue)
87 | {
88 | return Infos.getInt(Infos.FOR_COMMAND_QUEUE, commandQueue,
89 | CL_QUEUE_REFERENCE_COUNT);
90 | }
91 |
92 | /**
93 | * The properties of the command queue.
94 | *
95 | * @param commandQueue The command queue
96 | *
97 | * @return The value
98 | */
99 | public static long getProperties(cl_command_queue commandQueue)
100 | {
101 | return Infos.getLong(Infos.FOR_COMMAND_QUEUE, commandQueue,
102 | CL_QUEUE_PROPERTIES);
103 | }
104 |
105 | /**
106 | * The properties of the command queue, as a String
107 | *
108 | * @param commandQueue The command queue
109 | *
110 | * @return The value
111 | */
112 | public static String getPropertiesString(cl_command_queue commandQueue)
113 | {
114 | return stringFor_cl_command_queue_properties(getProperties(commandQueue));
115 | }
116 |
117 | /**
118 | * Private constructor to prevent instantiation
119 | */
120 | private CommandQueueInfos()
121 | {
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/ContextInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.Sizeof;
31 | import org.jocl.cl_context;
32 | import org.jocl.cl_device_id;
33 |
34 | import static org.jocl.CL.*;
35 |
36 | /**
37 | * Utility methods for obtaining information about cl_context objects
38 | */
39 | public class ContextInfos
40 | {
41 |
42 | /**
43 | * The reference count. Only intended for identifying memory leaks.
44 | *
45 | * @param context The context
46 | *
47 | * @return The value
48 | */
49 | public static int getReferenceCount(cl_context context)
50 | {
51 | return Infos.getInt(Infos.FOR_CONTEXT, context,
52 | CL_CONTEXT_REFERENCE_COUNT);
53 | }
54 |
55 | /**
56 | * The number of devices associated with the context.
57 | *
58 | * @param context The context
59 | *
60 | * @return The value
61 | */
62 | public static int getNumDevices(cl_context context)
63 | {
64 | return Infos.getInt(Infos.FOR_CONTEXT, context,
65 | CL_CONTEXT_NUM_DEVICES);
66 | }
67 |
68 | /**
69 | * The devices associated with the context.
70 | *
71 | * @param context The context
72 | *
73 | * @return The value
74 | */
75 | public static cl_device_id[] getDevices(cl_context context)
76 | {
77 | int numDevices = getNumDevices(context);
78 | cl_device_id devices[] = new cl_device_id[numDevices];
79 | Infos.getPointers(Infos.FOR_CONTEXT, context,
80 | CL_CONTEXT_DEVICES, devices);
81 | cl_device_id nullDevice = new cl_device_id();
82 | for(int i = 0; i < numDevices; i++)
83 | {
84 | if(devices[i].equals(nullDevice))
85 | {
86 | devices[i] = null;
87 | }
88 | }
89 | return devices;
90 | }
91 |
92 | /**
93 | * The properties of the context.
94 | *
95 | * @param context The context
96 | *
97 | * @return The value
98 | */
99 | public static long[] getProperties(cl_context context)
100 | {
101 | long valueSize = Infos.FOR_CONTEXT.getSize(context,
102 | CL_CONTEXT_PROPERTIES);
103 | int numValues = (int) (valueSize / Sizeof.POINTER);
104 | return Infos.getSizes(Infos.FOR_CONTEXT, context,
105 | CL_CONTEXT_PROPERTIES, numValues);
106 | }
107 |
108 | /**
109 | * The properties of the context, as Strings. The strings are the key-value pairs of the properties. The even indices of the properties array are assumed to
110 | * be of type cl_context_properties, and the odd entries are assumed to be values that are returned in a hexadecimal form.
111 | *
112 | * @param context The context
113 | *
114 | * @return The value
115 | */
116 | public static String[] getPropertiesStrings(cl_context context)
117 | {
118 | long properties[] = getProperties(context);
119 | // Omit trailing '0' entry
120 | String result[] = new String[properties.length - 1];
121 | for(int i = 0; i < properties.length / 2; i++)
122 | {
123 | long p0 = properties[i * 2 + 0];
124 | long p1 = properties[i * 2 + 1];
125 | result[i * 2 + 0] = stringFor_cl_context_properties((int) p0);
126 | result[i * 2 + 1] = "0x" + Long.toHexString(p1);
127 | }
128 | return result;
129 | }
130 |
131 | /**
132 | * Private constructor to prevent instantiation
133 | */
134 | private ContextInfos()
135 | {
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/Contexts.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.cl_context;
31 | import org.jocl.cl_context_properties;
32 | import org.jocl.cl_device_id;
33 | import org.jocl.cl_platform_id;
34 |
35 | import java.util.Arrays;
36 | import java.util.List;
37 |
38 | import static org.jocl.CL.*;
39 |
40 | /**
41 | * Utility methods related to cl_context objects
42 | */
43 | public class Contexts
44 | {
45 | /**
46 | * Create a new context for the given platform and devices.
47 | *
48 | * @param platform The platform
49 | * @param devices The devices
50 | *
51 | * @return The new context
52 | */
53 | public static cl_context create(
54 | cl_platform_id platform, cl_device_id... devices)
55 | {
56 | return create(platform, Arrays.asList(devices), null);
57 | }
58 |
59 | /**
60 | * Create a new context for the given platform and devices.
61 | *
62 | * @param platform The platform
63 | * @param devices The devices
64 | *
65 | * @return The new context
66 | */
67 | public static cl_context create(
68 | cl_platform_id platform, List devices)
69 | {
70 | return create(platform, devices, null);
71 | }
72 |
73 | /**
74 | * Create a new context with the given platform and devices, using the given additional context properties. The additional context properties are assumed to
75 | * contain pairs of long values, where even entries contain the context property name, and odd values the corresponding value. This array may be
76 | * null
.
77 | *
78 | * @param platform The platform
79 | * @param devices The devices
80 | * @param additionalContextProperties Additional context properties
81 | *
82 | * @return The new context
83 | */
84 | public static cl_context create(
85 | cl_platform_id platform, List devices,
86 | long additionalContextProperties[])
87 | {
88 | cl_device_id devicesArray[] =
89 | devices.toArray(new cl_device_id[devices.size()]);
90 |
91 | cl_context_properties contextProperties = new cl_context_properties();
92 | contextProperties.addProperty(CL_CONTEXT_PLATFORM, platform);
93 | if(additionalContextProperties != null)
94 | {
95 | for(int i = 0; i < additionalContextProperties.length / 2; i++)
96 | {
97 | contextProperties.addProperty(
98 | additionalContextProperties[i * 2 + 0],
99 | additionalContextProperties[i * 2 + 1]);
100 | }
101 | }
102 | cl_context context = clCreateContext(
103 | contextProperties, devicesArray.length,
104 | devicesArray, null, null, null);
105 | return context;
106 | }
107 |
108 |
109 | /**
110 | * Release each of the given contexts if it is not null
.
111 | *
112 | * @param contexts The contexts to release
113 | */
114 | public static void release(cl_context... contexts)
115 | {
116 | if(contexts != null)
117 | {
118 | for(cl_context context : contexts)
119 | {
120 | if(context != null)
121 | {
122 | clReleaseContext(context);
123 | }
124 | }
125 | }
126 | }
127 |
128 | /**
129 | * Release each of the given contexts if it is not null
.
130 | *
131 | * @param contexts The contexts to release
132 | */
133 | public static void release(Iterable contexts)
134 | {
135 | if(contexts != null)
136 | {
137 | for(cl_context context : contexts)
138 | {
139 | if(context != null)
140 | {
141 | clReleaseContext(context);
142 | }
143 | }
144 | }
145 | }
146 |
147 |
148 | /**
149 | * Private constructor to prevent instantiation
150 | */
151 | private Contexts()
152 | {
153 | }
154 |
155 | }
156 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/Devices.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 | package org.jocl.utils;
28 |
29 | import org.jocl.CLException;
30 | import org.jocl.cl_device_id;
31 | import org.jocl.cl_platform_id;
32 |
33 | import java.util.Arrays;
34 | import java.util.Collections;
35 | import java.util.List;
36 |
37 | import static org.jocl.CL.*;
38 |
39 | /**
40 | * Utility methods related to devices.
41 | */
42 | public class Devices
43 | {
44 | /**
45 | * Returns an unmodifiable (possibly empty) list of all devices of the given platform.
46 | *
47 | * @param platform The platform
48 | *
49 | * @return The list of matching devices
50 | */
51 | public static List getDevices(cl_platform_id platform)
52 | {
53 | return getDevices(platform, CL_DEVICE_TYPE_ALL);
54 | }
55 |
56 | /**
57 | * Returns an unmodifiable (possibly empty) list of all devices of the given platform that match the specified device type. The device type must be one of
CL_DEVICE_TYPE_CPU
CL_DEVICE_TYPE_GPU
CL_DEVICE_TYPE_ACCELERATOR
CL_DEVICE_TYPE_DEFAULT
CL_DEVICE_TYPE_ALL
59 | *
60 | * @param platform The platform
61 | * @param deviceType The device type
62 | *
63 | * @return The list of matching devices
64 | */
65 | public static List getDevices(
66 | cl_platform_id platform, long deviceType)
67 | {
68 | // The clGetDeviceIDs method may cause an exception
69 | // to be thrown when no matching devices are found.
70 | // Return an empty list in this case.
71 | int numDevicesArray[] = new int[1];
72 | try
73 | {
74 | int result = clGetDeviceIDs(
75 | platform, deviceType, 0, null, numDevicesArray);
76 | if(result == CL_DEVICE_NOT_FOUND)
77 | {
78 | return Collections.emptyList();
79 | }
80 | }
81 | catch(CLException e)
82 | {
83 | if(e.getStatus() == CL_DEVICE_NOT_FOUND)
84 | {
85 | return Collections.emptyList();
86 | }
87 | throw e;
88 | }
89 | int numDevices = numDevicesArray[0];
90 | cl_device_id devices[] = new cl_device_id[numDevices];
91 | clGetDeviceIDs(platform, deviceType, numDevices, devices, null);
92 | return Arrays.asList(devices);
93 | }
94 |
95 | /**
96 | * Private constructor to prevent instantiation
97 | */
98 | private Devices()
99 | {
100 | }
101 |
102 |
103 | @SuppressWarnings("unused")
104 | private long maxFLOPs(cl_device_id device)
105 | {
106 | int maxComputeUnits = DeviceInfos.getMaxComputeUnits(device);
107 | int maxClockFrequency = DeviceInfos.getMaxClockFrequency(device);
108 |
109 | //System.out.println("maxComputeUnits "+maxComputeUnits);
110 | //System.out.println("maxClockFrequency "+maxClockFrequency);
111 |
112 | // TODO: The value '8' is only for NVIDIA cards!!!
113 | long coresPerComputeUnit = 8;
114 | long maxFlops =
115 | maxComputeUnits * coresPerComputeUnit *
116 | maxClockFrequency * 2 * 1000000;
117 | return maxFlops;
118 | }
119 |
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/EventInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package org.jocl.utils;
24 |
25 | import org.jocl.cl_command_queue;
26 | import org.jocl.cl_context;
27 | import org.jocl.cl_event;
28 |
29 | import static org.jocl.CL.*;
30 |
31 | /**
32 | * Utility methods for obtaining information about cl_event objects.
33 | */
34 | public class EventInfos
35 | {
36 | /**
37 | * The command-queue associated with event
38 | *
39 | * @param event The event
40 | *
41 | * @return The value
42 | */
43 | public static cl_command_queue getCommandQueue(cl_event event)
44 | {
45 | cl_command_queue result = new cl_command_queue();
46 | Infos.getPointer(Infos.FOR_EVENT, event,
47 | CL_EVENT_COMMAND_QUEUE, result);
48 | if(result.equals(new cl_command_queue()))
49 | {
50 | return null;
51 | }
52 | return result;
53 | }
54 |
55 | /**
56 | * The context that this event belongs to
57 | *
58 | * @param event The event
59 | *
60 | * @return The value
61 | */
62 | public static cl_context getContext(cl_event event)
63 | {
64 | cl_context result = new cl_context();
65 | Infos.getPointer(Infos.FOR_EVENT, event,
66 | CL_EVENT_CONTEXT, result);
67 | if(result.equals(new cl_context()))
68 | {
69 | return null;
70 | }
71 | return result;
72 | }
73 |
74 | /**
75 | * The command associated with event
76 | *
77 | * @param event The event
78 | *
79 | * @return The value
80 | */
81 | public static int getCommandType(cl_event event)
82 | {
83 | return Infos.getInt(Infos.FOR_EVENT, event,
84 | CL_EVENT_COMMAND_TYPE);
85 | }
86 |
87 | /**
88 | * The command associated with event, as a String
89 | *
90 | * @param event The event
91 | *
92 | * @return The value
93 | */
94 | public static String getCommandTypeString(cl_event event)
95 | {
96 | return stringFor_cl_command_type(
97 | Infos.getInt(Infos.FOR_EVENT, event,
98 | CL_EVENT_COMMAND_TYPE));
99 | }
100 |
101 | /**
102 | * The execution status of the command identified by event.
103 | *
104 | * @param event The event
105 | *
106 | * @return The value
107 | */
108 | public static int getCommandExecutionStatus(cl_event event)
109 | {
110 | return Infos.getInt(Infos.FOR_EVENT, event,
111 | CL_EVENT_COMMAND_EXECUTION_STATUS);
112 |
113 | }
114 |
115 | /**
116 | * The execution status of the command identified by event, as a String
117 | *
118 | * @param event The event
119 | *
120 | * @return The value
121 | */
122 | public static String getCommandExecutionStatusString(cl_event event)
123 | {
124 | return stringFor_command_execution_status(
125 | Infos.getInt(Infos.FOR_EVENT, event,
126 | CL_EVENT_COMMAND_EXECUTION_STATUS));
127 | }
128 |
129 |
130 | /**
131 | * The reference count. Only intended for identifying memory leaks.
132 | *
133 | * @param event The event
134 | *
135 | * @return The value
136 | */
137 | public static int getReferenceCount(cl_event event)
138 | {
139 | return Infos.getInt(Infos.FOR_EVENT, event,
140 | CL_EVENT_REFERENCE_COUNT);
141 | }
142 |
143 |
144 | /**
145 | * Private constructor to prevent instantiation
146 | */
147 | private EventInfos()
148 | {
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/EventProfilingInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package org.jocl.utils;
24 |
25 | import org.jocl.cl_event;
26 |
27 | import static org.jocl.CL.*;
28 |
29 | /**
30 | * Utility methods for obtaining profiling information about cl_event objects.
31 | */
32 | public class EventProfilingInfos
33 | {
34 | /**
35 | * The device counter, in nanoseconds, when the command of the given event was queued.
36 | *
37 | * @param event The event
38 | *
39 | * @return The value
40 | */
41 | public static long getCommandQueued(cl_event event)
42 | {
43 | return Infos.getLong(Infos.FOR_EVENT_PROFILING, event,
44 | CL_PROFILING_COMMAND_QUEUED);
45 | }
46 |
47 | /**
48 | * The device counter, in nanoseconds, when the command of the given event was submitted.
49 | *
50 | * @param event The event
51 | *
52 | * @return The value
53 | */
54 | public static long getCommandSubmit(cl_event event)
55 | {
56 | return Infos.getLong(Infos.FOR_EVENT_PROFILING, event,
57 | CL_PROFILING_COMMAND_SUBMIT);
58 | }
59 |
60 | /**
61 | * The device counter, in nanoseconds, when the command of the given event started execution.
62 | *
63 | * @param event The event
64 | *
65 | * @return The value
66 | */
67 | public static long getCommandStart(cl_event event)
68 | {
69 | return Infos.getLong(Infos.FOR_EVENT_PROFILING, event,
70 | CL_PROFILING_COMMAND_START);
71 | }
72 |
73 | /**
74 | * The device counter, in nanoseconds, when the command of the given event finished execution.
75 | *
76 | * @param event The event
77 | *
78 | * @return The value
79 | */
80 | public static long getCommandEnd(cl_event event)
81 | {
82 | return Infos.getLong(Infos.FOR_EVENT_PROFILING, event,
83 | CL_PROFILING_COMMAND_END);
84 | }
85 |
86 | /**
87 | * Private constructor to prevent instantiation
88 | */
89 | private EventProfilingInfos()
90 | {
91 |
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/Events.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.cl_event;
31 |
32 | import java.util.ArrayList;
33 | import java.util.Arrays;
34 | import java.util.List;
35 |
36 | import static org.jocl.CL.*;
37 |
38 | /**
39 | * Utility methods related to events.
40 | */
41 | public class Events
42 | {
43 | /**
44 | * Compute the execution time for the given event, in milliseconds. This may only be called if the event is associated with a command queue for which
45 | * profiling is enabled.
46 | *
47 | * @param event The event
48 | *
49 | * @return The execution time, in milliseconds
50 | */
51 | public static double computeExecutionTimeMs(cl_event event)
52 | {
53 | long startTime = EventProfilingInfos.getCommandStart(event);
54 | long endTime = EventProfilingInfos.getCommandEnd(event);
55 | return (endTime - startTime) * 1e-6;
56 | }
57 |
58 |
59 | /**
60 | * Wait for the given events if they are not null
.
61 | *
62 | * @param events The events to wait for
63 | */
64 | public static void waitFor(cl_event... events)
65 | {
66 | if(events != null)
67 | {
68 | waitFor(Arrays.asList(events));
69 | }
70 | }
71 |
72 | /**
73 | * Wait for the given events if they are not null
.
74 | *
75 | * @param events The events to wait for
76 | */
77 | public static void waitFor(Iterable events)
78 | {
79 | if(events != null)
80 | {
81 | List eventList = new ArrayList();
82 | for(cl_event event : events)
83 | {
84 | if(event != null)
85 | {
86 | eventList.add(event);
87 | }
88 | }
89 | cl_event array[] = eventList.toArray(
90 | new cl_event[eventList.size()]);
91 | clWaitForEvents(array.length, array);
92 | }
93 | }
94 |
95 |
96 | /**
97 | * Release each of the given events if it is not null
.
98 | *
99 | * @param events The events to release
100 | */
101 | public static void release(cl_event... events)
102 | {
103 | if(events != null)
104 | {
105 | release(Arrays.asList(events));
106 | }
107 | }
108 |
109 | /**
110 | * Release each of the given events if it is not null
.
111 | *
112 | * @param events The events to release
113 | */
114 | public static void release(Iterable events)
115 | {
116 | if(events != null)
117 | {
118 | for(cl_event event : events)
119 | {
120 | if(event != null)
121 | {
122 | clReleaseEvent(event);
123 | }
124 | }
125 | }
126 | }
127 |
128 |
129 | /**
130 | * Private constructor to prevent instantiation
131 | */
132 | private Events()
133 | {
134 |
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/KernelInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package org.jocl.utils;
24 |
25 | import org.jocl.cl_context;
26 | import org.jocl.cl_kernel;
27 | import org.jocl.cl_program;
28 |
29 | import static org.jocl.CL.*;
30 |
31 | /**
32 | * Utility methods for obtaining information about cl_kernel objects
33 | */
34 | public class KernelInfos
35 | {
36 | /**
37 | * The kernel function name.
38 | *
39 | * @param kernel The kernel
40 | *
41 | * @return The value
42 | */
43 | public static String getFunctionName(cl_kernel kernel)
44 | {
45 | return Infos.getString(Infos.FOR_KERNEL, kernel,
46 | CL_KERNEL_FUNCTION_NAME);
47 | }
48 |
49 | /**
50 | * The reference count - only provided for identifying memory leaks.
51 | *
52 | * @param kernel The kernel
53 | *
54 | * @return The value
55 | */
56 | public static int getReferenceCount(cl_kernel kernel)
57 | {
58 | return Infos.getInt(Infos.FOR_KERNEL, kernel,
59 | CL_KERNEL_REFERENCE_COUNT);
60 | }
61 |
62 | /**
63 | * The number of arguments
64 | *
65 | * @param kernel The kernel
66 | *
67 | * @return The value
68 | */
69 | public static int getNumArgs(cl_kernel kernel)
70 | {
71 | return Infos.getInt(Infos.FOR_KERNEL, kernel,
72 | CL_KERNEL_NUM_ARGS);
73 | }
74 |
75 | /**
76 | * The context that this kernel belongs to
77 | *
78 | * @param kernel The kernel
79 | *
80 | * @return The value
81 | */
82 | public static cl_context getContext(cl_kernel kernel)
83 | {
84 | cl_context result = new cl_context();
85 | Infos.getPointer(Infos.FOR_KERNEL, kernel,
86 | CL_KERNEL_CONTEXT, result);
87 | if(result.equals(new cl_context()))
88 | {
89 | return null;
90 | }
91 | return result;
92 | }
93 |
94 | /**
95 | * The program that this kernel belongs to
96 | *
97 | * @param kernel The kernel
98 | *
99 | * @return The value
100 | */
101 | public static cl_program getProgram(cl_kernel kernel)
102 | {
103 | cl_program result = new cl_program();
104 | Infos.getPointer(Infos.FOR_KERNEL, kernel,
105 | CL_KERNEL_PROGRAM, result);
106 | if(result.equals(new cl_program()))
107 | {
108 | return null;
109 | }
110 | return result;
111 | }
112 |
113 |
114 | /**
115 | * Private constructor to prevent instantiation
116 | */
117 | private KernelInfos()
118 | {
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/MemInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.Pointer;
31 | import org.jocl.cl_context;
32 | import org.jocl.cl_mem;
33 |
34 | import static org.jocl.CL.*;
35 |
36 | /**
37 | * Utility methods for obtaining information about cl_mem objects
38 | */
39 | public class MemInfos
40 | {
41 | /**
42 | * The type of the memory object
43 | *
44 | * @param mem The mem
45 | *
46 | * @return The value
47 | */
48 | public static int getType(cl_mem mem)
49 | {
50 | return Infos.getInt(Infos.FOR_MEM, mem,
51 | CL_MEM_TYPE);
52 | }
53 |
54 | /**
55 | * The type of the memory object as a String
56 | *
57 | * @param mem The mem
58 | *
59 | * @return The value
60 | */
61 | public static String getTypeString(cl_mem mem)
62 | {
63 | return stringFor_cl_mem_object_type(
64 | Infos.getInt(Infos.FOR_MEM, mem,
65 | CL_MEM_TYPE));
66 | }
67 |
68 | /**
69 | * The flags specified when the memory object was created
70 | *
71 | * @param mem The mem
72 | *
73 | * @return The value
74 | */
75 | public static long getFlags(cl_mem mem)
76 | {
77 | return Infos.getLong(Infos.FOR_MEM, mem,
78 | CL_MEM_FLAGS);
79 | }
80 |
81 | /**
82 | * The flags specified when the memory object was created
83 | *
84 | * @param mem The mem
85 | *
86 | * @return The value
87 | */
88 | public static String getFlagsString(cl_mem mem)
89 | {
90 | return stringFor_cl_mem_flags(
91 | Infos.getLong(Infos.FOR_MEM, mem,
92 | CL_MEM_FLAGS));
93 | }
94 |
95 | /**
96 | * Size of the memory object in bytes
97 | *
98 | * @param mem The mem
99 | *
100 | * @return The value
101 | */
102 | public static long getSize(cl_mem mem)
103 | {
104 | return Infos.getSize(Infos.FOR_MEM, mem,
105 | CL_MEM_SIZE);
106 | }
107 |
108 | /**
109 | * The host pointer specified when the memory object was created.
110 | *
111 | * @param mem The mem
112 | *
113 | * @return The value
114 | */
115 | public static Pointer getHostPtr(cl_mem mem)
116 | {
117 | Pointer result = new Pointer();
118 | Infos.getPointer(Infos.FOR_MEM, mem,
119 | CL_MEM_HOST_PTR, result);
120 | if(result.equals(new Pointer()))
121 | {
122 | return null;
123 | }
124 | return result;
125 | }
126 |
127 | /**
128 | * The map count - only provided for debugging.
129 | *
130 | * @param mem The mem
131 | *
132 | * @return The value
133 | */
134 | public static int getMapCount(cl_mem mem)
135 | {
136 | return Infos.getInt(Infos.FOR_MEM, mem,
137 | CL_MEM_MAP_COUNT);
138 | }
139 |
140 | /**
141 | * The reference count - only provided for identifying memory leaks.
142 | *
143 | * @param mem The mem
144 | *
145 | * @return The value
146 | */
147 | public static int getReferenceCount(cl_mem mem)
148 | {
149 | return Infos.getInt(Infos.FOR_MEM, mem,
150 | CL_MEM_REFERENCE_COUNT);
151 | }
152 |
153 | /**
154 | * The context that this memory object belongs to
155 | *
156 | * @param mem The mem
157 | *
158 | * @return The value
159 | */
160 | public static cl_context getContext(cl_mem mem)
161 | {
162 | cl_context result = new cl_context();
163 | Infos.getPointer(Infos.FOR_MEM, mem,
164 | CL_MEM_CONTEXT, result);
165 | if(result.equals(new cl_context()))
166 | {
167 | return null;
168 | }
169 | return result;
170 | }
171 |
172 | /**
173 | * The memory object specified as buffer argument to clCreateSubBuffer, or NULL
174 | *
175 | * @param mem The mem
176 | *
177 | * @return The value
178 | */
179 | public static cl_mem getAssociatedMemobject(cl_mem mem)
180 | {
181 | cl_mem result = new cl_mem();
182 | Infos.getPointer(Infos.FOR_MEM, mem,
183 | CL_MEM_ASSOCIATED_MEMOBJECT, result);
184 | if(result.equals(new cl_mem()))
185 | {
186 | return null;
187 | }
188 | return result;
189 | }
190 |
191 | /**
192 | * If the memory object is a sub-buffer, this is its offset, otherwise it is 0
193 | *
194 | * @param mem The mem
195 | *
196 | * @return The value
197 | */
198 | public static long getOffset(cl_mem mem)
199 | {
200 | return Infos.getSize(Infos.FOR_MEM, mem,
201 | CL_MEM_OFFSET);
202 | }
203 |
204 |
205 | /**
206 | * Private constructor to prevent instantiation
207 | */
208 | private MemInfos()
209 | {
210 |
211 | }
212 | }
213 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/Mems.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.Pointer;
31 | import org.jocl.Sizeof;
32 | import org.jocl.cl_context;
33 | import org.jocl.cl_mem;
34 |
35 | import java.util.Arrays;
36 |
37 | import static org.jocl.CL.*;
38 |
39 | /**
40 | * Utility methods related to memory objects.
41 | */
42 | public class Mems
43 | {
44 |
45 | /**
46 | * Create a memory object with the given size.
47 | *
48 | * @param context The context for which the memory object will be created
49 | * @param size The size of the memory object, in bytes
50 | *
51 | * @return The memory object
52 | */
53 | public static cl_mem create(cl_context context, int size)
54 | {
55 | cl_mem mem = clCreateBuffer(
56 | context, CL_MEM_READ_WRITE,
57 | size, null, null);
58 | return mem;
59 | }
60 |
61 | /**
62 | * Create a memory object that contains the data from the given array
63 | *
64 | * @param context The context for which the memory object will be created
65 | * @param array The array
66 | *
67 | * @return The memory object
68 | */
69 | public static cl_mem create(
70 | cl_context context, byte array[])
71 | {
72 | return create(
73 | context, array.length * Sizeof.cl_char, Pointer.to(array));
74 | }
75 |
76 | /**
77 | * Create a memory object that contains the data from the given array
78 | *
79 | * @param context The context for which the memory object will be created
80 | * @param array The array
81 | *
82 | * @return The memory object
83 | */
84 | public static cl_mem create(
85 | cl_context context, short array[])
86 | {
87 | return create(
88 | context, array.length * Sizeof.cl_short, Pointer.to(array));
89 | }
90 |
91 | /**
92 | * Create a memory object that contains the data from the given array
93 | *
94 | * @param context The context for which the memory object will be created
95 | * @param array The array
96 | *
97 | * @return The memory object
98 | */
99 | public static cl_mem create(
100 | cl_context context, int array[])
101 | {
102 | return create(
103 | context, array.length * Sizeof.cl_int, Pointer.to(array));
104 | }
105 |
106 | /**
107 | * Create a memory object that contains the data from the given array
108 | *
109 | * @param context The context for which the memory object will be created
110 | * @param array The array
111 | *
112 | * @return The memory object
113 | */
114 | public static cl_mem create(
115 | cl_context context, long array[])
116 | {
117 | return create(
118 | context, array.length * Sizeof.cl_long, Pointer.to(array));
119 | }
120 |
121 | /**
122 | * Create a memory object that contains the data from the given array
123 | *
124 | * @param context The context for which the memory object will be created
125 | * @param array The array
126 | *
127 | * @return The memory object
128 | */
129 | public static cl_mem create(
130 | cl_context context, float array[])
131 | {
132 | return create(
133 | context, array.length * Sizeof.cl_float, Pointer.to(array));
134 | }
135 |
136 | /**
137 | * Create a memory object that contains the data from the given array
138 | *
139 | * @param context The context for which the memory object will be created
140 | * @param array The array
141 | *
142 | * @return The memory object
143 | */
144 | public static cl_mem create(
145 | cl_context context, double array[])
146 | {
147 | return create(
148 | context, array.length * Sizeof.cl_double, Pointer.to(array));
149 | }
150 |
151 | /**
152 | * Creates a memory object with the given size that contains the data from the given source pointer.
153 | *
154 | * @param context The context for which the memory object will be created
155 | * @param size The size of the memory object, in bytes
156 | * @param source The pointer to the source data
157 | *
158 | * @return The memory object
159 | */
160 | private static cl_mem create(
161 | cl_context context, long size, Pointer source)
162 | {
163 | cl_mem mem = clCreateBuffer(
164 | context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,
165 | size, source, null);
166 | return mem;
167 | }
168 |
169 | /**
170 | * Release each of the given memory objects if it is not null
.
171 | *
172 | * @param mems The memory objects to release
173 | */
174 | public static void release(cl_mem... mems)
175 | {
176 | if(mems != null)
177 | {
178 | release(Arrays.asList(mems));
179 | }
180 | }
181 |
182 | /**
183 | * Release each of the given memory objects if it is not null
.
184 | *
185 | * @param mems The memory objects to release
186 | */
187 | public static void release(Iterable mems)
188 | {
189 | if(mems != null)
190 | {
191 | for(cl_mem mem : mems)
192 | {
193 | if(mem != null)
194 | {
195 | clReleaseMemObject(mem);
196 | }
197 | }
198 | }
199 | }
200 |
201 |
202 | /**
203 | * Private constructor to prevent instantiation
204 | */
205 | private Mems()
206 | {
207 |
208 | }
209 | }
210 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/PlatformInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * The MIT License (MIT)
3 | *
4 | * Copyright (c) 2016 by luxe - https://github.com/de-luxe - BURST-LUXE-RED2-G6JW-H4HG5
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
7 | * and associated documentation files (the "Software"), to deal in the Software without restriction,
8 | * including without limitation the rights to use, copy, modify, merge, publish, distribute,
9 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
10 | * is furnished to do so, subject to the following conditions:
11 | *
12 | * The above copyright notice and this permission notice shall be included in all copies
13 | * or substantial portions of the Software.
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
16 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 | *
21 | */
22 |
23 | package org.jocl.utils;
24 |
25 | import org.jocl.cl_platform_id;
26 |
27 | import static org.jocl.CL.*;
28 |
29 | /**
30 | * Utility methods for obtaining information about cl_platform_id objects
31 | */
32 | public class PlatformInfos
33 | {
34 | /**
35 | * Platform name string
36 | *
37 | * @param platform The platform
38 | *
39 | * @return The value
40 | */
41 | public static String getName(cl_platform_id platform)
42 | {
43 | return Infos.getString(Infos.FOR_PLATFORM, platform,
44 | CL_PLATFORM_NAME);
45 | }
46 |
47 | /**
48 | * Platform vendor string
49 | *
50 | * @param platform The platform
51 | *
52 | * @return The value
53 | */
54 | public static String getVendor(cl_platform_id platform)
55 | {
56 | return Infos.getString(Infos.FOR_PLATFORM, platform,
57 | CL_PLATFORM_VENDOR);
58 | }
59 |
60 | /**
61 | * OpenCL version string
62 | *
63 | * @param platform The platform
64 | *
65 | * @return The value
66 | */
67 | public static String getVersion(cl_platform_id platform)
68 | {
69 | return Infos.getString(Infos.FOR_PLATFORM, platform,
70 | CL_PLATFORM_VERSION);
71 | }
72 |
73 | /**
74 | * The profile name supported by the implementation
75 | *
76 | * @param platform The platform
77 | *
78 | * @return The value
79 | */
80 | public static String getProfile(cl_platform_id platform)
81 | {
82 | return Infos.getString(Infos.FOR_PLATFORM, platform,
83 | CL_PLATFORM_PROFILE);
84 | }
85 |
86 | /**
87 | * A space-separated list of extension names
88 | *
89 | * @param platform The platform
90 | *
91 | * @return The value
92 | */
93 | public static String getExtensions(cl_platform_id platform)
94 | {
95 | return Infos.getString(Infos.FOR_PLATFORM, platform,
96 | CL_PLATFORM_EXTENSIONS);
97 | }
98 |
99 |
100 | /**
101 | * Private constructor to prevent instantiation
102 | */
103 | private PlatformInfos()
104 | {
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/Platforms.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.cl_platform_id;
31 |
32 | import java.util.Arrays;
33 | import java.util.Collections;
34 | import java.util.List;
35 |
36 | import static org.jocl.CL.*;
37 |
38 | /**
39 | * Utility methods related to platforms.
40 | */
41 | public class Platforms
42 | {
43 | /**
44 | * Returns an unmodifiable list of all available platforms
45 | *
46 | * @return The list of all available platforms
47 | */
48 | public static List getPlatforms()
49 | {
50 | int numPlatformsArray[] = new int[1];
51 | clGetPlatformIDs(0, null, numPlatformsArray);
52 | int numPlatforms = numPlatformsArray[0];
53 |
54 | if(numPlatforms > 0)
55 | {
56 | cl_platform_id platforms[] = new cl_platform_id[numPlatforms];
57 | clGetPlatformIDs(platforms.length, platforms, null);
58 | return Arrays.asList(platforms);
59 | }
60 | return Collections.emptyList();
61 | }
62 |
63 |
64 | /**
65 | * Private constructor to prevent instantiation
66 | */
67 | private Platforms()
68 | {
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/org/jocl/utils/ProgramInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * JOCL Utilities
3 | *
4 | * Copyright (c) 2011-2012 Marco Hutter - http://www.jocl.org
5 | *
6 | * Permission is hereby granted, free of charge, to any person
7 | * obtaining a copy of this software and associated documentation
8 | * files (the "Software"), to deal in the Software without
9 | * restriction, including without limitation the rights to use,
10 | * copy, modify, merge, publish, distribute, sublicense, and/or sell
11 | * copies of the Software, and to permit persons to whom the
12 | * Software is furnished to do so, subject to the following
13 | * conditions:
14 | *
15 | * The above copyright notice and this permission notice shall be
16 | * included in all copies or substantial portions of the Software.
17 | *
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 | * OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | package org.jocl.utils;
29 |
30 | import org.jocl.Pointer;
31 | import org.jocl.cl_context;
32 | import org.jocl.cl_device_id;
33 | import org.jocl.cl_program;
34 |
35 | import static org.jocl.CL.*;
36 |
37 | /**
38 | * Utility methods for obtaining information about cl_program objects
39 | */
40 | public class ProgramInfos
41 | {
42 | /**
43 | * The reference count. Only intended for identifying memory leaks.
44 | *
45 | * @param program The program
46 | *
47 | * @return The value
48 | */
49 | public static int getReferenceCount(cl_program program)
50 | {
51 | return Infos.getInt(Infos.FOR_PROGRAM, program,
52 | CL_PROGRAM_REFERENCE_COUNT);
53 | }
54 |
55 | /**
56 | * The context of the program.
57 | *
58 | * @param program The program
59 | *
60 | * @return The value
61 | */
62 | public static cl_context getContext(cl_program program)
63 | {
64 | cl_context result = new cl_context();
65 | Infos.getPointer(Infos.FOR_PROGRAM, program,
66 | CL_PROGRAM_CONTEXT, result);
67 | if(result.equals(new cl_context()))
68 | {
69 | return null;
70 | }
71 | return result;
72 | }
73 |
74 | /**
75 | * The number of devices associated with the program.
76 | *
77 | * @param program The program
78 | *
79 | * @return The value
80 | */
81 | public static int getNumDevices(cl_program program)
82 | {
83 | return Infos.getInt(Infos.FOR_PROGRAM, program,
84 | CL_PROGRAM_NUM_DEVICES);
85 | }
86 |
87 | /**
88 | * The devices associated with the program.
89 | *
90 | * @param program The program
91 | *
92 | * @return The value
93 | */
94 | public static cl_device_id[] getDevices(cl_program program)
95 | {
96 | int numDevices = getNumDevices(program);
97 | cl_device_id devices[] = new cl_device_id[numDevices];
98 | Infos.getPointers(Infos.FOR_PROGRAM, program,
99 | CL_PROGRAM_DEVICES, devices);
100 | cl_device_id nullDevice = new cl_device_id();
101 | for(int i = 0; i < numDevices; i++)
102 | {
103 | if(devices[i].equals(nullDevice))
104 | {
105 | devices[i] = null;
106 | }
107 | }
108 | return devices;
109 | }
110 |
111 | /**
112 | * The program source code
113 | *
114 | * @param program The program
115 | *
116 | * @return The value
117 | */
118 | public static String getSource(cl_program program)
119 | {
120 | return Infos.getString(Infos.FOR_PROGRAM, program,
121 | CL_PROGRAM_SOURCE);
122 | }
123 |
124 |
125 | /**
126 | * The sizes of the program binaries for each device.
127 | *
128 | * @param program The program
129 | *
130 | * @return The value
131 | */
132 | public static long[] getBinarySizes(cl_program program)
133 | {
134 | int numBinaries = getNumDevices(program);
135 | return Infos.getSizes(Infos.FOR_PROGRAM, program,
136 | CL_PROGRAM_BINARY_SIZES, numBinaries);
137 | }
138 |
139 | /**
140 | * The sizes of the program binaries for each device.
141 | *
142 | * @param program The program
143 | *
144 | * @return The value
145 | */
146 | public static String[] getBinaries(cl_program program)
147 | {
148 | int numBinaries = getNumDevices(program);
149 | long sizes[] = getBinarySizes(program);
150 | byte dataArrays[][] = new byte[numBinaries][];
151 | Pointer dataPointers[] = new Pointer[numBinaries];
152 | for(int i = 0; i < numBinaries; i++)
153 | {
154 | dataArrays[i] = new byte[(int) sizes[i]];
155 | dataPointers[i] = Pointer.to(dataArrays[i]);
156 | }
157 | Infos.getPointers(Infos.FOR_PROGRAM, program,
158 | CL_PROGRAM_BINARIES, dataPointers);
159 | String dataStrings[] = new String[numBinaries];
160 | for(int i = 0; i < numBinaries; i++)
161 | {
162 | dataStrings[i] = new String(dataArrays[i], 0, (int) sizes[i] - 1);
163 | }
164 | return dataStrings;
165 | }
166 |
167 |
168 | /**
169 | * Private constructor to prevent instantiation
170 | */
171 | private ProgramInfos()
172 | {
173 |
174 | }
175 |
176 | }
177 |
--------------------------------------------------------------------------------
/src/main/java/pocminer/generate/MiningPlot.java:
--------------------------------------------------------------------------------
1 | package pocminer.generate;
2 |
3 | import fr.cryptohash.Shabal256;
4 |
5 | import java.nio.ByteBuffer;
6 | import java.util.Arrays;
7 |
8 | public class MiningPlot
9 | {
10 | public static int HASH_SIZE = 32;
11 | public static int HASHES_PER_SCOOP = 2;
12 | public static int SCOOP_SIZE = HASHES_PER_SCOOP * HASH_SIZE;
13 | public static int SCOOPS_PER_PLOT = 4096; // original 1MB/plot = 16384
14 | public static int PLOT_SIZE = SCOOPS_PER_PLOT * SCOOP_SIZE;
15 |
16 | public static int HASH_CAP = 4096;
17 |
18 | public byte[] data = new byte[PLOT_SIZE];
19 |
20 | public MiningPlot(long addr, long nonce)
21 | {
22 | ByteBuffer base_buffer = ByteBuffer.allocate(16);
23 | base_buffer.putLong(addr);
24 | base_buffer.putLong(nonce);
25 | byte[] base = base_buffer.array();
26 | Shabal256 md = new Shabal256();
27 | byte[] gendata = new byte[PLOT_SIZE + base.length];
28 | System.arraycopy(base, 0, gendata, PLOT_SIZE, base.length);
29 | for(int i = PLOT_SIZE; i > 0; i -= HASH_SIZE)
30 | {
31 | md.reset();
32 | int len = PLOT_SIZE + base.length - i;
33 | if(len > HASH_CAP)
34 | {
35 | len = HASH_CAP;
36 | }
37 | md.update(gendata, i, len);
38 | md.digest(gendata, i - HASH_SIZE, HASH_SIZE);
39 | }
40 | md.reset();
41 | md.update(gendata);
42 | byte[] finalhash = md.digest();
43 | for(int i = 0; i < PLOT_SIZE; i++)
44 | {
45 | data[i] = (byte) (gendata[i] ^ finalhash[i % HASH_SIZE]);
46 | }
47 | }
48 |
49 | public byte[] getScoop(int pos)
50 | {
51 | return Arrays.copyOfRange(data, pos * SCOOP_SIZE, (pos + 1) * SCOOP_SIZE);
52 | }
53 |
54 | public void hashScoop(Shabal256 md, int pos)
55 | {
56 | md.update(data, pos * SCOOP_SIZE, SCOOP_SIZE);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | logging.level.org.eclipse.jetty.util.log=WARN
2 | logging.level.org.springframework=WARN
3 | spring.jmx.enabled=false
--------------------------------------------------------------------------------