@@ -15,14 +15,15 @@ use blake2::{
15
15
VarBlake2b ,
16
16
} ;
17
17
use datasize:: DataSize ;
18
- use failure:: Fail ;
19
18
use rand:: {
20
19
distributions:: { Distribution , Standard } ,
21
20
Rng ,
22
21
} ;
23
22
#[ cfg( feature = "std" ) ]
24
23
use schemars:: { gen:: SchemaGenerator , schema:: Schema , JsonSchema } ;
25
24
use serde:: { de:: Error as SerdeError , Deserialize , Deserializer , Serialize , Serializer } ;
25
+ #[ cfg( feature = "std" ) ]
26
+ use thiserror:: Error ;
26
27
27
28
use crate :: {
28
29
bytesrepr:: { Error , FromBytes , ToBytes , U8_SERIALIZED_LENGTH } ,
@@ -106,22 +107,33 @@ impl TryFrom<u32> for ActionType {
106
107
/// Errors that can occur while changing action thresholds (i.e. the total [`Weight`]s of signing
107
108
/// [`AccountHash`]s required to perform various actions) on an account.
108
109
#[ repr( i32 ) ]
109
- #[ derive( Debug , Fail , PartialEq , Eq , Copy , Clone ) ]
110
+ #[ derive( Debug , PartialEq , Eq , Copy , Clone ) ]
111
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
110
112
pub enum SetThresholdFailure {
111
113
/// Setting the key-management threshold to a value lower than the deployment threshold is
112
114
/// disallowed.
113
- #[ fail( display = "New threshold should be greater than or equal to deployment threshold" ) ]
115
+ #[ cfg_attr(
116
+ feature = "std" ,
117
+ error( "New threshold should be greater than or equal to deployment threshold" )
118
+ ) ]
114
119
KeyManagementThreshold = 1 ,
115
120
/// Setting the deployment threshold to a value greater than any other threshold is disallowed.
116
- #[ fail( display = "New threshold should be lower than or equal to key management threshold" ) ]
121
+ #[ cfg_attr(
122
+ feature = "std" ,
123
+ error( "New threshold should be lower than or equal to key management threshold" )
124
+ ) ]
117
125
DeploymentThreshold = 2 ,
118
126
/// Caller doesn't have sufficient permissions to set new thresholds.
119
- #[ fail( display = "Unable to set action threshold due to insufficient permissions" ) ]
127
+ #[ cfg_attr(
128
+ feature = "std" ,
129
+ error( "Unable to set action threshold due to insufficient permissions" )
130
+ ) ]
120
131
PermissionDeniedError = 3 ,
121
132
/// Setting a threshold to a value greater than the total weight of associated keys is
122
133
/// disallowed.
123
- #[ fail(
124
- display = "New threshold should be lower or equal than total weight of associated keys"
134
+ #[ cfg_attr(
135
+ feature = "std" ,
136
+ error( "New threshold should be lower or equal than total weight of associated keys" )
125
137
) ]
126
138
InsufficientTotalWeight = 4 ,
127
139
}
@@ -396,19 +408,29 @@ impl Distribution<AccountHash> for Standard {
396
408
}
397
409
398
410
/// Errors that can occur while adding a new [`AccountHash`] to an account's associated keys map.
399
- #[ derive( PartialEq , Eq , Fail , Debug , Copy , Clone ) ]
411
+ #[ derive( PartialEq , Eq , Debug , Copy , Clone ) ]
412
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
400
413
#[ repr( i32 ) ]
401
414
pub enum AddKeyFailure {
402
415
/// There are already [`MAX_ASSOCIATED_KEYS`] [`AccountHash`]s associated with the given
403
416
/// account.
404
- #[ fail( display = "Unable to add new associated key because maximum amount of keys is reached" ) ]
417
+ #[ cfg_attr(
418
+ feature = "std" ,
419
+ error( "Unable to add new associated key because maximum amount of keys is reached" )
420
+ ) ]
405
421
MaxKeysLimit = 1 ,
406
422
/// The given [`AccountHash`] is already associated with the given account.
407
- #[ fail( display = "Unable to add new associated key because given key already exists" ) ]
423
+ #[ cfg_attr(
424
+ feature = "std" ,
425
+ error( "Unable to add new associated key because given key already exists" )
426
+ ) ]
408
427
DuplicateKey = 2 ,
409
428
/// Caller doesn't have sufficient permissions to associate a new [`AccountHash`] with the
410
429
/// given account.
411
- #[ fail( display = "Unable to add new associated key due to insufficient permissions" ) ]
430
+ #[ cfg_attr(
431
+ feature = "std" ,
432
+ error( "Unable to add new associated key due to insufficient permissions" )
433
+ ) ]
412
434
PermissionDenied = 3 ,
413
435
}
414
436
@@ -428,19 +450,26 @@ impl TryFrom<i32> for AddKeyFailure {
428
450
}
429
451
430
452
/// Errors that can occur while removing a [`AccountHash`] from an account's associated keys map.
431
- #[ derive( Fail , Debug , Eq , PartialEq , Copy , Clone ) ]
453
+ #[ derive( Debug , Eq , PartialEq , Copy , Clone ) ]
454
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
432
455
#[ repr( i32 ) ]
433
456
pub enum RemoveKeyFailure {
434
457
/// The given [`AccountHash`] is not associated with the given account.
435
- #[ fail ( display = "Unable to remove a key that does not exist" ) ]
458
+ #[ cfg_attr ( feature = "std" , error ( " Unable to remove a key that does not exist") ) ]
436
459
MissingKey = 1 ,
437
460
/// Caller doesn't have sufficient permissions to remove an associated [`AccountHash`] from the
438
461
/// given account.
439
- #[ fail( display = "Unable to remove associated key due to insufficient permissions" ) ]
462
+ #[ cfg_attr(
463
+ feature = "std" ,
464
+ error( "Unable to remove associated key due to insufficient permissions" )
465
+ ) ]
440
466
PermissionDenied = 2 ,
441
467
/// Removing the given associated [`AccountHash`] would cause the total weight of all remaining
442
468
/// `AccountHash`s to fall below one of the action thresholds for the given account.
443
- #[ fail( display = "Unable to remove a key which would violate action threshold constraints" ) ]
469
+ #[ cfg_attr(
470
+ feature = "std" ,
471
+ error( "Unable to remove a key which would violate action threshold constraints" )
472
+ ) ]
444
473
ThresholdViolation = 3 ,
445
474
}
446
475
@@ -465,20 +494,30 @@ impl TryFrom<i32> for RemoveKeyFailure {
465
494
466
495
/// Errors that can occur while updating the [`Weight`] of a [`AccountHash`] in an account's
467
496
/// associated keys map.
468
- #[ derive( PartialEq , Eq , Fail , Debug , Copy , Clone ) ]
497
+ #[ derive( PartialEq , Eq , Debug , Copy , Clone ) ]
498
+ #[ cfg_attr( feature = "std" , derive( Error ) ) ]
469
499
#[ repr( i32 ) ]
470
500
pub enum UpdateKeyFailure {
471
501
/// The given [`AccountHash`] is not associated with the given account.
472
- #[ fail( display = "Unable to update the value under an associated key that does not exist" ) ]
502
+ #[ cfg_attr(
503
+ feature = "std" ,
504
+ error( "Unable to update the value under an associated key that does not exist" )
505
+ ) ]
473
506
MissingKey = 1 ,
474
507
/// Caller doesn't have sufficient permissions to update an associated [`AccountHash`] from the
475
508
/// given account.
476
- #[ fail( display = "Unable to update associated key due to insufficient permissions" ) ]
509
+ #[ cfg_attr(
510
+ feature = "std" ,
511
+ error( "Unable to update associated key due to insufficient permissions" )
512
+ ) ]
477
513
PermissionDenied = 2 ,
478
514
/// Updating the [`Weight`] of the given associated [`AccountHash`] would cause the total
479
515
/// weight of all `AccountHash`s to fall below one of the action thresholds for the given
480
516
/// account.
481
- #[ fail( display = "Unable to update weight that would fall below any of action thresholds" ) ]
517
+ #[ cfg_attr(
518
+ feature = "std" ,
519
+ error( "Unable to update weight that would fall below any of action thresholds" )
520
+ ) ]
482
521
ThresholdViolation = 3 ,
483
522
}
484
523
0 commit comments