本文整理汇总了Java中org.web3j.protocol.core.methods.response.TransactionReceipt.getLogs方法的典型用法代码示例。如果您正苦于以下问题:Java TransactionReceipt.getLogs方法的具体用法?Java TransactionReceipt.getLogs怎么用?Java TransactionReceipt.getLogs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.web3j.protocol.core.methods.response.TransactionReceipt
的用法示例。
在下文中一共展示了TransactionReceipt.getLogs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTransferTokensTransaction
import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入方法依赖的package包/类
private void sendTransferTokensTransaction(
Credentials credentials, String to, String contractAddress, BigInteger qty)
throws Exception {
Function function = transfer(to, qty);
String functionHash = execute(credentials, function, contractAddress);
TransactionReceipt transferTransactionReceipt =
waitForTransactionReceipt(functionHash);
assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash));
List<Log> logs = transferTransactionReceipt.getLogs();
assertFalse(logs.isEmpty());
Log log = logs.get(0);
// verify the event was called with the function parameters
List<String> topics = log.getTopics();
assertThat(topics.size(), is(3));
Event transferEvent = transferEvent();
// check function signature - we only have a single topic our event signature,
// there are no indexed parameters in this example
String encodedEventSignature = EventEncoder.encode(transferEvent);
assertThat(topics.get(0), is(encodedEventSignature));
assertThat(new Address(topics.get(1)), is(new Address(credentials.getAddress())));
assertThat(new Address(topics.get(2)), is(new Address(to)));
// verify qty transferred
List<Type> results = FunctionReturnDecoder.decode(
log.getData(), transferEvent.getNonIndexedParameters());
assertThat(results, equalTo(Collections.singletonList(new Uint256(qty))));
}
示例2: sendApproveTransaction
import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入方法依赖的package包/类
private void sendApproveTransaction(
Credentials credentials, String spender, BigInteger value,
String contractAddress) throws Exception {
Function function = approve(spender, value);
String functionHash = execute(credentials, function, contractAddress);
TransactionReceipt transferTransactionReceipt =
waitForTransactionReceipt(functionHash);
assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash));
List<Log> logs = transferTransactionReceipt.getLogs();
assertFalse(logs.isEmpty());
Log log = logs.get(0);
// verify the event was called with the function parameters
List<String> topics = log.getTopics();
assertThat(topics.size(), is(3));
// event Transfer(address indexed _from, address indexed _to, uint256 _value);
Event event = approvalEvent();
// check function signature - we only have a single topic our event signature,
// there are no indexed parameters in this example
String encodedEventSignature = EventEncoder.encode(event);
assertThat(topics.get(0), is(encodedEventSignature));
assertThat(new Address(topics.get(1)), is(new Address(credentials.getAddress())));
assertThat(new Address(topics.get(2)), is(new Address(spender)));
// verify our two event parameters
List<Type> results = FunctionReturnDecoder.decode(
log.getData(), event.getNonIndexedParameters());
assertThat(results, equalTo(Collections.singletonList(new Uint256(value))));
}
示例3: sendTransferFromTransaction
import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入方法依赖的package包/类
public void sendTransferFromTransaction(
Credentials credentials, String from, String to, BigInteger value,
String contractAddress) throws Exception {
Function function = transferFrom(from, to, value);
String functionHash = execute(credentials, function, contractAddress);
TransactionReceipt transferTransactionReceipt =
waitForTransactionReceipt(functionHash);
assertThat(transferTransactionReceipt.getTransactionHash(), is(functionHash));
List<Log> logs = transferTransactionReceipt.getLogs();
assertFalse(logs.isEmpty());
Log log = logs.get(0);
Event transferEvent = transferEvent();
List<String> topics = log.getTopics();
// check function signature - we only have a single topic our event signature,
// there are no indexed parameters in this example
String encodedEventSignature = EventEncoder.encode(transferEvent);
assertThat(topics.get(0), is(encodedEventSignature));
assertThat(new Address(topics.get(1)), is(new Address(from)));
assertThat(new Address(topics.get(2)), is(new Address(to)));
// verify qty transferred
List<Type> results = FunctionReturnDecoder.decode(
log.getData(), transferEvent.getNonIndexedParameters());
assertThat(results, equalTo(Collections.singletonList(new Uint256(value))));
}
示例4: extractEventParameters
import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入方法依赖的package包/类
protected List<EventValues> extractEventParameters(
Event event, TransactionReceipt transactionReceipt) {
List<Log> logs = transactionReceipt.getLogs();
List<EventValues> values = new ArrayList<>();
for (Log log : logs) {
EventValues eventValues = extractEventParameters(event, log);
if (eventValues != null) {
values.add(eventValues);
}
}
return values;
}
示例5: testEventFilter
import org.web3j.protocol.core.methods.response.TransactionReceipt; //导入方法依赖的package包/类
@Test
public void testEventFilter() throws Exception {
unlockAccount();
Function function = createFibonacciFunction();
String encodedFunction = FunctionEncoder.encode(function);
BigInteger gas = estimateGas(encodedFunction);
String transactionHash = sendTransaction(ALICE, CONTRACT_ADDRESS, gas, encodedFunction);
TransactionReceipt transactionReceipt =
waitForTransactionReceipt(transactionHash);
assertFalse("Transaction execution ran out of gas",
gas.equals(transactionReceipt.getGasUsed()));
List<Log> logs = transactionReceipt.getLogs();
assertFalse(logs.isEmpty());
Log log = logs.get(0);
List<String> topics = log.getTopics();
assertThat(topics.size(), is(1));
Event event = new Event("Notify",
Collections.emptyList(),
Arrays.asList(new TypeReference<Uint256>() {}, new TypeReference<Uint256>() {}));
// check function signature - we only have a single topic our event signature,
// there are no indexed parameters in this example
String encodedEventSignature = EventEncoder.encode(event);
assertThat(topics.get(0),
is(encodedEventSignature));
// verify our two event parameters
List<Type> results = FunctionReturnDecoder.decode(
log.getData(), event.getNonIndexedParameters());
assertThat(results, equalTo(Arrays.asList(
new Uint256(BigInteger.valueOf(7)), new Uint256(BigInteger.valueOf(13)))));
// finally check it shows up in the event filter
List<EthLog.LogResult> filterLogs = createFilterForEvent(
encodedEventSignature, CONTRACT_ADDRESS);
assertFalse(filterLogs.isEmpty());
}