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:
avalanchego
can launch as a sub-process.snowman.block.ChainVM
interface that can be be registered via rpcchainvm.Serve
.For example, the timestamp VM can be run as follows:
```rust use avalanche_types::subnet; use timestampvm::vm; use tokio::sync::broadcast::{self, Receiver, Sender};
async fn main() -> std::io::Result<()> { let (stopchtx, stopchrx): (Sender<()>, Receiver<()>) = broadcast::channel(1); let vmserver = subnet::rpc::vm::server::Server::new(vm::Vm::new(), stopchtx); subnet::rpc::plugin::serve(vmserver, stopchrx).await } ```
See bin/timestampvm
for plugin implementation and tests/e2e
for full end-to-end tests.
| Version(s) | AvalancheGo Version(s) | | --- | --- | | v0.0.6 | v1.9.2,v1.9.3 | | v0.0.7 | v1.9.4 | | v0.0.8, v0.0.9 | v1.9.7 | | v0.0.10 | v1.9.8, v1.9.9 | | v0.0.11 | v1.9.10, v1.9.11 |
```bash
./scripts/build.release.sh \ && VMPLUGINPATH=$(pwd)/target/release/timestampvm \ ./scripts/tests.e2e.sh
./scripts/build.release.sh \ && VMPLUGINPATH=$(pwd)/target/release/timestampvm \ ./scripts/tests.e2e.sh ~/go/src/github.com/ava-labs/avalanchego/build/avalanchego
```
To test timestampvm
APIs, try the following commands:
```bash
curl -X POST --data '{ "jsonrpc": "2.0", "id" : 1, "method" : "timestampvm.ping", "params" : [] }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/vm/tGas3T58KzdjcJ2iKSyiYsWiqYctRXaPTqBCA11BqEkNg8kPc/static
```
```bash
curl -X POST --data '{ "jsonrpc": "2.0", "id" : 1, "method" : "timestampvm.ping", "params" : [] }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7/rpc
```
```bash
curl -X POST --data '{ "jsonrpc": "2.0", "id" : 1, "method" : "timestampvm.lastAccepted", "params" : [] }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7/rpc
curl -X POST --data '{ "jsonrpc": "2.0", "id" : 1, "method" : "timestampvm.getBlock", "params" : [{"id":"SDfFUzkdzWZbJ6YMysPPNEF5dWLp9q35mEMaLa8Ha2w9aMKoC"}] }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7/rpc
```
```bash
echo 1 | base64 | tr -d \n
curl -X POST --data '{ "jsonrpc": "2.0", "id" : 1, "method" : "timestampvm.proposeBlock", "params" : [{"data":"MQo="}] }' -H 'content-type:application/json;' 127.0.0.1:9650/ext/bc/2wb1UXxAstB8ywwv4rU2rFCjLgXnhT44hbLPbwpQoGvFb2wRR7/rpc
```