Skip to content

Commit

Permalink
Merge pull request #274 from XDagger/develop
Browse files Browse the repository at this point in the history
sync code
  • Loading branch information
LucasMLK authored Aug 29, 2023
2 parents 63272ca + 3357588 commit 2905e9a
Show file tree
Hide file tree
Showing 6 changed files with 420 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<snappy-java.version>1.1.10.1</snappy-java.version>
<druid.version>1.2.18</druid.version>
<mysql-connector.version>8.0.33</mysql-connector.version>
<h2.version>2.2.220</h2.version>
<surefire.test.excludes>**/*RandomXSyncTest.java,**/*SyncTest.java,**/*SnapshotJTest.java</surefire.test.excludes>
</properties>

Expand Down Expand Up @@ -674,7 +675,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.2.220</version>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class TransactionHistoryStoreImpl implements TransactionHistoryStore {
private static final int BLOCK_ADDRESS_FLAG = 0;
private static final int WALLET_ADDRESS_FLAG = 1;

private static final int Default_PAGE_SIZE = 100;
private static final int DEFAULT_PAGE_SIZE = 100;
private Connection connBatch = null;
private PreparedStatement pstmtBatch = null;
private int count = 0;
Expand All @@ -84,7 +84,7 @@ public boolean saveTxHistory(TxHistory txHistory) {
pstmt.setString(3, txHistory.getHash());
pstmt.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG));
pstmt.setInt(5, address.getType().asByte());
pstmt.setString(6, txHistory.getRemark());
pstmt.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : "");
pstmt.setTimestamp(7,
new java.sql.Timestamp(XdagTime.xdagTimestampToMs(txHistory.getTimestamp())));
result = pstmt.executeUpdate() == 1;
Expand Down Expand Up @@ -120,7 +120,7 @@ public boolean batchSaveTxHistory(TxHistory txHistory, int... cacheNum) {
pstmtBatch.setString(3, txHistory.getHash());
pstmtBatch.setBigDecimal(4, address.getAmount().toDecimal(9, XUnit.XDAG));
pstmtBatch.setInt(5, address.getType().asByte());
pstmtBatch.setString(6, txHistory.getRemark());
pstmtBatch.setString(6, txHistory.getRemark() != null ? txHistory.getRemark().trim() : "");
pstmtBatch.setTimestamp(7,
new java.sql.Timestamp(XdagTime.xdagTimestampToMs(txHistory.getTimestamp())));
pstmtBatch.addBatch();
Expand Down Expand Up @@ -162,7 +162,7 @@ public List<TxHistory> listTxHistoryByAddress(String address, int page, Object..
ResultSet rs = null;
List<TxHistory> txHistoryList = Lists.newArrayList();
int totalcount = 0;
int PAGE_SIZE = Default_PAGE_SIZE;
int PAGE_SIZE = DEFAULT_PAGE_SIZE;
long start = new Date(0).getTime();
long end = System.currentTimeMillis();
switch (parameters.length) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/xdag/net/message/impl/SyncBlockMessage.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* 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.net.message.impl;

import io.xdag.core.Block;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* 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.net.message.impl;

import io.xdag.core.XdagStats;
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/io/xdag/BlockBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public static Block generateExtraBlock(Config config, KeyPair key, long xdagTime
return generateExtraBlockGivenRandom(config, key, xdagTime, pendings, "1234");
}

public static Block generateExtraBlock(Config config, KeyPair key, long xdagTime, String remark, List<Address> pendings) {
Block b = new Block(config, xdagTime, null, pendings, true, null, remark, -1);
Bytes32 random = Hash.sha256(Bytes.wrap(Hex.decode("1234")));
b.signOut(key);
b.setNonce(random);
return b;
}

// TODO:set nonce means this block is a mining block, the mining param need to set true
public static Block generateExtraBlockGivenRandom(Config config, KeyPair key, long xdagTime,
List<Address> pendings, String randomS) {
Expand Down
Loading

0 comments on commit 2905e9a

Please sign in to comment.