Skip to content

add no cryptoKeyPair method #386

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

Open
wants to merge 10 commits into
base: dev-2.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,21 @@ public AssembleTransactionProcessor(

@Override
public void deployOnly(String abi, String bin, List<Object> params) throws ABICodecException {
transactionPusher.pushOnly(createSignedConstructor(abi, bin, params));
deployOnly(abi, bin, params, this.cryptoKeyPair);
}

public void deployOnly(String abi, String bin, List<Object> params, CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
transactionPusher.pushOnly(createSignedConstructor(abi, bin, params, cryptoKeyPair));
}

@Override
public TransactionReceipt deployAndGetReceipt(String data) {
String signedData = createSignedTransaction(null, data, this.cryptoKeyPair);
return deployAndGetReceipt(data, this.cryptoKeyPair);
}

public TransactionReceipt deployAndGetReceipt(String data, CryptoKeyPair cryptoKeyPair) {
String signedData = createSignedTransaction(null, data, cryptoKeyPair);
return transactionPusher.push(signedData);
}

Expand Down Expand Up @@ -145,16 +154,28 @@ public TransactionResponse deployAndGetResponse(String abi, String bin, List<Obj
return deployAndGetResponse(abi, bin, createSignedConstructor(abi, bin, params));
}

public TransactionResponse deployAndGetResponse(
String abi, String bin, List<Object> params, CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
return deployAndGetResponse(abi, createSignedConstructor(abi, bin, params, cryptoKeyPair));
}

@Override
public TransactionResponse deployAndGetResponseWithStringParams(
String abi, String bin, List<String> params) throws ABICodecException {
return deployAndGetResponseWithStringParams(abi, bin, params, this.cryptoKeyPair);
}

public TransactionResponse deployAndGetResponseWithStringParams(
String abi, String bin, List<String> params, CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
return deployAndGetResponse(
abi,
bin,
createSignedTransaction(
null,
abiCodec.encodeConstructorFromString(abi, bin, params),
this.cryptoKeyPair));
cryptoKeyPair));
}

@Override
Expand All @@ -164,12 +185,30 @@ public void deployAsync(
transactionPusher.pushAsync(createSignedConstructor(abi, bin, params), callback);
}

public void deployAsync(
String abi,
String bin,
List<Object> params,
TransactionCallback callback,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
transactionPusher.pushAsync(
createSignedConstructor(abi, bin, params, cryptoKeyPair), callback);
}

@Override
public CompletableFuture<TransactionReceipt> deployAsync(
String abi, String bin, List<Object> params) throws ABICodecException {
return transactionPusher.pushAsync(createSignedConstructor(abi, bin, params));
}

public CompletableFuture<TransactionReceipt> deployAsync(
String abi, String bin, List<Object> params, CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
return transactionPusher.pushAsync(
createSignedConstructor(abi, bin, params, cryptoKeyPair));
}

/**
* Deploy by bin and abi files. Should init with contractLoader.
*
Expand All @@ -183,21 +222,38 @@ public CompletableFuture<TransactionReceipt> deployAsync(
@Override
public TransactionResponse deployByContractLoader(String contractName, List<Object> args)
throws ABICodecException, TransactionBaseException {
return deployByContractLoader(contractName, args, this.cryptoKeyPair);
}

public TransactionResponse deployByContractLoader(
String contractName, List<Object> args, CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
return deployAndGetResponse(
contractLoader.getABIByContractName(contractName),
contractLoader.getBinaryByContractName(contractName),
args);
args,
cryptoKeyPair);
}

@Override
public void deployByContractLoaderAsync(
String contractName, List<Object> args, TransactionCallback callback)
throws ABICodecException, NoSuchTransactionFileException {
deployByContractLoaderAsync(contractName, args, callback, this.cryptoKeyPair);
}

public void deployByContractLoaderAsync(
String contractName,
List<Object> args,
TransactionCallback callback,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, NoSuchTransactionFileException {
deployAsync(
contractLoader.getABIByContractName(contractName),
contractLoader.getBinaryByContractName(contractName),
args,
callback);
callback,
cryptoKeyPair);
}

@Override
Expand All @@ -209,7 +265,13 @@ public void sendTransactionOnly(String signedData) {
public TransactionResponse sendTransactionAndGetResponse(
String to, String abi, String functionName, String data)
throws TransactionBaseException, ABICodecException {
String signedData = createSignedTransaction(to, data, this.cryptoKeyPair);
return sendTransactionAndGetResponse(to, abi, functionName, data, this.cryptoKeyPair);
}

public TransactionResponse sendTransactionAndGetResponse(
String to, String abi, String functionName, String data, CryptoKeyPair cryptoKeyPair)
throws TransactionBaseException, ABICodecException {
String signedData = createSignedTransaction(to, data, cryptoKeyPair);
TransactionReceipt receipt = this.transactionPusher.push(signedData);
try {
return transactionDecoder.decodeReceiptWithValues(abi, functionName, receipt);
Expand All @@ -224,22 +286,54 @@ public TransactionResponse sendTransactionAndGetResponse(
public TransactionResponse sendTransactionAndGetResponse(
String to, String abi, String functionName, List<Object> params)
throws ABICodecException, TransactionBaseException {
return sendTransactionAndGetResponse(to, abi, functionName, params, this.cryptoKeyPair);
}

public TransactionResponse sendTransactionAndGetResponse(
String to,
String abi,
String functionName,
List<Object> params,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
String data = encodeFunction(abi, functionName, params);
return sendTransactionAndGetResponse(to, abi, functionName, data);
return sendTransactionAndGetResponse(to, abi, functionName, data, cryptoKeyPair);
}

@Override
public TransactionResponse sendTransactionWithStringParamsAndGetResponse(
String to, String abi, String functionName, List<String> params)
throws ABICodecException, TransactionBaseException {
return sendTransactionWithStringParamsAndGetResponse(
to, abi, functionName, params, this.cryptoKeyPair);
}

public TransactionResponse sendTransactionWithStringParamsAndGetResponse(
String to,
String abi,
String functionName,
List<String> params,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
String data = abiCodec.encodeMethodFromString(abi, functionName, params);
return sendTransactionAndGetResponse(to, abi, functionName, data);
return sendTransactionAndGetResponse(to, abi, functionName, data, cryptoKeyPair);
}

@Override
public TransactionReceipt sendTransactionAndGetReceiptByContractLoader(
String contractName, String contractAddress, String functionName, List<Object> args)
throws ABICodecException, TransactionBaseException {
return sendTransactionAndGetReceiptByContractLoader(
contractName, contractAddress, functionName, args, this.cryptoKeyPair);
}

public TransactionReceipt sendTransactionAndGetReceiptByContractLoader(
String contractName,
String contractAddress,
String functionName,
List<Object> args,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
String data =
abiCodec.encodeMethod(
contractLoader.getABIByContractName(contractName), functionName, args);
Expand All @@ -253,11 +347,23 @@ public TransactionResponse sendTransactionAndGetResponseByContractLoader(
String functionName,
List<Object> funcParams)
throws ABICodecException, TransactionBaseException {
return sendTransactionAndGetResponseByContractLoader(
contractName, contractAddress, functionName, funcParams, this.cryptoKeyPair);
}

public TransactionResponse sendTransactionAndGetResponseByContractLoader(
String contractName,
String contractAddress,
String functionName,
List<Object> funcParams,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
return sendTransactionAndGetResponse(
contractAddress,
contractLoader.getABIByContractName(contractName),
functionName,
funcParams);
funcParams,
cryptoKeyPair);
}

@Override
Expand All @@ -273,8 +379,19 @@ public void sendTransactionAsync(
List<Object> params,
TransactionCallback callback)
throws TransactionBaseException, ABICodecException {
sendTransactionAsync(to, abi, functionName, params, callback, this.cryptoKeyPair);
}

public void sendTransactionAsync(
String to,
String abi,
String functionName,
List<Object> params,
TransactionCallback callback,
CryptoKeyPair cryptoKeyPair)
throws TransactionBaseException, ABICodecException {
String data = encodeFunction(abi, functionName, params);
sendTransactionAsync(to, data, this.cryptoKeyPair, callback);
sendTransactionAsync(to, data, cryptoKeyPair, callback);
}

@Override
Expand All @@ -290,10 +407,22 @@ public void sendTransactionAndGetReceiptByContractLoaderAsync(
List<Object> args,
TransactionCallback callback)
throws ABICodecException, TransactionBaseException {
sendTransactionAndGetReceiptByContractLoaderAsync(
contractName, contractAddress, functionName, args, callback, this.cryptoKeyPair);
}

public void sendTransactionAndGetReceiptByContractLoaderAsync(
String contractName,
String contractAddress,
String functionName,
List<Object> args,
TransactionCallback callback,
CryptoKeyPair cryptoKeyPair)
throws ABICodecException, TransactionBaseException {
String data =
abiCodec.encodeMethod(
contractLoader.getABIByContractName(contractName), functionName, args);
sendTransactionAsync(contractAddress, data, this.cryptoKeyPair, callback);
sendTransactionAsync(contractAddress, data, cryptoKeyPair, callback);
}

@Override
Expand Down Expand Up @@ -355,8 +484,14 @@ public CallResponse callAndGetResponse(
@Override
public String createSignedConstructor(String abi, String bin, List<Object> params)
throws ABICodecException {
return createSignedConstructor(abi, bin, params, this.cryptoKeyPair);
}

public String createSignedConstructor(
String abi, String bin, List<Object> params, CryptoKeyPair cryptoKeyPair)
throws ABICodecException {
return createSignedTransaction(
null, abiCodec.encodeConstructor(abi, bin, params), this.cryptoKeyPair);
null, abiCodec.encodeConstructor(abi, bin, params), cryptoKeyPair);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class TransactionProcessor implements TransactionProcessorInterface {
protected static Logger log = LoggerFactory.getLogger(TransactionProcessor.class);
protected final CryptoSuite cryptoSuite;
protected final CryptoKeyPair cryptoKeyPair;
protected CryptoKeyPair cryptoKeyPair;
protected final Client client;
protected final Integer groupId;
protected final String chainId;
Expand All @@ -55,29 +55,68 @@ public TransactionProcessor(
this.transactionEncoder = new TransactionEncoderService(client.getCryptoSuite());
}

public CryptoKeyPair getCryptoKeyPair() {
return cryptoKeyPair;
}

public void setCryptoKeyPair(CryptoKeyPair cryptoKeyPair) {
this.cryptoKeyPair = cryptoKeyPair;
}

@Override
public TransactionReceipt sendTransactionAndGetReceipt(
String to, String data, CryptoKeyPair cryptoKeyPair) {
String signedData = createSignedTransaction(to, data, cryptoKeyPair);
return this.client.sendRawTransactionAndGetReceipt(signedData);
if (cryptoKeyPair == null) {
return this.client.sendRawTransactionAndGetReceipt(
createSignedTransaction(to, data, this.cryptoKeyPair));
} else {
return this.client.sendRawTransactionAndGetReceipt(
createSignedTransaction(to, data, cryptoKeyPair));
}
}

@Override
public TransactionReceipt sendTransactionAndGetReceipt(String to, String data) {
return sendTransactionAndGetReceipt(to, data, this.cryptoKeyPair);
}

@Override
public void sendTransactionAsync(
String to, String data, CryptoKeyPair cryptoKeyPair, TransactionCallback callback) {
String signedData = createSignedTransaction(to, data, cryptoKeyPair);
client.sendRawTransactionAndGetReceiptAsync(signedData, callback);
if (cryptoKeyPair == null) {
client.sendRawTransactionAndGetReceiptAsync(
createSignedTransaction(to, data, this.cryptoKeyPair), callback);
} else {
client.sendRawTransactionAndGetReceiptAsync(
createSignedTransaction(to, data, cryptoKeyPair), callback);
}
}

@Override
public void sendTransactionAsync(String to, String data, TransactionCallback callback) {
sendTransactionAsync(to, data, this.cryptoKeyPair, callback);
}

@Override
public byte[] sendTransactionAsyncAndGetHash(
String to, String data, CryptoKeyPair cryptoKeyPair, TransactionCallback callback) {
String signedData = createSignedTransaction(to, data, cryptoKeyPair);
String signedData;
if (cryptoKeyPair == null) {
signedData = createSignedTransaction(to, data, this.cryptoKeyPair);
} else {
signedData = createSignedTransaction(to, data, cryptoKeyPair);
}
client.sendRawTransactionAndGetReceiptAsync(signedData, callback);
byte[] transactionHash = cryptoSuite.hash(Hex.decode(Numeric.cleanHexPrefix(signedData)));
return transactionHash;
}

@Override
public byte[] sendTransactionAsyncAndGetHash(
String to, String data, TransactionCallback callback) {
return sendTransactionAsyncAndGetHash(to, data, this.cryptoKeyPair, callback);
}

@Override
public Call executeCall(CallRequest callRequest) {
return executeCall(
Expand All @@ -101,6 +140,14 @@ public String createSignedTransaction(String to, String data, CryptoKeyPair cryp
new BigInteger(this.chainId),
BigInteger.valueOf(this.groupId),
"");
if (cryptoKeyPair == null) {
return transactionEncoder.encodeAndSign(rawTransaction, this.cryptoKeyPair);
}
return transactionEncoder.encodeAndSign(rawTransaction, cryptoKeyPair);
}

@Override
public String createSignedTransaction(String to, String data) {
return createSignedTransaction(to, data, this.cryptoKeyPair);
}
}
Loading