当前位置: 首页>>代码示例>>Java>>正文


Java Convert.Unit方法代码示例

本文整理汇总了Java中org.web3j.utils.Convert.Unit方法的典型用法代码示例。如果您正苦于以下问题:Java Convert.Unit方法的具体用法?Java Convert.Unit怎么用?Java Convert.Unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.web3j.utils.Convert的用法示例。


在下文中一共展示了Convert.Unit方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getBalance

import org.web3j.utils.Convert; //导入方法依赖的package包/类
public BigDecimal getBalance(String accountAddress, Convert.Unit unit) {
    try {
        BigInteger balance = web3j.ethGetBalance(accountAddress, DefaultBlockParameterName.LATEST).send().getBalance();
        return Convert.fromWei(new BigDecimal(balance), unit);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:9,代码来源:EthereumService.java

示例2: run

import org.web3j.utils.Convert; //导入方法依赖的package包/类
private void run(String walletFileLocation, String destinationAddress) {
    File walletFile = new File(walletFileLocation);
    Credentials credentials = getCredentials(walletFile);
    console.printf("Wallet for address " + credentials.getAddress() + " loaded\n");

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

    Web3j web3j = getEthereumClient();

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

    confirmTransfer(amountToTransfer, transferUnit, amountInWei, destinationAddress);

    TransactionReceipt transactionReceipt = performTransfer(
            web3j, destinationAddress, 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());
}
 
开发者ID:web3j,项目名称:web3j,代码行数:29,代码来源:WalletSendFunds.java

示例3: getTransferUnit

import org.web3j.utils.Convert; //导入方法依赖的package包/类
private Convert.Unit getTransferUnit() {
    String unit = console.readLine("Please specify the unit (ether, wei, ...) [ether]: ")
            .trim();

    Convert.Unit transferUnit;
    if (unit.equals("")) {
        transferUnit = Convert.Unit.ETHER;
    } else {
        transferUnit = Convert.Unit.fromString(unit.toLowerCase());
    }

    return transferUnit;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:WalletSendFunds.java

示例4: confirmTransfer

import org.web3j.utils.Convert; //导入方法依赖的package包/类
private void confirmTransfer(
        BigDecimal amountToTransfer, Convert.Unit transferUnit, BigDecimal amountInWei,
        String destinationAddress) {

    console.printf("Please confim that you wish to transfer %s %s (%s %s) to address %s%n",
            amountToTransfer.stripTrailingZeros().toPlainString(), transferUnit,
            amountInWei.stripTrailingZeros().toPlainString(),
            Convert.Unit.WEI, destinationAddress);
    String confirm = console.readLine("Please type 'yes' to proceed: ").trim();
    if (!confirm.toLowerCase().equals("yes")) {
        exitError("OK, some other time perhaps...");
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:WalletSendFunds.java

示例5: send

import org.web3j.utils.Convert; //导入方法依赖的package包/类
private TransactionReceipt send(
        String toAddress, BigDecimal value, Convert.Unit unit, BigInteger gasPrice,
        BigInteger gasLimit) throws IOException, InterruptedException,
        TransactionException {

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

    String resolvedAddress = ensResolver.resolve(toAddress);
    return send(resolvedAddress, "", weiValue.toBigIntegerExact(), gasPrice, gasLimit);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:16,代码来源:Transfer.java

示例6: sendFunds

import org.web3j.utils.Convert; //导入方法依赖的package包/类
public static RemoteCall<TransactionReceipt> sendFunds(
        Web3j web3j, Credentials credentials,
        String toAddress, BigDecimal value, Convert.Unit unit) throws InterruptedException,
        IOException, TransactionException {

    TransactionManager transactionManager = new RawTransactionManager(web3j, credentials);

    return new RemoteCall<>(() ->
            new Transfer(web3j, transactionManager).send(toAddress, value, unit));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:11,代码来源:Transfer.java


注:本文中的org.web3j.utils.Convert.Unit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。