cli

package
v0.0.0-...-d29d52d Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

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

Examples

Constants

View Source
const (
	// AlphaNumericSeedLength is the size of generated alphanumeric seeds, in bytes
	AlphaNumericSeedLength = 64
)
View Source
const (
	// Version is the CLI Version
	Version = "0.24.1"
)

Variables

View Source
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")
)
View Source
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

func AddPrivateKey(wlt *wallet.Wallet, key string) error

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

func AddressesToStrings(addrs []cipher.Address) []string

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

func FormatAddressesAsJSON(addrs []cipher.Address) (string, error)

FormatAddressesAsJSON converts []cipher.Address to strings and formats the array into a standard JSON object wrapper

func FormatAddressesAsJoinedArray

func FormatAddressesAsJoinedArray(addrs []cipher.Address) string

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

func GetWalletOutputs(c *webrpc.Client, wlt *wallet.Wallet) (*webrpc.OutputsResult, error)

GetWalletOutputs returns unspent outputs associated with all addresses in a wallet.Wallet

func GetWalletOutputsFromFile

func GetWalletOutputsFromFile(c *webrpc.Client, walletFile string) (*webrpc.OutputsResult, error)

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

func QuitChanFromContext(c *gcli.Context) chan struct{}

QuitChanFromContext returns a chan struct{} from a urfave/cli Context

func RPCClientFromContext

func RPCClientFromContext(c *gcli.Context) *webrpc.Client

RPCClientFromContext returns a webrpc.Client 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

type App struct {
	gcli.App
}

App Wraps the app so that main package won't use the raw App directly, which will cause import issue

func NewApp

func NewApp(cfg Config) (*App, error)

NewApp creates an app instance

func (*App) Run

func (app *App) Run(args []string) error

Run starts the app

type Balance

type Balance struct {
	Coins string `json:"coins"`
	Hours string `json:"hours"`
}

Balance represents an coin and hours balance

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

func ConfigFromContext(c *gcli.Context) Config

ConfigFromContext returns a Config from a urfave/cli Context

func LoadConfig

func LoadConfig() (Config, error)

LoadConfig loads config from environment, prior to parsing CLI flags

func (Config) FullDBPath

func (c Config) FullDBPath() string

FullDBPath returns the joined data directory and db file name path

func (Config) FullWalletPath

func (c Config) FullWalletPath() string

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

type PasswordReader interface {
	Password() ([]byte, error)
}

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

type SendAmount struct {
	Addr  string
	Coins uint64
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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