The backend for the project formerly known as signet, now known as beignet.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

submitfund.go 2.4 KiB

2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
2 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. }