• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java DefaultBlockParameterName类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.web3j.protocol.core.DefaultBlockParameterName的典型用法代码示例。如果您正苦于以下问题:Java DefaultBlockParameterName类的具体用法?Java DefaultBlockParameterName怎么用?Java DefaultBlockParameterName使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DefaultBlockParameterName类属于org.web3j.protocol.core包,在下文中一共展示了DefaultBlockParameterName类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: callHash

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private byte[] callHash(String name, Type...parameters) throws InterruptedException, ExecutionException {

        Function function = new Function(name,
            Arrays.asList(parameters),
            Arrays.asList(new TypeReference<Bytes32>() {})
        );
        String encodedFunction = FunctionEncoder.encode(function);

        TransactionManager transactionManager = cfg.getTransactionManager(cfg.getMainAddress());
        String channelLibraryAddress = contractsProperties.getAddress().get("ChannelLibrary").toString();
        org.web3j.protocol.core.methods.response.EthCall ethCall = web3j.ethCall(
            Transaction.createEthCallTransaction(
                transactionManager.getFromAddress(), channelLibraryAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

        String value = ethCall.getValue();
        List<Type> list = FunctionReturnDecoder.decode(value, function.getOutputParameters());
        return ((Bytes32) list.get(0)).getValue();
    }
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:21,代码来源:HashTest.java


示例2: detectCurrentParams

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
public TransactionParams detectCurrentParams(BigInteger maxGasPrice, BigInteger maxGasLimit, FunctionCall call, BigInteger value) throws IOException {
    BigInteger nonce = getNonce();
    BigInteger blockGasLimit = web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send().getBlock().getGasLimit();
    
    EthEstimateGas gas = web3j.ethEstimateGas(new Transaction(getFromAddress(), nonce, maxGasPrice, blockGasLimit, call.contractAddress, value, call.data)).send();
    BigInteger actualGasLimit = maxGasLimit;

    if (rpc.isFailFast()) {
        CallUtil.checkError(gas, call.toString());
    } 
    if (gas.getError() == null) {
        BigInteger amountUsed = gas.getAmountUsed();
        if (amountUsed.compareTo(maxGasLimit) >= 0) {
            throw new IllegalStateException(String.format("Estimate out of gas, used: %s, limit: %s, block limit: %s, from: %s, %s", amountUsed, maxGasLimit, blockGasLimit, getFromAddress(), call));
        }
        BigInteger estimateAmount = amountUsed.shiftLeft(1);
        if (estimateAmount.compareTo(maxGasLimit) < 0) {
            actualGasLimit = estimateAmount;
        }
    } else {
        log.warn("Transaction will fail from {}: {}", getFromAddress(), call);
    }
    EthGasPrice gasPrice = web3j.ethGasPrice().send();
    CallUtil.checkError(gasPrice);
    BigInteger actualGasPrice = gasPrice.getGasPrice();
    if (actualGasPrice.compareTo(maxGasPrice) > 0) {
        log.warn("Configured gas price is less than median. Median: {}, configured: {}", actualGasPrice, maxGasPrice);
        actualGasPrice = maxGasPrice;
    }
    return new TransactionParams(nonce, actualGasPrice, actualGasLimit);
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:32,代码来源:ThreadsafeTransactionManager.java


示例3: createTransaction

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
@Override
public Single<String> createTransaction(Wallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, byte[] data, String password) {
	final Web3j web3j = Web3jFactory.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl));

	return Single.fromCallable(() -> {
		EthGetTransactionCount ethGetTransactionCount = web3j
				.ethGetTransactionCount(from.address, DefaultBlockParameterName.LATEST)
				.send();
		return ethGetTransactionCount.getTransactionCount();
	})
	.flatMap(nonce -> accountKeystoreService.signTransaction(from, password, toAddress, subunitAmount, gasPrice, gasLimit, nonce.longValue(), data, networkRepository.getDefaultNetwork().chainId))
	.flatMap(signedMessage -> Single.fromCallable( () -> {
		EthSendTransaction raw = web3j
				.ethSendRawTransaction(Numeric.toHexString(signedMessage))
				.send();
		if (raw.hasError()) {
			throw new ServiceException(raw.getError().getMessage());
		}
		return raw.getTransactionHash();
	})).subscribeOn(Schedulers.io());
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:22,代码来源:TransactionRepository.java


示例4: getAddressBalance

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
/**
 * Ver el saldo de una cuenta ethereum
 *
 * @param address
 * @return
 * @throws Exception
 */
public BigInteger getAddressBalance(String address) throws Exception {
    try {
        // Vamos a enviar una solicitud asíncrona usando el objecto web3j 
        EthGetBalance ethGetBalance = web3j
                .ethGetBalance(address, DefaultBlockParameterName.LATEST)
                .sendAsync()
                .get();

        // saldo en wei
        BigInteger wei = ethGetBalance.getBalance();
        return wei;
    } catch (Exception ex) {
        throw ex;
    }
}
 
开发者ID:jestevez,项目名称:ethereum-java-wallet,代码行数:23,代码来源:EthereumWallet.java


示例5: callSmartContractFunction

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:HumanStandardTokenIT.java


示例6: isValid

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
/**
 * Check that the contract deployed at the address associated with this smart contract wrapper
 * is in fact the contract you believe it is.
 *
 * <p>This method uses the
 * <a href="https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getcode">eth_getCode</a> method
 * to get the contract byte code and validates it against the byte code stored in this smart
 * contract wrapper.
 *
 * @return true if the contract is valid
 * @throws IOException if unable to connect to web3j node
 */
public boolean isValid() throws IOException {
    if (contractAddress.equals("")) {
        throw new UnsupportedOperationException(
                "Contract binary not present, you will need to regenerate your smart "
                        + "contract wrapper with web3j v2.2.0+");
    }

    EthGetCode ethGetCode = web3j
            .ethGetCode(contractAddress, DefaultBlockParameterName.LATEST)
            .send();
    if (ethGetCode.hasError()) {
        return false;
    }

    String code = Numeric.cleanHexPrefix(ethGetCode.getCode());
    // There may be multiple contracts in the Solidity bytecode, hence we only check for a
    // match with a subset
    return !code.isEmpty() && contractBinary.contains(code);
}
 
开发者ID:web3j,项目名称:web3j,代码行数:32,代码来源:Contract.java


示例7: getContractCode

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
public static String getContractCode(Web3j web3j, String contractAddress) throws IOException {
    EthGetCode ethGetCode = web3j
        .ethGetCode(contractAddress, DefaultBlockParameterName.LATEST)
        .send();

    if (ethGetCode.hasError()) {
        throw new IllegalStateException("Failed to get code for " + contractAddress + ": " + ethGetCode.getError().getMessage());
    }

    return Numeric.cleanHexPrefix(ethGetCode.getCode());
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:12,代码来源:CryptoUtil.java


示例8: getBalance

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的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


示例9: getNonce

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
protected BigInteger getNonce() throws IOException {
    if (nonce.signum() == -1) {
        EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(
            credentials.getAddress(), DefaultBlockParameterName.PENDING).send();

        nonce = ethGetTransactionCount.getTransactionCount();
    } else {
        nonce = nonce.add(BigInteger.ONE);
    }
    return nonce;
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:12,代码来源:ThreadsafeTransactionManager.java


示例10: startObservable

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private static void startObservable() {
	logger.debug("[ETH-INFO] Starting the observable...");
	ese.newMessageEventObservable(DefaultBlockParameterName.EARLIEST, DefaultBlockParameterName.LATEST)
			.subscribe(messageEvent -> {
				logger.debug("[ETH-INFO] A new message has been posted from " + messageEvent.from + ": "
						+ messageEvent.message);
			});
}
 
开发者ID:CDCgov,项目名称:blockchain-collab,代码行数:9,代码来源:ContractHelper.java


示例11: getBalanceWei

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
/**
 * Returns the balance (in Wei) of the specified account address. 
 */
public static BigInteger getBalanceWei(Web3j web3j, String address) throws InterruptedException, ExecutionException {
	EthGetBalance balance = web3j
			.ethGetBalance(address, DefaultBlockParameterName.LATEST)
			.sendAsync()
			.get();

	return balance.getBalance();
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:12,代码来源:Web3jUtils.java


示例12: getNonce

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
/**
 * Return the nonce (tx count) for the specified address.
 */
public static BigInteger getNonce(Web3j web3j, String address) throws InterruptedException, ExecutionException {
	EthGetTransactionCount ethGetTransactionCount = 
			web3j.ethGetTransactionCount(address, DefaultBlockParameterName.LATEST).sendAsync().get();

	return ethGetTransactionCount.getTransactionCount();
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:10,代码来源:Web3jUtils.java


示例13: callSmartContractFunction

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private String callSmartContractFunction(
        org.web3j.abi.datatypes.Function function, String contractAddress, Wallet wallet) throws Exception {
    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(wallet.address, contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:12,代码来源:TokenRepository.java


示例14: balanceInWei

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
@Override
public Single<BigInteger> balanceInWei(Wallet wallet) {
	return Single.fromCallable(() -> Web3jFactory
				.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl, httpClient, false))
				.ethGetBalance(wallet.address, DefaultBlockParameterName.LATEST)
				.send()
				.getBalance())
               .subscribeOn(Schedulers.io());
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:10,代码来源:WalletRepository.java


示例15: getBalanceWei

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
public BigInteger getBalanceWei(String address) {
  try {
    EthGetBalance balanceResponse = getWeb3j().ethGetBalance(address, DefaultBlockParameterName.LATEST).sendAsync().get();
    BigInteger balance = getBalanceFix(balanceResponse);
    return balance;

    // return balanceResponse.getBalance();
  }
  catch (Exception e) {
    throw new ProcessingException("Failed to get balance for address '" + address + "'", e);
  }
}
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:13,代码来源:EthereumService.java


示例16: getNonceFix

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private BigInteger getNonceFix(String address) throws Exception {
  LOG.info("Getting nonce for address " + address + " ...");

  EthGetTransactionCount txCount = getWeb3j().ethGetTransactionCount(address, DefaultBlockParameterName.LATEST).sendAsync().get();
  // TODO fix this once web3j accouts for 'bug' in testrpc
  BigInteger nonce = getTransactionCount(txCount);

  LOG.info("Successfully got nonce: " + nonce);

  return nonce;
}
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:12,代码来源:EthereumService.java


示例17: transferEther

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
public static CompletableFuture<EthSendTransaction> transferEther(String from, String to, double ethAmount) {
    return web3j.ethGetTransactionCount(from, DefaultBlockParameterName.LATEST).sendAsync()
            .thenCompose(transactionCount -> parity.ethSendTransaction(
                            Transaction.createEtherTransaction(from, transactionCount.getTransactionCount(),
                                    GAS_PRICE, GAS_LIMIT, to, toWei(ethAmount))).sendAsync()
            );
}
 
开发者ID:papyrusglobal,项目名称:smartcontracts,代码行数:8,代码来源:PapyrusUtils.java


示例18: createFilterForEvent

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private List<EthLog.LogResult> createFilterForEvent(
        String encodedEventSignature, String contractAddress) throws Exception {
    EthFilter ethFilter = new EthFilter(
            DefaultBlockParameterName.EARLIEST,
            DefaultBlockParameterName.LATEST,
            contractAddress
    );

    ethFilter.addSingleTopic(encodedEventSignature);

    EthLog ethLog = web3j.ethGetLogs(ethFilter).send();
    return ethLog.getLogs();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:EventFilterIT.java


示例19: callSmartContractFunction

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
private String callSmartContractFunction(
        Function function, String contractAddress) throws Exception {

    String encodedFunction = FunctionEncoder.encode(function);

    org.web3j.protocol.core.methods.response.EthCall response = web3j.ethCall(
            Transaction.createEthCallTransaction(
                    ALICE.getAddress(), contractAddress, encodedFunction),
            DefaultBlockParameterName.LATEST)
            .sendAsync().get();

    return response.getValue();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:14,代码来源:DeployContractIT.java


示例20: isSynced

import org.web3j.protocol.core.DefaultBlockParameterName; //导入依赖的package包/类
boolean isSynced() throws Exception {
    EthSyncing ethSyncing = web3j.ethSyncing().send();
    if (ethSyncing.isSyncing()) {
        return false;
    } else {
        EthBlock ethBlock =
                web3j.ethGetBlockByNumber(DefaultBlockParameterName.LATEST, false).send();
        long timestamp = ethBlock.getBlock().getTimestamp().longValueExact() * 1000;

        return System.currentTimeMillis() - syncThreshold < timestamp;
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:13,代码来源:EnsResolver.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RedirectRequestHandler类代码示例发布时间:2022-05-23
下一篇:
Java EditPolicyRoles类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap