Skip to content

Commit 518aa8d

Browse files
committed
feat(lazer) Add response messages for lazer transactions
1 parent ca62063 commit 518aa8d

File tree

4 files changed

+60
-15
lines changed

4 files changed

+60
-15
lines changed

lazer/Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/publisher_sdk/proto/pyth_lazer_transaction.proto

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,26 @@ message LazerTransaction {
8888
GovernanceInstruction governance_instruction = 2;
8989
}
9090
}
91+
92+
// Response to SignedLazerTransactionResponse from the relayer
93+
message SignedLazerTransactionResponse {
94+
// [required] The ID of a transaction derived as sha256 of the payload.
95+
optional bytes transaction_id = 1;
96+
97+
// [required] Status of the transaction received by the relayer
98+
oneof status {
99+
// The transaction was accepted by the relayer
100+
SignedLazerTransactionAccepted accepted = 2;
101+
// The transaction was rejected by the relayer
102+
SignedLazerTransactionRejected rejected = 3;
103+
}
104+
105+
// Message containing additional details for accepted transactions
106+
message SignedLazerTransactionAccepted {}
107+
108+
// Message containing details why the transaction was rejected
109+
message SignedLazerTransactionRejected {
110+
// [required] Human readable error message
111+
optional string message = 1;
112+
}
113+
}

lazer/publisher_sdk/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pyth-lazer-protocol = { version = "0.7.2", path = "../../sdk/rust/protocol" }
1111
anyhow = "1.0.98"
1212
protobuf = "3.7.2"
1313
serde-value = "0.7.0"
14+
sha2 = "0.10.9"
1415
humantime = "2.2.0"
15-
tracing = "0.1.41"
1616

1717
[build-dependencies]
1818
fs-err = "3.1.0"

lazer/publisher_sdk/rust/src/lib.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::{collections::BTreeMap, time::Duration};
22

3-
use ::protobuf::MessageField;
3+
use crate::transaction::SignedLazerTransaction;
4+
use ::protobuf::{Message, MessageField};
45
use anyhow::{bail, ensure, Context};
56
use humantime::format_duration;
67
use protobuf::dynamic_value::{dynamic_value, DynamicValue};
78
use pyth_lazer_protocol::router::TimestampUs;
9+
use sha2::{Digest, Sha256};
810

911
pub mod transaction_envelope {
1012
pub use crate::protobuf::transaction_envelope::*;
@@ -160,3 +162,23 @@ impl TryFrom<DynamicValue> for serde_value::Value {
160162
}
161163
}
162164
}
165+
166+
impl SignedLazerTransaction {
167+
// The id of a SignedLazerTransaction is calculated as sha256 of its entire payload. This is
168+
// an unstable ID (sensitive to any proto changes) are should only be used to correlate
169+
// immediate responses sent from the relayer
170+
pub fn id(&self) -> anyhow::Result<[u8; 32]> {
171+
let mut hasher = Sha256::new();
172+
self.write_to_writer(&mut hasher)?;
173+
hasher
174+
.finalize()
175+
.try_into()
176+
.context("failed to calculate the sha256 as transaction id")
177+
}
178+
179+
pub fn calculate_id_from_bytes(payload: &Vec<u8>) -> anyhow::Result<[u8; 32]> {
180+
Ok(Sha256::digest(payload)
181+
.try_into()
182+
.context("failed to calculate the sha256 as transaction id")?)
183+
}
184+
}

0 commit comments

Comments
 (0)