Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ public TransactionResponse decodeReceiptWithoutValues(
String abi, TransactionReceipt transactionReceipt)
throws TransactionException, IOException, ABICodecException;

public Map<String, List<Object>> decodeEvents(String abi, List<Logs> logs)
public Map<String, List<List<Object>>> decodeEvents(String abi, List<Logs> logs)
throws ABICodecException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.fisco.bcos.sdk.transaction.codec.decode;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -111,12 +112,12 @@ public TransactionResponse decodeReceiptStatus(TransactionReceipt receipt) {

@SuppressWarnings("static-access")
@Override
public Map<String, List<Object>> decodeEvents(String abi, List<Logs> logs)
public Map<String, List<List<Object>>> decodeEvents(String abi, List<Logs> logs)
throws ABICodecException {
ABIDefinitionFactory abiDefinitionFactory = new ABIDefinitionFactory(cryptoSuite);
ContractABIDefinition contractABIDefinition = abiDefinitionFactory.loadABI(abi);
Map<String, List<ABIDefinition>> eventsMap = contractABIDefinition.getEvents();
Map<String, List<Object>> result = new HashMap<>();
Map<String, List<List<Object>>> result = new HashMap<>();
eventsMap.forEach(
(name, events) -> {
for (ABIDefinition abiDefinition : events) {
Expand All @@ -136,9 +137,11 @@ public Map<String, List<Object>> decodeEvents(String abi, List<Logs> logs)
abiCodecObject.decodeJavaObject(
outputObject, log.getData());
if (result.containsKey(name)) {
result.get("name").addAll(list);
result.get(name).add(list);
} else {
result.put(name, list);
List<List<Object>> l = new ArrayList<>();
l.add(list);
result.put(name, l);
}
} catch (Exception e) {
logger.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.fisco.bcos.sdk.transaction.model.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -92,11 +93,12 @@ public String getEvents() {
return events;
}

public Map<String, List<Object>> getEventResultMap() {
@JsonIgnore
public Map<String, List<List<Object>>> getEventResultMap() {
if (StringUtils.isEmpty(events)) {
return null;
}
return JsonUtils.fromJson(events, new TypeReference<Map<String, List<Object>>>() {});
return JsonUtils.fromJson(events, new TypeReference<Map<String, List<List<Object>>>>() {});
}

/** @param events the events to set */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testDecode() throws Exception {
EventLog eventLog = new EventLog(log.getData(), log.getTopics());
List<Object> list = abiCodec.decodeEvent(abi, "LogInit", eventLog);
Assert.assertEquals("test2", list.get(1));
Map<String, List<Object>> map = response.getEventResultMap();
Assert.assertEquals("test2", map.get("LogInit").get(1));
Map<String, List<List<Object>>> map = response.getEventResultMap();
Assert.assertEquals("test2", map.get("LogInit").get(0).get(1));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.fisco.bcos.sdk.transaction.tools.ContractLoader;
import org.fisco.bcos.sdk.transaction.tools.JsonUtils;
import org.junit.Assert;
import org.junit.Test;

Expand Down Expand Up @@ -76,11 +75,14 @@ public void testDecode() throws Exception {
Lists.newArrayList(BigInteger.valueOf(1)));
TransactionResponse transactionResponseWithoutValues =
decoder.decodeReceiptWithoutValues(abi, transactionReceipt);
System.out.println(JsonUtils.toJson(transactionResponseWithoutValues));
// System.out.println(JsonUtils.toJson(transactionResponseWithoutValues));
TransactionResponse transactionResponseWithValues =
decoder.decodeReceiptWithValues(abi, "incrementUint256", transactionReceipt);
// System.out.println(JsonUtils.toJson(transactionResponseWithValues));
Assert.assertEquals("Success", transactionResponseWithValues.getReceiptMessages());
Map<String, List<Object>> events = decoder.decodeEvents(abi, transactionReceipt.getLogs());
Map<String, List<List<Object>>> events =
decoder.decodeEvents(abi, transactionReceipt.getLogs());
// System.out.println(JsonUtils.toJson(events));
Assert.assertEquals(1, events.size());
// setBytes
List<Object> s = Lists.newArrayList("2".getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public void test2ComplexDeploy() throws Exception {
contractAddress,
"0x0000000000000000000000000000000000000000000000000000000000000000"));
// System.out.println(JsonUtils.toJson(response));
Map<String, List<Object>> map = response.getEventResultMap();
Assert.assertEquals("test2", map.get("LogInit").get(1));
Map<String, List<List<Object>>> map = response.getEventResultMap();
Assert.assertEquals("test2", map.get("LogInit").get(0).get(1));
}

@Test
Expand Down Expand Up @@ -296,9 +296,9 @@ public void test6ComplexSetValues() throws Exception {
transactionProcessor.sendTransactionAndGetResponse(
contractAddress, abi, "setValues", paramsSetValues);
// System.out.println(JsonUtils.toJson(transactionResponse));
Map<String, List<Object>> eventsMap = transactionResponse.getEventResultMap();
Map<String, List<List<Object>>> eventsMap = transactionResponse.getEventResultMap();
Assert.assertEquals(1, eventsMap.size());
Assert.assertEquals("set values 字符串", eventsMap.get("LogSetValues").get(2));
Assert.assertEquals("set values 字符串", eventsMap.get("LogSetValues").get(0).get(2));
}

@Test
Expand Down Expand Up @@ -330,10 +330,10 @@ public void test7ComplexSetBytes() throws Exception {
Assert.assertEquals(transactionResponse3.getValuesList().size(), 1);
Assert.assertEquals(transactionResponse3.getValuesList().get(0), "set bytes test");

Map<String, List<Object>> eventsMap3 = transactionResponse3.getEventResultMap();
// System.out.println(JsonUtils.toJson(eventsMap3));
Map<String, List<List<Object>>> eventsMap3 = transactionResponse3.getEventResultMap();
System.out.println(JsonUtils.toJson(eventsMap3));
Assert.assertEquals(1, eventsMap3.size());
Assert.assertEquals("set bytes test", eventsMap3.get("LogSetBytes").get(1));
Assert.assertEquals("set bytes test", eventsMap3.get("LogSetBytes").get(0).get(1));

// getBytes
CallResponse callResponse4 =
Expand Down