Giter Club home page Giter Club logo

bitcoin-rpc-client's Introduction

bitcoin-rpc-client

This is a lightweight java bitcoind JSON-RPC client binding. It does not require any external dependencies.

Maven

The package is published in the wf.bitcoin group and you can add it to you pom.xml adding a section like this:

<dependency>
    <groupId>wf.bitcoin</groupId>
    <artifactId>bitcoin-rpc-client</artifactId>
    <version>1.1.0</version>
</dependency>

Configuration

In order to know what RPC API to use, the library will look in the bitcoind configuration file (<user home>/.bitcoin/bitcoin.conf) and read the relevant configs:

  • rpcconnect
  • rpcport

Here is a sample bitcoin.conf that will setup bitcoind to run in regtest mode and in a way compatible with this library:

# Maintain full transaction index, used in lookups by the getrawtransaction call
txindex=1

# Run bitcoind in regtest mode
regtest=1

# Accept command line and JSON-RPC commands
server=1

# Tells bitcoind that the RPC API settings on the following lines apply to the regtest RPC API
[regtest]

# RPC API settings
rpcconnect=localhost
rpcport=9997

Note that the configuration does not contain any API credentials. The authentication is done via a temporary token stored in a cookie file by bitcoind (see details). The approach of using rpcuser and rpcpassword is still supported, even though bitcoind considers it legacy.

bitcoin-rpc-client's People

Contributors

cd2357 avatar eflorent2020 avatar frankchen021 avatar frpeters avatar henriquetft avatar phe-sto avatar polve avatar semsche avatar tdiesler avatar wkoszycki avatar zeroleak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bitcoin-rpc-client's Issues

Master build fails with javadoc errors

[ERROR] /Users/tdiesler/git/JavaBitcoindRpcClient/src/main/java/wf/bitcoin/javabitcoindrpcclient/BitcoinRPCException.java:23: error: malformed HTML
[ERROR]  * <[email protected]>
[ERROR]    ^
[ERROR] /Users/tdiesler/git/JavaBitcoindRpcClient/src/main/java/wf/bitcoin/javabitcoindrpcclient/BitcoinRPCException.java:23: error: bad use of '>'
[ERROR]  * <[email protected]>
[ERROR]                       ^
[ERROR] 
[ERROR] Command line was: /Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/jre/../bin/javadoc @options @packages
[ERROR] 
[ERROR] Refer to the generated Javadoc files in '/Users/tdiesler/git/JavaBitcoindRpcClient/target/apidocs' dir.
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

Any plans to implement getBlockTemplate?

I'm having problems finding a java library that is easy to use to connect to the bitcoin core api. Finally found this, but I need the getBlockTemplate function. Are there any plans to implement it, or do I have to keep looking?

endless loop in Json Parse

Code would go to an endless loop when get a big string. The stack are listed below

 at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSHash(CrippledJavaScriptParser.java:156)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSExpr(CrippledJavaScriptParser.java:191)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSArray(CrippledJavaScriptParser.java:99)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSExpr(CrippledJavaScriptParser.java:189)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSHash(CrippledJavaScriptParser.java:146)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSExpr(CrippledJavaScriptParser.java:191)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSHash(CrippledJavaScriptParser.java:146)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSExpr(CrippledJavaScriptParser.java:191)
    at wf.bitcoin.krotjson.CrippledJavaScriptParser.parseJSExpr(CrippledJavaScriptParser.java:256)
    at wf.bitcoin.krotjson.JSON.parse(JSON.java:129)
    at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.loadResponse(BitcoinJSONRPCClient.java:187)
    at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.query(BitcoinJSONRPCClient.java:229)
    at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient.getRawTransaction(BitcoinJSONRPCClient.java:1283)

It would occurs every time when getRawTransaction("b6299d23e836d649a5a5012ebfebd2474b4d100d5334d7608d3c6c01b8204b45")

sendToAddress method

You shouldn't keep amount in double. I suggest long in satoshi (like in BitcoinJ) or BigDecimal.

signrawtransaction complete support

Hi! I couldn't find how to pass to signrawtransaction all the parameter options it supports now. I'm mostly interested in validating transactions without boradcast them, as stated here. Are you still working in the library? Can you add it? Can I send a PR?
Thanks!

Maps may not always contain requested key

It is not generally true that the key/value map returned from the Bitcoin client contains a value for the requested pair. For example vout is not present for coinbase transactions. The API must therefore use Object equivalents of primitive types.

This is an incompatible change.

RPC Query Failed

wf.bitcoin.javabitcoindrpcclient.BitcoinRPCException: RPC Query Failed (method: getblockcount, params: [], response code: 415 responseMessage Unsupported Media Type, response: invalid content type, only application/json is supported

Request for invalid Tx should fail

Getting Tx: 853e910bedb7c8213bc93cab7e8337e0a59731db1e0c8968d2e19355d850bdc5
Nov 29, 2018 6:44:36 AM wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient$TransactionWrapper raw
WARNING: RPC Query Failed (method: getrawtransaction, params: [853e910bedb7c8213bc93cab7e8337e0a59731db1e0c8968d2e19355d850bdc5, 1], response code: 500 responseMessage Internal Server Error, response: {"result":null,"error":{"code":-5,"message":"No information available about transaction"},"id":"1"}

Got Tx: [tx=853e910bedb7c8213bc93cab7e8337e0a59731db1e0c8968d2e19355d850bdc5, vin=0, vout=0]

May returns a Tx object that has neither vin nor vout

Align version to that of bitcoin core

It may be useful to align the version of this project to the one of bitcoin core. In that way it would be immediately obvious what scope of functionality can be expected to be supported.

Propose a versioning scheme for this library

Also see PR #48

We have a few incompatible changes lined up in branch 0.17.x. Now that this version of bitcoin core has been released, it is time to bring them in to master.

The question however arises what the next version should be. I propose a semantic versioning scheme, where an incompatible API change would call for a major version bump.

The next version would therefore be 1.0.0

Add support for OP_RETURN data

Can not find any way to create raw transaction which has data in it's output list.
in bitcoin command, data can insert as one of outputs. e.g.
{
"mgt9WNsoi7pPY29ACTuWPVX73XGFVhD9Vi": 40,
"data": "ba3885e9aa5fd0949f40dc5d7905700fa039ef8ad425c60479cc52dfe16aa3e8"
}

but here amount of TxOut in double and can not use as String data.

Sorry, can not find any better way to contact.
if i missed something and there is a way in JavaBitcoindRpcClient, guide me to that.

Add support for missing network methods

Missing methods supported in 0.17.0 are ...

  • clearbanned
  • disconnectnode "[address]" [nodeid]
  • listbanned
  • setban "subnet" "add|remove" (bantime) (absolute)
  • setnetworkactive true|false

Change artifactId to a standard format

Perhaps like this

JavaBitcoindRpcClient => java-bitcoin-client

The repo name on github may then also want to change.

PS: most jars have a lower case name with dashes

Move operation returns boolean, not string

When I try to move funds from one account to another, I get an exception that boolean cannot be converted to string. Checking the result map in loadResponse, it shows "result" -> "true".

getTransaction requires txindex

I am using bitcoin-rpc-client in conjunction with walletnotify to get transaction data upon first confirmation. The problem is that getTransaction method returns Invalid Tx because of the following error under the hood:

No such mempool transaction. Use -txindex to enable blockchain transaction queries. Use gettransaction for wallet transactions.

I can set txindex, but it's redundant for me, as I am interested only in my wallet transactions, moreover AFAIU it will add some performance overhead.
I've found the source of the problem, but still can't understand the solution. Both getTransaction and getRawTransaction methods now do getrawtransaction under the hood which is inconvenient when one works with his own wallet transactions only

Add support for missing raw transaction methods

Missing methods supported in 0.17.0 are ...

  • combinepsbt ["psbt",...]
  • combinerawtransaction ["hexstring",...]
  • converttopsbt "hexstring" ( permitsigdata iswitness )
  • createpsbt [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable )
  • decodepsbt "psbt"
  • decoderawtransaction "hexstring" ( iswitness )
  • finalizepsbt "psbt" ( extract )
  • fundrawtransaction "hexstring" ( options iswitness )
  • signrawtransactionwithkey "hexstring" ["privatekey1",...] ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
  • testmempoolaccept ["rawtxs"] ( allowhighfees )

getNewAddress does not create account with 0.00 BTC balance

When i execute below code it create a account with this email: [email protected] .

BitcoinJSONRPCClient bitcoin = new BitcoinJSONRPCClient(url);
String address = bitcoin.getNewAddress("[email protected]");

when i execute bitcoin-cli listaccounts in my terminal. I can see account created with my email but i can see some default balance in it . Here is the listaccounts output:

{
  "": -0.55385912,
  "[email protected]": 1.11942880,
}

I want when ever i call getNewAddress method it should create account with 0 BTC balance

fundrawtransaction method

$ bitcoin-cli fundrawtransaction

error code: -1
error message:

fundrawtransaction "hexstring" ( options )

Add inputs to a transaction until it has enough in value to meet its out value.
This will not modify existing inputs, and will add one change output to the outputs.
Note that inputs which were signed may need to be resigned after completion since in/outputs have been added.
The inputs added will not be signed, use signrawtransaction for that.
Note that all existing inputs must have their previous output transaction be in the wallet.
Note that all inputs selected must be of standard form and P2SH scripts must be
in the wallet using importaddress or addmultisigaddress (to calculate fees).
You can see whether this is the case by checking the "solvable" field in the listunspent output.
Only pay-to-pubkey, multisig, and P2SH versions thereof are currently supported for watch-only

Arguments:
1. "hexstring"           (string, required) The hex string of the raw transaction
2. options               (object, optional)
   {
     "changeAddress"     (string, optional, default pool address) The bitcoin address to receive the change
     "changePosition"    (numeric, optional, default random) The index of the change output
     "includeWatching"   (boolean, optional, default false) Also select inputs which are watch only
     "lockUnspents"      (boolean, optional, default false) Lock selected unspent outputs
     "feeRate"           (numeric, optional, default not set: makes wallet determine the fee) Set a specific feerate (BTC per KB)
   }
                         for backward compatibility: passing in a true instead of an object will result in {"includeWatching":true}

Result:
{
  "hex":       "value", (string)  The resulting raw transaction (hex-encoded string)
  "fee":       n,         (numeric) Fee in BTC the resulting transaction pays
  "changepos": n          (numeric) The position of the added change output, or -1
}
"hex"             

Examples:

Create a transaction with no inputs
> bitcoin-cli createrawtransaction "[]" "{\"myaddress\":0.01}"

Add sufficient unsigned inputs to meet the output value
> bitcoin-cli fundrawtransaction "rawtransactionhex"

Sign the transaction
> bitcoin-cli signrawtransaction "fundedtransactionhex"

Send the transaction
> bitcoin-cli sendrawtransaction "signedtransactionhex"

Add support for missing wallet methods

Missing methods supported in 0.17.0 are ...

  • abandontransaction "txid"
  • abortrescan
  • bumpfee "txid" ( options )
  • createwallet "wallet_name" ( disable_private_keys )
  • getaddressesbylabel "label"
  • getaddressinfo "address"
  • importmulti "requests" ( "options" )
  • importprunedfunds
  • importpubkey "pubkey" ( "label" rescan )
  • listaddressgroupings
  • listlabels ( "purpose" )
  • listwallets
  • loadwallet "filename"
  • removeprunedfunds "txid"
  • rescanblockchain ("start_height") ("stop_height")
  • sendmany "" {"address":amount,...} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode")
  • sethdseed ( "newkeypool" "seed" )
  • signrawtransactionwithwallet "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
  • unloadwallet ( "wallet_name" )
  • walletcreatefundedpsbt [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable ) ( options bip32derivs )
  • walletlock
  • walletpassphrasechange "oldpassphrase" "newpassphrase"
  • walletprocesspsbt "psbt" ( sign "sighashtype" bip32derivs )

Add support for missing methods

Missing blockchain methods supported in 0.17.0 are ...

  • getblockheader "hash" ( verbose )
  • getblockstats hash_or_height ( stats )
  • getchaintips
  • getchaintxstats ( nblocks blockhash )
  • getmempoolancestors txid (verbose)
  • getmempooldescendants txid (verbose)
  • getmempoolentry txid
  • getmempoolinfo
  • gettxoutproof ["txid",...] ( blockhash )
  • preciousblock "blockhash"
  • pruneblockchain
  • savemempool
  • scantxoutset ( )
  • verifytxoutproof "proof"

Missing control methods supported in 0.17.0 are ...

  • getmemoryinfo ("mode")
  • logging ( )
  • uptime

Missing mining methods supported in 0.17.0 are ...

  • getblocktemplate ( TemplateRequest )
  • prioritisetransaction

Missing network methods supported in 0.17.0 are ...

  • clearbanned
  • disconnectnode "[address]" [nodeid]
  • listbanned
  • setban "subnet" "add|remove" (bantime) (absolute)
  • setnetworkactive true|false

Missing raw transaction methods supported in 0.17.0 are ...

  • combinepsbt ["psbt",...]
  • combinerawtransaction ["hexstring",...]
  • converttopsbt "hexstring" ( permitsigdata iswitness )
  • createpsbt [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable )
  • decodepsbt "psbt"
  • decoderawtransaction "hexstring" ( iswitness )
  • finalizepsbt "psbt" ( extract )
  • fundrawtransaction "hexstring" ( options iswitness )
  • testmempoolaccept ["rawtxs"] ( allowhighfees )

Missing util methods supported in 0.17.0 are ...

  • signmessagewithprivkey "privkey" "message"

Missing wallet methods supported in 0.17.0 are ...

  • abandontransaction "txid"
  • abortrescan
  • bumpfee "txid" ( options )
  • createwallet "wallet_name" ( disable_private_keys )
  • getaddressesbylabel "label"
  • getaddressinfo "address"
  • importmulti "requests" ( "options" )
  • importprunedfunds
  • importpubkey "pubkey" ( "label" rescan )
  • listaddressgroupings
  • listlabels ( "purpose" )
  • listwallets
  • loadwallet "filename"
  • removeprunedfunds "txid"
  • rescanblockchain ("start_height") ("stop_height")
  • sendmany "" {"address":amount,...} ( minconf "comment" ["address",...] replaceable conf_target "estimate_mode")
  • sethdseed ( "newkeypool" "seed" )
  • signrawtransactionwithwallet "hexstring" ( [{"txid":"id","vout":n,"scriptPubKey":"hex","redeemScript":"hex"},...] sighashtype )
  • unloadwallet ( "wallet_name" )
  • walletcreatefundedpsbt [{"txid":"id","vout":n},...] [{"address":amount},{"data":"hex"},...] ( locktime ) ( replaceable ) ( options bip32derivs )
  • walletlock
  • walletpassphrasechange "oldpassphrase" "newpassphrase"
  • walletprocesspsbt "psbt" ( sign "sighashtype" bip32derivs )

Missing ZeroMQ methods supported in 0.17.0 are ...

  • getzmqnotifications

Potential NPE in estimateSmartFee

java.lang.NullPointerException
	at java.math.BigDecimal.<init>(BigDecimal.java:806)
	at wf.bitcoin.javabitcoindrpcclient.MapWrapper.mapBigDecimal(MapWrapper.java:74)
	at wf.bitcoin.javabitcoindrpcclient.MapWrapper.mapBigDecimal(MapWrapper.java:60)
	at wf.bitcoin.javabitcoindrpcclient.BitcoinJSONRPCClient$SmartFeeResultMapWrapper.feeRate(BitcoinJSONRPCClient.java:925)
	at io.nessus.bitcoin.BitcoinNetwork.estimateSmartFee(BitcoinNetwork.java:42)
	at io.nessus.AbstractWallet.sendToAddress(AbstractWallet.java:246)
	at io.nessus.AbstractWallet.sendFromLabel(AbstractWallet.java:235)
	at io.nessus.test.bitcoin.RawTxTest.after(RawTxTest.java:62)

Case Sensitivity: BitcoinRpcException vs BitcoinRPCException

Can't compile on Mac or Linux because the two classes (BitcoinRpcExtension and BitcoinRPCException) have the same name, in the same package, but with different cases.

BitcoinRPCException should be renamed to avoid conflicts with BitcoinRpcException.

Extend result returned from getblockchaininfo

[bob@Nessus-IPFS ~]$ docker exec btcd bitcoin-cli -testnet=1 getblockchaininfo
{
  "chain": "test",
  "blocks": 1444656,
  "headers": 1444656,
  "bestblockhash": "000000000000013e04a490ac3b9814e163d8a9c6a04858649f206043c273a150",
  "difficulty": 12368745.01434309,
  "mediantime": 1542895208,
  "verificationprogress": 0.9999924124513836,
  "initialblockdownload": false,
  "chainwork": "0000000000000000000000000000000000000000000000d4be4d5f962630a176",
  "size_on_disk": 957663921,
  "pruned": true,
  "pruneheight": 1412618,
  "automatic_pruning": true,
  "prune_target_size": 1073741824,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": true
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": true
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": true
      }
    }
  ],
  "bip9_softforks": {
    "csv": {
      "status": "active",
      "startTime": 1456790400,
      "timeout": 1493596800,
      "since": 770112
    },
    "segwit": {
      "status": "active",
      "startTime": 1462060800,
      "timeout": 1493596800,
      "since": 834624
    }
  },
  "warnings": "Warning: unknown new rules activated (versionbit 28)"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.