mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 17:31:05 +00:00
Relay subcommand that performs token RLT <> MLAU token swap (#1141)
* token swap relay * token swap subcommand fixes * fmt * removed debug traces * removed commented code
This commit is contained in:
committed by
Bastian Köcher
parent
2db84b74cc
commit
5dbf6ba78c
@@ -777,12 +777,11 @@ pub mod pallet {
|
||||
/// messages and lanes states proofs.
|
||||
pub mod storage_keys {
|
||||
use super::*;
|
||||
use frame_support::StorageHasher;
|
||||
use sp_core::storage::StorageKey;
|
||||
|
||||
/// Storage key of the outbound message in the runtime storage.
|
||||
pub fn message_key(pallet_prefix: &str, lane: &LaneId, nonce: MessageNonce) -> StorageKey {
|
||||
storage_map_final_key(
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(
|
||||
pallet_prefix,
|
||||
"OutboundMessages",
|
||||
&MessageKey { lane_id: *lane, nonce }.encode(),
|
||||
@@ -791,28 +790,12 @@ pub mod storage_keys {
|
||||
|
||||
/// Storage key of the outbound message lane state in the runtime storage.
|
||||
pub fn outbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey {
|
||||
storage_map_final_key(pallet_prefix, "OutboundLanes", lane)
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(pallet_prefix, "OutboundLanes", lane)
|
||||
}
|
||||
|
||||
/// Storage key of the inbound message lane state in the runtime storage.
|
||||
pub fn inbound_lane_data_key(pallet_prefix: &str, lane: &LaneId) -> StorageKey {
|
||||
storage_map_final_key(pallet_prefix, "InboundLanes", lane)
|
||||
}
|
||||
|
||||
/// This is a copypaste of the `frame_support::storage::generator::StorageMap::storage_map_final_key`.
|
||||
fn storage_map_final_key(pallet_prefix: &str, map_name: &str, key: &[u8]) -> StorageKey {
|
||||
let pallet_prefix_hashed = frame_support::Twox128::hash(pallet_prefix.as_bytes());
|
||||
let storage_prefix_hashed = frame_support::Twox128::hash(map_name.as_bytes());
|
||||
let key_hashed = frame_support::Blake2_128Concat::hash(key);
|
||||
|
||||
let mut final_key =
|
||||
Vec::with_capacity(pallet_prefix_hashed.len() + storage_prefix_hashed.len() + key_hashed.len());
|
||||
|
||||
final_key.extend_from_slice(&pallet_prefix_hashed[..]);
|
||||
final_key.extend_from_slice(&storage_prefix_hashed[..]);
|
||||
final_key.extend_from_slice(key_hashed.as_ref());
|
||||
|
||||
StorageKey(final_key)
|
||||
bp_runtime::storage_map_final_key_blake2_128concat(pallet_prefix, "InboundLanes", lane)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,12 +56,11 @@ use bp_messages::{
|
||||
DeliveredMessages, LaneId, MessageNonce,
|
||||
};
|
||||
use bp_runtime::{messages::DispatchFeePayment, ChainId};
|
||||
use bp_token_swap::{TokenSwap, TokenSwapType};
|
||||
use codec::{Decode, Encode};
|
||||
use bp_token_swap::{TokenSwap, TokenSwapState, TokenSwapType};
|
||||
use codec::Encode;
|
||||
use frame_support::{
|
||||
fail,
|
||||
traits::{Currency, ExistenceRequirement},
|
||||
RuntimeDebug,
|
||||
};
|
||||
use sp_core::H256;
|
||||
use sp_io::hashing::blake2_256;
|
||||
@@ -71,22 +70,11 @@ use sp_std::vec::Vec;
|
||||
#[cfg(test)]
|
||||
mod mock;
|
||||
|
||||
/// Pending token swap state.
|
||||
#[derive(Encode, Decode, Clone, RuntimeDebug, PartialEq, Eq)]
|
||||
pub enum TokenSwapState {
|
||||
/// The swap has been started using the `start_claim` call, but we have no proof that it has
|
||||
/// happened at the Bridged chain.
|
||||
Started,
|
||||
/// The swap has happened at the Bridged chain and may be claimed by the Bridged chain party using
|
||||
/// the `claim_swap` call.
|
||||
Confirmed,
|
||||
/// The swap has failed at the Bridged chain and This chain party may cancel it using the
|
||||
/// `cancel_swap` call.
|
||||
Failed,
|
||||
}
|
||||
|
||||
pub use pallet::*;
|
||||
|
||||
/// Name of the `PendingSwaps` storage map.
|
||||
pub const PENDING_SWAPS_MAP_NAME: &str = "PendingSwaps";
|
||||
|
||||
// comes from #[pallet::event]
|
||||
#[allow(clippy::unused_unit)]
|
||||
#[frame_support::pallet]
|
||||
@@ -324,6 +312,13 @@ pub mod pallet {
|
||||
return sp_runtime::TransactionOutcome::Rollback(Err(Error::<T, I>::SwapAlreadyStarted.into()));
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
target: "runtime::bridge-token-swap",
|
||||
"The swap {:?} (hash {:?}) has been started",
|
||||
swap,
|
||||
swap_hash,
|
||||
);
|
||||
|
||||
// remember that we're waiting for the transfer message delivery confirmation
|
||||
PendingMessages::<T, I>::insert(transfer_message_nonce, swap_hash);
|
||||
|
||||
@@ -475,14 +470,21 @@ pub mod pallet {
|
||||
reads += 1;
|
||||
if let Some(swap_hash) = PendingMessages::<T, I>::take(message_nonce) {
|
||||
writes += 1;
|
||||
PendingSwaps::<T, I>::insert(
|
||||
|
||||
let token_swap_state = if delivered_messages.message_dispatch_result(message_nonce) {
|
||||
TokenSwapState::Confirmed
|
||||
} else {
|
||||
TokenSwapState::Failed
|
||||
};
|
||||
|
||||
log::trace!(
|
||||
target: "runtime::bridge-token-swap",
|
||||
"The dispatch of swap {:?} has been completed with {:?} status",
|
||||
swap_hash,
|
||||
if delivered_messages.message_dispatch_result(message_nonce) {
|
||||
TokenSwapState::Confirmed
|
||||
} else {
|
||||
TokenSwapState::Failed
|
||||
},
|
||||
token_swap_state,
|
||||
);
|
||||
|
||||
PendingSwaps::<T, I>::insert(swap_hash, token_swap_state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -534,6 +536,18 @@ pub mod pallet {
|
||||
));
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
target: "runtime::bridge-token-swap",
|
||||
"The swap {:?} (hash {:?}) has been completed with {} status",
|
||||
swap,
|
||||
swap_hash,
|
||||
match event {
|
||||
Event::SwapClaimed(_) => "claimed",
|
||||
Event::SwapCancelled(_) => "cancelled",
|
||||
_ => "<unknown>",
|
||||
},
|
||||
);
|
||||
|
||||
// forget about swap
|
||||
PendingSwaps::<T, I>::remove(swap_hash);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user