Giter Club home page Giter Club logo

turtlecoin-api-proxy's Introduction

TurtleCoind Node API Proxy

This project is designed to provide an API proxy for web services to contact any number of TurtleCoin nodes for basic information regarding the state of the Node. It utilizes a cache that helps speed up the delivery of responses to clients while minimzing the load against the daemon by remote callers.

The sample service.js includes an example of how to quickly spin up the web service. It supports clustering via PM2 and I highly recommend that you run it with multiple threads.

Dependencies

  • NodeJS v8.x

Easy Start

This will spin up a copy of the webservice on 0.0.0.0:80. See the additional options below to customize the port or IP the web service binds to.

git clone https://github.com/brandonlehmann/turtlecoin-api-proxy.git
cd turtlecoin-api-proxy
npm i
node service.js

Using the API

/getinfo

You may call the URL using any of the following paths.

  • /getinfo
  • /1.1.1.1/getinfo
  • /1.1.1.1/11898/getinfo

You will receive a JSON response as shown below.

{
    "alt_blocks_count": 34,
    "difficulty": 194403128,
    "grey_peerlist_size": 4199,
    "height": 270523,
    "incoming_connections_count": 30,
    "last_known_block_index": 270520,
    "outgoing_connections_count": 8,
    "status": "OK",
    "tx_count": 264219,
    "tx_pool_size": 0,
    "white_peerlist_size": 333,
    "cached": false,
    "node": {
    "host": "public.turtlenode.io",
    "port": 11898
    },
    "globalHashRate": 6480104
}

/getheight

You may call the URL using any of the following paths.

  • /getheight
  • /1.1.1.1/getheight
  • /1.1.1.1/11898/getheight

You will receive a JSON response as shown below.

{
    "height": 270524,
    "status": "OK",
    "cached": false,
    "node": {
        "host": "public.turtlenode.io",
        "port": 11898
    }
}

/gettransactions

You may call the URL using any of the following paths.

  • /gettransactions
  • /1.1.1.1/gettransactions
  • /1.1.1.1/11898/gettransactions

You will receive a JSON response as shown below.

{
    "missed_tx": [],
    "status": "OK",
    "txs_as_hex": [],
    "cached": false,
    "node": {
        "host": "public.turtlenode.io",
        "port": 11898
    }
}

/json_rpc

You may call the POST to the URL using any of the following paths.

  • /json_rpc
  • /1.1.1.1/json_rpc
  • /1.1.1.1/11898/json_rpc

These will respond back as if you made the same requests directly to the node. For full documentation of what's supported, see the TurtleCoin documentation.

Keep it Running

I'm a big fan of PM2 so if you don't have it installed, the setup is quite simple.

npm install -g pm2
pm2 startup
pm2 install pm2-logrotate
pm2 start service.js --watch --name turtlecoin-api-proxy -i max
pm2 save

Documentation

Initialization

This is incredibly simple to setup and use. No options are required but you can customize it as you see fit. Default values are provided below.

const TRTLProxy = require('./')

var service = new TRTLProxy({
  cacheTimeout: 30, // How quickly do we timeout cached responses from individual nodes
  bindIp: '0.0.0.0', // What IP address do we bind the web service to
  bindPort: 80 // What port do we bind the web service to
})

Methods

service.start()

Starts the web service

service.start()

service.stop()

Stops the web service

service.stop()

Events

Event - ready

Event is emitted when the web service is listening for connections.

service.on('ready', (ip, port) => {
  // do something
})

Event - stop

Event is emitted when the web service is stopped.

service.on('stop', () => {
  // do something
})

Event - error

Event is emitted when an error is encountered.

service.on('error', (err) => {
  // do something
})

turtlecoin-api-proxy's People

Contributors

shopglobal avatar

Watchers

 avatar  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.