Skip to content

Heidric/bitcoin-client-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bitcoin-client-wrapper

Requirements

  1. Go version 1.12.5 and higher for development and building
  2. Docker version 2.0 and higher for testing

Launch instructions

  1. Set two required global variables: RPC_ADDR (address of the bitcoin node to connect to) and MAIN_PORT (port to run the server on)
  2. Set the optional global variable, which is responsible for the debug log in the server responses: ENV. Set it to "dev" if you want the extra debug info in case of errors
  3. Download library from github.com/go-chi/chi
  4. Either build (for example, using the build.sh script from the test folder. Binary will be placed into the test/app/bin folder) and run source files or launch the built binary

Testing

Run the following command from inside the "test" folder. Don't forget to change {port} with the port of your choice

MAIN_PORT={port} go test -v

API description

All the methods return JSON object

{
  "Message": "Something went wrong"
}

with status code 500 in case of the server error.

Get transaction by it's id

GET /api/v1/transaction/{id}?watchonly=false/true

where {id} should be swapped with the transaction id and the "watchonly" can be provided as the query parameter, which defaults to false if it was not provided

Returns JSON object in the form of

{
  "amount": double,
  "fee": double,
  "confirmations" : int,
  "blockhash" : string,
  "blockindex" : int,
  "blocktime" : int,
  "txid" : string,
  "time" : int,
  "timereceived" : int,
  "bip125-replaceable": string,
  "details" : [
    {
      "account" : string,
      "address" : string,
      "category" : string,
      "amount" : float,
      "label" : string,
      "vout" : int,
      "fee": float,
      "abandoned": bool
    }
    ,...
  ],
  "hex" : string
}

with the status code 200 if the request was successfully processed

Get new address

POST /api/v1/get-new-address

Accepts JSON object in the request body, in the following form:

{
  "Passphrase": string, required,
  "Timeout": int, optional, defaults to 1,
  "Label": string, optional,
  "Address_type": string, optional, one of the “legacy”, “p2sh-segwit”, and “bech32”
}

Returns JSON object in the form of

{
  "result": string
}

with the status code 200 if the request was successfully processed

Returns

{
  "Message": "Passphrase is required"
}

with status code 400 if the passphrase wasn't provided

Returns

{
  "Message": "Address_type must be one of the following: legacy, p2sh-segwit, bech32"
}

with status code 400 if the address type had wrong value

Send btc to address

POST /api/v1/send-to-address

Accepts JSON object in the request body, in the following form:

{
  "Passphrase": string, required,
  "Timeout": int, optional, defaults to 1,

  "Address": string, required
  "Amount": string, required
  "Comment": string, optional
  "Comment_to": string, optional 
  "Subtractfeefromamount": bool, optional
  "Replaceable": bool, optional
  "Conf_target": int, optional
  "Estimate_mode": string, optional, one of the following: "UNSET", "ECONOMICAL", "CONSERVATIVE", defaults to "UNSET"
}

Returns JSON object in the form of

{
  "txid": string
}

with the status code 200 if the request was successfully processed

Returns

{
  "Message": "Passphrase is required"
}

with status code 400 if the passphrase wasn't provided

Returns

{
  "Message": "Estimate_mode must be one of the following: UNSET, ECONOMICAL, CONSERVATIVE"
}

with status code 400 if the estimate mode had wrong value

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published