mirror of
https://github.com/Qortal/qortal.git
synced 2025-07-26 11:41:24 +00:00
Added PirateChainHTLC.getUnspentFundingTxid(), allowing a minimum amount to be specified.
This will ensure that the correct fundingTxid can be redeemed or refunded by the trade bot.
This commit is contained in:
@@ -236,6 +236,37 @@ public class PirateChainHTLC {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string containing the unspent txid of the transaction that funded supplied <tt>p2shAddress</tt>
|
||||
* and is at least the value specified in <tt>minimumAmount</tt>
|
||||
* <p>
|
||||
* @throws ForeignBlockchainException if error occurs
|
||||
*/
|
||||
public static String getUnspentFundingTxid(BitcoinyBlockchainProvider blockchain, String p2shAddress, long minimumAmount) throws ForeignBlockchainException {
|
||||
byte[] ourScriptPubKey = addressToScriptPubKey(p2shAddress);
|
||||
|
||||
// Note: we can't include unconfirmed transactions here because the Pirate light wallet server requires a block range
|
||||
List<UnspentOutput> unspentOutputs = blockchain.getUnspentOutputs(p2shAddress, false);
|
||||
for (UnspentOutput unspentOutput : unspentOutputs) {
|
||||
|
||||
if (!Arrays.equals(ourScriptPubKey, unspentOutput.script)) {
|
||||
// Not funding our specific HTLC script hash
|
||||
continue;
|
||||
}
|
||||
|
||||
if (unspentOutput.value < minimumAmount) {
|
||||
// Not funding the required amount
|
||||
continue;
|
||||
}
|
||||
|
||||
return HashCode.fromBytes(unspentOutput.hash).toString();
|
||||
}
|
||||
|
||||
|
||||
// No valid unspent outputs, so must be already spent
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns HTLC status, given P2SH address and expected redeem/refund amount
|
||||
* <p>
|
||||
|
Reference in New Issue
Block a user