asset

package
v0.0.0-...-a0f938d Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: BlueOak-1.0.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const Simnet = Regtest

Simnet is an alias of Regtest.

Variables

View Source
var (
	ErrInvalidPassphrase = errors.New("invalid_passphrase")
)

Functions

func DecryptData

func DecryptData(data, passphrase []byte) ([]byte, error)

DecryptData uses the provided passphrase to decrypt the provided data.

func EncryptData

func EncryptData(data, passphrase []byte) ([]byte, error)

EncryptData encrypts the provided data with the provided passphrase.

func ReEncryptData

func ReEncryptData(data, oldPass, newPass []byte) ([]byte, error)

ReEncryptData decrypts the provided data using the oldPass and re-encrypts the data using newPass.

Types

type CreateWalletParams

type CreateWalletParams[Tx any] struct {
	OpenWalletParams[Tx]
	Pass     []byte
	Birthday time.Time
}

CreateWalletParams are the parameters for creating a wallet.

type Network

type Network uint8

Network flags passed to asset backends to signify which network to use.

const (
	Mainnet Network = iota
	Testnet
	Regtest
)

func NetFromString

func NetFromString(net string) (Network, error)

NetFromString returns the Network for the given network name.

func (Network) String

func (n Network) String() string

String returns the string representation of a Network.

type OpenWalletParams

type OpenWalletParams[Tx any] struct {
	Net            Network
	DataDir        string
	DbDriver       string
	Logger         slog.Logger
	UserConfigDB   walletdata.UserConfigDB
	WalletConfigDB walletdata.WalletConfigDB

	// TxIndexDB is only required if transaction indexing is desired. Can be nil
	// otherwise.
	TxIndexDB walletdata.TxIndexDB[Tx]
}

CreateWalletParams are the parameters for opening a wallet.

type PeerManagerChainService

type PeerManagerChainService interface {
	ConnectNode(addr string, permanent bool) error
	RemoveNodeByAddr(addr string) error
	Peers() []SPVPeer
}

PeerManagerChainService are the functions needed for an SPVPeerManager to communicate with a chain service.

type PeerSource

type PeerSource uint16
const (
	AddedPeer PeerSource = iota
	DefaultPeer
	DiscoveredPeer
)

type RecoveryCfg

type RecoveryCfg struct {
	Seed                 []byte
	NumExternalAddresses uint32
	NumInternalAddresses uint32
}

RecoveryCfg is the information used to recover a wallet.

type SPVPeer

type SPVPeer interface {
	StartingHeight() int32
	LastBlock() int32
	Addr() string
}

SPVPeer is satisfied by *neutrino.ServerPeer, but is generalized to accommodate underlying implementations other than lightninglabs/neutrino.

type SPVPeerManager

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

SPVPeerManager implements peer management functionality for all bitcoin clone SPV wallets.

func NewSPVPeerManager

func NewSPVPeerManager(cs PeerManagerChainService, defaultPeers []string, savedPeersFilePath string, log slog.Logger, defaultPort string) *SPVPeerManager

NewSPVPeerManager creates a new SPVPeerManager.

func (*SPVPeerManager) AddPeer

func (s *SPVPeerManager) AddPeer(addr string) error

AddPeer connects to a new peer and stores it in the db.

func (*SPVPeerManager) ConnectToInitialWalletPeers

func (s *SPVPeerManager) ConnectToInitialWalletPeers()

ConnectToInitialWalletPeers connects to the default peers and the peers that were added by the user and persisted in the db.

func (*SPVPeerManager) Peers

func (s *SPVPeerManager) Peers() ([]*WalletPeer, error)

Peers returns the list of peers that the wallet is connected to. It also returns the peers that the user added that the wallet may not currently be connected to.

func (*SPVPeerManager) RemovePeer

func (s *SPVPeerManager) RemovePeer(addr string) error

RemovePeer disconnects from a peer added by the user and removes it from the db.

type WalletBase

type WalletBase[Tx any] struct {
	// UserConfigDB is publicly embedded, so consumers can directly read from or
	// write to the user config db.
	walletdata.UserConfigDB
	// TxIndexDB is embedded so consumers can call tx indexing methods directly.
	// TxIndexDB may be nil and calling tx indexing methods when this field is
	// nil may panic.
	walletdata.TxIndexDB[Tx]
	// contains filtered or unexported fields
}

func NewWalletBase

func NewWalletBase[Tx any](params OpenWalletParams[Tx], seed, walletPass []byte, traits WalletTrait) (*WalletBase[Tx], error)

NewWalletBase initializes a WalletBase using the information provided. The wallet's seed is encrypted and saved, along with other basic wallet info.

func OpenWalletBase

func OpenWalletBase[Tx any](params OpenWalletParams[Tx]) (*WalletBase[Tx], error)

OpenWalletBase loads basic information for an existing wallet from the provided params.

func (*WalletBase[_]) AccountDiscoveryRequired

func (w *WalletBase[_]) AccountDiscoveryRequired() bool

func (*WalletBase[_]) DataDir

func (w *WalletBase[_]) DataDir() string

func (*WalletBase[_]) DecryptSeed

func (w *WalletBase[_]) DecryptSeed(passphrase []byte) (string, error)

DecryptSeed decrypts the encrypted wallet seed using the provided passphrase.

func (WalletBase) InitializeSyncContext

func (sh WalletBase) InitializeSyncContext(ctx context.Context) (context.Context, error)

InitializeSyncContext returns a context that should be used for bacgkround sync processes. All sync background processes should exit when the returned context is canceled. Call SyncEnded() when all sync processes have ended.

func (*WalletBase[_]) IsRestored

func (w *WalletBase[_]) IsRestored() bool

func (WalletBase) IsSyncingOrSynced

func (sh WalletBase) IsSyncingOrSynced() bool

IsSyncingOrSynced is true if the wallet synchronization was started.

func (*WalletBase[_]) IsWatchOnly

func (w *WalletBase[_]) IsWatchOnly() bool

func (*WalletBase[_]) MarkAccountDiscoveryComplete

func (w *WalletBase[_]) MarkAccountDiscoveryComplete()

func (*WalletBase[_]) Network

func (w *WalletBase[_]) Network() Network

func (*WalletBase[_]) ReEncryptSeed

func (w *WalletBase[_]) ReEncryptSeed(oldPass, newPass []byte) error

func (*WalletBase[_]) ReadUserConfigBoolValue

func (w *WalletBase[_]) ReadUserConfigBoolValue(key string, defaultValue ...bool) bool

ReadUserConfigBoolValue is a helper method for reading a bool user config value from the wallet's config db.

func (*WalletBase[_]) ReadUserConfigStringValue

func (w *WalletBase[_]) ReadUserConfigStringValue(key string, defaultValue ...string) string

ReadUserConfigStringValue is a helper method for reading a string user config value from the wallet's config db.

func (*WalletBase[_]) SeedVerificationRequired

func (w *WalletBase[_]) SeedVerificationRequired() bool

SeedVerificationRequired is true if the seed for this wallet is yet to be verified by the owner. The wallet's seed is saved in an encrypted form until it is verified.

func (WalletBase) StopSync

func (sh WalletBase) StopSync()

StopSync cancels the wallet's synchronization to the blockchain network. It may take a few moments for sync to completely stop. Use

func (WalletBase) SyncEnded

func (sh WalletBase) SyncEnded(err error)

SyncEnded signals that all sync processes have been stopped.

func (WalletBase) SyncIsStopping

func (sh WalletBase) SyncIsStopping() bool

func (*WalletBase[_]) VerifySeed

func (w *WalletBase[_]) VerifySeed(seedMnemonic string, passphrase []byte) (bool, error)

VerifySeed decrypts the encrypted wallet seed using the provided passphrase and compares it with the provided seedMnemonic. If it's a match, the wallet seed will no longer be saved.

func (WalletBase) WaitForSyncToStop

func (sh WalletBase) WaitForSyncToStop()

WaitForSyncToStop blocks until the wallet synchronization is fully stopped.

type WalletPeer

type WalletPeer struct {
	Addr      string     `json:"addr"`
	Source    PeerSource `json:"source"`
	Connected bool       `json:"connected"`
}

WalletPeer provides information about a wallet's peer.

type WalletTrait

type WalletTrait uint64

WalletTrait is a bitset indicating various optional wallet properties, such as if the wallet was restored or if it's watch only.

const (
	WalletTraitRestored  WalletTrait = 1 << iota // The Wallet is a restored wallet.
	WalletTraitWatchOnly                         // The Wallet is a watch only wallet.
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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