Skip to content

Commit

Permalink
fix: Edits processing (#3)
Browse files Browse the repository at this point in the history
* fix: Bug in edits processing

* fix: Unhandled case in proposal creation

* style: rustfmt
  • Loading branch information
cvauclair authored Nov 28, 2024
1 parent e5f5505 commit 11c495e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions core/proto/ipfs.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ message IpfsMetadata {
// We version the data structured used to represent proposal metadata. Each
// proposal type has their own metadata and versioning that we can change
// independently of other proposal types.
string version = 1;
ActionType type = 2;
ActionType type = 1;
string version = 2;
string id = 3;
string name = 4;
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/pb/ipfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub struct IpfsMetadata {
/// We version the data structured used to represent proposal metadata. Each
/// proposal type has their own metadata and versioning that we can change
/// independently of other proposal types.
#[prost(string, tag="1")]
pub version: ::prost::alloc::string::String,
#[prost(enumeration="ActionType", tag="2")]
#[prost(enumeration="ActionType", tag="1")]
pub r#type: i32,
#[prost(string, tag="2")]
pub version: ::prost::alloc::string::String,
#[prost(string, tag="3")]
pub id: ::prost::alloc::string::String,
#[prost(string, tag="4")]
Expand Down
10 changes: 9 additions & 1 deletion node/src/events/proposal_created.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ impl EventHandler {
let metadata = deserialize::<pb::ipfs::IpfsMetadata>(&bytes)?;

match metadata.r#type() {
pb::ipfs::ActionType::AddEdit => todo!(),
pb::ipfs::ActionType::AddEdit => {
// tracing::warn!(
// "Block #{} ({}): Edit proposal not supported",
// block.block_number,
// block.timestamp
// );
// TODO: Implement edit proposal
// Ok(())
}
pb::ipfs::ActionType::AddSubspace | pb::ipfs::ActionType::RemoveSubspace => {
let subspace_proposal = deserialize::<pb::ipfs::Subspace>(&bytes)?;

Expand Down
15 changes: 11 additions & 4 deletions node/src/events/proposal_processed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ impl EventHandler {
.get_bytes(&proposal_processed.content_uri.replace("ipfs://", ""), true)
.await?;

let metadata = deserialize::<pb::ipfs::IpfsMetadata>(&bytes)?;
let metadata = if let Ok(metadata) = deserialize::<pb::ipfs::IpfsMetadata>(&bytes) {
metadata
} else {
tracing::warn!(
"Invalid metadata for proposal {}",
proposal_processed.content_uri
);
return Ok(vec![]);
};

match metadata.r#type() {
pb::ipfs::ActionType::AddEdit => {
let edit = deserialize::<grc20::Edit>(&bytes)?;
Expand Down Expand Up @@ -111,9 +120,7 @@ impl EventHandler {
})
.collect())
}
action_type => Err(HandlerError::Other(
format!("Invalid proposal action type {action_type:?}").into(),
)),
_ => Ok(vec![]),
}
}
}

0 comments on commit 11c495e

Please sign in to comment.