Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.okexchain</groupId>
<artifactId>okexchain-java-sdk</artifactId>
<version>0.16.5</version>
<version>0.16.6</version>

<name>okexchain-java-sdk</name>
<!-- FIXME change it to the project's website -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.okexchain.msg.gov;

import com.okexchain.msg.MsgBase;
import com.okexchain.msg.common.Message;
import com.okexchain.msg.common.Token;
import com.okexchain.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class MsgContractBlockedListProposal extends MsgBase {

public MsgContractBlockedListProposal() {
setMsgType("okexchain/gov/MsgSubmitProposal");
}


public Message produceContractDeploymentWhitelistProposal(
String title,
String description,
String[] contractAddresses,
boolean isAdded,
String denom,
String amountDeposit
) {

// proposal
MsgContractBlockedListProposalValue proposal = new MsgContractBlockedListProposalValue();
proposal.setTitle(title);
proposal.setDescription(description);
proposal.setContractAddresses(contractAddresses);

proposal.setIsAdded(isAdded);

return produceContractDeploymentWhitelistProposal(proposal,denom, amountDeposit);
}


public Message produceContractDeploymentWhitelistProposal(
MsgContractBlockedListProposalValue proposal,
String denom,
String amountDeposit
) {

// content
Content<MsgContractBlockedListProposalValue> content = new Content<>();
content.setType("okexchain/evm/ManageContractBlockedListProposal");
content.setValue(proposal);

// submit
List<Token> depositList = new ArrayList<>();
Token deposit = new Token();
deposit.setDenom(denom);
deposit.setAmount(Utils.NewDecString(amountDeposit));
depositList.add(deposit);

MsgSubmitProposalValue<Content<MsgContractBlockedListProposalValue>> value = new MsgSubmitProposalValue<>();
value.setContent(content);
value.setInitialDeposit(depositList);
value.setProposer(this.address);

Message<MsgSubmitProposalValue<Content<MsgContractBlockedListProposalValue>>> msg = new Message<>();
msg.setType(msgType);
msg.setValue(value);
return msg;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.okexchain.msg.gov;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder(alphabetic = true)
public class MsgContractBlockedListProposalValue {

@JsonProperty("title")
@SerializedName("title")
private String title;


@JsonProperty("description")
@SerializedName("description")
private String description;

@JsonProperty("contract_addresses")
@SerializedName("contract_addresses")
private String [] contractAddresses;


@JsonProperty("is_added")
@SerializedName("is_added")
private boolean isAdded;


@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("title", title)
.append("description", description)
.append("contract_addresses", contractAddresses)
.append("isAdded", isAdded)
.toString();
}


public void setTitle(String title) {
this.title = title;
}


public void setDescription(String description) {
this.description = description;
}

public void setContractAddresses(String[] contractAddresses) {
this.contractAddresses = contractAddresses;
}

public void setIsAdded(boolean isAdded) {
this.isAdded = isAdded;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.okexchain.msg.gov;

import com.okexchain.msg.MsgBase;
import com.okexchain.msg.common.Message;
import com.okexchain.msg.common.Token;
import com.okexchain.utils.Utils;

import java.util.ArrayList;
import java.util.List;

public class MsgContractDeploymentWhitelistProposal extends MsgBase {

public MsgContractDeploymentWhitelistProposal() {
setMsgType("okexchain/gov/MsgSubmitProposal");
}


public Message produceContractDeploymentWhitelistProposal(
String title,
String description,
String[] distributorAddresses,
boolean isAdded,
String denom,
String amountDeposit
) {

// proposal
MsgContractDeploymentWhitelistProposalValue proposal = new MsgContractDeploymentWhitelistProposalValue();
proposal.setTitle(title);
proposal.setDescription(description);
proposal.setDistributorAddresses(distributorAddresses);
proposal.setIsAdded(isAdded);

return produceContractDeploymentWhitelistProposal(proposal,denom, amountDeposit);
}


public Message produceContractDeploymentWhitelistProposal(
MsgContractDeploymentWhitelistProposalValue proposal,
String denom,
String amountDeposit
) {

// content
Content<MsgContractDeploymentWhitelistProposalValue> content = new Content<>();
content.setType("okexchain/evm/ManageContractDeploymentWhitelistProposal");
content.setValue(proposal);

// submit
List<Token> depositList = new ArrayList<>();
Token deposit = new Token();
deposit.setDenom(denom);
deposit.setAmount(Utils.NewDecString(amountDeposit));
depositList.add(deposit);

MsgSubmitProposalValue<Content<MsgContractDeploymentWhitelistProposalValue>> value = new MsgSubmitProposalValue<>();
value.setContent(content);
value.setInitialDeposit(depositList);
value.setProposer(this.address);

Message<MsgSubmitProposalValue<Content<MsgContractDeploymentWhitelistProposalValue>>> msg = new Message<>();
msg.setType(msgType);
msg.setValue(value);
return msg;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.okexchain.msg.gov;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.gson.annotations.SerializedName;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonPropertyOrder(alphabetic = true)
public class MsgContractDeploymentWhitelistProposalValue {

@JsonProperty("title")
@SerializedName("title")
private String title;


@JsonProperty("description")
@SerializedName("description")
private String description;

@JsonProperty("distributor_addresses")
@SerializedName("distributor_addresses")
private String[] distributorAddresses;


@JsonProperty("is_added")
@SerializedName("is_added")
private boolean isAdded;


@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("title", title)
.append("description", description)
.append("distributorAddresses", distributorAddresses)
.append("isAdded", isAdded)
.toString();
}



public void setTitle(String title) {
this.title = title;
}


public void setDescription(String description) {
this.description = description;
}


public void setDistributorAddresses(String[] distributorAddresses) {
this.distributorAddresses = distributorAddresses;
}

public void setIsAdded(boolean isAdded) {
this.isAdded = isAdded;
}

}
71 changes: 68 additions & 3 deletions src/main/java/com/okexchain/sample/Gov.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.okexchain.sample;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.okexchain.env.EnvBase;
import com.okexchain.env.EnvInstance;
import com.okexchain.msg.MsgBase;
import com.okexchain.msg.gov.MsgDeListProposal;
import com.okexchain.msg.gov.MsgParameterChangeProposal;
import com.okexchain.msg.gov.MsgVote;
import com.okexchain.msg.common.Message;
import com.okexchain.msg.common.Signature;
import com.okexchain.msg.gov.*;
import com.okexchain.msg.tx.BroadcastTx;
import com.okexchain.msg.tx.UnsignedTx;
import com.okexchain.utils.crypto.PrivateKey;
Expand All @@ -21,6 +20,8 @@ public static void main(String[] args) throws JsonProcessingException {
// testParameterChangeProposal();
// testDeListProposal();
testVote();
testContractBlockedListProposal();
testContractBlockedListProposalValue();
}

static void testParameterChangeProposal() throws JsonProcessingException {
Expand Down Expand Up @@ -103,4 +104,68 @@ static void testVote() {
System.out.println("serialize transfer msg failed");
}
}

public static void testContractBlockedListProposal() {
EnvBase env = EnvInstance.getEnv();
env.setChainID("okexchainevm-8");
EnvInstance.getEnv().setRestServerUrl("http://localhost:8545");
env.setDenom("okt");

// {"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"}


MsgContractBlockedListProposal msg = new MsgContractBlockedListProposal();
msg.init(new PrivateKey("75dee45fc7b2dd69ec22dc6a825a2d982aee4ca2edd42c53ced0912173c4a788".toUpperCase()));

String[] contractAddresses = new String[]{"okexchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0","okexchain1qj5c07sm6jetjz8f509qtrxgh4psxkv32x0qas"};

Message messages = msg.produceContractDeploymentWhitelistProposal(
"String title",
"String description",
contractAddresses,
true,
"okt",
"100.000000000000000000"
);

JSONObject res = msg.submit(messages, "0.03", "2000000", "");
System.out.println(res.toJSONString());
try {
boolean succeed = msg.isTxSucceed(res);
System.out.println("tx " + (succeed ? "succeed": "failed"));
} catch (Exception e) {
System.out.println(e.toString());
}
}

public static void testContractBlockedListProposalValue() {
EnvBase env = EnvInstance.getEnv();
env.setChainID("okexchainevm-8");
EnvInstance.getEnv().setRestServerUrl("http://localhost:8545");
env.setDenom("okt");


MsgContractDeploymentWhitelistProposal msg = new MsgContractDeploymentWhitelistProposal();
msg.init(new PrivateKey("75dee45fc7b2dd69ec22dc6a825a2d982aee4ca2edd42c53ced0912173c4a788".toUpperCase()));

String[] distributorAddresses = new String[]{"okexchain1hw4r48aww06ldrfeuq2v438ujnl6alsz0685a0","okexchain1qj5c07sm6jetjz8f509qtrxgh4psxkv32x0qas"};

Message messages = msg.produceContractDeploymentWhitelistProposal(
"String title",
"String description",
distributorAddresses,
true,
"okt",
"100.000000000000000000"
);

JSONObject res = msg.submit(messages, "0.03", "2000000", "");
System.out.println(res.toJSONString());
try {
boolean succeed = msg.isTxSucceed(res);
System.out.println("tx " + (succeed ? "succeed": "failed"));
} catch (Exception e) {
System.out.println(e.toString());
}
}
}