omnicli

package module
v0.0.0-...-1af0624 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 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

	OmniBinPathEnv = "OMNI_BIN_PATH"

	CmdParamRegtest = "-regtest"
)

固定常量

Variables

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

bitcoin bin path

View Source
var (
	// PresetAccounts 一些预置账号
	PresetAccounts = []Addr{
		{Address: "mt6WnfniPEKziTgmAdebBkT33vAcM7jJFC", Privkey: "cTBichWb6XBPa6F6NUc3gkLjYDufRWx74CnJWEypxuFNsXd6dJNb", Pubkey: "032affe4397f911be5d4ff84531d84b7d9498263731f8c205c1082e73abcc60955"},
		{Address: "miP2AS7DQmQuc9WSYzz5uJrFh6xhe4TvYw", Privkey: "cVWuAHG981YURgJCFRYHuVdApgKtmciujVmkYFkZnaVeMLXz3pKX", Pubkey: "0264f183744e1dd7523ead4eef81b99e13870a8234724ee9035aee0ccfa70f1b1a"},
		{Address: "n4ekdCUgRUCZxAiVTiCKfKVU4fz5SewcKr", Privkey: "cNczugkPEDYcCm1UhukMJp1XCGdtqez4cVfzK4yBfcxtYbF2Ui7r", Pubkey: "0383b83e84538b334df3f8820539053e635e30ba05b85a05850302971d9b3ece3c"},
		{Address: "mrmsAWtDKgqGEppz2ULnd1yjthinGgZmY9", Privkey: "cNkMpgrsvvRjzkNYvBmMBWLbusFgCWJNrbfzhecmmSaKN7q9cgwx", Pubkey: "03ca007eefc39e3406d2131cf498efd5cca7fe3b3c5b61625b58a8342e84a4f947"},
		{Address: "mtxrtZn5RnMGXADrfUaMcyrb8EJ1c7276W", Privkey: "cN4pHDRjKbCjHot5iyQorPRVQWQqfRuWTFbCgPCz2UG2y1K9oHv9", Pubkey: "02f0744be0f11fd0db10bd669bb20f29e8fdbfdc39b0b9d1f8c81be2f42d7068a7"},
		{Address: "n162u2V7Sav6mUC1baJ1u7hGrBtsSLdszq", Privkey: "cN8Sq2fjq5bnUsRTQNL6CSdwxA7d2FmSsSG9r8h1DBwfY7eaz5EA", Pubkey: "02e5dcd14da054866160fa9adb1af3e04c21eae1d2677b46bded4d9b7f7b5a22b3"},
		{Address: "mopaTypypdaFh3u5nV16vsqZb22DcqM1pf", Privkey: "cUCXumLXtHHjLBr3mn888uyBvx45ELwznnzPzuFCvk9SThUi7jUJ", Pubkey: "0285c13d0769efbf118a0b7f5b87150f8f87fbe07a7acca8fe3a92e8b6541b0a65"},
		{Address: "mxFFWmHfp1Gz657QZeVuGiTCeEk71Z6aYX", Privkey: "cRsF4QaXXVwBNgunPEzNgEHkxz8GoeWzZ8jrk8JM46unBZaaiXmP", Pubkey: "03c935d1934055b83e1b19e60d16a8c9d4f89392aa3057d32b7d88a5ea36b098f6"},
		{Address: "mqbyybrXRZwHUET7taiShJ1S6dScnBd7yg", Privkey: "cV7Z95EMA7G5vrQ9bCe1tZRmL5eMncimvVXPjY9FuR7UyKzWvdZH", Pubkey: "0326b988f6da309846aded94a56f3230e1bdd1494878343830e89053ddd596e069"},
		{Address: "mzfveH16kQ7rNdPHNJMrkpWqjo7hVdpVHC", Privkey: "cPEnbKH87636VhGhsVQxHBV6RmPyp3d1NL9q9XQJGXpyMhyUJoMJ", Pubkey: "026c27bbb52665e6d1d3d1f5ccb8ac7b7b27ee8636019af14272ebaa0308b800b2"},
	}
)
View Source
var (
	PrintCmdOut = true
)

global vars

Functions

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 CliGetWalletInfo

func CliGetWalletInfo() (map[string]interface{}, error)

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) ([]btcjson.ListUnspentResult, error)

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

func CliOmniCreatepaloadSimplesend

func CliOmniCreatepaloadSimplesend(propertyID int, amount string) (string, error)

CliOmniCreatepaloadSimplesend .

func CliOmniCreaterawtxOpreturn

func CliOmniCreaterawtxOpreturn(rawtx string, payload string) (string, error)

CliOmniCreaterawtxOpreturn Adds a payload with class C (op-return) encoding to the transaction. If no raw transaction is provided, a new transaction is created. If the data encoding fails, then the transaction is not modified.

func CliOmniCreaterawtxReference

func CliOmniCreaterawtxReference(rawtx, destination string, amount *int) (string, error)

CliOmniCreaterawtxReference Adds a reference output to the transaction. If no raw transaction is provided, a new transaction is created. The output value is set to at least the dust threshold.

func CliSignrawtransaction

CliSignrawtransaction .

func CliSignrawtransactionwithkey

func CliSignrawtransactionwithkey(cmd btcjson.SignRawTransactionCmd) (btcjson.SignRawTransactionResult, error)

CliSignrawtransactionwithkey [Disabled in omni current version] https://bitcoin.org/en/developer-reference#signrawtransactionwithkey

func DecodeAndPrintTX

func DecodeAndPrintTX(title, rawtx string)

DecodeAndPrintTX panic on error

func IfOrString

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

IfOrString if flag return s ,or s2

func NoPrintCmd

func NoPrintCmd(fn func())

func StartOmnicored

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

StartOmnicored 启动bitcoind -regtest 用以测试. return close channel (cc)

func ToError

func ToError(str string) error

ToError 如果含有error字样,则视为error

func ToJson

func ToJson(i interface{}) string

func ToJsonIndent

func ToJsonIndent(i interface{}) string

func WrapJSONDecodeError

func WrapJSONDecodeError(e error, rawJSON string) error

WrapJSONDecodeError include raw json in error

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 OmniGetbalanceResult

type OmniGetbalanceResult struct {
	Balance  string `json:"balance"`
	Reserved string `json:"reserved"`
	Frozen   string `json:"frozen"`
}

OmniGetbalanceResult .

type OmniGettransactionResult

type OmniGettransactionResult struct {
	Txid             string `json:"txid"`             // (string) the hex-encoded hash of the transaction
	Sendingaddress   string `json:"sendingaddress"`   // (string) the Bitcoin address of the sender
	Referenceaddress string `json:"referenceaddress"` // (string) a Bitcoin address used as reference (if any)
	Ismine           bool   `json:"ismine"`           // (boolean) whether the transaction involes an address in the wallet
	Confirmations    int    `json:"confirmations"`    // (number) the number of transaction confirmations
	Fee              string `json:"fee"`              // (string) the transaction fee in bitcoins
	Blocktime        int    `json:"blocktime"`        // (number) the timestamp of the block that contains the transaction
	Valid            bool   `json:"valid"`            // (boolean) whether the transaction is valid
	Positioninblock  int    `json:"positioninblock"`  // (number) the position (index) of the transaction within the block
	Version          int    `json:"version"`          // (number) the transaction version
	TypeInt          int    `json:"type_int"`         // (number) the transaction type as number
	Type             string `json:"type"`             // (string) the transaction type as string
	//other
	Propertyid int `json:"propertyid"`
}

OmniGettransactionResult .

func CliOmniGettransaction

func CliOmniGettransaction(txHash string) (*OmniGettransactionResult, error)

CliOmniGettransaction .

type OmniSenddissuancefixedCmd

type OmniSenddissuancefixedCmd struct {
	Fromaddress                                    string
	Ecosystem                                      int
	Typ                                            int
	Previousid                                     int
	Category, Subcategory, Name, URL, Data, Amount string
}

OmniSenddissuancefixedCmd .

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"`
	Pubkey       string `json:"pubkey"`

	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