Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go template #36

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
3500730
fix: refactored code to declutter main
yemmyharry Apr 29, 2024
208a5a0
feat: add index file for home page
yemmyharry Apr 29, 2024
0b56342
feat: add handlers for templates
yemmyharry Apr 29, 2024
e175d42
feat: add buttons linking to pages
yemmyharry May 7, 2024
b1770cb
feat: add admin page
yemmyharry May 11, 2024
e04b00c
feat: add create invoice page
yemmyharry May 11, 2024
9f347b9
fix: updated path
yemmyharry May 11, 2024
a3f317f
feat: add invoice page
yemmyharry May 11, 2024
bed4489
feat: add create invoice, invoice and config methods
yemmyharry May 11, 2024
65e54ed
fix: updated routes
yemmyharry May 11, 2024
0e09983
feat: add ln-pay button
yemmyharry May 13, 2024
e9903d6
feat: add ln-pay page
yemmyharry May 13, 2024
d2d4c26
feat: add ln-pay handler
yemmyharry May 13, 2024
76a3fe0
feat: add route for ln-pay
yemmyharry May 15, 2024
e891819
feat: add conditional rendering for ln-pay
yemmyharry Jun 20, 2024
905af40
feat: remove amount
yemmyharry Jun 20, 2024
1550775
fix: Remove Payment Failed message on page load
yemmyharry Jun 20, 2024
134fb91
fix: add missing parameter
yemmyharry Jun 20, 2024
bebd6da
feat: Create Invoice for Pubkey Tweak
yemmyharry Jun 21, 2024
39671b6
feat: update routes to include creating invoice with pubkey tweak and…
yemmyharry Jun 27, 2024
d195de7
refactor: restructure paths
yemmyharry Jun 27, 2024
ead6293
feat: update routes to include creating invoice with pubkey tweak and…
yemmyharry Jun 27, 2024
166e863
feat: add claim invoice page
yemmyharry Jun 27, 2024
4075afc
feat: add check claim status page for external pubkey tweak
yemmyharry Jun 27, 2024
f535b45
feat: add methods to check claim status
yemmyharry Jun 27, 2024
d7464c4
feat: add withdraw and deposit pages
yemmyharry Jul 3, 2024
a469ae3
feat: implement withdraw and deposit functionalities
yemmyharry Jul 3, 2024
f0cbd2c
feat: add all mint pages
yemmyharry Jul 6, 2024
67d79ec
feat: add main mint page for user interaction
yemmyharry Jul 6, 2024
0d60ecd
feat: add all handlers for mint
yemmyharry Jul 6, 2024
4ceb162
feat: add all routes for mint
yemmyharry Jul 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 78 additions & 36 deletions wrappers/fedimint-go/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import (
"encoding/hex"
"encoding/json"
"fedimint-go-client/pkg/fedimint"
"fedimint-go-client/pkg/handlers"
"fmt"
"log"
"os"

"html/template"
"net/http"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/joho/godotenv"
)
Expand Down Expand Up @@ -64,17 +69,7 @@ func buildTestClient() *fedimint.FedimintClient {
return fedimint.NewFedimintClient(baseUrl, password, federationId)
}

func main() {
fc := buildTestClient()
fc.UseDefaultGateway()
keyPair := newKeyPair()
fmt.Printf("Generated Key Pair: ")
fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey)
fmt.Printf(" Public Key: %s\n", keyPair.PublicKey)

///////////////////
// ADMIN METHODS //
///////////////////
func adminMethods(fc *fedimint.FedimintClient) {

// `/v2/admin/config`
logMethod("/v2/admin/config")
Expand Down Expand Up @@ -186,9 +181,9 @@ func main() {

logInputAndOutput([]interface{}{10}, listOperationsResponseData)

///////////////////////
// LIGHTNING METHODS //
///////////////////////
}

func lnMethods(fc *fedimint.FedimintClient, kp KeyPair) {

// `/v2/ln/list-gateways`
logMethod("/v2/ln/list-gateways")
Expand All @@ -198,7 +193,7 @@ func main() {
return
}

jsonBytes, err = json.Marshal(gatewayList)
jsonBytes, err := json.Marshal(gatewayList)
if err != nil {
fmt.Println("Error marshaling JSON(list-gateways):", err)
return
Expand Down Expand Up @@ -284,56 +279,56 @@ func main() {

logInputAndOutput(invoiceData.OperationId, awaitInvoiceResponseData)

// `/v1/ln/invoice-external-pubkey-tweaked`
logMethod("/v1/ln/invoice-external-pubkey-tweaked")
tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", fc.GetActiveGatewayId(), nil, nil)
// `/v2/ln/invoice-external-pubkey-tweaked`
logMethod("/v2/ln/invoice-external-pubkey-tweaked")
tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(kp.PublicKey, 1, 10000, "test", fc.GetActiveGatewayId(), nil, nil)
if err != nil {
fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err)
return
}

jsonBytes, err = json.Marshal(tweakInvoice)
if err != nil {
fmt.Println("Error marshaling JSON(await-invoice):", err)
fmt.Println("Error marshaling JSON(invoice-external-pubkey-tweaked):", err)
return
}
var tweakInvoiceResponseData interface{}
err = json.Unmarshal(jsonBytes, &tweakInvoiceResponseData)
if err != nil {
fmt.Println("Error unmarshalling JSON(await-invoice):", err)
fmt.Println("Error unmarshalling JSON(invoice-external-pubkey-tweaked):", err)
return
}

logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData)
logInputAndOutput([]interface{}{kp.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData)
// pay the invoice
_, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil)
fmt.Println("Paid locked invoice!")

// `/v1/ln/claim-external-pubkey-tweaked`
logMethod("/v1/ln/claim-external-pubkey-tweaked")
claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, nil, nil)
// `/v2/ln/claim-external-receive-tweaked`
logMethod("/v2/ln/claim-external-receive-tweaked")
claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(kp.PrivateKey, []uint64{1}, nil, nil)
if err != nil {
fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err)
return
}

jsonBytes, err = json.Marshal(claimInvoice)
if err != nil {
fmt.Println("Error marshaling JSON(claim-external-pubkey-tweaked):", err)
fmt.Println("Error marshaling JSON(claim-external-receive-tweaked):", err)
return
}
var claimInvoiceResponseData interface{}
err = json.Unmarshal(jsonBytes, &claimInvoiceResponseData)
if err != nil {
fmt.Println("Error unmarshalling JSON(claim-external-pubkey-tweaked):", err)
fmt.Println("Error unmarshalling JSON(claim-external-receive-tweaked):", err)
return
}

logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoiceResponseData)
logInputAndOutput([]interface{}{kp.PrivateKey, []uint64{1}}, claimInvoiceResponseData)

}

//////////////////
// MINT METHODS //
//////////////////
func mintMethods(fc *fedimint.FedimintClient) {

// `/v2/mint/spend`
logMethod("/v2/mint/spend")
Expand All @@ -343,7 +338,7 @@ func main() {
return
}

jsonBytes, err = json.Marshal(mintData)
jsonBytes, err := json.Marshal(mintData)
if err != nil {
fmt.Println("Error marshaling JSON(spend):", err)
return
Expand Down Expand Up @@ -391,7 +386,7 @@ func main() {
}
encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson)
if err != nil {
fmt.Println("Error calling DECODE_NOTES: ", err)
fmt.Println("Error calling ENCODE_NOTES: ", err)
return
}

Expand Down Expand Up @@ -522,10 +517,9 @@ func main() {
}

logInputAndOutput(splitData.Notes, combineResponseData)
}

/////////////////////
// ONCHAIN METHODS //
/////////////////////
func onchainMethods(fc *fedimint.FedimintClient) {

// `/v2/onchain/deposit-address`
logMethod("/v2/onchain/deposit-address")
Expand All @@ -535,7 +529,7 @@ func main() {
return
}

jsonBytes, err = json.Marshal(addr)
jsonBytes, err := json.Marshal(addr)
if err != nil {
fmt.Println("Error marshaling JSON(deposit-address):", err)
return
Expand Down Expand Up @@ -574,4 +568,52 @@ func main() {
fmt.Println("============================================")
fmt.Println("|| Done: All methods tested successfully! ||")
fmt.Println("============================================")

}

func main() {
fc := buildTestClient()
fc.UseDefaultGateway()
// keyPair := newKeyPair()
// fmt.Printf("Generated Key Pair: ")
// fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey)
// fmt.Printf(" Public Key: %s\n", keyPair.PublicKey)

// admin methods
// adminMethods(fc)
//lightening methods
// lnMethods(fc, keyPair)
// mint methods
// mintMethods(fc)
//onchain methods
// onchainMethods(fc)

handlers := &handlers.Handler{
Tmpl: template.Must(template.ParseGlob("templates/*.gohtml")),
Fc: buildTestClient(),
}

r := http.NewServeMux()
r.HandleFunc("/", handlers.Index)
r.HandleFunc("/admin/config", handlers.AdminConfigHandler)
r.HandleFunc("/ln/invoice", handlers.InvoiceHandler)
r.HandleFunc("/create_invoice", handlers.CreateInvoiceHandler)
r.HandleFunc("/ln_pay", handlers.LnPayHandler)
r.HandleFunc("/create_invoice_pubkey_tweak", handlers.CreatePubKeyTweakInvoiceHandler)
r.HandleFunc("/claim_external", handlers.ClaimExternalReceiveTweak)
r.HandleFunc("/claim_invoice", handlers.ClaimInvoice)
r.HandleFunc("/onchain", handlers.OnchainHandler)
r.HandleFunc("/deposit", handlers.DepositHandler)
r.HandleFunc("/withdraw", handlers.WithdrawHandler)
r.HandleFunc("/mint", handlers.MintHandler)
r.HandleFunc("/spend", handlers.SpendHandler)
r.HandleFunc("/decode_notes", handlers.DecodeNotesHandler)
r.HandleFunc("/encode_notes", handlers.EncodeNotesHandler)
r.HandleFunc("/validate", handlers.ValidateNotesHandler)
r.HandleFunc("/reissue", handlers.ReissueNotesHandler)
r.HandleFunc("/split", handlers.SplitNotesHandler)
r.HandleFunc("/combine", handlers.CombineHandler)

log.Fatal(http.ListenAndServe(":8080", r))

}
Loading
Loading