The backend for the project formerly known as signet, now known as beignet.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.5 KiB

  1. package endpoints
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. . "github.com/imosed/signet/data"
  7. "github.com/rs/zerolog/log"
  8. "github.com/stellar/go/clients/horizonclient"
  9. "github.com/stellar/go/protocols/horizon"
  10. )
  11. var client = horizonclient.DefaultTestNetClient
  12. type SubmitFundRequest struct {
  13. FundID uint `json:"fundId"`
  14. }
  15. func SubmitFund(w http.ResponseWriter, r *http.Request) {
  16. var req SubmitFundRequest
  17. err := json.NewDecoder(r.Body).Decode(&req)
  18. if err != nil {
  19. log.Error().Err(err).Msg("Could not decode body in SubmitFund call")
  20. }
  21. var fund RewardFund
  22. Db.Find(&fund, req.FundID)
  23. // source := keypair.MustParseFull(fund.FundWallet)
  24. // sourceReq := horizonclient.AccountRequest{AccountID: source.Address()}
  25. // var sourceAcct horizon.Account
  26. // sourceAcct, err = client.AccountDetail(sourceReq)
  27. offerReq := horizonclient.OfferRequest{
  28. Selling: fmt.Sprintf("%s:%s", fund.Asset, fund.IssuerWallet),
  29. Seller: fund.IssuerWallet,
  30. Cursor: "0",
  31. }
  32. var offers horizon.OffersPage
  33. offers, err = client.Offers(offerReq)
  34. for _, o := range offers.Embedded.Records {
  35. if float64(o.PriceR.N)/float64(o.PriceR.D) == fund.Price {
  36. fmt.Println(o.PriceR.N)
  37. fmt.Println(o.Amount)
  38. }
  39. }
  40. // var tx *txnbuild.Transaction
  41. // tx, err = txnbuild.NewTransaction(
  42. // txnbuild.TransactionParams{
  43. // SourceAccount: &sourceAcct,
  44. // IncrementSequenceNum: true,
  45. // Operations: []txnbuild.Operation{
  46. // &txnbuild.ManageBuyOffer{
  47. // Selling: txnbuild.NativeAsset{},
  48. // Buying: txnbuild.CreditAsset{
  49. // Code: fund.Asset,
  50. // Issuer: fund.IssuerWallet,
  51. // },
  52. // Amount: fmt.Sprintf("%f", SumContributions(fund.Contributions)),
  53. // Price: xdr.Price{}, // TODO: get price
  54. // OfferID: 0,
  55. // SourceAccount: "",
  56. // },
  57. // },
  58. // BaseFee: txnbuild.MinBaseFee,
  59. // Memo: txnbuild.Memo(txnbuild.MemoText(strconv.Itoa(int(fund.Model.ID)))),
  60. // Preconditions: txnbuild.Preconditions{
  61. // TimeBounds: txnbuild.NewInfiniteTimeout(), // TODO: change from infinite
  62. // },
  63. // })
  64. // if err != nil {
  65. // log.Error().Err(err).Msg("Could not submit reward fund")
  66. // }
  67. //
  68. // tx, err = tx.Sign(network.TestNetworkPassphrase, source)
  69. // if err != nil {
  70. // log.Error().Err(err).Msg("Could not submit fund")
  71. // }
  72. //
  73. // var response horizon.Transaction
  74. // response, err = client.SubmitTransaction(tx)
  75. var resp SuccessResponse
  76. // resp.Success = response.Successful
  77. err = json.NewEncoder(w).Encode(resp)
  78. if err != nil {
  79. log.Error().Err(err).Msg("Could not deliver response in SubmitFund call")
  80. }
  81. }