Skip to content

Commit

Permalink
Improve errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Neopallium committed Nov 21, 2024
1 parent d3cc12d commit 4cad66a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions rust/chains/tw_polkadot/src/call_encoder/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl GenericBalances {
match &b.message_oneof {
BalanceVariant::transfer(t) => Self::encode_transfer(ctx, t),
BalanceVariant::asset_transfer(t) => Self::encode_asset_transfer(ctx, t),
_ => Err(EncodeError::InvalidCallIndex),
_ => Err(EncodeError::NotSupported),
}
}
}
Expand Down Expand Up @@ -229,7 +229,7 @@ impl GenericStaking {
StakingVariant::withdraw_unbonded(b) => Self::encode_withdraw_unbonded(b),
StakingVariant::rebond(b) => Self::encode_rebond(b),
StakingVariant::nominate(b) => Self::encode_nominate(ctx, b),
_ => Err(EncodeError::InvalidCallIndex),
_ => Err(EncodeError::NotSupported),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/tw_polkadot/src/call_encoder/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl TWPolkadotCallEncoder for PolkadotCallEncoder {
GenericStaking::encode_call(&self.0, s)?.map(PolkadotCall::Staking)
},
_ => {
return Err(EncodeError::InvalidCallIndex);
return Err(EncodeError::NotSupported);
},
};
Ok(RawOwned(call.to_scale()))
Expand Down Expand Up @@ -70,7 +70,7 @@ impl TWPolkadotCallEncoder for KusamaCallEncoder {
GenericStaking::encode_call(&self.0, s)?.map(KusamaCall::Staking)
},
_ => {
return Err(EncodeError::InvalidCallIndex);
return Err(EncodeError::NotSupported);
},
};
Ok(RawOwned(call.to_scale()))
Expand Down
10 changes: 5 additions & 5 deletions rust/chains/tw_polkadot/src/call_encoder/polymesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl PolymeshBalances {
pub fn encode_call(b: &Balance) -> WithCallIndexResult<Self> {
match &b.message_oneof {
BalanceVariant::transfer(t) => Self::encode_transfer(t),
_ => Err(EncodeError::InvalidCallIndex),
_ => Err(EncodeError::NotSupported),
}
}
}
Expand Down Expand Up @@ -175,7 +175,7 @@ impl PolymeshIdentity {
match &ident.message_oneof {
IdentityVariant::join_identity_as_key(t) => Self::encode_join_identity(t),
IdentityVariant::add_authorization(a) => Self::encode_add_authorization(a),
_ => Err(EncodeError::InvalidCallIndex),
_ => Err(EncodeError::NotSupported),
}
}
}
Expand Down Expand Up @@ -295,7 +295,7 @@ impl PolymeshStaking {
StakingVariant::withdraw_unbonded(b) => Self::encode_withdraw_unbonded(b),
StakingVariant::rebond(b) => Self::encode_rebond(b),
StakingVariant::nominate(b) => Self::encode_nominate(b),
_ => Err(EncodeError::InvalidCallIndex),
_ => Err(EncodeError::NotSupported),
}
}
}
Expand Down Expand Up @@ -329,14 +329,14 @@ impl TWPolkadotCallEncoder for PolymeshCallEncoder {
PolymeshIdentity::encode_call(msg)?.map(PolymeshCall::Identity)
},
PolymeshVariant::None => {
return Err(EncodeError::InvalidCallIndex);
return Err(EncodeError::NotSupported);
},
},
SigningVariant::staking_call(s) => {
PolymeshStaking::encode_call(s)?.map(PolymeshCall::Staking)
},
SigningVariant::None => {
return Err(EncodeError::InvalidCallIndex);
return Err(EncodeError::NotSupported);
},
};
Ok(RawOwned(call.to_scale()))
Expand Down
2 changes: 1 addition & 1 deletion rust/frameworks/tw_substrate/src/extrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl CallIndex {

pub fn required_from_tw(call_index: Option<(i32, i32)>) -> Result<Self, EncodeError> {
if call_index.is_none() {
return Err(EncodeError::MissingCallIndicesTable);
return Err(EncodeError::MissingCallIndices);
}
Self::from_tw(call_index)
}
Expand Down
6 changes: 4 additions & 2 deletions rust/frameworks/tw_substrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ pub use extensions::*;
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum EncodeError {
InvalidNetworkId,
MissingCallIndicesTable,
MissingCallIndices,
InvalidCallIndex,
InvalidAddress,
InvalidValue,
NotSupported,
}

impl From<EncodeError> for SigningError {
Expand All @@ -31,7 +32,8 @@ impl From<EncodeError> for SigningError {
TWError::new(match err {
EncodeError::InvalidAddress => SigningErrorType::Error_invalid_address,
EncodeError::InvalidValue => SigningErrorType::Error_input_parse,
EncodeError::MissingCallIndicesTable => SigningErrorType::Error_not_supported,
EncodeError::MissingCallIndices => SigningErrorType::Error_not_supported,
EncodeError::NotSupported => SigningErrorType::Error_not_supported,
_ => SigningErrorType::Error_invalid_params,
})
.context(format!("{err:?}"))
Expand Down

0 comments on commit 4cad66a

Please sign in to comment.