forked from stellar/go
/
errors.go
82 lines (65 loc) · 1.89 KB
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package txsub
import (
"errors"
"fmt"
"github.com/stellar/go/services/horizon/internal/codes"
"github.com/stellar/go/xdr"
)
var (
ErrNoResults = errors.New("No result found")
ErrCanceled = errors.New("canceled")
ErrTimeout = errors.New("timeout")
// ErrBadSequence is a canned error response for transactions whose sequence
// number is wrong.
ErrBadSequence = &FailedTransactionError{"AAAAAAAAAAD////7AAAAAA=="}
// ErrNoAccount is returned when the source account for the transaction
// cannot be found in the database
ErrNoAccount = &FailedTransactionError{"AAAAAAAAAAD////4AAAAAA=="}
)
// FailedTransactionError represent an error that occurred because
// stellar-core rejected the transaction. ResultXDR is a base64
// encoded TransactionResult struct
type FailedTransactionError struct {
ResultXDR string
}
func (err *FailedTransactionError) Error() string {
return fmt.Sprintf("tx failed: %s", err.ResultXDR)
}
func (fte *FailedTransactionError) Result() (result xdr.TransactionResult, err error) {
err = xdr.SafeUnmarshalBase64(fte.ResultXDR, &result)
return
}
func (fte *FailedTransactionError) TransactionResultCode() (result string, err error) {
r, err := fte.Result()
if err != nil {
return
}
result, err = codes.String(r.Result.Code)
return
}
func (fte *FailedTransactionError) OperationResultCodes() (result []string, err error) {
r, err := fte.Result()
if err != nil {
return
}
oprs, ok := r.Result.GetResults()
if !ok {
return
}
result = make([]string, len(oprs))
for i, opr := range oprs {
result[i], err = codes.ForOperationResult(opr)
if err != nil {
return
}
}
return
}
// MalformedTransactionError represent an error that occurred because
// a TransactionEnvelope could not be decoded from the provided data.
type MalformedTransactionError struct {
EnvelopeXDR string
}
func (err *MalformedTransactionError) Error() string {
return "tx malformed"
}