Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
feat: replace TokenSent event with CrossSubnetMessageSent (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastiendan authored May 3, 2023
1 parent 841a49a commit df8d0ec
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 63 deletions.
28 changes: 27 additions & 1 deletion crates/topos-sequencer-subnet-client/abi/IToposCore.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
"name": "CertStored",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "SubnetId",
"name": "targetSubnetId",
"type": "bytes32"
}
],
"name": "CrossSubnetMessageSent",
"type": "event"
},
{
"anonymous": false,
"inputs": [
Expand Down Expand Up @@ -116,6 +129,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "SubnetId",
"name": "targetSubnetId",
"type": "bytes32"
}
],
"name": "emitCrossSubnetMessage",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -405,4 +431,4 @@
"stateMutability": "nonpayable",
"type": "function"
}
]
]
7 changes: 1 addition & 6 deletions crates/topos-sequencer-subnet-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ pub type Hash = String;
/// Event collected from the sending subnet
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum SubnetEvent {
TokenSent {
sender: Address,
source_subnet_id: SubnetId,
CrossSubnetMessageSent {
target_subnet_id: SubnetId,
receiver: Address,
symbol: String,
amount: ethereum_types::U256,
},
ContractCall {
source_subnet_id: SubnetId,
Expand Down
61 changes: 6 additions & 55 deletions crates/topos-sequencer-subnet-client/src/subnet_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,22 @@ pub(crate) fn parse_events_from_log(
for log in &logs {
if let Some(event) = get_event_type_from_log(events, log) {
match event.name.as_str() {
"TokenSent" => {
// Parse TokenSent event
let sender = ethabi::decode(
vec![event.inputs[0].kind.clone()].as_slice(),
&log.topics[1].0,
)?;
"CrossSubnetMessageSent" => {
// Parse CrossSubnetMessageSent event
let event_arguments = web3::ethabi::decode(
&event
.inputs
.iter()
.skip(1)
.map(|i| i.kind.clone())
.collect::<Vec<ParamType>>(),
&log.data.0,
)?;
let send_token_event = SubnetEvent::TokenSent {
sender: if let ethabi::Token::Address(address) = sender[0] {
address.into()
} else {
return Err(Error::InvalidArgument {
message: "invalid sender address".to_string(),
});
},
source_subnet_id: if let ethabi::Token::FixedBytes(bytes) =
&event_arguments[0]
{
match bytes.as_slice().try_into() {
Ok(sender) => sender,
Err(_) => {
return Err(Error::InvalidArgument {
message: "invalid source subnet id".to_string(),
});
}
}
} else {
return Err(Error::InvalidArgument {
message: "invalid source subnet id".to_string(),
});
},
let cross_subnet_message_event = SubnetEvent::CrossSubnetMessageSent {
target_subnet_id: if let ethabi::Token::FixedBytes(bytes) =
&event_arguments[1]
&event_arguments[0]
{
match bytes.as_slice().try_into() {
Ok(sender) => sender,
Ok(target_subnet_id) => target_subnet_id,
Err(_) => {
return Err(Error::InvalidArgument {
message: "invalid target subnet id".to_string(),
Expand All @@ -103,29 +75,8 @@ pub(crate) fn parse_events_from_log(
message: "invalid target subnet id".to_string(),
});
},
receiver: if let ethabi::Token::Address(address) = event_arguments[2] {
address.into()
} else {
return Err(Error::InvalidArgument {
message: "invalid receiver address".to_string(),
});
},
symbol: if let ethabi::Token::String(symbol) = &event_arguments[3] {
symbol.clone()
} else {
return Err(Error::InvalidArgument {
message: "invalid symbol".to_string(),
});
},
amount: if let web3::ethabi::Token::Uint(value) = event_arguments[4] {
value
} else {
return Err(Error::InvalidArgument {
message: "invalid amount event argument".to_string(),
});
},
};
result.push(send_token_event);
result.push(cross_subnet_message_event);
}
"ContractCall" => {
// Parse ContractCall event
Expand Down
2 changes: 1 addition & 1 deletion crates/topos-sequencer-subnet-runtime/src/certification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl Certification {
let mut target_subnets: Vec<SubnetId> = Vec::new();
for event in &block_info.events {
match event {
SubnetEvent::TokenSent {
SubnetEvent::CrossSubnetMessageSent {
target_subnet_id, ..
} => {
target_subnets.push(*target_subnet_id);
Expand Down

0 comments on commit df8d0ec

Please sign in to comment.