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 skycoin node's status.
Example ¶
// In cmd/cli/cli.go: cfg, err := LoadConfig() if err != nil { fmt.Println(err) os.Exit(1) } app, err := NewApp(cfg) if err != nil { fmt.Println(err) os.Exit(1) } if err := app.Run(os.Args); err != nil { fmt.Println(err) os.Exit(1) }
Output:
Index ¶
- Constants
- Variables
- func AddPrivateKey(wlt *wallet.Wallet, key string) error
- func AddPrivateKeyToFile(walletFile, key string, pr PasswordReader) 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, pr PasswordReader) ([]cipher.Address, error)
- func GenerateWallet(walletFile string, opts wallet.Options, 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 MakeAlphanumericSeed() string
- func NewTransaction(utxos []wallet.UxBalance, keys []cipher.SecKey, outs []coin.TransactionOutput) *coin.Transaction
- func QuitChanFromContext(c *gcli.Context) chan struct{}
- func RPCClientFromContext(c *gcli.Context) *webrpc.Client
- type AddrHistory
- type AddressBalance
- type App
- type Balance
- type BalanceResult
- type Config
- type PasswordFromBytes
- type PasswordFromTerm
- type PasswordReader
- type SendAmount
- type StatusResult
- 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.24.1"
)
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 ¶
func AddPrivateKeyToFile(walletFile, key string, pr PasswordReader) error
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, password []byte) (*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, pr PasswordReader) (*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, pr PasswordReader) (*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 ¶
func GenerateAddressesInFile(walletFile string, num uint64, pr PasswordReader) ([]cipher.Address, error)
GenerateAddressesInFile generates addresses in given wallet file
func GenerateWallet ¶
func GenerateWallet(walletFile string, opts wallet.Options, numAddrs uint64) (*wallet.Wallet, error)
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 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 QuitChanFromContext ¶
QuitChanFromContext returns a chan struct{} from a urfave/cli Context
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 `json:"wallet_directory"` WalletName string `json:"wallet_name"` DataDir string `json:"data_directory"` Coin string `json:"coin"` RPCAddress string `json:"rpc_address"` UseCSRF bool `json:"use_csrf"` }
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 PasswordFromBytes ¶
type PasswordFromBytes []byte
PasswordFromBytes represents an implementation of PasswordReader, which reads password from the bytes itself.
func (PasswordFromBytes) Password ¶
func (p PasswordFromBytes) Password() ([]byte, error)
Password implements the PasswordReader's Password method
type PasswordFromTerm ¶
type PasswordFromTerm struct{}
PasswordFromTerm reads password from terminal
func (PasswordFromTerm) Password ¶
func (p PasswordFromTerm) Password() ([]byte, error)
Password implements the PasswordReader's Password method
type PasswordReader ¶
PasswordReader is an interface for getting password
func NewPasswordReader ¶
func NewPasswordReader(p []byte) PasswordReader
NewPasswordReader creats a PasswordReader instance, reads password from the input bytes first, if it's empty, then read from terminal.
type SendAmount ¶
SendAmount represents an amount to send to an address
type StatusResult ¶
type StatusResult struct { webrpc.StatusResult RPCAddress string `json:"webrpc_address"` UseCSRF bool `json:"use_csrf"` }
StatusResult is printed by cli status command
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 struct {
// contains filtered or unexported fields
}
WalletLoadError is returned if a wallet could not be loaded
type WalletSaveError ¶
type WalletSaveError struct {
// contains filtered or unexported fields
}
WalletSaveError is returned if a wallet could not be saved
Source Files ¶
- add_private_key.go
- address_gen.go
- blocks.go
- broadcast_rawtx.go
- check_balance.go
- checkdb.go
- cli.go
- create_rawtx.go
- decryptWallet.go
- encrypt_wallet.go
- generate_addrs.go
- generate_wallet.go
- last_blocks.go
- list_addrs.go
- list_wallets.go
- outputs.go
- send.go
- show_seed.go
- status.go
- transaction.go
- verify_address.go
- version.go
- wallet_dir.go
- wallet_history.go