Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions client/intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error {
SecretHash string `json:"secret_hash"`
ApprovalMechanism types.ApprovalToSignType `json:"approval_mechanism"`
ParamsToSign json.RawMessage `json:"params_to_sign"`
TransferAddress string `json:"transfer_address"`
}

var raw createIntentResponseCodec
Expand All @@ -62,6 +63,14 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error {
case types.ApprovalToSignTypeCosign:
resp.Cosign = new(types.ApprovalToSignCosign)
return json.Unmarshal(raw.ParamsToSign, resp.Cosign)
case types.ApprovalToSignTypeTransfer:
if raw.TransferAddress == "" {
return fmt.Errorf("transfer approval mechanism without a transfer address")
}

resp.Transfer = &types.ApprovalToSignTransfer{Address: raw.TransferAddress}

return nil
default:
return fmt.Errorf("unrecognized approval mechanism %v", resp.ApprovalMechanism)
}
Expand All @@ -88,6 +97,25 @@ func (c *Client) AddIntentApproval(ctx context.Context, params AddIntentApproval
return c.doRequest(ctx, http.MethodPost, endpoint, &params.Approval, nil)
}

// SubmitDepositParams represents parameters required to report a deposit the user made themselves.
type SubmitDepositParams struct {
IntentID uuid.UUID `json:"-"`
TxHash string `json:"tx_hash"`
}

// SubmitDepositResponse represents the response from the SubmitDeposit API endpoint.
type SubmitDepositResponse struct {
FulfillmentDeadline int64 `json:"fulfillment_deadline"`
}

// SubmitDeposit reports the transaction hash of a transfer the user broadcast themselves.
func (c *Client) SubmitDeposit(ctx context.Context, params SubmitDepositParams) (SubmitDepositResponse, error) {
var resp SubmitDepositResponse
endpoint := c.buildURL("intents/%s/deposit", params.IntentID.String())

return resp, c.doRequest(ctx, http.MethodPost, endpoint, &params, &resp)
}

// GetIntentStatusResponse represents the response from the GetIntentStatus API endpoint.
type GetIntentStatusResponse struct {
Status types.CombinedStatus `json:"status"`
Expand Down
10 changes: 9 additions & 1 deletion types/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import (
// ApprovalToSign defines approval mechanisms used by different blockchains to transfer ownership of funds to resolver.
//
// `approvalMechanism` holds the type of approval mechanism required for signing operations, and one of
// the `permit2|htlc|cosign` fields will be not nil (corresponding).
// the `permit2|htlc|cosign|transfer` fields will be not nil (corresponding).
type ApprovalToSign struct {
ApprovalMechanism ApprovalToSignType
Permit2 *ApprovalToSignPermit2
Htlc *ApprovalToSignHtlc
Cosign *ApprovalToSignCosign
Transfer *ApprovalToSignTransfer
}

// ApprovalToSignType represents the type of approval mechanism required for signing operations.
Expand All @@ -28,6 +29,8 @@ const (
ApprovalToSignTypeHtlc ApprovalToSignType = "htlc"
// ApprovalToSignTypeCosign defines `cosign` approval types.
ApprovalToSignTypeCosign ApprovalToSignType = "cosign"
// ApprovalToSignTypeTransfer defines the user-transfer flow.
ApprovalToSignTypeTransfer ApprovalToSignType = "transfer"
)

// ApprovalToSignPermit2 represents parameters of a permit2 approval used to authorize a resolver as a spender.
Expand All @@ -49,6 +52,11 @@ type Permit2AdditionalData struct {
WitnessHash string `json:"witness_hash"`
}

// ApprovalToSignTransfer carries the address the user sends a plain transfer to.
type ApprovalToSignTransfer struct {
Address string
}

// ParseWitness unmarshalls raw witness data into the provided struct.
//
// NOTE: `val` must be a pointer to a struct that implements `json.Unmarshaler`.
Expand Down
4 changes: 4 additions & 0 deletions types/intents.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const (
CombinedStatusRefundRequested CombinedStatus = "RefundRequested"
// CombinedStatusRefunded defines the `Refunded` status.
CombinedStatusRefunded CombinedStatus = "Refunded"
// CombinedStatusAwaitingBroadcast defines the `AwaitingBroadcast` status.
CombinedStatusAwaitingBroadcast CombinedStatus = "AwaitingBroadcast"
// CombinedStatusLapsed defines the `Lapsed` status.
CombinedStatusLapsed CombinedStatus = "Lapsed"
)

func (s CombinedStatus) String() string {
Expand Down
Loading