diff --git a/.gitignore b/.gitignore index 72bb3ff..b3377c7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,6 @@ target/ # Project-specific patterns logs/ -cloc_analysis_14122015.txt \ No newline at end of file +cloc_analysis_14122015.txt + +.idea/ diff --git a/README.md b/README.md index 872d968..8336991 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ Other dependencies: If you want to test locally (i.e. not checking in changes to github and doing a jitpack release), run `mvn install`, which will publish jars to your local maven repo as such: "com.github.bitsoex.btcd-cli4j:btcd-cli4j-core:1.0-SNAPSHOT" +``` +Make sure about setting the SDK 8 version for the project when using maven install from IDEA or set your JAVA_HOME to Java 1.8 when using it from terminal +``` + In your code depending upon this library, change your dependency to this snapshot version. You might need to instruct your gradle to search your local maven, so add this to your build.gradle file: repositories { diff --git a/core/pom.xml b/core/pom.xml index 9146f3c..202a184 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,48 +1,53 @@ - 4.0.0 - - com.github.bitsoex.btcd-cli4j - btcd-cli4j-parent - 1.0-SNAPSHOT - - btcd-cli4j-core - jar + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + + com.github.bitsoex.btcd-cli4j + btcd-cli4j-parent + 1.0-SNAPSHOT + + btcd-cli4j-core + jar - btcd-cli4j Core - A set of tools for working with the JSON-RPC API provided by Bitcoin Core + btcd-cli4j Core + A set of tools for working with the JSON-RPC API provided by Bitcoin Core - - - org.apache.httpcomponents - httpclient - 4.3.6 - - - com.fasterxml.jackson.core - jackson-core - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-annotations - ${jackson.version} - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - org.slf4j - slf4j-api - ${slf4j.version} - - - org.apache.commons - commons-lang3 - ${commons-lang.version} - - - \ No newline at end of file + + + com.github.bitsoex.btcd-cli4j + btcd-cli4j-proto + ${project.parent.version} + + + org.apache.httpcomponents + httpclient + 4.3.6 + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.apache.commons + commons-lang3 + ${commons-lang.version} + + + diff --git a/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClient.java b/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClient.java index 3a45cf5..e9745aa 100644 --- a/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClient.java +++ b/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClient.java @@ -4,8 +4,10 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Properties; +import com.bitso.model.BtcdServiceProto; import com.neemre.btcdcli4j.core.BitcoindException; import com.neemre.btcdcli4j.core.CommunicationException; import com.neemre.btcdcli4j.core.domain.Account; @@ -167,6 +169,8 @@ List getRawMemPool(Boolean isDetailed) throws BitcoindExceptio String getRawTransaction(String txId) throws BitcoindException, CommunicationException; + Optional getRawTransactionResponse(String txId); + Object getRawTransaction(String txId, Integer verbosity) throws BitcoindException, CommunicationException; diff --git a/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClientImpl.java b/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClientImpl.java index d0531e6..3e2154a 100644 --- a/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClientImpl.java +++ b/core/src/main/java/com/neemre/btcdcli4j/core/client/BtcdClientImpl.java @@ -5,9 +5,13 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Properties; +import com.bitso.model.BtcdServiceProto; +import com.neemre.btcdcli4j.core.NodeProperties; import com.neemre.btcdcli4j.core.domain.*; +import com.neemre.btcdcli4j.core.grpc.BtcdGrpcClient; import org.apache.http.impl.client.CloseableHttpClient; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -28,37 +32,39 @@ public class BtcdClientImpl implements BtcdClient { private ClientConfigurator configurator; private JsonRpcClient rpcClient; - + private BtcdGrpcClient grpcClient; public BtcdClientImpl(Properties nodeConfig) throws BitcoindException, CommunicationException { this(null, nodeConfig); } - public BtcdClientImpl(CloseableHttpClient httpProvider, Properties nodeConfig) + public BtcdClientImpl(CloseableHttpClient httpProvider, Properties nodeConfig) throws BitcoindException, CommunicationException { initialize(); - rpcClient = new JsonRpcClientImpl(configurator.checkHttpProvider(httpProvider), + grpcClient = new BtcdGrpcClient(nodeConfig.getProperty(NodeProperties.RPC_HOST.getDefaultValue()), + Integer.parseInt(NodeProperties.RPC_PORT.getDefaultValue())); + rpcClient = new JsonRpcClientImpl(configurator.checkHttpProvider(httpProvider), configurator.checkNodeConfig(nodeConfig)); configurator.checkNodeVersion(getNetworkInfo().getVersion()); configurator.checkNodeHealth((Block)getBlock(getBestBlockHash(), true)); } - public BtcdClientImpl(String rpcUser, String rpcPassword) throws BitcoindException, + public BtcdClientImpl(String rpcUser, String rpcPassword) throws BitcoindException, CommunicationException { this(null, null, rpcUser, rpcPassword); } - public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcUser, String rpcPassword) + public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcUser, String rpcPassword) throws BitcoindException, CommunicationException { this(httpProvider, null, null, rpcUser, rpcPassword); } - public BtcdClientImpl(String rpcHost, Integer rpcPort, String rpcUser, String rpcPassword) + public BtcdClientImpl(String rpcHost, Integer rpcPort, String rpcUser, String rpcPassword) throws BitcoindException, CommunicationException { this((String)null, rpcHost, rpcPort, rpcUser, rpcPassword); } - public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcHost, Integer rpcPort, + public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcHost, Integer rpcPort, String rpcUser, String rpcPassword) throws BitcoindException, CommunicationException { this(httpProvider, null, rpcHost, rpcPort, rpcUser, rpcPassword); } @@ -69,36 +75,36 @@ public BtcdClientImpl(String rpcProtocol, String rpcHost, Integer rpcPort, Strin } public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcProtocol, String rpcHost, - Integer rpcPort, String rpcUser, String rpcPassword) throws BitcoindException, + Integer rpcPort, String rpcUser, String rpcPassword) throws BitcoindException, CommunicationException { this(httpProvider, rpcProtocol, rpcHost, rpcPort, rpcUser, rpcPassword, null); } - public BtcdClientImpl(String rpcProtocol, String rpcHost, Integer rpcPort, String rpcUser, - String rpcPassword, String httpAuthScheme) throws BitcoindException, + public BtcdClientImpl(String rpcProtocol, String rpcHost, Integer rpcPort, String rpcUser, + String rpcPassword, String httpAuthScheme) throws BitcoindException, CommunicationException { this(null, rpcProtocol, rpcHost, rpcPort, rpcUser, rpcPassword, httpAuthScheme); } public BtcdClientImpl(CloseableHttpClient httpProvider, String rpcProtocol, String rpcHost, - Integer rpcPort, String rpcUser, String rpcPassword, String httpAuthScheme) + Integer rpcPort, String rpcUser, String rpcPassword, String httpAuthScheme) throws BitcoindException, CommunicationException { - this(httpProvider, new ClientConfigurator().toProperties(rpcProtocol, rpcHost, rpcPort, + this(httpProvider, new ClientConfigurator().toProperties(rpcProtocol, rpcHost, rpcPort, rpcUser, rpcPassword, httpAuthScheme)); } @Override - public String addMultiSigAddress(Integer minSignatures, List addresses) + public String addMultiSigAddress(Integer minSignatures, List addresses) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(minSignatures, addresses); - String multiSigAddressJson = rpcClient.execute(Commands.ADD_MULTI_SIG_ADDRESS.getName(), + String multiSigAddressJson = rpcClient.execute(Commands.ADD_MULTI_SIG_ADDRESS.getName(), params); String multiSigAddress = rpcClient.getParser().parseString(multiSigAddressJson); - return multiSigAddress; + return multiSigAddress; } @Override - public String addMultiSigAddress(Integer minSignatures, List addresses, + public String addMultiSigAddress(Integer minSignatures, List addresses, String account) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(minSignatures, addresses, account); String multiSigAddressJson = rpcClient.execute(Commands.ADD_MULTI_SIG_ADDRESS.getName(), @@ -108,7 +114,7 @@ public String addMultiSigAddress(Integer minSignatures, List addresses, } @Override - public void addNode(String node, String command) throws BitcoindException, + public void addNode(String node, String command) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(node, command); rpcClient.execute(Commands.ADD_NODE.getName(), params); @@ -124,17 +130,17 @@ public MultiSigAddress createMultiSig(Integer minSignatures, List addres throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(minSignatures, addresses); String multiSigAddressJson = rpcClient.execute(Commands.CREATE_MULTI_SIG.getName(), params); - MultiSigAddress multiSigAddress = rpcClient.getMapper().mapToEntity(multiSigAddressJson, + MultiSigAddress multiSigAddress = rpcClient.getMapper().mapToEntity(multiSigAddressJson, MultiSigAddress.class); return multiSigAddress; } @Override - public String createRawTransaction(List outputs, + public String createRawTransaction(List outputs, Map toAddresses) throws BitcoindException, CommunicationException { toAddresses = NumberUtils.setValueScale(toAddresses, Defaults.DECIMAL_SCALE); List params = CollectionUtils.asList(outputs, toAddresses); - String hexTransactionJson = rpcClient.execute(Commands.CREATE_RAW_TRANSACTION.getName(), + String hexTransactionJson = rpcClient.execute(Commands.CREATE_RAW_TRANSACTION.getName(), params); String hexTransaction = rpcClient.getParser().parseString(hexTransactionJson); return hexTransaction; @@ -156,11 +162,11 @@ public RawTransactionOverview decodeRawTransaction(String hexTransaction, Boolea } @Override - public RedeemScript decodeScript(String hexRedeemScript) throws BitcoindException, + public RedeemScript decodeScript(String hexRedeemScript) throws BitcoindException, CommunicationException { - String redeemScriptJson = rpcClient.execute(Commands.DECODE_SCRIPT.getName(), + String redeemScriptJson = rpcClient.execute(Commands.DECODE_SCRIPT.getName(), hexRedeemScript); - RedeemScript redeemScript = rpcClient.getMapper().mapToEntity(redeemScriptJson, + RedeemScript redeemScript = rpcClient.getMapper().mapToEntity(redeemScriptJson, RedeemScript.class); redeemScript.setHex(hexRedeemScript); return redeemScript; @@ -179,7 +185,7 @@ public void dumpWallet(String filePath) throws BitcoindException, CommunicationE } @Override - public String encryptWallet(String passphrase) throws BitcoindException, + public String encryptWallet(String passphrase) throws BitcoindException, CommunicationException { String noticeMsgJson = rpcClient.execute(Commands.ENCRYPT_WALLET.getName(), passphrase); String noticeMsg = rpcClient.getParser().parseString(noticeMsgJson); @@ -196,9 +202,9 @@ public BigDecimal estimateSmartFee(Integer maxBlocks, EstimateFee.Mode mode) thr } @Override - public BigDecimal estimatePriority(Integer maxBlocks) throws BitcoindException, + public BigDecimal estimatePriority(Integer maxBlocks) throws BitcoindException, CommunicationException { - String estimatedPriorityJson = rpcClient.execute(Commands.ESTIMATE_PRIORITY.getName(), + String estimatedPriorityJson = rpcClient.execute(Commands.ESTIMATE_PRIORITY.getName(), maxBlocks); BigDecimal estimatedPriority = rpcClient.getParser().parseBigDecimal(estimatedPriorityJson); return estimatedPriority; @@ -212,7 +218,7 @@ public String getAccount(String address) throws BitcoindException, Communication } @Override - public String getAccountAddress(String account) throws BitcoindException, + public String getAccountAddress(String account) throws BitcoindException, CommunicationException { String addressJson = rpcClient.execute(Commands.GET_ACCOUNT_ADDRESS.getName(), account); String address = rpcClient.getParser().parseString(addressJson); @@ -222,27 +228,27 @@ public String getAccountAddress(String account) throws BitcoindException, @Override public List getAddedNodeInfo(Boolean withDetails) throws BitcoindException, CommunicationException { - String addedNodesJson = rpcClient.execute(Commands.GET_ADDED_NODE_INFO.getName(), + String addedNodesJson = rpcClient.execute(Commands.GET_ADDED_NODE_INFO.getName(), withDetails); - List addedNodes = rpcClient.getMapper().mapToList(addedNodesJson, + List addedNodes = rpcClient.getMapper().mapToList(addedNodesJson, AddedNode.class); return addedNodes; } @Override - public List getAddedNodeInfo(Boolean withDetails, String node) + public List getAddedNodeInfo(Boolean withDetails, String node) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(withDetails, node); String addedNodesJson = rpcClient.execute(Commands.GET_ADDED_NODE_INFO.getName(), params); - List addedNodes = rpcClient.getMapper().mapToList(addedNodesJson, + List addedNodes = rpcClient.getMapper().mapToList(addedNodesJson, AddedNode.class); return addedNodes; } @Override - public List getAddressesByAccount(String account) throws BitcoindException, + public List getAddressesByAccount(String account) throws BitcoindException, CommunicationException { - String addressesJson = rpcClient.execute(Commands.GET_ADDRESSES_BY_ACCOUNT.getName(), + String addressesJson = rpcClient.execute(Commands.GET_ADDRESSES_BY_ACCOUNT.getName(), account); List addresses = rpcClient.getMapper().mapToList(addressesJson, String.class); return addresses; @@ -263,7 +269,7 @@ public BigDecimal getBalance(String account) throws BitcoindException, Communica } @Override - public BigDecimal getBalance(String account, Integer confirmations) throws BitcoindException, + public BigDecimal getBalance(String account, Integer confirmations) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(account, confirmations); String balanceJson = rpcClient.execute(Commands.GET_BALANCE.getName(), params); @@ -295,7 +301,7 @@ public Block getBlock(String headerHash) throws BitcoindException, Communication } @Override - public Object getBlock(String headerHash, Boolean isDecoded) throws BitcoindException, + public Object getBlock(String headerHash, Boolean isDecoded) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(headerHash, isDecoded); String blockJson = rpcClient.execute(Commands.GET_BLOCK.getName(), params); @@ -311,9 +317,9 @@ public Object getBlock(String headerHash, Boolean isDecoded) throws BitcoindExce @Override public BlockChainInfo getBlockChainInfo() throws BitcoindException, CommunicationException { String blockChainInfoJson = rpcClient.execute(Commands.GET_BLOCK_CHAIN_INFO.getName()); - BlockChainInfo blockChainInfo = rpcClient.getMapper().mapToEntity(blockChainInfoJson, + BlockChainInfo blockChainInfo = rpcClient.getMapper().mapToEntity(blockChainInfoJson, BlockChainInfo.class); - return blockChainInfo; + return blockChainInfo; } @Override @@ -324,7 +330,7 @@ public Integer getBlockCount() throws BitcoindException, CommunicationException } @Override - public String getBlockHash(Integer blockHeight) throws BitcoindException, + public String getBlockHash(Integer blockHeight) throws BitcoindException, CommunicationException { String headerHashJson = rpcClient.execute(Commands.GET_BLOCK_HASH.getName(), blockHeight); String headerHash = rpcClient.getParser().parseString(headerHashJson); @@ -376,7 +382,7 @@ public Info getInfo() throws BitcoindException, CommunicationException { @Override public MemPoolInfo getMemPoolInfo() throws BitcoindException, CommunicationException { String memPoolInfoJson = rpcClient.execute(Commands.GET_MEM_POOL_INFO.getName()); - MemPoolInfo memPoolInfo = rpcClient.getMapper().mapToEntity(memPoolInfoJson, + MemPoolInfo memPoolInfo = rpcClient.getMapper().mapToEntity(memPoolInfoJson, MemPoolInfo.class); return memPoolInfo; } @@ -391,7 +397,7 @@ public MiningInfo getMiningInfo() throws BitcoindException, CommunicationExcepti @Override public NetworkTotals getNetTotals() throws BitcoindException, CommunicationException { String netTotalsJson = rpcClient.execute(Commands.GET_NET_TOTALS.getName()); - NetworkTotals netTotals = rpcClient.getMapper().mapToEntity(netTotalsJson, + NetworkTotals netTotals = rpcClient.getMapper().mapToEntity(netTotalsJson, NetworkTotals.class); return netTotals; } @@ -404,7 +410,7 @@ public BigInteger getNetworkHashPs() throws BitcoindException, CommunicationExce } @Override - public BigInteger getNetworkHashPs(Integer blocks) throws BitcoindException, + public BigInteger getNetworkHashPs(Integer blocks) throws BitcoindException, CommunicationException { String networkHashPsJson = rpcClient.execute(Commands.GET_NETWORK_HASH_PS.getName(), blocks); BigInteger networkHashPs = rpcClient.getParser().parseBigInteger(networkHashPsJson); @@ -423,7 +429,7 @@ public BigInteger getNetworkHashPs(Integer blocks, Integer blockHeight) throws B @Override public NetworkInfo getNetworkInfo() throws BitcoindException, CommunicationException { String networkInfoJson = rpcClient.execute(Commands.GET_NETWORK_INFO.getName()); - NetworkInfo networkInfo = rpcClient.getMapper().mapToEntity(networkInfoJson, + NetworkInfo networkInfo = rpcClient.getMapper().mapToEntity(networkInfoJson, NetworkInfo.class); return networkInfo; } @@ -464,7 +470,7 @@ public List getRawMemPool() throws BitcoindException, CommunicationExcep } @Override - public List getRawMemPool(Boolean isDetailed) throws BitcoindException, + public List getRawMemPool(Boolean isDetailed) throws BitcoindException, CommunicationException { String memPoolTxnsJson = rpcClient.execute(Commands.GET_RAW_MEM_POOL.getName(), isDetailed); if (isDetailed) { @@ -475,12 +481,23 @@ public List getRawMemPool(Boolean isDetailed) throws BitcoindE } return new ArrayList(memPoolTxns.values()); } else { - List memPoolTxns = rpcClient.getMapper().mapToList(memPoolTxnsJson, + List memPoolTxns = rpcClient.getMapper().mapToList(memPoolTxnsJson, String.class); return memPoolTxns; } } + @Override + public Optional getRawTransactionResponse(String txId){ + + BtcdServiceProto.GetRawTransactionRequest request = BtcdServiceProto.GetRawTransactionRequest.newBuilder() + .setTxid(txId) + .setVerbose(true) + .build(); + + return grpcClient.getRawTransaction(request); + } + @Override public String getRawTransaction(String txId) throws BitcoindException, CommunicationException { String hexTransactionJson = rpcClient.execute(Commands.GET_RAW_TRANSACTION.getName(), txId); @@ -488,8 +505,9 @@ public String getRawTransaction(String txId) throws BitcoindException, Communica return hexTransaction; } + @Deprecated @Override - public Object getRawTransaction(String txId, Integer verbosity) throws BitcoindException, + public Object getRawTransaction(String txId, Integer verbosity) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(txId, verbosity); String transactionJson = rpcClient.execute(Commands.GET_RAW_TRANSACTION.getName(), params); @@ -497,7 +515,7 @@ public Object getRawTransaction(String txId, Integer verbosity) throws BitcoindE String hexTransaction = rpcClient.getParser().parseString(transactionJson); return hexTransaction; } else { - RawTransaction rawTransaction = rpcClient.getMapper().mapToEntity(transactionJson, + RawTransaction rawTransaction = rpcClient.getMapper().mapToEntity(transactionJson, RawTransaction.class); // make a replacement for list of addresses with the unique address present rawTransaction.getVOut() @@ -524,7 +542,7 @@ void setVoutAddressToList(PubKeyScript pubKeyScript) { } @Override - public BigDecimal getReceivedByAccount(String account) throws BitcoindException, + public BigDecimal getReceivedByAccount(String account) throws BitcoindException, CommunicationException { String totalReceivedJson = rpcClient.execute(Commands.GET_RECEIVED_BY_ACCOUNT.getName(), account); @@ -533,17 +551,17 @@ public BigDecimal getReceivedByAccount(String account) throws BitcoindException, } @Override - public BigDecimal getReceivedByAccount(String account, Integer confirmations) + public BigDecimal getReceivedByAccount(String account, Integer confirmations) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(account, confirmations); - String totalReceivedJson = rpcClient.execute(Commands.GET_RECEIVED_BY_ACCOUNT.getName(), + String totalReceivedJson = rpcClient.execute(Commands.GET_RECEIVED_BY_ACCOUNT.getName(), params); BigDecimal totalReceived = rpcClient.getParser().parseBigDecimal(totalReceivedJson); return totalReceived; } @Override - public BigDecimal getReceivedByAddress(String address) throws BitcoindException, + public BigDecimal getReceivedByAddress(String address) throws BitcoindException, CommunicationException { String totalReceivedJson = rpcClient.execute(Commands.GET_RECEIVED_BY_ADDRESS.getName(), address); @@ -552,7 +570,7 @@ public BigDecimal getReceivedByAddress(String address) throws BitcoindException, } @Override - public BigDecimal getReceivedByAddress(String address, Integer confirmations) + public BigDecimal getReceivedByAddress(String address, Integer confirmations) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, confirmations); String totalReceivedJson = rpcClient.execute(Commands.GET_RECEIVED_BY_ADDRESS.getName(), @@ -562,7 +580,7 @@ public BigDecimal getReceivedByAddress(String address, Integer confirmations) } @Override - public Transaction getTransaction(String txId) throws BitcoindException, + public Transaction getTransaction(String txId) throws BitcoindException, CommunicationException { String transactionJson = rpcClient.execute(Commands.GET_TRANSACTION.getName(), txId); Transaction transaction = rpcClient.getMapper().mapToEntity(transactionJson, @@ -583,7 +601,7 @@ public Transaction getTransaction(String txId, Boolean withWatchOnly) throws Bit @Override public TxOutSetInfo getTxOutSetInfo() throws BitcoindException, CommunicationException { String txnOutSetInfoJson = rpcClient.execute(Commands.GET_TX_OUT_SET_INFO.getName()); - TxOutSetInfo txnOutSetInfo = rpcClient.getMapper().mapToEntity(txnOutSetInfoJson, + TxOutSetInfo txnOutSetInfo = rpcClient.getMapper().mapToEntity(txnOutSetInfoJson, TxOutSetInfo.class); return txnOutSetInfo; } @@ -593,7 +611,7 @@ public BigDecimal getUnconfirmedBalance() throws BitcoindException, Communicatio String unconfirmedBalanceJson = rpcClient.execute(Commands.GET_UNCONFIRMED_BALANCE.getName()); BigDecimal unconfirmedBalance = rpcClient.getParser().parseBigDecimal(unconfirmedBalanceJson); return unconfirmedBalance; - } + } @Override public WalletInfo getWalletInfo() throws BitcoindException, CommunicationException { @@ -622,14 +640,14 @@ public void importAddress(String address) throws BitcoindException, Communicatio } @Override - public void importAddress(String address, String account) throws BitcoindException, + public void importAddress(String address, String account) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, account); rpcClient.execute(Commands.IMPORT_ADDRESS.getName(), params); } @Override - public void importAddress(String address, String account, Boolean withRescan) + public void importAddress(String address, String account, Boolean withRescan) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, account, withRescan); rpcClient.execute(Commands.IMPORT_ADDRESS.getName(), params); @@ -641,14 +659,14 @@ public void importPrivKey(String privateKey) throws BitcoindException, Communica } @Override - public void importPrivKey(String privateKey, String account) throws BitcoindException, + public void importPrivKey(String privateKey, String account) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(privateKey, account); rpcClient.execute(Commands.IMPORT_PRIV_KEY.getName(), params); } @Override - public void importPrivKey(String privateKey, String account, Boolean withRescan) + public void importPrivKey(String privateKey, String account, Boolean withRescan) throws BitcoindException, CommunicationException{ List params = CollectionUtils.asList(privateKey, account, withRescan); rpcClient.execute(Commands.IMPORT_PRIV_KEY.getName(), params); @@ -665,7 +683,7 @@ public void keyPoolRefill() throws BitcoindException, CommunicationException { } @Override - public void keyPoolRefill(Integer keypoolSize) throws BitcoindException, + public void keyPoolRefill(Integer keypoolSize) throws BitcoindException, CommunicationException { rpcClient.execute(Commands.KEY_POOL_REFILL.getName(), keypoolSize); } @@ -673,38 +691,38 @@ public void keyPoolRefill(Integer keypoolSize) throws BitcoindException, @Override public Map listAccounts() throws BitcoindException, CommunicationException { String accountsJson = rpcClient.execute(Commands.LIST_ACCOUNTS.getName()); - Map accounts = rpcClient.getMapper().mapToMap(accountsJson, + Map accounts = rpcClient.getMapper().mapToMap(accountsJson, String.class, BigDecimal.class); accounts = NumberUtils.setValueScale(accounts, Defaults.DECIMAL_SCALE); return accounts; } @Override - public Map listAccounts(Integer confirmations) throws BitcoindException, + public Map listAccounts(Integer confirmations) throws BitcoindException, CommunicationException { String accountsJson = rpcClient.execute(Commands.LIST_ACCOUNTS.getName(), confirmations); - Map accounts = rpcClient.getMapper().mapToMap(accountsJson, + Map accounts = rpcClient.getMapper().mapToMap(accountsJson, String.class, BigDecimal.class); accounts = NumberUtils.setValueScale(accounts, Defaults.DECIMAL_SCALE); return accounts; } @Override - public Map listAccounts(Integer confirmations, Boolean withWatchOnly) + public Map listAccounts(Integer confirmations, Boolean withWatchOnly) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(confirmations, withWatchOnly); String accountsJson = rpcClient.execute(Commands.LIST_ACCOUNTS.getName(), params); - Map accounts = rpcClient.getMapper().mapToMap(accountsJson, + Map accounts = rpcClient.getMapper().mapToMap(accountsJson, String.class, BigDecimal.class); accounts = NumberUtils.setValueScale(accounts, Defaults.DECIMAL_SCALE); return accounts; } @Override - public List> listAddressGroupings() throws BitcoindException, + public List> listAddressGroupings() throws BitcoindException, CommunicationException { String groupingsJson = rpcClient.execute(Commands.LIST_ADDRESS_GROUPINGS.getName()); - List> groupings = rpcClient.getMapper().mapToNestedLists(1, + List> groupings = rpcClient.getMapper().mapToNestedLists(1, groupingsJson, AddressOverview.class); return groupings; } @@ -712,7 +730,7 @@ public List> listAddressGroupings() throws BitcoindExcepti @Override public List listLockUnspent() throws BitcoindException, CommunicationException { String lockedOutputsJson = rpcClient.execute(Commands.LIST_LOCK_UNSPENT.getName()); - List lockedOutputs = rpcClient.getMapper().mapToList(lockedOutputsJson, + List lockedOutputs = rpcClient.getMapper().mapToList(lockedOutputsJson, OutputOverview.class); return lockedOutputs; } @@ -725,29 +743,29 @@ public List listReceivedByAccount() throws BitcoindException, Communica } @Override - public List listReceivedByAccount(Integer confirmations) throws BitcoindException, + public List listReceivedByAccount(Integer confirmations) throws BitcoindException, CommunicationException { - String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), + String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), confirmations); List accounts = rpcClient.getMapper().mapToList(accountsJson, Account.class); return accounts; } @Override - public List listReceivedByAccount(Integer confirmations, Boolean withUnused) + public List listReceivedByAccount(Integer confirmations, Boolean withUnused) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(confirmations, withUnused); - String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), + String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), params); List accounts = rpcClient.getMapper().mapToList(accountsJson, Account.class); return accounts; } @Override - public List listReceivedByAccount(Integer confirmations, Boolean withUnused, + public List listReceivedByAccount(Integer confirmations, Boolean withUnused, Boolean withWatchOnly) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(confirmations, withUnused, withWatchOnly); - String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), + String accountsJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ACCOUNT.getName(), params); List accounts = rpcClient.getMapper().mapToList(accountsJson, Account.class); return accounts; @@ -761,7 +779,7 @@ public List
listReceivedByAddress() throws BitcoindException, Communica } @Override - public List
listReceivedByAddress(Integer confirmations) throws BitcoindException, + public List
listReceivedByAddress(Integer confirmations) throws BitcoindException, CommunicationException { String addressesJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ADDRESS.getName(), confirmations); @@ -770,7 +788,7 @@ public List
listReceivedByAddress(Integer confirmations) throws Bitcoin } @Override - public List
listReceivedByAddress(Integer confirmations, Boolean withUnused) + public List
listReceivedByAddress(Integer confirmations, Boolean withUnused) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(confirmations, withUnused); String addressesJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ADDRESS.getName(), @@ -780,7 +798,7 @@ public List
listReceivedByAddress(Integer confirmations, Boolean withUn } @Override - public List
listReceivedByAddress(Integer confirmations, Boolean withUnused, + public List
listReceivedByAddress(Integer confirmations, Boolean withUnused, Boolean withWatchOnly) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(confirmations, withUnused, withWatchOnly); String addressesJson = rpcClient.execute(Commands.LIST_RECEIVED_BY_ADDRESS.getName(), @@ -797,7 +815,7 @@ public SinceBlock listSinceBlock() throws BitcoindException, CommunicationExcept } @Override - public SinceBlock listSinceBlock(String headerHash) throws BitcoindException, + public SinceBlock listSinceBlock(String headerHash) throws BitcoindException, CommunicationException { String sinceBlockJson = rpcClient.execute(Commands.LIST_SINCE_BLOCK.getName(), headerHash); SinceBlock sinceBlock = rpcClient.getMapper().mapToEntity(sinceBlockJson, SinceBlock.class); @@ -805,7 +823,7 @@ public SinceBlock listSinceBlock(String headerHash) throws BitcoindException, } @Override - public SinceBlock listSinceBlock(String headerHash, Integer confirmations) + public SinceBlock listSinceBlock(String headerHash, Integer confirmations) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(headerHash, confirmations); String sinceBlockJson = rpcClient.execute(Commands.LIST_SINCE_BLOCK.getName(), params); @@ -814,7 +832,7 @@ public SinceBlock listSinceBlock(String headerHash, Integer confirmations) } @Override - public SinceBlock listSinceBlock(String headerHash, Integer confirmations, + public SinceBlock listSinceBlock(String headerHash, Integer confirmations, Boolean withWatchOnly) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(headerHash, confirmations, withWatchOnly); String sinceBlockJson = rpcClient.execute(Commands.LIST_SINCE_BLOCK.getName(), params); @@ -830,7 +848,7 @@ public List listTransactions() throws BitcoindException, CommunicationE } @Override - public List listTransactions(String account) throws BitcoindException, + public List listTransactions(String account) throws BitcoindException, CommunicationException { String paymentsJson = rpcClient.execute(Commands.LIST_TRANSACTIONS.getName(), account); List payments = rpcClient.getMapper().mapToList(paymentsJson, Payment.class); @@ -838,7 +856,7 @@ public List listTransactions(String account) throws BitcoindException, } @Override - public List listTransactions(String account, Integer count) throws BitcoindException, + public List listTransactions(String account, Integer count) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(account, count); String paymentsJson = rpcClient.execute(Commands.LIST_TRANSACTIONS.getName(), params); @@ -856,7 +874,7 @@ public List listTransactions(String account, Integer count, Integer off } @Override - public List listTransactions(String account, Integer count, Integer offset, + public List listTransactions(String account, Integer count, Integer offset, Boolean withWatchOnly) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(account, count, offset, withWatchOnly); String paymentsJson = rpcClient.execute(Commands.LIST_TRANSACTIONS.getName(), params); @@ -873,9 +891,9 @@ public List listUnspent() throws BitcoindException, CommunicationExcepti } @Override - public List listUnspent(Integer minConfirmations) throws BitcoindException, + public List listUnspent(Integer minConfirmations) throws BitcoindException, CommunicationException { - String unspentOutputsJson = rpcClient.execute(Commands.LIST_UNSPENT.getName(), + String unspentOutputsJson = rpcClient.execute(Commands.LIST_UNSPENT.getName(), minConfirmations); List unspentOutputs = rpcClient.getMapper().mapToList(unspentOutputsJson, Output.class); @@ -883,7 +901,7 @@ public List listUnspent(Integer minConfirmations) throws BitcoindExcepti } @Override - public List listUnspent(Integer minConfirmations, Integer maxConfirmations) + public List listUnspent(Integer minConfirmations, Integer maxConfirmations) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(minConfirmations, maxConfirmations); String unspentOutputsJson = rpcClient.execute(Commands.LIST_UNSPENT.getName(), params); @@ -893,7 +911,7 @@ public List listUnspent(Integer minConfirmations, Integer maxConfirmatio } @Override - public List listUnspent(Integer minConfirmations, Integer maxConfirmations, + public List listUnspent(Integer minConfirmations, Integer maxConfirmations, List addresses) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(minConfirmations, maxConfirmations, addresses); String unspentOutputsJson = rpcClient.execute(Commands.LIST_UNSPENT.getName(), params); @@ -903,7 +921,7 @@ public List listUnspent(Integer minConfirmations, Integer maxConfirmatio } @Override - public Boolean lockUnspent(Boolean isUnlocked) throws BitcoindException, + public Boolean lockUnspent(Boolean isUnlocked) throws BitcoindException, CommunicationException { String isSuccessJson = rpcClient.execute(Commands.LOCK_UNSPENT.getName(), isUnlocked); Boolean isSuccess = rpcClient.getParser().parseBoolean(isSuccessJson); @@ -911,7 +929,7 @@ public Boolean lockUnspent(Boolean isUnlocked) throws BitcoindException, } @Override - public Boolean lockUnspent(Boolean isUnlocked, List outputs) + public Boolean lockUnspent(Boolean isUnlocked, List outputs) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(isUnlocked, outputs); String isSuccessJson = rpcClient.execute(Commands.LOCK_UNSPENT.getName(), params); @@ -920,7 +938,7 @@ public Boolean lockUnspent(Boolean isUnlocked, List outputs) } @Override - public Boolean move(String fromAccount, String toAccount, BigDecimal amount) + public Boolean move(String fromAccount, String toAccount, BigDecimal amount) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(fromAccount, toAccount, amount); @@ -945,7 +963,7 @@ public void ping() throws BitcoindException, CommunicationException { } @Override - public Boolean prioritiseTransaction(String txId, BigDecimal deltaPriority, Long deltaFee) + public Boolean prioritiseTransaction(String txId, BigDecimal deltaPriority, Long deltaFee) throws BitcoindException, CommunicationException { deltaPriority = deltaPriority.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(txId, deltaPriority, deltaFee); @@ -955,7 +973,7 @@ public Boolean prioritiseTransaction(String txId, BigDecimal deltaPriority, Long } @Override - public String sendFrom(String fromAccount, String toAddress, BigDecimal amount) + public String sendFrom(String fromAccount, String toAddress, BigDecimal amount) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(fromAccount, toAddress, amount); @@ -965,7 +983,7 @@ public String sendFrom(String fromAccount, String toAddress, BigDecimal amount) } @Override - public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, + public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, Integer confirmations) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(fromAccount, toAddress, amount, confirmations); @@ -975,11 +993,11 @@ public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, } @Override - public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, - Integer confirmations, String comment) throws BitcoindException, + public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, + Integer confirmations, String comment) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); - List params = CollectionUtils.asList(fromAccount, toAddress, amount, confirmations, + List params = CollectionUtils.asList(fromAccount, toAddress, amount, confirmations, comment); String transactionIdJson = rpcClient.execute(Commands.SEND_FROM.getName(), params); String transactionId = rpcClient.getParser().parseString(transactionIdJson); @@ -987,8 +1005,8 @@ public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, } @Override - public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, - Integer confirmations, String comment, String commentTo) throws BitcoindException, + public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, + Integer confirmations, String comment, String commentTo) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(fromAccount, toAddress, amount, confirmations, @@ -999,7 +1017,7 @@ public String sendFrom(String fromAccount, String toAddress, BigDecimal amount, } @Override - public String sendMany(String fromAccount, Map toAddresses) + public String sendMany(String fromAccount, Map toAddresses) throws BitcoindException, CommunicationException { toAddresses = NumberUtils.setValueScale(toAddresses, Defaults.DECIMAL_SCALE); List params = CollectionUtils.asList(fromAccount, toAddresses); @@ -1009,7 +1027,7 @@ public String sendMany(String fromAccount, Map toAddresses) } @Override - public String sendMany(String fromAccount, Map toAddresses, + public String sendMany(String fromAccount, Map toAddresses, Integer confirmations) throws BitcoindException, CommunicationException { toAddresses = NumberUtils.setValueScale(toAddresses, Defaults.DECIMAL_SCALE); List params = CollectionUtils.asList(fromAccount, toAddresses, confirmations); @@ -1020,7 +1038,7 @@ public String sendMany(String fromAccount, Map toAddresses, @Override public String sendMany(String fromAccount, Map toAddresses, - Integer confirmations, String comment) throws BitcoindException, + Integer confirmations, String comment) throws BitcoindException, CommunicationException { toAddresses = NumberUtils.setValueScale(toAddresses, Defaults.DECIMAL_SCALE); List params = CollectionUtils.asList(fromAccount, toAddresses, confirmations, @@ -1031,26 +1049,26 @@ public String sendMany(String fromAccount, Map toAddresses, } @Override - public String sendRawTransaction(String hexTransaction) throws BitcoindException, + public String sendRawTransaction(String hexTransaction) throws BitcoindException, CommunicationException { - String transactionIdJson = rpcClient.execute(Commands.SEND_RAW_TRANSACTION.getName(), + String transactionIdJson = rpcClient.execute(Commands.SEND_RAW_TRANSACTION.getName(), hexTransaction); String transactionId = rpcClient.getParser().parseString(transactionIdJson); return transactionId; } @Override - public String sendRawTransaction(String hexTransaction, Boolean withHighFees) + public String sendRawTransaction(String hexTransaction, Boolean withHighFees) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(hexTransaction, withHighFees); - String transactionIdJson = rpcClient.execute(Commands.SEND_RAW_TRANSACTION.getName(), + String transactionIdJson = rpcClient.execute(Commands.SEND_RAW_TRANSACTION.getName(), params); String transactionId = rpcClient.getParser().parseString(transactionIdJson); return transactionId; } @Override - public String sendToAddress(String toAddress, BigDecimal amount) throws BitcoindException, + public String sendToAddress(String toAddress, BigDecimal amount) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(toAddress, amount); @@ -1060,7 +1078,7 @@ public String sendToAddress(String toAddress, BigDecimal amount) throws Bitcoind } @Override - public String sendToAddress(String toAddress, BigDecimal amount, String comment) + public String sendToAddress(String toAddress, BigDecimal amount, String comment) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(toAddress, amount, comment); @@ -1070,7 +1088,7 @@ public String sendToAddress(String toAddress, BigDecimal amount, String comment) } @Override - public String sendToAddress(String toAddress, BigDecimal amount, String comment, + public String sendToAddress(String toAddress, BigDecimal amount, String comment, String commentTo) throws BitcoindException, CommunicationException { amount = amount.setScale(Defaults.DECIMAL_SCALE, Defaults.ROUNDING_MODE); List params = CollectionUtils.asList(toAddress, amount, comment, commentTo); @@ -1080,7 +1098,7 @@ public String sendToAddress(String toAddress, BigDecimal amount, String comment, } @Override - public void setAccount(String address, String account) throws BitcoindException, + public void setAccount(String address, String account) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, account); rpcClient.execute(Commands.SET_ACCOUNT.getName(), params); @@ -1088,11 +1106,11 @@ public void setAccount(String address, String account) throws BitcoindException, @Override public void setGenerate(Boolean isGenerate) throws BitcoindException, CommunicationException { - rpcClient.execute(Commands.SET_GENERATE.getName(), isGenerate); + rpcClient.execute(Commands.SET_GENERATE.getName(), isGenerate); } @Override - public void setGenerate(Boolean isGenerate, Integer processors) throws BitcoindException, + public void setGenerate(Boolean isGenerate, Integer processors) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(isGenerate, processors); rpcClient.execute(Commands.SET_GENERATE.getName(), params); @@ -1107,7 +1125,7 @@ public Boolean setTxFee(BigDecimal txFee) throws BitcoindException, Communicatio } @Override - public String signMessage(String address, String message) throws BitcoindException, + public String signMessage(String address, String message) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, message); String signatureJson = rpcClient.execute(Commands.SIGN_MESSAGE.getName(), params); @@ -1116,44 +1134,44 @@ public String signMessage(String address, String message) throws BitcoindExcepti } @Override - public SignatureResult signRawTransaction(String hexTransaction) throws BitcoindException, + public SignatureResult signRawTransaction(String hexTransaction) throws BitcoindException, CommunicationException { - String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), + String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), hexTransaction); - SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, + SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, SignatureResult.class); return signatureResult; } @Override - public SignatureResult signRawTransaction(String hexTransaction, List outputs) + public SignatureResult signRawTransaction(String hexTransaction, List outputs) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(hexTransaction, outputs); - String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), + String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), params); - SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, + SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, SignatureResult.class); return signatureResult; } @Override - public SignatureResult signRawTransaction(String hexTransaction, List outputs, + public SignatureResult signRawTransaction(String hexTransaction, List outputs, List privateKeys) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(hexTransaction, outputs, privateKeys); String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), params); - SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, + SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, SignatureResult.class); return signatureResult; } @Override - public SignatureResult signRawTransaction(String hexTransaction, List outputs, - List privateKeys, String sigHashType) throws BitcoindException, + public SignatureResult signRawTransaction(String hexTransaction, List outputs, + List privateKeys, String sigHashType) throws BitcoindException, CommunicationException { - List params = CollectionUtils.asList(hexTransaction, outputs, privateKeys, + List params = CollectionUtils.asList(hexTransaction, outputs, privateKeys, sigHashType); - String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), + String signatureResultJson = rpcClient.execute(Commands.SIGN_RAW_TRANSACTION.getName(), params); SignatureResult signatureResult = rpcClient.getMapper().mapToEntity(signatureResultJson, SignatureResult.class); @@ -1175,7 +1193,7 @@ public String submitBlock(String block) throws BitcoindException, CommunicationE } @Override - public String submitBlock(String block, Map extraParameters) + public String submitBlock(String block, Map extraParameters) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(block, extraParameters); String blockStatusJson = rpcClient.execute(Commands.SUBMIT_BLOCK.getName(), params); @@ -1184,10 +1202,10 @@ public String submitBlock(String block, Map extraParameters) } @Override - public AddressInfo validateAddress(String address) throws BitcoindException, + public AddressInfo validateAddress(String address) throws BitcoindException, CommunicationException { String addressInfoJson = rpcClient.execute(Commands.VALIDATE_ADDRESS.getName(), address); - AddressInfo addressInfo = rpcClient.getMapper().mapToEntity(addressInfoJson, + AddressInfo addressInfo = rpcClient.getMapper().mapToEntity(addressInfoJson, AddressInfo.class); return addressInfo; } @@ -1216,7 +1234,7 @@ public Boolean verifyChain(Integer checkLevel, Integer blocks) throws BitcoindEx } @Override - public Boolean verifyMessage(String address, String signature, String message) + public Boolean verifyMessage(String address, String signature, String message) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(address, signature, message); String isSigValidJson = rpcClient.execute(Commands.VERIFY_MESSAGE.getName(), params); @@ -1230,14 +1248,14 @@ public void walletLock() throws BitcoindException, CommunicationException { } @Override - public void walletPassphrase(String passphrase, Integer authTimeout) throws BitcoindException, + public void walletPassphrase(String passphrase, Integer authTimeout) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(passphrase, authTimeout); rpcClient.execute(Commands.WALLET_PASSPHRASE.getName(), params); } @Override - public void walletPassphraseChange(String curPassphrase, String newPassphrase) + public void walletPassphraseChange(String curPassphrase, String newPassphrase) throws BitcoindException, CommunicationException { List params = CollectionUtils.asList(curPassphrase, newPassphrase); rpcClient.execute(Commands.WALLET_PASSPHRASE_CHANGE.getName(), params); diff --git a/core/src/main/java/com/neemre/btcdcli4j/core/grpc/BtcdGrpcClient.java b/core/src/main/java/com/neemre/btcdcli4j/core/grpc/BtcdGrpcClient.java new file mode 100644 index 0000000..cda104a --- /dev/null +++ b/core/src/main/java/com/neemre/btcdcli4j/core/grpc/BtcdGrpcClient.java @@ -0,0 +1,47 @@ +package com.neemre.btcdcli4j.core.grpc; + +import com.bitso.model.BtcdServiceGrpc; +import com.bitso.model.BtcdServiceProto; +import com.neemre.btcdcli4j.core.grpc.config.BtcdGrpcServiceConfig; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.util.Optional; + +/** + * Class for handling grpc clients for bitcoin network nodes + */ +@Slf4j +@RequiredArgsConstructor +public class BtcdGrpcClient { + + // grpc client for node + private final BtcdServiceGrpc.BtcdServiceBlockingStub grcpClient; + + /** + * Initiate gRPC client with host and port + * @param host host + * @param port port + */ + public BtcdGrpcClient(final String host, final int port){ + grcpClient = new BtcdGrpcServiceConfig().createStub(host, port); + } + + /** + * @see getrawtransaction + * @param request get raw transaction request + * @return Optional BtcdServiceProto.GetRawTransactionResponse get raw transaction response + */ + public Optional getRawTransaction( + final BtcdServiceProto.GetRawTransactionRequest request){ + + try { + return Optional.of(grcpClient.getRawTransaction(request)); + } + catch (Exception exception){ + log.error("Error when tried 'getRawTransaction' for request: {}", request.toString()); + return Optional.empty(); + } + } + +} diff --git a/core/src/main/java/com/neemre/btcdcli4j/core/grpc/config/BtcdGrpcServiceConfig.java b/core/src/main/java/com/neemre/btcdcli4j/core/grpc/config/BtcdGrpcServiceConfig.java new file mode 100644 index 0000000..bbbaefe --- /dev/null +++ b/core/src/main/java/com/neemre/btcdcli4j/core/grpc/config/BtcdGrpcServiceConfig.java @@ -0,0 +1,27 @@ +package com.neemre.btcdcli4j.core.grpc.config; + +import com.bitso.model.BtcdServiceGrpc; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; + +/** + * Configuration to create a gRPC client for the {@code .bitsocluster.bitsoops.com} service + */ +public class BtcdGrpcServiceConfig { + + /** + * Create a blocking stub for the given host and port + * @param host host address + * @param port port address + * @return BtcdServiceGrpc.BtcdServiceBlockingStub stub + */ + public BtcdServiceGrpc.BtcdServiceBlockingStub createStub(final String host, final int port) { + + ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port) + .usePlaintext() + .build(); + + return BtcdServiceGrpc.newBlockingStub(channel); + } + +} diff --git a/pom.xml b/pom.xml index b3cc358..3376c20 100644 --- a/pom.xml +++ b/pom.xml @@ -1,110 +1,113 @@ - 4.0.0 - com.github.bitsoex.btcd-cli4j - btcd-cli4j-parent - 1.0-SNAPSHOT - pom + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 + com.github.bitsoex.btcd-cli4j + btcd-cli4j-parent + 1.0-SNAPSHOT + pom - btcd-cli4j Parent - A simple Java wrapper around Bitcoin Core's JSON-RPC (via HTTP) interface - http://btcd-cli4j.neemre.com/ + btcd-cli4j Parent + A simple Java wrapper around Bitcoin Core's JSON-RPC (via HTTP) interface + http://btcd-cli4j.neemre.com/ - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - + + + The Apache Software License, Version 2.0 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + + - - core - daemon - examples - + + core + daemon + examples + proto + - - - mvn-nemp-ftp - Nemp's Maven Repository - ftp://nemp.planet.ee/htdocs/mvn/ - - + + + mvn-nemp-ftp + Nemp's Maven Repository + ftp://nemp.planet.ee/htdocs/mvn/ + + - - UTF-8 + + UTF-8 - 1.8 - 2.9.0 - 1.7.25 - 3.3.2 - + 1.8 + 2.9.0 + 1.3.2 + 1.7.25 + 3.3.2 + 1.49.1 + - - - org.projectlombok - lombok - 1.18.2 - provided - - + + + org.projectlombok + lombok + 1.18.2 + provided + + - - - - org.apache.maven.wagon - wagon-ftp - 2.8 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.2 - - ${jdk.version} - ${jdk.version} - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - org.apache.maven.plugins - maven-source-plugin - 2.4 - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-project-info-reports-plugin - 2.8 - - - - \ No newline at end of file + + + + org.apache.maven.wagon + wagon-ftp + 2.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + ${jdk.version} + ${jdk.version} + + + + org.apache.maven.plugins + maven-jar-plugin + 2.6 + + + org.apache.maven.plugins + maven-source-plugin + 2.4 + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.8 + + + + diff --git a/proto/pom.xml b/proto/pom.xml new file mode 100644 index 0000000..9b797ce --- /dev/null +++ b/proto/pom.xml @@ -0,0 +1,80 @@ + + + 4.0.0 + + + com.github.bitsoex.btcd-cli4j + btcd-cli4j-parent + 1.0-SNAPSHOT + + + btcd-cli4j-proto + jar + + btcd-cli4j Proto + Proto lib + + + + + javax.annotation + javax.annotation-api + ${javax-annotation.version} + + + + io.grpc + grpc-netty + ${grpc.version} + + + + io.grpc + grpc-protobuf + ${grpc.version} + + + + io.grpc + grpc-stub + ${grpc.version} + + + + + + + + kr.motd.maven + os-maven-plugin + 1.6.1 + + + + + org.xolstice.maven.plugins + protobuf-maven-plugin + 0.6.1 + + + com.google.protobuf:protoc:3.3.0:exe:${os.detected.classifier} + + grpc-java + + io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier} + + + + + + compile + compile-custom + + + + + + + + diff --git a/proto/src/main/proto/btcd_service.proto b/proto/src/main/proto/btcd_service.proto new file mode 100644 index 0000000..6f440ec --- /dev/null +++ b/proto/src/main/proto/btcd_service.proto @@ -0,0 +1,25 @@ +syntax = "proto3"; +package protos.model; + +option java_package = "com.bitso.model"; +option java_outer_classname = "BtcdServiceProto"; + +// getrawtransaction object request +message GetRawTransactionRequest { + string txid = 1; + bool verbose = 2; +} + +// getrawtransaction object response +message GetRawTransactionResponse { + string txid = 1; + string hex = 2; +} + +// the deposit btcd service definition +service BtcdService { + + // getrawtransaction method definition + rpc GetRawTransaction (GetRawTransactionRequest) returns (GetRawTransactionResponse) {} + +}