forked from stellar/go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_request.go
35 lines (29 loc) · 1008 Bytes
/
submit_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package horizonclient
import (
"fmt"
"net/http"
"net/url"
"strings"
"github.com/stellar/go/support/errors"
)
// BuildURL returns the url for submitting transactions to a running horizon instance
func (sr submitRequest) BuildURL() (endpoint string, err error) {
if sr.endpoint == "" || sr.transactionXdr == "" {
return endpoint, errors.New("invalid request: too few parameters")
}
query := url.Values{}
query.Set("tx", sr.transactionXdr)
endpoint = fmt.Sprintf("%s?%s", sr.endpoint, query.Encode())
return endpoint, err
}
// HTTPRequest returns the http request for submitting transactions to a running horizon instance
func (sr submitRequest) HTTPRequest(horizonURL string) (*http.Request, error) {
form := url.Values{}
form.Set("tx", sr.transactionXdr)
request, err := http.NewRequest("POST", horizonURL+sr.endpoint, strings.NewReader(form.Encode()))
if err != nil {
return nil, err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
return request, nil
}