Hello!

I have a addCoinsReceivedEventListener which is invoked whenever I send 
Bitcoin to the correct address via bitcoin-cli (using a call like 
`bitcoin-cli -regtest sendtoaddress 2MwnQZ9zqU7hH9h4DVWiudGeuPS1GbQRGrx 1`):

kit.wallet().addCoinsReceivedEventListener((wallet, tx, prevBalance, 
newBalance) -> {
        // I want to read transaction comment here                
});

I want to be able to add a comment to a transaction.

When I send Bitcoin, I use this command:

bitcoin-cli -regtest sendtoaddress 2MwnQZ9zqU7hH9h4DVWiudGeuPS1GbQRGrx 1 
"Comment 4"

Questions:

1. Is it possible to read the comment ("Comment 4" in this case) in the 
addCoinsReceivedEventListener? If yes, how?

2. Am using the correct bitcoin-cli command to send Bitcoin with comment?

Thanks in advance

Dmitrii Pisarenko

P. S.: Below you can find the full source code of the wallet listener.

import org.bitcoinj.core.Address;
import org.bitcoinj.core.Coin;
import org.bitcoinj.kits.WalletAppKit;
import org.bitcoinj.utils.BriefLogFormatter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.Optional;

@Component
public class WalletObserver {
    @Autowired
    ClojureService clojureService;

    @Value("${accounts.btc.exchange.address}")
    String exchangeAddress;

    @PostConstruct
    public void init() {
        BriefLogFormatter.init();
        final LocalTestNetParams netParams = new LocalTestNetParams();
        netParams.setPort(18444);

        try {
            final WalletAppKit kit = new WalletAppKit(netParams, new 
File("."), "_minimalCryptoExchangeBtcWallet");
            kit.connectToLocalHost();
            kit.startAsync();
            kit.awaitRunning();

            kit.wallet().addWatchedAddress(Address.fromString(netParams, 
 exchangeAddress));

            kit.wallet().addCoinsReceivedEventListener((wallet, tx, 
prevBalance, newBalance) -> {
                                // I want to read transaction comment here 
               
            });
        }
        catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

-- 
You received this message because you are subscribed to the Google Groups 
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bitcoinj/ea6325e0-5303-46cb-b503-66ca9d234788n%40googlegroups.com.

Reply via email to