use of org.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.
the class Utils method getParameterizedTypeFromArray.
static <T extends Type> Class<T> getParameterizedTypeFromArray(TypeReference typeReference) throws ClassNotFoundException {
java.lang.reflect.Type type = typeReference.getType();
java.lang.reflect.Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments();
String parameterizedTypeName = typeArguments[0].getTypeName();
return (Class<T>) Class.forName(parameterizedTypeName);
}
use of org.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.
the class NodeActionTools method processNodeAction.
static void processNodeAction(ApplicationContext ctx, NodeAction nodeAction, String[] args) {
try {
switch(args[1]) {
case "cancelNode":
case "registerNode":
if (args.length < 3) {
System.out.println("Please input: node.json");
break;
}
System.out.println("node.json=" + args[2]);
Resource template = ctx.getResource(args[2]);
InputStream ksInputStream = template.getInputStream();
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
NodeInfo nodeInfo = mapper.readValue(ksInputStream, NodeInfo.class);
if (args[1].equals("cancelNode")) {
nodeAction.cancelNode(new Utf8String(nodeInfo.getId())).get();
} else {
nodeAction.registerNode(new Utf8String(nodeInfo.getId()), new Utf8String(nodeInfo.getIp()), new Uint256(nodeInfo.getPort()), new Uint8(nodeInfo.getCategory()), new Utf8String(nodeInfo.getDesc()), new Utf8String(nodeInfo.getCAhash()), new Utf8String(nodeInfo.getAgencyinfo()), new Uint256(nodeInfo.getIdx())).get();
}
case "all":
Uint256 len = nodeAction.getNodeIdsLength().get();
System.out.println("NodeIdsLength= " + len.getValue().intValue());
for (int i = 0; i < len.getValue().intValue(); i++) {
System.out.println("----------node " + i + "---------");
Utf8String id = nodeAction.getNodeId(new Uint256(i)).get();
System.out.println("id=" + id);
List<Type> node = nodeAction.getNode(id).get();
System.out.println("ip=" + node.get(0));
System.out.println("port=" + ((BigInteger) (node.get(1).getValue())).intValue());
System.out.println("category=" + ((BigInteger) (node.get(2).getValue())).intValue());
System.out.println("desc=" + node.get(3));
System.out.println("CAhash=" + node.get(4));
System.out.println("agencyinfo=" + node.get(5));
System.out.println("blocknumber=" + ((BigInteger) (node.get(2).getValue())).intValue());
System.out.println("Idx=" + ((BigInteger) (nodeAction.getNodeIdx(id).get()).getValue()).intValue());
}
break;
default:
break;
}
} catch (Exception e) {
System.out.println(e);
}
}
use of org.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.
the class SystemContractTools method getAction.
static String getAction(SystemProxy systemProxy, String filename) {
String address = new String();
try {
List<Type> route = systemProxy.getRoute(new Utf8String(filename)).get();
address = route.get(0).toString();
} catch (Exception e) {
System.out.println(e);
}
return address;
}
use of org.bcos.web3j.abi.datatypes.Type in project web3sdk by FISCO-BCOS.
the class SystemProxyTools method processSystemProxy.
static void processSystemProxy(SystemProxy systemProxy, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
try {
System.out.println("-----------------系统路由表----------------------");
Uint256 routelength = systemProxy.getRouteSize().get();
for (int i = 0; i < routelength.getValue().intValue(); i++) {
Utf8String key = systemProxy.getRouteNameByIndex(new Uint256(i)).get();
List<Type> route = systemProxy.getRoute(key).get();
System.out.println(" " + i + ")" + key + "=>" + (route.get(0)) + "," + route.get(1).getValue() + "," + ((BigInteger) (route.get(2).getValue())).intValue());
if (key.getValue().equals("TransactionFilterChain")) {
TransactionFilterChain transactionFilterChain1 = TransactionFilterChain.load(route.get(0).toString(), web3j, credentials, gasPrice, gasLimit);
Uint256 filterlength = transactionFilterChain1.getFiltersLength().get();
for (int j = 0; j < filterlength.getValue().intValue(); j++) {
Address filter = transactionFilterChain1.getFilter(new Uint256(j)).get();
TransactionFilterBase transactionFilterBase = TransactionFilterBase.load(filter.toString(), web3j, credentials, gasPrice, gasLimit);
Utf8String name = transactionFilterBase._name().get();
Utf8String version = transactionFilterBase._version().get();
System.out.println(" " + name + "=>" + version + "," + filter);
}
}
}
} catch (Exception e) {
System.out.println(e);
}
}
use of org.bcos.web3j.abi.datatypes.Type 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