use of org.web3j.crypto.Credentials in project SmartMesh_Android by SmartMeshFoundation.
the class WalletCopyActivity method getWalletPrivateKey.
/**
* access to the private key
* Password @ param walletPwd purse
*/
private void getWalletPrivateKey(final String walletPwd, final int type) {
LoadingDialog.show(WalletCopyActivity.this, "");
new Thread(new Runnable() {
@Override
public void run() {
try {
Credentials keys = WalletStorage.getInstance(getApplicationContext()).getFullWallet(WalletCopyActivity.this, walletPwd, storableWallet.getPublicKey());
BigInteger privateKey = keys.getEcKeyPair().getPrivateKey();
Message message = Message.obtain();
message.what = type;
message.obj = privateKey;
mHandler.sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (JSONException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(4);
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(3);
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(5);
}
}
}).start();
}
use of org.web3j.crypto.Credentials in project jbpm-work-items by kiegroup.
the class QueryExistingContractWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
String serviceURL = (String) workItem.getParameter("ServiceURL");
String contractAddress = (String) workItem.getParameter("ContractAddress");
String contractMethodName = (String) workItem.getParameter("ContractMethodName");
String contractMethodOutputType = (String) workItem.getParameter("MethodOutputType");
if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractAddress) && StringUtils.isNotEmpty(contractMethodName)) {
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();
List<TypeReference<?>> outputTypeList = null;
if (contractMethodOutputType != null) {
Class typeClazz = Class.forName(contractMethodOutputType);
outputTypeList = Collections.singletonList(TypeReference.create(typeClazz));
}
Object queryReturnObj = EthereumUtils.queryExistingContract(credentials, web3j, contractAddress, contractMethodName, null, outputTypeList);
results.put(RESULTS, queryReturnObj);
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing service url, valid address or method name to execute.");
throw new IllegalArgumentException("Missing service url, valid address or method name to execute.");
}
} catch (Exception e) {
logger.error("Error executing workitem: " + e.getMessage());
handleException(e);
}
}
use of org.web3j.crypto.Credentials in project jbpm-work-items by kiegroup.
the class DeployContractWorkitemHandler method executeWorkItem.
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) {
try {
String serviceURL = (String) workItem.getParameter("ServiceURL");
String contractPath = (String) workItem.getParameter("ContractPath");
String depositAmount = (String) workItem.getParameter("DepositAmount");
String waitForReceiptStr = (String) workItem.getParameter("WaitForReceipt");
if (StringUtils.isNotEmpty(serviceURL) && StringUtils.isNotEmpty(contractPath)) {
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);
}
String createdContractAddress = EthereumUtils.deployContract(credentials, web3j, EthereumUtils.convertStreamToStr(classLoader.getResourceAsStream(contractPath)), depositEtherAmountToSend, waitForReceipt, EthereumUtils.DEFAULT_SLEEP_DURATION, org.jbpm.process.workitem.ethereum.EthereumUtils.DEFAULT_ATTEMPTS);
results.put(RESULTS, createdContractAddress);
workItemManager.completeWorkItem(workItem.getId(), results);
} else {
logger.error("Missing service url, or contract path.");
throw new IllegalArgumentException("Missing service url, or contract path.");
}
} catch (Exception e) {
logger.error("Error executing workitem: " + e.getMessage());
handleException(e);
}
}
Aggregations