How do I get the address that received a payment?

1

1

I am using BitcoinJ and wondering who user that I should credit, all users have their own receiving addresses. Please post an example also, if you have time. :) Current code:

    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String txid = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address; // The receive address that the payment was sent to.
            int UserID = MySQL.getUserIDbyAddress(address);
            // Here will I credit the user.
        }
    });

HydroTekZ

Posted 2015-05-06T12:16:55.720

Reputation: 21

I'm afraid I don't understand the question. It sounds like you have some piece of information and you want to get some other piece, but it's not clear to me exactly what those pieces are.Nate Eldredge 2015-05-07T06:27:14.983

@NateEldredge I think he wants the address that recieved the payment, given the arguments to onCoinsReceived. Is that correct, HydroTekZ?Nick ODell 2015-05-07T14:43:52.373

It is very correct, @NickOdell. NateEldredge, I want to get the address that recived the payment.HydroTekZ 2015-05-08T11:00:15.640

Please don't offer people money. It's against SE's policies.Nick ODell 2015-05-08T14:52:56.270

Sorry, never mind about the money then... Anyways, do somebody know how I can get the address that recive a payment?HydroTekZ 2015-05-08T19:22:55.557

Answers

1

I found out in the end how to do it, here you can see:

    wallet.addEventListener(new AbstractWalletEventListener(){
        @Override
        public void onCoinsReceived(Wallet wallet, Transaction tx, Coin prevBalance, Coin newBalance) {
            String hash = tx.getHashAsString();
            long received = newBalance.value-prevBalance.value;
            String address = null;
            for (TransactionOutput txop : tx.getOutputs()){
                if (txop.isMine(wallet)){
                    address = txop.getScriptPubKey().getToAddress(params).toString();
                }
            }
            int UserID = MySQL.getUserIDbyAddress(address);
            // Code...
        }
    });

HydroTekZ

Posted 2015-05-06T12:16:55.720

Reputation: 21