Skip to content

Commit

Permalink
update rust bindings and add option to txs cli
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Jan 13, 2024
1 parent a5354ab commit fa9ad6d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 9 deletions.
36 changes: 36 additions & 0 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ pub enum EntryFunctionCall {
code: Vec<Vec<u8>>,
},

/// Users can change their account to slow, by calling the entry function
/// Warning: this is permanent for the account. There's no way to
/// reverse a "slow wallet".
SlowWalletSetSlow {},

SlowWalletSmokeTestVmUnlock {
user_addr: AccountAddress,
unlocked: u64,
Expand Down Expand Up @@ -806,6 +811,7 @@ impl EntryFunctionCall {
metadata_serialized,
code,
),
SlowWalletSetSlow {} => slow_wallet_set_slow(),
SlowWalletSmokeTestVmUnlock {
user_addr,
unlocked,
Expand Down Expand Up @@ -2105,6 +2111,24 @@ pub fn resource_account_create_resource_account_and_publish_package(
))
}

/// Users can change their account to slow, by calling the entry function
/// Warning: this is permanent for the account. There's no way to
/// reverse a "slow wallet".
pub fn slow_wallet_set_slow() -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("slow_wallet").to_owned(),
),
ident_str!("set_slow").to_owned(),
vec![],
vec![],
))
}

pub fn slow_wallet_smoke_test_vm_unlock(
user_addr: AccountAddress,
unlocked: u64,
Expand Down Expand Up @@ -3064,6 +3088,14 @@ mod decoder {
}
}

pub fn slow_wallet_set_slow(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(_script) = payload {
Some(EntryFunctionCall::SlowWalletSetSlow {})
} else {
None
}
}

pub fn slow_wallet_smoke_test_vm_unlock(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -3446,6 +3478,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"resource_account_create_resource_account_and_publish_package".to_string(),
Box::new(decoder::resource_account_create_resource_account_and_publish_package),
);
map.insert(
"slow_wallet_set_slow".to_string(),
Box::new(decoder::slow_wallet_set_slow),
);
map.insert(
"slow_wallet_smoke_test_vm_unlock".to_string(),
Box::new(decoder::slow_wallet_smoke_test_vm_unlock),
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
38 changes: 29 additions & 9 deletions tools/txs/src/txs_cli_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use diem_types::{
account_address::AccountAddress, account_config::CORE_CODE_ADDRESS,
transaction::TransactionPayload,
};
use libra_cached_packages::libra_stdlib::account_rotate_authentication_key;
use libra_cached_packages::libra_stdlib;
use libra_types::{
exports::{AuthenticationKey, Ed25519PrivateKey},
type_extensions::client_ext::ClientExt,
Expand All @@ -17,30 +17,50 @@ use libra_wallet::account_keys::get_keys_from_prompt;
#[derive(clap::Subcommand)]
pub enum UserTxs {
RotateKey(RotateKeyTx),
SetSlow(SetSlowTx),
}

#[derive(clap::Args)]
pub struct RotateKeyTx {
#[clap(short, long)]
/// The new authkey to be used
new_private_key: Option<String>, // Dev NOTE: account address has the same bytes as AuthKey
}

impl UserTxs {
pub async fn run(&self, sender: &mut Sender) -> anyhow::Result<()> {
match &self {
UserTxs::RotateKey(tx) => match tx.run(sender).await {
UserTxs::RotateKey(rotate) => match rotate.run(sender).await {
Ok(_) => println!("SUCCESS: privated key rotated"),
Err(e) => {
println!("ERROR: could not rotate private key, message: {}", e);
}
},
SetSlow => {

}
}

Ok(())
}
}

#[derive(clap::Args)]
pub struct SetSlowTx {
// TODO: any arguments needed? Confirmation?
}

impl SetSlowTx {
pub async fn run(&self, sender: &mut Sender) -> anyhow::Result<()> {
let payload = libra_stdlib::slow_wallet_set_slow();
sender.sign_submit_wait(payload).await?;
Ok(())
}
}


#[derive(clap::Args)]
pub struct RotateKeyTx {
#[clap(short, long)]
/// The new authkey to be used
new_private_key: Option<String>, // Dev NOTE: account address has the same bytes as AuthKey
}


impl RotateKeyTx {
pub async fn run(&self, sender: &mut Sender) -> anyhow::Result<()> {
let user_account: AccountAddress = sender.local_account.address();
Expand Down Expand Up @@ -94,7 +114,7 @@ pub fn rotate_key(
let rotation_proof_signed_by_new_private_key =
new_private_key.sign_arbitrary_message(&rotation_msg);

let payload = account_rotate_authentication_key(
let payload = libra_stdlib::account_rotate_authentication_key(
0,
// Existing public key
current_private_key.public_key().to_bytes().to_vec(),
Expand Down

0 comments on commit fa9ad6d

Please sign in to comment.