Skip to content

Commit

Permalink
public client
Browse files Browse the repository at this point in the history
  • Loading branch information
gohumble committed Jul 17, 2023
1 parent 31c55c8 commit 1494df2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
12 changes: 6 additions & 6 deletions cmd/cashu/feni/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func StartClientConfiguration() {

Wallet = MintWallet{
proofs: make([]cashu.Proof, 0),
client: &Client{Url: fmt.Sprintf("%s:%s", Config.MintServerHost, Config.MintServerPort)},
Client: &Client{Url: fmt.Sprintf("%s:%s", Config.MintServerHost, Config.MintServerPort)},
}

Wallet.loadDefaultMint()
Expand All @@ -82,7 +82,7 @@ func (w *MintWallet) loadMint(keySetId string) {
w.currentKeySet = &set
}
}
w.client.Url = w.currentKeySet.MintUrl
w.Client.Url = w.currentKeySet.MintUrl
w.loadDefaultMint()
}
func (w *MintWallet) setCurrentKeySet(keySet crypto.KeySet) {
Expand All @@ -103,7 +103,7 @@ func (w *MintWallet) loadDefaultMint() {
keySet, _ := w.persistCurrentKeysSet()
w.loadPersistedKeySets()
w.setCurrentKeySet(keySet)
k, err := w.client.KeySets()
k, err := w.Client.KeySets()
if err != nil {
panic(err)
}
Expand All @@ -120,14 +120,14 @@ func (w *MintWallet) loadDefaultMint() {

}
func (w *MintWallet) persistCurrentKeysSet() (crypto.KeySet, error) {
activeKeys, err := w.client.Keys()
activeKeys, err := w.Client.Keys()
if err != nil {
panic(err)
}
return w.persistKeysSet(activeKeys)
}
func (w *MintWallet) persistKeysSet(keys map[uint64]*secp256k1.PublicKey) (crypto.KeySet, error) {
keySet := crypto.KeySet{MintUrl: w.client.Url, FirstSeen: time.Now(), PublicKeys: crypto.PublicKeyList{}}
keySet := crypto.KeySet{MintUrl: w.Client.Url, FirstSeen: time.Now(), PublicKeys: crypto.PublicKeyList{}}
keySet.SetPublicKeyList(keys)
keySet.DeriveKeySetId()
err := storage.StoreKeySet(keySet)
Expand All @@ -140,7 +140,7 @@ func (w *MintWallet) checkAndPersistKeySet(id string) error {
var ks []crypto.KeySet
var err error
if ks, err = storage.GetKeySet(db.KeySetWithId(id)); err != nil || len(ks) == 0 {
keys, err := w.client.KeysForKeySet(id)
keys, err := w.Client.KeysForKeySet(id)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/cashu/feni/invoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func mintCmd(cmd *cobra.Command, args []string) {
}
if hash == "" {
var invoice lightning.Invoicer
invoice, err = Wallet.client.GetMint(int64(amount))
invoice, err = Wallet.Client.GetMint(int64(amount))
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -80,7 +80,7 @@ func mintCmd(cmd *cobra.Command, args []string) {
}

func invalidate(proofs []cashu.Proof) error {
resp, err := Wallet.client.Check(cashu.CheckSpendableRequest{Proofs: proofs})
resp, err := Wallet.Client.Check(cashu.CheckSpendableRequest{Proofs: proofs})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cashu/feni/pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func pay(cmd *cobra.Command, args []string) {
return
}
invoice := args[0]
fee, err := Wallet.client.CheckFee(cashu.CheckFeesRequest{Pr: invoice})
fee, err := Wallet.Client.CheckFee(cashu.CheckFeesRequest{Pr: invoice})
if err != nil {
log.Fatal(err)
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/cashu/feni/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func receive(cmd *cobra.Command, args []string) {
log.Fatal("Aborted!")
}*/
for _, token := range tokens.Token {
defaultUrl := Wallet.client.Url
defaultUrl := Wallet.Client.Url
defer func() {
Wallet.client.Url = defaultUrl
Wallet.Client.Url = defaultUrl
}()
Wallet.client.Url = token.Mint
Wallet.Client.Url = token.Mint
_, _, err := Wallet.redeem(token.Proofs, script, signature)
if err != nil {
log.Fatal(err)
Expand All @@ -124,10 +124,10 @@ func verifyMints(cmd cobra.Command, token Tokens) (trust bool) {
continue
}
trust = false
u := Wallet.client.Url
Wallet.client.Url = m.Mint
u := Wallet.Client.Url
Wallet.Client.Url = m.Mint
// fetch unknown keysets from mint
wks, err := Wallet.client.KeySets()
wks, err := Wallet.Client.KeySets()
if err != nil {
panic(err)
}
Expand All @@ -145,7 +145,7 @@ func verifyMints(cmd cobra.Command, token Tokens) (trust bool) {
}
// ask user to verify trust
cmd.Printf("Warning: Tokens are from a mint you don't know yet.\n")
cmd.Printf("Mint URL: %s\n", Wallet.client.Url)
cmd.Printf("Mint URL: %s\n", Wallet.Client.Url)
cmd.Printf("Mint keyset: %s\n", kid)
cmd.Printf("Do you trust this mint and want to receive the tokens? (y/n)\n")
trust = ask(&cmd)
Expand All @@ -155,7 +155,7 @@ func verifyMints(cmd cobra.Command, token Tokens) (trust bool) {
panic(err)
}
}
Wallet.client.Url = u // reset the url
Wallet.Client.Url = u // reset the url
}
return
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/cashu/feni/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func askMintSelection(cmd *cobra.Command) error {
cmd.Printf("Mint: %d Balance: %d sat (available: %d) URL: %s\n", i+1, setBalance[set.MintUrl], setBalanceAvailable[set.MintUrl], set.MintUrl)
}
cmd.Printf("Select mint [1-%d, press enter default 1]\n\n", len(filteredKeySets))
Wallet.client.Url = filteredKeySets[askInt(cmd)-1].MintUrl
Wallet.Client.Url = filteredKeySets[askInt(cmd)-1].MintUrl
Wallet.loadDefaultMint()
return nil
}
Expand Down Expand Up @@ -118,7 +118,7 @@ func send(cmd *cobra.Command, args []string) {
p2sh = true
}
mint, _ := strconv.Atoi(args[1])
Wallet.client.Url = filteredKeySets[mint].MintUrl
Wallet.Client.Url = filteredKeySets[mint].MintUrl
Wallet.loadDefaultMint()
amount, err := strconv.Atoi(args[0])
if err != nil {
Expand Down Expand Up @@ -146,7 +146,7 @@ func send(cmd *cobra.Command, args []string) {
func (w MintWallet) serializeToken(proofs []cashu.Proof, hideSecrets bool) (string, error) {
// Create a new Token structure with the given proofs and an empty Mints map.
token := Tokens{Token: make([]Token, 0)}
token.Token = append(token.Token, Token{Proofs: proofs, Mint: w.client.Url})
token.Token = append(token.Token, Token{Proofs: proofs, Mint: w.Client.Url})
// Iterate over each proof in the `proofs` slice.
for i := range proofs {
// If `hideSecrets` is true, set the `Secret` field of the current proof to an empty string.
Expand Down
8 changes: 4 additions & 4 deletions cmd/cashu/feni/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type MintWallet struct {
keySets []crypto.KeySet // current keySet id from mint server.
proofs []cashu.Proof
currentKeySet *crypto.KeySet
client *Client
Client *Client
}

var Wallet MintWallet
Expand Down Expand Up @@ -118,7 +118,7 @@ func (w MintWallet) mint(amounts []uint64, paymentHash string) []cashu.Proof {
panic(err)
}
req, privateKeys := constructOutputs(amounts, secrets)
blindedSignatures, err := w.client.Mint(req, paymentHash)
blindedSignatures, err := w.Client.Mint(req, paymentHash)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -241,7 +241,7 @@ func (w MintWallet) PayLightning(proofs []cashu.Proof, invoice string) ([]cashu.
secrets = append(secrets, generateSecret())
}
payloads, rs := constructOutputs(amounts, secrets)
res, err := w.client.Melt(cashu.MeltRequest{Proofs: proofs, Pr: invoice, Outputs: payloads.Outputs})
res, err := w.Client.Melt(cashu.MeltRequest{Proofs: proofs, Pr: invoice, Outputs: payloads.Outputs})
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -391,7 +391,7 @@ func (w MintWallet) split(proofs []cashu.Proof, amount uint64, scndSecret string
}
// TODO -- check used secrets(secrtes)
payloads, rs := constructOutputs(amounts, secrets)
response, err := w.client.Split(cashu.SplitRequest{Amount: amount, Proofs: proofs, Outputs: payloads.Outputs})
response, err := w.Client.Split(cashu.SplitRequest{Amount: amount, Proofs: proofs, Outputs: payloads.Outputs})
if err != nil {
return nil, nil, err
}
Expand Down

0 comments on commit 1494df2

Please sign in to comment.