Skip to content

Commit

Permalink
feat: new Zinnia API stationId (#520)
Browse files Browse the repository at this point in the history
Receive station_id from Core via a new env var and expose it to modules as `Zinnia.stationId`.
  • Loading branch information
PatrickNercessian authored Apr 17, 2024
1 parent d314f74 commit f9b1eb3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
*.DS_Store
4 changes: 4 additions & 0 deletions daemon/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub struct CliArgs {
#[arg(long, short = 'w', env = "FIL_WALLET_ADDRESS", name = "FIL ADDRESS")]
pub wallet_address: String,

/// Unique identifier of the Filecoin Station (required).
#[arg(long, env = "STATION_ID", name = "STATION ID")]
pub station_id: String,

/// Directory where to keep state files.
#[arg(long, env, default_value_t = get_default_state_dir(env::var), name = "LOCAL STATE DIR PATH")]
pub state_root: String,
Expand Down
2 changes: 2 additions & 0 deletions daemon/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ async fn run(config: CliArgs) -> Result<RunOutput> {
zinnia_version: env!("CARGO_PKG_VERSION"),
agent_version: format!("zinniad/{} {module_name}", env!("CARGO_PKG_VERSION")),
wallet_address: config.wallet_address,
station_id: config.station_id,
reporter: Rc::new(StationReporter::new(
state_file,
Duration::from_millis(200),
Expand Down Expand Up @@ -178,6 +179,7 @@ mod tests {
cache_root: temp.join("cache").to_string_lossy().into(),
state_root: temp.join("state").to_string_lossy().into(),
wallet_address: "f1test".to_string(),
station_id: "zinnia-dev".to_string(),
files: vec![mod_js.path().to_string_lossy().to_string()],
};
let RunOutput { lassie_daemon, .. } = run(args).await.expect("cannot run dummy.js");
Expand Down
1 change: 1 addition & 0 deletions daemon/tests/daemon_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn it_removes_lassie_temp_on_start() {
let mut cmd = Command::new(bin);
cmd.env("NO_COLOR", "1")
.env("FIL_WALLET_ADDRESS", "f1test")
.env("STATION_ID", "zinnia-dev")
.env("CACHE_ROOT", cache_root.display().to_string())
.env("STATE_ROOT", state_root.display().to_string())
.args([&mod_js.as_os_str()])
Expand Down
4 changes: 4 additions & 0 deletions docs/building-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,10 @@ for await (const chunk of response) {

### Integration with Filecoin Station

#### `Zinnia.stationId`

The associated Station Core's unique identifier (public key)

#### `Zinnia.walletAddress`

The wallet address where to send rewards. When running inside the Station Desktop, this API will
Expand Down
1 change: 1 addition & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function bootstrapMainRuntime(runtimeOptions) {

ObjectDefineProperties(globalThis.Zinnia, {
walletAddress: util.readOnly(runtimeOptions.walletAddress),
stationId: util.readOnly(runtimeOptions.stationId),
});

// delete `Deno` global
Expand Down
5 changes: 5 additions & 0 deletions runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub struct BootstrapOptions {
/// Filecoin wallet address - typically the built-in wallet in Filecoin Station
pub wallet_address: String,

/// Station ID - the unique identifier of the Filecoin Station
pub station_id: String,

/// Report activities
pub reporter: Rc<dyn Reporter>,

Expand Down Expand Up @@ -62,6 +65,7 @@ impl BootstrapOptions {
module_root,
// See https://lotus.filecoin.io/lotus/manage/manage-fil/#public-key-address
wallet_address: String::from("t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za"),
station_id: String::from("zinnia-dev"),
reporter,
lassie_daemon,
zinnia_version: env!("CARGO_PKG_VERSION"),
Expand All @@ -73,6 +77,7 @@ impl BootstrapOptions {
"noColor": self.no_color,
"isTty": self.is_tty,
"walletAddress": self.wallet_address,
"stationId": self.station_id,
"lassieUrl": format!("http://127.0.0.1:{}/", self.lassie_daemon.port()),
"lassieAuth": match self.lassie_daemon.access_token() {
Some(token) => serde_json::Value::String(format!("Bearer {token}")),
Expand Down
4 changes: 4 additions & 0 deletions runtime/tests/js/station_apis_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ test("Zinnia.walletAddress", () => {
// and the value is the default testnet one.
assertStrictEquals(Zinnia.walletAddress, "t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za");
});

test("Zinnia.stationId", () => {
assertStrictEquals(Zinnia.stationId, "zinnia-dev");
});

0 comments on commit f9b1eb3

Please sign in to comment.