capi

package module
v0.0.0-...-8576238 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2019 License: GPL-3.0 Imports: 7 Imported by: 0

README

Capi v0.1

The Goal

Build an easy to use, coin agnostic API with a built in Block Explorer

Forks and PRs Welcome - I'm teaching myself Go! :-)


Important! Your daemon's coin.conf file needs to have txindex=1

Table of contents

Configuration

capi will look for a config file in ./config/config.json. If you have the capi binary in ~/home/Username/capiv1.0/capi:

  1. create a new config directory under ~/home/Username/capiv1.0/config
  2. create a new file called config.json and paste the below contents and change it as you see fit.
Example
{
  "Coin"               : "Feathercoin",
  "Ticker"             : "FTC",
  "Daemon"             : "nomp.pools.ac:19337",
  "RPCUser"            : "admin",
  "RPCPassword"        : "123456",
  "HTTPPostMode"       : true,
  "DisableTLS"         : true,
  "EnableCoinCodexAPI" : true,
  "capi_port"          : ":8000"
}
Options

The following table describes all configurable options for capi.

Option Description
Coin Coin name as a string
Ticker Coin symbol / price ticker as a string
Daemon Coin daemon URL+Port as a string
RPCUser Coin daemon RPC user as a string
RPCPassword Coin daemon RPC Password as a string
HTTPPostMode Enable HTTP only posts to coin daemon, bool true or false
DisableTLS DisableTLS connection to coin daemon, bool true or false
EnableCoinCodexAPI Enable or Disable the CoinCodexApi data which is used for prices, bool true or false
capi_port The port capi will listen on, string of ":PORT" . eg :8000 for capi to listen on port 8000

Endpoints

Once capi is running you can hit the following api endpoints

/address/{WalletAddress}

Returns an array of transactions and amounts received for the specified Address.

Call
Response
[
{
"txid": "2edf6d9e9d2b7b7a8628a8e926550141bd3807fbc373aee420d5a44fcb66ee2a",
"address": [
"n25K9Zf4UvRo1TzgYcGReHRmhZUVR3vKLr"
],
"received": 80,
"confirmations": 15083,
"block_hash": "3527435a31c0f0904f4f5ecdfb423c7b60b6499b318d70985c91ec8e64b7678e",
"tx_time": 1544781080
},
{
"txid": "b63dced29e83cc18c62fa692395d32f673abb3fb374b8b3a03025041d941da24",
"address": [
"n25K9Zf4UvRo1TzgYcGReHRmhZUVR3vKLr"
],
"received": 80,
"confirmations": 15082,
"block_hash": "a0b195b32da8dbadbbc72898b4e22129f25c58720a0c61dce234bf42bc6907b4",
"tx_time": 1544781082
},
{
"txid": "bc76921962dc8901fa6c401b2a5c74d4eb614c3198151a040c3d1284615bc1df",
"address": [
"n25K9Zf4UvRo1TzgYcGReHRmhZUVR3vKLr"
],
"received": 80,
"confirmations": 15081,
"block_hash": "56ad3fe44c58b9c3a5db07933a6ea64b0414024b48d4874ab27f99b257666f69",
"tx_time": 1544781096
}
]
/tx/{TransactionID}

Returns information for the specified Transaction Identifier.

Call
Response
{
    "hex": "01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff03510108ffffffff020050d6dc010000002321021a9f576cf7e5c0e3ad0c7c02e60aec4bb205362d240f6e5601c1c2bad0fc9374ac0000000000000000266a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf900000000",
    "txid": "e473d72f183f25e0f1cb97ab2b977bc98039cb0ac31e91fbb96a8257ff622bd5",
    "hash": "e473d72f183f25e0f1cb97ab2b977bc98039cb0ac31e91fbb96a8257ff622bd5",
    "size": 145,
    "vsize": 145,
    "version": 1,
    "locktime": 0,
    "vin": [
        {
            "coinbase": "510108",
            "sequence": 4294967295
        }
    ],
    "vout": [
        {
            "value": 80,
            "n": 0,
            "scriptPubKey": {
                "asm": "021a9f576cf7e5c0e3ad0c7c02e60aec4bb205362d240f6e5601c1c2bad0fc9374 OP_CHECKSIG",
                "hex": "21021a9f576cf7e5c0e3ad0c7c02e60aec4bb205362d240f6e5601c1c2bad0fc9374ac",
                "reqSigs": 1,
                "type": "pubkey",
                "addresses": [
                    "mojQnATqdQhzKMGS6LnvBxdo1t2zTCTB2u"
                ]
            }
        },
        {
            "value": 0,
            "n": 1,
            "scriptPubKey": {
                "asm": "OP_RETURN aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
                "hex": "6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9",
                "type": "nulldata"
            }
        }
    ],
    "blockhash": "afece97d0118541252714663e8a7c719a0baac65c0588dcd28fe83238d61ab16",
    "confirmations": 5611,
    "time": 1544779888,
    "blocktime": 1544779888
}
/block/{BlockHashorBlockHeight}

Returns block information based on block hash or block height.

Call
  • block height: http://127.0.0.1:8000/block/0
  • block hash: http://127.0.0.1:8000/block/4b6c3362e2f2a6b6317c85ecaa0f5415167e2bb333d2bf3d3699d73df613b91f
Response
[
    {
        "hash": "4b6c3362e2f2a6b6317c85ecaa0f5415167e2bb333d2bf3d3699d73df613b91f",
        "confirmations": 5612,
        "size": 280,
        "strippedSize": 280,
        "weight": 1120,
        "height": 0,
        "version": 1,
        "versionHex": "00000001",
        "merkleRoot": "97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9",
        "tx": [
            "97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9"
        ],
        "time": 1536656597,
        "nonce": 529517,
        "bits": "1e0ffff0",
        "difficulty": 0.000244140625,
        "previousBlockHash": "",
        "nextBlockHash": "afece97d0118541252714663e8a7c719a0baac65c0588dcd28fe83238d61ab16"
    }
]
/market

Returns recent market information.

Call
Response
{
    "symbol": "FTC",
    "coin_name": "Feathercoin",
    "today_open": 0.018926488,
    "price_high_24_usd": 0.020271526,
    "price_low_24_usd": 0.018661281,
    "volume_24_usd": 7017.345357014,
    "data_provider": "CoinCodex.com"
}

Documentation

Index

Constants

View Source
const (
	// BoltDB codifies the value to specify to use boltdb as a datastore.
	BoltDB datastore = "boltdb"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	ID                string   `json:"id" storm:"id"`
	Hash              string   `json:"hash" storm:"index"`
	Confirmations     int      `json:"confirmations"`
	StrippedSize      int      `json:"strippedsize"`
	Size              int      `json:"size"`
	Weight            int      `json:"weight"`
	Height            int      `json:"height" storm:"index"`
	Version           int      `json:"version"`
	VersionHex        string   `json:"versionHex"`
	MerkleRoot        string   `json:"merkleroot"`
	BlockTransactions []string `json:"tx"`
	Time              int64    `json:"time"`
	Mediantime        int      `json:"mediantime"`
	Nonce             uint32   `json:"nonce"`
	Bits              string   `json:"bits"`
	Difficulty        float64  `json:"difficulty"`
	Chainwork         string   `json:"chainwork"`
	PreviousHash      string   `json:"previousBlockHash"`
	NextHash          string   `json:"nextBlockHash"`
}

Block provides the domain model for a blockchain block.

type Coin

type Coin struct {
	// Name is the human readable name of the coin. For example, "Feathercoin".
	Name string `yaml:"name"`

	// Code is the 3 letter coin code. For example, "FTC".
	Code string `yaml:"code"`

	// Host is the Coin's API daemon hostname on which to connect to the API.
	Host string `yaml:"host"`

	// Port is the Coin's API daemon port on which to connect to the API.
	Port uint16 `yaml:"port"`

	// Username is the username to use in order to authenticate to the Coin's
	// API daemon.
	Username string `yaml:"username"`

	// Password is the password to use in order to authenticate to the Coin's
	// API daemon.
	Password string `yaml:"password"`

	// Timeout is how long to wait before timing out API requests.
	Timeout int `yaml:"timeout"`

	// SSL is whether to connect over SSL.
	// If not specified, the default is false.
	SSL bool `yaml:"ssl"`

	// EnableCoinCodexAPI is whether to enable the coin's codex API.
	// If not specified, the default is false.
	EnableCoinCodexAPI bool `yaml:"enableCoinCodexAPI"`
}

Coin provides the configuration required to connect to a coin daemon API.

type Config

type Config struct {
	// Port configures the API port CAPI will serve from.
	Port uint16 `yaml:"port"`

	// Coin Configuration.
	Coins []Coin `yaml:"coins"`

	// Datastore configuration.
	Datastore Datastore `yaml:"datastore"`
}

Config provides the domain structure to enable configuring CAPI.

func NewConfig

func NewConfig(configFilepath string) (*Config, error)

NewConfig returns a processed config object.

type ConfigBoltDB

type ConfigBoltDB struct {
	// DbPath enables storing data files at a path other than where the binary
	// is started from.
	DbPath string `yaml:"dbPath"`

	// Timeout specifies, in seconds, how long to wait before timing out when
	// trying to gain a file lock on the database's BoltDB data file.
	Timeout int `yaml:"timeout"`
}

ConfigBoltDB provides specific configuration customisation for BoltDB.

type Datastore

type Datastore struct {
	// Backend is the specific datastore driver to use.
	Backend datastore `yaml:"backend"`

	// BoltDB specific datastore configuration.
	BoltDB ConfigBoltDB `yaml:"boltdb"`
}

Datastore provides customization for backend datastores.

type Transaction

type Transaction struct {
	ID string
}

Transaction provides the domain model for a blockchain transaction.

Directories

Path Synopsis
cmd
capi command
capi-beta command
dev provides the development build, which may have unimplemented features, or dragons..
dev provides the development build, which may have unimplemented features, or dragons..
old

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL