This library provides the core API that can be used to write smart contracts for the Concordium blockchain in the Rust programming language. It aims to provide safe wrappers around the core primitives exposed by the chain and accessible to smart contracts.
By default the library will be linked with the
std crate, the rust standard library,
however to minimize code size this library supports toggling compilation
#![no_std] attribute via the feature
std which is enabled by
To use this library without the
std feature you have to disable it, which
can be done, for example, as follows.
[dependencies.concordium-contracts-common] default-features = false
In your project's
This crate supports both compilation to x86 native code, as well as to the wasm32-unknown-unknown target. When there is a conflict, the preference should always be to make the wasm32-unknown-unknown the more efficient one.
The functionality in this library is re-exported via the concordium-std
crate, which is intended as the entry-point for development of smart
contracts in Rust.
concordium-std adds a number of helper macros and
traits on top of the basic functionality available here.
This library supports two features,
derive-serde. The former one
is enabled by default, but the latter is disabled.
derive-serde feature is intended to be used by off-chain tools to make
it easier to test smart contracts, as well as to inter-operate with them
once they are deployed. It can also be used in unit tests, since enabling
this feature exposes additional trait implementations on the defined types.
The reason these trait implementations are not enabled by default is that they have non-trivial dependencies, which tends to increase compilation times, as well as code size, if used accidentally.
The main traits defined in this crate deal with binary serialization. The general principles behind serialization is to consistently use little-endian encoding. The native endianess of Wasm32 (when, e.g., reading from linear memory) is little endian, thus having serialization in little endian means as little overhead as possible.
In particular, the Get is noteworthy. It makes it possible to omit writing the type explicitly, if it is already clear from the context, allowing us to write, e.g.,
let n = source.get()?;
let n = u8::deserial(source)?;
Currently defined attributes possible in a policy.
Types related to contract schemas. These are optional annotations in modules that allow the users of smart contracts to interact with them in a way that is better than constructing raw bytes as parameters.
Address of an account, as raw bytes.
The type of amounts on the chain
Tag of an attribute. See the module attributes for the currently supported attributes.
Chain metadata accessible to both receive and init methods.
Address of a contract.
Add offset tracking inside a data structure.
Duration of time in milliseconds.
Zero-sized type to represent an error when reading bytes and deserializing.
Policy on the credential of the account.
Timestamp represented as milliseconds since unix epoch.
Either an address of an account, or contract.
An error indicating why parsing of an amount failed. Since amount parsing is typically a user-facing activity this is fairly precise, so we can notify the user why we failed, and what they can do to fix it.
This is the equivalent to the
SeekFrom type from
the rust standard library, but reproduced here to avoid dependency on
Size of an account address when serialized in binary. NB: This is different from the Base58 representation.
A more convenient wrapper around
Read a BTreeMap as a list of key-value pairs given some length. NB: This ensures there are no duplicates, hence the specialized type. Moreover this will only succeed if keys are listed in order.
Read a BTreeMap as a list of key-value pairs given some length.
Slightly faster version of
Read a BTreeSet as an list of keys, given some length. NB: This ensures there are no duplicates, hence the specialized type. Moreover this will only succeed if keys are listed in order.
Read a BTreeSet as an list of key-value pairs given some length.
Slightly faster version of
Read a vector given a length.
Write a Map as a list of key-value pairs ordered by the key, without the length information.
Write a BTreeSet as an ascending list of keys, without the length information.
Write a slice of elements, without including length information. This is intended to be used either when the length is statically known, or when the length is serialized independently as part of a bigger structure.
Serialize the given value to a freshly allocated vector of bytes using
A borrowed attribute value. The slice will have at most 31 bytes. The meaning of the bytes is dependent on the type of the attribute.
Height of the block. Height of the genesis block is 0, and otherwise it is always the case that a block has height one more than its parent.
Finalized height. In the context of chain metadata this is the height of the block which is explicitly recorded as the last finalized block in the block under consideration.
Index of the identity provider on the chain. An identity provider with the given index will not be replaced, so this is a stable identifier.
An owned counterpart of
A policy with a vector of attributes, fully allocated and owned. This is in contrast to a policy which is lazily read from a read source. The latter is useful for efficiency, this type is more useful for testing since the values are easier to construct.
A type alias used to indicate that the value is a result
of parsing from binary via the
Genesis block has slot number 0, and otherwise it is always the case that a
parent of a block has a slot number strictly less than the block itself.
However in contrast to
Time at the beginning of the current slot, in miliseconds since unix epoch.