Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update sidechain invoke #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions src/main/java/com/github/ontio/OntSdk.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class OntSdk {
public SignatureScheme defaultSignScheme = SignatureScheme.SHA256WITHECDSA;
public long DEFAULT_GAS_LIMIT = 20000;
public long DEFAULT_DEPLOY_GAS_LIMIT = 30000000;
public long sideChainId;
public static synchronized OntSdk getInstance(){
if(instance == null){
instance = new OntSdk();
Expand Down Expand Up @@ -157,6 +158,9 @@ public ConnectMgr getSideChainConnectMgr() {
public void setSideChainRpc(String url) {
this.sideChainConnectMgr = new ConnectMgr(url, "rpc");
}
public void setSideChainId(long sideChainId) {
this.sideChainId = sideChainId;
}
public void setSideChainRest(String url) {
this.sideChainConnectMgr = new ConnectMgr(url, "restful");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import com.github.ontio.common.Address;

public class InflationParam {
public String sideChainId;
public long sideChainId;
public Address address;
public long depositAdd;
public long ongPoolAdd;
public InflationParam(String sideChainId, Address address, long depositAdd, long ongPoolAdd){
public InflationParam(long sideChainId, Address address, long depositAdd, long ongPoolAdd){
this.sideChainId = sideChainId;
this.address = address;
this.depositAdd = depositAdd;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
public class NodeToSideChainParams implements Serializable {
public String peerPubkey;
public Address address;
public String sideChainId;
public long sideChainId;
public NodeToSideChainParams(){}
public NodeToSideChainParams(String peerPubkey, Address address, String sideChainId){
public NodeToSideChainParams(String peerPubkey, Address address, long sideChainId){
this.peerPubkey = peerPubkey;
this.address = address;
this.sideChainId = sideChainId;
Expand All @@ -23,7 +23,7 @@ public NodeToSideChainParams(String peerPubkey, Address address, String sideChai
public void deserialize(BinaryReader reader) throws IOException {
this.peerPubkey = reader.readVarString();
this.address = utils.readAddress(reader);
this.sideChainId = reader.readVarString();
this.sideChainId = reader.readLong();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import com.github.ontio.common.Address;

public class QuitSideChainParam {
public String sideChainID;
public long sideChainID;
public Address address;
public QuitSideChainParam(String sideChainID, Address address){
public QuitSideChainParam(long sideChainID, Address address){
this.sideChainID = sideChainID;
this.address = address;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
import com.github.ontio.common.Address;

public class RegisterSideChainParam {
public String sideChainID;
public long sideChainID;
public Address address;
public int ratio;
public long deposit;
public long ongPool;
public byte[] genesisBlock;
public byte[] caller;
public int keyNo;
public RegisterSideChainParam(String sideChainID, Address address, int ratio, long deposit, long ongPool, byte[] caller, int keyNo){
public RegisterSideChainParam(long sideChainID, Address address, int ratio, long deposit, long ongPool,byte[] genesisBlock, byte[] caller, int keyNo){
this.sideChainID = sideChainID;
this.address = address;
this.ratio = ratio;
this.deposit = deposit;
this.ongPool = ongPool;
this.genesisBlock = genesisBlock;
this.caller = caller;
this.keyNo = keyNo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.alibaba.fastjson.JSON;
import com.github.ontio.common.Address;
import com.github.ontio.common.Helper;
import com.github.ontio.io.BinaryReader;
import com.github.ontio.io.BinaryWriter;
import com.github.ontio.io.Serializable;
Expand All @@ -11,18 +12,19 @@
import java.util.Map;

public class SideChain implements Serializable {
public String sideChainId;
public long sideChainId;
public Address address;
public long ratio;
public long deposit;
public long ongNum;
public long ongPool;
public byte status;
public byte[] genesisBlock;

public SideChain(){}
@Override
public void deserialize(BinaryReader reader) throws IOException {
this.sideChainId = reader.readVarString();
this.sideChainId = reader.readLong();
try {
this.address = reader.readSerializable(Address.class);
} catch (InstantiationException e) {
Expand All @@ -35,6 +37,7 @@ public void deserialize(BinaryReader reader) throws IOException {
this.ongNum = reader.readLong();
this.ongPool = reader.readLong();
this.status = reader.readByte();
this.genesisBlock = reader.readVarBytes();
}

@Override
Expand All @@ -50,6 +53,7 @@ public String toJson(){
map.put("ongNum", this.ongNum);
map.put("ongPool", this.ongPool);
map.put("status", this.status);
map.put("genesisBlock", Helper.toHexString(genesisBlock));
return JSON.toJSONString(map);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
import java.util.Map;

public class SwapParam {
public String sideChainId;
public long sideChainId;
public Address address;
public long ongXAccount;
public SwapParam(String sideChainId, Address address, long ongXAccount){
public SwapParam(long sideChainId, Address address, long ongXAccount){
this.sideChainId = sideChainId;
this.address = address;
this.ongXAccount = ongXAccount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface IConnector {
int getBlockHeight() throws ConnectorException, IOException;
Block getBlock(int height) throws ConnectorException, IOException;
Block getBlock(String hash) throws ConnectorException, IOException ;
String getBlockBytes(int height) throws ConnectorException, IOException ;
String getBlockBytes(String hash) throws ConnectorException, IOException ;
Object getBlockJson(int height) throws ConnectorException, IOException;
Object getBlockJson(String hash) throws ConnectorException, IOException;

Expand All @@ -54,5 +56,5 @@ public interface IConnector {
String getVersion() throws ConnectorException, IOException;
String getGrantOng(String address) throws ConnectorException, IOException;
int getNetworkId() throws ConnectorException, IOException;
String getSideChainData(String sideChainID) throws ConnectorException, IOException;
String getSideChainData(int sideChainID) throws ConnectorException, IOException;
}
21 changes: 20 additions & 1 deletion src/main/java/com/github/ontio/network/rest/RestClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ public Block getBlock(String hash) throws RestfulException {
throw new RestfulException(ErrorCode.BlockDeserializeError, e);
}
}
@Override
public String getBlockBytes(int height) throws ConnectorException, IOException {
String rs = api.getBlock(height, "1");
Result rr = JSON.parseObject(rs, Result.class);
if (rr.Error != 0) {
throw new RestfulException(to(rr));
}
return (String) rr.Result;
}

@Override
public String getBlockBytes(String hash) throws ConnectorException, IOException {
String rs = api.getBlock(hash, "1");
Result rr = JSON.parseObject(rs, Result.class);
if (rr.Error != 0) {
throw new RestfulException(to(rr));
}
return (String) rr.Result;
}

@Override
public Object getBalance(String address) throws RestfulException {
Expand Down Expand Up @@ -299,7 +318,7 @@ public int getNetworkId() throws ConnectorException, IOException {
}

@Override
public String getSideChainData(String sideChainID) throws ConnectorException, IOException {
public String getSideChainData(int sideChainID) throws ConnectorException, IOException {
return null;
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/github/ontio/network/rpc/RpcClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,18 @@ public Block getBlock(String hash) throws ConnectorException, IOException {
}
}

@Override
public String getBlockBytes(int height) throws ConnectorException, IOException {
Object result = rpc.call("getblock",height);
return (String) result;
}

@Override
public String getBlockBytes(String hash) throws ConnectorException, IOException {
Object result = rpc.call("getblock",hash);
return (String) result;
}

@Override
public Object getSmartCodeEvent(int height) throws ConnectorException, IOException {
Object result = rpc.call("getsmartcodeevent", height);
Expand Down Expand Up @@ -273,7 +285,7 @@ public int getNetworkId() throws ConnectorException, IOException {
}

@Override
public String getSideChainData(String sideChainID) throws ConnectorException, IOException {
public String getSideChainData(int sideChainID) throws ConnectorException, IOException {
Object result = rpc.call("getsidechaindata", sideChainID);
try {
return (String) result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ public Block getBlock(String hash) throws ConnectorException, IOException{
mWebSocket.send(JSON.toJSONString(map));
return null;
}

@Override
public String getBlockBytes(int height) throws ConnectorException, IOException {
Map map = new HashMap<>();
map.put("Action", "getblockbyheight");
map.put("Version", "1.0.0");
map.put("Height",height);
map.put("Raw","1");
map.put("Id", generateReqId());
mWebSocket.send(JSON.toJSONString(map));
return null;
}

@Override
public String getBlockBytes(String hash) throws ConnectorException, IOException {
Map map = new HashMap<>();
map.put("Action", "getblockbyhash");
map.put("Version", "1.0.0");
map.put("Hash",hash);
map.put("Raw","1");
map.put("Id", generateReqId());
mWebSocket.send(JSON.toJSONString(map));
return null;
}

@Override
public Block getBlockJson(int height) throws ConnectorException, IOException{
Map map = new HashMap<>();
Expand Down Expand Up @@ -342,7 +367,7 @@ public int getNetworkId() throws ConnectorException, IOException {
}

@Override
public String getSideChainData(String sideChainID) throws ConnectorException, IOException {
public String getSideChainData(int sideChainID) throws ConnectorException, IOException {
return null;
}

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/com/github/ontio/sdk/manager/ConnectMgr.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ public Block getBlock(String hash) throws ConnectorException, IOException {

}

public String getBlockBytes(int height) throws ConnectorException, IOException, SDKException {
if (height < 0) {
throw new SDKException(ErrorCode.ParamError);
}
return connector.getBlockBytes(height);
}

public String getBlockBytes(String blockHash) throws ConnectorException, IOException {
return connector.getBlockBytes(blockHash);
}

public Object getBalance(String address) throws ConnectorException, IOException {
return connector.getBalance(address);
}
Expand Down Expand Up @@ -280,7 +291,7 @@ public String getGrantOng(String address) throws ConnectorException, IOException
public int getNetworkId() throws ConnectorException, IOException {
return connector.getNetworkId();
}
public String getSideChainData(String sideChianId) throws ConnectorException, IOException {
public String getSideChainData(int sideChianId) throws ConnectorException, IOException {
return connector.getSideChainData(sideChianId);
}

Expand Down
Loading