From 50029698bfa0e5e640ebc3e137e372e8762c0867 Mon Sep 17 00:00:00 2001 From: monan <651932351@qq.com> Date: Wed, 9 Oct 2024 16:29:08 +0800 Subject: [PATCH] Add setTermWeight --- build.gradle | 2 +- .../command/category/ConsensusOpCommand.java | 15 ++++++++++++++- .../console/precompiled/PrecompiledFace.java | 2 ++ .../console/precompiled/PrecompiledImpl.java | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 4e0d5d92..5cd5398f 100644 --- a/build.gradle +++ b/build.gradle @@ -42,7 +42,7 @@ dependencies { //implementation 'org.fisco-bcos:solcJ:0.5.2.1' implementation 'org.fisco-bcos:solcJ:1.0.0-SNAPSHOT' - implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.8.0-SNAPSHOT') { + implementation ('org.fisco-bcos.java-sdk:fisco-bcos-java-sdk:3.9.0-SNAPSHOT') { exclude group: "org.slf4j" } diff --git a/src/main/java/console/command/category/ConsensusOpCommand.java b/src/main/java/console/command/category/ConsensusOpCommand.java index 200a76a1..d5e17252 100644 --- a/src/main/java/console/command/category/ConsensusOpCommand.java +++ b/src/main/java/console/command/category/ConsensusOpCommand.java @@ -133,6 +133,18 @@ public Map getAllCommandInfo(boolean isWasm) { 2, 2); + public static final CommandInfo SET_CONSENSUS_TERM_WEIGHT = + new CommandInfo( + "setConsensusTermWeight", + "Set consensus term weight for the specified node", + HelpInfo::setConsensusWeightHelp, + (consoleInitializer, params, pwd) -> + consoleInitializer + .getPrecompiledFace() + .setConsensusNodeTermWeight(params), + 2, + 2); + static { Field[] fields = ConsensusOpCommand.class.getDeclaredFields(); for (Field field : fields) { @@ -159,5 +171,6 @@ public Map getAllCommandInfo(boolean isWasm) { ConsensusOpCommand.ADD_OBSERVER.getCommand(), ConsensusOpCommand.ADD_SEALER.getCommand(), ConsensusOpCommand.REMOVE_NODE.getCommand(), - ConsensusOpCommand.SET_CONSENSUS_WEIGHT.getCommand())); + ConsensusOpCommand.SET_CONSENSUS_WEIGHT.getCommand(), + ConsensusOpCommand.SET_CONSENSUS_TERM_WEIGHT.getCommand())); } diff --git a/src/main/java/console/precompiled/PrecompiledFace.java b/src/main/java/console/precompiled/PrecompiledFace.java index 045d7566..df26c744 100644 --- a/src/main/java/console/precompiled/PrecompiledFace.java +++ b/src/main/java/console/precompiled/PrecompiledFace.java @@ -29,6 +29,8 @@ void setSystemConfigByKey(ConsoleInitializer consoleInitializer, String[] params void setConsensusNodeWeight(String[] params) throws Exception; + void setConsensusNodeTermWeight(String[] params) throws Exception; + void changeDir(String[] params) throws Exception; void makeDir(String[] params) throws Exception; diff --git a/src/main/java/console/precompiled/PrecompiledImpl.java b/src/main/java/console/precompiled/PrecompiledImpl.java index 237a277a..094c402b 100644 --- a/src/main/java/console/precompiled/PrecompiledImpl.java +++ b/src/main/java/console/precompiled/PrecompiledImpl.java @@ -134,6 +134,23 @@ public void setConsensusNodeWeight(String[] params) throws Exception { } } + @Override + public void setConsensusNodeTermWeight(String[] params) throws Exception { + String nodeId = params[1]; + int weight = ConsoleUtils.processNonNegativeNumber("consensusWeight", params[2]); + if (nodeId.length() != 128) { + ConsoleUtils.printJson(PrecompiledRetCode.CODE_INVALID_NODEID.toString()); + } else { + RetCode retCode = + this.consensusService.setTermWeight(nodeId, BigInteger.valueOf(weight)); + ConsoleUtils.printJson(retCode.toString()); + if (retCode.getCode() == PrecompiledRetCode.CODE_NO_AUTHORIZED.getCode()) { + System.out.println( + "Maybe you should use 'setConsensusNodeTermWeightProposal' command to change system config."); + } + } + } + @Override public void setSystemConfigByKey(ConsoleInitializer consoleInitializer, String[] params) throws Exception {