wallet

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 31 Imported by: 5

Documentation

Index

Constants

View Source
const (
	Version1 = 1 // initial version
	Version2 = 2 // supporting Ed25519

	VersionLatest = Version2
)

Variables

View Source
var (
	// ErrInvalidNetwork describes an error in which the network is invalid.
	ErrInvalidNetwork = errors.New("invalid network")

	// ErrOffline describes an error in which the wallet is offline.
	ErrOffline = errors.New("wallet is in offline mode")

	// ErrHistoryExists describes an error in which the transaction already exists
	// in history.
	ErrHistoryExists = errors.New("transaction already exists")
)

Functions

func CheckMnemonic added in v0.13.0

func CheckMnemonic(mnemonic string) error

CheckMnemonic is a wrapper for `vault.CheckMnemonic`.

func GenerateMnemonic

func GenerateMnemonic(entropy int) (string, error)

GenerateMnemonic is a wrapper for `vault.GenerateMnemonic`.

func OptionFee

func OptionFee(fee amount.Amount) func(builder *txBuilder) error

OptionFee sets the transaction fee using an Amount input.

func OptionFeeFromString added in v1.6.0

func OptionFeeFromString(feeStr string) func(builder *txBuilder) error

OptionFeeFromString sets the transaction fee using a string input.

func OptionLockTime added in v0.15.0

func OptionLockTime(lockTime uint32) func(builder *txBuilder) error

OptionLockTime sets the lock time for the transaction.

func OptionMemo

func OptionMemo(memo string) func(builder *txBuilder) error

OptionMemo sets a memo or note for the transaction.

Types

type CRCNotMatchError added in v0.15.0

type CRCNotMatchError struct {
	Expected uint32
	Got      uint32
}

CRCNotMatchError describes an error in which the wallet CRC is not matched.

func (CRCNotMatchError) Error added in v0.15.0

func (e CRCNotMatchError) Error() string

type Config added in v1.2.0

type Config struct {
	// private config
	WalletsDir string            `toml:"-"`
	ChainType  genesis.ChainType `toml:"-"`
}

func DefaultConfig added in v1.2.0

func DefaultConfig() *Config

type ExitsError added in v0.15.0

type ExitsError struct {
	Path string
}

ExitsError describes an error in which a wallet exists in the given path.

func (ExitsError) Error added in v0.15.0

func (e ExitsError) Error() string

type HistoryInfo

type HistoryInfo struct {
	TxID        string
	Time        *time.Time
	PayloadType string
	Desc        string
	Amount      amount.Amount
}

type Info added in v1.6.0

type Info struct {
	WalletName string
	Version    int64
	Network    string
	UUID       string
	Encrypted  bool
	CreatedAt  time.Time
}

type Manager added in v1.2.0

type Manager struct {
	// contains filtered or unexported fields
}

func NewWalletManager added in v1.2.0

func NewWalletManager(conf *Config) *Manager

func (*Manager) AddressHistory added in v1.2.0

func (wm *Manager) AddressHistory(
	walletName, address string,
) ([]HistoryInfo, error)

func (*Manager) CreateWallet added in v1.2.0

func (wm *Manager) CreateWallet(
	walletName, password string,
) (string, error)

func (*Manager) GetAddressInfo added in v1.6.0

func (wm *Manager) GetAddressInfo(walletName, address string) (*vault.AddressInfo, error)

func (*Manager) GetNewAddress added in v1.2.0

func (wm *Manager) GetNewAddress(
	walletName, label, password string,
	addressType crypto.AddressType,
) (*vault.AddressInfo, error)

func (*Manager) GetValidatorAddress added in v1.2.0

func (*Manager) GetValidatorAddress(
	publicKey string,
) (string, error)

func (*Manager) ListAddress added in v1.6.0

func (wm *Manager) ListAddress(walletName string) ([]vault.AddressInfo, error)

func (*Manager) ListWallet added in v1.6.0

func (wm *Manager) ListWallet() ([]string, error)

func (*Manager) LoadWallet added in v1.2.0

func (wm *Manager) LoadWallet(walletName, serverAddr string) error

func (*Manager) RestoreWallet added in v1.2.0

func (wm *Manager) RestoreWallet(walletName, mnemonic, password string) error

func (*Manager) SetAddressLabel added in v1.6.0

func (wm *Manager) SetAddressLabel(walletName, address, label string) error

func (*Manager) SignMessage added in v1.4.0

func (wm *Manager) SignMessage(walletName, password, addr, msg string) (string, error)

func (*Manager) SignRawTransaction added in v1.2.0

func (wm *Manager) SignRawTransaction(
	walletName, password string, rawTx []byte,
) ([]byte, []byte, error)

func (*Manager) TotalBalance added in v1.2.0

func (wm *Manager) TotalBalance(
	walletName string,
) (amount.Amount, error)

func (*Manager) TotalStake added in v1.6.0

func (wm *Manager) TotalStake(walletName string) (amount.Amount, error)

func (*Manager) UnloadWallet added in v1.2.0

func (wm *Manager) UnloadWallet(
	walletName string,
) error

func (*Manager) WalletInfo added in v1.6.0

func (wm *Manager) WalletInfo(walletName string) (*Info, error)

type Option added in v1.4.0

type Option func(*walletOpt)

func WithCustomServers added in v1.4.0

func WithCustomServers(servers []string) Option

func WithTimeout added in v1.4.0

func WithTimeout(timeout time.Duration) Option

type Store added in v1.5.0

type Store struct {
	Version   int               `json:"version"`
	UUID      uuid.UUID         `json:"uuid"`
	CreatedAt time.Time         `json:"created_at"`
	Network   genesis.ChainType `json:"network"`
	VaultCRC  uint32            `json:"crc"`
	Vault     *vault.Vault      `json:"vault"`
	History   history           `json:"history"`
}

func FromBytes added in v1.5.0

func FromBytes(data []byte) (*Store, error)

func (*Store) ToBytes added in v1.5.0

func (s *Store) ToBytes() ([]byte, error)

func (*Store) UpgradeWallet added in v1.5.0

func (s *Store) UpgradeWallet(walletPath string) error

func (*Store) ValidateCRC added in v1.5.0

func (s *Store) ValidateCRC() error

type TxOption

type TxOption func(builder *txBuilder) error

TxOption defines a function type used to apply options to a txBuilder.

type UnsupportedVersionError added in v1.5.0

type UnsupportedVersionError struct {
	WalletVersion    int
	SupportedVersion int
}

UnsupportedVersionError indicates the wallet version is incompatible with the software's supported version.

func (UnsupportedVersionError) Error added in v1.5.0

func (e UnsupportedVersionError) Error() string

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

func Create

func Create(walletPath, mnemonic, password string, chain genesis.ChainType,
	options ...Option,
) (*Wallet, error)

Create creates a wallet from mnemonic (seed phrase) and save it at the given path.

func Open added in v0.10.0

func Open(walletPath string, offline bool, options ...Option) (*Wallet, error)

Open tries to open a wallet at the given path. If the wallet doesn’t exist on this path, it returns an error. A wallet can be opened in offline or online modes. Offline wallet doesn’t have any connection to any node. Online wallet has a connection to one of the pre-defined servers.

func (*Wallet) AddTransaction

func (w *Wallet) AddTransaction(txID tx.ID) error

func (*Wallet) AddressCount

func (w *Wallet) AddressCount() int

AddressCount returns the number of addresses inside the wallet.

func (*Wallet) AddressFromPath added in v0.18.0

func (w *Wallet) AddressFromPath(p string) *vault.AddressInfo

func (*Wallet) AddressInfo

func (w *Wallet) AddressInfo(addr string) *vault.AddressInfo

func (*Wallet) AddressInfos added in v0.15.0

func (w *Wallet) AddressInfos() []vault.AddressInfo

func (*Wallet) AllAccountAddresses added in v1.1.0

func (w *Wallet) AllAccountAddresses() []vault.AddressInfo

func (*Wallet) AllValidatorAddresses added in v0.18.0

func (w *Wallet) AllValidatorAddresses() []vault.AddressInfo

func (*Wallet) Balance

func (w *Wallet) Balance(addrStr string) (amount.Amount, error)

Balance returns balance of the account associated with the address..

func (*Wallet) BroadcastTransaction

func (w *Wallet) BroadcastTransaction(trx *tx.Tx) (string, error)

func (*Wallet) CalculateFee

func (w *Wallet) CalculateFee(amt amount.Amount, payloadType payload.Type) (amount.Amount, error)

func (*Wallet) CoinType added in v1.6.0

func (w *Wallet) CoinType() uint32

func (*Wallet) Contains

func (w *Wallet) Contains(addr string) bool

func (*Wallet) CreationTime added in v1.5.0

func (w *Wallet) CreationTime() time.Time

func (*Wallet) History added in v1.5.0

func (w *Wallet) History(addr string) []HistoryInfo

func (*Wallet) ImportBLSPrivateKey added in v1.5.0

func (w *Wallet) ImportBLSPrivateKey(password string, prv *bls.PrivateKey) error

func (*Wallet) ImportEd25519PrivateKey added in v1.6.0

func (w *Wallet) ImportEd25519PrivateKey(password string, prv *ed25519.PrivateKey) error

func (*Wallet) Info added in v1.6.0

func (w *Wallet) Info() *Info

func (*Wallet) IsEncrypted

func (w *Wallet) IsEncrypted() bool

func (*Wallet) IsOffline

func (w *Wallet) IsOffline() bool

func (*Wallet) Label

func (w *Wallet) Label(addr string) string

Label returns label of addr.

func (*Wallet) MakeBondTx

func (w *Wallet) MakeBondTx(sender, receiver, pubKey string, amt amount.Amount,
	options ...TxOption,
) (*tx.Tx, error)

MakeBondTx creates a new bond transaction based on the given parameters.

func (*Wallet) MakeTransferTx added in v0.13.0

func (w *Wallet) MakeTransferTx(sender, receiver string, amt amount.Amount,
	options ...TxOption,
) (*tx.Tx, error)

MakeTransferTx creates a new transfer transaction based on the given parameters.

func (*Wallet) MakeUnbondTx

func (w *Wallet) MakeUnbondTx(addr string, opts ...TxOption) (*tx.Tx, error)

MakeUnbondTx creates a new unbond transaction based on the given parameters.

func (*Wallet) MakeWithdrawTx

func (w *Wallet) MakeWithdrawTx(sender, receiver string, amt amount.Amount,
	options ...TxOption,
) (*tx.Tx, error)

MakeWithdrawTx creates a new withdraw transaction based on the given parameters.

func (*Wallet) Mnemonic

func (w *Wallet) Mnemonic(password string) (string, error)

func (*Wallet) Name

func (w *Wallet) Name() string

func (*Wallet) Network added in v1.5.0

func (w *Wallet) Network() genesis.ChainType

func (*Wallet) NewBLSAccountAddress added in v0.15.0

func (w *Wallet) NewBLSAccountAddress(label string) (*vault.AddressInfo, error)

NewBLSAccountAddress create a new BLS-based account address and associates it with the given label.

func (*Wallet) NewEd25519AccountAddress added in v1.5.0

func (w *Wallet) NewEd25519AccountAddress(label, password string) (*vault.AddressInfo, error)

NewEd25519AccountAddress create a new Ed25519-based account address and associates it with the given label. The password is required to access the master private key needed for address generation.

func (*Wallet) NewValidatorAddress added in v0.15.0

func (w *Wallet) NewValidatorAddress(label string) (*vault.AddressInfo, error)

NewValidatorAddress creates a new BLS validator address and associates it with the given label.

func (*Wallet) Path

func (w *Wallet) Path() string

func (*Wallet) PrivateKey

func (w *Wallet) PrivateKey(password, addr string) (crypto.PrivateKey, error)

func (*Wallet) PrivateKeys added in v0.10.0

func (w *Wallet) PrivateKeys(password string, addrs []string) ([]crypto.PrivateKey, error)

func (*Wallet) Save

func (w *Wallet) Save() error

func (*Wallet) SetLabel

func (w *Wallet) SetLabel(addr, label string) error

SetLabel sets label for addr.

func (*Wallet) SignMessage added in v1.4.0

func (w *Wallet) SignMessage(password, addr, msg string) (string, error)

func (*Wallet) SignTransaction

func (w *Wallet) SignTransaction(password string, trx *tx.Tx) error

func (*Wallet) Stake

func (w *Wallet) Stake(addrStr string) (amount.Amount, error)

Stake returns stake of the validator associated with the address..

func (*Wallet) TotalBalance added in v1.1.0

func (w *Wallet) TotalBalance() (amount.Amount, error)

TotalBalance return the total available balance of the wallet.

func (*Wallet) TotalStake added in v1.6.0

func (w *Wallet) TotalStake() (amount.Amount, error)

TotalStake return total available stake of the wallet.

func (*Wallet) UpdatePassword

func (w *Wallet) UpdatePassword(oldPassword, newPassword string) error

func (*Wallet) Version added in v1.5.0

func (w *Wallet) Version() int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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