Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions porteer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,34 @@ pub mod pallet {
/// The XcmFeeConfig has been set.
XcmFeeConfigSet { fees: XcmFeeParams<BalanceOf<T>> },
/// Ported some tokens to the destination chain.
PortedTokens { who: AccountIdOf<T>, amount: BalanceOf<T> },
PortedTokens {
who: AccountIdOf<T>,
amount: BalanceOf<T>,
source_nonce: PortTokensNonceOf<T>,
},
/// Minted some tokens ported from another chain!
MintedPortedTokens {
who: AccountIdOf<T>,
amount: BalanceOf<T>,
source_nonce: PortTokensNonceOf<T>,
},
/// Forwarded some minted tokens to another location.
ForwardedPortedTokens { who: AccountIdOf<T>, amount: BalanceOf<T>, location: T::Location },
ForwardedPortedTokens {
who: AccountIdOf<T>,
amount: BalanceOf<T>,
location: T::Location,
source_nonce: PortTokensNonceOf<T>,
},
/// Failed to forward the tokens to the final destination.
FailedToForwardTokens { who: AccountIdOf<T>, amount: BalanceOf<T>, location: T::Location },
FailedToForwardTokens {
who: AccountIdOf<T>,
amount: BalanceOf<T>,
location: T::Location,
source_nonce: PortTokensNonceOf<T>,
},
/// Tried to forward the tokens to an illegal destination, hence the operation was
/// aborted (tokens were successfully minted on this chain though).
IllegalForwardingLocation { location: T::Location },
IllegalForwardingLocation { location: T::Location, source_nonce: PortTokensNonceOf<T> },
}

#[pallet::error]
Expand Down Expand Up @@ -419,7 +433,7 @@ pub mod pallet {
Fortitude::Polite,
)?;

let nonce = PortTokensNonce::<T>::mutate(|n| {
let source_nonce = PortTokensNonce::<T>::mutate(|n| {
*n = n.saturating_add(1u32.into());
*n
});
Expand All @@ -428,14 +442,14 @@ pub mod pallet {
signer.clone(),
amount,
forward_tokens_to_location,
nonce,
source_nonce,
)
.map_err(|e| {
log::error!(target: LOG_TARGET, "Port tokens error: {:?}", e);
Error::<T>::PortTokensInitError
})?;

Self::deposit_event(Event::<T>::PortedTokens { who: signer, amount });
Self::deposit_event(Event::<T>::PortedTokens { who: signer, amount, source_nonce });
Ok(())
}

Expand Down Expand Up @@ -473,15 +487,20 @@ pub mod pallet {
who: beneficiary.clone(),
amount,
location: l,
source_nonce,
}),
Err(_) => Self::deposit_event(Event::<T>::FailedToForwardTokens {
who: beneficiary.clone(),
amount,
location: l,
source_nonce,
}),
}
} else {
Self::deposit_event(Event::<T>::IllegalForwardingLocation { location: l })
Self::deposit_event(Event::<T>::IllegalForwardingLocation {
location: l,
source_nonce,
})
}
}
Ok(())
Expand Down
2 changes: 2 additions & 0 deletions porteer/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ fn minting_ported_tokens_with_forwarding_non_whitelisted_location_preserves_bala

let expected_event = RuntimeEvent::Porteer(PorteerEvent::IllegalForwardingLocation {
location: WHITELISTED_LOCATION,
source_nonce: 0,
});
assert!(System::events().iter().any(|a| a.event == expected_event));

Expand Down Expand Up @@ -527,6 +528,7 @@ fn minting_ported_tokens_with_forwarding_to_unsupported_location_preserves_balan
who: bob.clone(),
amount: mint_amount,
location: WHITELISTED_BUT_UNSUPPORTED_LOCATION,
source_nonce: 0,
});
assert!(System::events().iter().any(|a| a.event == expected_event));

Expand Down
Loading