use of org.web3j.protocol.core.methods.response.TransactionReceipt in project jbpm-work-items by kiegroup.
the class EthereumUtils method deployContract.
public static String deployContract(Credentials credentials, Web3j web3j, String contractBinary, int toSendEther, boolean waitForReceipt, int sleepDuration, int attempts) throws Exception {
BigInteger depositEtherAmountToSend = BigInteger.valueOf(toSendEther);
RawTransaction rawTransaction = RawTransaction.createContractTransaction(getNextNonce(credentials.getAddress(), web3j), DEFAULT_GAS_PRICE, DEFAULT_GAS_LIMIT, depositEtherAmountToSend, contractBinary);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
String hexValue = Numeric.toHexString(signedMessage);
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
if (waitForReceipt) {
TransactionReceipt transReceipt = waitForTransactionReceipt(ethSendTransaction.getTransactionHash(), sleepDuration, attempts, web3j);
if (transReceipt != null) {
return transReceipt.getContractAddress();
}
}
// we dont have a contract address
logger.warn("Unable to retrieve contract address.");
return null;
}
use of org.web3j.protocol.core.methods.response.TransactionReceipt in project jbpm-work-items by kiegroup.
the class SendEtherWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
String serviceURL = (String) workItem.getParameter("ServiceURL");
String amount = (String) workItem.getParameter("Amount");
String toAddress = (String) workItem.getParameter("ToAddress");
if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(toAddress) && StringUtils.isNotEmpty(amount) && NumberUtils.isDigits(amount)) {
Map<String, Object> results = new HashMap<String, Object>();
if (web3j == null) {
web3j = Web3j.build(new HttpService(serviceURL));
}
auth = new EthereumAuth(walletPassword, walletPath, classLoader);
Credentials credentials = auth.getCredentials();
TransactionManager transactionManager = new RawTransactionManager(web3j, credentials);
if (transfer == null) {
transfer = new Transfer(web3j, transactionManager);
}
int amountToSend = 0;
if (amount != null) {
amountToSend = Integer.parseInt(amount);
}
TransactionReceipt transactionReceipt = EthereumUtils.sendFundsToContract(credentials, web3j, amountToSend, toAddress, transfer);
results.put(RESULTS, transactionReceipt);
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing service url or valid ether amount or toAddress.");
throw new IllegalArgumentException("Missing service url or valid ether amount or toAddress.");
}
} catch (Exception e) {
logger.error("Error executing workitem: " + e.getMessage());
handleException(e);
}
}
use of org.web3j.protocol.core.methods.response.TransactionReceipt in project jbpm-work-items by kiegroup.
the class TransactExistingContractWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
String serviceURL = (String) workItem.getParameter("ServiceURL");
String contractAddress = (String) workItem.getParameter("ContractAddress");
String waitForReceiptStr = (String) workItem.getParameter("WaitForReceipt");
String methodName = (String) workItem.getParameter("MethodName");
Type methodInputType = (Type) workItem.getParameter("MethodInputType");
String depositAmount = (String) workItem.getParameter("DepositAmount");
if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractAddress) && StringUtils.isNotEmpty(methodName)) {
Map<String, Object> results = new HashMap<String, Object>();
if (web3j == null) {
web3j = Web3j.build(new HttpService(serviceURL));
}
auth = new EthereumAuth(walletPassword, walletPath, classLoader);
Credentials credentials = auth.getCredentials();
int depositEtherAmountToSend = 0;
if (depositAmount != null) {
depositEtherAmountToSend = Integer.parseInt(depositAmount);
}
boolean waitForReceipt = false;
if (waitForReceiptStr != null) {
waitForReceipt = Boolean.parseBoolean(waitForReceiptStr);
}
List<Type> methodInputTypeList = new ArrayList<>();
if (methodInputType != null) {
methodInputTypeList = Collections.singletonList(methodInputType);
}
TransactionReceipt transactionReceipt = EthereumUtils.transactExistingContract(credentials, web3j, depositEtherAmountToSend, EthereumUtils.DEFAULT_GAS_PRICE, EthereumUtils.DEFAULT_GAS_LIMIT, contractAddress, methodName, methodInputTypeList, null, waitForReceipt, EthereumUtils.DEFAULT_SLEEP_DURATION, EthereumUtils.DEFAULT_ATTEMPTS);
results.put(RESULTS, transactionReceipt);
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing service url, valid toAddress or method name to execute.");
throw new IllegalArgumentException("Missing service url, valid toAddress or method name to execute.");
}
} catch (Exception e) {
logger.error("Error executing workitem: " + e.getMessage());
handleException(e);
}
}
use of org.web3j.protocol.core.methods.response.TransactionReceipt in project AppCoins-ethereumj by AppStoreFoundation.
the class TransactionFactory method fromEthGetTransactionReceipt.
public static Transaction fromEthGetTransactionReceipt(EthGetTransactionReceipt ethGetTransactionReceipt) {
TransactionReceipt transactionReceipt = ethGetTransactionReceipt.getTransactionReceipt();
String hash = transactionReceipt.getTransactionHash();
String from = transactionReceipt.getFrom();
Log log = transactionReceipt.getLogs().get(0);
String to = log.getAddress();
String value = extractValueFromEthGetTransactionReceipt(log.getData());
Status status = parseStatus(transactionReceipt.getStatus());
String contractAddress = ethGetTransactionReceipt.getTransactionReceipt().getTo();
return new Transaction(hash, from, to, value, status);
}
use of org.web3j.protocol.core.methods.response.TransactionReceipt in project jbpm-work-items by kiegroup.
the class EthereumWorkitemHandlerTest method testSendEther.
@Test
public void testSendEther() throws Exception {
TestWorkItemManager manager = new TestWorkItemManager();
WorkItemImpl workItem = new WorkItemImpl();
workItem.setParameter("ServiceURL", "http://localhost:8545/");
workItem.setParameter("Amount", "10");
workItem.setParameter("ToAddress", "0x00211e7e");
SendEtherWorkitemHandler handler = new SendEtherWorkitemHandler(TEST_WALLET_PASSWORD, "wallet/testwallet.json");
handler.setWeb3j(web3j);
handler.setTransfer(transfer);
handler.executeWorkItem(workItem, manager);
assertNotNull(manager.getResults());
assertEquals(1, manager.getResults().size());
assertTrue(manager.getResults().containsKey(workItem.getId()));
TransactionReceipt receipt = (TransactionReceipt) manager.getResults().get(workItem.getId()).get("Receipt");
assertNotNull(receipt);
}
Aggregations