Help us shape the future of Go! Take the 2026 Go Developer Survey

omnicli

package module
v0.5.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2019 License: BSD-3-Clause Imports: 11 Imported by: 0

README

Omnicore cli wrapper

Control omnicored omnicore-cli from golang.

Zero dependency.

Currently not support windows

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

How to use?

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

Notice:

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

LiCENSE

BSD 3-Clause License

Documentation

Index

Constants

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

	RPCPortRegtest = 18443

	OmniBinPathEnv = "OMNI_BIN_PATH"

	CmdParamRegtest = "-regtest"
)

固定常量

View Source
const (
	NetRegtest = iota + 1
	NetTestnet3
	NetMainnet
)

some net id

Variables

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

omnicore 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 IfOrString

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

IfOrString if flag return s ,or s2

func NoPrintCmd

func NoPrintCmd(fn func())

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
}

Addr .

func (*Addr) String

func (ad *Addr) String() string

type Cli

type Cli struct {
	IgnoreCliCmd bool //not print cmd
	IgnoreCliOut bool //not print cli out
	// contains filtered or unexported fields
}

Cli .

func NewCliFromRunningOmnicored

func NewCliFromRunningOmnicored(options RunningOmnicoredOptions) (*Cli, error)

NewCliFromRunningOmnicored .

func RunOmnicored

func RunOmnicored(optionsPtr *RunOptions) (*Cli, func(), error)

RunOmnicored .

func (*Cli) Addmultisigaddress

func (cli *Cli) Addmultisigaddress(cmd btcjson.AddMultisigAddressCmd) (string, error)

Addmultisigaddress .

func (*Cli) AppendArgs

func (cli *Cli) AppendArgs(args ...string) []string

AppendArgs .

func (*Cli) Createmultisig

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

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

func (*Cli) DecodeAndPrintTX

func (cli *Cli) DecodeAndPrintTX(title, rawtx string)

DecodeAndPrintTX panic on error

func (*Cli) Dumpprivkey

func (cli *Cli) Dumpprivkey(addr string) (string, error)

Dumpprivkey https://bitcoin.org/en/developer-reference#dumpprivkey

func (*Cli) Generatetoaddress

func (cli *Cli) Generatetoaddress(nBlocks uint, address string, maxtriesPtr *uint) ([]string, error)

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

func (*Cli) GetMemPoolAncestors

func (cli *Cli) GetMemPoolAncestors(txid string, verbose bool, ret *MemPoolAncestorsResult) error

GetMemPoolAncestors .

func (*Cli) GetWalletInfo

func (cli *Cli) GetWalletInfo() (map[string]interface{}, error)

GetWalletInfo .

func (*Cli) Getbestblockhash

func (cli *Cli) Getbestblockhash() (string, error)

Getbestblockhash .

func (*Cli) Getblockcount

func (cli *Cli) Getblockcount() (int, error)

Getblockcount .

func (*Cli) Getblockhash

func (cli *Cli) Getblockhash(height int) (string, error)

Getblockhash .

func (*Cli) Getnewaddress

func (cli *Cli) Getnewaddress(labelPtr, addressTypePtr *string) (hexedAddress string, err error)

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

func (*Cli) Getrawtransaction

func (cli *Cli) Getrawtransaction(cmd btcjson.GetRawTransactionCmd) (*btcjson.RawTx, error)

Getrawtransaction .

func (*Cli) Getreceivedbyaddress

func (cli *Cli) Getreceivedbyaddress(addr string, minconf int) (string, error)

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

func (*Cli) Gettransaction

func (cli *Cli) Gettransaction(txid string, includeWatchonly bool) (*btcjson.GetTransactionResult, error)

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

func (*Cli) Importaddress

func (cli *Cli) Importaddress(cmd btcjson.ImportAddressCmd) error

Importaddress .

func (*Cli) Listunspent

func (cli *Cli) Listunspent(minconf, maxconf int, addresses []string) ([]btcjson.ListUnspentResult, error)

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

func (*Cli) OmniCreatepaloadSimplesend

func (cli *Cli) OmniCreatepaloadSimplesend(propertyID int, amount string) (string, error)

OmniCreatepaloadSimplesend .

func (*Cli) OmniCreaterawtxChange

func (cli *Cli) OmniCreaterawtxChange(rawtx string, prevtxs []btcjson.PreviousDependentTxOutput, destination string, fee float64, position *int) (string, error)

OmniCreaterawtxChange https://github.com/OmniLayer/omnicore/blob/master/src/omnicore/doc/rpc-api.md#omni_createrawtx_change

func (*Cli) OmniCreaterawtxOpreturn

func (cli *Cli) OmniCreaterawtxOpreturn(rawtx string, payload string) (string, error)

OmniCreaterawtxOpreturn 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 (*Cli) OmniCreaterawtxReference

func (cli *Cli) OmniCreaterawtxReference(rawtx, destination string, amount *int) (string, error)

OmniCreaterawtxReference 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 (*Cli) OmniGettransaction

func (cli *Cli) OmniGettransaction(txHash string) (*OmniGettransactionResult, error)

OmniGettransaction .

func (*Cli) Signrawtransaction

func (cli *Cli) Signrawtransaction(cmd btcjson.SignRawTransactionCmd) (btcjson.SignRawTransactionResult, error)

Signrawtransaction .

func (*Cli) Signrawtransactionwithkey

func (cli *Cli) Signrawtransactionwithkey(cmd btcjson.SignRawTransactionCmd) (btcjson.SignRawTransactionResult, error)

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

func (*Cli) ToolGetSomeAddrs

func (cli *Cli) ToolGetSomeAddrs(n int) ([]Addr, error)

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

func (*Cli) Validateaddress

func (cli *Cli) Validateaddress(addr string) (ValidateAddressResp, error)

Validateaddress .

type MemPoolAncestorsResult

type MemPoolAncestorsResult struct {
	NoVerbose []string
	Verbose   *btcjson.GetMempoolEntryResult
}

MemPoolAncestorsResult .

type OmniFundedSendCmd

type OmniFundedSendCmd struct {
	Fromaddress string //required 	the address to send the tokens from
	Toaddress   string //required 	the address of the receiver
	Propertyid  int    //required 	the identifier of the tokens to send
	Amount      string //required 	the amount to send
	Feeaddress  string //required 	the address that is used for change and to pay for fees, if needed
}

OmniFundedSendCmd .

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 .

type OmniSenddissuancefixedCmd

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

OmniSenddissuancefixedCmd . fromaddress string required the address to send from ecosystem number required the ecosystem to create the tokens in (1 for main ecosystem, 2 for test ecosystem) type number required the type of the tokens to create: (1 for indivisible tokens, 2 for divisible tokens) previousid number required an identifier of a predecessor token (0 for new tokens) category string required a category for the new tokens (can be "") subcategory string required a subcategory for the new tokens (can be "") name string required the name of the new tokens to create url string required an URL for further information about the new tokens (can be "") data string required a description for the new tokens (can be "") amount string required the number of tokens to create

type RunOptions

type RunOptions struct {
	NewTmpDir bool //创建一个临时的目录,并在完成后立即删除这个目录
	RPCPort   uint
	Args      []string
}

RunOptions .

type RunningOmnicoredOptions

type RunningOmnicoredOptions struct {
	RPCPort     uint
	RPCUser     string
	RPCPassword string
	DataDir     string
	NetID       uint32
}

RunningOmnicoredOptions .

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 .

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