forked from CosmWasm/wasmvm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
55 lines (46 loc) · 1011 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"io/ioutil"
"os"
wasmvm "github.com/CosmWasm/wasmvm"
)
const (
SUPPORTED_CAPABILITIES = "staking"
PRINT_DEBUG = true
MEMORY_LIMIT = 32 // MiB
CACHE_SIZE = 100 // MiB
)
// This is just a demo to ensure we can compile a static go binary
func main() {
file := os.Args[1]
if file == "version" {
libwasmvmVersion, err := wasmvm.LibwasmvmVersion()
if err != nil {
panic(err)
}
fmt.Printf("libwasmvm: %s\n", libwasmvmVersion)
return
}
fmt.Printf("Running %s...\n", file)
bz, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
}
fmt.Println("Loaded!")
err = os.MkdirAll("tmp", 0o755)
if err != nil {
panic(err)
}
vm, err := wasmvm.NewVM("tmp", SUPPORTED_CAPABILITIES, MEMORY_LIMIT, PRINT_DEBUG, CACHE_SIZE)
if err != nil {
panic(err)
}
checksum, err := vm.StoreCode(bz)
if err != nil {
panic(err)
}
fmt.Printf("Stored code with checksum: %X\n", checksum)
vm.Cleanup()
fmt.Println("finished")
}