Skip to content

Commit

Permalink
Merge branch 'feature/0.9.12' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
niels1286 committed Jul 9, 2018
2 parents 8d27c41 + 02dc870 commit ad4ce8a
Show file tree
Hide file tree
Showing 230 changed files with 4,443 additions and 1,865 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ nuls>mvn clean package

```shell
$ mvn clean package
$ cd node/target
$ tar zxvf nuls-node.tar.gz
$ cd client-module/client/target
$ tar -zxvf nuls-node.tar.gz
$ cd bin
```
Using start.sh running the nuls process.
Expand Down
8 changes: 4 additions & 4 deletions account-ledger-module/account-ledger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@
<parent>
<artifactId>account-ledger-module</artifactId>
<groupId>io.nuls</groupId>
<version>0.9.11</version>
<version>0.9.12</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>

<dependencies>
<dependency>
<groupId>io.nuls.core-module</groupId>
<artifactId>kernel</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.account-module</groupId>
<artifactId>account</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ public interface AccountLedgerService {

/**
* create a transaction by inputs data and outputs data
* @param inputsKey key of utxo
* @param inputs used utxos
* @param outputs new utxos
* @param remark remarks of transaction
* @return Result
*/
Result createTransaction(List<byte[]> inputsKey, List<Coin> outputs, byte[] remark);
Result createTransaction(List<Coin> inputs, List<Coin> outputs, byte[] remark);

/**
* 签名交易
Expand Down Expand Up @@ -202,4 +202,13 @@ public interface AccountLedgerService {
* @return Result
*/
Result<List<Coin>> getLockedUtxo(byte[] address);

/**
* delete unconfirmed transactions of an account
*
* @param address address
* @return Result
*/
Result<Integer> deleteUnconfirmedTx(byte[] address);

}
12 changes: 6 additions & 6 deletions account-ledger-module/base/account-ledger-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@
<parent>
<artifactId>account-ledger-module</artifactId>
<groupId>io.nuls</groupId>
<version>0.9.11</version>
<version>0.9.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger-base</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>


<dependencies>
<dependency>
<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger-storage</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.protocol-module</groupId>
<artifactId>protocol</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.consensus-module</groupId>
<artifactId>consensus</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void start() {
BalanceManager balanceManager = NulsContext.getServiceBean(BalanceManager.class);
balanceManager.initAccountBalance();
ScheduledThreadPoolExecutor executor = TaskManager.createScheduledThreadPool(1, new NulsThreadFactory(AccountLedgerConstant.MODULE_ID_ACCOUNTLEDGER, "CheckUnConfirmTxThread"));
executor.scheduleAtFixedRate(NulsContext.getServiceBean(CheckUnConfirmTxThread.class), 120, 60, TimeUnit.SECONDS);
executor.scheduleAtFixedRate(NulsContext.getServiceBean(CheckUnConfirmTxThread.class), 10, 10, TimeUnit.MINUTES);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,28 +425,28 @@ public CoinDataResult getCoinData(byte[] address, Na amount, int size, Na price)
//每次累加一条未花费余额时,需要重新计算手续费
Na fee = TransactionFeeCalculator.getFee(size, price);
values = values.add(coin.getNa());
if (values.isGreaterOrEquals(amount.add(fee))) {
//余额足够后,需要判断是否找零,如果有找零,则需要重新计算手续费

//需要判断是否找零,如果有找零,则需要重新计算手续费
if (values.isGreaterThan(amount.add(fee))) {
Na change = values.subtract(amount.add(fee));
if (change.isGreaterThan(Na.ZERO)) {
Coin changeCoin = new Coin();
changeCoin.setOwner(address);
changeCoin.setNa(change);

fee = TransactionFeeCalculator.getFee(size + changeCoin.size(), price);
if (values.isLessThan(amount.add(fee))) {
continue;
}
coinDataResult.setChange(changeCoin);
}
Coin changeCoin = new Coin();
changeCoin.setOwner(address);
changeCoin.setNa(change);

fee = TransactionFeeCalculator.getFee(size + changeCoin.size(), price);
if (values.isLessThan(amount.add(fee))) {
continue;
}
coinDataResult.setChange(changeCoin);
}
coinDataResult.setFee(fee);
if (values.isGreaterOrEquals(amount.add(fee))) {
enough = true;
coinDataResult.setEnough(true);
coinDataResult.setFee(fee);
coinDataResult.setCoinList(coins);
break;
}
}
coinDataResult.setCoinList(coins);
if (!enough) {
coinDataResult.setEnough(false);
return coinDataResult;
Expand Down Expand Up @@ -490,6 +490,8 @@ public Na getTxFee(byte[] address, Na amount, int size, Na price) {
fee = TransactionFeeCalculator.getFee(size + changeCoin.size(), price);
if (values.isLessThan(amount.add(fee))) {
continue;
} else {
break;
}
}
}
Expand Down Expand Up @@ -545,8 +547,8 @@ public Result transfer(byte[] from, byte[] to, Na values, String password, Strin
if (saveResult.isFailed()) {
return saveResult;
}
transactionService.newTx(tx);
Result sendResult = transactionService.forwardTx(tx, null);
// transactionService.newTx(tx);
Result sendResult = transactionService.broadcastTx(tx);
if (sendResult.isFailed()) {
this.rollbackTransaction(tx);
return sendResult;
Expand Down Expand Up @@ -577,34 +579,19 @@ public Result transferFee(byte[] from, byte[] to, Na values, String remark, Na p
CoinData coinData = new CoinData();
Coin toCoin = new Coin(to, values);
coinData.getTo().add(toCoin);
Na fee = getTxFee(from, values, tx.size(), price);
tx.setCoinData(coinData);
Na fee = getTxFee(from, values, tx.size() + P2PKHScriptSig.DEFAULT_SERIALIZE_LENGTH, price);
Result result = Result.getSuccess().setData(fee);
return result;
}

@Override
public Result createTransaction(List<byte[]> inputsKey, List<Coin> outputs, byte[] remark) {
public Result createTransaction(List<Coin> inputs, List<Coin> outputs, byte[] remark) {
TransferTransaction tx = new TransferTransaction();
CoinData coinData = new CoinData();
coinData.setTo(outputs);
coinData.setFrom(inputs);
tx.setRemark(remark);
//验证地址是否一致
byte[] owner = null;
for (int i = 0; i < inputsKey.size(); i++) {
Coin coin = ledgerService.getUtxo(inputsKey.get(i));
if (coin == null) {
return Result.getFailed(LedgerErrorCode.UTXO_NOT_FOUND);
}
if (i == 0) {
owner = coin.getOwner();
} else {
if (!Arrays.equals(coin.getOwner(), owner)) {
return Result.getFailed(LedgerErrorCode.INVALID_INPUT);
}
}
coin.setOwner(inputsKey.get(i));
coinData.getFrom().add(coin);
}

tx.setCoinData(coinData);
tx.setTime(TimeService.currentTimeMillis());
Expand Down Expand Up @@ -634,7 +621,6 @@ public Result createTransaction(List<byte[]> inputsKey, List<Coin> outputs, byte

@Override
public Transaction signTransaction(Transaction tx, ECKey ecKey) throws IOException {
tx.setHash(NulsDigestData.calcDigestData(tx.serializeForHash()));
P2PKHScriptSig sig = new P2PKHScriptSig();
sig.setPublicKey(ecKey.getPubKey());
sig.setSignData(accountService.signDigest(tx.getHash().getDigestBytes(), ecKey));
Expand All @@ -644,7 +630,7 @@ public Transaction signTransaction(Transaction tx, ECKey ecKey) throws IOExcepti

@Override
public Result broadcast(Transaction tx) {
return transactionService.forwardTx(tx, null);
return transactionService.broadcastTx(tx);
}


Expand Down Expand Up @@ -708,6 +694,25 @@ public Result<List<Coin>> getLockedUtxo(byte[] address) {
return result;
}

@Override
public Result<Integer> deleteUnconfirmedTx(byte[] address) {
Result result = getAllUnconfirmedTransaction();
if (result.getData() == null) {
return Result.getSuccess().setData(new Integer(0));
}
List<Transaction> txs = (List<Transaction>) result.getData();
int i = 0;
for (Transaction tx : txs) {
if (Arrays.equals(tx.getAddressFromSig(), address)) {
unconfirmedTransactionStorageService.deleteUnconfirmedTx(tx.getHash());
localUtxoService.deleteUtxoOfTransaction(tx);
i++;
}

}
return Result.getSuccess().setData(new Integer(i));
}

protected Result<Integer> importConfirmedTransaction(Transaction tx, byte[] address) {

if (!AccountLegerUtils.isTxRelatedToAddress(tx, address)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
import io.nuls.kernel.lite.annotation.Autowired;
import io.nuls.kernel.lite.annotation.Component;
import io.nuls.kernel.model.*;
import io.nuls.kernel.utils.AddressTool;
import io.nuls.kernel.utils.VarInt;
import io.nuls.ledger.service.LedgerService;
import io.nuls.protocol.service.TransactionService;
import io.nuls.protocol.utils.TransactionTimeComparator;

import java.io.IOException;
import java.util.*;
Expand Down Expand Up @@ -73,6 +75,8 @@ public class CheckUnConfirmTxThread implements Runnable {
@Autowired
private TransactionInfoService transactionInfoService;

private TransactionTimeComparator comparator = TransactionTimeComparator.getInstance();

@Override
public void run() {
try {
Expand All @@ -90,21 +94,24 @@ private void doTask() {

Map<String, Coin> toMaps = new HashMap<>();
Set<String> fromSet = new HashSet<>();
Collections.sort(list, this.comparator);
for (Transaction tx : list) {
if (TimeService.currentTimeMillis() - tx.getTime() < 120000L) {
return;
}

Result result = verifyTransaction(tx, toMaps, fromSet);
if (result.isSuccess()) {
if (TimeService.currentTimeMillis() - tx.getTime() < 300000L) {
return;
}
result = reBroadcastTransaction(tx);
if (result.isFailed()) {
Log.info("reBroadcastTransaction tx error");
}
} else {
deleteUnconfirmedTransaction(tx);
List<byte[]> addresses = tx.getAllRelativeAddress();
Set<String> set = new HashSet<>();
for (byte[] address : addresses) {
if (AccountLegerUtils.isLocalAccount(address)) {
if (AccountLegerUtils.isLocalAccount(address) && set.add(AddressTool.getStringAddressByBytes(address))) {
balanceManager.refreshBalance(address);
}
}
Expand Down Expand Up @@ -155,7 +162,10 @@ private void rollbackUtxo(Transaction tx) {
if (!AccountLegerUtils.isLocalAccount(fromCoin.getOwner())) {
continue;
}

Coin fromCoinFromLedger = ledgerService.getUtxo(fromSource);
if (fromCoinFromLedger == null || !fromCoinFromLedger.usable()) {
continue;
}
fromList.add(new Entry<>(from.getOwner(), fromCoin.serialize()));
} catch (IOException e) {
throw new NulsRuntimeException(e);
Expand Down Expand Up @@ -186,7 +196,7 @@ private void rollbackUtxo(Transaction tx) {


private Result reBroadcastTransaction(Transaction tx) {
Result sendResult = transactionService.forwardTx(tx, null);
Result sendResult = transactionService.broadcastTx(tx);
if (sendResult.isFailed()) {
return sendResult;
}
Expand Down
10 changes: 5 additions & 5 deletions account-ledger-module/base/account-ledger-rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<parent>
<artifactId>account-ledger-module</artifactId>
<groupId>io.nuls</groupId>
<version>0.9.11</version>
<version>0.9.12</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger-rpc</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>


<dependencies>
Expand All @@ -39,17 +39,17 @@
<dependency>
<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.account-ledger-module</groupId>
<artifactId>account-ledger-base</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
<dependency>
<groupId>io.nuls.ledger-module</groupId>
<artifactId>ledger</artifactId>
<version>0.9.11</version>
<version>0.9.12</version>
</dependency>
</dependencies>

Expand Down
Loading

0 comments on commit ad4ce8a

Please sign in to comment.