forked from coinbase/mesh-bitcoin
/
errors.go
211 lines (186 loc) · 5.81 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
// Copyright 2020 Coinbase, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package services
import (
"github.com/coinbase/rosetta-sdk-go/types"
)
var (
// Errors contains all errors that could be returned
// by this Rosetta implementation.
Errors = []*types.Error{
ErrUnimplemented,
ErrUnavailableOffline,
ErrNotReady,
ErrRavend,
ErrBlockNotFound,
ErrUnableToDerive,
ErrUnclearIntent,
ErrUnableToParseIntermediateResult,
ErrScriptPubKeysMissing,
ErrInvalidCoin,
ErrUnableToDecodeAddress,
ErrUnableToDecodeScriptPubKey,
ErrUnableToCalculateSignatureHash,
ErrUnsupportedScriptType,
ErrUnableToComputePkScript,
ErrUnableToGetCoins,
ErrTransactionNotFound,
ErrCouldNotGetFeeRate,
ErrUnableToGetBalance,
}
// ErrUnimplemented is returned when an endpoint
// is called that is not implemented.
ErrUnimplemented = &types.Error{
Code: 0, //nolint
Message: "Endpoint not implemented",
}
// ErrUnavailableOffline is returned when an endpoint
// is called that is not available offline.
ErrUnavailableOffline = &types.Error{
Code: 1, //nolint
Message: "Endpoint unavailable offline",
}
// ErrNotReady is returned when ravend is not
// yet ready to serve queries.
ErrNotReady = &types.Error{
Code: 2, //nolint
Message: "Ravend is not ready",
Retriable: true,
}
// ErrRavend is returned when ravend
// errors on a request.
ErrRavend = &types.Error{
Code: 3, //nolint
Message: "Ravend error",
}
// ErrBlockNotFound is returned when a block
// is not available in the indexer.
ErrBlockNotFound = &types.Error{
Code: 4, //nolint
Message: "Block not found",
}
// ErrUnableToDerive is returned when an address
// cannot be derived from a provided public key.
ErrUnableToDerive = &types.Error{
Code: 5, //nolint
Message: "Unable to derive address",
}
// ErrUnclearIntent is returned when operations
// provided in /construction/preprocess or /construction/payloads
// are not valid.
ErrUnclearIntent = &types.Error{
Code: 6, //nolint
Message: "Unable to parse intent",
}
// ErrUnableToParseIntermediateResult is returned
// when a data structure passed between Construction
// API calls is not valid.
ErrUnableToParseIntermediateResult = &types.Error{
Code: 7, //nolint
Message: "Unable to parse intermediate result",
}
// ErrScriptPubKeysMissing is returned when
// the indexer cannot populate the required
// ravencoin.ScriptPubKeys to construct a transaction.
ErrScriptPubKeysMissing = &types.Error{
Code: 8, //nolint
Message: "Missing ScriptPubKeys",
}
// ErrInvalidCoin is returned when a *types.Coin
// cannot be parsed during construction.
ErrInvalidCoin = &types.Error{
Code: 9, //nolint
Message: "Coin is invalid",
}
// ErrUnableToDecodeAddress is returned when an address
// cannot be parsed during construction.
ErrUnableToDecodeAddress = &types.Error{
Code: 10, //nolint
Message: "Unable to decode address",
}
// ErrUnableToDecodeScriptPubKey is returned when a
// ravencoin.ScriptPubKey cannot be parsed during construction.
ErrUnableToDecodeScriptPubKey = &types.Error{
Code: 11, //nolint
Message: "Unable to decode ScriptPubKey",
}
// ErrUnableToCalculateSignatureHash is returned
// when some payload to sign cannot be generated.
ErrUnableToCalculateSignatureHash = &types.Error{
Code: 12, //nolint
Message: "Unable to calculate signature hash",
}
// ErrUnsupportedScriptType is returned when
// trying to sign an input with an unsupported
// script type.
ErrUnsupportedScriptType = &types.Error{
Code: 13, //nolint
Message: "Script type is not supported",
}
// ErrUnableToComputePkScript is returned
// when trying to compute the PkScript in
// ConsructionParse.
ErrUnableToComputePkScript = &types.Error{
Code: 14, //nolint
Message: "Unable to compute PK script",
}
// ErrUnableToGetCoins is returned by the indexer
// when it is not possible to get the coins
// owned by a *types.AccountIdentifier.
ErrUnableToGetCoins = &types.Error{
Code: 15, //nolint
Message: "Unable to get coins",
}
// ErrTransactionNotFound is returned by the indexer
// when it is not possible to find a transaction.
ErrTransactionNotFound = &types.Error{
Code: 16, // nolint
Message: "Transaction not found",
}
// ErrCouldNotGetFeeRate is returned when the fetch
// to get the suggested fee rate fails.
ErrCouldNotGetFeeRate = &types.Error{
Code: 17, // nolint
Message: "Could not get suggested fee rate",
}
// ErrUnableToGetBalance is returned by the indexer
// when it is not possible to get the balance
// of a *types.AccountIdentifier.
ErrUnableToGetBalance = &types.Error{
Code: 18, //nolint
Message: "Unable to get balance",
}
// ErrCouldNotGetBestBlock is returned when the fetch
// to get the best block heigth.
ErrCouldNotGetBestBlock = &types.Error{
Code: 19, // nolint
Message: "Could not get best block height",
}
)
// wrapErr adds details to the types.Error provided. We use a function
// to do this so that we don't accidentially overrwrite the standard
// errors.
func wrapErr(rErr *types.Error, err error) *types.Error {
newErr := &types.Error{
Code: rErr.Code,
Message: rErr.Message,
Retriable: rErr.Retriable,
}
if err != nil {
newErr.Details = map[string]interface{}{
"context": err.Error(),
}
}
return newErr
}