-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspv.go
33 lines (31 loc) · 775 Bytes
/
spv.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
package pact
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
func SPV(spvCmd SPVCommand, apiHost string) (res interface{}, err error) {
defer func() {
if e := recover(); e != nil {
switch er := e.(type) {
case Error:
err = er
case error:
err = er
}
}
}()
EnforceType(spvCmd.TargetChainId, "string", "targetChainId")
EnforceType(spvCmd.RequestKey, "string", "requestKey")
req, err := MarshalBody(spvCmd)
EnforceNoError(err)
resp, err := http.Post(fmt.Sprintf("%s/spv", apiHost), "application/json", req)
EnforceNoError(err)
body, err := ioutil.ReadAll(resp.Body)
EnforceNoError(err)
EnforceValid(resp.StatusCode == http.StatusOK, fmt.Errorf("%v", string(body)))
err = json.Unmarshal(body, &res)
EnforceNoError(err)
return
}