Skip to content

Commit

Permalink
Merge pull request #224 from Holt666/develop
Browse files Browse the repository at this point in the history
redefine XDAG amount unit
  • Loading branch information
LucasMLK committed May 12, 2023
2 parents 45db7d7 + 87085a1 commit dc31f4a
Show file tree
Hide file tree
Showing 40 changed files with 849 additions and 452 deletions.
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,6 @@
<version>1.5.0</version>
</dependency>

<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.4.2</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/xdag/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import io.xdag.core.Block;
import io.xdag.core.BlockWrapper;
import io.xdag.core.SimpleEncoder;
import io.xdag.core.XAmount;
import io.xdag.crypto.Aes;
import io.xdag.crypto.Bip32ECKeyPair;
import io.xdag.crypto.Keys;
Expand Down Expand Up @@ -72,7 +73,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt64;
import org.bouncycastle.crypto.generators.BCrypt;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.hyperledger.besu.crypto.KeyPair;
Expand Down Expand Up @@ -503,7 +503,7 @@ public List<BlockWrapper> createTransactionBlock(Map<Address, KeyPair> ourKeys,

// base count a block <header + send address + defKey signature>
int base = 1 + 1 + 2 + hasRemark;
UInt64 amount = UInt64.ZERO;
XAmount amount = XAmount.ZERO;

while (stack.size() > 0) {
Map.Entry<Address, KeyPair> key = stack.peek();
Expand All @@ -527,7 +527,7 @@ public List<BlockWrapper> createTransactionBlock(Map<Address, KeyPair> ourKeys,
keysPerBlock = new HashSet<>();
keysPerBlock.add(getDefKey());
base = 1 + 1 + 2 + hasRemark;
amount = UInt64.ZERO;
amount = XAmount.ZERO;
}
}
if (keys.size() != 0) {
Expand All @@ -537,7 +537,7 @@ public List<BlockWrapper> createTransactionBlock(Map<Address, KeyPair> ourKeys,
return res;
}

private BlockWrapper createTransaction(Bytes32 to, UInt64 amount, Map<Address, KeyPair> keys, String remark) {
private BlockWrapper createTransaction(Bytes32 to, XAmount amount, Map<Address, KeyPair> keys, String remark) {

List<Address> tos = Lists.newArrayList(new Address(to, XDAG_FIELD_OUTPUT, amount,true));

Expand Down
163 changes: 83 additions & 80 deletions src/main/java/io/xdag/cli/Commands.java

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/main/java/io/xdag/config/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.xdag.config.spec.RandomxSpec;
import io.xdag.config.spec.SnapshotSpec;
import io.xdag.config.spec.WalletSpec;
import io.xdag.core.XAmount;
import io.xdag.core.XdagField;
import io.xdag.crypto.DnetKeys;
import io.xdag.rpc.modules.ModuleDescription;
Expand Down Expand Up @@ -131,9 +132,9 @@ public class AbstractConfig implements Config, AdminSpec, PoolSpec, NodeSpec, Wa
// =========================
protected long xdagEra;
protected XdagField.FieldType xdagFieldHeader;
protected long mainStartAmount;
protected XAmount mainStartAmount;
protected long apolloForkHeight;
protected long apolloForkAmount;
protected XAmount apolloForkAmount;


// =========================
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/io/xdag/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.xdag.config.spec.RandomxSpec;
import io.xdag.config.spec.SnapshotSpec;
import io.xdag.config.spec.WalletSpec;
import io.xdag.core.XAmount;
import io.xdag.core.XdagField;

/**
Expand Down Expand Up @@ -68,13 +69,13 @@ public interface Config {
*/
WalletSpec getWalletSpec();

long getMainStartAmount();
XAmount getMainStartAmount();

long getXdagEra();

long getApolloForkHeight();

long getApolloForkAmount();
XAmount getApolloForkAmount();

XdagField.FieldType getXdagFieldHeader();

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xdag/config/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

package io.xdag.config;

import com.google.common.primitives.UnsignedLong;
import org.apache.tuweni.units.bigints.UInt64;

public class Constants {

Expand Down Expand Up @@ -62,7 +62,7 @@ public class Constants {
public static final Long SEND_PERIOD = 10L;
public static final int DNET_PKT_XDAG = 0x8B;

public static final long REQUEST_BLOCKS_MAX_TIME = UnsignedLong.fromLongBits(1L << 20).longValue();
public static final long REQUEST_BLOCKS_MAX_TIME = UInt64.valueOf(1L << 20).toLong();
public static final long REQUEST_WAIT = 64;
public static final long MAX_ALLOWED_EXTRA = 65536;
/**
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/io/xdag/config/DevnetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST;

import com.google.common.primitives.UnsignedLong;
import org.apache.commons.lang3.StringUtils;
import org.apache.tuweni.units.bigints.UInt64;

import io.xdag.core.XAmount;

public class DevnetConfig extends AbstractConfig {

Expand All @@ -38,10 +40,10 @@ public DevnetConfig() {
this.waitEpoch = 1;

this.xdagEra = 0x16900000000L;
this.mainStartAmount = UnsignedLong.fromLongBits(1L << 42).longValue();
this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong());

this.apolloForkHeight = 1000;
this.apolloForkAmount = UnsignedLong.fromLongBits(1L << 39).longValue();
this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong());
this.xdagFieldHeader = XDAG_FIELD_HEAD_TEST;

this.dnetKeyFile = this.rootDir + "/dnet_keys.bin";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/xdag/config/MainnetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD;

import com.google.common.primitives.UnsignedLong;
import org.apache.tuweni.units.bigints.UInt64;
import io.xdag.core.XAmount;

public class MainnetConfig extends AbstractConfig {

Expand All @@ -35,10 +36,10 @@ public MainnetConfig() {
this.whitelistUrl = "https://raw.githubusercontent.com/XDagger/xdag/master/client/netdb-white.txt";

this.xdagEra = 0x16940000000L;
this.mainStartAmount = UnsignedLong.fromLongBits(1L << 42).longValue();
this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong());

this.apolloForkHeight = 1017323;
this.apolloForkAmount = UnsignedLong.fromLongBits(1L << 39).longValue();
this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong());
this.xdagFieldHeader = XDAG_FIELD_HEAD;

this.dnetKeyFile = this.rootDir + "/dnet_keys.bin";
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/io/xdag/config/TestnetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_HEAD_TEST;

import com.google.common.primitives.UnsignedLong;
import org.apache.tuweni.units.bigints.UInt64;
import io.xdag.core.XAmount;

public class TestnetConfig extends AbstractConfig {

Expand All @@ -38,10 +39,10 @@ public TestnetConfig() {
this.waitEpoch = 1;

this.xdagEra = 0x16900000000L;
this.mainStartAmount = UnsignedLong.fromLongBits(1L << 42).longValue();
this.mainStartAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 42).toLong());

this.apolloForkHeight = 196250;
this.apolloForkAmount = UnsignedLong.fromLongBits(1L << 39).longValue();
this.apolloForkAmount = XAmount.ofXAmount(UInt64.valueOf(1L << 39).toLong());
this.xdagFieldHeader = XDAG_FIELD_HEAD_TEST;

this.dnetKeyFile = this.rootDir + "/dnet_keys.bin";
Expand Down
16 changes: 9 additions & 7 deletions src/main/java/io/xdag/core/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Address {
/**
* 转账金额(输入or输出)
*/
protected UInt64 amount = UInt64.ZERO;
protected XAmount amount = XAmount.ZERO;
/**
* 地址hash低192bit
*/
Expand Down Expand Up @@ -81,7 +81,7 @@ public Address(Bytes32 hashLow,boolean isAddress) {
}else {
this.addressHash.set(8,hashLow.mutableCopy().slice(8,20));
}
this.amount = UInt64.ZERO;
this.amount = XAmount.ZERO;
parsed = true;
}

Expand All @@ -91,7 +91,7 @@ public Address(Bytes32 hashLow,boolean isAddress) {
public Address(Block block) {
this.isAddress = false;
this.addressHash = block.getHashLow().mutableCopy();
this.amount = UInt64.ZERO;
this.amount = XAmount.ZERO;
parsed = true;
}

Expand All @@ -108,7 +108,7 @@ public Address(Bytes32 blockHashlow, XdagField.FieldType type, Boolean isAddress
}


public Address(Bytes32 hash, XdagField.FieldType type, UInt64 amount, Boolean isAddress) {
public Address(Bytes32 hash, XdagField.FieldType type, XAmount amount, Boolean isAddress) {
this.isAddress = isAddress;
this.type = type;
if(!isAddress){
Expand All @@ -130,7 +130,8 @@ public Bytes getData() {
}else {
this.data.set(8, this.addressHash.slice(8,20));
}
this.data.set(0, Bytes.wrap(BytesUtils.bigIntegerToBytes(amount,8)));
UInt64 u64v = amount.toXAmount();
this.data.set(0, Bytes.wrap(BytesUtils.bigIntegerToBytes(u64v,8)));
}
return this.data;
}
Expand All @@ -144,12 +145,13 @@ public void parse() {
this.addressHash = MutableBytes32.create();
this.addressHash.set(8,this.data.slice(8,20));
}
this.amount = UInt64.fromBytes(this.data.slice(0, 8));
UInt64 u64v = UInt64.fromBytes(this.data.slice(0, 8));
this.amount = XAmount.ofXAmount(u64v.toLong());
this.parsed = true;
}
}

public UInt64 getAmount() {
public XAmount getAmount() {
parse();
return this.amount;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/xdag/core/BlockInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@

package io.xdag.core;

import static io.xdag.utils.BasicUtils.amount2xdag;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import org.apache.tuweni.units.bigints.UInt64;

@Getter
@Setter
Expand All @@ -47,7 +45,7 @@ public class BlockInfo {
private byte[] remark;
private byte[] hash;
private byte[] hashlow;
private UInt64 amount = UInt64.ZERO;
private XAmount amount = XAmount.ZERO;
private long timestamp;

// snapshot
Expand All @@ -60,7 +58,7 @@ public String toString() {
"height=" + height +
", hash=" + Arrays.toString(hash) +
", hashlow=" + Arrays.toString(hashlow) +
", amount=" + amount2xdag(amount) +
", amount=" + amount.toString() +
", type=" + type +
", difficulty=" + difficulty +
", ref=" + Arrays.toString(ref) +
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/xdag/core/Blockchain.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ public interface Blockchain {

XdagTopStatus getXdagTopStatus();

long getReward(long nmain);
XAmount getReward(long nmain);

long getSupply(long nmain);
XAmount getSupply(long nmain);

List<Block> getBlocksByTime(long starttime, long endtime);

Expand Down
Loading

0 comments on commit dc31f4a

Please sign in to comment.