Repository provides examples of how to solve some tasks in C++ using v8 library.
The following libraries are required to be installed:
libopenssl
V8 # Completed build of V8 libraries can be find in the repository.git clone https://github.com/metahashorg/vm_v8
cd vm_8
cd build
./build.sh/src directory contains built vm_v8 utility.
Before launching the utility, it is needed to run the following command:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:src/v8/lib- Output of the bytecode:
./vm_v8 -mode bt -js [js file path]- Counting the number of instructions:
./vm_v8 -mode btcount -js [js file path]- Memory footprint:
./vm_v8 -mode mem -js [js file path]- Testing external variable:
./vm_v8 -mode external -intarg [integer]- sha256:
./vm_v8 -mode sha256 -strarg [string]- Signature check:
./vm_v8 -mode sig- Generating address on public key:
./vm_v8 -mode newaddr -strarg [public key in the form of hex string]- Compiler test:
./vm_v8 -mode compile -a ADDR -js FILE.JS- Initialization status:
./vm_v8 -mode run -a ADDR -cmd run.js -js FILE.JS -cmpl FILE.cmpl -snap_o I_FILE.shot- Status dump:
./vm_v8 -mode run -a ADDR -cmd run.js -snap_i I_FILE.shot -snap_o I_FILE.shotADDR — address of the contract
FILE.JS — file containing core js code. When running contract initialization test there is a contract code (contract.js).
FILE.cmpl — file containing compiler cache, is equal to FILE.js.
run.js - file containing js code, that conducts one of 2 operations, i.e. initialization or status dump (init.js and dump.js)
I_FILE.shot - input file of the virtual machine memory snapshot, it is mandatory for the status test and optional for the initialization test.
I_FILE.shot — file containing memory snapshot after core code and command code
Following files are added to the project:
contract.js
contract.cmpl
init.js
dump.js./vm_v8 -mode run -a 0xaddress -cmd init.js -js contract.js -cmpl contract.cmpl -snap_o init.shotOutput:
snapshot
init.shotEntry in theerr.logfile shows that contract has been initialized successfully:ContractStateTest:[object Object]
./test -mode run -a 0xaddress -cmd dump.js -snap_i init.shot -snap_o result.shotOutput:
Final snapshot
result.shot.
Entry in the
err.logfile regarding contract status:ContractStateTest: { "items": [ { "key":"ammount", "type":"number", "value":220 }, { "key":"data", "type":"Map", "value": [ ["Jane",100],["Bob",120] ] } ] }