farmstar-survey-backend/pkg/custodial/custodial.go

48 lines
871 B
Go
Raw Permalink Normal View History

2024-02-05 14:05:28 +01:00
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
}