Search in sources :

Example 6 with Credentials

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();
}
Also used : Message(android.os.Message) CipherException(org.web3j.crypto.CipherException) BigInteger(java.math.BigInteger) JSONException(org.json.JSONException) IOException(java.io.IOException) Credentials(org.web3j.crypto.Credentials)

Example 7 with Credentials

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);
    }
}
Also used : HashMap(java.util.HashMap) HttpService(org.web3j.protocol.http.HttpService) TypeReference(org.web3j.abi.TypeReference) Credentials(org.web3j.crypto.Credentials)

Example 8 with Credentials

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);
    }
}
Also used : HashMap(java.util.HashMap) HttpService(org.web3j.protocol.http.HttpService) Credentials(org.web3j.crypto.Credentials)

Aggregations

Credentials (org.web3j.crypto.Credentials)8 HashMap (java.util.HashMap)5 HttpService (org.web3j.protocol.http.HttpService)5 Message (android.os.Message)3 IOException (java.io.IOException)3 BigInteger (java.math.BigInteger)3 CipherException (org.web3j.crypto.CipherException)3 JSONException (org.json.JSONException)2 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 StorableWallet (com.lingtuan.firefly.wallet.vo.StorableWallet)1 File (java.io.File)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1 ArrayList (java.util.ArrayList)1 TypeReference (org.web3j.abi.TypeReference)1 Type (org.web3j.abi.datatypes.Type)1 ECKeyPair (org.web3j.crypto.ECKeyPair)1 WalletFile (org.web3j.crypto.WalletFile)1