This repository was archived by the owner on Sep 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
update precompile-xcm #161
Open
gitofdeepanshu
wants to merge
33
commits into
polkadot-v0.9.39
Choose a base branch
from
feat/setAppendix-xcm-precompile
base: polkadot-v0.9.39
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
904470b
add SetAppendix in remote_transact
gitofdeepanshu 401c1ce
formatting abstract params
gitofdeepanshu bcff3fd
update remote_transact()
gitofdeepanshu cc97ce4
remove println
gitofdeepanshu af7fcef
add send_xcm function to precompile
gitofdeepanshu 527b642
fix remote_transact call
gitofdeepanshu 97b60aa
small fixes xcm.sol
gitofdeepanshu 55886ec
fix typos xcm.sol
gitofdeepanshu a9b7a5d
change bytes32 to bytes in send_xcm()
gitofdeepanshu 3df8b14
add test for xcm_call
gitofdeepanshu a064674
fix xcm_send using Bytes
gitofdeepanshu 75a1bea
add multilocation for xcm-precompile
gitofdeepanshu d1c0d56
update licenses
gitofdeepanshu b77fcc2
fix scope issue for String
gitofdeepanshu edc738e
fmt
gitofdeepanshu 450c780
minor refactor, add log:trace
gitofdeepanshu a4cf0be
Empty-Commit
gitofdeepanshu 83ae4ad
make input field in EvmDataReader pub(crate)
gitofdeepanshu 65a22ef
remove setAppendix from remote_transact()
gitofdeepanshu 0171f31
old interface added for legacy support
gitofdeepanshu 6c5a6ea
fmt
gitofdeepanshu 6038c63
add tests for multilocation and bytes
gitofdeepanshu 60bcbb6
data encapsulation fix
gitofdeepanshu 27cd351
newline in tests
gitofdeepanshu 028e3dc
add mock and test::transfer for xtokens
gitofdeepanshu 37aa31c
test: add transfer_multiasset
gitofdeepanshu 8117882
add new functions for xtokens
gitofdeepanshu cd3360e
test: transfer_multi_currencies
gitofdeepanshu fba5ee3
test: transfer_multi_assets
gitofdeepanshu c61f391
test: transfer_multiassets_cannot_insert_more_than_max
gitofdeepanshu 7dafadb
test: transfer_multi_currencies_cannot_insert_more_than_max
gitofdeepanshu 910eee0
more tests and fixes
gitofdeepanshu 6a6b941
typo fix
gitofdeepanshu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,220 @@ | ||
| // This file is part of Astar. | ||
|
|
||
| // Copyright 2019-2022 PureStake Inc. | ||
| // Copyright (C) 2022-2023 Stake Technologies Pte.Ltd. | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| // | ||
| // This file is part of Utils package, originally developed by Purestake Inc. | ||
| // Utils package used in Astar Network in terms of GPLv3. | ||
| // | ||
| // Utils is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
|
|
||
| // Utils is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
|
|
||
| // You should have received a copy of the GNU General Public License | ||
| // along with Utils. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| use super::*; | ||
| use alloc::borrow::ToOwned; | ||
| pub use alloc::string::String; | ||
| use sp_core::{ConstU32, Get}; | ||
|
|
||
| type ConstU32Max = ConstU32<{ u32::MAX }>; | ||
|
|
||
| pub type UnboundedBytes = BoundedBytesString<BytesKind, ConstU32Max>; | ||
| pub type BoundedBytes<S> = BoundedBytesString<BytesKind, S>; | ||
|
|
||
| trait Kind { | ||
| fn signature() -> String; | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct BytesKind; | ||
|
|
||
| impl Kind for BytesKind { | ||
| fn signature() -> String { | ||
| String::from("bytes") | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| pub struct StringKind; | ||
|
|
||
| impl Kind for StringKind { | ||
| fn signature() -> String { | ||
| String::from("string") | ||
| } | ||
| } | ||
|
|
||
| /// The `bytes/string` type of Solidity. | ||
| /// It is different from `Vec<u8>` which will be serialized with padding for each `u8` element | ||
| /// of the array, while `Bytes` is tightly packed. | ||
| #[derive(Debug)] | ||
| pub struct BoundedBytesString<K, S> { | ||
| data: Vec<u8>, | ||
| _phantom: PhantomData<(K, S)>, | ||
| } | ||
|
|
||
| impl<K: Kind, S: Get<u32>> Clone for BoundedBytesString<K, S> { | ||
| fn clone(&self) -> Self { | ||
| Self { | ||
| data: self.data.clone(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<K1, S1, K2, S2> PartialEq<BoundedBytesString<K2, S2>> for BoundedBytesString<K1, S1> { | ||
| fn eq(&self, other: &BoundedBytesString<K2, S2>) -> bool { | ||
| self.data.eq(&other.data) | ||
| } | ||
| } | ||
|
|
||
| impl<K, S> Eq for BoundedBytesString<K, S> {} | ||
|
|
||
| impl<K, S: Get<u32>> BoundedBytesString<K, S> { | ||
| pub fn as_bytes(&self) -> &[u8] { | ||
| &self.data | ||
| } | ||
|
|
||
| pub fn as_str(&self) -> Result<&str, sp_std::str::Utf8Error> { | ||
| sp_std::str::from_utf8(&self.data) | ||
| } | ||
| } | ||
|
|
||
| impl<K: Kind, S: Get<u32>> EvmData for BoundedBytesString<K, S> { | ||
| fn read(reader: &mut EvmDataReader) -> EvmResult<Self> { | ||
| let mut inner_reader = reader.read_pointer()?; | ||
|
|
||
| // Read bytes/string size. | ||
| let array_size: usize = inner_reader | ||
| .read::<U256>() | ||
| .map_err(|_| revert("length, out of bounds"))? | ||
| .try_into() | ||
| .map_err(|_| revert("length, value too large"))?; | ||
|
|
||
| if array_size > S::get() as usize { | ||
| return Err(revert("length, value too large").into()); | ||
| } | ||
|
|
||
| // Get valid range over the bytes data. | ||
| let range = inner_reader.move_cursor(array_size)?; | ||
|
|
||
| let data = inner_reader | ||
| .get_input_from_range(range) | ||
| .ok_or_else(|| revert(K::signature()))?; | ||
|
|
||
| let bytes = Self { | ||
| data: data.to_owned(), | ||
| _phantom: PhantomData, | ||
| }; | ||
|
|
||
| Ok(bytes) | ||
| } | ||
|
|
||
| fn write(writer: &mut EvmDataWriter, value: Self) { | ||
| let value: Vec<_> = value.into(); | ||
| let length = value.len(); | ||
|
|
||
| // Pad the data. | ||
| // Leave it as is if a multiple of 32, otherwise pad to next | ||
| // multiple or 32. | ||
| let chunks = length / 32; | ||
| let padded_size = match length % 32 { | ||
| 0 => chunks * 32, | ||
| _ => (chunks + 1) * 32, | ||
| }; | ||
|
|
||
| let mut value = value.to_vec(); | ||
| value.resize(padded_size, 0); | ||
|
|
||
| writer.write_pointer( | ||
| EvmDataWriter::new() | ||
| .write(U256::from(length)) | ||
| .write_raw_bytes(&value) | ||
| .build(), | ||
| ); | ||
| } | ||
|
|
||
| fn has_static_size() -> bool { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| // BytesString <=> Vec/&[u8] | ||
|
|
||
| impl<K, S> From<BoundedBytesString<K, S>> for Vec<u8> { | ||
| fn from(value: BoundedBytesString<K, S>) -> Self { | ||
| value.data | ||
| } | ||
| } | ||
|
|
||
| impl<K, S> From<Vec<u8>> for BoundedBytesString<K, S> { | ||
| fn from(value: Vec<u8>) -> Self { | ||
| Self { | ||
| data: value, | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<K, S> From<&[u8]> for BoundedBytesString<K, S> { | ||
| fn from(value: &[u8]) -> Self { | ||
| Self { | ||
| data: value.to_vec(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<K, S, const N: usize> From<[u8; N]> for BoundedBytesString<K, S> { | ||
| fn from(value: [u8; N]) -> Self { | ||
| Self { | ||
| data: value.to_vec(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<K, S, const N: usize> From<&[u8; N]> for BoundedBytesString<K, S> { | ||
| fn from(value: &[u8; N]) -> Self { | ||
| Self { | ||
| data: value.to_vec(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // BytesString <=> String/str | ||
|
|
||
| impl<K, S> TryFrom<BoundedBytesString<K, S>> for String { | ||
| type Error = alloc::string::FromUtf8Error; | ||
|
|
||
| fn try_from(value: BoundedBytesString<K, S>) -> Result<Self, Self::Error> { | ||
| alloc::string::String::from_utf8(value.data) | ||
| } | ||
| } | ||
|
|
||
| impl<K, S> From<&str> for BoundedBytesString<K, S> { | ||
| fn from(value: &str) -> Self { | ||
| Self { | ||
| data: value.as_bytes().into(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl<K, S> From<String> for BoundedBytesString<K, S> { | ||
| fn from(value: String) -> Self { | ||
| Self { | ||
| data: value.as_bytes().into(), | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
gitofdeepanshu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.