-
Notifications
You must be signed in to change notification settings - Fork 819
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sort out AccountId<>Location conversion
- Loading branch information
Showing
7 changed files
with
47 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
use snowbridge_outbound_queue_primitives::Log; | ||
use crate::Log; | ||
|
||
use sp_core::{RuntimeDebug, H160}; | ||
use sp_std::prelude::*; | ||
|
@@ -15,33 +15,39 @@ sol! { | |
|
||
/// An inbound message that has had its outer envelope decoded. | ||
#[derive(Clone, RuntimeDebug)] | ||
pub struct Envelope { | ||
pub struct MessageReceipt<AccountId> | ||
where | ||
AccountId: From<[u8; 32]> + Clone | ||
{ | ||
/// The address of the outbound queue on Ethereum that emitted this message as an event log | ||
pub gateway: H160, | ||
/// A nonce for enforcing replay protection and ordering. | ||
/// The nonce of the dispatched message | ||
pub nonce: u64, | ||
/// Delivery status | ||
pub success: bool, | ||
/// The reward address | ||
pub reward_address: [u8; 32], | ||
pub reward_address: AccountId, | ||
} | ||
|
||
#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)] | ||
pub enum EnvelopeDecodeError { | ||
pub enum MessageReceiptDecodeError { | ||
DecodeLogFailed, | ||
DecodeAccountFailed, | ||
} | ||
|
||
impl TryFrom<&Log> for Envelope { | ||
type Error = EnvelopeDecodeError; | ||
impl<AccountId> TryFrom<&Log> for MessageReceipt<AccountId> | ||
where | ||
AccountId: From<[u8; 32]> + Clone | ||
{ | ||
type Error = MessageReceiptDecodeError; | ||
|
||
fn try_from(log: &Log) -> Result<Self, Self::Error> { | ||
let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect(); | ||
|
||
let event = InboundMessageDispatched::decode_raw_log(topics, &log.data, true) | ||
.map_err(|_| EnvelopeDecodeError::DecodeLogFailed)?; | ||
.map_err(|_| MessageReceiptDecodeError::DecodeLogFailed)?; | ||
|
||
let account = event.reward_address.into(); | ||
let account: AccountId = AccountId::from(event.reward_address.0); | ||
|
||
Ok(Self { | ||
gateway: log.address, | ||
|
This file contains 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 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