Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temporary work to unbrick the integritee para #215

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ node-template-runtime = { git = "https://github.com/paritytech/substrate.git", b
keyring = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master", package = "sp-keyring" }
clap = { version = "2.33", features = ["yaml"] }


[features]
default = ["std", "ws-client"]
std = [
Expand Down Expand Up @@ -130,6 +129,9 @@ path = "src/examples/example_custom_client.rs"
name = "example_get_existential_deposit"
path = "src/examples/example_get_existential_deposit.rs"

[[example]]
name = "example_transfer_using_seed"
path = "src/examples/example_transfer_using_seed.rs"
# DEPRECATED. might work but too much work to maintain, sorry

# needed for contract example
Expand Down
16 changes: 8 additions & 8 deletions src/examples/example_sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

use clap::{load_yaml, App};
use codec::Compact;
use keyring::AccountKeyring;
use sp_core::crypto::Pair;
use sp_core::{crypto::{Pair, Ss58Codec}, sr25519};
use substrate_api_client::rpc::WsRpcClient;
use substrate_api_client::{
compose_call, compose_extrinsic, Api, GenericAddress, UncheckedExtrinsicV4, XtStatus,
Expand All @@ -29,23 +28,24 @@ fn main() {
env_logger::init();
let url = get_node_url_from_cli();

// initialize api and set the signer (sender) that is used to sign the extrinsics
let sudoer = AccountKeyring::Alice.pair();
// Alice's seed: subkey inspect //Alice (replace with real sudo seed!)
let sudoer: sr25519::Pair = Pair::from_string("0xe5be9a5092b81bca64be81d212e7f2f9eba183bb7a90954f7b76361f6edb5c0a", None).unwrap();

let client = WsRpcClient::new(&url);
let api = Api::new(client).map(|api| api.set_signer(sudoer)).unwrap();

// set the recipient of newly issued funds
let to = AccountKeyring::Bob.to_account_id();
let to = sr25519::Public::from_ss58check("2LNz3ia9jQsgpCdRVu4MUhrar6LrVue6aCYnCebEhoegJeW2").unwrap();

// this call can only be called by sudo
#[allow(clippy::redundant_clone)]
let call = compose_call!(
api.metadata.clone(),
"Balances",
"set_balance",
GenericAddress::Id(to),
Compact(42_u128),
Compact(42_u128)
GenericAddress::Id(to.into()),
Compact(42_000_000_000_000u128),
Compact(0u128)
);
#[allow(clippy::redundant_clone)]
let xt: UncheckedExtrinsicV4<_> = compose_extrinsic!(api.clone(), "Sudo", "sudo", call);
Expand Down
80 changes: 80 additions & 0 deletions src/examples/example_transfer_using_seed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
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.
*/

///! Very simple example that shows how to use a predefined extrinsic from the extrinsic module
use clap::{load_yaml, App};
use sp_core::{crypto::{Pair, Ss58Codec}, sr25519};

use sp_runtime::MultiAddress;

use substrate_api_client::rpc::WsRpcClient;
use substrate_api_client::{Api, 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());
// initialize api and set the signer (sender) that is used to sign the extrinsics
//let from = AccountKeyring::Alice.pair();
let client = WsRpcClient::new(&url);
let api = Api::new(client)
.map(|api| api.set_signer(from.clone()))
.unwrap();

// Bob
let to = sr25519::Public::from_ss58check("5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty").unwrap();

match api.get_account_data(&to.into()).unwrap() {
Some(bob) => println!("[+] Bob's Free Balance is is {}\n", bob.free),
None => println!("[+] Bob's Free Balance is is 0\n"),
}
// generate extrinsic
let xt = api.balance_transfer(MultiAddress::Id(to.into()), 1000000000000);

println!(
"Sending an extrinsic from Alice (Key = {}),\n\nto Bob (Key = {})\n",
from.public(),
to
);

println!("[+] Composed extrinsic: {:?}\n", xt);

// send and watch extrinsic until finalized
let tx_hash = api
.send_extrinsic(xt.hex_encode(), XtStatus::InBlock)
.unwrap();
println!("[+] Transaction got included. Hash: {:?}\n", tx_hash);

// verify that Bob's free Balance increased
match api.get_account_data(&to.into()).unwrap() {
Some(bob) => println!("[+] Bob's Free Balance is is {}\n", bob.free),
None => println!("[+] Bob's Free Balance is is 0\n"),
}
}

pub fn get_node_url_from_cli() -> String {
let yml = load_yaml!("../../src/examples/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
}