Documentation
¶
Overview ¶
Package cli implements an interface for creating a CLI application. Includes methods for manipulating wallets files and interacting with the webrpc API to query a spo node's status.
Example ¶
// In cmd/cli/cli.go:
cfg, err := LoadConfig()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
app := NewApp(cfg)
if err := app.Run(os.Args); err != nil {
fmt.Println(err)
os.Exit(1)
}
Index ¶
- Constants
- Variables
- func AddPrivateKey(wlt *wallet.Wallet, key string) error
- func AddPrivateKeyToFile(walletFile, key string) error
- func AddressesToStrings(addrs []cipher.Address) []string
- func CreateRawTx(c *webrpc.Client, wlt *wallet.Wallet, inAddrs []string, chgAddr string, ...) (*coin.Transaction, error)
- func CreateRawTxFromAddress(c *webrpc.Client, addr, walletFile, chgAddr string, toAddrs []SendAmount) (*coin.Transaction, error)
- func CreateRawTxFromWallet(c *webrpc.Client, walletFile, chgAddr string, toAddrs []SendAmount) (*coin.Transaction, error)
- func FormatAddressesAsJSON(addrs []cipher.Address) (string, error)
- func FormatAddressesAsJoinedArray(addrs []cipher.Address) string
- func GenerateAddressesInFile(walletFile string, num uint64) ([]cipher.Address, error)
- func GenerateWallet(walletFile, label, seed string, numAddrs uint64) (*wallet.Wallet, error)
- func GetWalletOutputs(c *webrpc.Client, wlt *wallet.Wallet) (*webrpc.OutputsResult, error)
- func GetWalletOutputsFromFile(c *webrpc.Client, walletFile string) (*webrpc.OutputsResult, error)
- func IntegrityCheck(db *bolt.DB, genesisPubkey cipher.PubKey) error
- func MakeAlphanumericSeed() string
- func NewTransaction(utxos []wallet.UxBalance, keys []cipher.SecKey, outs []coin.TransactionOutput) *coin.Transaction
- func RPCClientFromContext(c *gcli.Context) *webrpc.Client
- func SendFromAddress(c *webrpc.Client, addr, walletFile, chgAddr string, toAddrs []SendAmount) (string, error)
- func SendFromWallet(c *webrpc.Client, walletFile, chgAddr string, toAddrs []SendAmount) (string, error)
- type AddrHistory
- type AddressBalance
- type App
- type Balance
- type BalanceResult
- type Config
- type SendAmount
- type WalletEntry
- type WalletLoadError
- type WalletSaveError
Examples ¶
Constants ¶
const (
// AlphaNumericSeedLength is the size of generated alphanumeric seeds, in bytes
AlphaNumericSeedLength = 64
)
const (
// Version is the CLI Version
Version = "0.23.0"
)
Variables ¶
var ( // ErrWalletName is returned if the wallet file name is invalid ErrWalletName = fmt.Errorf("error wallet file name, must have %s extension", walletExt) // ErrAddress is returned if an address is invalid ErrAddress = errors.New("invalid address") // ErrJSONMarshal is returned if JSON marshaling failed ErrJSONMarshal = errors.New("json marshal failed") )
var ( // ErrTemporaryInsufficientBalance is returned if a wallet does not have enough balance for a spend, but will have enough after unconfirmed transactions confirm ErrTemporaryInsufficientBalance = errors.New("balance is not sufficient. Balance will be sufficient after unconfirmed transactions confirm") )
Functions ¶
func AddPrivateKey ¶
AddPrivateKey adds a private key to a *wallet.Wallet. Caller should save the wallet afterwards
func AddPrivateKeyToFile ¶
AddPrivateKeyToFile adds a private key to a wallet based on filename. Will save the wallet after modifying.
func AddressesToStrings ¶
AddressesToStrings converts []cipher.Address to []string
func CreateRawTx ¶
func CreateRawTx(c *webrpc.Client, wlt *wallet.Wallet, inAddrs []string, chgAddr string, toAddrs []SendAmount) (*coin.Transaction, error)
CreateRawTx creates a transaction from a set of addresses contained in a loaded *wallet.Wallet
func CreateRawTxFromAddress ¶
func CreateRawTxFromAddress(c *webrpc.Client, addr, walletFile, chgAddr string, toAddrs []SendAmount) (*coin.Transaction, error)
CreateRawTxFromAddress creates a transaction from a specific address in a wallet
func CreateRawTxFromWallet ¶
func CreateRawTxFromWallet(c *webrpc.Client, walletFile, chgAddr string, toAddrs []SendAmount) (*coin.Transaction, error)
CreateRawTxFromWallet creates a transaction from any address or combination of addresses in a wallet
func FormatAddressesAsJSON ¶
FormatAddressesAsJSON converts []cipher.Address to strings and formats the array into a standard JSON object wrapper
func FormatAddressesAsJoinedArray ¶
FormatAddressesAsJoinedArray converts []cipher.Address to strings and concatenates them with a comma
func GenerateAddressesInFile ¶
GenerateAddressesInFile generates addresses in given wallet file
func GenerateWallet ¶
GenerateWallet generates a new wallet with filename walletFile, label, seed and number of addresses. Caller should save the wallet file to its chosen directory
func GetWalletOutputs ¶
GetWalletOutputs returns unspent outputs associated with all addresses in a wallet.Wallet
func GetWalletOutputsFromFile ¶
GetWalletOutputsFromFile returns unspent outputs associated with all addresses in a wallet file
func IntegrityCheck ¶
IntegrityCheck checks database integrity
func MakeAlphanumericSeed ¶
func MakeAlphanumericSeed() string
MakeAlphanumericSeed creates a random seed with AlphaNumericSeedLength bytes and hex encodes it
func NewTransaction ¶
func NewTransaction(utxos []wallet.UxBalance, keys []cipher.SecKey, outs []coin.TransactionOutput) *coin.Transaction
NewTransaction creates a transaction. The transaction should be validated against hard and soft constraints before transmission.
func RPCClientFromContext ¶
RPCClientFromContext returns a webrpc.Client from a urfave/cli Context
func SendFromAddress ¶
func SendFromAddress(c *webrpc.Client, addr, walletFile, chgAddr string, toAddrs []SendAmount) (string, error)
SendFromAddress sends from a specific address in a wallet. Returns txid.
func SendFromWallet ¶
func SendFromWallet(c *webrpc.Client, walletFile, chgAddr string, toAddrs []SendAmount) (string, error)
SendFromWallet sends from any address or combination of addresses from a wallet. Returns txid.
Types ¶
type AddrHistory ¶
type AddrHistory struct {
BlockSeq uint64 `json:"-"`
Txid string `json:"txid"`
Address string `json:"address"`
Amount string `json:"amount"`
Timestamp time.Time `json:"timestamp"`
Status int `json:"status"`
// contains filtered or unexported fields
}
AddrHistory represents a transactional event for an address
type AddressBalance ¶
type AddressBalance struct {
Confirmed Balance `json:"confirmed"`
Spendable Balance `json:"spendable"`
Expected Balance `json:"expected"`
Address string `json:"address"`
}
AddressBalance represents an address's balance
type App ¶
App Wraps the app so that main package won't use the raw App directly, which will cause import issue
type BalanceResult ¶
type BalanceResult struct {
Confirmed Balance `json:"confirmed"`
Spendable Balance `json:"spendable"`
Expected Balance `json:"expected"`
Addresses []AddressBalance `json:"addresses"`
}
BalanceResult represents an set of addresses' balances
func CheckWalletBalance ¶
func CheckWalletBalance(c *webrpc.Client, walletFile string) (*BalanceResult, error)
CheckWalletBalance returns the total and individual balances of addresses in a wallet file
func GetBalanceOfAddresses ¶
func GetBalanceOfAddresses(c *webrpc.Client, addrs []string) (*BalanceResult, error)
GetBalanceOfAddresses returns the total and individual balances of a set of addresses
type Config ¶
type Config struct {
WalletDir string
WalletName string
DataDir string
Coin string
RPCAddress string
}
Config cli's configuration struct
func ConfigFromContext ¶
ConfigFromContext returns a Config from a urfave/cli Context
func LoadConfig ¶
LoadConfig loads config from environment, prior to parsing CLI flags
func (Config) FullDBPath ¶
FullDBPath returns the joined data directory and db file name path
func (Config) FullWalletPath ¶
FullWalletPath returns the joined wallet dir and wallet name path
type SendAmount ¶
SendAmount represents an amount to send to an address
type WalletEntry ¶
type WalletEntry struct {
Name string `json:"name"`
Label string `json:"label"`
AddressNum int `json:"address_num"`
}
WalletEntry represents an enty in a wallet file
type WalletLoadError ¶
type WalletLoadError error
WalletLoadError is returned if a wallet could not be loaded
type WalletSaveError ¶
type WalletSaveError error
WalletSaveError is returned if a wallet could not be saved