diff --git a/Cargo.lock b/Cargo.lock index 6b4b7f05f..f74fb5287 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -403,6 +403,15 @@ dependencies = [ "yaml-rust", ] +[[package]] +name = "cmake" +version = "0.1.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" +dependencies = [ + "cc", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -990,6 +999,12 @@ version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" +[[package]] +name = "glob" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" + [[package]] name = "hash-db" version = "0.15.2" @@ -3165,6 +3180,7 @@ dependencies = [ "sp-std", "sp-version", "thiserror", + "wabt", "ws", ] @@ -3564,6 +3580,29 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wabt" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00bef93d5e6c81a293bccf107cf43aa47239382f455ba14869d36695d8963b9c" +dependencies = [ + "serde", + "serde_derive", + "serde_json", + "wabt-sys", +] + +[[package]] +name = "wabt-sys" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a4e043159f63e16986e713e9b5e1c06043df4848565bf672e27c523864c7791" +dependencies = [ + "cc", + "cmake", + "glob", +] + [[package]] name = "walkdir" version = "2.3.2" diff --git a/compose-macros/src/lib.rs b/compose-macros/src/lib.rs index 5ef9ade8c..ddea99938 100644 --- a/compose-macros/src/lib.rs +++ b/compose-macros/src/lib.rs @@ -133,7 +133,7 @@ macro_rules! compose_extrinsic { Era::Immortal, $api.genesis_hash, $api.genesis_hash, - $api.runtime_version.spec_version, + 2, $api.runtime_version.transaction_version ) } else { diff --git a/examples/example_setcode_extrinsic.rs b/examples/example_setcode_extrinsic.rs new file mode 100644 index 000000000..53468320a --- /dev/null +++ b/examples/example_setcode_extrinsic.rs @@ -0,0 +1,76 @@ +/* + Copyright 2019 Supercomputing Systems AG + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +///! Example that shows how to compose a setCode extrinsic. +/// Upgrade from node 1.05 to 1.0.6: use wasm integritee_node_runtime-v6.compact.wasm +use clap::{load_yaml, App}; +use sp_core::crypto::Ss58Codec; +use sp_core::{crypto::Pair, sr25519}; +use support::weights::Weight; + +use substrate_api_client::rpc::WsRpcClient; +use substrate_api_client::{compose_call, compose_extrinsic, Api, UncheckedExtrinsicV4, XtStatus}; + +fn main() { + env_logger::init(); + let url = get_node_url_from_cli(); + + // Alice's seed: subkey inspect //Alice + let from: sr25519::Pair = Pair::from_string( + "0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", + None, + ) + .unwrap(); + println!("signer account: {}", from.public().to_ss58check()); + + let client = WsRpcClient::new(&url); + let api = Api::new(client) + .map(|api| api.set_signer(from.clone())) + .unwrap(); + + //let new_wasm: &[u8] = include_bytes!("integritee_node_runtime-v6.compact.wasm"); + let new_wasm: &[u8] = include_bytes!("shell_runtime-v3.compact.compressed.wasm"); + + // this call can only be called by sudo + #[allow(clippy::redundant_clone)] + let call = compose_call!( + api.metadata.clone(), + "System", + "set_code_without_checks", + new_wasm.to_vec() + ); + + let weight: Weight = 0; + + #[allow(clippy::redundant_clone)] + let xt: UncheckedExtrinsicV4<_> = + compose_extrinsic!(api.clone(), "Sudo", "sudo_unchecked_weight", call, weight); + + // send and watch extrinsic until finalized + let tx_hash = api + .send_extrinsic(xt.hex_encode(), XtStatus::InBlock) + .unwrap(); + + println!("[+] Transaction got included. Hash: {:?}", tx_hash); +} + +pub fn get_node_url_from_cli() -> String { + let yml = load_yaml!("cli.yml"); + let matches = App::from_yaml(yml).get_matches(); + + let node_ip = matches.value_of("node-server").unwrap_or("ws://127.0.0.1"); + let node_port = matches.value_of("node-port").unwrap_or("9944"); + let url = format!("{}:{}", node_ip, node_port); + println!("Interacting with node on {}\n", url); + url +} diff --git a/examples/shell_runtime-v3.compact.compressed.wasm b/examples/shell_runtime-v3.compact.compressed.wasm new file mode 100644 index 000000000..66283c563 Binary files /dev/null and b/examples/shell_runtime-v3.compact.compressed.wasm differ