btctools

package module
v0.0.0-...-16f18e5 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 8 Imported by: 0

README

btctools

Build Status GoDoc

btctools implements a Bitcoin JSON-RPC client package written in Go.

This library is heavily inspired and based on parts of btcd/rpcclient lib. The main purpose of this lib is providing compatability with other Bitcoin-based cryptocurrencies like Litecoin or Dash.

License

Package btctools is licensed under the MIT license.

Documentation

Index

Constants

View Source
const (
	TxCategorySend     = "send"
	TxCategoryReceive  = "receive"
	TxCategoryGenerate = "generate"
	TxCategoryImmature = "immature"
	TxCategoryOrphan   = "orphan"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockChainInfo

type BlockChainInfo struct {
	Chain                string  `json:"chain"`
	Blocks               uint64  `json:"blocks"`
	Headers              uint64  `json:"headers"`
	BestBlockHash        string  `json:"bestblockhash"`
	Difficulty           float64 `json:"difficulty"`
	MedianTime           int64   `json:"mediantime"`
	VerificationProgress float64 `json:"verificationprogress"`
	ChainWork            string  `json:"chainwork"`
	Pruned               bool    `json:"pruned"`
	PruneHeight          int64   `json:"pruneheight,omitempty"`
	SoftForks            []struct {
		ID      string `json:"id"`
		Version int    `json:"version"`
		Reject  struct {
			Status   bool   `json:"status,omitempty"`
			Found    uint64 `json:"found,omitempty"`
			Required uint64 `json:"required"`
			Window   uint64 `json:"window"`
		} `json:"reject"`
	} `json:"softforks"`
}

BlockChainInfo is a response for `GetBlockChainInfo` RPC call

type BlockHeader

type BlockHeader struct {
	Hash              string               `json:"hash"`
	Confirmations     int64                `json:"confirmations"`
	Height            int64                `json:"height"`
	Version           int64                `json:"version"`
	VersionHex        string               `json:"versionHex"`
	MerkleRoot        string               `json:"merkleroot"`
	Time              uint64               `json:"time"`
	MedianTime        int64                `json:"mediantime"`
	Nonce             int64                `json:"nonce"`
	Bits              string               `json:"bits"`
	Difficulty        float64              `json:"difficulty"`
	ChainWork         string               `json:"chainwork"`
	PreviousBlockHash blockchain.BlockHash `json:"previousblockhash"`
	NextBlockHash     blockchain.BlockHash `json:"nextblockhash"`
}

BlockHeader is a response for `GetBlockHeader` RPC call

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Bitcoin RPC client which allows easy access to the various RPC methods available on a Bitcoin RPC server. Each of the wrapper functions handle the details of converting the passed and return types to and from the underlying JSON types which are required for the JSON-RPC invocations

func New

func New(config *ConnConfig) (*Client, error)

New creates a new RPC client based on the provided connection configuration details

func (*Client) GetBlockChainInfo

func (c *Client) GetBlockChainInfo() (*BlockChainInfo, error)

GetBlockChainInfo provides information about the current state of the block chain.

func (*Client) GetBlockHeader

func (c *Client) GetBlockHeader(hash *blockchain.BlockHash) (*BlockHeader, error)

GetBlockHeader gets a block header with a particular header hash from the local block database

func (*Client) GetNetworkInfo

func (c *Client) GetNetworkInfo() (*ClientNetworkInfo, error)

GetNetworkInfo returns information about the node’s connection to the network

func (*Client) GetNewAddress

func (c *Client) GetNewAddress(account string) (blockchain.Address, error)

GetNewAddress returns a new address for receiving payments

func (*Client) GetType

func (c *Client) GetType() (Forks, error)

GetType will try to guess what exactly

func (*Client) ListSinceBlock

func (c *Client) ListSinceBlock(hash *blockchain.BlockHash) (*ListSinceBlockResult, error)

ListSinceBlock gets all transactions affecting the wallet which have occurred since a particular block, plus the header hash of a block at a particular depth

func (*Client) SendToAddress

func (c *Client) SendToAddress(to blockchain.Address, amount float64, comment string, commentTo string, subtractFeeFromAmount bool) (string, error)

SendToAddress spends an amount to a given address

type ClientNetworkInfo

type ClientNetworkInfo struct {
	Version         int64  `json:"version"`
	Subversion      string `json:"subversion"`
	ProtocolVersion int64  `json:"protocolversion"`
	LocalServices   string `json:"localservices"`
	LocalRelay      bool   `json:"localrelay"`
	TimeOffset      int64  `json:"timeoffset"`
	Connections     uint64 `json:"connections"`
	Networks        []struct {
		Name                      string `json:"name"`
		Limited                   bool   `json:"limited"`
		Reachable                 bool   `json:"reachable"`
		ProxyRandomizeCredentials bool   `json:"proxy_randomize_credentials"`
		Proxy                     string `json:"proxy"`
	} `json:"networks"`
	RelayFee       float64 `json:"relayfee"`
	LocalAddresses []struct {
		Address string `json:"address"`
		Port    uint16 `json:"port"`
		Score   uint32 `json:"score"`
	} `json:"localaddresses"`
	Warnings string `json:"warnings"`
}

ClientNetworkInfo is a response for `GetNetworkInfo` RPC call

type ConnConfig

type ConnConfig struct {
	// Host is the IP address and port of the RPC server you want to connect to
	Host string

	// User is the username to use to authenticate to the RPC server
	User string
	// Pass is the password to use to authenticate to the RPC server
	Pass string
}

ConnConfig describes the connection configuration parameters for the client

type Forks

type Forks int

Forks represent daemon type

const (
	// ForkUnknown indicates daemon type is not yet detected
	ForkUnknown Forks = iota

	// ForkOriginal indicates original Satoshi daemon
	ForkOriginal

	// ForkLitecoin indicates Litecoin (SCrypt, lower block time)
	ForkLitecoin

	// ForkDash indicates Dash (Master nodes, PrivateSend, InstantSend)
	ForkDash
)

type ListSinceBlockResult

type ListSinceBlockResult struct {
	Transactions []struct {
		Address blockchain.AddressPubKeyHash `json:"address,omitempty"`
		Amount  float64                      `json:"amount"`
		//bip125-replaceable": "no",
		BlockHash     blockchain.BlockHash `json:"blockhash,omitempty"`
		BlockIndex    int64                `json:"blockindex,omitempty"`
		BlockTime     uint64               `json:"blocktime,omitempty"`
		Category      TxCategory           `json:"category"`
		Confirmations uint64               `json:"confirmations"`
		Label         string               `json:"label"`
		Time          uint64               `json:"time"`
		TimeReceived  uint64               `json:"timereceived"`
		TxID          string               `json:"txid"`
		Vout          uint32               `json:"vout"`
	} `json:"transactions"`
	LastBlock blockchain.BlockHash `json:"lastblock"`
}

ListSinceBlockResult is a response for `ListSinceBlock` RPC call

type TxCategory

type TxCategory string

TxCategory represents type of transaction

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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