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

[Client] use new extrinsic: attest_attendees instead of old attest_claims #264

Merged
merged 3 commits into from
Nov 19, 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
21 changes: 10 additions & 11 deletions client/bootstrap_demo_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,11 @@

def perform_meetup(client, cid):
print('Starting meetup...')
print('Creating claims...')
vote = len(accounts)
claim1 = client.new_claim(account1, vote, cid)
claim2 = client.new_claim(account2, vote, cid)
claim3 = client.new_claim(account3, vote, cid)

print('Sending claims of attestees to chain...')
client.attest_claims(account1, [claim2, claim3])
client.attest_claims(account2, [claim1, claim3])
client.attest_claims(account3, [claim1, claim2])
print('Attest other attendees...')
client.attest_attendees(account1, cid, [account2, account3])
client.attest_attendees(account2, cid, [account1, account3])
client.attest_attendees(account3, cid, [account1, account2])


def update_spec_with_cid(file, cid):
Expand Down Expand Up @@ -186,14 +181,18 @@ def main(ipfs_local, client, port, spec_file):
faucet(client, cid)

register_participants_and_perform_meetup(client, cid, accounts)
client.next_phase()
client.await_block(1)

balance = client.balance(account1)

print("Claiming early rewards")
claim_rewards(client, cid, account1)
if(not balance == client.balance(account1)):
print("claim_reward fees were not refunded if paid in native currency")
exit(1)

client.next_phase()
client.await_block(1)

print(f'Balances for new community with cid: {cid}.')
bal = [client.balance(a, cid=cid) for a in accounts]
[print(f'Account balance for {ab[0]} is {ab[1]}.') for ab in list(zip(accounts, bal))]
Expand Down
6 changes: 2 additions & 4 deletions client/bot-community.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,10 @@ def perform_meetup(client: Client, meetup, cid):
n = len(meetup)
print(f'Performing meetup with {n} participants')

claims = [client.new_claim(p, n, cid) for p in meetup]

for p_index in range(len(meetup)):
attestor = meetup[p_index]
attestees_claims = claims[:p_index] + claims[p_index + 1:]
client.attest_claims(attestor, attestees_claims)
attendees = meetup[:p_index] + meetup[p_index + 1:]
client.attest_attendees(attestor, cid, attendees)


if __name__ == '__main__':
Expand Down
4 changes: 2 additions & 2 deletions client/py_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ def list_meetups(self, cid):
meetups.append(participants)
return meetups

def attest_claims(self, account, claims, pay_fees_in_cc=False):
ret = self.run_cli_command(["attest-claims", account] + claims, pay_fees_in_cc=pay_fees_in_cc)
def attest_attendees(self, account, cid, attendees, pay_fees_in_cc=False):
ret = self.run_cli_command(["attest-attendees", account] + attendees, cid=cid, pay_fees_in_cc=pay_fees_in_cc)
ensure_clean_exit(ret.returncode)

def list_attestees(self, cid):
Expand Down
14 changes: 7 additions & 7 deletions client/src/cli_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const ACCOUNT_ARG: &'static str = "accountid";
const SEED_ARG: &'static str = "seed";
const SIGNER_ARG: &'static str = "signer";
const CID_ARG: &'static str = "cid";
const CLAIMS_ARG: &'static str = "claims";
const ATTESTEES_ARG: &'static str = "attestees";
const CEREMONY_INDEX_ARG: &'static str = "ceremony-index";
const IPFS_CID_ARG: &'static str = "ipfs-cid";
const BOOTSTRAPPER_ARG: &'static str = "bootstrapper";
Expand All @@ -25,7 +25,7 @@ pub trait EncointerArgs<'b> {
fn seed_arg(self) -> Self;
fn signer_arg(self, help: &'b str) -> Self;
fn optional_cid_arg(self) -> Self;
fn claims_arg(self) -> Self;
fn attestees_arg(self) -> Self;
fn ceremony_index_arg(self) -> Self;
fn ipfs_cid_arg(self) -> Self;
fn bootstrapper_arg(self) -> Self;
Expand All @@ -46,7 +46,7 @@ pub trait EncointerArgsExtractor {
fn seed_arg(&self) -> Option<&str>;
fn signer_arg(&self) -> Option<&str>;
fn cid_arg(&self) -> Option<&str>;
fn claims_arg(&self) -> Option<Vec<&str>>;
fn attestees_arg(&self) -> Option<Vec<&str>>;
fn ceremony_index_arg(&self) -> Option<i32>;
fn ipfs_cid_arg(&self) -> Option<&str>;
fn bootstrapper_arg(&self) -> Option<&str>;
Expand Down Expand Up @@ -108,9 +108,9 @@ impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
)
}

fn claims_arg(self) -> Self {
fn attestees_arg(self) -> Self {
self.arg(
Arg::with_name(CLAIMS_ARG)
Arg::with_name(ATTESTEES_ARG)
.takes_value(true)
.required(true)
.multiple(true)
Expand Down Expand Up @@ -274,8 +274,8 @@ impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
self.value_of(CID_ARG)
}

fn claims_arg(&self) -> Option<Vec<&str>> {
self.values_of(CLAIMS_ARG).map(|c| c.collect())
fn attestees_arg(&self) -> Option<Vec<&str>> {
self.values_of(ATTESTEES_ARG).map(|c| c.collect())
}

fn ceremony_index_arg(&self) -> Option<i32> {
Expand Down
31 changes: 22 additions & 9 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,34 +1007,47 @@ fn main() {
}),
)
.add_cmd(
Command::new("attest-claims")
Command::new("attest-attendees")
.description("Register encointer ceremony claim of attendances for supplied community")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.account_arg()
.claims_arg()
.account_arg()
.optional_cid_arg()
.attestees_arg()
})
.runner(move |_args: &str, matches: &ArgMatches<'_>| {
let who = matches.account_arg().map(get_pair_from_str).unwrap();

let claims: Vec<ClaimOfAttendance<MultiSignature, AccountId, Moment>> = matches.claims_arg().unwrap()
let attestees: Vec<_> = matches.attestees_arg().unwrap()
.into_iter()
.map(|c| Decode::decode(&mut &hex::decode(c).unwrap()[..]).unwrap())
.map(get_accountid_from_str)
.collect();

debug!("claims: {:?}", claims);
let vote = attestees.len() as u32 + 1u32;

debug!("attestees: {:?}", attestees);

info!("send attest_claims by {}", who.public());
info!("send attest_attendees by {}", who.public());

let mut api = get_chain_api(matches).set_signer(who.clone().into());

let tx_payment_cid_arg = matches.tx_payment_cid_arg();
api = set_api_extrisic_params_builder(api, tx_payment_cid_arg);

let cid = verify_cid(&api,
matches
.cid_arg()
.expect("please supply argument --cid"),
None
);

let xt: EncointerXt<_> = compose_extrinsic!(
api.clone(),
"EncointerCeremonies",
"attest_claims",
claims.clone()
"attest_attendees",
cid,
vote,
attestees.clone()
);

ensure_payment(&api, &xt.hex_encode(), tx_payment_cid_arg);
Expand Down