Browse Source

Refactored ledger core;

tags/1.1.0
huanghaiquan 5 years ago
parent
commit
00e07f79ec
37 changed files with 352 additions and 409 deletions
  1. +31
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/AccountQuery.java
  2. +1
    -25
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountQuery.java
  3. +19
    -21
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccountSet.java
  4. +1
    -28
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountQuery.java
  5. +16
    -6
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccountSet.java
  6. +52
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyAccountSet.java
  7. +6
    -110
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/EmptyLedgerDataset.java
  8. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerInitializer.java
  9. +20
    -12
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQuery.java
  10. +30
    -30
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java
  11. +6
    -6
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerRepositoryImpl.java
  12. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerTransactionContext.java
  13. +2
    -2
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionBatchProcessor.java
  14. +24
    -0
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionQuery.java
  15. +9
    -5
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/TransactionSet.java
  16. +1
    -27
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountQuery.java
  17. +7
    -7
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccountSet.java
  18. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/AbtractContractEventSendOperationHandle.java
  19. +1
    -1
      source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/handles/DataAccountKVSetOperationHandle.java
  20. +12
    -12
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java
  21. +21
    -21
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java
  22. +2
    -1
      source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java
  23. +1
    -6
      source/ledger/ledger-model/src/main/java/com/jd/blockchain/contract/EventHandle.java
  24. +31
    -31
      source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java
  25. +9
    -9
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java
  26. +4
    -4
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeTest.java
  27. +4
    -4
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerInitializeWebTest.java
  28. +2
    -2
      source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java
  29. +3
    -3
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java
  30. +2
    -2
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4Bftsmart.java
  31. +2
    -2
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTest4MQ.java
  32. +15
    -15
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java
  33. +4
    -4
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeTest.java
  34. +4
    -4
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/initializer/LedgerInitializeWeb4Nodes.java
  35. +1
    -1
      source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/ledger/LedgerBlockGeneratingTest.java
  36. +4
    -3
      source/test/test-ledger/src/test/java/test/com/jd/blockchain/test/ledger/RolesAuthorizationTest.java
  37. +1
    -1
      source/tools/tools-mocker/src/main/java/com/jd/blockchain/mocker/MockerNodeContext.java

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

}

+ 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> {


} }

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

@@ -11,7 +11,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 ContractAccountSet implements MerkleProvable, Transactional, ContractAccountQuery {
public class ContractAccountSet implements Transactional, ContractAccountQuery {
private AccountSet accountSet; private AccountSet accountSet;
@@ -27,8 +27,8 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex,count);
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getAccounts(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,7 +50,7 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
* @return * @return
*/ */
@Override @Override
public long getTotalCount() {
public long getTotal() {
return accountSet.getTotalCount(); return accountSet.getTotalCount();
} }
@@ -65,13 +65,18 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
} }
@Override @Override
public ContractAccount getContract(Bytes address) {
public ContractAccount getAccount(Bytes address) {
BaseAccount accBase = accountSet.getAccount(address); BaseAccount accBase = accountSet.getAccount(address);
return new ContractAccount(accBase); return new ContractAccount(accBase);
} }
@Override @Override
public ContractAccount getContract(Bytes address, long version) {
public ContractAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
}
@Override
public ContractAccount getAccount(Bytes address, long version) {
BaseAccount accBase = accountSet.getAccount(address, version); BaseAccount accBase = accountSet.getAccount(address, version);
return new ContractAccount(accBase); return new ContractAccount(accBase);
} }
@@ -79,14 +84,10 @@ public class ContractAccountSet implements MerkleProvable, Transactional, Contra
/** /**
* 部署一项新的合约链码; * 部署一项新的合约链码;
* *
* @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) {
@@ -100,12 +101,9 @@ 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) {


+ 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> {


} }

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

@@ -11,7 +11,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 DataAccountSet implements MerkleProvable, Transactional, DataAccountQuery {
public class DataAccountSet implements Transactional, DataAccountQuery {
private AccountSet accountSet; private AccountSet accountSet;
@@ -27,7 +27,7 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex, count); return accountSet.getAccounts(fromIndex, count);
} }
@@ -38,17 +38,22 @@ 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() {
public long getTotal() {
return accountSet.getTotalCount(); return accountSet.getTotalCount();
} }
@Override
public boolean contains(Bytes address) {
return accountSet.contains(address);
}
/** /**
* 返回账户的存在性证明; * 返回账户的存在性证明;
*/ */
@@ -63,6 +68,11 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
return new DataAccount(accBase); return new DataAccount(accBase);
} }
@Override
public DataAccount getAccount(String address) {
return getAccount(Bytes.fromBase58(address));
}
/** /**
* 返回数据账户; <br> * 返回数据账户; <br>
* 如果不存在,则返回 null; * 如果不存在,则返回 null;
@@ -71,7 +81,7 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
* @return * @return
*/ */
@Override @Override
public DataAccount getDataAccount(Bytes address) {
public DataAccount getAccount(Bytes address) {
BaseAccount accBase = accountSet.getAccount(address); BaseAccount accBase = accountSet.getAccount(address);
if (accBase == null) { if (accBase == null) {
return null; return null;
@@ -80,7 +90,7 @@ public class DataAccountSet implements MerkleProvable, Transactional, DataAccoun
} }
@Override @Override
public DataAccount getDataAccount(Bytes address, long version) {
public DataAccount getAccount(Bytes address, long version) {
BaseAccount accBase = accountSet.getAccount(address, version); BaseAccount 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/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;
} }




+ 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();


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


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

@@ -79,7 +79,7 @@ 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().getAuthorizations(), previousAdminDataset.getParticipantDataset(), previousAdminDataset.getAdminInfo().getAuthorizations(), previousAdminDataset.getParticipantDataset(),
@@ -93,7 +93,7 @@ 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(


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


+ 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> {


} }

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

@@ -15,7 +15,7 @@ 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 AccountSet accountSet;
@@ -32,7 +32,7 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
} }
@Override @Override
public AccountHeader[] getAccounts(int fromIndex, int count) {
public AccountHeader[] getHeaders(int fromIndex, int count) {
return accountSet.getAccounts(fromIndex,count); return accountSet.getAccounts(fromIndex,count);
} }
@@ -42,7 +42,7 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
* @return * @return
*/ */
@Override @Override
public long getTotalCount() {
public long getTotal() {
return accountSet.getTotalCount(); return accountSet.getTotalCount();
} }
@@ -65,12 +65,12 @@ 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) {
public UserAccount getAccount(Bytes address) {
BaseAccount baseAccount = accountSet.getAccount(address); BaseAccount baseAccount = accountSet.getAccount(address);
return new UserAccount(baseAccount); return new UserAccount(baseAccount);
} }
@@ -81,7 +81,7 @@ public class UserAccountSet implements Transactional, MerkleProvable, UserAccoun
} }
@Override @Override
public UserAccount getUser(Bytes address, long version) {
public UserAccount getAccount(Bytes address, long version) {
BaseAccount baseAccount = accountSet.getAccount(address, version); BaseAccount baseAccount = accountSet.getAccount(address, version);
return new UserAccount(baseAccount); return new UserAccount(baseAccount);
} }


+ 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!");
} }


+ 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();


+ 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 {


+ 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]);
} }


} }

+ 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();




+ 4
- 3
source/test/test-ledger/src/test/java/test/com/jd/blockchain/test/ledger/RolesAuthorizationTest.java View File

@@ -127,7 +127,8 @@ public class RolesAuthorizationTest {
new TransactionDefiner() { new TransactionDefiner() {
@Override @Override
public void define(TransactionBuilder txBuilder) { public void define(TransactionBuilder txBuilder) {
txBuilder.security().roles().configure("NORMAL").enable(LedgerPermission.REGISTER_DATA_ACCOUNT)
txBuilder.security().roles().configure("NORMAL")
.enable(LedgerPermission.REGISTER_DATA_ACCOUNT)
.disable(LedgerPermission.REGISTER_USER) .disable(LedgerPermission.REGISTER_USER)
.enable(TransactionPermission.CONTRACT_OPERATION); .enable(TransactionPermission.CONTRACT_OPERATION);


@@ -215,9 +216,9 @@ public class RolesAuthorizationTest {
private void assertPredefineData(HashDigest ledgerHash, MemoryKVStorage storage) { private void assertPredefineData(HashDigest ledgerHash, MemoryKVStorage storage) {
LedgerManager ledgerManager = new LedgerManager(); LedgerManager ledgerManager = new LedgerManager();
LedgerRepository ledger = ledgerManager.register(ledgerHash, storage); LedgerRepository ledger = ledgerManager.register(ledgerHash, storage);
UserAccount newUser = ledger.getUserAccountSet().getUser(NEW_USER.getAddress());
UserAccount newUser = ledger.getUserAccountSet().getAccount(NEW_USER.getAddress());
assertNotNull(newUser); assertNotNull(newUser);
DataAccount dataAccount = ledger.getDataAccountSet().getDataAccount(DATA_ACCOUNT_ID.getAddress());
DataAccount dataAccount = ledger.getDataAccountSet().getAccount(DATA_ACCOUNT_ID.getAddress());
assertNotNull(dataAccount); assertNotNull(dataAccount);


UserRoles userRoles = ledger.getAdminSettings().getAuthorizations().getUserRoles(NEW_USER.getAddress()); UserRoles userRoles = ledger.getAdminSettings().getAuthorizations().getUserRoles(NEW_USER.getAddress());


+ 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