Code Monkey home page Code Monkey logo

bitcoin-client-wrapper's Introduction

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

bitcoin-client-wrapper's People

Contributors

heidric avatar

Watchers

James Cloos avatar

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.