diff --git a/source/base/pom.xml b/source/base/pom.xml index 3ffd649b..5c91544a 100644 --- a/source/base/pom.xml +++ b/source/base/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT base diff --git a/source/binary-proto/pom.xml b/source/binary-proto/pom.xml index 95a548a5..08838ab2 100644 --- a/source/binary-proto/pom.xml +++ b/source/binary-proto/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT binary-proto diff --git a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java index c06c6039..ecaee503 100644 --- a/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java +++ b/source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java @@ -11,7 +11,6 @@ import com.jd.blockchain.utils.io.BytesSlice; import com.jd.blockchain.utils.io.BytesUtils; public class BinaryProtocol { - public static void encode(Object data, Class contractType, OutputStream out) { DataContractEncoder encoder = DataContractContext.resolve(contractType); @@ -33,8 +32,6 @@ public class BinaryProtocol { byte[] bytes = BytesUtils.copyToBytes(in); return decode(bytes); } - - public static T decode(byte[] dataSegment) { BytesSlice bytes = new BytesSlice(dataSegment, 0, dataSegment.length); @@ -49,19 +46,32 @@ public class BinaryProtocol { return encoder.decode(bytes.getInputStream()); } - - - public static T decodeAs(byte[] dataSegment, Class contractType) { + public static T decode(byte[] dataSegment, Class contractType) { + return decode(dataSegment, contractType, true); + } + + public static T decode(byte[] dataSegment, Class contractType, boolean autoRegister) { DataContractEncoder encoder = DataContractContext.ENCODER_LOOKUP.lookup(contractType); if (encoder == null) { - throw new DataContractException("Contract type is not registered! --" + contractType.toString()); + if (autoRegister) { + encoder = DataContractContext.resolve(contractType); + } else { + throw new DataContractException("Contract type is not registered! --" + contractType.toString()); + } } BytesSlice bytes = new BytesSlice(dataSegment, 0, dataSegment.length); return encoder.decode(bytes.getInputStream()); } - - - - + + + @Deprecated + public static T decodeAs(byte[] dataSegment, Class contractType) { + return decode(dataSegment, contractType, true); + } + + @Deprecated + public static T decodeAs(byte[] dataSegment, Class contractType, boolean autoRegister) { + return decode(dataSegment, contractType, autoRegister); + } } diff --git a/source/consensus/consensus-bftsmart/pom.xml b/source/consensus/consensus-bftsmart/pom.xml index 18e537a2..8adbd140 100644 --- a/source/consensus/consensus-bftsmart/pom.xml +++ b/source/consensus/consensus-bftsmart/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain consensus - 1.1.3.RELEASE + 1.1.4-SNAPSHOT consensus-bftsmart diff --git a/source/consensus/consensus-framework/pom.xml b/source/consensus/consensus-framework/pom.xml index 500466d9..9ada5722 100644 --- a/source/consensus/consensus-framework/pom.xml +++ b/source/consensus/consensus-framework/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain consensus - 1.1.3.RELEASE + 1.1.4-SNAPSHOT consensus-framework diff --git a/source/consensus/consensus-mq/pom.xml b/source/consensus/consensus-mq/pom.xml index c0919e68..ec29e80c 100644 --- a/source/consensus/consensus-mq/pom.xml +++ b/source/consensus/consensus-mq/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain consensus - 1.1.3.RELEASE + 1.1.4-SNAPSHOT consensus-mq diff --git a/source/consensus/pom.xml b/source/consensus/pom.xml index 860ad28c..a9cb1ca4 100644 --- a/source/consensus/pom.xml +++ b/source/consensus/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT consensus pom diff --git a/source/contract/contract-framework/pom.xml b/source/contract/contract-framework/pom.xml index d3ece19d..507264b4 100644 --- a/source/contract/contract-framework/pom.xml +++ b/source/contract/contract-framework/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain contract - 1.1.3.RELEASE + 1.1.4-SNAPSHOT contract-framework diff --git a/source/contract/contract-jvm/pom.xml b/source/contract/contract-jvm/pom.xml index fe0a1f38..5128f313 100644 --- a/source/contract/contract-jvm/pom.xml +++ b/source/contract/contract-jvm/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain contract - 1.1.3.RELEASE + 1.1.4-SNAPSHOT contract-jvm diff --git a/source/contract/contract-maven-plugin/pom.xml b/source/contract/contract-maven-plugin/pom.xml index b0f38b42..c448685e 100644 --- a/source/contract/contract-maven-plugin/pom.xml +++ b/source/contract/contract-maven-plugin/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain contract - 1.1.3.RELEASE + 1.1.4-SNAPSHOT contract-maven-plugin maven-plugin diff --git a/source/contract/contract-samples/pom.xml b/source/contract/contract-samples/pom.xml index 893c1240..8f17e183 100644 --- a/source/contract/contract-samples/pom.xml +++ b/source/contract/contract-samples/pom.xml @@ -5,7 +5,7 @@ contract com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/contract/pom.xml b/source/contract/pom.xml index f583ef6f..22c8620f 100644 --- a/source/contract/pom.xml +++ b/source/contract/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT contract pom diff --git a/source/crypto/crypto-adv/pom.xml b/source/crypto/crypto-adv/pom.xml index 5d3ce4e7..523e3cf1 100644 --- a/source/crypto/crypto-adv/pom.xml +++ b/source/crypto/crypto-adv/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain crypto - 1.1.3.RELEASE + 1.1.4-SNAPSHOT crypto-adv diff --git a/source/crypto/crypto-classic/pom.xml b/source/crypto/crypto-classic/pom.xml index 8f9732ba..48ac54ce 100644 --- a/source/crypto/crypto-classic/pom.xml +++ b/source/crypto/crypto-classic/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain crypto - 1.1.3.RELEASE + 1.1.4-SNAPSHOT crypto-classic diff --git a/source/crypto/crypto-framework/pom.xml b/source/crypto/crypto-framework/pom.xml index 48f9ee24..b19dbcd5 100644 --- a/source/crypto/crypto-framework/pom.xml +++ b/source/crypto/crypto-framework/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain crypto - 1.1.3.RELEASE + 1.1.4-SNAPSHOT crypto-framework diff --git a/source/crypto/crypto-pki/pom.xml b/source/crypto/crypto-pki/pom.xml index 1c8f6136..39206071 100644 --- a/source/crypto/crypto-pki/pom.xml +++ b/source/crypto/crypto-pki/pom.xml @@ -5,7 +5,7 @@ crypto com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/crypto/crypto-sm/pom.xml b/source/crypto/crypto-sm/pom.xml index 3c6db318..fcc7f869 100644 --- a/source/crypto/crypto-sm/pom.xml +++ b/source/crypto/crypto-sm/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain crypto - 1.1.3.RELEASE + 1.1.4-SNAPSHOT crypto-sm diff --git a/source/crypto/pom.xml b/source/crypto/pom.xml index b550723c..8653e539 100644 --- a/source/crypto/pom.xml +++ b/source/crypto/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT crypto pom diff --git a/source/deployment/deployment-gateway/pom.xml b/source/deployment/deployment-gateway/pom.xml index 498a42c2..22baa141 100644 --- a/source/deployment/deployment-gateway/pom.xml +++ b/source/deployment/deployment-gateway/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain deployment - 1.1.3.RELEASE + 1.1.4-SNAPSHOT deployment-gateway diff --git a/source/deployment/deployment-peer/pom.xml b/source/deployment/deployment-peer/pom.xml index 559457c4..308c5273 100644 --- a/source/deployment/deployment-peer/pom.xml +++ b/source/deployment/deployment-peer/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain deployment - 1.1.3.RELEASE + 1.1.4-SNAPSHOT deployment-peer diff --git a/source/deployment/pom.xml b/source/deployment/pom.xml index c7b07ea0..2cab2716 100644 --- a/source/deployment/pom.xml +++ b/source/deployment/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT deployment pom diff --git a/source/gateway/pom.xml b/source/gateway/pom.xml index aa58230c..c333f215 100644 --- a/source/gateway/pom.xml +++ b/source/gateway/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT gateway diff --git a/source/ledger/ledger-core/pom.xml b/source/ledger/ledger-core/pom.xml index a00b495d..68707eca 100644 --- a/source/ledger/ledger-core/pom.xml +++ b/source/ledger/ledger-core/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain ledger - 1.1.3.RELEASE + 1.1.4-SNAPSHOT ledger-core diff --git a/source/ledger/ledger-model/pom.xml b/source/ledger/ledger-model/pom.xml index 785af0a7..65682d6e 100644 --- a/source/ledger/ledger-model/pom.xml +++ b/source/ledger/ledger-model/pom.xml @@ -6,7 +6,7 @@ com.jd.blockchain ledger - 1.1.3.RELEASE + 1.1.4-SNAPSHOT ledger-model diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java index bba464e3..9a413d36 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java @@ -1,16 +1,10 @@ package com.jd.blockchain.transaction; import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; - -import org.springframework.cglib.proxy.UndeclaredThrowableException; import com.jd.blockchain.crypto.AsymmetricKeypair; import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.ledger.DigitalSignature; -import com.jd.blockchain.ledger.OperationResult; import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.TransactionRequest; @@ -21,34 +15,17 @@ public class PreparedTx implements PreparedTransaction { private TransactionRequestBuilder txReqBuilder; - private TransactionService txProcessor; - - private OperationResultHandle[] opReturnValueHandlers; - - private TxStateManager stateManager; + private TransactionService txService; /** * 创建一个“就绪交易”对象; * - * @param txReqBuilder 交易请求构建器; - * @param txProcessor 交易处理服务; - * @param opReturnValueHandlerList 操作返回值处理器列表; + * @param txReqBuilder 交易请求构建器; + * @param txService 交易处理服务; */ - public PreparedTx(TxStateManager stateManager, TransactionRequestBuilder txReqBuilder, - TransactionService txProcessor, Collection opReturnValueHandlerList) { - this.stateManager = stateManager; + public PreparedTx(TransactionRequestBuilder txReqBuilder, TransactionService txService) { this.txReqBuilder = txReqBuilder; - this.txProcessor = txProcessor; - - this.opReturnValueHandlers = opReturnValueHandlerList - .toArray(new OperationResultHandle[opReturnValueHandlerList.size()]); - // 按照操作索引升序排列; - Arrays.sort(opReturnValueHandlers, new Comparator() { - @Override - public int compare(OperationResultHandle o1, OperationResultHandle o2) { - return o1.getOperationIndex() - o2.getOperationIndex(); - } - }); + this.txService = txService; } @Override @@ -75,60 +52,14 @@ public class PreparedTx implements PreparedTransaction { @Override public TransactionResponse commit() { - stateManager.commit(); - TransactionResponse txResponse = null; - try { - TransactionRequest txReq = txReqBuilder.buildRequest(); - // 发起交易请求; - txResponse = txProcessor.process(txReq); - - stateManager.complete(); - - } catch (Exception ex) { - stateManager.close(); - handleError(ex); - throw new UndeclaredThrowableException(ex); - } - - if (txResponse != null) { - handleResults(txResponse); - } - - return txResponse; + // 生成请求; + TransactionRequest txReq = txReqBuilder.buildRequest(); + // 发起交易请求; + return txService.process(txReq); } @Override public void close() throws IOException { - if (!stateManager.close()) { - TransactionCancelledExeption error = new TransactionCancelledExeption( - "Prepared transaction has been cancelled!"); - handleError(error); - } - } - - private void handleError(Throwable error) { - for (OperationResultHandle handle : opReturnValueHandlers) { - handle.complete(error); - } - } - - private void handleResults(TransactionResponse txResponse) { - // 解析返回值;正常的情况下,返回结果列表与结果处理器列表中元素对应的操作索引是一致的; - OperationResult[] opResults = txResponse.getOperationResults(); - if (opResults != null && opResults.length > 0) { - if (opResults.length != opReturnValueHandlers.length) { - throw new IllegalStateException(String.format( - "The operation result list of tx doesn't match it's return value handler list! --[TX.Content.Hash=%s][NumOfResults=%s][NumOfHandlers=%s]", - txResponse.getContentHash(), opResults.length, opReturnValueHandlers.length)); - } - for (int i = 0; i < opResults.length; i++) { - if (opResults[i].getIndex() != opReturnValueHandlers[i].getOperationIndex()) { - throw new IllegalStateException( - "The operation indexes of the items in the result list and in the handler list don't match!"); - } - opReturnValueHandlers[i].complete(opResults[i].getResult()); - } - } } } diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/StatefulPreparedTx.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/StatefulPreparedTx.java new file mode 100644 index 00000000..d20ff16d --- /dev/null +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/StatefulPreparedTx.java @@ -0,0 +1,108 @@ +package com.jd.blockchain.transaction; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; + +import org.springframework.cglib.proxy.UndeclaredThrowableException; + +import com.jd.blockchain.crypto.AsymmetricKeypair; +import com.jd.blockchain.ledger.DigitalSignature; +import com.jd.blockchain.ledger.OperationResult; +import com.jd.blockchain.ledger.TransactionRequestBuilder; +import com.jd.blockchain.ledger.TransactionResponse; + +class StatefulPreparedTx extends PreparedTx { + + private OperationResultHandle[] opReturnValueHandlers; + + private TxStateManager stateManager; + + /** + * 创建一个“就绪交易”对象; + * + * @param txReqBuilder 交易请求构建器; + * @param txProcessor 交易处理服务; + * @param opReturnValueHandlerList 操作返回值处理器列表; + */ + StatefulPreparedTx(TxStateManager stateManager, TransactionRequestBuilder txReqBuilder, + TransactionService txProcessor, Collection opReturnValueHandlerList) { + super(txReqBuilder, txProcessor); + this.stateManager = stateManager; + + this.opReturnValueHandlers = opReturnValueHandlerList + .toArray(new OperationResultHandle[opReturnValueHandlerList.size()]); + // 按照操作索引升序排列; + Arrays.sort(opReturnValueHandlers, new Comparator() { + @Override + public int compare(OperationResultHandle o1, OperationResultHandle o2) { + return o1.getOperationIndex() - o2.getOperationIndex(); + } + }); + } + + @Override + public DigitalSignature sign(AsymmetricKeypair keyPair) { + DigitalSignature signature = SignatureUtils.sign(getTransactionContent(), keyPair); + addSignature(signature); + return signature; + } + + @Override + public TransactionResponse commit() { + stateManager.commit(); + TransactionResponse txResponse = null; + try { + // 发起交易请求; + txResponse = super.commit(); + + stateManager.complete(); + } catch (Exception ex) { + stateManager.close(); + handleError(ex); + throw new UndeclaredThrowableException(ex); + } + + if (txResponse != null) { + handleResults(txResponse); + } + + return txResponse; + } + + @Override + public void close() throws IOException { + if (!stateManager.close()) { + TransactionCancelledExeption error = new TransactionCancelledExeption( + "Prepared transaction has been cancelled!"); + handleError(error); + } + } + + private void handleError(Throwable error) { + for (OperationResultHandle handle : opReturnValueHandlers) { + handle.complete(error); + } + } + + private void handleResults(TransactionResponse txResponse) { + // 解析返回值;正常的情况下,返回结果列表与结果处理器列表中元素对应的操作索引是一致的; + OperationResult[] opResults = txResponse.getOperationResults(); + if (opResults != null && opResults.length > 0) { + if (opResults.length != opReturnValueHandlers.length) { + throw new IllegalStateException(String.format( + "The operation result list of tx doesn't match it's return value handler list! --[TX.Content.Hash=%s][NumOfResults=%s][NumOfHandlers=%s]", + txResponse.getContentHash(), opResults.length, opReturnValueHandlers.length)); + } + for (int i = 0; i < opResults.length; i++) { + if (opResults[i].getIndex() != opReturnValueHandlers[i].getOperationIndex()) { + throw new IllegalStateException( + "The operation indexes of the items in the result list and in the handler list don't match!"); + } + opReturnValueHandlers[i].complete(opResults[i].getResult()); + } + } + } + +} diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java index 01fb8caf..45562a48 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java @@ -32,7 +32,7 @@ public class TxTemplate implements TransactionTemplate { public PreparedTransaction prepare() { stateManager.prepare(); TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest(); - return new PreparedTx(stateManager, txReqBuilder, txService, txBuilder.getReturnValuehandlers()); + return new StatefulPreparedTx(stateManager, txReqBuilder, txService, txBuilder.getReturnValuehandlers()); } @Override diff --git a/source/ledger/ledger-rpc/pom.xml b/source/ledger/ledger-rpc/pom.xml index 64ee90f6..f8b88f67 100644 --- a/source/ledger/ledger-rpc/pom.xml +++ b/source/ledger/ledger-rpc/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain ledger - 1.1.3.RELEASE + 1.1.4-SNAPSHOT ledger-rpc diff --git a/source/ledger/pom.xml b/source/ledger/pom.xml index 098124c6..e4ec442f 100644 --- a/source/ledger/pom.xml +++ b/source/ledger/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT ledger pom diff --git a/source/manager/manager-booter/pom.xml b/source/manager/manager-booter/pom.xml index 3266e88f..8264e361 100644 --- a/source/manager/manager-booter/pom.xml +++ b/source/manager/manager-booter/pom.xml @@ -5,7 +5,7 @@ manager com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/manager/manager-model/pom.xml b/source/manager/manager-model/pom.xml index 020546e4..484cff2b 100644 --- a/source/manager/manager-model/pom.xml +++ b/source/manager/manager-model/pom.xml @@ -5,7 +5,7 @@ manager com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/manager/manager-service/pom.xml b/source/manager/manager-service/pom.xml index 70f6a406..cd94d9ad 100644 --- a/source/manager/manager-service/pom.xml +++ b/source/manager/manager-service/pom.xml @@ -5,7 +5,7 @@ manager com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/manager/manager-web/pom.xml b/source/manager/manager-web/pom.xml index 7149dea3..9cb78597 100644 --- a/source/manager/manager-web/pom.xml +++ b/source/manager/manager-web/pom.xml @@ -5,7 +5,7 @@ manager com.jd.blockchain - 1.1.3.RELEASE + 1.1.4-SNAPSHOT 4.0.0 diff --git a/source/manager/pom.xml b/source/manager/pom.xml index 2a104a63..a2cfff1e 100644 --- a/source/manager/pom.xml +++ b/source/manager/pom.xml @@ -11,7 +11,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT manager pom diff --git a/source/peer/pom.xml b/source/peer/pom.xml index 04205994..7771db28 100644 --- a/source/peer/pom.xml +++ b/source/peer/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT peer diff --git a/source/pom.xml b/source/pom.xml index 86d5e2ae..8251c264 100644 --- a/source/pom.xml +++ b/source/pom.xml @@ -11,7 +11,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT pom jdchain diff --git a/source/runtime/pom.xml b/source/runtime/pom.xml index 3d3d9870..4814f299 100644 --- a/source/runtime/pom.xml +++ b/source/runtime/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT runtime pom diff --git a/source/runtime/runtime-context/pom.xml b/source/runtime/runtime-context/pom.xml index 6ea31e8d..594cffa3 100644 --- a/source/runtime/runtime-context/pom.xml +++ b/source/runtime/runtime-context/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain runtime - 1.1.3.RELEASE + 1.1.4-SNAPSHOT runtime-context diff --git a/source/runtime/runtime-modular-booter/pom.xml b/source/runtime/runtime-modular-booter/pom.xml index 3550c636..91f9c315 100644 --- a/source/runtime/runtime-modular-booter/pom.xml +++ b/source/runtime/runtime-modular-booter/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain runtime - 1.1.3.RELEASE + 1.1.4-SNAPSHOT runtime-modular-booter \ No newline at end of file diff --git a/source/runtime/runtime-modular/pom.xml b/source/runtime/runtime-modular/pom.xml index 2994c6af..d1edfa4b 100644 --- a/source/runtime/runtime-modular/pom.xml +++ b/source/runtime/runtime-modular/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain runtime - 1.1.3.RELEASE + 1.1.4-SNAPSHOT runtime-modular diff --git a/source/sdk/pom.xml b/source/sdk/pom.xml index 2bf21355..945bfd29 100644 --- a/source/sdk/pom.xml +++ b/source/sdk/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT sdk pom diff --git a/source/sdk/sdk-base/pom.xml b/source/sdk/sdk-base/pom.xml index 385d07c1..e5691e41 100644 --- a/source/sdk/sdk-base/pom.xml +++ b/source/sdk/sdk-base/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain sdk - 1.1.3.RELEASE + 1.1.4-SNAPSHOT sdk-base diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java index eff792a3..f7dcf433 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java @@ -1,6 +1,8 @@ package com.jd.blockchain.sdk; import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.ledger.PreparedTransaction; +import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.TransactionTemplate; public interface BlockchainTransactionService { @@ -12,6 +14,14 @@ public interface BlockchainTransactionService { */ TransactionTemplate newTransaction(HashDigest ledgerHash); + /** + * 根据交易内容准备交易实例; + * + * @param content + * @return + */ + PreparedTransaction prepareTransaction(TransactionContent content); + // /** // * 以指定的科目和流水号发起新交易; // * diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java index 9984cef5..16f047b9 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java @@ -11,6 +11,8 @@ import com.jd.blockchain.ledger.LedgerInfo; import com.jd.blockchain.ledger.LedgerMetadata; import com.jd.blockchain.ledger.LedgerTransaction; import com.jd.blockchain.ledger.ParticipantNode; +import com.jd.blockchain.ledger.PreparedTransaction; +import com.jd.blockchain.ledger.TransactionContent; import com.jd.blockchain.ledger.TransactionState; import com.jd.blockchain.ledger.TransactionTemplate; import com.jd.blockchain.ledger.UserInfo; @@ -19,7 +21,9 @@ import com.jd.blockchain.sdk.BlockchainEventListener; import com.jd.blockchain.sdk.BlockchainService; import com.jd.blockchain.sdk.converters.ClientResolveUtil; import com.jd.blockchain.transaction.BlockchainQueryService; +import com.jd.blockchain.transaction.PreparedTx; import com.jd.blockchain.transaction.TransactionService; +import com.jd.blockchain.transaction.TxRequestBuilder; import com.jd.blockchain.transaction.TxTemplate; public abstract class BlockchainServiceProxy implements BlockchainService { @@ -33,6 +37,12 @@ public abstract class BlockchainServiceProxy implements BlockchainService { public TransactionTemplate newTransaction(HashDigest ledgerHash) { return new TxTemplate(ledgerHash, getTransactionService(ledgerHash)); } + + @Override + public PreparedTransaction prepareTransaction(TransactionContent content) { + TxRequestBuilder txReqBuilder = new TxRequestBuilder(content); + return new PreparedTx(txReqBuilder, getTransactionService(content.getLedgerHash())); + } @Override public BlockchainEventHandle addBlockchainEventListener(int filteredEventTypes, String filteredTxHash, diff --git a/source/sdk/sdk-client/pom.xml b/source/sdk/sdk-client/pom.xml index bab9a30f..0d4fc9af 100644 --- a/source/sdk/sdk-client/pom.xml +++ b/source/sdk/sdk-client/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain sdk - 1.1.3.RELEASE + 1.1.4-SNAPSHOT sdk-client diff --git a/source/sdk/sdk-samples/pom.xml b/source/sdk/sdk-samples/pom.xml index 2f514ac5..eba91fec 100644 --- a/source/sdk/sdk-samples/pom.xml +++ b/source/sdk/sdk-samples/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain sdk - 1.1.3.RELEASE + 1.1.4-SNAPSHOT sdk-samples diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Tx_Persistance.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Tx_Persistance.java new file mode 100644 index 00000000..c564a306 --- /dev/null +++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Tx_Persistance.java @@ -0,0 +1,112 @@ +/** + * Copyright: Copyright 2016-2020 JD.COM All Right Reserved + * FileName: com.jd.blockchain.sdk.samples.SDKDemo_RegisterUser + * Author: shaozhuguang + * Department: 区块链研发部 + * Date: 2018/10/18 下午2:00 + * Description: 注册用户 + */ +package com.jd.blockchain.sdk.samples; + +import com.jd.blockchain.binaryproto.BinaryProtocol; +import com.jd.blockchain.binaryproto.DataContractRegistry; +import com.jd.blockchain.crypto.AsymmetricKeypair; +import com.jd.blockchain.crypto.HashDigest; +import com.jd.blockchain.crypto.PrivKey; +import com.jd.blockchain.crypto.PubKey; +import com.jd.blockchain.ledger.*; +import com.jd.blockchain.sdk.BlockchainService; +import com.jd.blockchain.sdk.client.GatewayServiceFactory; +import com.jd.blockchain.transaction.SignatureUtils; +import com.jd.blockchain.utils.ConsoleUtils; + +/** + * 注册用户 + * + * @author shaozhuguang + * @create 2018/10/18 + * @since 1.0.0 + */ + +public class SDKDemo_Tx_Persistance { + public static void main(String[] args) { + + String GATEWAY_IPADDR = "127.0.0.1"; + int GATEWAY_PORT = 8081; + if (args != null && args.length == 2) { + GATEWAY_IPADDR = args[0]; + GATEWAY_PORT = Integer.parseInt(args[1]); + } + + // 注册相关class + DataContractRegistry.register(TransactionContent.class); + DataContractRegistry.register(TransactionContentBody.class); + DataContractRegistry.register(TransactionRequest.class); + DataContractRegistry.register(NodeRequest.class); + DataContractRegistry.register(EndpointRequest.class); + DataContractRegistry.register(TransactionResponse.class); + + PrivKey privKey1 = SDKDemo_Params.privkey1; + PubKey pubKey1 = SDKDemo_Params.pubKey1; + PrivKey privKey2 = SDKDemo_Params.privkey1; + PubKey pubKey2 = SDKDemo_Params.pubKey1; + + BlockchainKeypair CLIENT_CERT = new BlockchainKeypair(SDKDemo_Params.pubKey0, SDKDemo_Params.privkey0); + + boolean SECURE = false; + GatewayServiceFactory gatewayServiceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE, + CLIENT_CERT); + BlockchainService blockchainService = gatewayServiceFactory.getBlockchainService(); + + HashDigest[] ledgerHashs = blockchainService.getLedgerHashs(); + // 在本地定义注册账号的 TX; + TransactionTemplate txTemp = blockchainService.newTransaction(ledgerHashs[0]); + + // existed signer + AsymmetricKeypair keyPair1 = new BlockchainKeypair(pubKey1, privKey1); + AsymmetricKeypair keyPair2 = new BlockchainKeypair(pubKey2, privKey2); + + BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate(); + + // 注册 + txTemp.users().register(user.getIdentity()); + + // 定义角色权限; + txTemp.security().roles().configure("MANAGER") + .enable(LedgerPermission.REGISTER_USER, LedgerPermission.REGISTER_DATA_ACCOUNT) + .enable(TransactionPermission.CONTRACT_OPERATION); + txTemp.security().authorziations().forUser(user.getIdentity()).authorize("MANAGER"); + + // TX 准备就绪; + PreparedTransaction prepTx = txTemp.prepare(); + + // 序列化交易内容; + byte[] txContentBytes = BinaryProtocol.encode(prepTx.getTransactionContent(), TransactionContent.class); + + // 反序列化交易内容; + TransactionContent txContent = BinaryProtocol.decode(txContentBytes, TransactionContent.class); + + // 对交易内容签名; + DigitalSignature signature1 = SignatureUtils.sign(txContent, keyPair1); + + // 根据交易内容重新准备交易; + PreparedTransaction decodedPrepTx = blockchainService.prepareTransaction(txContent); + + // 使用私钥进行签名,或附加签名; + decodedPrepTx.addSignature(signature1); + decodedPrepTx.sign(keyPair2); + + // 提交交易; + TransactionResponse transactionResponse = decodedPrepTx.commit(); + // 解析返回结果;如果是合约调用的操作,需要自行解析返回结果; + if (transactionResponse.isSuccess()) { + // 操作结果对应于交易中的操作顺序;无返回结果的操作对应结果为 null; + OperationResult opResult = transactionResponse.getOperationResults()[0];// + Class dataClazz = null;//返回值的类型; + Object value = BytesValueEncoding.decode(opResult.getResult(), dataClazz); + } + + + ConsoleUtils.info("register user complete, result is [%s]", transactionResponse.isSuccess()); + } +} \ No newline at end of file diff --git a/source/storage/pom.xml b/source/storage/pom.xml index 2afb3321..239487c4 100644 --- a/source/storage/pom.xml +++ b/source/storage/pom.xml @@ -3,7 +3,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT storage pom diff --git a/source/storage/storage-composite/pom.xml b/source/storage/storage-composite/pom.xml index 67245540..c4578e00 100644 --- a/source/storage/storage-composite/pom.xml +++ b/source/storage/storage-composite/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain storage - 1.1.3.RELEASE + 1.1.4-SNAPSHOT storage-composite diff --git a/source/storage/storage-redis/pom.xml b/source/storage/storage-redis/pom.xml index b5d2db3d..048b8dc4 100644 --- a/source/storage/storage-redis/pom.xml +++ b/source/storage/storage-redis/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain storage - 1.1.3.RELEASE + 1.1.4-SNAPSHOT storage-redis diff --git a/source/storage/storage-rocksdb/pom.xml b/source/storage/storage-rocksdb/pom.xml index c105925e..af58eb92 100644 --- a/source/storage/storage-rocksdb/pom.xml +++ b/source/storage/storage-rocksdb/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain storage - 1.1.3.RELEASE + 1.1.4-SNAPSHOT storage-rocksdb diff --git a/source/storage/storage-service/pom.xml b/source/storage/storage-service/pom.xml index fab5ed91..b9d50f1a 100644 --- a/source/storage/storage-service/pom.xml +++ b/source/storage/storage-service/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain storage - 1.1.3.RELEASE + 1.1.4-SNAPSHOT storage-service diff --git a/source/test/pom.xml b/source/test/pom.xml index 0905a211..8e730c75 100644 --- a/source/test/pom.xml +++ b/source/test/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT test pom diff --git a/source/test/test-consensus-client/pom.xml b/source/test/test-consensus-client/pom.xml index 7d64f1a4..f7106643 100644 --- a/source/test/test-consensus-client/pom.xml +++ b/source/test/test-consensus-client/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain test - 1.1.3.RELEASE + 1.1.4-SNAPSHOT test-consensus-client diff --git a/source/test/test-consensus-node/pom.xml b/source/test/test-consensus-node/pom.xml index 8268b0e2..372b070d 100644 --- a/source/test/test-consensus-node/pom.xml +++ b/source/test/test-consensus-node/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain test - 1.1.3.RELEASE + 1.1.4-SNAPSHOT test-consensus-node @@ -38,7 +38,7 @@ com.jd.blockchain consensus-bftsmart - 1.1.3.RELEASE + 1.1.4-SNAPSHOT org.springframework.boot diff --git a/source/test/test-integration/pom.xml b/source/test/test-integration/pom.xml index ba432b9d..acbbc3e6 100644 --- a/source/test/test-integration/pom.xml +++ b/source/test/test-integration/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain test - 1.1.3.RELEASE + 1.1.4-SNAPSHOT test-integration diff --git a/source/test/test-ledger/pom.xml b/source/test/test-ledger/pom.xml index c0ef2a27..1f80bfa2 100644 --- a/source/test/test-ledger/pom.xml +++ b/source/test/test-ledger/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain test - 1.1.3.RELEASE + 1.1.4-SNAPSHOT test-ledger diff --git a/source/tools/pom.xml b/source/tools/pom.xml index d2fbc440..e56dbe94 100644 --- a/source/tools/pom.xml +++ b/source/tools/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT tools pom diff --git a/source/tools/tools-initializer-booter/pom.xml b/source/tools/tools-initializer-booter/pom.xml index 7981e5ed..5fa93720 100644 --- a/source/tools/tools-initializer-booter/pom.xml +++ b/source/tools/tools-initializer-booter/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain tools - 1.1.3.RELEASE + 1.1.4-SNAPSHOT tools-initializer-booter diff --git a/source/tools/tools-initializer/pom.xml b/source/tools/tools-initializer/pom.xml index 259c8049..0a089ce4 100644 --- a/source/tools/tools-initializer/pom.xml +++ b/source/tools/tools-initializer/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain tools - 1.1.3.RELEASE + 1.1.4-SNAPSHOT tools-initializer diff --git a/source/tools/tools-keygen-booter/pom.xml b/source/tools/tools-keygen-booter/pom.xml index eecb12f2..36f078b9 100644 --- a/source/tools/tools-keygen-booter/pom.xml +++ b/source/tools/tools-keygen-booter/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain tools - 1.1.3.RELEASE + 1.1.4-SNAPSHOT tools-keygen-booter diff --git a/source/tools/tools-keygen/pom.xml b/source/tools/tools-keygen/pom.xml index 8728029d..ac33efdb 100644 --- a/source/tools/tools-keygen/pom.xml +++ b/source/tools/tools-keygen/pom.xml @@ -5,7 +5,7 @@ com.jd.blockchain tools - 1.1.3.RELEASE + 1.1.4-SNAPSHOT tools-keygen diff --git a/source/utils/pom.xml b/source/utils/pom.xml index 868e9a7b..f35d4d01 100644 --- a/source/utils/pom.xml +++ b/source/utils/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain jdchain-root - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils pom diff --git a/source/utils/utils-common/pom.xml b/source/utils/utils-common/pom.xml index 14c02285..c137ccf4 100644 --- a/source/utils/utils-common/pom.xml +++ b/source/utils/utils-common/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils-common diff --git a/source/utils/utils-http/pom.xml b/source/utils/utils-http/pom.xml index 2f76a9f6..ea4821a7 100644 --- a/source/utils/utils-http/pom.xml +++ b/source/utils/utils-http/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT diff --git a/source/utils/utils-serialize/pom.xml b/source/utils/utils-serialize/pom.xml index 00a67c67..b053c5a9 100644 --- a/source/utils/utils-serialize/pom.xml +++ b/source/utils/utils-serialize/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils-serialize diff --git a/source/utils/utils-test/pom.xml b/source/utils/utils-test/pom.xml index 94b073e5..6d339986 100644 --- a/source/utils/utils-test/pom.xml +++ b/source/utils/utils-test/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils-test diff --git a/source/utils/utils-web-server/pom.xml b/source/utils/utils-web-server/pom.xml index d58aec28..dbc4c670 100644 --- a/source/utils/utils-web-server/pom.xml +++ b/source/utils/utils-web-server/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils-web-server diff --git a/source/utils/utils-web/pom.xml b/source/utils/utils-web/pom.xml index b1408723..7995bceb 100644 --- a/source/utils/utils-web/pom.xml +++ b/source/utils/utils-web/pom.xml @@ -4,7 +4,7 @@ com.jd.blockchain utils - 1.1.3.RELEASE + 1.1.4-SNAPSHOT utils-web