use of org.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.
the class FileServerManager method notifyEventObservable.
public Observable<NotifyEventResponse> notifyEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
final Event event = new Event("Notify", Arrays.<TypeReference<?>>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
}, new TypeReference<Utf8String>() {
}));
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(event));
return web3j.ethLogObservable(filter).map(new Func1<Log, NotifyEventResponse>() {
@Override
public NotifyEventResponse call(Log log) {
EventValues eventValues = extractEventParameters(event, log);
NotifyEventResponse typedResponse = new NotifyEventResponse();
typedResponse._errno = (Uint256) eventValues.getNonIndexedValues().get(0);
typedResponse._info = (Utf8String) eventValues.getNonIndexedValues().get(1);
return typedResponse;
}
});
}
use of org.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.
the class FileServerManager method getNotifyEvents.
public static List<NotifyEventResponse> getNotifyEvents(TransactionReceipt transactionReceipt) {
final Event event = new Event("Notify", Arrays.<TypeReference<?>>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
}, new TypeReference<Utf8String>() {
}));
List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
ArrayList<NotifyEventResponse> responses = new ArrayList<NotifyEventResponse>(valueList.size());
for (EventValues eventValues : valueList) {
NotifyEventResponse typedResponse = new NotifyEventResponse();
typedResponse._errno = (Uint256) eventValues.getNonIndexedValues().get(0);
typedResponse._info = (Utf8String) eventValues.getNonIndexedValues().get(1);
responses.add(typedResponse);
}
return responses;
}
use of org.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.
the class NodeAction method logMessageEventObservable.
public Observable<LogMessageEventResponse> logMessageEventObservable(DefaultBlockParameter startBlock, DefaultBlockParameter endBlock) {
final Event event = new Event("LogMessage", Arrays.<TypeReference<?>>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {
}, new TypeReference<Uint256>() {
}, new TypeReference<Utf8String>() {
}));
EthFilter filter = new EthFilter(startBlock, endBlock, getContractAddress());
filter.addSingleTopic(EventEncoder.encode(event));
return web3j.ethLogObservable(filter).map(new Func1<Log, LogMessageEventResponse>() {
@Override
public LogMessageEventResponse call(Log log) {
EventValues eventValues = extractEventParameters(event, log);
LogMessageEventResponse typedResponse = new LogMessageEventResponse();
typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(0);
typedResponse.code = (Uint256) eventValues.getNonIndexedValues().get(1);
typedResponse.msg = (Utf8String) eventValues.getNonIndexedValues().get(2);
return typedResponse;
}
});
}
use of org.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.
the class NodeAction method getLogMessageEvents.
public static List<LogMessageEventResponse> getLogMessageEvents(TransactionReceipt transactionReceipt) {
final Event event = new Event("LogMessage", Arrays.<TypeReference<?>>asList(), Arrays.<TypeReference<?>>asList(new TypeReference<Address>() {
}, new TypeReference<Uint256>() {
}, new TypeReference<Utf8String>() {
}));
List<EventValues> valueList = extractEventParameters(event, transactionReceipt);
ArrayList<LogMessageEventResponse> responses = new ArrayList<LogMessageEventResponse>(valueList.size());
for (EventValues eventValues : valueList) {
LogMessageEventResponse typedResponse = new LogMessageEventResponse();
typedResponse.addr = (Address) eventValues.getNonIndexedValues().get(0);
typedResponse.code = (Uint256) eventValues.getNonIndexedValues().get(1);
typedResponse.msg = (Utf8String) eventValues.getNonIndexedValues().get(2);
responses.add(typedResponse);
}
return responses;
}
use of org.bcos.web3j.abi.TypeReference in project web3sdk by FISCO-BCOS.
the class Contract method extractEventParameters.
/**
* @desc 为了能在sol实例化出来的java类里面用到static的方法,而不需要实例化这个java类(load方法,用了name service,屏蔽了自身address)
*/
protected static EventValues extractEventParameters(Event event, Log log) {
List<String> topics = log.getTopics();
String encodedEventSignature = EventEncoder.encode(event);
if (!topics.get(0).equals(encodedEventSignature)) {
return null;
}
List<Type> indexedValues = new ArrayList<>();
List<Type> nonIndexedValues = FunctionReturnDecoder.decode(log.getData(), event.getNonIndexedParameters());
List<TypeReference<Type>> indexedParameters = event.getIndexedParameters();
for (int i = 0; i < indexedParameters.size(); i++) {
Type value = FunctionReturnDecoder.decodeIndexedValue(topics.get(i + 1), indexedParameters.get(i));
indexedValues.add(value);
}
return new EventValues(indexedValues, nonIndexedValues);
}
Aggregations