Skip to content

Commit

Permalink
Made initial self bond value an input parameter to the script
Browse files Browse the repository at this point in the history
  • Loading branch information
aion-shidokht committed Oct 15, 2019
1 parent 221971b commit ece8261
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ Pool will be in an active state after registration is complete.

**Usage:**

```./registerPool.sh node_address private_key signing_address commission_rate metadata_url metadata_content_hash```
```./registerPool.sh node_address private_key signing_address commission_rate metadata_url metadata_content_hash value```

`node_address` node address in ip:port format.<br />
`private_key` private key of the pool identity address. Private key should start with `0x`. Both 32 and 64 byte keys are accepted as an input.<br />
`signing_address` signing address of the pool.<br />
`commission_rate` the pool commission rate with 4 decimal places of granularity (between [0, 1000000]).<br />
`metadata_url` url hosting the metadata json file.<br />
`metadata_content_hash` Blake2b hash of the json object hosted at the metadata url.<br />
`value` value in nAmps to pass along the transaction. This will be counted towards the self-bond value and has to be at least 1000 Aions (1000000000000000000000 nAmps).<br />

### delegate.sh

Expand Down
Binary file modified Tools.jar
Binary file not shown.
12 changes: 7 additions & 5 deletions registerPool.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -----------------------------------------------------------------------------
# This script can be used to register a pool and do self bond.
#
# Usage: ./registerPool.sh node_address private_key signing_address commission_rate metadata_url metadata_content_hash
# Usage: ./registerPool.sh node_address private_key signing_address commission_rate metadata_url metadata_content_hash value
# -----------------------------------------------------------------------------

POOL_REGISTRY_ADDRESS="0xa01b68fa4f947ea4829bebdac148d1f7f8a0be9a8fd5ce33e1696932bef05356"
Expand Down Expand Up @@ -73,10 +73,10 @@ function get_coinbase(){
fi
}

if [ $# -ne 6 ]
if [ $# -ne 7 ]
then
echo "Invalid number of parameters."
echo "Usage: ./registerPool.sh node_address(ip:port) private_key signing_address commission_rate metadata_url metadata_content_hash"
echo "Usage: ./registerPool.sh node_address(ip:port) private_key signing_address commission_rate metadata_url metadata_content_hash value"
exit 1
fi
node_address="$1"
Expand All @@ -85,6 +85,7 @@ signing_address="$3"
commission="$4"
metadata_url="$5"
metadata_content_hash="$6"
amount="$7"

if [ ${#private_key} == 130 ]
then
Expand All @@ -107,7 +108,7 @@ echo "Using nonce $NONCE"
echo "Sending registration call..."
# registerStaker(Address signingAddress, int commissionRate, byte[] metaDataUrl, byte[] metaDataContentHash)
callPayload="$(java -cp $TOOLS_JAR cli.ComposeCallPayload "registerPool" "$signing_address" "$commission" "$metadata_url" "$metadata_content_hash")"
receipt=`./rpc.sh --call "$private_key" "$NONCE" "$POOL_REGISTRY_ADDRESS" "$callPayload" "1000000000000000000000"`
receipt=`./rpc.sh --call "$private_key" "$NONCE" "$POOL_REGISTRY_ADDRESS" "$callPayload" "$amount"`
require_success $?

echo "Transaction hash: \"$receipt\". Waiting for transaction to complete..."
Expand All @@ -117,8 +118,9 @@ echo "Transaction completed"
echo "Verifying that pool was registered and is active..."
# getStake(Address pool, Address staker)
callPayload="$(java -cp $TOOLS_JAR cli.ComposeCallPayload "getStake" "$identity_address" "$identity_address")"
amount_hex="$(java -cp $TOOLS_JAR cli.EncodeType "BigInteger" "$amount")"
# This result in a BigInteger: 0x23 (byte), length (byte), value (big-endian length bytes)
verify_state "$POOL_REGISTRY_ADDRESS" "$callPayload" "0x23093635c9adc5dea00000"
verify_state "$POOL_REGISTRY_ADDRESS" "$callPayload" "$amount_hex"
echo "Current stake = 1000 Aions"

callPayload="$(java -cp $TOOLS_JAR cli.ComposeCallPayload "isActive" "$identity_address")"
Expand Down
27 changes: 27 additions & 0 deletions src/cli/EncodeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cli;

import net.i2p.crypto.eddsa.Utils;
import org.aion.avm.userlib.abi.ABIEncoder;

import java.math.BigInteger;

public class EncodeType {
public static void main(String[] args) {
if (0 == args.length) {
System.err.println("Usage: cli.EncodeType Type");
System.exit(1);
}

byte[] rawCallData = null;
String type = args[0];
switch (type) {
case "BigInteger":
rawCallData = ABIEncoder.encodeOneBigInteger(new BigInteger(args[1]));
break;
default:
System.err.println("Type " + type + " is not defined.");
System.exit(1);
}
System.out.println("0x" + Utils.bytesToHex(rawCallData));
}
}

0 comments on commit ece8261

Please sign in to comment.