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

upgrade the pin protobufs, so that CID is optional #21

Merged
merged 2 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
2 changes: 2 additions & 0 deletions proto/gevulot/gevulot/pin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ message PinSpec {
message PinStatus {
repeated string assignedWorkers = 1;
repeated PinAck workerAcks = 2;
string cid = 3;
}

message PinAck {
string worker = 1;
uint64 blockHeight = 2;
bool success = 3;
}
7 changes: 6 additions & 1 deletion proto/gevulot/gevulot/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,15 @@ message MsgCreatePin {
repeated string fallback_urls = 10;
}

message MsgCreatePinResponse {}
message MsgCreatePinResponse {
string id = 1;
}

message MsgDeletePin {
option (cosmos.msg.v1.signer) = "creator";
string creator = 1;
string cid = 2;
string id = 3;
}

message MsgDeletePinResponse {}
Expand All @@ -253,6 +256,8 @@ message MsgAckPin {
string creator = 1;
string workerId = 2;
string cid = 3;
string id = 4;
bool success = 5;
}

message MsgAckPinResponse {}
Expand Down
6 changes: 6 additions & 0 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ impl MsgCreatePinBuilder {
pub struct MsgDeletePin {
pub creator: String,
pub cid: String,
pub id: String,
}

impl MsgDeletePinBuilder {
Expand All @@ -195,6 +196,7 @@ impl MsgDeletePinBuilder {
Ok(gevulot::MsgDeletePin {
creator: msg.creator,
cid: msg.cid,
id: msg.id,
})
}
}
Expand Down Expand Up @@ -253,7 +255,9 @@ impl MsgDeleteWorkerBuilder {
pub struct MsgAckPin {
pub creator: String,
pub cid: String,
pub id: String,
pub worker_id: String,
pub success: bool,
}

impl MsgAckPinBuilder {
Expand All @@ -264,7 +268,9 @@ impl MsgAckPinBuilder {
Ok(gevulot::MsgAckPin {
creator: msg.creator,
cid: msg.cid,
id: msg.id,
worker_id: msg.worker_id,
success: msg.success,
})
}
}
Expand Down
32 changes: 32 additions & 0 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ impl GevulotEvent {
})
.filter(|url| !url.is_empty())
.collect::<Vec<String>>();
let id = event
.attributes
.iter()
.find(|attr| attr.key_bytes() == b"id")
.map(|attr| attr.value_str().unwrap_or_default().to_string())
.unwrap_or_else(|| cid.clone());

Ok(GevulotEvent::Pin(PinEvent::Create(PinCreateEvent {
block_height,
Expand All @@ -432,6 +438,7 @@ impl GevulotEvent {
assigned_workers,
retention_period,
fallback_urls,
id,
})))
}
"delete-pin" => {
Expand All @@ -449,11 +456,18 @@ impl GevulotEvent {
.ok_or(Error::MissingEventAttribute("creator"))?
.value_str()?
.to_string();
let id = event
.attributes
.iter()
.find(|attr| attr.key_bytes() == b"id")
.map(|attr| attr.value_str().unwrap_or_default().to_string())
.unwrap_or_else(|| cid.clone());

Ok(GevulotEvent::Pin(PinEvent::Delete(PinDeleteEvent {
block_height,
cid,
creator,
id,
})))
}
"ack-pin" => {
Expand All @@ -478,11 +492,25 @@ impl GevulotEvent {
.ok_or(Error::MissingEventAttribute("creator"))?
.value_str()?
.to_string();
let success = event
.attributes
.iter()
.find(|attr| attr.key_bytes() == b"success")
.map(|attr| attr.value_str().unwrap_or("true").parse().unwrap_or(true))
.unwrap_or(true);
let id = event
.attributes
.iter()
.find(|attr| attr.key_bytes() == b"id")
.map(|attr| attr.value_str().unwrap_or_default().to_string())
.unwrap_or_else(|| cid.clone());
Ok(GevulotEvent::Pin(PinEvent::Ack(PinAckEvent {
block_height,
cid,
worker_id,
creator,
success,
id,
})))
}
_ => Err(Error::UnknownEventKind(event.kind.clone())),
Expand All @@ -494,6 +522,7 @@ impl GevulotEvent {
pub struct PinCreateEvent {
pub block_height: Height,
pub cid: String,
pub id: String,
pub creator: String,
pub assigned_workers: Vec<String>,
pub retention_period: u64,
Expand All @@ -504,15 +533,18 @@ pub struct PinCreateEvent {
pub struct PinDeleteEvent {
pub block_height: Height,
pub cid: String,
pub id: String,
pub creator: String,
}

#[derive(Clone, Debug)]
pub struct PinAckEvent {
pub block_height: Height,
pub cid: String,
pub id: String,
pub creator: String,
pub worker_id: String,
pub success: bool,
}

#[derive(Clone, Debug)]
Expand Down