Dmitrii Pisarenko
unread,Dec 9, 2021, 5:16:06 AM12/9/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to bitcoinj
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();
}
}
}