From ae9d4aaa7b3904d42d9bc9814df0acc81903cb34 Mon Sep 17 00:00:00 2001 From: huanghaiquan Date: Thu, 24 Oct 2019 11:34:49 +0800 Subject: [PATCH] Refactored MerkleAccount; --- .../ledger/core/ContractAccount.java | 4 +- .../ledger/core/LedgerQueryService.java | 5 +- .../blockchain/ledger/core/MerkleAccount.java | 103 +++++++----------- .../ledger/core/MerkleAccountSet.java | 25 +++-- .../blockchain/ledger/core/UserAccount.java | 6 +- .../ledger/core/ContractInvokingTest.java | 16 +-- .../ledger/core/LedgerEditorTest.java | 2 +- .../core/TransactionBatchProcessorTest.java | 12 +- .../ledger/core/TransactionSetTest.java | 4 +- .../com/jd/blockchain/ledger/BytesValue.java | 2 +- .../jd/blockchain/ledger/KVDataObject.java | 28 ++--- .../com/jd/blockchain/ledger/TypedValue.java | 6 +- .../resolver/AbstractBytesValueResolver.java | 2 +- .../ledger/BytesToBytesValueResolverTest.java | 2 +- .../ledger/BytesValueEncodingTest.java | 4 +- .../DataAccountKVSetOpTemplateTest.java | 2 +- .../IntegerToBytesValueResolverTest.java | 6 +- .../com/jd/blockchain/ledger/KVDataTest.java | 2 +- .../ledger/LongToBytesValueResolverTest.java | 6 +- .../ledger/ShortToBytesValueResolverTest.java | 2 +- .../StringToBytesValueResolverTest.java | 4 +- .../blockchain/ledger/TxContentBlobTest.java | 8 +- .../peer/web/LedgerQueryController.java | 16 +-- .../sdk/converters/ClientResolveUtil.java | 2 +- .../intgr/IntegrationTestAll4Redis.java | 14 +-- .../java/com/jd/blockchain/utils/Dataset.java | 22 ---- 26 files changed, 136 insertions(+), 169 deletions(-) diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java index b0f8104d..0d288d7b 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java @@ -40,11 +40,11 @@ public class ContractAccount extends AccountDecorator implements ContractInfo { } public byte[] getChainCode() { - return getHeaders().getValue(CHAIN_CODE_KEY).getValue().toBytes(); + return getHeaders().getValue(CHAIN_CODE_KEY).getBytes().toBytes(); } public byte[] getChainCode(long version) { - return getHeaders().getValue(CHAIN_CODE_KEY, version).getValue().toBytes(); + return getHeaders().getValue(CHAIN_CODE_KEY, version).getBytes().toBytes(); } public long getChaincodeVersion() { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java index b965f842..2c9e92de 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerQueryService.java @@ -5,7 +5,6 @@ import java.util.List; import com.jd.blockchain.contract.ContractException; import com.jd.blockchain.crypto.HashDigest; -import com.jd.blockchain.ledger.AccountHeader; import com.jd.blockchain.ledger.BlockchainIdentity; import com.jd.blockchain.ledger.BytesValue; import com.jd.blockchain.ledger.ContractInfo; @@ -293,12 +292,12 @@ public class LedgerQueryService implements BlockchainQueryService { for (int i = 0; i < entries.length; i++) { final String currKey = keys[i]; - ver = dataAccount == null ? -1 : dataAccount.getDataset().getVersion(Bytes.fromString(currKey)); + ver = dataAccount == null ? -1 : dataAccount.getDataset().getVersion(currKey); if (ver < 0) { entries[i] = new KVDataObject(currKey, -1, null); } else { - BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(currKey), ver); + BytesValue value = dataAccount.getDataset().getValue(currKey, ver); entries[i] = new KVDataObject(currKey, ver, value); } } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java index 384b39bd..6b59dacc 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccount.java @@ -49,68 +49,60 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho private Dataset typedData; - private long version; +// private long version; /** - * Create a new Account with the specified address and pubkey;
+ * Create a new Account with the specified identity(address and pubkey);
* * At the same time, a empty merkle dataset is also created for this account, * which is used for storing data of this account.
+ * + * This new account will be writable.
* - * Note that, the blockchain identity of the account is not stored in the - * account's merkle dataset, but is stored by the outer invoker; - * - * @param accountID 身份; - * @param cryptoSetting 密码参数; - * @param keyPrefix 数据前缀; - * @param exStorage - * @param verStorage + * @param accountID Identity of this new account; + * @param cryptoSetting Settings about crypto operations; + * @param keyPrefix Prefix of all keys in this account's dataset; + * @param exStorage The base storage for existance operation; + * @param verStorage The base storage for versioning operation; */ public MerkleAccount(BlockchainIdentity accountID, CryptoSetting cryptoSetting, Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { - this(accountID.getAddress(), accountID.getPubKey(), -1, null, cryptoSetting, keyPrefix, exStorage, verStorage, - false); + // 初始化数据集; + initializeDatasets(null, cryptoSetting, keyPrefix, exStorage, verStorage, false); initPubKey(accountID.getPubKey()); + this.accountID = accountID; } /** - * Create a account instance with the specified address and pubkey and load it's + * Create a account instance with the specified address and root hash; load it's * merkle dataset from the specified root hash. This merkle dateset is used for * storing data of this account.
* - * @param accountID identity of this account; - * @param version - * @param dataRootHash merkle root hash of account's data; if set to a null - * value, an empty merkle dataset is created; - * @param cryptoSetting - * @param keyPrefix - * @param exStorage - * @param verStorage - * @param readonly + * @param address Address of this account; + * @param rootHash Merkle root hash of this account; It can not be null; + * @param cryptoSetting Settings about crypto operations; + * @param keyPrefix Prefix of all keys in this account's dataset; + * @param exStorage The base storage for existance operation; + * @param verStorage The base storage for versioning operation; + * @param readonly Readonly about this account's dataset; */ - public MerkleAccount(Bytes address, long version, HashDigest dataRootHash, CryptoSetting cryptoSetting, - Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { - this(address, null, version, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); - } + public MerkleAccount(Bytes address, HashDigest rootHash, CryptoSetting cryptoSetting, Bytes keyPrefix, + ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { + if (rootHash == null) { + throw new IllegalArgumentException("Specified a null root hash for account[" + address.toBase58() + "]!"); + } - /** - * 内部构造器; - * - * @param address 账户地址; - * @param pubKey 账户公钥; 如果为空,则会进行加载验证; - * @param version 账户版本; - * @param rootHash 账户根哈希; - * @param cryptoSetting 密码参数设置; - * @param keyPrefix 当前账户的 Key 前缀; - * @param exStorage 单键存储服务; - * @param verStorage 多版本存储服务; - * @param readonly 是否只读; - */ - private MerkleAccount(Bytes address, PubKey pubKey, long version, HashDigest rootHash, CryptoSetting cryptoSetting, - Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { - this.version = version; + // 初始化数据集; + initializeDatasets(rootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); + + // 初始化账户的身份; + PubKey pubKey = loadPubKey(); + this.accountID = new AccountID(address, pubKey); + } + private void initializeDatasets(HashDigest rootHash, CryptoSetting cryptoSetting, Bytes keyPrefix, + ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { // 加载“根数据集” this.rootDataset = new MerkleDataSet(rootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); @@ -148,15 +140,6 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho Bytes dataPrefix = keyPrefix.concat(DATA_PREFIX); this.dataDataset = new MerkleDataSet(dataRoot, cryptoSetting, dataPrefix, exStorage, verStorage, readonly); this.typedData = DatasetHelper.listen(DatasetHelper.map(dataDataset, valueMapper), dataChangedListener); - - // 初始化账户的身份; - if (pubKey == null) { - if (version < 0) { - throw new IllegalArgumentException("Specified a null PubKey for newly Account!"); - } - pubKey = loadPubKey(); - } - this.accountID = new AccountID(address, pubKey); } private HashDigest loadHeaderRoot() { @@ -258,6 +241,9 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho */ private PubKey loadPubKey() { TypedValue value = typedHeader.getValue(KEY_PUBKEY); + if (value == null) { + return null; + } return value.pubKeyValue(); } @@ -276,12 +262,10 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho * * 此方法默认会返回新的账户版本号,等于当前版本号加 1 ; * - * @param newRootHash - * @param currentVersion - * @return + * @param previousRootHash 提交前的根哈希;如果是新账户的首次提交,则为 null; + * @param newRootHash 新的根哈希; */ - protected long onCommited(HashDigest newRootHash, long currentVersion) { - return currentVersion + 1; + protected void onCommited(HashDigest previousRootHash, HashDigest newRootHash) { } @Override @@ -303,8 +287,9 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho } if (rootDataset.isUpdated()) { + HashDigest previousRootHash = rootDataset.getRootHash(); rootDataset.commit(); - this.version = onCommited(rootDataset.getRootHash(), version); + onCommited(previousRootHash, rootDataset.getRootHash()); } } @@ -340,10 +325,6 @@ public class MerkleAccount implements LedgerAccount, HashProvable, MerkleSnapsho } - public long getVersion() { - return version; - } - // private static class MerkleDatasetAdapter implements Dataset { // // private static DataChangedListener NULL_LISTENER = new DataChangedListener() { diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java index 6952c89e..73696c27 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/MerkleAccountSet.java @@ -94,7 +94,8 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ BlockchainIdentity[] ids = new BlockchainIdentity[results.length]; for (int i = 0; i < results.length; i++) { - InnerMerkleAccount account = createAccount(results[i].getKey(), new HashDigest(results[i].getValue()), results[i].getVersion(), true); + InnerMerkleAccount account = createAccount(results[i].getKey(), new HashDigest(results[i].getValue()), + results[i].getVersion(), true); ids[i] = account.getID(); } return ids; @@ -284,11 +285,11 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ return createAccount(address, rootHash, version, readonly); } - - private InnerMerkleAccount createAccount(Bytes address,HashDigest rootHash, long version, boolean readonly) { + + private InnerMerkleAccount createAccount(Bytes address, HashDigest rootHash, long version, boolean readonly) { // prefix; Bytes prefix = keyPrefix.concat(address); - + return new InnerMerkleAccount(address, version, rootHash, cryptoSetting, prefix, baseExStorage, baseVerStorage, readonly); } @@ -358,14 +359,18 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ */ private class InnerMerkleAccount extends MerkleAccount { + private long version; + public InnerMerkleAccount(BlockchainIdentity accountID, CryptoSetting cryptoSetting, Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage) { super(accountID, cryptoSetting, keyPrefix, exStorage, verStorage); + this.version = -1; } public InnerMerkleAccount(Bytes address, long version, HashDigest dataRootHash, CryptoSetting cryptoSetting, Bytes keyPrefix, ExPolicyKVStorage exStorage, VersioningKVStorage verStorage, boolean readonly) { - super(address, version, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); + super(address, dataRootHash, cryptoSetting, keyPrefix, exStorage, verStorage, readonly); + this.version = version; } @Override @@ -374,13 +379,17 @@ public class MerkleAccountSet implements Transactional, MerkleProvable, AccountQ } @Override - protected long onCommited(HashDigest newRootHash, long currentVersion) { - long newVersion = merkleDataset.setValue(this.getAddress(), newRootHash.toBytes(), currentVersion); + protected void onCommited(HashDigest previousRootHash, HashDigest newRootHash) { + long newVersion = merkleDataset.setValue(this.getAddress(), newRootHash.toBytes(), version); if (newVersion < 0) { // Update fail; throw new LedgerException("Account updating fail! --[Address=" + this.getAddress() + "]"); } - return newVersion; + this.version = newVersion; + } + + public long getVersion() { + return version; } } diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java index df3231c4..1ac4b4fe 100644 --- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java +++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java @@ -43,7 +43,7 @@ public class UserAccount extends AccountDecorator implements UserInfo { // imple if (pkBytes == null) { return null; } - dataPubKey = new PubKey(pkBytes.getValue().toBytes()); + dataPubKey = new PubKey(pkBytes.getBytes().toBytes()); } return dataPubKey; } @@ -69,12 +69,12 @@ public class UserAccount extends AccountDecorator implements UserInfo { // imple public String getProperty(String key) { BytesValue value = getHeaders().getValue(encodePropertyKey(key)); - return value == null ? null : value.getValue().toUTF8String(); + return value == null ? null : value.getBytes().toUTF8String(); } public String getProperty(String key, long version) { BytesValue value = getHeaders().getValue(encodePropertyKey(key), version); - return value == null ? null : value.getValue().toUTF8String(); + return value == null ? null : value.getBytes().toUTF8String(); } private String encodePropertyKey(String key) { diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java index 4af4c707..14e29d65 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java @@ -27,7 +27,6 @@ import com.jd.blockchain.ledger.BlockchainKeypair; import com.jd.blockchain.ledger.BytesValue; import com.jd.blockchain.ledger.DataAccountRegisterOperation; import com.jd.blockchain.ledger.EndpointRequest; -import com.jd.blockchain.ledger.KVDataEntry; import com.jd.blockchain.ledger.LedgerBlock; import com.jd.blockchain.ledger.LedgerInitSetting; import com.jd.blockchain.ledger.LedgerPermission; @@ -65,6 +64,7 @@ import com.jd.blockchain.storage.service.utils.MemoryKVStorage; import com.jd.blockchain.transaction.BooleanValueHolder; import com.jd.blockchain.transaction.TxBuilder; import com.jd.blockchain.utils.Bytes; +import com.jd.blockchain.utils.DataEntry; import com.jd.blockchain.utils.io.BytesUtils; import test.com.jd.blockchain.ledger.TxTestContract; @@ -243,7 +243,7 @@ public class ContractInvokingTest { BytesValue latestValue = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getValue(key, -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.getBytes().toUTF8String()); boolean readable = readableHolder.get(); assertTrue(readable); @@ -301,9 +301,9 @@ public class ContractInvokingTest { } }); // 预期数据都能够正常写入; - KVDataEntry kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", + DataEntry kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 0); - KVDataEntry kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K2", + DataEntry kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K2", 0); assertEquals(0, kv1.getVersion()); assertEquals(0, kv2.getVersion()); @@ -322,8 +322,8 @@ public class ContractInvokingTest { } }); // 预期数据都能够正常写入; - kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1); - kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K2", 1); + kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 1); + kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K2", 1); assertEquals(1, kv1.getVersion()); assertEquals(1, kv2.getVersion()); assertEquals("V1-1", kv1.getValue()); @@ -341,10 +341,10 @@ public class ContractInvokingTest { } }); // 预期数据都能够正常写入; - kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 1); + kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 1); assertEquals(1, kv1.getVersion()); assertEquals("V1-1", kv1.getValue()); - kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataEntry("K1", 2); + kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 2); assertEquals(-1, kv1.getVersion()); assertEquals(null, kv1.getValue()); diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerEditorTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerEditorTest.java index 0bd470a7..78f04762 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerEditorTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/LedgerEditorTest.java @@ -109,7 +109,7 @@ public class LedgerEditorTest { // 验证数据读写的一致性; BytesValue bytes = dataAccount.getDataset().getValue("A"); assertEquals(DataType.TEXT, bytes.getType()); - String textValue = bytes.getValue().toUTF8String(); + String textValue = bytes.getBytes().toUTF8String(); assertEquals("abc", textValue); } diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java index e1442bc3..a9f09845 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionBatchProcessorTest.java @@ -346,10 +346,10 @@ public class TransactionBatchProcessorTest { assertNotNull(v2); assertNotNull(v3); - assertEquals("V-1-1", v1_0.getValue().toUTF8String()); - assertEquals("V-1-2", v1_1.getValue().toUTF8String()); - assertEquals("V-2-1", v2.getValue().toUTF8String()); - assertEquals("V-3-1", v3.getValue().toUTF8String()); + assertEquals("V-1-1", v1_0.getBytes().toUTF8String()); + assertEquals("V-1-2", v1_1.getBytes().toUTF8String()); + assertEquals("V-2-1", v2.getBytes().toUTF8String()); + assertEquals("V-3-1", v3.getBytes().toUTF8String()); // 提交多笔数据写入的交易,包含存在数据版本冲突的交易,验证交易是否正确回滚; // 先写一笔正确的交易; k3 的版本将变为 1 ; @@ -390,8 +390,8 @@ public class TransactionBatchProcessorTest { assertNotNull(v1); assertNotNull(v3); - assertEquals("V-1-2", v1.getValue().toUTF8String()); - assertEquals("V-3-2", v3.getValue().toUTF8String()); + assertEquals("V-1-2", v1.getBytes().toUTF8String()); + assertEquals("V-3-2", v3.getBytes().toUTF8String()); // // 验证正确性; // ledgerManager = new LedgerManager(); diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java index cd5ebc9f..63ee3e64 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/TransactionSetTest.java @@ -164,8 +164,8 @@ public class TransactionSetTest { for (int i = 0; i < acutualKVWriteSet.length; i++) { assertEquals(expKVWriteSet[i].getKey(), acutualKVWriteSet[i].getKey()); assertEquals(expKVWriteSet[i].getExpectedVersion(), acutualKVWriteSet[i].getExpectedVersion()); - assertTrue(BytesUtils.equals(expKVWriteSet[i].getValue().getValue().toBytes(), - acutualKVWriteSet[i].getValue().getValue().toBytes())); + assertTrue(BytesUtils.equals(expKVWriteSet[i].getValue().getBytes().toBytes(), + acutualKVWriteSet[i].getValue().getBytes().toBytes())); } ContractCodeDeployOperation actualContractDplOp = (ContractCodeDeployOperation) actualOperations[3]; diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValue.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValue.java index 6e7b9b46..47d4ad16 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValue.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValue.java @@ -29,6 +29,6 @@ public interface BytesValue { * @return */ @DataField(order = 1, primitiveType = PrimitiveType.BYTES) - Bytes getValue(); + Bytes getBytes(); } diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataObject.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataObject.java index 1e8247ee..a19d9fff 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataObject.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataObject.java @@ -72,15 +72,15 @@ public class KVDataObject implements KVDataEntry { case NIL: return null; case TEXT: - return bytesValue.getValue().toUTF8String(); + return bytesValue.getBytes().toUTF8String(); case BYTES: - return ByteArray.toHex(bytesValue.getValue().toBytes()); + return ByteArray.toHex(bytesValue.getBytes().toBytes()); case INT64: - return BytesUtils.toLong(bytesValue.getValue().toBytes()); + return BytesUtils.toLong(bytesValue.getBytes().toBytes()); case JSON: - return bytesValue.getValue().toUTF8String(); + return bytesValue.getBytes().toUTF8String(); case XML: - return bytesValue.getValue().toUTF8String(); + return bytesValue.getBytes().toUTF8String(); default: throw new IllegalStateException("Unsupported value type[" + getType() + "] to resolve!"); @@ -106,7 +106,7 @@ public class KVDataObject implements KVDataEntry { * @return */ Bytes bytesArray() { - return bytesValue.getValue(); + return bytesValue.getBytes(); } /** @@ -122,7 +122,7 @@ public class KVDataObject implements KVDataEntry { */ public byte tinyValue() { if (DataType.INT8 == getType()) { - return bytesValue.getValue().toBytes()[0]; + return bytesValue.getBytes().toBytes()[0]; } throw new IllegalStateException(String.format("Expected type [%s], but [%s]", DataType.INT8, getType())); } @@ -140,7 +140,7 @@ public class KVDataObject implements KVDataEntry { */ public short shortValue() { if (DataType.INT16 == getType()) { - return BytesUtils.toShort(bytesValue.getValue().toBytes(), 0); + return BytesUtils.toShort(bytesValue.getBytes().toBytes(), 0); } throw new IllegalStateException(String.format("Expected type [%s], but [%s]", DataType.INT16, getType())); } @@ -158,7 +158,7 @@ public class KVDataObject implements KVDataEntry { */ public int intValue() { if (DataType.INT32 == getType()) { - return BytesUtils.toInt(bytesValue.getValue().toBytes(), 0); + return BytesUtils.toInt(bytesValue.getBytes().toBytes(), 0); } throw new IllegalStateException(String.format("Expected type [%s], but [%s]", DataType.INT32, getType())); } @@ -176,7 +176,7 @@ public class KVDataObject implements KVDataEntry { */ public long longValue() { if (DataType.INT64 == getType()) { - return BytesUtils.toLong(bytesValue.getValue().toBytes(), 0); + return BytesUtils.toLong(bytesValue.getBytes().toBytes(), 0); } throw new IllegalStateException(String.format("Expected type [%s], but [%s]", DataType.INT64, getType())); @@ -195,7 +195,7 @@ public class KVDataObject implements KVDataEntry { */ public BigInteger bigIntValue() { if (DataType.BIG_INT == getType()) { - return new BigInteger(bytesValue.getValue().toBytes()); + return new BigInteger(bytesValue.getBytes().toBytes()); } throw new IllegalStateException( String.format("Expected type [%s], but [%s]", DataType.BIG_INT, getType())); @@ -214,7 +214,7 @@ public class KVDataObject implements KVDataEntry { */ public boolean boolValue() { if (DataType.BOOLEAN == getType()) { - return BytesUtils.toBoolean(bytesValue.getValue().toBytes()[0]); + return BytesUtils.toBoolean(bytesValue.getBytes().toBytes()[0]); } throw new IllegalStateException( String.format("Expected type [%s], but [%s]", DataType.BOOLEAN, getType())); @@ -233,7 +233,7 @@ public class KVDataObject implements KVDataEntry { */ public Date datetimeValue() { if (DataType.TIMESTAMP == getType()) { - long ts = BytesUtils.toLong(bytesValue.getValue().toBytes()); + long ts = BytesUtils.toLong(bytesValue.getBytes().toBytes()); return new Date(ts); } throw new IllegalStateException( @@ -255,7 +255,7 @@ public class KVDataObject implements KVDataEntry { public String stringValue() { DataType type = getType(); if (DataType.TEXT == type || DataType.JSON == type || DataType.XML == type) { - return bytesValue.getValue().toUTF8String(); + return bytesValue.getBytes().toUTF8String(); } throw new IllegalStateException(String.format("Expected type [%s] or [%s] or [%s] , but [%s]", PrimitiveType.TEXT, DataType.JSON, DataType.XML, type)); diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TypedValue.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TypedValue.java index 333badaa..e2c0c9d5 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TypedValue.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TypedValue.java @@ -34,7 +34,7 @@ public class TypedValue implements BytesValue { private TypedValue(BytesValue bytesValue) { this.type = bytesValue.getType(); - this.value = bytesValue.getValue(); + this.value = bytesValue.getBytes(); } private TypedValue() { @@ -48,11 +48,11 @@ public class TypedValue implements BytesValue { } @Override - public Bytes getValue() { + public Bytes getBytes() { return this.value; } - public Object getTypedValue() { + public Object getValue() { if (isNil()) { return null; } diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/resolver/AbstractBytesValueResolver.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/resolver/AbstractBytesValueResolver.java index 995d5522..d6ee0b98 100644 --- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/resolver/AbstractBytesValueResolver.java +++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/resolver/AbstractBytesValueResolver.java @@ -47,7 +47,7 @@ public abstract class AbstractBytesValueResolver implements BytesValueResolver { if (!isSupport(dataType)) { throw new IllegalStateException(String.format("Un-support encode DataType[%s] Object !!!", dataType.name())); } - return decode(value.getValue()); + return decode(value.getBytes()); } protected abstract Object decode(Bytes value); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesToBytesValueResolverTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesToBytesValueResolverTest.java index 3635743c..2dfa0dbd 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesToBytesValueResolverTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesToBytesValueResolverTest.java @@ -26,7 +26,7 @@ public class BytesToBytesValueResolverTest { assertEquals(bytesValue.getType(), DataType.BYTES); - assertEquals(bytesObj, bytesValue.getValue()); + assertEquals(bytesObj, bytesValue.getBytes()); Bytes resolveBytesObj = (Bytes)resolver.decode(bytesValue); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesValueEncodingTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesValueEncodingTest.java index e5b624c9..f572a831 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesValueEncodingTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/BytesValueEncodingTest.java @@ -28,9 +28,9 @@ public class BytesValueEncodingTest { BytesValue longBytesVal2 = BytesValueEncoding.encodeSingle(longVal, long.class); BytesValue longBytesVal3 = BytesValueEncoding.encodeSingle(longVal, Long.class); - assertEquals(longBytesVal1.getValue(), longBytesVal2.getValue()); + assertEquals(longBytesVal1.getBytes(), longBytesVal2.getBytes()); assertEquals(longBytesVal1.getType(), longBytesVal2.getType()); - assertEquals(longBytesVal2.getValue(), longBytesVal3.getValue()); + assertEquals(longBytesVal2.getBytes(), longBytesVal3.getBytes()); assertEquals(longBytesVal2.getType(), longBytesVal3.getType()); long resolveLongVal1 = (long)BytesValueEncoding.decode(longBytesVal1); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/DataAccountKVSetOpTemplateTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/DataAccountKVSetOpTemplateTest.java index a3faea12..6c1d4f57 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/DataAccountKVSetOpTemplateTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/DataAccountKVSetOpTemplateTest.java @@ -63,7 +63,7 @@ public class DataAccountKVSetOpTemplateTest { assertEquals(dataKv.length, resolvedKv.length); for (int i = 0; i < dataKv.length; i++) { assertEquals(dataKv[i].getKey(), resolvedKv[i].getKey()); - assertArrayEquals(dataKv[i].getValue().getValue().toBytes(), resolvedKv[i].getValue().getValue().toBytes()); + assertArrayEquals(dataKv[i].getValue().getBytes().toBytes(), resolvedKv[i].getValue().getBytes().toBytes()); assertEquals(dataKv[i].getValue().getType().CODE, resolvedKv[i].getValue().getType().CODE); assertEquals(dataKv[i].getExpectedVersion(), resolvedKv[i].getExpectedVersion()); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/IntegerToBytesValueResolverTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/IntegerToBytesValueResolverTest.java index 8e39aa85..dd9d4632 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/IntegerToBytesValueResolverTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/IntegerToBytesValueResolverTest.java @@ -22,13 +22,13 @@ public class IntegerToBytesValueResolverTest { BytesValue intBytesValue2 = resolver.encode(intVal, Integer.class); - assertEquals(intBytesValue.getValue(), intBytesValue1.getValue()); + assertEquals(intBytesValue.getBytes(), intBytesValue1.getBytes()); - assertEquals(intBytesValue.getValue(), intBytesValue2.getValue()); + assertEquals(intBytesValue.getBytes(), intBytesValue2.getBytes()); Bytes intBytes = Bytes.fromInt(intVal); - assertEquals(intBytes, intBytesValue.getValue()); + assertEquals(intBytes, intBytesValue.getBytes()); assertEquals(intBytesValue.getType(), DataType.INT32); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/KVDataTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/KVDataTest.java index bcadfc1e..3d54f16c 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/KVDataTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/KVDataTest.java @@ -48,7 +48,7 @@ public class KVDataTest { System.out.println("------Assert start ------"); assertEquals(resolvedKvData.getKey(), kvData.getKey()); assertEquals(resolvedKvData.getExpectedVersion(), kvData.getExpectedVersion()); - assertArrayEquals(resolvedKvData.getValue().getValue().toBytes(), kvData.getValue().getValue().toBytes()); + assertArrayEquals(resolvedKvData.getValue().getBytes().toBytes(), kvData.getValue().getBytes().toBytes()); System.out.println("------Assert OK ------"); } } \ No newline at end of file diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/LongToBytesValueResolverTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/LongToBytesValueResolverTest.java index 899a6415..b4d20b4c 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/LongToBytesValueResolverTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/LongToBytesValueResolverTest.java @@ -23,13 +23,13 @@ public class LongToBytesValueResolverTest { BytesValue longBytesValue2 = resolver.encode(longVal, Long.class); - assertEquals(longBytesValue.getValue(), longBytesValue1.getValue()); + assertEquals(longBytesValue.getBytes(), longBytesValue1.getBytes()); - assertEquals(longBytesValue.getValue(), longBytesValue2.getValue()); + assertEquals(longBytesValue.getBytes(), longBytesValue2.getBytes()); Bytes longBytes = Bytes.fromLong(longVal); - assertEquals(longBytes, longBytesValue.getValue()); + assertEquals(longBytes, longBytesValue.getBytes()); assertEquals(longBytesValue.getType(), DataType.INT64); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/ShortToBytesValueResolverTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/ShortToBytesValueResolverTest.java index b35cedd7..2e8e46be 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/ShortToBytesValueResolverTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/ShortToBytesValueResolverTest.java @@ -21,7 +21,7 @@ public class ShortToBytesValueResolverTest { Bytes shortBytes = new Bytes(BytesUtils.toBytes(shortVal)); - assertEquals(shortBytes, shortBytesValue.getValue()); + assertEquals(shortBytes, shortBytesValue.getBytes()); assertEquals(shortBytesValue.getType(), DataType.INT16); diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/StringToBytesValueResolverTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/StringToBytesValueResolverTest.java index 17dd0c04..544f06bb 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/StringToBytesValueResolverTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/StringToBytesValueResolverTest.java @@ -20,7 +20,7 @@ public class StringToBytesValueResolverTest { BytesValue textBytesValue = resolver.encode(textVal); - assertEquals(Bytes.fromString(textVal), textBytesValue.getValue()); + assertEquals(Bytes.fromString(textVal), textBytesValue.getBytes()); assertEquals(textBytesValue.getType(), DataType.TEXT); @@ -43,7 +43,7 @@ public class StringToBytesValueResolverTest { Person person = new Person("zhangsan", 80); String personJson = JSON.toJSONString(person); BytesValue textBytesValue = resolver.encode(personJson); - assertEquals(Bytes.fromString(personJson), textBytesValue.getValue()); + assertEquals(Bytes.fromString(personJson), textBytesValue.getBytes()); assertEquals(textBytesValue.getType(), DataType.JSON); } diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/TxContentBlobTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/TxContentBlobTest.java index 0404ee38..c8d8c313 100644 --- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/TxContentBlobTest.java +++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/TxContentBlobTest.java @@ -77,8 +77,8 @@ public class TxContentBlobTest { for (int j = 0; j < dataKv.length; j++) { assertEquals(dataKv[i].getKey(), resolvedKv[i].getKey()); assertEquals(dataKv[i].getExpectedVersion(), resolvedKv[i].getExpectedVersion()); - assertArrayEquals(dataKv[i].getValue().getValue().toBytes(), - resolvedKv[i].getValue().getValue().toBytes()); + assertArrayEquals(dataKv[i].getValue().getBytes().toBytes(), + resolvedKv[i].getValue().getBytes().toBytes()); } } } @@ -108,8 +108,8 @@ public class TxContentBlobTest { for (int j = 0; j < dataKv.length; j++) { assertEquals(dataKv[i].getKey(), resolvedKv[i].getKey()); assertEquals(dataKv[i].getExpectedVersion(), resolvedKv[i].getExpectedVersion()); - assertArrayEquals(dataKv[i].getValue().getValue().toBytes(), - resolvedKv[i].getValue().getValue().toBytes()); + assertArrayEquals(dataKv[i].getValue().getBytes().toBytes(), + resolvedKv[i].getValue().getBytes().toBytes()); } } } diff --git a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java index 64b7bbef..8bbada7f 100644 --- a/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java +++ b/source/peer/src/main/java/com/jd/blockchain/peer/web/LedgerQueryController.java @@ -331,7 +331,7 @@ public class LedgerQueryController implements BlockchainQueryService { LedgerQuery ledger = ledgerService.getLedger(ledgerHash); LedgerBlock block = ledger.getLatestBlock(); DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); - return dataAccountSet.getAccount(Bytes.fromBase58(address)); + return dataAccountSet.getAccount(Bytes.fromBase58(address)).getID(); } @RequestMapping(method = { RequestMethod.GET, @@ -350,11 +350,11 @@ public class LedgerQueryController implements BlockchainQueryService { KVDataEntry[] entries = new KVDataEntry[keys.length]; long ver; for (int i = 0; i < entries.length; i++) { - ver = dataAccount.getDataset().getVersion(Bytes.fromString(keys[i])); + ver = dataAccount.getDataset().getVersion(keys[i]); if (ver < 0) { entries[i] = new KVDataObject(keys[i], -1, null); } else { - BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver); + BytesValue value = dataAccount.getDataset().getValue(keys[i], ver); entries[i] = new KVDataObject(keys[i], ver, value); } } @@ -404,12 +404,12 @@ public class LedgerQueryController implements BlockchainQueryService { if (ver < 0) { entries[i] = new KVDataObject(keys[i], -1, null); } else { - if (dataAccount.getDataEntriesTotalCount() == 0 - || dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver) == null) { + if (dataAccount.getDataset().getDataCount() == 0 + || dataAccount.getDataset().getValue(keys[i], ver) == null) { // is the address is not exist; the result is null; entries[i] = new KVDataObject(keys[i], -1, null); } else { - BytesValue value = dataAccount.getDataset().getValue(Bytes.fromString(keys[i]), ver); + BytesValue value = dataAccount.getDataset().getValue(keys[i], ver); entries[i] = new KVDataObject(keys[i], ver, value); } } @@ -431,7 +431,7 @@ public class LedgerQueryController implements BlockchainQueryService { DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address)); - int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataEntriesTotalCount()); + int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) dataAccount.getDataset().getDataCount()); return dataAccount.getDataEntries(pages[0], pages[1]); } @@ -445,7 +445,7 @@ public class LedgerQueryController implements BlockchainQueryService { DataAccountQuery dataAccountSet = ledger.getDataAccountSet(block); DataAccount dataAccount = dataAccountSet.getAccount(Bytes.fromBase58(address)); - return dataAccount.getDataEntriesTotalCount(); + return dataAccount.getDataset().getDataCount(); } @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts/address/{address}") diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/converters/ClientResolveUtil.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/converters/ClientResolveUtil.java index 895010f3..cc6d41a7 100644 --- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/converters/ClientResolveUtil.java +++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/converters/ClientResolveUtil.java @@ -108,7 +108,7 @@ public class ClientResolveUtil { public static Object readValueByBytesValue(BytesValue bytesValue) { DataType dataType = bytesValue.getType(); - Bytes saveVal = bytesValue.getValue(); + Bytes saveVal = bytesValue.getBytes(); Object showVal; switch (dataType) { case BYTES: diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java index 72e6f3f2..86b70840 100644 --- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java +++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationTestAll4Redis.java @@ -236,13 +236,13 @@ public class IntegrationTestAll4Redis { assertEquals(ledgerRepository.retrieveLatestBlockHeight(), txResp.getBlockHeight()); assertEquals("Value_A_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) - .getAccount(dataKey.getAddress()).getDataset().getValue("A").getValue().toUTF8String()); + .getAccount(dataKey.getAddress()).getDataset().getValue("A").getBytes().toUTF8String()); assertEquals("Value_B_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) - .getAccount(dataKey.getAddress()).getDataset().getValue("B").getValue().toUTF8String()); + .getAccount(dataKey.getAddress()).getDataset().getValue("B").getBytes().toUTF8String()); assertEquals("Value_C_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) - .getAccount(dataKey.getAddress()).getDataset().getValue("C").getValue().toUTF8String()); + .getAccount(dataKey.getAddress()).getDataset().getValue("C").getBytes().toUTF8String()); assertEquals("Value_D_0", ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) - .getAccount(dataKey.getAddress()).getDataset().getValue("D").getValue().toUTF8String()); + .getAccount(dataKey.getAddress()).getDataset().getValue("D").getBytes().toUTF8String()); assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) .getAccount(dataKey.getAddress()).getDataset().getVersion("A")); assertEquals(0, ledgerRepository.getDataAccountSet(ledgerRepository.retrieveLatestBlock()) @@ -473,7 +473,7 @@ public class IntegrationTestAll4Redis { Bytes dataAddress = AddressEncoding.generateAddress(pubKey); assertEquals(dataAddress, dataAccountSet.getAccount(dataAddress).getID().getAddress()); assertEquals("hello", - dataAccountSet.getAccount(dataAddress).getDataset().getValue(KEY_TOTAL, -1).getValue().toUTF8String()); + dataAccountSet.getAccount(dataAddress).getDataset().getValue(KEY_TOTAL, -1).getBytes().toUTF8String()); // 验证userAccount,从合约内部赋值,然后外部验证;内部定义动态key,外部不便于得到,临时屏蔽; // UserAccountSet userAccountSet = @@ -504,8 +504,8 @@ public class IntegrationTestAll4Redis { .getDataset().getValue("A"); BytesValue val2InDb = ledgerRepository.getDataAccountSet(block).getAccount(contractDataKey.getAddress()) .getDataset().getValue(KEY_TOTAL); - assertEquals("Value_A_0", val1InDb.getValue().toUTF8String()); - assertEquals("total value,dataAccount", val2InDb.getValue().toUTF8String()); + assertEquals("Value_A_0", val1InDb.getBytes().toUTF8String()); + assertEquals("total value,dataAccount", val2InDb.getBytes().toUTF8String()); } /** diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java index 33ad1f7c..a84654c2 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java @@ -4,28 +4,6 @@ public interface Dataset { long getDataCount(); -// /** -// * Create or update the value associated the specified key if the version -// * checking is passed.
-// * -// * The value of the key will be updated only if it's latest version equals the -// * specified version argument.
-// * If the key doesn't exist, it will be created when the version arg was -1. -// *

-// * If updating is performed, the version of the key increase by 1.
-// * If creating is performed, the version of the key initialize by 0.
-// * -// * @param key The key of data; -// * @param value The value of data; -// * @param version The expected latest version of the key. -// * @return The new version of the key.
-// * If the key is new created success, then return 0;
-// * If the key is updated success, then return the new version;
-// * If this operation fail by version checking or other reason, then -// * return -1; -// */ -// long setValue(String key, byte[] value, long version); - /** * Create or update the value associated the specified key if the version * checking is passed.