rpc

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// VERSION - represents bitcoind package version
	VERSION = 0.1

	// RPCCLIENT_TIMEOUT - represent http timeout for rcp client
	RPCCLIENT_TIMEOUT = 30
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BTCRpcClient

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

BTCRpcClient - represents a JSON RPC client (over HTTP(s)).

type Bitcoind

type Bitcoind struct {
	ChainParams *chaincfg.Params
	// contains filtered or unexported fields
}

Bitcoind - represents a Bitcoind client

func New

func New(host string, port int, user, passwd string, useSSL bool, chainParams *chaincfg.Params) (*Bitcoind, error)

New - return a new bitcoind

func (*Bitcoind) DumpPrivKey

func (b *Bitcoind) DumpPrivKey(address btcutil.Address) (*btcutil.WIF, error)

DumpPrivKey return private key as string associated to public <address>

func (*Bitcoind) FundRawTransaction

func (b *Bitcoind) FundRawTransaction(tx *wire.MsgTx, feePerKb btcutil.Amount) (fundedTx *wire.MsgTx, fee btcutil.Amount, err error)

func (*Bitcoind) Generate

func (b *Bitcoind) Generate(blockNumber uint64) (bh []string, err error)

generate blockNumber of block on regtest network

func (*Bitcoind) GetAccount

func (b *Bitcoind) GetAccount(address string) (account string, err error)

GetAccount returns the account associated with the given address.

func (*Bitcoind) GetAccountAddress

func (b *Bitcoind) GetAccountAddress(account string) (address string, err error)

GetAccountAddress Returns the current bitcoin address for receiving payments to this account. If account does not exist, it will be created along with an associated new address that will be returned.

func (*Bitcoind) GetAddressesByAccount

func (b *Bitcoind) GetAddressesByAccount(account string) (addresses []string, err error)

GetAddressesByAccount return addresses associated with account <account>

func (*Bitcoind) GetBalance

func (b *Bitcoind) GetBalance(account string, minconf uint64) (balance float64, err error)

GetBalance return the balance of the server or of a specific account If [account] is "", returns the server's total available balance. If [account] is specified, returns the balance in the account

func (*Bitcoind) GetBestBlockhash

func (b *Bitcoind) GetBestBlockhash() (bestBlockHash string, err error)

GetBestBlockhash returns the hash of the best (tip) block in the longest block chain.

func (*Bitcoind) GetBlock

func (b *Bitcoind) GetBlock(blockHash string) (block Block, err error)

GetBlock returns information about the block with the given hash.

func (*Bitcoind) GetBlockCount

func (b *Bitcoind) GetBlockCount() (count uint64, err error)

GetBlockCount returns the number of blocks in the longest block chain.

func (*Bitcoind) GetBlockHash

func (b *Bitcoind) GetBlockHash(index uint64) (hash string, err error)

GetBlockHash returns hash of block in best-block-chain at <index>

func (*Bitcoind) GetDifficulty

func (b *Bitcoind) GetDifficulty() (difficulty float64, err error)

GetDifficulty returns the proof-of-work difficulty as a multiple of the minimum difficulty.

func (*Bitcoind) GetFeePerKb

func (b *Bitcoind) GetFeePerKb() (useFee, relayFee btcutil.Amount, err error)

getFeePerKb queries the wallet for the transaction relay fee/kB to use and the minimum mempool relay fee. It first tries to get the user-set fee in the wallet. If unset, it attempts to find an estimate using estimatefee 6. If both of these fail, it falls back to mempool relay fee policy.

func (*Bitcoind) GetGenerate

func (b *Bitcoind) GetGenerate() (generate bool, err error)

GetGenerate returns true or false whether bitcoind is currently generating hashes

func (*Bitcoind) GetHashesPerSec

func (b *Bitcoind) GetHashesPerSec() (hashpersec float64, err error)

GetHashesPerSec returns a recent hashes per second performance measurement while generating.

func (*Bitcoind) GetNewAddress

func (b *Bitcoind) GetNewAddress(account ...string) (addr string, err error)

GetNewAddress return a new address for account [account].

func (*Bitcoind) GetRawChangeAddress

func (b *Bitcoind) GetRawChangeAddress() (btcutil.Address, error)

getRawChangeAddress calls the getrawchangeaddress JSON-RPC method. It is implemented manually as the rpcclient implementation always passes the account parameter which was removed in Bitcoin Core 0.15.

func (*Bitcoind) GetRawMempool

func (b *Bitcoind) GetRawMempool() (txId []string, err error)

GetRawMempool returns all transaction ids in memory pool

func (*Bitcoind) GetRawTransaction

func (b *Bitcoind) GetRawTransaction(txId string, verbose bool) (rawTx interface{}, err error)

GetRawTransaction returns raw transaction representation for given transaction id.

func (*Bitcoind) GetReceivedByAccount

func (b *Bitcoind) GetReceivedByAccount(account string, minconf uint32) (amount float64, err error)

GetReceivedByAccount Returns the total amount received by addresses with [account] in transactions with at least [minconf] confirmations. If [account] is set to all return will include all transactions to all accounts

func (*Bitcoind) GetReceivedByAddress

func (b *Bitcoind) GetReceivedByAddress(address string, minconf uint32) (amount float64, err error)

Returns the amount received by <address> in transactions with at least [minconf] confirmations. It correctly handles the case where someone has sent to the address in multiple transactions. Keep in mind that addresses are only ever used for receiving transactions. Works only for addresses in the local wallet, external addresses will always show 0.

func (*Bitcoind) GetTransaction

func (b *Bitcoind) GetTransaction(txid string) (transaction Transaction, err error)

GetTransaction returns a Bitcoind.Transation struct about the given transaction

func (*Bitcoind) GetTxOut

func (b *Bitcoind) GetTxOut(txid string, n uint32, includeMempool bool) (transactionOut UTransactionOut, err error)

GetTxOut returns details about an unspent transaction output (UTXO)

func (*Bitcoind) GetTxOutsetInfo

func (b *Bitcoind) GetTxOutsetInfo() (txOutSet TransactionOutSet, err error)

GetTxOutsetInfo returns statistics about the unspent transaction output (UTXO) set

func (*Bitcoind) ListAccounts

func (b *Bitcoind) ListAccounts(minconf int32) (accounts map[string]float64, err error)

ListAccounts returns Object that has account names as keys, account balances as values.

func (*Bitcoind) ListLockUnspent

func (b *Bitcoind) ListLockUnspent() (unspendableOutputs []UnspendableOutput, err error)

ListLockUnspent returns list of temporarily unspendable outputs

func (*Bitcoind) ListSinceBlock

func (b *Bitcoind) ListSinceBlock(blockHash string, targetConfirmations uint32) (transaction []Transaction, err error)

ListSinceBlock

func (*Bitcoind) ListTransactions

func (b *Bitcoind) ListTransactions(account string, count, from uint32) (transaction []Transaction, err error)

ListTransactions returns up to [count] most recent transactions skipping the first [from] transactions for account [account]. If [account] not provided it'll return recent transactions from all accounts.

func (*Bitcoind) ListUnspent

func (b *Bitcoind) ListUnspent(minconf, maxconf uint32) (transactions []Transaction, err error)

ListUnspent returns array of unspent transaction inputs in the wallet.

func (*Bitcoind) LockUnspent

func (b *Bitcoind) LockUnspent(lock bool, outputs []UnspendableOutput) (success bool, err error)

LockUnspent updates(lock/unlock) list of temporarily unspendable outputs

func (*Bitcoind) Move

func (b *Bitcoind) Move(formAccount, toAccount string, amount float64, minconf uint32, comment string) (success bool, err error)

Move from one account in your wallet to another

func (*Bitcoind) PublishTx

func (b *Bitcoind) PublishTx(tx *wire.MsgTx, name string) (*chainhash.Hash, error)

func (*Bitcoind) SendFrom

func (b *Bitcoind) SendFrom(fromAccount, toAddress string, amount float64, minconf uint32, comment, commentTo string) (txID string, err error)

SendFrom send amount from fromAccount to toAddress

amount is a real and is rounded to 8 decimal places.
Will send the given amount to the given address, ensuring the account has a valid balance using [minconf] confirmations.

func (*Bitcoind) SendToAddress

func (b *Bitcoind) SendToAddress(toAddress string, amount float64, comment, commentTo string) (txID string, err error)

SendToAddress send an amount to a given address

func (*Bitcoind) SignRawTransaction

func (b *Bitcoind) SignRawTransaction(tx *wire.MsgTx) (*wire.MsgTx, bool, error)

SignRawTransaction signs inputs for the passed transaction and returns the signed transaction as well as whether or not all inputs are now signed.

This function assumes the RPC server already knows the input transactions and private keys for the passed transaction which needs to be signed and uses the default signature hash type. Use one of the SignRawTransaction# variants to specify that information if needed.

func (*Bitcoind) Stop

func (b *Bitcoind) Stop() error

Stop stop bitcoin server.

func (*Bitcoind) ValidateAddress

func (b *Bitcoind) ValidateAddress(address string) (va ValidateAddressResponse, err error)

ValidateAddress return information about <bitcoinaddress>.

type Block

type Block struct {
	// The block hash
	Hash string `json:"hash"`
	// The number of confirmations
	Confirmations uint64 `json:"confirmations"`
	// The block size
	Size uint64 `json:"size"`
	// The block height or index
	Height uint64 `json:"height"`
	// The block version
	Version uint32 `json:"version"`
	// The merkle root
	Merkleroot string `json:"merkleroot"`
	// The block time in seconds since epoch (Jan 1 1970 GMT)
	Time int64 `json:"time"`
	// The nonce
	Nonce uint64 `json:"nonce"`
	// The bits
	Bits string `json:"bits"`
	// The difficulty
	Difficulty float64 `json:"difficulty"`
	// Total amount of work in active chain, in hexadecimal
	Chainwork string `json:"chainwork,omitempty"`
	// The hash of the previous block
	Previousblockhash string `json:"previousblockhash"`
	// The hash of the next block
	Nextblockhash string `json:"nextblockhash"`
	// Slice on transaction ids
	Tx []string `json:"tx"`
}

Block - Represents a block

type RawTransaction

type RawTransaction struct {
	Hex           string `json:"hex"`
	Txid          string `json:"txid"`
	Version       uint32 `json:"version"`
	LockTime      uint32 `json:"locktime"`
	Vin           []Vin  `json:"vin"`
	Vout          []Vout `json:"vout"`
	BlockHash     string `json:"blockhash,omitempty"`
	Confirmations uint64 `json:"confirmations,omitempty"`
	Time          int64  `json:"time,omitempty"`
	Blocktime     int64  `json:"blocktime,omitempty"`
}

RawTx - represents a raw transaction

type ScriptPubKey

type ScriptPubKey struct {
	Asm       string   `json:"asm"`
	Hex       string   `json:"hex"`
	ReqSigs   int      `json:"reqSigs,omitempty"`
	Type      string   `json:"type"`
	Addresses []string `json:"addresses,omitempty"`
}

ScriptPubKey - represents a scriptpubkey

type ScriptSig

type ScriptSig struct {
	Asm string `json:"asm"`
	Hex string `json:"hex"`
}

ScriptSig - represents a scriptsyg

type Transaction

type Transaction struct {
	Amount          float64              `json:"amount"`
	Account         string               `json:"account,omitempty"`
	Address         string               `json:"address,omitempty"`
	Category        string               `json:"category,omitempty"`
	Fee             float64              `json:"fee,omitempty"`
	Confirmations   int64                `json:"confirmations"`
	BlockHash       string               `json:"blockhash"`
	BlockIndex      int64                `json:"blockindex"`
	BlockTime       int64                `json:"blocktime"`
	TxID            string               `json:"txid"`
	WalletConflicts []string             `json:"walletconflicts"`
	Time            int64                `json:"time"`
	TimeReceived    int64                `json:"timereceived"`
	Details         []TransactionDetails `json:"details,omitempty"`
	Hex             string               `json:"hex,omitempty"`
}

Transaction - represents a transaction

type TransactionDetails

type TransactionDetails struct {
	Account  string  `json:"account"`
	Address  string  `json:"address,omitempty"`
	Category string  `json:"category"`
	Amount   float64 `json:"amount"`
	Fee      float64 `json:"fee,omitempty"`
}

TransactionDetails - represents details about a transaction

type TransactionOutSet

type TransactionOutSet struct {
	Height          uint32  `json:"height"`
	Bestblock       string  `json:"bestblock"`
	Transactions    float64 `json:"transactions"`
	TxOuts          float64 `json:"txouts"`
	BytesSerialized float64 `json:"bytes_serialized"`
	HashSerialized  string  `json:"hash_serialized"`
	TotalAmount     float64 `json:"total_amount"`
}

TransactionOutSet - represents statistics about the unspent transaction output database

type UTransactionOut

type UTransactionOut struct {
	Bestblock     string       `json:"bestblock"`
	Confirmations uint32       `json:"confirmations"`
	Value         float64      `json:"value"`
	ScriptPubKey  ScriptPubKey `json:"scriptPubKey"`
	Version       uint32       `json:"version"`
	Coinbase      bool         `json:"coinbase"`
}

UTransactionOut - represents a unspent transaction out (UTXO)

type UnspendableOutput

type UnspendableOutput struct {
	TxId string `json:"txid"`
	Vout uint64 `json:"vout"`
}

UnspendableOutput - represents a unspendable (locked) output

type ValidateAddressResponse

type ValidateAddressResponse struct {
	IsValid      bool   `json:"isvalid"`
	Address      string `json:"address"`
	IsMine       bool   `json:"ismine"`
	IsScript     bool   `json:"isscript"`
	PubKey       string `json:"pubkey"`
	IsCompressed bool   `json:"iscompressed"`
	Account      string `json:"account"`
}

ValidateAddressResponse - represents a response to "validateaddress" call

type Vin

type Vin struct {
	Coinbase  string    `json:"coinbase"`
	Txid      string    `json:"txid"`
	Vout      int       `json:"vout"`
	ScriptSig ScriptSig `json:"scriptSig"`
	Sequence  uint32    `json:"sequence"`
}

Vin - represent an IN value

type Vout

type Vout struct {
	Value        float64      `json:"value"`
	N            int          `json:"n"`
	ScriptPubKey ScriptPubKey `json:"scriptPubKey"`
}

Vout - represent an OUT value

Jump to

Keyboard shortcuts

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