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

Various wallet/snap fixes #533

Merged
merged 4 commits into from
Jul 2, 2018
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
4 changes: 2 additions & 2 deletions multinode-demo/client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ rsync_leader_url=$(rsync_url "$leader")

set -ex
mkdir -p $SOLANA_CONFIG_DIR
rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/
$rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
$rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/

# shellcheck disable=SC2086 # $solana_client_demo should not be quoted
exec $solana_client_demo \
Expand Down
2 changes: 2 additions & 0 deletions multinode-demo/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
# Disable complaints about unused variables in this file:
# shellcheck disable=2034

rsync=rsync
if [[ -d "$SNAP" ]]; then # Running inside a Linux Snap?
solana_program() {
declare program="$1"
printf "%s/command-%s.wrapper" "$SNAP" "$program"
}
rsync="$SNAP"/bin/rsync
SOLANA_CUDA="$(snapctl get enable-cuda)"

elif [[ -n "$USE_SNAP" ]]; then # Use the Linux Snap binaries
Expand Down
4 changes: 2 additions & 2 deletions multinode-demo/drone.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ fi
rsync_leader_url=$(rsync_url "$leader")
set -ex
mkdir -p $SOLANA_CONFIG_DIR
rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/
$rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
$rsync -vPz "$rsync_leader_url"/config-private/mint.json $SOLANA_CONFIG_DIR/

# shellcheck disable=SC2086 # $solana_drone should not be quoted
exec $solana_drone \
Expand Down
2 changes: 1 addition & 1 deletion multinode-demo/validator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ rsync_leader_url=$(rsync_url "$leader")
set -ex
SOLANA_LEADER_CONFIG_DIR="$SOLANA_CONFIG_DIR"/leader-config
rm -rf "$SOLANA_LEADER_CONFIG_DIR"
rsync -vPrz "$rsync_leader_url"/config/ "$SOLANA_LEADER_CONFIG_DIR"
$rsync -vPrz "$rsync_leader_url"/config/ "$SOLANA_LEADER_CONFIG_DIR"
ls -lh "$SOLANA_LEADER_CONFIG_DIR"

# shellcheck disable=SC2086 # $program should not be quoted
Expand Down
6 changes: 3 additions & 3 deletions multinode-demo/wallet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ here=$(dirname "$0")
source "$here"/common.sh
SOLANA_CONFIG_DIR=config-client

# if $1 isn't host:path or some local path
if [[ ${1%:} != "$1" || -d $1 ]]; then
# if $1 isn't host:path, something.com, or a valid local path
if [[ ${1%:} != "$1" || "$1" =~ [^.].[^.] || -d $1 ]]; then
leader=$1 # interpret
shift
else
Expand All @@ -21,7 +21,7 @@ rsync_leader_url=$(rsync_url "$leader")
set -e
mkdir -p $SOLANA_CONFIG_DIR
if [[ ! -r $SOLANA_CONFIG_DIR/leader.json ]]; then
rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
$rsync -vPz "$rsync_leader_url"/config/leader.json $SOLANA_CONFIG_DIR/
fi

client_json=$SOLANA_CONFIG_DIR/client.json
Expand Down
27 changes: 22 additions & 5 deletions src/bin/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum WalletCommand {
#[derive(Debug, Clone)]
enum WalletError {
CommandNotRecognized(String),
BadParameter(String),
}

impl fmt::Display for WalletError {
Expand Down Expand Up @@ -173,6 +174,11 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
let pubkey_vec = bs58::decode(pay_matches.value_of("to").unwrap())
.into_vec()
.expect("base58-encoded public key");

if pubkey_vec.len() != std::mem::size_of::<PublicKey>() {
display_actions();
Err(WalletError::BadParameter("Invalid public key".to_string()))?;
}
to = PublicKey::clone_from_slice(&pubkey_vec);
} else {
to = id.pubkey();
Expand All @@ -187,8 +193,14 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
let sig_vec = bs58::decode(confirm_matches.value_of("signature").unwrap())
.into_vec()
.expect("base58-encoded signature");
let sig = Signature::clone_from_slice(&sig_vec);
Ok(WalletCommand::Confirm(sig))

if sig_vec.len() == std::mem::size_of::<Signature>() {
let sig = Signature::clone_from_slice(&sig_vec);
Ok(WalletCommand::Confirm(sig))
} else {
display_actions();
Err(WalletError::BadParameter("Invalid signature".to_string()))
}
}
("balance", Some(_balance_matches)) => Ok(WalletCommand::Balance),
("address", Some(_address_matches)) => Ok(WalletCommand::Address),
Expand Down Expand Up @@ -238,7 +250,7 @@ fn process_command(
WalletCommand::AirDrop(tokens) => {
println!("Airdrop requested...");
println!("Airdropping {:?} tokens", tokens);
let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64);
let _airdrop = request_airdrop(&config.drone_addr, &config.id, tokens as u64)?;
// TODO: return airdrop Result from Drone
sleep(Duration::from_millis(100));
println!(
Expand Down Expand Up @@ -301,15 +313,20 @@ fn mk_client(r: &ReplicatedData) -> io::Result<ThinClient> {
))
}

fn request_airdrop(drone_addr: &SocketAddr, id: &Mint, tokens: u64) {
let mut stream = TcpStream::connect(drone_addr).unwrap();
fn request_airdrop(
drone_addr: &SocketAddr,
id: &Mint,
tokens: u64,
) -> Result<(), Box<error::Error>> {
let mut stream = TcpStream::connect(drone_addr)?;
let req = DroneRequest::GetAirdrop {
airdrop_request_amount: tokens,
client_public_key: id.pubkey(),
};
let tx = serialize(&req).expect("serialize drone request");
stream.write_all(&tx).unwrap();
// TODO: add timeout to this function, in case of unresponsive drone
Ok(())
}

fn main() -> Result<(), Box<error::Error>> {
Expand Down