Java Code Examples for org.web3j.utils.Convert#toVon()

The following examples show how to use org.web3j.utils.Convert#toVon() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
public TransactionResponse delegate() throws Exception {
    StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    BigDecimal stakingAmount = Convert.toVon("500000", Unit.LAT);

    PlatonSendTransaction platonSendTransaction = delegateContract.delegateReturnTransaction(nodeId, stakingAmountType, stakingAmount.toBigInteger()).send();
    TransactionResponse baseResponse = delegateContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}
 
Example 2
Source File: WalletSendFunds.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private void run(String walletFileLocation,String chainId, String destinationAddress) {
    File walletFile = new File(walletFileLocation);
    Credentials credentials = getCredentials(walletFile);
    console.printf("Wallet for address " + credentials.getAddress() + " loaded\n");

    if (!WalletUtils.isValidAddress(destinationAddress)) {
        exitError("Invalid destination address specified");
    }

    Web3j web3j = getEthereumClient();

    BigDecimal amountToTransfer = getAmountToTransfer();
    Convert.Unit transferUnit = getTransferUnit();
    BigDecimal amountInWei = Convert.toVon(amountToTransfer, transferUnit);

    confirmTransfer(amountToTransfer, transferUnit, amountInWei, destinationAddress);

    TransactionReceipt transactionReceipt = performTransfer(
            web3j, destinationAddress,chainId, credentials, amountInWei);

    console.printf("Funds have been successfully transferred from %s to %s%n"
                    + "Transaction hash: %s%nMined block number: %s%n",
            credentials.getAddress(),
            destinationAddress,
            transactionReceipt.getTransactionHash(),
            transactionReceipt.getBlockNumber());
}
 
Example 3
Source File: Transfer.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
private TransactionReceipt send(String toAddress, BigDecimal value, Convert.Unit unit, BigInteger gasPrice,
                                BigInteger gasLimit) throws IOException, InterruptedException,
        TransactionException {

    BigDecimal weiValue = Convert.toVon(value, unit);
    if (!Numeric.isIntegerValue(weiValue)) {
        throw new UnsupportedOperationException(
                "Non decimal Wei value provided: " + value + " " + unit.toString()
                        + " = " + weiValue + " Wei");
    }

    return send(toAddress, "", weiValue.toBigIntegerExact(), gasPrice, gasLimit);
}
 
Example 4
Source File: StakingContractTest.java    From client-sdk-java with Apache License 2.0 5 votes vote down vote up
@Test
public void staking() throws Exception {   	
    try {
    	StakingAmountType stakingAmountType = StakingAmountType.FREE_AMOUNT_TYPE;
    	String benifitAddress = benefitCredentials.getAddress();
    	String externalId = "";
        String nodeName = "chendai-node3";
        String webSite = "www.baidu.com";
        String details = "chendai-node3-details";
        BigDecimal stakingAmount = Convert.toVon("5000000", Unit.LAT);
        BigInteger rewardPer = BigInteger.valueOf(1000L);
    	
        PlatonSendTransaction platonSendTransaction = stakingContract.stakingReturnTransaction(new StakingParam.Builder()
                .setNodeId(nodeId)
                .setAmount(stakingAmount.toBigInteger())  
                .setStakingAmountType(stakingAmountType)
                .setBenifitAddress(benifitAddress)
                .setExternalId(externalId)
                .setNodeName(nodeName)
                .setWebSite(webSite)
                .setDetails(details)
                .setBlsPubKey(blsPubKey)
                .setProcessVersion(web3j.getProgramVersion().send().getAdminProgramVersion())
                .setBlsProof(web3j.getSchnorrNIZKProve().send().getAdminSchnorrNIZKProve())
                .setRewardPer(rewardPer)
                .build()).send();
        TransactionResponse baseResponse = stakingContract.getTransactionResponse(platonSendTransaction).send();
        System.out.println(baseResponse.toString());  //394
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: StakingScenario.java    From client-sdk-java with Apache License 2.0 4 votes vote down vote up
public TransactionResponse unDelegate(BigInteger stakingBlockNum) throws Exception {
    BigDecimal stakingAmount = Convert.toVon("500000", Unit.LAT);
    PlatonSendTransaction platonSendTransaction = delegateContract.unDelegateReturnTransaction(nodeId, stakingBlockNum, stakingAmount.toBigInteger()).send();
    TransactionResponse baseResponse = delegateContract.getTransactionResponse(platonSendTransaction).send();
    return baseResponse;
}