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

Java TransactionReceipt类代码示例

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

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



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

示例1: getApprovalEvents

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
public List<ApprovalEventResponse> getApprovalEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Approval", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<ApprovalEventResponse> responses = new ArrayList<ApprovalEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        ApprovalEventResponse typedResponse = new ApprovalEventResponse();
        typedResponse.log = transactionReceipt.getLogs().get(valueList.indexOf(eventValues));
        typedResponse._owner = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse._spender = (String) eventValues.getIndexedValues().get(1).getValue();
        typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:17,代码来源:HumanStandardToken.java


示例2: testSendFunds

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
/**
 * Ether transfer tests using methods {@link Transfer#sendFunds()}.
 * Sending account needs to be unlocked for this to work.   
 */
@Test
public void testSendFunds() throws Exception {
	BigDecimal amountEther = BigDecimal.valueOf(0.123);
	BigInteger amountWei = Convert.toWei(amountEther, Convert.Unit.ETHER).toBigInteger();

	ensureFunds(Alice.ADDRESS, amountWei);

	BigInteger fromBalanceBefore = getBalanceWei(Alice.ADDRESS);
	BigInteger toBalanceBefore = getBalanceWei(Bob.ADDRESS);

	// this is the method to test here
	TransactionReceipt txReceipt = Transfer.sendFunds(
			web3j, Alice.CREDENTIALS, Bob.ADDRESS, amountEther, Convert.Unit.ETHER);

	BigInteger txFees = txReceipt.getGasUsed().multiply(Web3jConstants.GAS_PRICE);

	assertFalse(txReceipt.getBlockHash().isEmpty());
	assertEquals("Unexected balance for 'from' address", fromBalanceBefore.subtract(amountWei.add(txFees)), getBalanceWei(Alice.ADDRESS));
	assertEquals("Unexected balance for 'to' address", toBalanceBefore.add(amountWei), getBalanceWei(Bob.ADDRESS));
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:25,代码来源:TransferEtherTest.java


示例3: testProcessEvent

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
@Test
public void testProcessEvent() {
    TransactionReceipt transactionReceipt = new TransactionReceipt();
    Log log = new Log();
    log.setTopics(Arrays.asList(
            // encoded function
            "0xfceb437c298f40d64702ac26411b2316e79f3c28ffa60edfc891ad4fc8ab82ca",
            // indexed value
            "0000000000000000000000003d6cb163f7c72d20b0fcd6baae5889329d138a4a"));
    // non-indexed value
    log.setData("0000000000000000000000000000000000000000000000000000000000000001");

    transactionReceipt.setLogs(Arrays.asList(log));

    EventValues eventValues = contract.processEvent(transactionReceipt).get(0);

    assertThat(eventValues.getIndexedValues(),
            equalTo(Collections.singletonList(
                    new Address("0x3d6cb163f7c72d20b0fcd6baae5889329d138a4a"))));
    assertThat(eventValues.getNonIndexedValues(),
            equalTo(Collections.singletonList(new Uint256(BigInteger.ONE))));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:23,代码来源:ContractTest.java


示例4: create

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private <T extends Contract> T create(Class<T> type, TransactionReceipt rc) {
    try {
        Constructor<T> constructor = type.getDeclaredConstructor(
            String.class,
            Web3j.class, TransactionManager.class,
            BigInteger.class, BigInteger.class);
        constructor.setAccessible(true);

        T contract = constructor.newInstance(null, web3j, transactionManager, rpcProperties.getGasPrice(), rpcProperties.getGasLimit());
        contract.setContractAddress(rc.getContractAddress());
        contract.setTransactionReceipt(rc);
        return contract;
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:17,代码来源:ContractsManager.java


示例5: testSetBlockResult

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
@Test
public void testSetBlockResult() throws Exception {
    ChannelManagerContract contract = channelManager(dsp);
    Assert.assertEquals("Contract not found", 3, contract.channelParticipantCount(channelId).send().getValue().intValueExact());
    Assert.assertEquals(new Address(dsp.getAddress()), contract.channelParticipant(channelId, new Uint64(0)).send());
    Assert.assertEquals(new Address(ssp.getAddress()), contract.channelParticipant(channelId, new Uint64(1)).send());
    Assert.assertEquals(new Address(auditor.getAddress()), contract.channelParticipant(channelId, new Uint64(2)).send());


    Uint64 blockNumber = new Uint64(System.currentTimeMillis());
    contract.setBlockPart(channelId, blockNumber, new DynamicBytes("Test".getBytes())).send();
    byte[] bPart = contract.blockPart(channelId, Uint64.DEFAULT, blockNumber).send().getValue();
    Assert.assertEquals("Test", new String(bPart));
    byte[] resultHash = CryptoUtil.sha3("Hello".getBytes());
    TransactionReceipt receipt = contract.setBlockResult(channelId, blockNumber, new Bytes32(resultHash), new Uint256(1)).send();
    Tuple2<Bytes32, Uint256> tuple2 = contract.blockResult(channelId, Uint64.DEFAULT, blockNumber).send();
    Assert.assertEquals(1, tuple2.getValue2().getValue().intValueExact());
    Assert.assertArrayEquals(resultHash, tuple2.getValue1().getValue());
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:20,代码来源:TestCreateContract.java


示例6: transferFromCoinbaseAndWait

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
/**
 * Transfers the specified amount of Wei from the coinbase to the specified account.
 * The method waits for the transfer to complete using method {@link waitForReceipt}.  
 */
public static TransactionReceipt transferFromCoinbaseAndWait(Web3j web3j, String to, BigInteger amountWei) 
		throws Exception 
{
	String coinbase = getCoinbase(web3j).getResult();
	BigInteger nonce = getNonce(web3j, coinbase);
	// this is a contract method call -> gas limit higher than simple fund transfer
	BigInteger gasLimit = Web3jConstants.GAS_LIMIT_ETHER_TX.multiply(BigInteger.valueOf(2)); 
	Transaction transaction = Transaction.createEtherTransaction(
			coinbase, 
			nonce, 
			Web3jConstants.GAS_PRICE, 
			gasLimit, 
			to, 
			amountWei);

	EthSendTransaction ethSendTransaction = web3j
			.ethSendTransaction(transaction)
			.sendAsync()
			.get();

	String txHash = ethSendTransaction.getTransactionHash();
	
	return waitForReceipt(web3j, txHash);
}
 
开发者ID:matthiaszimmermann,项目名称:web3j_demo,代码行数:29,代码来源:Web3jUtils.java


示例7: waitForReceipt

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
/**
 * Waits for the receipt for the transaction specified by the provided tx hash.
 * Makes 40 attempts (waiting 1 sec. inbetween attempts) to get the receipt object.
 * In the happy case the tx receipt object is returned.
 * Otherwise, a runtime exception is thrown. 
 */
public static TransactionReceipt waitForReceipt(Web3j web3j, String transactionHash) 
		throws Exception 
{

	int attempts = Web3jConstants.CONFIRMATION_ATTEMPTS;
	int sleep_millis = Web3jConstants.SLEEP_DURATION;
	
	Optional<TransactionReceipt> receipt = getReceipt(web3j, transactionHash);

	while(attempts-- > 0 && !receipt.isPresent()) {
		Thread.sleep(sleep_millis);
		receipt = getReceipt(web3j, transactionHash);
	}

	if (attempts <= 0) {
		throw new RuntimeException("No Tx receipt received");
	}

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


示例8: getReceipt

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
/**
 * Returns the TransactionRecipt for the specified tx hash as an optional.
 */
public static Optional<TransactionReceipt> getReceipt(Web3j web3j, String transactionHash) 
		throws Exception 
{
	EthGetTransactionReceipt receipt = web3j
			.ethGetTransactionReceipt(transactionHash)
			.sendAsync()
			.get();

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


示例9: publish

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
/**
 * Publish the specified order.
 *
 * @param type
 *          order type
 * @param amount
 * @param price
 * @return the transaction hash of the new order. Empty String if error occurred .
 */
public String publish(Order order) {
  //TODO [uko] Check if order contains dealNr => not allowed
  Bool buy = new Bool(order.isBuy());
  Uint256 dealQuantity = new Uint256(BigInteger.valueOf(order.getAmount()));
  Uint256 dealPrice = new Uint256(BigInteger.valueOf((long) (100 * order.getPrice())));
  Uint256 extId = new Uint256(BigInteger.valueOf((long) order.getExtId()));

  String transactionHash = "";
  try {
    TransactionReceipt receipt = getContract(order.getCurrencyPair()).createOrder(dealQuantity, dealPrice, buy, extId).get();
    transactionHash = receipt.getTransactionHash();
  }
  catch (InterruptedException | ExecutionException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  return transactionHash;
}
 
开发者ID:BSI-Business-Systems-Integration-AG,项目名称:trading-network,代码行数:28,代码来源:OrderBookService.java


示例10: createContract

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private String createContract(
        Credentials credentials, BigInteger initialSupply) throws Exception {
    String createTransactionHash = sendCreateContractTransaction(credentials, initialSupply);
    assertFalse(createTransactionHash.isEmpty());

    TransactionReceipt createTransactionReceipt =
            waitForTransactionReceipt(createTransactionHash);

    assertThat(createTransactionReceipt.getTransactionHash(), is(createTransactionHash));

    assertFalse("Contract execution ran out of gas",
            createTransactionReceipt.getGasUsed().equals(GAS_LIMIT));

    String contractAddress = createTransactionReceipt.getContractAddress();

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


示例11: getTransactionReceipt

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private Optional<TransactionReceipt> getTransactionReceipt(
        String transactionHash, int sleepDuration, int attempts) throws Exception {

    Optional<TransactionReceipt> receiptOptional =
            sendTransactionReceiptRequest(transactionHash);
    for (int i = 0; i < attempts; i++) {
        if (!receiptOptional.isPresent()) {
            Thread.sleep(sleepDuration);
            receiptOptional = sendTransactionReceiptRequest(transactionHash);
        } else {
            break;
        }
    }

    return receiptOptional;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:17,代码来源:Scenario.java


示例12: testTransferEther

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
@Test
public void testTransferEther() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());
    RawTransaction rawTransaction = createEtherTransaction(
            nonce, BOB.getAddress());

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction ethSendTransaction =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    String transactionHash = ethSendTransaction.getTransactionHash();

    assertFalse(transactionHash.isEmpty());

    TransactionReceipt transactionReceipt =
            waitForTransactionReceipt(transactionHash);

    assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:21,代码来源:CreateRawTransactionIT.java


示例13: testDeploySmartContract

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
@Test
public void testDeploySmartContract() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());
    RawTransaction rawTransaction = createSmartContractTransaction(nonce);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction ethSendTransaction =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    String transactionHash = ethSendTransaction.getTransactionHash();

    assertFalse(transactionHash.isEmpty());

    TransactionReceipt transactionReceipt =
            waitForTransactionReceipt(transactionHash);

    assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));

    assertFalse("Contract execution ran out of gas",
            rawTransaction.getGasLimit().equals(transactionReceipt.getGasUsed()));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:23,代码来源:CreateRawTransactionIT.java


示例14: testFibonacciNotify

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
@Test
public void testFibonacciNotify() throws Exception {
    Fibonacci fibonacci = Fibonacci.load(
            "0x3c05b2564139fb55820b18b72e94b2178eaace7d", Web3j.build(new HttpService()),
            ALICE, GAS_PRICE, GAS_LIMIT);

    TransactionReceipt transactionReceipt = fibonacci.fibonacciNotify(
            BigInteger.valueOf(15)).send();

    Fibonacci.NotifyEventResponse result = fibonacci.getNotifyEvents(transactionReceipt).get(0);

    assertThat(result.input,
            equalTo(new Uint256(BigInteger.valueOf(15))));

    assertThat(result.result,
            equalTo(new Uint256(BigInteger.valueOf(610))));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:18,代码来源:FunctionWrappersIT.java


示例15: getTransferEvents

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
public List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
    final Event event = new Event("Transfer", 
            Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {}, new TypeReference<Address>() {}),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
    ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
    for (EventValues eventValues : valueList) {
        TransferEventResponse typedResponse = new TransferEventResponse();
        typedResponse.log = transactionReceipt.getLogs().get(valueList.indexOf(eventValues));
        typedResponse._from = (String) eventValues.getIndexedValues().get(0).getValue();
        typedResponse._to = (String) eventValues.getIndexedValues().get(1).getValue();
        typedResponse._value = (BigInteger) eventValues.getNonIndexedValues().get(0).getValue();
        responses.add(typedResponse);
    }
    return responses;
}
 
开发者ID:web3j,项目名称:web3j,代码行数:17,代码来源:HumanStandardToken.java


示例16: performTransfer

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private TransactionReceipt performTransfer(
        Web3j web3j, String destinationAddress, Credentials credentials,
        BigDecimal amountInWei) {

    console.printf("Commencing transfer (this may take a few minutes) ");
    try {
        Future<TransactionReceipt> future = Transfer.sendFunds(
                web3j, credentials, destinationAddress, amountInWei, Convert.Unit.WEI)
                .sendAsync();

        while (!future.isDone()) {
            console.printf(".");
            Thread.sleep(500);
        }
        console.printf("$%n%n");
        return future.get();
    } catch (InterruptedException | ExecutionException | TransactionException | IOException e) {
        exitError("Problem encountered transferring funds: \n" + e.getMessage());
    }
    throw new RuntimeException("Application exit failure");
}
 
开发者ID:web3j,项目名称:web3j,代码行数:22,代码来源:WalletSendFunds.java


示例17: buildTransactionFunction

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private static void buildTransactionFunction(
        AbiDefinition functionDefinition,
        MethodSpec.Builder methodBuilder,
        String inputParams) throws ClassNotFoundException {

    if (functionDefinition.isPayable()) {
        methodBuilder.addParameter(BigInteger.class, WEI_VALUE);
    }

    String functionName = functionDefinition.getName();

    methodBuilder.returns(buildRemoteCall(TypeName.get(TransactionReceipt.class)));

    methodBuilder.addStatement("$T function = new $T(\n$S, \n$T.<$T>asList($L), \n$T"
                    + ".<$T<?>>emptyList())",
            Function.class, Function.class, functionName,
            Arrays.class, Type.class, inputParams, Collections.class,
            TypeReference.class);
    if (functionDefinition.isPayable()) {
        methodBuilder.addStatement(
                "return executeRemoteCallTransaction(function, $N)", WEI_VALUE);
    } else {
        methodBuilder.addStatement("return executeRemoteCallTransaction(function)");
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:26,代码来源:SolidityFunctionWrapper.java


示例18: sendTransactionReceiptRequests

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private void sendTransactionReceiptRequests() {
    for (RequestWrapper requestWrapper : pendingTransactions) {
        try {
            String transactionHash = requestWrapper.getTransactionHash();
            Optional<TransactionReceipt> transactionReceipt =
                    sendTransactionReceiptRequest(transactionHash);
            if (transactionReceipt.isPresent()) {
                callback.accept(transactionReceipt.get());
                pendingTransactions.remove(requestWrapper);
            } else {
                if (requestWrapper.getCount() == pollingAttemptsPerTxHash) {
                    throw new TransactionException(
                            "No transaction receipt for txHash: " + transactionHash
                                    + "received after " + pollingAttemptsPerTxHash
                                    + " attempts");
                } else {
                    requestWrapper.incrementCount();
                }
            }
        } catch (IOException | TransactionException e) {
            pendingTransactions.remove(requestWrapper);
            callback.exception(e);
        }
    }
}
 
开发者ID:web3j,项目名称:web3j,代码行数:26,代码来源:QueuingTransactionReceiptProcessor.java


示例19: getTransactionReceipt

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
private TransactionReceipt getTransactionReceipt(
        String transactionHash, long sleepDuration, int attempts)
        throws IOException, TransactionException {

    Optional<TransactionReceipt> receiptOptional =
            sendTransactionReceiptRequest(transactionHash);
    for (int i = 0; i < attempts; i++) {
        if (!receiptOptional.isPresent()) {
            try {
                Thread.sleep(sleepDuration);
            } catch (InterruptedException e) {
                throw new TransactionException(e);
            }
            receiptOptional = sendTransactionReceiptRequest(transactionHash);
        } else {
            return receiptOptional.get();
        }
    }

    throw new TransactionException("Transaction receipt was not generated after "
            + ((sleepDuration * attempts) / 1000
            + " seconds for transaction: " + transactionHash));
}
 
开发者ID:web3j,项目名称:web3j,代码行数:24,代码来源:PollingTransactionReceiptProcessor.java


示例20: mint

import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入依赖的package包/类
public void mint(List<Token> tokens) throws ExecutionException, InterruptedException {
    for(Token token:tokens) {
        if(modumToken == null) {
            LOG.error("no modum token bean created");
        } else {
            Future<TransactionReceipt> receipt = modumToken.mint(new Address(token.getWalletAddress()), new Uint256(token.getAmount()));
            receipt.get();
            LOG.debug("minting: {}:{}", token.getWalletAddress(), token.getAmount());
        }
    }
}
 
开发者ID:modum-io,项目名称:tokenapp-backend,代码行数:12,代码来源:Minting.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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