-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,558 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// This code is available on the terms of the project LICENSE.md file, | ||
// also available online at https://blueoakcouncil.org/license/1.0.0. | ||
|
||
package zec | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// Error codes here are used on the frontend. | ||
const ( | ||
errNoFundsRequested = iota | ||
errBalanceRetrieval | ||
errInsufficientBalance | ||
errUTxORetrieval | ||
errLockUnspent | ||
errFunding | ||
) | ||
|
||
// Error is an error code and a wrapped error. | ||
type Error struct { | ||
code int | ||
err error | ||
} | ||
|
||
// Error returns the error string. Satisfies the error interface. | ||
func (e *Error) Error() string { | ||
return e.err.Error() | ||
} | ||
|
||
// Code returns the error code. | ||
func (e *Error) Code() *int { | ||
return &e.code | ||
} | ||
|
||
// Unwrap returns the underlying wrapped error. | ||
func (e *Error) Unwrap() error { | ||
return e.err | ||
} | ||
|
||
// newError is a constructor for a new Error. | ||
func newError(code int, s string, a ...any) error { | ||
return &Error{ | ||
code: code, | ||
err: fmt.Errorf(s, a...), // s may contain a %w verb to wrap an error | ||
} | ||
} | ||
|
||
// codedError converts the error to an Error with the specified code. | ||
func codedError(code int, err error) error { | ||
return &Error{ | ||
code: code, | ||
err: err, | ||
} | ||
} | ||
|
||
// errorHasCode checks whether the error is an Error and has the specified code. | ||
func errorHasCode(err error, code int) bool { | ||
var e *Error | ||
return errors.As(err, &e) && e.code == code | ||
} | ||
|
||
// UnwrapErr returns the result of calling the Unwrap method on err, | ||
// until it returns a non-wrapped error. | ||
func UnwrapErr(err error) error { | ||
InnerErr := errors.Unwrap(err) | ||
if InnerErr == nil { | ||
return err | ||
} | ||
return UnwrapErr(InnerErr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.