Browse Source

Merge remote-tracking branch 'origin/develop' into feature/admin1-local

tags/1.1.0
shaozhuguang 5 years ago
parent
commit
e1325a3e40
74 changed files with 738 additions and 574 deletions
  1. +10
    -10
      source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java
  2. +1
    -1
      source/deployment/deployment-peer/src/main/resources/scripts/keygen.sh
  3. +0
    -0
      source/deployment/deployment-peer/src/main/resources/scripts/manager-start.sh
  4. +0
    -0
      source/deployment/deployment-peer/src/main/resources/scripts/manager-stop.sh
  5. +0
    -0
      source/deployment/deployment-peer/src/main/resources/scripts/peer-shutdown.sh
  6. +0
    -0
      source/deployment/deployment-peer/src/main/resources/scripts/peer-startup.sh
  7. +12
    -1
      source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java
  8. +31
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AccountQuery.java
  9. +3
    -3
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java
  10. +1
    -25
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountQuery.java
  11. +27
    -29
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountSet.java
  12. +4
    -4
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java
  13. +1
    -28
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountQuery.java
  14. +24
    -14
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountSet.java
  15. +52
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyAccountSet.java
  16. +6
    -110
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyLedgerDataset.java
  17. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminDataset.java
  18. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitializer.java
  19. +20
    -12
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQuery.java
  20. +30
    -30
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java
  21. +6
    -6
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerRepositoryImpl.java
  22. +3
    -3
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManagerImpl.java
  23. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerTransactionContext.java
  24. +6
    -6
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java
  25. +34
    -28
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java
  26. +2
    -4
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleProvable.java
  27. +4
    -4
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java
  28. +24
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionQuery.java
  29. +9
    -5
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionSet.java
  30. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java
  31. +1
    -27
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountQuery.java
  32. +15
    -15
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountSet.java
  33. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserRoleDataset.java
  34. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/AbtractContractEventSendOperationHandle.java
  35. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/DataAccountKVSetOperationHandle.java
  36. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantRegisterOperationHandle.java
  37. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantStateUpdateOperationHandle.java
  38. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/UserAuthorizeOperationHandle.java
  39. +6
    -6
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/AccountSetTest.java
  40. +2
    -2
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/BaseAccountTest.java
  41. +12
    -12
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java
  42. +2
    -2
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerAccountTest.java
  43. +7
    -7
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerAdminDatasetTest.java
  44. +21
    -21
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java
  45. +2
    -1
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java
  46. +1
    -6
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/contract/EventHandle.java
  47. +2
    -5
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/AccountHeader.java
  48. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerAdminSettings.java
  49. +15
    -0
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/MerkleSnapshot.java
  50. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantRegisterOperation.java
  51. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ParticipantStateUpdateOperation.java
  52. +1
    -1
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/UserAuthorizationSettings.java
  53. +5
    -5
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantRegisterOpTemplate.java
  54. +5
    -5
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ParticipantStateUpdateOpTemplate.java
  55. +7
    -7
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/UserAuthorizeOpTemplate.java
  56. +31
    -31
      source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java
  57. +8
    -2
      source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java
  58. +12
    -0
      source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java
  59. +19
    -19
      source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Constant.java
  60. +26
    -0
      source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_RoleConfig_Demo.java
  61. +44
    -0
      source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDK_User2Role_Demo.java
  62. +9
    -9
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java
  63. +4
    -4
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java
  64. +4
    -4
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java
  65. +2
    -2
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java
  66. +3
    -3
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java
  67. +2
    -2
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4Bftsmart.java
  68. +2
    -2
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4MQ.java
  69. +15
    -15
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java
  70. +4
    -4
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java
  71. +4
    -4
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java
  72. +1
    -1
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java
  73. +114
    -7
      source/test/test-ledger/src/test/java/test/com/jd/blockchain/test/ledger/RolesAuthorizationTest.java
  74. +1
    -1
      source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java

+ 10
- 10
source/base/src/main/java/com/jd/blockchain/consts/DataCodes.java View File

@@ -7,6 +7,8 @@ package com.jd.blockchain.consts;
* *
*/ */
public interface DataCodes { public interface DataCodes {
public static final int MERKLE_SNAPSHOT = 0x070;


public static final int BYTES_VALUE = 0x080; public static final int BYTES_VALUE = 0x080;


@@ -57,13 +59,13 @@ public interface DataCodes {
public static final int TX_RESPONSE = 0x360; public static final int TX_RESPONSE = 0x360;


public static final int TX_OP_RESULT = 0x370; public static final int TX_OP_RESULT = 0x370;
public static final int TX_OP_ROLE_CONFIGURE = 0x371; public static final int TX_OP_ROLE_CONFIGURE = 0x371;
public static final int TX_OP_ROLE_CONFIGURE_ENTRY = 0x372; public static final int TX_OP_ROLE_CONFIGURE_ENTRY = 0x372;
public static final int TX_OP_USER_ROLES_AUTHORIZE = 0x373; public static final int TX_OP_USER_ROLES_AUTHORIZE = 0x373;
public static final int TX_OP_USER_ROLE_AUTHORIZE_ENTRY = 0x374; public static final int TX_OP_USER_ROLE_AUTHORIZE_ENTRY = 0x374;


// enum types of permissions; // enum types of permissions;
@@ -74,11 +76,11 @@ public interface DataCodes {
public static final int PRIVILEGE_SET = 0x410; public static final int PRIVILEGE_SET = 0x410;


public static final int ROLE_SET = 0x411; public static final int ROLE_SET = 0x411;
public static final int SECURITY_INIT_SETTING = 0x420; public static final int SECURITY_INIT_SETTING = 0x420;


public static final int SECURITY_ROLE_INIT_SETTING = 0x421; public static final int SECURITY_ROLE_INIT_SETTING = 0x421;
public static final int SECURITY_USER_AUTH_INIT_SETTING = 0x422; public static final int SECURITY_USER_AUTH_INIT_SETTING = 0x422;


// contract types of metadata; // contract types of metadata;
@@ -103,7 +105,6 @@ public interface DataCodes {
// //
// public static final int METADATA_CRYPTO_SETTING = 0x642; // public static final int METADATA_CRYPTO_SETTING = 0x642;



// public static final int METADATA_CONSENSUS_NODE = 0x630; // public static final int METADATA_CONSENSUS_NODE = 0x630;


public static final int METADATA_CONSENSUS_SETTING = 0x631; public static final int METADATA_CONSENSUS_SETTING = 0x631;
@@ -113,10 +114,10 @@ public interface DataCodes {
public static final int METADATA_PARTICIPANT_STATE_INFO = 0x641; public static final int METADATA_PARTICIPANT_STATE_INFO = 0x641;


public static final int METADATA_CRYPTO_SETTING = 0x642; public static final int METADATA_CRYPTO_SETTING = 0x642;
public static final int METADATA_CRYPTO_SETTING_PROVIDER = 0x643; public static final int METADATA_CRYPTO_SETTING_PROVIDER = 0x643;


// public static final int ACCOUNT = 0x700;
// public static final int ACCOUNT = 0x700;


public static final int ACCOUNT_HEADER = 0x710; public static final int ACCOUNT_HEADER = 0x710;


@@ -194,5 +195,4 @@ public interface DataCodes {


public static final int CONSENSUS_MSGQUEUE_BLOCK_SETTINGS = CONSENSUS_MSGQUEUE | 0x05; public static final int CONSENSUS_MSGQUEUE_BLOCK_SETTINGS = CONSENSUS_MSGQUEUE | 0x05;


} }

+ 1
- 1
source/deployment/deployment-peer/src/main/resources/scripts/keygen.sh View File

@@ -12,5 +12,5 @@ else
else else
echo "keys file will be saved $HOME/config/keys" echo "keys file will be saved $HOME/config/keys"
fi fi
java -jar $HOME/libs/$boot_file -o $HOME/config/keys -l $HOME/config/init/local.conf $*
java -jar $HOME/libs/$boot_file -o $HOME/config/keys $*
fi fi

source/deployment/deployment-peer/src/main/resources/scripts/jump-start.sh → source/deployment/deployment-peer/src/main/resources/scripts/manager-start.sh View File


source/deployment/deployment-peer/src/main/resources/scripts/jump-stop.sh → source/deployment/deployment-peer/src/main/resources/scripts/manager-stop.sh View File


source/deployment/deployment-peer/src/main/resources/scripts/shutdown.sh → source/deployment/deployment-peer/src/main/resources/scripts/peer-shutdown.sh View File


source/deployment/deployment-peer/src/main/resources/scripts/startup.sh → source/deployment/deployment-peer/src/main/resources/scripts/peer-startup.sh View File


+ 12
- 1
source/gateway/src/main/java/com/jd/blockchain/gateway/web/GatewayWebServerConfigurer.java View File

@@ -35,7 +35,18 @@ public class GatewayWebServerConfigurer implements WebMvcConfigurer {
JSONSerializeUtils.disableCircularReferenceDetect(); JSONSerializeUtils.disableCircularReferenceDetect();
JSONSerializeUtils.configStringSerializer(ByteArray.class); JSONSerializeUtils.configStringSerializer(ByteArray.class);
DataContractRegistry.register(BftsmartNodeSettings.class); DataContractRegistry.register(BftsmartNodeSettings.class);
// DataContractRegistry.register(LedgerAdminInfo.class);

// 注册角色/权限相关接口
DataContractRegistry.register(RolesConfigureOperation.class);
DataContractRegistry.register(RolesConfigureOperation.RolePrivilegeEntry.class);
DataContractRegistry.register(UserAuthorizeOperation.class);
DataContractRegistry.register(UserAuthorizeOperation.UserRolesEntry.class);
DataContractRegistry.register(PrivilegeSet.class);
DataContractRegistry.register(RoleSet.class);
DataContractRegistry.register(SecurityInitSettings.class);
DataContractRegistry.register(RoleInitSettings.class);
DataContractRegistry.register(UserAuthInitSettings.class);
DataContractRegistry.register(LedgerMetadata_V2.class);
} }






+ 31
- 0
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AccountQuery.java View File

@@ -0,0 +1,31 @@
package com.jd.blockchain.ledger.core;

import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.utils.Bytes;

public interface AccountQuery<T> extends MerkleProvable {

AccountHeader[] getHeaders(int fromIndex, int count);

/**
* 返回总数;
*
* @return
*/
long getTotal();

boolean contains(Bytes address);

/**
* 返回账户实例;
*
* @param address Base58 格式的账户地址;
* @return 账户实例,如果不存在则返回 null;
*/
T getAccount(String address);

T getAccount(Bytes address);

T getAccount(Bytes address, long version);

}

+ 3
- 3
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java View File

@@ -14,9 +14,9 @@ public class ContractAccount implements ContractInfo {
private static final Bytes CHAIN_CODE_KEY = Bytes.fromString("CHAIN-CODE"); private static final Bytes CHAIN_CODE_KEY = Bytes.fromString("CHAIN-CODE");
private BaseAccount accBase;
private MerkleAccount accBase;
public ContractAccount(BaseAccount accBase) {
public ContractAccount(MerkleAccount accBase) {
this.accBase = accBase; this.accBase = accBase;
} }
@@ -57,7 +57,7 @@ public class ContractAccount implements ContractInfo {
} }
public long getChaincodeVersion() { public long getChaincodeVersion() {
return accBase.getKeyVersion(CHAIN_CODE_KEY);
return accBase.getVersion(CHAIN_CODE_KEY);
} }
public long setProperty(Bytes key, String value, long version) { public long setProperty(Bytes key, String value, long version) {


+ 1
- 25
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountQuery.java View File

@@ -1,29 +1,5 @@
package com.jd.blockchain.ledger.core; package com.jd.blockchain.ledger.core;


import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.utils.Bytes;

public interface ContractAccountQuery {

AccountHeader[] getAccounts(int fromIndex, int count);

HashDigest getRootHash();

/**
* 返回合约总数;
*
* @return
*/
long getTotalCount();

MerkleProof getProof(Bytes address);

boolean contains(Bytes address);

ContractAccount getContract(Bytes address);

ContractAccount getContract(Bytes address, long version);
public interface ContractAccountQuery extends AccountQuery<ContractAccount> {


} }

+ 27
- 29
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountSet.java View File

@@ -11,24 +11,24 @@ import com.jd.blockchain.storage.service.VersioningKVStorage;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.Transactional; import com.jd.blockchain.utils.Transactional;
public class ContractAccountSet implements MerkleProvable, Transactional, ContractAccountQuery {
public class ContractAccountSet implements Transactional, ContractAccountQuery {
private AccountSet accountSet;
private MerkleAccountSet accountSet;
public ContractAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, public ContractAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage,
VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) { VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy);
accountSet = new MerkleAccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy);
} }
public ContractAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix, public ContractAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly,
AccountAccessPolicy accessPolicy) { AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy);
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy);
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex,count);
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getHeaders(fromIndex, count);
} }
public boolean isReadonly() { public boolean isReadonly() {
@@ -38,7 +38,7 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
void setReadonly() { void setReadonly() {
accountSet.setReadonly(); accountSet.setReadonly();
} }
@Override @Override
public HashDigest getRootHash() { public HashDigest getRootHash() {
return accountSet.getRootHash(); return accountSet.getRootHash();
@@ -50,8 +50,8 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
* @return * @return
*/ */
@Override @Override
public long getTotalCount() {
return accountSet.getTotalCount();
public long getTotal() {
return accountSet.getTotal();
} }
@Override @Override
@@ -65,33 +65,34 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
} }
@Override @Override
public ContractAccount getContract(Bytes address) {
BaseAccount accBase = accountSet.getAccount(address);
public ContractAccount getAccount(Bytes address) {
MerkleAccount accBase = accountSet.getAccount(address);
return new ContractAccount(accBase); return new ContractAccount(accBase);
} }
@Override @Override
public ContractAccount getContract(Bytes address, long version) {
BaseAccount accBase = accountSet.getAccount(address, version);
public ContractAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
}
@Override
public ContractAccount getAccount(Bytes address, long version) {
MerkleAccount accBase = accountSet.getAccount(address, version);
return new ContractAccount(accBase); return new ContractAccount(accBase);
} }
/** /**
* 部署一项新的合约链码; * 部署一项新的合约链码;
* *
* @param address
* 合约账户地址;
* @param pubKey
* 合约账户公钥;
* @param addressSignature
* 地址签名;合约账户的私钥对地址的签名;
* @param chaincode
* 链码内容;
* @param address 合约账户地址;
* @param pubKey 合约账户公钥;
* @param addressSignature 地址签名;合约账户的私钥对地址的签名;
* @param chaincode 链码内容;
* @return 合约账户; * @return 合约账户;
*/ */
public ContractAccount deploy(Bytes address, PubKey pubKey, DigitalSignature addressSignature, byte[] chaincode) { public ContractAccount deploy(Bytes address, PubKey pubKey, DigitalSignature addressSignature, byte[] chaincode) {
// TODO: 校验和记录合约地址签名; // TODO: 校验和记录合约地址签名;
BaseAccount accBase = accountSet.register(address, pubKey);
MerkleAccount accBase = accountSet.register(address, pubKey);
ContractAccount contractAcc = new ContractAccount(accBase); ContractAccount contractAcc = new ContractAccount(accBase);
contractAcc.setChaincode(chaincode, -1); contractAcc.setChaincode(chaincode, -1);
return contractAcc; return contractAcc;
@@ -100,16 +101,13 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
/** /**
* 更新指定账户的链码; * 更新指定账户的链码;
* *
* @param address
* 合约账户地址;
* @param chaincode
* 链码内容;
* @param version
* 链码版本;
* @param address 合约账户地址;
* @param chaincode 链码内容;
* @param version 链码版本;
* @return 返回链码的新版本号; * @return 返回链码的新版本号;
*/ */
public long update(Bytes address, byte[] chaincode, long version) { public long update(Bytes address, byte[] chaincode, long version) {
BaseAccount accBase = accountSet.getAccount(address);
MerkleAccount accBase = accountSet.getAccount(address);
ContractAccount contractAcc = new ContractAccount(accBase); ContractAccount contractAcc = new ContractAccount(accBase);
return contractAcc.setChaincode(chaincode, version); return contractAcc.setChaincode(chaincode, version);
} }


+ 4
- 4
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java View File

@@ -13,9 +13,9 @@ import com.jd.blockchain.utils.Bytes;
public class DataAccount implements AccountHeader, MerkleProvable { public class DataAccount implements AccountHeader, MerkleProvable {
private BaseAccount baseAccount;
private MerkleAccount baseAccount;
public DataAccount(BaseAccount accBase) {
public DataAccount(MerkleAccount accBase) {
this.baseAccount = accBase; this.baseAccount = accBase;
} }
@@ -135,7 +135,7 @@ public class DataAccount implements AccountHeader, MerkleProvable {
* @return * @return
*/ */
public long getDataVersion(String key) { public long getDataVersion(String key) {
return baseAccount.getKeyVersion(Bytes.fromString(key));
return baseAccount.getVersion(Bytes.fromString(key));
} }
/** /**
@@ -146,7 +146,7 @@ public class DataAccount implements AccountHeader, MerkleProvable {
* @return * @return
*/ */
public long getDataVersion(Bytes key) { public long getDataVersion(Bytes key) {
return baseAccount.getKeyVersion(key);
return baseAccount.getVersion(key);
} }
/** /**


+ 1
- 28
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountQuery.java View File

@@ -1,32 +1,5 @@
package com.jd.blockchain.ledger.core; package com.jd.blockchain.ledger.core;


import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.utils.Bytes;

public interface DataAccountQuery {

AccountHeader[] getAccounts(int fromIndex, int count);

HashDigest getRootHash();

long getTotalCount();

/**
* 返回账户的存在性证明;
*/
MerkleProof getProof(Bytes address);

/**
* 返回数据账户; <br>
* 如果不存在,则返回 null;
*
* @param address
* @return
*/
DataAccount getDataAccount(Bytes address);

DataAccount getDataAccount(Bytes address, long version);
public interface DataAccountQuery extends AccountQuery<DataAccount> {


} }

+ 24
- 14
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountSet.java View File

@@ -11,24 +11,24 @@ import com.jd.blockchain.storage.service.VersioningKVStorage;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.Transactional; import com.jd.blockchain.utils.Transactional;
public class DataAccountSet implements MerkleProvable, Transactional, DataAccountQuery {
public class DataAccountSet implements Transactional, DataAccountQuery {
private AccountSet accountSet;
private MerkleAccountSet accountSet;
public DataAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage, public DataAccountSet(CryptoSetting cryptoSetting, String prefix, ExPolicyKVStorage exStorage,
VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) { VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy);
accountSet = new MerkleAccountSet(cryptoSetting, prefix, exStorage, verStorage, accessPolicy);
} }
public DataAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix, public DataAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String prefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly,
AccountAccessPolicy accessPolicy) { AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy);
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, prefix, exStorage, verStorage, readonly, accessPolicy);
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex, count);
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getHeaders(fromIndex, count);
} }
public boolean isReadonly() { public boolean isReadonly() {
@@ -38,15 +38,20 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
void setReadonly() { void setReadonly() {
accountSet.setReadonly(); accountSet.setReadonly();
} }
@Override @Override
public HashDigest getRootHash() { public HashDigest getRootHash() {
return accountSet.getRootHash(); return accountSet.getRootHash();
} }
@Override @Override
public long getTotalCount() {
return accountSet.getTotalCount();
public long getTotal() {
return accountSet.getTotal();
}
@Override
public boolean contains(Bytes address) {
return accountSet.contains(address);
} }
/** /**
@@ -59,10 +64,15 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
public DataAccount register(Bytes address, PubKey pubKey, DigitalSignature addressSignature) { public DataAccount register(Bytes address, PubKey pubKey, DigitalSignature addressSignature) {
// TODO: 未实现对地址签名的校验和记录; // TODO: 未实现对地址签名的校验和记录;
BaseAccount accBase = accountSet.register(address, pubKey);
MerkleAccount accBase = accountSet.register(address, pubKey);
return new DataAccount(accBase); return new DataAccount(accBase);
} }
@Override
public DataAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
}
/** /**
* 返回数据账户; <br> * 返回数据账户; <br>
* 如果不存在,则返回 null; * 如果不存在,则返回 null;
@@ -71,8 +81,8 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
* @return * @return
*/ */
@Override @Override
public DataAccount getDataAccount(Bytes address) {
BaseAccount accBase = accountSet.getAccount(address);
public DataAccount getAccount(Bytes address) {
MerkleAccount accBase = accountSet.getAccount(address);
if (accBase == null) { if (accBase == null) {
return null; return null;
} }
@@ -80,8 +90,8 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
} }
@Override @Override
public DataAccount getDataAccount(Bytes address, long version) {
BaseAccount accBase = accountSet.getAccount(address, version);
public DataAccount getAccount(Bytes address, long version) {
MerkleAccount accBase = accountSet.getAccount(address, version);
return new DataAccount(accBase); return new DataAccount(accBase);
} }


+ 52
- 0
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyAccountSet.java View File

@@ -0,0 +1,52 @@
package com.jd.blockchain.ledger.core;

import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.utils.Bytes;

public class EmptyAccountSet<T> implements AccountQuery<T> {
private static final AccountHeader[] EMPTY = {};

@Override
public HashDigest getRootHash() {
return null;
}

@Override
public MerkleProof getProof(Bytes key) {
return null;
}

@Override
public AccountHeader[] getHeaders(int fromIndex, int count) {
return EMPTY;
}

@Override
public long getTotal() {
return 0;
}

@Override
public boolean contains(Bytes address) {
return false;
}

@Override
public T getAccount(String address) {
return null;
}

@Override
public T getAccount(Bytes address) {
return null;
}

@Override
public T getAccount(Bytes address, long version) {
return null;
}

}

+ 6
- 110
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyLedgerDataset.java View File

@@ -1,7 +1,6 @@
package com.jd.blockchain.ledger.core; package com.jd.blockchain.ledger.core;


import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.LedgerAdminSettings; import com.jd.blockchain.ledger.LedgerAdminSettings;
import com.jd.blockchain.ledger.MerkleProof; import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.ledger.ParticipantDataQuery; import com.jd.blockchain.ledger.ParticipantDataQuery;
@@ -90,120 +89,17 @@ public class EmptyLedgerDataset implements LedgerDataQuery {
} }
private static class EmptyUserAccountSet implements UserAccountQuery{
private static class EmptyUserAccountSet extends EmptyAccountSet<UserAccount> implements UserAccountQuery{


@Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return null;
}

@Override
public long getTotalCount() {
return 0;
}

@Override
public HashDigest getRootHash() {
return null;
}

@Override
public MerkleProof getProof(Bytes key) {
return null;
}

@Override
public UserAccount getUser(String address) {
return null;
}

@Override
public UserAccount getUser(Bytes address) {
return null;
}

@Override
public boolean contains(Bytes address) {
return false;
}

@Override
public UserAccount getUser(Bytes address, long version) {
return null;
}
} }
private static class EmptyDataAccountSet implements DataAccountQuery{

@Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return null;
}

@Override
public HashDigest getRootHash() {
return null;
}

@Override
public long getTotalCount() {
return 0;
}

@Override
public MerkleProof getProof(Bytes address) {
return null;
}
private static class EmptyDataAccountSet extends EmptyAccountSet<DataAccount> implements DataAccountQuery{


@Override
public DataAccount getDataAccount(Bytes address) {
return null;
}

@Override
public DataAccount getDataAccount(Bytes address, long version) {
return null;
}
}
private static class EmptyContractAccountSet extends EmptyAccountSet<ContractAccount> implements ContractAccountQuery{
} }


private static class EmptyContractAccountSet implements ContractAccountQuery{

@Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return null;
}

@Override
public HashDigest getRootHash() {
return null;
}

@Override
public long getTotalCount() {
return 0;
}

@Override
public MerkleProof getProof(Bytes address) {
return null;
}

@Override
public boolean contains(Bytes address) {
return false;
}

@Override
public ContractAccount getContract(Bytes address) {
return null;
}

@Override
public ContractAccount getContract(Bytes address, long version) {
return null;
}
}
} }

+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerAdminDataset.java View File

@@ -16,7 +16,7 @@ import com.jd.blockchain.ledger.LedgerMetadata_V2;
import com.jd.blockchain.ledger.LedgerSettings; import com.jd.blockchain.ledger.LedgerSettings;
import com.jd.blockchain.ledger.ParticipantNode; import com.jd.blockchain.ledger.ParticipantNode;
import com.jd.blockchain.ledger.RolePrivilegeSettings; import com.jd.blockchain.ledger.RolePrivilegeSettings;
import com.jd.blockchain.ledger.UserRolesSettings;
import com.jd.blockchain.ledger.UserAuthorizationSettings;
import com.jd.blockchain.storage.service.ExPolicyKVStorage; import com.jd.blockchain.storage.service.ExPolicyKVStorage;
import com.jd.blockchain.storage.service.ExPolicyKVStorage.ExPolicy; import com.jd.blockchain.storage.service.ExPolicyKVStorage.ExPolicy;
import com.jd.blockchain.storage.service.VersioningKVStorage; import com.jd.blockchain.storage.service.VersioningKVStorage;
@@ -105,7 +105,7 @@ public class LedgerAdminDataset implements Transactional, LedgerAdminDataQuery,
} }
@Override @Override
public UserRolesSettings getUserRoles() {
public UserAuthorizationSettings getAuthorizations() {
return userRoles; return userRoles;
} }


+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitializer.java View File

@@ -272,12 +272,12 @@ public class LedgerInitializer {
} }


@Override @Override
public LedgerDataQuery getDataSet(LedgerBlock block) {
public LedgerDataQuery getLedgerData(LedgerBlock block) {
return dataset; return dataset;
} }


@Override @Override
public TransactionSet getTransactionSet(LedgerBlock block) {
public TransactionQuery getTransactionSet(LedgerBlock block) {
return null; return null;
} }




+ 20
- 12
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQuery.java View File

@@ -54,16 +54,30 @@ public interface LedgerQuery {
LedgerAdminInfo getAdminInfo(); LedgerAdminInfo getAdminInfo();


LedgerAdminInfo getAdminInfo(LedgerBlock block); LedgerAdminInfo getAdminInfo(LedgerBlock block);
LedgerAdminSettings getAdminSettings(); LedgerAdminSettings getAdminSettings();
LedgerAdminSettings getAdminSettings(LedgerBlock block); LedgerAdminSettings getAdminSettings(LedgerBlock block);


LedgerBlock getBlock(HashDigest hash); LedgerBlock getBlock(HashDigest hash);


LedgerDataQuery getDataSet(LedgerBlock block);
/**
* 返回指定
* @param block
* @return
*/
LedgerDataQuery getLedgerData(LedgerBlock block);
/**
* 返回最新区块对应的账本数据;
*
* @return
*/
default LedgerDataQuery getLedgerData() {
return getLedgerData(getLatestBlock());
}


TransactionSet getTransactionSet(LedgerBlock block);
TransactionQuery getTransactionSet(LedgerBlock block);


UserAccountQuery getUserAccountSet(LedgerBlock block); UserAccountQuery getUserAccountSet(LedgerBlock block);


@@ -71,11 +85,7 @@ public interface LedgerQuery {


ContractAccountQuery getContractAccountSet(LedgerBlock block); ContractAccountQuery getContractAccountSet(LedgerBlock block);


default LedgerDataQuery getDataSet() {
return getDataSet(getLatestBlock());
}

default TransactionSet getTransactionSet() {
default TransactionQuery getTransactionSet() {
return getTransactionSet(getLatestBlock()); return getTransactionSet(getLatestBlock());
} }


@@ -90,7 +100,7 @@ public interface LedgerQuery {
default ContractAccountQuery getContractAccountset() { default ContractAccountQuery getContractAccountset() {
return getContractAccountSet(getLatestBlock()); return getContractAccountSet(getLatestBlock());
} }
/** /**
* 重新检索最新区块,同时更新缓存; * 重新检索最新区块,同时更新缓存;
* *
@@ -111,7 +121,5 @@ public interface LedgerQuery {
* @return * @return
*/ */
HashDigest retrieveLatestBlockHash(); HashDigest retrieveLatestBlockHash();


} }

+ 30
- 30
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java View File

@@ -93,7 +93,7 @@ public class LedgerQueryService implements BlockchainQueryService {
public long getTransactionCount(HashDigest ledgerHash, long height) { public long getTransactionCount(HashDigest ledgerHash, long height) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
TransactionSet txset = ledger.getTransactionSet(block);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.getTotalCount(); return txset.getTotalCount();
} }


@@ -101,7 +101,7 @@ public class LedgerQueryService implements BlockchainQueryService {
public long getTransactionCount(HashDigest ledgerHash, HashDigest blockHash) { public long getTransactionCount(HashDigest ledgerHash, HashDigest blockHash) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
TransactionSet txset = ledger.getTransactionSet(block);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.getTotalCount(); return txset.getTotalCount();
} }


@@ -109,7 +109,7 @@ public class LedgerQueryService implements BlockchainQueryService {
public long getTransactionTotalCount(HashDigest ledgerHash) { public long getTransactionTotalCount(HashDigest ledgerHash) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.getTotalCount(); return txset.getTotalCount();
} }


@@ -118,7 +118,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@Override @Override
@@ -126,7 +126,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@Override @Override
@@ -134,7 +134,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@Override @Override
@@ -142,7 +142,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@Override @Override
@@ -150,7 +150,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@Override @Override
@@ -158,7 +158,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@Override @Override
@@ -166,7 +166,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@Override @Override
@@ -174,7 +174,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@Override @Override
@@ -182,14 +182,14 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@Override @Override
public LedgerTransaction[] getTransactions(HashDigest ledgerHash, long height, int fromIndex, int count) { public LedgerTransaction[] getTransactions(HashDigest ledgerHash, long height, int fromIndex, int count) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(height); LedgerBlock ledgerBlock = ledger.getBlock(height);
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock);
TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
int lastHeightTxTotalNums = 0; int lastHeightTxTotalNums = 0;


if (height > 0) { if (height > 0) {
@@ -219,7 +219,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHash); LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
long height = ledgerBlock.getHeight(); long height = ledgerBlock.getHeight();
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock);
TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
int lastHeightTxTotalNums = 0; int lastHeightTxTotalNums = 0;


if (height > 0) { if (height > 0) {
@@ -248,7 +248,7 @@ public class LedgerQueryService implements BlockchainQueryService {
public LedgerTransaction getTransactionByContentHash(HashDigest ledgerHash, HashDigest contentHash) { public LedgerTransaction getTransactionByContentHash(HashDigest ledgerHash, HashDigest contentHash) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.get(contentHash); return txset.get(contentHash);
} }


@@ -256,8 +256,8 @@ public class LedgerQueryService implements BlockchainQueryService {
public TransactionState getTransactionStateByContentHash(HashDigest ledgerHash, HashDigest contentHash) { public TransactionState getTransactionStateByContentHash(HashDigest ledgerHash, HashDigest contentHash) {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
return txset.getTxState(contentHash);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.getState(contentHash);
} }


@Override @Override
@@ -265,7 +265,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getUser(address);
return userAccountSet.getAccount(address);


} }


@@ -274,7 +274,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getDataAccount(Bytes.fromBase58(address));
return dataAccountSet.getAccount(Bytes.fromBase58(address));
} }


@Override @Override
@@ -285,7 +285,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


KVDataEntry[] entries = new KVDataEntry[keys.length]; KVDataEntry[] entries = new KVDataEntry[keys.length];
long ver; long ver;
@@ -333,7 +333,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


KVDataEntry[] entries = new KVDataEntry[keys.length]; KVDataEntry[] entries = new KVDataEntry[keys.length];
long ver = -1; long ver = -1;
@@ -363,7 +363,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataEntriesTotalCount()); int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataEntriesTotalCount());
return dataAccount.getDataEntries(pages[0], pages[1]); return dataAccount.getDataEntries(pages[0], pages[1]);
@@ -374,7 +374,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


return dataAccount.getDataEntriesTotalCount(); return dataAccount.getDataEntriesTotalCount();
} }
@@ -384,7 +384,7 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getContract(Bytes.fromBase58(address));
return contractAccountSet.getAccount(Bytes.fromBase58(address));
} }


@Override @Override
@@ -392,8 +392,8 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotalCount());
return userAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotal());
return userAccountSet.getHeaders(pages[0], pages[1]);
} }


@Override @Override
@@ -401,8 +401,8 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotalCount());
return dataAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotal());
return dataAccountSet.getHeaders(pages[0], pages[1]);
} }


@Override @Override
@@ -410,8 +410,8 @@ public class LedgerQueryService implements BlockchainQueryService {
checkLedgerHash(ledgerHash); checkLedgerHash(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotalCount());
return contractAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotal());
return contractAccountSet.getHeaders(pages[0], pages[1]);
} }


} }

+ 6
- 6
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerRepositoryImpl.java View File

@@ -118,7 +118,7 @@ class LedgerRepositoryImpl implements LedgerRepository {
private LedgerState retrieveLatestState() { private LedgerState retrieveLatestState() {
LedgerBlock latestBlock = innerGetBlock(innerGetLatestBlockHeight()); LedgerBlock latestBlock = innerGetBlock(innerGetLatestBlockHeight());
LedgerDataset ledgerDataset = innerGetLedgerDataset(latestBlock); LedgerDataset ledgerDataset = innerGetLedgerDataset(latestBlock);
TransactionSet txSet = loadTransactionSet(latestBlock.getTransactionSetHash(),
TransactionQuery txSet = loadTransactionSet(latestBlock.getTransactionSetHash(),
ledgerDataset.getAdminDataset().getSettings().getCryptoSetting(), keyPrefix, exPolicyStorage, ledgerDataset.getAdminDataset().getSettings().getCryptoSetting(), keyPrefix, exPolicyStorage,
versioningStorage, true); versioningStorage, true);
this.latestState = new LedgerState(latestBlock, ledgerDataset, txSet); this.latestState = new LedgerState(latestBlock, ledgerDataset, txSet);
@@ -253,7 +253,7 @@ class LedgerRepositoryImpl implements LedgerRepository {
} }


@Override @Override
public TransactionSet getTransactionSet(LedgerBlock block) {
public TransactionQuery getTransactionSet(LedgerBlock block) {
long height = getLatestBlockHeight(); long height = getLatestBlockHeight();
if (height == block.getHeight()) { if (height == block.getHeight()) {
// 从缓存中返回最新区块的数据集; // 从缓存中返回最新区块的数据集;
@@ -354,7 +354,7 @@ class LedgerRepositoryImpl implements LedgerRepository {
} }


@Override @Override
public LedgerDataset getDataSet(LedgerBlock block) {
public LedgerDataset getLedgerData(LedgerBlock block) {
long height = getLatestBlockHeight(); long height = getLatestBlockHeight();
if (height == block.getHeight()) { if (height == block.getHeight()) {
return latestState.getLedgerDataset(); return latestState.getLedgerDataset();
@@ -579,11 +579,11 @@ class LedgerRepositoryImpl implements LedgerRepository {


private final LedgerBlock block; private final LedgerBlock block;


private final TransactionSet transactionSet;
private final TransactionQuery transactionSet;


private final LedgerDataset ledgerDataset; private final LedgerDataset ledgerDataset;


public LedgerState(LedgerBlock block, LedgerDataset ledgerDataset, TransactionSet transactionSet) {
public LedgerState(LedgerBlock block, LedgerDataset ledgerDataset, TransactionQuery transactionSet) {
this.block = block; this.block = block;
this.ledgerDataset = ledgerDataset; this.ledgerDataset = ledgerDataset;
this.transactionSet = transactionSet; this.transactionSet = transactionSet;
@@ -610,7 +610,7 @@ class LedgerRepositoryImpl implements LedgerRepository {
return ledgerDataset.getUserAccountSet(); return ledgerDataset.getUserAccountSet();
} }


public TransactionSet getTransactionSet() {
public TransactionQuery getTransactionSet() {
return transactionSet; return transactionSet;
} }




+ 3
- 3
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerSecurityManagerImpl.java View File

@@ -17,7 +17,7 @@ import com.jd.blockchain.ledger.RolesPolicy;
import com.jd.blockchain.ledger.TransactionPermission; import com.jd.blockchain.ledger.TransactionPermission;
import com.jd.blockchain.ledger.UserDoesNotExistException; import com.jd.blockchain.ledger.UserDoesNotExistException;
import com.jd.blockchain.ledger.UserRoles; import com.jd.blockchain.ledger.UserRoles;
import com.jd.blockchain.ledger.UserRolesSettings;
import com.jd.blockchain.ledger.UserAuthorizationSettings;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;


/** /**
@@ -30,7 +30,7 @@ public class LedgerSecurityManagerImpl implements LedgerSecurityManager {


private RolePrivilegeSettings rolePrivilegeSettings; private RolePrivilegeSettings rolePrivilegeSettings;


private UserRolesSettings userRolesSettings;
private UserAuthorizationSettings userRolesSettings;


// 用户的权限配置 // 用户的权限配置
private Map<Bytes, UserRolesPrivileges> userPrivilegesCache = new ConcurrentHashMap<>(); private Map<Bytes, UserRolesPrivileges> userPrivilegesCache = new ConcurrentHashMap<>();
@@ -41,7 +41,7 @@ public class LedgerSecurityManagerImpl implements LedgerSecurityManager {
private ParticipantDataQuery participantsQuery; private ParticipantDataQuery participantsQuery;
private UserAccountQuery userAccountsQuery; private UserAccountQuery userAccountsQuery;


public LedgerSecurityManagerImpl(RolePrivilegeSettings rolePrivilegeSettings, UserRolesSettings userRolesSettings,
public LedgerSecurityManagerImpl(RolePrivilegeSettings rolePrivilegeSettings, UserAuthorizationSettings userRolesSettings,
ParticipantDataQuery participantsQuery, UserAccountQuery userAccountsQuery) { ParticipantDataQuery participantsQuery, UserAccountQuery userAccountsQuery) {
this.rolePrivilegeSettings = rolePrivilegeSettings; this.rolePrivilegeSettings = rolePrivilegeSettings;
this.userRolesSettings = userRolesSettings; this.userRolesSettings = userRolesSettings;


+ 1
- 1
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerTransactionContext.java View File

@@ -24,7 +24,7 @@ public interface LedgerTransactionContext {
* *
* @return * @return
*/ */
TransactionSet getTransactionSet();
TransactionQuery getTransactionSet();


/** /**
* 交易请求; * 交易请求;


source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/BaseAccount.java → source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java View File

@@ -20,7 +20,7 @@ import com.jd.blockchain.utils.Transactional;
* @author huanghaiquan * @author huanghaiquan
* *
*/ */
public class BaseAccount implements AccountHeader, MerkleProvable, Transactional {
public class MerkleAccount implements AccountHeader, MerkleProvable, Transactional {


private BlockchainIdentity bcid; private BlockchainIdentity bcid;


@@ -38,7 +38,7 @@ public class BaseAccount implements AccountHeader, MerkleProvable, Transactional
* @param address * @param address
* @param pubKey * @param pubKey
*/ */
public BaseAccount(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting, String keyPrefix,
public MerkleAccount(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) {
this(address, pubKey, null, cryptoSetting, keyPrefix, exStorage, verStorage, false); this(address, pubKey, null, cryptoSetting, keyPrefix, exStorage, verStorage, false);
} }
@@ -58,7 +58,7 @@ public class BaseAccount implements AccountHeader, MerkleProvable, Transactional
* @param verStorage * @param verStorage
* @param accessPolicy * @param accessPolicy
*/ */
public BaseAccount(BlockchainIdentity bcid, CryptoSetting cryptoSetting, String keyPrefix,
public MerkleAccount(BlockchainIdentity bcid, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) {
this(bcid, null, cryptoSetting, keyPrefix, exStorage, verStorage, false); this(bcid, null, cryptoSetting, keyPrefix, exStorage, verStorage, false);
} }
@@ -78,13 +78,13 @@ public class BaseAccount implements AccountHeader, MerkleProvable, Transactional
* @param readonly * @param readonly
* @param accessPolicy * @param accessPolicy
*/ */
public BaseAccount(Bytes address, PubKey pubKey, HashDigest dataRootHash, CryptoSetting cryptoSetting,
public MerkleAccount(Bytes address, PubKey pubKey, HashDigest dataRootHash, CryptoSetting cryptoSetting,
String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) {
this(new BlockchainIdentityData(address, pubKey), dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, this(new BlockchainIdentityData(address, pubKey), dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage,
readonly); readonly);
} }


public BaseAccount(BlockchainIdentity bcid, HashDigest dataRootHash, CryptoSetting cryptoSetting, String keyPrefix,
public MerkleAccount(BlockchainIdentity bcid, HashDigest dataRootHash, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) {
this.bcid = bcid; this.bcid = bcid;
this.dataset = new MerkleDataSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); this.dataset = new MerkleDataSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly);
@@ -169,7 +169,7 @@ public class BaseAccount implements AccountHeader, MerkleProvable, Transactional
* @param key * @param key
* @return * @return
*/ */
public long getKeyVersion(Bytes key) {
public long getVersion(Bytes key) {
return dataset.getVersion(key); return dataset.getVersion(key);
} }



source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AccountSet.java → source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java View File

@@ -13,14 +13,16 @@ import com.jd.blockchain.ledger.BytesValue;
import com.jd.blockchain.ledger.CryptoSetting; import com.jd.blockchain.ledger.CryptoSetting;
import com.jd.blockchain.ledger.LedgerException; import com.jd.blockchain.ledger.LedgerException;
import com.jd.blockchain.ledger.MerkleProof; import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.ledger.MerkleSnapshot;
import com.jd.blockchain.storage.service.ExPolicyKVStorage; import com.jd.blockchain.storage.service.ExPolicyKVStorage;
import com.jd.blockchain.storage.service.VersioningKVStorage; import com.jd.blockchain.storage.service.VersioningKVStorage;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.Transactional; import com.jd.blockchain.utils.Transactional;
public class AccountSet implements Transactional, MerkleProvable {
public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQuery<MerkleAccount> {
static { static {
DataContractRegistry.register(MerkleSnapshot.class);
DataContractRegistry.register(AccountHeader.class); DataContractRegistry.register(AccountHeader.class);
} }
@@ -34,7 +36,7 @@ public class AccountSet implements Transactional, MerkleProvable {
* *
*/ */
// TODO:未考虑大数据量时,由于缺少过期策略,会导致内存溢出的问题; // TODO:未考虑大数据量时,由于缺少过期策略,会导致内存溢出的问题;
private Map<Bytes, VersioningAccount> latestAccountsCache = new HashMap<>();
private Map<Bytes, InnerVersioningAccount> latestAccountsCache = new HashMap<>();
private ExPolicyKVStorage baseExStorage; private ExPolicyKVStorage baseExStorage;
@@ -49,18 +51,19 @@ public class AccountSet implements Transactional, MerkleProvable {
public boolean isReadonly() { public boolean isReadonly() {
return merkleDataset.isReadonly(); return merkleDataset.isReadonly();
} }
void setReadonly() { void setReadonly() {
merkleDataset.setReadonly(); merkleDataset.setReadonly();
} }
public AccountSet(CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage exStorage,
public MerkleAccountSet(CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage exStorage,
VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) { VersioningKVStorage verStorage, AccountAccessPolicy accessPolicy) {
this(null, cryptoSetting, keyPrefix, exStorage, verStorage, false, accessPolicy); this(null, cryptoSetting, keyPrefix, exStorage, verStorage, false, accessPolicy);
} }
public AccountSet(HashDigest rootHash, CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage exStorage,
VersioningKVStorage verStorage, boolean readonly, AccountAccessPolicy accessPolicy) {
public MerkleAccountSet(HashDigest rootHash, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly,
AccountAccessPolicy accessPolicy) {
this.keyPrefix = keyPrefix; this.keyPrefix = keyPrefix;
this.cryptoSetting = cryptoSetting; this.cryptoSetting = cryptoSetting;
this.baseExStorage = exStorage; this.baseExStorage = exStorage;
@@ -80,7 +83,7 @@ public class AccountSet implements Transactional, MerkleProvable {
return merkleDataset.getProof(key); return merkleDataset.getProof(key);
} }
public AccountHeader[] getAccounts(int fromIndex, int count) {
public AccountHeader[] getHeaders(int fromIndex, int count) {
byte[][] results = merkleDataset.getLatestValues(fromIndex, count); byte[][] results = merkleDataset.getLatestValues(fromIndex, count);
AccountHeader[] accounts = new AccountHeader[results.length]; AccountHeader[] accounts = new AccountHeader[results.length];
@@ -110,17 +113,22 @@ public class AccountSet implements Transactional, MerkleProvable {
* *
* @return * @return
*/ */
public long getTotalCount() {
public long getTotal() {
return merkleDataset.getDataCount(); return merkleDataset.getDataCount();
} }
@Override
public MerkleAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
}
/** /**
* 返回最新版本的 Account; * 返回最新版本的 Account;
* *
* @param address * @param address
* @return * @return
*/ */
public BaseAccount getAccount(Bytes address) {
public MerkleAccount getAccount(Bytes address) {
return this.getAccount(address, -1); return this.getAccount(address, -1);
} }
@@ -149,7 +157,7 @@ public class AccountSet implements Transactional, MerkleProvable {
* @return * @return
*/ */
public long getVersion(Bytes address) { public long getVersion(Bytes address) {
VersioningAccount acc = latestAccountsCache.get(address);
InnerVersioningAccount acc = latestAccountsCache.get(address);
if (acc != null) { if (acc != null) {
// 已注册尚未提交,也返回 -1; // 已注册尚未提交,也返回 -1;
return acc.version == -1 ? 0 : acc.version; return acc.version == -1 ? 0 : acc.version;
@@ -163,15 +171,13 @@ public class AccountSet implements Transactional, MerkleProvable {
* *
* 只有最新版本的账户才能可写的,其它都是只读; * 只有最新版本的账户才能可写的,其它都是只读;
* *
* @param address
* 账户地址;
* @param version
* 账户版本;如果指定为 -1,则返回最新版本;
* @param address 账户地址;
* @param version 账户版本;如果指定为 -1,则返回最新版本;
* @return * @return
*/ */
public BaseAccount getAccount(Bytes address, long version) {
public MerkleAccount getAccount(Bytes address, long version) {
version = version < 0 ? -1 : version; version = version < 0 ? -1 : version;
VersioningAccount acc = latestAccountsCache.get(address);
InnerVersioningAccount acc = latestAccountsCache.get(address);
if (acc != null && version == -1) { if (acc != null && version == -1) {
return acc; return acc;
} else if (acc != null && acc.version == version) { } else if (acc != null && acc.version == version) {
@@ -233,14 +239,14 @@ public class AccountSet implements Transactional, MerkleProvable {
* @param pubKey 公钥; * @param pubKey 公钥;
* @return 注册成功的账户对象; * @return 注册成功的账户对象;
*/ */
public BaseAccount register(Bytes address, PubKey pubKey) {
public MerkleAccount register(Bytes address, PubKey pubKey) {
if (isReadonly()) { if (isReadonly()) {
throw new IllegalArgumentException("This AccountSet is readonly!"); throw new IllegalArgumentException("This AccountSet is readonly!");
} }
verifyAddressEncoding(address, pubKey); verifyAddressEncoding(address, pubKey);
VersioningAccount cachedAcc = latestAccountsCache.get(address);
InnerVersioningAccount cachedAcc = latestAccountsCache.get(address);
if (cachedAcc != null) { if (cachedAcc != null) {
if (cachedAcc.version < 0) { if (cachedAcc.version < 0) {
// 同一个新账户已经注册,但尚未提交,所以重复注册不会引起任何变化; // 同一个新账户已经注册,但尚未提交,所以重复注册不会引起任何变化;
@@ -267,7 +273,7 @@ public class AccountSet implements Transactional, MerkleProvable {
// accExStorage, accVerStorage); // accExStorage, accVerStorage);
String prefix = keyPrefix + address; String prefix = keyPrefix + address;
VersioningAccount acc = createInstance(address, pubKey, cryptoSetting, prefix, baseExStorage, baseVerStorage,
InnerVersioningAccount acc = createInstance(address, pubKey, cryptoSetting, prefix, baseExStorage, baseVerStorage,
-1); -1);
latestAccountsCache.put(address, acc); latestAccountsCache.put(address, acc);
updated = true; updated = true;
@@ -282,15 +288,15 @@ public class AccountSet implements Transactional, MerkleProvable {
} }
} }
private VersioningAccount createInstance(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting,
private InnerVersioningAccount createInstance(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting,
String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, long version) { String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, long version) {
return new VersioningAccount(address, pubKey, cryptoSetting, keyPrefix, exStorage, verStorage, version);
return new InnerVersioningAccount(address, pubKey, cryptoSetting, keyPrefix, exStorage, verStorage, version);
} }
private VersioningAccount deserialize(byte[] bytes, CryptoSetting cryptoSetting, String keyPrefix,
private InnerVersioningAccount deserialize(byte[] bytes, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, long version) { ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, long version) {
AccountHeader accInfo = BinaryProtocol.decode(bytes); AccountHeader accInfo = BinaryProtocol.decode(bytes);
return new VersioningAccount(accInfo.getAddress(), accInfo.getPubKey(), accInfo.getRootHash(), cryptoSetting,
return new InnerVersioningAccount(accInfo.getAddress(), accInfo.getPubKey(), accInfo.getRootHash(), cryptoSetting,
keyPrefix, exStorage, verStorage, readonly, version); keyPrefix, exStorage, verStorage, readonly, version);
} }
@@ -309,7 +315,7 @@ public class AccountSet implements Transactional, MerkleProvable {
return; return;
} }
try { try {
for (VersioningAccount acc : latestAccountsCache.values()) {
for (InnerVersioningAccount acc : latestAccountsCache.values()) {
// updated or new created; // updated or new created;
if (acc.isUpdated() || acc.version < 0) { if (acc.isUpdated() || acc.version < 0) {
// 提交更改,更新哈希; // 提交更改,更新哈希;
@@ -337,7 +343,7 @@ public class AccountSet implements Transactional, MerkleProvable {
Bytes[] addresses = new Bytes[latestAccountsCache.size()]; Bytes[] addresses = new Bytes[latestAccountsCache.size()];
latestAccountsCache.keySet().toArray(addresses); latestAccountsCache.keySet().toArray(addresses);
for (Bytes address : addresses) { for (Bytes address : addresses) {
VersioningAccount acc = latestAccountsCache.remove(address);
InnerVersioningAccount acc = latestAccountsCache.remove(address);
// cancel; // cancel;
if (acc.isUpdated()) { if (acc.isUpdated()) {
acc.cancel(); acc.cancel();
@@ -375,7 +381,7 @@ public class AccountSet implements Transactional, MerkleProvable {
} }
private class VersioningAccount extends BaseAccount {
private class InnerVersioningAccount extends MerkleAccount {
// private final BaseAccount account; // private final BaseAccount account;
@@ -386,14 +392,14 @@ public class AccountSet implements Transactional, MerkleProvable {
// this.version = version; // this.version = version;
// } // }
public VersioningAccount(Bytes address, PubKey pubKey, HashDigest rootHash, CryptoSetting cryptoSetting,
public InnerVersioningAccount(Bytes address, PubKey pubKey, HashDigest rootHash, CryptoSetting cryptoSetting,
String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, String keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly,
long version) { long version) {
super(address, pubKey, rootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); super(address, pubKey, rootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly);
this.version = version; this.version = version;
} }
public VersioningAccount(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting, String keyPrefix,
public InnerVersioningAccount(Bytes address, PubKey pubKey, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, long version) { ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, long version) {
super(address, pubKey, cryptoSetting, keyPrefix, exStorage, verStorage); super(address, pubKey, cryptoSetting, keyPrefix, exStorage, verStorage);
this.version = version; this.version = version;

+ 2
- 4
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleProvable.java View File

@@ -1,12 +1,10 @@
package com.jd.blockchain.ledger.core; package com.jd.blockchain.ledger.core;


import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.MerkleProof; import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.ledger.MerkleSnapshot;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;


public interface MerkleProvable {

HashDigest getRootHash();
public interface MerkleProvable extends MerkleSnapshot {


/** /**
* Get the merkle proof of the latest version of specified key; <br> * Get the merkle proof of the latest version of specified key; <br>


+ 4
- 4
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java View File

@@ -79,10 +79,10 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
this.handlesRegisteration = handlesRegisteration; this.handlesRegisteration = handlesRegisteration;
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery ledgerDataQuery = ledgerRepo.getDataSet(ledgerBlock);
LedgerDataQuery ledgerDataQuery = ledgerRepo.getLedgerData(ledgerBlock);
LedgerAdminDataQuery previousAdminDataset = ledgerDataQuery.getAdminDataset(); LedgerAdminDataQuery previousAdminDataset = ledgerDataQuery.getAdminDataset();
this.securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminInfo().getRolePrivileges(), this.securityManager = new LedgerSecurityManagerImpl(previousAdminDataset.getAdminInfo().getRolePrivileges(),
previousAdminDataset.getAdminInfo().getUserRoles(), previousAdminDataset.getParticipantDataset(),
previousAdminDataset.getAdminInfo().getAuthorizations(), previousAdminDataset.getParticipantDataset(),
ledgerDataQuery.getUserAccountSet()); ledgerDataQuery.getUserAccountSet());
this.newBlockEditor = ledgerRepo.createNextBlock(); this.newBlockEditor = ledgerRepo.createNextBlock();
@@ -93,12 +93,12 @@ public class TransactionBatchProcessor implements TransactionBatchProcess {
OperationHandleRegisteration handlesRegisteration) { OperationHandleRegisteration handlesRegisteration) {
LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock(); LedgerBlock ledgerBlock = ledgerRepo.getLatestBlock();
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(ledgerBlock);


LedgerAdminDataQuery previousAdminDataset = previousBlockDataset.getAdminDataset(); LedgerAdminDataQuery previousAdminDataset = previousBlockDataset.getAdminDataset();
LedgerSecurityManager securityManager = new LedgerSecurityManagerImpl( LedgerSecurityManager securityManager = new LedgerSecurityManagerImpl(
previousAdminDataset.getAdminInfo().getRolePrivileges(), previousAdminDataset.getAdminInfo().getRolePrivileges(),
previousAdminDataset.getAdminInfo().getUserRoles(), previousAdminDataset.getParticipantDataset(),
previousAdminDataset.getAdminInfo().getAuthorizations(), previousAdminDataset.getParticipantDataset(),
previousBlockDataset.getUserAccountSet()); previousBlockDataset.getUserAccountSet());


TransactionBatchProcessor processor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, TransactionBatchProcessor processor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo,


+ 24
- 0
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionQuery.java View File

@@ -0,0 +1,24 @@
package com.jd.blockchain.ledger.core;

import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.LedgerTransaction;
import com.jd.blockchain.ledger.TransactionState;

public interface TransactionQuery extends MerkleProvable {

LedgerTransaction[] getTxs(int fromIndex, int count);

byte[][] getValuesByIndex(int fromIndex, int count);

long getTotalCount();

/**
* @param txContentHash
* Base58 编码的交易内容的哈希;
* @return
*/
LedgerTransaction get(HashDigest txContentHash);

TransactionState getState(HashDigest txContentHash);

}

+ 9
- 5
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionSet.java View File

@@ -13,7 +13,7 @@ import com.jd.blockchain.storage.service.VersioningKVStorage;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.Transactional; import com.jd.blockchain.utils.Transactional;


public class TransactionSet implements Transactional, MerkleProvable {
public class TransactionSet implements Transactional, TransactionQuery {


static { static {
DataContractRegistry.register(LedgerTransaction.class); DataContractRegistry.register(LedgerTransaction.class);
@@ -25,6 +25,7 @@ public class TransactionSet implements Transactional, MerkleProvable {


private MerkleDataSet txSet; private MerkleDataSet txSet;


@Override
public LedgerTransaction[] getTxs(int fromIndex, int count) { public LedgerTransaction[] getTxs(int fromIndex, int count) {
if (count > LedgerConsts.MAX_LIST_COUNT) { if (count > LedgerConsts.MAX_LIST_COUNT) {
throw new IllegalArgumentException("Count exceed the upper limit[" + LedgerConsts.MAX_LIST_COUNT + "]!"); throw new IllegalArgumentException("Count exceed the upper limit[" + LedgerConsts.MAX_LIST_COUNT + "]!");
@@ -38,6 +39,7 @@ public class TransactionSet implements Transactional, MerkleProvable {
return ledgerTransactions; return ledgerTransactions;
} }


@Override
public byte[][] getValuesByIndex(int fromIndex, int count) { public byte[][] getValuesByIndex(int fromIndex, int count) {
byte[][] values = new byte[count][]; byte[][] values = new byte[count][];
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@@ -57,6 +59,7 @@ public class TransactionSet implements Transactional, MerkleProvable {
return txSet.getProof(key); return txSet.getProof(key);
} }


@Override
public long getTotalCount() { public long getTotalCount() {
// 每写入一个交易,同时写入交易内容Hash与交易结果的索引,因此交易记录数为集合总记录数除以 2; // 每写入一个交易,同时写入交易内容Hash与交易结果的索引,因此交易记录数为集合总记录数除以 2;
return txSet.getDataCount() / 2; return txSet.getDataCount() / 2;
@@ -113,10 +116,10 @@ public class TransactionSet implements Transactional, MerkleProvable {
} }


/** /**
* @param txContentHash
* Base58 编码的交易内容的哈希;
* @param txContentHash Base58 编码的交易内容的哈希;
* @return * @return
*/ */
@Override
public LedgerTransaction get(HashDigest txContentHash) { public LedgerTransaction get(HashDigest txContentHash) {
// transaction has only one version; // transaction has only one version;
Bytes key = new Bytes(txContentHash.toBytes()); Bytes key = new Bytes(txContentHash.toBytes());
@@ -129,7 +132,8 @@ public class TransactionSet implements Transactional, MerkleProvable {
return tx; return tx;
} }


public TransactionState getTxState(HashDigest txContentHash) {
@Override
public TransactionState getState(HashDigest txContentHash) {
Bytes resultKey = encodeTxStateKey(txContentHash); Bytes resultKey = encodeTxStateKey(txContentHash);
// transaction has only one version; // transaction has only one version;
byte[] bytes = txSet.getValue(resultKey, 0); byte[] bytes = txSet.getValue(resultKey, 0);
@@ -154,7 +158,7 @@ public class TransactionSet implements Transactional, MerkleProvable {
public boolean isReadonly() { public boolean isReadonly() {
return txSet.isReadonly(); return txSet.isReadonly();
} }
void setReadonly() { void setReadonly() {
txSet.setReadonly(); txSet.setReadonly();
} }


+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java View File

@@ -19,7 +19,7 @@ public class UserAccount implements UserInfo {
private static final Bytes DATA_PUB_KEY = Bytes.fromString("DATA-PUBKEY"); private static final Bytes DATA_PUB_KEY = Bytes.fromString("DATA-PUBKEY");
private BaseAccount baseAccount;
private MerkleAccount baseAccount;
@Override @Override
public Bytes getAddress() { public Bytes getAddress() {
@@ -36,7 +36,7 @@ public class UserAccount implements UserInfo {
return baseAccount.getRootHash(); return baseAccount.getRootHash();
} }
public UserAccount(BaseAccount baseAccount) {
public UserAccount(MerkleAccount baseAccount) {
this.baseAccount = baseAccount; this.baseAccount = baseAccount;
} }


+ 1
- 27
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountQuery.java View File

@@ -1,31 +1,5 @@
package com.jd.blockchain.ledger.core; package com.jd.blockchain.ledger.core;


import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.utils.Bytes;

public interface UserAccountQuery {

AccountHeader[] getAccounts(int fromIndex, int count);

/**
* 返回用户总数;
*
* @return
*/
long getTotalCount();

HashDigest getRootHash();

MerkleProof getProof(Bytes key);

UserAccount getUser(String address);

UserAccount getUser(Bytes address);

boolean contains(Bytes address);

UserAccount getUser(Bytes address, long version);
public interface UserAccountQuery extends AccountQuery<UserAccount> {


} }

+ 15
- 15
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountSet.java View File

@@ -15,25 +15,25 @@ import com.jd.blockchain.utils.Transactional;
* @author huanghaiquan * @author huanghaiquan
* *
*/ */
public class UserAccountSet implements Transactional, MerkleProvable, UserAccountQuery {
public class UserAccountSet implements Transactional, UserAccountQuery {
private AccountSet accountSet;
private MerkleAccountSet accountSet;
public UserAccountSet(CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage simpleStorage, public UserAccountSet(CryptoSetting cryptoSetting, String keyPrefix, ExPolicyKVStorage simpleStorage,
VersioningKVStorage versioningStorage, AccountAccessPolicy accessPolicy) { VersioningKVStorage versioningStorage, AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(cryptoSetting, keyPrefix, simpleStorage, versioningStorage, accessPolicy);
accountSet = new MerkleAccountSet(cryptoSetting, keyPrefix, simpleStorage, versioningStorage, accessPolicy);
} }
public UserAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String keyPrefix, public UserAccountSet(HashDigest dataRootHash, CryptoSetting cryptoSetting, String keyPrefix,
ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly,
AccountAccessPolicy accessPolicy) { AccountAccessPolicy accessPolicy) {
accountSet = new AccountSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly,
accountSet = new MerkleAccountSet(dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly,
accessPolicy); accessPolicy);
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex,count);
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getHeaders(fromIndex,count);
} }
/** /**
@@ -42,8 +42,8 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
* @return * @return
*/ */
@Override @Override
public long getTotalCount() {
return accountSet.getTotalCount();
public long getTotal() {
return accountSet.getTotal();
} }
public boolean isReadonly() { public boolean isReadonly() {
@@ -65,13 +65,13 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
} }
@Override @Override
public UserAccount getUser(String address) {
return getUser(Bytes.fromBase58(address));
public UserAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
} }
@Override @Override
public UserAccount getUser(Bytes address) {
BaseAccount baseAccount = accountSet.getAccount(address);
public UserAccount getAccount(Bytes address) {
MerkleAccount baseAccount = accountSet.getAccount(address);
return new UserAccount(baseAccount); return new UserAccount(baseAccount);
} }
@@ -81,8 +81,8 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
} }
@Override @Override
public UserAccount getUser(Bytes address, long version) {
BaseAccount baseAccount = accountSet.getAccount(address, version);
public UserAccount getAccount(Bytes address, long version) {
MerkleAccount baseAccount = accountSet.getAccount(address, version);
return new UserAccount(baseAccount); return new UserAccount(baseAccount);
} }
@@ -100,7 +100,7 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
* @return 注册成功的用户对象; * @return 注册成功的用户对象;
*/ */
public UserAccount register(Bytes address, PubKey pubKey) { public UserAccount register(Bytes address, PubKey pubKey) {
BaseAccount baseAccount = accountSet.register(address, pubKey);
MerkleAccount baseAccount = accountSet.register(address, pubKey);
return new UserAccount(baseAccount); return new UserAccount(baseAccount);
} }


+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserRoleDataset.java View File

@@ -11,7 +11,7 @@ import com.jd.blockchain.ledger.MerkleProof;
import com.jd.blockchain.ledger.RoleSet; import com.jd.blockchain.ledger.RoleSet;
import com.jd.blockchain.ledger.RolesPolicy; import com.jd.blockchain.ledger.RolesPolicy;
import com.jd.blockchain.ledger.UserRoles; import com.jd.blockchain.ledger.UserRoles;
import com.jd.blockchain.ledger.UserRolesSettings;
import com.jd.blockchain.ledger.UserAuthorizationSettings;
import com.jd.blockchain.storage.service.ExPolicyKVStorage; import com.jd.blockchain.storage.service.ExPolicyKVStorage;
import com.jd.blockchain.storage.service.VersioningKVEntry; import com.jd.blockchain.storage.service.VersioningKVEntry;
import com.jd.blockchain.storage.service.VersioningKVStorage; import com.jd.blockchain.storage.service.VersioningKVStorage;
@@ -24,7 +24,7 @@ import com.jd.blockchain.utils.Transactional;
* @author huanghaiquan * @author huanghaiquan
* *
*/ */
public class UserRoleDataset implements Transactional, MerkleProvable, UserRolesSettings {
public class UserRoleDataset implements Transactional, MerkleProvable, UserAuthorizationSettings {


private MerkleDataSet dataset; private MerkleDataSet dataset;




+ 1
- 1
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/AbtractContractEventSendOperationHandle.java View File

@@ -57,7 +57,7 @@ public abstract class AbtractContractEventSendOperationHandle implements Operati
ContractLedgerContext ledgerContext = new ContractLedgerContext(queryService, opHandleContext); ContractLedgerContext ledgerContext = new ContractLedgerContext(queryService, opHandleContext);


// 先检查合约引擎是否已经加载合约;如果未加载,再从账本中读取合约代码并装载到引擎中执行; // 先检查合约引擎是否已经加载合约;如果未加载,再从账本中读取合约代码并装载到引擎中执行;
ContractAccount contract = contractSet.getContract(contractOP.getContractAddress());
ContractAccount contract = contractSet.getAccount(contractOP.getContractAddress());
if (contract == null) { if (contract == null) {
throw new LedgerException(String.format("Contract was not registered! --[ContractAddress=%s]", throw new LedgerException(String.format("Contract was not registered! --[ContractAddress=%s]",
contractOP.getContractAddress())); contractOP.getContractAddress()));


+ 1
- 1
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/DataAccountKVSetOperationHandle.java View File

@@ -30,7 +30,7 @@ public class DataAccountKVSetOperationHandle extends AbstractLedgerOperationHand
securityPolicy.checkEndpointPermission(LedgerPermission.WRITE_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE); securityPolicy.checkEndpointPermission(LedgerPermission.WRITE_DATA_ACCOUNT, MultiIDsPolicy.AT_LEAST_ONE);


// 操作账本; // 操作账本;
DataAccount account = newBlockDataset.getDataAccountSet().getDataAccount(kvWriteOp.getAccountAddress());
DataAccount account = newBlockDataset.getDataAccountSet().getAccount(kvWriteOp.getAccountAddress());
if (account == null) { if (account == null) {
throw new DataAccountDoesNotExistException("DataAccount doesn't exist!"); throw new DataAccountDoesNotExistException("DataAccount doesn't exist!");
} }


+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantRegisterOperationHandle.java View File

@@ -39,7 +39,7 @@ public class ParticipantRegisterOperationHandle extends AbstractLedgerOperationH


LedgerAdminDataset adminAccountDataSet = newBlockDataset.getAdminDataset(); LedgerAdminDataset adminAccountDataSet = newBlockDataset.getAdminDataset();


ParticipantInfo participantInfo = new ParticipantInfoData(participantRegOp.getParticipantName(), participantRegOp.getParticipantIdentity().getPubKey(), participantRegOp.getNetworkAddress());
ParticipantInfo participantInfo = new ParticipantInfoData(participantRegOp.getParticipantName(), participantRegOp.getParticipantRegisterIdentity().getPubKey(), participantRegOp.getNetworkAddress());


ParticipantNode participantNode = new PartNode((int)(adminAccountDataSet.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTERED); ParticipantNode participantNode = new PartNode((int)(adminAccountDataSet.getParticipantCount()), participantInfo.getName(), participantInfo.getPubKey(), ParticipantNodeState.REGISTERED);


@@ -47,7 +47,7 @@ public class ParticipantRegisterOperationHandle extends AbstractLedgerOperationH
adminAccountDataSet.addParticipant(participantNode); adminAccountDataSet.addParticipant(participantNode);


// Build UserRegisterOperation, reg participant as user // Build UserRegisterOperation, reg participant as user
UserRegisterOperation userRegOp = new UserRegisterOpTemplate(participantRegOp.getParticipantIdentity());
UserRegisterOperation userRegOp = new UserRegisterOpTemplate(participantRegOp.getParticipantRegisterIdentity());
handleContext.handle(userRegOp); handleContext.handle(userRegOp);
} }




+ 1
- 1
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/ParticipantStateUpdateOperationHandle.java View File

@@ -48,7 +48,7 @@ public class ParticipantStateUpdateOperationHandle extends AbstractLedgerOperati
ParticipantNode participantNode = null; ParticipantNode participantNode = null;


for(int i = 0; i < participants.length; i++) { for(int i = 0; i < participants.length; i++) {
if (stateUpdateOperation.getParticipantIdentity().getPubKey().equals(participants[i].getPubKey())) {
if (stateUpdateOperation.getStateUpdateIdentity().getPubKey().equals(participants[i].getPubKey())) {
participantNode = new PartNode(participants[i].getId(), participants[i].getName(), participants[i].getPubKey(), ParticipantNodeState.ACTIVED); participantNode = new PartNode(participants[i].getId(), participants[i].getName(), participants[i].getPubKey(), ParticipantNodeState.ACTIVED);
break; break;
} }


+ 2
- 2
source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/UserAuthorizeOperationHandle.java View File

@@ -9,7 +9,7 @@ import com.jd.blockchain.ledger.RolesPolicy;
import com.jd.blockchain.ledger.UserAuthorizeOperation; import com.jd.blockchain.ledger.UserAuthorizeOperation;
import com.jd.blockchain.ledger.UserAuthorizeOperation.UserRolesEntry; import com.jd.blockchain.ledger.UserAuthorizeOperation.UserRolesEntry;
import com.jd.blockchain.ledger.UserRoles; import com.jd.blockchain.ledger.UserRoles;
import com.jd.blockchain.ledger.UserRolesSettings;
import com.jd.blockchain.ledger.UserAuthorizationSettings;
import com.jd.blockchain.ledger.core.LedgerDataset; import com.jd.blockchain.ledger.core.LedgerDataset;
import com.jd.blockchain.ledger.core.LedgerQuery; import com.jd.blockchain.ledger.core.LedgerQuery;
import com.jd.blockchain.ledger.core.MultiIDsPolicy; import com.jd.blockchain.ledger.core.MultiIDsPolicy;
@@ -36,7 +36,7 @@ public class UserAuthorizeOperationHandle extends AbstractLedgerOperationHandle<
// 操作账本; // 操作账本;


UserRolesEntry[] urcfgs = operation.getUserRolesAuthorizations(); UserRolesEntry[] urcfgs = operation.getUserRolesAuthorizations();
UserRolesSettings urSettings = newBlockDataset.getAdminDataset().getUserRoles();
UserAuthorizationSettings urSettings = newBlockDataset.getAdminDataset().getAuthorizations();
RolePrivilegeSettings rolesSettings = newBlockDataset.getAdminDataset().getRolePrivileges(); RolePrivilegeSettings rolesSettings = newBlockDataset.getAdminDataset().getRolePrivileges();
if (urcfgs != null) { if (urcfgs != null) {
for (UserRolesEntry urcfg : urcfgs) { for (UserRolesEntry urcfg : urcfgs) {


+ 6
- 6
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/AccountSetTest.java View File

@@ -14,8 +14,8 @@ import com.jd.blockchain.crypto.service.classic.ClassicCryptoService;
import com.jd.blockchain.crypto.service.sm.SMCryptoService; import com.jd.blockchain.crypto.service.sm.SMCryptoService;
import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeyGenerator;
import com.jd.blockchain.ledger.BlockchainKeypair; import com.jd.blockchain.ledger.BlockchainKeypair;
import com.jd.blockchain.ledger.core.AccountSet;
import com.jd.blockchain.ledger.core.BaseAccount;
import com.jd.blockchain.ledger.core.MerkleAccountSet;
import com.jd.blockchain.ledger.core.MerkleAccount;
import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.CryptoConfig;
import com.jd.blockchain.ledger.core.OpeningAccessPolicy; import com.jd.blockchain.ledger.core.OpeningAccessPolicy;
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; import com.jd.blockchain.storage.service.utils.MemoryKVStorage;
@@ -43,12 +43,12 @@ public class AccountSetTest {
cryptoConf.setHashAlgorithm(ClassicAlgorithm.SHA256); cryptoConf.setHashAlgorithm(ClassicAlgorithm.SHA256);


String keyPrefix = ""; String keyPrefix = "";
AccountSet accset = new AccountSet(cryptoConf, keyPrefix, storage, storage, accessPolicy);
MerkleAccountSet accset = new MerkleAccountSet(cryptoConf, keyPrefix, storage, storage, accessPolicy);


BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate();
accset.register(userKey.getAddress(), userKey.getPubKey()); accset.register(userKey.getAddress(), userKey.getPubKey());


BaseAccount userAcc = accset.getAccount(userKey.getAddress());
MerkleAccount userAcc = accset.getAccount(userKey.getAddress());
assertNotNull(userAcc); assertNotNull(userAcc);
assertTrue(accset.contains(userKey.getAddress())); assertTrue(accset.contains(userKey.getAddress()));


@@ -56,8 +56,8 @@ public class AccountSetTest {
HashDigest rootHash = accset.getRootHash(); HashDigest rootHash = accset.getRootHash();
assertNotNull(rootHash); assertNotNull(rootHash);


AccountSet reloadAccSet = new AccountSet(rootHash, cryptoConf, keyPrefix, storage, storage, true, accessPolicy);
BaseAccount reloadUserAcc = reloadAccSet.getAccount(userKey.getAddress());
MerkleAccountSet reloadAccSet = new MerkleAccountSet(rootHash, cryptoConf, keyPrefix, storage, storage, true, accessPolicy);
MerkleAccount reloadUserAcc = reloadAccSet.getAccount(userKey.getAddress());
assertNotNull(reloadUserAcc); assertNotNull(reloadUserAcc);
assertTrue(reloadAccSet.contains(userKey.getAddress())); assertTrue(reloadAccSet.contains(userKey.getAddress()));




+ 2
- 2
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/BaseAccountTest.java View File

@@ -13,7 +13,7 @@ import com.jd.blockchain.crypto.service.sm.SMCryptoService;
import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeyGenerator;
import com.jd.blockchain.ledger.BlockchainKeypair; import com.jd.blockchain.ledger.BlockchainKeypair;
import com.jd.blockchain.ledger.BytesData; import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.ledger.core.BaseAccount;
import com.jd.blockchain.ledger.core.MerkleAccount;
import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.CryptoConfig;
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; import com.jd.blockchain.storage.service.utils.MemoryKVStorage;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
@@ -48,7 +48,7 @@ public class BaseAccountTest {
BlockchainKeypair bck = BlockchainKeyGenerator.getInstance().generate(); BlockchainKeypair bck = BlockchainKeyGenerator.getInstance().generate();


// 新建账户; // 新建账户;
BaseAccount baseAccount = new BaseAccount(bck.getIdentity(), cryptoConf, keyPrefix, testStorage, testStorage);
MerkleAccount baseAccount = new MerkleAccount(bck.getIdentity(), cryptoConf, keyPrefix, testStorage, testStorage);
assertFalse(baseAccount.isUpdated());// 空的账户; assertFalse(baseAccount.isUpdated());// 空的账户;
assertFalse(baseAccount.isReadonly()); assertFalse(baseAccount.isReadonly());




+ 12
- 12
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java View File

@@ -106,7 +106,7 @@ public class ContractInvokingTest {
deploy(ledgerRepo, ledgerManager, opReg, ledgerHash, contractKey); deploy(ledgerRepo, ledgerManager, opReg, ledgerHash, contractKey);
// 创建新区块的交易处理器; // 创建新区块的交易处理器;
LedgerBlock preBlock = ledgerRepo.getLatestBlock(); LedgerBlock preBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(preBlock);


// 加载合约 // 加载合约
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();
@@ -181,7 +181,7 @@ public class ContractInvokingTest {


// 创建新区块的交易处理器; // 创建新区块的交易处理器;
LedgerBlock preBlock = ledgerRepo.getLatestBlock(); LedgerBlock preBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(preBlock);


// 加载合约 // 加载合约
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();
@@ -218,7 +218,7 @@ public class ContractInvokingTest {
TransactionBatchResultHandle txResultHandle = txbatchProcessor.prepare(); TransactionBatchResultHandle txResultHandle = txbatchProcessor.prepare();
txResultHandle.commit(); txResultHandle.commit();


BytesValue latestValue = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getBytes(key,
BytesValue latestValue = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getBytes(key,
-1); -1);
System.out.printf("latest value=[%s] %s \r\n", latestValue.getType(), latestValue.getValue().toUTF8String()); System.out.printf("latest value=[%s] %s \r\n", latestValue.getType(), latestValue.getValue().toUTF8String());


@@ -278,9 +278,9 @@ public class ContractInvokingTest {
} }
}); });
// 预期数据都能够正常写入; // 预期数据都能够正常写入;
KVDataEntry kv1 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K1",
KVDataEntry kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1",
0); 0);
KVDataEntry kv2 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K2",
KVDataEntry kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K2",
0); 0);
assertEquals(0, kv1.getVersion()); assertEquals(0, kv1.getVersion());
assertEquals(0, kv2.getVersion()); assertEquals(0, kv2.getVersion());
@@ -299,8 +299,8 @@ public class ContractInvokingTest {
} }
}); });
// 预期数据都能够正常写入; // 预期数据都能够正常写入;
kv1 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1);
kv2 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K2", 1);
kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1);
kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K2", 1);
assertEquals(1, kv1.getVersion()); assertEquals(1, kv1.getVersion());
assertEquals(1, kv2.getVersion()); assertEquals(1, kv2.getVersion());
assertEquals("V1-1", kv1.getValue()); assertEquals("V1-1", kv1.getValue());
@@ -318,10 +318,10 @@ public class ContractInvokingTest {
} }
}); });
// 预期数据都能够正常写入; // 预期数据都能够正常写入;
kv1 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1);
kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1);
assertEquals(1, kv1.getVersion()); assertEquals(1, kv1.getVersion());
assertEquals("V1-1", kv1.getValue()); assertEquals("V1-1", kv1.getValue());
kv1 = ledgerRepo.getDataAccountSet().getDataAccount(kpDataAccount.getAddress()).getDataEntry("K1", 2);
kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 2);
assertEquals(-1, kv1.getVersion()); assertEquals(-1, kv1.getVersion());
assertEquals(null, kv1.getValue()); assertEquals(null, kv1.getValue());


@@ -330,7 +330,7 @@ public class ContractInvokingTest {
private LedgerBlock buildBlock(LedgerRepository ledgerRepo, LedgerService ledgerService, private LedgerBlock buildBlock(LedgerRepository ledgerRepo, LedgerService ledgerService,
OperationHandleRegisteration opReg, TxDefinitor txDefinitor) { OperationHandleRegisteration opReg, TxDefinitor txDefinitor) {
LedgerBlock preBlock = ledgerRepo.getLatestBlock(); LedgerBlock preBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(preBlock);
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();
TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(getSecurityManager(), newBlockEditor, TransactionBatchProcessor txbatchProcessor = new TransactionBatchProcessor(getSecurityManager(), newBlockEditor,
ledgerRepo, opReg); ledgerRepo, opReg);
@@ -363,7 +363,7 @@ public class ContractInvokingTest {
private void registerDataAccount(LedgerRepository ledgerRepo, LedgerManager ledgerManager, private void registerDataAccount(LedgerRepository ledgerRepo, LedgerManager ledgerManager,
DefaultOperationHandleRegisteration opReg, HashDigest ledgerHash, BlockchainKeypair kpDataAccount) { DefaultOperationHandleRegisteration opReg, HashDigest ledgerHash, BlockchainKeypair kpDataAccount) {
LedgerBlock preBlock = ledgerRepo.getLatestBlock(); LedgerBlock preBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(preBlock);


// 加载合约 // 加载合约
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();
@@ -393,7 +393,7 @@ public class ContractInvokingTest {
DefaultOperationHandleRegisteration opReg, HashDigest ledgerHash, BlockchainKeypair contractKey) { DefaultOperationHandleRegisteration opReg, HashDigest ledgerHash, BlockchainKeypair contractKey) {
// 创建新区块的交易处理器; // 创建新区块的交易处理器;
LedgerBlock preBlock = ledgerRepo.getLatestBlock(); LedgerBlock preBlock = ledgerRepo.getLatestBlock();
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(preBlock);
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(preBlock);


// 加载合约 // 加载合约
LedgerEditor newBlockEditor = ledgerRepo.createNextBlock(); LedgerEditor newBlockEditor = ledgerRepo.createNextBlock();


+ 2
- 2
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerAccountTest.java View File

@@ -15,7 +15,7 @@ import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm;
import com.jd.blockchain.crypto.service.sm.SMAlgorithm; import com.jd.blockchain.crypto.service.sm.SMAlgorithm;
import com.jd.blockchain.ledger.AccountHeader; import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.UserInfo; import com.jd.blockchain.ledger.UserInfo;
import com.jd.blockchain.ledger.core.AccountSet;
import com.jd.blockchain.ledger.core.MerkleAccountSet;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;


/** /**
@@ -44,7 +44,7 @@ public class LedgerAccountTest {
String address = "xxxxxxxxxxxx"; String address = "xxxxxxxxxxxx";
PubKey pubKey = new PubKey(SMAlgorithm.SM2, rawDigestBytes); PubKey pubKey = new PubKey(SMAlgorithm.SM2, rawDigestBytes);
HashDigest hashDigest = new HashDigest(ClassicAlgorithm.SHA256, rawDigestBytes); HashDigest hashDigest = new HashDigest(ClassicAlgorithm.SHA256, rawDigestBytes);
AccountSet.AccountHeaderData accountHeaderData = new AccountSet.AccountHeaderData(Bytes.fromString(address),
MerkleAccountSet.AccountHeaderData accountHeaderData = new MerkleAccountSet.AccountHeaderData(Bytes.fromString(address),
pubKey, hashDigest); pubKey, hashDigest);


// encode and decode // encode and decode


+ 7
- 7
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerAdminDatasetTest.java View File

@@ -33,7 +33,7 @@ import com.jd.blockchain.ledger.RolePrivileges;
import com.jd.blockchain.ledger.RolesPolicy; import com.jd.blockchain.ledger.RolesPolicy;
import com.jd.blockchain.ledger.TransactionPermission; import com.jd.blockchain.ledger.TransactionPermission;
import com.jd.blockchain.ledger.UserRoles; import com.jd.blockchain.ledger.UserRoles;
import com.jd.blockchain.ledger.UserRolesSettings;
import com.jd.blockchain.ledger.UserAuthorizationSettings;
import com.jd.blockchain.ledger.core.CryptoConfig; import com.jd.blockchain.ledger.core.CryptoConfig;
import com.jd.blockchain.ledger.core.LedgerAdminDataset; import com.jd.blockchain.ledger.core.LedgerAdminDataset;
import com.jd.blockchain.ledger.core.LedgerConfiguration; import com.jd.blockchain.ledger.core.LedgerConfiguration;
@@ -100,7 +100,7 @@ public class LedgerAdminDatasetTest {
new TransactionPermission[] { TransactionPermission.DIRECT_OPERATION, new TransactionPermission[] { TransactionPermission.DIRECT_OPERATION,
TransactionPermission.CONTRACT_OPERATION }); TransactionPermission.CONTRACT_OPERATION });


ledgerAdminDataset.getUserRoles().addUserRoles(parties[0].getAddress(), RolesPolicy.UNION, "DEFAULT");
ledgerAdminDataset.getAuthorizations().addUserRoles(parties[0].getAddress(), RolesPolicy.UNION, "DEFAULT");


// New created instance is updated until being committed; // New created instance is updated until being committed;
assertTrue(ledgerAdminDataset.isUpdated()); assertTrue(ledgerAdminDataset.isUpdated());
@@ -148,7 +148,7 @@ public class LedgerAdminDatasetTest {
verifyReadonlyState(reloadAdminAccount1); verifyReadonlyState(reloadAdminAccount1);


verifyRealoadingRoleAuthorizations(reloadAdminAccount1, ledgerAdminDataset.getRolePrivileges(), verifyRealoadingRoleAuthorizations(reloadAdminAccount1, ledgerAdminDataset.getRolePrivileges(),
ledgerAdminDataset.getUserRoles());
ledgerAdminDataset.getAuthorizations());


// -------------- // --------------
// 重新加载,并进行修改; // 重新加载,并进行修改;
@@ -168,7 +168,7 @@ public class LedgerAdminDatasetTest {


reloadAdminAccount2.getRolePrivileges().disablePermissions("DEFAULT", TransactionPermission.CONTRACT_OPERATION); reloadAdminAccount2.getRolePrivileges().disablePermissions("DEFAULT", TransactionPermission.CONTRACT_OPERATION);


reloadAdminAccount2.getUserRoles().addUserRoles(parties[1].getAddress(), RolesPolicy.UNION, "DEFAULT", "ADMIN");
reloadAdminAccount2.getAuthorizations().addUserRoles(parties[1].getAddress(), RolesPolicy.UNION, "DEFAULT", "ADMIN");


reloadAdminAccount2.commit(); reloadAdminAccount2.commit();


@@ -228,7 +228,7 @@ public class LedgerAdminDatasetTest {
} }


private void verifyRealoadingRoleAuthorizations(LedgerAdminSettings actualAccount, private void verifyRealoadingRoleAuthorizations(LedgerAdminSettings actualAccount,
RolePrivilegeSettings expRolePrivilegeSettings, UserRolesSettings expUserRoleSettings) {
RolePrivilegeSettings expRolePrivilegeSettings, UserAuthorizationSettings expUserRoleSettings) {
// 验证基本信息; // 验证基本信息;
RolePrivilegeSettings actualRolePrivileges = actualAccount.getRolePrivileges(); RolePrivilegeSettings actualRolePrivileges = actualAccount.getRolePrivileges();
RolePrivileges[] expRPs = expRolePrivilegeSettings.getRolePrivileges(); RolePrivileges[] expRPs = expRolePrivilegeSettings.getRolePrivileges();
@@ -242,12 +242,12 @@ public class LedgerAdminDatasetTest {
assertArrayEquals(expRP.getTransactionPrivilege().toBytes(), actualRP.getTransactionPrivilege().toBytes()); assertArrayEquals(expRP.getTransactionPrivilege().toBytes(), actualRP.getTransactionPrivilege().toBytes());
} }


UserRolesSettings actualUserRoleSettings = actualAccount.getUserRoles();
UserAuthorizationSettings actualUserRoleSettings = actualAccount.getAuthorizations();
UserRoles[] expUserRoles = expUserRoleSettings.getUserRoles(); UserRoles[] expUserRoles = expUserRoleSettings.getUserRoles();
assertEquals(expUserRoles.length, actualUserRoleSettings.getUserCount()); assertEquals(expUserRoles.length, actualUserRoleSettings.getUserCount());


for (UserRoles expUR : expUserRoles) { for (UserRoles expUR : expUserRoles) {
UserRoles actualUR = actualAccount.getUserRoles().getUserRoles(expUR.getUserAddress());
UserRoles actualUR = actualAccount.getAuthorizations().getUserRoles(expUR.getUserAddress());
assertNotNull(actualUR); assertNotNull(actualUR);
assertEquals(expUR.getPolicy(), actualUR.getPolicy()); assertEquals(expUR.getPolicy(), actualUR.getPolicy());
String[] expRoles = expUR.getRoles(); String[] expRoles = expUR.getRoles();


+ 21
- 21
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java View File

@@ -84,8 +84,8 @@ public class TransactionBatchProcessorTest {
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE); LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE);


// 验证参与方账户的存在; // 验证参与方账户的存在;
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getUser(parti0.getAddress());
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getAccount(parti0.getAddress());
assertNotNull(user0); assertNotNull(user0);
boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress()); boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress());
assertTrue(partiRegistered); assertTrue(partiRegistered);
@@ -144,8 +144,8 @@ public class TransactionBatchProcessorTest {
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE); LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE);


// 验证参与方账户的存在; // 验证参与方账户的存在;
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getUser(parti0.getAddress());
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getAccount(parti0.getAddress());
assertNotNull(user0); assertNotNull(user0);
boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress()); boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress());
assertTrue(partiRegistered); assertTrue(partiRegistered);
@@ -183,7 +183,7 @@ public class TransactionBatchProcessorTest {
assertEquals(newBlock.getHash(), latestBlock.getHash()); assertEquals(newBlock.getHash(), latestBlock.getHash());
assertEquals(1, newBlock.getHeight()); assertEquals(1, newBlock.getHeight());


LedgerDataQuery ledgerDS = ledgerRepo.getDataSet(latestBlock);
LedgerDataQuery ledgerDS = ledgerRepo.getLedgerData(latestBlock);
boolean existUser1 = ledgerDS.getUserAccountSet().contains(userKeypair1.getAddress()); boolean existUser1 = ledgerDS.getUserAccountSet().contains(userKeypair1.getAddress());
boolean existUser2 = ledgerDS.getUserAccountSet().contains(userKeypair2.getAddress()); boolean existUser2 = ledgerDS.getUserAccountSet().contains(userKeypair2.getAddress());
assertTrue(existUser1); assertTrue(existUser1);
@@ -202,8 +202,8 @@ public class TransactionBatchProcessorTest {
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE); LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE);


// 验证参与方账户的存在; // 验证参与方账户的存在;
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getUser(parti0.getAddress());
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getAccount(parti0.getAddress());
assertNotNull(user0); assertNotNull(user0);
boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress()); boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress());
assertTrue(partiRegistered); assertTrue(partiRegistered);
@@ -261,7 +261,7 @@ public class TransactionBatchProcessorTest {
assertNotNull(tx3); assertNotNull(tx3);
assertEquals(TransactionState.SUCCESS, tx3.getExecutionState()); assertEquals(TransactionState.SUCCESS, tx3.getExecutionState());


LedgerDataQuery ledgerDS = ledgerRepo.getDataSet(latestBlock);
LedgerDataQuery ledgerDS = ledgerRepo.getLedgerData(latestBlock);
boolean existUser1 = ledgerDS.getUserAccountSet().contains(userKeypair1.getAddress()); boolean existUser1 = ledgerDS.getUserAccountSet().contains(userKeypair1.getAddress());
boolean existUser2 = ledgerDS.getUserAccountSet().contains(userKeypair2.getAddress()); boolean existUser2 = ledgerDS.getUserAccountSet().contains(userKeypair2.getAddress());
boolean existUser3 = ledgerDS.getUserAccountSet().contains(userKeypair3.getAddress()); boolean existUser3 = ledgerDS.getUserAccountSet().contains(userKeypair3.getAddress());
@@ -282,8 +282,8 @@ public class TransactionBatchProcessorTest {
LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE); LedgerRepository ledgerRepo = ledgerManager.register(ledgerHash, STORAGE);


// 验证参与方账户的存在; // 验证参与方账户的存在;
LedgerDataQuery previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getUser(parti0.getAddress());
LedgerDataQuery previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
UserAccount user0 = previousBlockDataset.getUserAccountSet().getAccount(parti0.getAddress());
assertNotNull(user0); assertNotNull(user0);
boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress()); boolean partiRegistered = previousBlockDataset.getUserAccountSet().contains(parti0.getAddress());
assertTrue(partiRegistered); assertTrue(partiRegistered);
@@ -305,7 +305,7 @@ public class TransactionBatchProcessorTest {
newBlockEditor.commit(); newBlockEditor.commit();


assertEquals(TransactionState.SUCCESS, txResp1.getExecutionState()); assertEquals(TransactionState.SUCCESS, txResp1.getExecutionState());
DataAccount dataAccount = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress());
DataAccount dataAccount = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress());
assertNotNull(dataAccount); assertNotNull(dataAccount);


// 正确写入 KV 数据; // 正确写入 KV 数据;
@@ -321,7 +321,7 @@ public class TransactionBatchProcessorTest {
"K1", "V-1-2", 0, ledgerHash, parti0, parti0); "K1", "V-1-2", 0, ledgerHash, parti0, parti0);


newBlockEditor = ledgerRepo.createNextBlock(); newBlockEditor = ledgerRepo.createNextBlock();
previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg); txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg);


txbatchProcessor.schedule(txreq1); txbatchProcessor.schedule(txreq1);
@@ -332,13 +332,13 @@ public class TransactionBatchProcessorTest {
newBlock = newBlockEditor.prepare(); newBlock = newBlockEditor.prepare();
newBlockEditor.commit(); newBlockEditor.commit();


BytesValue v1_0 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K1",
BytesValue v1_0 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K1",
0); 0);
BytesValue v1_1 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K1",
BytesValue v1_1 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K1",
1); 1);
BytesValue v2 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K2",
BytesValue v2 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K2",
0); 0);
BytesValue v3 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K3",
BytesValue v3 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K3",
0); 0);


assertNotNull(v1_0); assertNotNull(v1_0);
@@ -360,7 +360,7 @@ public class TransactionBatchProcessorTest {
"K1", "V-1-3", 0, ledgerHash, parti0, parti0); "K1", "V-1-3", 0, ledgerHash, parti0, parti0);


newBlockEditor = ledgerRepo.createNextBlock(); newBlockEditor = ledgerRepo.createNextBlock();
previousBlockDataset = ledgerRepo.getDataSet(ledgerRepo.getLatestBlock());
previousBlockDataset = ledgerRepo.getLedgerData(ledgerRepo.getLatestBlock());
txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg); txbatchProcessor = new TransactionBatchProcessor(securityManager, newBlockEditor, ledgerRepo, opReg);


txbatchProcessor.schedule(txreq5); txbatchProcessor.schedule(txreq5);
@@ -376,15 +376,15 @@ public class TransactionBatchProcessorTest {
newBlock = newBlockEditor.prepare(); newBlock = newBlockEditor.prepare();
newBlockEditor.commit(); newBlockEditor.commit();


BytesValue v1 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K1");
v3 = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress()).getBytes("K3");
BytesValue v1 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K1");
v3 = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress()).getBytes("K3");


// k1 的版本仍然为1,没有更新; // k1 的版本仍然为1,没有更新;
long k1_version = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress())
long k1_version = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress())
.getDataVersion("K1"); .getDataVersion("K1");
assertEquals(1, k1_version); assertEquals(1, k1_version);


long k3_version = ledgerRepo.getDataAccountSet().getDataAccount(dataAccountKeypair.getAddress())
long k3_version = ledgerRepo.getDataAccountSet().getAccount(dataAccountKeypair.getAddress())
.getDataVersion("K3"); .getDataVersion("K3");
assertEquals(1, k3_version); assertEquals(1, k3_version);




+ 2
- 1
source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java View File

@@ -17,6 +17,7 @@ import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.crypto.HashDigest; import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry; import com.jd.blockchain.ledger.DataAccountKVSetOperation.KVWriteEntry;
import com.jd.blockchain.ledger.core.LedgerTransactionData; import com.jd.blockchain.ledger.core.LedgerTransactionData;
import com.jd.blockchain.ledger.core.TransactionQuery;
import com.jd.blockchain.ledger.core.TransactionSet; import com.jd.blockchain.ledger.core.TransactionSet;
import com.jd.blockchain.ledger.core.TransactionStagedSnapshot; import com.jd.blockchain.ledger.core.TransactionStagedSnapshot;
import com.jd.blockchain.storage.service.utils.MemoryKVStorage; import com.jd.blockchain.storage.service.utils.MemoryKVStorage;
@@ -103,7 +104,7 @@ public class TransactionSetTest {
assertEquals(5, tx.getTransactionContent().getOperations().length); assertEquals(5, tx.getTransactionContent().getOperations().length);


// Reload ; // Reload ;
TransactionSet reloadTxset = new TransactionSet(txsetRootHash, defCryptoSetting, keyPrefix, testStorage,
TransactionQuery reloadTxset = new TransactionSet(txsetRootHash, defCryptoSetting, keyPrefix, testStorage,
testStorage, true); testStorage, true);


assertEquals(1, reloadTxset.getTotalCount()); assertEquals(1, reloadTxset.getTotalCount());


+ 1
- 6
source/ledger/ledger-model/src/main/java/com/jd/blockchain/contract/EventHandle.java View File

@@ -5,12 +5,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/**
* HTTP 服务方法;
*
* @author haiq
*
*/
@Target({ ElementType.METHOD }) @Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface EventHandle { public @interface EventHandle {


+ 2
- 5
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/AccountHeader.java View File

@@ -4,20 +4,17 @@ import com.jd.blockchain.binaryproto.DataContract;
import com.jd.blockchain.binaryproto.DataField; import com.jd.blockchain.binaryproto.DataField;
import com.jd.blockchain.binaryproto.PrimitiveType; import com.jd.blockchain.binaryproto.PrimitiveType;
import com.jd.blockchain.consts.DataCodes; import com.jd.blockchain.consts.DataCodes;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PubKey; import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;


@DataContract(code= DataCodes.ACCOUNT_HEADER) @DataContract(code= DataCodes.ACCOUNT_HEADER)
public interface AccountHeader {
public interface AccountHeader extends MerkleSnapshot{
@DataField(order=1, primitiveType = PrimitiveType.BYTES) @DataField(order=1, primitiveType = PrimitiveType.BYTES)
Bytes getAddress(); Bytes getAddress();
@DataField(order=2, primitiveType = PrimitiveType.BYTES) @DataField(order=2, primitiveType = PrimitiveType.BYTES)
PubKey getPubKey(); PubKey getPubKey();
@DataField(order=3, primitiveType = PrimitiveType.BYTES)
HashDigest getRootHash();

} }

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

@@ -2,7 +2,7 @@ package com.jd.blockchain.ledger;


public interface LedgerAdminSettings extends LedgerAdminInfo { public interface LedgerAdminSettings extends LedgerAdminInfo {


UserRolesSettings getUserRoles();
UserAuthorizationSettings getAuthorizations();


RolePrivilegeSettings getRolePrivileges(); RolePrivilegeSettings getRolePrivileges();
} }

+ 15
- 0
source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/MerkleSnapshot.java View File

@@ -0,0 +1,15 @@
package com.jd.blockchain.ledger;

import com.jd.blockchain.binaryproto.DataContract;
import com.jd.blockchain.binaryproto.DataField;
import com.jd.blockchain.binaryproto.PrimitiveType;
import com.jd.blockchain.consts.DataCodes;
import com.jd.blockchain.crypto.HashDigest;

@DataContract(code = DataCodes.MERKLE_SNAPSHOT)
public interface MerkleSnapshot {

@DataField(order = 0, primitiveType = PrimitiveType.BYTES)
HashDigest getRootHash();

}

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

@@ -13,7 +13,7 @@ public interface ParticipantRegisterOperation extends Operation {
String getParticipantName(); String getParticipantName();


@DataField(order = 1, refContract = true) @DataField(order = 1, refContract = true)
BlockchainIdentity getParticipantIdentity();
BlockchainIdentity getParticipantRegisterIdentity();


@DataField(order = 2, primitiveType = PrimitiveType.BYTES) @DataField(order = 2, primitiveType = PrimitiveType.BYTES)
NetworkAddress getNetworkAddress(); NetworkAddress getNetworkAddress();


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

@@ -10,7 +10,7 @@ import com.jd.blockchain.utils.net.NetworkAddress;
public interface ParticipantStateUpdateOperation extends Operation { public interface ParticipantStateUpdateOperation extends Operation {


@DataField(order = 0, refContract = true) @DataField(order = 0, refContract = true)
BlockchainIdentity getParticipantIdentity();
BlockchainIdentity getStateUpdateIdentity();


@DataField(order = 1, primitiveType = PrimitiveType.BYTES) @DataField(order = 1, primitiveType = PrimitiveType.BYTES)
NetworkAddress getNetworkAddress(); NetworkAddress getNetworkAddress();


source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/UserRolesSettings.java → source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/UserAuthorizationSettings.java View File

@@ -4,7 +4,7 @@ import java.util.Collection;


import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;


public interface UserRolesSettings {
public interface UserAuthorizationSettings {


/** /**
* 单一用户可被授权的角色数量的最大值; * 单一用户可被授权的角色数量的最大值;

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

@@ -14,12 +14,12 @@ public class ParticipantRegisterOpTemplate implements ParticipantRegisterOperati
} }


private String participantName; private String participantName;
private BlockchainIdentity participantPubKey;
private BlockchainIdentity participantRegisterIdentity;
private NetworkAddress networkAddress; private NetworkAddress networkAddress;


public ParticipantRegisterOpTemplate(String participantName, BlockchainIdentity participantPubKey, NetworkAddress networkAddress) {
public ParticipantRegisterOpTemplate(String participantName, BlockchainIdentity participantRegisterIdentity, NetworkAddress networkAddress) {
this.participantName = participantName; this.participantName = participantName;
this.participantPubKey = participantPubKey;
this.participantRegisterIdentity = participantRegisterIdentity;
this.networkAddress = networkAddress; this.networkAddress = networkAddress;


} }
@@ -30,8 +30,8 @@ public class ParticipantRegisterOpTemplate implements ParticipantRegisterOperati
} }


@Override @Override
public BlockchainIdentity getParticipantIdentity() {
return participantPubKey;
public BlockchainIdentity getParticipantRegisterIdentity() {
return participantRegisterIdentity;
} }


@Override @Override


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

@@ -12,21 +12,21 @@ public class ParticipantStateUpdateOpTemplate implements ParticipantStateUpdateO
DataContractRegistry.register(ParticipantStateUpdateOperation.class); DataContractRegistry.register(ParticipantStateUpdateOperation.class);
} }


private BlockchainIdentity blockchainIdentity;
private BlockchainIdentity stateUpdateIdentity;
private NetworkAddress networkAddress; private NetworkAddress networkAddress;
private ParticipantNodeState participantNodeState; private ParticipantNodeState participantNodeState;


public ParticipantStateUpdateOpTemplate(BlockchainIdentity blockchainIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState) {
public ParticipantStateUpdateOpTemplate(BlockchainIdentity stateUpdateIdentity, NetworkAddress networkAddress, ParticipantNodeState participantNodeState) {


this.blockchainIdentity = blockchainIdentity;
this.stateUpdateIdentity = stateUpdateIdentity;
this.networkAddress = networkAddress; this.networkAddress = networkAddress;
this.participantNodeState = participantNodeState; this.participantNodeState = participantNodeState;
} }




@Override @Override
public BlockchainIdentity getParticipantIdentity() {
return blockchainIdentity;
public BlockchainIdentity getStateUpdateIdentity() {
return stateUpdateIdentity;
} }


@Override @Override


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

@@ -22,8 +22,8 @@ public class UserAuthorizeOpTemplate implements UserAuthorizer, UserAuthorizeOpe
DataContractRegistry.register(UserRolesEntry.class); DataContractRegistry.register(UserRolesEntry.class);
} }
private Set<UserRolesAuthorization> userAuthMap = Collections
.synchronizedSet(new LinkedHashSet<UserRolesAuthorization>());
private Set<AuthorizationDataEntry> userAuthMap = Collections
.synchronizedSet(new LinkedHashSet<AuthorizationDataEntry>());
public UserAuthorizeOpTemplate() { public UserAuthorizeOpTemplate() {
} }
@@ -32,8 +32,8 @@ public class UserAuthorizeOpTemplate implements UserAuthorizer, UserAuthorizeOpe
} }
@Override @Override
public UserRolesAuthorization[] getUserRolesAuthorizations() {
return ArrayUtils.toArray(userAuthMap, UserRolesAuthorization.class);
public AuthorizationDataEntry[] getUserRolesAuthorizations() {
return ArrayUtils.toArray(userAuthMap, AuthorizationDataEntry.class);
} }
@Override @Override
@@ -43,7 +43,7 @@ public class UserAuthorizeOpTemplate implements UserAuthorizer, UserAuthorizeOpe
@Override @Override
public UserRolesAuthorizer forUser(Bytes... userAddresses) { public UserRolesAuthorizer forUser(Bytes... userAddresses) {
UserRolesAuthorization userRolesAuth = new UserRolesAuthorization(userAddresses);
AuthorizationDataEntry userRolesAuth = new AuthorizationDataEntry(userAddresses);
userAuthMap.add(userRolesAuth); userAuthMap.add(userRolesAuth);
return userRolesAuth; return userRolesAuth;
} }
@@ -54,7 +54,7 @@ public class UserAuthorizeOpTemplate implements UserAuthorizer, UserAuthorizeOpe
return forUser(addresses); return forUser(addresses);
} }
private class UserRolesAuthorization implements UserRolesAuthorizer, UserRolesEntry {
private class AuthorizationDataEntry implements UserRolesAuthorizer, UserRolesEntry {
private Bytes[] userAddress; private Bytes[] userAddress;
@@ -63,7 +63,7 @@ public class UserAuthorizeOpTemplate implements UserAuthorizer, UserAuthorizeOpe
private Set<String> authRoles = new LinkedHashSet<String>(); private Set<String> authRoles = new LinkedHashSet<String>();
private Set<String> unauthRoles = new LinkedHashSet<String>(); private Set<String> unauthRoles = new LinkedHashSet<String>();
private UserRolesAuthorization(Bytes[] userAddress) {
private AuthorizationDataEntry(Bytes[] userAddress) {
this.userAddress = userAddress; this.userAddress = userAddress;
} }


+ 31
- 31
source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java View File

@@ -20,7 +20,7 @@ import com.jd.blockchain.ledger.core.DataAccountQuery;
import com.jd.blockchain.ledger.core.LedgerQuery; import com.jd.blockchain.ledger.core.LedgerQuery;
import com.jd.blockchain.ledger.core.LedgerService; import com.jd.blockchain.ledger.core.LedgerService;
import com.jd.blockchain.ledger.core.ParticipantCertData; import com.jd.blockchain.ledger.core.ParticipantCertData;
import com.jd.blockchain.ledger.core.TransactionSet;
import com.jd.blockchain.ledger.core.TransactionQuery;
import com.jd.blockchain.ledger.core.UserAccountQuery; import com.jd.blockchain.ledger.core.UserAccountQuery;
import com.jd.blockchain.transaction.BlockchainQueryService; import com.jd.blockchain.transaction.BlockchainQueryService;
import com.jd.blockchain.utils.Bytes; import com.jd.blockchain.utils.Bytes;
@@ -116,7 +116,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@PathVariable(name = "blockHeight") long blockHeight) { @PathVariable(name = "blockHeight") long blockHeight) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHeight); LedgerBlock block = ledger.getBlock(blockHeight);
TransactionSet txSet = ledger.getTransactionSet(block);
TransactionQuery txSet = ledger.getTransactionSet(block);
return txSet.getTotalCount(); return txSet.getTotalCount();
} }


@@ -126,7 +126,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@PathVariable(name = "blockHash") HashDigest blockHash) { @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
TransactionSet txSet = ledger.getTransactionSet(block);
TransactionQuery txSet = ledger.getTransactionSet(block);
return txSet.getTotalCount(); return txSet.getTotalCount();
} }


@@ -135,7 +135,7 @@ public class LedgerQueryController implements BlockchainQueryService {
public long getTransactionTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) { public long getTransactionTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txSet = ledger.getTransactionSet(block);
TransactionQuery txSet = ledger.getTransactionSet(block);
return txSet.getTotalCount(); return txSet.getTotalCount();
} }


@@ -146,7 +146,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/accounts/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/accounts/count")
@@ -156,7 +156,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/count")
@@ -165,7 +165,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getTotalCount();
return dataAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/users/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/users/count")
@@ -175,7 +175,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/users/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/users/count")
@@ -185,7 +185,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/count")
@@ -194,7 +194,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getTotalCount();
return userAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/contracts/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/contracts/count")
@@ -204,7 +204,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height); LedgerBlock block = ledger.getBlock(height);
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/contracts/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/contracts/count")
@@ -214,7 +214,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash); LedgerBlock block = ledger.getBlock(blockHash);
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts/count") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts/count")
@@ -223,7 +223,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getTotalCount();
return contractAccountSet.getTotal();
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/txs") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/txs")
@@ -235,7 +235,7 @@ public class LedgerQueryController implements BlockchainQueryService {


LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHeight); LedgerBlock ledgerBlock = ledger.getBlock(blockHeight);
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock);
TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
int lastHeightTxTotalNums = 0; int lastHeightTxTotalNums = 0;


if (blockHeight > 0) { if (blockHeight > 0) {
@@ -269,7 +269,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHash); LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
long height = ledgerBlock.getHeight(); long height = ledgerBlock.getHeight();
TransactionSet transactionSet = ledger.getTransactionSet(ledgerBlock);
TransactionQuery transactionSet = ledger.getTransactionSet(ledgerBlock);
int lastHeightTxTotalNums = 0; int lastHeightTxTotalNums = 0;


if (height > 0) { if (height > 0) {
@@ -300,7 +300,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@PathVariable(name = "contentHash") HashDigest contentHash) { @PathVariable(name = "contentHash") HashDigest contentHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.get(contentHash); return txset.get(contentHash);
} }


@@ -310,8 +310,8 @@ public class LedgerQueryController implements BlockchainQueryService {
@PathVariable(name = "contentHash") HashDigest contentHash) { @PathVariable(name = "contentHash") HashDigest contentHash) {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
return txset.getTxState(contentHash);
TransactionQuery txset = ledger.getTransactionSet(block);
return txset.getState(contentHash);
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/address/{address}") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/address/{address}")
@@ -321,7 +321,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
return userAccountSet.getUser(address);
return userAccountSet.getAccount(address);
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}")
@@ -331,7 +331,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getDataAccount(Bytes.fromBase58(address));
return dataAccountSet.getAccount(Bytes.fromBase58(address));
} }


@RequestMapping(method = { RequestMethod.GET, @RequestMapping(method = { RequestMethod.GET,
@@ -345,7 +345,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


KVDataEntry[] entries = new KVDataEntry[keys.length]; KVDataEntry[] entries = new KVDataEntry[keys.length];
long ver; long ver;
@@ -394,7 +394,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


KVDataEntry[] entries = new KVDataEntry[keys.length]; KVDataEntry[] entries = new KVDataEntry[keys.length];
long ver = -1; long ver = -1;
@@ -429,7 +429,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataEntriesTotalCount()); int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataEntriesTotalCount());
return dataAccount.getDataEntries(pages[0], pages[1]); return dataAccount.getDataEntries(pages[0], pages[1]);
@@ -443,7 +443,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address));


return dataAccount.getDataEntriesTotalCount(); return dataAccount.getDataEntriesTotalCount();
} }
@@ -455,7 +455,7 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
return contractAccountSet.getContract(Bytes.fromBase58(address));
return contractAccountSet.getAccount(Bytes.fromBase58(address));
} }


/** /**
@@ -474,8 +474,8 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
UserAccountQuery userAccountSet = ledger.getUserAccountSet(block); UserAccountQuery userAccountSet = ledger.getUserAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotalCount());
return userAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) userAccountSet.getTotal());
return userAccountSet.getHeaders(pages[0], pages[1]);
} }


/** /**
@@ -494,8 +494,8 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotalCount());
return dataAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccountSet.getTotal());
return dataAccountSet.getHeaders(pages[0], pages[1]);
} }


@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts") @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts")
@@ -506,8 +506,8 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerQuery ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock(); LedgerBlock block = ledger.getLatestBlock();
ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block); ContractAccountQuery contractAccountSet = ledger.getContractAccountSet(block);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotalCount());
return contractAccountSet.getAccounts(pages[0], pages[1]);
int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotal());
return contractAccountSet.getHeaders(pages[0], pages[1]);
} }


} }

+ 8
- 2
source/peer/src/main/java/com/jd/blockchain/peer/web/ManagementController.java View File

@@ -113,12 +113,18 @@ public class ManagementController implements LedgerBindingConfigAware, PeerManag
DataContractRegistry.register(LedgerAdminInfo.class); DataContractRegistry.register(LedgerAdminInfo.class);
DataContractRegistry.register(LedgerSettings.class); DataContractRegistry.register(LedgerSettings.class);

// 注册角色/权限相关接口
DataContractRegistry.register(RolesConfigureOperation.class);
DataContractRegistry.register(RolesConfigureOperation.RolePrivilegeEntry.class);
DataContractRegistry.register(UserAuthorizeOperation.class);
DataContractRegistry.register(UserAuthorizeOperation.UserRolesEntry.class);
DataContractRegistry.register(PrivilegeSet.class);
DataContractRegistry.register(RoleSet.class); DataContractRegistry.register(RoleSet.class);
DataContractRegistry.register(SecurityInitSettings.class); DataContractRegistry.register(SecurityInitSettings.class);
DataContractRegistry.register(RoleInitSettings.class); DataContractRegistry.register(RoleInitSettings.class);
DataContractRegistry.register(UserAuthInitSettings.class); DataContractRegistry.register(UserAuthInitSettings.class);
DataContractRegistry.register(PrivilegeSet.class);

DataContractRegistry.register(LedgerMetadata_V2.class);
} }


/** /**


+ 12
- 0
source/sdk/sdk-client/src/main/java/com/jd/blockchain/sdk/client/GatewayServiceFactory.java View File

@@ -56,6 +56,18 @@ public class GatewayServiceFactory implements BlockchainServiceFactory, Closeabl
DataContractRegistry.register(ClientIdentification.class); DataContractRegistry.register(ClientIdentification.class);
DataContractRegistry.register(BytesValueList.class); DataContractRegistry.register(BytesValueList.class);
// 注册角色/权限相关接口
DataContractRegistry.register(RolesConfigureOperation.class);
DataContractRegistry.register(RolesConfigureOperation.RolePrivilegeEntry.class);
DataContractRegistry.register(UserAuthorizeOperation.class);
DataContractRegistry.register(UserAuthorizeOperation.UserRolesEntry.class);
DataContractRegistry.register(PrivilegeSet.class);
DataContractRegistry.register(RoleSet.class);
DataContractRegistry.register(SecurityInitSettings.class);
DataContractRegistry.register(RoleInitSettings.class);
DataContractRegistry.register(UserAuthInitSettings.class);
DataContractRegistry.register(LedgerMetadata_V2.class);
ByteArrayObjectUtil.init(); ByteArrayObjectUtil.init();
} }


+ 19
- 19
source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_Constant.java View File

@@ -7,37 +7,37 @@ import java.io.File;


public class SDKDemo_Constant { public class SDKDemo_Constant {


// public static final String GW_IPADDR = "127.0.0.1";
public static final String GW_IPADDR = "192.168.151.41";

// public static final int GW_PORT = 11000;
public static final int GW_PORT = 18081;

// public static final String[] PUB_KEYS = {
// "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
// "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
// "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
// "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"};
//
// public static final String[] PRIV_KEYS = {
// "177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
// "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
// "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
// "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns"};
public static final String GW_IPADDR = "127.0.0.1";
// public static final String GW_IPADDR = "192.168.151.41";


public static final int GW_PORT = 11000;
// public static final int GW_PORT = 18081;


public static final String[] PUB_KEYS = { public static final String[] PUB_KEYS = {
"3snPdw7i7PXvEDgq96QyzcKhfWL4mgYspzKwvgXiuAidWb2rkRMgDY",
"3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
"3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX", "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
"3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x", "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
"3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"}; "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"};


public static final String[] PRIV_KEYS = { public static final String[] PRIV_KEYS = {
"177gjsxj2ezADGthZ4tGqWeCAqRAwtNvesPjRnyKqCb1huU8LKZmJ3HGZNMPKWQJK3DP1B2",
"177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
"177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT", "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
"177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF", "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
"177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns"}; "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns"};



// public static final String[] PUB_KEYS = {
// "3snPdw7i7PXvEDgq96QyzcKhfWL4mgYspzKwvgXiuAidWb2rkRMgDY",
// "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
// "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
// "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk"};
//
// public static final String[] PRIV_KEYS = {
// "177gjsxj2ezADGthZ4tGqWeCAqRAwtNvesPjRnyKqCb1huU8LKZmJ3HGZNMPKWQJK3DP1B2",
// "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
// "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
// "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns"};

public static final String PASSWORD = "abc"; public static final String PASSWORD = "abc";


public static final byte[] readChainCodes(String contractZip) { public static final byte[] readChainCodes(String contractZip) {


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

@@ -0,0 +1,26 @@
package com.jd.blockchain.sdk.samples;

import com.jd.blockchain.ledger.*;

public class SDK_RoleConfig_Demo extends SDK_Base_Demo {

public static void main(String[] args) {
new SDK_RoleConfig_Demo().executeRoleConfig();
}

public void executeRoleConfig() {

// 定义交易模板
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);

// 新增加一个角色

txTpl.security().roles().configure("MyRole")
.enable(LedgerPermission.APPROVE_TX, LedgerPermission.CONSENSUS_TX)
.disable(TransactionPermission.CONTRACT_OPERATION);
TransactionResponse txResp = commit(txTpl);

System.out.println(txResp.isSuccess());

}
}

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

@@ -0,0 +1,44 @@
package com.jd.blockchain.sdk.samples;

import com.jd.blockchain.ledger.*;
import com.jd.blockchain.utils.Bytes;

public class SDK_User2Role_Demo extends SDK_Base_Demo {

public static void main(String[] args) {
new SDK_User2Role_Demo().executeUser2Role();
}

public void executeUser2Role() {

// 定义交易模板
TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);

// 注册一个用户
BlockchainKeypair user = createUser();

Bytes userAddress = user.getAddress();
// 获取数据账户地址
System.out.printf("UserAddress = %s \r\n", userAddress.toBase58());


txTpl.security().authorziations().forUser(user.getIdentity())
.authorize("MYROLE")
.setPolicy(RolesPolicy.UNION)
.unauthorize("MYROLE");
TransactionResponse txResp = commit(txTpl);

System.out.println(txResp.isSuccess());

}

private BlockchainKeypair createUser() {
// 首先注册一个数据账户
BlockchainKeypair newUser = BlockchainKeyGenerator.getInstance().generate();

TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
txTpl.users().register(newUser.getIdentity());
commit(txTpl);
return newUser;
}
}

+ 9
- 9
source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java View File

@@ -336,21 +336,21 @@ public class IntegrationTest {
// getDataAccountCount according to blockhash // getDataAccountCount according to blockhash
for (int i = 0; i < ledgerHeight + 1; i++) { for (int i = 0; i < ledgerHeight + 1; i++) {
LedgerBlock expectBlock = ledgerOfNode0.getBlock(i); LedgerBlock expectBlock = ledgerOfNode0.getBlock(i);
long expectDataCount = ledgerOfNode0.getDataAccountSet(expectBlock).getTotalCount();
long expectDataCount = ledgerOfNode0.getDataAccountSet(expectBlock).getTotal();
long actualDataCount = blockchainService.getDataAccountCount(ledgerHash, expectBlock.getHash()); long actualDataCount = blockchainService.getDataAccountCount(ledgerHash, expectBlock.getHash());
} }


// getUserCount according to blockhash // getUserCount according to blockhash
for (int i = 0; i < ledgerHeight + 1; i++) { for (int i = 0; i < ledgerHeight + 1; i++) {
LedgerBlock expectBlock = ledgerOfNode0.getBlock(i); LedgerBlock expectBlock = ledgerOfNode0.getBlock(i);
long expectUserCount = ledgerOfNode0.getUserAccountSet(expectBlock).getTotalCount();
long expectUserCount = ledgerOfNode0.getUserAccountSet(expectBlock).getTotal();
long actualUserCount = blockchainService.getUserCount(ledgerHash, expectBlock.getHash()); long actualUserCount = blockchainService.getUserCount(ledgerHash, expectBlock.getHash());
} }


// getContractCount according to blockhash // getContractCount according to blockhash
for (int i = 0; i < ledgerHeight + 1; i++) { for (int i = 0; i < ledgerHeight + 1; i++) {
LedgerBlock expectBlock = ledgerOfNode0.getBlock(i); LedgerBlock expectBlock = ledgerOfNode0.getBlock(i);
long expectContractCount = ledgerOfNode0.getContractAccountSet(expectBlock).getTotalCount();
long expectContractCount = ledgerOfNode0.getContractAccountSet(expectBlock).getTotal();
long actualContractCount = blockchainService.getContractCount(ledgerHash, expectBlock.getHash()); long actualContractCount = blockchainService.getContractCount(ledgerHash, expectBlock.getHash());
} }


@@ -372,9 +372,9 @@ public class IntegrationTest {
// expect block acount total // expect block acount total
LedgerBlock ledgerBlock = ledgerOfNode0.getBlock(i); LedgerBlock ledgerBlock = ledgerOfNode0.getBlock(i);
expectTransactionTotal = ledgerOfNode0.getTransactionSet(ledgerBlock).getTotalCount(); expectTransactionTotal = ledgerOfNode0.getTransactionSet(ledgerBlock).getTotalCount();
expectUserTotal = ledgerOfNode0.getUserAccountSet(ledgerBlock).getTotalCount();
expectDataTotal = ledgerOfNode0.getDataAccountSet(ledgerBlock).getTotalCount();
expectContractTotal = ledgerOfNode0.getContractAccountSet(ledgerBlock).getTotalCount();
expectUserTotal = ledgerOfNode0.getUserAccountSet(ledgerBlock).getTotal();
expectDataTotal = ledgerOfNode0.getDataAccountSet(ledgerBlock).getTotal();
expectContractTotal = ledgerOfNode0.getContractAccountSet(ledgerBlock).getTotal();
} }


// getTransactionTotalCount // getTransactionTotalCount
@@ -579,7 +579,7 @@ public class IntegrationTest {
Node node0 = context.getNode(0); Node node0 = context.getNode(0);
LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight()); LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight());
byte[] contractCodeInDb = ledgerOfNode0.getContractAccountSet(block).getContract(contractDeployKey.getAddress())
byte[] contractCodeInDb = ledgerOfNode0.getContractAccountSet(block).getAccount(contractDeployKey.getAddress())
.getChainCode(); .getChainCode();
txContentHash = ptx.getHash(); txContentHash = ptx.getHash();


@@ -659,9 +659,9 @@ public class IntegrationTest {


LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash); LedgerQuery ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight()); LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight());
BytesValue val1InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
BytesValue val1InDb = ledgerOfNode0.getDataAccountSet(block).getAccount(contractDataKey.getAddress())
.getBytes("A"); .getBytes("A");
BytesValue val2InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
BytesValue val2InDb = ledgerOfNode0.getDataAccountSet(block).getAccount(contractDataKey.getAddress())
.getBytes(KEY_TOTAL); .getBytes(KEY_TOTAL);
} }




+ 4
- 4
source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java View File

@@ -117,19 +117,19 @@ public class LedgerInitializeTest {


PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]);
Bytes address0 = AddressEncoding.generateAddress(pubKey0); Bytes address0 = AddressEncoding.generateAddress(pubKey0);
UserAccount user0_0 = userset0.getUser(address0);
UserAccount user0_0 = userset0.getAccount(address0);


PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]);
Bytes address1 = AddressEncoding.generateAddress(pubKey1); Bytes address1 = AddressEncoding.generateAddress(pubKey1);
UserAccount user1_0 = userset0.getUser(address1);
UserAccount user1_0 = userset0.getAccount(address1);


PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]);
Bytes address2 = AddressEncoding.generateAddress(pubKey2); Bytes address2 = AddressEncoding.generateAddress(pubKey2);
UserAccount user2_0 = userset0.getUser(address2);
UserAccount user2_0 = userset0.getAccount(address2);


PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]);
Bytes address3 = AddressEncoding.generateAddress(pubKey3); Bytes address3 = AddressEncoding.generateAddress(pubKey3);
UserAccount user3_0 = userset0.getUser(address3);
UserAccount user3_0 = userset0.getAccount(address3);
} }


public static LedgerInitProperties loadInitSetting() { public static LedgerInitProperties loadInitSetting() {


+ 4
- 4
source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java View File

@@ -305,19 +305,19 @@ public class LedgerInitializeWebTest {


PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]);
Bytes address0 = AddressEncoding.generateAddress(pubKey0); Bytes address0 = AddressEncoding.generateAddress(pubKey0);
UserAccount user0_0 = userset0.getUser(address0);
UserAccount user0_0 = userset0.getAccount(address0);


PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]);
Bytes address1 = AddressEncoding.generateAddress(pubKey1); Bytes address1 = AddressEncoding.generateAddress(pubKey1);
UserAccount user1_0 = userset0.getUser(address1);
UserAccount user1_0 = userset0.getAccount(address1);


PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]);
Bytes address2 = AddressEncoding.generateAddress(pubKey2); Bytes address2 = AddressEncoding.generateAddress(pubKey2);
UserAccount user2_0 = userset0.getUser(address2);
UserAccount user2_0 = userset0.getAccount(address2);


PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]);
Bytes address3 = AddressEncoding.generateAddress(pubKey3); Bytes address3 = AddressEncoding.generateAddress(pubKey3);
UserAccount user3_0 = userset0.getUser(address3);
UserAccount user3_0 = userset0.getAccount(address3);
} }


public static LedgerInitProperties loadInitSetting_1() { public static LedgerInitProperties loadInitSetting_1() {


+ 2
- 2
source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java View File

@@ -282,7 +282,7 @@ public class LedgerPerformanceTest {
ConsoleUtils.info("\r\n\r\n================= 准备测试交易 [执行合约] ================="); ConsoleUtils.info("\r\n\r\n================= 准备测试交易 [执行合约] =================");


LedgerBlock latestBlock = ledger.getLatestBlock(); LedgerBlock latestBlock = ledger.getLatestBlock();
LedgerDataQuery previousDataSet = ledger.getDataSet(latestBlock);
LedgerDataQuery previousDataSet = ledger.getLedgerData(latestBlock);
LedgerEditor newEditor = ledger.createNextBlock(); LedgerEditor newEditor = ledger.createNextBlock();
TransactionBatchProcessor txProc = new TransactionBatchProcessor(DEFAULT_SECURITY_MANAGER, newEditor, TransactionBatchProcessor txProc = new TransactionBatchProcessor(DEFAULT_SECURITY_MANAGER, newEditor,
ledger, opHandler); ledger, opHandler);
@@ -315,7 +315,7 @@ public class LedgerPerformanceTest {
long batchStartTs = System.currentTimeMillis(); long batchStartTs = System.currentTimeMillis();
for (int i = 0; i < batchCount; i++) { for (int i = 0; i < batchCount; i++) {
LedgerBlock latestBlock = ledger.getLatestBlock(); LedgerBlock latestBlock = ledger.getLatestBlock();
LedgerDataQuery previousDataSet = ledger.getDataSet(latestBlock);
LedgerDataQuery previousDataSet = ledger.getLedgerData(latestBlock);
if (statistic) { if (statistic) {
ConsoleUtils.info("------ 开始执行交易, 即将生成区块[高度:%s] ------", (latestBlock.getHeight() + 1)); ConsoleUtils.info("------ 开始执行交易, 即将生成区块[高度:%s] ------", (latestBlock.getHeight() + 1));
} }


+ 3
- 3
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java View File

@@ -240,7 +240,7 @@ public class IntegrationBase {


if (keyPairType == KeyPairType.DATAACCOUNT) { if (keyPairType == KeyPairType.DATAACCOUNT) {
assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock()) assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
.getDataAccount(keyPair.getAddress()));
.getAccount(keyPair.getAddress()));
} }
System.out.printf("validKeyPair end %s \r\n", index); System.out.printf("validKeyPair end %s \r\n", index);
} }
@@ -264,7 +264,7 @@ public class IntegrationBase {


if (keyPairType == KeyPairType.DATAACCOUNT) { if (keyPairType == KeyPairType.DATAACCOUNT) {
assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock()) assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
.getDataAccount(keyPair.getAddress()));
.getAccount(keyPair.getAddress()));
} }
countDownLatch.countDown(); countDownLatch.countDown();
} }
@@ -527,7 +527,7 @@ public class IntegrationBase {


LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight()); LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight());
byte[] contractCodeInDb = ledgerRepository.getContractAccountSet(block) byte[] contractCodeInDb = ledgerRepository.getContractAccountSet(block)
.getContract(contractDeployKey.getAddress()).getChainCode();
.getAccount(contractDeployKey.getAddress()).getChainCode();
assertArrayEquals(contractCode, contractCodeInDb); assertArrayEquals(contractCode, contractCodeInDb);


// execute the contract; // execute the contract;


+ 2
- 2
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4Bftsmart.java View File

@@ -153,7 +153,7 @@ public class IntegrationTest4Bftsmart {


long participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); long participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount();


long userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotalCount();
long userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotal();


System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount);


@@ -164,7 +164,7 @@ public class IntegrationTest4Bftsmart {


participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount();


userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotalCount();
userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotal();


System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount);




+ 2
- 2
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4MQ.java View File

@@ -149,7 +149,7 @@ public class IntegrationTest4MQ {


long participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); long participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount();


long userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotalCount();
long userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotal();


System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); System.out.printf("before add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount);


@@ -160,7 +160,7 @@ public class IntegrationTest4MQ {


participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount(); participantCount = ledgerRepository.getAdminInfo(ledgerRepository.retrieveLatestBlock()).getParticipantCount();


userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotalCount();
userCount = ledgerRepository.getUserAccountSet(ledgerRepository.retrieveLatestBlock()).getTotal();


System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount); System.out.printf("after add participant: participantCount = %d, userCount = %d\r\n", (int)participantCount, (int)userCount);




+ 15
- 15
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java View File

@@ -214,21 +214,21 @@ public class IntegrationTestAll4Redis {
assertEquals(ledgerRepository.retrieveLatestBlockHeight(), txResp.getBlockHeight()); assertEquals(ledgerRepository.retrieveLatestBlockHeight(), txResp.getBlockHeight());


assertEquals("Value_A_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals("Value_A_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getBytes("A").getValue().toUTF8String());
.getAccount(dataKey.getAddress()).getBytes("A").getValue().toUTF8String());
assertEquals("Value_B_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals("Value_B_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getBytes("B").getValue().toUTF8String());
.getAccount(dataKey.getAddress()).getBytes("B").getValue().toUTF8String());
assertEquals("Value_C_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals("Value_C_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getBytes("C").getValue().toUTF8String());
.getAccount(dataKey.getAddress()).getBytes("C").getValue().toUTF8String());
assertEquals("Value_D_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals("Value_D_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getBytes("D").getValue().toUTF8String());
.getAccount(dataKey.getAddress()).getBytes("D").getValue().toUTF8String());
assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getDataVersion("A"));
.getAccount(dataKey.getAddress()).getDataVersion("A"));
assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getDataVersion("B"));
.getAccount(dataKey.getAddress()).getDataVersion("B"));
assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getDataVersion("C"));
.getAccount(dataKey.getAddress()).getDataVersion("C"));
assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock())
.getDataAccount(dataKey.getAddress()).getDataVersion("D"));
.getAccount(dataKey.getAddress()).getDataVersion("D"));


return; return;
} }
@@ -321,7 +321,7 @@ public class IntegrationTestAll4Redis {
assertEquals(txResp.getContentHash(), transactionHash); assertEquals(txResp.getContentHash(), transactionHash);
assertEquals(txResp.getBlockHash(), ledgerRepository.getLatestBlockHash()); assertEquals(txResp.getBlockHash(), ledgerRepository.getLatestBlockHash());
assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock()) assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
.getDataAccount(dataAccount.getAddress()));
.getAccount(dataAccount.getAddress()));


return dataAccount; return dataAccount;
} }
@@ -383,7 +383,7 @@ public class IntegrationTestAll4Redis {
txTpl.dataAccounts().register(contractDataKey.getIdentity()); txTpl.dataAccounts().register(contractDataKey.getIdentity());
// dataAccountSet.getDataAccount(dataAddress) // dataAccountSet.getDataAccount(dataAddress)
DataAccount dataAccount = ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock()) DataAccount dataAccount = ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
.getDataAccount(contractDataKey.getAddress());
.getAccount(contractDataKey.getAddress());


DataAccountKVSetOperation kvsetOP = txTpl.dataAccount(contractDataKey.getAddress()) DataAccountKVSetOperation kvsetOP = txTpl.dataAccount(contractDataKey.getAddress())
.setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1) .setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1)
@@ -407,7 +407,7 @@ public class IntegrationTestAll4Redis {


LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight()); LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight());
byte[] contractCodeInDb = ledgerRepository.getContractAccountSet(block) byte[] contractCodeInDb = ledgerRepository.getContractAccountSet(block)
.getContract(contractDeployKey.getAddress()).getChainCode();
.getAccount(contractDeployKey.getAddress()).getChainCode();
assertArrayEquals(contractCode, contractCodeInDb); assertArrayEquals(contractCode, contractCodeInDb);
txContentHash = ptx.getHash(); txContentHash = ptx.getHash();


@@ -449,9 +449,9 @@ public class IntegrationTestAll4Redis {
AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair(); AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair();
PubKey pubKey = key.getPubKey(); PubKey pubKey = key.getPubKey();
Bytes dataAddress = AddressEncoding.generateAddress(pubKey); Bytes dataAddress = AddressEncoding.generateAddress(pubKey);
assertEquals(dataAddress, dataAccountSet.getDataAccount(dataAddress).getAddress());
assertEquals(dataAddress, dataAccountSet.getAccount(dataAddress).getAddress());
assertEquals("hello", assertEquals("hello",
dataAccountSet.getDataAccount(dataAddress).getBytes(KEY_TOTAL, -1).getValue().toUTF8String());
dataAccountSet.getAccount(dataAddress).getBytes(KEY_TOTAL, -1).getValue().toUTF8String());


// 验证userAccount,从合约内部赋值,然后外部验证;内部定义动态key,外部不便于得到,临时屏蔽; // 验证userAccount,从合约内部赋值,然后外部验证;内部定义动态key,外部不便于得到,临时屏蔽;
// UserAccountSet userAccountSet = // UserAccountSet userAccountSet =
@@ -478,9 +478,9 @@ public class IntegrationTestAll4Redis {


// 验证结果; // 验证结果;
LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight()); LedgerBlock block = ledgerRepository.getBlock(txResp.getBlockHeight());
BytesValue val1InDb = ledgerRepository.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
BytesValue val1InDb = ledgerRepository.getDataAccountSet(block).getAccount(contractDataKey.getAddress())
.getBytes("A"); .getBytes("A");
BytesValue val2InDb = ledgerRepository.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
BytesValue val2InDb = ledgerRepository.getDataAccountSet(block).getAccount(contractDataKey.getAddress())
.getBytes(KEY_TOTAL); .getBytes(KEY_TOTAL);
assertEquals("Value_A_0", val1InDb.getValue().toUTF8String()); assertEquals("Value_A_0", val1InDb.getValue().toUTF8String());
assertEquals("total value,dataAccount", val2InDb.getValue().toUTF8String()); assertEquals("total value,dataAccount", val2InDb.getValue().toUTF8String());


+ 4
- 4
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java View File

@@ -151,22 +151,22 @@ public class LedgerInitializeTest {


PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]);
Bytes address0 = AddressEncoding.generateAddress(pubKey0); Bytes address0 = AddressEncoding.generateAddress(pubKey0);
UserAccount user0_0 = userset0.getUser(address0);
UserAccount user0_0 = userset0.getAccount(address0);
assertNotNull(user0_0); assertNotNull(user0_0);


PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]);
Bytes address1 = AddressEncoding.generateAddress(pubKey1); Bytes address1 = AddressEncoding.generateAddress(pubKey1);
UserAccount user1_0 = userset0.getUser(address1);
UserAccount user1_0 = userset0.getAccount(address1);
assertNotNull(user1_0); assertNotNull(user1_0);


PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]);
Bytes address2 = AddressEncoding.generateAddress(pubKey2); Bytes address2 = AddressEncoding.generateAddress(pubKey2);
UserAccount user2_0 = userset0.getUser(address2);
UserAccount user2_0 = userset0.getAccount(address2);
assertNotNull(user2_0); assertNotNull(user2_0);


PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]);
Bytes address3 = AddressEncoding.generateAddress(pubKey3); Bytes address3 = AddressEncoding.generateAddress(pubKey3);
UserAccount user3_0 = userset0.getUser(address3);
UserAccount user3_0 = userset0.getAccount(address3);
assertNotNull(user3_0); assertNotNull(user3_0);
} }




+ 4
- 4
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java View File

@@ -158,24 +158,24 @@ public class LedgerInitializeWeb4Nodes {
PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]); PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]);
Bytes address0 = AddressEncoding.generateAddress(pubKey0); Bytes address0 = AddressEncoding.generateAddress(pubKey0);
System.out.printf("localNodeAddress0 = %s \r\n", address0.toBase58()); System.out.printf("localNodeAddress0 = %s \r\n", address0.toBase58());
UserAccount user0_0 = userset0.getUser(address0);
UserAccount user0_0 = userset0.getAccount(address0);
assertNotNull(user0_0); assertNotNull(user0_0);


PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]); PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]);
Bytes address1 = AddressEncoding.generateAddress(pubKey1); Bytes address1 = AddressEncoding.generateAddress(pubKey1);
UserAccount user1_0 = userset0.getUser(address1);
UserAccount user1_0 = userset0.getAccount(address1);
assertNotNull(user1_0); assertNotNull(user1_0);
System.out.printf("localNodeAddress1 = %s \r\n", address1.toBase58()); System.out.printf("localNodeAddress1 = %s \r\n", address1.toBase58());


PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]); PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]);
Bytes address2 = AddressEncoding.generateAddress(pubKey2); Bytes address2 = AddressEncoding.generateAddress(pubKey2);
UserAccount user2_0 = userset0.getUser(address2);
UserAccount user2_0 = userset0.getAccount(address2);
assertNotNull(user2_0); assertNotNull(user2_0);
System.out.printf("localNodeAddress2 = %s \r\n", address2.toBase58()); System.out.printf("localNodeAddress2 = %s \r\n", address2.toBase58());


PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]); PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]);
Bytes address3 = AddressEncoding.generateAddress(pubKey3); Bytes address3 = AddressEncoding.generateAddress(pubKey3);
UserAccount user3_0 = userset0.getUser(address3);
UserAccount user3_0 = userset0.getAccount(address3);
assertNotNull(user3_0); assertNotNull(user3_0);
System.out.printf("localNodeAddress3 = %s \r\n", address3.toBase58()); System.out.printf("localNodeAddress3 = %s \r\n", address3.toBase58());




+ 1
- 1
source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java View File

@@ -77,7 +77,7 @@ public class LedgerBlockGeneratingTest {
LedgerBlock latestBlock = ledger.getLatestBlock(); LedgerBlock latestBlock = ledger.getLatestBlock();
assertEquals(height + i, latestBlock.getHeight()); assertEquals(height + i, latestBlock.getHeight());


LedgerDataQuery previousDataSet = ledger.getDataSet(latestBlock);
LedgerDataQuery previousDataSet = ledger.getLedgerData(latestBlock);
ConsoleUtils.info("------ 开始执行交易, 即将生成区块[%s] ------", (latestBlock.getHeight() + 1)); ConsoleUtils.info("------ 开始执行交易, 即将生成区块[%s] ------", (latestBlock.getHeight() + 1));
long startTs = System.currentTimeMillis(); long startTs = System.currentTimeMillis();




+ 114
- 7
source/test/test-ledger/src/test/java/test/com/jd/blockchain/test/ledger/RolesAuthorizationTest.java View File

@@ -9,6 +9,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;


import org.junit.Test; import org.junit.Test;
@@ -36,9 +37,12 @@ import com.jd.blockchain.ledger.TransactionBuilder;
import com.jd.blockchain.ledger.TransactionPermission; import com.jd.blockchain.ledger.TransactionPermission;
import com.jd.blockchain.ledger.TransactionRequest; import com.jd.blockchain.ledger.TransactionRequest;
import com.jd.blockchain.ledger.TransactionRequestBuilder; import com.jd.blockchain.ledger.TransactionRequestBuilder;
import com.jd.blockchain.ledger.TransactionResponse;
import com.jd.blockchain.ledger.TransactionState;
import com.jd.blockchain.ledger.UserAuthorizeOperation; import com.jd.blockchain.ledger.UserAuthorizeOperation;
import com.jd.blockchain.ledger.UserRegisterOperation; import com.jd.blockchain.ledger.UserRegisterOperation;
import com.jd.blockchain.ledger.UserRoles; import com.jd.blockchain.ledger.UserRoles;
import com.jd.blockchain.ledger.core.DataAccount;
import com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration; import com.jd.blockchain.ledger.core.DefaultOperationHandleRegisteration;
import com.jd.blockchain.ledger.core.LedgerInitializer; import com.jd.blockchain.ledger.core.LedgerInitializer;
import com.jd.blockchain.ledger.core.LedgerManager; import com.jd.blockchain.ledger.core.LedgerManager;
@@ -46,6 +50,7 @@ import com.jd.blockchain.ledger.core.LedgerQuery;
import com.jd.blockchain.ledger.core.LedgerRepository; import com.jd.blockchain.ledger.core.LedgerRepository;
import com.jd.blockchain.ledger.core.OperationHandleRegisteration; import com.jd.blockchain.ledger.core.OperationHandleRegisteration;
import com.jd.blockchain.ledger.core.TransactionBatchProcessor; import com.jd.blockchain.ledger.core.TransactionBatchProcessor;
import com.jd.blockchain.ledger.core.UserAccount;
import com.jd.blockchain.service.TransactionBatchResult; import com.jd.blockchain.service.TransactionBatchResult;
import com.jd.blockchain.service.TransactionBatchResultHandle; import com.jd.blockchain.service.TransactionBatchResultHandle;
import com.jd.blockchain.storage.service.KVStorageService; import com.jd.blockchain.storage.service.KVStorageService;
@@ -79,6 +84,8 @@ public class RolesAuthorizationTest {
private static final BlockchainKeypair DEFAULT_USER; private static final BlockchainKeypair DEFAULT_USER;
private static final BlockchainKeypair GUEST_USER; private static final BlockchainKeypair GUEST_USER;


// 预置的新普通用户;
private static final BlockchainKeypair NEW_USER = BlockchainKeyGenerator.getInstance().generate();
// 预置的数据账户; // 预置的数据账户;
private static final BlockchainIdentity DATA_ACCOUNT_ID = BlockchainKeyGenerator.getInstance().generate() private static final BlockchainIdentity DATA_ACCOUNT_ID = BlockchainKeyGenerator.getInstance().generate()
.getIdentity(); .getIdentity();
@@ -107,24 +114,124 @@ public class RolesAuthorizationTest {
public void test() { public void test() {
MemoryKVStorage storage = new MemoryKVStorage(); MemoryKVStorage storage = new MemoryKVStorage();
LedgerBlock genesisBlock = initLedger(storage); LedgerBlock genesisBlock = initLedger(storage);
final HashDigest ledgerHash = genesisBlock.getHash();


LedgerManager ledgerManager = new LedgerManager(); LedgerManager ledgerManager = new LedgerManager();
LedgerRepository ledger = ledgerManager.register(genesisBlock.getHash(), storage);
LedgerRepository ledger = ledgerManager.register(ledgerHash, storage);


// 验证角色和用户的权限配置; // 验证角色和用户的权限配置;
assertUserRolesPermissions(ledger); assertUserRolesPermissions(ledger);


// 预置数据;
TransactionRequest tx = buildRequest(ledger.getHash(), ADMIN_USER, ADMIN_USER, new TransactionDefiner() {
// 预置数据:准备一个新用户和数据账户;
TransactionRequest predefinedTx = buildRequest(ledger.getHash(), ADMIN_USER, ADMIN_USER,
new TransactionDefiner() {
@Override
public void define(TransactionBuilder txBuilder) {
txBuilder.security().roles().configure("NORMAL")
.enable(LedgerPermission.REGISTER_DATA_ACCOUNT)
.disable(LedgerPermission.REGISTER_USER)
.enable(TransactionPermission.CONTRACT_OPERATION);

txBuilder.users().register(NEW_USER.getIdentity());

txBuilder.security().authorziations().forUser(NEW_USER.getAddress()).authorize("NORMAL");

txBuilder.dataAccounts().register(DATA_ACCOUNT_ID);
}
});

TransactionBatchResult procResult = executeTransactions(ledger, predefinedTx);

//断言预定义数据的交易和区块成功;
assertBlock(1, procResult);
assertTransactionAllSuccess(procResult);

//断言预定义的数据符合预期;
assertPredefineData(ledgerHash, storage);

// 用不具备“注册用户”权限的用户,注册另一个新用户,预期交易失败;
BlockchainKeypair tempUser = BlockchainKeyGenerator.getInstance().generate();
TransactionRequest tx = buildRequest(ledger.getHash(), NEW_USER, ADMIN_USER, new TransactionDefiner() {
@Override @Override
public void define(TransactionBuilder txBuilder) { public void define(TransactionBuilder txBuilder) {
txBuilder.dataAccounts().register(DATA_ACCOUNT_ID);
txBuilder.users().register(tempUser.getIdentity());
} }
}); });


TransactionBatchResult procResult = executeTransactions(ledger, tx);
assertEquals(1, procResult.getBlock().getHeight());
procResult = executeTransactions(ledger, tx);
assertBlock(2, procResult);
assertTransactionAllFail(procResult, TransactionState.REJECTED_BY_SECURITY_POLICY);
}

/**
* 断言区块高度;
*
* @param blockHeight
* @param procResult
*/
private void assertBlock(long blockHeight, TransactionBatchResult procResult) {
assertEquals(blockHeight, procResult.getBlock().getHeight());
}


/**
* 断言全部交易结果都是成功的;
*
* @param procResult
*/
private void assertTransactionAllSuccess(TransactionBatchResult procResult) {

Iterator<TransactionResponse> responses = procResult.getResponses();
while (responses.hasNext()) {
TransactionResponse transactionResponse = (TransactionResponse) responses.next();

assertEquals(true, transactionResponse.isSuccess());
assertEquals(TransactionState.SUCCESS, transactionResponse.getExecutionState());
assertEquals(procResult.getBlock().getHash(), transactionResponse.getBlockHash());
assertEquals(procResult.getBlock().getHeight(), transactionResponse.getBlockHeight());
}
}
/**
* 断言全部交易结果都是失败的;
*
* @param procResult
*/
private void assertTransactionAllFail(TransactionBatchResult procResult, TransactionState txState) {
Iterator<TransactionResponse> responses = procResult.getResponses();
while (responses.hasNext()) {
TransactionResponse transactionResponse = (TransactionResponse) responses.next();
assertEquals(false, transactionResponse.isSuccess());
assertEquals(txState, transactionResponse.getExecutionState());
}
}

/**
* 断言预定义的数据符合预期;
*
* @param ledgerHash
* @param storage
*/
private void assertPredefineData(HashDigest ledgerHash, MemoryKVStorage storage) {
LedgerManager ledgerManager = new LedgerManager();
LedgerRepository ledger = ledgerManager.register(ledgerHash, storage);
UserAccount newUser = ledger.getUserAccountSet().getAccount(NEW_USER.getAddress());
assertNotNull(newUser);
DataAccount dataAccount = ledger.getDataAccountSet().getAccount(DATA_ACCOUNT_ID.getAddress());
assertNotNull(dataAccount);

UserRoles userRoles = ledger.getAdminSettings().getAuthorizations().getUserRoles(NEW_USER.getAddress());
assertNotNull(userRoles);
assertEquals(1, userRoles.getRoleCount());
assertEquals("NORMAL", userRoles.getRoles()[0]);

RolePrivileges normalRole = ledger.getAdminSettings().getRolePrivileges().getRolePrivilege("NORMAL");
assertNotNull(normalRole);
assertEquals(true, normalRole.getLedgerPrivilege().isEnable(LedgerPermission.REGISTER_DATA_ACCOUNT));
assertEquals(false, normalRole.getLedgerPrivilege().isEnable(LedgerPermission.REGISTER_USER));
assertEquals(true, normalRole.getTransactionPrivilege().isEnable(TransactionPermission.CONTRACT_OPERATION));
assertEquals(false, normalRole.getTransactionPrivilege().isEnable(TransactionPermission.DIRECT_OPERATION));
} }


private TransactionBatchResult executeTransactions(LedgerRepository ledger, TransactionRequest... transactions) { private TransactionBatchResult executeTransactions(LedgerRepository ledger, TransactionRequest... transactions) {
@@ -192,7 +299,7 @@ public class RolesAuthorizationTest {
if (roles == null) { if (roles == null) {
roles = new String[0]; roles = new String[0];
} }
UserRoles userRoles = ledger.getAdminSettings().getUserRoles().getUserRoles(address);
UserRoles userRoles = ledger.getAdminSettings().getAuthorizations().getUserRoles(address);
assertNotNull(userRoles); assertNotNull(userRoles);
assertEquals(policy, userRoles.getPolicy()); assertEquals(policy, userRoles.getPolicy());




+ 1
- 1
source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java View File

@@ -440,7 +440,7 @@ public class MockerNodeContext implements BlockchainQueryService {
public OperationResult[] txProcess(TransactionRequest txRequest) { public OperationResult[] txProcess(TransactionRequest txRequest) {
LedgerEditor newEditor = ledgerRepository.createNextBlock(); LedgerEditor newEditor = ledgerRepository.createNextBlock();
LedgerBlock latestBlock = ledgerRepository.getLatestBlock(); LedgerBlock latestBlock = ledgerRepository.getLatestBlock();
LedgerDataQuery previousDataSet = ledgerRepository.getDataSet(latestBlock);
LedgerDataQuery previousDataSet = ledgerRepository.getLedgerData(latestBlock);
TransactionBatchProcessor txProc = new TransactionBatchProcessor(getSecurityManager(), newEditor, TransactionBatchProcessor txProc = new TransactionBatchProcessor(getSecurityManager(), newEditor,
ledgerRepository, opHandler); ledgerRepository, opHandler);
TransactionResponse txResp = txProc.schedule(txRequest); TransactionResponse txResp = txProc.schedule(txRequest);


Loading…
Cancel
Save