[−][src]Crate concordium_std
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-sc-base] default-features = false
In your project's Cargo.toml
file.
The library is meant to be used as a standard library for developing smart contracts. For this reason it re-exports a number of definitions from other libraries.
Global allocator.
Importing this library has a side-effect of setting the allocator to wee_alloc which is a memory allocator aimed at small code footprint. This allocator is designed to be used in contexts where there are a few large allocations up-front, and the memory later used during the lifetime of the program. Frequent small allocations will have bad performance, and should be avoided.
Panic handler
When compiled without the std
feature this crate sets the panic handler
to a no-op.
Modules
collections | Re-export. |
convert | Re-export. |
mem | Re-export. |
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. |
test_infrastructure | The test infrastructure module provides alternative implementations of
|
Macros
bail | The |
claim | The |
claim_eq | Ensure the first two arguments are equal, just like |
claim_ne | Ensure the first two arguments are not equal, just like |
ensure | The |
ensure_eq | Variants of |
ensure_ne | Ensure the first two arguments are not equal, using |
fail | The |
Structs
AccountAddress | Address of an account, as raw bytes. |
Action | Actions that can be produced at the end of a contract execution. This
type is deliberately not cloneable so that we can enforce that
|
Amount | The type of amounts on the chain |
ChainMetaExtern | |
ChainMetadata | Chain metadata accessible to both receive and init methods. |
ContractAddress | Address of a contract. |
ContractState | A type representing the constract state bytes. |
Cursor | Add offset tracking inside a data structure. |
InitContext | Chain context accessible to the init methods. |
InitContextExtern | |
Logger | A type representing the logger. |
Parameter | A type representing the parameter to init and receive methods. |
ParseError | Zero-sized type to represent an error when reading bytes and deserializing. |
ReceiveContext | Chain context accessible to the receive methods. |
ReceiveContextExtern | |
Reject | A non-descript error message, signalling rejection of a smart contract invocation. |
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
|
Constants
ACCOUNT_ADDRESS_SIZE | Size of an account address when serialized in binary. NB: This is different from the Base58 representation. |
Traits
Deserial | The |
Get | A more convenient wrapper around |
HasActions | An object that can serve to construct actions. |
HasChainMetadata | Objects which can access chain metadata. |
HasContractState | A type that can serve as the contract state type. |
HasInitContext | Types which can act as init contexts. |
HasLogger | Objects which can serve as loggers. |
HasParameter | Objects which can access parameters to contracts. |
HasReceiveContext | Types which can act as receive contexts. |
Read | The |
Seek | The |
Serial | The |
Serialize | The |
Write | The |
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_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_vector_no_length | Read a vector given a length. |
from_bytes | Dual to |
put_in_memory | Allocates a Vec of bytes prepended with its length as a |
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 |
trap | Terminate execution immediately without panicking.
When the |
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. |
InitResult | The expected return type of the init method of the smart contract, parametrized by the state type of the smart contract. |
ParseResult | A type alias used to indicate that the value is a result
of parsing from binary via the |
ReceiveResult | The expected return type of the receive method of a smart contract. |
SlotNumber | Sequential slot number |
SlotTime | Time at the beginning of the current slot, in miliseconds. |
Attribute Macros
concordium_cfg_test | Sets the cfg for testing targeting either Wasm and native. |
concordium_test | Derive the appropriate export for an annotated test function, when feature "wasm-test" is enabled, otherwise behaves like #test. |
contract_state | |
init | Derive the appropriate export for an annotated init function. |
receive | Derive the appropriate export for an annotated receive function. |
Derive Macros
Deserial | Derive the Deserial trait. See the documentation of |
SchemaType | |
Serial | Derive the Serial trait for the type. |
Serialize | A helper macro to derive both the Serial and Deserial traits.
|