C# Translation Overview
The Pravda project allows you to write programs in the subset of C# language. The Pravda Translator translates CIL to Pravda bytecode.
Supported C# Subset
The Pravda Translator only supports certain C# features.
Notably, it currently supports the following features:
- Access to the storage via class fields.
- Access to the storage via Mapping<K, V>
(get
, getDefault
, put
, exists
methods).
- Access to the sender address via Info.Sender()
method.
- Access to the list of contract callers' addresses via Info.Callers()
method.
- Class methods that are translated to program methods.
- Integer primitive types (int
, short
, byte
, uint
) and bool
.
- Basic arithmetics and logical operations.
- Local variables and method arguments.
- If-conditions and loops.
- String
s and auxiliary methods (+
, access to particular chars, Slice
);
- Bytes
(immutable byte arrays), auxiliary methods (access to particular bytes, Slice
, Concat
), creation from byte[]
: new Bytes(bytes_array)
;
- Arrays of primitive types (int
, byte
, String
), reading and writing of particular elements;
- Explicit conversion of primitive types via
System.Convert.ToByte
, System.Convert.ToChar
,System.Convert.ToInt16
,System.Convert.ToInt32
,System.Convert.ToDouble
,System.Convert.ToBoolean
,System.Convert.ToString
- Cryptographic functions: Ripemd160 hashing, validation of Ed25519 Signature. See more in Standard library docs.
- User defined classes (although you cannot store them in the storage yet).
- The calling of other programs via ProgramHelper.Program<...>
interface.
You can check out the examples here: (Pcall.cs, PcallProgram.cs).
- Create events in your program via Log.Event("name of event", <some_data>)
, see Event.cs
Features that are not supported: - Standard C# library (except for some specific functions from the list above); - Standard C# collections.
Important note: The entire code placed in the Expload.Pravda
namespace is ignored.
It is needed to support stub methods in Pravda.dll
.
Examples
You can have a look at several examples of test programs that illustrate the current translation abilities:
- String examples that show how to operate String
s.
- Array examples that show how to operate arrays.
- Simple program with balanceOf
and transfer
methods similar to the corresponding methods from ERC20
- Buffer -- Dynamic resizable array implemented in C#.
- Zoo program that allows you to create zoos, pets and breed them.
- Poker program that implements simple a poker game on the blockchain. _(poker.cs was provided by Ducatur team)