Skip to content

Commit

Permalink
fix cmd wallet and storage
Browse files Browse the repository at this point in the history
  • Loading branch information
gohumble committed Oct 15, 2023
1 parent 8b8560d commit 30c2c7c
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 27 deletions.
5 changes: 1 addition & 4 deletions cashu/cashu.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,7 @@ func (e ErrorResponse) Error() string {

// CreateInvoice will generate a blank invoice
func CreateInvoice() lightning.Invoicer {
if lightning.Config.Lightning.Enabled {
return lnbits.NewInvoice()
}
return nil
return lnbits.NewInvoice()
}

type Mint struct {
Expand Down
2 changes: 1 addition & 1 deletion cmd/cashu/feni/burn.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func burnCmd(wallet *wallet.Wallet, params cobraParameter) {
proofs := make([]cashu.Proof, 0)
var err error
if all {
proofs, err = storage.GetReservedProofs()
proofs, err = wallet.Storage.GetReservedProofs()
if err != nil {
log.Fatal(err)
}
Expand Down
3 changes: 0 additions & 3 deletions cmd/cashu/feni/feni.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package feni
import (
"fmt"
"github.com/c-bata/go-prompt"
"github.com/cashubtc/cashu-feni/db"
"github.com/cashubtc/cashu-feni/wallet"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
Expand All @@ -12,8 +11,6 @@ import (
"path"
)

var storage db.MintStorage

const getWalletsAnnotationValue = "GetWallets"

var GetWalletsDynamic = func(annotationValue string) []prompt.Suggest {
Expand Down
8 changes: 1 addition & 7 deletions cmd/cashu/feni/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,13 @@ func mintCmd(wallet *wallet.Wallet, params cobraParameter) {
panic(err)
}
if amount > 0 {
if !wallet.Config.Lightning {
if _, err := wallet.Mint(uint64(amount), hash); err != nil {
log.Error(err)
}
return
}
if hash == "" {
var invoice lightning.Invoicer
invoice, err = wallet.Client.GetMint(int64(amount))
if err != nil {
panic(err)
}
err = storage.StoreLightningInvoice(invoice)
err = wallet.Storage.StoreLightningInvoice(invoice)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cashu/feni/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ func flagIsPay2ScriptHash() bool {
}

func lock(wallet *wallet.Wallet, params cobraParameter) {
fmt.Println(createP2SHLock())
fmt.Println(createP2SHLock(wallet))
}

func createP2SHLock() *cashu.P2SHScript {
func createP2SHLock(wallet *wallet.Wallet) *cashu.P2SHScript {
key := bitcoin.Step0CarolPrivateKey()
txInRedeemScript := bitcoin.Step0CarolCheckSigRedeemScript(*key.PubKey())
fmt.Println(txInRedeemScript)
Expand All @@ -45,7 +45,7 @@ func createP2SHLock() *cashu.P2SHScript {
txInRedeemScriptB64 := base64.URLEncoding.EncodeToString(txInRedeemScript)
txInSignatureB64 := base64.URLEncoding.EncodeToString(txInSignature.SignatureScript)
p2SHScript := cashu.P2SHScript{Script: txInRedeemScriptB64, Signature: txInSignatureB64, Address: txInP2SHAdress.EncodeAddress()}
err = storage.StoreScript(p2SHScript)
err = wallet.Storage.StoreScript(p2SHScript)
if err != nil {
return nil
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/cashu/feni/locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func init() {

const getLocksAnnotationValue = "GetLocks"

var GetLocksDynamic = func(annotationValue string) []prompt.Suggest {
scripts, err := storage.GetScripts("")
var GetLocksDynamic = func(wallet *wallet.Wallet, annotationValue string) []prompt.Suggest {
scripts, err := wallet.Storage.GetScripts("")
if err != nil {
return nil
}
Expand All @@ -39,14 +39,14 @@ var locksCommand = &cobra.Command{
}

func locks(wallet *wallet.Wallet, params cobraParameter) {
scriptLocks := getP2SHLocks()
scriptLocks := getP2SHLocks(wallet)
for _, l := range scriptLocks {
fmt.Printf("P2SH:%s\n", l.Address)
}
}

func getP2SHLocks() []cashu.P2SHScript {
scripts, err := storage.GetScripts("")
func getP2SHLocks(wallet *wallet.Wallet) []cashu.P2SHScript {
scripts, err := wallet.Storage.GetScripts("")
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cashu/feni/pending.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
RootCmd.Command().AddCommand(pendingCommand)
}
func pendingCmd(wallet *wallet.Wallet, params cobraParameter) {
reserved, err := storage.GetReservedProofs()
reserved, err := wallet.Storage.GetReservedProofs()
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cashu/feni/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func DynamicSuggestion(cmd *RootCommand) func(annotationValue string, document *
return suggestions
}
} else if document.Text == "locks " || document.Text == "-l " {
if suggestions := GetLocksDynamic(annotationValue); suggestions != nil {
if suggestions := GetLocksDynamic(cmd.wallet, annotationValue); suggestions != nil {
return suggestions
}
} else if sendRegex.MatchString(document.Text) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cashu/feni/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var sendCommand = &cobra.Command{
}
var filteredKeySets []crypto.KeySet
var GetMintsDynamic = func(wallet *wallet.Wallet, annotationValue string) []prompt.Suggest {
keysets, err := storage.GetKeySet()
keysets, err := wallet.Storage.GetKeySet()
if err != nil {
return nil
}
Expand All @@ -59,7 +59,7 @@ var GetMintsDynamic = func(wallet *wallet.Wallet, annotationValue string) []prom
}

func askMintSelection(wallet *wallet.Wallet, cmd *cobra.Command) error {
keysets, err := storage.GetKeySet()
keysets, err := wallet.Storage.GetKeySet()
if err != nil {
return nil
}
Expand Down

0 comments on commit 30c2c7c

Please sign in to comment.