Skip to content
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

fix: Edits processing #3

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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![]),
}
}
}