-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: Factor out icp-app from icp
#771
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
Open
adamspofford-dfinity
wants to merge
3
commits into
spofford/de-context-operations
from
spofford/factor-app
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
309e97e
refactor: ask for wasm modules and observation rather than reaching f…
adamspofford-dfinity 6278c4e
refactor: split the app half of `icp` into `icp-app`
adamspofford-dfinity 2428267
fix: pass a boxed cause through instead of restating it
adamspofford-dfinity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| [package] | ||
| name = "icp-app" | ||
| version.workspace = true | ||
| edition = { workspace = true } | ||
| license = { workspace = true } | ||
| publish.workspace = true | ||
|
|
||
| [features] | ||
| # `clap::ValueEnum` derives on the settings/identity enums used as CLI value | ||
| # types. Enabled by `icp-cli`. | ||
| clap = ["dep:clap", "icp/clap"] | ||
| # Exposes this crate's mocks, as `icp`'s own feature does for its seams. | ||
| test-util = ["icp/test-util"] | ||
|
|
||
| [dependencies] | ||
| async-dropper = { workspace = true } | ||
| async-trait = { workspace = true } | ||
| base64 = { workspace = true } | ||
| backoff = { workspace = true } | ||
| bigdecimal = { workspace = true } | ||
| bip32 = { workspace = true } | ||
| bollard = { workspace = true } | ||
| camino = { workspace = true } | ||
| camino-tempfile = { workspace = true } | ||
| candid = { workspace = true } | ||
| clap = { workspace = true, optional = true } | ||
| crypto-bigint = { workspace = true } | ||
| directories = { workspace = true } | ||
| dunce = { workspace = true } | ||
| ed25519-consensus = { workspace = true } | ||
| elliptic-curve = { workspace = true } | ||
| flate2 = { workspace = true } | ||
| futures = { workspace = true } | ||
| hex = { workspace = true } | ||
| hmac = { workspace = true } | ||
| hybrid-array = { workspace = true } | ||
| ic-agent = { workspace = true } | ||
| ic-ed25519 = { workspace = true } | ||
| ic-identity-hsm = { workspace = true } | ||
| ic-ledger-types = { workspace = true } | ||
| ic-management-canister-types = { workspace = true } | ||
| ic-utils = { workspace = true } | ||
| icp = { workspace = true } | ||
| icp-canister-interfaces = { workspace = true } | ||
| icp-events = { workspace = true } | ||
| icrc-ledger-types = { workspace = true } | ||
| itertools = { workspace = true } | ||
| k256 = { workspace = true } | ||
| keyring = { workspace = true } | ||
| notify = { workspace = true } | ||
| num-bigint = { workspace = true } | ||
| num-traits = { workspace = true } | ||
| p256 = { workspace = true } | ||
| pem = { workspace = true } | ||
| phf = { workspace = true } | ||
| pkcs8 = { workspace = true } | ||
| rand = { workspace = true } | ||
| reqwest = { workspace = true } | ||
| scrypt = { workspace = true } | ||
| sec1 = { workspace = true } | ||
| semver = { workspace = true } | ||
| serde = { workspace = true } | ||
| serde_cbor = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| sha2 = { workspace = true } | ||
| snafu = { workspace = true } | ||
| strum = { workspace = true } | ||
| sysinfo = { workspace = true } | ||
| tar = { workspace = true } | ||
| time = { workspace = true } | ||
| tiny-bip39 = { workspace = true } | ||
| tokio = { workspace = true, features = ["sync", "macros", "rt", "time", "io-util", "io-std", "process", "signal"] } | ||
| tracing = { workspace = true } | ||
| url = { workspace = true } | ||
| uuid = { workspace = true } | ||
| wslpath2 = { workspace = true } | ||
| zeroize = { workspace = true } | ||
|
|
||
| [target.'cfg(windows)'.dependencies] | ||
| winreg = { workspace = true } | ||
|
|
||
| [dev-dependencies] | ||
| httptest = { workspace = true } | ||
| icp = { workspace = true, features = ["test-util"] } | ||
| indexmap = { workspace = true } | ||
| indoc = { workspace = true } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| use std::{sync::Arc, time::Duration}; | ||
|
|
||
| use async_trait::async_trait; | ||
| use ic_agent::{Agent, AgentError, Identity}; | ||
| use snafu::prelude::*; | ||
|
|
||
| use icp::prelude::*; | ||
|
|
||
| #[derive(Debug, Snafu)] | ||
| pub enum CreateAgentError { | ||
| #[snafu(display("failed to create agent"))] | ||
| Agent { source: AgentError }, | ||
| } | ||
|
|
||
| /// How far ahead of now an agent dates the messages it expires, unless the | ||
| /// caller pins something else. | ||
| const DEFAULT_INGRESS_EXPIRY: Duration = Duration::from_secs(4 * MINUTE); | ||
|
|
||
| #[async_trait] | ||
| pub trait Create: Sync + Send { | ||
| /// Builds an agent talking to `url` as `id`. | ||
| /// | ||
| /// `ingress_expiry` pins how far ahead of now the agent dates the messages it | ||
| /// derives an expiry for. Pass `None` for the default. Pass `Some` only when | ||
| /// the expiry is itself part of the output — signing a message here for | ||
| /// another machine to submit, where the call envelope and the pre-signed | ||
| /// `request_status` that accompanies it have to land in the same submission | ||
| /// window. A pinned expiry is used verbatim, so the | ||
| /// `ICP_CLI_TEST_ADVANCE_TIME_MS` clock offset applies to the default only. | ||
| async fn create( | ||
| &self, | ||
| id: Arc<dyn Identity>, | ||
| url: &str, | ||
| ingress_expiry: Option<Duration>, | ||
| ) -> Result<Agent, CreateAgentError>; | ||
| } | ||
|
|
||
| pub struct Creator; | ||
|
|
||
| #[async_trait] | ||
| impl Create for Creator { | ||
| async fn create( | ||
| &self, | ||
| id: Arc<dyn Identity>, | ||
| url: &str, | ||
| ingress_expiry: Option<Duration>, | ||
| ) -> Result<Agent, CreateAgentError> { | ||
| let ingress_expiry = | ||
| ingress_expiry.unwrap_or_else(|| DEFAULT_INGRESS_EXPIRY + test_time_advance()); | ||
|
|
||
| let b = Agent::builder() | ||
| .with_url(url) | ||
| .with_arc_identity(id) | ||
| .with_ingress_expiry(ingress_expiry); | ||
|
|
||
| Ok(b.build().context(AgentSnafu)?) | ||
| } | ||
| } | ||
|
|
||
| /// How far a test has advanced the replica's clock past this machine's, so the | ||
| /// default ingress expiry stays ahead of replica time. | ||
| fn test_time_advance() -> Duration { | ||
| match std::env::var("ICP_CLI_TEST_ADVANCE_TIME_MS") { | ||
| Ok(ms) => Duration::from_millis( | ||
| ms.parse::<u64>() | ||
| .expect("ICP_CLI_TEST_ADVANCE_TIME_MS must be set to an int"), | ||
| ), | ||
| Err(_) => Duration::ZERO, | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.