Skip to main content
deleted 646 characters in body
Source Link
Nick ODell
  • 29.5k
  • 11
  • 73
  • 132

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReasonDefaultCoinSelector.DEPTHisSelectable(transaction) {
                 System.out.println("An incoming transaction was just seen in at// leastdo onesomething block.");here
             }
        }
    });
}

Note: code is untested.

EDIT

This also works:

override def onCoinsReceived(
  wallet: Wallet,
  transaction: Transaction,
  prevBalance: Coin,
  newBalance: Coin
) {
  ...

  transaction.getConfidence().addEventListener(new TransactionConfidence.Listener() {
    def onConfidenceChanged(confidence: TransactionConfidence, reason: TransactionConfidence.Listener.ChangeReason) {
      DefaultCoinSelector.isSelectable(transaction) {
        // spend here
      }
    }
  }
}

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReason.DEPTH) {
                 System.out.println("An incoming transaction was just seen in at least one block.");
             }
        }
    });
}

Note: code is untested.

EDIT

This also works:

override def onCoinsReceived(
  wallet: Wallet,
  transaction: Transaction,
  prevBalance: Coin,
  newBalance: Coin
) {
  ...

  transaction.getConfidence().addEventListener(new TransactionConfidence.Listener() {
    def onConfidenceChanged(confidence: TransactionConfidence, reason: TransactionConfidence.Listener.ChangeReason) {
      DefaultCoinSelector.isSelectable(transaction) {
        // spend here
      }
    }
  }
}

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
            DefaultCoinSelector.isSelectable(transaction) {
                // do something here
            }
        }
    });
}
DefaultCoinSelector.isSelectable() also does the trick.
Source Link

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReason.DEPTH) {
                 System.out.println("An incoming transaction was just seen in at least one block.");
             }
        }
    });
}

Note: code is untested.

EDIT

This also works:

override def onCoinsReceived(
  wallet: Wallet,
  transaction: Transaction,
  prevBalance: Coin,
  newBalance: Coin
) {
  ...

  transaction.getConfidence().addEventListener(new TransactionConfidence.Listener() {
    def onConfidenceChanged(confidence: TransactionConfidence, reason: TransactionConfidence.Listener.ChangeReason) {
      DefaultCoinSelector.isSelectable(transaction) {
        // spend here
      }
    }
  }
}

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReason.DEPTH) {
                 System.out.println("An incoming transaction was just seen in at least one block.");
             }
        }
    });
}

Note: code is untested.

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReason.DEPTH) {
                 System.out.println("An incoming transaction was just seen in at least one block.");
             }
        }
    });
}

Note: code is untested.

EDIT

This also works:

override def onCoinsReceived(
  wallet: Wallet,
  transaction: Transaction,
  prevBalance: Coin,
  newBalance: Coin
) {
  ...

  transaction.getConfidence().addEventListener(new TransactionConfidence.Listener() {
    def onConfidenceChanged(confidence: TransactionConfidence, reason: TransactionConfidence.Listener.ChangeReason) {
      DefaultCoinSelector.isSelectable(transaction) {
        // spend here
      }
    }
  }
}
Source Link
Nick ODell
  • 29.5k
  • 11
  • 73
  • 132

Technically speaking, the coins are spendable immediately; they'll just take longer to spend and cost more in transaction fees. But to know when the coins are confirmed, in onCoinsRecieved:

If you want to know when such a transaction receives its first confirmation, register a TransactionConfidence event listener using the object retrieved via Transaction.getConfidence(). It's safe to modify the wallet in this callback, for example, by spending the transaction just received.

(Source.)

Use something like this:

public void onCoinsReceived(Wallet wallet,
                            Transaction tx,
                            Coin prevBalance,
                            Coin newBalance) {
    TransactionConfidence confidence = Transaction.getConfidence();
    confidence.addEventListener(new TransactionConfidence.Listener() {
        public void onConfidenceChanged(Transaction tx,
                         TransactionConfidence.Listener.ChangeReason reason) {
             if(reason == TransactionConfidence.Listener.ChangeReason.DEPTH) {
                 System.out.println("An incoming transaction was just seen in at least one block.");
             }
        }
    });
}

Note: code is untested.