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 for dust error when redeeming P2SH-B #17

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 3 additions & 2 deletions src/main/java/org/qortal/controller/TradeBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public TradeBotData getTradeBotData() {
private static final Logger LOGGER = LogManager.getLogger(TradeBot.class);
private static final Random RANDOM = new SecureRandom();
private static final long FEE_AMOUNT = 5000L;
private static final long P2SHB_REDEEM_AMOUNT = 1000L;

private static TradeBot instance;

Expand Down Expand Up @@ -766,7 +767,7 @@ private void handleBobWaitingForP2shB(Repository repository, TradeBotData tradeB
}

// Redeem P2SH-B using secret-B
Coin redeemAmount = Coin.ZERO; // The real funds are in P2SH-A
Coin redeemAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // We need to redeem an amount higher than the dust threshold (3000 sats/kB). The real funds are in P2SH-A
ECKey redeemKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
List<TransactionOutput> fundingOutputs = BTC.getInstance().getUnspentOutputs(p2shAddress);
byte[] receivingAccountInfo = tradeBotData.getReceivingAccountInfo();
Expand Down Expand Up @@ -976,7 +977,7 @@ private void handleAliceRefundingP2shB(Repository repository, TradeBotData trade
byte[] redeemScriptBytes = BTCP2SH.buildScript(tradeBotData.getTradeForeignPublicKeyHash(), crossChainTradeData.lockTimeB, crossChainTradeData.creatorBitcoinPKH, crossChainTradeData.hashOfSecretB);
String p2shAddress = BTC.getInstance().deriveP2shAddress(redeemScriptBytes);

Coin refundAmount = Coin.ZERO;
Coin refundAmount = Coin.valueOf(P2SHB_REDEEM_AMOUNT); // We need to redeem an amount higher than the dust threshold (3000 sats/kB). The rest will be used to pay the fee.
ECKey refundKey = ECKey.fromPrivate(tradeBotData.getTradePrivateKey());
List<TransactionOutput> fundingOutputs = BTC.getInstance().getUnspentOutputs(p2shAddress);

Expand Down