Skip to content
Open
Changes from 1 commit
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
41 changes: 26 additions & 15 deletions src/sinks/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,38 @@ impl gasket::framework::Worker<Stage> for Worker {

async fn execute(&mut self, unit: &ChainEvent, stage: &mut Stage) -> Result<(), WorkerError> {
let point = unit.point().clone();
let record = unit.record().cloned();

if record.is_none() {
return Ok(());
}

let body = serde_json::Value::from(record.unwrap());

let point_header = match &point {
Point::Origin => String::from("origin"),
Point::Specific(a, b) => format!("{a},{}", hex::encode(b)),
};

let request = self
.client
.post(&stage.config.url)
.header("x-oura-chainsync-action", "apply")
.header("x-oura-chainsync-point", point_header)
.json(&body)
.build()
.or_panic()?;
let request = match unit {
ChainEvent::Apply(_, record) => {
let body = serde_json::Value::from(record.clone());
self.client
.post(&stage.config.url)
.header("x-oura-chainsync-action", "apply")
.header("x-oura-chainsync-point", point_header)
.json(&body)
}
ChainEvent::Undo(_, record) => {
let body = serde_json::Value::from(record.clone());
self.client
.post(&stage.config.url)
.header("x-oura-chainsync-action", "undo")
.header("x-oura-chainsync-point", point_header)
.json(&body)
}

ChainEvent::Reset(_) => self
.client
.post(&stage.config.url)
.header("x-oura-chainsync-action", "reset")
.header("x-oura-chainsync-point", point_header),
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
}
.build()
.or_panic()?;

self.client
.execute(request)
Expand Down
Loading