difftreelog
refactor remove unnecessary reencoding in CE
in: master
1 file changed
runtime/src/chain_extension.rsdiffbeforeafterboth44impl<C: Config> ChainExtension<C> for NFTExtension {44impl<C: Config> ChainExtension<C> for NFTExtension {45 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>45 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>46 where46 where47 E: Ext<T = C>,47 <E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,48 <E::T as SysConfig>::AccountId: UncheckedFrom<<E::T as SysConfig>::Hash> + AsRef<[u8]>,48 {49 {49 // The memory of the vm stores buf in scale-codec50 // The memory of the vm stores buf in scale-codec52 let mut env = env.buf_in_buf_out();53 let mut env = env.buf_in_buf_out();53 let input: NFTExtTransfer<E> = env.read_as()?;54 let input: NFTExtTransfer<E> = env.read_as()?;5455 // Sender to AccountId3256 let mut bytes_sender: [u8; 32] = [0; 32];57 let addr_vec_sender: Vec<u8> = env.ext().caller().encode();58 for i in 0..32 {59 bytes_sender[i] = addr_vec_sender[i];60 }61 let sender = AccountId32::from(bytes_sender);6263 // Recipient to AccountId3264 let mut bytes_rec: [u8; 32] = [0; 32];65 let addr_vec_rec: Vec<u8> = input.recipient.encode();66 for i in 0..32 {67 bytes_rec[i] = addr_vec_rec[i];68 }69 let recipient = AccountId32::from(bytes_rec);705571 let collection = pallet_nft::Module::<Runtime>::get_collection(input.collection_id)?;56 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;725773 match pallet_nft::Module::<Runtime>::transfer_internal(sender, recipient, &collection, input.token_id, input.amount) {58 match pallet_nft::Module::<C>::transfer_internal(59 env.ext().caller().clone(),60 input.recipient,61 &collection,62 input.token_id,63 input.amount,64 ) {74 Ok(_) => Ok(RetVal::Converging(func_id)),65 Ok(_) => Ok(RetVal::Converging(func_id)),75 _ => Err(DispatchError::Other("Transfer error"))66 _ => Err(DispatchError::Other("Transfer error"))80 let mut env = env.buf_in_buf_out();71 let mut env = env.buf_in_buf_out();81 let input: NFTExtCreateItem<E> = env.read_as()?;72 let input: NFTExtCreateItem<E> = env.read_as()?;8283 // Contract address to AccountId3284 let mut bytes_contract: [u8; 32] = [0; 32];85 let addr_vec_contract: Vec<u8> = env.ext().address().encode();86 for i in 0..32 {87 bytes_contract[i] = addr_vec_contract[i];88 }89 let sender = AccountId32::from(bytes_contract);9091 // Recipient to AccountId3292 let mut bytes_rec: [u8; 32] = [0; 32];93 let addr_vec_rec: Vec<u8> = input.owner.encode();94 for i in 0..32 {95 bytes_rec[i] = addr_vec_rec[i];96 }97 let recipient = AccountId32::from(bytes_rec);9899 // Parse data100 let cdata = input.data.encode();101 let vdata: [u8; 0] = [0; 0];102 let item_data = CreateItemData::NFT(CreateNftData{103 const_data: cdata,104 variable_data: vdata.to_vec()105 });10673107 match pallet_nft::Module::<Runtime>::create_item_internal(sender, input.collection_id, recipient, item_data) {74 match pallet_nft::Module::<C>::create_item_internal(75 env.ext().address().clone(),76 input.collection_id,77 input.owner,78 input.data,79 ) {108 Ok(_) => Ok(RetVal::Converging(func_id)),80 Ok(_) => Ok(RetVal::Converging(func_id)),109 _ => Err(DispatchError::Other("CreateItem error"))81 _ => Err(DispatchError::Other("CreateItem error"))