Class SignedTransactionBuilder
- java.lang.Object
-
- org.aion4j.avm.helper.signing.SignedTransactionBuilder
-
public final class SignedTransactionBuilder extends Object
A convenience class for building an Aion transaction and signing it locally (offline) using a private key.In general, if a specific method is invoked multiple times before building the transaction, then the last invocation takes precedence.
The builder can be used to construct additional transactions after each build, and the previous build settings will apply.
The builder provides a
resetmethod that will clear the build back to its initial state.The sender of the transaction will be the Aion account that corresponds to the provided private key.
-
-
Constructor Summary
Constructors Constructor Description SignedTransactionBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]buildSignedTransaction()Constructs a transaction whose fields correspond to the fields as they have been set by the provided builder methods, and signs this transaction with the provided private key.SignedTransactionBuilderdata(String data)The transaction data.SignedTransactionBuilderdestination(String destination)The destination address of the transaction.SignedTransactionBuilderenergyLimit(long limit)The energy limit of the transaction.SignedTransactionBuilderenergyPrice(long price)The energy price of the transaction.static StringgetAionAddress(String pvtKey)static voidmain(String[] args)SignedTransactionBuilderprivateKey(String privateKey)The private key used to sign the transaction with.voidreset()Resets the builder so that it is in its initial state.SignedTransactionBuildersenderNonce(BigInteger nonce)The nonce of the sender.static StringsignWithPvtKey(String pvtKey, String to, BigInteger value, String callData, BigInteger nonce, long energy, long energyPrice)SignedTransactionBuilderuseAvmTransactionType()Sets the transaction type to be the type used by the AVM.SignedTransactionBuildervalue(BigInteger value)The amount of value to transfer from the sender to the destination.
-
-
-
Method Detail
-
privateKey
public SignedTransactionBuilder privateKey(String privateKey)
The private key used to sign the transaction with. This field must be set.- Parameters:
privateKey- The private key.- Returns:
- this builder.
-
destination
public SignedTransactionBuilder destination(String destination)
The destination address of the transaction. This field must be set.- Parameters:
destination- The destination.- Returns:
- this builder.
-
value
public SignedTransactionBuilder value(BigInteger value)
The amount of value to transfer from the sender to the destination.- Parameters:
value- The amount of value to transfer.- Returns:
- this builder.
-
senderNonce
public SignedTransactionBuilder senderNonce(BigInteger nonce)
The nonce of the sender. This field must be set.- Parameters:
nonce- The sender nonce.- Returns:
- this builder.
-
data
public SignedTransactionBuilder data(String data)
The transaction data.- Parameters:
data- The data.- Returns:
- this builder.
-
energyLimit
public SignedTransactionBuilder energyLimit(long limit)
The energy limit of the transaction. This field must be set.- Parameters:
limit- The energy limit.- Returns:
- this builder.
-
energyPrice
public SignedTransactionBuilder energyPrice(long price)
The energy price of the transaction.- Parameters:
price- The energy price.- Returns:
- this builder.
-
useAvmTransactionType
public SignedTransactionBuilder useAvmTransactionType()
Sets the transaction type to be the type used by the AVM.- Returns:
- this builder.
-
buildSignedTransaction
public byte[] buildSignedTransaction() throws InvalidKeySpecException, InvalidKeyException, SignatureException, NoSuchAlgorithmExceptionConstructs a transaction whose fields correspond to the fields as they have been set by the provided builder methods, and signs this transaction with the provided private key.The following fields must be set prior to calling this method: - private key - nonce - energy limit
The following fields, if not set, will have the following default values: - value:
BigInteger.ZERO- destination: empty array - data: empty array - energy price:10_000_000_000L(aka. 10 AMP) - type:0x1- Returns:
- the bytes of the signed transaction.
- Throws:
InvalidKeySpecExceptionInvalidKeyExceptionSignatureExceptionNoSuchAlgorithmException
-
reset
public void reset()
Resets the builder so that it is in its initial state.The state of the builder after a call to this method is the same as the state of a newly constructed builder.
-
signWithPvtKey
public static String signWithPvtKey(String pvtKey, String to, BigInteger value, String callData, BigInteger nonce, long energy, long energyPrice) throws Exception
- Throws:
Exception
-
getAionAddress
public static String getAionAddress(String pvtKey) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
-