Skip to content

Commit

Permalink
update xcm-primitives src folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ozgunozerk committed Sep 19, 2024
1 parent 3ed33a7 commit 93c4286
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 488 deletions.
6 changes: 4 additions & 2 deletions primitives/xcm/src/asset_id_conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ where
AssetIdInfoGetter: AssetTypeGetter<AssetId, AssetType>,
{
fn convert(id: &xcm::v4::Location) -> Option<AssetId> {
let v3_location = xcm_builder::WithLatestLocationConverter::<xcm::v3::Location>::convert(id)?;
let v3_location =
xcm_builder::WithLatestLocationConverter::<xcm::v3::Location>::convert(id)?;
AssetIdInfoGetter::get_asset_id(v3_location.clone().into())
}
fn convert_back(what: &AssetId) -> Option<xcm::v4::Location> {
Expand All @@ -66,7 +67,8 @@ where
AssetIdInfoGetter: AssetTypeGetter<AssetId, AssetType>,
{
fn convert_location(id: &xcm::v4::Location) -> Option<AssetId> {
let v3_location = xcm_builder::WithLatestLocationConverter::<xcm::v3::Location>::convert(id)?;
let v3_location =
xcm_builder::WithLatestLocationConverter::<xcm::v3::Location>::convert(id)?;
AssetIdInfoGetter::get_asset_id(v3_location.clone().into())
}
}
Expand Down
2 changes: 1 addition & 1 deletion primitives/xcm/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Moonbeam. If not, see <http://www.gnu.org/licenses/>.

pub const MAX_ASSETS: u32 = 64;
pub const MAX_ASSETS: u32 = 20;
59 changes: 45 additions & 14 deletions primitives/xcm/src/ethereum_xcm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct EthereumXcmTransactionV1 {
pub gas_limit: U256,
/// Fee configuration of choice.
pub fee_payment: EthereumXcmFee,
/// Either a Call (the callee, account or contract address) or Create (currently unsupported).
/// Either a Call (the callee, account or contract address) or Create (unsupported for v1).
pub action: TransactionAction,
/// Value to be transfered.
pub value: U256,
Expand All @@ -93,7 +93,7 @@ pub struct EthereumXcmTransactionV1 {
pub struct EthereumXcmTransactionV2 {
/// Gas limit to be consumed by EVM execution.
pub gas_limit: U256,
/// Either a Call (the callee, account or contract address) or Create (currently unsupported).
/// Either a Call (the callee, account or contract address) or Create).
pub action: TransactionAction,
/// Value to be transfered.
pub value: U256,
Expand All @@ -104,20 +104,34 @@ pub struct EthereumXcmTransactionV2 {
}

pub trait XcmToEthereum {
fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option<TransactionV2>;
fn into_transaction_v2(
&self,
nonce: U256,
chain_id: u64,
allow_create: bool,
) -> Option<TransactionV2>;
}

impl XcmToEthereum for EthereumXcmTransaction {
fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option<TransactionV2> {
fn into_transaction_v2(
&self,
nonce: U256,
chain_id: u64,
allow_create: bool,
) -> Option<TransactionV2> {
match self {
EthereumXcmTransaction::V1(v1_tx) => v1_tx.into_transaction_v2(nonce, chain_id),
EthereumXcmTransaction::V2(v2_tx) => v2_tx.into_transaction_v2(nonce, chain_id),
EthereumXcmTransaction::V1(v1_tx) => {
v1_tx.into_transaction_v2(nonce, chain_id, allow_create)
}
EthereumXcmTransaction::V2(v2_tx) => {
v2_tx.into_transaction_v2(nonce, chain_id, allow_create)
}
}
}
}

impl XcmToEthereum for EthereumXcmTransactionV1 {
fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option<TransactionV2> {
fn into_transaction_v2(&self, nonce: U256, chain_id: u64, _: bool) -> Option<TransactionV2> {
// We dont support creates for now
if self.action == TransactionAction::Create {
return None;
Expand Down Expand Up @@ -195,9 +209,14 @@ impl XcmToEthereum for EthereumXcmTransactionV1 {
}

impl XcmToEthereum for EthereumXcmTransactionV2 {
fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option<TransactionV2> {
// We dont support creates for now
if self.action == TransactionAction::Create {
fn into_transaction_v2(
&self,
nonce: U256,
chain_id: u64,
allow_create: bool,
) -> Option<TransactionV2> {
if !allow_create && self.action == TransactionAction::Create {
// Create not allowed
return None;
}
let from_tuple_to_access_list = |t: &Vec<(H160, Vec<H256>)>| -> AccessList {
Expand Down Expand Up @@ -274,7 +293,10 @@ mod tests {
s: H256::from_low_u64_be(1u64),
}));

assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx);
assert_eq!(
xcm_transaction.into_transaction_v2(nonce, 111, false),
expected_tx
);
}

#[test]
Expand Down Expand Up @@ -302,7 +324,10 @@ mod tests {
signature: TransactionSignature::new(42, rs_id(), rs_id()).unwrap(),
}));

assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx);
assert_eq!(
xcm_transaction.into_transaction_v2(nonce, 111, false),
expected_tx
);
}
#[test]
fn test_eip_2930_v1() {
Expand Down Expand Up @@ -344,7 +369,10 @@ mod tests {
s: H256::from_low_u64_be(1u64),
}));

assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx);
assert_eq!(
xcm_transaction.into_transaction_v2(nonce, 111, false),
expected_tx
);
}

#[test]
Expand Down Expand Up @@ -373,6 +401,9 @@ mod tests {
s: H256::from_low_u64_be(1u64),
}));

assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx);
assert_eq!(
xcm_transaction.into_transaction_v2(nonce, 111, false),
expected_tx
);
}
}
Loading

0 comments on commit 93c4286

Please sign in to comment.