From f73a2280d94e6d61dc8590025850772215bbd40b Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Fri, 21 Jun 2019 15:38:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Delete=20the=20public=20key=20part=20involv?= =?UTF-8?q?ed=20in=20the=20bftsmart=20file=20=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bftsmart/BftsmartCommitBlockConfig.java | 70 ++++++------ .../bftsmart/BftsmartCommitBlockSettings.java | 34 +++--- .../bftsmart/BftsmartConsensusConfig.java | 26 +++-- .../bftsmart/BftsmartConsensusSettings.java | 4 +- .../BftsmartConsensusSettingsBuilder.java | 106 ++++++++++-------- .../BftsmartConsensusManageService.java | 18 +-- .../bftsmart/service/BftsmartNodeServer.java | 2 +- .../service/BftsmartServerSettingConfig.java | 3 - .../service/BftsmartServerSettings.java | 1 - ...xyClientTest.java => ProxyClientTest.java} | 11 +- source/consensus/consensus-framework/pom.xml | 5 + .../consensus/ConsensusSettingsBuilder.java | 10 +- .../mq/MsgQueueConsensusSettingsBuilder.java | 3 +- .../resources/config/init/bftsmart.config | 15 --- .../main/resources/config/init/ledger.init | 53 +++------ .../src/main/resources/config/init/local.conf | 3 +- .../resources/config/init/mq/ledger-init.conf | 66 ----------- .../main/resources/config/init/mq/ledger.init | 74 ++++++++++++ .../main/resources/config/init/mq/local.conf | 23 ++-- .../src/main/resources/scripts/ledger-init.sh | 2 +- .../jd/blockchain/intgr/IntegrationTest.java | 5 +- .../intgr/consensus/ConsensusTest.java | 4 +- .../intgr/perf/GlobalPerformanceTest.java | 4 +- .../intgr/perf/LedgerInitializeWebTest.java | 8 +- .../intgr/perf/LedgerPerformanceTest.java | 4 +- .../com/jd/blockchain/intgr/perf/Utils.java | 52 +++++++++ .../blockchain/intgr/IntegrationBaseTest.java | 5 +- .../jd/blockchain/intgr/IntegrationTest2.java | 5 +- .../intgr/IntegrationTestDataAccount.java | 5 +- .../LedgerInitializeWeb4Nodes.java | 5 +- .../LedgerInitializeWeb4SingleStepsTest.java | 5 +- .../ledger/LedgerBlockGeneratingTest.java | 5 +- .../src/test/resources/bftsmart.config | 25 +---- .../src/test/resources/ledger.init | 1 - .../initializer/LedgerInitProperties.java | 10 +- .../web/LedgerInitializeWebController.java | 9 +- 36 files changed, 366 insertions(+), 315 deletions(-) rename source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/{proxyClientTest.java => ProxyClientTest.java} (93%) delete mode 100644 source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger-init.conf create mode 100644 source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockConfig.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockConfig.java index 23f682ce..5fa31a11 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockConfig.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockConfig.java @@ -1,35 +1,35 @@ -package com.jd.blockchain.consensus.bftsmart; - -public class BftsmartCommitBlockConfig implements BftsmartCommitBlockSettings { - - private int txSizePerBlock; - - private long maxDelayMilliSecondsPerBlock; - - - public BftsmartCommitBlockConfig() { - - } - - public BftsmartCommitBlockConfig(int txSizePerBlock, long maxDelayMilliSecondsPerBlock) { - this.txSizePerBlock = txSizePerBlock; - this.maxDelayMilliSecondsPerBlock = maxDelayMilliSecondsPerBlock; - } - @Override - public int getTxSizePerBlock() { - return txSizePerBlock; - } - - public void setTxSizePerBlock(int txSizePerBlock) { - this.txSizePerBlock = txSizePerBlock; - } - - @Override - public long getMaxDelayMilliSecondsPerBlock() { - return maxDelayMilliSecondsPerBlock; - } - - public void setMaxDelayMilliSecondsPerBlock(long maxDelayMilliSecondsPerBlock) { - this.maxDelayMilliSecondsPerBlock = maxDelayMilliSecondsPerBlock; - } -} +//package com.jd.blockchain.consensus.bftsmart; +// +//public class BftsmartCommitBlockConfig implements BftsmartCommitBlockSettings { +// +// private int txSizePerBlock; +// +// private long maxDelayMilliSecondsPerBlock; +// +// +// public BftsmartCommitBlockConfig() { +// +// } +// +// public BftsmartCommitBlockConfig(int txSizePerBlock, long maxDelayMilliSecondsPerBlock) { +// this.txSizePerBlock = txSizePerBlock; +// this.maxDelayMilliSecondsPerBlock = maxDelayMilliSecondsPerBlock; +// } +// @Override +// public int getTxSizePerBlock() { +// return txSizePerBlock; +// } +// +// public void setTxSizePerBlock(int txSizePerBlock) { +// this.txSizePerBlock = txSizePerBlock; +// } +// +// @Override +// public long getMaxDelayMilliSecondsPerBlock() { +// return maxDelayMilliSecondsPerBlock; +// } +// +// public void setMaxDelayMilliSecondsPerBlock(long maxDelayMilliSecondsPerBlock) { +// this.maxDelayMilliSecondsPerBlock = maxDelayMilliSecondsPerBlock; +// } +//} diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockSettings.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockSettings.java index 675344da..2924c9f0 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockSettings.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartCommitBlockSettings.java @@ -1,17 +1,17 @@ -package com.jd.blockchain.consensus.bftsmart; - -import com.jd.blockchain.binaryproto.DataContract; -import com.jd.blockchain.binaryproto.DataField; -import com.jd.blockchain.binaryproto.PrimitiveType; -import com.jd.blockchain.consts.DataCodes; - - -@DataContract(code = DataCodes.CONSENSUS_BFTSMART_BLOCK_SETTINGS) -public interface BftsmartCommitBlockSettings { - - @DataField(order = 0, primitiveType = PrimitiveType.INT32) - int getTxSizePerBlock(); - - @DataField(order = 1, primitiveType = PrimitiveType.INT64) - long getMaxDelayMilliSecondsPerBlock(); -} +//package com.jd.blockchain.consensus.bftsmart; +// +//import com.jd.blockchain.binaryproto.DataContract; +//import com.jd.blockchain.binaryproto.DataField; +//import com.jd.blockchain.binaryproto.PrimitiveType; +//import com.jd.blockchain.consts.DataCodes; +// +// +//@DataContract(code = DataCodes.CONSENSUS_BFTSMART_BLOCK_SETTINGS) +//public interface BftsmartCommitBlockSettings { +// +// @DataField(order = 0, primitiveType = PrimitiveType.INT32) +// int getTxSizePerBlock(); +// +// @DataField(order = 1, primitiveType = PrimitiveType.INT64) +// long getMaxDelayMilliSecondsPerBlock(); +//} diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusConfig.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusConfig.java index ca3a301e..48d5acb9 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusConfig.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusConfig.java @@ -9,7 +9,7 @@ public class BftsmartConsensusConfig implements BftsmartConsensusSettings { private BftsmartNodeSettings[] nodes; - private BftsmartCommitBlockSettings commitBlockSettings; +// private BftsmartCommitBlockSettings commitBlockSettings; static { DataContractRegistry.register(BftsmartConsensusSettings.class); @@ -24,9 +24,11 @@ public class BftsmartConsensusConfig implements BftsmartConsensusSettings { * @param bftsmartSystemConfigs * bftsmart系统配置; */ - public BftsmartConsensusConfig(BftsmartNodeSettings[] nodes, BftsmartCommitBlockSettings commitBlockSettings, Property[] bftsmartSystemConfigs) { + public BftsmartConsensusConfig(BftsmartNodeSettings[] nodes, +// BftsmartCommitBlockSettings commitBlockSettings, + Property[] bftsmartSystemConfigs) { this.nodes = nodes; - this.commitBlockSettings = commitBlockSettings; +// this.commitBlockSettings = commitBlockSettings; this.bftsmartSystemConfig = bftsmartSystemConfigs; } @@ -40,13 +42,13 @@ public class BftsmartConsensusConfig implements BftsmartConsensusSettings { return bftsmartSystemConfig; } - @Override - public BftsmartCommitBlockSettings getCommitBlockSettings() { - return commitBlockSettings; - } - - - public void setCommitBlockSettings(BftsmartCommitBlockSettings commitBlockSettings) { - this.commitBlockSettings = commitBlockSettings; - } +// @Override +// public BftsmartCommitBlockSettings getCommitBlockSettings() { +// return commitBlockSettings; +// } +// +// +// public void setCommitBlockSettings(BftsmartCommitBlockSettings commitBlockSettings) { +// this.commitBlockSettings = commitBlockSettings; +// } } diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettings.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettings.java index f4e24cf5..d3ce6494 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettings.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettings.java @@ -14,7 +14,7 @@ public interface BftsmartConsensusSettings extends ConsensusSettings { @DataField(order = 1, primitiveType = PrimitiveType.BYTES, list=true) Property[] getSystemConfigs(); - @DataField(order = 2, refContract = true) - BftsmartCommitBlockSettings getCommitBlockSettings(); +// @DataField(order = 2, refContract = true) +// BftsmartCommitBlockSettings getCommitBlockSettings(); } diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettingsBuilder.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettingsBuilder.java index 1311a3a2..e72f866a 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettingsBuilder.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/BftsmartConsensusSettingsBuilder.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.Properties; +import com.jd.blockchain.ledger.ParticipantNode; import com.jd.blockchain.tools.keygen.KeyGenCommand; import com.jd.blockchain.utils.PropertiesUtils; import com.jd.blockchain.utils.codec.Base58Utils; @@ -24,6 +25,8 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde private static final String CONFIG_TEMPLATE_FILE = "bftsmart.config"; + private static final String CONFIG_LEDGER_INIT = "ledger.init"; + /** * 参数键:节点数量; */ @@ -61,6 +64,8 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde */ public static final String CONSENSUS_SECURE_PATTERN = "system.server.%s.network.secure"; + + private static Properties CONFIG_TEMPLATE; static { ClassPathResource configResource = new ClassPathResource(CONFIG_TEMPLATE_FILE); @@ -74,31 +79,31 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde } //解析得到结块的相关配置信息 - public BftsmartCommitBlockConfig createBlockConfig(Properties resolvingProps) { - BftsmartCommitBlockConfig blockConfig = new BftsmartCommitBlockConfig(); - - String txSizeString = PropertiesUtils.getRequiredProperty(resolvingProps, BFTSMART_BLOCK_TXSIZE_KEY); - resolvingProps.remove(BFTSMART_BLOCK_TXSIZE_KEY); - - if (txSizeString == null || txSizeString.length() == 0) { - blockConfig.setTxSizePerBlock(DEFAULT_TXSIZE); - } - else { - blockConfig.setTxSizePerBlock(Integer.parseInt(txSizeString)); - } - - String maxDelayString = PropertiesUtils.getRequiredProperty(resolvingProps, BFTSMART_BLOCK_MAXDELAY_KEY); - resolvingProps.remove(BFTSMART_BLOCK_MAXDELAY_KEY); - - if (maxDelayString == null || maxDelayString.length() == 0) { - blockConfig.setMaxDelayMilliSecondsPerBlock(DEFAULT_MAXDELAY); - } - else { - blockConfig.setMaxDelayMilliSecondsPerBlock(Long.parseLong(maxDelayString)); - } - - return blockConfig; - } +// public BftsmartCommitBlockConfig createBlockConfig(Properties resolvingProps) { +// BftsmartCommitBlockConfig blockConfig = new BftsmartCommitBlockConfig(); +// +// String txSizeString = PropertiesUtils.getRequiredProperty(resolvingProps, BFTSMART_BLOCK_TXSIZE_KEY); +// resolvingProps.remove(BFTSMART_BLOCK_TXSIZE_KEY); +// +// if (txSizeString == null || txSizeString.length() == 0) { +// blockConfig.setTxSizePerBlock(DEFAULT_TXSIZE); +// } +// else { +// blockConfig.setTxSizePerBlock(Integer.parseInt(txSizeString)); +// } +// +// String maxDelayString = PropertiesUtils.getRequiredProperty(resolvingProps, BFTSMART_BLOCK_MAXDELAY_KEY); +// resolvingProps.remove(BFTSMART_BLOCK_MAXDELAY_KEY); +// +// if (maxDelayString == null || maxDelayString.length() == 0) { +// blockConfig.setMaxDelayMilliSecondsPerBlock(DEFAULT_MAXDELAY); +// } +// else { +// blockConfig.setMaxDelayMilliSecondsPerBlock(Long.parseLong(maxDelayString)); +// } +// +// return blockConfig; +// } @Override public Properties createPropertiesTemplate() { @@ -106,7 +111,7 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde } @Override - public BftsmartConsensusSettings createSettings(Properties props) { + public BftsmartConsensusSettings createSettings(Properties props, ParticipantNode[] participantNodes) { Properties resolvingProps = PropertiesUtils.cloneFrom(props); int serversNum = PropertiesUtils.getInt(resolvingProps, SERVER_NUM_KEY); if (serversNum < 0) { @@ -115,18 +120,26 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde if (serversNum < 4) { throw new IllegalArgumentException(String.format("Property[%s] is less than 4!", SERVER_NUM_KEY)); } + if (participantNodes == null) { + throw new IllegalArgumentException("ParticipantNodes is Empty !!!"); + } + if (serversNum != participantNodes.length) { + throw new IllegalArgumentException(String.format("Property[%s] which is [%s] unequal " + + "ParticipantNodes's length which is [%s] !", SERVER_NUM_KEY, serversNum, participantNodes.length)); + } - BftsmartCommitBlockConfig blockConfig = createBlockConfig(resolvingProps); +// BftsmartCommitBlockConfig blockConfig = createBlockConfig(resolvingProps); BftsmartNodeSettings[] nodesSettings = new BftsmartNodeSettings[serversNum]; for (int i = 0; i < serversNum; i++) { int id = i; - String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); - String base58PubKey = PropertiesUtils.getRequiredProperty(resolvingProps, keyOfPubkey); +// String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); +// String base58PubKey = PropertiesUtils.getRequiredProperty(resolvingProps, keyOfPubkey); // PubKey pubKey = new PubKey(Base58Utils.decode(base58PubKey)); - PubKey pubKey = KeyGenCommand.decodePubKey(base58PubKey); - resolvingProps.remove(keyOfPubkey); +// PubKey pubKey = KeyGenCommand.decodePubKey(base58PubKey); + PubKey pubKey = participantNodes[i].getPubKey(); +// resolvingProps.remove(keyOfPubkey); String keyOfHost = keyOfNode(CONSENSUS_HOST_PATTERN, id); String networkAddressHost = PropertiesUtils.getRequiredProperty(resolvingProps, keyOfHost); @@ -145,7 +158,8 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde nodesSettings[i] = nodeConfig; } - BftsmartConsensusConfig config = new BftsmartConsensusConfig(nodesSettings, blockConfig, + BftsmartConsensusConfig config = new BftsmartConsensusConfig(nodesSettings, +// blockConfig, PropertiesUtils.getOrderedValues(resolvingProps)); return config; } @@ -160,8 +174,8 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde if (serversNum > 0) { for (int i = 0; i < serversNum; i++) { int id = i; - String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); - props.remove(keyOfPubkey); +// String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); +// props.remove(keyOfPubkey); String keyOfHost = keyOfNode(CONSENSUS_HOST_PATTERN, id); props.remove(keyOfHost); @@ -180,22 +194,22 @@ public class BftsmartConsensusSettingsBuilder implements ConsensusSettingsBuilde props.setProperty(SERVER_NUM_KEY, serversNum + ""); //获得结块相关的属性信息 - BftsmartCommitBlockSettings blockSettings = bftsmartSettings.getCommitBlockSettings(); - if (blockSettings == null) { - props.setProperty(BFTSMART_BLOCK_TXSIZE_KEY, DEFAULT_TXSIZE + ""); - props.setProperty(BFTSMART_BLOCK_MAXDELAY_KEY, DEFAULT_MAXDELAY + ""); - } else { - int txSize = blockSettings.getTxSizePerBlock(); - long maxDelay = blockSettings.getMaxDelayMilliSecondsPerBlock(); - props.setProperty(BFTSMART_BLOCK_TXSIZE_KEY, txSize + ""); - props.setProperty(BFTSMART_BLOCK_MAXDELAY_KEY, maxDelay + ""); - } +// BftsmartCommitBlockSettings blockSettings = bftsmartSettings.getCommitBlockSettings(); +// if (blockSettings == null) { +// props.setProperty(BFTSMART_BLOCK_TXSIZE_KEY, DEFAULT_TXSIZE + ""); +// props.setProperty(BFTSMART_BLOCK_MAXDELAY_KEY, DEFAULT_MAXDELAY + ""); +// } else { +// int txSize = blockSettings.getTxSizePerBlock(); +// long maxDelay = blockSettings.getMaxDelayMilliSecondsPerBlock(); +// props.setProperty(BFTSMART_BLOCK_TXSIZE_KEY, txSize + ""); +// props.setProperty(BFTSMART_BLOCK_MAXDELAY_KEY, maxDelay + ""); +// } for (int i = 0; i < serversNum; i++) { BftsmartNodeSettings ns = nodesSettings[i]; int id = i; - String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); - props.setProperty(keyOfPubkey, ns.getPubKey().toBase58()); +// String keyOfPubkey = keyOfNode(PUBKEY_PATTERN, id); +// props.setProperty(keyOfPubkey, ns.getPubKey().toBase58()); String keyOfHost = keyOfNode(CONSENSUS_HOST_PATTERN, id); props.setProperty(keyOfHost, ns.getNetworkAddress() == null ? "" : ns.getNetworkAddress().getHost()); diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java index 215486d0..1e82ee0f 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartConsensusManageService.java @@ -34,26 +34,28 @@ public class BftsmartConsensusManageService implements ConsensusManageService { @Override public BftsmartClientIncomingSettings authClientIncoming(ClientIdentification authId) { if (verify(authId)) { - BftsmartClientIncomingSettings clientIncomingSettings = new BftsmartClientIncomingConfig(); + BftsmartClientIncomingConfig clientIncomingSettings = new BftsmartClientIncomingConfig(); - ((BftsmartClientIncomingConfig) clientIncomingSettings) + clientIncomingSettings .setTopology(BinarySerializeUtils.serialize(nodeServer.getTopology())); - ((BftsmartClientIncomingConfig) clientIncomingSettings) + + clientIncomingSettings .setTomConfig(BinarySerializeUtils.serialize(nodeServer.getTomConfig())); - ((BftsmartClientIncomingConfig) clientIncomingSettings) + + clientIncomingSettings .setConsensusSettings(nodeServer.getConsensusSetting()); - ((BftsmartClientIncomingConfig) clientIncomingSettings).setPubKey(authId.getPubKey()); + + clientIncomingSettings.setPubKey(authId.getPubKey()); // compute gateway id + authLock.lock(); try { - authLock.lock(); - ((BftsmartClientIncomingConfig) clientIncomingSettings).setClientId(clientId++); + clientIncomingSettings.setClientId(clientId++); clientId += CLIENT_SIZE_PER_GATEWAY; } finally { authLock.unlock(); } return clientIncomingSettings; - } return null; diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java index ce97797a..162ff130 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartNodeServer.java @@ -107,7 +107,7 @@ public class BftsmartNodeServer extends DefaultRecoverable implements NodeServer setting = ((BftsmartServerSettings) serverSettings).getConsensusSettings(); - List configList = new ArrayList(); + List configList = new ArrayList<>(); NodeSettings[] nodeSettingsArray = setting.getNodes(); for (NodeSettings nodeSettings : nodeSettingsArray) { diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettingConfig.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettingConfig.java index 16420932..3b42bb0d 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettingConfig.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettingConfig.java @@ -1,10 +1,7 @@ package com.jd.blockchain.consensus.bftsmart.service; import com.jd.blockchain.consensus.NodeSettings; -import com.jd.blockchain.consensus.bftsmart.BftsmartCommitBlockSettings; import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusSettings; -import com.jd.blockchain.consensus.bftsmart.BftsmartNodeSettings; -import com.jd.blockchain.consensus.service.ServerSettings; public class BftsmartServerSettingConfig implements BftsmartServerSettings { private NodeSettings replicaSettings; diff --git a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettings.java b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettings.java index 1cf627d2..f6806b96 100644 --- a/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettings.java +++ b/source/consensus/consensus-bftsmart/src/main/java/com/jd/blockchain/consensus/bftsmart/service/BftsmartServerSettings.java @@ -1,6 +1,5 @@ package com.jd.blockchain.consensus.bftsmart.service; -import com.jd.blockchain.consensus.bftsmart.BftsmartCommitBlockSettings; import com.jd.blockchain.consensus.bftsmart.BftsmartConsensusSettings; import com.jd.blockchain.consensus.service.ServerSettings; diff --git a/source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/proxyClientTest.java b/source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/ProxyClientTest.java similarity index 93% rename from source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/proxyClientTest.java rename to source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/ProxyClientTest.java index f597d8d0..3f32fd6b 100644 --- a/source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/proxyClientTest.java +++ b/source/consensus/consensus-bftsmart/src/test/java/test/com/jd/blockchain/consensus/bftsmart/ProxyClientTest.java @@ -26,7 +26,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -public class proxyClientTest { +public class ProxyClientTest { int number = 1500000; @@ -69,13 +69,14 @@ public class proxyClientTest { nodesSettings[i] = (BftsmartNodeSettings) node; } - BftsmartConsensusConfig consensusConfig = new BftsmartConsensusConfig(nodesSettings, null, + BftsmartConsensusConfig consensusConfig = new BftsmartConsensusConfig(nodesSettings, +// null, PropertiesUtils.getOrderedValues(bftsmartConf)); for (int j = 0; j < nodeNum; j++) { - ServerSettings serverSettings = new BftsmartServerSettingConfig(); - ((BftsmartServerSettingConfig) serverSettings).setReplicaSettings(nodesSettings[j]); - ((BftsmartServerSettingConfig) serverSettings).setConsensusSettings(consensusConfig); + BftsmartServerSettingConfig serverSettings = new BftsmartServerSettingConfig(); + serverSettings.setReplicaSettings(nodesSettings[j]); + serverSettings.setConsensusSettings(consensusConfig); BftsmartNodeServer server = new BftsmartNodeServer(serverSettings, null, null); nodeServers[j] = server; nodeStartPools.execute(() -> { diff --git a/source/consensus/consensus-framework/pom.xml b/source/consensus/consensus-framework/pom.xml index dd1150ea..a810d22b 100644 --- a/source/consensus/consensus-framework/pom.xml +++ b/source/consensus/consensus-framework/pom.xml @@ -25,5 +25,10 @@ utils-common ${project.version} + + com.jd.blockchain + ledger-model + ${project.version} + \ No newline at end of file diff --git a/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/ConsensusSettingsBuilder.java b/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/ConsensusSettingsBuilder.java index 8adc61dd..c4f46776 100644 --- a/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/ConsensusSettingsBuilder.java +++ b/source/consensus/consensus-framework/src/main/java/com/jd/blockchain/consensus/ConsensusSettingsBuilder.java @@ -1,5 +1,7 @@ package com.jd.blockchain.consensus; +import com.jd.blockchain.ledger.ParticipantNode; + import java.util.Properties; public interface ConsensusSettingsBuilder { @@ -9,13 +11,11 @@ public interface ConsensusSettingsBuilder { * * @param props * 属性表; - * @param keyPrefix - * 属性的key 的前缀;
- * 在解析过程中,以具体协议实现的标准参数的key 加入此前缀后从属性表中检索参数值;
- * 如果指定为 null 或者空白,则忽略此参数; + * @param participantNodes + * 参与方列表;
* @return */ - ConsensusSettings createSettings(Properties props); + ConsensusSettings createSettings(Properties props, ParticipantNode[] participantNodes); Properties createPropertiesTemplate(); diff --git a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/MsgQueueConsensusSettingsBuilder.java b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/MsgQueueConsensusSettingsBuilder.java index 839be6e0..85b1fbc3 100644 --- a/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/MsgQueueConsensusSettingsBuilder.java +++ b/source/consensus/consensus-mq/src/main/java/com/jd/blockchain/consensus/mq/MsgQueueConsensusSettingsBuilder.java @@ -21,6 +21,7 @@ import com.jd.blockchain.consensus.mq.settings.MsgQueueNetworkSettings; import com.jd.blockchain.consensus.mq.settings.MsgQueueNodeSettings; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.PubKey; +import com.jd.blockchain.ledger.ParticipantNode; import com.jd.blockchain.tools.keygen.KeyGenCommand; import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.PropertiesUtils; @@ -97,7 +98,7 @@ public class MsgQueueConsensusSettingsBuilder implements ConsensusSettingsBuilde } @Override - public MsgQueueConsensusSettings createSettings(Properties props) { + public MsgQueueConsensusSettings createSettings(Properties props, ParticipantNode[] participantNodes) { MsgQueueNetworkConfig networkConfig = new MsgQueueNetworkConfig(); Properties resolvingProps = PropertiesUtils.cloneFrom(props); diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/bftsmart.config b/source/deployment/deployment-peer/src/main/resources/config/init/bftsmart.config index 8c2ba5af..57e905b0 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/bftsmart.config +++ b/source/deployment/deployment-peer/src/main/resources/config/init/bftsmart.config @@ -13,22 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. - -############################################ -###### Consensus Commit Block Parameters: transaction count ###### -############################################ -system.block.txsize=15 - -############################################ -###### Consensus Commit Block Parameters: delay time ###### -############################################ -system.block.maxdelay=500 - ############################################ ###### #Consensus Participant0 ###### ############################################ -system.server.0.pubkey= system.server.0.network.host=127.0.0.1 system.server.0.network.port=16000 system.server.0.network.secure=false @@ -37,7 +25,6 @@ system.server.0.network.secure=false ###### #Consensus Participant1 ###### ############################################ -system.server.1.pubkey= system.server.1.network.host=127.0.0.1 system.server.1.network.port=16010 system.server.1.network.secure=false @@ -46,7 +33,6 @@ system.server.1.network.secure=false ###### #Consensus Participant2 ###### ############################################ -system.server.2.pubkey= system.server.2.network.host=127.0.0.1 system.server.2.network.port=16020 system.server.2.network.secure=false @@ -55,7 +41,6 @@ system.server.2.network.secure=false ###### #Consensus Participant3 ###### ############################################ -system.server.3.pubkey= system.server.3.network.host=127.0.0.1 system.server.3.network.port=16030 system.server.3.network.secure=false diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init index 9df38d79..057e9966 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init +++ b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init @@ -1,10 +1,11 @@ - #账本的种子;一段16进制字符,最长可以包含64个字符;可以用字符“-”分隔,以便更容易读取; ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe #账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; ledger.name= +#声明的账本创建时间;格式为 “yyyy-MM-dd HH:mm:ss.SSSZ”,表示”年-月-日 时:分:秒:毫秒时区“;例如:“2019-08-01 14:26:58.069+0800”,其中,+0800 表示时区是东8区 +created-time=2019-08-01 14:26:58.069+0800 #共识服务提供者;必须; consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider @@ -21,36 +22,24 @@ com.jd.blockchain.crypto.service.sm.SMCryptoService cons_parti.count=4 #第0个参与方的名称; -cons_parti.0.name=jd.com +cons_parti.0.name= #第0个参与方的公钥文件路径; -cons_parti.0.pubkey-path=keys/jd-com.pub +cons_parti.0.pubkey-path= #第0个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; -cons_parti.0.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 -#第0个参与方的共识服务的主机地址; -cons_parti.0.consensus.host=127.0.0.1 -#第0个参与方的共识服务的端口; -cons_parti.0.consensus.port=8900 -#第0个参与方的共识服务是否开启安全连接; -cons_parti.0.consensus.secure=true +cons_parti.0.pubkey= #第0个参与方的账本初始服务的主机; cons_parti.0.initializer.host=127.0.0.1 #第0个参与方的账本初始服务的端口; cons_parti.0.initializer.port=8800 #第0个参与方的账本初始服务是否开启安全连接; -cons_parti.0.initializer.secure=true +cons_parti.0.initializer.secure=false #第1个参与方的名称; -cons_parti.1.name=at.com +cons_parti.1.name= #第1个参与方的公钥文件路径; -cons_parti.1.pubkey-path=keys/at-com.pub +cons_parti.1.pubkey-path= #第1个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; -cons_parti.1.pubkey=3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX -#第1个参与方的共识服务的主机地址; -cons_parti.1.consensus.host=127.0.0.1 -#第1个参与方的共识服务的端口; -cons_parti.1.consensus.port=8910 -#第1个参与方的共识服务是否开启安全连接; -cons_parti.1.consensus.secure=false +cons_parti.1.pubkey= #第1个参与方的账本初始服务的主机; cons_parti.1.initializer.host=127.0.0.1 #第1个参与方的账本初始服务的端口; @@ -59,36 +48,24 @@ cons_parti.1.initializer.port=8810 cons_parti.1.initializer.secure=false #第2个参与方的名称; -cons_parti.2.name=bt.com +cons_parti.2.name= #第2个参与方的公钥文件路径; -cons_parti.2.pubkey-path=classpath:keys/parti2.pub +cons_parti.2.pubkey-path= #第2个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; cons_parti.2.pubkey= -#第2个参与方的共识服务的主机地址; -cons_parti.2.consensus.host=127.0.0.1 -#第2个参与方的共识服务的端口; -cons_parti.2.consensus.port=8920 -#第2个参与方的共识服务是否开启安全连接; -cons_parti.2.consensus.secure=false #第2个参与方的账本初始服务的主机; cons_parti.2.initializer.host=127.0.0.1 #第2个参与方的账本初始服务的端口; cons_parti.2.initializer.port=8820 #第2个参与方的账本初始服务是否开启安全连接; -cons_parti.2.initializer.secure=true +cons_parti.2.initializer.secure=false #第3个参与方的名称; -cons_parti.3.name=xt.com +cons_parti.3.name= #第3个参与方的公钥文件路径; -cons_parti.3.pubkey-path=keys/xt-com.pub +cons_parti.3.pubkey-path= #第3个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; -cons_parti.3.pubkey=3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk -#第3个参与方的共识服务的主机地址; -cons_parti.3.consensus.host=127.0.0.1 -#第3个参与方的共识服务的端口; -cons_parti.3.consensus.port=8930 -#第3个参与方的共识服务是否开启安全连接; -cons_parti.3.consensus.secure=false +cons_parti.3.pubkey= #第3个参与方的账本初始服务的主机; cons_parti.3.initializer.host=127.0.0.1 #第3个参与方的账本初始服务的端口; diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/local.conf b/source/deployment/deployment-peer/src/main/resources/config/init/local.conf index 27652184..2a5392c5 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/local.conf +++ b/source/deployment/deployment-peer/src/main/resources/config/init/local.conf @@ -20,5 +20,4 @@ ledger.binding.out=../ ledger.db.uri= #账本数据库的连接口令 -ledger.db.pwd= - +ledger.db.pwd= \ No newline at end of file diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger-init.conf b/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger-init.conf deleted file mode 100644 index 38b1788a..00000000 --- a/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger-init.conf +++ /dev/null @@ -1,66 +0,0 @@ -#账本的种子;一段16进制字符,最长可以包含64个字符;可以用字符“-”分隔,以便更容易读取; -ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe - -#账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; -#ledger.name= - -#参与方的个数,后续以 cons_parti.id 分别标识每一个参与方的配置; -cons_parti.count=4 - - -#第0个参与方的名称 -cons_parti.0.name=xx-0.com -#第0个参与方的公钥文件路径 -cons_parti.0.pubkey-path= -#第0个参与方的公钥内容(由keygen工具生成),此参数优先于 pubkey-path 参数 -cons_parti.0.pubkey=endPsK36koyFr1D245Sa9j83vt6pZUdFBJoJRB3xAsWM6cwhRbna -#第0个参与方的账本初始服务的主机 -cons_parti.0.initializer.host=127.0.0.1 -#第0个参与方的账本初始服务的端口 -cons_parti.0.initializer.port=17000 -#第0个参与方的账本初始服务是否开启安全连接 -cons_parti.0.initializer.secure=false - - -#第1个参与方的名称 -cons_parti.1.name=xx-1.com -#第1个参与方的公钥文件路径 -cons_parti.1.pubkey-path= -#第1个参与方的公钥内容(由keygen工具生成),此参数优先于 pubkey-path 参数 -cons_parti.1.pubkey=endPsK36sC5JdPCDPDAXUwZtS3sxEmqEhFcC4whayAsTTh8Z6eoZ -#第1个参与方的账本初始服务的主机 -cons_parti.1.initializer.host=127.0.0.1 -#第1个参与方的账本初始服务的端口 -cons_parti.1.initializer.port=17010 -#第1个参与方的账本初始服务是否开启安全连接 -cons_parti.1.initializer.secure=false - - -#第2个参与方的名称 -cons_parti.2.name=xx-2.com -#第2个参与方的公钥文件路径 -cons_parti.2.pubkey-path= -#第2个参与方的公钥内容(由keygen工具生成),此参数优先于 pubkey-path 参数 -cons_parti.2.pubkey=endPsK36jEG281HMHeh6oSqzqLkT95DTnCM6REDURjdb2c67uR3R -#第2个参与方的账本初始服务的主机 -cons_parti.2.initializer.host=127.0.0.1 -#第2个参与方的账本初始服务的端口 -cons_parti.2.initializer.port=17020 -#第2个参与方的账本初始服务是否开启安全连接 -cons_parti.2.initializer.secure=false - - -#第3个参与方的名称 -cons_parti.3.name=xx-3.com -#第3个参与方的公钥文件路径 -cons_parti.3.pubkey-path= -#第3个参与方的公钥内容(由keygen工具生成),此参数优先于 pubkey-path 参数 -cons_parti.3.pubkey=endPsK36nse1dck4uF19zPvAMijCV336Y3zWdgb4rQG8QoRj5ktR -#第3个参与方的账本初始服务的主机 -cons_parti.3.initializer.host=127.0.0.1 -#第3个参与方的账本初始服务的端口 -cons_parti.3.initializer.port=17030 -#第3个参与方的账本初始服务是否开启安全连接 -cons_parti.3.initializer.secure=false - - diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init b/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init new file mode 100644 index 00000000..f7e7d593 --- /dev/null +++ b/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init @@ -0,0 +1,74 @@ +#账本的种子;一段16进制字符,最长可以包含64个字符;可以用字符“-”分隔,以便更容易读取; +ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe + +#账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; +ledger.name= + +#声明的账本创建时间;格式为 “yyyy-MM-dd HH:mm:ss.SSSZ”,表示”年-月-日 时:分:秒:毫秒时区“;例如:“2019-08-01 14:26:58.069+0800”,其中,+0800 表示时区是东8区 +created-time=2019-08-01 14:26:58.069+0800 + +#共识服务提供者;必须; +consensus.service-provider=com.jd.blockchain.consensus.mq.MsgQueueConsensusProvider + +#共识服务的参数配置;必须; +consensus.conf=classpath:mq.config + +#密码服务提供者列表,以英文逗点“,”分隔;必须; +crypto.service-providers=com.jd.blockchain.crypto.service.classic.ClassicCryptoService, \ +com.jd.blockchain.crypto.service.sm.SMCryptoService + + +#参与方的个数,后续以 cons_parti.id 分别标识每一个参与方的配置; +cons_parti.count=4 + +#第0个参与方的名称; +cons_parti.0.name=jd.com +#第0个参与方的公钥文件路径; +cons_parti.0.pubkey-path=keys/jd-com.pub +#第0个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; +cons_parti.0.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 +#第0个参与方的账本初始服务的主机; +cons_parti.0.initializer.host=127.0.0.1 +#第0个参与方的账本初始服务的端口; +cons_parti.0.initializer.port=8800 +#第0个参与方的账本初始服务是否开启安全连接; +cons_parti.0.initializer.secure=false + +#第1个参与方的名称; +cons_parti.1.name=at.com +#第1个参与方的公钥文件路径; +cons_parti.1.pubkey-path=keys/at-com.pub +#第1个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; +cons_parti.1.pubkey=3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX +#第1个参与方的账本初始服务的主机; +cons_parti.1.initializer.host=127.0.0.1 +#第1个参与方的账本初始服务的端口; +cons_parti.1.initializer.port=8810 +#第1个参与方的账本初始服务是否开启安全连接; +cons_parti.1.initializer.secure=false + +#第2个参与方的名称; +cons_parti.2.name=bt.com +#第2个参与方的公钥文件路径; +cons_parti.2.pubkey-path=classpath:keys/parti2.pub +#第2个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; +cons_parti.2.pubkey= +#第2个参与方的账本初始服务的主机; +cons_parti.2.initializer.host=127.0.0.1 +#第2个参与方的账本初始服务的端口; +cons_parti.2.initializer.port=8820 +#第2个参与方的账本初始服务是否开启安全连接; +cons_parti.2.initializer.secure=false + +#第3个参与方的名称; +cons_parti.3.name=xt.com +#第3个参与方的公钥文件路径; +cons_parti.3.pubkey-path=keys/xt-com.pub +#第3个参与方的公钥内容(由keygen工具生成);此参数优先于 pubkey-path 参数; +cons_parti.3.pubkey=3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk +#第3个参与方的账本初始服务的主机; +cons_parti.3.initializer.host=127.0.0.1 +#第3个参与方的账本初始服务的端口; +cons_parti.3.initializer.port=8830 +#第3个参与方的账本初始服务是否开启安全连接; +cons_parti.3.initializer.secure=false diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/mq/local.conf b/source/deployment/deployment-peer/src/main/resources/config/init/mq/local.conf index 08e99b84..2a5392c5 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/mq/local.conf +++ b/source/deployment/deployment-peer/src/main/resources/config/init/mq/local.conf @@ -2,31 +2,22 @@ local.parti.id=0 #当前参与方的公钥 -local.parti.pubkey=endPsK36koyFr1D245Sa9j83vt6pZUdFBJoJRB3xAsWM6cwhRbna +local.parti.pubkey= #当前参与方的私钥(密文编码) -local.parti.privkey=177gjsj5PHeCpbAtJE7qnbmhuZMHAEKuMsd45zHkv8F8AWBvTBbff8yRKdCyT3kwrmAjSnY +local.parti.privkey= #当前参与方的私钥解密密钥(原始口令的一次哈希,Base58格式),如果不设置,则启动过程中需要从控制台输入 -local.parti.pwd=DYu3G8aGTMBW1WrTw76zxQJQU4DHLw9MLyy7peG4LKkY +local.parti.pwd= #账本初始化完成后生成的"账本绑定配置文件"的输出目录 #推荐使用绝对路径,相对路径以当前文件(local.conf)所在目录为基准 ledger.binding.out=../ #账本数据库的连接字符 -#rocksdb数据库连接格式:rocksdb://{path} -#redis数据库连接格式:redis://{ip}:{prot}/{db} -ledger.db.uri=rocksdb:///export/App08/peer/rocks.db/rocksdb0.db +#rocksdb数据库连接格式:rocksdb://{path},例如:rocksdb:///export/App08/peer/rocks.db/rocksdb0.db +#redis数据库连接格式:redis://{ip}:{prot}/{db},例如:redis://127.0.0.1:6379/0 +ledger.db.uri= #账本数据库的连接口令 -ledger.db.pwd= - -#共识配置文件路径 -#推荐使用绝对路径,相对路径以当前文件(local.conf)所在目录为基准 -consensus.conf=mq.config - -#共识Providers配置 -#BftSmart共识Provider:com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider -#简单消息共识Provider:com.jd.blockchain.consensus.mq.MsgQueueConsensusProvider -consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider +ledger.db.pwd= \ No newline at end of file diff --git a/source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh b/source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh index e30a91c6..c9f3db47 100644 --- a/source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh +++ b/source/deployment/deployment-peer/src/main/resources/scripts/ledger-init.sh @@ -5,5 +5,5 @@ boot_file=$(ls ../libs | grep tools-initializer-booter-) if [ ! -n "$boot_file" ]; then echo "tools-initializer-booter is null" else - java -jar $HOME/libs/$boot_file -l $HOME/config/init/local.conf -i $HOME/config/init/ledger-init.conf $* + java -jar $HOME/libs/$boot_file -l $HOME/config/init/local.conf -i $HOME/config/init/ledger.init $* fi diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java index d83272f7..a7051431 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java @@ -52,6 +52,7 @@ import com.jd.blockchain.utils.net.NetworkAddress; import test.com.jd.blockchain.intgr.IntegratedContext.Node; import test.com.jd.blockchain.intgr.perf.LedgerInitializeWebTest; +import test.com.jd.blockchain.intgr.perf.Utils; public class IntegrationTest { // 合约测试使用的初始化数据; @@ -435,7 +436,9 @@ public class IntegrationTest { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = LedgerInitializeWebTest.loadConsensusSetting(); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); 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 d7f66545..9eb45aee 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 @@ -188,7 +188,9 @@ public class ConsensusTest { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = Utils.loadConsensusSetting(); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); 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 a35584c0..f4c21fe7 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 @@ -186,7 +186,9 @@ public class GlobalPerformanceTest { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = Utils.loadConsensusSetting(); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); 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 fe0d8bbc..569472d9 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 @@ -75,7 +75,9 @@ public class LedgerInitializeWebTest { Properties props = loadConsensusSetting(); // ConsensusProperties csProps = new ConsensusProperties(props); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); @@ -240,7 +242,9 @@ public class LedgerInitializeWebTest { Properties props = loadConsensusSetting(); // ConsensusProperties csProps = new ConsensusProperties(props); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java index 25a40ad0..76f3a1e7 100644 --- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java +++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java @@ -495,7 +495,9 @@ public class LedgerPerformanceTest { LedgerInitProperties initSetting = loadInitSetting(); Properties props = loadConsensusSetting(config); ConsensusProvider csProvider = getConsensusProvider(provider); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); DBSetting dbsetting0; DBSetting dbsetting1; 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 b5bcd809..80b133ad 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 @@ -9,6 +9,8 @@ import java.util.concurrent.ConcurrentHashMap; import com.jd.blockchain.crypto.*; import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; import com.jd.blockchain.crypto.service.sm.SMCryptoService; +import com.jd.blockchain.ledger.ParticipantNode; +import com.jd.blockchain.tools.keygen.KeyGenCommand; import org.springframework.core.io.ClassPathResource; import com.jd.blockchain.consensus.ConsensusProvider; @@ -72,6 +74,14 @@ public class Utils { } } + public static ParticipantNode[] loadParticipantNodes() { + ParticipantNode[] participantNodes = new ParticipantNode[PUB_KEYS.length]; + for (int i = 0; i < PUB_KEYS.length; i++) { + participantNodes[i] = new PartNode(i, KeyGenCommand.decodePubKey(PUB_KEYS[i])); + } + return participantNodes; + } + public static class NodeContext { private LedgerManager ledgerManager = new LedgerManager(); @@ -215,4 +225,46 @@ public class Utils { } + private static class PartNode implements ParticipantNode { + + private int id; + + private String address; + + private String name; + + private PubKey pubKey; + + public PartNode(int id, PubKey pubKey) { + this(id, id + "", pubKey); + } + + public PartNode(int id, String name, PubKey pubKey) { + this.id = id; + this.name = name; + this.pubKey = pubKey; + this.address = pubKey.toBase58(); + } + + @Override + public int getId() { + return id; + } + + @Override + public String getAddress() { + return address; + } + + @Override + public String getName() { + return name; + } + + @Override + public PubKey getPubKey() { + return pubKey; + } + } + } diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBaseTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBaseTest.java index 0703ef98..0fb2d461 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBaseTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBaseTest.java @@ -29,6 +29,7 @@ import com.jd.blockchain.utils.net.NetworkAddress; import test.com.jd.blockchain.intgr.IntegratedContext.Node; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest.NodeWebContext; +import test.com.jd.blockchain.intgr.perf.Utils; public class IntegrationBaseTest { @@ -122,7 +123,9 @@ public class IntegrationBaseTest { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = LedgerInitializeWeb4SingleStepsTest.loadConsensusSetting(configPath); ConsensusProvider csProvider = LedgerInitConsensusConfig.getConsensusProvider(providerName); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest2.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest2.java index f1f5288c..3e5a1e85 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest2.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest2.java @@ -42,6 +42,7 @@ import test.com.jd.blockchain.intgr.IntegratedContext.Node; import test.com.jd.blockchain.intgr.contract.AssetContract; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest.NodeWebContext; +import test.com.jd.blockchain.intgr.perf.Utils; /** * 测试合约,提交后不立即进行验证,因为此时可能还没有完成正式结块; @@ -160,7 +161,9 @@ public class IntegrationTest2 { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = LedgerInitializeWeb4SingleStepsTest.loadConsensusSetting(config.getConfigPath()); ConsensusProvider csProvider = LedgerInitConsensusConfig.getConsensusProvider(config.getProvider()); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestDataAccount.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestDataAccount.java index e031d763..41d8c800 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestDataAccount.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestDataAccount.java @@ -46,6 +46,7 @@ import com.jd.blockchain.utils.net.NetworkAddress; import test.com.jd.blockchain.intgr.IntegratedContext.Node; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeWeb4SingleStepsTest.NodeWebContext; +import test.com.jd.blockchain.intgr.perf.Utils; public class IntegrationTestDataAccount { @@ -257,7 +258,9 @@ public class IntegrationTestDataAccount { LedgerInitProperties initSetting = loadInitSetting_integration(); Properties props = LedgerInitializeWeb4SingleStepsTest.loadConsensusSetting(config.getConfigPath()); ConsensusProvider csProvider = LedgerInitConsensusConfig.getConsensusProvider(config.getProvider()); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); 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 ef18078f..a37afc62 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 @@ -27,6 +27,7 @@ import org.springframework.core.io.ClassPathResource; import test.com.jd.blockchain.intgr.IntegrationBase; import test.com.jd.blockchain.intgr.LedgerInitConsensusConfig; import test.com.jd.blockchain.intgr.PresetAnswerPrompter; +import test.com.jd.blockchain.intgr.perf.Utils; import java.io.IOException; import java.io.InputStream; @@ -70,7 +71,9 @@ public class LedgerInitializeWeb4Nodes { LedgerInitProperties initSetting = loadInitSetting_2(); Properties props = loadConsensusSetting(config.getConfigPath()); ConsensusProvider csProvider = LedgerInitConsensusConfig.getConsensusProvider(config.getProvider()); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); 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 3426b296..875dda05 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 @@ -50,6 +50,7 @@ import com.jd.blockchain.utils.net.NetworkAddress; import test.com.jd.blockchain.intgr.LedgerInitConsensusConfig; import test.com.jd.blockchain.intgr.PresetAnswerPrompter; +import test.com.jd.blockchain.intgr.perf.Utils; public class LedgerInitializeWeb4SingleStepsTest { @@ -77,7 +78,9 @@ public class LedgerInitializeWeb4SingleStepsTest { // 加载共识配置; Properties props = loadConsensusSetting(consensusConfig.getConfigPath()); ConsensusProvider csProvider = LedgerInitConsensusConfig.getConsensusProvider(consensusConfig.getProvider()); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); // 启动服务器; NetworkAddress initAddr0 = initSetting.getConsensusParticipant(0).getInitializerAddress(); diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java index 77bdef66..306d065f 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java @@ -45,6 +45,7 @@ import com.jd.blockchain.utils.net.NetworkAddress; import test.com.jd.blockchain.intgr.PresetAnswerPrompter; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeTest; import test.com.jd.blockchain.intgr.initializer.LedgerInitializeTest.NodeContext; +import test.com.jd.blockchain.intgr.perf.Utils; public class LedgerBlockGeneratingTest { @@ -128,7 +129,9 @@ public class LedgerBlockGeneratingTest { LedgerInitProperties initSetting = loadInitSetting(); Properties props = loadConsensusSetting(); ConsensusProvider csProvider = getConsensusProvider(); - ConsensusSettings csProps = csProvider.getSettingsFactory().getConsensusSettingsBuilder().createSettings(props); + ConsensusSettings csProps = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(props, Utils.loadParticipantNodes()); NodeContext node0 = new NodeContext(initSetting.getConsensusParticipant(0).getInitializerAddress(), serviceRegisterMap); diff --git a/source/test/test-integration/src/test/resources/bftsmart.config b/source/test/test-integration/src/test/resources/bftsmart.config index c68e39fd..80ed0f6a 100644 --- a/source/test/test-integration/src/test/resources/bftsmart.config +++ b/source/test/test-integration/src/test/resources/bftsmart.config @@ -14,58 +14,36 @@ # limitations under the License. -############################################ -###### Consensus Commit Block Parameters: transaction count ###### -############################################ -system.block.txsize=15 - -############################################ -###### Consensus Commit Block Parameters: delay time ###### -############################################ -system.block.maxdelay=500 - ############################################ ###### Consensus Participant0 ###### ############################################ -system.server.0.pubkey=3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9 system.server.0.network.host=127.0.0.1 - system.server.0.network.port=8910 - system.server.0.network.secure=false ############################################ ###### #Consensus Participant1 ###### ############################################ -system.server.1.pubkey=3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX system.server.1.network.host=127.0.0.1 - system.server.1.network.port=8920 - system.server.1.network.secure=false ############################################ ###### #Consensus Participant2 ###### ############################################ -system.server.2.pubkey=3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x system.server.2.network.host=127.0.0.1 - system.server.2.network.port=8930 - system.server.2.network.secure=false ############################################ ###### Consensus Participant3 ###### ############################################ -system.server.3.pubkey=3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk system.server.3.network.host=127.0.0.1 - system.server.3.network.port=8940 - system.server.3.network.secure=false ############################################ @@ -174,5 +152,4 @@ system.ttp.id = 7002 system.bft = true #Custom View Storage; -#view.storage.handler=bftsmart.reconfiguration.views.DefaultViewStorage - +#view.storage.handler=bftsmart.reconfiguration.views.DefaultViewStorage \ No newline at end of file diff --git a/source/test/test-integration/src/test/resources/ledger.init b/source/test/test-integration/src/test/resources/ledger.init index 9df38d79..48e74994 100644 --- a/source/test/test-integration/src/test/resources/ledger.init +++ b/source/test/test-integration/src/test/resources/ledger.init @@ -5,7 +5,6 @@ ledger.seed=932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323 #账本的描述名称;此属性不参与共识,仅仅在当前参与方的本地节点用于描述用途; ledger.name= - #共识服务提供者;必须; consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java index ee6be810..5a6ed045 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java @@ -95,6 +95,14 @@ public class LedgerInitProperties { return consensusParticipants; } + public ParticipantNode[] getConsensusParticipantNodes() { + if (consensusParticipants.isEmpty()) { + return null; + } + ParticipantNode[] participantNodes = new ParticipantNode[consensusParticipants.size()]; + return consensusParticipants.toArray(participantNodes); + } + public String[] getCryptoProviders() { return cryptoProviders.clone(); } @@ -106,7 +114,7 @@ public class LedgerInitProperties { /** * 返回参与者; * - * @param address 从 1 开始; 小于等于 {@link #getConsensusParticipantCount()}; + * @param id 从 1 开始; 小于等于 {@link #getConsensusParticipantCount()}; * @return */ public ConsensusParticipantConfig getConsensusParticipant(int id) { 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 15546d9e..22002841 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 @@ -181,8 +181,9 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI Properties csProps = ledgerInitProps.getConsensusConfig(); ConsensusProvider csProvider = ConsensusProviders.getProvider(ledgerInitProps.getConsensusProvider()); - ConsensusSettings csSettings = csProvider.getSettingsFactory().getConsensusSettingsBuilder() - .createSettings(csProps); + ConsensusSettings csSettings = csProvider.getSettingsFactory() + .getConsensusSettingsBuilder() + .createSettings(csProps, ledgerInitProps.getConsensusParticipantNodes()); setConsensusProvider(csProvider); prompter.info("Init settings and sign permision..."); @@ -335,7 +336,9 @@ public class LedgerInitializeWebController implements LedgerInitProcess, LedgerI initSetting.setCryptoSetting(cryptoSetting); List partiList = ledgerProps.getConsensusParticipants(); - ConsensusParticipantConfig[] parties = partiList.toArray(new ConsensusParticipantConfig[partiList.size()]); + ConsensusParticipantConfig[] parties = new ConsensusParticipantConfig[partiList.size()]; + parties = partiList.toArray(parties); +// ConsensusParticipantConfig[] parties = partiList.toArray(new ConsensusParticipantConfig[partiList.size()]); ConsensusParticipantConfig[] orderedParties = sortAndVerify(parties); initSetting.setConsensusParticipants(orderedParties); initSetting.setCreatedTime(ledgerProps.getCreatedTime()); From 4edfe964ec0512b009ba909383cbe33213e8fc91 Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Fri, 21 Jun 2019 17:42:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1=E3=80=81Fixed=20get=20consensus=20file=20?= =?UTF-8?q?error=20=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contract/jvm/JavaContractCode.java | 4 +- .../src/main/resources/config/gateway.conf | 3 +- .../src/main/resources/docs/api_doc_cn_1.4.MD | 2083 +++++++++++++++++ .../main/resources/config/init/ledger.init | 2 +- .../initializer/LedgerInitProperties.java | 9 +- .../com/jd/blockchain/utils/io/FileUtils.java | 23 + 6 files changed, 2118 insertions(+), 6 deletions(-) create mode 100644 source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD diff --git a/source/contract/contract-jvm/src/main/java/com/jd/blockchain/contract/jvm/JavaContractCode.java b/source/contract/contract-jvm/src/main/java/com/jd/blockchain/contract/jvm/JavaContractCode.java index c6b7c5b9..fa4d8260 100644 --- a/source/contract/contract-jvm/src/main/java/com/jd/blockchain/contract/jvm/JavaContractCode.java +++ b/source/contract/contract-jvm/src/main/java/com/jd/blockchain/contract/jvm/JavaContractCode.java @@ -68,7 +68,7 @@ public class JavaContractCode extends AbstractContractCode { @Override public BytesValue processEvent(ContractEventContext eventContext) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Start processing event[%s] of contract[%s]...", eventContext.getEvent(), address.toString()); + LOGGER.debug("Start processing event{} of contract{}...", eventContext.getEvent(), address.toString()); } try { return codeModule.call(new ContractExecution(eventContext)); @@ -78,7 +78,7 @@ public class JavaContractCode extends AbstractContractCode { throw ex; } finally { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("End processing event[%s] of contract[%s]. ", eventContext.getEvent(), address.toString()); + LOGGER.debug("End processing event{} of contract{}. ", eventContext.getEvent(), address.toString()); } } } diff --git a/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf b/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf index d2913069..1fc0594c 100644 --- a/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf +++ b/source/deployment/deployment-gateway/src/main/resources/config/gateway.conf @@ -1,4 +1,4 @@ -#网关的HTTP服务地址; +#网关的HTTP服务地址,建议直接使用0.0.0.0; http.host=0.0.0.0 #网关的HTTP服务端口; http.port=8081 @@ -18,6 +18,7 @@ peer.providers=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider #数据检索服务对应URL,格式:http://{ip}:{port},例如:http://127.0.0.1:10001 #若该值不配置或配置不正确,则浏览器模糊查询部分无法正常显示 +#数据检索服务模块(Argus)需单独部署,若不部署其他功能仍可正常使用 data.retrieval.url=http://127.0.0.1:10001 #默认公钥的内容(Base58编码数据); diff --git a/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD b/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD new file mode 100644 index 00000000..7ff79c96 --- /dev/null +++ b/source/deployment/deployment-gateway/src/main/resources/docs/api_doc_cn_1.4.MD @@ -0,0 +1,2083 @@ +# 京东区块链浏览器API文档参考 V_1.4 + +## 1 API调用说明 + +该文档内的所有api的调用成功和失败均按照以下规则 + +### 1.1 成功 + +```json +{ + "data": ..., + "success": true +} +``` + +说明 + + - success 值为 true 表明api调用成功 + - data 为返回的数据,具体数据类型参考具体的api说明 + +### 1.2 失败 + +```json +{ + "error": { + "errorCode": 5000, + "errorMessage": "未预期的异常! --Unsupported access ledger[6Gw3cK4uazegy4HjoaM81ck9NgYLNoKyBMb7a1TK1jt3d] !" + }, + "success": false +} +``` + +说明 + + - success 值为 false 表明api调用成功 + - errorCode 为异常代码 + - errorMessage 为错误提示 + +## 2 账本 + +### 2.1 获取账本总数 + +```http +GET /ledgers/count +``` + +#### 参数 +无 + + +#### 请求实例 +```http +http://localhost/ledgers/count +``` + +#### 返回实例 + +```json +{ + "data": 2, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账本总数| + + +### 2.2 获取账本列表 + +```http +GET /ledgers?fromIndex={start_index}&count={count} +``` + +#### 参数 +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|query|start_index|否|查询账本的起始序号,默认为0|数字 +|query|count|否|查询返回账本的数量限制,默认最大限制为100,小于0或大于100均返回最大可返回结果集|数字 + + +#### 请求实例 +```http +http://localhost/ledgers?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data": [ + { + "value": "657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs" + } + ], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账本哈希列表| +|value|账户哈希| + +### 2.3 获取账本详细信息 + +```http +GET /ledgers/{ledger} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs +``` + +#### 返回实例 + +```json +{ + "data": { + "hash": { + "value": "657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs" + }, + "latestBlockHash": { + "value": "67XsKWgqZTBz1NsytKGpyNWHMbMRENWcBj8PEDYQnWiDL" + }, + "latestBlockHeight": 66 + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账本信息| +|hash.value|账本哈希| +|latestBlockHash.value|最新区块哈希 +|latestBlockHeight|账本高度 + + +### 2.4 获取账本成员总数 + +```http +GET /ledgers/{ledger}/participants/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/participants/count +``` + +#### 返回实例 + +```json +{ + "data": 4, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账本成员总数| + + +### 2.5 获取账本成员列表 + +```http +GET /ledgers/{ledger}/participants?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|query|start_index|否|查询成员起始序号,默认为0|数字 +|query|count|否|查询成员返回数量,默认最大返回100,小于0或大于100均返回最大可返回结果集|数字 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/participants?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data": [ + { + "address": "5SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522", + "name": "jd.com", + "id": 0, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + } + }, + { + "address": "5SmA98VknTbZ1Z7fmbNPHBuN2pbD89ogy8Ha", + "name": "at.com", + "id": 1, + "pubKey": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + }, + { + "address": "5SmMWsqV2kbgrRMjyQFtSq1wvYuPzeRVepHG", + "name": "bt.com", + "id": 2, + "pubKey": { + "value": "mb4AtiGAH7vtPufMDuap2oca2Ww9X6KTkp59Eh5nZjXA5H" + } + }, + { + "address": "5Sm5QFyvN1dVB4GHFxWhDCp8vsJbNkdx31Ds", + "name": "xt.com", + "id": 3, + "pubKey": { + "value": "mb7pGhmmjqYUhxrJJ57C1YxXr9h1AWXv8QVosETyuLhVvH" + } + } + ], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|id|成员唯一标识| +|name|成员名称| +|address|成员地址| +|pubKey.value|成员公钥| + + + +### 2.6 获取账本元数据信息 + +```http +GET /ledgers/{ledger}/metadata +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/metadata +``` + +#### 返回实例 + +```json +{ + "data": { + "participantsHash": { + "value": "j5hQErg4epzNh38FR3EABx8YJqPkLYZoY828giAyKpCXMd" + }, + "seed": "ky3+I/4jIy8oPzL63TKqdoMiyi9WI2zacTazIssyP/4=", + "setting": { + "consensusProvider": "com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider", + "cryptoSetting": { + "supportedProviders": [{ + "algorithms": [{}, {}, {}, {}, {}, {}, {}], + "name": "com.jd.blockchain.crypto.service.classic.ClassicCryptoService" + }, { + "algorithms": [{}, {}, {}], + "name": "com.jd.blockchain.crypto.service.sm.SMCryptoService" + }], + "autoVerifyHash": true, + "hashAlgorithm": 8216 + }, + "consensusSetting": { + "value": "112ky33NcTKBkV..." + } + } + }, + "success": true +} + +``` + +说明 + +|名称|说明| +|---|---| +|seed|账本生成种子| +|consensusSetting|共识配置,每种共识不同,需独立解析| + + + + +### 2.7 获取账本配置信息 + +```http +GET /ledgers/{ledger}/settings +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/settings +``` + +#### 返回实例 + +```json + +{ + "data": { + "consensusProtocol": "com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider", + "consensusSettings": { + "nodes": [{ + "address": "LdeNgXM4J1SybrdUn71KdPhwBYvJzZ6xUG5Rd", + "id": 0, + "networkAddress": { + "host": "127.0.0.1", + "port": 26000, + "secure": false + }, + "pubKey": { + "value": "7VeRMXAkf3zoqr4N2RgLZ83xAv7wurqu6Vxak1V1GHv4Kfe3" + } + }, { + "address": "LdeNwbLhiAHQCVxnXsyKLhgcmUi2fuwYd6jkh", + "id": 1, + "networkAddress": { + "host": "127.0.0.1", + "port": 26010, + "secure": false + }, + "pubKey": { + "value": "7VeRAt79WPnMQ7TsM5cfhy2ERwVLu8fXbDezfFb6bT9BgYaZ" + } + }, { + "address": "LdeNgVjFaUTzsSHySB3ZrBaLiEeZebLkkyWFP", + "id": 2, + "networkAddress": { + "host": "127.0.0.1", + "port": 26020, + "secure": false + }, + "pubKey": { + "value": "7VeR9rnFNzgECCYGF8V3G36xhF3X9rr6YzqfN8h6CojgLpEY" + } + }, { + "address": "LdeNgVAkBAAdKLD1z3Nb7n5vtGujfqWdhx8G7", + "id": 3, + "networkAddress": { + "host": "127.0.0.1", + "port": 26030, + "secure": false + }, + "pubKey": { + "value": "7VeRPkXMyHFvpPf2jayHjiLX8H7CAcTJpF9F1FARogiroSK2" + } + }], + "systemConfigs": [{ + "name": "system.bft", + "value": "true" + }, { + "name": "system.communication.defaultkeys", + "value": "true" + }, { + "name": "system.communication.inQueueSize", + "value": "500000" + }, { + "name": "system.communication.outQueueSize", + "value": "500000" + }, { + "name": "system.communication.useMACs", + "value": "1" + }, { + "name": "system.communication.useSenderThread", + "value": "true" + }, { + "name": "system.communication.useSignatures", + "value": "0" + }, { + "name": "system.debug", + "value": "0" + }, { + "name": "system.initial.view", + "value": "0,1,2,3" + }, { + "name": "system.servers.f", + "value": "1" + }, { + "name": "system.servers.num", + "value": "4" + }, { + "name": "system.shutdownhook", + "value": "true" + }, { + "name": "system.totalordermulticast.checkpoint_period", + "value": "1000" + }, { + "name": "system.totalordermulticast.checkpoint_to_disk", + "value": "false" + }, { + "name": "system.totalordermulticast.global_checkpoint_period", + "value": "120000" + }, { + "name": "system.totalordermulticast.highMark", + "value": "10000" + }, { + "name": "system.totalordermulticast.log", + "value": "true" + }, { + "name": "system.totalordermulticast.log_parallel", + "value": "false" + }, { + "name": "system.totalordermulticast.log_to_disk", + "value": "false" + }, { + "name": "system.totalordermulticast.maxbatchsize", + "value": "400" + }, { + "name": "system.totalordermulticast.nonces", + "value": "10" + }, { + "name": "system.totalordermulticast.revival_highMark", + "value": "10" + }, { + "name": "system.totalordermulticast.state_transfer", + "value": "true" + }, { + "name": "system.totalordermulticast.sync_ckp", + "value": "false" + }, { + "name": "system.totalordermulticast.sync_log", + "value": "false" + }, { + "name": "system.totalordermulticast.timeout", + "value": "2000" + }, { + "name": "system.totalordermulticast.timeout_highMark", + "value": "200" + }, { + "name": "system.totalordermulticast.verifyTimestamps", + "value": "false" + }, { + "name": "system.ttp.id", + "value": "7002" + }] + }, + "cryptoSetting": { + "autoVerifyHash": true, + "hashAlgorithm": 8216, + "supportedProviders": [{ + "algorithms": [{}, {}, {}, {}, {}, {}, {}], + "name": "com.jd.blockchain.crypto.service.classic.ClassicCryptoService" + }, { + "algorithms": [{}, {}, {}], + "name": "com.jd.blockchain.crypto.service.sm.SMCryptoService" + }] + }, + "participantNodes": [{ + "address": "LdeNgXM4J1SybrdUn71KdPhwBYvJzZ6xUG5Rd", + "id": 0, + "name": "a.com", + "pubKey": { + "value": "7VeRMXAkf3zoqr4N2RgLZ83xAv7wurqu6Vxak1V1GHv4Kfe3" + } + }, { + "address": "LdeNwbLhiAHQCVxnXsyKLhgcmUi2fuwYd6jkh", + "id": 1, + "name": "b.com", + "pubKey": { + "value": "7VeRAt79WPnMQ7TsM5cfhy2ERwVLu8fXbDezfFb6bT9BgYaZ" + } + }, { + "address": "LdeNgVjFaUTzsSHySB3ZrBaLiEeZebLkkyWFP", + "id": 2, + "name": "c.com", + "pubKey": { + "value": "7VeR9rnFNzgECCYGF8V3G36xhF3X9rr6YzqfN8h6CojgLpEY" + } + }, { + "address": "LdeNgVAkBAAdKLD1z3Nb7n5vtGujfqWdhx8G7", + "id": 3, + "name": "d.com", + "pubKey": { + "value": "7VeRPkXMyHFvpPf2jayHjiLX8H7CAcTJpF9F1FARogiroSK2" + } + }], + "participantsHash": { + "value": "j5hQErg4epzNh38FR3EABx8YJqPkLYZoY828giAyKpCXMd" + }, + "seed": "932dfe23-fe23232f-283f32fa-dd32aa76-8322ca2f-56236cda-7136b322-cb323ffe" + }, + "success": true +} + + +``` + +说明 + +|名称|说明| +|---|---| +|seed|账本种子信息| +|consensusProtocol|共识协议,以字符串方式显示| +|consensusSettings|共识配置,不同共识协议内容不同,上述示例为BFTSmart相关配置| +|cryptoSetting|密码相关配置| +|cryptoSetting.hashAlgorithm|Hash算法Code(8216代表SHA256)| +|cryptoSetting.autoVerifyHash|是否自动校验Hash| +|cryptoSetting.supportedProviders|支持的算法库| +|participantNodes|参与方列表信息| +|participantNodes.id|参与方序号| +|participantNodes.address|参与方地址| +|participantNodes.name|参与方名称| +|participantNodes.pubKey.value|参与方公钥信息| +|participantsHash.value|参与方根Hash| + + + +## 3 区块 + +### 3.1 获取最新区块 + +```http +GET /ledgers/{ledger}/blocks/latest +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/latest +``` + +#### 返回实例 + +```json +{ + "data": { + "ledgerHash": { + "value": "657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs" + }, + "previousHash": { + "value": "6EJZnMc9464DCSU2kgi96RyngEv8YeEfVoJNhH3yZ2v5T" + }, + "transactionSetHash": { + "value": "6LmZtDpMM7xE8FPChACEmLj1PLhfaoVM2rEHRsrV3ohPN" + }, + "userAccountSetHash": { + "value": "67jx7SctrwdSczxxuYjwBocA8fER7V8qcRZUzWamSav5p" + }, + "contractAccountSetHash": { + "value": "67ftaBhPDez24NEB9wiiTM3SNcn1XFz5rb7boYhpbbLXN" + }, + "adminAccountHash": { + "value": "69KEFp9m5iFyAiyGmJ2qPcVxuT79gMChMf9JkStBZe8aa" + }, + "dataAccountSetHash": { + "value": "6LB9gosVWEPG3uvWXkxTcWq22mcwMHVehbiXkavFtr5fZ" + }, + "hash": { + "value": "67XsKWgqZTBz1NsytKGpyNWHMbMRENWcBj8PEDYQnWiDL" + }, + "height": 66 + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|hash|区块哈希| +|ledgerHash|账本哈希| +|previousHash|前置区块哈希| +|transactionSetHash|交易集哈希| +|userAccountSetHash|用户集哈希| +|contractAccountSetHash|合约集哈希| +|adminAccountHash|管理员集哈希| +|dataAccountSetHash|数据账户集哈希| + +### 3.2 根据区块哈希获取区块详细信息 + +```http +GET /ledgers/{ledger}/blocks/hash/{block_hash} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串| +|path|block_hash|是|区块哈希|字符串| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/hash/67XsKWgqZTBz1NsytKGpyNWHMbMRENWcBj8PEDYQnWiDL +``` + +#### 返回实例 + +[参考](#block-detail) + + +### 3.3 根据区块高度获取区块详细信息 + +```http +GET /ledgers/{ledger}/blocks/height/{block_height} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串| +|path|block_height|是|区块高度|数字| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/height/66 +``` + +#### 返回实例 + +[参考](#block-detail) + + +### 3.4 根据哈希查询区块总数 + +```http + GET /ledgers/{ledger}/blocks/count/search?keyword={keyword} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是| 区块哈希的全部或者一部分|string| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/count/search?keyword=6D5M +``` + +#### 返回实例 + +```json +{ + "data": 26, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|查询到的区块总数| + +### 3.5 根据哈希查询区块 + +```http + GET /ledgers/{ledger}/blocks/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是| 区块哈希的全部或者一部分|string| +|**query**|**start_index**|否| 查询区块结果起始序号,默认为0|string| +|**query**|**count**|否| 查询区块结果返回数量,默认最大值为100,小于0或大于100均返回最大可返回结果集|string| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/search?keyword=6D5M&fromIndex=0&count=-1 +``` + + +#### 返回实例 + +```json +{ + "data": { + "blocks": [ + { + "hash": "6D5MJZnybT69bXET5QdCZdLGT16rZBJEjxLkANmDuykcb" + } + ] + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|blocks|查询到的区块列表| +|hash|区块哈希值| +|height|区块高度| +|txCount|区块内交易数量| + +## 4 交易 + +### 4.1 获取账本交易总数 + +```http +GET /ledgers/{ledger}/txs/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/txs/count +``` + +##### 返回实例 + +```json +{ + "data": 688, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|交易数量| + +### 4.2 根据区块高度查询区块内的交易数量 + +```http +GET /ledgers/{ledger}/blocks/height/{block_height}/txs/additional-count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串| +|path|block_height|是|区块高度|数字| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/height/66/txs/additional-count + +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/hash/6D5MJZnybT69bXET5QdCZdLGT16rZBJEjxLkANmDuykcb/txs/additional-count +``` + +#### 返回实例 + +```json +{ + "data": 86, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|交易数量| + + +### 4.3 根据区块哈希查询区块内的交易数量 + +```http +GET /ledgers/{ledger}/blocks/hash/{block_hash}/txs/additional-count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串| +|path|block_hash|是|区块哈希|字符串| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/hash/6D5MJZnybT69bXET5QdCZdLGT16rZBJEjxLkANmDuykcb/txs/additional-count +``` + +#### 返回实例 + +```json +{ + "data": 86, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|交易数量| + + +### 4.4 获取指定高度的区块交易列表 + +```http +GET /ledgers/{ledger}/blocks/height/{height}/txs?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|height|是|区块高度|数字| +|query|start_index|否|查询交易的起始序号,默认为0|数字| +|query|count|否|查询返回交易的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/height/66/txs?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data": [ + { + "blockHeight": 1, + "executionState": "SUCCESS", + "transactionContent": { + "ledgerHash": { + "value": "657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs" + }, + "operations": [ + { + "userID": { + "address": { + "value": "5SmBgzsrnY6u9Y7DgSSkXfTkCgp83hiFin3v" + }, + "pubKey": { + "value": "mb5kukaqjWtXyAerfHU1JDtVwabSeBU5c3khMZbNh7R8VJ" + } + } + }, + { + "accountID": { + "address": { + "value": "5SmA98VknTbZ1Z7fmbNPHBuN2pbD89ogy8Ha" + }, + "pubKey": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + } + }, + { + "contractID": { + "address": { + "value": "5SmA98VknTbZ1Z7fmbNPHBuN2pbD89ogy8Ha" + }, + "pubKey": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + }, + "chainCode": "----------" + }, + { + "contractAddress": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + }, + "event": "----------", + "args": "----------" + }, + { + "writeSet": [{ + "key": "jdchain", + "value": { + "type": "TEXT", + "value": { + "value": "----------" + } + }, + "expectedVersion": 0 + }], + "accountAddress": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + } + ], + "hash": { + "value": "6BLtM1agb7ERKoN5AJgZKiTjzdS7BpjgzQNYK8ZeDqotA" + } + }, + "endpointSignatures": [ + { + "digest": { + "value": "42pbfM5YKnf39Gitr4UsjTCzhhnJjwNyi8MnLFYgP4VKewTLzHitzArHEMrCt3hZYUe5ex9XvqtmiCoWpeAbdc31F" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + } + } + ], + "nodeSignatures": [ + { + "digest": { + "value": "66SQ95SbDaApAJhN2NsFx5sfAQTxsWhMW26D5iPqXc1jZU9rJEhRnqT1nzt62ZAcCvsfrjEsay3MxqXYA5tWPoA2U" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + } + } + ] + } + ], + "success": true +} +``` + + +说明 + +|名称|说明| +|---|---| +|executionState|交易执行结果| +|transactionContent.hash|交易的哈希| +|transactionContent.operations|交易的操作列表| +|endpointSignatures|终端签名列表| +|nodeSignatures|节点的签名列表| + +### 4.5 获取指定哈希的区块的交易列表 + +```http +GET /ledgers/{ledger}/blocks/hash/{block_hash}/txs?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|block_hash|是|区块哈希|字符串| +|query|start_index|否|查询交易的起始序号,默认为0|数字| +|query|count|否|查询返回交易的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/blocks/hash/6D5MJZnybT69bXET5QdCZdLGT16rZBJEjxLkANmDuykcb/txs?fromIndex=0&count=-1 +``` + +#### 返回实例 + +[参考](#tx-list) + + +### 4.6 获取交易详细信息 + +```http +GET /ledgers/{ledger}/txs/hash/{tx_hash} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|tx_hash|是|交易哈希|字符串| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/txs/hash/6BLtM1agb7ERKoN5AJgZKiTjzdS7BpjgzQNYK8ZeDqotA +``` + +#### 返回实例 + +```json +{ + "data": { + "blockHeight": 1, + "executionState": "SUCCESS", + "transactionContent": { + "ledgerHash": { + "value": "657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs" + }, + "operations": [ + { + "userID": { + "address": { + "value": "5SmBgzsrnY6u9Y7DgSSkXfTkCgp83hiFin3v" + }, + "pubKey": { + "value": "mb5kukaqjWtXyAerfHU1JDtVwabSeBU5c3khMZbNh7R8VJ" + } + } + }, + { + "accountID": { + "address": { + "value": "5SmA98VknTbZ1Z7fmbNPHBuN2pbD89ogy8Ha" + }, + "pubKey": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + } + }, + { + "contractID": { + "address": { + "value": "5SmA98VknTbZ1Z7fmbNPHBuN2pbD89ogy8Ha" + }, + "pubKey": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + }, + "chainCode": "----------" + }, + { + "contractAddress": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + }, + "event": "----------", + "args": "----------" + }, + { + "writeSet": [{ + "key": "jdchain", + "value": { + "type": "TEXT", + "value": { + "value": "----------" + } + }, + "expectedVersion": 0 + }], + "accountAddress": { + "value": "mbC8hzmYBz2SsLLqwoBXAJiGeHrCnByBEvcaUZWscAiPqR" + } + } + ], + "hash": { + "value": "6BLtM1agb7ERKoN5AJgZKiTjzdS7BpjgzQNYK8ZeDqotA" + } + }, + "endpointSignatures": [ + { + "digest": { + "value": "42pbfM5YKnf39Gitr4UsjTCzhhnJjwNyi8MnLFYgP4VKewTLzHitzArHEMrCt3hZYUe5ex9XvqtmiCoWpeAbdc31F" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + } + } + ], + "nodeSignatures": [ + { + "digest": { + "value": "66SQ95SbDaApAJhN2NsFx5sfAQTxsWhMW26D5iPqXc1jZU9rJEhRnqT1nzt62ZAcCvsfrjEsay3MxqXYA5tWPoA2U" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + } + } + ] + }, + "success": true +} +``` + +说明 + +[参考](#tx-keyword) + + +### 4.7 根据哈希查询交易总数 + +```http + GET /ledgers/{ledgers}/txs/count/search?keyword={keyword} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledgers**|是|所要搜索的账本范围,需要完整的账本哈希|string| +|**query**|**keyword**|是|交易哈希,签名者公钥,或者节点公钥的全部或者部分的|string| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/txs/search?keyword=6BLt +``` + +#### 返回实例 + +```json +{ + "data": 36, + "success": true +} +``` + + +说明 + +|名称|说明| +|---|---| +|data|指定交易数量| + + +### 4.8 根据哈希查询交易 + +```http + GET /ledgers/{ledgers}/txs/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledgers**|是|所要搜索的账本范围,需要完整的账本哈希|string| +|**query**|**keyword**|是|交易哈希,签名者公钥,或者节点公钥的全部或者部分的|string| +|**query**|**start_index**|否|查询交易的起始序号,默认为0|数字| +|**query**|**count**|否|查询返回交易的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/txs/search?keyword=6BLt +``` + + +#### 返回 + +```json +{ + "data": { + "txs": [ + { + "hash": "6L3ehswCmC1jqBfvGJP9vaPx8qxkLsieu2aRgYepmkiw3" + } + ] + }, + "success": true +} +``` + +## 5 用户 + +### 5.1 获取用户总数 + +```http +GET /ledgers/{ledger}/users/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/users/count +``` + +#### 返回实例 + +```json +{ + "data": 4, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|用户总数| + + +### 5.2 获取用户列表 + +```http +GET /ledgers/{ledger}/users?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|query|start_index|否|查询用户的起始序号,默认为0|数字| +|query|count|否|查询返回用户的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/users?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data":[{ + "address": { + "value": "5SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + }, + "rootHash": { + "value": "5SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522" + } + }], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|用户地址| +|pubKey.value|用户公钥| + + +### 5.3 获取用户详细信息 + +```http +GET /ledgers/{ledger}/users/address/{address} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|用户地址|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/users/address/55SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522 +``` + +#### 返回实例 + +```json +{ + "data": { + "address": { + "value": "5SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522" + }, + "pubKey": { + "value": "mb5kbwzACnhK9P1dVxgMPB2ySJLFyJKQbHpH7T9oRK3LpS" + }, + "rootHash": { + "value": "5SmFzgFtHtpbJwMCsmWTwjNGTk6SeMKU1522" + } + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|用户地址| +|pubKey.value|用户公钥| +|rootHash.value|用户根Hash| + + +### 5.4 用户查询数量 + +```http + GET /ledgers/{ledger}/users/count/search?keyword={keyword} +``` + +#### 说明 + +用户有公钥和地址两个属性,可以通过公钥或者地址查找特定用户数量,也可以返回全部用户的数量 + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是| 用户的公钥或者地址的全部或者部分|string| +|**query**|**start_index**|否|查询用户的起始序号,默认为0|数字| +|**query**|**count**|否|查询返回用户的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/users/count/search?keyword=5Sm +``` + +#### 返回实例 + +```json +{ + "data": 4, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|用户数量| + +### 5.5 用户查询 + +```http + GET /ledgers/{ledger}/users/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 说明 + +用户有公钥和地址两个属性,可以通过公钥或者地址查找特定用户,也可以返回全部用户的列表 + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是| 用户的公钥或者地址的全部或者部分|string| +|**query**|**start_index**|否|查询用户的起始序号,默认为0|数字| +|**query**|**count**|否|查询返回用户的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/users/search?keyword=5Sm&fromIndex=0&count=-1 +``` + + +#### 返回实例 + +```json +{ + "data": { + "users": [ + { + "address": { + "value": "5SmAGKgmXyj5VsVvJgHbYCJ67iTizwSkNpw1" + }, + "pubKey": { + "value": "mb97eG4bba2EjrgjXYiD9chAstjg4HaNuV5xgCtSHc5TeB" + } + } + ] + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|用户地址| +|pubKey.value|用户公钥| +|rootHash.value|用户根Hash| + +## 6 数据账户 + +### 6.1 获取账户列表 + +```http +GET /ledgers/{ledger}/accounts?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|query|start_index|否|查询数据账户的起始序号,默认为0|数字| +|query|count|否|查询返回数据账户的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data":[{ + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "rootHash": { + "value": "6GiAH2PBRLnoE724ia83bKVijkKsNuNU5danA4AAi5qMM" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + }], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|账户地址| +|pubKey.value|账户公钥| +|rootHash.value|默克尔树根哈希| + + +### 6.2 获取账户详细信息 + +```http +GET /ledgers/{ledger}/accounts/address/{address} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|账户地址|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa +``` + +#### 返回实例 + +```json +{ + "data": { + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "rootHash": { + "value": "6GiAH2PBRLnoE724ia83bKVijkKsNuNU5danA4AAi5qMM" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|账户地址| +|pubKey.value|账户公钥| +|rootHash.value|默克尔树根哈希| + + +### 6.3 获取账户总数 + +```http +GET /ledgers/{ledger}/accounts/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/count +``` + +#### 返回实例 + +```json +{ + "data": 18, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账户数量| + + +### 6.4 查询数据账户匹配的数量 + +```http +GET /ledgers/{ledger}/accounts/count/search?keyword={keyword} +``` + +#### 说明 + +通过账户的公钥和地址的全部或者部分查询特定账户的总数量,也可以通过KV值的Key来查询含有该Key的账户的总数量 + + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|字符串 +|**query**|**keyword**|是|数据账户的公钥或者地址的全部或者部分,或者是KV值的key|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/count/search?keyword=jd +``` + +#### 返回实例 + +```json +{ + "data": 2, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|账户数量| + + +### 6.5 查询数据账户 + +```http + GET /ledgers/{ledger}/accounts/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 说明 + +通过账户的公钥和地址的全部或者部分查询特定账户,也可以通过KV值的Key来查询含有该Key的账户 + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是| 数据账户的公钥或者地址的全部或者部分,或者是KV值的key|string| +|**query**|**start_index**|否|查询数据账户的起始序号,默认为0|数字| +|**query**|**count**|否|查询返回数据账户的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/search?keyword=5Sm5V&fromIndex=0&count=-1 +``` + + +#### 返回实例 + +```json +{ + "data": { + "accounts": [ + { + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + } + ] + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|账户地址| +|pubKey.value|账户公钥| +|rootHash.value|数据账户根Hash| + + +### 6.6 获取某数据账户KV总数 + +```http + GET /ledgers/{ledger}/accounts/address/{address}/entries/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|账户地址|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa/entries/count +``` + +#### 返回实例 + +```json +{ + "data": 66, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|KV总数| + + +### 6.7 获取某数据账户KV详情 + +```http + GET/POST /ledgers/{ledger}/accounts/address/{address}/entries?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|账户地址|字符串 +|form|keys|是|key详细内容列表|字符串 +|query|start_index|否|查询数据账户对应KV的起始序号,默认为0|数字| +|query|count|否|查询返回数据账户对应KV的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +> keys说明: + 1)keys使用表单方式提交,且keys为需要查询Key的列表,列表中每个Key都需要为完整Key + 2)Key提交方式使用GET或POST均可 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa/entries +``` + +说明:表单提交参数为keys={"jd", "jdchain"} + + +#### 返回实例 + +```json +{ + "data": [ + { + "key": "jd", + "version": 0, + "type": "TEXT", + "value": "www.jd.com" + }, + { + "key": "jdchain", + "version": 0, + "type": "TEXT", + "value": "www.blockchain.com" + }], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|key|键| +|version|版本号| +|type|value类型| +|value|值| + + + + +### 6.8 获取某数据账户KV整个历史详情 + +```http + GET/POST /ledgers/{ledger}/accounts/{address}/entries-version +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|账户地址|字符串 +|form|KVInfoVO|是|Key相关信息|对象 + +KVInfoVO对应格式如下: + +```json + +{ + "data": [{ + "key": "zhangsan", + "version": [0, 1, 2] + }, { + "key": "lisi", + "version": [0, 1] + }] +} + +``` + +KVInfoVO说明: + + 1)支持多个Key作为入参; + + + 2)每个Key支持多个version; + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/accounts/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa/entries-version +``` + + +#### 返回实例 + +```json +{ + "data": [ + { + "key": "jd", + "version": 0, + "type": "TEXT", + "value": "www.jd.com" + }, + { + "key": "jdchain", + "version": 0, + "type": "TEXT", + "value": "www.blockchain.com" + }], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|key|键| +|version|版本号| +|type|value类型| +|value|值| + + +## 7 搜索 + +### 7.1 搜索区块链 + +```http + GET /ledgers/{ledger}/all/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 说明 + +通过关键字搜索区块数据,支持区块哈希,交易哈希,用户公钥和地址,合约公钥和地址,数据账户哈希和地址的搜索 + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本,需要完整的账本哈希|string| +|**query**|**keyword**|是|关键字|string| +|**query**|**start_index**|否|查询匹配结果的起始序号,默认为0|数字| +|**query**|**count**|否|查询匹配结果的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/all/search?keyword=5Sm5V&fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "message": "OK", + "code": 0, + "data": { + "blocks": ..., + "txs": ..., + "users": ..., + "accounts": ..., + "contracts": ..., + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|blocks|[参考](#query-blocks-result)| +|txs|[参考](#query-txs-result)| +|users|[参考](#query-users-result)| +|accounts|[参考](#query-accounts-result)| +|contracts|[参考](#query-contracts-result)| + +## 8 合约 + +### 8.1 获取合约列表 + +```http +GET /ledgers/{ledger}/contracts?fromIndex={start_index}&count={count} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|query|start_index|否|查询合约的起始序号,默认为0|数字| +|query|count|否|查询返回合约的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/contracts?fromIndex=0&count=-1 +``` + +#### 返回实例 + +```json +{ + "data": [{ + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "rootHash": { + "value": "6GiAH2PBRLnoE724ia83bKVijkKsNuNU5danA4AAi5qMM" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + }], + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|账户地址| +|pubKey.value|账户公钥| +|rootHash.value|默克尔树根哈希| + + +### 8.2 获取合约详细信息 + +```http +GET /ledgers/{ledger}/contracts/address/{address} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 +|path|address|是|合约地址|字符串 + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/contracts/address/5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa +``` + +#### 返回实例 + +```json +{ + "data": { + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "rootHash": { + "value": "6GiAH2PBRLnoE724ia83bKVijkKsNuNU5danA4AAi5qMM" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|账户地址| +|pubKey.value|账户公钥| +|rootHash.value|默克尔树根哈希| + +### 8.3 获取合约总数 + +```http +GET /ledgers/{ledger}/contracts/count +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型 +|---|---|---|---|---| +|path|ledger|是|账本哈希|字符串 + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/contracts/count +``` + +#### 返回实例 + +```json +{ + "data": 27, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|合约数量| + + +### 8.4 查询指定合约数量 + +```http +GET /ledgers/{ledger}/contracts/count/search?keyword={keyword} +``` + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本范围,需要完整的账本哈希|string| +|**query**|**keyword**|是| 合约的公钥或者地址的全部或者一部分|string| + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/contracts/count/search?keyword=5Sm2 +``` + +#### 返回实例 + +```json +{ + "data": 2, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|data|合约数量| + +### 8.5 合约查询 + +```http + GET /ledgers/{ledger}/contracts/search?keyword={keyword}&fromIndex={start_index}&count={count} +``` + +#### 说明 + +合约有公钥和地址两个属性,可以通过合约的这两个属性查询特定合约,也可以返回一个当前所有合约的列表 + +#### 参数 + +|请求类型|名称|是否必需|说明|数据类型| +|---|---|---|---|---| +|**path**|**ledger**|是|所要搜索的账本范围,需要完整的账本哈希|string| +|**query**|**keyword**|是| 合约的公钥或者地址的全部或者一部分|string| +|**query**|**start_index**|否|查询合约的起始序号,默认为0|数字| +|**query**|**count**|否|查询返回合约的数量,默认最大返回值为100,小于0或大于100均返回最大可返回结果集|数字| + + +#### 请求实例 +```http +http://localhost/ledgers/657TQAw6ssVoeKniWGwbovk7njvCTvikPambM9eBv6ezs/contracts/earch?keyword=5Sm2&fromIndex=0&count=-1 +``` + + +#### 返回 + +```json +{ + "data": { + "contracts": [ + { + "address": { + "value": "5Sm4gWXrNpDWW9Boi4xZCzZMHboRvEDm29Fa" + }, + "rootHash": { + "value": "6GiAH2PBRLnoE724ia83bKVijkKsNuNU5danA4AAi5qMM" + }, + "pubKey": { + "value": "mavweXqvKGUAJzSxE9S15pV7c7qe9bgUn5R1HwpqmXVTUs" + } + } + ] + }, + "success": true +} +``` + +说明 + +|名称|说明| +|---|---| +|address.value|合约地址| +|pubKey.value|合约公钥| +|rootHash|合约根Hash| diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init index 057e9966..e9895ce2 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init +++ b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init @@ -10,7 +10,7 @@ created-time=2019-08-01 14:26:58.069+0800 #共识服务提供者;必须; consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider -#共识服务的参数配置;必须; +#共识服务的参数配置;推荐使用绝对路径;必须; consensus.conf=classpath:bftsmart.config #密码服务提供者列表,以英文逗点“,”分隔;必须; diff --git a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java index 5a6ed045..fa29ba71 100644 --- a/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java +++ b/source/tools/tools-initializer/src/main/java/com/jd/blockchain/tools/initializer/LedgerInitProperties.java @@ -141,7 +141,8 @@ public class LedgerInitProperties { public static LedgerInitProperties resolve(String initSettingFile) { Properties props = FileUtils.readProperties(initSettingFile, "UTF-8"); - return resolve(props); + File realFile = new File(initSettingFile); + return resolve(realFile.getParentFile().getPath(), props); } public static LedgerInitProperties resolve(InputStream in) { @@ -150,6 +151,10 @@ public class LedgerInitProperties { } public static LedgerInitProperties resolve(Properties props) { + return resolve(null, props); + } + + public static LedgerInitProperties resolve(String dir, Properties props) { String hexLedgerSeed = PropertiesUtils.getRequiredProperty(props, LEDGER_SEED).replace("-", ""); byte[] ledgerSeed = HexUtils.decode(hexLedgerSeed); LedgerInitProperties initProps = new LedgerInitProperties(ledgerSeed); @@ -166,7 +171,7 @@ public class LedgerInitProperties { initProps.consensusProvider = PropertiesUtils.getRequiredProperty(props, CONSENSUS_SERVICE_PROVIDER); String consensusConfigFilePath = PropertiesUtils.getRequiredProperty(props, CONSENSUS_CONFIG); try { - File consensusConfigFile = ResourceUtils.getFile(consensusConfigFilePath); + File consensusConfigFile = FileUtils.getFile(dir, consensusConfigFilePath); initProps.consensusConfig = FileUtils.readProperties(consensusConfigFile); } catch (FileNotFoundException e) { throw new IllegalArgumentException( diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/io/FileUtils.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/io/FileUtils.java index 0d4d86e1..17ed444f 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/io/FileUtils.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/io/FileUtils.java @@ -16,6 +16,7 @@ import java.io.Reader; import java.util.ArrayList; import java.util.Properties; +import com.jd.blockchain.utils.PathUtils; import org.springframework.util.ResourceUtils; /** @@ -482,4 +483,26 @@ public class FileUtils { } return path.delete(); } + + /** + * 获取指定路径和位置的文件信息 + * + * @param dir + * 指定路径,不要以"/"结尾 + * @param resourceLocation + * 文件位置信息,可支持绝对路径、相对路径(相对dir)、classpath:前缀 + * @return + * + * @throws FileNotFoundException + */ + public static File getFile(String dir, String resourceLocation) throws FileNotFoundException { + if (resourceLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) { + return ResourceUtils.getFile(resourceLocation); + } + if (resourceLocation.startsWith(PathUtils.PATH_SEPERATOR)) { + return new File(resourceLocation); + } + String totalPath = PathUtils.concatPaths(dir, resourceLocation); + return new File(totalPath); + } } From 40e397da05461d2c389b2f81943183bea2b98049 Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Fri, 21 Jun 2019 18:03:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?Modify=20contract=20usage=20in=20readme=20f?= =?UTF-8?q?ile=20=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 49 ++++++++++--------- .../jd/blockchain/intgr/IntegrationBase.java | 18 +++---- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index c498e807..6b98db84 100644 --- a/README.md +++ b/README.md @@ -596,28 +596,31 @@ JD区块链的核心对象包括: // 合约地址 String contractAddressBase58 = ""; - - // Event - String event = ""; - - // args(注意参数的格式) - byte[] args = "20##30##abc".getBytes(); - - - // 提交合约执行代码 - txTemp.contractEvents().send(contractAddressBase58, event, args); - - // TX 准备就绪; - PreparedTransaction prepTx = txTemp.prepare(); - - // 生成私钥并使用私钥进行签名; - CryptoKeyPair keyPair = getSponsorKey(); - - prepTx.sign(keyPair); - - // 提交交易; - TransactionResponse transactionResponse = prepTx.commit(); - - assertTrue(transactionResponse.isSuccess()); + + // 使用接口方式调用合约 + TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class); + + // 使用decode方式调用合约内部方法(create方法) + // 返回GenericValueHolder可通过get方法获取结果,但get方法需要在commit调用后执行 + GenericValueHolder result = ContractReturnValue.decode(transferContract.create(address, account, money)); + + PreparedTransaction ptx = txTpl.prepare(); + + ptx.sign(adminKey); + + TransactionResponse transactionResponse = ptx.commit(); + + String cotractExecResult = result.get(); + + // TransactionResponse也提供了可供查询结果的接口 + OperationResult[] operationResults = transactionResponse.getOperationResults(); + + // 通过OperationResult获取结果 + for (int i = 0; i < operationResults.length; i++) { + OperationResult opResult = operationResults[i]; + System.out.printf("Operation[%s].result = %s \r\n", + opResult.getIndex(), BytesValueEncoding.decode(opResult.getResult())); + } + ``` \ No newline at end of file diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java index 455940dd..84de078f 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java @@ -25,6 +25,7 @@ import java.util.Random; import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicLong; +import com.jd.blockchain.ledger.*; import org.apache.commons.io.FileUtils; import org.springframework.core.io.ClassPathResource; @@ -33,17 +34,6 @@ import com.jd.blockchain.contract.ReadContract; import com.jd.blockchain.crypto.AddressEncoding; import com.jd.blockchain.crypto.AsymmetricKeypair; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.BlockchainKeyGenerator; -import com.jd.blockchain.ledger.BlockchainKeypair; -import com.jd.blockchain.ledger.KVDataEntry; -import com.jd.blockchain.ledger.LedgerBlock; -import com.jd.blockchain.ledger.LedgerInitOperation; -import com.jd.blockchain.ledger.OperationResult; -import com.jd.blockchain.ledger.PreparedTransaction; -import com.jd.blockchain.ledger.TransactionResponse; -import com.jd.blockchain.ledger.TransactionState; -import com.jd.blockchain.ledger.TransactionTemplate; -import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.impl.LedgerManager; import com.jd.blockchain.sdk.BlockchainService; @@ -609,6 +599,12 @@ public class IntegrationBase { System.out.printf("readContract1.result = %s \r\n", result1.get()); System.out.printf("readContract3.result = %s \r\n", result3.get()); + for (int i = 0; i < operationResults.length; i++) { + OperationResult opResult = operationResults[i]; + System.out.printf("Operation[%s].result = %s \r\n", opResult.getIndex(), BytesValueEncoding.decode(opResult.getResult())); + } + + // // 打印结果 // for (OperationResult or : operationResults) { From 08ca5926a9eea8ee9d768ee57d85a31c039711af Mon Sep 17 00:00:00 2001 From: shaozhuguang Date: Fri, 21 Jun 2019 18:25:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?Modify=20the=20default=20settings=20for=20t?= =?UTF-8?q?he=20initialization=20part=20of=20the=20ledger=20=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../deployment-peer/src/main/resources/config/init/ledger.init | 2 +- .../deployment-peer/src/main/resources/config/init/local.conf | 2 +- .../src/main/resources/config/init/mq/ledger.init | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init index e9895ce2..14a95134 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init +++ b/source/deployment/deployment-peer/src/main/resources/config/init/ledger.init @@ -11,7 +11,7 @@ created-time=2019-08-01 14:26:58.069+0800 consensus.service-provider=com.jd.blockchain.consensus.bftsmart.BftsmartConsensusProvider #共识服务的参数配置;推荐使用绝对路径;必须; -consensus.conf=classpath:bftsmart.config +consensus.conf=bftsmart.config #密码服务提供者列表,以英文逗点“,”分隔;必须; crypto.service-providers=com.jd.blockchain.crypto.service.classic.ClassicCryptoService, \ diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/local.conf b/source/deployment/deployment-peer/src/main/resources/config/init/local.conf index 2a5392c5..31518046 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/local.conf +++ b/source/deployment/deployment-peer/src/main/resources/config/init/local.conf @@ -1,4 +1,4 @@ -#当前参与方的 id +#当前参与方的 id,与ledger.init文件中cons_parti.id一致,默认从0开始 local.parti.id=0 #当前参与方的公钥 diff --git a/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init b/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init index f7e7d593..1abf98e9 100644 --- a/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init +++ b/source/deployment/deployment-peer/src/main/resources/config/init/mq/ledger.init @@ -11,7 +11,7 @@ created-time=2019-08-01 14:26:58.069+0800 consensus.service-provider=com.jd.blockchain.consensus.mq.MsgQueueConsensusProvider #共识服务的参数配置;必须; -consensus.conf=classpath:mq.config +consensus.conf=mq.config #密码服务提供者列表,以英文逗点“,”分隔;必须; crypto.service-providers=com.jd.blockchain.crypto.service.classic.ClassicCryptoService, \