Crate pchain_sdk

source ·
Expand description

The ParallelChain Mainnet Contract SDK (pchain-sdk) provides Rust structs, functions, types, and macros that aid with the development of smart contracts executable in WebAssembly (WASM) engines implementing the ParallelChain Mainnet Contract Binary Interface Subprotocol.

Re-exports

Modules

  • Defines functions for getting the information about the Blockchain that is available in the context of this Transaction. This includes information about the ‘current’ Block, e.g., its height and timestamp, but also information about preceding Blocks.
  • Defines a collection of bareboned data structures for CRUD operations in world state. They are designed to get gas consumption to be efficient, consistent and predictable.
  • Defines runtime-supported cryptographic functions. What cryptgraphic functions have in common is that the operations they implement are: 1. Relatively expensive, and 2. Relatively common in Contract applications. In order to reduce gas costs, these functions are implemented in native (not-WASM) code that lives outside of the WASM runtime, and exposed to calls through the handles defined in this module.
  • Internal functions that interacts within this transaction context. For example, setting data to receipts, calling other contracts, transfer to other account.
  • Defines the abstract level of inputs and outputs of a contract method. Contracts written use the #[contract] macro to unpack those Transaction Command Call that contain a serialized arguments. This structure selects the Method that a call should enter, as well as provides the arguments for the function call.
  • Defines functions to defer a network command that to be executed after success of this contract call. This command is considered as part of the contract call. i.e. There is no modification on the field commands in the Transaction, and no additional Command Receipt for it.
  • Defines functions for reading and writing into Contract Storage (a.k.a. ‘World State’). It also defines two types: ‘Storage’ and ‘StoragePath’, that are used in macro-expanded code in a convoluted and hard-to-explain manner. These types will be moved out of this module, or removed entirely, in a future version of the SDK.
  • Defines functions for getting information about the Transaction that triggered this call, e.g. the calling account (Transaction’s signer) and transaction_hash, etc.

Attribute Macros

  • call macro applies to impl methods for contract method call.
  • contract defines basic struct as a programming model of a contract. Fields are data representation of contract storage.
  • The macro contract_field can generate impl so that nested struct can be supported in contract struct.
  • contract_methods defines impl for the contract struct. Methods declared in the impl are callable by Transaction Command Call if their visibility is pub.
  • use_contract provides smart contract developers a way to make cross contract calls by using public functions from other smart contracts in the form of traits.