feni

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const DynamicSuggestionsAnnotation = "cobra-prompt-dynamic-suggestions"

DynamicSuggestionsAnnotation for dynamic suggestions.

View Source
const PersistFlagValuesFlag = "persist-flag-values"

PersistFlagValuesFlag the flag that will be avaiailable when PersistFlagValues is true

Variables

View Source
var GetLocksDynamic = func(annotationValue string) []prompt.Suggest {
	scripts, err := storage.GetScripts("")
	if err != nil {
		return nil
	}
	suggestions := make([]prompt.Suggest, 0)
	for _, script := range scripts {
		suggestions = append(suggestions, prompt.Suggest{Text: fmt.Sprintf("P2SH:%s", script.Address), Description: fmt.Sprintf("Your P2SH lock for receiving and sending cashu tokens")})

	}
	return suggestions
}
View Source
var GetMintsDynamic = func(annotationValue string) []prompt.Suggest {
	keysets, err := storage.GetKeySet()
	if err != nil {
		return nil
	}
	suggestions := make([]prompt.Suggest, 0)
	setBalanceAvailable := make(map[string]uint64)
	balances, err := Wallet.balancePerKeySet()
	if err != nil {
		panic(err)
	}
	filteredKeySets = lo.UniqBy[crypto.KeySet, string](keysets, func(k crypto.KeySet) string {
		if b := balances.ById(k.Id); b != nil {
			setBalanceAvailable[k.MintUrl] = b.Available
		}

		return k.MintUrl
	})

	for i, set := range filteredKeySets {
		suggestions = append(suggestions, prompt.Suggest{
			Text:        fmt.Sprintf("%d", i),
			Description: fmt.Sprintf("Balance: %d sat URL: %s\n", setBalanceAvailable[set.MintUrl], set.MintUrl)})
	}
	return suggestions
}
View Source
var GetWalletsDynamic = func(annotationValue string) []prompt.Suggest {
	dirname, err := os.UserHomeDir()
	if err != nil {
		log.Fatal(err)
	}
	err = godotenv.Load()
	files, err := os.ReadDir(path.Join(dirname, ".cashu"))
	if err != nil {
		log.Fatal(err)
	}
	suggestions := make([]prompt.Suggest, 0)
	for _, file := range files {
		if file.IsDir() {
			suggestions = append(suggestions, prompt.Suggest{Text: file.Name(), Description: fmt.Sprintf("Wallet %s in your home folder", file.Name())})
		}

	}
	return suggestions
}
View Source
var Host string
View Source
var RootCmd = &cobra.Command{
	Use:   "feni",
	Short: "Cashu Feni is a cashu wallet application",
	Long:  ``,
	Annotations: map[string]string{
		DynamicSuggestionsAnnotation: getWalletsAnnotationValue,
	},
	Run: func(cmd *cobra.Command, args []string) {
	},
}
View Source
var WalletUsed string

Functions

func InitializeDatabase

func InitializeDatabase(wallet string)

func PreRunFeni

func PreRunFeni(cmd *cobra.Command, args []string)

func RandStringRunes

func RandStringRunes(n int) string

func SumProofs

func SumProofs(p []cashu.Proof) uint64

Types

type Balance

type Balance struct {
	Balance   uint64
	Available uint64
	Mint      Mint
}

type Balances added in v0.1.7

type Balances []*Balance

func (Balances) ById added in v0.1.7

func (b Balances) ById(id string) *Balance

type Client

type Client struct {
	Url string
}

func (Client) CheckFee

func (c Client) CheckFee(CheckFeesRequest cashu.CheckFeesRequest) (*cashu.CheckFeesResponse, error)

func (Client) GetMint

func (c Client) GetMint(amount int64) (lightning.Invoicer, error)

func (Client) KeySets

func (c Client) KeySets() (*cashu.GetKeySetsResponse, error)

func (Client) Keys

func (c Client) Keys() (map[uint64]*secp256k1.PublicKey, error)

func (Client) KeysForKeySet added in v0.1.7

func (c Client) KeysForKeySet(kid string) (map[uint64]*secp256k1.PublicKey, error)

func (Client) Melt

func (c Client) Melt(data cashu.MeltRequest) (*cashu.MeltResponse, error)

func (Client) Mint

func (c Client) Mint(data cashu.MintRequest, paymentHash string) (*cashu.MintResponse, error)

func (Client) Split

func (c Client) Split(data cashu.SplitRequest) (*cashu.SplitResponse, error)

type CobraPrompt

type CobraPrompt struct {
	// RootCmd is the start point, all its sub commands and flags will be available as suggestions
	RootCmd *cobra.Command

	// GoPromptOptions is for customize go-prompt
	// see https://github.com/c-bata/go-prompt/blob/master/option.go
	GoPromptOptions []prompt.Option

	// DynamicSuggestionsFunc will be executed if an command has CallbackAnnotation as an annotation. If it's included
	// the value will be provided to the DynamicSuggestionsFunc function.
	DynamicSuggestionsFunc func(annotationValue string, document *prompt.Document) []prompt.Suggest

	// PersistFlagValues will persist flags. For example have verbose turned on every command.
	PersistFlagValues bool

	// ShowHelpCommandAndFlags will make help command and flag for every command available.
	ShowHelpCommandAndFlags bool

	// DisableCompletionCommand will disable the default completion command for cobra
	DisableCompletionCommand bool

	// ShowHiddenCommands makes hidden commands available
	ShowHiddenCommands bool

	// ShowHiddenFlags makes hidden flags available
	ShowHiddenFlags bool

	// AddDefaultExitCommand adds a command for exiting prompt loop
	AddDefaultExitCommand bool

	// OnErrorFunc handle error for command.Execute, if not set print error and exit
	OnErrorFunc func(err error)

	// InArgsParser adds a custom parser for the command line arguments (default: strings.Fields)
	InArgsParser func(args string) []string

	// SuggestionFilter will be uses when filtering suggestions as typing
	SuggestionFilter func(suggestions []prompt.Suggest, document *prompt.Document) []prompt.Suggest
}

CobraPrompt given a Cobra command it will make every flag and sub commands available as suggestions. Command.Short will be used as description for the suggestion.

func (CobraPrompt) Run

func (co CobraPrompt) Run()

Run will automatically generate suggestions for all cobra commands and flags defined by RootCmd and execute the selected commands. Run will also reset all given flags by default, see PersistFlagValues

type Mint added in v0.1.7

type Mint struct {
	URL string   `json:"url"`
	Ks  []string `json:"ks"`
}

type MintWallet

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

func (MintWallet) GetSpendableProofs

func (w MintWallet) GetSpendableProofs() ([]cashu.Proof, error)

func (MintWallet) Mint

func (w MintWallet) Mint(amount uint64, paymentHash string) ([]cashu.Proof, error)

func (MintWallet) PayLightning

func (w MintWallet) PayLightning(proofs []cashu.Proof, invoice string) ([]cashu.Proof, error)

func (*MintWallet) Split

func (w *MintWallet) Split(proofs []cashu.Proof, amount uint64, scndSecret string) (keep []cashu.Proof, send []cashu.Proof, err error)

func (MintWallet) SplitToSend

func (w MintWallet) SplitToSend(amount uint64, scndSecret string, setReserved bool) (keep []cashu.Proof, send []cashu.Proof, err error)

type Mints added in v0.1.7

type Mints map[string]Mint

type Pair

type Pair[T, U any] struct {
	First  T
	Second U
}

func Zip

func Zip[T, U any](ts []T, us []U) []Pair[T, U]

type Proofs added in v0.2.0

type Proofs struct {
	ID     string `json:"id"`
	Amount int    `json:"amount"`
	Secret string `json:"secret"`
	C      string `json:"C"`
}

type Token added in v0.1.7

type Token struct {
	Mint   string        `json:"mint"`
	Proofs []cashu.Proof `json:"proofs"`
}

type Tokens added in v0.2.0

type Tokens struct {
	Token []Token `json:"token"`
	Memo  string  `json:"memo"`
}

func NewTokens added in v0.2.0

func NewTokens(t string) *Tokens

func (Tokens) String added in v0.2.0

func (t Tokens) String() string

type WalletConfig

type WalletConfig struct {
	Debug          bool   `env:"DEBUG"`
	Lightning      bool   `env:"LIGHTNING"`
	MintServerHost string `env:"MINT_HOST"`
	MintServerPort string `env:"MINT_PORT"`
	Wallet         string `env:"WALLET"`
}
var Config WalletConfig

Jump to

Keyboard shortcuts

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