Skip to content
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
filippo.io/edwards25519 v1.1.0
github.com/aws/aws-sdk-go-v2 v0.17.0
github.com/code-payments/code-vm-indexer v1.2.0
github.com/code-payments/ocp-protobuf-api v1.11.0
github.com/code-payments/ocp-protobuf-api v1.12.0
github.com/emirpasic/gods v1.12.0
github.com/envoyproxy/protoc-gen-validate v1.2.1
github.com/golang/protobuf v1.5.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I
github.com/cockroachdb/apd v1.1.0/go.mod h1:8Sl8LxpKi29FqWXR16WEFZRNSz3SoPzUzeMeY4+DwBQ=
github.com/code-payments/code-vm-indexer v1.2.0 h1:rSHpBMiT9BKgmKcXg/VIoi/h0t7jNxGx07Qz59m+6Q0=
github.com/code-payments/code-vm-indexer v1.2.0/go.mod h1:vn91YN2qNqb+gGJeZe2+l+TNxVmEEiRHXXnIn2Y40h8=
github.com/code-payments/ocp-protobuf-api v1.11.0 h1:bvAtcOC3llKWckLKcuK2/i1aY6LorVZebWUybNG43PM=
github.com/code-payments/ocp-protobuf-api v1.11.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/code-payments/ocp-protobuf-api v1.12.0 h1:Gm+DMGJXvV4PIdM609BfcxoRrAwJHDAC12mRc6SL+Jc=
github.com/code-payments/ocp-protobuf-api v1.12.0/go.mod h1:tw6BooY5a8l6CtSZnKOruyKII0W04n89pcM4BizrgG8=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
Expand Down
61 changes: 61 additions & 0 deletions ocp/rpc/transaction/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,67 @@ func handleStatefulSwapStructuredError(streamer transactionpb.Transaction_Statef
return streamer.Send(errResp)
}

func handleStatelessSwapError(streamer transactionpb.Transaction_StatelessSwapServer, err error) error {
// gRPC status errors are passed through as is
if _, ok := status.FromError(err); ok {
return err
}

// Case 1: Errors that map to a Code error response
switch err.(type) {
case SwapValidationError:
return handleStatelessSwapStructuredError(
streamer,
transactionpb.StatelessSwapResponse_Error_INVALID_SWAP,
toReasonStringErrorDetails(err),
)
case SwapDeniedError:
return handleStatelessSwapStructuredError(
streamer,
transactionpb.StatelessSwapResponse_Error_DENIED,
toDeniedErrorDetails(err),
)
}

switch err {
case ErrInvalidSignature:
return handleStatelessSwapStructuredError(
streamer,
transactionpb.StatelessSwapResponse_Error_SIGNATURE_ERROR,
toReasonStringErrorDetails(err),
)
case transaction.ErrTransactionFailed:
return handleStatelessSwapStructuredError(
streamer,
transactionpb.StatelessSwapResponse_Error_TRANSACTION_FAILED,
toReasonStringErrorDetails(err),
)
case ErrNotImplemented:
return status.Error(codes.Unimplemented, err.Error())
}

// Case 2: Errors that map to gRPC status errors
switch err {
case ErrTimedOutReceivingRequest, context.DeadlineExceeded:
return status.Error(codes.DeadlineExceeded, err.Error())
case context.Canceled:
return status.Error(codes.Canceled, err.Error())
}
return status.Error(codes.Internal, "rpc server failure")
}

func handleStatelessSwapStructuredError(streamer transactionpb.Transaction_StatelessSwapServer, code transactionpb.StatelessSwapResponse_Error_Code, errorDetails ...*transactionpb.ErrorDetails) error {
errResp := &transactionpb.StatelessSwapResponse{
Response: &transactionpb.StatelessSwapResponse_Error_{
Error: &transactionpb.StatelessSwapResponse_Error{
Code: code,
ErrorDetails: errorDetails,
},
},
}
return streamer.Send(errResp)
}

func shouldFilterSubmitIntentFailureMetricReport(err error) bool {
if statusErr, ok := status.FromError(err); ok {
switch statusErr.Code() {
Expand Down
File renamed without changes.
Loading
Loading