package endpoints import ( "encoding/json" "fmt" "net/http" . "github.com/imosed/signet/data" "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 { panic("Could not decode body") } 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 { // panic("Could not submit reward fund") // } // // tx, err = tx.Sign(network.TestNetworkPassphrase, source) // if err != nil { // panic("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 { panic("Could not deliver response") } }