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

Second Leu rescue tooling #249

Merged
merged 8 commits into from
Aug 20, 2022
Merged
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
9 changes: 9 additions & 0 deletions client/batch-transfer-calls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CID=u0qj944rhWE
SENDER=5GTUm6tgZwqn8pqinRz3tAKAXinXHUnncCWVs5mvYqfZtz4v
while IFS="," read -r accountk account amount
do
#echo "$account $amount"
CALL=$(encointer-client-notee -u wss://kusama.api.encointer.org -p 443 transfer $SENDER $account $amount --cid $CID --dryrun)
echo "$CALL"
done < $1

43 changes: 43 additions & 0 deletions client/batch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
"""
create a substrate batch call from a file with individual calls per line, hex encoded and 0x prefixed
"""

from substrateinterface import SubstrateInterface
from substrateinterface.base import RuntimeConfigurationObject
from scalecodec.types import GenericCall
from scalecodec import ScaleBytes
import click
import csv

@click.command()
@click.argument('filename')
@click.option('--endpoint', default="ws://localhost:9944", help='rpc websocket endpoint to talk to the chain')
@click.option('--maxcalls', default=100, help='maximum number of calls in same batch')
def batch(filename, endpoint, maxcalls):
substrate = SubstrateInterface(
url=endpoint
)
#call = RuntimeConfigurationObject().create_scale_object("Call")
calls = []
with open(filename) as calls_file:
reader = csv.reader(calls_file)
for row in reader:
call = GenericCall(ScaleBytes(row[0]))
calls.append(call)

print(f"read {len(calls)} calls from {filename}")

chunks = [calls[i:i + maxcalls] for i in range(0, len(calls), maxcalls)]
for chunk in chunks:
batch_call = substrate.compose_call(
call_module='Utility',
call_function='batch_all',
call_params={
'calls': chunk
}
)
print(batch_call.encode())

if __name__ == '__main__':
batch()
15 changes: 15 additions & 0 deletions client/dump-accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

#!/usr/bin/env python3
"""
dump all existing accounts for an endpoint/chain
"""
from substrateinterface import SubstrateInterface

substrate = SubstrateInterface(
url="wss://kusama.api.encointer.org"
)

result = substrate.query_map('System', 'Account')

for account, identity_info in result:
print(f"{account.value}")
2 changes: 1 addition & 1 deletion client/dump_account_balances.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cat accounts_all.txt | while read a
do
BAL=$(../target/release/encointer-client-notee -u wss://kusama.api.encointer.org -p 443 balance $a --cid u0qj92QX9PQ --at 0xcfb07c60aadd57676ce0591678b58511ebd03bdef7385c9690f42e744f1dbff6)
BAL=$(../target/release/encointer-client-notee -u wss://kusama.api.encointer.org -p 443 balance $a --cid u0qj9QqA2Q --at 0xe3310c3d23bb95a618f72cca98a512c1e928923e80997bd29d121bc66bcb8a86)
# translate Kusama prefix to substrate prefix for easy search
ACC=$(subkey inspect $a --network substrate | grep -P '^[\s]+SS58' | sed 's/^ *SS58 Address: *//')
echo $a,$ACC,$BAL
Expand Down
5 changes: 2 additions & 3 deletions client/fetch-account-history.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
for block in range(start_block, end_block):
page = 0
while True:
response = requests.post('https://encointer.api.subscan.io/api/scan/events',
try:
response = requests.post('https://encointer.api.subscan.io/api/scan/events',
headers={
'Content-Type': 'application/json',
'X-API-Key': api_key,
Expand All @@ -46,8 +47,6 @@
'block_num': block
}
)

try:
events = response.json()['data']['events']
except:
print(response)
Expand Down
16 changes: 16 additions & 0 deletions client/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const TO_CINDEX_ARG: &'static str = "to-cindex";
const ENDORSEES_ARG: &'static str = "endorsees";
const TIME_OFFSET_ARG: &'static str = "time-offset";
const ALL_FLAG: &'static str = "all";
const DRYRUN_FLAG: &'static str = "dryrun";
const TX_PAYMENT_CID_ARG: &'static str = "tx-payment-cid";
const MEETUP_INDEX_ARG: &'static str = "meetup-index";
const AT_BLOCK_ARG: &'static str = "at";
Expand All @@ -32,6 +33,7 @@ pub trait EncointerArgs<'b> {
fn endorsees_arg(self) -> Self;
fn time_offset_arg(self) -> Self;
fn all_flag(self) -> Self;
fn dryrun_flag(self) -> Self;
fn tx_payment_cid_arg(self) -> Self;
fn meetup_index_arg(self) -> Self;
fn at_block_arg(self) -> Self;
Expand All @@ -51,6 +53,7 @@ pub trait EncointerArgsExtractor {
fn endorsees_arg(&self) -> Option<Vec<&str>>;
fn time_offset_arg(&self) -> Option<i32>;
fn all_flag(&self) -> bool;
fn dryrun_flag(&self) -> bool;
fn tx_payment_cid_arg(&self) -> Option<&str>;
fn meetup_index_arg(&self) -> Option<u64>;
fn at_block_arg(&self) -> Option<Hash>;
Expand Down Expand Up @@ -195,6 +198,16 @@ impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
.help("list all community currency balances for account"),
)
}
fn dryrun_flag(self) -> Self {
self.arg(
Arg::with_name(DRYRUN_FLAG)
.short("d")
.long("dryrun")
.takes_value(false)
.required(false)
.help("print the encoded call instead of signing and sending an extrinsic"),
)
}
fn tx_payment_cid_arg(self) -> Self {
self.arg(
Arg::with_name(TX_PAYMENT_CID_ARG)
Expand Down Expand Up @@ -281,6 +294,9 @@ impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
fn all_flag(&self) -> bool {
self.is_present(ALL_FLAG)
}
fn dryrun_flag(&self) -> bool {
self.is_present(DRYRUN_FLAG)
}
fn tx_payment_cid_arg(&self) -> Option<&str> {
self.value_of(TX_PAYMENT_CID_ARG)
}
Expand Down
45 changes: 30 additions & 15 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ fn main() {
.description("transfer funds from one account to another. If --cid is supplied, send that community (amount is fixpoint). Otherwise send native ERT tokens (amount is integer)")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.dryrun_flag()
.arg(
Arg::with_name("from")
.takes_value(true)
Expand All @@ -281,48 +282,62 @@ fn main() {
)
})
.runner(|_args: &str, matches: &ArgMatches<'_>| {
let api = get_chain_api(matches);
let mut api = get_chain_api(matches);
let arg_from = matches.value_of("from").unwrap();
let arg_to = matches.value_of("to").unwrap();
let from = get_pair_from_str(arg_from);
if !matches.dryrun_flag() {
let from = get_pair_from_str(arg_from);
info!("from ss58 is {}", from.public().to_ss58check());
api = api.set_signer(sr25519_core::Pair::from(from));
}
let to = get_accountid_from_str(arg_to);
info!("from ss58 is {}", from.public().to_ss58check());
info!("to ss58 is {}", to.to_ss58check());
let mut _api = api.set_signer(sr25519_core::Pair::from(from));
let tx_payment_cid_arg = matches.tx_payment_cid_arg();
let tx_hash = match matches.cid_arg() {
Some(cid_str) => {
let cid = verify_cid(&_api, cid_str, None);
let cid = verify_cid(&api, cid_str, None);
let amount = BalanceType::from_str(matches.value_of("amount").unwrap())
.expect("amount can be converted to fixpoint");

_api = set_api_extrisic_params_builder(_api, tx_payment_cid_arg);
api = set_api_extrisic_params_builder(api, tx_payment_cid_arg);

let xt: EncointerXt<_> = compose_extrinsic!(
_api.clone(),
api.clone(),
"EncointerBalances",
"transfer",
to.clone(),
cid,
amount
);
ensure_payment(&_api, &xt.hex_encode(), tx_payment_cid_arg);
_api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap()
if matches.dryrun_flag() {
println!("0x{}", hex::encode(xt.function.encode()));
None
} else {
ensure_payment(&api, &xt.hex_encode(), tx_payment_cid_arg);
api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap()
}
},
None => {
let amount = u128::from_str_radix(matches.value_of("amount").unwrap(), 10)
.expect("amount can be converted to u128");
let xt = _api.balance_transfer(
let xt = api.balance_transfer(
GenericAddress::Id(to.clone()),
amount
);
ensure_payment(&_api, &xt.hex_encode(), tx_payment_cid_arg);
_api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap()
if matches.dryrun_flag() {
println!("0x{}", hex::encode(xt.function.encode()));
None
} else {
ensure_payment(&api, &xt.hex_encode(), tx_payment_cid_arg);
api.send_extrinsic(xt.hex_encode(), XtStatus::InBlock).unwrap()
}
}
};
info!("[+] Transaction included. Hash: {:?}\n", tx_hash);
let result = _api.get_account_data(&to.clone()).unwrap().unwrap();
println!("balance for {} is now {}", to, result.free);
if let Some(txh) = tx_hash {
info!("[+] Transaction included. Hash: {:?}\n", txh);
let result = api.get_account_data(&to.clone()).unwrap().unwrap();
println!("balance for {} is now {}", to, result.free);
}
Ok(())
}),
)
Expand Down
38 changes: 38 additions & 0 deletions client/test-data/leu.zuerich.V2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"type": "FeatureCollection",
"community": {
"meta": {
"name": "Leu Zurich",
"symbol": "LEU",
"assets": "QmSpwTDiKbRVqHaV2LvaUVkwZkkuF8w1BjTjwXD9PEzHnd",
"url": "https://leu.zuerich"
},
"bootstrappers": [
"5HTJ7uvBZgp4VcXsWqMSz5r6C5vCzfodB3oYgJikmbesmGAQ",
"5ELFUAhU3qNijJeWi9vDHR8Q8GTmdeQ7vCmhwHYBTKLfkiVt",
"5F4WftsrF1Wqtbm7kK5FRRrvUf4w8syazFJH3Mz5JkdcZqs7",
"5Cm38saAbnwrxvnGCp4Pqff5K3rKy4awYQnrdqDeHfvW2ZUM",
"5EEh6sjZjxaMkm3vn7nKib9ciuxAGQRc4uosmuDa6vuTgfDp",
"5FvNKkMDRb8pBsXfxRBphY9ZmkkCNUHWnq5Dpw7hKpvBU1L4",
"5F23TQ7ReiDj3fDKra9QwWSy94XAsmF4AKVdBFLmn4bmUYAD",
"5C86aoJWYuuHxYsi5d74ddJ6tYNhwnLeXHe5qqBWui2cmmPh",
"5Hq1naLbJFSYzeVxPySmxH2qHgUBULQW9hPyNxKSuBGEJzSZ",
"5E9bTMkC6tJUKBxw7Jz9qQ1t1yVAU2j3ctXbsE7JVccfaK4X"
],
"demurrage_halving_blocks": 2628000,
"ceremony_income": 1077
},
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
8.516483679413795,
47.389592385736165
]
}
}
]
}
4 changes: 2 additions & 2 deletions client/test-data/leu.zuerich.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"url": "https://leu.zuerich"
},
"bootstrappers": [
"5Hq1naLbJFSYzeVxPySmxH2qHgUBULQW9hPyNxKSuBGEJzSZ",
"5HTJ7uvBZgp4VcXsWqMSz5r6C5vCzfodB3oYgJikmbesmGAQ",
"5ELFUAhU3qNijJeWi9vDHR8Q8GTmdeQ7vCmhwHYBTKLfkiVt",
"5F4WftsrF1Wqtbm7kK5FRRrvUf4w8syazFJH3Mz5JkdcZqs7",
Expand All @@ -16,11 +17,10 @@
"5FvNKkMDRb8pBsXfxRBphY9ZmkkCNUHWnq5Dpw7hKpvBU1L4",
"5F23TQ7ReiDj3fDKra9QwWSy94XAsmF4AKVdBFLmn4bmUYAD",
"5C86aoJWYuuHxYsi5d74ddJ6tYNhwnLeXHe5qqBWui2cmmPh",
"5Hq1naLbJFSYzeVxPySmxH2qHgUBULQW9hPyNxKSuBGEJzSZ",
"5E9bTMkC6tJUKBxw7Jz9qQ1t1yVAU2j3ctXbsE7JVccfaK4X"
],
"demurrage_halving_blocks": 2628000,
"ceremony_income": 1077
"ceremony_income": 1520
},
"features": [
{
Expand Down