Skip to content

Commit

Permalink
Added an optional coinbase address config property
Browse files Browse the repository at this point in the history
  • Loading branch information
aion-shidokht committed Nov 12, 2019
1 parent 3c5958a commit 708f845
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ port=8545

# Logging level
verboseLoggingEnabled=false

#---------------------------------------------------------------
# Following config properties are optional and mainly used for testing purposes
coinbaseAddress=
25 changes: 17 additions & 8 deletions src/org/aion/staker/BlockSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static void main(String[] args) throws InvalidKeySpecException, Interrupt
String ip = null;
String port = null;
boolean verboseLoggingEnabled = false;
String coinbaseAddress = "";

if (args.length == 0 || (args.length == 1 && args[0].equals("-h"))) {
printHelp();
Expand All @@ -49,6 +50,7 @@ public static void main(String[] args) throws InvalidKeySpecException, Interrupt
ip = config.getConfigValue("ip");
port = config.getConfigValue("port");
verboseLoggingEnabled = Boolean.parseBoolean(config.getConfigValue("verboseLoggingEnabled"));
coinbaseAddress = config.getConfigValue("coinbaseAddress");
} else if (args.length >= 3 && args.length <= 6) {
signingAddressPrivateKey = args[0];
identityAddressString = args[1];
Expand All @@ -74,7 +76,11 @@ public static void main(String[] args) throws InvalidKeySpecException, Interrupt
logger = new Logger(verboseLoggingEnabled);
stakerPrivateKey = getStakerPrivateKey(signingAddressPrivateKey);
rpc = new RPC(ip, port, logger);
coinbase = getCoinbaseAddress(networkName, identityAddressString);
if (coinbaseAddress.length() > 0) {
coinbase = getAddressFromString(coinbaseAddress);
} else {
coinbase = getCoinbaseAddress(networkName, identityAddressString);
}

logger.log("Producing blocks now..");

Expand Down Expand Up @@ -147,12 +153,6 @@ private static Address getCoinbaseAddress(String networkName, String identityAdd
throw new IllegalArgumentException("null identity address provided");
}

if (identityAddressString.startsWith("0x")) {
identityAddressString = identityAddressString.substring(2);
}

byte[] identityAddressBytes = Hex.decode(identityAddressString);

Address stakerRegistryAddress;
if (networkName.toLowerCase().equals("amity")) {
stakerRegistryAddress = STAKER_REGISTRY_AMITY_ADDRESS;
Expand All @@ -166,7 +166,7 @@ private static Address getCoinbaseAddress(String networkName, String identityAdd

byte[] callData = new ABIStreamingEncoder()
.encodeOneString("getCoinbaseAddress")
.encodeOneAddress(new avm.Address(identityAddressBytes))
.encodeOneAddress(getAddressFromString(identityAddressString))
.toBytes();

Transaction callTx = new Transaction(stakerRegistryAddress, callData);
Expand All @@ -182,4 +182,13 @@ private static void printHelp(){
System.out.println("-config <configFilePath>");
System.exit(0);
}

private static Address getAddressFromString(String addressString){
if (addressString.startsWith("0x")) {
addressString = addressString.substring(2);
}

byte[] addressBytes = Hex.decode(addressString);
return new avm.Address(addressBytes);
}
}

0 comments on commit 708f845

Please sign in to comment.