本文整理汇总了Java中org.web3j.protocol.core.methods.response.TransactionReceipt类的典型用法代码示例。如果您正苦于以下问题:Java TransactionReceipt类的具体用法?Java TransactionReceipt怎么用?Java TransactionReceipt使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TransactionReceipt类属于org.web3j.protocol.core.methods.response包,在下文中一共展示了TransactionReceipt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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));
}
示例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))));
}
示例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);
}
}
示例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());
}
示例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);
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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()));
}
示例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))));
}
示例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;
}