本文整理汇总了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);
}
}
示例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());
}
示例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;
}
示例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...");
}
}
示例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);
}
示例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));
}