@Test public void name() throws Exception { String read = IoUtils.read("protocol-config.json"); ProtocolLoader.load(2, read); }
public static void load(int chainId, String protocolConfigJson) throws Exception { if (ProtocolGroupManager.isLoadProtocol()) { List<ProtocolConfigJson> protocolConfigs = JSONUtils.json2list(protocolConfigJson, ProtocolConfigJson.class); protocolConfigs.sort(PROTOCOL_CONFIG_COMPARATOR); Map<Short, Protocol> protocolsMap = new HashMap<>(protocolConfigs.size()); for (ProtocolConfigJson configJson : protocolConfigs) { Protocol protocol = new Protocol(); protocol.setVersion(configJson.getVersion()); short extend = configJson.getExtend(); Set<MessageDefine> msgList = new HashSet<>(); Set<TxDefine> txList = new HashSet<>(); List<MessageDefine> validMessages = configJson.getValidMsgs(); List<TxDefine> validTransactions = configJson.getValidTxs(); Set<String> discardMsgs = new HashSet<>(); String[] strings1 = configJson.getInvalidMsgs().split(","); Collections.addAll(discardMsgs, strings1); discardMsgs.remove(""); Set<String> discardTxs = new HashSet<>(); String[] strings = configJson.getInvalidTxs().split(","); Collections.addAll(discardTxs, strings); discardTxs.remove(""); if (extend > 0) { Protocol parent = protocolsMap.get(extend); List<String> msg = validMessages.stream().map(MessageDefine::getName).collect(Collectors.toList()); discardMsgs.addAll(parent.getInvalidMsgs()); discardMsgs.removeIf(msg::contains); msgList.addAll(parent.getAllowMsg()); msgList.removeIf(e -> msg.contains(e.getName())); List<Short> tx = validTransactions.stream().map(TxDefine::getType).collect(Collectors.toList()); discardTxs.addAll(parent.getInvalidTxs()); discardTxs.removeIf(e -> tx.contains(Short.valueOf(e))); txList.addAll(parent.getAllowTx()); txList.removeIf(e -> tx.contains(e.getType())); } msgList.addAll(validMessages); msgList.removeIf(e -> discardMsgs.contains(e.getName())); txList.addAll(validTransactions); txList.removeIf(e -> discardTxs.contains(e.getType() + "")); protocol.setAllowMsg(msgList); protocol.setAllowTx(txList); protocol.setInvalidTxs(discardTxs); protocol.setInvalidMsgs(discardMsgs); protocolsMap.put(protocol.getVersion(), protocol); } ProtocolGroupManager.init(chainId, protocolsMap, (short) 1); } else { ProtocolGroupManager.init(chainId, null, (short) 1); } }
ProtocolLoader { public static void load(int chainId, String protocolConfigJson) throws Exception { if (ProtocolGroupManager.isLoadProtocol()) { List<ProtocolConfigJson> protocolConfigs = JSONUtils.json2list(protocolConfigJson, ProtocolConfigJson.class); protocolConfigs.sort(PROTOCOL_CONFIG_COMPARATOR); Map<Short, Protocol> protocolsMap = new HashMap<>(protocolConfigs.size()); for (ProtocolConfigJson configJson : protocolConfigs) { Protocol protocol = new Protocol(); protocol.setVersion(configJson.getVersion()); short extend = configJson.getExtend(); Set<MessageDefine> msgList = new HashSet<>(); Set<TxDefine> txList = new HashSet<>(); List<MessageDefine> validMessages = configJson.getValidMsgs(); List<TxDefine> validTransactions = configJson.getValidTxs(); Set<String> discardMsgs = new HashSet<>(); String[] strings1 = configJson.getInvalidMsgs().split(","); Collections.addAll(discardMsgs, strings1); discardMsgs.remove(""); Set<String> discardTxs = new HashSet<>(); String[] strings = configJson.getInvalidTxs().split(","); Collections.addAll(discardTxs, strings); discardTxs.remove(""); if (extend > 0) { Protocol parent = protocolsMap.get(extend); List<String> msg = validMessages.stream().map(MessageDefine::getName).collect(Collectors.toList()); discardMsgs.addAll(parent.getInvalidMsgs()); discardMsgs.removeIf(msg::contains); msgList.addAll(parent.getAllowMsg()); msgList.removeIf(e -> msg.contains(e.getName())); List<Short> tx = validTransactions.stream().map(TxDefine::getType).collect(Collectors.toList()); discardTxs.addAll(parent.getInvalidTxs()); discardTxs.removeIf(e -> tx.contains(Short.valueOf(e))); txList.addAll(parent.getAllowTx()); txList.removeIf(e -> tx.contains(e.getType())); } msgList.addAll(validMessages); msgList.removeIf(e -> discardMsgs.contains(e.getName())); txList.addAll(validTransactions); txList.removeIf(e -> discardTxs.contains(e.getType() + "")); protocol.setAllowMsg(msgList); protocol.setAllowTx(txList); protocol.setInvalidTxs(discardTxs); protocol.setInvalidMsgs(discardMsgs); protocolsMap.put(protocol.getVersion(), protocol); } ProtocolGroupManager.init(chainId, protocolsMap, (short) 1); } else { ProtocolGroupManager.init(chainId, null, (short) 1); } } }
ProtocolLoader { public static void load(int chainId, String protocolConfigJson) throws Exception { if (ProtocolGroupManager.isLoadProtocol()) { List<ProtocolConfigJson> protocolConfigs = JSONUtils.json2list(protocolConfigJson, ProtocolConfigJson.class); protocolConfigs.sort(PROTOCOL_CONFIG_COMPARATOR); Map<Short, Protocol> protocolsMap = new HashMap<>(protocolConfigs.size()); for (ProtocolConfigJson configJson : protocolConfigs) { Protocol protocol = new Protocol(); protocol.setVersion(configJson.getVersion()); short extend = configJson.getExtend(); Set<MessageDefine> msgList = new HashSet<>(); Set<TxDefine> txList = new HashSet<>(); List<MessageDefine> validMessages = configJson.getValidMsgs(); List<TxDefine> validTransactions = configJson.getValidTxs(); Set<String> discardMsgs = new HashSet<>(); String[] strings1 = configJson.getInvalidMsgs().split(","); Collections.addAll(discardMsgs, strings1); discardMsgs.remove(""); Set<String> discardTxs = new HashSet<>(); String[] strings = configJson.getInvalidTxs().split(","); Collections.addAll(discardTxs, strings); discardTxs.remove(""); if (extend > 0) { Protocol parent = protocolsMap.get(extend); List<String> msg = validMessages.stream().map(MessageDefine::getName).collect(Collectors.toList()); discardMsgs.addAll(parent.getInvalidMsgs()); discardMsgs.removeIf(msg::contains); msgList.addAll(parent.getAllowMsg()); msgList.removeIf(e -> msg.contains(e.getName())); List<Short> tx = validTransactions.stream().map(TxDefine::getType).collect(Collectors.toList()); discardTxs.addAll(parent.getInvalidTxs()); discardTxs.removeIf(e -> tx.contains(Short.valueOf(e))); txList.addAll(parent.getAllowTx()); txList.removeIf(e -> tx.contains(e.getType())); } msgList.addAll(validMessages); msgList.removeIf(e -> discardMsgs.contains(e.getName())); txList.addAll(validTransactions); txList.removeIf(e -> discardTxs.contains(e.getType() + "")); protocol.setAllowMsg(msgList); protocol.setAllowTx(txList); protocol.setInvalidTxs(discardTxs); protocol.setInvalidMsgs(discardMsgs); protocolsMap.put(protocol.getVersion(), protocol); } ProtocolGroupManager.init(chainId, protocolsMap, (short) 1); } else { ProtocolGroupManager.init(chainId, null, (short) 1); } }  }
ProtocolLoader { public static void load(int chainId, String protocolConfigJson) throws Exception { if (ProtocolGroupManager.isLoadProtocol()) { List<ProtocolConfigJson> protocolConfigs = JSONUtils.json2list(protocolConfigJson, ProtocolConfigJson.class); protocolConfigs.sort(PROTOCOL_CONFIG_COMPARATOR); Map<Short, Protocol> protocolsMap = new HashMap<>(protocolConfigs.size()); for (ProtocolConfigJson configJson : protocolConfigs) { Protocol protocol = new Protocol(); protocol.setVersion(configJson.getVersion()); short extend = configJson.getExtend(); Set<MessageDefine> msgList = new HashSet<>(); Set<TxDefine> txList = new HashSet<>(); List<MessageDefine> validMessages = configJson.getValidMsgs(); List<TxDefine> validTransactions = configJson.getValidTxs(); Set<String> discardMsgs = new HashSet<>(); String[] strings1 = configJson.getInvalidMsgs().split(","); Collections.addAll(discardMsgs, strings1); discardMsgs.remove(""); Set<String> discardTxs = new HashSet<>(); String[] strings = configJson.getInvalidTxs().split(","); Collections.addAll(discardTxs, strings); discardTxs.remove(""); if (extend > 0) { Protocol parent = protocolsMap.get(extend); List<String> msg = validMessages.stream().map(MessageDefine::getName).collect(Collectors.toList()); discardMsgs.addAll(parent.getInvalidMsgs()); discardMsgs.removeIf(msg::contains); msgList.addAll(parent.getAllowMsg()); msgList.removeIf(e -> msg.contains(e.getName())); List<Short> tx = validTransactions.stream().map(TxDefine::getType).collect(Collectors.toList()); discardTxs.addAll(parent.getInvalidTxs()); discardTxs.removeIf(e -> tx.contains(Short.valueOf(e))); txList.addAll(parent.getAllowTx()); txList.removeIf(e -> tx.contains(e.getType())); } msgList.addAll(validMessages); msgList.removeIf(e -> discardMsgs.contains(e.getName())); txList.addAll(validTransactions); txList.removeIf(e -> discardTxs.contains(e.getType() + "")); protocol.setAllowMsg(msgList); protocol.setAllowTx(txList); protocol.setInvalidTxs(discardTxs); protocol.setInvalidMsgs(discardMsgs); protocolsMap.put(protocol.getVersion(), protocol); } ProtocolGroupManager.init(chainId, protocolsMap, (short) 1); } else { ProtocolGroupManager.init(chainId, null, (short) 1); } }  static void load(int chainId, String protocolConfigJson); static void load(int chainId); static void load(int chainId, boolean loadProtocol); }
ProtocolLoader { public static void load(int chainId, String protocolConfigJson) throws Exception { if (ProtocolGroupManager.isLoadProtocol()) { List<ProtocolConfigJson> protocolConfigs = JSONUtils.json2list(protocolConfigJson, ProtocolConfigJson.class); protocolConfigs.sort(PROTOCOL_CONFIG_COMPARATOR); Map<Short, Protocol> protocolsMap = new HashMap<>(protocolConfigs.size()); for (ProtocolConfigJson configJson : protocolConfigs) { Protocol protocol = new Protocol(); protocol.setVersion(configJson.getVersion()); short extend = configJson.getExtend(); Set<MessageDefine> msgList = new HashSet<>(); Set<TxDefine> txList = new HashSet<>(); List<MessageDefine> validMessages = configJson.getValidMsgs(); List<TxDefine> validTransactions = configJson.getValidTxs(); Set<String> discardMsgs = new HashSet<>(); String[] strings1 = configJson.getInvalidMsgs().split(","); Collections.addAll(discardMsgs, strings1); discardMsgs.remove(""); Set<String> discardTxs = new HashSet<>(); String[] strings = configJson.getInvalidTxs().split(","); Collections.addAll(discardTxs, strings); discardTxs.remove(""); if (extend > 0) { Protocol parent = protocolsMap.get(extend); List<String> msg = validMessages.stream().map(MessageDefine::getName).collect(Collectors.toList()); discardMsgs.addAll(parent.getInvalidMsgs()); discardMsgs.removeIf(msg::contains); msgList.addAll(parent.getAllowMsg()); msgList.removeIf(e -> msg.contains(e.getName())); List<Short> tx = validTransactions.stream().map(TxDefine::getType).collect(Collectors.toList()); discardTxs.addAll(parent.getInvalidTxs()); discardTxs.removeIf(e -> tx.contains(Short.valueOf(e))); txList.addAll(parent.getAllowTx()); txList.removeIf(e -> tx.contains(e.getType())); } msgList.addAll(validMessages); msgList.removeIf(e -> discardMsgs.contains(e.getName())); txList.addAll(validTransactions); txList.removeIf(e -> discardTxs.contains(e.getType() + "")); protocol.setAllowMsg(msgList); protocol.setAllowTx(txList); protocol.setInvalidTxs(discardTxs); protocol.setInvalidMsgs(discardMsgs); protocolsMap.put(protocol.getVersion(), protocol); } ProtocolGroupManager.init(chainId, protocolsMap, (short) 1); } else { ProtocolGroupManager.init(chainId, null, (short) 1); } }  static void load(int chainId, String protocolConfigJson); static void load(int chainId); static void load(int chainId, boolean loadProtocol);  }