From 009f86dab3342d515a708836753ea499d6ea6b31 Mon Sep 17 00:00:00 2001 From: huanghaiquan Date: Wed, 7 Aug 2019 14:29:02 +0800 Subject: [PATCH] Completed the definition of role privilege, and dealed some naming conflicts; --- .../com/jd/blockchain/consts/DataCodes.java | 13 ++- .../conf/application-gw.properties | 0 .../gateway/boot/GatewayBooter.java | 10 ++- .../ledger/core/AbstractPrivilege.java | 63 ++++++++++++++ .../blockchain/ledger/core/Authorization.java | 2 - .../jd/blockchain/ledger/core/Consensus.java | 21 ----- .../ledger/core/LedgerAdminPrivilege.java | 5 -- ...ermission.java => LedgerInitProposal.java} | 4 +- ...nData.java => LedgerInitProposalData.java} | 6 +- .../ledger/core/LedgerPermission.java | 87 ++++++++++++++++++- .../ledger/core/LedgerPrivilege.java | 20 +++++ .../ledger/core/LedgerSecurityManager.java | 2 +- .../jd/blockchain/ledger/core/P2PRealm.java | 21 ----- .../jd/blockchain/ledger/core/Privilege.java | 51 +---------- .../com/jd/blockchain/ledger/core/Role.java | 4 +- .../blockchain/ledger/core/RolePrivilege.java | 68 +++++++++++++++ .../blockchain/ledger/core/TxPermission.java | 34 ++++++++ .../blockchain/ledger/core/TxPrivilege.java | 14 +++ .../intgr/consensus/ConsensusTest.java | 6 +- .../intgr/perf/GlobalPerformanceTest.java | 6 +- .../intgr/perf/LedgerInitializeTest.java | 8 +- .../intgr/perf/LedgerInitializeWebTest.java | 20 ++--- .../com/jd/blockchain/intgr/perf/Utils.java | 8 +- .../initializer/LedgerInitializeTest.java | 8 +- .../LedgerInitializeWeb4Nodes.java | 2 +- .../LedgerInitializeWeb4SingleStepsTest.java | 20 ++--- .../web/LedgerInitConsensusService.java | 4 +- .../web/LedgerInitMessageConverter.java | 8 +- .../web/LedgerInitializeWebController.java | 28 +++--- .../web/PermissionResponseConverter.java | 2 +- .../mocker/MockerLedgerInitializer.java | 12 +-- .../mocker/node/NodeWebContext.java | 4 +- 32 files changed, 377 insertions(+), 184 deletions(-) create mode 100644 source/deployment/deployment-gateway/conf/application-gw.properties create mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AbstractPrivilege.java delete mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Consensus.java delete mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminPrivilege.java rename source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/{LedgerInitPermission.java => LedgerInitProposal.java} (92%) rename source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/{LedgerInitPermissionData.java => LedgerInitProposalData.java} (71%) create mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPrivilege.java delete mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/P2PRealm.java create mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/RolePrivilege.java create mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPermission.java create mode 100644 source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPrivilege.java diff --git a/source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java b/source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java index e2f8d65b..4b670ba4 100644 --- a/source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java +++ b/source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java @@ -8,11 +8,11 @@ package com.jd.blockchain.consts; */ public interface DataCodes { - public static final int BYTES_VALUE = 0x80; + public static final int BYTES_VALUE = 0x080; - public static final int BYTES_VALUE_LIST = 0x81; + public static final int BYTES_VALUE_LIST = 0x081; - public static final int BLOCK_CHAIN_IDENTITY = 0x90; + public static final int BLOCK_CHAIN_IDENTITY = 0x090; public static final int BLOCK = 0x100; @@ -52,12 +52,17 @@ public interface DataCodes { public static final int TX_RESPONSE = 0x350; public static final int TX_OP_RESULT = 0x360; + + // enum types of permissions; + public static final int ENUM_TX_PERMISSIONS = 0x401; + public static final int ENUM_LEDGER_PERMISSIONS = 0x402; + // contract types of metadata; public static final int METADATA = 0x600; public static final int METADATA_INIT_SETTING = 0x610; - public static final int METADATA_INIT_PERMISSION = 0x611; + public static final int METADATA_INIT_PROPOSAL = 0x611; public static final int METADATA_INIT_DECISION = 0x612; diff --git a/source/deployment/deployment-gateway/conf/application-gw.properties b/source/deployment/deployment-gateway/conf/application-gw.properties new file mode 100644 index 00000000..e69de29b diff --git a/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java b/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java index 93ca75ff..f6c637ad 100644 --- a/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java +++ b/source/deployment/deployment-gateway/src/main/java/com/jd/blockchain/gateway/boot/GatewayBooter.java @@ -18,15 +18,13 @@ public class GatewayBooter { writePID(); GatewayServerBooter.main(args); } catch (Exception e) { + e.printStackTrace(); System.err.println("Error!!! --[" + e.getClass().getName() + "] " + e.getMessage()); } } private static final void writePID() throws Exception { - URL url = GatewayBooter.class - .getProtectionDomain() - .getCodeSource() - .getLocation(); + URL url = GatewayBooter.class.getProtectionDomain().getCodeSource().getLocation(); String currPath = java.net.URLDecoder.decode(url.getPath(), "UTF-8"); if (currPath.contains("!/")) { currPath = currPath.substring(5, currPath.indexOf("!/")); @@ -40,6 +38,10 @@ public class GatewayBooter { String pidFilePath = homeDir + File.separator + "bin" + File.separator + "PID.log"; File pidFile = new File(pidFilePath); if (!pidFile.exists()) { + File dir = pidFile.getParentFile(); + if (!dir.exists()) { + dir.mkdirs(); + } pidFile.createNewFile(); } String name = ManagementFactory.getRuntimeMXBean().getName(); diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AbstractPrivilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AbstractPrivilege.java new file mode 100644 index 00000000..f4925a3d --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AbstractPrivilege.java @@ -0,0 +1,63 @@ +package com.jd.blockchain.ledger.core; + +import java.util.BitSet; + +import com.jd.blockchain.utils.io.BytesSerializable; + +/** + * LedgerPrivilege 账本特权是授权给特定角色的权限代码序列; + * + * @author huanghaiquan + * + */ +public abstract class AbstractPrivilege> implements Privilege, BytesSerializable { + + private BitSet permissions; + + public AbstractPrivilege(byte[] codeBytes) { + permissions = BitSet.valueOf(codeBytes); + } + + public boolean isEnable(E permission) { + return permissions.get(getCodeIndex(permission)); + } + + public void enable(E permission) { + permissions.set(getCodeIndex(permission)); + } + + public void disable(E permission) { + permissions.clear(getCodeIndex(permission)); + } + +// private int getCodeIndex(E permission) { +// return permission.CODE & 0xFF; +// } + + protected abstract int getCodeIndex(E permission); + + @Override + public byte[] toBytes() { + return permissions.toByteArray(); + } + +// public boolean[] getPermissionStates() { +// LedgerPermission[] PMs = LedgerPermission.values(); +// +// LedgerPermission maxPermission = Arrays.stream(PMs).max(new Comparator() { +// @Override +// public int compare(LedgerPermission o1, LedgerPermission o2) { +// return getCodeIndex(o1) - getCodeIndex(o2); +// } +// }).get(); +// +// boolean[] states = new boolean[getCodeIndex(maxPermission) + 1]; +// int idx = -1; +// for (LedgerPermission pm : PMs) { +// idx = getCodeIndex(pm); +// states[idx] = permissions.get(idx); +// } +// +// return states; +// } +} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Authorization.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Authorization.java index 18f1bf70..44c86d57 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Authorization.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Authorization.java @@ -1,7 +1,5 @@ package com.jd.blockchain.ledger.core; -import com.jd.blockchain.ledger.DigitalSignature; - /** * {@link Authorization} 抽象了对特定用户/角色的授权信息; * diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Consensus.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Consensus.java deleted file mode 100644 index da7b6104..00000000 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Consensus.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jd.blockchain.ledger.core; - - -/** - * @author hhq - * @version 1.0 - * @created 14-6��-2018 12:13:32 - */ -public class Consensus { - - public P2PRealm m_P2PRealm; - - public Consensus(){ - - } - - public void finalize() throws Throwable { - - } - -} \ No newline at end of file diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminPrivilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminPrivilege.java deleted file mode 100644 index b436b5da..00000000 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminPrivilege.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.jd.blockchain.ledger.core; - -public enum LedgerAdminPrivilege { - -} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermission.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposal.java similarity index 92% rename from source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermission.java rename to source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposal.java index 7ca9e15c..2baaacbd 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermission.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposal.java @@ -13,8 +13,8 @@ import com.jd.blockchain.ledger.LedgerInitOperation; * @author huanghaiquan * */ -@DataContract(code = DataCodes.METADATA_INIT_PERMISSION) -public interface LedgerInitPermission { +@DataContract(code = DataCodes.METADATA_INIT_PROPOSAL) +public interface LedgerInitProposal { /** * 做出许可的参与方 ID; diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermissionData.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposalData.java similarity index 71% rename from source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermissionData.java rename to source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposalData.java index ead25a56..6b6c79aa 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitPermissionData.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitProposalData.java @@ -2,7 +2,7 @@ package com.jd.blockchain.ledger.core; import com.jd.blockchain.crypto.SignatureDigest; -public class LedgerInitPermissionData implements LedgerInitPermission { +public class LedgerInitProposalData implements LedgerInitProposal { private int participantId; @@ -11,10 +11,10 @@ public class LedgerInitPermissionData implements LedgerInitPermission { /** * a private contructor for deserialize; */ - private LedgerInitPermissionData() { + private LedgerInitProposalData() { } - public LedgerInitPermissionData(int participantId, SignatureDigest initTxSignature) { + public LedgerInitProposalData(int participantId, SignatureDigest initTxSignature) { this.participantId = participantId; this.transactionSignature = initTxSignature; } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPermission.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPermission.java index 99f6b907..e5b6b751 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPermission.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPermission.java @@ -1,9 +1,94 @@ package com.jd.blockchain.ledger.core; +import com.jd.blockchain.binaryproto.EnumContract; +import com.jd.blockchain.binaryproto.EnumField; +import com.jd.blockchain.binaryproto.PrimitiveType; +import com.jd.blockchain.consts.DataCodes; + +/** + * 账本相关的权限,这些权限属于全局性的; + * + * @author huanghaiquan + * + */ +@EnumContract(code = DataCodes.ENUM_LEDGER_PERMISSIONS) public enum LedgerPermission { - SET_ROLE((byte) 0); + /** + * 设置角色权限;
+ * 包括:创建角色、设置角色的权限代码、分配用户角色; + */ + SET_ROLE_PERMISSION((byte) 0x01), + + /** + * 设置共识协议;
+ */ + SET_CONSENSUS((byte) 0x02), + + /** + * 设置密码体系;
+ */ + SET_CRYPTO((byte) 0x03), + + /** + * 注册参与方;
+ */ + REGISTER_PARTICIPANT((byte) 0x04), + + /** + * 设置参与方的权限;
+ * + * 如果不具备此项权限,则无法设置参与方的“提交交易”、“参与共识”的权限; + */ + SET_PARTICIPANT_PERMISSION((byte) 0x05), + + /** + * 参与方核准交易;
+ * + * 如果不具备此项权限,则无法作为网关节点接入并签署由终端提交的交易; + */ + APPROVE_TX((byte) 0x06), + + /** + * 参与方共识交易;
+ * + * 如果不具备此项权限,则无法作为共识节点接入并对交易进行共识; + */ + CONSENSUS_TX((byte) 0x07), + + /** + * 注册用户;
+ * + * 如果不具备此项权限,则无法注册用户; + */ + REGISTER_USER((byte) 0x08), + + /** + * 设置用户属性;
+ */ + SET_USER_ATTRIBUTES((byte) 0x09), + + /** + * 注册数据账户;
+ */ + REGISTER_DATA_ACCOUNT((byte) 0x0A), + + /** + * 写入数据账户;
+ */ + WRITE_DATA_ACCOUNT((byte) 0x0B), + + /** + * 注册合约;
+ */ + REGISTER_CONTRACT((byte) 0x0C), + + /** + * 升级合约 + */ + UPGRADE_CONTRACT((byte) 0x0D); + @EnumField(type = PrimitiveType.INT8) public final byte CODE; private LedgerPermission(byte code) { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPrivilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPrivilege.java new file mode 100644 index 00000000..f4efbecb --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerPrivilege.java @@ -0,0 +1,20 @@ +package com.jd.blockchain.ledger.core; + +/** + * LedgerPrivilege 账本特权是授权给特定角色的权限代码序列; + * + * @author huanghaiquan + * + */ +public class LedgerPrivilege extends AbstractPrivilege { + + public LedgerPrivilege(byte[] codeBytes) { + super(codeBytes); + } + + @Override + protected int getCodeIndex(LedgerPermission permission) { + return permission.CODE & 0xFF; + } + +} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManager.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManager.java index 11c99c9e..a44dc575 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManager.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManager.java @@ -22,7 +22,7 @@ public class LedgerSecurityManager { throw new IllegalStateException("Not implemented!"); } - public Role setRole(String role, Privilege privilege) { + public Role setRole(String role, LedgerPrivilege privilege) { throw new IllegalStateException("Not implemented!"); } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/P2PRealm.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/P2PRealm.java deleted file mode 100644 index c7480e07..00000000 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/P2PRealm.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.jd.blockchain.ledger.core; - - -/** - * @author hhq - * @version 1.0 - * @created 14-6��-2018 12:13:33 - */ -public class P2PRealm { - - public Peer m_Peer; - - public P2PRealm(){ - - } - - public void finalize() throws Throwable { - - } - -} \ No newline at end of file diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Privilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Privilege.java index 95443f45..25f6c9eb 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Privilege.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Privilege.java @@ -1,54 +1,5 @@ package com.jd.blockchain.ledger.core; -import java.util.Arrays; -import java.util.BitSet; -import java.util.Comparator; +public interface Privilege> { -public class Privilege { - - private BitSet permissions; - - public Privilege(byte[] codeBytes) { - permissions = BitSet.valueOf(codeBytes); - } - - public boolean isEnable(LedgerPermission permission) { - return permissions.get(getCodeIndex(permission)); - } - - public void enable(LedgerPermission permission) { - permissions.set(getCodeIndex(permission)); - } - - public void disable(LedgerPermission permission) { - permissions.clear(getCodeIndex(permission)); - } - - public static int getCodeIndex(LedgerPermission permission) { - return permission.CODE & 0xFF; - } - - public byte[] toCodeBytes() { - return permissions.toByteArray(); - } - - public boolean[] getPermissionStates() { - LedgerPermission[] PMs = LedgerPermission.values(); - - LedgerPermission maxPermission = Arrays.stream(PMs).max(new Comparator() { - @Override - public int compare(LedgerPermission o1, LedgerPermission o2) { - return getCodeIndex(o1) - getCodeIndex(o2); - } - }).get(); - - boolean[] states = new boolean[getCodeIndex(maxPermission) + 1]; - int idx = -1; - for (LedgerPermission pm : PMs) { - idx = getCodeIndex(pm); - states[idx] = permissions.get(idx); - } - - return states; - } } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Role.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Role.java index 23149745..7ece80cf 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Role.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/Role.java @@ -6,7 +6,7 @@ public class Role { private long version; - private Privilege privilege; + private LedgerPrivilege privilege; @@ -18,7 +18,7 @@ public class Role { return version; } - public Privilege getPrivilege() { + public LedgerPrivilege getPrivilege() { return privilege; } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/RolePrivilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/RolePrivilege.java new file mode 100644 index 00000000..19949af5 --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/RolePrivilege.java @@ -0,0 +1,68 @@ +package com.jd.blockchain.ledger.core; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; + +import com.jd.blockchain.utils.io.BytesEncoding; +import com.jd.blockchain.utils.io.BytesSerializable; + +/** + * 表示赋予角色的特权码; + * + * @author huanghaiquan + * + */ +public class RolePrivilege implements BytesSerializable { + + // 权限码的数量;目前有2种:账本权限 + 交易权限; + private static final int SEGMENT_COUNT = 2; + + private LedgerPrivilege ledgerPrivilege; + + private TxPrivilege txPrivilege; + + public Privilege getTxPrivilege() { + return txPrivilege; + } + + public Privilege getLedgerPrivilege() { + return ledgerPrivilege; + } + + public RolePrivilege(byte[] priviledgeCodes) { + byte[][] bytesSegments = decodeBytes(priviledgeCodes); + ledgerPrivilege = new LedgerPrivilege(bytesSegments[0]); + txPrivilege = new TxPrivilege(bytesSegments[1]); + } + + private byte[] encodeBytes(byte[]... bytes) { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + // write one byte; + out.write(bytes.length); + for (int i = 0; i < bytes.length; i++) { + BytesEncoding.writeInTiny(bytes[i], out); + } + return out.toByteArray(); + } + + private byte[][] decodeBytes(byte[] bytes) { + ByteArrayInputStream in = new ByteArrayInputStream(bytes); + // read one byte; + int len = in.read(); + if (len < 1 || len > SEGMENT_COUNT) { + throw new IllegalStateException("Decoded illegal privilege bytes!"); + } + byte[][] bytesSegments = new byte[len][]; + for (int i = 0; i < bytesSegments.length; i++) { + bytesSegments[i] = BytesEncoding.readInTiny(in); + } + return bytesSegments; + } + + @Override + public byte[] toBytes() { + // 保持和解码时一致的顺序; + return encodeBytes(ledgerPrivilege.toBytes(), txPrivilege.toBytes()); + } + +} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPermission.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPermission.java new file mode 100644 index 00000000..b73ceaa3 --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPermission.java @@ -0,0 +1,34 @@ +package com.jd.blockchain.ledger.core; + +import com.jd.blockchain.binaryproto.EnumContract; +import com.jd.blockchain.binaryproto.EnumField; +import com.jd.blockchain.binaryproto.PrimitiveType; +import com.jd.blockchain.consts.DataCodes; + +/** + * TxPermission 交易权限表示一个用户可以发起的交易类型; + * + * @author huanghaiquan + * + */ +@EnumContract(code = DataCodes.ENUM_TX_PERMISSIONS) +public enum TxPermission { + + /** + * 交易中包含指令操作; + */ + COMMAND((byte) 0x01), + + /** + * 交易中包含合约操作; + */ + CONTRACT((byte) 0x02); + + @EnumField(type = PrimitiveType.INT8) + public final byte CODE; + + private TxPermission(byte code) { + this.CODE = code; + } + +} diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPrivilege.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPrivilege.java new file mode 100644 index 00000000..30e45a18 --- /dev/null +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TxPrivilege.java @@ -0,0 +1,14 @@ +package com.jd.blockchain.ledger.core; + +public class TxPrivilege extends AbstractPrivilege { + + public TxPrivilege(byte[] codeBytes) { + super(codeBytes); + } + + @Override + protected int getCodeIndex(TxPermission permission) { + return permission.CODE & 0xFF; + } + +} diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/consensus/ConsensusTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/consensus/ConsensusTest.java index 9eb45aee..d5532f63 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/consensus/ConsensusTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/consensus/ConsensusTest.java @@ -26,7 +26,7 @@ import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.TransactionTemplate; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.sdk.BlockchainService; @@ -326,7 +326,7 @@ public class ConsensusTest { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); } @@ -398,7 +398,7 @@ public class ConsensusTest { return invoker.start(); } - public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, + public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { return controller.prepareLocalPermission(id, privKey, setting, csProps); } diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/GlobalPerformanceTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/GlobalPerformanceTest.java index f4c21fe7..b2f1c135 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/GlobalPerformanceTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/GlobalPerformanceTest.java @@ -28,7 +28,7 @@ import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.TransactionTemplate; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.sdk.BlockchainService; @@ -326,7 +326,7 @@ public class GlobalPerformanceTest { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); } @@ -400,7 +400,7 @@ public class GlobalPerformanceTest { return invoker.start(); } - public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, + public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { return controller.prepareLocalPermission(id, privKey, setting, csProps); } diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java index dbd8b21b..f4b24b36 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java @@ -21,7 +21,7 @@ import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.ledger.LedgerBlock; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.UserAccount; import com.jd.blockchain.ledger.core.UserAccountSet; @@ -251,10 +251,10 @@ public class LedgerInitializeTest { } @Override - public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { - ThreadInvoker invoker = new ThreadInvoker() { + public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { + ThreadInvoker invoker = new ThreadInvoker() { @Override - protected LedgerInitPermission invoke() { + protected LedgerInitProposal invoke() { return initCsService.requestPermission(requesterId, signature); } }; diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java index 569472d9..c6ca3fdc 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java @@ -26,7 +26,7 @@ import com.jd.blockchain.ledger.Operation; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.UserAccount; import com.jd.blockchain.ledger.core.UserAccountSet; @@ -112,10 +112,10 @@ public class LedgerInitializeWebTest { PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); // 测试生成“账本初始化许可”; - LedgerInitPermission permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); - LedgerInitPermission permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); - LedgerInitPermission permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); - LedgerInitPermission permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); + LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); + LedgerInitProposal permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); + LedgerInitProposal permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); + LedgerInitProposal permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); TransactionContent initTxContent0 = node0.getInitTxContent(); TransactionContent initTxContent1 = node1.getInitTxContent(); @@ -205,9 +205,9 @@ public class LedgerInitializeWebTest { testRequestDecision(node3, node2, initCsService2); } - private LedgerInitPermission testPreparePermisssion(NodeWebContext node, PrivKey privKey, + private LedgerInitProposal testPreparePermisssion(NodeWebContext node, PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { - LedgerInitPermission permission = node.preparePermision(privKey, setting, csProps); + LedgerInitProposal permission = node.preparePermision(privKey, setting, csProps); return permission; } @@ -215,7 +215,7 @@ public class LedgerInitializeWebTest { private void testRequestPermission(NodeWebContext fromNode, PrivKey fromPrivkey, NodeWebContext targetNode, LedgerInitConsensusService targetNodeService) { SignatureDigest reqSignature = fromNode.createPermissionRequestSignature(fromNode.getId(), fromPrivkey); - LedgerInitPermission targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); + LedgerInitProposal targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); } private void testRequestDecision(NodeWebContext fromNode, NodeWebContext targetNode, @@ -374,7 +374,7 @@ public class LedgerInitializeWebTest { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); } @@ -457,7 +457,7 @@ public class LedgerInitializeWebTest { return invoker.start(); } - public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, + public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { return controller.prepareLocalPermission(id, privKey, setting, csProps); } diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java index 80b133ad..591f738a 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/Utils.java @@ -18,7 +18,7 @@ import com.jd.blockchain.consensus.ConsensusSettings; import com.jd.blockchain.ledger.CryptoSetting; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.storage.service.DbConnectionFactory; @@ -202,10 +202,10 @@ public class Utils { } @Override - public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { - ThreadInvoker invoker = new ThreadInvoker() { + public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { + ThreadInvoker invoker = new ThreadInvoker() { @Override - protected LedgerInitPermission invoke() { + protected LedgerInitProposal invoke() { return initCsService.requestPermission(requesterId, signature); } }; diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java index 09ddf134..ffdcaa80 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java @@ -30,7 +30,7 @@ import com.jd.blockchain.ledger.LedgerInitOperation; import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.UserAccount; import com.jd.blockchain.ledger.core.UserAccountSet; @@ -301,10 +301,10 @@ public class LedgerInitializeTest { } @Override - public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { - ThreadInvoker invoker = new ThreadInvoker() { + public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { + ThreadInvoker invoker = new ThreadInvoker() { @Override - protected LedgerInitPermission invoke() { + protected LedgerInitProposal invoke() { return initCsService.requestPermission(requesterId, signature); } }; diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java index a37afc62..9415e3b6 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java @@ -213,7 +213,7 @@ public class LedgerInitializeWeb4Nodes { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); } diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4SingleStepsTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4SingleStepsTest.java index 2cf5701d..64371207 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4SingleStepsTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4SingleStepsTest.java @@ -27,7 +27,7 @@ import com.jd.blockchain.ledger.Operation; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.storage.service.DbConnection; @@ -116,10 +116,10 @@ public class LedgerInitializeWeb4SingleStepsTest { PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]); // 测试生成“账本初始化许可”; - LedgerInitPermission permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); - LedgerInitPermission permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); - LedgerInitPermission permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); - LedgerInitPermission permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); + LedgerInitProposal permission0 = testPreparePermisssion(node0, privkey0, initSetting, csProps); + LedgerInitProposal permission1 = testPreparePermisssion(node1, privkey1, initSetting, csProps); + LedgerInitProposal permission2 = testPreparePermisssion(node2, privkey2, initSetting, csProps); + LedgerInitProposal permission3 = testPreparePermisssion(node3, privkey3, initSetting, csProps); TransactionContent initTxContent0 = node0.getInitTxContent(); TransactionContent initTxContent1 = node1.getInitTxContent(); @@ -240,9 +240,9 @@ public class LedgerInitializeWeb4SingleStepsTest { testRequestDecision(node3, node2, initCsService2); } - private LedgerInitPermission testPreparePermisssion(NodeWebContext node, PrivKey privKey, + private LedgerInitProposal testPreparePermisssion(NodeWebContext node, PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { - LedgerInitPermission permission = node.preparePermision(privKey, setting, csProps); + LedgerInitProposal permission = node.preparePermision(privKey, setting, csProps); assertEquals(node.getId(), permission.getParticipantId()); assertNotNull(permission.getTransactionSignature()); @@ -253,7 +253,7 @@ public class LedgerInitializeWeb4SingleStepsTest { private void testRequestPermission(NodeWebContext fromNode, PrivKey fromPrivkey, NodeWebContext targetNode, LedgerInitConsensusService targetNodeService) { SignatureDigest reqSignature = fromNode.createPermissionRequestSignature(fromNode.getId(), fromPrivkey); - LedgerInitPermission targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); + LedgerInitProposal targetPermission = targetNodeService.requestPermission(fromNode.getId(), reqSignature); assertEquals(targetNode.getId(), targetPermission.getParticipantId()); assertEquals(targetNode.getLocalPermission().getTransactionSignature(), targetPermission.getTransactionSignature()); @@ -312,7 +312,7 @@ public class LedgerInitializeWeb4SingleStepsTest { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); } @@ -385,7 +385,7 @@ public class LedgerInitializeWeb4SingleStepsTest { return invoker.start(); } - public LedgerInitPermission preparePermision(PrivKey privKey, LedgerInitProperties setting, + public LedgerInitProposal preparePermision(PrivKey privKey, LedgerInitProperties setting, ConsensusSettings csProps) { return controller.prepareLocalPermission(id, privKey, setting, csProps); } diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitConsensusService.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitConsensusService.java index d9699560..46ae01b5 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitConsensusService.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitConsensusService.java @@ -2,7 +2,7 @@ package com.jd.blockchain.tools.initializer.web; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.utils.http.HttpAction; import com.jd.blockchain.utils.http.HttpMethod; import com.jd.blockchain.utils.http.HttpService; @@ -21,7 +21,7 @@ public interface LedgerInitConsensusService { * 请求者的私钥对 “id” + “账本种子” 做出的签名;只有签名合法且参与者是初始化配置中的参与方才能获得有效返回,否则将被拒绝; */ @HttpAction(path = "/legerinit/permission/{requesterId}", method = HttpMethod.POST, contentType = LedgerInitMessageConverter.CONTENT_TYPE_VALUE, responseConverter = PermissionResponseConverter.class) - LedgerInitPermission requestPermission(@PathParam(name = "requesterId") int requesterId, + LedgerInitProposal requestPermission(@PathParam(name = "requesterId") int requesterId, @RequestBody(converter = SignatureDigestRequestBodyConverter.class) SignatureDigest signature); /** diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitMessageConverter.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitMessageConverter.java index 5658f9f6..6361d6a1 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitMessageConverter.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitMessageConverter.java @@ -17,8 +17,8 @@ import com.jd.blockchain.binaryproto.BinaryProtocol; import com.jd.blockchain.binaryproto.DataContractRegistry; import com.jd.blockchain.crypto.SignatureDigest; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; -import com.jd.blockchain.ledger.core.LedgerInitPermissionData; +import com.jd.blockchain.ledger.core.LedgerInitProposal; +import com.jd.blockchain.ledger.core.LedgerInitProposalData; import com.jd.blockchain.utils.io.BytesUtils; /** @@ -38,10 +38,10 @@ public class LedgerInitMessageConverter implements HttpMessageConverter private static final Map, Class> SUPPORTED_CONTRACT_TYPES = new HashMap<>(); static { - DataContractRegistry.register(LedgerInitPermission.class); + DataContractRegistry.register(LedgerInitProposal.class); DataContractRegistry.register(LedgerInitDecision.class); - SUPPORTED_CONTRACT_TYPES.put(LedgerInitPermission.class, LedgerInitPermissionData.class); + SUPPORTED_CONTRACT_TYPES.put(LedgerInitProposal.class, LedgerInitProposalData.class); SUPPORTED_CONTRACT_TYPES.put(LedgerInitDecision.class, LedgerInitDecisionData.class); // SUPPORTED_CONTRACT_TYPES.add(LedgerInitResponse.class); diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java index 116a381a..09de6518 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/LedgerInitializeWebController.java @@ -46,8 +46,8 @@ import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.LedgerEditor; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; -import com.jd.blockchain.ledger.core.LedgerInitPermissionData; +import com.jd.blockchain.ledger.core.LedgerInitProposal; +import com.jd.blockchain.ledger.core.LedgerInitProposalData; import com.jd.blockchain.ledger.core.LedgerManage; import com.jd.blockchain.ledger.core.LedgerTransactionContext; import com.jd.blockchain.storage.service.DbConnection; @@ -84,7 +84,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI private final SignatureFunction SIGN_FUNC; - private volatile LedgerInitPermission localPermission; + private volatile LedgerInitProposal localPermission; private TransactionContent initTxContent; @@ -92,7 +92,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI private volatile LedgerInitSetting ledgerInitSetting; - private volatile LedgerInitPermission[] permissions; + private volatile LedgerInitProposal[] permissions; private volatile NetworkAddress[] initializerAddresses; @@ -140,7 +140,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI return initTxContent; } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return localPermission; } @@ -319,13 +319,13 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI return defCryptoSetting; } - public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, + public LedgerInitProposal prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, ConsensusSettings consensusProps) { CryptoSetting defCryptoSetting = createDefaultCryptoSetting(); return prepareLocalPermission(currentId, privKey, ledgerProps, consensusProps, defCryptoSetting); } - public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, + public LedgerInitProposal prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, ConsensusSettings csSettings, CryptoSetting cryptoSetting) { // 创建初始化配置; LedgerInitSettingData initSetting = new LedgerInitSettingData(); @@ -383,10 +383,10 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI // 对初始交易签名,生成当前参与者的账本初始化许可; SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); - LedgerInitPermissionData permission = new LedgerInitPermissionData(currentId, permissionSign); + LedgerInitProposalData permission = new LedgerInitProposalData(currentId, permissionSign); this.currentId = currentId; - this.permissions = new LedgerInitPermission[initSetting.getConsensusParticipants().length]; + this.permissions = new LedgerInitProposal[initSetting.getConsensusParticipants().length]; this.permissions[currentId] = permission; this.localPermission = permission; @@ -493,7 +493,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI continue; } PubKey pubKey = participants[i].getPubKey(); - LedgerInitPermission permission = (LedgerInitPermission) results[i].getValue(); + LedgerInitProposal permission = (LedgerInitProposal) results[i].getValue(); if (permission.getParticipantId() != participants[i].getId()) { prompter.error("\r\nThe id of received permission isn't equal to it's participant ! --[Id=%s][name=%s]", participants[i].getAddress(), participants[i].getName()); @@ -534,16 +534,16 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI * @param latch * @return */ - private InvocationResult doRequestPermission(int targetId, SignatureDigest reqAuthSign, + private InvocationResult doRequestPermission(int targetId, SignatureDigest reqAuthSign, CountDownLatch latch) { - InvocationResult result = new InvocationResult<>(); + InvocationResult result = new InvocationResult<>(); try { LedgerInitConsensusService initConsensus = connectToParticipant(targetId); Thread thrd = new Thread(new Runnable() { @Override public void run() { try { - LedgerInitPermission permission = initConsensus.requestPermission(currentId, reqAuthSign); + LedgerInitProposal permission = initConsensus.requestPermission(currentId, reqAuthSign); result.setValue(permission); } catch (Exception e) { result.setError(e); @@ -561,7 +561,7 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI @RequestMapping(path = "/legerinit/permission/{requesterId}", method = RequestMethod.POST, produces = LedgerInitMessageConverter.CONTENT_TYPE_VALUE, consumes = LedgerInitMessageConverter.CONTENT_TYPE_VALUE) @Override - public LedgerInitPermission requestPermission(@PathVariable(name = "requesterId") int requesterId, + public LedgerInitProposal requestPermission(@PathVariable(name = "requesterId") int requesterId, @RequestBody SignatureDigest signature) { if (requesterId == currentId) { throw new LedgerInitException("There is a id conflict!"); diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/PermissionResponseConverter.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/PermissionResponseConverter.java index ab5b0308..e07fa4d7 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/PermissionResponseConverter.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/web/PermissionResponseConverter.java @@ -3,7 +3,7 @@ package com.jd.blockchain.tools.initializer.web; import java.io.InputStream; import com.jd.blockchain.binaryproto.BinaryProtocol; -import com.jd.blockchain.ledger.core.LedgerInitPermissionData; +import com.jd.blockchain.ledger.core.LedgerInitProposalData; import com.jd.blockchain.tools.initializer.LedgerInitException; import com.jd.blockchain.utils.http.HttpServiceContext; import com.jd.blockchain.utils.http.ResponseConverter; diff --git a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerLedgerInitializer.java b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerLedgerInitializer.java index 0c2361fa..962c79ae 100644 --- a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerLedgerInitializer.java +++ b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerLedgerInitializer.java @@ -45,7 +45,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon private final SignatureFunction SIGN_FUNC; - private volatile LedgerInitPermission localPermission; + private volatile LedgerInitProposal localPermission; private TransactionContent initTxContent; @@ -92,7 +92,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon return initTxContent; } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return localPermission; } @@ -129,7 +129,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon prompter.info("Init settings and sign permision..."); - prepareLocalPermission(currentId, privKey, ledgerInitProps, null, cryptoSetting); + prepareLocalProposal(currentId, privKey, ledgerInitProps, null, cryptoSetting); try { // 连接数据库; @@ -201,7 +201,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon return defCryptoSetting; } - public LedgerInitPermission prepareLocalPermission(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, + public LedgerInitProposal prepareLocalProposal(int currentId, PrivKey privKey, LedgerInitProperties ledgerProps, ConsensusSettings csSettings, CryptoSetting cryptoSetting) { // 创建初始化配置; LedgerInitSettingData initSetting = new LedgerInitSettingData(); @@ -249,7 +249,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon // 对初始交易签名,生成当前参与者的账本初始化许可; SignatureDigest permissionSign = SignatureUtils.sign(initTxContent, privKey); - localPermission = new LedgerInitPermissionData(currentId, permissionSign); + localPermission = new LedgerInitProposalData(currentId, permissionSign); this.currentId = currentId; return localPermission; @@ -300,7 +300,7 @@ public class MockerLedgerInitializer implements LedgerInitProcess, LedgerInitCon } @Override - public LedgerInitPermission requestPermission(int requesterId, SignatureDigest signature) { + public LedgerInitProposal requestPermission(int requesterId, SignatureDigest signature) { return localPermission; } diff --git a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/node/NodeWebContext.java b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/node/NodeWebContext.java index 93096613..38bc0575 100644 --- a/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/node/NodeWebContext.java +++ b/source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/node/NodeWebContext.java @@ -4,7 +4,7 @@ import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.PrivKey; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.core.LedgerInitDecision; -import com.jd.blockchain.ledger.core.LedgerInitPermission; +import com.jd.blockchain.ledger.core.LedgerInitProposal; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.mocker.config.LedgerInitWebConfiguration; @@ -48,7 +48,7 @@ public class NodeWebContext { return controller.getInitTxContent(); } - public LedgerInitPermission getLocalPermission() { + public LedgerInitProposal getLocalPermission() { return controller.getLocalPermission(); }