Skip to content

Commit

Permalink
Use try from over truncate from
Browse files Browse the repository at this point in the history
  • Loading branch information
KarishmaBothara committed Apr 5, 2024
1 parent 140a047 commit cd9ed41
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions evm-precompiles/marketplace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ where
.collect::<Result<Vec<(SerialNumber, Balance)>, PrecompileFailure>>()?;

let serial_numbers: BoundedVec<(SerialNumber, Balance), Runtime::MaxTokensPerListing> =
BoundedVec::truncate_from(serials_unbounded);
BoundedVec::try_from(serials_unbounded)
.or_else(|_| Err(revert("Marketplace: Too many serial numbers")))?;
let tokens = ListingTokens::Sft(SftListing { collection_id, serial_numbers });
let buyer: H160 = buyer.into();
let buyer: Option<Runtime::AccountId> =
Expand Down Expand Up @@ -763,7 +764,8 @@ where
.collect::<Result<Vec<(SerialNumber, Balance)>, PrecompileFailure>>()?;

let serial_numbers: BoundedVec<(SerialNumber, Balance), Runtime::MaxTokensPerListing> =
BoundedVec::truncate_from(serials_unbounded);
BoundedVec::try_from(serials_unbounded)
.or_else(|_| Err(revert("Marketplace: Too many serial numbers")))?;
let tokens = ListingTokens::Sft(SftListing { collection_id, serial_numbers });

handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
Expand Down

0 comments on commit cd9ed41

Please sign in to comment.