mirror of
https://gitee.com/BDWare/cp.git
synced 2025-01-10 09:54:07 +00:00
update ledgerUtil
This commit is contained in:
parent
8db5c8e2d7
commit
4b96899653
@ -1,11 +1,16 @@
|
|||||||
package org.bdware.sc.boundry.utils;
|
package org.bdware.sc.boundry.utils;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
import org.bdware.bdledger.api.grpc.Client;
|
import org.bdware.bdledger.api.grpc.Client;
|
||||||
import org.bdware.bdledger.api.grpc.pb.CommonProto.Transaction;
|
import org.bdware.bdledger.api.grpc.pb.CommonProto.Transaction;
|
||||||
import org.bdware.bdledger.api.grpc.pb.CommonProto.TransactionType;
|
import org.bdware.bdledger.api.grpc.pb.CommonProto.TransactionType;
|
||||||
import org.bdware.bdledger.api.grpc.pb.LedgerProto.SendTransactionResponse;
|
import org.bdware.bdledger.api.grpc.pb.LedgerProto.SendTransactionResponse;
|
||||||
import org.bdware.bdledger.api.grpc.pb.QueryProto.GetTransactionByHashResponse;
|
import org.bdware.bdledger.api.grpc.pb.QueryProto.GetTransactionByHashResponse;
|
||||||
|
import org.bdware.sc.boundry.JavaScriptEntry;
|
||||||
import org.bdware.sc.compiler.PermissionStub;
|
import org.bdware.sc.compiler.PermissionStub;
|
||||||
|
import org.bdware.sc.engine.JSONTool;
|
||||||
import org.bdware.sc.node.Permission;
|
import org.bdware.sc.node.Permission;
|
||||||
import org.bdware.sc.util.HashUtil;
|
import org.bdware.sc.util.HashUtil;
|
||||||
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
import wrp.jdk.nashorn.api.scripting.ScriptObjectMirror;
|
||||||
@ -19,6 +24,20 @@ import java.security.SecureRandom;
|
|||||||
public class LedgerUtil {
|
public class LedgerUtil {
|
||||||
static SecureRandom random = new SecureRandom((System.currentTimeMillis() + "").getBytes());
|
static SecureRandom random = new SecureRandom((System.currentTimeMillis() + "").getBytes());
|
||||||
|
|
||||||
|
public static Object getLedgerParams() {
|
||||||
|
//format:{nodes:[{ip:ip,port:port}]}
|
||||||
|
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
||||||
|
JsonElement jo = JsonParser.parseString(ledgerParam);
|
||||||
|
return JSONTool.convertJsonElementToMirror(jo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Client getDefaultClient() {
|
||||||
|
String ledgerParam = JavaScriptEntry.get.syncGet("", "getLedgerParams", "");
|
||||||
|
JsonElement jo = JsonParser.parseString(ledgerParam);
|
||||||
|
JsonObject param = jo.getAsJsonObject().get("nodes").getAsJsonArray().get(0).getAsJsonObject();
|
||||||
|
return new Client(param.get("ip").getAsString(), param.get("port").getAsInt());
|
||||||
|
}
|
||||||
|
|
||||||
public static Client getClient(ScriptObjectMirror str) {
|
public static Client getClient(ScriptObjectMirror str) {
|
||||||
return new Client((String) str.get("ip"), Integer.parseInt(str.get("port").toString()));
|
return new Client((String) str.get("ip"), Integer.parseInt(str.get("port").toString()));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user