timestampvm-rs
timestampvm-rs
is a virtual machine that can build blocks from a user-provided arbitrary data. It is a minimal implementation of an Avalanche custom virtual machine (VM) in Rust, using the Avalanche Rust SDK.
Currently, Avalanche custom VM requires the following:
- Compiled to a binary that
avalanchego
can launch as a sub-process. - Plugin binary path in hash of 32 bytes.
- Implements
snowman.block.ChainVM
interface that can be be registered viarpcchainvm.Serve
. - Implements VM-specific services that can be served via URL path of the blockchain ID.
- (Optionally) Implements VM-specific static handlers that can be served via URL path of the VM ID.
For example, the timestamp VM can be run as follows:
use subnet;
use vm;
use ;
async
See bin/timestampvm
for plugin implementation and tests/e2e
for full end-to-end tests.
Example
# build the timestampvm plugin, run e2e tests, and keep the network running
&& VM_PLUGIN_PATH= /target/release/timestampvm\
# or, specify the custom avalanchego binary
&& VM_PLUGIN_PATH= /target/release/timestampvm\
# (optional) set NETWORK_RUNNER_ENABLE_SHUTDOWN=1 in "tests.e2e.sh"
# to shut down the network afterwards
To test timestampvm
APIs, try the following commands:
# "tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc" is the Vm Id
# e.g., timestampvm vm-id timestampvm
# {"jsonrpc":"2.0","result":{"success":true},"id":1}
# "2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7" is the blockchain Id
# {"jsonrpc":"2.0","result":{"success":true},"id":1}
# to get genesis block
# "2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7" is the blockchain Id
# {"jsonrpc":"2.0","result":{"id":"SDfFUzkdzWZbJ6YMysPPNEF5dWLp9q35mEMaLa8Ha2w9aMKoC"},"id":1}
# "2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7" is the blockchain Id
# {"jsonrpc":"2.0","result":{"block":{"data":"0x32596655705939524358","height":0,"parent_id":"11111111111111111111111111111111LpoYY","timestamp":0}},"id":1}
# to propose data
| |
# MQo=
# {"jsonrpc":"2.0","result":{"success":true},"id":1}