use of com.neemre.btcdcli4j.core.BitcoindException in project bisq-core by bisq-network.
the class RpcService method setup.
public void setup() throws BsqBlockchainException {
try {
long startTs = System.currentTimeMillis();
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
CloseableHttpClient httpProvider = HttpClients.custom().setConnectionManager(cm).build();
Properties nodeConfig = new Properties();
nodeConfig.setProperty("node.bitcoind.rpc.protocol", "http");
nodeConfig.setProperty("node.bitcoind.rpc.host", "127.0.0.1");
nodeConfig.setProperty("node.bitcoind.rpc.auth_scheme", "Basic");
nodeConfig.setProperty("node.bitcoind.rpc.user", rpcUser);
nodeConfig.setProperty("node.bitcoind.rpc.password", rpcPassword);
nodeConfig.setProperty("node.bitcoind.rpc.port", rpcPort);
nodeConfig.setProperty("node.bitcoind.notification.block.port", rpcBlockPort);
nodeConfig.setProperty("node.bitcoind.notification.alert.port", "64647");
nodeConfig.setProperty("node.bitcoind.notification.wallet.port", "64648");
nodeConfig.setProperty("node.bitcoind.http.auth_scheme", "Basic");
BtcdClientImpl client = new BtcdClientImpl(httpProvider, nodeConfig);
daemon = new BtcdDaemonImpl(client);
log.info("Setup took {} ms", System.currentTimeMillis() - startTs);
this.client = client;
} catch (BitcoindException | CommunicationException e) {
if (e instanceof CommunicationException)
log.error("Probably Bitcoin core is not running or the rpc port is not set correctly. rpcPort=" + rpcPort);
log.error(e.toString());
e.printStackTrace();
log.error(e.getCause() != null ? e.getCause().toString() : "e.getCause()=null");
throw new BsqBlockchainException(e.getMessage(), e);
} catch (Throwable e) {
log.error(e.toString());
e.printStackTrace();
throw new BsqBlockchainException(e.toString(), e);
}
}
use of com.neemre.btcdcli4j.core.BitcoindException in project bisq-core by bisq-network.
the class RpcService method requestTx.
public Tx requestTx(String txId, int blockHeight) throws BsqBlockchainException {
try {
RawTransaction rawTransaction = requestRawTransaction(txId);
// rawTransaction.getTime() is in seconds but we keep it in ms internally
final long time = rawTransaction.getTime() * 1000;
final List<TxInput> txInputs = rawTransaction.getVIn().stream().filter(rawInput -> rawInput != null && rawInput.getVOut() != null && rawInput.getTxId() != null).map(rawInput -> new TxInput(rawInput.getTxId(), rawInput.getVOut())).collect(Collectors.toList());
final List<TxOutput> txOutputs = rawTransaction.getVOut().stream().filter(e -> e != null && e.getN() != null && e.getValue() != null && e.getScriptPubKey() != null).map(rawOutput -> {
byte[] opReturnData = null;
final com.neemre.btcdcli4j.core.domain.PubKeyScript scriptPubKey = rawOutput.getScriptPubKey();
if (scriptPubKey.getType().equals(ScriptTypes.NULL_DATA)) {
String[] chunks = scriptPubKey.getAsm().split(" ");
// We get on testnet a lot of "OP_RETURN 0" data, so we filter those away
if (chunks.length == 2 && chunks[0].equals("OP_RETURN") && !"0".equals(chunks[1])) {
try {
opReturnData = Utils.HEX.decode(chunks[1]);
} catch (Throwable t) {
// We get sometimes exceptions, seems BitcoinJ
// cannot handle all existing OP_RETURN data, but we ignore them
// anyway as our OP_RETURN data is valid in BitcoinJ
log.warn("Error at Utils.HEX.decode(chunks[1]): " + t.toString() + " / chunks[1]=" + chunks[1]);
}
}
}
// We don't support raw MS which are the only case where scriptPubKey.getAddresses()>1
String address = scriptPubKey.getAddresses() != null && scriptPubKey.getAddresses().size() == 1 ? scriptPubKey.getAddresses().get(0) : null;
final PubKeyScript pubKeyScript = dumpBlockchainData ? new PubKeyScript(scriptPubKey) : null;
return new TxOutput(rawOutput.getN(), rawOutput.getValue().movePointRight(8).longValue(), rawTransaction.getTxId(), pubKeyScript, address, opReturnData, blockHeight);
}).collect(Collectors.toList());
return new Tx(txId, blockHeight, rawTransaction.getBlockHash(), time, ImmutableList.copyOf(txInputs), ImmutableList.copyOf(txOutputs));
} catch (BitcoindException | CommunicationException e) {
log.error("error at requestTx with txId={}, blockHeight={}", txId, blockHeight);
throw new BsqBlockchainException(e.getMessage(), e);
}
}
use of com.neemre.btcdcli4j.core.BitcoindException in project bisq-core by bisq-network.
the class RpcService method requestFees.
public void requestFees(String txId, int blockHeight, Map<Integer, Long> feesByBlock) throws BsqBlockchainException {
try {
Transaction transaction = requestTx(txId);
final BigDecimal fee = transaction.getFee();
if (fee != null)
feesByBlock.put(blockHeight, Math.abs(fee.multiply(BigDecimal.valueOf(Coin.COIN.value)).longValue()));
} catch (BitcoindException | CommunicationException e) {
log.error("error at requestFees with txId={}, blockHeight={}", txId, blockHeight);
throw new BsqBlockchainException(e.getMessage(), e);
}
}
Aggregations