diff --git a/pom.xml b/pom.xml
index e1849b9b..7951b033 100644
--- a/pom.xml
+++ b/pom.xml
@@ -393,7 +393,7 @@
io.xdag
xdagj-native-randomx
- 0.1.6
+ 0.1.7
diff --git a/src/main/java/io/xdag/Wallet.java b/src/main/java/io/xdag/Wallet.java
index 812621d3..1c1fed2e 100644
--- a/src/main/java/io/xdag/Wallet.java
+++ b/src/main/java/io/xdag/Wallet.java
@@ -34,13 +34,12 @@
import io.xdag.core.Address;
import io.xdag.core.Block;
import io.xdag.core.BlockWrapper;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.core.XAmount;
import io.xdag.crypto.Aes;
import io.xdag.crypto.Bip32ECKeyPair;
import io.xdag.crypto.Keys;
import io.xdag.crypto.MnemonicUtils;
-import io.xdag.crypto.SecureRandomUtils;
import io.xdag.crypto.Sign;
import io.xdag.utils.Numeric;
import io.xdag.utils.SimpleDecoder;
@@ -77,6 +76,7 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPrivateKey;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
@Slf4j
@Getter
@@ -222,7 +222,7 @@ protected void writeAccounts(byte[] key, SimpleEncoder enc) {
synchronized (accounts) {
enc.writeInt(accounts.size());
for (KeyPair keyPair : accounts.values()) {
- byte[] iv = SecureRandomUtils.secureRandom().generateSeed(16);
+ byte[] iv = SecureRandomProvider.publicSecureRandom().generateSeed(16);
enc.writeBytes(iv);
enc.writeBytes(Aes.encrypt(keyPair.getPrivateKey().getEncoded(), key, iv));
@@ -251,7 +251,7 @@ protected void writeHdSeed(byte[] key, SimpleEncoder enc) {
e.writeString(mnemonicPhrase);
e.writeInt(nextAccountIndex);
- byte[] iv = SecureRandomUtils.secureRandom().generateSeed(16);
+ byte[] iv = SecureRandomProvider.publicSecureRandom().generateSeed(16);
byte[] hdSeedRaw = e.toBytes();
byte[] hdSeedEncrypted = Aes.encrypt(hdSeedRaw, key, iv);
@@ -325,7 +325,7 @@ public boolean flush() {
SimpleEncoder enc = new SimpleEncoder();
enc.writeInt(VERSION);
- byte[] salt = SecureRandomUtils.secureRandom().generateSeed(SALT_LENGTH);
+ byte[] salt = SecureRandomProvider.publicSecureRandom().generateSeed(SALT_LENGTH);
enc.writeBytes(salt);
byte[] key = BCrypt.generate(password.getBytes(UTF_8), salt, BCRYPT_COST);
diff --git a/src/main/java/io/xdag/cli/XdagCli.java b/src/main/java/io/xdag/cli/XdagCli.java
index 2a434232..6e9f643f 100644
--- a/src/main/java/io/xdag/cli/XdagCli.java
+++ b/src/main/java/io/xdag/cli/XdagCli.java
@@ -33,7 +33,6 @@
import io.xdag.config.Constants;
import io.xdag.crypto.Keys;
import io.xdag.crypto.MnemonicUtils;
-import io.xdag.crypto.SecureRandomUtils;
import io.xdag.crypto.Sign;
import io.xdag.db.SnapshotStore;
import io.xdag.db.rocksdb.DatabaseName;
@@ -57,6 +56,7 @@
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPrivateKey;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import com.google.common.collect.Lists;
@@ -467,7 +467,7 @@ public boolean initializedHdSeed(Wallet wallet, PrintStream printer) {
// HD Mnemonic
printer.println("HdWallet Initializing...");
byte[] initialEntropy = new byte[16];
- SecureRandomUtils.secureRandom().nextBytes(initialEntropy);
+ SecureRandomProvider.publicSecureRandom().nextBytes(initialEntropy);
String phrase = MnemonicUtils.generateMnemonic(initialEntropy);
printer.println("HdWallet Mnemonic:" + phrase);
diff --git a/src/main/java/io/xdag/core/Address.java b/src/main/java/io/xdag/core/Address.java
index 07eba7d6..13fb3d19 100644
--- a/src/main/java/io/xdag/core/Address.java
+++ b/src/main/java/io/xdag/core/Address.java
@@ -65,10 +65,6 @@ public Address(XdagField field, Boolean isAddress) {
parse();
}
- public Address(XdagField field) {
-
- }
-
/**
* 只用于ref 跟 maxdifflink
*/
@@ -121,7 +117,6 @@ public Address(Bytes32 hash, XdagField.FieldType type, XAmount amount, Boolean i
parsed = true;
}
-
public Bytes getData() {
if (this.data == null) {
this.data = MutableBytes32.create();
diff --git a/src/main/java/io/xdag/core/Block.java b/src/main/java/io/xdag/core/Block.java
index fbbb2182..3aacbb72 100644
--- a/src/main/java/io/xdag/core/Block.java
+++ b/src/main/java/io/xdag/core/Block.java
@@ -48,6 +48,8 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
+
+import io.xdag.utils.SimpleEncoder;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
@@ -80,20 +82,25 @@ public class Block implements Cloneable {
/**
* 区块的links 列表 输入输出*
*/
+ @Getter
private List
inputs = new CopyOnWriteArrayList<>();
/**
* ouput包含pretop
*/
+ @Getter
private List outputs = new CopyOnWriteArrayList<>();
/**
* 记录公钥 前缀+压缩公钥*
*/
+ @Getter
private List pubKeys = new CopyOnWriteArrayList<>();
+ @Getter
private Map insigs = new LinkedHashMap<>();
private SECPSignature outsig;
/**
* 主块的nonce记录矿工地址跟nonce*
*/
+ @Getter
private Bytes32 nonce;
private XdagBlock xdagBlock;
private boolean parsed;
@@ -468,30 +475,10 @@ public MutableBytes32 getHashLow() {
return MutableBytes32.wrap(info.getHashlow());
}
- public List getOutputs() {
- return outputs;
- }
-
- public List getInputs() {
- return inputs;
- }
-
- public List getPubKeys() {
- return pubKeys;
- }
-
- public Bytes32 getNonce() {
- return nonce;
- }
-
public SECPSignature getOutsig() {
return outsig == null ? null : outsig;
}
- public Map getInsigs() {
- return insigs;
- }
-
@Override
public String toString() {
return String.format("Block info:[Hash:{%s}][Time:{%s}]", getHashLow().toHexString(),
diff --git a/src/main/java/io/xdag/core/BlockState.java b/src/main/java/io/xdag/core/BlockState.java
index 3d1cf9ac..c59899db 100644
--- a/src/main/java/io/xdag/core/BlockState.java
+++ b/src/main/java/io/xdag/core/BlockState.java
@@ -23,6 +23,9 @@
*/
package io.xdag.core;
+import lombok.Getter;
+
+@Getter
public enum BlockState {
MAIN(0, "Main"),
REJECTED(1, "Rejected"),
@@ -37,11 +40,4 @@ public enum BlockState {
this.desc = desc;
}
- public int getCode() {
- return this.code;
- }
-
- public String getDesc() {
- return this.desc;
- }
}
diff --git a/src/main/java/io/xdag/core/BlockType.java b/src/main/java/io/xdag/core/BlockType.java
index c9cb14b3..ada0b626 100644
--- a/src/main/java/io/xdag/core/BlockType.java
+++ b/src/main/java/io/xdag/core/BlockType.java
@@ -23,6 +23,9 @@
*/
package io.xdag.core;
+import lombok.Getter;
+
+@Getter
public enum BlockType {
MAIN_BLOCK(0, "Main"),
WALLET(1, "Wallet"),
@@ -37,11 +40,4 @@ public enum BlockType {
this.desc = desc;
}
- public int getCode() {
- return this.code;
- }
-
- public String getDesc() {
- return this.desc;
- }
}
diff --git a/src/main/java/io/xdag/core/BlockWrapper.java b/src/main/java/io/xdag/core/BlockWrapper.java
index 1ce5783e..58f783db 100644
--- a/src/main/java/io/xdag/core/BlockWrapper.java
+++ b/src/main/java/io/xdag/core/BlockWrapper.java
@@ -25,7 +25,6 @@
package io.xdag.core;
import io.xdag.net.Peer;
-import io.xdag.net.node.Node;
import lombok.Getter;
import lombok.Setter;
diff --git a/src/main/java/io/xdag/core/Blockchain.java b/src/main/java/io/xdag/core/Blockchain.java
index f017430b..0d727fec 100644
--- a/src/main/java/io/xdag/core/Blockchain.java
+++ b/src/main/java/io/xdag/core/Blockchain.java
@@ -24,13 +24,14 @@
package io.xdag.core;
-import io.xdag.listener.Listener;
import java.util.List;
import java.util.Map;
-import org.apache.tuweni.bytes.Bytes;
+
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.crypto.KeyPair;
+import io.xdag.listener.Listener;
+
public interface Blockchain {
// for snapshot pre-seed
@@ -52,8 +53,6 @@ public interface Blockchain {
List listMinedBlocks(int count);
- Map getMemOurBlocks();
-
XdagStats getXdagStats();
XdagTopStatus getXdagTopStatus();
diff --git a/src/main/java/io/xdag/core/BlockchainImpl.java b/src/main/java/io/xdag/core/BlockchainImpl.java
index 8aa956f0..ef20a0cd 100644
--- a/src/main/java/io/xdag/core/BlockchainImpl.java
+++ b/src/main/java/io/xdag/core/BlockchainImpl.java
@@ -677,7 +677,7 @@ private XAmount applyBlock(Block block) {
updateBlockFlag(block, BI_MAIN_REF, true);
List links = block.getLinks();
- if (links == null || links.size() == 0) {
+ if (links == null || links.isEmpty()) {
updateBlockFlag(block, BI_APPLIED, true);
return XAmount.ZERO;
}
@@ -1096,7 +1096,7 @@ public BigInteger calculateBlockDiff(Block block, BigInteger cuDiff) {
// 临时区块
Block tmpBlock;
- if (block.getLinks().size() == 0) {
+ if (block.getLinks().isEmpty()) {
return cuDiff;
}
@@ -1323,7 +1323,7 @@ public XdagStats getXdagStats() {
public boolean canUseInput(Block block) {
List keys = block.verifiedKeys();
List inputs = block.getInputs();
- if (inputs == null || inputs.size() == 0) {
+ if (inputs == null || inputs.isEmpty()) {
return true;
}
/*
@@ -1729,10 +1729,6 @@ public List listMinedBlocks(int count) {
return res;
}
- public Map getMemOurBlocks() {
- return memOurBlocks;
- }
-
enum OrphanRemoveActions {
ORPHAN_REMOVE_NORMAL, ORPHAN_REMOVE_REUSE, ORPHAN_REMOVE_EXTRA
}
diff --git a/src/main/java/io/xdag/core/ImportResult.java b/src/main/java/io/xdag/core/ImportResult.java
index c4b667ed..3f816be8 100644
--- a/src/main/java/io/xdag/core/ImportResult.java
+++ b/src/main/java/io/xdag/core/ImportResult.java
@@ -26,6 +26,8 @@
import org.apache.tuweni.bytes.MutableBytes32;
+import lombok.Getter;
+
public enum ImportResult {
ERROR,
EXIST,
@@ -39,6 +41,7 @@ public enum ImportResult {
MutableBytes32 hashLow;
+ @Getter
String errorInfo;
public MutableBytes32 getHashlow() {
@@ -49,15 +52,8 @@ public void setHashlow(MutableBytes32 hashLow) {
this.hashLow = hashLow;
}
- public String getErrorInfo() {
- return errorInfo;
- }
-
public void setErrorInfo(String errorInfo) {
this.errorInfo = errorInfo;
}
- public boolean isNormal() {
- return this == IMPORTED_NOT_BEST || this == IMPORTED_BEST || this == EXIST || this == IMPORTED_EXTRA || this == IN_MEM;
- }
}
diff --git a/src/main/java/io/xdag/core/SnapshotInfo.java b/src/main/java/io/xdag/core/SnapshotInfo.java
index f72a5a2a..b2197df3 100644
--- a/src/main/java/io/xdag/core/SnapshotInfo.java
+++ b/src/main/java/io/xdag/core/SnapshotInfo.java
@@ -24,9 +24,12 @@
package io.xdag.core;
import java.util.Arrays;
-import lombok.Data;
-@Data
+import lombok.Getter;
+import lombok.Setter;
+
+@Getter
+@Setter
public class SnapshotInfo {
protected boolean type; // true PUBKEY false BLOCK_DATA
diff --git a/src/main/java/io/xdag/core/SnapshotUnit.java b/src/main/java/io/xdag/core/SnapshotUnit.java
deleted file mode 100644
index c9d154e1..00000000
--- a/src/main/java/io/xdag/core/SnapshotUnit.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020-2030 The XdagJ Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package io.xdag.core;
-
-import static io.xdag.utils.BasicUtils.hash2Address;
-
-import java.math.BigInteger;
-import lombok.Data;
-import lombok.extern.slf4j.Slf4j;
-import org.apache.tuweni.bytes.Bytes;
-import org.apache.tuweni.bytes.Bytes32;
-import org.apache.tuweni.units.bigints.UInt64;
-
-@Data
-@Slf4j
-public class SnapshotUnit {
-
- protected byte[] pubkey;
- protected SnapshotBalanceData balanceData;
- // data means block data
- protected byte[] data;
- protected boolean hasPubkey = false;
- protected int type;
- protected int keyIndex = -1;
- protected byte[] hash;
-
- public SnapshotUnit() {
-
- }
-
- public SnapshotUnit(byte[] pubkey, SnapshotBalanceData balanceData, byte[] data, byte[] hash) {
- if (pubkey == null && data != null) {
- this.type = 0; //BI_DATA_BALANCE;
- } else if (pubkey != null && balanceData != null) {
- this.type = 1; //Type.BI_PUBKEY_BALANCE;
- } else {
- this.type = 2; //Type.BI_PUBKEY;
- }
- this.pubkey = pubkey;
- this.balanceData = balanceData;
- this.data = data;
- this.hash = hash;
- }
-
- public SnapshotUnit(byte[] pubkey, SnapshotBalanceData balanceData, byte[] data, byte[] hash, int keyIndex) {
- if (pubkey == null && data != null) {
- this.type = 0; //BI_DATA_BALANCE;
- } else if (pubkey != null && balanceData != null) {
- this.type = 1; //Type.BI_PUBKEY_BALANCE;
- } else {
- this.type = 2; //Type.BI_PUBKEY;
- }
- this.pubkey = pubkey;
- this.balanceData = balanceData;
- this.data = data;
- this.hash = hash;
- this.keyIndex = keyIndex;
- }
-
- public static BlockInfo trasferToBlockInfo(SnapshotUnit snapshotUnit) {
- BlockInfo blockInfo = new BlockInfo();
- blockInfo.setDifficulty(BigInteger.ZERO);
- blockInfo.setFlags(snapshotUnit.getBalanceData().flags);
- if (snapshotUnit.type == 2) {
- blockInfo.setAmount(XAmount.ZERO);
- blockInfo.setTimestamp(0);
- } else {
- UInt64 u64v = UInt64.valueOf(snapshotUnit.getBalanceData().getAmount());
- blockInfo.setAmount(XAmount.ofXAmount(u64v.toLong()));
- blockInfo.setTimestamp(snapshotUnit.getBalanceData().getTime());
- }
- blockInfo.setHash(snapshotUnit.getHash());
- byte[] hashLow = new byte[32];
- System.arraycopy(snapshotUnit.getHash(), 8, hashLow, 8, 24);
- blockInfo.setHashlow(hashLow);
- blockInfo.setSnapshot(true);
- if (snapshotUnit.type == 0) {
- blockInfo.setSnapshotInfo(new SnapshotInfo(false, snapshotUnit.getData()));
- } else {
- blockInfo.setSnapshotInfo(new SnapshotInfo(true, snapshotUnit.getPubkey()));
- }
- return blockInfo;
- }
-
- public boolean hasPubkey() {
- return hasPubkey;
- }
-
- public boolean hasData() {
- return data != null;
- }
-
- @Override
- public String toString() {
- return "SnapshotUnit{" +
- "pubkey=" + (pubkey == null ? null : Bytes.wrap(pubkey)) +
- ", balanceData=" + balanceData +
- ", hash=" + hash2Address(Bytes32.wrap(hash)) +
- '}';
- }
-}
diff --git a/src/main/java/io/xdag/core/StatsBlock.java b/src/main/java/io/xdag/core/StatsBlock.java
deleted file mode 100644
index 9e2e8a26..00000000
--- a/src/main/java/io/xdag/core/StatsBlock.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020-2030 The XdagJ Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package io.xdag.core;
-
-import static io.xdag.utils.BasicUtils.hash2Address;
-
-import java.math.BigInteger;
-import java.nio.ByteOrder;
-import lombok.Data;
-import org.apache.tuweni.bytes.Bytes;
-import org.apache.tuweni.bytes.Bytes32;
-import org.bouncycastle.util.Arrays;
-
-@Data
-public class StatsBlock {
-
- protected long height;
- protected long time;
- protected byte[] hash;
- protected BigInteger difficulty;
-
- public StatsBlock() {
-
- }
-
- public StatsBlock(long height, long time, byte[] hash, BigInteger difficulty) {
- this.height = height;
- this.time = time;
- this.hash = Arrays.reverse(hash);
- this.difficulty = difficulty;
- }
-
- public static StatsBlock parse(Bytes key, Bytes value,int offset) {
- long time = value.getLong(8, ByteOrder.LITTLE_ENDIAN);
- Bytes32 hash = Bytes32.wrap(value.slice(16, 32));
- BigInteger diff = value.slice(48, 16).toUnsignedBigInteger(ByteOrder.LITTLE_ENDIAN);
- return new StatsBlock(offset, time, hash.toArray(), diff);
- }
-
-
- @Override
- public String toString() {
- return "StatsBlock{" +
- "height=" + height +
- ", time=" + time +
- ", hash=" + hash2Address(Bytes32.wrap(hash)) +
- ", difficulty=" + difficulty.toString(16) +
- '}';
- }
-}
diff --git a/src/main/java/io/xdag/core/XdagBlock.java b/src/main/java/io/xdag/core/XdagBlock.java
index 7724e741..5f1aee1d 100644
--- a/src/main/java/io/xdag/core/XdagBlock.java
+++ b/src/main/java/io/xdag/core/XdagBlock.java
@@ -30,6 +30,8 @@
import org.apache.tuweni.bytes.MutableBytes;
import org.apache.tuweni.bytes.MutableBytes32;
+import lombok.Getter;
+
public class XdagBlock {
public static final int XDAG_BLOCK_FIELDS = 16;
@@ -39,6 +41,11 @@ public class XdagBlock {
* data 以添加签名
*/
private MutableBytes data;
+ /**
+ * -- GETTER --
+ * 获取区块sums*
+ */
+ @Getter
private long sum;
private XdagField[] fields;
@@ -101,10 +108,4 @@ public MutableBytes getData() {
return data;
}
- /**
- * 获取区块sums*
- */
- public long getSum() {
- return sum;
- }
}
diff --git a/src/main/java/io/xdag/core/XdagStats.java b/src/main/java/io/xdag/core/XdagStats.java
index 12891b89..843c73ca 100644
--- a/src/main/java/io/xdag/core/XdagStats.java
+++ b/src/main/java/io/xdag/core/XdagStats.java
@@ -97,10 +97,6 @@ public void update(XdagStats remoteXdagStats) {
}
}
- public BigInteger getMaxdifficulty() {
- return maxdifficulty;
- }
-
public void updateMaxDiff(BigInteger maxdifficulty) {
if (this.getMaxdifficulty().compareTo(maxdifficulty) < 0) {
this.maxdifficulty = maxdifficulty;
diff --git a/src/main/java/io/xdag/crypto/Base58.java b/src/main/java/io/xdag/crypto/Base58.java
index 83f1c045..a2a4334d 100644
--- a/src/main/java/io/xdag/crypto/Base58.java
+++ b/src/main/java/io/xdag/crypto/Base58.java
@@ -81,7 +81,7 @@ public static String encodeChecked(byte[] payload) {
public static byte[] decode(String input) throws AddressFormatException {
- if (input.length() == 0) {
+ if (input.isEmpty()) {
return new byte[0];
}
// Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits).
diff --git a/src/main/java/io/xdag/crypto/Bip32ECKeyPair.java b/src/main/java/io/xdag/crypto/Bip32ECKeyPair.java
index ba2496b2..1da1c80d 100644
--- a/src/main/java/io/xdag/crypto/Bip32ECKeyPair.java
+++ b/src/main/java/io/xdag/crypto/Bip32ECKeyPair.java
@@ -51,9 +51,13 @@ public class Bip32ECKeyPair {
public static final int HARDENED_BIT = 0x80000000;
private final boolean parentHasPrivate;
+ @Getter
private final int childNumber;
+ @Getter
private final int depth;
+ @Getter
private final byte[] chainCode;
+ @Getter
private final int parentFingerprint;
private final KeyPair keyPair;
@@ -156,22 +160,6 @@ private int getFingerprint() {
return id[3] & 0xFF | (id[2] & 0xFF) << 8 | (id[1] & 0xFF) << 16 | (id[0] & 0xFF) << 24;
}
- public int getDepth() {
- return depth;
- }
-
- public int getParentFingerprint() {
- return parentFingerprint;
- }
-
- public byte[] getChainCode() {
- return chainCode;
- }
-
- public int getChildNumber() {
- return childNumber;
- }
-
private byte[] getIdentifier() {
return sha256hash160(Bytes.wrap(getPublicKeyPoint().getEncoded(true)));
}
diff --git a/src/main/java/io/xdag/crypto/Keys.java b/src/main/java/io/xdag/crypto/Keys.java
index 04e9c290..02bb7f8a 100644
--- a/src/main/java/io/xdag/crypto/Keys.java
+++ b/src/main/java/io/xdag/crypto/Keys.java
@@ -24,8 +24,6 @@
package io.xdag.crypto;
-import static io.xdag.crypto.SecureRandomUtils.secureRandom;
-
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
@@ -37,6 +35,7 @@
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
import org.hyperledger.besu.crypto.SECPPublicKey;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import org.hyperledger.besu.crypto.SignatureAlgorithm;
/**
@@ -48,9 +47,6 @@ public class Keys {
public static final String PROVIDER = BouncyCastleProvider.PROVIDER_NAME;
public static final String CURVE_NAME = "secp256k1";
- public static final int PUBLIC_KEY_SIZE = 64;
- static final int PUBLIC_KEY_LENGTH_IN_HEX = PUBLIC_KEY_SIZE << 1;
-
static {
if (Security.getProvider(PROVIDER) == null) {
Security.addProvider(new BouncyCastleProvider());
@@ -70,7 +66,7 @@ private Keys() {
static KeyPair createSecp256k1KeyPair()
throws NoSuchProviderException, NoSuchAlgorithmException,
InvalidAlgorithmParameterException {
- return createSecp256k1KeyPair(secureRandom());
+ return createSecp256k1KeyPair(SecureRandomProvider.publicSecureRandom());
}
static KeyPair createSecp256k1KeyPair(SecureRandom random)
diff --git a/src/main/java/io/xdag/crypto/MnemonicUtils.java b/src/main/java/io/xdag/crypto/MnemonicUtils.java
index da5bc718..c45bb5e9 100644
--- a/src/main/java/io/xdag/crypto/MnemonicUtils.java
+++ b/src/main/java/io/xdag/crypto/MnemonicUtils.java
@@ -60,7 +60,7 @@ public class MnemonicUtils {
* The mnemonic must encode entropy in a multiple of 32 bits. With more entropy security is
* improved but the sentence length increases. We refer to the initial entropy length as ENT.
* The allowed size of ENT is 128-256 bits.
- *
+ *
*
Mnemonic generation algorithm
*
* Given a randomly generated initial entropy of size ENT, first a checksum is generated by
diff --git a/src/main/java/io/xdag/crypto/RandomX.java b/src/main/java/io/xdag/crypto/RandomX.java
index 417bbb0d..840189cd 100644
--- a/src/main/java/io/xdag/crypto/RandomX.java
+++ b/src/main/java/io/xdag/crypto/RandomX.java
@@ -24,10 +24,28 @@
package io.xdag.crypto;
+import static io.xdag.config.RandomXConstants.RANDOMX_FORK_HEIGHT;
+import static io.xdag.config.RandomXConstants.RANDOMX_TESTNET_FORK_HEIGHT;
+import static io.xdag.config.RandomXConstants.SEEDHASH_EPOCH_BLOCKS;
+import static io.xdag.config.RandomXConstants.SEEDHASH_EPOCH_LAG;
+import static io.xdag.config.RandomXConstants.SEEDHASH_EPOCH_TESTNET_BLOCKS;
+import static io.xdag.config.RandomXConstants.SEEDHASH_EPOCH_TESTNET_LAG;
+import static io.xdag.config.RandomXConstants.XDAG_RANDOMX;
+import static io.xdag.utils.BytesUtils.bytesToPointer;
+import static io.xdag.utils.BytesUtils.equalBytes;
+
+import java.util.concurrent.locks.ReadWriteLock;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
+
+import org.apache.tuweni.bytes.Bytes;
+import org.apache.tuweni.bytes.Bytes32;
+import org.bouncycastle.util.Arrays;
+import org.bouncycastle.util.encoders.Hex;
+
import com.sun.jna.Memory;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
-import com.sun.jna.ptr.PointerByReference;
+
import io.xdag.config.Config;
import io.xdag.config.MainnetConfig;
import io.xdag.core.Block;
@@ -39,17 +57,6 @@
import io.xdag.utils.XdagTime;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
-import org.apache.tuweni.bytes.Bytes;
-import org.apache.tuweni.bytes.Bytes32;
-import org.bouncycastle.util.Arrays;
-import org.bouncycastle.util.encoders.Hex;
-
-import java.util.concurrent.locks.ReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-import static io.xdag.config.RandomXConstants.*;
-import static io.xdag.utils.BytesUtils.bytesToPointer;
-import static io.xdag.utils.BytesUtils.equalBytes;
@Slf4j
@@ -179,7 +186,7 @@ public void init() {
// 矿池初始化dataset
- public void randomXPoolInitDataset(PointerByReference rxCache, PointerByReference rxDataset) {
+ public void randomXPoolInitDataset(Pointer rxCache, Pointer rxDataset) {
RandomXJNA.INSTANCE.randomx_init_dataset(rxDataset, rxCache, new NativeLong(0), RandomXJNA.INSTANCE.randomx_dataset_item_count());
}
@@ -250,7 +257,7 @@ public byte[] randomXBlockHash(byte[] data, int dataSize, long blockTime) {
}
- public PointerByReference randomXUpdateVm(RandomXMemory randomXMemory, boolean isPoolVm) {
+ public Pointer randomXUpdateVm(RandomXMemory randomXMemory, boolean isPoolVm) {
if (isPoolVm) {
randomXMemory.poolVm = RandomXJNA.INSTANCE.randomx_create_vm(flags, randomXMemory.rxCache, randomXMemory.rxDataset);
return randomXMemory.poolVm;
diff --git a/src/main/java/io/xdag/crypto/RandomXMemory.java b/src/main/java/io/xdag/crypto/RandomXMemory.java
index 476bfaf0..8887e9c6 100644
--- a/src/main/java/io/xdag/crypto/RandomXMemory.java
+++ b/src/main/java/io/xdag/crypto/RandomXMemory.java
@@ -24,7 +24,8 @@
package io.xdag.crypto;
-import com.sun.jna.ptr.PointerByReference;
+import com.sun.jna.Pointer;
+
import lombok.Getter;
import lombok.Setter;
@@ -37,10 +38,10 @@ public class RandomXMemory {
protected long seedTime;
protected long switchTime;
protected int isSwitched;
- protected PointerByReference rxCache;
- protected PointerByReference rxDataset;
- protected PointerByReference poolVm;
- protected PointerByReference blockVm;
+ protected Pointer rxCache;
+ protected Pointer rxDataset;
+ protected Pointer poolVm;
+ protected Pointer blockVm;
public RandomXMemory() {
this.switchTime = -1;
diff --git a/src/main/java/io/xdag/crypto/SecureRandomUtils.java b/src/main/java/io/xdag/crypto/SecureRandomUtils.java
deleted file mode 100644
index 03318615..00000000
--- a/src/main/java/io/xdag/crypto/SecureRandomUtils.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020-2030 The XdagJ Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package io.xdag.crypto;
-
-import java.security.SecureRandom;
-
-public class SecureRandomUtils {
-
- private static final SecureRandom SECURE_RANDOM;
- // Taken from BitcoinJ implementation
- // https://github.com/bitcoinj/bitcoinj/blob/3cb1f6c6c589f84fe6e1fb56bf26d94cccc85429/core/src/main/java/org/bitcoinj/core/Utils.java#L573
- private static int isAndroid = -1;
-
- static {
- if (isAndroidRuntime()) {
- new LinuxSecureRandom();
- }
- SECURE_RANDOM = new SecureRandom();
- }
-
- private SecureRandomUtils() {
- }
-
- public static SecureRandom secureRandom() {
- return SECURE_RANDOM;
- }
-
- static boolean isAndroidRuntime() {
- if (isAndroid == -1) {
- final String runtime = System.getProperty("java.runtime.name");
- isAndroid = (runtime != null && runtime.equals("Android Runtime")) ? 1 : 0;
- }
- return isAndroid == 1;
- }
-
-}
diff --git a/src/main/java/io/xdag/crypto/Sign.java b/src/main/java/io/xdag/crypto/Sign.java
index 05dc4532..525766ef 100644
--- a/src/main/java/io/xdag/crypto/Sign.java
+++ b/src/main/java/io/xdag/crypto/Sign.java
@@ -111,17 +111,6 @@ public static BigInteger publicFromPoint(byte[] bits) {
return new BigInteger(1, Arrays.copyOfRange(bits, 1, bits.length)); // remove prefix
}
- /**
- * Verify that the provided precondition holds true.
- *
- * @param assertionResult assertion value
- * @param errorMessage error message if precondition failure
- */
- public static void verifyPrecondition(boolean assertionResult, String errorMessage) {
- if (!assertionResult) {
- throw new RuntimeException(errorMessage);
- }
- }
public static SECPSignature toCanonical(SECPSignature signature) {
if(signature.getS().compareTo(HALF_CURVE_ORDER)>0){
return SECPSignature.create(signature.getR(), CURVE.getN().subtract(signature.getS()), (byte) 0, CURVE.getN());
diff --git a/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java b/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java
index e9ca6c21..e171b744 100644
--- a/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java
+++ b/src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java
@@ -169,33 +169,34 @@ public List listTxHistoryByAddress(String address, int page, Object..
long start = new Date(0).getTime();
long end = System.currentTimeMillis();
switch (parameters.length) {
- case 0: break;
- case 1:
- int pageSize = Integer.parseInt(parameters[0].toString());
- PAGE_SIZE = (pageSize > 0 && pageSize <= TX_PAGE_SIZE_LIMIT ) ? pageSize : PAGE_SIZE;
- break;
- case 2:
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- start = sdf.parse(parameters[0].toString()).getTime();
- end = sdf.parse(parameters[1].toString()).getTime();
- } catch (ParseException e) {
- start = Long.parseLong(parameters[0].toString());
- end = Long.parseLong(parameters[1].toString());
- }
- break;
- case 3:
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- start = sdf.parse(parameters[0].toString()).getTime();
- end = sdf.parse(parameters[1].toString()).getTime();
- } catch (ParseException e) {
- start = Long.parseLong(parameters[0].toString());
- end = Long.parseLong(parameters[1].toString());
- }
- int page_size = Integer.parseInt(parameters[2].toString());
- PAGE_SIZE = (page_size > 0 && page_size <= TX_PAGE_SIZE_LIMIT) ? page_size : PAGE_SIZE;
- break;
+ case 0 -> {
+ }
+ case 1 -> {
+ int pageSize = Integer.parseInt(parameters[0].toString());
+ PAGE_SIZE = (pageSize > 0 && pageSize <= TX_PAGE_SIZE_LIMIT) ? pageSize : PAGE_SIZE;
+ }
+ case 2 -> {
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ start = sdf.parse(parameters[0].toString()).getTime();
+ end = sdf.parse(parameters[1].toString()).getTime();
+ } catch (ParseException e) {
+ start = Long.parseLong(parameters[0].toString());
+ end = Long.parseLong(parameters[1].toString());
+ }
+ }
+ case 3 -> {
+ try {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ start = sdf.parse(parameters[0].toString()).getTime();
+ end = sdf.parse(parameters[1].toString()).getTime();
+ } catch (ParseException e) {
+ start = Long.parseLong(parameters[0].toString());
+ end = Long.parseLong(parameters[1].toString());
+ }
+ int page_size = Integer.parseInt(parameters[2].toString());
+ PAGE_SIZE = (page_size > 0 && page_size <= TX_PAGE_SIZE_LIMIT) ? page_size : PAGE_SIZE;
+ }
}
try {
conn = DruidUtils.getConnection();
diff --git a/src/main/java/io/xdag/db/rocksdb/SnapshotStoreImpl.java b/src/main/java/io/xdag/db/rocksdb/SnapshotStoreImpl.java
index cc946236..1dd1d660 100644
--- a/src/main/java/io/xdag/db/rocksdb/SnapshotStoreImpl.java
+++ b/src/main/java/io/xdag/db/rocksdb/SnapshotStoreImpl.java
@@ -39,6 +39,7 @@
import io.xdag.db.execption.SerializationException;
import io.xdag.utils.BasicUtils;
import io.xdag.utils.BytesUtils;
+import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
@@ -68,9 +69,13 @@ public class SnapshotStoreImpl implements SnapshotStore {
private final RocksdbKVSource snapshotSource;
private final Kryo kryo;
+ @Getter
private XAmount ourBalance = XAmount.ZERO;
+ @Getter
private XAmount allBalance = XAmount.ZERO;
+ @Getter
private long nextTime;
+ @Getter
private long height;
@@ -289,23 +294,6 @@ public void save(RocksIterator iter, BlockInfo blockInfo) {
snapshotSource.put(iter.key(), value);
}
- public XAmount getOurBalance() {
- return this.ourBalance;
- }
-
- public XAmount getAllBalance() {
- return this.allBalance;
- }
-
- public long getNextTime() {
- return nextTime;
- }
-
- public long getHeight() {
- return height;
- }
-
-
public Object deserialize(final byte[] bytes, Class> type) throws DeserializationException {
synchronized (kryo) {
try {
diff --git a/src/main/java/io/xdag/net/XdagP2pHandler.java b/src/main/java/io/xdag/net/XdagP2pHandler.java
index 65bec77b..2530964a 100644
--- a/src/main/java/io/xdag/net/XdagP2pHandler.java
+++ b/src/main/java/io/xdag/net/XdagP2pHandler.java
@@ -38,6 +38,7 @@
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes;
import org.apache.tuweni.bytes.MutableBytes32;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import com.google.common.util.concurrent.SettableFuture;
@@ -52,7 +53,6 @@
import io.xdag.core.BlockWrapper;
import io.xdag.core.Blockchain;
import io.xdag.core.XdagStats;
-import io.xdag.crypto.SecureRandomUtils;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageQueue;
import io.xdag.net.message.ReasonCode;
@@ -112,7 +112,7 @@ public Thread newThread(Runnable r) {
private ScheduledFuture> getNodes = null;
private ScheduledFuture> pingPong = null;
- private byte[] secret = SecureRandomUtils.secureRandom().generateSeed(InitMessage.SECRET_LENGTH);
+ private byte[] secret = SecureRandomProvider.publicSecureRandom().generateSeed(InitMessage.SECRET_LENGTH);
private long timestamp = System.currentTimeMillis();
public XdagP2pHandler(Channel channel, Kernel kernel) {
diff --git a/src/main/java/io/xdag/net/message/consensus/NewBlockMessage.java b/src/main/java/io/xdag/net/message/consensus/NewBlockMessage.java
index f382d0ca..59d5408a 100644
--- a/src/main/java/io/xdag/net/message/consensus/NewBlockMessage.java
+++ b/src/main/java/io/xdag/net/message/consensus/NewBlockMessage.java
@@ -23,17 +23,11 @@
*/
package io.xdag.net.message.consensus;
-import static io.xdag.config.Constants.DNET_PKT_XDAG;
-
-import org.apache.tuweni.bytes.Bytes;
-import org.apache.tuweni.bytes.MutableBytes;
-
import io.xdag.core.Block;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.core.XdagBlock;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
-import io.xdag.utils.BytesUtils;
import io.xdag.utils.SimpleDecoder;
import lombok.Getter;
import lombok.Setter;
diff --git a/src/main/java/io/xdag/net/message/consensus/SumReplyMessage.java b/src/main/java/io/xdag/net/message/consensus/SumReplyMessage.java
index 2ae5ea80..8f93abee 100644
--- a/src/main/java/io/xdag/net/message/consensus/SumReplyMessage.java
+++ b/src/main/java/io/xdag/net/message/consensus/SumReplyMessage.java
@@ -23,17 +23,12 @@
*/
package io.xdag.net.message.consensus;
-import java.math.BigInteger;
-
-import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.core.XdagStats;
import io.xdag.net.NetDB;
import io.xdag.net.message.MessageCode;
-import io.xdag.utils.BytesUtils;
-import io.xdag.utils.Numeric;
import io.xdag.utils.SimpleDecoder;
import lombok.Getter;
import lombok.Setter;
diff --git a/src/main/java/io/xdag/net/message/consensus/SyncBlockMessage.java b/src/main/java/io/xdag/net/message/consensus/SyncBlockMessage.java
index bd75c9e2..589325df 100644
--- a/src/main/java/io/xdag/net/message/consensus/SyncBlockMessage.java
+++ b/src/main/java/io/xdag/net/message/consensus/SyncBlockMessage.java
@@ -23,17 +23,11 @@
*/
package io.xdag.net.message.consensus;
-import static io.xdag.config.Constants.DNET_PKT_XDAG;
-
-import org.apache.tuweni.bytes.Bytes;
-import org.apache.tuweni.bytes.MutableBytes;
-
import io.xdag.core.Block;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.core.XdagBlock;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
-import io.xdag.utils.BytesUtils;
import io.xdag.utils.SimpleDecoder;
import lombok.Getter;
import lombok.Setter;
diff --git a/src/main/java/io/xdag/net/message/consensus/XdagMessage.java b/src/main/java/io/xdag/net/message/consensus/XdagMessage.java
index d783ed12..8c86cacc 100644
--- a/src/main/java/io/xdag/net/message/consensus/XdagMessage.java
+++ b/src/main/java/io/xdag/net/message/consensus/XdagMessage.java
@@ -25,10 +25,9 @@
import java.math.BigInteger;
-import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.core.XdagStats;
import io.xdag.net.NetDB;
import io.xdag.net.message.Message;
diff --git a/src/main/java/io/xdag/net/message/p2p/DisconnectMessage.java b/src/main/java/io/xdag/net/message/p2p/DisconnectMessage.java
index 92357362..790a2390 100644
--- a/src/main/java/io/xdag/net/message/p2p/DisconnectMessage.java
+++ b/src/main/java/io/xdag/net/message/p2p/DisconnectMessage.java
@@ -23,7 +23,7 @@
*/
package io.xdag.net.message.p2p;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
import io.xdag.net.message.ReasonCode;
diff --git a/src/main/java/io/xdag/net/message/p2p/HandshakeMessage.java b/src/main/java/io/xdag/net/message/p2p/HandshakeMessage.java
index 2c6b2ec0..bc437047 100644
--- a/src/main/java/io/xdag/net/message/p2p/HandshakeMessage.java
+++ b/src/main/java/io/xdag/net/message/p2p/HandshakeMessage.java
@@ -36,7 +36,7 @@
import io.xdag.Network;
import io.xdag.config.Config;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.crypto.Hash;
import io.xdag.crypto.Keys;
import io.xdag.crypto.Sign;
diff --git a/src/main/java/io/xdag/net/message/p2p/InitMessage.java b/src/main/java/io/xdag/net/message/p2p/InitMessage.java
index 0ee3d3a7..6b5de649 100644
--- a/src/main/java/io/xdag/net/message/p2p/InitMessage.java
+++ b/src/main/java/io/xdag/net/message/p2p/InitMessage.java
@@ -23,7 +23,7 @@
*/
package io.xdag.net.message.p2p;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
import io.xdag.utils.BytesUtils;
diff --git a/src/main/java/io/xdag/net/message/p2p/PingMessage.java b/src/main/java/io/xdag/net/message/p2p/PingMessage.java
index b9686f58..e24a366d 100644
--- a/src/main/java/io/xdag/net/message/p2p/PingMessage.java
+++ b/src/main/java/io/xdag/net/message/p2p/PingMessage.java
@@ -23,7 +23,7 @@
*/
package io.xdag.net.message.p2p;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
import io.xdag.utils.SimpleDecoder;
diff --git a/src/main/java/io/xdag/net/message/p2p/PongMessage.java b/src/main/java/io/xdag/net/message/p2p/PongMessage.java
index ca87e38f..093a5366 100644
--- a/src/main/java/io/xdag/net/message/p2p/PongMessage.java
+++ b/src/main/java/io/xdag/net/message/p2p/PongMessage.java
@@ -23,7 +23,7 @@
*/
package io.xdag.net.message.p2p;
-import io.xdag.core.SimpleEncoder;
+import io.xdag.utils.SimpleEncoder;
import io.xdag.net.message.Message;
import io.xdag.net.message.MessageCode;
import io.xdag.utils.SimpleDecoder;
diff --git a/src/main/java/io/xdag/core/SimpleEncoder.java b/src/main/java/io/xdag/utils/SimpleEncoder.java
similarity index 99%
rename from src/main/java/io/xdag/core/SimpleEncoder.java
rename to src/main/java/io/xdag/utils/SimpleEncoder.java
index 3fab1e3d..09c2e11d 100644
--- a/src/main/java/io/xdag/core/SimpleEncoder.java
+++ b/src/main/java/io/xdag/utils/SimpleEncoder.java
@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
-package io.xdag.core;
+package io.xdag.utils;
import io.xdag.utils.exception.SimpleCodecException;
import java.io.ByteArrayOutputStream;
diff --git a/src/test/java/io/xdag/crypto/SecureRandomUtilsTest.java b/src/test/java/io/xdag/crypto/SecureRandomUtilsTest.java
deleted file mode 100644
index 4fb87beb..00000000
--- a/src/test/java/io/xdag/crypto/SecureRandomUtilsTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2020-2030 The XdagJ Developers
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-package io.xdag.crypto;
-
-import static io.xdag.crypto.SecureRandomUtils.isAndroidRuntime;
-import static io.xdag.crypto.SecureRandomUtils.secureRandom;
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-
-public class SecureRandomUtilsTest {
-
- @Test
- public void testSecureRandom() {
- secureRandom().nextInt();
- }
-
- @Test
- public void testIsNotAndroidRuntime() {
- assertFalse(isAndroidRuntime());
- }
-}
diff --git a/src/test/java/io/xdag/net/message/p2p/HelloMessageTest.java b/src/test/java/io/xdag/net/message/p2p/HelloMessageTest.java
index c23ad674..ffd96de5 100644
--- a/src/test/java/io/xdag/net/message/p2p/HelloMessageTest.java
+++ b/src/test/java/io/xdag/net/message/p2p/HelloMessageTest.java
@@ -28,13 +28,13 @@
import static org.junit.Assert.assertTrue;
import org.hyperledger.besu.crypto.KeyPair;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import org.junit.Test;
import io.xdag.config.Config;
import io.xdag.config.DevnetConfig;
import io.xdag.crypto.Keys;
import io.xdag.crypto.SampleKeys;
-import io.xdag.crypto.SecureRandomUtils;
import io.xdag.crypto.Sign;
import io.xdag.net.CapabilityTreeSet;
import io.xdag.net.Peer;
@@ -45,11 +45,11 @@ public class HelloMessageTest {
public void testCodec() {
Config config = new DevnetConfig();
- KeyPair key = KeyPair.create(SampleKeys.SRIVATE_KEY, Sign.CURVE, Sign.CURVE_NAME);;
+ KeyPair key = KeyPair.create(SampleKeys.SRIVATE_KEY, Sign.CURVE, Sign.CURVE_NAME);
String peerId = toBase58(Keys.toBytesAddress(key));
HelloMessage msg = new HelloMessage(config.getNodeSpec().getNetwork(), config.getNodeSpec().getNetworkVersion(), peerId, 8001,
config.getClientId(), config.getClientCapabilities().toArray(), 2,
- SecureRandomUtils.secureRandom().generateSeed(InitMessage.SECRET_LENGTH), key);
+ SecureRandomProvider.publicSecureRandom().generateSeed(InitMessage.SECRET_LENGTH), key);
assertTrue(msg.validate(config));
msg = new HelloMessage(msg.getBody());
diff --git a/src/test/java/io/xdag/net/message/p2p/InitMessageTest.java b/src/test/java/io/xdag/net/message/p2p/InitMessageTest.java
index d2392a56..63775d96 100644
--- a/src/test/java/io/xdag/net/message/p2p/InitMessageTest.java
+++ b/src/test/java/io/xdag/net/message/p2p/InitMessageTest.java
@@ -26,15 +26,14 @@
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import org.junit.Test;
-import io.xdag.crypto.SecureRandomUtils;
-
public class InitMessageTest {
@Test
public void testCodec() {
- byte[] secret = SecureRandomUtils.secureRandom().generateSeed(32);
+ byte[] secret = SecureRandomProvider.publicSecureRandom().generateSeed(32);
long timestamp = System.currentTimeMillis();
InitMessage msg = new InitMessage(secret, timestamp);
diff --git a/src/test/java/io/xdag/net/message/p2p/WorldMessageTest.java b/src/test/java/io/xdag/net/message/p2p/WorldMessageTest.java
index 2b986ae9..03189986 100644
--- a/src/test/java/io/xdag/net/message/p2p/WorldMessageTest.java
+++ b/src/test/java/io/xdag/net/message/p2p/WorldMessageTest.java
@@ -28,13 +28,13 @@
import static org.junit.Assert.assertTrue;
import org.hyperledger.besu.crypto.KeyPair;
+import org.hyperledger.besu.crypto.SecureRandomProvider;
import org.junit.Test;
import io.xdag.config.Config;
import io.xdag.config.DevnetConfig;
import io.xdag.crypto.Keys;
import io.xdag.crypto.SampleKeys;
-import io.xdag.crypto.SecureRandomUtils;
import io.xdag.crypto.Sign;
import io.xdag.net.CapabilityTreeSet;
import io.xdag.net.Peer;
@@ -49,7 +49,7 @@ public void testCodec() {
String peerId = toBase58(Keys.toBytesAddress(key));
WorldMessage msg = new WorldMessage(config.getNodeSpec().getNetwork(), config.getNodeSpec().getNetworkVersion(), peerId, 8001,
config.getClientId(), config.getClientCapabilities().toArray(), 2,
- SecureRandomUtils.secureRandom().generateSeed(InitMessage.SECRET_LENGTH), key);
+ SecureRandomProvider.publicSecureRandom().generateSeed(InitMessage.SECRET_LENGTH), key);
assertTrue(msg.validate(config));
msg = new WorldMessage(msg.getBody());
diff --git a/src/test/java/io/xdag/utils/BytesTest.java b/src/test/java/io/xdag/utils/BytesTest.java
index 44a4b52b..38de3a7a 100644
--- a/src/test/java/io/xdag/utils/BytesTest.java
+++ b/src/test/java/io/xdag/utils/BytesTest.java
@@ -25,14 +25,15 @@
import static org.junit.Assert.assertEquals;
-import io.xdag.crypto.Hash;
import java.nio.charset.StandardCharsets;
+
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.bytes.MutableBytes32;
-import org.junit.Assert;
import org.junit.Test;
+import io.xdag.crypto.Hash;
+
public class BytesTest {
@Test