The backend for the project formerly known as signet, now known as beignet.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

93 linhas
2.4 KiB

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