|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package endpoints
-
- import (
- "encoding/json"
- "fmt"
- "net/http"
-
- . "github.com/imosed/signet/data"
- "github.com/rs/zerolog/log"
- "github.com/stellar/go/clients/horizonclient"
- "github.com/stellar/go/protocols/horizon"
- )
-
- var client = horizonclient.DefaultTestNetClient
-
- type SubmitFundRequest struct {
- FundID uint `json:"fundId"`
- }
-
- func SubmitFund(w http.ResponseWriter, r *http.Request) {
- var req SubmitFundRequest
- err := json.NewDecoder(r.Body).Decode(&req)
- if err != nil {
- log.Error().Err(err).Msg("Could not decode body in SubmitFund call")
- }
-
- var fund RewardFund
- Db.Find(&fund, req.FundID)
-
- // source := keypair.MustParseFull(fund.FundWallet)
- // sourceReq := horizonclient.AccountRequest{AccountID: source.Address()}
- // var sourceAcct horizon.Account
- // sourceAcct, err = client.AccountDetail(sourceReq)
-
- offerReq := horizonclient.OfferRequest{
- Selling: fmt.Sprintf("%s:%s", fund.Asset, fund.IssuerWallet),
- Seller: fund.IssuerWallet,
- Cursor: "0",
- }
-
- var offers horizon.OffersPage
- offers, err = client.Offers(offerReq)
- for _, o := range offers.Embedded.Records {
- if float64(o.PriceR.N)/float64(o.PriceR.D) == fund.Price {
- fmt.Println(o.PriceR.N)
- fmt.Println(o.Amount)
- }
- }
-
- // var tx *txnbuild.Transaction
- // tx, err = txnbuild.NewTransaction(
- // txnbuild.TransactionParams{
- // SourceAccount: &sourceAcct,
- // IncrementSequenceNum: true,
- // Operations: []txnbuild.Operation{
- // &txnbuild.ManageBuyOffer{
- // Selling: txnbuild.NativeAsset{},
- // Buying: txnbuild.CreditAsset{
- // Code: fund.Asset,
- // Issuer: fund.IssuerWallet,
- // },
- // Amount: fmt.Sprintf("%f", SumContributions(fund.Contributions)),
- // Price: xdr.Price{}, // TODO: get price
- // OfferID: 0,
- // SourceAccount: "",
- // },
- // },
- // BaseFee: txnbuild.MinBaseFee,
- // Memo: txnbuild.Memo(txnbuild.MemoText(strconv.Itoa(int(fund.Model.ID)))),
- // Preconditions: txnbuild.Preconditions{
- // TimeBounds: txnbuild.NewInfiniteTimeout(), // TODO: change from infinite
- // },
- // })
- // if err != nil {
- // log.Error().Err(err).Msg("Could not submit reward fund")
- // }
- //
- // tx, err = tx.Sign(network.TestNetworkPassphrase, source)
- // if err != nil {
- // log.Error().Err(err).Msg("Could not submit fund")
- // }
- //
- // var response horizon.Transaction
- // response, err = client.SubmitTransaction(tx)
-
- var resp SuccessResponse
- // resp.Success = response.Successful
-
- err = json.NewEncoder(w).Encode(resp)
- if err != nil {
- log.Error().Err(err).Msg("Could not deliver response in SubmitFund call")
- }
- }
|