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
19 changes: 12 additions & 7 deletions src/main/java/com/okexchain/msg/common/Data2Sign.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.gson.annotations.SerializedName;
import com.okexchain.msg.tx.BoardcastTx;
import com.okexchain.utils.Utils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
Expand Down Expand Up @@ -88,16 +89,20 @@ public void setData(Fee fee) {
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("account_number", accountNumber)
.append("chain_id", chainId)
.append("fee", fee)
.append("memo", memo)
.append("msgs", msgs)
.append("sequence", sequence)
.toString();
.append("account_number", accountNumber)
.append("chain_id", chainId)
.append("fee", fee)
.append("memo", memo)
.append("msgs", msgs)
.append("sequence", sequence)
.toString();
}

public String toJson() {
return Utils.serializer.toJson(this);
}

public static Data2Sign fromJson(String json) {
return Utils.serializer.fromJson(json, Data2Sign.class);
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/okexchain/msg/tx/UnsignedTx.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.okexchain.msg.common.Signature;
import com.okexchain.msg.common.TxValue;
import com.okexchain.msg.common.Data2Sign;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -30,6 +31,7 @@ public BoardcastTx signed(Signature signature) {
boardcastTx.getTx().setSignatures(signatureList);
return boardcastTx;
}

public BoardcastValue sign4gentx(Signature signature) {
List<Signature> signatureList = new ArrayList<>();
signatureList.add(signature);
Expand All @@ -40,4 +42,18 @@ public BoardcastValue sign4gentx(Signature signature) {
public String toString() {
return unsignedTxJson;
}


public static BoardcastTx genBroadcastTx(String unsignedTxStr, Signature signature) {
Data2Sign data = Data2Sign.fromJson(unsignedTxStr);

TxValue txValue = new TxValue();
txValue.setMsgs(data.getMsgs());
txValue.setFee(data.getFee());
txValue.setMemo(data.getMemo());

UnsignedTx unsignedTx = new UnsignedTx(txValue, unsignedTxStr);

return unsignedTx.signed(signature);
}
}
13 changes: 8 additions & 5 deletions src/main/java/com/okexchain/sample/ColdSign.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@ public static void main(String[] args) {
PrivateKey key = new PrivateKey("8145bfb1d3acc216c54490952c994d5e3bce09dd65ae73d0c79f892284f721e7");

MsgSend msg = new MsgSend();
msg.init(key.getAddress(), key.getPubKey());
// msg.init(key.getAddress(), key.getPubKey());

// or init by account number and sequence number
// msg.init(key.getPubKey(), "0", "10");
msg.init(key.getPubKey(), "0", "10");

Message messages = msg.produceSendMsg(
"okt",
"6.00000000",
"okexchain1v853tq96n9ghvyxlvqyxyj97589clccrufrkz9");

try {
UnsignedTx unsignedTx = msg.getUnsignedTx(messages,"0.01000000", "200000", "okexchain transfer!");
UnsignedTx unsignedTx = msg.getUnsignedTx(messages, "0.01000000", "200000", "okexchain transfer!");

Signature signature = MsgBase.signTx(unsignedTx.toString(), key.getPriKey());

BoardcastTx signedTx = unsignedTx.signed(signature);
// BoardcastTx signedTx = unsignedTx.signed(signature);
BoardcastTx signedTx = UnsignedTx.genBroadcastTx(unsignedTx.toString(), signature);
System.out.println(signedTx.toJson());

MsgBase.boardcast(signedTx.toJson(), EnvInstance.getEnv().GetRestServerUrl());

// MsgBase.boardcast(signedTx.toJson(), EnvInstance.getEnv().GetRestServerUrl());

} catch (Exception e) {
System.out.println("serialize transfer msg failed");
Expand Down