utils

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: ISC Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogFileName = "libwallet.log"

	NilAsset       AssetType = ""
	BTCWalletAsset AssetType = "BTC"
	DCRWalletAsset AssetType = "DCR"
	LTCWalletAsset AssetType = "LTC"

	InvalidSyncStage          SyncStage = -1
	CFiltersFetchSyncStage    SyncStage = 0
	HeadersFetchSyncStage     SyncStage = 1
	AddressDiscoverySyncStage SyncStage = 2
	HeadersRescanSyncStage    SyncStage = 3

	TxFilterAll         int32 = 0
	TxFilterSent        int32 = 1
	TxFilterReceived    int32 = 2
	TxFilterTransferred int32 = 3
	TxFilterStaking     int32 = 4
	TxFilterCoinBase    int32 = 5
	TxFilterRegular     int32 = 6
	TxFilterMixed       int32 = 7
	TxFilterVoted       int32 = 8
	TxFilterRevoked     int32 = 9
	TxFilterImmature    int32 = 10
	TxFilterLive        int32 = 11
	TxFilterUnmined     int32 = 12
	TxFilterExpired     int32 = 13
	TxFilterTickets     int32 = 14

	TypeFilter          = "Type"
	DirectionFilter     = "Direction"
	HeightFilter        = "BlockHeight"
	TicketSpenderFilter = "TicketSpender"

	LogLevelOff      = "off"
	LogLevelTrace    = "trace"
	LogLevelDebug    = "debug"
	LogLevelInfo     = "info"
	LogLevelWarn     = "warn"
	LogLevelError    = "error"
	LogLevelCritical = "critical"
	DefaultLogLevel  = LogLevelInfo

	// UserFilePerm contains permissions for the user only. Attempting to modify
	// more permissions require a super user permission that isn't readily available.
	UserFilePerm = fs.FileMode(0o700)
)
View Source
const (
	// Error Codes
	ErrInsufficientBalance          = "insufficient_balance"
	ErrInvalid                      = "invalid"
	ErrWalletLocked                 = "wallet_locked"
	ErrWalletDatabaseInUse          = "wallet_db_in_use"
	ErrWalletNotLoaded              = "wallet_not_loaded"
	ErrWalletNotFound               = "wallet_not_found"
	ErrWalletNameExist              = "wallet_name_exists"
	ErrReservedWalletName           = "wallet_name_reserved"
	ErrWalletIsRestored             = "wallet_is_restored"
	ErrWalletIsWatchOnly            = "watch_only_wallet"
	ErrUnusableSeed                 = "unusable_seed"
	ErrPassphraseRequired           = "passphrase_required"
	ErrInvalidPassphrase            = "invalid_passphrase"
	ErrNotConnected                 = "not_connected"
	ErrExist                        = "exists"
	ErrNotExist                     = "not_exists"
	ErrEmptySeed                    = "empty_seed"
	ErrInvalidAddress               = "invalid_address"
	ErrInvalidAuth                  = "invalid_auth"
	ErrUnavailable                  = "unavailable"
	ErrContextCanceled              = "context_canceled"
	ErrFailedPrecondition           = "failed_precondition"
	ErrSyncAlreadyInProgress        = "sync_already_in_progress"
	ErrNoPeers                      = "no_peers"
	ErrInvalidPeers                 = "invalid_peers"
	ErrListenerAlreadyExist         = "listener_already_exist"
	ErrLoggerAlreadyRegistered      = "logger_already_registered"
	ErrLogRotatorAlreadyInitialized = "log_rotator_already_initialized"
	ErrAddressDiscoveryNotDone      = "address_discovery_not_done"
	ErrChangingPassphrase           = "err_changing_passphrase"
	ErrSavingWallet                 = "err_saving_wallet"
	ErrIndexOutOfRange              = "err_index_out_of_range"
	ErrNoMixableOutput              = "err_no_mixable_output"
	ErrInvalidVoteBit               = "err_invalid_vote_bit"
	ErrNotSynced                    = "err_not_synced"
	ErrNoSeed                       = "no_seed"
)

Variables

View Source
var (
	ErrInvalidNet        = errors.New("invalid network type found")
	ErrAssetUnknown      = errors.New("unknown asset found")
	ErrBTCNotInitialized = errors.New("btc asset not initialized")
	ErrDCRNotInitialized = errors.New("dcr asset not initialized")
	ErrLTCNotInitialized = errors.New("ltc asset not initialized")

	ErrUnsupporttedIPV6Address = errors.New("IPv6 addresses unsupportted by the current network")
	ErrNetConnectionTimeout    = errors.New("Timeout on network connection")
	ErrPeerConnectionRejected  = errors.New("Peer connection rejected")
)
View Source
var (
	DCRmainnetParams      = dcrcfg.MainNetParams()
	DCRtestnetParams      = dcrcfg.TestNet3Params()
	DCRSimnetParams       = dcrcfg.SimNetParams()
	DCRRegnetParams       = dcrcfg.RegNetParams()
	BTCmainnetParams      = &btccfg.MainNetParams
	BTCtestnetParams      = &btccfg.TestNet3Params
	BTCSimnetParams       = &btccfg.SimNetParams
	BTCRegnetParamsVal    = btccfg.RegressionNetParams
	LTCmainnetParams      = &ltccfg.MainNetParams
	LTCtestnetParams      = &ltccfg.TestNet4Params
	LTCSimnetParams       = &ltccfg.SimNetParams
	LTCRegnetParamsVal    = ltccfg.RegressionNetParams
	DCRDEXSimnetParams    = dcrcfg.SimNetParams()
	BTCDEXRegnetParamsVal = btccfg.RegressionNetParams
	LTCDEXRegnetParamsVal = ltccfg.RegressionNetParams
)

Functions

func BTCChainParams

func BTCChainParams(netType NetworkType) (*btccfg.Params, error)

BTCChainParams returns the network parameters from the BTC chain provided a given network.

func DCRChainParams

func DCRChainParams(netType NetworkType) (*dcrcfg.Params, error)

DCRChainParams returns the network parameters from the DCR chain provided a given network.

func DecodeBase64

func DecodeBase64(base64Text string) ([]byte, error)

func EncodeBase64

func EncodeBase64(text []byte) string

func EncodeHex

func EncodeHex(hexBytes []byte) string

func ErrBTCMethodNotImplemented

func ErrBTCMethodNotImplemented(method string) error

func ErrDCRMethodNotImplemented

func ErrDCRMethodNotImplemented(method string) error

func ErrLTCMethodNotImplemented

func ErrLTCMethodNotImplemented(method string) error

func ExtractDateOrTime

func ExtractDateOrTime(timestamp int64) string

ExtractDateOrTime returns the date represented by the timestamp as a date string if the timestamp is over 24 hours ago. Otherwise, the time alone is returned as a string.

func FormatUTCShortTime

func FormatUTCShortTime(timestamp int64) string

func FormatUTCTime

func FormatUTCTime(timestamp int64) string

func GradientColorSchemes

func GradientColorSchemes() map[AssetType]GradientColorScheme

func HTTPRequest

func HTTPRequest(reqConfig *ReqConfig, respObj interface{}) (*http.Response, error)

HTTPRequest queries the API provided in the ReqConfig object and converts the returned json(Byte data) into an respObj interface. Returned http response body is usually empty because the http stream cannot be read twice.

func IsOnline

func IsOnline() bool

IsOnline is a function to check whether an internet connection can be established. If established, IsOnline should return true otherwise IsOnline returns false.

func LTCChainParams

func LTCChainParams(netType NetworkType) (*ltccfg.Params, error)

LTCChainParams returns the network parameters from the LTC chain provided a network type is given.

func NetDir

func NetDir(assetType AssetType, netType NetworkType) string

NetDir returns data directory name for a given asset's type and network connected. If "unknown" is returned, unsupported asset type or network was detected.

func NormalizeAddress

func NormalizeAddress(addr string, defaultPort string) (string, error)

func ShannonEntropy

func ShannonEntropy(text string) (entropy float64)

func ShutdownHTTPClients

func ShutdownHTTPClients()

ShutdownHTTPClients shutdowns any active connection by cancelling the context.

func TranslateError

func TranslateError(err error) error

todo, should update this method to translate more error kinds.

func TranslateNetworkError

func TranslateNetworkError(host string, errMsg error) error

func TrimNonAphaNumeric

func TrimNonAphaNumeric(text string) string

TrimNonAphanumeric removes all the characters that don't include the following: `abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-`

Types

type AssetType

type AssetType string

AssetType is the capitalized version of an asset's symbol (e.g BTC, DCR, LTC) that serves as the asset's unique identity.

func (AssetType) String

func (str AssetType) String() string

func (AssetType) ToFull

func (str AssetType) ToFull() string

ToFull returns the full network name of the provided asset.

func (AssetType) ToStringLower

func (str AssetType) ToStringLower() string

Stringer used in generating the directory path where the lowercase of the asset type is required. The uppercase defined by default is required to asset previously created using the uppercase.

type ChainsParams

type ChainsParams struct {
	DCR *dcrcfg.Params
	BTC *btccfg.Params
	LTC *ltccfg.Params
}

ChainsParams collectively defines the chain parameters of all assets supported.

func GetChainParams

func GetChainParams(assetType AssetType, netType NetworkType) (*ChainsParams, error)

GetChainParams returns the network parameters of a chain provided its asset type and network type.

type Client

type Client struct {
	HTTPClient *http.Client
	// contains filtered or unexported fields
}

Client is the base for http/https calls

type ColorScheme

type ColorScheme struct {
	R uint8   // Red Subpixel
	G uint8   // Green Subpixel
	B uint8   // Blue Subpixel
	O float64 // Opacity; value range 0-1
}

func (*ColorScheme) NRGBAColor

func (c *ColorScheme) NRGBAColor() color.NRGBA

NRGBAColor converts figma color scheme to gioui nrgba color scheme.

type Dailer

type Dailer func(addr net.Addr) (net.Conn, error)

func DialerFunc

func DialerFunc(ctx context.Context) Dailer

DialerFunc returns a customized dialer function that is make it easier to control node level tcp connections especially after a shutdown. It also includes a timeout value preventing a connection waiting forever for a response to be returned.

type GradientColorScheme

type GradientColorScheme struct {
	Color1 ColorScheme
	Color2 ColorScheme
	Blend1 float64 // percent of position along X axis where color1 blend ends.
	Blend2 float64 // percent of position along X axis where color2 blend ends.
}

type HTTPAPIType

type HTTPAPIType uint8
const (

	// Below lists the Http APIs that have a privacy control implemented on them.
	GovernanceHTTPAPI HTTPAPIType = iota
	FeeRateHTTPAPI
	ExchangeHTTPAPI
	VspAPI
	UpdateAPI
)

type NetworkType

type NetworkType string
const (
	Mainnet    NetworkType = "mainnet"
	Testnet    NetworkType = "testnet"
	Regression NetworkType = "regression"
	Simulation NetworkType = "simulation"
	DEXTest    NetworkType = "dextest"
	Unknown    NetworkType = "unknown"
)

func ToNetworkType

func ToNetworkType(str string) NetworkType

ToNetworkType maps the provided network string identifier to the available network type constants.

func (NetworkType) Display

func (n NetworkType) Display() string

Display returns the title case network name to be displayed on the app UI.

type ProposalStatus added in v1.1.0

type ProposalStatus int
const (
	ProposalStatusSynced ProposalStatus = iota
	ProposalStatusNewProposal
	ProposalStatusVoteStarted
	ProposalStatusVoteFinished
)

type ReqConfig

type ReqConfig struct {
	Payload interface{}
	Cookies []*http.Cookie
	Headers http.Header
	Method  string
	HTTPURL string
	// If IsRetByte is set to true, client.Do will delegate
	// response processing to caller.
	IsRetByte bool
}

ReqConfig models the configuration options for requests.

type SyncStage

type SyncStage int8

Jump to

Keyboard shortcuts

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