Refactor tx handling

This commit is contained in:
Manfred Karrer 2015-03-16 09:57:21 +01:00
parent ca32014f8b
commit 25ff3d26f1
3 changed files with 23 additions and 22 deletions

View File

@ -370,7 +370,7 @@ public class WalletService {
List<TransactionConfidence> transactionConfidenceList = new ArrayList<>(); List<TransactionConfidence> transactionConfidenceList = new ArrayList<>();
mergedOutputs.stream().filter(e -> e.getScriptPubKey().isSentToAddress() || mergedOutputs.stream().filter(e -> e.getScriptPubKey().isSentToAddress() ||
e.getScriptPubKey().isSentToP2SH()).forEach(transactionOutput -> { e.getScriptPubKey().isPayToScriptHash()).forEach(transactionOutput -> {
Address outputAddress = transactionOutput.getScriptPubKey().getToAddress(params); Address outputAddress = transactionOutput.getScriptPubKey().getToAddress(params);
if (address.equals(outputAddress)) { if (address.equals(outputAddress)) {
transactionConfidenceList.add(tx.getConfidence()); transactionConfidenceList.add(tx.getConfidence());
@ -440,12 +440,10 @@ public class WalletService {
private Coin getBalance(LinkedList<TransactionOutput> transactionOutputs, Address address) { private Coin getBalance(LinkedList<TransactionOutput> transactionOutputs, Address address) {
Coin balance = Coin.ZERO; Coin balance = Coin.ZERO;
for (TransactionOutput transactionOutput : transactionOutputs) { for (TransactionOutput transactionOutput : transactionOutputs) {
if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey() if (transactionOutput.getScriptPubKey().isSentToAddress() || transactionOutput.getScriptPubKey().isPayToScriptHash()) {
.isSentToP2SH()) {
Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params); Address addressOutput = transactionOutput.getScriptPubKey().getToAddress(params);
if (addressOutput.equals(address)) { if (addressOutput.equals(address))
balance = balance.add(transactionOutput.getValue()); balance = balance.add(transactionOutput.getValue());
}
} }
} }
return balance; return balance;
@ -795,7 +793,7 @@ public class WalletService {
verifyTransaction(depositTx); verifyTransaction(depositTx);
checkWalletConsistency(); checkWalletConsistency();
checkScriptSigForAllInputs(depositTx); //checkScriptSigForAllInputs(depositTx);
// Broadcast depositTx // Broadcast depositTx
log.trace("Wallet balance before broadcastTransaction: " + wallet.getBalance()); log.trace("Wallet balance before broadcastTransaction: " + wallet.getBalance());
@ -1017,9 +1015,8 @@ public class WalletService {
private void checkScriptSig(Transaction transaction, TransactionInput input, int inputIndex) throws TransactionVerificationException { private void checkScriptSig(Transaction transaction, TransactionInput input, int inputIndex) throws TransactionVerificationException {
try { try {
log.trace("Verifies that this script (interpreted as a scriptSig) correctly spends the given scriptPubKey."); log.trace("Verifies that this script (interpreted as a scriptSig) correctly spends the given scriptPubKey. Check input at index: " + inputIndex);
input.getScriptSig().correctlySpends(transaction, inputIndex, input.getConnectedOutput().getScriptPubKey()); input.getScriptSig().correctlySpends(transaction, inputIndex, input.getConnectedOutput().getScriptPubKey());
inputIndex++;
} catch (Throwable t) { } catch (Throwable t) {
t.printStackTrace(); t.printStackTrace();
log.error(t.getMessage()); log.error(t.getMessage());
@ -1027,12 +1024,13 @@ public class WalletService {
} }
} }
private void checkScriptSigForAllInputs(Transaction transaction) throws TransactionVerificationException { /*private void checkScriptSigForAllInputs(Transaction transaction) throws TransactionVerificationException {
int inputIndex = 0; int inputIndex = 0;
for (TransactionInput input : transaction.getInputs()) { for (TransactionInput input : transaction.getInputs()) {
checkScriptSig(transaction, input, inputIndex); checkScriptSig(transaction, input, inputIndex);
inputIndex++;
} }
} }*/
private void removeSignatures(Transaction transaction) throws InsufficientMoneyException { private void removeSignatures(Transaction transaction) throws InsufficientMoneyException {
for (TransactionInput input : transaction.getInputs()) { for (TransactionInput input : transaction.getInputs()) {

View File

@ -213,6 +213,7 @@ public class TradeManager {
case OPEN: case OPEN:
break; break;
case OFFERER_ACCEPTED: case OFFERER_ACCEPTED:
case TAKE_OFFER_FEE_PAID:
case DEPOSIT_PUBLISHED: case DEPOSIT_PUBLISHED:
case DEPOSIT_CONFIRMED: case DEPOSIT_CONFIRMED:
case FIAT_PAYMENT_STARTED: case FIAT_PAYMENT_STARTED:

View File

@ -29,18 +29,22 @@
</root> </root>
<logger name="io.bitsquare" level="TRACE"/> <logger name="io.bitsquare" level="TRACE"/>
<logger name="io.bitsquare.network.tomp2p.BootstrappedPeerBuilder" level="ERROR"/>
<logger name="io.bitsquare.gui.util.Profiler" level="ERROR"/> <logger name="io.bitsquare.gui.util.Profiler" level="ERROR"/>
<logger name="io.bitsquare.persistence.Persistence" level="ERROR"/> <logger name="io.bitsquare.persistence.Persistence" level="ERROR"/>
<logger name="io.bitsquare.locale.BSResources" level="ERROR"/> <logger name="io.bitsquare.locale.BSResources" level="ERROR"/>
<logger name="org.bitcoinj" level="TRACE"/> <logger name="org.bitcoinj" level="DEBUG"/>
<logger name="net.tomp2p" level="ERROR"/> <logger name="net.tomp2p" level="ERROR"/>
<logger name="com.vinumeris.updatefx" level="OFF"/>
<logger name="io.netty" level="OFF"/> <logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
<logger name="org.bitcoinj.core.BitcoinSerializer" level="ERROR"/> <logger name="org.bitcoinj.core.Peer" level="WARN"/>
<logger name="org.bitcoinj.core.Peer" level="ERROR"/>
<!--
<logger name="com.vinumeris.updatefx" level="OFF"/>
<logger name="io.netty" level="OFF"/>
<logger name="org.bitcoinj.core.BitcoinSerializer" level="ERROR"/>
<logger name="org.bitcoinj.core.Peer" level="ERROR"/>-->
<!-- <logger name="net.tomp2p.message.Encoder" level="WARN"/> <!-- <logger name="net.tomp2p.message.Encoder" level="WARN"/>
<logger name="net.tomp2p.message.Decoder" level="WARN"/> <logger name="net.tomp2p.message.Decoder" level="WARN"/>
<logger name="net.tomp2p.message.MessageHeaderCodec" level="WARN"/> <logger name="net.tomp2p.message.MessageHeaderCodec" level="WARN"/>
@ -50,12 +54,10 @@
<logger name="io.netty.channel" level="WARN"/> <logger name="io.netty.channel" level="WARN"/>
<logger name="io.netty.buffer" level="WARN"/>--> <logger name="io.netty.buffer" level="WARN"/>-->
<!-- <logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/>
<!-- <logger name="org.bitcoinj.core.BitcoinSerializer" level="WARN"/> <logger name="org.bitcoinj.core.AbstractBlockChain" level="WARN"/>
<logger name="org.bitcoinj.core.AbstractBlockChain" level="WARN"/> <logger name="org.bitcoinj.wallet.DeterministicKeyChain" level="WARN"/>-->
<logger name="org.bitcoinj.wallet.DeterministicKeyChain" level="WARN"/>-->
<!-- <logger name="io.bitsquare.btc.WalletService" level="WARN"/>--> <!-- <logger name="io.bitsquare.btc.WalletService" level="WARN"/>-->
<!-- <!--