Browse Source

Merge remote-tracking branch 'remotes/origin/hotfix/sdk-tx-submit' into release/1.1.4

tags/1.1.4
zhaoguangwei 5 years ago
parent
commit
379876a037
69 changed files with 334 additions and 153 deletions
  1. +1
    -1
      source/base/pom.xml
  2. +1
    -1
      source/binary-proto/pom.xml
  3. +21
    -11
      source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java
  4. +1
    -1
      source/consensus/consensus-bftsmart/pom.xml
  5. +1
    -1
      source/consensus/consensus-framework/pom.xml
  6. +1
    -1
      source/consensus/consensus-mq/pom.xml
  7. +1
    -1
      source/consensus/pom.xml
  8. +1
    -1
      source/contract/contract-framework/pom.xml
  9. +1
    -1
      source/contract/contract-jvm/pom.xml
  10. +1
    -1
      source/contract/contract-maven-plugin/pom.xml
  11. +1
    -1
      source/contract/contract-samples/pom.xml
  12. +1
    -1
      source/contract/pom.xml
  13. +1
    -1
      source/crypto/crypto-adv/pom.xml
  14. +1
    -1
      source/crypto/crypto-classic/pom.xml
  15. +1
    -1
      source/crypto/crypto-framework/pom.xml
  16. +1
    -1
      source/crypto/crypto-pki/pom.xml
  17. +1
    -1
      source/crypto/crypto-sm/pom.xml
  18. +1
    -1
      source/crypto/pom.xml
  19. +1
    -1
      source/deployment/deployment-gateway/pom.xml
  20. +1
    -1
      source/deployment/deployment-peer/pom.xml
  21. +1
    -1
      source/deployment/pom.xml
  22. +1
    -1
      source/gateway/pom.xml
  23. +1
    -1
      source/ledger/ledger-core/pom.xml
  24. +1
    -1
      source/ledger/ledger-model/pom.xml
  25. +9
    -78
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java
  26. +108
    -0
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/StatefulPreparedTx.java
  27. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java
  28. +1
    -1
      source/ledger/ledger-rpc/pom.xml
  29. +1
    -1
      source/ledger/pom.xml
  30. +1
    -1
      source/manager/manager-booter/pom.xml
  31. +1
    -1
      source/manager/manager-model/pom.xml
  32. +1
    -1
      source/manager/manager-service/pom.xml
  33. +1
    -1
      source/manager/manager-web/pom.xml
  34. +1
    -1
      source/manager/pom.xml
  35. +1
    -1
      source/peer/pom.xml
  36. +1
    -1
      source/pom.xml
  37. +1
    -1
      source/runtime/pom.xml
  38. +1
    -1
      source/runtime/runtime-context/pom.xml
  39. +1
    -1
      source/runtime/runtime-modular-booter/pom.xml
  40. +1
    -1
      source/runtime/runtime-modular/pom.xml
  41. +1
    -1
      source/sdk/pom.xml
  42. +1
    -1
      source/sdk/sdk-base/pom.xml
  43. +10
    -0
      source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java
  44. +10
    -0
      source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java
  45. +1
    -1
      source/sdk/sdk-client/pom.xml
  46. +1
    -1
      source/sdk/sdk-samples/pom.xml
  47. +112
    -0
      source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Tx_Persistance.java
  48. +1
    -1
      source/storage/pom.xml
  49. +1
    -1
      source/storage/storage-composite/pom.xml
  50. +1
    -1
      source/storage/storage-redis/pom.xml
  51. +1
    -1
      source/storage/storage-rocksdb/pom.xml
  52. +1
    -1
      source/storage/storage-service/pom.xml
  53. +1
    -1
      source/test/pom.xml
  54. +1
    -1
      source/test/test-consensus-client/pom.xml
  55. +2
    -2
      source/test/test-consensus-node/pom.xml
  56. +1
    -1
      source/test/test-integration/pom.xml
  57. +1
    -1
      source/test/test-ledger/pom.xml
  58. +1
    -1
      source/tools/pom.xml
  59. +1
    -1
      source/tools/tools-initializer-booter/pom.xml
  60. +1
    -1
      source/tools/tools-initializer/pom.xml
  61. +1
    -1
      source/tools/tools-keygen-booter/pom.xml
  62. +1
    -1
      source/tools/tools-keygen/pom.xml
  63. +1
    -1
      source/utils/pom.xml
  64. +1
    -1
      source/utils/utils-common/pom.xml
  65. +1
    -1
      source/utils/utils-http/pom.xml
  66. +1
    -1
      source/utils/utils-serialize/pom.xml
  67. +1
    -1
      source/utils/utils-test/pom.xml
  68. +1
    -1
      source/utils/utils-web-server/pom.xml
  69. +1
    -1
      source/utils/utils-web/pom.xml

+ 1
- 1
source/base/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>base</artifactId>



+ 1
- 1
source/binary-proto/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>binary-proto</artifactId>



+ 21
- 11
source/binary-proto/src/main/java/com/jd/blockchain/binaryproto/BinaryProtocol.java View File

@@ -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> 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> T decodeAs(byte[] dataSegment, Class<T> contractType) {
public static <T> T decode(byte[] dataSegment, Class<T> contractType) {
return decode(dataSegment, contractType, true);
}

public static <T> T decode(byte[] dataSegment, Class<T> 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> T decodeAs(byte[] dataSegment, Class<T> contractType) {
return decode(dataSegment, contractType, true);
}

@Deprecated
public static <T> T decodeAs(byte[] dataSegment, Class<T> contractType, boolean autoRegister) {
return decode(dataSegment, contractType, autoRegister);
}

}

+ 1
- 1
source/consensus/consensus-bftsmart/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>consensus</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>consensus-bftsmart</artifactId>



+ 1
- 1
source/consensus/consensus-framework/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>consensus</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>consensus-framework</artifactId>



+ 1
- 1
source/consensus/consensus-mq/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>consensus</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>consensus-mq</artifactId>



+ 1
- 1
source/consensus/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>consensus</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/contract/contract-framework/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>contract</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>contract-framework</artifactId>



+ 1
- 1
source/contract/contract-jvm/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>contract</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>contract-jvm</artifactId>



+ 1
- 1
source/contract/contract-maven-plugin/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>contract</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>contract-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>


+ 1
- 1
source/contract/contract-samples/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>contract</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/contract/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>contract</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/crypto/crypto-adv/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>crypto-adv</artifactId>



+ 1
- 1
source/crypto/crypto-classic/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>crypto-classic</artifactId>



+ 1
- 1
source/crypto/crypto-framework/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>crypto-framework</artifactId>



+ 1
- 1
source/crypto/crypto-pki/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>crypto</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/crypto/crypto-sm/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>crypto</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>crypto-sm</artifactId>



+ 1
- 1
source/crypto/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>crypto</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/deployment/deployment-gateway/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>deployment</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>deployment-gateway</artifactId>



+ 1
- 1
source/deployment/deployment-peer/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>deployment</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>deployment-peer</artifactId>



+ 1
- 1
source/deployment/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>deployment</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/gateway/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>gateway</artifactId>



+ 1
- 1
source/ledger/ledger-core/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>ledger</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>ledger-core</artifactId>



+ 1
- 1
source/ledger/ledger-model/pom.xml View File

@@ -6,7 +6,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>ledger</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>ledger-model</artifactId>



+ 9
- 78
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PreparedTx.java View File

@@ -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<OperationResultHandle> 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<OperationResultHandle>() {
@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());
}
}
}

}

+ 108
- 0
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/StatefulPreparedTx.java View File

@@ -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<OperationResultHandle> opReturnValueHandlerList) {
super(txReqBuilder, txProcessor);
this.stateManager = stateManager;

this.opReturnValueHandlers = opReturnValueHandlerList
.toArray(new OperationResultHandle[opReturnValueHandlerList.size()]);
// 按照操作索引升序排列;
Arrays.sort(opReturnValueHandlers, new Comparator<OperationResultHandle>() {
@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());
}
}
}

}

+ 1
- 1
source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/TxTemplate.java View File

@@ -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


+ 1
- 1
source/ledger/ledger-rpc/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>ledger</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>ledger-rpc</artifactId>



+ 1
- 1
source/ledger/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>ledger</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/manager/manager-booter/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>manager</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/manager/manager-model/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>manager</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/manager/manager-service/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>manager</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/manager/manager-web/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<artifactId>manager</artifactId>
<groupId>com.jd.blockchain</groupId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>



+ 1
- 1
source/manager/pom.xml View File

@@ -11,7 +11,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>manager</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/peer/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>peer</artifactId>



+ 1
- 1
source/pom.xml View File

@@ -11,7 +11,7 @@

<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
<packaging>pom</packaging>
<description>jdchain</description>



+ 1
- 1
source/runtime/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>runtime</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/runtime/runtime-context/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>runtime</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>runtime-context</artifactId>



+ 1
- 1
source/runtime/runtime-modular-booter/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>runtime</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>runtime-modular-booter</artifactId>
</project>

+ 1
- 1
source/runtime/runtime-modular/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>runtime</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>runtime-modular</artifactId>



+ 1
- 1
source/sdk/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>sdk</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/sdk/sdk-base/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>sdk</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>sdk-base</artifactId>



+ 10
- 0
source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/BlockchainTransactionService.java View File

@@ -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);

// /**
// * 以指定的科目和流水号发起新交易;
// *


+ 10
- 0
source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/proxy/BlockchainServiceProxy.java View File

@@ -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,


+ 1
- 1
source/sdk/sdk-client/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>sdk</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>sdk-client</artifactId>



+ 1
- 1
source/sdk/sdk-samples/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>sdk</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>sdk-samples</artifactId>



+ 112
- 0
source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Tx_Persistance.java View File

@@ -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());
}
}

+ 1
- 1
source/storage/pom.xml View File

@@ -3,7 +3,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>storage</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/storage/storage-composite/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>storage</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>storage-composite</artifactId>



+ 1
- 1
source/storage/storage-redis/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>storage</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>storage-redis</artifactId>



+ 1
- 1
source/storage/storage-rocksdb/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>storage</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>storage-rocksdb</artifactId>



+ 1
- 1
source/storage/storage-service/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>storage</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>storage-service</artifactId>



+ 1
- 1
source/test/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>test</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/test/test-consensus-client/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>test</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>test-consensus-client</artifactId>



+ 2
- 2
source/test/test-consensus-node/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>test</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>test-consensus-node</artifactId>
<dependencies>
@@ -38,7 +38,7 @@
<dependency>
<groupId>com.jd.blockchain</groupId>
<artifactId>consensus-bftsmart</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>


+ 1
- 1
source/test/test-integration/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>test</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>test-integration</artifactId>



+ 1
- 1
source/test/test-ledger/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>test</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>test-ledger</artifactId>



+ 1
- 1
source/tools/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>tools</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/tools/tools-initializer-booter/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>tools</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>tools-initializer-booter</artifactId>



+ 1
- 1
source/tools/tools-initializer/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>tools</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>tools-initializer</artifactId>



+ 1
- 1
source/tools/tools-keygen-booter/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>tools</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>tools-keygen-booter</artifactId>



+ 1
- 1
source/tools/tools-keygen/pom.xml View File

@@ -5,7 +5,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>tools</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>tools-keygen</artifactId>



+ 1
- 1
source/utils/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>jdchain-root</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils</artifactId>
<packaging>pom</packaging>


+ 1
- 1
source/utils/utils-common/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils-common</artifactId>



+ 1
- 1
source/utils/utils-http/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>

<properties>


+ 1
- 1
source/utils/utils-serialize/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils-serialize</artifactId>



+ 1
- 1
source/utils/utils-test/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils-test</artifactId>



+ 1
- 1
source/utils/utils-web-server/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils-web-server</artifactId>



+ 1
- 1
source/utils/utils-web/pom.xml View File

@@ -4,7 +4,7 @@
<parent>
<groupId>com.jd.blockchain</groupId>
<artifactId>utils</artifactId>
<version>1.1.3.RELEASE</version>
<version>1.1.4-SNAPSHOT</version>
</parent>
<artifactId>utils-web</artifactId>
<dependencies>


Loading…
Cancel
Save