From ebfe5217955f0eb06c65fae25ad978d6e7046a4a Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 25 Mar 2024 23:13:12 +0530 Subject: [PATCH 01/23] fix::> Added testify/assert || added basic tests for client --- .direnv/flake-profile | 1 + .direnv/flake-profile-1-link | 1 + wrappers/fedimint-go/go.mod | 5 + wrappers/fedimint-go/go.sum | 9 + .../fedimint-go/pkg/fedimint/client_test.go | 334 ++++++++++++++++++ 5 files changed, 350 insertions(+) create mode 120000 .direnv/flake-profile create mode 120000 .direnv/flake-profile-1-link create mode 100644 wrappers/fedimint-go/pkg/fedimint/client_test.go diff --git a/.direnv/flake-profile b/.direnv/flake-profile new file mode 120000 index 0000000..0c05709 --- /dev/null +++ b/.direnv/flake-profile @@ -0,0 +1 @@ +flake-profile-1-link \ No newline at end of file diff --git a/.direnv/flake-profile-1-link b/.direnv/flake-profile-1-link new file mode 120000 index 0000000..283ea47 --- /dev/null +++ b/.direnv/flake-profile-1-link @@ -0,0 +1 @@ +/nix/store/q61ni6s1mqr37fcp38wyzm5ryn82z26n-nix-shell-env \ No newline at end of file diff --git a/wrappers/fedimint-go/go.mod b/wrappers/fedimint-go/go.mod index 015fe7f..e629b25 100644 --- a/wrappers/fedimint-go/go.mod +++ b/wrappers/fedimint-go/go.mod @@ -2,8 +2,13 @@ module fedimint-go-client go 1.21.3 +require github.com/stretchr/testify v1.9.0 + require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect + github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/joho/godotenv v1.5.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/wrappers/fedimint-go/go.sum b/wrappers/fedimint-go/go.sum index ca953b9..17e4630 100644 --- a/wrappers/fedimint-go/go.sum +++ b/wrappers/fedimint-go/go.sum @@ -1,6 +1,15 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go new file mode 100644 index 0000000..35d8a31 --- /dev/null +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -0,0 +1,334 @@ +// Client_tests +package fedimint + +import ( + "fedimint-go-client/pkg/fedimint/types/modules" + "fmt" + "testing" + + "github.com/stretchr/testify/assert" +) + +func CreateNewFedimintClient() *FedimintClient { + // Define test data + baseURL := "http://localhost:3333" + password := "password" + federationID := "federation123" + + fc := NewFedimintClient(baseURL, password, federationID) + + return fc +} + +func TestNewFedimintClient(t *testing.T) { + fc := CreateNewFedimintClient() + assert.NotNil(t, fc) + + assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") + assert.Equal(t, fc.Password, "password") + assert.Equal(t, fc.FederationId, "federation123") + + assert.Equal(t, fc, fc.Ln.Client) + assert.Equal(t, fc, fc.Wallet.Client) + assert.Equal(t, fc, fc.Mint.Client) +} + +func TestGetActiveFederationId(t *testing.T) { + fc := CreateNewFedimintClient() + + fedId := fc.getActiveFederationId() + assert.Equal(t, fedId, "federation123") +} + +func TestSetActiveFederationId(t *testing.T) { + fc := CreateNewFedimintClient() + new_fedId := "New_federation123" + + fedId_prev := fc.FederationId + fc.setActiveFederationId(new_fedId) + fedId_now := fc.FederationId + assert.Equal(t, fedId_now, "New_federation123") + assert.NotEqual(t, fedId_now, fedId_prev) +} + +//////////// +// Wallet // +//////////// + +func TestCreateDepositAddress(t *testing.T) { + fc := CreateNewFedimintClient() + + depositAddressRequest := modules.DepositAddressRequest{ + Timeout: 3600, + } + + depositResponse, err := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, depositResponse, nil) + assert.Equal(t, depositResponse.OperationID, nil) + assert.Equal(t, depositResponse.Address, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, depositResponse.OperationID, nil) + assert.NotEqual(t, depositResponse.Address, nil) + } + + awaitDepositRequest := modules.AwaitDepositRequest{ + OperationID: depositResponse.OperationID, + } + + _, err = fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + if err != nil { + fmt.Println("Error awaiting deposit: ", err) + return + } +} + +func TestWithdraw(t *testing.T) { + fc := CreateNewFedimintClient() + + withdrawRequest := modules.WithdrawRequest{ + Address: "UNKNOWN", + AmountMsat: "10000", + } + + withdrawResponse, _ := fc.Wallet.withdraw(withdrawRequest, &fc.FederationId) + + assert.NotEqual(t, withdrawResponse, nil) + + // Intentionally make an error (like - wrong FederationId/request) + wrong_fed_id := "12112" + _, err := fc.Wallet.withdraw(withdrawRequest, &wrong_fed_id) + assert.NotEqual(t, err, nil) +} + +func TestAwaitWithdraw(t *testing.T) { + fc := CreateNewFedimintClient() + + depositAddressRequest := modules.DepositAddressRequest{ + Timeout: 3600, + } + depositResponse, _ := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + + awaitDepositRequest := modules.AwaitDepositRequest{ + OperationID: depositResponse.OperationID, + } + + awaitDepositResponse, err := fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, awaitDepositResponse, nil) + assert.Equal(t, awaitDepositResponse.Status, nil) + } else { + assert.Equal(t, err, nil) + // println(awaitDepositResponse.Status) + assert.NotEqual(t, awaitDepositResponse.Status, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Wallet.awaitDeposit(awaitDepositRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +////////// +// mint // +////////// + +// func TestReissue(t *testing.T) { +// fc := CreateNewFedimintClient() + +// oobNotesData := modules.OOBNotes { + +// } +// } + +func TestSpend(t *testing.T) { + fc := CreateNewFedimintClient() + + spendRequest := modules.SpendRequest{ + AmountMsat: 10000, + AllowOverpay: true, + Timeout: 3600, + } + + spendResponse, err := fc.Mint.Spend(spendRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, spendResponse, nil) + assert.Equal(t, spendResponse.Operation, nil) + assert.Equal(t, spendResponse.Notes, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, spendResponse, nil) + assert.NotEqual(t, spendResponse.Operation, nil) + assert.NotEqual(t, spendResponse.Notes, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Mint.Spend(spendRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +// func TestValidate(t *testing.T) { +// fc := CreateNewFedimintClient() + +// } + +//////// +// Ln // +//////// + +func TestCreateInvoice(t *testing.T) { + fc := CreateNewFedimintClient() + + invoiceRequest := modules.LnInvoiceRequest{ + AmountMsat: 10000, + Description: "test", + } + + invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, invoiceResponse, nil) + assert.Equal(t, invoiceResponse.OperationID, nil) + assert.Equal(t, invoiceResponse.Invoice, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, invoiceResponse, nil) + assert.NotEqual(t, invoiceResponse.OperationID, nil) + assert.NotEqual(t, invoiceResponse.Invoice, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.CreateInvoice(invoiceRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestAwaitInvoice(t *testing.T) { + fc := CreateNewFedimintClient() + + awaitInvoiceRequest := modules.AwaitInvoiceRequest{ + OperationID: "TestAwaitInvoice", + } + + infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, infoResponse, nil) + assert.Equal(t, infoResponse.DenominationsMsat, nil) + assert.Equal(t, infoResponse.FederationID, nil) + assert.Equal(t, infoResponse.Meta, nil) + assert.Equal(t, infoResponse.Network, nil) + assert.Equal(t, infoResponse.TotalAmountMsat, nil) + assert.Equal(t, infoResponse.TotalNumNotes, nil) + assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) + } else { + assert.Equal(t, err, nil) + assert.Equal(t, infoResponse.FederationID, fc.FederationId) + assert.NotEqual(t, infoResponse, nil) + assert.NotEqual(t, infoResponse.Meta, nil) + assert.NotEqual(t, infoResponse.Network, nil) + assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) + assert.NotEqual(t, infoResponse.TotalNumNotes, nil) + assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "" + _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestPay(t *testing.T) { + fc := CreateNewFedimintClient() + + lnPayRequest := modules.LnPayRequest{ + Payment_info: "TestPayment", + Finish_in_background: true, + } + + lnPayResponse, err := fc.Ln.Pay(lnPayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, lnPayResponse, nil) + assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.Fee, nil) + assert.Equal(t, lnPayResponse.Payment_type, nil) + assert.Equal(t, lnPayResponse.Pperation_id, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, lnPayResponse, nil) + assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.Fee, nil) + assert.NotEqual(t, lnPayResponse.Payment_type, nil) + assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.Pay(lnPayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestAwaitPay(t *testing.T) { + fc := CreateNewFedimintClient() + + awaitLnPayRequest := modules.AwaitLnPayRequest{ + Operation_id: "TestAwaitLnPay", + } + + lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, lnPayResponse, nil) + assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.Fee, nil) + assert.Equal(t, lnPayResponse.Payment_type, nil) + assert.Equal(t, lnPayResponse.Pperation_id, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, lnPayResponse, nil) + assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.Fee, nil) + assert.NotEqual(t, lnPayResponse.Payment_type, nil) + assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} + +func TestListGateways(t *testing.T) { + fc := CreateNewFedimintClient() + + gatewaysResponse, err := fc.Ln.ListGateways() + if err != nil { + assert.Equal(t, gatewaysResponse, nil) + } else { + assert.Equal(t, err, nil) + assert.NotEqual(t, gatewaysResponse, nil) + } +} + +func TestSwitchGateway(t *testing.T) { + fc := CreateNewFedimintClient() + + switchGatewayRequest := modules.SwitchGatewayRequest{ + Gateway_id: "TestGateway1", + } + + gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.FederationId) + if err != nil { + assert.Equal(t, gatewayResponse, nil) + assert.Equal(t, gatewayResponse.Active, true) + assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) + } else { + assert.Equal(t, err, nil) + assert.Equal(t, gatewayResponse.Active, true) + assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) + } + + // intentionally giving wrong parameters + wrong_fed_id := "12112" + _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) + assert.NotEqual(t, err1, nil) +} From e137a9c104aa05a5113cf42220a90a1238deb4e1 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Thu, 28 Mar 2024 11:41:21 +0530 Subject: [PATCH 02/23] fix:: Updated the test cases according to new changes in the fn, parameter, var names --- .../fedimint-go/pkg/fedimint/client_test.go | 161 +++++++++--------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 35d8a31..9d5d182 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -26,17 +26,17 @@ func TestNewFedimintClient(t *testing.T) { assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") assert.Equal(t, fc.Password, "password") - assert.Equal(t, fc.FederationId, "federation123") + assert.Equal(t, fc.ActiveFederationId, "federation123") assert.Equal(t, fc, fc.Ln.Client) - assert.Equal(t, fc, fc.Wallet.Client) + assert.Equal(t, fc, fc.Onchain.Client) assert.Equal(t, fc, fc.Mint.Client) } func TestGetActiveFederationId(t *testing.T) { fc := CreateNewFedimintClient() - fedId := fc.getActiveFederationId() + fedId := fc.GetActiveFederationId() assert.Equal(t, fedId, "federation123") } @@ -44,40 +44,40 @@ func TestSetActiveFederationId(t *testing.T) { fc := CreateNewFedimintClient() new_fedId := "New_federation123" - fedId_prev := fc.FederationId - fc.setActiveFederationId(new_fedId) - fedId_now := fc.FederationId + fedId_prev := fc.ActiveFederationId + fc.SetActiveFederationId(new_fedId, false) + fedId_now := fc.ActiveFederationId assert.Equal(t, fedId_now, "New_federation123") assert.NotEqual(t, fedId_now, fedId_prev) } //////////// -// Wallet // +// Onchain // //////////// func TestCreateDepositAddress(t *testing.T) { fc := CreateNewFedimintClient() - depositAddressRequest := modules.DepositAddressRequest{ + depositAddressRequest := modules.OnchainDepositAddressRequest{ Timeout: 3600, } - depositResponse, err := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) if err != nil { assert.Equal(t, depositResponse, nil) - assert.Equal(t, depositResponse.OperationID, nil) + assert.Equal(t, depositResponse.OperationId, nil) assert.Equal(t, depositResponse.Address, nil) } else { assert.Equal(t, err, nil) - assert.NotEqual(t, depositResponse.OperationID, nil) + assert.NotEqual(t, depositResponse.OperationId, nil) assert.NotEqual(t, depositResponse.Address, nil) } - awaitDepositRequest := modules.AwaitDepositRequest{ - OperationID: depositResponse.OperationID, + awaitDepositRequest := modules.OnchainAwaitDepositRequest{ + OperationId: depositResponse.OperationId, } - _, err = fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) if err != nil { fmt.Println("Error awaiting deposit: ", err) return @@ -87,34 +87,34 @@ func TestCreateDepositAddress(t *testing.T) { func TestWithdraw(t *testing.T) { fc := CreateNewFedimintClient() - withdrawRequest := modules.WithdrawRequest{ - Address: "UNKNOWN", - AmountMsat: "10000", + withdrawRequest := modules.OnchainWithdrawRequest{ + Address: "UNKNOWN", + AmountSat: 10000, } - withdrawResponse, _ := fc.Wallet.withdraw(withdrawRequest, &fc.FederationId) + withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) assert.NotEqual(t, withdrawResponse, nil) - // Intentionally make an error (like - wrong FederationId/request) + // Intentionally make an error (like - wrong ActiveFederationId/request) wrong_fed_id := "12112" - _, err := fc.Wallet.withdraw(withdrawRequest, &wrong_fed_id) + _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) assert.NotEqual(t, err, nil) } func TestAwaitWithdraw(t *testing.T) { fc := CreateNewFedimintClient() - depositAddressRequest := modules.DepositAddressRequest{ + depositAddressRequest := modules.OnchainDepositAddressRequest{ Timeout: 3600, } - depositResponse, _ := fc.Wallet.createDepositAddress(depositAddressRequest, &fc.FederationId) + depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) - awaitDepositRequest := modules.AwaitDepositRequest{ - OperationID: depositResponse.OperationID, + awaitDepositRequest := modules.OnchainAwaitDepositRequest{ + OperationId: depositResponse.OperationId, } - awaitDepositResponse, err := fc.Wallet.awaitDeposit(awaitDepositRequest, &fc.FederationId) + awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) if err != nil { assert.Equal(t, awaitDepositResponse, nil) assert.Equal(t, awaitDepositResponse.Status, nil) @@ -126,7 +126,7 @@ func TestAwaitWithdraw(t *testing.T) { // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Wallet.awaitDeposit(awaitDepositRequest, &wrong_fed_id) + _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) assert.NotEqual(t, err1, nil) } @@ -145,27 +145,27 @@ func TestAwaitWithdraw(t *testing.T) { func TestSpend(t *testing.T) { fc := CreateNewFedimintClient() - spendRequest := modules.SpendRequest{ + spendRequest := modules.MintSpendRequest{ AmountMsat: 10000, AllowOverpay: true, Timeout: 3600, } - spendResponse, err := fc.Mint.Spend(spendRequest, &fc.FederationId) + spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) if err != nil { assert.Equal(t, spendResponse, nil) - assert.Equal(t, spendResponse.Operation, nil) + assert.Equal(t, spendResponse.OperationId, nil) assert.Equal(t, spendResponse.Notes, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, spendResponse, nil) - assert.NotEqual(t, spendResponse.Operation, nil) + assert.NotEqual(t, spendResponse.OperationId, nil) assert.NotEqual(t, spendResponse.Notes, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Mint.Spend(spendRequest, &wrong_fed_id) + _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) assert.NotEqual(t, err1, nil) } @@ -181,37 +181,40 @@ func TestSpend(t *testing.T) { func TestCreateInvoice(t *testing.T) { fc := CreateNewFedimintClient() + expiryTime := 3600 + GatewayID := "test_GatewayID" invoiceRequest := modules.LnInvoiceRequest{ AmountMsat: 10000, Description: "test", + ExpiryTime: &expiryTime, } - invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest, &fc.FederationId) + invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) if err != nil { assert.Equal(t, invoiceResponse, nil) - assert.Equal(t, invoiceResponse.OperationID, nil) + assert.Equal(t, invoiceResponse.OperationId, nil) assert.Equal(t, invoiceResponse.Invoice, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, invoiceResponse, nil) - assert.NotEqual(t, invoiceResponse.OperationID, nil) + assert.NotEqual(t, invoiceResponse.OperationId, nil) assert.NotEqual(t, invoiceResponse.Invoice, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Ln.CreateInvoice(invoiceRequest, &wrong_fed_id) + _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) assert.NotEqual(t, err1, nil) } func TestAwaitInvoice(t *testing.T) { fc := CreateNewFedimintClient() - awaitInvoiceRequest := modules.AwaitInvoiceRequest{ - OperationID: "TestAwaitInvoice", + awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ + OperationId: "TestAwaitInvoice", } - infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &fc.FederationId) + infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) if err != nil { assert.Equal(t, infoResponse, nil) assert.Equal(t, infoResponse.DenominationsMsat, nil) @@ -223,7 +226,7 @@ func TestAwaitInvoice(t *testing.T) { assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) } else { assert.Equal(t, err, nil) - assert.Equal(t, infoResponse.FederationID, fc.FederationId) + assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) assert.NotEqual(t, infoResponse, nil) assert.NotEqual(t, infoResponse.Meta, nil) assert.NotEqual(t, infoResponse.Network, nil) @@ -234,68 +237,72 @@ func TestAwaitInvoice(t *testing.T) { // intentionally giving wrong parameters wrong_fed_id := "" - _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest, &wrong_fed_id) + _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) assert.NotEqual(t, err1, nil) } func TestPay(t *testing.T) { fc := CreateNewFedimintClient() + LnurlComment := "test_LnurlComment" + GatewayID := "test_GatewayID" + AmountMsat := uint64(10000) lnPayRequest := modules.LnPayRequest{ - Payment_info: "TestPayment", - Finish_in_background: true, + PaymentInfo: "TestPayment", + AmountMsat: &AmountMsat, + LnurlComment: &LnurlComment, } - lnPayResponse, err := fc.Ln.Pay(lnPayRequest, &fc.FederationId) + lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) if err != nil { assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.Contract_id, nil) + assert.Equal(t, lnPayResponse.ContractId, nil) assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.Payment_type, nil) - assert.Equal(t, lnPayResponse.Pperation_id, nil) + assert.Equal(t, lnPayResponse.PaymentType, nil) + assert.Equal(t, lnPayResponse.PperationId, nil) } else { assert.Equal(t, err, nil) assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.Contract_id, nil) + assert.NotEqual(t, lnPayResponse.ContractId, nil) assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.Payment_type, nil) - assert.NotEqual(t, lnPayResponse.Pperation_id, nil) + assert.NotEqual(t, lnPayResponse.PaymentType, nil) + assert.NotEqual(t, lnPayResponse.PperationId, nil) } // intentionally giving wrong parameters wrong_fed_id := "12112" - _, err1 := fc.Ln.Pay(lnPayRequest, &wrong_fed_id) + _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) assert.NotEqual(t, err1, nil) } -func TestAwaitPay(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestAwaitPay(t *testing.T) { +// fc := CreateNewFedimintClient() - awaitLnPayRequest := modules.AwaitLnPayRequest{ - Operation_id: "TestAwaitLnPay", - } +// awaitLnPayRequest := modules.AwaitLnPayRequest{ +// OperationId: "TestAwaitLnPay", +// } - lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.FederationId) - if err != nil { - assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.Contract_id, nil) - assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.Payment_type, nil) - assert.Equal(t, lnPayResponse.Pperation_id, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.Contract_id, nil) - assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.Payment_type, nil) - assert.NotEqual(t, lnPayResponse.Pperation_id, nil) - } +// lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, lnPayResponse, nil) +// assert.Equal(t, lnPayResponse.Contract_id, nil) +// assert.Equal(t, lnPayResponse.Fee, nil) +// assert.Equal(t, lnPayResponse.Payment_type, nil) +// assert.Equal(t, lnPayResponse.Pperation_id, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, lnPayResponse, nil) +// assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// assert.NotEqual(t, lnPayResponse.Fee, nil) +// assert.NotEqual(t, lnPayResponse.Payment_type, nil) +// assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } func TestListGateways(t *testing.T) { fc := CreateNewFedimintClient() @@ -313,10 +320,10 @@ func TestSwitchGateway(t *testing.T) { fc := CreateNewFedimintClient() switchGatewayRequest := modules.SwitchGatewayRequest{ - Gateway_id: "TestGateway1", + GatewayId: "TestGateway1", } - gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.FederationId) + gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) if err != nil { assert.Equal(t, gatewayResponse, nil) assert.Equal(t, gatewayResponse.Active, true) From 24eb700fdf0624e41b3634585bbf67755345a2a9 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 31 Mar 2024 16:29:31 +0530 Subject: [PATCH 03/23] fix::> Added support func to tests and Updated CreateNewFedimintClient() --- .gitignore | 1 + flake.lock | 98 +++++++++++++++++++ shell.nix | 6 ++ wrappers/fedimint-go/go.mod | 5 +- wrappers/fedimint-go/go.sum | 6 ++ .../fedimint-go/pkg/fedimint/client_test.go | 95 ++++++++++++++++-- 6 files changed, 204 insertions(+), 7 deletions(-) create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index db36602..4f7664f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ fm_client_db .cargo .vscode .DS_Store +fm_db \ No newline at end of file diff --git a/flake.lock b/flake.lock index fd30016..a2ec040 100644 --- a/flake.lock +++ b/flake.lock @@ -69,6 +69,104 @@ "type": "github" } }, +<<<<<<< HEAD +||||||| parent of cdebb0d (fix::> Added support func to tests and Updated CreateNewFedimintClient()) + "devshell_2": { + "inputs": { + "nixpkgs": [ + "flakebox", + "android-nixpkgs", + "nixpkgs" + ], + "systems": "systems_6" + }, + "locked": { + "lastModified": 1695195896, + "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", + "owner": "numtide", + "repo": "devshell", + "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "fedimint": { + "inputs": { + "advisory-db": "advisory-db", + "bundlers": "bundlers", + "fenix": "fenix", + "flake-utils": "flake-utils_2", + "flakebox": "flakebox", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1710534977, + "narHash": "sha256-RWzV+/NZkV87JnydefwRMwJ9tDkwDCg6m3pCxsVlKeY=", + "owner": "fedimint", + "repo": "fedimint", + "rev": "9d552fdf82f4af429165a1fd409615809ada4058", + "type": "github" + }, + "original": { + "owner": "fedimint", + "repo": "fedimint", + "rev": "9d552fdf82f4af429165a1fd409615809ada4058", + "type": "github" + } + }, +======= + "devshell_2": { + "inputs": { + "nixpkgs": [ + "flakebox", + "android-nixpkgs", + "nixpkgs" + ], + "systems": "systems_6" + }, + "locked": { + "lastModified": 1695195896, + "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", + "owner": "numtide", + "repo": "devshell", + "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "devshell", + "type": "github" + } + }, + "fedimint": { + "inputs": { + "advisory-db": "advisory-db", + "bundlers": "bundlers", + "fenix": "fenix", + "flake-utils": "flake-utils_2", + "flakebox": "flakebox", + "nixpkgs": "nixpkgs_4" + }, + "locked": { + "lastModified": 1711405975, + "narHash": "sha256-I8uUhpqN5oGDkT+sN4jztzun/wD/mN/CtzCxlV3pdjY=", + "owner": "fedimint", + "repo": "fedimint", + "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", + "type": "github" + }, + "original": { + "owner": "fedimint", + "repo": "fedimint", + "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", + "type": "github" + } + }, +>>>>>>> cdebb0d (fix::> Added support func to tests and Updated CreateNewFedimintClient()) "fenix": { "inputs": { "nixpkgs": [ diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..bfcd84b --- /dev/null +++ b/shell.nix @@ -0,0 +1,6 @@ +# save this as shell.nix +{ pkgs ? import {}}: + +pkgs.mkShell { + packages = [ pkgs.hello ]; +} diff --git a/wrappers/fedimint-go/go.mod b/wrappers/fedimint-go/go.mod index e629b25..c50e3e5 100644 --- a/wrappers/fedimint-go/go.mod +++ b/wrappers/fedimint-go/go.mod @@ -4,10 +4,13 @@ go 1.21.3 require github.com/stretchr/testify v1.9.0 +require github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0 // indirect + require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect + github.com/decred/dcrd/dcrec/secp256k1 v1.0.4 + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 github.com/joho/godotenv v1.5.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/wrappers/fedimint-go/go.sum b/wrappers/fedimint-go/go.sum index 17e4630..1fce7d4 100644 --- a/wrappers/fedimint-go/go.sum +++ b/wrappers/fedimint-go/go.sum @@ -2,6 +2,12 @@ github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1 v1.0.4 h1:0XErmfJBiVbl0NvyclGn4jr+1hIylDf5beFi9W0o7Fc= +github.com/decred/dcrd/dcrec/secp256k1 v1.0.4/go.mod h1:00z7mJdugt+GBAzPN1QrDRGCXxyKUiexEHu6ukxEw3k= +github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0 h1:3GIJYXQDAKpLEFriGFN8SbSffak10UXHGdIcFaMPykY= +github.com/decred/dcrd/dcrec/secp256k1/v2 v2.0.0/go.mod h1:3s92l0paYkZoIHuj4X93Teg/HB7eGM9x/zokGw+u4mY= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs= github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 9d5d182..18d9aba 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -4,20 +4,103 @@ package fedimint import ( "fedimint-go-client/pkg/fedimint/types/modules" "fmt" + "os" "testing" "github.com/stretchr/testify/assert" ) +type KeyPair struct { + PrivateKey string + PublicKey string +} + +func logMethod(method string) { + fmt.Println("--------------------") + fmt.Println("Method:", method) +} + +func logInputAndOutput(input interface{}, output interface{}) { + fmt.Println("Input: ", input) + fmt.Println("Output: ", output) + fmt.Println("--------------------") +} + +// BIG ISSUE // +// func newKeyPair() KeyPair { +// var privateKey *big.Int +// var err error + +// for { +// privateKey, err = rand.Int(rand.Reader, secp256k1.S256().Params().N) +// if err != nil { +// log.Fatal(err) +// } +// if privateKey.Sign() > 0 && privateKey.Cmp(secp256k1.S256().Params().N) < 0 { +// break +// } +// } + +// // publicKey := secp256k1.PublicKey{} +// // secp256k1.S256().SerializePublicKey(publicKey[:], privateKey.Bytes()) + +// publicKey := secp256k1.PublicKey{} +// publicKey1 := secp256k1.PublicKey{ +// x: new(big.Int), +// y: new(big.Int), +// } +// (publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) + +// return KeyPair{ +// PrivateKey: hex.EncodeToString(privateKey.Bytes()), +// PublicKey: hex.EncodeToString(publicKey[:]), +// } +// } + +/* + async function buildTestClient() { + const baseUrl = process.env.FEDIMINT_CLIENTD_BASE_URL || "127.0.0.1:3333"; + const password = process.env.FEDIMINT_CLIENTD_PASSWORD || "password"; + const activeFederationId = + process.env.FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID || + "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"; + const builder = new FedimintClientBuilder(); + builder + .setBaseUrl(baseUrl) + .setPassword(password) + .setActiveFederationId(activeFederationId); + + const client = await builder.build(); + + await client.useDefaultGateway(); + + console.log("Default gateway id: ", client.getActiveGatewayId()); + + return client; + } +*/ func CreateNewFedimintClient() *FedimintClient { // Define test data - baseURL := "http://localhost:3333" - password := "password" - federationID := "federation123" - - fc := NewFedimintClient(baseURL, password, federationID) + baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") + if baseURL == "" { + baseURL = "127.0.0.1:3333" + } + password := os.Getenv("FEDIMINT_CLIENTD_PASSWORD") + if password == "" { + password = "password" + } + activeFederationID := os.Getenv("FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID") + if activeFederationID == "" { + activeFederationID = "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" + } - return fc + done := make(chan *FedimintClient) + go func() { + fc := NewFedimintClient(baseURL, password, activeFederationID) + fc.UseDefaultGateway() + done <- fc + }() + return <-done } func TestNewFedimintClient(t *testing.T) { From fe061abffb7c771a01697ab56151c68d361f20d5 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 31 Mar 2024 23:47:01 +0530 Subject: [PATCH 04/23] fix::> Added main testing function - TestFedimintGo --- .../fedimint-go/pkg/fedimint/client_test.go | 607 ++++++++++-------- 1 file changed, 338 insertions(+), 269 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 18d9aba..9fa0ccc 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -2,12 +2,13 @@ package fedimint import ( - "fedimint-go-client/pkg/fedimint/types/modules" + "encoding/hex" "fmt" + "log" "os" "testing" - "github.com/stretchr/testify/assert" + "github.com/btcsuite/btcd/btcec/v2" ) type KeyPair struct { @@ -49,36 +50,34 @@ func logInputAndOutput(input interface{}, output interface{}) { // x: new(big.Int), // y: new(big.Int), // } -// (publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) +// //(publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) +// secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) -// return KeyPair{ -// PrivateKey: hex.EncodeToString(privateKey.Bytes()), -// PublicKey: hex.EncodeToString(publicKey[:]), +// return KeyPair{ +// PrivateKey: hex.EncodeToString(privateKey.Bytes()), +// PublicKey: hex.EncodeToString(publicKey[:]), +// } // } -// } - -/* - async function buildTestClient() { - const baseUrl = process.env.FEDIMINT_CLIENTD_BASE_URL || "127.0.0.1:3333"; - const password = process.env.FEDIMINT_CLIENTD_PASSWORD || "password"; - const activeFederationId = - process.env.FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID || - "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3"; - const builder = new FedimintClientBuilder(); - builder - .setBaseUrl(baseUrl) - .setPassword(password) - .setActiveFederationId(activeFederationId); - const client = await builder.build(); +func newKeyPair() KeyPair { + privKey, err := btcec.NewPrivateKey() + if err != nil { + log.Fatal("Error generating private key:", err) + } - await client.useDefaultGateway(); + // Get the corresponding public key + pubKey := privKey.PubKey() - console.log("Default gateway id: ", client.getActiveGatewayId()); + // Print the private and public keys + fmt.Printf("Private key: %x\n", privKey.Serialize()) + fmt.Printf("Public key: %x\n", pubKey.SerializeCompressed()) - return client; + return KeyPair{ + PrivateKey: hex.EncodeToString(privKey.Serialize()), + PublicKey: hex.EncodeToString(pubKey.SerializeCompressed()), } -*/ +} + func CreateNewFedimintClient() *FedimintClient { // Define test data baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -103,322 +102,392 @@ func CreateNewFedimintClient() *FedimintClient { return <-done } -func TestNewFedimintClient(t *testing.T) { +func TestFedimintGo(t *testing.T) { fc := CreateNewFedimintClient() - assert.NotNil(t, fc) - - assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") - assert.Equal(t, fc.Password, "password") - assert.Equal(t, fc.ActiveFederationId, "federation123") - - assert.Equal(t, fc, fc.Ln.Client) - assert.Equal(t, fc, fc.Onchain.Client) - assert.Equal(t, fc, fc.Mint.Client) -} - -func TestGetActiveFederationId(t *testing.T) { - fc := CreateNewFedimintClient() - - fedId := fc.GetActiveFederationId() - assert.Equal(t, fedId, "federation123") -} - -func TestSetActiveFederationId(t *testing.T) { - fc := CreateNewFedimintClient() - new_fedId := "New_federation123" - - fedId_prev := fc.ActiveFederationId - fc.SetActiveFederationId(new_fedId, false) - fedId_now := fc.ActiveFederationId - assert.Equal(t, fedId_now, "New_federation123") - assert.NotEqual(t, fedId_now, fedId_prev) -} - -//////////// -// Onchain // -//////////// + 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 // + /////////////////// + + // `/v2/admin/config` + logMethod("/v2/admin/config") + data, err := fc.Config() + if err != nil { + fmt.Println("Error calling CONFIG: ", err) + return + } + logInputAndOutput(nil, data) -func TestCreateDepositAddress(t *testing.T) { - fc := CreateNewFedimintClient() + // `/v2/admin/discover-version` + logMethod("/v2/admin/discover-version") + data, err = fc.DiscoverVersion(1) + if err != nil { + fmt.Println("Error calling VERSION: ", err) + return + } + logInputAndOutput(1, data) - depositAddressRequest := modules.OnchainDepositAddressRequest{ - Timeout: 3600, + // `/v2/admin/federation-ids + logMethod("/v2/admin/federation-ids") + federationIds, err := fc.FederationIds() + if err != nil { + fmt.Println("Error calling FEDERATION_IDS: ", err) + return } + logInputAndOutput(nil, federationIds) - depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) + // `/v2/admin/info` + logMethod("/v2/admin/info") + infoData, err := fc.Info() if err != nil { - assert.Equal(t, depositResponse, nil) - assert.Equal(t, depositResponse.OperationId, nil) - assert.Equal(t, depositResponse.Address, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, depositResponse.OperationId, nil) - assert.NotEqual(t, depositResponse.Address, nil) + fmt.Println("Error calling INFO: ", err) + return } + logInputAndOutput(nil, infoData) - awaitDepositRequest := modules.OnchainAwaitDepositRequest{ - OperationId: depositResponse.OperationId, + // `/v2/admin/join` + inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") + if inviteCode == "" { + inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } + logMethod("/v2/admin/join") + joinData, err := fc.Join(inviteCode, true, true, false) + if err != nil { + fmt.Println("Error calling JOIN: ", err) + return + } + logInputAndOutput(nil, joinData) - _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) + // `/v2/admin/list-operations` + logMethod("/v2/admin/list-operations") + listOperationsData, err := fc.ListOperations(10, &fc.ActiveFederationId) if err != nil { - fmt.Println("Error awaiting deposit: ", err) + fmt.Println("Error calling JOIN: ", err) return } + logInputAndOutput(nil, listOperationsData) } -func TestWithdraw(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestNewFedimintClient(t *testing.T) { +// fc := CreateNewFedimintClient() +// assert.NotNil(t, fc) - withdrawRequest := modules.OnchainWithdrawRequest{ - Address: "UNKNOWN", - AmountSat: 10000, - } +// assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") +// assert.Equal(t, fc.Password, "password") +// assert.Equal(t, fc.ActiveFederationId, "federation123") - withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) +// assert.Equal(t, fc, fc.Ln.Client) +// assert.Equal(t, fc, fc.Onchain.Client) +// assert.Equal(t, fc, fc.Mint.Client) +// } - assert.NotEqual(t, withdrawResponse, nil) +// func TestGetActiveFederationId(t *testing.T) { +// fc := CreateNewFedimintClient() - // Intentionally make an error (like - wrong ActiveFederationId/request) - wrong_fed_id := "12112" - _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) - assert.NotEqual(t, err, nil) -} +// fedId := fc.GetActiveFederationId() +// assert.Equal(t, fedId, "federation123") +// } -func TestAwaitWithdraw(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestSetActiveFederationId(t *testing.T) { +// fc := CreateNewFedimintClient() +// new_fedId := "New_federation123" - depositAddressRequest := modules.OnchainDepositAddressRequest{ - Timeout: 3600, - } - depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// fedId_prev := fc.ActiveFederationId +// fc.SetActiveFederationId(new_fedId, false) +// fedId_now := fc.ActiveFederationId +// assert.Equal(t, fedId_now, "New_federation123") +// assert.NotEqual(t, fedId_now, fedId_prev) +// } - awaitDepositRequest := modules.OnchainAwaitDepositRequest{ - OperationId: depositResponse.OperationId, - } +// //////////// +// // Onchain // +// //////////// - awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, awaitDepositResponse, nil) - assert.Equal(t, awaitDepositResponse.Status, nil) - } else { - assert.Equal(t, err, nil) - // println(awaitDepositResponse.Status) - assert.NotEqual(t, awaitDepositResponse.Status, nil) - } +// func TestCreateDepositAddress(t *testing.T) { +// fc := CreateNewFedimintClient() - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// depositAddressRequest := modules.OnchainDepositAddressRequest{ +// Timeout: 3600, +// } + +// depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, depositResponse, nil) +// assert.Equal(t, depositResponse.OperationId, nil) +// assert.Equal(t, depositResponse.Address, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, depositResponse.OperationId, nil) +// assert.NotEqual(t, depositResponse.Address, nil) +// } + +// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ +// OperationId: depositResponse.OperationId, +// } + +// _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// fmt.Println("Error awaiting deposit: ", err) +// return +// } +// } + +// func TestWithdraw(t *testing.T) { +// fc := CreateNewFedimintClient() -////////// -// mint // -////////// +// withdrawRequest := modules.OnchainWithdrawRequest{ +// Address: "UNKNOWN", +// AmountSat: 10000, +// } + +// withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) + +// assert.NotEqual(t, withdrawResponse, nil) -// func TestReissue(t *testing.T) { +// // Intentionally make an error (like - wrong ActiveFederationId/request) +// wrong_fed_id := "12112" +// _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) +// assert.NotEqual(t, err, nil) +// } + +// func TestAwaitWithdraw(t *testing.T) { // fc := CreateNewFedimintClient() -// oobNotesData := modules.OOBNotes { +// depositAddressRequest := modules.OnchainDepositAddressRequest{ +// Timeout: 3600, +// } +// depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) +// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ +// OperationId: depositResponse.OperationId, // } + +// awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, awaitDepositResponse, nil) +// assert.Equal(t, awaitDepositResponse.Status, nil) +// } else { +// assert.Equal(t, err, nil) +// // println(awaitDepositResponse.Status) +// assert.NotEqual(t, awaitDepositResponse.Status, nil) +// } + +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) // } -func TestSpend(t *testing.T) { - fc := CreateNewFedimintClient() +// ////////// +// // mint // +// ////////// - spendRequest := modules.MintSpendRequest{ - AmountMsat: 10000, - AllowOverpay: true, - Timeout: 3600, - } +// // func TestReissue(t *testing.T) { +// // fc := CreateNewFedimintClient() - spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, spendResponse, nil) - assert.Equal(t, spendResponse.OperationId, nil) - assert.Equal(t, spendResponse.Notes, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, spendResponse, nil) - assert.NotEqual(t, spendResponse.OperationId, nil) - assert.NotEqual(t, spendResponse.Notes, nil) - } +// // oobNotesData := modules.OOBNotes { - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // } +// // } -// func TestValidate(t *testing.T) { +// func TestSpend(t *testing.T) { // fc := CreateNewFedimintClient() -// } +// spendRequest := modules.MintSpendRequest{ +// AmountMsat: 10000, +// AllowOverpay: true, +// Timeout: 3600, +// } -//////// -// Ln // -//////// +// spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, spendResponse, nil) +// assert.Equal(t, spendResponse.OperationId, nil) +// assert.Equal(t, spendResponse.Notes, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, spendResponse, nil) +// assert.NotEqual(t, spendResponse.OperationId, nil) +// assert.NotEqual(t, spendResponse.Notes, nil) +// } -func TestCreateInvoice(t *testing.T) { - fc := CreateNewFedimintClient() +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } - expiryTime := 3600 - GatewayID := "test_GatewayID" - invoiceRequest := modules.LnInvoiceRequest{ - AmountMsat: 10000, - Description: "test", - ExpiryTime: &expiryTime, - } +// // func TestValidate(t *testing.T) { +// // fc := CreateNewFedimintClient() - invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, invoiceResponse, nil) - assert.Equal(t, invoiceResponse.OperationId, nil) - assert.Equal(t, invoiceResponse.Invoice, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, invoiceResponse, nil) - assert.NotEqual(t, invoiceResponse.OperationId, nil) - assert.NotEqual(t, invoiceResponse.Invoice, nil) - } +// // } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// //////// +// // Ln // +// //////// -func TestAwaitInvoice(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestCreateInvoice(t *testing.T) { +// fc := CreateNewFedimintClient() - awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ - OperationId: "TestAwaitInvoice", - } +// expiryTime := 3600 +// GatewayID := "test_GatewayID" +// invoiceRequest := modules.LnInvoiceRequest{ +// AmountMsat: 10000, +// Description: "test", +// ExpiryTime: &expiryTime, +// } - infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, infoResponse, nil) - assert.Equal(t, infoResponse.DenominationsMsat, nil) - assert.Equal(t, infoResponse.FederationID, nil) - assert.Equal(t, infoResponse.Meta, nil) - assert.Equal(t, infoResponse.Network, nil) - assert.Equal(t, infoResponse.TotalAmountMsat, nil) - assert.Equal(t, infoResponse.TotalNumNotes, nil) - assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) - } else { - assert.Equal(t, err, nil) - assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) - assert.NotEqual(t, infoResponse, nil) - assert.NotEqual(t, infoResponse.Meta, nil) - assert.NotEqual(t, infoResponse.Network, nil) - assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) - assert.NotEqual(t, infoResponse.TotalNumNotes, nil) - assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) - } +// invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, invoiceResponse, nil) +// assert.Equal(t, invoiceResponse.OperationId, nil) +// assert.Equal(t, invoiceResponse.Invoice, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, invoiceResponse, nil) +// assert.NotEqual(t, invoiceResponse.OperationId, nil) +// assert.NotEqual(t, invoiceResponse.Invoice, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "" - _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } -func TestPay(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestAwaitInvoice(t *testing.T) { +// fc := CreateNewFedimintClient() - LnurlComment := "test_LnurlComment" - GatewayID := "test_GatewayID" - AmountMsat := uint64(10000) - lnPayRequest := modules.LnPayRequest{ - PaymentInfo: "TestPayment", - AmountMsat: &AmountMsat, - LnurlComment: &LnurlComment, - } +// awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ +// OperationId: "TestAwaitInvoice", +// } - lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, lnPayResponse, nil) - assert.Equal(t, lnPayResponse.ContractId, nil) - assert.Equal(t, lnPayResponse.Fee, nil) - assert.Equal(t, lnPayResponse.PaymentType, nil) - assert.Equal(t, lnPayResponse.PperationId, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, lnPayResponse, nil) - assert.NotEqual(t, lnPayResponse.ContractId, nil) - assert.NotEqual(t, lnPayResponse.Fee, nil) - assert.NotEqual(t, lnPayResponse.PaymentType, nil) - assert.NotEqual(t, lnPayResponse.PperationId, nil) - } +// infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, infoResponse, nil) +// assert.Equal(t, infoResponse.DenominationsMsat, nil) +// assert.Equal(t, infoResponse.FederationID, nil) +// assert.Equal(t, infoResponse.Meta, nil) +// assert.Equal(t, infoResponse.Network, nil) +// assert.Equal(t, infoResponse.TotalAmountMsat, nil) +// assert.Equal(t, infoResponse.TotalNumNotes, nil) +// assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) +// assert.NotEqual(t, infoResponse, nil) +// assert.NotEqual(t, infoResponse.Meta, nil) +// assert.NotEqual(t, infoResponse.Network, nil) +// assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) +// assert.NotEqual(t, infoResponse.TotalNumNotes, nil) +// assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "" +// _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } -// func TestAwaitPay(t *testing.T) { +// func TestPay(t *testing.T) { // fc := CreateNewFedimintClient() -// awaitLnPayRequest := modules.AwaitLnPayRequest{ -// OperationId: "TestAwaitLnPay", +// LnurlComment := "test_LnurlComment" +// GatewayID := "test_GatewayID" +// AmountMsat := uint64(10000) +// lnPayRequest := modules.LnPayRequest{ +// PaymentInfo: "TestPayment", +// AmountMsat: &AmountMsat, +// LnurlComment: &LnurlComment, // } -// lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) // if err != nil { // assert.Equal(t, lnPayResponse, nil) -// assert.Equal(t, lnPayResponse.Contract_id, nil) +// assert.Equal(t, lnPayResponse.ContractId, nil) // assert.Equal(t, lnPayResponse.Fee, nil) -// assert.Equal(t, lnPayResponse.Payment_type, nil) -// assert.Equal(t, lnPayResponse.Pperation_id, nil) +// assert.Equal(t, lnPayResponse.PaymentType, nil) +// assert.Equal(t, lnPayResponse.PperationId, nil) // } else { // assert.Equal(t, err, nil) // assert.NotEqual(t, lnPayResponse, nil) -// assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// assert.NotEqual(t, lnPayResponse.ContractId, nil) // assert.NotEqual(t, lnPayResponse.Fee, nil) -// assert.NotEqual(t, lnPayResponse.Payment_type, nil) -// assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// assert.NotEqual(t, lnPayResponse.PaymentType, nil) +// assert.NotEqual(t, lnPayResponse.PperationId, nil) // } // // intentionally giving wrong parameters // wrong_fed_id := "12112" -// _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) // assert.NotEqual(t, err1, nil) // } -func TestListGateways(t *testing.T) { - fc := CreateNewFedimintClient() +// // func TestAwaitPay(t *testing.T) { +// // fc := CreateNewFedimintClient() + +// // awaitLnPayRequest := modules.AwaitLnPayRequest{ +// // OperationId: "TestAwaitLnPay", +// // } + +// // lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) +// // if err != nil { +// // assert.Equal(t, lnPayResponse, nil) +// // assert.Equal(t, lnPayResponse.Contract_id, nil) +// // assert.Equal(t, lnPayResponse.Fee, nil) +// // assert.Equal(t, lnPayResponse.Payment_type, nil) +// // assert.Equal(t, lnPayResponse.Pperation_id, nil) +// // } else { +// // assert.Equal(t, err, nil) +// // assert.NotEqual(t, lnPayResponse, nil) +// // assert.NotEqual(t, lnPayResponse.Contract_id, nil) +// // assert.NotEqual(t, lnPayResponse.Fee, nil) +// // assert.NotEqual(t, lnPayResponse.Payment_type, nil) +// // assert.NotEqual(t, lnPayResponse.Pperation_id, nil) +// // } + +// // // intentionally giving wrong parameters +// // wrong_fed_id := "12112" +// // _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) +// // assert.NotEqual(t, err1, nil) +// // } + +// func TestListGateways(t *testing.T) { +// fc := CreateNewFedimintClient() - gatewaysResponse, err := fc.Ln.ListGateways() - if err != nil { - assert.Equal(t, gatewaysResponse, nil) - } else { - assert.Equal(t, err, nil) - assert.NotEqual(t, gatewaysResponse, nil) - } -} +// gatewaysResponse, err := fc.Ln.ListGateways() +// if err != nil { +// assert.Equal(t, gatewaysResponse, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.NotEqual(t, gatewaysResponse, nil) +// } +// } -func TestSwitchGateway(t *testing.T) { - fc := CreateNewFedimintClient() +// func TestSwitchGateway(t *testing.T) { +// fc := CreateNewFedimintClient() - switchGatewayRequest := modules.SwitchGatewayRequest{ - GatewayId: "TestGateway1", - } +// switchGatewayRequest := modules.SwitchGatewayRequest{ +// GatewayId: "TestGateway1", +// } - gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) - if err != nil { - assert.Equal(t, gatewayResponse, nil) - assert.Equal(t, gatewayResponse.Active, true) - assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) - } else { - assert.Equal(t, err, nil) - assert.Equal(t, gatewayResponse.Active, true) - assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) - } +// gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) +// if err != nil { +// assert.Equal(t, gatewayResponse, nil) +// assert.Equal(t, gatewayResponse.Active, true) +// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) +// } else { +// assert.Equal(t, err, nil) +// assert.Equal(t, gatewayResponse.Active, true) +// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) +// } - // intentionally giving wrong parameters - wrong_fed_id := "12112" - _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) - assert.NotEqual(t, err1, nil) -} +// // intentionally giving wrong parameters +// wrong_fed_id := "12112" +// _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) +// assert.NotEqual(t, err1, nil) +// } From 35fb74bcf5a38a461f07421b3e301512095ff00a Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 01:11:32 +0530 Subject: [PATCH 05/23] fix::> justfile.local.just updated --- justfile.local.just | 3 +++ 1 file changed, 3 insertions(+) diff --git a/justfile.local.just b/justfile.local.just index 178441d..c8320bb 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -16,5 +16,8 @@ test-py-async: test-go: cd wrappers/fedimint-go && go run cmd/main.go +test-go-pps: + cd wrappers/fedimint-go && go run pkg/fedimint/client_test.go + wscat: mprocs -c mprocs-wscat.yaml From b7305caf9994b6ba51f1219652f48a00b453984e Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 11:57:31 +0530 Subject: [PATCH 06/23] fix::> Added test suite for LIGHTNING METHODS updated --- justfile.local.just | 2 +- .../fedimint-go/pkg/fedimint/client_test.go | 83 ++++++++++++++++++- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/justfile.local.just b/justfile.local.just index c8320bb..85e06eb 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -17,7 +17,7 @@ test-go: cd wrappers/fedimint-go && go run cmd/main.go test-go-pps: - cd wrappers/fedimint-go && go run pkg/fedimint/client_test.go + cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index 9fa0ccc..f5224f0 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -24,7 +24,7 @@ func logMethod(method string) { func logInputAndOutput(input interface{}, output interface{}) { fmt.Println("Input: ", input) fmt.Println("Output: ", output) - fmt.Println("--------------------") + fmt.Println("====================") } // BIG ISSUE // @@ -160,16 +160,91 @@ func TestFedimintGo(t *testing.T) { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(nil, joinData) + logInputAndOutput(inviteCode, joinData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") - listOperationsData, err := fc.ListOperations(10, &fc.ActiveFederationId) + listOperationsData, err := fc.ListOperations(10, nil) if err != nil { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(nil, listOperationsData) + logInputAndOutput([]interface{}{10}, listOperationsData) + + /////////////////////// + // LIGHTNING METHODS // + /////////////////////// + + // `/v2/ln/list-gateways` + gatewayList, err := fc.Ln.ListGateways() + if err != nil { + fmt.Println("Error calling LIST_GATEWAYS: ", err) + return + } + logInputAndOutput(nil, gatewayList) + + // `/v2/ln/invoice` + logMethod("/v2/ln/invoice") + invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) + if err != nil { + fmt.Println("Error calling INVOICE: ", err) + return + } + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) + + // `/v2/ln/pay` + logMethod("/v2/ln/pay") + payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + if err != nil { + fmt.Println("Error calling PAY: ", err) + return + } + logInputAndOutput(invoiceData.Invoice, payData) + + // /v2/ln/await-invoice + logMethod("/v2/ln/await-invoice") + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_INVOICE: ", err) + return + } + logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + // `/v1/ln/invoice-external-pubkey-tweaked` + logMethod("/v1/ln/invoice-external-pubkey-tweaked") + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, nil) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + // `/v1/ln/invoice-external-pubkey` + logMethod("/v1/ln/invoice-external-pubkey") + invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) } // func TestNewFedimintClient(t *testing.T) { From f128a23985fafc3c78a97d3ca370901a7ceb762c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 12:46:57 +0530 Subject: [PATCH 07/23] fix::> changed the type of field in DecodeNotesResponse struct and MintSpendResponse --- wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go index 1b6c5a5..a743b6b 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/mint.go @@ -63,7 +63,7 @@ type DecodeNotesRequest struct { } type DecodeNotesResponse struct { - NotesJson string `json:"notesJson"` + NotesJson NotesJson `json:"notesJson"` } type EncodeNotesRequest struct { @@ -89,8 +89,8 @@ type MintSpendRequest struct { } type MintSpendResponse struct { - OperationId string `json:"operationId"` - Notes OOBNotes `json:"notes"` + OperationId string `json:"operationId"` + Notes string `json:"notes"` } type MintValidateRequest struct { From ca915fd1a8692c1da4e7251f6fa17d3eebe1ef22 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 12:48:21 +0530 Subject: [PATCH 08/23] fix::> Added test suite for MINT METHODS --- .../fedimint-go/pkg/fedimint/client_test.go | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index f5224f0..d370b28 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -245,6 +245,80 @@ func TestFedimintGo(t *testing.T) { return } logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) + + ////////////////// + // MINT METHODS // + ////////////////// + + // `/v2/mint/spend` + logMethod("/v2/mint/spend") + mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) + if err != nil { + fmt.Println("Error calling SPEND: ", err) + return + } + logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + // `/v2/mint/decode-notes` + logMethod("/v2/mint/decode-notes") + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(mintData.Notes, decodedData) + + // `/v2/mint/encode-notes` + logMethod("/v2/mint/encode-notes") + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(decodedData.NotesJson, encodedData) + + // `/v2/mint/validate` + logMethod("/v2/mint/validate") + validateData, err := fc.Mint.Validate(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling VALIDATE: ", err) + return + } + logInputAndOutput(mintData.Notes, validateData) + + // `/v2/mint/reissue` + logMethod("/v2/mint/reissue") + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling REISSUE: ", err) + return + } + logInputAndOutput(mintData.Notes, reissueData) + + // `/v2/mint/split` + logMethod("/v2/mint/split") + splitData, err := fc.Mint.Split(mintData.Notes) + if err != nil { + fmt.Println("Error calling SPLIT: ", err) + return + } + logInputAndOutput(mintData.Notes, splitData) + + // `/v2/mint/combine` + logMethod("/v2/mint/combine") + notesVec := func() []string { + result := make([]string, 0, len(splitData.Notes)) + for _, value := range splitData.Notes { + result = append(result, value) + } + return result + }() + combineData, err := fc.Mint.Combine(notesVec) + if err != nil { + fmt.Println("Error calling COMBINE: ", err) + return + } + logInputAndOutput(splitData.Notes, combineData) } // func TestNewFedimintClient(t *testing.T) { From 68dc12b2c8d1447b17b24f48c7b8e1786a441ee9 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Mon, 1 Apr 2024 16:10:02 +0530 Subject: [PATCH 09/23] fix::> Added test suite for ONCHAIN METHODS --- .../fedimint-go/pkg/fedimint/client_test.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go index d370b28..3ced302 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ b/wrappers/fedimint-go/pkg/fedimint/client_test.go @@ -319,6 +319,37 @@ func TestFedimintGo(t *testing.T) { return } logInputAndOutput(splitData.Notes, combineData) + + ///////////////////// + // ONCHAIN METHODS // + ///////////////////// + + // `/v2/onchain/deposit-address` + logMethod("/v2/onchain/deposit-address") + addr, err := fc.Onchain.createDepositAddress(1000, nil) + if err != nil { + fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) + return + } + logInputAndOutput(1000, addr) + + // `/v2/onchain/withdraw` + logMethod("/v2/onchain/withdraw") + withdrawData, err := fc.Onchain.withdraw(addr.Address, 1000, nil) + if err != nil { + fmt.Println("Error calling WITHDRAW: ", err) + return + } + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + + // `/v2/onchain/await-deposit` + logMethod("/v2/onchain/await-deposit") + awaitDepositData, err := fc.Onchain.awaitDeposit(addr.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_DEPOSIT: ", err) + return + } + logInputAndOutput(addr.Address, awaitDepositData) } // func TestNewFedimintClient(t *testing.T) { From ec20a4cdeaab05342284985036442c83d60d2a05 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 2 Apr 2024 23:27:02 +0530 Subject: [PATCH 10/23] minor changes in structure --- wrappers/fedimint-go/pkg/fedimint/client.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 9fc153a..28870bf 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -259,8 +259,8 @@ func (fc *FedimintClient) FederationIds() (types.FederationIdsResponse, error) { return response, nil } -func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret bool) (types.JoinResponse, error) { - request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: useManualSecret} +func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret *bool) (types.JoinResponse, error) { + request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: *useManualSecret} var response types.JoinResponse responseBody, err := fc.post("/admin/join", request) @@ -287,7 +287,7 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us // Onchain // //////////// -func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { +func (onchain *OnchainModule) CreateDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { request := modules.OnchainDepositAddressRequest{Timeout: timeout} resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, federationId) if err != nil { @@ -301,7 +301,7 @@ func (onchain *OnchainModule) createDepositAddress(timeout int, federationId *st return &depositAddressResp, nil } -func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { +func (onchain *OnchainModule) AwaitDeposit(operationId string, federationId *string) (*modules.OnchainAwaitDepositResponse, error) { request := modules.OnchainAwaitDepositRequest{OperationId: operationId} resp, err := onchain.Client.postWithFederationId("/onchain/await-deposit", request, federationId) if err != nil { @@ -315,7 +315,7 @@ func (onchain *OnchainModule) awaitDeposit(operationId string, federationId *str return &depositResp, nil } -func (onchain *OnchainModule) withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { +func (onchain *OnchainModule) Withdraw(address string, amountSat int, federationId *string) (*modules.OnchainWithdrawResponse, error) { request := modules.OnchainWithdrawRequest{Address: address, AmountSat: amountSat} resp, err := onchain.Client.postWithFederationId("/onchain/withdraw", request, federationId) if err != nil { From cb8b6f749018e0bcb3bbeaf05b92f3ace3a1a619 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Tue, 2 Apr 2024 23:28:56 +0530 Subject: [PATCH 11/23] fix::> Transfered all TEST function to main.go and mirrored them with fedimint-ts --- wrappers/fedimint-go/cmd/main.go | 221 ++++++++++++++++++++++++++----- 1 file changed, 191 insertions(+), 30 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 9b927ec..493863e 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -64,95 +64,256 @@ func buildTestClient() *fedimint.FedimintClient { } func main() { - client := buildTestClient() + fc := buildTestClient() keyPair := newKeyPair() - fmt.Println("Generated key pair: ", keyPair) + fmt.Printf("Generated Key Pair: ") + fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) + fmt.Printf(" Public Key: %s\n", keyPair.PublicKey) + + /////////////////// + // ADMIN METHODS // + /////////////////// - // ADMIN METHODS // `/v2/admin/config` logMethod("/v2/admin/config") - data, err := client.Config() + data, err := fc.Config() if err != nil { - fmt.Println("Error calling config: ", err) + fmt.Println("Error calling CONFIG: ", err) return } logInputAndOutput(nil, data) // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = client.DiscoverVersion(1) + data, err = fc.DiscoverVersion(1) // TS-mirror dont use any parameters if err != nil { - fmt.Println("Error calling discoverVersion: ", err) + fmt.Println("Error calling VERSION: ", err) return } - logInputAndOutput(nil, data) + logInputAndOutput(1, data) - // `/v2/admin/federation-ids` + // `/v2/admin/federation-ids logMethod("/v2/admin/federation-ids") - federationIds, err := client.FederationIds() + federationIds, err := fc.FederationIds() if err != nil { - fmt.Println("Error calling federationIds: ", err) + fmt.Println("Error calling FEDERATION_IDS: ", err) return } logInputAndOutput(nil, federationIds) // `/v2/admin/info` logMethod("/v2/admin/info") - infoData, err := client.Info() + infoData, err := fc.Info() if err != nil { - fmt.Println("Error calling info: ", err) + fmt.Println("Error calling INFO: ", err) return } logInputAndOutput(nil, infoData) // `/v2/admin/join` - inviteCode := os.Getenv("FEDIMINT_CLIENTD_INVITE_CODE") + inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") if inviteCode == "" { inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } logMethod("/v2/admin/join") - joinData, err := client.Join(inviteCode, true, true, false) + joinData, err := fc.Join(inviteCode, true, true, nil) if err != nil { - fmt.Println("Error calling join: ", err) + fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(map[string]interface{}{"inviteCode": inviteCode}, joinData) + logInputAndOutput(inviteCode, joinData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") - listOperationsData, err := client.ListOperations(10, nil) + listOperationsData, err := fc.ListOperations(10, nil) if err != nil { - fmt.Println("Error calling listOperations: ", err) + fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(map[string]interface{}{"limit": 10}, listOperationsData) + logInputAndOutput([]interface{}{10}, listOperationsData) + + /////////////////////// + // LIGHTNING METHODS // + /////////////////////// - // LIGHTNING METHODS // `/v2/ln/list-gateways` logMethod("/v2/ln/list-gateways") - listGatewaysData, err := client.Ln.ListGateways() + gatewayList, err := fc.Ln.ListGateways() if err != nil { - fmt.Println("Error calling listGateways: ", err) + fmt.Println("Error calling LIST_GATEWAYS: ", err) return } - logInputAndOutput(nil, listGatewaysData) + logInputAndOutput(nil, gatewayList) // `/v2/ln/invoice` logMethod("/v2/ln/invoice") - invoiceData, err := client.Ln.CreateInvoice(10000, "test", nil, nil, nil) + invoiceData, err := fc.Ln.CreateInvoice(10000, "test", nil, nil, nil) if err != nil { - fmt.Println("Error calling createInvoice: ", err) + fmt.Println("Error calling INVOICE: ", err) return } - logInputAndOutput(map[string]interface{}{"amountMsat": 10000, "description": "test"}, invoiceData) + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) // `/v2/ln/pay` logMethod("/v2/ln/pay") - payData, err := client.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + if err != nil { + fmt.Println("Error calling PAY: ", err) + return + } + logInputAndOutput(invoiceData.Invoice, payData) + + // /v2/ln/await-invoice + logMethod("/v2/ln/await-invoice") + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + if err != nil { + fmt.Println("Error calling AWAIT_INVOICE: ", err) + return + } + logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + // `/v1/ln/invoice-external-pubkey-tweaked` + logMethod("/v1/ln/invoice-external-pubkey-tweaked") + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + if err != nil { + fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + // pay the invoice + _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) + + // `/v1/ln/claim-external-pubkey-tweaked` + logMethod("/v1/ln/claim-external-pubkey-tweaked") + activeFederationID := fc.GetActiveFederationId() + claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, &activeFederationID) + if err != nil { + fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + return + } + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + // // `/v1/ln/invoice-external-pubkey` + // logMethod("/v1/ln/invoice-external-pubkey") + // invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) + // if err != nil { + // fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) + // return + // } + // logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) + + // // `/v1/ln/claim-external-pubkey-tweaked` + // logMethod("/v1/ln/claim-external-pubkey-tweaked") + // claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) + // if err != nil { + // fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) + // return + // } + // logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) + + ////////////////// + // MINT METHODS // + ////////////////// + + // `/v2/mint/spend` + logMethod("/v2/mint/spend") + mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) + if err != nil { + fmt.Println("Error calling SPEND: ", err) + return + } + logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + // `/v2/mint/decode-notes` + logMethod("/v2/mint/decode-notes") + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(mintData.Notes, decodedData) + + // `/v2/mint/encode-notes` + logMethod("/v2/mint/encode-notes") + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + if err != nil { + fmt.Println("Error calling DECODE_NOTES: ", err) + return + } + logInputAndOutput(decodedData.NotesJson, encodedData) + + // `/v2/mint/validate` + logMethod("/v2/mint/validate") + validateData, err := fc.Mint.Validate(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling VALIDATE: ", err) + return + } + logInputAndOutput(mintData.Notes, validateData) + + // `/v2/mint/reissue` + logMethod("/v2/mint/reissue") + reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) + if err != nil { + fmt.Println("Error calling REISSUE: ", err) + return + } + logInputAndOutput(mintData.Notes, reissueData) + + // `/v2/mint/split` + logMethod("/v2/mint/split") + splitData, err := fc.Mint.Split(mintData.Notes) if err != nil { - fmt.Println("Error calling pay: ", err) + fmt.Println("Error calling SPLIT: ", err) return } - logInputAndOutput(map[string]interface{}{"paymentInfo": invoiceData.Invoice}, payData) + logInputAndOutput(mintData.Notes, splitData) + + // `/v2/mint/combine` + logMethod("/v2/mint/combine") + notesVec := func() []string { + result := make([]string, 0, len(splitData.Notes)) + for _, value := range splitData.Notes { + result = append(result, value) + } + return result + }() + combineData, err := fc.Mint.Combine(notesVec) + if err != nil { + fmt.Println("Error calling COMBINE: ", err) + return + } + logInputAndOutput(splitData.Notes, combineData) + + ///////////////////// + // ONCHAIN METHODS // + ///////////////////// + + // `/v2/onchain/deposit-address` + logMethod("/v2/onchain/deposit-address") + addr, err := fc.Onchain.CreateDepositAddress(1000, nil) + if err != nil { + fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) + return + } + logInputAndOutput(1000, addr) + + // `/v2/onchain/withdraw` + logMethod("/v2/onchain/withdraw") + withdrawData, err := fc.Onchain.Withdraw(addr.Address, 1000, nil) + if err != nil { + fmt.Println("Error calling WITHDRAW: ", err) + return + } + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + + // `/v2/onchain/await-deposit` + logMethod("/v2/onchain/await-deposit") + // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) + // if err != nil { + // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) + // return + // } + // logInputAndOutput(addr.Address, awaitDepositData) } From e10e7be25ae8651f809e9908d10d8deb4dd6313c Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Apr 2024 00:01:30 +0530 Subject: [PATCH 12/23] fix::> updated some parameters --- wrappers/fedimint-go/cmd/main.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 493863e..c10fbb8 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -85,7 +85,7 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) // TS-mirror dont use any parameters + data, err = fc.DiscoverVersion(nil) if err != nil { fmt.Println("Error calling VERSION: ", err) return @@ -185,8 +185,7 @@ func main() { // `/v1/ln/claim-external-pubkey-tweaked` logMethod("/v1/ln/claim-external-pubkey-tweaked") - activeFederationID := fc.GetActiveFederationId() - claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, &activeFederationID) + claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, fc.GetActiveFederationId()) if err != nil { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return @@ -226,7 +225,7 @@ func main() { // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") - decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) + decodedData, err := fc.Mint.DecodeNotes(mintData.Notes) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) return @@ -235,7 +234,7 @@ func main() { // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") - encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) + encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson) if err != nil { fmt.Println("Error calling DECODE_NOTES: ", err) return From f0c1eab9d418486d258cf81ffeab97e99c774b34 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Wed, 3 Apr 2024 00:03:21 +0530 Subject: [PATCH 13/23] fix::> Made some changes in parameters of func --- wrappers/fedimint-go/pkg/fedimint/client.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 28870bf..8794b07 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -216,8 +216,8 @@ func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *st return err } -func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { - request := types.DiscoverVersionRequest{Threshold: threshold} +func (fc *FedimintClient) DiscoverVersion(threshold *uint16) (*types.FedimintResponse, error) { + request := types.DiscoverVersionRequest{Threshold: *threshold} resp, err := fc.post("/admin/discover-version", request) if err != nil { return nil, err @@ -333,9 +333,9 @@ func (onchain *OnchainModule) Withdraw(address string, amountSat int, federation // mint // ////////// -func (mint *MintModule) DecodeNotes(notes string, federationId *string) (*modules.DecodeNotesResponse, error) { +func (mint *MintModule) DecodeNotes(notes string) (*modules.DecodeNotesResponse, error) { request := modules.DecodeNotesRequest{Notes: notes} - resp, err := mint.Client.postWithFederationId("/mint/decode-notes", request, federationId) + resp, err := mint.Client.post("/mint/decode-notes", request) if err != nil { return nil, err } @@ -347,13 +347,13 @@ func (mint *MintModule) DecodeNotes(notes string, federationId *string) (*module return &decodeResp, nil } -func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson, federationId *string) (*modules.EncodeNotesResponse, error) { +func (mint *MintModule) EncodeNotes(notesJson modules.NotesJson) (*modules.EncodeNotesResponse, error) { notesJsonStr, err := json.Marshal(notesJson) if err != nil { return nil, err } request := modules.EncodeNotesRequest{NotesJsonStr: string(notesJsonStr)} - resp, err := mint.Client.postWithFederationId("/mint/encode-notes", request, federationId) + resp, err := mint.Client.post("/mint/encode-notes", request) if err != nil { return nil, err } @@ -517,9 +517,9 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) return &infoResp, nil } -func (ln *LnModule) ClaimPubkeyReceiveTweaked(privateKey string, tweaks []uint64, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, federationId string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyTweakedRequest{PrivateKey: privateKey, Tweaks: tweaks} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, federationId) + resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, &federationId) if err != nil { return nil, err } From 7921744a4b33baaa54d772315094e8e7af535299 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sat, 6 Apr 2024 00:19:22 +0530 Subject: [PATCH 14/23] fix::> Mirrored python tests with go tests + updated just.local files --- justfile.local.just | 3 --- wrappers/fedimint-go/cmd/main.go | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/justfile.local.just b/justfile.local.just index 85e06eb..178441d 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -16,8 +16,5 @@ test-py-async: test-go: cd wrappers/fedimint-go && go run cmd/main.go -test-go-pps: - cd wrappers/fedimint-go && go test pkg/fedimint/client_test.go - wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index c10fbb8..92ae7ec 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -182,6 +182,7 @@ func main() { logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) // 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") @@ -305,14 +306,14 @@ func main() { return } logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) + fmt.Println("Done: All methods tested successfully!") // `/v2/onchain/await-deposit` - logMethod("/v2/onchain/await-deposit") + // logMethod("/v2/onchain/await-deposit") // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) // if err != nil { // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) // return // } // logInputAndOutput(addr.Address, awaitDepositData) - } From 83d2127a43e4ab80f54e4d5767359e7a4a9df56e Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sat, 6 Apr 2024 01:20:58 +0530 Subject: [PATCH 15/23] fix::> discover_version now takes threshold as a copulsory input --- wrappers/fedimint-go/cmd/main.go | 2 +- wrappers/fedimint-go/pkg/fedimint/client.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 92ae7ec..b2409a3 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -85,7 +85,7 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(nil) + data, err = fc.DiscoverVersion(1) if err != nil { fmt.Println("Error calling VERSION: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 8794b07..68ab816 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -216,8 +216,8 @@ func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *st return err } -func (fc *FedimintClient) DiscoverVersion(threshold *uint16) (*types.FedimintResponse, error) { - request := types.DiscoverVersionRequest{Threshold: *threshold} +func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { + request := types.DiscoverVersionRequest{Threshold: threshold} resp, err := fc.post("/admin/discover-version", request) if err != nil { return nil, err From ec006eaef36e6b89649470f45980622484c2dbff Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 09:40:52 +0530 Subject: [PATCH 16/23] fix::> Codebase cleanup --- wrappers/fedimint-go/cmd/main.go | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index b2409a3..3e647d3 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -193,24 +193,6 @@ func main() { } logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) - // // `/v1/ln/invoice-external-pubkey` - // logMethod("/v1/ln/invoice-external-pubkey") - // invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) - // if err != nil { - // fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) - // return - // } - // logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) - - // // `/v1/ln/claim-external-pubkey-tweaked` - // logMethod("/v1/ln/claim-external-pubkey-tweaked") - // claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) - // if err != nil { - // fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - // return - // } - // logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) - ////////////////// // MINT METHODS // ////////////////// @@ -307,13 +289,4 @@ func main() { } logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) fmt.Println("Done: All methods tested successfully!") - - // `/v2/onchain/await-deposit` - // logMethod("/v2/onchain/await-deposit") - // awaitDepositData, err := fc.Onchain.AwaitDeposit(addr.OperationId, nil) - // if err != nil { - // fmt.Println("Error calling AWAIT_DEPOSIT: ", err) - // return - // } - // logInputAndOutput(addr.Address, awaitDepositData) } From 31b7267366c56de43e10ea5473d3107b2273e470 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 10:41:25 +0530 Subject: [PATCH 17/23] fix::> discover_version deserialization done + signal SIGSEGV Error treated --- wrappers/fedimint-go/cmd/main.go | 25 ++++++++++++++++----- wrappers/fedimint-go/pkg/fedimint/client.go | 4 ++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 3e647d3..aed4336 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/hex" + "encoding/json" "fedimint-go-client/pkg/fedimint" "fmt" "os" @@ -85,12 +86,25 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) + discoverResponseData, err := fc.DiscoverVersion(1) if err != nil { fmt.Println("Error calling VERSION: ", err) return } - logInputAndOutput(1, data) + + jsonBytes, err := json.Marshal(discoverResponseData) + if err != nil { + fmt.Println("Error marshaling JSON(discover-version):", err) + return + } + var fedimintResponseData interface{} + err = json.Unmarshal(jsonBytes, &fedimintResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(discover-version):", err) + return + } + + logInputAndOutput(1, fedimintResponseData) // `/v2/admin/federation-ids logMethod("/v2/admin/federation-ids") @@ -103,12 +117,13 @@ func main() { // `/v2/admin/info` logMethod("/v2/admin/info") - infoData, err := fc.Info() + infoDataResponse, err := fc.Info() if err != nil { fmt.Println("Error calling INFO: ", err) return } - logInputAndOutput(nil, infoData) + + logInputAndOutput(nil, infoDataResponse) // `/v2/admin/join` inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -116,7 +131,7 @@ func main() { inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" } logMethod("/v2/admin/join") - joinData, err := fc.Join(inviteCode, true, true, nil) + joinData, err := fc.Join(inviteCode, true, true, false) if err != nil { fmt.Println("Error calling JOIN: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 68ab816..fc7d1fb 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -259,8 +259,8 @@ func (fc *FedimintClient) FederationIds() (types.FederationIdsResponse, error) { return response, nil } -func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret *bool) (types.JoinResponse, error) { - request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: *useManualSecret} +func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, useDefaultGateway bool, useManualSecret bool) (types.JoinResponse, error) { + request := types.JoinRequest{InviteCode: inviteCode, UseManualSecret: useManualSecret} var response types.JoinResponse responseBody, err := fc.post("/admin/join", request) From acca3e4da92ba3e0ed21567287245e2d2bada3e4 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Sun, 7 Apr 2024 11:41:04 +0530 Subject: [PATCH 18/23] fix::> added deserialize functionality to all outputs --- wrappers/fedimint-go/cmd/main.go | 274 ++++++++++++++++++++++++++++--- 1 file changed, 255 insertions(+), 19 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index aed4336..bae7419 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -123,7 +123,19 @@ func main() { return } - logInputAndOutput(nil, infoDataResponse) + jsonBytes, err = json.Marshal(infoDataResponse) + if err != nil { + fmt.Println("Error marshaling JSON(discover-version):", err) + return + } + var infoResponseData interface{} + err = json.Unmarshal(jsonBytes, &infoResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(discover-version):", err) + return + } + + logInputAndOutput(nil, infoResponseData) // `/v2/admin/join` inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") @@ -136,7 +148,20 @@ func main() { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput(inviteCode, joinData) + + jsonBytes, err = json.Marshal(joinData) + if err != nil { + fmt.Println("Error marshaling JSON(join):", err) + return + } + var joinResponseData interface{} + err = json.Unmarshal(jsonBytes, &joinResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(join):", err) + return + } + + logInputAndOutput(inviteCode, joinResponseData) // `/v2/admin/list-operations` logMethod("/v2/admin/list-operations") @@ -145,7 +170,20 @@ func main() { fmt.Println("Error calling JOIN: ", err) return } - logInputAndOutput([]interface{}{10}, listOperationsData) + + jsonBytes, err = json.Marshal(listOperationsData) + if err != nil { + fmt.Println("Error marshaling JSON(list-operations):", err) + return + } + var listOperationsResponseData interface{} + err = json.Unmarshal(jsonBytes, &listOperationsResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(list-operations):", err) + return + } + + logInputAndOutput([]interface{}{10}, listOperationsResponseData) /////////////////////// // LIGHTNING METHODS // @@ -158,7 +196,20 @@ func main() { fmt.Println("Error calling LIST_GATEWAYS: ", err) return } - logInputAndOutput(nil, gatewayList) + + jsonBytes, err = json.Marshal(gatewayList) + if err != nil { + fmt.Println("Error marshaling JSON(list-gateways):", err) + return + } + var gatewayListResponseData interface{} + err = json.Unmarshal(jsonBytes, &gatewayListResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(list-gateways):", err) + return + } + + logInputAndOutput(nil, gatewayListResponseData) // `/v2/ln/invoice` logMethod("/v2/ln/invoice") @@ -167,7 +218,20 @@ func main() { fmt.Println("Error calling INVOICE: ", err) return } - logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) + + jsonBytes, err = json.Marshal(invoiceData) + if err != nil { + fmt.Println("Error marshaling JSON(invoice):", err) + return + } + var invoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &invoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(invoice):", err) + return + } + + logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceResponseData) // `/v2/ln/pay` logMethod("/v2/ln/pay") @@ -176,7 +240,20 @@ func main() { fmt.Println("Error calling PAY: ", err) return } - logInputAndOutput(invoiceData.Invoice, payData) + + jsonBytes, err = json.Marshal(payData) + if err != nil { + fmt.Println("Error marshaling JSON(pay):", err) + return + } + var payResponseData interface{} + err = json.Unmarshal(jsonBytes, &payResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(pay):", err) + return + } + + logInputAndOutput(invoiceData.Invoice, payResponseData) // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") @@ -185,7 +262,20 @@ func main() { fmt.Println("Error calling AWAIT_INVOICE: ", err) return } - logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) + + jsonBytes, err = json.Marshal(awaitInvoiceData) + if err != nil { + fmt.Println("Error marshaling JSON(await-invoice):", err) + return + } + var awaitInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &awaitInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(await-invoice):", err) + return + } + + logInputAndOutput(invoiceData.OperationId, awaitInvoiceResponseData) // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked") @@ -194,7 +284,20 @@ func main() { fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) return } - logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) + + jsonBytes, err = json.Marshal(tweakInvoice) + if err != nil { + fmt.Println("Error marshaling JSON(await-invoice):", err) + return + } + var tweakInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &tweakInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(await-invoice):", err) + return + } + + logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData) // pay the invoice _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) fmt.Println("Paid locked invoice!") @@ -206,7 +309,20 @@ func main() { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return } - logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) + + jsonBytes, err = json.Marshal(claimInvoice) + if err != nil { + fmt.Println("Error marshaling JSON(claim-external-pubkey-tweaked):", err) + return + } + var claimInvoiceResponseData interface{} + err = json.Unmarshal(jsonBytes, &claimInvoiceResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(claim-external-pubkey-tweaked):", err) + return + } + + logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoiceResponseData) ////////////////// // MINT METHODS // @@ -219,7 +335,20 @@ func main() { fmt.Println("Error calling SPEND: ", err) return } - logInputAndOutput([]interface{}{3000, true, 1000}, mintData) + + jsonBytes, err = json.Marshal(mintData) + if err != nil { + fmt.Println("Error marshaling JSON(spend):", err) + return + } + var mintResponseData interface{} + err = json.Unmarshal(jsonBytes, &mintResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(spend):", err) + return + } + + logInputAndOutput([]interface{}{3000, true, 1000}, mintResponseData) // `/v2/mint/decode-notes` logMethod("/v2/mint/decode-notes") @@ -228,7 +357,20 @@ func main() { fmt.Println("Error calling DECODE_NOTES: ", err) return } - logInputAndOutput(mintData.Notes, decodedData) + + jsonBytes, err = json.Marshal(decodedData) + if err != nil { + fmt.Println("Error marshaling JSON(decode-notes):", err) + return + } + var decodedResponseData interface{} + err = json.Unmarshal(jsonBytes, &decodedResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(decode-notes):", err) + return + } + + logInputAndOutput(mintData.Notes, decodedResponseData) // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes") @@ -237,7 +379,20 @@ func main() { fmt.Println("Error calling DECODE_NOTES: ", err) return } - logInputAndOutput(decodedData.NotesJson, encodedData) + + jsonBytes, err = json.Marshal(encodedData) + if err != nil { + fmt.Println("Error marshaling JSON(encode-notes):", err) + return + } + var encodedResponseData interface{} + err = json.Unmarshal(jsonBytes, &encodedResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(encode-notes):", err) + return + } + + logInputAndOutput(decodedData.NotesJson, encodedResponseData) // `/v2/mint/validate` logMethod("/v2/mint/validate") @@ -246,7 +401,20 @@ func main() { fmt.Println("Error calling VALIDATE: ", err) return } - logInputAndOutput(mintData.Notes, validateData) + + jsonBytes, err = json.Marshal(validateData) + if err != nil { + fmt.Println("Error marshaling JSON(validate):", err) + return + } + var validateResponseData interface{} + err = json.Unmarshal(jsonBytes, &validateResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(validate):", err) + return + } + + logInputAndOutput(mintData.Notes, validateResponseData) // `/v2/mint/reissue` logMethod("/v2/mint/reissue") @@ -255,7 +423,20 @@ func main() { fmt.Println("Error calling REISSUE: ", err) return } - logInputAndOutput(mintData.Notes, reissueData) + + jsonBytes, err = json.Marshal(reissueData) + if err != nil { + fmt.Println("Error marshaling JSON(reissue):", err) + return + } + var reissueResponseData interface{} + err = json.Unmarshal(jsonBytes, &reissueResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(reissue):", err) + return + } + + logInputAndOutput(mintData.Notes, reissueResponseData) // `/v2/mint/split` logMethod("/v2/mint/split") @@ -264,7 +445,20 @@ func main() { fmt.Println("Error calling SPLIT: ", err) return } - logInputAndOutput(mintData.Notes, splitData) + + jsonBytes, err = json.Marshal(splitData) + if err != nil { + fmt.Println("Error marshaling JSON(split):", err) + return + } + var splitResponseData interface{} + err = json.Unmarshal(jsonBytes, &splitResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(split):", err) + return + } + + logInputAndOutput(mintData.Notes, splitResponseData) // `/v2/mint/combine` logMethod("/v2/mint/combine") @@ -280,7 +474,20 @@ func main() { fmt.Println("Error calling COMBINE: ", err) return } - logInputAndOutput(splitData.Notes, combineData) + + jsonBytes, err = json.Marshal(combineData) + if err != nil { + fmt.Println("Error marshaling JSON(split):", err) + return + } + var combineResponseData interface{} + err = json.Unmarshal(jsonBytes, &combineResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(split):", err) + return + } + + logInputAndOutput(splitData.Notes, combineResponseData) ///////////////////// // ONCHAIN METHODS // @@ -293,7 +500,20 @@ func main() { fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) return } - logInputAndOutput(1000, addr) + + jsonBytes, err = json.Marshal(addr) + if err != nil { + fmt.Println("Error marshaling JSON(deposit-address):", err) + return + } + var addrResponseData interface{} + err = json.Unmarshal(jsonBytes, &addrResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(deposit-address):", err) + return + } + + logInputAndOutput(1000, addrResponseData) // `/v2/onchain/withdraw` logMethod("/v2/onchain/withdraw") @@ -302,6 +522,22 @@ func main() { fmt.Println("Error calling WITHDRAW: ", err) return } - logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) - fmt.Println("Done: All methods tested successfully!") + + jsonBytes, err = json.Marshal(withdrawData) + if err != nil { + fmt.Println("Error marshaling JSON(withdraw):", err) + return + } + var withdrawResponseData interface{} + err = json.Unmarshal(jsonBytes, &withdrawResponseData) + if err != nil { + fmt.Println("Error unmarshaling JSON(withdraw):", err) + return + } + + logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawResponseData) + + fmt.Println("============================================") + fmt.Println("|| Done: All methods tested successfully! ||") + fmt.Println("============================================") } From 1b0974c11c436afd3fc54c2bab0399d7441a8dfd Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Fri, 12 Apr 2024 19:22:45 +0530 Subject: [PATCH 19/23] fix::> Made gatewayId as a compulsory parameter for all Ln methods --- wrappers/fedimint-go/pkg/fedimint/client.go | 34 +++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index fc7d1fb..6d2760b 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -276,10 +276,6 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us if setActiveFederationId { fc.SetActiveFederationId(response.ThisFederationId, useDefaultGateway) } - - if err != nil { - return response, err - } return response, nil } @@ -444,13 +440,13 @@ func (mint *MintModule) Combine(notesVec []string) (*modules.MintCombineResponse // Ln // //////// -func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceRequest{ AmountMsat: amountMsat, Description: description, ExpiryTime: expiryTime, } - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, gatewayId, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -462,7 +458,7 @@ func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, expiryT return &invoiceResp, nil } -func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceExternalPubkeyRequest{ AmountMsat: amountMsat, Description: description, @@ -470,7 +466,7 @@ func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, des ExternalPubkey: pubkey, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey", request, gatewayId, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -482,7 +478,7 @@ func (ln *LnModule) CreateInvoiceForPubkey(pubkey string, amountMsat uint64, des return &invoiceResp, nil } -func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceExternalPubkeyTweakedRequest{ AmountMsat: amountMsat, Description: description, @@ -491,7 +487,7 @@ func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amo Tweak: tweak, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey-tweaked", request, gatewayId, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice-external-pubkey-tweaked", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -503,9 +499,9 @@ func (ln *LnModule) CreateInvoiceForPubkeyTweak(pubkey string, tweak uint64, amo return &invoiceResp, nil } -func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) ClaimPubkeyReceive(privateKey string, gatewayId string, federationId *string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyReceiveRequest{PrivateKey: privateKey} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive", request, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/claim-external-receive", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -517,9 +513,9 @@ func (ln *LnModule) ClaimPubkeyReceive(privateKey string, federationId *string) return &infoResp, nil } -func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, federationId string) (*types.InfoResponse, error) { +func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, gatewayId string, federationId string) (*types.InfoResponse, error) { request := modules.LnClaimPubkeyTweakedRequest{PrivateKey: privateKey, Tweaks: tweaks} - resp, err := ln.Client.postWithFederationId("/ln/claim-external-receive-tweaked", request, &federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/claim-external-receive-tweaked", request, &gatewayId, &federationId) if err != nil { return nil, err } @@ -531,9 +527,9 @@ func (ln *LnModule) ClaimPubkeyTweakReceive(privateKey string, tweaks []uint64, return &infoResp, nil } -func (ln *LnModule) AwaitInvoice(operationId string, federationId *string) (*types.InfoResponse, error) { +func (ln *LnModule) AwaitInvoice(operationId string, gatewayId string, federationId *string) (*types.InfoResponse, error) { request := modules.LnAwaitInvoiceRequest{OperationId: operationId} - resp, err := ln.Client.postWithFederationId("/ln/await-invoice", request, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/await-invoice", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -545,14 +541,14 @@ func (ln *LnModule) AwaitInvoice(operationId string, federationId *string) (*typ return &infoResp, nil } -func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *string, gatewayId *string, federationId *string) (*modules.LnPayResponse, error) { +func (ln *LnModule) Pay(paymentInfo string, gatewayId string, amountMsat *uint64, lnurlComment *string, federationId *string) (*modules.LnPayResponse, error) { request := modules.LnPayRequest{ PaymentInfo: paymentInfo, AmountMsat: amountMsat, LnurlComment: lnurlComment, } fmt.Println("request: ", request) - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/pay", request, gatewayId, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/pay", request, &gatewayId, federationId) if err != nil { return nil, err } @@ -564,7 +560,7 @@ func (ln *LnModule) Pay(paymentInfo string, amountMsat *uint64, lnurlComment *st return &payResp, nil } -func (ln *LnModule) ListGateways() ([]modules.Gateway, error) { +func (ln *LnModule) ListGateways(gatewayId string) ([]modules.Gateway, error) { resp, err := ln.Client.get("/ln/list-gateways") if err != nil { return nil, err From 62a604b9d54692eacfd57a12256474a85634b241 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Fri, 12 Apr 2024 19:37:29 +0530 Subject: [PATCH 20/23] fix::> stash added ad1de49 --- justfile.local.just | 2 +- wrappers/fedimint-go/pkg/fedimint/client.go | 8 +- .../fedimint-go/pkg/fedimint/client_test.go | 673 ------------------ wrappers/fedimint-py/FedimintClient.py | 6 +- 4 files changed, 8 insertions(+), 681 deletions(-) delete mode 100644 wrappers/fedimint-go/pkg/fedimint/client_test.go diff --git a/justfile.local.just b/justfile.local.just index 178441d..72f82a4 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -14,7 +14,7 @@ test-py-async: python3.11 wrappers/fedimint-py/test_async.py test-go: - cd wrappers/fedimint-go && go run cmd/main.go + go run wrappers/fedimint-go/cmd/main.go wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 6d2760b..a0b351e 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -91,7 +91,7 @@ func (fc *FedimintClient) SetActiveGatewayId(gatewayId string) { func (fc *FedimintClient) UseDefaultGateway() error { // hits list_gateways and sets activeGatewayId to the first gateway - gateways, err := fc.Ln.ListGateways() + gateways, err := fc.Ln.ListGateways(nil) if err != nil { return fmt.Errorf("error getting gateways: %w", err) } @@ -440,13 +440,13 @@ func (mint *MintModule) Combine(notesVec []string) (*modules.MintCombineResponse // Ln // //////// -func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, gatewayId string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, gatewayId *string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceRequest{ AmountMsat: amountMsat, Description: description, ExpiryTime: expiryTime, } - resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, &gatewayId, federationId) + resp, err := ln.Client.postWithGatewayIdAndFederationId("/ln/invoice", request, gatewayId, federationId) if err != nil { return nil, err } @@ -560,7 +560,7 @@ func (ln *LnModule) Pay(paymentInfo string, gatewayId string, amountMsat *uint64 return &payResp, nil } -func (ln *LnModule) ListGateways(gatewayId string) ([]modules.Gateway, error) { +func (ln *LnModule) ListGateways(gatewayId *string) ([]modules.Gateway, error) { resp, err := ln.Client.get("/ln/list-gateways") if err != nil { return nil, err diff --git a/wrappers/fedimint-go/pkg/fedimint/client_test.go b/wrappers/fedimint-go/pkg/fedimint/client_test.go deleted file mode 100644 index 3ced302..0000000 --- a/wrappers/fedimint-go/pkg/fedimint/client_test.go +++ /dev/null @@ -1,673 +0,0 @@ -// Client_tests -package fedimint - -import ( - "encoding/hex" - "fmt" - "log" - "os" - "testing" - - "github.com/btcsuite/btcd/btcec/v2" -) - -type KeyPair struct { - PrivateKey string - PublicKey string -} - -func logMethod(method string) { - fmt.Println("--------------------") - fmt.Println("Method:", method) -} - -func logInputAndOutput(input interface{}, output interface{}) { - fmt.Println("Input: ", input) - fmt.Println("Output: ", output) - fmt.Println("====================") -} - -// BIG ISSUE // -// func newKeyPair() KeyPair { -// var privateKey *big.Int -// var err error - -// for { -// privateKey, err = rand.Int(rand.Reader, secp256k1.S256().Params().N) -// if err != nil { -// log.Fatal(err) -// } -// if privateKey.Sign() > 0 && privateKey.Cmp(secp256k1.S256().Params().N) < 0 { -// break -// } -// } - -// // publicKey := secp256k1.PublicKey{} -// // secp256k1.S256().SerializePublicKey(publicKey[:], privateKey.Bytes()) - -// publicKey := secp256k1.PublicKey{} -// publicKey1 := secp256k1.PublicKey{ -// x: new(big.Int), -// y: new(big.Int), -// } -// //(publicKey1.x, publicKey1.y) = secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) -// secp256k1.S256().ScalarBaseMult(privateKey.Bytes()) - -// return KeyPair{ -// PrivateKey: hex.EncodeToString(privateKey.Bytes()), -// PublicKey: hex.EncodeToString(publicKey[:]), -// } -// } - -func newKeyPair() KeyPair { - privKey, err := btcec.NewPrivateKey() - if err != nil { - log.Fatal("Error generating private key:", err) - } - - // Get the corresponding public key - pubKey := privKey.PubKey() - - // Print the private and public keys - fmt.Printf("Private key: %x\n", privKey.Serialize()) - fmt.Printf("Public key: %x\n", pubKey.SerializeCompressed()) - - return KeyPair{ - PrivateKey: hex.EncodeToString(privKey.Serialize()), - PublicKey: hex.EncodeToString(pubKey.SerializeCompressed()), - } -} - -func CreateNewFedimintClient() *FedimintClient { - // Define test data - baseURL := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") - if baseURL == "" { - baseURL = "127.0.0.1:3333" - } - password := os.Getenv("FEDIMINT_CLIENTD_PASSWORD") - if password == "" { - password = "password" - } - activeFederationID := os.Getenv("FEDIMINT_CLIENTD_ACTIVE_FEDERATION_ID") - if activeFederationID == "" { - activeFederationID = "15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" - } - - done := make(chan *FedimintClient) - go func() { - fc := NewFedimintClient(baseURL, password, activeFederationID) - fc.UseDefaultGateway() - done <- fc - }() - return <-done -} - -func TestFedimintGo(t *testing.T) { - fc := CreateNewFedimintClient() - 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 // - /////////////////// - - // `/v2/admin/config` - logMethod("/v2/admin/config") - data, err := fc.Config() - if err != nil { - fmt.Println("Error calling CONFIG: ", err) - return - } - logInputAndOutput(nil, data) - - // `/v2/admin/discover-version` - logMethod("/v2/admin/discover-version") - data, err = fc.DiscoverVersion(1) - if err != nil { - fmt.Println("Error calling VERSION: ", err) - return - } - logInputAndOutput(1, data) - - // `/v2/admin/federation-ids - logMethod("/v2/admin/federation-ids") - federationIds, err := fc.FederationIds() - if err != nil { - fmt.Println("Error calling FEDERATION_IDS: ", err) - return - } - logInputAndOutput(nil, federationIds) - - // `/v2/admin/info` - logMethod("/v2/admin/info") - infoData, err := fc.Info() - if err != nil { - fmt.Println("Error calling INFO: ", err) - return - } - logInputAndOutput(nil, infoData) - - // `/v2/admin/join` - inviteCode := os.Getenv("FEDIMINT_CLIENTD_BASE_URL") - if inviteCode == "" { - inviteCode = "fed11qgqrgvnhwden5te0v9k8q6rp9ekh2arfdeukuet595cr2ttpd3jhq6rzve6zuer9wchxvetyd938gcewvdhk6tcqqysptkuvknc7erjgf4em3zfh90kffqf9srujn6q53d6r056e4apze5cw27h75" - } - logMethod("/v2/admin/join") - joinData, err := fc.Join(inviteCode, true, true, false) - if err != nil { - fmt.Println("Error calling JOIN: ", err) - return - } - logInputAndOutput(inviteCode, joinData) - - // `/v2/admin/list-operations` - logMethod("/v2/admin/list-operations") - listOperationsData, err := fc.ListOperations(10, nil) - if err != nil { - fmt.Println("Error calling JOIN: ", err) - return - } - logInputAndOutput([]interface{}{10}, listOperationsData) - - /////////////////////// - // LIGHTNING METHODS // - /////////////////////// - - // `/v2/ln/list-gateways` - gatewayList, err := fc.Ln.ListGateways() - if err != nil { - fmt.Println("Error calling LIST_GATEWAYS: ", err) - return - } - logInputAndOutput(nil, gatewayList) - - // `/v2/ln/invoice` - logMethod("/v2/ln/invoice") - invoiceData, err := fc.Ln.CreateInvoice(10000, "test_INVOICE", nil, nil, nil) - if err != nil { - fmt.Println("Error calling INVOICE: ", err) - return - } - logInputAndOutput([]interface{}{10000, "test_Invoice"}, invoiceData) - - // `/v2/ln/pay` - logMethod("/v2/ln/pay") - payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) - if err != nil { - fmt.Println("Error calling PAY: ", err) - return - } - logInputAndOutput(invoiceData.Invoice, payData) - - // /v2/ln/await-invoice - logMethod("/v2/ln/await-invoice") - awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) - if err != nil { - fmt.Println("Error calling AWAIT_INVOICE: ", err) - return - } - logInputAndOutput(invoiceData.OperationId, awaitInvoiceData) - - // `/v1/ln/invoice-external-pubkey-tweaked` - logMethod("/v1/ln/invoice-external-pubkey-tweaked") - tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) - if err != nil { - fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoice) - - // `/v1/ln/claim-external-pubkey-tweaked` - logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err := fc.Ln.ClaimPubkeyReceiveTweaked(keyPair.PrivateKey, []uint64{1}, nil) - if err != nil { - fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PrivateKey, []uint64{1}}, claimInvoice) - - // `/v1/ln/invoice-external-pubkey` - logMethod("/v1/ln/invoice-external-pubkey") - invoiceInfo, err := fc.Ln.CreateInvoiceForPubkey(keyPair.PublicKey, 10000, "test", nil, nil, nil) - if err != nil { - fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PublicKey, 10000, "test"}, invoiceInfo) - - // `/v1/ln/claim-external-pubkey-tweaked` - logMethod("/v1/ln/claim-external-pubkey-tweaked") - claimInvoice, err = fc.Ln.ClaimPubkeyReceive(keyPair.PrivateKey, nil) - if err != nil { - fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) - return - } - logInputAndOutput([]interface{}{keyPair.PrivateKey}, claimInvoice) - - ////////////////// - // MINT METHODS // - ////////////////// - - // `/v2/mint/spend` - logMethod("/v2/mint/spend") - mintData, err := fc.Mint.Spend(3000, true, 1000, false, nil) - if err != nil { - fmt.Println("Error calling SPEND: ", err) - return - } - logInputAndOutput([]interface{}{3000, true, 1000}, mintData) - - // `/v2/mint/decode-notes` - logMethod("/v2/mint/decode-notes") - decodedData, err := fc.Mint.DecodeNotes(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling DECODE_NOTES: ", err) - return - } - logInputAndOutput(mintData.Notes, decodedData) - - // `/v2/mint/encode-notes` - logMethod("/v2/mint/encode-notes") - encodedData, err := fc.Mint.EncodeNotes(decodedData.NotesJson, nil) - if err != nil { - fmt.Println("Error calling DECODE_NOTES: ", err) - return - } - logInputAndOutput(decodedData.NotesJson, encodedData) - - // `/v2/mint/validate` - logMethod("/v2/mint/validate") - validateData, err := fc.Mint.Validate(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling VALIDATE: ", err) - return - } - logInputAndOutput(mintData.Notes, validateData) - - // `/v2/mint/reissue` - logMethod("/v2/mint/reissue") - reissueData, err := fc.Mint.Reissue(mintData.Notes, nil) - if err != nil { - fmt.Println("Error calling REISSUE: ", err) - return - } - logInputAndOutput(mintData.Notes, reissueData) - - // `/v2/mint/split` - logMethod("/v2/mint/split") - splitData, err := fc.Mint.Split(mintData.Notes) - if err != nil { - fmt.Println("Error calling SPLIT: ", err) - return - } - logInputAndOutput(mintData.Notes, splitData) - - // `/v2/mint/combine` - logMethod("/v2/mint/combine") - notesVec := func() []string { - result := make([]string, 0, len(splitData.Notes)) - for _, value := range splitData.Notes { - result = append(result, value) - } - return result - }() - combineData, err := fc.Mint.Combine(notesVec) - if err != nil { - fmt.Println("Error calling COMBINE: ", err) - return - } - logInputAndOutput(splitData.Notes, combineData) - - ///////////////////// - // ONCHAIN METHODS // - ///////////////////// - - // `/v2/onchain/deposit-address` - logMethod("/v2/onchain/deposit-address") - addr, err := fc.Onchain.createDepositAddress(1000, nil) - if err != nil { - fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) - return - } - logInputAndOutput(1000, addr) - - // `/v2/onchain/withdraw` - logMethod("/v2/onchain/withdraw") - withdrawData, err := fc.Onchain.withdraw(addr.Address, 1000, nil) - if err != nil { - fmt.Println("Error calling WITHDRAW: ", err) - return - } - logInputAndOutput([]interface{}{addr.Address, 1000}, withdrawData) - - // `/v2/onchain/await-deposit` - logMethod("/v2/onchain/await-deposit") - awaitDepositData, err := fc.Onchain.awaitDeposit(addr.OperationId, nil) - if err != nil { - fmt.Println("Error calling AWAIT_DEPOSIT: ", err) - return - } - logInputAndOutput(addr.Address, awaitDepositData) -} - -// func TestNewFedimintClient(t *testing.T) { -// fc := CreateNewFedimintClient() -// assert.NotNil(t, fc) - -// assert.Equal(t, fc.BaseURL, "http://localhost:3333/fedimint/v2") -// assert.Equal(t, fc.Password, "password") -// assert.Equal(t, fc.ActiveFederationId, "federation123") - -// assert.Equal(t, fc, fc.Ln.Client) -// assert.Equal(t, fc, fc.Onchain.Client) -// assert.Equal(t, fc, fc.Mint.Client) -// } - -// func TestGetActiveFederationId(t *testing.T) { -// fc := CreateNewFedimintClient() - -// fedId := fc.GetActiveFederationId() -// assert.Equal(t, fedId, "federation123") -// } - -// func TestSetActiveFederationId(t *testing.T) { -// fc := CreateNewFedimintClient() -// new_fedId := "New_federation123" - -// fedId_prev := fc.ActiveFederationId -// fc.SetActiveFederationId(new_fedId, false) -// fedId_now := fc.ActiveFederationId -// assert.Equal(t, fedId_now, "New_federation123") -// assert.NotEqual(t, fedId_now, fedId_prev) -// } - -// //////////// -// // Onchain // -// //////////// - -// func TestCreateDepositAddress(t *testing.T) { -// fc := CreateNewFedimintClient() - -// depositAddressRequest := modules.OnchainDepositAddressRequest{ -// Timeout: 3600, -// } - -// depositResponse, err := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, depositResponse, nil) -// assert.Equal(t, depositResponse.OperationId, nil) -// assert.Equal(t, depositResponse.Address, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, depositResponse.OperationId, nil) -// assert.NotEqual(t, depositResponse.Address, nil) -// } - -// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ -// OperationId: depositResponse.OperationId, -// } - -// _, err = fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// fmt.Println("Error awaiting deposit: ", err) -// return -// } -// } - -// func TestWithdraw(t *testing.T) { -// fc := CreateNewFedimintClient() - -// withdrawRequest := modules.OnchainWithdrawRequest{ -// Address: "UNKNOWN", -// AmountSat: 10000, -// } - -// withdrawResponse, _ := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &fc.ActiveFederationId) - -// assert.NotEqual(t, withdrawResponse, nil) - -// // Intentionally make an error (like - wrong ActiveFederationId/request) -// wrong_fed_id := "12112" -// _, err := fc.Onchain.withdraw(withdrawRequest.Address, withdrawRequest.AmountSat, &wrong_fed_id) -// assert.NotEqual(t, err, nil) -// } - -// func TestAwaitWithdraw(t *testing.T) { -// fc := CreateNewFedimintClient() - -// depositAddressRequest := modules.OnchainDepositAddressRequest{ -// Timeout: 3600, -// } -// depositResponse, _ := fc.Onchain.createDepositAddress(depositAddressRequest.Timeout, &fc.ActiveFederationId) - -// awaitDepositRequest := modules.OnchainAwaitDepositRequest{ -// OperationId: depositResponse.OperationId, -// } - -// awaitDepositResponse, err := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, awaitDepositResponse, nil) -// assert.Equal(t, awaitDepositResponse.Status, nil) -// } else { -// assert.Equal(t, err, nil) -// // println(awaitDepositResponse.Status) -// assert.NotEqual(t, awaitDepositResponse.Status, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Onchain.awaitDeposit(awaitDepositRequest.OperationId, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// ////////// -// // mint // -// ////////// - -// // func TestReissue(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // oobNotesData := modules.OOBNotes { - -// // } -// // } - -// func TestSpend(t *testing.T) { -// fc := CreateNewFedimintClient() - -// spendRequest := modules.MintSpendRequest{ -// AmountMsat: 10000, -// AllowOverpay: true, -// Timeout: 3600, -// } - -// spendResponse, err := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, spendResponse, nil) -// assert.Equal(t, spendResponse.OperationId, nil) -// assert.Equal(t, spendResponse.Notes, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, spendResponse, nil) -// assert.NotEqual(t, spendResponse.OperationId, nil) -// assert.NotEqual(t, spendResponse.Notes, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Mint.Spend(spendRequest.AmountMsat, spendRequest.AllowOverpay, spendRequest.Timeout, true, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// // func TestValidate(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // } - -// //////// -// // Ln // -// //////// - -// func TestCreateInvoice(t *testing.T) { -// fc := CreateNewFedimintClient() - -// expiryTime := 3600 -// GatewayID := "test_GatewayID" -// invoiceRequest := modules.LnInvoiceRequest{ -// AmountMsat: 10000, -// Description: "test", -// ExpiryTime: &expiryTime, -// } - -// invoiceResponse, err := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, invoiceResponse, nil) -// assert.Equal(t, invoiceResponse.OperationId, nil) -// assert.Equal(t, invoiceResponse.Invoice, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, invoiceResponse, nil) -// assert.NotEqual(t, invoiceResponse.OperationId, nil) -// assert.NotEqual(t, invoiceResponse.Invoice, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.CreateInvoice(invoiceRequest.AmountMsat, invoiceRequest.Description, invoiceRequest.ExpiryTime, &GatewayID, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// func TestAwaitInvoice(t *testing.T) { -// fc := CreateNewFedimintClient() - -// awaitInvoiceRequest := modules.LnAwaitInvoiceRequest{ -// OperationId: "TestAwaitInvoice", -// } - -// infoResponse, err := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, infoResponse, nil) -// assert.Equal(t, infoResponse.DenominationsMsat, nil) -// assert.Equal(t, infoResponse.FederationID, nil) -// assert.Equal(t, infoResponse.Meta, nil) -// assert.Equal(t, infoResponse.Network, nil) -// assert.Equal(t, infoResponse.TotalAmountMsat, nil) -// assert.Equal(t, infoResponse.TotalNumNotes, nil) -// assert.Equal(t, infoResponse.DenominationsMsat.Tiered, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.Equal(t, infoResponse.FederationID, fc.ActiveFederationId) -// assert.NotEqual(t, infoResponse, nil) -// assert.NotEqual(t, infoResponse.Meta, nil) -// assert.NotEqual(t, infoResponse.Network, nil) -// assert.NotEqual(t, infoResponse.TotalAmountMsat, nil) -// assert.NotEqual(t, infoResponse.TotalNumNotes, nil) -// assert.NotEqual(t, infoResponse.DenominationsMsat.Tiered, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "" -// _, err1 := fc.Ln.AwaitInvoice(awaitInvoiceRequest.OperationId, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// func TestPay(t *testing.T) { -// fc := CreateNewFedimintClient() - -// LnurlComment := "test_LnurlComment" -// GatewayID := "test_GatewayID" -// AmountMsat := uint64(10000) -// lnPayRequest := modules.LnPayRequest{ -// PaymentInfo: "TestPayment", -// AmountMsat: &AmountMsat, -// LnurlComment: &LnurlComment, -// } - -// lnPayResponse, err := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, lnPayResponse, nil) -// assert.Equal(t, lnPayResponse.ContractId, nil) -// assert.Equal(t, lnPayResponse.Fee, nil) -// assert.Equal(t, lnPayResponse.PaymentType, nil) -// assert.Equal(t, lnPayResponse.PperationId, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, lnPayResponse, nil) -// assert.NotEqual(t, lnPayResponse.ContractId, nil) -// assert.NotEqual(t, lnPayResponse.Fee, nil) -// assert.NotEqual(t, lnPayResponse.PaymentType, nil) -// assert.NotEqual(t, lnPayResponse.PperationId, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.Pay(lnPayRequest.PaymentInfo, lnPayRequest.AmountMsat, lnPayRequest.LnurlComment, &GatewayID, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } - -// // func TestAwaitPay(t *testing.T) { -// // fc := CreateNewFedimintClient() - -// // awaitLnPayRequest := modules.AwaitLnPayRequest{ -// // OperationId: "TestAwaitLnPay", -// // } - -// // lnPayResponse, err := fc.Ln.AwaitPay(awaitLnPayRequest, &fc.ActiveFederationId) -// // if err != nil { -// // assert.Equal(t, lnPayResponse, nil) -// // assert.Equal(t, lnPayResponse.Contract_id, nil) -// // assert.Equal(t, lnPayResponse.Fee, nil) -// // assert.Equal(t, lnPayResponse.Payment_type, nil) -// // assert.Equal(t, lnPayResponse.Pperation_id, nil) -// // } else { -// // assert.Equal(t, err, nil) -// // assert.NotEqual(t, lnPayResponse, nil) -// // assert.NotEqual(t, lnPayResponse.Contract_id, nil) -// // assert.NotEqual(t, lnPayResponse.Fee, nil) -// // assert.NotEqual(t, lnPayResponse.Payment_type, nil) -// // assert.NotEqual(t, lnPayResponse.Pperation_id, nil) -// // } - -// // // intentionally giving wrong parameters -// // wrong_fed_id := "12112" -// // _, err1 := fc.Ln.AwaitPay(awaitLnPayRequest, &wrong_fed_id) -// // assert.NotEqual(t, err1, nil) -// // } - -// func TestListGateways(t *testing.T) { -// fc := CreateNewFedimintClient() - -// gatewaysResponse, err := fc.Ln.ListGateways() -// if err != nil { -// assert.Equal(t, gatewaysResponse, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.NotEqual(t, gatewaysResponse, nil) -// } -// } - -// func TestSwitchGateway(t *testing.T) { -// fc := CreateNewFedimintClient() - -// switchGatewayRequest := modules.SwitchGatewayRequest{ -// GatewayId: "TestGateway1", -// } - -// gatewayResponse, err := fc.Ln.SwitchGateway(switchGatewayRequest, &fc.ActiveFederationId) -// if err != nil { -// assert.Equal(t, gatewayResponse, nil) -// assert.Equal(t, gatewayResponse.Active, true) -// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) -// } else { -// assert.Equal(t, err, nil) -// assert.Equal(t, gatewayResponse.Active, true) -// assert.NotEqual(t, gatewayResponse.Node_pub_key, nil) -// } - -// // intentionally giving wrong parameters -// wrong_fed_id := "12112" -// _, err1 := fc.Ln.SwitchGateway(switchGatewayRequest, &wrong_fed_id) -// assert.NotEqual(t, err1, nil) -// } diff --git a/wrappers/fedimint-py/FedimintClient.py b/wrappers/fedimint-py/FedimintClient.py index ecd5810..338ff66 100644 --- a/wrappers/fedimint-py/FedimintClient.py +++ b/wrappers/fedimint-py/FedimintClient.py @@ -69,7 +69,7 @@ def __init__( def get_active_federation_id(self): return self.active_federation_id - +# *** def set_active_federation_id(self, federation_id: str): self.active_federation_id = federation_id @@ -161,10 +161,10 @@ def discover_version(self, threshold: int) -> DiscoverVersionResponse: def federation_ids(self): return self._get("/admin/federation-ids") - +# *** def list_operations(self, request: ListOperationsRequest): return self._post_with_federation_id("/admin/list-operations", request) - +# *** def join(self, invite_code: str, use_manual_secret: bool = False): return self._post( "/admin/join", From a582f267bff578e1ee823daf3fcc9da40a7bc406 Mon Sep 17 00:00:00 2001 From: Abhinav Prakash Date: Fri, 12 Apr 2024 19:50:57 +0530 Subject: [PATCH 21/23] fix::> Updated Ln test suite to accept ActiveGatewayIds --- wrappers/fedimint-go/cmd/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index bae7419..15a7381 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -191,7 +191,7 @@ func main() { // `/v2/ln/list-gateways` logMethod("/v2/ln/list-gateways") - gatewayList, err := fc.Ln.ListGateways() + gatewayList, err := fc.Ln.ListGateways(nil) if err != nil { fmt.Println("Error calling LIST_GATEWAYS: ", err) return @@ -235,7 +235,7 @@ func main() { // `/v2/ln/pay` logMethod("/v2/ln/pay") - payData, err := fc.Ln.Pay(invoiceData.Invoice, nil, nil, nil, nil) + payData, err := fc.Ln.Pay(invoiceData.Invoice, fc.GetActiveGatewayId(), nil, nil, nil) if err != nil { fmt.Println("Error calling PAY: ", err) return @@ -257,7 +257,7 @@ func main() { // /v2/ln/await-invoice logMethod("/v2/ln/await-invoice") - awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, nil) + awaitInvoiceData, err := fc.Ln.AwaitInvoice(invoiceData.OperationId, fc.GetActiveGatewayId(), nil) if err != nil { fmt.Println("Error calling AWAIT_INVOICE: ", err) return @@ -279,7 +279,7 @@ func main() { // `/v1/ln/invoice-external-pubkey-tweaked` logMethod("/v1/ln/invoice-external-pubkey-tweaked") - tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", nil, nil, nil) + tweakInvoice, err := fc.Ln.CreateInvoiceForPubkeyTweak(keyPair.PublicKey, 1, 10000, "test", fc.GetActiveGatewayId(), nil, nil) if err != nil { fmt.Println("Error calling CREATE_INVOICE_FOR_PUBKEY_TWEAK: ", err) return @@ -299,12 +299,12 @@ func main() { logInputAndOutput([]interface{}{keyPair.PublicKey, 1, 10000, "test"}, tweakInvoiceResponseData) // pay the invoice - _, _ = fc.Ln.Pay(tweakInvoice.Invoice, nil, nil, nil, nil) + _, _ = fc.Ln.Pay(tweakInvoice.Invoice, fc.GetActiveGatewayId(), 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}, fc.GetActiveFederationId()) + claimInvoice, err := fc.Ln.ClaimPubkeyTweakReceive(keyPair.PrivateKey, []uint64{1}, fc.GetActiveFederationId(), fc.GetActiveFederationId()) if err != nil { fmt.Println("Error calling CLAIM_PUBKEY_RECEIVE_TWEAKED: ", err) return From aadadd23fd0b72e9fcb34b18e92763fa8b0a9397 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Sat, 13 Apr 2024 10:46:26 -0700 Subject: [PATCH 22/23] fix: all go working --- .gitignore | 2 +- fedimint-clientd/src/main.rs | 4 +- justfile.local.just | 2 +- wrappers/fedimint-go/cmd/main.go | 1 + wrappers/fedimint-go/pkg/fedimint/client.go | 113 +++++++++++------- .../pkg/fedimint/types/modules/ln.go | 34 +++--- wrappers/fedimint-py/AsyncFedimintClient.py | 6 +- wrappers/fedimint-py/FedimintClient.py | 15 ++- wrappers/fedimint-ts/FedimintClient.ts | 8 +- 9 files changed, 109 insertions(+), 76 deletions(-) diff --git a/.gitignore b/.gitignore index 4f7664f..24ef0f2 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ fm_client_db .cargo .vscode .DS_Store -fm_db \ No newline at end of file +fm_db diff --git a/fedimint-clientd/src/main.rs b/fedimint-clientd/src/main.rs index 73d37c0..024c4b3 100644 --- a/fedimint-clientd/src/main.rs +++ b/fedimint-clientd/src/main.rs @@ -254,7 +254,7 @@ fn fedimint_v2_rest() -> Router { post(fedimint::ln::list_gateways::handle_rest), ); - let wallet_router = Router::new() + let onchain_router = Router::new() .route( "/deposit-address", post(fedimint::onchain::deposit_address::handle_rest), @@ -291,7 +291,7 @@ fn fedimint_v2_rest() -> Router { .nest("/admin", admin_router) .nest("/mint", mint_router) .nest("/ln", ln_router) - .nest("/wallet", wallet_router) + .nest("/onchain", onchain_router) } /// Implements Cashu V1 API Routes: diff --git a/justfile.local.just b/justfile.local.just index 72f82a4..178441d 100644 --- a/justfile.local.just +++ b/justfile.local.just @@ -14,7 +14,7 @@ test-py-async: python3.11 wrappers/fedimint-py/test_async.py test-go: - go run wrappers/fedimint-go/cmd/main.go + cd wrappers/fedimint-go && go run cmd/main.go wscat: mprocs -c mprocs-wscat.yaml diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 15a7381..be05dac 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -66,6 +66,7 @@ func buildTestClient() *fedimint.FedimintClient { func main() { fc := buildTestClient() + fc.UseDefaultGateway() keyPair := newKeyPair() fmt.Printf("Generated Key Pair: ") fmt.Printf(" Private Key: %s\n", keyPair.PrivateKey) diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index a0b351e..d2a6b82 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -107,82 +107,110 @@ func (fc *FedimintClient) get(endpoint string) ([]byte, error) { return fc.fetchWithAuth(endpoint, "GET", nil) } +// Post performs a POST request with JSON body, handling JSON marshalling within. func (fc *FedimintClient) post(endpoint string, body interface{}) ([]byte, error) { jsonBody, err := json.Marshal(body) if err != nil { - return nil, err + return nil, fmt.Errorf("error marshaling request body: %w", err) } - fmt.Println("jsonBody: ", string(jsonBody)) + + fmt.Printf("jsonBody: %s\n", jsonBody) + // Assuming fetchWithAuth is correctly implemented. return fc.fetchWithAuth(endpoint, "POST", jsonBody) } -func (fc *FedimintClient) postWithFederationId(endpoint string, body interface{}, federationId *string) ([]byte, error) { - // Marshal the original body to JSON - originalBodyJSON, err := json.Marshal(body) - if err != nil { - return nil, err - } +// postWithFederationId takes any request object, marshals it to JSON, optionally adds a federationId, and makes a POST request. +func (fc *FedimintClient) postWithFederationId(endpoint string, requestBody interface{}, federationId *string) ([]byte, error) { + // Initialize an empty map for the request body. + requestMap := make(map[string]interface{}) - // Unmarshal the JSON into a map to add federationId - var bodyMap map[string]interface{} - err = json.Unmarshal(originalBodyJSON, &bodyMap) - if err != nil { - return nil, err + // If the requestBody is not nil and not empty, marshal and unmarshal it into the map. + if requestBody != nil { + requestJSON, err := json.Marshal(requestBody) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body: %w", err) + } + + // Unmarshal the JSON into the map only if it's not empty to avoid overwriting the initialized map. + if string(requestJSON) != "{}" { + err = json.Unmarshal(requestJSON, &requestMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal request JSON into map: %w", err) + } + } } - // Add federationId to the map + // Determine the effective federationId to use effectiveFederationId := fc.ActiveFederationId + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) if federationId != nil { effectiveFederationId = *federationId } - bodyMap["federationId"] = effectiveFederationId + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + + // Add federationId to the map, which is now guaranteed to be initialized. + requestMap["federationId"] = effectiveFederationId - // Marshal the modified map back to JSON - modifiedBodyJSON, err := json.Marshal(bodyMap) + // Marshal the request map back to JSON to use as the request body. + modifiedRequestJSON, err := json.Marshal(requestMap) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to marshal modified request map: %w", err) } - // Use the modified JSON as the body for the POST request - return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) + fmt.Printf("modifiedRequestJSON: %s\n", modifiedRequestJSON) + + // Proceed to make the POST request with the modified JSON body. + return fc.fetchWithAuth(endpoint, "POST", modifiedRequestJSON) } -func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, body interface{}, gatewayId *string, federationId *string) ([]byte, error) { - // Marshal the original body to JSON - originalBodyJSON, err := json.Marshal(body) - if err != nil { - return nil, err - } +func (fc *FedimintClient) postWithGatewayIdAndFederationId(endpoint string, requestBody interface{}, gatewayId *string, federationId *string) ([]byte, error) { + // Initialize an empty map for the request body. + requestMap := make(map[string]interface{}) - // Unmarshal the JSON into a map to add federationId - var bodyMap map[string]interface{} - err = json.Unmarshal(originalBodyJSON, &bodyMap) - if err != nil { - return nil, err + // If the requestBody is not nil and not empty, marshal and unmarshal it into the map. + if requestBody != nil { + requestJSON, err := json.Marshal(requestBody) + if err != nil { + return nil, fmt.Errorf("failed to marshal request body: %w", err) + } + + // Unmarshal the JSON into the map only if it's not empty to avoid overwriting the initialized map. + if string(requestJSON) != "{}" { + err = json.Unmarshal(requestJSON, &requestMap) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal request JSON into map: %w", err) + } + } } - // Add federationId to the map + // Determine the effective federationId to use effectiveFederationId := fc.ActiveFederationId if federationId != nil { effectiveFederationId = *federationId } - bodyMap["federationId"] = effectiveFederationId + fmt.Printf("effectiveFederationId: %s\n", effectiveFederationId) + requestMap["federationId"] = effectiveFederationId - // Add gatewayId to the map + // Determine the effective gatewayId to use effectiveGatewayId := fc.ActiveGatewayId if gatewayId != nil { effectiveGatewayId = *gatewayId } - bodyMap["gatewayId"] = effectiveGatewayId + fmt.Printf("effectiveGatewayId: %s\n", effectiveGatewayId) - // Marshal the modified map back to JSON - modifiedBodyJSON, err := json.Marshal(bodyMap) + // Add gatewayId to the map, which is now guaranteed to be initialized. + requestMap["gatewayId"] = effectiveGatewayId + + // Marshal the request map back to JSON to use as the request body. + modifiedRequestJSON, err := json.Marshal(requestMap) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to marshal modified request map: %w", err) } - // Use the modified JSON as the body for the POST request - return fc.fetchWithAuth(endpoint, "POST", modifiedBodyJSON) + fmt.Printf("modifiedRequestJSON: %s\n", modifiedRequestJSON) + + // Proceed to make the POST request with the modified JSON body. + return fc.fetchWithAuth(endpoint, "POST", modifiedRequestJSON) } func (fc *FedimintClient) Info() (*types.InfoResponse, error) { @@ -440,7 +468,7 @@ func (mint *MintModule) Combine(notesVec []string) (*modules.MintCombineResponse // Ln // //////// -func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, gatewayId *string, expiryTime *int, federationId *string) (*modules.LnInvoiceResponse, error) { +func (ln *LnModule) CreateInvoice(amountMsat uint64, description string, expiryTime *int, gatewayId *string, federationId *string) (*modules.LnInvoiceResponse, error) { request := modules.LnInvoiceRequest{ AmountMsat: amountMsat, Description: description, @@ -552,6 +580,9 @@ func (ln *LnModule) Pay(paymentInfo string, gatewayId string, amountMsat *uint64 if err != nil { return nil, err } + + fmt.Printf("Raw response body: %s\n", string(resp)) + var payResp modules.LnPayResponse err = json.Unmarshal(resp, &payResp) if err != nil { diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go index 2f1466c..1ecebda 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/ln.go @@ -45,11 +45,16 @@ type LnPayRequest struct { LnurlComment *string `json:"lnurlComment"` } +type PaymentTypeInfo struct { + Internal *string `json:"internal,omitempty"` + Lightning *string `json:"lightning,omitempty"` +} + type LnPayResponse struct { - PperationId string `json:"operationId"` - PaymentType string `json:"paymentType"` - ContractId string `json:"contractId"` - Fee int `json:"fee"` + OperationId string `json:"operationId"` + PaymentType PaymentTypeInfo `json:"paymentType"` + ContractId string `json:"contractId"` + Fee int `json:"fee"` } type AwaitLnPayRequest struct { @@ -59,13 +64,13 @@ type AwaitLnPayRequest struct { type GatewayInfo struct { API string `json:"api"` Fees GatewayFees `json:"fees"` - GatewayID string `json:"gatewayId"` - GatewayRedeemKey string `json:"gatewayRedeemKey"` - LightningAlias string `json:"lightningAlias"` - MintChannelID int `json:"mintChannelId"` - NodePubKey string `json:"nodePubKey"` - RouteHints []interface{} `json:"routeHints"` // Adjust the type according to the actual structure of route hints - SupportsPrivatePayments bool `json:"supportsPrivatePayments"` + GatewayID string `json:"gateway_id"` + GatewayRedeemKey string `json:"gateway_redeem_key"` + LightningAlias string `json:"lightning_alias"` + MintChannelID int `json:"mint_channel_id"` + NodePubKey string `json:"node_pub_key"` + RouteHints []interface{} `json:"route_hints"` // Consider defining a more specific type if possible + SupportsPrivatePayments bool `json:"supports_private_payments"` } type GatewayFees struct { @@ -79,15 +84,10 @@ type GatewayTTL struct { } type Gateway struct { - FederationID string `json:"federationId"` + FederationID string `json:"federation_id"` Info GatewayInfo `json:"info"` TTL GatewayTTL `json:"ttl"` Vetted bool `json:"vetted"` } -// string::> FederationId type ListGatewaysResponse map[string][]Gateway - -type SwitchGatewayRequest struct { - GatewayId string `json:"gatewayId"` -} diff --git a/wrappers/fedimint-py/AsyncFedimintClient.py b/wrappers/fedimint-py/AsyncFedimintClient.py index 95a26a8..bd08e22 100644 --- a/wrappers/fedimint-py/AsyncFedimintClient.py +++ b/wrappers/fedimint-py/AsyncFedimintClient.py @@ -380,7 +380,7 @@ def __init__(self, client): async def create_deposit_address(self, timeout: int, federation_id: str = None): request: OnchainDepositAddressRequest = {"timeout": timeout} return await self.client._post_with_federation_id( - "/wallet/deposit-address", request, federation_id + "/onchain/deposit-address", request, federation_id ) async def await_deposit( @@ -388,7 +388,7 @@ async def await_deposit( ) -> OnchainAwaitDepositResponse: request: OnchainAwaitDepositRequest = {"operationId": operation_id} return await self.client._post_with_federation_id( - "/wallet/await-deposit", request, federation_id + "/onchain/await-deposit", request, federation_id ) async def withdraw( @@ -402,5 +402,5 @@ async def withdraw( "amountSat": amount_sat, } return await self.client._post_with_federation_id( - "/wallet/withdraw", request, federationId + "/onchain/withdraw", request, federationId ) diff --git a/wrappers/fedimint-py/FedimintClient.py b/wrappers/fedimint-py/FedimintClient.py index 338ff66..07b4c57 100644 --- a/wrappers/fedimint-py/FedimintClient.py +++ b/wrappers/fedimint-py/FedimintClient.py @@ -69,7 +69,8 @@ def __init__( def get_active_federation_id(self): return self.active_federation_id -# *** + + # *** def set_active_federation_id(self, federation_id: str): self.active_federation_id = federation_id @@ -161,10 +162,12 @@ def discover_version(self, threshold: int) -> DiscoverVersionResponse: def federation_ids(self): return self._get("/admin/federation-ids") -# *** + + # *** def list_operations(self, request: ListOperationsRequest): return self._post_with_federation_id("/admin/list-operations", request) -# *** + + # *** def join(self, invite_code: str, use_manual_secret: bool = False): return self._post( "/admin/join", @@ -342,7 +345,7 @@ def __init__(self, client): def create_deposit_address(self, timeout: int, federation_id: str = None): request: OnchainDepositAddressRequest = {"timeout": timeout} return self.client._post_with_federation_id( - "/wallet/deposit-address", request, federation_id + "/onchain/deposit-address", request, federation_id ) def await_deposit( @@ -350,7 +353,7 @@ def await_deposit( ) -> OnchainAwaitDepositResponse: request: OnchainAwaitDepositRequest = {"operationId": operation_id} return self.client._post_with_federation_id( - "/wallet/await-deposit", request, federation_id + "/onchain/await-deposit", request, federation_id ) def withdraw( @@ -364,5 +367,5 @@ def withdraw( "amountSat": amount_sat, } return self.client._post_with_federation_id( - "/wallet/withdraw", request, federation_id + "/onchain/withdraw", request, federation_id ) diff --git a/wrappers/fedimint-ts/FedimintClient.ts b/wrappers/fedimint-ts/FedimintClient.ts index da35cd3..fda8926 100644 --- a/wrappers/fedimint-ts/FedimintClient.ts +++ b/wrappers/fedimint-ts/FedimintClient.ts @@ -289,7 +289,6 @@ class FedimintClient { gatewayId: effectiveGatewayId, }); } catch (error) { - console.error("Error posting with federation and gateway id: ", error); throw error; } } @@ -559,7 +558,6 @@ class FedimintClient { const request: MintEncodeNotesRequest = { notesJsonStr: JSON.stringify(notesJson), }; - console.log("request: ", request); return await this.post( "/mint/encode-notes", @@ -677,7 +675,7 @@ class FedimintClient { const request: OnchainDepositAddressRequest = { timeout }; return await this.postWithFederationId( - "/wallet/deposit-address", + "/onchain/deposit-address", request, federationId ); @@ -696,7 +694,7 @@ class FedimintClient { const request: OnchainAwaitDepositRequest = { operationId }; return await this.postWithFederationId( - "/wallet/await-deposit", + "/onchain/await-deposit", request, federationId ); @@ -720,7 +718,7 @@ class FedimintClient { const request: OnchainWithdrawRequest = { address, amountSat }; return await this.postWithFederationId( - "/wallet/withdraw", + "/onchain/withdraw", request, federationId ); From 44f7cac09f2b89df6c299de36e7291acf16f37b3 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Sat, 13 Apr 2024 11:17:48 -0700 Subject: [PATCH 23/23] fix: fix --- flake.lock | 128 ++------------- misc/git-hooks/pre-commit | 173 ++++++++++---------- wrappers/fedimint-go/cmd/main.go | 38 ++--- wrappers/fedimint-go/pkg/fedimint/client.go | 4 +- 4 files changed, 122 insertions(+), 221 deletions(-) diff --git a/flake.lock b/flake.lock index a2ec040..112303e 100644 --- a/flake.lock +++ b/flake.lock @@ -69,104 +69,6 @@ "type": "github" } }, -<<<<<<< HEAD -||||||| parent of cdebb0d (fix::> Added support func to tests and Updated CreateNewFedimintClient()) - "devshell_2": { - "inputs": { - "nixpkgs": [ - "flakebox", - "android-nixpkgs", - "nixpkgs" - ], - "systems": "systems_6" - }, - "locked": { - "lastModified": 1695195896, - "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", - "owner": "numtide", - "repo": "devshell", - "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "fedimint": { - "inputs": { - "advisory-db": "advisory-db", - "bundlers": "bundlers", - "fenix": "fenix", - "flake-utils": "flake-utils_2", - "flakebox": "flakebox", - "nixpkgs": "nixpkgs_4" - }, - "locked": { - "lastModified": 1710534977, - "narHash": "sha256-RWzV+/NZkV87JnydefwRMwJ9tDkwDCg6m3pCxsVlKeY=", - "owner": "fedimint", - "repo": "fedimint", - "rev": "9d552fdf82f4af429165a1fd409615809ada4058", - "type": "github" - }, - "original": { - "owner": "fedimint", - "repo": "fedimint", - "rev": "9d552fdf82f4af429165a1fd409615809ada4058", - "type": "github" - } - }, -======= - "devshell_2": { - "inputs": { - "nixpkgs": [ - "flakebox", - "android-nixpkgs", - "nixpkgs" - ], - "systems": "systems_6" - }, - "locked": { - "lastModified": 1695195896, - "narHash": "sha256-pq9q7YsGXnQzJFkR5284TmxrLNFc0wo4NQ/a5E93CQU=", - "owner": "numtide", - "repo": "devshell", - "rev": "05d40d17bf3459606316e3e9ec683b784ff28f16", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "devshell", - "type": "github" - } - }, - "fedimint": { - "inputs": { - "advisory-db": "advisory-db", - "bundlers": "bundlers", - "fenix": "fenix", - "flake-utils": "flake-utils_2", - "flakebox": "flakebox", - "nixpkgs": "nixpkgs_4" - }, - "locked": { - "lastModified": 1711405975, - "narHash": "sha256-I8uUhpqN5oGDkT+sN4jztzun/wD/mN/CtzCxlV3pdjY=", - "owner": "fedimint", - "repo": "fedimint", - "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", - "type": "github" - }, - "original": { - "owner": "fedimint", - "repo": "fedimint", - "rev": "c32bbe8ed8d95ae420b5879e92dda6ce48f5c914", - "type": "github" - } - }, ->>>>>>> cdebb0d (fix::> Added support func to tests and Updated CreateNewFedimintClient()) "fenix": { "inputs": { "nixpkgs": [ @@ -175,11 +77,11 @@ "rust-analyzer-src": "rust-analyzer-src" }, "locked": { - "lastModified": 1712730246, - "narHash": "sha256-iB8bFj+07RHpmt+XuGGvYQk2Iwm12u6+DklGq/+Tg5s=", + "lastModified": 1712903033, + "narHash": "sha256-KcvsEm0h1mIwBHFAzWFBjGihnbf2fxpAaXOdVbUfAI4=", "owner": "nix-community", "repo": "fenix", - "rev": "d402ae4a5e5676722290470f61a5e8e3155b5487", + "rev": "c739f83545e625227f4d0af7fe2a71e69931fa4c", "type": "github" }, "original": { @@ -193,11 +95,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1701680307, - "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -232,11 +134,11 @@ ] }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -275,11 +177,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712437997, - "narHash": "sha256-g0whLLwRvgO2FsyhY8fNk+TWenS3jg5UdlWL4uqgFeo=", + "lastModified": 1712867921, + "narHash": "sha256-edTFV4KldkCMdViC/rmpJa7oLIU8SE/S35lh/ukC7bg=", "owner": "nixos", "repo": "nixpkgs", - "rev": "e38d7cb66ea4f7a0eb6681920615dfcc30fc2920", + "rev": "51651a540816273b67bc4dedea2d37d116c5f7fe", "type": "github" }, "original": { @@ -300,11 +202,11 @@ "rust-analyzer-src": { "flake": false, "locked": { - "lastModified": 1712663608, - "narHash": "sha256-tN9ZL6kGppmHg84lxlpAlaN+kXWNctKK7Yitq/iXDEw=", + "lastModified": 1712818880, + "narHash": "sha256-VDxsvgj/bNypHq48tQWtc3VRbWvzlFjzKf9ZZIVO10Y=", "owner": "rust-lang", "repo": "rust-analyzer", - "rev": "a5feb4f05f09adca661c869b1bf2324898cbaa43", + "rev": "657b33b0cb9bd49085202e91ad5b4676532c9140", "type": "github" }, "original": { diff --git a/misc/git-hooks/pre-commit b/misc/git-hooks/pre-commit index 7959e97..d21df26 100755 --- a/misc/git-hooks/pre-commit +++ b/misc/git-hooks/pre-commit @@ -9,13 +9,13 @@ set -e # Revert `git stash` on exit function revert_git_stash { - >&2 echo "Unstashing uncommitted changes..." + echo >&2 "Unstashing uncommitted changes..." git stash pop -q } # Stash pending changes and revert them when script ends if [ -z "${NO_STASH:-}" ] && [ $is_unclean -ne 0 ]; then - >&2 echo "Stashing uncommitted changes..." + echo >&2 "Stashing uncommitted changes..." GIT_LITERAL_PATHSPECS=0 git stash -q --keep-index trap revert_git_stash EXIT fi @@ -25,146 +25,145 @@ FLAKEBOX_GIT_LS="$(git ls-files)" export FLAKEBOX_GIT_LS_TEXT FLAKEBOX_GIT_LS_TEXT="$(echo "$FLAKEBOX_GIT_LS" | grep -v -E "\.(png|ods|jpg|jpeg|woff2|keystore|wasm|ttf|jar|ico|gif)\$")" - function check_nothing() { true } export -f check_nothing function check_cargo_fmt() { - set -euo pipefail + set -euo pipefail - flakebox-in-each-cargo-workspace cargo fmt --all --check + flakebox-in-each-cargo-workspace cargo fmt --all --check } export -f check_cargo_fmt function check_cargo_lock() { - set -euo pipefail + set -euo pipefail - # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 - flakebox-in-each-cargo-workspace cargo update --workspace --locked + # https://users.rust-lang.org/t/check-if-the-cargo-lock-is-up-to-date-without-building-anything/91048/5 + flakebox-in-each-cargo-workspace cargo update --workspace --locked } export -f check_cargo_lock function check_leftover_dbg() { - set -euo pipefail - - errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do - if grep 'dbg!(' "$path" > /dev/null; then - >&2 echo "$path contains dbg! macro" - errors="true" - fi - done - - if [ -n "$errors" ]; then - >&2 echo "Fix the problems above or use --no-verify" 1>&2 - return 1 + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep '.*\.rs'); do + if grep 'dbg!(' "$path" >/dev/null; then + echo >&2 "$path contains dbg! macro" + errors="true" fi + done + + if [ -n "$errors" ]; then + echo >&2 "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi } export -f check_leftover_dbg function check_semgrep() { - set -euo pipefail + set -euo pipefail - # semgrep is not available on MacOS - if ! command -v semgrep > /dev/null ; then - >&2 echo "Skipping semgrep check: not available" - return 0 - fi + # semgrep is not available on MacOS + if ! command -v semgrep >/dev/null; then + echo >&2 "Skipping semgrep check: not available" + return 0 + fi - if [ ! -f .config/semgrep.yaml ] ; then - >&2 echo "Skipping semgrep check: .config/semgrep.yaml doesn't exist" - return 0 - fi + if [ ! -f .config/semgrep.yaml ]; then + echo >&2 "Skipping semgrep check: .config/semgrep.yaml doesn't exist" + return 0 + fi - if [ ! -s .config/semgrep.yaml ] ; then - >&2 echo "Skipping semgrep check: .config/semgrep.yaml empty" - return 0 - fi + if [ ! -s .config/semgrep.yaml ]; then + echo >&2 "Skipping semgrep check: .config/semgrep.yaml empty" + return 0 + fi - env SEMGREP_ENABLE_VERSION_CHECK=0 \ - semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml + env SEMGREP_ENABLE_VERSION_CHECK=0 \ + semgrep -q --error --no-rewrite-rule-ids --config .config/semgrep.yaml } export -f check_semgrep function check_shellcheck() { - set -euo pipefail + set -euo pipefail - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do - shellcheck --severity=warning "$path" - done + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT" | grep -E '.*\.sh$'); do + shellcheck --severity=warning "$path" + done } export -f check_shellcheck function check_trailing_newline() { - set -euo pipefail - - errors="" - for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do - - # extra branches for clarity - if [ ! -s "$path" ]; then - # echo "$path is empty" - true - elif [ -z "$(tail -c 1 < "$path")" ]; then - # echo "$path ends with a newline or with a null byte" - true - else - >&2 echo "$path doesn't end with a newline" 1>&2 - errors="true" - fi - done - - if [ -n "$errors" ]; then - >&2 echo "Fix the problems above or use --no-verify" 1>&2 - return 1 + set -euo pipefail + + errors="" + for path in $(echo "$FLAKEBOX_GIT_LS_TEXT"); do + + # extra branches for clarity + if [ ! -s "$path" ]; then + # echo "$path is empty" + true + elif [ -z "$(tail -c 1 <"$path")" ]; then + # echo "$path ends with a newline or with a null byte" + true + else + echo >&2 "$path doesn't end with a newline" 1>&2 + errors="true" fi + done + + if [ -n "$errors" ]; then + echo >&2 "Fix the problems above or use --no-verify" 1>&2 + return 1 + fi } export -f check_trailing_newline function check_trailing_whitespace() { - set -euo pipefail - - rev="HEAD" - if ! git rev-parse -q 1>/dev/null HEAD 2>/dev/null ; then - >&2 echo "Warning: no commits yet, checking against --root" - rev="--root" - fi - if ! git diff --check $rev ; then - >&2 echo "Trailing whitespace detected. Please remove them before committing." - return 1 - fi + set -euo pipefail + + rev="HEAD" + if ! git rev-parse -q HEAD 1>/dev/null 2>/dev/null; then + echo >&2 "Warning: no commits yet, checking against --root" + rev="--root" + fi + if ! git diff --check $rev; then + echo >&2 "Trailing whitespace detected. Please remove them before committing." + return 1 + fi } export -f check_trailing_whitespace function check_typos() { - set -euo pipefail + set -euo pipefail - if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude ; then - >&2 echo "Typos found: Valid new words can be added to '.typos.toml'" - return 1 - fi + if ! echo "$FLAKEBOX_GIT_LS_TEXT" | typos --file-list - --force-exclude; then + echo >&2 "Typos found: Valid new words can be added to '.typos.toml'" + return 1 + fi } export -f check_typos parallel \ --nonotice \ -::: \ - check_cargo_fmt \ - check_cargo_lock \ - check_leftover_dbg \ - check_semgrep \ - check_shellcheck \ - check_trailing_newline \ - check_trailing_whitespace \ - check_typos \ + ::: \ + check_cargo_fmt \ + check_cargo_lock \ + check_leftover_dbg \ + check_semgrep \ + check_shellcheck \ + check_trailing_newline \ + check_trailing_whitespace \ + check_typos \ check_nothing diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index be05dac..cfd198c 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -101,7 +101,7 @@ func main() { var fedimintResponseData interface{} err = json.Unmarshal(jsonBytes, &fedimintResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(discover-version):", err) + fmt.Println("Error unmarshalling JSON(discover-version):", err) return } @@ -132,7 +132,7 @@ func main() { var infoResponseData interface{} err = json.Unmarshal(jsonBytes, &infoResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(discover-version):", err) + fmt.Println("Error unmarshalling JSON(discover-version):", err) return } @@ -158,7 +158,7 @@ func main() { var joinResponseData interface{} err = json.Unmarshal(jsonBytes, &joinResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(join):", err) + fmt.Println("Error unmarshalling JSON(join):", err) return } @@ -180,7 +180,7 @@ func main() { var listOperationsResponseData interface{} err = json.Unmarshal(jsonBytes, &listOperationsResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(list-operations):", err) + fmt.Println("Error unmarshalling JSON(list-operations):", err) return } @@ -206,7 +206,7 @@ func main() { var gatewayListResponseData interface{} err = json.Unmarshal(jsonBytes, &gatewayListResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(list-gateways):", err) + fmt.Println("Error unmarshalling JSON(list-gateways):", err) return } @@ -228,7 +228,7 @@ func main() { var invoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &invoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(invoice):", err) + fmt.Println("Error unmarshalling JSON(invoice):", err) return } @@ -250,7 +250,7 @@ func main() { var payResponseData interface{} err = json.Unmarshal(jsonBytes, &payResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(pay):", err) + fmt.Println("Error unmarshalling JSON(pay):", err) return } @@ -272,7 +272,7 @@ func main() { var awaitInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &awaitInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(await-invoice):", err) + fmt.Println("Error unmarshalling JSON(await-invoice):", err) return } @@ -294,7 +294,7 @@ func main() { var tweakInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &tweakInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(await-invoice):", err) + fmt.Println("Error unmarshalling JSON(await-invoice):", err) return } @@ -319,7 +319,7 @@ func main() { var claimInvoiceResponseData interface{} err = json.Unmarshal(jsonBytes, &claimInvoiceResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(claim-external-pubkey-tweaked):", err) + fmt.Println("Error unmarshalling JSON(claim-external-pubkey-tweaked):", err) return } @@ -345,7 +345,7 @@ func main() { var mintResponseData interface{} err = json.Unmarshal(jsonBytes, &mintResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(spend):", err) + fmt.Println("Error unmarshalling JSON(spend):", err) return } @@ -367,7 +367,7 @@ func main() { var decodedResponseData interface{} err = json.Unmarshal(jsonBytes, &decodedResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(decode-notes):", err) + fmt.Println("Error unmarshalling JSON(decode-notes):", err) return } @@ -389,7 +389,7 @@ func main() { var encodedResponseData interface{} err = json.Unmarshal(jsonBytes, &encodedResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(encode-notes):", err) + fmt.Println("Error unmarshalling JSON(encode-notes):", err) return } @@ -411,7 +411,7 @@ func main() { var validateResponseData interface{} err = json.Unmarshal(jsonBytes, &validateResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(validate):", err) + fmt.Println("Error unmarshalling JSON(validate):", err) return } @@ -433,7 +433,7 @@ func main() { var reissueResponseData interface{} err = json.Unmarshal(jsonBytes, &reissueResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(reissue):", err) + fmt.Println("Error unmarshalling JSON(reissue):", err) return } @@ -455,7 +455,7 @@ func main() { var splitResponseData interface{} err = json.Unmarshal(jsonBytes, &splitResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(split):", err) + fmt.Println("Error unmarshalling JSON(split):", err) return } @@ -484,7 +484,7 @@ func main() { var combineResponseData interface{} err = json.Unmarshal(jsonBytes, &combineResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(split):", err) + fmt.Println("Error unmarshalling JSON(split):", err) return } @@ -510,7 +510,7 @@ func main() { var addrResponseData interface{} err = json.Unmarshal(jsonBytes, &addrResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(deposit-address):", err) + fmt.Println("Error unmarshalling JSON(deposit-address):", err) return } @@ -532,7 +532,7 @@ func main() { var withdrawResponseData interface{} err = json.Unmarshal(jsonBytes, &withdrawResponseData) if err != nil { - fmt.Println("Error unmarshaling JSON(withdraw):", err) + fmt.Println("Error unmarshalling JSON(withdraw):", err) return } diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index d2a6b82..a4ce78c 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -591,8 +591,8 @@ func (ln *LnModule) Pay(paymentInfo string, gatewayId string, amountMsat *uint64 return &payResp, nil } -func (ln *LnModule) ListGateways(gatewayId *string) ([]modules.Gateway, error) { - resp, err := ln.Client.get("/ln/list-gateways") +func (ln *LnModule) ListGateways(federationId *string) ([]modules.Gateway, error) { + resp, err := ln.Client.postWithFederationId("/ln/list-gateways", nil, federationId) if err != nil { return nil, err }