mirror of
https://github.com/grassrootseconomics/farmstar-survey-backend.git
synced 2024-12-22 23:47:32 +01:00
48 lines
871 B
Go
48 lines
871 B
Go
package custodial
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/carlmjohnson/requests"
|
|
)
|
|
|
|
type (
|
|
CustodialClient struct {
|
|
endpoint string
|
|
}
|
|
|
|
SignTransferPayload struct {
|
|
Amount uint `json:"amount"`
|
|
From string `json:"from"`
|
|
To string `json:"to"`
|
|
VoucherAddress string `json:"voucherAddress"`
|
|
}
|
|
|
|
CustodialResponse struct {
|
|
Ok bool `json:"ok"`
|
|
Result struct {
|
|
TrackingId string `json:"trackingId"`
|
|
} `json:"result"`
|
|
}
|
|
)
|
|
|
|
func New(endpoint string) *CustodialClient {
|
|
return &CustodialClient{
|
|
endpoint: endpoint,
|
|
}
|
|
}
|
|
|
|
func (cc *CustodialClient) SignTransfer(ctx context.Context, payload SignTransferPayload) (string, error) {
|
|
var resp CustodialResponse
|
|
|
|
if err := requests.
|
|
URL(cc.endpoint).
|
|
BodyJSON(&payload).
|
|
ToJSON(&resp).
|
|
Fetch(ctx); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return resp.Result.TrackingId, nil
|
|
}
|