Skip to content

Commit 7d5f891

Browse files
authored
fix(pyth-lazer-puiblisher-sdk): Add Deployment Script (#2587)
* output publisher update types * run publish script to test imports * update publish script * Update export paths * Return files to normal * fix rm build command * add publish command * update publish ci * bump publisher sdk version * remove build from cargo.toml and use python for updating lib * fix rust test suite * add build sbf * pin 94 for proc macro and update toolchain * try v94 again for proc macro 2 * update workflow again * try using later toolchain for anchor install * update solana version * try 95 * revert some changes to workflow and pin v95 there too * try no idl * use 82 on anchor and try suggestion * undo changes to solana test workflow * add impl for timestampus * undo change to proc macro version * remove build sbf step * address pr comment
1 parent 25a3789 commit 7d5f891

File tree

8 files changed

+59
-5
lines changed

8 files changed

+59
-5
lines changed

.github/workflows/ci-lazer-rust.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: install extra tools
3131
run: |
3232
cargo install --locked [email protected]
33-
sudo apt-get install -y protobuf-compiler
33+
sudo apt-get update && sudo apt-get install -y protobuf-compiler
3434
- name: Install Solana Cli
3535
run: |
3636
sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"

.github/workflows/publish-rust-lazer-publisher-sdk.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout sources
1414
uses: actions/checkout@v2
1515

16-
- run: cargo publish --token ${CARGO_REGISTRY_TOKEN}
16+
- run: publish.sh
1717
env:
1818
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
1919
working-directory: "lazer/publisher_sdk/rust"

lazer/Cargo.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/publisher_sdk/rust/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
[package]
22
name = "pyth-lazer-publisher-sdk"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "Pyth Lazer Publisher SDK types."
66
license = "Apache-2.0"
77
repository = "https://github.com/pyth-network/pyth-crosschain"
8-
build = "build.rs"
98

109
[dependencies]
1110
protobuf = "3.7.2"

lazer/publisher_sdk/rust/publish.sh

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
set -e
3+
4+
PACKAGE_DIR="."
5+
6+
echo "building package to generate type files"
7+
OUT_DIR=$(cargo build --message-format=json | jq -r 'select(.reason == "build-script-executed") | .out_dir' | grep "pyth-lazer-publisher-sdk")
8+
9+
echo "using output directory: ${OUT_DIR}"
10+
11+
echo "copying files from protobuf output to package directory"
12+
cp -r "${OUT_DIR}/protobuf" "${PACKAGE_DIR}/src/"
13+
14+
echo "deleting build.rs file"
15+
rm -f "${PACKAGE_DIR}/build.rs"
16+
17+
echo "updating lib.rs to export local protobuf files"
18+
python3 -c "
19+
import re
20+
21+
def replace_mod_protobuf(file_path):
22+
with open(file_path, 'r') as f:
23+
content = f.read()
24+
25+
pattern = re.compile(r'mod\s+protobuf\s*\{.*?\}', re.DOTALL)
26+
27+
replacement = 'mod protobuf;'
28+
29+
new_content = pattern.sub(replacement, content)
30+
31+
with open(file_path, 'w') as f:
32+
f.write(new_content)
33+
34+
replace_mod_protobuf('${PACKAGE_DIR}/src/lib.rs')
35+
"
36+
37+
echo "publishing package"
38+
cargo publish --token ${CARGO_REGISTRY_TOKEN}

lazer/publisher_sdk/rust/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ pub mod transaction {
22
pub use crate::protobuf::pyth_lazer_transaction::*;
33
}
44

5+
pub mod publisher_update {
6+
pub use crate::protobuf::publisher_update::*;
7+
}
8+
59
mod protobuf {
610
include!(concat!(env!("OUT_DIR"), "/protobuf/mod.rs"));
711
}

lazer/sdk/rust/protocol/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ derive_more = { version = "1.0.0", features = ["from"] }
1515
itertools = "0.13.0"
1616
rust_decimal = "1.36.0"
1717
base64 = "0.22.1"
18+
protobuf = "3.7.2"
1819

1920
[dev-dependencies]
2021
bincode = "1.3.3"

lazer/sdk/rust/protocol/src/router.rs

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use {
44
crate::payload::AggregatedPriceFeedData,
55
anyhow::{bail, Context},
66
itertools::Itertools,
7+
protobuf::well_known_types::timestamp::Timestamp,
78
rust_decimal::{prelude::FromPrimitive, Decimal},
89
serde::{de::Error, Deserialize, Serialize},
910
std::{
@@ -26,6 +27,16 @@ pub struct ChannelId(pub u8);
2627
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
2728
pub struct TimestampUs(pub u64);
2829

30+
impl TryFrom<&Timestamp> for TimestampUs {
31+
type Error = anyhow::Error;
32+
33+
fn try_from(timestamp: &Timestamp) -> anyhow::Result<Self> {
34+
let seconds_in_micros: u64 = (timestamp.seconds * 1_000_000).try_into()?;
35+
let nanos_in_micros: u64 = (timestamp.nanos / 1_000).try_into()?;
36+
Ok(TimestampUs(seconds_in_micros + nanos_in_micros))
37+
}
38+
}
39+
2940
impl TimestampUs {
3041
pub fn now() -> Self {
3142
let value = SystemTime::now()

0 commit comments

Comments
 (0)