Pravda project allows you to write programs in subset of C# language. Pravda Translator translates CIL to Pravda bytecode.
Pravda provides special Pravda.dll
file with auxiliary methods for translation from CIL to Pravda bytecode.
This dll file serves only as meta info for translator, it doesn't provide any meaningful implementation for these methods. Translator just looks at calls of these methods and generates necessary Pravda bytecode.
You can download Pravda.dll
here.
Source of this dll can be found here.
For full support of all translation features you need also to compile your program with /debug:portable
option.
This options will trigger the creation of your_program.pdb
file that contains various auxiliary information about C# source.
Portable pdb files are quite new, so you need up-to-date csc
compiler to generate them. See more here.
To compile your C# program with Pravda.dll
:
csc your_program.cs /reference:Pravda.dll /debug:portable
Pravda CLI has special command to run translation of .exe
file produced by C# compiler.
pravda compile dotnet --input input.exe --output output.pravda --pdb input.pdb
pdb
file is optional, but it's strongly recommended to provide it (see Compile section for instructions).
Pravda Translator supports only part of all C# features.
For the moment it supports the following:
- Access to the storage via class fields;
- Access to the storage via
Mapping<K, V>
(get
,getDefault
,put
,exists
methods); - Access to sender address via
Info.Sender()
method; - Class methods that are translated to program methods;
- Integer primitive types (
int
,short
,byte
,uint
) andbool
; - 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 frombyte[]
: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 can't store them in the storage yet).
- Calling other programs via
ProgramHelper.Program<...>
interface. See some examples (pcall.cs, pcall_program.cs). Important note: For being able to useProgramHelper.Program<...>
interface you should put called program toExpload.Pravda.Programs
namespace. - Create events in your program via
Log.Event("name of event", <some_data>)
, see event.cs
Things that are not supported:
- Standard C# library (except of some specific functions from the list above);
- Standard C# collections.
You can look at several examples of test programs to learn current abilities of translation:
- String examples that show how to operate with
String
s. - Array examples that show how to operate with arrays.
- Simple program with
balanceOf
andtransfer
methods similar to 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 poker game on the blockchain. (poker.cs was provided by Ducatur team)