Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a synchronization bug & some display issues. #298

Merged
merged 1 commit into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/io/xdag/consensus/XdagSync.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ private void getBlocks() {
if (i >= size) {
break;
}
//when the synchronization process channel is removed and reset, update the channel
if (!xc.isActive()){
log.debug("sync channel need to update");
return;
}

long time = syncWindow.get(i);
sendGetBlocks(xc, time, sf);
if (i == 30) lastRequestTime = time;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.Date;
import java.util.List;

import static io.xdag.config.Constants.MIN_GAS;
import static io.xdag.core.XdagField.FieldType.XDAG_FIELD_INPUT;
import static io.xdag.utils.BasicUtils.hash2Address;
import static io.xdag.utils.BasicUtils.hash2byte;
import static io.xdag.utils.WalletUtils.checkAddress;
Expand Down Expand Up @@ -87,7 +89,8 @@ public boolean saveTxHistory(TxHistory txHistory) {
pstmt.setString(1, addr);
pstmt.setInt(2, address.getIsAddress() ? WALLET_ADDRESS_FLAG : BLOCK_ADDRESS_FLAG);
pstmt.setString(3, txHistory.getHash());
pstmt.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG));
pstmt.setBigDecimal(4, address.getType().equals(XDAG_FIELD_INPUT) ? address.getAmount().subtract(MIN_GAS).toDecimal(9, XUnit.XDAG) :
address.getAmount().toDecimal(9, XUnit.XDAG));
pstmt.setInt(5, address.getType().asByte());
pstmt.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : "");
pstmt.setTimestamp(7,
Expand Down Expand Up @@ -123,7 +126,8 @@ public boolean batchSaveTxHistory(TxHistory txHistory, int... cacheNum) {
pstmtBatch.setString(1, addr);
pstmtBatch.setInt(2, address.getIsAddress() ? WALLET_ADDRESS_FLAG : BLOCK_ADDRESS_FLAG);
pstmtBatch.setString(3, txHistory.getHash());
pstmtBatch.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG));
pstmtBatch.setBigDecimal(4, address.getType().equals(XDAG_FIELD_INPUT) ? address.getAmount().subtract(MIN_GAS).toDecimal(9, XUnit.XDAG) :
address.getAmount().toDecimal(9, XUnit.XDAG));
pstmtBatch.setInt(5, address.getType().asByte());
pstmtBatch.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : "");
pstmtBatch.setTimestamp(7,
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/io/xdag/rpc/modules/xdag/XdagModuleChainBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private List<TxLink> getTxLinks(Block block, int page, Object... parameters) {
remark = new String(block.getInfo().getRemark(), StandardCharsets.UTF_8).trim();
}
XAmount earnFee = kernel.getBlockStore().getBlockInfoByHash(block.getHashLow()).getFee();
if (block.getInfo().getAmount().equals(XAmount.ZERO)){ earnFee = XAmount.ZERO;} //when block amount is zero, fee also should make zero.
// if (block.getInfo().getAmount().equals(XAmount.ZERO)){ earnFee = XAmount.ZERO;} //when block amount is zero, fee also should make zero.
txLinkBuilder.address(hash2Address(block.getHashLow()))
.hashlow(block.getHashLow().toUnprefixedHexString())
.amount(String.format("%s", blockchain.getReward(block.getInfo().getHeight()).add(earnFee).toDecimal(9, XUnit.XDAG).toPlainString()))
Expand Down Expand Up @@ -341,14 +341,10 @@ private List<TxLink> getTxHistory(String address, int page, Object... parameters
if ((blockInfo.flags & BI_APPLIED) == 0) {
continue;
}
//这里查账户,账户的input是扣手续费的(角色是to),output才不扣(角色是from)
XAmount Amount =txHistory.getAddress().getAmount();
if (txHistory.getAddress().getType().equals(XDAG_FIELD_INPUT)){
Amount = Amount.subtract(MIN_GAS);
}

txLinkBuilder.address(hash2Address(txHistory.getAddress().getAddress()))
.hashlow(txHistory.getAddress().getAddress().toUnprefixedHexString())
.amount(String.format("%s", Amount.toDecimal(9, XUnit.XDAG).toPlainString()))
.amount(String.format("%s", txHistory.getAddress().getAmount().toDecimal(9, XUnit.XDAG).toPlainString()))
.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)
Expand Down