btccli

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

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

Go to latest
Published: Jul 5, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Bitcoin cli wrapper

Using go to wrap bitcoin cli.Useful for integreting bitcoin to tests.

See bitcoin-core-apis

Zero dependency.

Currently not support windows

Im developing under macOS and linux, not enough time to deal with windows.

How to use?

  • env variable BITCOIN_BIN_PATH to your [bitcoin bin] path (see init.go
  • init.go
  • func.go
  • other funcs normally start with name which same as file preffix (eg:func in cli_wrap.go usually like cliXxx)

Notice:

  • Some behaviors may be effected by your local bitcoin.conf.

TODO

versions

Im considering keep same as bitcoincore version, currently 0.18.0.

LiCENSE

BSD 3-Clause License

Documentation

Index

Constants

View Source
const (
	RPCUser   = "rpcusr"
	RPCPasswd = "233"

	RPCPortRegtest = 18443

	BitcoinBinPathEnv = "BITCOIN_BIN_PATH"

	CmdParamRegtest = "-regtest"
)

固定常量

Variables

View Source
var (
	BasePath      = "/Users/some_user/Applications/bitcoin/bin" //see init()
	CmdBitcoind   = BasePath + "/bitcoind"
	CmdBitcoinCli = BasePath + "/bitcoin-cli"
)

bitcoin bin path

View Source
var (
	PrintCmdOut = true
)

global vars

Functions

func BitcoindRegtest

func BitcoindRegtest() (closeChan chan struct{}, err error)

BitcoindRegtest 启动bitcoind -regtest 用以测试,

func CliCreatemultisig

func CliCreatemultisig(nRequired uint8, keys []string, addressType *string) (btcjson.CreateMultiSigResult, error)

CliCreatemultisig https://bitcoin.org/en/developer-reference#createmultisig

func CliGeneratetoaddress

func CliGeneratetoaddress(nBlocks uint, address string, maxtriesPtr *uint) ([]string, error)

CliGeneratetoaddress https://bitcoin.org/en/developer-reference#generatetoaddress

func CliGetAddressInfo

func CliGetAddressInfo(addr string) (*btcjson.GetAddressInfoResp, error)

func CliGetWalletInfo

func CliGetWalletInfo() map[string]interface{}

func CliGetbestblockhash

func CliGetbestblockhash() (string, error)

func CliGetblockcount

func CliGetblockcount() (int, error)

func CliGetblockhash

func CliGetblockhash(height int) (string, error)

func CliGetnewaddress

func CliGetnewaddress(labelPtr, addressTypePtr *string) (hexedAddress string, err error)

CliGetnewaddress https://bitcoin.org/en/developer-reference#getnewaddress

func CliGetrawtransaction

func CliGetrawtransaction(cmd btcjson.GetRawTransactionCmd) (*btcjson.RawTx, error)

CliGetrawtransaction .

func CliGetreceivedbyaddress

func CliGetreceivedbyaddress(addr string, minconf int) (string, error)

CliGetreceivedbyaddress https://bitcoin.org/en/developer-reference#getreceivedbyaddress

func CliGettransaction

func CliGettransaction(txid string, includeWatchonly bool) (*btcjson.GetTransactionResult, error)

CliGettransaction https://bitcoin.org/en/developer-reference#gettransaction

func CliImportaddress

func CliImportaddress(cmd btcjson.ImportAddressCmd) error

CliImportaddress .

func CliListunspent

func CliListunspent(minconf, maxconf int, addresses []string, includeUnsafe *bool, query *btcjson.ListUnspentQueryOptions) ([]btcjson.ListUnspentResult, error)

CliListunspent https://bitcoin.org/en/developer-reference#listunspent

func IfOrString

func IfOrString(flag bool, trueS, falseS string) string

IfOrString if flag return s ,or s2

func ToJson

func ToJson(i interface{}) string

func ToJsonIndent

func ToJsonIndent(i interface{}) string

Types

type Addr

type Addr struct {
	Address string
	Privkey string
	Pubkey  string
}

func CliToolGetSomeAddrs

func CliToolGetSomeAddrs(n int) ([]Addr, error)

CliToolGetSomeAddrs 一次获取n个地址(包含pub-priv key)

func (*Addr) String

func (ad *Addr) String() string

type ValidateAddressResp

type ValidateAddressResp struct {
	Isvalid      bool   `json:"isvalid"`
	Address      string `json:"address"`
	ScriptPubKey string `json:"scriptPubKey"`
	Isscript     bool   `json:"isscript"`
	Iswitness    bool   `json:"iswitness"`

	WitnessVersion string `json:"witness_version"` // version   (numeric, optional) The version number of the witness program
	WitnessProgram string `json:"witness_program"` // "hex"     (string, optional) The hex value of the witness program
}

ValidateAddressResp .

func CliValidateaddress

func CliValidateaddress(addr string) (ValidateAddressResp, error)

CliValidateaddress .

Directories

Path Synopsis
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.

Jump to

Keyboard shortcuts

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