Skip to content

Commit

Permalink
Add setTermWeight and get (#931)
Browse files Browse the repository at this point in the history
* Add term weight

* Fix wrong pre-commmit

* Remove binary of consensus precompiled, add version check
  • Loading branch information
morebtcg authored Oct 9, 2024
1 parent cd6fe37 commit a0090c2
Show file tree
Hide file tree
Showing 8 changed files with 310 additions and 48 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ext {
// integrationTest.mustRunAfter test
allprojects {
group = 'org.fisco-bcos.java-sdk'
version = '3.8.0'
version = '3.9.0-SNAPSHOT'

apply plugin: 'maven-publish'
apply plugin: 'idea'
Expand Down
4 changes: 2 additions & 2 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
bash gradlew verifyGoogleJavaFormat
result=$?
printf "the verifyGoogleJavaFormat result code is $result"
if [[ "$result" = 0 ]] ; then
if [ "$result" -eq 0 ]; then
echo "\033[32m
....
....
Expand All @@ -30,4 +30,4 @@ else
....
\033[0m"
exit 1
fi
fi
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public static class ConsensusNodeInfo {
@JsonProperty("weight")
private Integer weight;

@JsonProperty("termWeight")
private Integer termWeight;

@JsonProperty("index")
private Integer index;

Expand All @@ -65,6 +68,14 @@ public void setWeight(Integer weight) {
this.weight = weight;
}

public Integer getTermWeight() {
return termWeight;
}

public void setTermWeight(Integer termWeight) {
this.termWeight = termWeight;
}

public Integer getIndex() {
return index;
}
Expand All @@ -82,6 +93,9 @@ public String toString() {
+ ", weight='"
+ weight
+ '\''
+ ", termWeight='"
+ termWeight
+ '\''
+ ", index='"
+ index
+ '\''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,21 @@ public class SealerList extends JsonRpcResponse<List<SealerList.Sealer>> {
public static class Sealer {
private String nodeID;
private int weight;
private int termWeight;

@Override
public String toString() {
return "Sealer{" + "nodeID='" + nodeID + '\'' + ", weight=" + weight + '}';
return "Sealer{"
+ "nodeID='"
+ nodeID
+ '\''
+ ", weight="
+ weight
+ "'"
+ "termWeight='"
+ termWeight
+ "'"
+ '}';
}

public String getNodeID() {
Expand All @@ -46,6 +57,14 @@ public void setWeight(int weight) {
this.weight = weight;
}

public int getTermWeight() {
return termWeight;
}

public void setTermWeight(int termWeight) {
this.termWeight = termWeight;
}

@Override
public int hashCode() {
return this.getNodeID().hashCode() + this.getWeight();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.fisco.bcos.sdk.v3.client.protocol.response.SealerList;
import org.fisco.bcos.sdk.v3.client.protocol.response.SyncStatus;
import org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledAddress;
import org.fisco.bcos.sdk.v3.contract.precompiled.model.PrecompiledVersionCheck;
import org.fisco.bcos.sdk.v3.crypto.keypair.CryptoKeyPair;
import org.fisco.bcos.sdk.v3.model.PrecompiledRetCode;
import org.fisco.bcos.sdk.v3.model.RetCode;
Expand Down Expand Up @@ -131,4 +132,19 @@ public RetCode setWeight(String nodeId, BigInteger weight) throws ContractExcept
return ReceiptParser.parseTransactionReceipt(
receipt, tr -> consensusPrecompiled.getSetWeightOutput(tr).getValue1());
}

public RetCode setTermWeight(String nodeId, BigInteger weight) throws ContractException {
long currentVersion =
client.getGroupInfo()
.getResult()
.getNodeList()
.get(0)
.getProtocol()
.getCompatibilityVersion();
PrecompiledVersionCheck.TERM_WEIGHT_MIN_SUPPORT_VERSION.checkVersion(currentVersion);

TransactionReceipt receipt = consensusPrecompiled.setTermWeight(nodeId, weight);
return ReceiptParser.parseTransactionReceipt(
receipt, tr -> consensusPrecompiled.getSetTermWeightOutput(tr).getValue1());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public class PrecompiledVersionCheck {
public static final Version V330_FIX_BFS_VERSION = new Version("fixBfs", "3.3.0");

public static final Version BALANCE_PRECOMPILED_VERSION = new Version("balance", "3.6.0");
public static final Version TERM_WEIGHT_MIN_SUPPORT_VERSION =
new Version("consensus", "3.12.0");
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ contract ConsensusPrecompiled {
function addObserver(string memory) public returns (int256){}
function remove(string memory) public returns (int256){}
function setWeight(string memory,uint256) public returns (int256){}
function setTermWeight(string memory,uint256) public returns (int256){}
}

0 comments on commit a0090c2

Please sign in to comment.