Skip to content

Commit

Permalink
Merge pull request #256 from Junze888/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
LucasMLK authored Aug 4, 2023
2 parents e5c4742 + 75f5f2a commit b135b2f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 47 deletions.
38 changes: 20 additions & 18 deletions docs/XDAGJ_RPC.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion script/mysql_create_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ CREATE TABLE `t_transaction_history` (
`famount` decimal(20,9) unsigned zerofill NOT NULL,
`ftype` tinyint NOT NULL,
`fremark` varchar(64) DEFAULT NULL,
`ftime` datetime NOT NULL,
`ftime` datetime(3) NOT NULL,
PRIMARY KEY (`fid`),
UNIQUE KEY `id_UNIQUE` (`fid`),
KEY `faddress_index` (`faddress`)
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/xdag/cli/Commands.java
Original file line number Diff line number Diff line change
Expand Up @@ -525,18 +525,18 @@ public String printBlockInfo(Block block, boolean raw) {
tx.append(String.format(" input: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
} else if (address.getType().equals(XDAG_FIELD_OUT)) {
tx.append(String.format(" output: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
} else {
tx.append(String.format(" snapshot: %s %s %s%n",
hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
}
}

Expand Down Expand Up @@ -725,28 +725,28 @@ public String address(Bytes32 wrap, int page) {
tx.append(String.format(" input: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
} else if (address.getType().equals(XDAG_FIELD_OUTPUT)) {
tx.append(String.format(" output: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
} else if (address.getType().equals(XDAG_FIELD_COINBASE) && (blockInfo.flags&BI_MAIN) != 0) {
tx.append(String.format(" coinbase: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
} else {
tx.append(String.format(" snapshot: %s %s %s%n", hash2Address(address.getAddress()),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
}
}else {
tx.append(String.format(" snapshot: %s %s %s%n", (toBase58(BytesUtils.byte32ToArray(address.getAddress()))),
address.getAmount().toDecimal(9, XUnit.XDAG).toPlainString(),
FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss.SSS")
.format(XdagTime.xdagTimestampToMs(txHistory.getTimestamp()))));
.format(txHistory.getTimestamp())));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/xdag/config/AbstractConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public class AbstractConfig implements Config, AdminSpec, PoolSpec, NodeSpec, Wa

protected int maxShareCountPerChannel = 20;
protected int awardEpoch = 0xf;
protected int waitEpoch = 10;
protected int waitEpoch = 20;

// =========================
// Node spec
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/io/xdag/db/mysql/TransactionHistoryStoreImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public boolean saveTxHistory(TxHistory txHistory) {
pstmt.setBigDecimal(3, txHistory.getAddress().getAmount().toDecimal(9, XUnit.XDAG));
pstmt.setInt(4, txHistory.getAddress().getType().asByte());
pstmt.setString(5, txHistory.getRemark());
pstmt.setTimestamp(6, new java.sql.Timestamp(txHistory.getTimestamp()));
pstmt.setTimestamp(6, new java.sql.Timestamp(XdagTime.xdagTimestampToMs(txHistory.getTimestamp())));
result = pstmt.executeUpdate() == 1;
}
} catch (Exception e) {
Expand Down Expand Up @@ -110,7 +110,7 @@ public boolean batchSaveTxHistory(TxHistory txHistory) {
pstmtBatch.setBigDecimal(3, address.getAmount().toDecimal(9, XUnit.XDAG));
pstmtBatch.setInt(4, address.getType().asByte());
pstmtBatch.setString(5, txHistory.getRemark());
pstmtBatch.setTimestamp(6, new java.sql.Timestamp(txHistory.getTimestamp()));
pstmtBatch.setTimestamp(6, new java.sql.Timestamp(XdagTime.xdagTimestampToMs(txHistory.getTimestamp())));
pstmtBatch.addBatch();
count++;
}
Expand Down Expand Up @@ -146,16 +146,16 @@ public List<TxHistory> listTxHistoryByAddress(String address, int page, Object..
ResultSet rs = null;
List<TxHistory> txHistoryList = Lists.newArrayList();
int totalcount = 0;
long start = XdagTime.msToXdagtimestamp(new Date(0).getTime());
long end = XdagTime.msToXdagtimestamp(System.currentTimeMillis());
long start = new Date(0).getTime();
long end = System.currentTimeMillis();
if (timeRange.length != 0){
try{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
start =XdagTime.msToXdagtimestamp(sdf.parse(timeRange[0].toString()).getTime());
end = XdagTime.msToXdagtimestamp(sdf.parse(timeRange[1].toString()).getTime());
start =sdf.parse(timeRange[0].toString()).getTime();
end = sdf.parse(timeRange[1].toString()).getTime();
}catch (ParseException e){
start = XdagTime.msToXdagtimestamp(Long.parseLong(timeRange[0].toString()));
end = XdagTime.msToXdagtimestamp(Long.parseLong(timeRange[1].toString()));
start = Long.parseLong(timeRange[0].toString());
end = Long.parseLong(timeRange[1].toString());
}
}
try {
Expand Down
24 changes: 15 additions & 9 deletions src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private BlockResultDTO transferBlockInfoToBlockResultDTO(Block block, int page,
.balance(String.format("%s", block.getInfo().getAmount().toDecimal(9, XUnit.XDAG).toPlainString()))
.type(SNAPSHOT.getDesc())
.blockTime(xdagTimestampToMs(kernel.getConfig().getSnapshotSpec().getSnapshotTime()))
.timeStamp(kernel.getConfig().getSnapshotSpec().getSnapshotTime())
.timeStamp(kernel.getConfig().getSnapshotSpec().getSnapshotTime());
// .flags(Integer.toHexString(block.getInfo().getFlags()))
// .diff(toQuantityJsonHex(block.getInfo().getDifficulty()))
// .remark(block.getInfo().getRemark() == null ? "" : new String(block.getInfo().getRemark(),
Expand All @@ -205,8 +205,10 @@ private BlockResultDTO transferBlockInfoToBlockResultDTO(Block block, int page,
// .type(getType(block))
// .refs(getLinks(block))
// .height(block.getInfo().getHeight())
.transactions(getTxLinks(block, page, timeRange))
if (page != 0){
BlockResultDTOBuilder.transactions(getTxLinks(block, page, timeRange))
.totalPage(totalPage);
}
totalPage = 1;
return BlockResultDTOBuilder.build();
}
Expand All @@ -221,9 +223,11 @@ private BlockResultDTO transferAccountToBlockResultDTO(String address, int page,
.type("Wallet")
.blockTime(xdagTimestampToMs(kernel.getConfig().getSnapshotSpec().getSnapshotTime()))
.timeStamp(kernel.getConfig().getSnapshotSpec().getSnapshotTime())
.state("Accepted")
.transactions(getTxHistory(address, page, timeRange))
.state("Accepted");
if (page != 0){
BlockResultDTOBuilder.transactions(getTxHistory(address, page, timeRange))
.totalPage(totalPage);
}
totalPage = 1;
return BlockResultDTOBuilder.build();
}
Expand All @@ -245,9 +249,11 @@ private BlockResultDTO transferBlockToBlockResultDTO(Block block, int page, Obje
.state(getStateByFlags(block.getInfo().getFlags()))
.type(getType(block))
.refs(getLinks(block))
.height(block.getInfo().getHeight())
.transactions(getTxLinks(block, page, timeRange))
.totalPage(totalPage);
.height(block.getInfo().getHeight());
if (page != 0) {
BlockResultDTOBuilder.transactions(getTxLinks(block, page, timeRange))
.totalPage(totalPage);
}
totalPage = 1;
return BlockResultDTOBuilder.build();
}
Expand Down Expand Up @@ -320,7 +326,7 @@ private List<TxLink> getTxLinks(Block block, int page, Object timeRange) {
.amount(String.format("%s", txHistory.getAddress().getAmount().toDecimal(9, XUnit.XDAG).toPlainString()))
.direction(txHistory.getAddress().getType().equals(XDAG_FIELD_IN) ? 0 :
txHistory.getAddress().getType().equals(XDAG_FIELD_OUT) ? 1 : 3)
.time(xdagTimestampToMs(txHistory.getTimestamp()))
.time(txHistory.getTimestamp())
.remark(txHistory.getRemark());
txLinks.add(txLinkBuilder.build());
}
Expand All @@ -344,7 +350,7 @@ private List<TxLink> getTxHistory(String address, int page, Object... timeRange)
.direction(txHistory.getAddress().getType().equals(XDAG_FIELD_INPUT) ? 0 :
txHistory.getAddress().getType().equals(XDAG_FIELD_OUTPUT) ? 1 :
txHistory.getAddress().getType().equals(XDAG_FIELD_COINBASE) ? 2 : 3)
.time(xdagTimestampToMs(txHistory.getTimestamp()))
.time(txHistory.getTimestamp())
.remark(txHistory.getRemark());
} else {
txLinkBuilder.address(toBase58(BytesUtils.byte32ToArray(txHistory.getAddress().getAddress())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.sql.Statement;
import java.util.List;

import io.xdag.utils.XdagTime;
import org.apache.tuweni.bytes.Bytes32;
import org.hyperledger.besu.crypto.SECPPrivateKey;
import org.junit.BeforeClass;
Expand All @@ -60,7 +61,7 @@ public class TransactionHistoryStoreImplTest {
`famount` decimal(20,9) NOT NULL,
`ftype` tinyint NOT NULL,
`fremark` varchar(64) DEFAULT NULL,
`ftime` datetime NOT NULL,
`ftime` datetime(3) NOT NULL,
PRIMARY KEY (`fid`),
UNIQUE KEY `id_UNIQUE` (`fid`),
KEY `faddress_index` (`faddress`)
Expand Down Expand Up @@ -93,7 +94,7 @@ public void testTxHistorySaveAndListAndCount() {
txHistory.setAddress(input);
txHistory.setHash(hash);
txHistory.setRemark(remark);
txHistory.setTimestamp(timestamp);
txHistory.setTimestamp(XdagTime.msToXdagtimestamp(timestamp));
assertTrue(txHistoryStore.saveTxHistory(txHistory));

String addr = input.getIsAddress()?toBase58(hash2byte(input.getAddress())):hash2Address(input.getAddress());
Expand Down

0 comments on commit b135b2f

Please sign in to comment.