8
8
#include < eosio/chain/chain_config.hpp>
9
9
#include < eosio/chain/transaction.hpp>
10
10
#include < eosio/chain/asset.hpp>
11
+ #include < eosio/chain/exceptions.hpp>
11
12
#include < fc/io/raw.hpp>
12
13
#include < boost/algorithm/string/predicate.hpp>
13
14
#include < fc/io/varint.hpp>
@@ -109,8 +110,8 @@ namespace eosio { namespace chain {
109
110
structs[st.name ] = st;
110
111
111
112
for ( const auto & td : abi.types ) {
112
- FC_ASSERT (_is_type (td.type , 0 , deadline, max_serialization_time), " invalid type" , (" type" ,td.type ));
113
- FC_ASSERT (!_is_type (td.new_type_name , 0 , deadline, max_serialization_time), " type already exists" , (" new_type_name" ,td.new_type_name ));
113
+ EOS_ASSERT (_is_type (td.type , 0 , deadline, max_serialization_time), invalid_type_inside_abi , " invalid type" , (" type" ,td.type ));
114
+ EOS_ASSERT (!_is_type (td.new_type_name , 0 , deadline, max_serialization_time), duplicate_abi_type_def_exception , " type already exists" , (" new_type_name" ,td.new_type_name ));
114
115
typedefs[td.new_type_name ] = td.type ;
115
116
}
116
117
@@ -127,11 +128,11 @@ namespace eosio { namespace chain {
127
128
* The ABI vector may contain duplicates which would make it
128
129
* an invalid ABI
129
130
*/
130
- FC_ASSERT ( typedefs.size () == abi.types .size () );
131
- FC_ASSERT ( structs.size () == abi.structs .size () );
132
- FC_ASSERT ( actions.size () == abi.actions .size () );
133
- FC_ASSERT ( tables.size () == abi.tables .size () );
134
- FC_ASSERT ( error_messages.size () == abi.error_messages .size () );
131
+ EOS_ASSERT ( typedefs.size () == abi.types .size (), duplicate_abi_type_def_exception, " duplicate type definition detected " );
132
+ EOS_ASSERT ( structs.size () == abi.structs .size (), duplicate_abi_struct_def_exception, " duplicate struct definition detected " );
133
+ EOS_ASSERT ( actions.size () == abi.actions .size (), duplicate_abi_action_def_exception, " duplicate action definition detected " );
134
+ EOS_ASSERT ( tables.size () == abi.tables .size (), duplicate_abi_table_def_exception, " duplicate table definition detected " );
135
+ EOS_ASSERT ( error_messages.size () == abi.error_messages .size (), duplicate_abi_err_msg_def_exception, " duplicate error message definition detected " );
135
136
136
137
validate (deadline, max_serialization_time);
137
138
}
@@ -147,7 +148,7 @@ namespace eosio { namespace chain {
147
148
148
149
int abi_serializer::get_integer_size (const type_name& type) const {
149
150
string stype = type;
150
- FC_ASSERT ( is_integer (type), " ${stype} is not an integer type" , (" stype" ,stype));
151
+ EOS_ASSERT ( is_integer (type), invalid_type_inside_abi , " ${stype} is not an integer type" , (" stype" ,stype));
151
152
if ( boost::starts_with (stype, " uint" ) ) {
152
153
return boost::lexical_cast<int >(stype.substr (4 ));
153
154
} else {
@@ -178,7 +179,7 @@ namespace eosio { namespace chain {
178
179
}
179
180
180
181
bool abi_serializer::_is_type (const type_name& rtype, size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time)const {
181
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
182
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
182
183
if ( ++recursion_depth > max_recursion_depth) return false ;
183
184
auto type = fundamental_type (rtype);
184
185
if ( built_in_types.find (type) != built_in_types.end () ) return true ;
@@ -189,7 +190,7 @@ namespace eosio { namespace chain {
189
190
190
191
const struct_def& abi_serializer::get_struct (const type_name& type)const {
191
192
auto itr = structs.find (resolve_type (type) );
192
- FC_ASSERT ( itr != structs.end (), " Unknown struct ${type}" , (" type" ,type) );
193
+ EOS_ASSERT ( itr != structs.end (), invalid_type_inside_abi , " Unknown struct ${type}" , (" type" ,type) );
193
194
return itr->second ;
194
195
}
195
196
@@ -198,40 +199,40 @@ namespace eosio { namespace chain {
198
199
vector<type_name> types_seen{t.first , t.second };
199
200
auto itr = typedefs.find (t.second );
200
201
while ( itr != typedefs.end () ) {
201
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
202
- FC_ASSERT ( find (types_seen.begin (), types_seen.end (), itr->second ) == types_seen.end (), " Circular reference in type ${type}" , (" type" ,t.first ) );
202
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
203
+ EOS_ASSERT ( find (types_seen.begin (), types_seen.end (), itr->second ) == types_seen.end (), abi_circular_def_exception , " Circular reference in type ${type}" , (" type" ,t.first ) );
203
204
types_seen.emplace_back (itr->second );
204
205
itr = typedefs.find (itr->second );
205
206
}
206
207
} FC_CAPTURE_AND_RETHROW ( (t) ) }
207
208
for ( const auto & t : typedefs ) { try {
208
- FC_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time), " " , (" type" ,t.second ) );
209
+ EOS_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time), invalid_type_inside_abi , " " , (" type" ,t.second ) );
209
210
} FC_CAPTURE_AND_RETHROW ( (t) ) }
210
211
for ( const auto & s : structs ) { try {
211
212
if ( s.second .base != type_name () ) {
212
213
struct_def current = s.second ;
213
214
vector<type_name> types_seen{current.name };
214
215
while ( current.base != type_name () ) {
215
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
216
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
216
217
const auto & base = get_struct (current.base ); // <-- force struct to inherit from another struct
217
- FC_ASSERT ( find (types_seen.begin (), types_seen.end (), base.name ) == types_seen.end (), " Circular reference in struct ${type}" , (" type" ,s.second .name ) );
218
+ EOS_ASSERT ( find (types_seen.begin (), types_seen.end (), base.name ) == types_seen.end (), abi_circular_def_exception , " Circular reference in struct ${type}" , (" type" ,s.second .name ) );
218
219
types_seen.emplace_back (base.name );
219
220
current = base;
220
221
}
221
222
}
222
223
for ( const auto & field : s.second .fields ) { try {
223
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
224
- FC_ASSERT (_is_type (field.type , 0 , deadline, max_serialization_time) );
224
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
225
+ EOS_ASSERT (_is_type (field.type , 0 , deadline, max_serialization_time), invalid_type_inside_abi, " " , ( " type " ,field. type ) );
225
226
} FC_CAPTURE_AND_RETHROW ( (field) ) }
226
227
} FC_CAPTURE_AND_RETHROW ( (s) ) }
227
228
for ( const auto & a : actions ) { try {
228
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
229
- FC_ASSERT (_is_type (a.second , 0 , deadline, max_serialization_time), " " , (" type" ,a.second ) );
229
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
230
+ EOS_ASSERT (_is_type (a.second , 0 , deadline, max_serialization_time), invalid_type_inside_abi , " " , (" type" ,a.second ) );
230
231
} FC_CAPTURE_AND_RETHROW ( (a) ) }
231
232
232
233
for ( const auto & t : tables ) { try {
233
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
234
- FC_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time), " " , (" type" ,t.second ) );
234
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
235
+ EOS_ASSERT (_is_type (t.second , 0 , deadline, max_serialization_time), invalid_type_inside_abi , " " , (" type" ,t.second ) );
235
236
} FC_CAPTURE_AND_RETHROW ( (t) ) }
236
237
}
237
238
@@ -251,8 +252,8 @@ namespace eosio { namespace chain {
251
252
fc::mutable_variant_object& obj, size_t recursion_depth,
252
253
const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
253
254
{
254
- FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
255
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
255
+ EOS_ASSERT ( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception , " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
256
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
256
257
const auto & st = get_struct (type);
257
258
if ( st.base != type_name () ) {
258
259
_binary_to_variant (resolve_type (st.base ), stream, obj, recursion_depth, deadline, max_serialization_time);
@@ -265,8 +266,8 @@ namespace eosio { namespace chain {
265
266
fc::variant abi_serializer::_binary_to_variant ( const type_name& type, fc::datastream<const char *>& stream,
266
267
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
267
268
{
268
- FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
269
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
269
+ EOS_ASSERT ( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception , " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
270
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
270
271
type_name rtype = resolve_type (type);
271
272
auto ftype = fundamental_type (rtype);
272
273
auto btype = built_in_types.find (ftype );
@@ -279,12 +280,13 @@ namespace eosio { namespace chain {
279
280
vector<fc::variant> vars;
280
281
for ( decltype (size.value ) i = 0 ; i < size; ++i ) {
281
282
auto v = _binary_to_variant (ftype, stream, recursion_depth, deadline, max_serialization_time);
282
- FC_ASSERT ( !v.is_null (), " Invalid packed array" );
283
+ EOS_ASSERT ( !v.is_null (), unpack_exception , " Invalid packed array" );
283
284
vars.emplace_back (std::move (v));
284
285
}
285
- FC_ASSERT ( vars.size () == size.value ,
286
- " packed size does not match unpacked array size, packed size ${p} actual size ${a}" ,
287
- (" p" , size)(" a" , vars.size ()) );
286
+ EOS_ASSERT ( vars.size () == size.value ,
287
+ unpack_exception,
288
+ " packed size does not match unpacked array size, packed size ${p} actual size ${a}" ,
289
+ (" p" , size)(" a" , vars.size ()) );
288
290
return fc::variant ( std::move (vars) );
289
291
} else if ( is_optional (rtype) ) {
290
292
char flag;
@@ -294,24 +296,24 @@ namespace eosio { namespace chain {
294
296
295
297
fc::mutable_variant_object mvo;
296
298
_binary_to_variant (rtype, stream, mvo, recursion_depth, deadline, max_serialization_time);
297
- FC_ASSERT ( mvo.size () > 0 , " Unable to unpack stream ${type}" , (" type" , type) );
299
+ EOS_ASSERT ( mvo.size () > 0 , unpack_exception , " Unable to unpack stream ${type}" , (" type" , type) );
298
300
return fc::variant ( std::move (mvo) );
299
301
}
300
302
301
303
fc::variant abi_serializer::_binary_to_variant ( const type_name& type, const bytes& binary,
302
304
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
303
305
{
304
- FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
305
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
306
+ EOS_ASSERT ( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception , " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
307
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
306
308
fc::datastream<const char *> ds ( binary.data (), binary.size () );
307
309
return _binary_to_variant (type, ds, recursion_depth, deadline, max_serialization_time);
308
310
}
309
311
310
312
void abi_serializer::_variant_to_binary ( const type_name& type, const fc::variant& var, fc::datastream<char *>& ds,
311
313
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
312
314
{ try {
313
- FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
314
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
315
+ EOS_ASSERT ( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception , " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
316
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
315
317
auto rtype = resolve_type (type);
316
318
317
319
auto btype = built_in_types.find (fundamental_type (rtype));
@@ -339,14 +341,12 @@ namespace eosio { namespace chain {
339
341
else {
340
342
_variant_to_binary (field.type , fc::variant (), ds, recursion_depth, deadline, max_serialization_time);
341
343
// / TODO: default construct field and write it out
342
- FC_THROW ( " Missing '${f}' in variant object" , (" f" ,field.name ) );
344
+ EOS_THROW ( pack_exception, " Missing '${f}' in variant object" , (" f" ,field.name ) );
343
345
}
344
346
}
345
347
} else if ( var.is_array () ) {
346
348
const auto & va = var.get_array ();
347
-
348
- FC_ASSERT ( st.base == type_name (), " support for base class as array not yet implemented" );
349
-
349
+ EOS_ASSERT ( st.base == type_name (), invalid_type_inside_abi, " support for base class as array not yet implemented" );
350
350
uint32_t i = 0 ;
351
351
if (va.size () > 0 ) {
352
352
for ( const auto & field : st.fields ) {
@@ -364,8 +364,8 @@ namespace eosio { namespace chain {
364
364
bytes abi_serializer::_variant_to_binary ( const type_name& type, const fc::variant& var,
365
365
size_t recursion_depth, const fc::time_point& deadline, const fc::microseconds& max_serialization_time )const
366
366
{ try {
367
- FC_ASSERT ( ++recursion_depth < max_recursion_depth, " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
368
- FC_ASSERT ( fc::time_point::now () < deadline, " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
367
+ EOS_ASSERT ( ++recursion_depth < max_recursion_depth, abi_recursion_depth_exception , " recursive definition, max_recursion_depth ${r} " , (" r" , max_recursion_depth) );
368
+ EOS_ASSERT ( fc::time_point::now () < deadline, abi_serialization_deadline_exception , " serialization time limit ${t}us exceeded" , (" t" , max_serialization_time) );
369
369
if ( !_is_type (type, recursion_depth, deadline, max_serialization_time) ) {
370
370
return var.as <bytes>();
371
371
}
0 commit comments