-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add connectors v2 extrinsics & inbound msg handlers #1364
Changes from 51 commits
333baa1
c1c07d0
d825bf3
a444162
f7d7bed
2c67d1d
ffc8522
f1246d7
0cb33b1
78badd0
9e9013a
21587ef
9c3947d
ac05f8b
20c6af2
6630451
04ade36
61209a4
740067b
6158fca
4c99a90
c3c9d0a
fa64b45
ccb88f9
46cafd4
3c52de6
4f56811
0e83682
b3eea35
24c3952
6d59c69
59ba987
f8d7fab
abc0ed9
40cd1f6
4ba010b
4589410
5396f5f
44469c9
c04a1fe
cbba52c
dbb0502
714cfd9
d4e382d
bd7ed80
a04aef7
a8d9748
4b82591
78e58a3
2860526
2165341
de64a54
a588972
a8d8ad7
fe841c0
036d16a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2021 Centrifuge GmbH (centrifuge.io). | ||
// This file is part of Centrifuge chain project. | ||
|
||
// Centrifuge 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 (see http://www.gnu.org/licenses). | ||
|
||
// Centrifuge 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. | ||
|
||
use codec::Input; | ||
use frame_support::dispatch::DispatchResult; | ||
use sp_std::vec::Vec; | ||
|
||
/// An encoding & decoding trait for the purpose of meeting the | ||
/// Connectors General Message Passing Format | ||
pub trait Codec: Sized { | ||
fn serialize(&self) -> Vec<u8>; | ||
fn deserialize<I: Input>(input: &mut I) -> Result<Self, codec::Error>; | ||
} | ||
|
||
/// The trait required for processing outbound connectors messages. | ||
pub trait OutboundQueue { | ||
// pub trait OutboundQueue<Sender, Message, Destination> { | ||
wischli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// The sender type of the outgoing message. | ||
type Sender; | ||
|
||
/// The message type that is processed. | ||
type Message; | ||
|
||
/// The destination this message should go to. | ||
type Destination; | ||
|
||
/// Submit a message to the outbound queue. | ||
fn submit( | ||
// destination: Destination, | ||
// sender: Sender, | ||
// msg: Message, | ||
wischli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
destination: Self::Destination, | ||
sender: Self::Sender, | ||
msg: Self::Message, | ||
wischli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) -> DispatchResult; | ||
} | ||
|
||
/// The trait required for processing incoming connectors messages. | ||
pub trait InboundQueue { | ||
/// The sender type of the incoming message. | ||
type Sender; | ||
|
||
/// The connector message enum. | ||
type Message; | ||
|
||
/// Process a message from the inbound queue. | ||
fn process(sender: Self::Sender, msg: Self::Message) -> DispatchResult; | ||
wischli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,11 @@ | |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
|
||
use cfg_utils::vec_to_fixed_array; | ||
use codec::{Decode, Encode, MaxEncodedLen}; | ||
use cfg_traits::connectors::Codec; | ||
use cfg_utils::{decode_be_bytes, vec_to_fixed_array}; | ||
use codec::{Decode, Encode, Input, MaxEncodedLen}; | ||
use scale_info::TypeInfo; | ||
use sp_core::TypeId; | ||
use sp_std::{vec, vec::Vec}; | ||
|
||
use crate::EVMChainId; | ||
|
||
|
@@ -32,15 +33,38 @@ pub enum Domain { | |
EVM(EVMChainId), | ||
} | ||
|
||
impl Codec for Domain { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: Moved from |
||
fn serialize(&self) -> Vec<u8> { | ||
match self { | ||
Self::Centrifuge => vec![0; 9], | ||
Self::EVM(chain_id) => { | ||
let mut output: Vec<u8> = 1u8.encode(); | ||
output.append(&mut chain_id.to_be_bytes().to_vec()); | ||
|
||
output | ||
} | ||
} | ||
} | ||
|
||
fn deserialize<I: Input>(input: &mut I) -> Result<Self, codec::Error> { | ||
let variant = input.read_byte()?; | ||
|
||
match variant { | ||
0 => Ok(Self::Centrifuge), | ||
1 => { | ||
let chain_id = decode_be_bytes::<8, _, _>(input)?; | ||
Ok(Self::EVM(chain_id)) | ||
} | ||
_ => Err(codec::Error::from("Unknown Domain variant")), | ||
} | ||
} | ||
} | ||
|
||
#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)] | ||
pub struct DomainLocator<Domain> { | ||
pub domain: Domain, | ||
} | ||
|
||
impl<Domain> TypeId for DomainLocator<Domain> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NOTE: Moved to |
||
const TYPE_ID: [u8; 4] = *b"domn"; | ||
} | ||
|
||
#[derive(Encode, Decode, Clone, PartialEq, Eq, TypeInfo, MaxEncodedLen)] | ||
#[cfg_attr(feature = "std", derive(Debug))] | ||
pub enum DomainAddress { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: Moved from
pallets/connectors/src
as requested.