Skip to content

Commit 4dce6e3

Browse files
sanityclaude
andcommitted
feat: add ContractKey::from_id_and_code constructor
This allows reconstructing a ContractKey from stored index data when the node has the instance ID and code hash but not the original contract code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent f9b3c6d commit 4dce6e3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "freenet-stdlib"
3-
version = "0.1.25"
3+
version = "0.1.26"
44
edition = "2021"
55
rust-version = "1.71.1"
66
publish = true

rust/src/contract_interface/key.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@ impl ContractKey {
183183
pub fn id(&self) -> &ContractInstanceId {
184184
&self.instance
185185
}
186+
187+
/// Constructs a ContractKey from a pre-computed instance ID and code hash.
188+
///
189+
/// This is useful when the node needs to reconstruct a key from stored index data.
190+
/// Callers must ensure the instance_id was correctly derived from the code_hash
191+
/// and parameters, as this constructor does not verify consistency.
192+
pub fn from_id_and_code(instance_id: ContractInstanceId, code_hash: CodeHash) -> Self {
193+
Self {
194+
instance: instance_id,
195+
code: code_hash,
196+
}
197+
}
186198
}
187199

188200
impl PartialEq for ContractKey {

0 commit comments

Comments
 (0)