cmn

package
v0.0.0-...-e8a7bc5 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ICON_DELETE   = "\U0000f057 " //"\uf00d"
	ICON_EDIT     = "\uf044 "
	ICON_COPY     = "\uf0c5 "
	ICON_DROPLIST = "\ueb6e "
	ICON_PROMOTE  = "\ued65 "
	ICON_ADD      = "\ueadc "
	ICON_3DOTS    = "\U000f01d8"
	ICON_BACK     = "\U000f006e "
	ICON_SEND     = "\U000f048a "
	ICON_LINK     = "\uf08e "
	ICON_FEED     = "\uf09e "
	ICON_DOWNLOAD = "\ueac2 "
	ICON_VSC      = "\U000f0a1e "
	ICON_TRUST    = "\uebc1 "
	ICON_NO_ENTRY = "\uf4f4 "
	ICON_LIGHT    = "\U000f06e8 "
	ICON_CHECK    = "\U000f0134 "
	ICON_UNCHECK  = "\U000f0130 "
	ICON_ALERT    = "\U000f0028 "
)
View Source
const (
	ALERT_ARROW = "<blink>\U000f0028\uf178 </blink>"
)
View Source
const CONFIG_NAME = "config.yaml"
View Source
const LOG_NAME = "web3pro.log"
View Source
const MAX_DECIMALS = 80
View Source
const PRECISION = 20
View Source
const SOLT_SIZE = 32
View Source
const VERSION = "0.1.0"

Variables

View Source
var AppName = "web3pro"
View Source
var ConfPath = CONFIG_NAME
View Source
var ConfigChanged = false
View Source
var DataFolder = "data"
View Source
var EXPLORER_API_TYPES = []string{"etherscan", "blockscout"}
View Source
var FMT_NEG_SUFFIXES = []string{"", "m", "µ", "n", "p", "f", "a", "/^21", "/^24", "/^27", "/^30", "/^33",
	"/^36", "/^39", "/^42", "/^45", "/^48", "/^51", "/^54", "/^57", "/^60", "/^63", "/^66", "/^69", "/^72", "/^75", "/^76"}

var FMT_NEG_SUFFIXES = []string{"", "/K", "/M", "/B", "/T", "/Qa", "/Qi", "/^21", "/^24", "/^27", "/^30", "/^33",

"/^36", "/^39", "/^42", "/^45", "/^48", "/^51", "/^54", "/^57", "/^60", "/^63", "/^66", "/^69", "/^72", "/^75", "/^76"}
View Source
var FMT_SUFFIXES = []string{"", "k", "M", "B", "T", "Qa", "Qi", "^21", "^24", "^27", "^30", "^33", "^36", "^39",
	"^42", "^45", "^48", "^51", "^54", "^57", "^60", "^63", "^66", "^69", "^72", "^75", "^76"}
View Source
var KNOWN_FEEDERS = []string{"dexscreener", "coinmarketcap"}
View Source
var KNOWN_SIGNER_TYPES = []string{"mnemonics", "ledger", "trezor"}
View Source
var LogPath = LOG_NAME
View Source
var PD []XF
View Source
var PredefinedBlockchains []Blockchain = []Blockchain{}/* 242 elements not displayed */
View Source
var PrefedinedLP_V3 = map[int]([]PD_V3){
	1: {
		{
			Name:    "Uni",
			Address: common.HexToAddress("0xC36442b4a4522E871399CD717aBDD847Ab11FE88"),
			URL:     "https://app.uniswap.org/swap",
		},
		{
			Name:    "Pancake",
			Address: common.HexToAddress("0x46A15B0b27311cedF172AB29E4f4766fbE7F4364"),
			URL:     "https://pancakeswap.finance/swap&chin=eth",
		},
	},
	369: {
		{
			Name:    "9Inch",
			Address: common.HexToAddress("0x18A532b36A9F6B10b3FEC5BF225C00A0Ec89B79E"),
			URL:     "https://v3.9inch.io/?chain=pulse",
		},
		{
			Name:    "9mm",
			Address: common.HexToAddress("0xCC05bf158202b4F461Ede8843d76dcd7Bbad07f2"),
			URL:     "https://v3.9mm.pro",
		},
	},
	56: {
		{
			Name:    "Pancake",
			Address: common.HexToAddress("0x46A15B0b27311cedF172AB29E4f4766fbE7F4364"),
			URL:     "https://pancakeswap.finance/swap&chin=eth",
		},
	},
}
View Source
var STANDARD_DERIVATIONS = map[string]struct {
	Name   string
	Format string
}{
	"legacy": {
		Name:   "Legacy (MEW, MyCrypto) m/44'/60'/0'/%d",
		Format: "m/44'/60'/0'/%d",
	},
	"ledger-live": {
		Name:   "Ledger Live m/44'/60'/%d'/0/0",
		Format: "m/44'/60'/%d'/0/0",
	},
	"default": {
		Name:   "Default m/44'/60'/0'/0/%d",
		Format: "m/44'/60'/0'/0/%d",
	},
}
View Source
var StandardOnClickHotspot func(v *gocui.View, hs *gocui.Hotspot)
View Source
var StandardOnOverHotspot func(v *gocui.View, hs *gocui.Hotspot)
View Source
var XF_NaN = &XF{big.NewInt(0), 0, true}

Functions

func AddAddressLink(v *gocui.View, a common.Address)
func AddAddressShortLink(v *gocui.View, a common.Address)
func AddDollarLink(v *gocui.View, val float64)
func AddDollarValueLink(v *gocui.View, val *big.Int, t *Token)
func AddValueLink(v *gocui.View, val *big.Int, t *Token)
func AddValueSymbolLink(v *gocui.View, val *big.Int, t *Token)

func AddressFromAny

func AddressFromAny(value any) common.Address

func Amount2Str

func Amount2Str(amount *big.Int, decimals int) string

func BigIntFromAny

func BigIntFromAny(value any) *big.Int

func ConfirmEIP712Template

func ConfirmEIP712Template(data apitypes.TypedData, confirmed bool) string

func Contains

func Contains(s string, subststr string) bool

func Create

func Create(name, pass string) error

func Exists

func Exists(name string) bool

func Float

func Float(value *big.Int, decimals int) *big.Float

func Float64

func Float64(value *big.Int, decimals int) float64

func FmtAmount

func FmtAmount(amount *big.Int, decimals int, fixed bool) string

func FmtFloat64

func FmtFloat64(v float64, fixed bool) string

func FmtFloat64D

func FmtFloat64D(v float64, fixed bool) string

func FmtFloat64DN

func FmtFloat64DN(num float64) string

Normal format with 4 decimal places

func FormatFloatWithCommas

func FormatFloatWithCommas(num float64) string

func FormatUInt64

func FormatUInt64(v uint64, fixed bool) string

func GetDataFolder

func GetDataFolder() (string, error)

func GetHostName

func GetHostName(URL string) string

func InitConfig

func InitConfig()

func IntFromAny

func IntFromAny(value any) int

func IsContractDownloaded

func IsContractDownloaded(a common.Address) bool

func IsInArray

func IsInArray(slice []string, item string) bool

func Open

func Open(name string, pass string) error

func OpenBrowser

func OpenBrowser(url string) error

func RestoreConfig

func RestoreConfig(path string) error

func SaveConfig

func SaveConfig() error

func SaveToFile

func SaveToFile(w *Wallet, file, pass string) error

func ShortAddress

func ShortAddress(a common.Address) string

func Split3

func Split3(input string) []string

Split3 splits the input string into a slice of strings. Guarantees that the result has at least 3 elements.

func SplitN

func SplitN(input string, n int) []string

Split splits the input string into a slice of strings. Guarantees that the result has at least n elements.

func Str2Wei

func Str2Wei(str string, decimals int) (*big.Int, error)

convert string to the "weis" value

func SystemCommand

func SystemCommand(command string) error
func TagAddressShortLink(a common.Address) string
func TagBytesLink(b []byte) string
func TagDollarLink(val float64) string
func TagDollarValueLink(val *big.Int, t *Token) string
func TagLink(text, action, tip string) string
func TagShortDollarLink(val float64) string
func TagShortDollarValueLink(val *big.Int, t *Token) string
func TagShortValueSymbolLink(val *big.Int, t *Token) string
func TagUint64Link(val uint64) string
func TagValueLink(val *big.Int, t *Token) string
func TagValueSymbolLink(val *big.Int, t *Token) string

func Uint256FromHex

func Uint256FromHex(hex string) *big.Int

func WalletList

func WalletList() []string

Types

type Address

type Address struct {
	Name    string         `json:"name"`
	Tag     string         `json:"tag"`
	Address common.Address `json:"address"`
	Signer  string         `json:"signer"`
	Path    string         `json:"path"`
}

type Blockchain

type Blockchain struct {
	Name             string         `json:"name"`
	Url              string         `json:"url"`
	ChainId          int            `json:"chain_id"`
	ExplorerUrl      string         `json:"explorer_url"`
	ExplorerAPIUrl   string         `json:"explorer_api_url"`
	ExplorerAPIToken string         `json:"explorer_api_token"`
	ExplorerApiType  string         `json:"explorer_api_type"`
	Currency         string         `json:"currency"`
	WTokenAddress    common.Address `json:"wrapped_native_token_address"`
	Multicall        common.Address `json:"multicall"`
}
func (b *Blockchain) ExplorerLink(address common.Address) string

type Contract

type Contract struct {
	Name    string `json:"name"`
	Trusted bool   `json:"trusted"`
}

type LP_V3

type LP_V3 struct {
	Name     string         `json:"name"`
	Provider common.Address `json:"provider"`
	ChainId  int            `json:"chain_id"`
	URL      string         `json:"url"`
}

type LP_V3_Position

type LP_V3_Position struct {
	Owner     common.Address `json:"owner"`
	ChainId   int            `json:"chain_id"`
	Provider  common.Address `json:"provider"`
	NFT_Token *big.Int       `json:"nft_token"`
	Token0    common.Address `json:"token0"`
	Token1    common.Address `json:"token1"`
	Fee       *big.Int       `json:"fee"`
	Pool      common.Address `json:"pool"`
	TickLower int64          `json:"tick_lower"`
	TickUpper int64          `json:"tick_upper"`
}

type Origin

type Origin struct {
	URL       string           `json:"url"`
	ChainId   int              `json:"chain_id"`
	Addresses []common.Address `json:"addresses"`
}

func (*Origin) IsAllowed

func (o *Origin) IsAllowed(a common.Address) bool

func (*Origin) ShortName

func (o *Origin) ShortName() string

type PD_V3

type PD_V3 struct {
	Name    string
	Address common.Address
	URL     string
}

type SConfig

type SConfig struct {
	WalletName             string        `yaml:"wallet_name"`              // last wallet used
	Verbosity              string        `yaml:"verbosity"`                // log verbosity
	Theme                  string        `yaml:"theme"`                    // UI theme
	BusTimeout             time.Duration `yaml:"bus_timeout"`              // timeout for bus requests
	BusHardTimeout         time.Duration `yaml:"bus_hard_timeout"`         // hard timeout for bus requests
	USBLog                 bool          `yaml:"usb_log"`                  // log USB events
	USBBackgroundEnumerate bool          `yaml:"usb_background_enumerate"` // enumerate USB devices in background
	PriceFeed              string        `yaml:"price_feed"`               // price feed
	PriceUpdatePeriod      string        `yaml:"price_update_period"`      // price update period
	Editor                 string        `yaml:"editor"`                   // editor
	CMC_API_KEY            string        `yaml:"cmc_api_key"`              // CoinMarketCap API key
}
var Config *SConfig = &SConfig{
	WalletName:             "default",
	Verbosity:              "debug",
	Theme:                  "dark",
	BusTimeout:             3 * time.Minute,
	BusHardTimeout:         5 * time.Minute,
	USBLog:                 false,
	USBBackgroundEnumerate: true,
	PriceUpdatePeriod:      "15m",
	Editor:                 "code",
}

type SignedDataInfo

type SignedDataInfo struct {
	Type       string
	Blockchain *Blockchain
	Token      *Token
	Value      *big.Int
	Address    *Address
}

type Signer

type Signer struct {
	Name      string   `json:"name"`
	Type      string   `json:"type"`
	MasterKey string   `json:"master-key"`
	Copies    []string `json:"copies"`
}

func (*Signer) GetAllCopies

func (s *Signer) GetAllCopies() []string

type Token

type Token struct {
	ChainId        int            `json:"chain_id"`
	Name           string         `json:"name"`
	Symbol         string         `json:"symbol"`
	Address        common.Address `json:"address"`
	Decimals       int            `json:"decimals"`
	Native         bool           `json:"native"`
	Unique         bool           `json:"-"` // Unique name in the blockchain
	PriceFeeder    string         `json:"price_feeder"`
	PriceFeedParam string         `json:"price_feed_id"`
	Price          float64        `json:"price"`
	PriceChange24  float64        `json:"price_change_24"`
	PriceTimestamp time.Time      `json:"price_timestamp"` // Unix timestamp
}

func (*Token) Float64

func (t *Token) Float64(value *big.Int) float64

func (*Token) FmtValue64D

func (t *Token) FmtValue64D(v float64, fixed bool) string

func (*Token) GetPrintName

func (t *Token) GetPrintName() string

func (*Token) Str2Wei

func (t *Token) Str2Wei(str string) (*big.Int, error)

convert string to the "weis" value

func (*Token) Value2Str

func (t *Token) Value2Str(value *big.Int) string

type Wallet

type Wallet struct {
	Name            string            `json:"name"`
	Blockchains     []*Blockchain     `json:"blockchains"`
	Signers         []*Signer         `json:"signers"`
	Addresses       []*Address        `json:"addresses"`
	Tokens          []*Token          `json:"tokens"`
	Origins         []*Origin         `json:"origins"`
	LP_V3_Providers []*LP_V3          `json:"lp_v3_providers"`
	LP_V3_Positions []*LP_V3_Position `json:"lp_v3_positions"`
	Contracts       map[common.Address]*Contract
	AppsPaneOn      bool `json:"apps_pane_on"`
	LP_V3PaneOn     bool `json:"lp_v3_pane_on"`

	CurrentChainId int            `json:"current_chain_id"`
	CurrentAddress common.Address `json:"current_address"`
	CurrentOrigin  string         `json:"current_origin"`

	// Auxilary params
	ParamInt map[string]int    `json:"param_int"`
	ParamStr map[string]string `json:"param_str"`

	SoundOn bool   `json:"sound_on"`
	Sound   string `json:"sound"`
	// contains filtered or unexported fields
}
var CurrentWallet *Wallet

func (*Wallet) AddBlockchain

func (w *Wallet) AddBlockchain(b *Blockchain) error

func (*Wallet) AddLP_V3

func (w *Wallet) AddLP_V3(lp *LP_V3) error

func (*Wallet) AddLP_V3Position

func (w *Wallet) AddLP_V3Position(lp *LP_V3_Position) error

func (*Wallet) AddOrigin

func (w *Wallet) AddOrigin(o *Origin) error

func (*Wallet) AddOriginAddress

func (w *Wallet) AddOriginAddress(url string, a string) error

func (*Wallet) AddToken

func (w *Wallet) AddToken(chain int, a common.Address, n string, s string, d int) error

func (*Wallet) DeleteBlockchain

func (w *Wallet) DeleteBlockchain(name string) error

func (*Wallet) DeleteToken

func (w *Wallet) DeleteToken(chain int, a common.Address) error

func (*Wallet) EditBlockchain

func (w *Wallet) EditBlockchain(ub *Blockchain) error

func (*Wallet) GetAddress

func (w *Wallet) GetAddress(a any) *Address

func (*Wallet) GetAddressByName

func (w *Wallet) GetAddressByName(n string) *Address

func (*Wallet) GetBlockchain

func (w *Wallet) GetBlockchain(id int) *Blockchain

func (*Wallet) GetBlockchainByName

func (w *Wallet) GetBlockchainByName(n string) *Blockchain

func (*Wallet) GetContract

func (w *Wallet) GetContract(a common.Address) *Contract

func (*Wallet) GetLP_V3

func (w *Wallet) GetLP_V3(chainId int, addr common.Address) *LP_V3

func (*Wallet) GetLP_V3Position

func (w *Wallet) GetLP_V3Position(chainId int, provider common.Address, nft *big.Int) *LP_V3_Position

func (*Wallet) GetLP_V3_by_name

func (w *Wallet) GetLP_V3_by_name(chainId int, name string) *LP_V3

func (*Wallet) GetNativeToken

func (w *Wallet) GetNativeToken(b *Blockchain) (*Token, error)

func (*Wallet) GetOrigin

func (w *Wallet) GetOrigin(url string) *Origin

func (*Wallet) GetSigner

func (w *Wallet) GetSigner(n string) *Signer

func (*Wallet) GetSignerWithCopies

func (w *Wallet) GetSignerWithCopies(name string) []*Signer

func (*Wallet) GetSignerWithCopyIndex

func (w *Wallet) GetSignerWithCopyIndex(name string) (*Signer, int)

func (*Wallet) GetToken

func (w *Wallet) GetToken(chain int, a string) *Token

func (*Wallet) GetTokenByAddress

func (w *Wallet) GetTokenByAddress(chain int, a common.Address) *Token

func (*Wallet) GetTokenBySymbol

func (w *Wallet) GetTokenBySymbol(chain int, s string) *Token

func (*Wallet) IsContractTrusted

func (w *Wallet) IsContractTrusted(addr common.Address) bool

func (*Wallet) PromoteOriginAddress

func (w *Wallet) PromoteOriginAddress(url string, a string) error

func (*Wallet) RemoveLP_V3

func (w *Wallet) RemoveLP_V3(chainId int, provider common.Address) error

func (*Wallet) RemoveLP_V3Position

func (w *Wallet) RemoveLP_V3Position(addr common.Address, chainId int, provider common.Address, nft *big.Int) error

func (*Wallet) RemoveOrigin

func (w *Wallet) RemoveOrigin(url string) error

func (*Wallet) RemoveOriginAddress

func (w *Wallet) RemoveOriginAddress(url string, a common.Address) error

func (*Wallet) Save

func (w *Wallet) Save() error

func (*Wallet) SetContract

func (w *Wallet) SetContract(a common.Address, c *Contract) error

func (*Wallet) SetOrigin

func (w *Wallet) SetOrigin(url string) error

func (*Wallet) SetOriginChain

func (w *Wallet) SetOriginChain(url string, ch string) error

func (*Wallet) SetParamInt

func (w *Wallet) SetParamInt(name string, val int) error

func (*Wallet) SetParamStr

func (w *Wallet) SetParamStr(name string, val string) error

func (*Wallet) TrustContract

func (w *Wallet) TrustContract(addr common.Address) error

func (*Wallet) UntrustContract

func (w *Wallet) UntrustContract(addr common.Address) error

type XF

type XF struct {
	*big.Int

	NaN bool
	// contains filtered or unexported fields
}

func Add

func Add(x, y *XF) *XF

func Div

func Div(x, y *XF) *XF

func Mul

func Mul(x, y *XF) *XF

func NewXF

func NewXF(v *big.Int, decimal int) *XF

func NewXF_BigFloat

func NewXF_BigFloat(v *big.Float) *XF

func NewXF_Float64

func NewXF_Float64(v float64) *XF

func NewXF_UInt64

func NewXF_UInt64(v uint64) *XF

func ParseXF

func ParseXF(s string) (*XF, error)

func Pow10

func Pow10(N int) *XF

func Sub

func Sub(x, y *XF) *XF

func (*XF) Add

func (n *XF) Add(x *XF) *XF

func (*XF) BigInt

func (n *XF) BigInt() *big.Int

func (*XF) Div

func (n *XF) Div(x *XF) *XF

func (*XF) Dump

func (n *XF) Dump() string

func (*XF) Float64

func (n *XF) Float64() float64

func (*XF) Format

func (n *XF) Format(fixed bool, prefix string) string

func (*XF) IsZero

func (n *XF) IsZero() bool

func (*XF) Mul

func (n *XF) Mul(x *XF) *XF

func (*XF) Norm

func (n *XF) Norm() *XF

func (*XF) OrderOfMagnitude

func (n *XF) OrderOfMagnitude() int

func (*XF) String

func (n *XF) String() string

func (*XF) Sub

func (n *XF) Sub(x *XF) *XF

Jump to

Keyboard shortcuts

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