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

feat: add Zinnia.walletAddress API #123

Merged
merged 2 commits into from
Mar 22, 2023
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
8 changes: 8 additions & 0 deletions docs/building-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ for await (const chunk of response) {
}
```

### `Zinnia.walletAddress`

The wallet address where to send rewards. When running inside the Station Desktop, this API will
return the address of Station's built-in wallet.

The value is hard-coded to a testnet address `t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za` when
running the module via `zinnia` CLI.

<!--
UNSUPPORTED APIs
-->
Expand Down
4 changes: 4 additions & 0 deletions runtime/js/99_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ function bootstrapMainRuntime(runtimeOptions) {

runtimeStart(runtimeOptions);

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

// delete `Deno` global
delete globalThis.Deno;

Expand Down
6 changes: 6 additions & 0 deletions runtime/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub struct BootstrapOptions {

/// Seed value for initializing the random number generator
pub rng_seed: Option<u64>,

/// Filecoin wallet address - typically the built-in wallet in Filecoin Station
pub wallet_address: String,
}

impl Default for BootstrapOptions {
Expand All @@ -43,6 +46,8 @@ impl Default for BootstrapOptions {
is_tty: colors::is_tty(),
agent_version: format!("zinnia_runtime/{}", env!("CARGO_PKG_VERSION")),
rng_seed: None,
// See https://lotus.filecoin.io/lotus/manage/manage-fil/#public-key-address
wallet_address: String::from("t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za"),
}
}
}
Expand All @@ -52,6 +57,7 @@ impl BootstrapOptions {
let payload = serde_json::json!({
"noColor": self.no_color,
"isTty": self.is_tty,
"walletAddress": self.wallet_address,
});
serde_json::to_string_pretty(&payload).unwrap()
}
Expand Down
20 changes: 20 additions & 0 deletions runtime/tests/js/station_apis_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { assertStrictEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";

test("Zinnia.walletAddress", () => {
// Runtime JS tests are executed with the default configuration
// In this test, we assert that we can access the wallet address
// and the value is the default testnet one.
assertStrictEquals(Zinnia.walletAddress, "t1abjxfbp274xpdqcpuaykwkfb43omjotacm2p3za");
});

// A dummy wrapper to create isolated scopes for individual tests
// We should eventually replace this with a proper test runner
// See https://github.com/filecoin-station/zinnia/issues/30
function test(name, fn) {
try {
fn();
} catch (err) {
err.message = `Test ${name} failed. ` + err.message;
throw err;
}
}
1 change: 1 addition & 0 deletions runtime/tests/runtime_integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ js_tests!(timers_tests);
js_tests!(webapis_tests);
js_tests!(webcrypto_tests);
js_tests!(libp2p_tests);
js_tests!(station_apis_tests);

// Run all tests in a single JS file
async fn run_js_test_file(name: &str) -> Result<(), AnyError> {
Expand Down