wasm-pack utility to pack wasm files into transactions payload

This commit is contained in:
NikVolf
2017-06-09 18:33:05 +03:00
parent 25110c32a8
commit 729dddc9cc
7 changed files with 86 additions and 3 deletions

2
pack/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
Cargo.lock

9
pack/Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "wasm-pack"
version = "0.1.0"
authors = ["NikVolf <nikvolf@gmail.com>"]
[dependencies]
parity-wasm = { git="https://github.com/nikvolf/parity-wasm" }
wasm-utils = { path = "../" }
clap = "2.24"

32
pack/src/main.rs Normal file
View File

@ -0,0 +1,32 @@
extern crate parity_wasm;
extern crate wasm_utils;
extern crate clap;
use clap::{App, Arg};
fn main() {
wasm_utils::init_log();
let matches = App::new("wasm-opt")
.arg(Arg::with_name("input")
.index(1)
.required(true)
.help("Input WASM file"))
.arg(Arg::with_name("output")
.index(2)
.required(true)
.help("Output WASM file"))
.get_matches();
let input = matches.value_of("input").expect("is required; qed");
let output = matches.value_of("output").expect("is required; qed");
// doing serialization roundtrip to make sure the input is a valid wasm module
let module = parity_wasm::deserialize_file(&input).expect("Failed to load wasm module from file");
let bytes = parity_wasm::serialize(module).expect("Failed to serialize wasm module");
// Wrap contract code into the wasm module that returns it
let packed_module = wasm_utils::pack_instance(bytes);
parity_wasm::serialize_to_file(&output, packed_module).unwrap();
}