-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8038bc0
commit 9d7eb8f
Showing
3 changed files
with
127 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
package rollups | ||
|
||
import ( | ||
"encoding/json" | ||
"bytes" | ||
"encoding/hex" | ||
"encoding/json" | ||
"net/http" | ||
"bytes" | ||
"os" | ||
"os" | ||
) | ||
|
||
var rollup_server = os.Getenv("ROLLUP_HTTP_SERVER_URL") | ||
|
||
func SendPost(endpoint string, jsonData []byte) (*http.Response, error) { | ||
req, err := http.NewRequest(http.MethodPost, rollup_server + "/" + endpoint, bytes.NewBuffer(jsonData)) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
req, err := http.NewRequest(http.MethodPost, rollup_server+"/"+endpoint, bytes.NewBuffer(jsonData)) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
req.Header.Set("Content-Type", "application/json; charset=UTF-8") | ||
|
||
return http.DefaultClient.Do(req) | ||
return http.DefaultClient.Do(req) | ||
} | ||
|
||
func SendFinish(finish *FinishRequest) (*http.Response, error) { | ||
body, err := json.Marshal(finish) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
return SendPost("finish", body) | ||
body, err := json.Marshal(finish) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
|
||
return SendPost("finish", body) | ||
} | ||
|
||
func SendReport(report *ReportRequest) (*http.Response, error) { | ||
body, err := json.Marshal(report) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
return SendPost("report", body) | ||
body, err := json.Marshal(report) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
|
||
return SendPost("report", body) | ||
} | ||
|
||
func SendNotice(notice *NoticeRequest) (*http.Response, error) { | ||
body, err := json.Marshal(notice) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
return SendPost("notice", body) | ||
body, err := json.Marshal(notice) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
|
||
return SendPost("notice", body) | ||
} | ||
|
||
func SendVoucher(voucher *VoucherRequest) (*http.Response, error) { | ||
body, err := json.Marshal(voucher) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
return SendPost("voucher", body) | ||
body, err := json.Marshal(voucher) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
|
||
return SendPost("voucher", body) | ||
} | ||
|
||
func SendException(exception *ExceptionRequest) (*http.Response, error) { | ||
body, err := json.Marshal(exception) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
return SendPost("exception", body) | ||
body, err := json.Marshal(exception) | ||
if err != nil { | ||
return &http.Response{}, err | ||
} | ||
|
||
return SendPost("exception", body) | ||
} | ||
|
||
func Hex2Str(hx string) (string, error) { | ||
str, err := hex.DecodeString(hx[2:]) | ||
str, err := hex.DecodeString(hx[2:]) | ||
if err != nil { | ||
return string(str), err | ||
return string(str), err | ||
} | ||
return string(str), nil | ||
return string(str), nil | ||
} | ||
|
||
func Str2Hex(str string) string { | ||
hx := hex.EncodeToString([]byte(str)) | ||
return "0x"+string(hx) | ||
hx := hex.EncodeToString([]byte(str)) | ||
return "0x" + string(hx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters