Skip to content

Commit

Permalink
Allow unconfirmed in SLP tx builder
Browse files Browse the repository at this point in the history
  • Loading branch information
pokkst committed May 21, 2020
1 parent 3b877c8 commit 0e0ea7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
12 changes: 10 additions & 2 deletions core/src/main/java/org/bitcoinj/core/slp/SlpTxBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import java.nio.ByteBuffer
class SlpTxBuilder {
companion object {
@JvmStatic
fun buildTx(tokenId: String, amount: Double, toAddress: String, slpAppKit: SlpAppKit, aesKey: KeyParameter?): Single<Transaction> {
fun buildTx(tokenId: String, amount: Double, toAddress: String, slpAppKit: SlpAppKit, aesKey: KeyParameter?, allowUnconfirmed: Boolean): Single<Transaction> {
return sendTokenUtxoSelection(tokenId, amount, slpAppKit)
.map {
val cashAddr = SlpAddress(slpAppKit.wallet.params, toAddress).toCashAddress()
val addrTo = CashAddress.fromCashAddress(slpAppKit.wallet.params, cashAddr)
// Add OP RETURN and receiver output
val req = SendRequest.createSlpTransaction(slpAppKit.wallet.params)

if(allowUnconfirmed)
req.allowUnconfirmed()

req.aesKey = aesKey
req.shuffleOutputs = false
req.utxos = null
Expand Down Expand Up @@ -60,11 +64,15 @@ class SlpTxBuilder {
}

@JvmStatic
fun buildTxBip70(tokenId: String, slpAppKit: SlpAppKit, aesKey: KeyParameter?, rawTokens: List<Long>, addresses: List<String>, paymentSession: SlpPaymentSession): Single<Transaction> {
fun buildTxBip70(tokenId: String, slpAppKit: SlpAppKit, aesKey: KeyParameter?, rawTokens: List<Long>, addresses: List<String>, paymentSession: SlpPaymentSession, allowUnconfirmed: Boolean): Single<Transaction> {
return sendTokenUtxoSelectionBip70(tokenId, rawTokens, slpAppKit)
.map {
// Add OP RETURN and receiver output
val req = SendRequest.createSlpTransaction(slpAppKit.wallet.params)

if(allowUnconfirmed)
req.allowUnconfirmed()

req.aesKey = aesKey
req.shuffleOutputs = false
req.utxos = null
Expand Down
12 changes: 10 additions & 2 deletions core/src/main/java/org/bitcoinj/kits/SlpAppKit.java
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,19 @@ public void setTorProxyPort(String port) {
}

public Transaction createSlpTransaction(String slpDestinationAddress, String tokenId, double numTokens, @Nullable KeyParameter aesKey) throws InsufficientMoneyException {
return SlpTxBuilder.buildTx(tokenId, numTokens, slpDestinationAddress, this, aesKey).blockingGet();
return this.createSlpTransaction(slpDestinationAddress, tokenId, numTokens, aesKey, true);
}

public Transaction createSlpTransaction(String slpDestinationAddress, String tokenId, double numTokens, @Nullable KeyParameter aesKey, boolean allowUnconfirmed) throws InsufficientMoneyException {
return SlpTxBuilder.buildTx(tokenId, numTokens, slpDestinationAddress, this, aesKey, allowUnconfirmed).blockingGet();
}

public Transaction createSlpTransactionBip70(String tokenId, @Nullable KeyParameter aesKey, List<Long> rawTokens, List<String> addresses, SlpPaymentSession paymentSession) throws InsufficientMoneyException {
return SlpTxBuilder.buildTxBip70(tokenId, this, aesKey, rawTokens, addresses, paymentSession).blockingGet();
return this.createSlpTransactionBip70(tokenId, aesKey, rawTokens, addresses, paymentSession, true);
}

public Transaction createSlpTransactionBip70(String tokenId, @Nullable KeyParameter aesKey, List<Long> rawTokens, List<String> addresses, SlpPaymentSession paymentSession, boolean allowUnconfirmed) throws InsufficientMoneyException {
return SlpTxBuilder.buildTxBip70(tokenId, this, aesKey, rawTokens, addresses, paymentSession, allowUnconfirmed).blockingGet();
}

public Transaction createSlpGenesisTransaction(String ticker, String name, String url, int decimals, long tokenQuantity, @Nullable KeyParameter aesKey) throws InsufficientMoneyException {
Expand Down

0 comments on commit 0e0ea7e

Please sign in to comment.