Newer
Older
#[subxt::subxt(
runtime_metadata_path = "res/metadata.scale",
derive_for_all_types = "Debug"
)]
pub mod runtime {
// IF NEEDED
// #[subxt(substitute_type = "spcore::sr25519::Signature")]
// use crate::gdev::runtime_types::sp_core::sr25519::Signature;
}
pub type Client = subxt::OnlineClient<Runtime>;
pub type AccountId = subxt::ext::sp_runtime::AccountId32;
pub type TxInBlock = subxt::tx::TxInBlock<Runtime, Client>;
pub type TxProgress = subxt::tx::TxProgress<Runtime, Client>;
pub type Balance = u64;
pub type AccountData = runtime::runtime_types::pallet_duniter_account::types::AccountData<Balance>;
pub type AccountInfo = runtime::runtime_types::frame_system::AccountInfo<u32, AccountData>;
type Hashing = subxt::ext::sp_runtime::traits::BlakeTwo256;
type Address = subxt::ext::sp_runtime::MultiAddress<Self::AccountId, u32>;
type Header = subxt::ext::sp_runtime::generic::Header<
Self::BlockNumber,
subxt::ext::sp_runtime::traits::BlakeTwo256,
>;
type Signature = subxt::ext::sp_runtime::MultiSignature;
type ExtrinsicParams = subxt::tx::BaseExtrinsicParams<Self, Tip>;
// Tip for transaction fee
#[derive(Copy, Clone, Debug, Default, codec::Encode)]
pub fn new(amount: u64) -> Self {
Tip { tip: amount }
}
// define command line arguments
#[derive(Clone, clap::Parser, Debug, Default)]
#[clap(subcommand)]
pub subcommand: Subcommand,
/// Overwrite indexer endpoint
#[clap(short, long, default_value = "")]
indexer: String,
/// Do not use indexer
#[clap(long)]
no_indexer: bool,
/// Secret key or BIP39 mnemonic
/// (eventually followed by derivation path)
#[clap(short, long)]
secret: Option<String>,
/// Secret key format (seed, substrate)
#[clap(short = 'S', long, default_value = SecretFormat::Substrate)]
secret_format: SecretFormat,
/// Address
#[clap(short, long)]
address: Option<String>,
/// Overwrite duniter websocket RPC endpoint
#[clap(short, long, default_value = "")]
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/// track progress of transaction on the network
/// until it is in block with success or failure
pub async fn track_progress(progress: TxProgress) -> anyhow::Result<()> {
println!("submitted transaction to network, waiting 6 seconds...");
// wait for in block
let tx = progress.wait_for_in_block().await?;
// print result
println!("{:?}", tx.wait_for_success().await?);
// return empty
Ok(())
}
/// custom error type intended to provide more convenient error message to user
#[derive(Debug)]
pub enum GcliError {
/// error coming from subxt
Subxt(subxt::Error),
/// error coming from anyhow
Anyhow(anyhow::Error),
}
impl std::fmt::Display for GcliError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for GcliError {}
impl From<subxt::Error> for GcliError {
fn from(e: subxt::Error) -> GcliError {
GcliError::Subxt(e)
}
}
impl From<anyhow::Error> for GcliError {
fn from(e: anyhow::Error) -> GcliError {
GcliError::Anyhow(e)
}
}
#[derive(Clone, Debug, clap::Subcommand, Default)]
/// Show address corresponding to given arguments
ShowAddress,
/// Fetch identity
Identity {
#[clap(short = 'p', long = "pubkey")]
account_id: Option<AccountId>,
#[clap(short = 'i', long = "identity")]
identity_id: Option<u32>,
#[clap(short = 'u', long = "username")]
username: Option<String>,
},
/// Create and certify an identity
///
/// Caller must be member, and the target account must exist.
CreateIdentity {
/// Confirm an identity
///
/// To be called by the certified not-yet-member account, to become member.
ConfirmIdentity {
name: String,
},
/// Generate a revocation document for the provided account
GenRevocDoc,
/// Revoke an identity immediately
RevokeIdentity,
#[clap(long = "oneshot")]
dest_oneshot: bool,
},
ConsumeOneshotWithRemaining {
balance: u64,
#[clap(long = "rem-one")]
remaining_to_oneshot: bool,
},
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/// List upcoming expirations that require an action
Expire {
/// Show certs that expire within less than this number of blocks
#[clap(short, long, default_value_t = 100800)]
blocks: u32,
/// Show authorities that should rotate keys within less than this number of sessions
#[clap(short, long, default_value_t = 100)]
sessions: u32,
},
GoOffline,
GoOnline,
/// List online authorities
Online,
#[clap(hide = true)]
Repart {
// Number of transactions per block to target
target: u32,
#[clap(short = 'o', long = "old-repart")]
// Old/actual repartition
actual_repart: Option<u32>,
},
#[clap(hide = true)]
SpamRoll {
actual_repart: usize,
},
SudoSetKey {
/// Emit a smith certification
SmithCert {
to: u32,
},
/// List members of the technical committee
TechMembers,
/// List proposals to the technical committee
TechProposals,
/// Vote a proposal to the technical committee
TechVote {
/// Proposal hash
hash: H256,
/// Proposal index
index: u32,
/// Vote (0=against, 1=for)
vote: u8,
},
Transfer {
/// Amount to transfer
amount: u64,
/// Destination address
/// Prevent from going below account existential deposit
#[clap(short = 'k', long = "keep-alive")]
keep_alive: bool,
},
/// Transfer the same amount for each space-separated address.
/// If an address appears mutiple times, it will get multiple times the same amount
TransferMultiple {
/// Amount given to each destination address
amount: u64,
/// List of target addresses
},
/// Rotate and set session keys
UpdateKeys,
/// Check current block
CurrentBlock,
/// Check that indexer and node are on the same network
CheckIndexerAgainstBlockchain,
Indexer(indexer::Subcommand),
/// Config subcommands
#[clap(subcommand)]
Config(conf::Subcommand),
Subcommand::GetBalance => {
data = data
.build_client()
.await
.fetch_system_properties()
.await?;
commands::account::get_balance(data).await?
}
Subcommand::ShowAddress => {
data = data.build_address();
println!("address is: {}", data.address());
}
Subcommand::CreateIdentity { target } => {
data = data.build_client().await.build_keypair();
let progress =
commands::identity::create_identity(data.keypair(), data.client(), target).await?;
track_progress(progress).await?
}
Subcommand::ConfirmIdentity { name } => {
data = data.build_client().await.build_keypair();
let progress =
commands::identity::confirm_identity(data.keypair(), data.client(), name).await?;
track_progress(progress).await?
Subcommand::RevokeIdentity => {
data = data
.build_client()
.await
.build_keypair()
.fetch_idty_index()
.await?
.fetch_genesis_hash()
.await?;
let progress = commands::identity::revoke_identity(data).await?;
track_progress(progress).await?
}
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
Subcommand::CreateOneshot { balance, dest } => {
commands::oneshot::create_oneshot_account(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
balance,
dest,
)
.await?
}
Subcommand::ConsumeOneshot { dest, dest_oneshot } => {
commands::oneshot::consume_oneshot_account(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
dest,
dest_oneshot,
)
.await?
}
Subcommand::ConsumeOneshotWithRemaining {
balance,
dest,
dest_oneshot,
remaining_to,
remaining_to_oneshot,
} => {
commands::oneshot::consume_oneshot_account_with_remaining(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
balance,
dest,
dest_oneshot,
remaining_to,
remaining_to_oneshot,
)
.await?
}
Subcommand::Expire { blocks, sessions } => {
commands::expire::monitor_expirations(
Client::from_url(&args.url).await.unwrap(),
blocks,
sessions,
&args,
)
.await?
}
Subcommand::Identity {
ref account_id,
identity_id,
ref username,
} => {
account_id.clone(),
identity_id,
username.clone(),
&args,
)
.await?
}
Subcommand::GenRevocDoc => {
data = data
.build_client()
.await
.build_keypair()
.fetch_idty_index()
.await?
.fetch_genesis_hash()
.await?;
commands::revocation::print_revoc_sig(&data)
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
}
Subcommand::GoOffline => {
commands::smith::go_offline(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
)
.await?
}
Subcommand::GoOnline => {
commands::smith::go_online(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
)
.await?
}
Subcommand::OneshotBalance { account } => {
commands::oneshot::oneshot_account_balance(
Client::from_url(&args.url).await.unwrap(),
account,
)
.await?
}
Subcommand::Online => {
commands::smith::online(Client::from_url(&args.url).await.unwrap(), &args).await?
}
Subcommand::Repart {
target,
actual_repart,
} => {
commands::net_test::repart(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
target,
actual_repart,
)
.await?
}
Subcommand::SpamRoll { actual_repart } => {
commands::net_test::spam_roll(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
actual_repart,
)
.await?
}
Subcommand::SudoSetKey { new_key } => {
data = data.build_keypair().build_client().await;
commands::sudo::set_key(data.keypair(), data.client(), new_key).await?
Subcommand::SmithCert { to } => {
data = data
.build_client()
.await
.build_keypair()
.fetch_idty_index()
.await?;
commands::smith::cert(data.client(), data.keypair(), data.idty_index(), to).await?
}
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
Subcommand::TechMembers => {
commands::collective::technical_committee_members(
Client::from_url(&args.url).await.unwrap(),
&args,
)
.await?
}
Subcommand::TechProposals => {
commands::collective::technical_committee_proposals(
Client::from_url(&args.url).await.unwrap(),
)
.await?
}
Subcommand::TechVote { hash, index, vote } => {
let vote = match vote {
0 => false,
1 => true,
_ => panic!("Vote must be written 0 if you disagree, or 1 if you agree."),
};
commands::collective::technical_committee_vote(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
hash, //H256::from_str(&hash).expect("Invalid hash formatting"),
index,
vote,
)
.await?
}
Subcommand::Transfer {
amount,
dest,
keep_alive,
} => {
commands::transfer::transfer(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
amount,
dest,
keep_alive,
)
.await?
}
Subcommand::TransferMultiple { amount, dests } => {
commands::transfer::transfer_multiple(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
amount,
dests,
)
.await?
}
Subcommand::UpdateKeys => commands::smith::update_session_keys(
get_keys(
args.secret_format,
&args.address,
&args.secret,
NeededKeys::Secret,
)?
.1
.unwrap(),
Client::from_url(&args.url).await.unwrap(),
)
.await
.unwrap(),
Subcommand::RuntimeInfo => {
data = data.build_client().await.fetch_system_properties().await?;
commands::runtime::runtime_info(data).await;
}
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
Subcommand::CurrentBlock => {
data = data.build_client().await;
println!(
"current block: {}",
data.client()
.storage()
.fetch(&runtime::storage().system().number(), None)
.await?
.unwrap()
);
}
Subcommand::CheckIndexerAgainstBlockchain => {
data = data
.build_client()
.await
.build_indexer()?
.fetch_genesis_hash()
.await?
.fetch_indexer_genesis_hash()
.await?;
if data.genesis_hash == data.indexer_genesis_hash {
println!(
"{} and {} have the same genesis hash: {}",
data.args.url,
data.indexer().gql_url,
data.genesis_hash
);
} else {
println!(
"⚠️ {} ({}) and {} ({}) do not share same genesis",
data.args.url,
data.genesis_hash,
data.indexer().gql_url,
data.indexer_genesis_hash
);
}
}
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await?,
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand)?,