Skip to content

Commit e980dcb

Browse files
authored
chore: expose update_lock_file fn that does not depend on wallet context (#22112)
## Description Walrus intends to avoid using the `SuiClient` within the `WalletContext` since it lacks retry semantics. To this end, we would prefer to avoid relying on Sui functions that force such usage. This PR extracts the internals of `update_lock_file` so that it can be used directly without need to pass in the `WalrusContext`. ## Test plan CI Pipeline.
1 parent bcea93b commit e980dcb

File tree

1 file changed

+33
-12
lines changed
  • crates/sui-package-management/src

1 file changed

+33
-12
lines changed

crates/sui-package-management/src/lib.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,10 @@ pub enum PublishedAtError {
4545
},
4646
}
4747

48-
/// Update the `Move.lock` file with automated address management info.
49-
/// Expects a wallet context, the publish or upgrade command, its response.
50-
/// The `Move.lock` principally file records the published address (i.e., package ID) of
51-
/// a package under an environment determined by the wallet context config. See the
52-
/// `ManagedPackage` type in the lock file for a complete spec.
48+
/// Update the `Move.lock` file with automated address management info. Expects a wallet context,
49+
/// the publish or upgrade command, and its response. The `Move.lock` file principally records the
50+
/// published address (i.e., package ID) of a package under an environment determined by the wallet
51+
/// context config. See the `ManagedPackage` type in the lock file for a complete spec.
5352
pub async fn update_lock_file(
5453
context: &WalletContext,
5554
command: LockCommand,
@@ -65,7 +64,33 @@ pub async fn update_lock_file(
6564
.get_chain_identifier()
6665
.await
6766
.context("Network issue: couldn't determine chain identifier for updating Move.lock")?;
67+
let env = context.config.get_active_env().context(
68+
"Could not resolve environment from active wallet context. \
69+
Try ensure `sui client active-env` is valid.",
70+
)?;
71+
update_lock_file_for_chain_env(
72+
&chain_identifier,
73+
&env.alias,
74+
command,
75+
install_dir,
76+
lock_file,
77+
response,
78+
)
79+
.await
80+
}
6881

82+
/// Update the `Move.lock` file with automated address management info. Expects a chain identifier,
83+
/// env alias, the publish or upgrade command, and its response. The `Move.lock` file principally
84+
/// records the published address (i.e., package ID) of a package under an environment in the given
85+
/// chain. See the `ManagedPackage` type in the lock file for a complete spec.
86+
pub async fn update_lock_file_for_chain_env(
87+
chain_identifier: &str,
88+
env_alias: &str,
89+
command: LockCommand,
90+
install_dir: Option<PathBuf>,
91+
lock_file: Option<PathBuf>,
92+
response: &SuiTransactionBlockResponse,
93+
) -> Result<(), anyhow::Error> {
6994
let (original_id, version, _) = get_new_package_obj_from_response(response).context(
7095
"Expected a valid published package response but didn't see \
7196
one when attempting to update the `Move.lock`.",
@@ -78,24 +103,20 @@ pub async fn update_lock_file(
78103
)
79104
};
80105
let install_dir = install_dir.unwrap_or(PathBuf::from("."));
81-
let env = context.config.get_active_env().context(
82-
"Could not resolve environment from active wallet context. \
83-
Try ensure `sui client active-env` is valid.",
84-
)?;
85106

86107
let mut lock = LockFile::from(install_dir.clone(), &lock_file)?;
87108
match command {
88109
LockCommand::Publish => lock_file::schema::update_managed_address(
89110
&mut lock,
90-
&env.alias,
111+
env_alias,
91112
lock_file::schema::ManagedAddressUpdate::Published {
92-
chain_id: chain_identifier,
113+
chain_id: chain_identifier.to_string(),
93114
original_id: original_id.to_string(),
94115
},
95116
),
96117
LockCommand::Upgrade => lock_file::schema::update_managed_address(
97118
&mut lock,
98-
&env.alias,
119+
env_alias,
99120
lock_file::schema::ManagedAddressUpdate::Upgraded {
100121
latest_id: original_id.to_string(),
101122
version: version.into(),

0 commit comments

Comments
 (0)