Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions pallets/flexible-fee/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use std::{marker::PhantomData, sync::Arc};
use std::{convert::TryInto, marker::PhantomData, sync::Arc};

pub use bifrost_flexible_fee_rpc_runtime_api::FlexibleFeeRuntimeApi as FeeRuntimeApi;
use codec::{Codec, Decode};
Expand All @@ -31,7 +31,6 @@ use sp_rpc::number::NumberOrHex;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, Zero},
SaturatedConversion,
};

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -125,8 +124,19 @@ where

let rs = api.get_fee_token_and_amount(&at, who, total_inclusion_fee);

let try_into_rpc_balance = |value: Balance| {
value.try_into().map_err(|_| RpcError {
code: ErrorCode::InvalidParams,
message: format!("{} doesn't fit in NumberOrHex representation", value),
data: None,
})
};

match rs {
Ok((id, val)) => Ok((id, NumberOrHex::Number(val.saturated_into()))),
Ok((id, val)) => match try_into_rpc_balance(val) {
Ok(value) => Ok((id, value)),
Err(e) => Err(e),
},
Err(e) => Err(RpcError {
code: ErrorCode::ServerError(Error::RuntimeError.into()),
message: "Unable to query fee token and amount.".into(),
Expand Down