pub struct ContractInstanceId(/* private fields */);Expand description
The key representing the hash of the contract executable code hash and a set of parameters.
Implementations§
Source§impl ContractInstanceId
impl ContractInstanceId
pub fn from_params_and_code<'a>( params: impl Borrow<Parameters<'a>>, code: impl Borrow<ContractCode<'a>>, ) -> Self
pub const fn new(key: [u8; 32]) -> Self
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn from_base58(bytes: impl AsRef<[u8]>) -> Result<Self, Error>
pub fn from_base58(bytes: impl AsRef<[u8]>) -> Result<Self, Error>
Parse a ContractInstanceId from its base58 text form — the inverse
of Self::encode.
The input is base58 characters, not the id’s 32 raw bytes. It takes
impl AsRef<[u8]> only so that &str, String and &[u8] of base58
text all work; handing it a raw 32-byte id is a bug, and one that does
not look like a bug at the call site. Use
ContractInstanceId::new for raw bytes you already hold, or the
crate-internal instance_id_from_fbs for bytes off the wire.
This was called from_bytes, documented as “build from the binary
representation”. That name and doc caused four decode sites to feed it
raw wire bytes, which panicked on every well-formed request: a random
32-byte id essentially never consists solely of base58 characters (the
alphabet is 58 of 256 byte values, so the odds are about 2e-21).
Caveat, pre-existing and unchanged: bs58’s onto writes the decoded
bytes LEFT-aligned into the 32-byte buffer and reports how many it
wrote, which this discards. So base58 text that decodes to fewer than 32
bytes yields a zero-padded id rather than an error — from_base58("1")
is the all-zero id. Callers that accept untrusted text (freenet-core
parses URL path segments with this) get a well-formed but wrong id
rather than a rejection.
Sourcepub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error>
👎Deprecated: renamed to from_base58: this parses base58 TEXT, not raw bytes. For a raw 32-byte id use ContractInstanceId::new.
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, Error>
renamed to from_base58: this parses base58 TEXT, not raw bytes. For a raw 32-byte id use ContractInstanceId::new.
Renamed to Self::from_base58, which says what it actually does.
Kept as a delegating alias so the rename is not a breaking change.
Trait Implementations§
Source§impl Clone for ContractInstanceId
impl Clone for ContractInstanceId
Source§fn clone(&self) -> ContractInstanceId
fn clone(&self) -> ContractInstanceId
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more