git.delta.rocks / unique-network / refs/commits / 9252b2e53bcd

difftreelog

path: Add check for address length.

Trubnikov Sergey2022-08-05parent: #a0a04c8.patch.diff
in: master

2 files changed

modifiedpallets/common/src/eth.rsdiffbeforeafterboth
1616
17//! The module contains a number of functions for converting and checking ethereum identifiers.17//! The module contains a number of functions for converting and checking ethereum identifiers.
1818
19use evm_coder::{types::*};19use evm_coder::{types::uint256, execution::Result};
20pub use pallet_evm::account::CrossAccountId;20pub use pallet_evm::account::CrossAccountId;
21use sp_core::H160;21use sp_core::H160;
22use up_data_structs::CollectionId;22use up_data_structs::CollectionId;
53}53}
5454
55/// Convert `CrossAccountId` to `uint256`.55/// Convert `CrossAccountId` to `uint256`.
56pub fn convert_cross_account_to_eth_uint256<T: Config>(from: &T::CrossAccountId) -> uint25656pub fn convert_cross_account_to_eth_uint256<T: Config>(from: &T::CrossAccountId) -> Result<uint256>
57where57where
58 T::AccountId: AsRef<[u8]>,58 T::AccountId: AsRef<[u8]>,
59{59{
62 uint256::from_big_endian(slice)62 uint256::from_big_endian(slice)
63}63}
64
65/// Converts Substrate address to CrossAccountId
66pub fn convert_substrate_address_to_cross_account_id<T: Config>(
67 address: uint256,
68) -> T::CrossAccountId
69where
70 T::AccountId: From<[u8; 32]>,
71{
72 let mut address_arr: [u8; 32] = Default::default();
73 address.to_big_endian(&mut address_arr);
74 let account_id = T::AccountId::from(address_arr);
75 T::CrossAccountId::from_sub(account_id)
76}
7764
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
110 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {110 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {
111 let sponsor =111 let sponsor =
112 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;112 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;
113 let sponsor_sub = pallet_common::eth::convert_cross_account_to_eth_uint256::<T>(&sponsor);113 let sponsor_sub = pallet_common::eth::convert_cross_account_to_eth_uint256::<T>(&sponsor)?;
114 Ok((*sponsor.as_eth(), sponsor_sub))114 Ok((*sponsor.as_eth(), sponsor_sub))
115 }115 }
116116