[][src]Crate concordium_contracts_common

This library provides the core API that can be used to write smart contracts for the Concordium blockchain. 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 with the #![no_std] attribute via the feature std which is enabled by default. Compilation without the std feature requires a nightly version of rust.

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 Cargo.toml file.

Modules

schema

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.

Structs

AccountAddress

Address of an account, as raw bytes.

Amount

The type of amounts on the chain

ChainMetadata

Chain metadata accessible to both receive and init methods.

ContractAddress

Address of a contract.

Cursor

Add offset tracking inside a data structure.

InitContext

Chain context accessible to the init methods.

ParseError

Zero-sized type to represent an error when reading bytes and deserializing.

ReceiveContext

Chain context accessible to the receive methods.

Enums

Address

Either an address of an account, or contract.

AmountParseError

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.

SeekFrom

This is the equivalent to the SeekFrom type from the rust standard library, but reproduced here to avoid dependency on std::io.

Constants

ACCOUNT_ADDRESS_SIZE

Size of an account address when serialized in binary. NB: This is different from the Base58 representation.

Traits

Deserial

The Deserial trait provides a means of reading structures from byte-sinks (Read).

Get

A more convenient wrapper around Deserial that makes it easier to write deserialization code. It has a blanked implementation for any read and serialize pair. The key idea is that the type to deserialize is inferred from the context, enabling one to write, for example,

Read

The Read trait provides a means of reading from byte streams.

Seek

The Seek trait provides a cursor which can be moved within a stream of bytes. This is essentially a copy of std::io::Seek, but avoiding its dependency on std::io::Error, and the associated code size increase.

Serial

The Serial trait provides a means of writing structures into byte-sinks (Write).

Serialize

The Serialize trait provides a means of writing structures into byte-sinks (Write) or reading structures from byte sources (Read).

Write

The Write trait provides functionality for writing to byte streams.

Functions

deserial_map_no_length

Read a Map as an 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.

deserial_map_no_length_no_order_check

Read a Map as an list of key-value pairs given some length. Slightly faster version of deserial_map_no_length as it is skipping the order checking

deserial_set_no_length

Read a Set 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.

deserial_set_no_length_no_order_check

Read a Set as an list of key-value pairs given some length. Slightly faster version of deserial_set_no_length as it is skipping the order checking.

deserial_vector_no_length

Read a vector given a length.

from_bytes

Dual to to_bytes.

serial_map_no_length

Write a Map as a list of key-value pairs ordered by the key, without the length information.

serial_set_no_length

Write a Set as an list of keys ordered, without the length information.

serial_vector_no_length

Write a vector without including length information.

to_bytes

Serialize the given value to a freshly allocated vector of bytes using the provided Serial instance.

Type Definitions

BlockHeight

Height of the block.

FinalizedHeight

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.

ParseResult

A type alias used to indicate that the value is a result of parsing from binary via the Serial instance.

SlotNumber

Sequential slot number

SlotTime

Time at the beginning of the current slot, in miliseconds.