Skip to content

Commit 299f15d

Browse files
committed
<fix>(auth): fix auth bug, add auth interfaces.
1 parent cf931bf commit 299f15d

File tree

9 files changed

+245
-34
lines changed

9 files changed

+245
-34
lines changed

sdk-core/src/main/java/org/fisco/bcos/sdk/model/TransactionReceipt.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public void setGasUsed(String gasUsed) {
193193
}
194194

195195
public String getContractAddress() {
196-
if (!isWasm() && Objects.nonNull(contractAddress)) {
196+
if (!isWasm() && Objects.nonNull(contractAddress) && !contractAddress.isEmpty()) {
197197
return "0x" + contractAddress;
198198
}
199199

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/manager/AuthManager.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.List;
66
import org.fisco.bcos.sdk.client.Client;
77
import org.fisco.bcos.sdk.codec.ABICodecException;
8+
import org.fisco.bcos.sdk.codec.datatypes.NumericType;
9+
import org.fisco.bcos.sdk.codec.datatypes.Type;
810
import org.fisco.bcos.sdk.contract.auth.contracts.Committee;
911
import org.fisco.bcos.sdk.contract.auth.contracts.CommitteeManager;
1012
import org.fisco.bcos.sdk.contract.auth.contracts.ContractAuthPrecompiled;
@@ -116,6 +118,15 @@ public BigInteger setDeployAuthType(AuthType deployAuthType)
116118
return getProposal(transactionResponse);
117119
}
118120

121+
/**
122+
* get global deploy auth type
123+
*
124+
* @return deployAuthType
125+
*/
126+
public BigInteger getDeployAuthType() throws ContractException {
127+
return this.contractAuthPrecompiled.deployType();
128+
}
129+
119130
/**
120131
* submit a proposal of adding deploy contract auth for account, only governor can call it
121132
*
@@ -186,11 +197,17 @@ public BigInteger getProposal(TransactionResponse transactionResponse)
186197
if (transactionResponse == null) {
187198
throw new TransactionException("Decode transaction response error");
188199
}
189-
List<Object> valuesList = transactionResponse.getValuesList();
200+
if (transactionResponse.getTransactionReceipt().getStatus() != 0) {
201+
throw new TransactionException(
202+
transactionResponse.getReceiptMessages(),
203+
transactionResponse.getTransactionReceipt().getStatus());
204+
}
205+
List<Type> valuesList = transactionResponse.getResults();
190206
if (valuesList == null || valuesList.isEmpty()) {
191207
throw new TransactionException("Decode transaction response error");
192208
}
193-
return BigInteger.valueOf((long) valuesList.get(0));
209+
NumericType value = (NumericType) valuesList.get(0);
210+
return value.getValue();
194211
}
195212

196213
/**

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/CommitteeInfo.java

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,66 @@
11
package org.fisco.bcos.sdk.contract.auth.po;
22

33
import java.math.BigInteger;
4+
import java.util.ArrayList;
45
import java.util.List;
56
import org.fisco.bcos.sdk.codec.datatypes.generated.tuples.generated.Tuple4;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
69

710
public class CommitteeInfo {
8-
private List<String> governorList;
9-
private List<BigInteger> weightList;
11+
private final Logger logger = LoggerFactory.getLogger(CommitteeInfo.class);
12+
13+
class GovernorInfo {
14+
String governorAddress;
15+
BigInteger weight;
16+
17+
public GovernorInfo(String governorAddress, BigInteger weight) {
18+
this.governorAddress = governorAddress;
19+
this.weight = weight;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "GovernorInfo{"
25+
+ "governorAddress='"
26+
+ governorAddress
27+
+ '\''
28+
+ ", weight="
29+
+ weight
30+
+ '}';
31+
}
32+
}
33+
34+
private List<GovernorInfo> governorList = new ArrayList<>();
1035
private int participatesRate;
1136
private int winRate;
1237

1338
public CommitteeInfo fromTuple(
1439
Tuple4<BigInteger, BigInteger, List<String>, List<BigInteger>> tuple) {
15-
this.governorList = tuple.getValue3();
16-
this.weightList = tuple.getValue4();
40+
List<String> governorNameList = tuple.getValue3();
41+
List<BigInteger> weightList = tuple.getValue4();
42+
try {
43+
for (int i = 0; i < governorNameList.size(); i++) {
44+
this.governorList.add(new GovernorInfo(governorNameList.get(i), weightList.get(i)));
45+
}
46+
} catch (IndexOutOfBoundsException e) {
47+
logger.error(
48+
"Governor list size not fit with weight list, you should check committee info. e:",
49+
e);
50+
}
1751
this.participatesRate = tuple.getValue1().intValue();
1852
this.winRate = tuple.getValue2().intValue();
1953
return this;
2054
}
2155

22-
public List<String> getGovernorList() {
56+
public List<GovernorInfo> getGovernorList() {
2357
return governorList;
2458
}
2559

26-
public void setGovernorList(List<String> governorList) {
60+
public void setGovernorList(List<GovernorInfo> governorList) {
2761
this.governorList = governorList;
2862
}
2963

30-
public List<BigInteger> getWeightList() {
31-
return weightList;
32-
}
33-
34-
public void setWeightList(List<BigInteger> weightList) {
35-
this.weightList = weightList;
36-
}
37-
3864
public int getParticipatesRate() {
3965
return participatesRate;
4066
}
@@ -56,8 +82,6 @@ public String toString() {
5682
return "CommitteeInfo{"
5783
+ "governorList="
5884
+ governorList
59-
+ ", weightList="
60-
+ weightList
6185
+ ", participatesRate="
6286
+ participatesRate
6387
+ ", winRate="

sdk-transaction/src/main/java/org/fisco/bcos/sdk/contract/auth/po/ProposalInfo.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.fisco.bcos.sdk.codec.datatypes.generated.tuples.generated.Tuple7;
66

77
public class ProposalInfo {
8-
private String id;
8+
private String resourceId;
99
private String proposer;
1010
private int proposalType;
1111
private long blockNumberInterval;
@@ -16,7 +16,7 @@ public class ProposalInfo {
1616
public ProposalInfo fromTuple(
1717
Tuple7<String, String, BigInteger, BigInteger, BigInteger, List<String>, List<String>>
1818
tuple7) {
19-
this.id = tuple7.getValue1();
19+
this.resourceId = tuple7.getValue1();
2020
this.proposer = tuple7.getValue2();
2121
this.proposalType = tuple7.getValue3().intValue();
2222
this.blockNumberInterval = tuple7.getValue4().longValue();
@@ -26,12 +26,12 @@ public ProposalInfo fromTuple(
2626
return this;
2727
}
2828

29-
public String getId() {
30-
return id;
29+
public String getResourceId() {
30+
return resourceId;
3131
}
3232

33-
public void setId(String id) {
34-
this.id = id;
33+
public void setResourceId(String resourceId) {
34+
this.resourceId = resourceId;
3535
}
3636

3737
public String getProposer() {
@@ -85,18 +85,18 @@ public void setAgainstVoters(List<String> againstVoters) {
8585
@Override
8686
public String toString() {
8787
return "ProposalInfo{"
88-
+ "id='"
89-
+ id
88+
+ "resourceId='"
89+
+ resourceId
9090
+ '\''
9191
+ ", proposer='"
9292
+ proposer
9393
+ '\''
9494
+ ", proposalType="
95-
+ proposalType
95+
+ ProposalType.fromInt(proposalType).getValue()
9696
+ ", blockNumberInterval="
9797
+ blockNumberInterval
9898
+ ", status="
99-
+ status
99+
+ ProposalStatus.fromInt(status).getValue()
100100
+ ", agreeVoters="
101101
+ agreeVoters
102102
+ ", againstVoters="
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.fisco.bcos.sdk.contract.auth.po;
2+
3+
public enum ProposalStatus {
4+
NOT_ENOUGH_VOTE("notEnoughVotes"),
5+
SUCCESS("success"),
6+
FAILED("failed"),
7+
REVOKE("revoke"),
8+
UNKNOWN("unknown");
9+
10+
private final String value;
11+
12+
ProposalStatus(String value) {
13+
this.value = value;
14+
}
15+
16+
public final String getValue() {
17+
return value;
18+
}
19+
20+
static ProposalStatus fromInt(int status) {
21+
switch (status) {
22+
case 1:
23+
return NOT_ENOUGH_VOTE;
24+
case 2:
25+
return SUCCESS;
26+
case 3:
27+
return FAILED;
28+
case 4:
29+
return REVOKE;
30+
default:
31+
return UNKNOWN;
32+
}
33+
}
34+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package org.fisco.bcos.sdk.contract.auth.po;
2+
3+
public enum ProposalType {
4+
SET_WEIGHT("setWeight"),
5+
SET_RATE("setRate"),
6+
SET_DEPLOY_AUTH_TYPE("setDeployAuthType"),
7+
MODIFY_DEPLOY_AUTH("modifyDeployAuth"),
8+
RESET_ADMIN("resetAdmin"),
9+
UNKNOWN("unknown");
10+
11+
private final String value;
12+
13+
ProposalType(String value) {
14+
this.value = value;
15+
}
16+
17+
public final String getValue() {
18+
return value;
19+
}
20+
21+
static ProposalType fromInt(int type) {
22+
switch (type) {
23+
case 11:
24+
return ProposalType.SET_WEIGHT;
25+
case 12:
26+
return ProposalType.SET_RATE;
27+
case 21:
28+
return ProposalType.SET_DEPLOY_AUTH_TYPE;
29+
case 22:
30+
return ProposalType.MODIFY_DEPLOY_AUTH;
31+
case 31:
32+
return ProposalType.RESET_ADMIN;
33+
default:
34+
return ProposalType.UNKNOWN;
35+
}
36+
}
37+
}

sdk-transaction/src/main/java/org/fisco/bcos/sdk/transaction/codec/decode/ReceiptParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static RetCode parseTransactionReceipt(TransactionReceipt receipt)
4040
throws ContractException {
4141
RetCode retCode;
4242
try {
43-
Integer status = receipt.getStatus();
43+
int status = receipt.getStatus();
4444
if (status != 0) {
4545
retCode = TransactionReceiptStatus.getStatusMessage(status, receipt.getMessage());
4646
Tuple2<Boolean, String> errorOutput =

sdk-transaction/src/main/java/org/fisco/bcos/sdk/transaction/model/exception/TransactionException.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
public class TransactionException extends Exception {
77
private static final long serialVersionUID = -2204228001512046284L;
88
private Optional<String> transactionHash = Optional.empty();
9-
private String status;
9+
private int status;
1010
private BigInteger gasUsed;
1111

12-
public String getStatus() {
12+
public int getStatus() {
1313
return status;
1414
}
1515

16-
public void setStatus(String status) {
16+
public void setStatus(int status) {
1717
this.status = status;
1818
}
1919

@@ -38,8 +38,13 @@ public TransactionException(String message, String transactionHash) {
3838
this.transactionHash = Optional.ofNullable(transactionHash);
3939
}
4040

41+
public TransactionException(String message, int status) {
42+
super(message);
43+
this.status = status;
44+
}
45+
4146
public TransactionException(
42-
String message, String status, BigInteger gasUsed, String transactionHash) {
47+
String message, int status, BigInteger gasUsed, String transactionHash) {
4348
super(message);
4449
this.status = status;
4550
this.gasUsed = gasUsed;

0 commit comments

Comments
 (0)