farmstar-survey-backend/pkg/custodial/custodial.go
2024-02-05 16:05:28 +03:00

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
}