Skip to content

Commit 21f57a7

Browse files
zhshy11shaoyun.zhan@okcoin.com
andauthored
Merge PR: add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list (#92)
* add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 : rm useless code * add update-contract-deployment-whitelist and submit-proposal update-contract-blocked-list , modify verison to v0.16.6 : add sample Co-authored-by: shaoyun.zhan@okcoin.com <shaoyun.zhan@okcoin.com>
1 parent 8e05875 commit 21f57a7

6 files changed

Lines changed: 329 additions & 4 deletions

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.okexchain</groupId>
88
<artifactId>okexchain-java-sdk</artifactId>
9-
<version>0.16.5</version>
9+
<version>0.16.6</version>
1010

1111
<name>okexchain-java-sdk</name>
1212
<!-- FIXME change it to the project's website -->
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.okexchain.msg.gov;
2+
3+
import com.okexchain.msg.MsgBase;
4+
import com.okexchain.msg.common.Message;
5+
import com.okexchain.msg.common.Token;
6+
import com.okexchain.utils.Utils;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class MsgContractBlockedListProposal extends MsgBase {
12+
13+
public MsgContractBlockedListProposal() {
14+
setMsgType("okexchain/gov/MsgSubmitProposal");
15+
}
16+
17+
18+
public Message produceContractDeploymentWhitelistProposal(
19+
String title,
20+
String description,
21+
String[] contractAddresses,
22+
boolean isAdded,
23+
String denom,
24+
String amountDeposit
25+
) {
26+
27+
// proposal
28+
MsgContractBlockedListProposalValue proposal = new MsgContractBlockedListProposalValue();
29+
proposal.setTitle(title);
30+
proposal.setDescription(description);
31+
proposal.setContractAddresses(contractAddresses);
32+
33+
proposal.setIsAdded(isAdded);
34+
35+
return produceContractDeploymentWhitelistProposal(proposal,denom, amountDeposit);
36+
}
37+
38+
39+
public Message produceContractDeploymentWhitelistProposal(
40+
MsgContractBlockedListProposalValue proposal,
41+
String denom,
42+
String amountDeposit
43+
) {
44+
45+
// content
46+
Content<MsgContractBlockedListProposalValue> content = new Content<>();
47+
content.setType("okexchain/evm/ManageContractBlockedListProposal");
48+
content.setValue(proposal);
49+
50+
// submit
51+
List<Token> depositList = new ArrayList<>();
52+
Token deposit = new Token();
53+
deposit.setDenom(denom);
54+
deposit.setAmount(Utils.NewDecString(amountDeposit));
55+
depositList.add(deposit);
56+
57+
MsgSubmitProposalValue<Content<MsgContractBlockedListProposalValue>> value = new MsgSubmitProposalValue<>();
58+
value.setContent(content);
59+
value.setInitialDeposit(depositList);
60+
value.setProposer(this.address);
61+
62+
Message<MsgSubmitProposalValue<Content<MsgContractBlockedListProposalValue>>> msg = new Message<>();
63+
msg.setType(msgType);
64+
msg.setValue(value);
65+
return msg;
66+
}
67+
68+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.okexchain.msg.gov;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
import com.google.gson.annotations.SerializedName;
7+
import org.apache.commons.lang3.builder.ToStringBuilder;
8+
import org.apache.commons.lang3.builder.ToStringStyle;
9+
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
@JsonPropertyOrder(alphabetic = true)
12+
public class MsgContractBlockedListProposalValue {
13+
14+
@JsonProperty("title")
15+
@SerializedName("title")
16+
private String title;
17+
18+
19+
@JsonProperty("description")
20+
@SerializedName("description")
21+
private String description;
22+
23+
@JsonProperty("contract_addresses")
24+
@SerializedName("contract_addresses")
25+
private String [] contractAddresses;
26+
27+
28+
@JsonProperty("is_added")
29+
@SerializedName("is_added")
30+
private boolean isAdded;
31+
32+
33+
@Override
34+
public String toString() {
35+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
36+
.append("title", title)
37+
.append("description", description)
38+
.append("contract_addresses", contractAddresses)
39+
.append("isAdded", isAdded)
40+
.toString();
41+
}
42+
43+
44+
public void setTitle(String title) {
45+
this.title = title;
46+
}
47+
48+
49+
public void setDescription(String description) {
50+
this.description = description;
51+
}
52+
53+
public void setContractAddresses(String[] contractAddresses) {
54+
this.contractAddresses = contractAddresses;
55+
}
56+
57+
public void setIsAdded(boolean isAdded) {
58+
this.isAdded = isAdded;
59+
}
60+
61+
62+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.okexchain.msg.gov;
2+
3+
import com.okexchain.msg.MsgBase;
4+
import com.okexchain.msg.common.Message;
5+
import com.okexchain.msg.common.Token;
6+
import com.okexchain.utils.Utils;
7+
8+
import java.util.ArrayList;
9+
import java.util.List;
10+
11+
public class MsgContractDeploymentWhitelistProposal extends MsgBase {
12+
13+
public MsgContractDeploymentWhitelistProposal() {
14+
setMsgType("okexchain/gov/MsgSubmitProposal");
15+
}
16+
17+
18+
public Message produceContractDeploymentWhitelistProposal(
19+
String title,
20+
String description,
21+
String[] distributorAddresses,
22+
boolean isAdded,
23+
String denom,
24+
String amountDeposit
25+
) {
26+
27+
// proposal
28+
MsgContractDeploymentWhitelistProposalValue proposal = new MsgContractDeploymentWhitelistProposalValue();
29+
proposal.setTitle(title);
30+
proposal.setDescription(description);
31+
proposal.setDistributorAddresses(distributorAddresses);
32+
proposal.setIsAdded(isAdded);
33+
34+
return produceContractDeploymentWhitelistProposal(proposal,denom, amountDeposit);
35+
}
36+
37+
38+
public Message produceContractDeploymentWhitelistProposal(
39+
MsgContractDeploymentWhitelistProposalValue proposal,
40+
String denom,
41+
String amountDeposit
42+
) {
43+
44+
// content
45+
Content<MsgContractDeploymentWhitelistProposalValue> content = new Content<>();
46+
content.setType("okexchain/evm/ManageContractDeploymentWhitelistProposal");
47+
content.setValue(proposal);
48+
49+
// submit
50+
List<Token> depositList = new ArrayList<>();
51+
Token deposit = new Token();
52+
deposit.setDenom(denom);
53+
deposit.setAmount(Utils.NewDecString(amountDeposit));
54+
depositList.add(deposit);
55+
56+
MsgSubmitProposalValue<Content<MsgContractDeploymentWhitelistProposalValue>> value = new MsgSubmitProposalValue<>();
57+
value.setContent(content);
58+
value.setInitialDeposit(depositList);
59+
value.setProposer(this.address);
60+
61+
Message<MsgSubmitProposalValue<Content<MsgContractDeploymentWhitelistProposalValue>>> msg = new Message<>();
62+
msg.setType(msgType);
63+
msg.setValue(value);
64+
return msg;
65+
}
66+
67+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.okexchain.msg.gov;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
6+
import com.google.gson.annotations.SerializedName;
7+
import org.apache.commons.lang3.builder.ToStringBuilder;
8+
import org.apache.commons.lang3.builder.ToStringStyle;
9+
10+
@JsonIgnoreProperties(ignoreUnknown = true)
11+
@JsonPropertyOrder(alphabetic = true)
12+
public class MsgContractDeploymentWhitelistProposalValue {
13+
14+
@JsonProperty("title")
15+
@SerializedName("title")
16+
private String title;
17+
18+
19+
@JsonProperty("description")
20+
@SerializedName("description")
21+
private String description;
22+
23+
@JsonProperty("distributor_addresses")
24+
@SerializedName("distributor_addresses")
25+
private String[] distributorAddresses;
26+
27+
28+
@JsonProperty("is_added")
29+
@SerializedName("is_added")
30+
private boolean isAdded;
31+
32+
33+
@Override
34+
public String toString() {
35+
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
36+
.append("title", title)
37+
.append("description", description)
38+
.append("distributorAddresses", distributorAddresses)
39+
.append("isAdded", isAdded)
40+
.toString();
41+
}
42+
43+
44+
45+
public void setTitle(String title) {
46+
this.title = title;
47+
}
48+
49+
50+
public void setDescription(String description) {
51+
this.description = description;
52+
}
53+
54+
55+
public void setDistributorAddresses(String[] distributorAddresses) {
56+
this.distributorAddresses = distributorAddresses;
57+
}
58+
59+
public void setIsAdded(boolean isAdded) {
60+
this.isAdded = isAdded;
61+
}
62+
63+
}

src/main/java/com/okexchain/sample/Gov.java

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.okexchain.sample;
22

3+
import com.alibaba.fastjson.JSONObject;
34
import com.fasterxml.jackson.core.JsonProcessingException;
45
import com.okexchain.env.EnvBase;
56
import com.okexchain.env.EnvInstance;
67
import com.okexchain.msg.MsgBase;
7-
import com.okexchain.msg.gov.MsgDeListProposal;
8-
import com.okexchain.msg.gov.MsgParameterChangeProposal;
9-
import com.okexchain.msg.gov.MsgVote;
108
import com.okexchain.msg.common.Message;
119
import com.okexchain.msg.common.Signature;
10+
import com.okexchain.msg.gov.*;
1211
import com.okexchain.msg.tx.BroadcastTx;
1312
import com.okexchain.msg.tx.UnsignedTx;
1413
import com.okexchain.utils.crypto.PrivateKey;
@@ -21,6 +20,8 @@ public static void main(String[] args) throws JsonProcessingException {
2120
// testParameterChangeProposal();
2221
// testDeListProposal();
2322
testVote();
23+
testContractBlockedListProposal();
24+
testContractBlockedListProposalValue();
2425
}
2526

2627
static void testParameterChangeProposal() throws JsonProcessingException {
@@ -103,4 +104,68 @@ static void testVote() {
103104
System.out.println("serialize transfer msg failed");
104105
}
105106
}
107+
108+
public static void testContractBlockedListProposal() {
109+
EnvBase env = EnvInstance.getEnv();
110+
env.setChainID("okexchainevm-8");
111+
EnvInstance.getEnv().setRestServerUrl("http://localhost:8545");
112+
env.setDenom("okt");
113+
114+
// {"codespace":"sdk","code":4,"gas_used":"67065","gas_wanted":"2000000","raw_log":"unauthorized: signature verification failed; verify correct account sequence and chain-id, sign msg:{\"account_number\":\"2\",\"chain_id\":\"okexchainevm-8\",\"fee\":{\"amount\":[{\"amount\":\"0.030000000000000000\",\"denom\":\"okt\"}],\"gas\":\"2000000\"},\"memo\":\"\",\"msgs\":[{\"type\":\"okexchain/gov/MsgSubmitProposal\",\"value\":{\"content\":{\"type\":\"okexchain/evm/ManageContractBlockedListProposal\",\"value\":{\"contract_addresses\":[\"okexchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0\",\"okexchain1qj5c07sm6jetjz8f509qtrxgh4psxkv32x0qas\"],\"description\":\"String description\",\"is_added\":true,\"title\":\"String title\"}},\"initial_deposit\":[{\"amount\":\"100.000000000000000000\",\"denom\":\"okt\"}],\"proposer\":\"okexchain1qpel9c5wlrc30efaskqfgzrda7h3sd745rcxeh\"}}],\"sequence\":\"9\"}","height":"0","txhash":"8240A3B7734DEB2878BD629CEB2426E04E1D4E96C3A3E7E87CB1933DD2FD0A49"}
115+
116+
117+
MsgContractBlockedListProposal msg = new MsgContractBlockedListProposal();
118+
msg.init(new PrivateKey("75dee45fc7b2dd69ec22dc6a825a2d982aee4ca2edd42c53ced0912173c4a788".toUpperCase()));
119+
120+
String[] contractAddresses = new String[]{"okexchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0","okexchain1qj5c07sm6jetjz8f509qtrxgh4psxkv32x0qas"};
121+
122+
Message messages = msg.produceContractDeploymentWhitelistProposal(
123+
"String title",
124+
"String description",
125+
contractAddresses,
126+
true,
127+
"okt",
128+
"100.000000000000000000"
129+
);
130+
131+
JSONObject res = msg.submit(messages, "0.03", "2000000", "");
132+
System.out.println(res.toJSONString());
133+
try {
134+
boolean succeed = msg.isTxSucceed(res);
135+
System.out.println("tx " + (succeed ? "succeed": "failed"));
136+
} catch (Exception e) {
137+
System.out.println(e.toString());
138+
}
139+
}
140+
141+
public static void testContractBlockedListProposalValue() {
142+
EnvBase env = EnvInstance.getEnv();
143+
env.setChainID("okexchainevm-8");
144+
EnvInstance.getEnv().setRestServerUrl("http://localhost:8545");
145+
env.setDenom("okt");
146+
147+
148+
MsgContractDeploymentWhitelistProposal msg = new MsgContractDeploymentWhitelistProposal();
149+
msg.init(new PrivateKey("75dee45fc7b2dd69ec22dc6a825a2d982aee4ca2edd42c53ced0912173c4a788".toUpperCase()));
150+
151+
String[] distributorAddresses = new String[]{"okexchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0","okexchain1qj5c07sm6jetjz8f509qtrxgh4psxkv32x0qas"};
152+
153+
Message messages = msg.produceContractDeploymentWhitelistProposal(
154+
"String title",
155+
"String description",
156+
distributorAddresses,
157+
true,
158+
"okt",
159+
"100.000000000000000000"
160+
);
161+
162+
JSONObject res = msg.submit(messages, "0.03", "2000000", "");
163+
System.out.println(res.toJSONString());
164+
try {
165+
boolean succeed = msg.isTxSucceed(res);
166+
System.out.println("tx " + (succeed ? "succeed": "failed"));
167+
} catch (Exception e) {
168+
System.out.println(e.toString());
169+
}
170+
}
106171
}

0 commit comments

Comments
 (0)