Skip to content

Commit

Permalink
Code tidying, more CLI tightening
Browse files Browse the repository at this point in the history
  • Loading branch information
mikera committed Jan 30, 2024
1 parent 1220124 commit 6081955
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 3 additions & 1 deletion convex-cli/src/main/java/convex/cli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,12 @@ public char[] getKeyPassword() {
keypass=new char[0];
}
}
if (keypass.length==0) {
paranoia("Cannot use an empty private key password");
}
return keypass;
}


/**
* Gets the keystore file name currently used for the CLI
* @return File name, or null if not specified
Expand Down
12 changes: 2 additions & 10 deletions convex-cli/src/main/java/convex/cli/key/KeyGenerate.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.security.KeyStore;
import java.util.Arrays;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import convex.cli.Constants;
import convex.core.crypto.AKeyPair;
import convex.core.crypto.BIP39;
Expand All @@ -31,8 +28,6 @@
description="Generate private key pair(s) in the currently configured keystore. Will create a keystore if it does not exist.")
public class KeyGenerate extends AKeyCommand {

private static final Logger log = LoggerFactory.getLogger(KeyGenerate.class);

@Option(names="--count",
defaultValue="" + Constants.KEY_GENERATE_COUNT,
description="Number of keys to generate. Default: ${DEFAULT-VALUE}")
Expand Down Expand Up @@ -60,7 +55,7 @@ private AKeyPair generateKeyPair() {
}
}
if (passphrase.isBlank()) {
cli().paranoia("Cannot use an empty passphrase for secure key generation");
cli().paranoia("Cannot use an empty BIP39 passphrase for secure key generation");
}
Blob bipseed = BIP39.getSeed(mnemonic, passphrase);
AKeyPair result= BIP39.seedToKeyPair(bipseed);
Expand All @@ -77,10 +72,9 @@ private AKeyPair generateKeyPair() {
public void run() {
// check the number of keys to generate.
if (count <= 0) {
log.warn("No keys to generate: count = "+count);
cli().printErr("No keys generated. Perhaps specify a positive --count ?");
return;
}
log.debug("Generating {} keys",count);

char[] storePass=cli().getStorePassword();
try {
Expand All @@ -93,9 +87,7 @@ public void run() {
PFXTools.setKeyPair(ks, kp, keyPassword);
Arrays.fill(keyPassword, 'p');
}
log.debug(count+ " keys successfully generated");
cli().saveKeyStore(storePass);
log.trace("Keystore saved successfully");
} catch (Throwable e) {
throw Utils.sneakyThrow(e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ private void buy(Object outcome) {
changeStake(outcome, 1000000);
}

@SuppressWarnings("unused")
private void changeStake(Object outcome, long delta) {
// TODO: this is broken and needs fixing
State state = marketsPanel.getLatestState();
Long stk = getStake(state, outcome);
if (stk == null) stk = 0L;
Expand Down

0 comments on commit 6081955

Please sign in to comment.