versionList = new ArrayList<>();
- if(kvInfoVO != null){
- for(KVDataVO kvDataVO : kvInfoVO.getData()){
- for(Long version : kvDataVO.getVersion()){
+ if (kvInfoVO != null) {
+ for (KVDataVO kvDataVO : kvInfoVO.getData()) {
+ for (Long version : kvDataVO.getVersion()) {
keyList.add(kvDataVO.getKey());
versionList.add(version);
}
@@ -301,12 +309,12 @@ public class LedgerQueryService implements BlockchainQueryService {
if (keys == null || keys.length == 0) {
return null;
}
- if (versions == null || versions.length == 0) {
- return null;
- }
- if(keys.length != versions.length){
- throw new ContractException("keys.length!=versions.length!");
- }
+ if (versions == null || versions.length == 0) {
+ return null;
+ }
+ if (keys.length != versions.length) {
+ throw new ContractException("keys.length!=versions.length!");
+ }
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
@@ -314,22 +322,21 @@ public class LedgerQueryService implements BlockchainQueryService {
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
KVDataEntry[] entries = new KVDataEntry[keys.length];
- long ver = -1;
+ long ver = -1;
for (int i = 0; i < entries.length; i++) {
// ver = dataAccount.getDataVersion(Bytes.fromString(keys[i]));
// dataAccount.getBytes(Bytes.fromString(keys[i]),1);
ver = versions[i];
if (ver < 0) {
- entries[i] = new KVDataObject(keys[i], -1, PrimitiveType.NIL, null);
- }else {
- if(dataAccount.getDataEntriesTotalCount()==0 ||
- dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null){
- //is the address is not exist; the result is null;
- entries[i] = new KVDataObject(keys[i], -1, PrimitiveType.NIL, null);
+ entries[i] = new KVDataObject(keys[i], -1, null);
+ } else {
+ if (dataAccount.getDataEntriesTotalCount() == 0
+ || dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null) {
+ // is the address is not exist; the result is null;
+ entries[i] = new KVDataObject(keys[i], -1, null);
} else {
- byte[] value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
- BytesValue decodeData = BinaryProtocol.decode(value);
- entries[i] = new KVDataObject(keys[i], ver, PrimitiveType.valueOf(decodeData.getType().CODE), decodeData.getValue().toBytes());
+ BytesValue value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
+ entries[i] = new KVDataObject(keys[i], ver, value);
}
}
}
@@ -381,8 +388,8 @@ public class LedgerQueryService implements BlockchainQueryService {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet 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.getTotalCount());
+ return dataAccountSet.getAccounts(pages[0], pages[1]);
}
@Override
@@ -390,8 +397,8 @@ public class LedgerQueryService implements BlockchainQueryService {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
ContractAccountSet 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.getTotalCount());
+ return contractAccountSet.getAccounts(pages[0], pages[1]);
}
private LedgerAdministration ledgerAdministration(HashDigest ledgerHash) {
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java
index 3182c736..69e3223f 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/LedgerRepositoryImpl.java
@@ -13,7 +13,6 @@ import com.jd.blockchain.ledger.core.LedgerAdministration;
import com.jd.blockchain.ledger.core.LedgerConsts;
import com.jd.blockchain.ledger.core.LedgerDataSet;
import com.jd.blockchain.ledger.core.LedgerEditor;
-import com.jd.blockchain.ledger.core.LedgerException;
import com.jd.blockchain.ledger.core.LedgerRepository;
import com.jd.blockchain.ledger.core.LedgerTransactionContext;
import com.jd.blockchain.ledger.core.TransactionSet;
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/OpeningAccessPolicy.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/OpeningAccessPolicy.java
index 3af84a5a..14c5b9b4 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/OpeningAccessPolicy.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/OpeningAccessPolicy.java
@@ -16,7 +16,7 @@ import com.jd.blockchain.utils.Bytes;
public class OpeningAccessPolicy implements AccountAccessPolicy {
@Override
- public boolean checkCommitting(AccountHeader account) {
+ public boolean checkDataWriting(AccountHeader account) {
return true;
}
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java
index 7a0670b8..2adda2f6 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/TransactionBatchProcessor.java
@@ -9,13 +9,13 @@ import org.slf4j.LoggerFactory;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.LedgerBlock;
+import com.jd.blockchain.ledger.LedgerException;
import com.jd.blockchain.ledger.Operation;
import com.jd.blockchain.ledger.TransactionRequest;
import com.jd.blockchain.ledger.TransactionResponse;
import com.jd.blockchain.ledger.TransactionState;
import com.jd.blockchain.ledger.core.LedgerDataSet;
import com.jd.blockchain.ledger.core.LedgerEditor;
-import com.jd.blockchain.ledger.core.LedgerException;
import com.jd.blockchain.ledger.core.LedgerService;
import com.jd.blockchain.ledger.core.LedgerTransactionContext;
import com.jd.blockchain.ledger.core.OperationHandle;
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractEventSendOperationHandle.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractEventSendOperationHandle.java
index e1930a35..5680846c 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractEventSendOperationHandle.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractEventSendOperationHandle.java
@@ -9,11 +9,11 @@ import com.jd.blockchain.contract.engine.ContractCode;
import com.jd.blockchain.contract.engine.ContractEngine;
import com.jd.blockchain.contract.engine.ContractServiceProviders;
import com.jd.blockchain.ledger.ContractEventSendOperation;
+import com.jd.blockchain.ledger.LedgerException;
import com.jd.blockchain.ledger.Operation;
import com.jd.blockchain.ledger.core.ContractAccount;
import com.jd.blockchain.ledger.core.ContractAccountSet;
import com.jd.blockchain.ledger.core.LedgerDataSet;
-import com.jd.blockchain.ledger.core.LedgerException;
import com.jd.blockchain.ledger.core.LedgerService;
import com.jd.blockchain.ledger.core.OperationHandle;
import com.jd.blockchain.ledger.core.TransactionRequestContext;
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java
index 60d418a5..162f3408 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/ContractLedgerContext.java
@@ -3,10 +3,25 @@ package com.jd.blockchain.ledger.core.impl.handles;
import java.util.ArrayList;
import java.util.List;
-import com.alibaba.fastjson.JSON;
import com.jd.blockchain.contract.LedgerContext;
import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.ledger.*;
+import com.jd.blockchain.ledger.AccountHeader;
+import com.jd.blockchain.ledger.BlockchainIdentity;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.DataAccountKVSetOperation;
+import com.jd.blockchain.ledger.DataAccountRegisterOperation;
+import com.jd.blockchain.ledger.KVDataEntry;
+import com.jd.blockchain.ledger.KVInfoVO;
+import com.jd.blockchain.ledger.LedgerBlock;
+import com.jd.blockchain.ledger.LedgerInfo;
+import com.jd.blockchain.ledger.LedgerMetadata;
+import com.jd.blockchain.ledger.LedgerTransaction;
+import com.jd.blockchain.ledger.Operation;
+import com.jd.blockchain.ledger.ParticipantNode;
+import com.jd.blockchain.ledger.TransactionState;
+import com.jd.blockchain.ledger.UserInfo;
+import com.jd.blockchain.ledger.UserRegisterOperation;
import com.jd.blockchain.ledger.core.impl.OperationHandleContext;
import com.jd.blockchain.transaction.BlockchainQueryService;
import com.jd.blockchain.transaction.DataAccountKVSetOperationBuilder;
@@ -16,7 +31,6 @@ import com.jd.blockchain.transaction.KVData;
import com.jd.blockchain.transaction.UserRegisterOperationBuilder;
import com.jd.blockchain.transaction.UserRegisterOperationBuilderImpl;
import com.jd.blockchain.utils.Bytes;
-import com.jd.blockchain.utils.io.BytesUtils;
public class ContractLedgerContext implements LedgerContext {
@@ -250,60 +264,95 @@ public class ContractLedgerContext implements LedgerContext {
this.accountAddress = accountAddress;
}
- public boolean isJson(String str) {
- boolean result = false;
- try {
- Object obj = JSON.parse(str);
- result = true;
- } catch (Exception e) {
- result = false;
- }
- return result;
- }
-
@Override
public DataAccountKVSetOperation getOperation() {
return op;
}
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
+// BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+// this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+// handle(op);
+// return this;
+// }
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.BYTES, value);
+ public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromText(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
- generatedOpList.add(op);
- opHandleContext.handle(op);
+ handle(op);
return this;
}
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
- BytesValue bytesValue;
- if (isJson(value)) {
+ public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+ handle(op);
+ return this;
+ }
- bytesValue = new BytesValueEntry(BytesValueType.JSON, BytesUtils.toBytes(value));
- }
- else {
- bytesValue = new BytesValueEntry(BytesValueType.TEXT, BytesUtils.toBytes(value));
- }
+ @Override
+ public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromInt64(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
- generatedOpList.add(op);
- opHandleContext.handle(op);
+ handle(op);
return this;
}
+
+// @Deprecated
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
+// BytesValue bytesValue = BytesValueEntry.fromText(value);
+// this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+// handle(op);
+// return this;
+// }
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, Bytes value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.BYTES, value.toBytes());
+ public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromJSON(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
- generatedOpList.add(op);
- opHandleContext.handle(op);
+ handle(op);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromXML(value);
+ this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+ handle(op);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+ handle(op);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromImage(value);
+ this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+ handle(op);
return this;
}
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, long value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.INT64, BytesUtils.toBytes(value));
+ public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromTimestamp(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
+ handle(op);
+ return this;
+ }
+
+ private void handle(Operation op) {
generatedOpList.add(op);
opHandleContext.handle(op);
- return this;
}
/**
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/DataAccountKVSetOperationHandle.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/DataAccountKVSetOperationHandle.java
index 2d7735d4..4331c29c 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/DataAccountKVSetOperationHandle.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/impl/handles/DataAccountKVSetOperationHandle.java
@@ -24,8 +24,7 @@ public class DataAccountKVSetOperationHandle implements OperationHandle{
DataAccount account = dataset.getDataAccountSet().getDataAccount(kvWriteOp.getAccountAddress());
KVWriteEntry[] writeset = kvWriteOp.getWriteSet();
for (KVWriteEntry kvw : writeset) {
- byte[] value = BinaryProtocol.encode(kvw.getValue(), BytesValue.class);
- account.setBytes(Bytes.fromString(kvw.getKey()), value, kvw.getExpectedVersion());
+ account.setBytes(Bytes.fromString(kvw.getKey()), kvw.getValue(), kvw.getExpectedVersion());
}
}
diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/BaseAccountTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/BaseAccountTest.java
index 23b3445a..ac9f50b1 100644
--- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/BaseAccountTest.java
+++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/BaseAccountTest.java
@@ -12,12 +12,11 @@ import com.jd.blockchain.crypto.service.classic.ClassicCryptoService;
import com.jd.blockchain.crypto.service.sm.SMCryptoService;
import com.jd.blockchain.ledger.BlockchainKeyGenerator;
import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.BytesValueEntry;
import com.jd.blockchain.ledger.core.BaseAccount;
import com.jd.blockchain.ledger.core.CryptoConfig;
-import com.jd.blockchain.ledger.core.impl.OpeningAccessPolicy;
import com.jd.blockchain.storage.service.utils.MemoryKVStorage;
import com.jd.blockchain.utils.Bytes;
-import com.jd.blockchain.utils.io.BytesUtils;
/**
*
@@ -44,44 +43,43 @@ public class BaseAccountTest {
cryptoConf.setAutoVerifyHash(true);
cryptoConf.setHashAlgorithm(ClassicAlgorithm.SHA256);
- OpeningAccessPolicy accPlc = new OpeningAccessPolicy();
+// OpeningAccessPolicy accPlc = new OpeningAccessPolicy();
BlockchainKeypair bck = BlockchainKeyGenerator.getInstance().generate();
// 新建账户;
- BaseAccount baseAccount = new BaseAccount(bck.getIdentity(), cryptoConf, keyPrefix, testStorage, testStorage,
- accPlc);
+ BaseAccount baseAccount = new BaseAccount(bck.getIdentity(), cryptoConf, keyPrefix, testStorage, testStorage);
assertFalse(baseAccount.isUpdated());// 空的账户;
assertFalse(baseAccount.isReadonly());
// 在空白状态下写入数据;
- long v = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A"), 0);
+ long v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), 0);
// 预期失败;
assertEquals(-1, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A"), 1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), 1);
// 预期失败;
assertEquals(-1, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A"), -1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), -1);
// 预期成功;
assertEquals(0, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A-1"), -1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A-1"), -1);
// 已经存在版本,指定版本号-1,预期导致失败;
assertEquals(-1, v);
baseAccount.commit();
v = 0;
for (int i = 0; i < 10; i++) {
- long s = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A_" + i), v);
+ long s = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A_" + i), v);
baseAccount.commit();
// 预期成功;
assertEquals(v + 1, s);
v++;
}
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesUtils.toBytes("VALUE_A_" + v), v + 1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A_" + v), v + 1);
// 预期成功;
assertEquals(-1, v);
diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java
index 3ae78c32..5018ede7 100644
--- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java
+++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerEditerTest.java
@@ -1,10 +1,10 @@
package test.com.jd.blockchain.ledger;
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import org.junit.Before;
import org.junit.Test;
import com.jd.blockchain.binaryproto.DataContractRegistry;
@@ -17,6 +17,8 @@ import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm;
import com.jd.blockchain.crypto.service.classic.ClassicCryptoService;
import com.jd.blockchain.crypto.service.sm.SMCryptoService;
import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.BytesValueType;
import com.jd.blockchain.ledger.LedgerBlock;
import com.jd.blockchain.ledger.LedgerInitSetting;
import com.jd.blockchain.ledger.LedgerTransaction;
@@ -37,67 +39,99 @@ import com.jd.blockchain.utils.io.BytesUtils;
import com.jd.blockchain.utils.net.NetworkAddress;
public class LedgerEditerTest {
-
+
private static final String[] SUPPORTED_PROVIDERS = { ClassicCryptoService.class.getName(),
SMCryptoService.class.getName() };
-
static {
DataContractRegistry.register(com.jd.blockchain.ledger.TransactionContent.class);
DataContractRegistry.register(com.jd.blockchain.ledger.UserRegisterOperation.class);
DataContractRegistry.register(com.jd.blockchain.ledger.BlockBody.class);
}
- String ledgerKeyPrefix = "LDG://";
- SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519");
+ private static final String LEDGER_KEY_PREFIX = "LDG://";
+ private SignatureFunction signatureFunction;
- // 存储;
- MemoryKVStorage storage = new MemoryKVStorage();
+ /**
+ * 初始化一个;
+ */
+ @Before
+ public void beforeTest() {
+ signatureFunction = Crypto.getSignatureFunction("ED25519");
+ }
- TransactionRequest genesisTxReq = LedgerTestUtils.createTxRequest(null, signatureFunction);
+ /**
+ * @return
+ */
+ private LedgerEditor createLedgerInitEditor() {
+ // 存储;
+ MemoryKVStorage storage = new MemoryKVStorage();
- // 创建初始化配置;
- LedgerInitSetting initSetting = createLedgerInitSetting();
+ // 创建初始化配置;
+ LedgerInitSetting initSetting = createLedgerInitSetting();
- // 创建账本;
- LedgerEditor ldgEdt = LedgerTransactionalEditor.createEditor(initSetting, ledgerKeyPrefix, storage, storage);
- LedgerTransactionContext txCtx = ldgEdt.newTransaction(genesisTxReq);
- LedgerDataSet ldgDS = txCtx.getDataSet();
+ // 创建账本;
+ return LedgerTransactionalEditor.createEditor(initSetting, LEDGER_KEY_PREFIX, storage, storage);
+ }
- AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair();
+ private LedgerTransactionContext createGenisisTx(LedgerEditor ldgEdt) {
+ TransactionRequest genesisTxReq = LedgerTestUtils.createTxRequest(null, signatureFunction);
+
+ LedgerTransactionContext txCtx = ldgEdt.newTransaction(genesisTxReq);
+
+ return txCtx;
+ }
@SuppressWarnings("unused")
@Test
public void testWriteDataAccoutKvOp() {
-
+ LedgerEditor ldgEdt = createLedgerInitEditor();
+ LedgerTransactionContext genisisTxCtx = createGenisisTx(ldgEdt);
+ LedgerDataSet ldgDS = genisisTxCtx.getDataSet();
+
+
+ AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair();
BlockchainKeypair dataKP = new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey());
DataAccount dataAccount = ldgDS.getDataAccountSet().register(dataKP.getAddress(), dataKP.getPubKey(), null);
- dataAccount.setBytes(Bytes.fromString("A"), "abc".getBytes(), -1);
+ dataAccount.setBytes(Bytes.fromString("A"), "abc", -1);
- LedgerTransaction tx = txCtx.commit(TransactionState.SUCCESS);
+ LedgerTransaction tx = genisisTxCtx.commit(TransactionState.SUCCESS);
LedgerBlock block = ldgEdt.prepare();
// 提交数据,写入存储;
ldgEdt.commit();
- byte[] bytes = dataAccount.getBytes("A");
- assertArrayEquals("abc".getBytes(), bytes);
+ // 预期这是第1个区块;
+ assertNotNull(block);
+ assertNotNull(block.getHash());
+ assertEquals(0, block.getHeight());
+
+ // 验证数据读写的一致性;
+ BytesValue bytes = dataAccount.getBytes("A");
+ assertEquals(BytesValueType.TEXT, bytes.getType());
+ String textValue = bytes.getValue().toUTF8String();
+ assertEquals("abc", textValue);
}
/**
* 测试创建账本;
*/
@Test
- public void testLedgerEditorCreation() {
+ public void testGennesisBlockCreation() {
+ LedgerEditor ldgEdt = createLedgerInitEditor();
+ LedgerTransactionContext genisisTxCtx = createGenisisTx(ldgEdt);
+ LedgerDataSet ldgDS = genisisTxCtx.getDataSet();
+ AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair();
BlockchainKeypair userKP = new BlockchainKeypair(cryptoKeyPair.getPubKey(), cryptoKeyPair.getPrivKey());
UserAccount userAccount = ldgDS.getUserAccountSet().register(userKP.getAddress(), userKP.getPubKey());
userAccount.setProperty("Name", "孙悟空", -1);
userAccount.setProperty("Age", "10000", -1);
- LedgerTransaction tx = txCtx.commit(TransactionState.SUCCESS);
+ LedgerTransaction tx = genisisTxCtx.commit(TransactionState.SUCCESS);
+ TransactionRequest genesisTxReq = genisisTxCtx.getRequestTX();
assertEquals(genesisTxReq.getTransactionContent().getHash(), tx.getTransactionContent().getHash());
assertEquals(0, tx.getBlockHeight());
@@ -116,7 +150,7 @@ public class LedgerEditerTest {
private LedgerInitSetting createLedgerInitSetting() {
SignatureFunction signFunc = Crypto.getSignatureFunction("ED25519");
-
+
CryptoProvider[] supportedProviders = new CryptoProvider[SUPPORTED_PROVIDERS.length];
for (int i = 0; i < SUPPORTED_PROVIDERS.length; i++) {
supportedProviders[i] = Crypto.getProvider(SUPPORTED_PROVIDERS[i]);
diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java
index ba533a4a..d99ed706 100644
--- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java
+++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/LedgerTransactionDataTest.java
@@ -257,7 +257,7 @@ public class LedgerTransactionDataTest {
// contentBlob.setSubjectAccount(id.getAddress());
// contentBlob.setSequenceNumber(1);
DataAccountKVSetOperation kvsetOP = opFactory.dataAccount(id.getAddress())
- .set("Name", ByteArray.fromString("AAA", "UTF-8"), -1).getOperation();
+ .setText("Name", "AAA", -1).getOperation();
contentBlob.addOperation(kvsetOP);
return contentBlob;
}
diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionSetTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionSetTest.java
index 41a9d3b5..83ea8f9a 100644
--- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionSetTest.java
+++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/TransactionSetTest.java
@@ -68,7 +68,7 @@ public class TransactionSetTest {
DataAccountRegisterOperation dataAccRegOp = txBuilder.dataAccounts().register(dataKey.getIdentity());
DataAccountKVSetOperation kvsetOP = txBuilder.dataAccount(dataKey.getAddress())
- .set("A", "Value_A_0".getBytes(), -1).set("B", "Value_B_0".getBytes(), -1).getOperation();
+ .setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1).getOperation();
byte[] chainCode = new byte[128];
rand.nextBytes(chainCode);
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 864484f3..ae340106 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
@@ -4,7 +4,7 @@ import com.jd.blockchain.binaryproto.DataContract;
import com.jd.blockchain.binaryproto.DataField;
import com.jd.blockchain.binaryproto.PrimitiveType;
import com.jd.blockchain.consts.DataCodes;
-import com.jd.blockchain.utils.io.BytesSlice;
+import com.jd.blockchain.utils.Bytes;
/**
* BytesValue is the base structure of Value in Blockchain Account;
@@ -29,6 +29,6 @@ public interface BytesValue {
* @return
*/
@DataField(order = 1, primitiveType = PrimitiveType.BYTES)
- BytesSlice getValue();
+ Bytes getValue();
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueEntry.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueEntry.java
index 753f5f3d..bf88ff70 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueEntry.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueEntry.java
@@ -1,31 +1,114 @@
package com.jd.blockchain.ledger;
-import com.jd.blockchain.utils.io.BytesSlice;
+import com.jd.blockchain.utils.Bytes;
+import com.jd.blockchain.utils.io.BytesUtils;
/**
- * Created by zhangshuang3 on 2018/12/3.
+ *
+ * @author huanghaiquan
+ *
*/
-public class BytesValueEntry implements BytesValue{
- BytesValueType type;
- BytesSlice slice;
-
- public BytesValueEntry(BytesValueType type, byte[] bytes) {
- this.type = type;
- this.slice = new BytesSlice(bytes);
- }
-
- @Override
- public BytesValueType getType() {
- return this.type;
- }
-
- public void setType(BytesValueType type) {
- this.type = type;
- }
-
- @Override
- public BytesSlice getValue() {
- return this.slice;
- }
+public class BytesValueEntry implements BytesValue {
+ BytesValueType type;
+ Bytes value;
+
+ private BytesValueEntry(BytesValueType type, byte[] bytes) {
+ this.type = type;
+ this.value = new Bytes(bytes);
+ }
+
+ private BytesValueEntry(BytesValueType type, Bytes bytes) {
+ this.type = type;
+ this.value = bytes;
+ }
+
+ public static BytesValue fromBytes(byte[] value) {
+ return new BytesValueEntry(BytesValueType.BYTES, value);
+ }
+
+ public static BytesValue fromBytes(Bytes value) {
+ return new BytesValueEntry(BytesValueType.BYTES, value);
+ }
+
+ public static BytesValue fromImage(byte[] value) {
+ return new BytesValueEntry(BytesValueType.IMG, value);
+ }
+
+ public static BytesValue fromImage(Bytes value) {
+ return new BytesValueEntry(BytesValueType.IMG, value);
+ }
+
+ /**
+ * 以 UTF-8 编码从字符串转换为字节数组值;
+ *
+ * @param value
+ * @return
+ */
+ public static BytesValue fromText(String value) {
+ return new BytesValueEntry(BytesValueType.TEXT, BytesUtils.toBytes(value));
+ }
+
+ /**
+ * 以 UTF-8 编码把字节数组值转换为字符串;
+ *
+ * @param bytesValue
+ * @return
+ */
+ public static String toText(BytesValue bytesValue) {
+ if (bytesValue == null) {
+ return null;
+ }
+ if (bytesValue.getType() != BytesValueType.TEXT) {
+ throw new ValueTypeCastException("The expected value type is " + BytesValueType.TEXT.toString()
+ + ", but it is actually " + bytesValue.getType().toString() + "!");
+ }
+ return bytesValue.getValue().toUTF8String();
+ }
+
+ public static BytesValue fromJSON(String value) {
+ return new BytesValueEntry(BytesValueType.JSON, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromXML(String value) {
+ return new BytesValueEntry(BytesValueType.XML, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromInt32(int value) {
+ return new BytesValueEntry(BytesValueType.INT32, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromInt64(long value) {
+ return new BytesValueEntry(BytesValueType.INT64, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromInt16(short value) {
+ return new BytesValueEntry(BytesValueType.INT16, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromInt8(byte value) {
+ return new BytesValueEntry(BytesValueType.INT8, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromTimestamp(long value) {
+ return new BytesValueEntry(BytesValueType.TIMESTAMP, BytesUtils.toBytes(value));
+ }
+
+ public static BytesValue fromBoolean(boolean value) {
+ return new BytesValueEntry(BytesValueType.BOOLEAN, BytesUtils.toBytes(value));
+ }
+
+ @Override
+ public BytesValueType getType() {
+ return this.type;
+ }
+
+ public void setType(BytesValueType type) {
+ this.type = type;
+ }
+
+ @Override
+ public Bytes getValue() {
+ return this.value;
+ }
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueType.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueType.java
index 306b2b89..11049ea9 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueType.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueType.java
@@ -37,9 +37,9 @@ public enum BytesValueType {
INT64(PrimitiveType.INT64.CODE),
/**
- * 日期时间;
+ * 时间戳;
*/
- DATETIME(PrimitiveType.DATETIME.CODE),
+ TIMESTAMP(PrimitiveType.TIMESTAMP.CODE),
/**
* 文本数据;
@@ -81,7 +81,6 @@ public enum BytesValueType {
*/
LOCATION(PrimitiveType.LOCATION.CODE);
-
@EnumField(type = PrimitiveType.INT8)
public final byte CODE;
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataEntry.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataEntry.java
index efce0703..9d4e0870 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataEntry.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/KVDataEntry.java
@@ -1,7 +1,5 @@
package com.jd.blockchain.ledger;
-import com.jd.blockchain.binaryproto.PrimitiveType;
-
public interface KVDataEntry {
/**
@@ -27,11 +25,12 @@ public interface KVDataEntry {
*
* @return
*/
- PrimitiveType getType();
+ BytesValueType getType();
/**
* 值;
* @return
*/
Object getValue();
+
}
\ No newline at end of file
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 26467e85..2f081642 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
@@ -1,11 +1,10 @@
package com.jd.blockchain.ledger;
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.Date;
import com.jd.blockchain.binaryproto.PrimitiveType;
+import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.io.ByteArray;
import com.jd.blockchain.utils.io.BytesUtils;
@@ -25,13 +24,10 @@ public class KVDataObject implements KVDataEntry {
private long version;
- private PrimitiveType type;
+ private BytesValue bytesValue;
- private byte[] bytesValue;
-
- public KVDataObject(String key, long version, PrimitiveType type, byte[] bytesValue) {
+ public KVDataObject(String key, long version, BytesValue bytesValue) {
this.key = key;
- this.type = type;
this.version = version < 0 ? -1 : version;
this.bytesValue = bytesValue;
}
@@ -62,8 +58,8 @@ public class KVDataObject implements KVDataEntry {
* @see com.jd.blockchain.ledger.KVDataEntry#getType()
*/
@Override
- public PrimitiveType getType() {
- return type;
+ public BytesValueType getType() {
+ return bytesValue == null ? BytesValueType.NIL : bytesValue.getType();
}
@Override
@@ -72,24 +68,20 @@ public class KVDataObject implements KVDataEntry {
return null;
}
- try {
- switch (type) {
- case NIL:
- return null;
- case TEXT:
- return new String(bytesValue, "UTF-8");
- case BYTES:
- return ByteArray.toHex(bytesValue);
- case INT64:
- return BytesUtils.readLong(new ByteArrayInputStream(bytesValue));
- case JSON:
- return new String(bytesValue, "UTF-8");
+ switch (getType()) {
+ case NIL:
+ return null;
+ case TEXT:
+ return bytesValue.getValue().toUTF8String();
+ case BYTES:
+ return ByteArray.toHex(bytesValue.getValue().toBytes());
+ case INT64:
+ return BytesUtils.toLong(bytesValue.getValue().toBytes());
+ case JSON:
+ return bytesValue.getValue().toUTF8String();
- default:
- throw new IllegalStateException("Unsupported value type[" + type + "] to resolve!");
- }
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException(e.getMessage(), e);
+ default:
+ throw new IllegalStateException("Unsupported value type[" + getType() + "] to resolve!");
}
}
@@ -103,7 +95,7 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public boolean isNil() {
- return PrimitiveType.NIL == type;
+ return bytesValue == null || BytesValueType.NIL == bytesValue.getType();
}
/**
@@ -111,8 +103,8 @@ public class KVDataObject implements KVDataEntry {
*
* @return
*/
- ByteArray bytesArray() {
- return ByteArray.wrapReadonly(bytesValue);
+ Bytes bytesArray() {
+ return bytesValue.getValue();
}
/**
@@ -127,10 +119,10 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public byte tinyValue() {
- if (PrimitiveType.INT8 == type) {
- return bytesValue[0];
+ if (BytesValueType.INT8 == getType()) {
+ return bytesValue.getValue().toBytes()[0];
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.INT8, type));
+ throw new IllegalStateException(String.format("Expected type [%s], but [%s]", BytesValueType.INT8, getType()));
}
/**
@@ -145,10 +137,10 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public short shortValue() {
- if (PrimitiveType.INT16 == type) {
- return BytesUtils.toShort(bytesValue, 0);
+ if (BytesValueType.INT16 == getType()) {
+ return BytesUtils.toShort(bytesValue.getValue().toBytes(), 0);
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.INT16, type));
+ throw new IllegalStateException(String.format("Expected type [%s], but [%s]", BytesValueType.INT16, getType()));
}
/**
@@ -163,10 +155,10 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public int intValue() {
- if (PrimitiveType.INT32 == type) {
- return BytesUtils.toInt(bytesValue, 0);
+ if (BytesValueType.INT32 == getType()) {
+ return BytesUtils.toInt(bytesValue.getValue().toBytes(), 0);
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.INT32, type));
+ throw new IllegalStateException(String.format("Expected type [%s], but [%s]", BytesValueType.INT32, getType()));
}
/**
@@ -181,10 +173,10 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public long longValue() {
- if (PrimitiveType.INT64 == type) {
- return BytesUtils.toLong(bytesValue, 0);
+ if (BytesValueType.INT64 == getType()) {
+ return BytesUtils.toLong(bytesValue.getValue().toBytes(), 0);
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.INT64, type));
+ throw new IllegalStateException(String.format("Expected type [%s], but [%s]", BytesValueType.INT64, getType()));
}
@@ -200,10 +192,11 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public BigInteger bigIntValue() {
- if (PrimitiveType.BIG_INT == type) {
- return new BigInteger(bytesValue);
+ if (BytesValueType.BIG_INT == getType()) {
+ return new BigInteger(bytesValue.getValue().toBytes());
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.BIG_INT, type));
+ throw new IllegalStateException(
+ String.format("Expected type [%s], but [%s]", BytesValueType.BIG_INT, getType()));
}
/**
@@ -218,17 +211,18 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public boolean boolValue() {
- if (PrimitiveType.BOOLEAN == type) {
- return bytesValue[0] != 0;
+ if (BytesValueType.BOOLEAN == getType()) {
+ return BytesUtils.toBoolean(bytesValue.getValue().toBytes()[0]);
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.BOOLEAN, type));
+ throw new IllegalStateException(
+ String.format("Expected type [%s], but [%s]", BytesValueType.BOOLEAN, getType()));
}
/**
* 返回日期时间值;
*
*
- * 仅当数据类型 {@link #getType()} 为 {@link PrimitiveType#DATETIME} 有效;
+ * 仅当数据类型 {@link #getType()} 为 {@link PrimitiveType#TIMESTAMP} 有效;
*
*
* 无效类型将引发 {@link IllegalStateException} 异常;
@@ -236,19 +230,20 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public Date datetimeValue() {
- if (PrimitiveType.DATETIME == type) {
- long ts = BytesUtils.toLong(bytesValue);
+ if (BytesValueType.TIMESTAMP == getType()) {
+ long ts = BytesUtils.toLong(bytesValue.getValue().toBytes());
return new Date(ts);
}
- throw new IllegalStateException(String.format("Expected type [%s], but [%s]", PrimitiveType.DATETIME, type));
+ throw new IllegalStateException(
+ String.format("Expected type [%s], but [%s]", BytesValueType.TIMESTAMP, getType()));
}
/**
* 返回大整数值;
*
*
- * 仅当数据类型 {@link #getType()} 为 {@link PrimitiveType#TEXT} / {@link PrimitiveType#JSON} /
- * {@link PrimitiveType#XML} 有效;
+ * 仅当数据类型 {@link #getType()} 为 {@link PrimitiveType#TEXT} /
+ * {@link PrimitiveType#JSON} / {@link PrimitiveType#XML} 有效;
*
*
* 无效类型将引发 {@link IllegalStateException} 异常;
@@ -256,15 +251,12 @@ public class KVDataObject implements KVDataEntry {
* @return
*/
public String stringValue() {
- if (PrimitiveType.TEXT == type || PrimitiveType.JSON == type || PrimitiveType.XML == type) {
- try {
- return new String(bytesValue, "UTF-8");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
+ BytesValueType type = getType();
+ if (BytesValueType.TEXT == type || BytesValueType.JSON == type || BytesValueType.XML == type) {
+ return bytesValue.getValue().toUTF8String();
}
- throw new IllegalStateException(String.format("Expected type [%s] or [%s] or [%s] , but [%s]", PrimitiveType.TEXT,
- PrimitiveType.JSON, PrimitiveType.XML, type));
+ throw new IllegalStateException(String.format("Expected type [%s] or [%s] or [%s] , but [%s]",
+ PrimitiveType.TEXT, BytesValueType.JSON, BytesValueType.XML, type));
}
// // ----------------
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerException.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerException.java
similarity index 87%
rename from source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerException.java
rename to source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerException.java
index cca719cb..9d0dd838 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/LedgerException.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerException.java
@@ -1,4 +1,4 @@
-package com.jd.blockchain.ledger.core;
+package com.jd.blockchain.ledger;
public class LedgerException extends RuntimeException {
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerPermissionException.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerPermissionException.java
new file mode 100644
index 00000000..21b3cee1
--- /dev/null
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/LedgerPermissionException.java
@@ -0,0 +1,15 @@
+package com.jd.blockchain.ledger;
+
+public class LedgerPermissionException extends LedgerException {
+
+ private static final long serialVersionUID = 6077975401474519117L;
+
+ public LedgerPermissionException(String message) {
+ super(message);
+ }
+
+ public LedgerPermissionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PermissionType.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PermissionType.java
new file mode 100644
index 00000000..3f6a4634
--- /dev/null
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PermissionType.java
@@ -0,0 +1,68 @@
+package com.jd.blockchain.ledger;
+
+/**
+ * 权限类型;
+ *
+ * @author huanghaiquan
+ *
+ */
+public enum PermissionType {
+
+ /**
+ * 账户权限配置;
+ */
+ SET_PRIVILEGE(1),
+
+ /**
+ * 注册参与方;
+ */
+ REG_PARTICIPANT(2),
+
+ /**
+ * 配置账本;包括除了{@link #SET_PRIVILEGE}、 {@link #REG_PARTICIPANT} 之外的其它账本设置,例如:设置密码参数、共识参数等;
+ */
+ CONFIG_LEDGER(4),
+
+ /**
+ * 用户注册;
+ */
+ REG_USER(8),
+
+ /**
+ * 注册数据账户;
+ */
+ REG_DATA_ACCOUNT(16),
+
+ /**
+ * 部署新的合约代码;
+ */
+ DEPLOY_CONTRACT(32),
+
+ /**
+ * 写入用户信息;
+ */
+ SET_USER(1024),
+
+ /**
+ * 写入数据;
+ */
+ SET_DATA(2048),
+
+ /**
+ * 写入数据;
+ */
+ INVOKE_CONTRACT(4096),
+
+ /**
+ * 升级合约代码;
+ */
+ UPDATE_CONTRACT(8192);
+
+
+ public final int CODE;
+
+ private PermissionType(int code) {
+ this.CODE = code;
+ }
+
+}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PrivilegeType.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PrivilegeType.java
deleted file mode 100644
index 63e1383d..00000000
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PrivilegeType.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.jd.blockchain.ledger;
-
-/**
- * 权限类型;
- *
- * @author huanghaiquan
- *
- */
-public enum PrivilegeType {
-
- /**
- * 账户注册;
- */
- ACCOUNT_REGISTER(1),
-
- /**
- * 账户权限配置;
- */
- PRIVILEGE_CONFIG(2),
-
- /**
- * 状态数据写入;
- */
- STATE_WRITE(4),
-
- /**
- * 合约应用部署;
- */
- CONTRACT_APP_DEPLOY(8),
-
- /**
- * 合约应用调用;
- */
- CONTRACT_APP_INVOKE(16);
-
- public final int CODE;
-
- private PrivilegeType(int code) {
- this.CODE = code;
- }
-
-}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ValueTypeCastException.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ValueTypeCastException.java
new file mode 100644
index 00000000..30da88cb
--- /dev/null
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/ValueTypeCastException.java
@@ -0,0 +1,17 @@
+package com.jd.blockchain.ledger;
+
+public class ValueTypeCastException extends LedgerException {
+
+
+ private static final long serialVersionUID = 6641080037721006099L;
+
+
+ public ValueTypeCastException(String message) {
+ super(message);
+ }
+
+ public ValueTypeCastException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java
index c8769428..9f2d97d1 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BlockchainOperationFactory.java
@@ -148,43 +148,80 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe
return innerBuilder.getOperation();
}
- @Override
- public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
- innerBuilder.set(key, value, expVersion);
+ private void addOperation() {
if (op == null) {
op = innerBuilder.getOperation();
operationList.add(op);
}
+ }
+
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
+// innerBuilder.set(key, value, expVersion);
+// addOperation();
+// return this;
+// }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) {
+ innerBuilder.setText(key, value, expVersion);
+ addOperation();
return this;
}
@Override
- public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
- innerBuilder.set(key, value, expVersion);
- if (op == null) {
- op = innerBuilder.getOperation();
- operationList.add(op);
- }
+ public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) {
+ innerBuilder.setInt64(key, value, expVersion);
+ addOperation();
return this;
}
@Override
- public DataAccountKVSetOperationBuilder set(String key, long value, long expVersion) {
- innerBuilder.set(key, value, expVersion);
- if (op == null) {
- op = innerBuilder.getOperation();
- operationList.add(op);
- }
+ public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) {
+ innerBuilder.setBytes(key, value, expVersion);
+ addOperation();
return this;
}
@Override
- public DataAccountKVSetOperationBuilder set(String key, Bytes value, long expVersion) {
- innerBuilder.set(key, value, expVersion);
- if (op == null) {
- op = innerBuilder.getOperation();
- operationList.add(op);
- }
+ public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) {
+ innerBuilder.setBytes(key, value, expVersion);
+ addOperation();
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) {
+ innerBuilder.setImage(key, value, expVersion);
+ addOperation();
+ return this;
+ }
+
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
+// innerBuilder.setText(key, value, expVersion);
+// addOperation();
+// return this;
+// }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) {
+ innerBuilder.setJSON(key, value, expVersion);
+ addOperation();
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) {
+ innerBuilder.setXML(key, value, expVersion);
+ addOperation();
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) {
+ innerBuilder.setTimestamp(key, value, expVersion);
+ addOperation();
return this;
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilder.java
index 4e0a903c..f7c9ae8f 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilder.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilder.java
@@ -3,6 +3,10 @@ package com.jd.blockchain.transaction;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
import com.jd.blockchain.utils.Bytes;
+/**
+ * @author huanghaiquan
+ *
+ */
public interface DataAccountKVSetOperationBuilder {
/**
@@ -12,8 +16,22 @@ public interface DataAccountKVSetOperationBuilder {
*/
DataAccountKVSetOperation getOperation();
+// /**
+// * 写入字节数组;
+// *
+// * @param key
+// * 键;
+// * @param value
+// * 值;byte[]格式
+// * @param expVersion
+// * 预期的当前版本;如果版本不匹配,则写入失败;
+// * @return
+// */
+// @Deprecated
+// DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion);
+
/**
- * 写入键值;
+ * 写入字节数组;
*
* @param key
* 键;
@@ -23,7 +41,21 @@ public interface DataAccountKVSetOperationBuilder {
* 预期的当前版本;如果版本不匹配,则写入失败;
* @return
*/
- DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion);
+ DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion);
+
+ /**
+ * 写入字节数组;
+ *
+ * @param key
+ * 键;
+ * @param value
+ * 值;Bytes格式
+ * @param expVersion
+ * 预期的当前版本;如果版本不匹配,则写入失败;
+ * @return
+ */
+ DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion);
+
/**
* 写入键值;
*
@@ -35,21 +67,76 @@ public interface DataAccountKVSetOperationBuilder {
* 预期的当前版本;如果版本不匹配,则写入失败;
* @return
*/
- DataAccountKVSetOperationBuilder set(String key, String value, long expVersion);
+ DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion);
+
+// /**
+// * 写入文本键值;
+// *
+// * @param key
+// * 键;
+// * @param value
+// * 值;String格式
+// * @param expVersion
+// * 预期的当前版本;如果版本不匹配,则写入失败;
+// * @return
+// */
+// @Deprecated
+// DataAccountKVSetOperationBuilder set(String key, String value, long expVersion);
+
/**
- * 写入键值;
+ * 写入文本键值;
*
* @param key
* 键;
* @param value
- * 值;Bytes格式
+ * 值;String格式
* @param expVersion
* 预期的当前版本;如果版本不匹配,则写入失败;
* @return
*/
- DataAccountKVSetOperationBuilder set(String key, Bytes value, long expVersion);
+ DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion);
+
/**
- * 写入键值;
+ * 写入JSON键值;
+ *
+ * @param key
+ * 键;
+ * @param value
+ * 值;String格式
+ * @param expVersion
+ * 预期的当前版本;如果版本不匹配,则写入失败;
+ * @return
+ */
+ DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion);
+
+ /**
+ * 写入XML键值;
+ *
+ * @param key
+ * 键;
+ * @param value
+ * 值;String格式
+ * @param expVersion
+ * 预期的当前版本;如果版本不匹配,则写入失败;
+ * @return
+ */
+ DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion);
+
+ /**
+ * 写入64位整数;
+ *
+ * @param key
+ * 键;
+ * @param value
+ * 值;long格式
+ * @param expVersion
+ * 预期的当前版本;如果版本不匹配,则写入失败;
+ * @return
+ */
+ DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion);
+
+ /**
+ * 写入时间戳;
*
* @param key
* 键;
@@ -59,6 +146,6 @@ public interface DataAccountKVSetOperationBuilder {
* 预期的当前版本;如果版本不匹配,则写入失败;
* @return
*/
- DataAccountKVSetOperationBuilder set(String key, long value, long expVersion);
+ DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion);
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilderImpl.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilderImpl.java
index 537efdf7..d8125022 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilderImpl.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountKVSetOperationBuilderImpl.java
@@ -3,15 +3,12 @@ package com.jd.blockchain.transaction;
import com.jd.blockchain.ledger.BytesValue;
import com.jd.blockchain.ledger.BytesValueEntry;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
-import com.jd.blockchain.ledger.BytesValueType;
import com.jd.blockchain.utils.Bytes;
-import com.jd.blockchain.utils.io.BytesUtils;
-import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils;
-public class DataAccountKVSetOperationBuilderImpl implements DataAccountKVSetOperationBuilder{
-
+public class DataAccountKVSetOperationBuilderImpl implements DataAccountKVSetOperationBuilder {
+
private DataAccountKVSetOpTemplate operation;
-
+
public DataAccountKVSetOperationBuilderImpl(Bytes accountAddress) {
operation = new DataAccountKVSetOpTemplate(accountAddress);
}
@@ -21,35 +18,69 @@ public class DataAccountKVSetOperationBuilderImpl implements DataAccountKVSetOpe
return operation;
}
+// @Deprecated
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
+// return setBytes(key, value, expVersion);
+// }
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, byte[] value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.BYTES, value);
+ public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromBytes(value);
operation.set(key, bytesValue, expVersion);
return this;
}
@Override
- public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
- BytesValue bytesValue;
- if (JSONSerializeUtils.isJSON(value)) {
- bytesValue = new BytesValueEntry(BytesValueType.JSON, BytesUtils.toBytes(value));
- }
- else {
- bytesValue = new BytesValueEntry(BytesValueType.TEXT, BytesUtils.toBytes(value));
- }
+ public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromImage(value);
operation.set(key, bytesValue, expVersion);
return this;
}
+// @Override
+// public DataAccountKVSetOperationBuilder set(String key, String value, long expVersion) {
+// return setText(key, value, expVersion);
+// }
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, Bytes value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.BYTES, value.toBytes());
+ public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromText(value);
operation.set(key, bytesValue, expVersion);
return this;
}
+
+ @Override
+ public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ operation.set(key, bytesValue, expVersion);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromInt64(value);
+ operation.set(key, bytesValue, expVersion);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromJSON(value);
+ operation.set(key, bytesValue, expVersion);
+ return this;
+ }
+
+ @Override
+ public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromXML(value);
+ operation.set(key, bytesValue, expVersion);
+ return this;
+ }
+
@Override
- public DataAccountKVSetOperationBuilder set(String key, long value, long expVersion) {
- BytesValue bytesValue = new BytesValueEntry(BytesValueType.INT64, BytesUtils.toBytes(value));
+ public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) {
+ BytesValue bytesValue = BytesValueEntry.fromTimestamp(value);
operation.set(key, bytesValue, expVersion);
return this;
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountOperator.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountOperator.java
index 7964e7ef..89ea895e 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountOperator.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/DataAccountOperator.java
@@ -13,14 +13,16 @@ public interface DataAccountOperator {
DataAccountRegisterOperationBuilder dataAccounts();
/**
- * 写入数据;
+ * 写入数据;
+ *
* @param accountAddress
* @return
*/
DataAccountKVSetOperationBuilder dataAccount(String accountAddress);
-
+
/**
* 写入数据;
+ *
* @param accountAddress
* @return
*/
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PrivilegeSettingOperationBuilder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PrivilegeSettingOperationBuilder.java
index f2cbab74..f10d77e1 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PrivilegeSettingOperationBuilder.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/PrivilegeSettingOperationBuilder.java
@@ -1,6 +1,6 @@
package com.jd.blockchain.transaction;
-import com.jd.blockchain.ledger.PrivilegeType;
+import com.jd.blockchain.ledger.PermissionType;
/**
* 账户权限设置操作;
@@ -16,10 +16,10 @@ import com.jd.blockchain.ledger.PrivilegeType;
*/
public interface PrivilegeSettingOperationBuilder {
- PrivilegeSettingOperationBuilder setThreshhold(PrivilegeType privilege, long threshhold);
+ PrivilegeSettingOperationBuilder setThreshhold(PermissionType privilege, long threshhold);
- PrivilegeSettingOperationBuilder enable(PrivilegeType privilege, String address, int weight);
+ PrivilegeSettingOperationBuilder enable(PermissionType privilege, String address, int weight);
- PrivilegeSettingOperationBuilder disable(PrivilegeType privilege, String address);
+ PrivilegeSettingOperationBuilder disable(PermissionType privilege, String address);
}
diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountKVSetOpTemplateTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountKVSetOpTemplateTest.java
index c5ccd7f6..005af7c6 100644
--- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountKVSetOpTemplateTest.java
+++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/DataAccountKVSetOpTemplateTest.java
@@ -8,22 +8,21 @@
*/
package test.com.jd.blockchain.ledger.data;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
import com.jd.blockchain.binaryproto.BinaryProtocol;
import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.ledger.BytesValueEntry;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
-import com.jd.blockchain.ledger.BytesValueType;
import com.jd.blockchain.ledger.Operation;
import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate;
import com.jd.blockchain.transaction.KVData;
import com.jd.blockchain.utils.Bytes;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
/**
*
* @author shaozhuguang
@@ -43,11 +42,11 @@ public class DataAccountKVSetOpTemplateTest {
String accountAddress = "zhangsandhakhdkah";
data = new DataAccountKVSetOpTemplate(Bytes.fromString(accountAddress));
KVData kvData1 =
- new KVData("test1", new BytesValueEntry(BytesValueType.TEXT, "zhangsan".getBytes()), 9999L);
+ new KVData("test1", BytesValueEntry.fromText("zhangsan"), 9999L);
KVData kvData2 =
- new KVData("test2", new BytesValueEntry(BytesValueType.TEXT, "lisi".getBytes()), 9990L);
+ new KVData("test2", BytesValueEntry.fromText("lisi"), 9990L);
KVData kvData3 =
- new KVData("test3", new BytesValueEntry(BytesValueType.TEXT, "wangwu".getBytes()), 1990L);
+ new KVData("test3", BytesValueEntry.fromText("wangwu"), 1990L);
data.set(kvData1);
data.set(kvData2);
data.set(kvData3);
diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/KVDataTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/KVDataTest.java
index 86314a6f..39824505 100644
--- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/KVDataTest.java
+++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/KVDataTest.java
@@ -8,20 +8,19 @@
*/
package test.com.jd.blockchain.ledger.data;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+
import com.jd.blockchain.binaryproto.BinaryProtocol;
import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.ledger.BytesValueEntry;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
-import com.jd.blockchain.ledger.BytesValueType;
import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate;
import com.jd.blockchain.transaction.KVData;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
/**
*
* @author shaozhuguang
@@ -30,26 +29,26 @@ import static org.junit.Assert.assertEquals;
*/
public class KVDataTest {
- private KVData kvData;
-
- @Before
- public void initKVData() throws Exception {
- DataContractRegistry.register(DataAccountKVSetOperation.KVWriteEntry.class);
- String key = "test-key";
- byte[] value = "test-value".getBytes();
- long expectedVersion = 9999L;
-
- kvData = new KVData(key, new BytesValueEntry(BytesValueType.BYTES, value), expectedVersion);
- }
-
- @Test
- public void testSerialize_KVEntry() throws Exception {
- byte[] serialBytes = BinaryProtocol.encode(kvData, DataAccountKVSetOperation.KVWriteEntry.class);
- DataAccountKVSetOpTemplate.KVWriteEntry resolvedKvData = BinaryProtocol.decode(serialBytes);
- System.out.println("------Assert start ------");
- assertEquals(resolvedKvData.getKey(), kvData.getKey());
- assertEquals(resolvedKvData.getExpectedVersion(), kvData.getExpectedVersion());
- assertArrayEquals(resolvedKvData.getValue().getValue().toBytes(), kvData.getValue().getValue().toBytes());
- System.out.println("------Assert OK ------");
- }
+ private KVData kvData;
+
+ @Before
+ public void initKVData() throws Exception {
+ DataContractRegistry.register(DataAccountKVSetOperation.KVWriteEntry.class);
+ String key = "test-key";
+ byte[] value = "test-value".getBytes();
+ long expectedVersion = 9999L;
+
+ kvData = new KVData(key, BytesValueEntry.fromBytes(value), expectedVersion);
+ }
+
+ @Test
+ public void testSerialize_KVEntry() throws Exception {
+ byte[] serialBytes = BinaryProtocol.encode(kvData, DataAccountKVSetOperation.KVWriteEntry.class);
+ DataAccountKVSetOpTemplate.KVWriteEntry resolvedKvData = BinaryProtocol.decode(serialBytes);
+ System.out.println("------Assert start ------");
+ assertEquals(resolvedKvData.getKey(), kvData.getKey());
+ assertEquals(resolvedKvData.getExpectedVersion(), kvData.getExpectedVersion());
+ assertArrayEquals(resolvedKvData.getValue().getValue().toBytes(), kvData.getValue().getValue().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/data/TxContentBlobTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java
index a76e4e93..fc4120d3 100644
--- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java
+++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxContentBlobTest.java
@@ -22,7 +22,6 @@ import com.jd.blockchain.ledger.TransactionContent;
import com.jd.blockchain.ledger.TransactionContentBody;
import com.jd.blockchain.transaction.BlockchainOperationFactory;
import com.jd.blockchain.transaction.TxContentBlob;
-import com.jd.blockchain.utils.io.ByteArray;
public class TxContentBlobTest {
@@ -48,7 +47,7 @@ public class TxContentBlobTest {
contentBlob.setHash(contentHash);
DataAccountKVSetOperation kvsetOP = opFactory.dataAccount(id.getAddress())
- .set("Name", ByteArray.fromString("AAA", "UTF-8"), -1).getOperation();
+ .setText("Name", "AAA", -1).getOperation();
contentBlob.addOperation(kvsetOP);
}
diff --git a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java
index dd7366f9..6083089f 100644
--- a/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java
+++ b/source/ledger/ledger-model/src/test/java/test/com/jd/blockchain/ledger/data/TxRequestMessageTest.java
@@ -37,7 +37,6 @@ import com.jd.blockchain.transaction.BlockchainOperationFactory;
import com.jd.blockchain.transaction.DigitalSignatureBlob;
import com.jd.blockchain.transaction.TxContentBlob;
import com.jd.blockchain.transaction.TxRequestMessage;
-import com.jd.blockchain.utils.io.ByteArray;
/**
*
@@ -204,7 +203,7 @@ public class TxRequestMessageTest {
// contentBlob.setSubjectAccount(id.getAddress());
// contentBlob.setSequenceNumber(1);
DataAccountKVSetOperation kvsetOP = opFactory.dataAccount(id.getAddress())
- .set("Name", ByteArray.fromString("AAA", "UTF-8"), -1).getOperation();
+ .setText("Name","AAA", -1).getOperation();
contentBlob.addOperation(kvsetOP);
return contentBlob;
}
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 222d7bf6..01c2ef61 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
@@ -1,14 +1,31 @@
package com.jd.blockchain.peer.web;
-import com.jd.blockchain.contract.ContractException;
-import com.jd.blockchain.ledger.*;
-import com.jd.blockchain.utils.StringUtils;
+import java.util.ArrayList;
+import java.util.List;
+
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
-import com.jd.blockchain.binaryproto.BinaryProtocol;
-import com.jd.blockchain.binaryproto.PrimitiveType;
+import com.jd.blockchain.contract.ContractException;
import com.jd.blockchain.crypto.HashDigest;
+import com.jd.blockchain.ledger.AccountHeader;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.KVDataEntry;
+import com.jd.blockchain.ledger.KVDataObject;
+import com.jd.blockchain.ledger.KVDataVO;
+import com.jd.blockchain.ledger.KVInfoVO;
+import com.jd.blockchain.ledger.LedgerBlock;
+import com.jd.blockchain.ledger.LedgerInfo;
+import com.jd.blockchain.ledger.LedgerMetadata;
+import com.jd.blockchain.ledger.LedgerTransaction;
+import com.jd.blockchain.ledger.ParticipantNode;
+import com.jd.blockchain.ledger.TransactionState;
+import com.jd.blockchain.ledger.UserInfo;
import com.jd.blockchain.ledger.core.ContractAccountSet;
import com.jd.blockchain.ledger.core.DataAccount;
import com.jd.blockchain.ledger.core.DataAccountSet;
@@ -22,15 +39,12 @@ import com.jd.blockchain.transaction.BlockchainQueryService;
import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.QueryUtil;
-import java.util.ArrayList;
-import java.util.List;
-
@RestController
@RequestMapping(path = "/")
public class LedgerQueryController implements BlockchainQueryService {
-
- @Autowired
- private LedgerService ledgerService;
+
+ @Autowired
+ private LedgerService ledgerService;
@RequestMapping(method = RequestMethod.GET, path = "ledgers")
@Override
@@ -42,7 +56,8 @@ public class LedgerQueryController implements BlockchainQueryService {
@Override
public LedgerInfo getLedger(@PathVariable(name = "ledgerHash") HashDigest ledgerHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
- //TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
+ // TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher
+ // ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
LedgerInfo ledgerInfo = new LedgerInfo();
ledgerInfo.setHash(ledgerHash);
ledgerInfo.setLatestBlockHash(ledger.getLatestBlockHash());
@@ -83,25 +98,27 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}")
@Override
public LedgerBlock getBlock(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long blockHeight) {
+ @PathVariable(name = "blockHeight") long blockHeight) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
- //TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
+ // TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher
+ // ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
return ledger.getBlock(blockHeight);
}
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}")
@Override
public LedgerBlock getBlock(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash) {
+ @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
- //TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
+ // TODO: 需要配置返回值的 spring MsgQueueMessageDispatcher
+ // ,对返回对象仅仅序列化声明的返回值类型的属性,而不是整个对象本身;
return ledger.getBlock(blockHash);
}
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/txs/count")
@Override
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long blockHeight) {
+ @PathVariable(name = "blockHeight") long blockHeight) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHeight);
TransactionSet txSet = ledger.getTransactionSet(block);
@@ -111,7 +128,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/txs/count")
@Override
public long getTransactionCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash) {
+ @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash);
TransactionSet txSet = ledger.getTransactionSet(block);
@@ -130,7 +147,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/accounts/count")
@Override
public long getDataAccountCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long height) {
+ @PathVariable(name = "blockHeight") long height) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height);
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
@@ -140,7 +157,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/accounts/count")
@Override
public long getDataAccountCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash) {
+ @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash);
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
@@ -159,7 +176,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/users/count")
@Override
public long getUserCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long height) {
+ @PathVariable(name = "blockHeight") long height) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height);
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
@@ -169,7 +186,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/users/count")
@Override
public long getUserCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash) {
+ @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash);
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
@@ -188,7 +205,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/contracts/count")
@Override
public long getContractCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long height) {
+ @PathVariable(name = "blockHeight") long height) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(height);
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
@@ -198,7 +215,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/contracts/count")
@Override
public long getContractCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash) {
+ @PathVariable(name = "blockHash") HashDigest blockHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getBlock(blockHash);
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
@@ -217,9 +234,9 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/height/{blockHeight}/txs")
@Override
public LedgerTransaction[] getTransactions(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHeight") long blockHeight,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ @PathVariable(name = "blockHeight") long blockHeight,
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHeight);
@@ -230,8 +247,8 @@ public class LedgerQueryController implements BlockchainQueryService {
lastHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(blockHeight - 1)).getTotalCount();
}
- int currentHeightTxTotalNums = (int)ledger.getTransactionSet(ledger.getBlock(blockHeight)).getTotalCount();
- //取当前高度的增量交易数,在增量交易里进行查找
+ int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(blockHeight)).getTotalCount();
+ // 取当前高度的增量交易数,在增量交易里进行查找
int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
// if (fromIndex < 0 || fromIndex >= currentHeightTxNums) {
@@ -245,15 +262,15 @@ public class LedgerQueryController implements BlockchainQueryService {
// count = currentHeightTxNums - fromIndex;
// }
int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
- return transactionSet.getTxs(lastHeightTxTotalNums + indexAndCount[0] , indexAndCount[1]);
+ return transactionSet.getTxs(lastHeightTxTotalNums + indexAndCount[0], indexAndCount[1]);
}
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/blocks/hash/{blockHash}/txs")
@Override
public LedgerTransaction[] getTransactions(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "blockHash") HashDigest blockHash,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ @PathVariable(name = "blockHash") HashDigest blockHash,
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock ledgerBlock = ledger.getBlock(blockHash);
long height = ledgerBlock.getHeight();
@@ -264,8 +281,8 @@ public class LedgerQueryController implements BlockchainQueryService {
lastHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(height - 1)).getTotalCount();
}
- int currentHeightTxTotalNums = (int)ledger.getTransactionSet(ledger.getBlock(height)).getTotalCount();
- //取当前块hash的增量交易数,在增量交易里进行查找
+ int currentHeightTxTotalNums = (int) ledger.getTransactionSet(ledger.getBlock(height)).getTotalCount();
+ // 取当前块hash的增量交易数,在增量交易里进行查找
int currentHeightTxNums = currentHeightTxTotalNums - lastHeightTxTotalNums;
// if (fromIndex < 0 || fromIndex >= currentHeightTxNums) {
@@ -279,13 +296,13 @@ public class LedgerQueryController implements BlockchainQueryService {
// count = currentHeightTxNums - fromIndex;
// }
int indexAndCount[] = QueryUtil.calFromIndexAndCount(fromIndex, count, currentHeightTxNums);
- return transactionSet.getTxs(lastHeightTxTotalNums + indexAndCount[0] , indexAndCount[1]);
+ return transactionSet.getTxs(lastHeightTxTotalNums + indexAndCount[0], indexAndCount[1]);
}
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/txs/{contentHash}")
@Override
public LedgerTransaction getTransactionByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "contentHash")HashDigest contentHash) {
+ @PathVariable(name = "contentHash") HashDigest contentHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
@@ -295,7 +312,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/txs/state/{contentHash}")
@Override
public TransactionState getTransactionStateByContentHash(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "contentHash") HashDigest contentHash) {
+ @PathVariable(name = "contentHash") HashDigest contentHash) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
TransactionSet txset = ledger.getTransactionSet(block);
@@ -305,7 +322,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users/address/{address}")
@Override
public UserInfo getUser(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address) {
+ @PathVariable(name = "address") String address) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
UserAccountSet userAccountSet = ledger.getUserAccountSet(block);
@@ -315,18 +332,18 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}")
@Override
public AccountHeader getDataAccount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address) {
+ @PathVariable(name = "address") String address) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
return dataAccountSet.getDataAccount(Bytes.fromBase58(address));
}
- @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, path = "ledgers/{ledgerHash}/accounts/{address}/entries")
+ @RequestMapping(method = { RequestMethod.GET,
+ RequestMethod.POST }, path = "ledgers/{ledgerHash}/accounts/{address}/entries")
@Override
public KVDataEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address,
- @RequestParam("keys") String... keys) {
+ @PathVariable(name = "address") String address, @RequestParam("keys") String... keys) {
if (keys == null || keys.length == 0) {
return null;
}
@@ -334,51 +351,50 @@ public class LedgerQueryController implements BlockchainQueryService {
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
DataAccount dataAccount = dataAccountSet.getDataAccount(Bytes.fromBase58(address));
-
+
KVDataEntry[] entries = new KVDataEntry[keys.length];
long ver;
for (int i = 0; i < entries.length; i++) {
ver = dataAccount.getDataVersion(Bytes.fromString(keys[i]));
if (ver < 0) {
- entries[i] = new KVDataObject(keys[i], -1, PrimitiveType.NIL, null);
- }else {
- byte[] value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
- BytesValue decodeData = BinaryProtocol.decode(value);
- entries[i] = new KVDataObject(keys[i], ver, PrimitiveType.valueOf(decodeData.getType().CODE), decodeData.getValue().toBytes());
+ entries[i] = new KVDataObject(keys[i], -1, null);
+ } else {
+ BytesValue value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
+ entries[i] = new KVDataObject(keys[i], ver, value);
}
}
-
+
return entries;
}
- @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, path = "ledgers/{ledgerHash}/accounts/{address}/entries-version")
+ @RequestMapping(method = { RequestMethod.GET,
+ RequestMethod.POST }, path = "ledgers/{ledgerHash}/accounts/{address}/entries-version")
@Override
public KVDataEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address,
- @RequestBody KVInfoVO kvInfoVO) {
- //parse kvInfoVO;
- List keyList = new ArrayList<>();
- List versionList = new ArrayList<>();
- if(kvInfoVO != null){
- for(KVDataVO kvDataVO : kvInfoVO.getData()){
- for(Long version : kvDataVO.getVersion()){
- keyList.add(kvDataVO.getKey());
- versionList.add(version);
- }
- }
- }
- String[] keys = keyList.toArray(new String[keyList.size()]);
- Long[] versions = versionList.toArray(new Long[versionList.size()]);
+ @PathVariable(name = "address") String address, @RequestBody KVInfoVO kvInfoVO) {
+ // parse kvInfoVO;
+ List keyList = new ArrayList<>();
+ List versionList = new ArrayList<>();
+ if (kvInfoVO != null) {
+ for (KVDataVO kvDataVO : kvInfoVO.getData()) {
+ for (Long version : kvDataVO.getVersion()) {
+ keyList.add(kvDataVO.getKey());
+ versionList.add(version);
+ }
+ }
+ }
+ String[] keys = keyList.toArray(new String[keyList.size()]);
+ Long[] versions = versionList.toArray(new Long[versionList.size()]);
if (keys == null || keys.length == 0) {
- return null;
+ return null;
}
if (versions == null || versions.length == 0) {
return null;
}
- if(keys.length != versions.length){
- throw new ContractException("keys.length!=versions.length!");
- }
+ if (keys.length != versions.length) {
+ throw new ContractException("keys.length!=versions.length!");
+ }
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
@@ -389,18 +405,17 @@ public class LedgerQueryController implements BlockchainQueryService {
long ver = -1;
for (int i = 0; i < entries.length; i++) {
// ver = dataAccount.getDataVersion(Bytes.fromString(keys[i]));
- ver = versions[i];
+ ver = versions[i];
if (ver < 0) {
- entries[i] = new KVDataObject(keys[i], -1, PrimitiveType.NIL, null);
- }else {
- if(dataAccount.getDataEntriesTotalCount()==0 ||
- dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null){
- //is the address is not exist; the result is null;
- entries[i] = new KVDataObject(keys[i], -1, PrimitiveType.NIL, null);
+ entries[i] = new KVDataObject(keys[i], -1, null);
+ } else {
+ if (dataAccount.getDataEntriesTotalCount() == 0
+ || dataAccount.getBytes(Bytes.fromString(keys[i]), ver) == null) {
+ // is the address is not exist; the result is null;
+ entries[i] = new KVDataObject(keys[i], -1, null);
} else {
- byte[] value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
- BytesValue decodeData = BinaryProtocol.decode(value);
- entries[i] = new KVDataObject(keys[i], ver, PrimitiveType.valueOf(decodeData.getType().CODE), decodeData.getValue().toBytes());
+ BytesValue value = dataAccount.getBytes(Bytes.fromString(keys[i]), ver);
+ entries[i] = new KVDataObject(keys[i], ver, value);
}
}
}
@@ -408,12 +423,13 @@ public class LedgerQueryController implements BlockchainQueryService {
return entries;
}
- @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, path = "ledgers/{ledgerHash}/accounts/address/{address}/entries")
+ @RequestMapping(method = { RequestMethod.GET,
+ RequestMethod.POST }, path = "ledgers/{ledgerHash}/accounts/address/{address}/entries")
@Override
public KVDataEntry[] getDataEntries(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ @PathVariable(name = "address") String address,
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
@@ -426,7 +442,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts/address/{address}/entries/count")
@Override
public long getDataEntriesTotalCount(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address) {
+ @PathVariable(name = "address") String address) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
@@ -439,7 +455,7 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts/address/{address}")
@Override
public AccountHeader getContract(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @PathVariable(name = "address") String address) {
+ @PathVariable(name = "address") String address) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
@@ -448,6 +464,7 @@ public class LedgerQueryController implements BlockchainQueryService {
/**
* get more users by fromIndex and count;
+ *
* @param ledgerHash
* @param fromIndex
* @param count
@@ -456,44 +473,45 @@ public class LedgerQueryController implements BlockchainQueryService {
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/users")
@Override
public AccountHeader[] getUsers(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
UserAccountSet 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.getTotalCount());
+ return userAccountSet.getAccounts(pages[0], pages[1]);
}
/**
* get more dataAccounts by fromIndex and count;
+ *
* @param ledgerHash
* @param fromIndex
* @param count
* @return
*/
@RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/accounts")
- @Override
+ @Override
public AccountHeader[] getDataAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
LedgerBlock block = ledger.getLatestBlock();
DataAccountSet dataAccountSet = ledger.getDataAccountSet(block);
- int pages[] = QueryUtil.calFromIndexAndCount(fromIndex,count,(int)dataAccountSet.getTotalCount());
- return dataAccountSet.getAccounts(pages[0],pages[1]);
- }
-
- @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts")
- @Override
- public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
- @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
- @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
- LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
- LedgerBlock block = ledger.getLatestBlock();
- ContractAccountSet 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) dataAccountSet.getTotalCount());
+ return dataAccountSet.getAccounts(pages[0], pages[1]);
+ }
+
+ @RequestMapping(method = RequestMethod.GET, path = "ledgers/{ledgerHash}/contracts")
+ @Override
+ public AccountHeader[] getContractAccounts(@PathVariable(name = "ledgerHash") HashDigest ledgerHash,
+ @RequestParam(name = "fromIndex", required = false, defaultValue = "0") int fromIndex,
+ @RequestParam(name = "count", required = false, defaultValue = "-1") int count) {
+ LedgerRepository ledger = ledgerService.getLedger(ledgerHash);
+ LedgerBlock block = ledger.getLatestBlock();
+ ContractAccountSet contractAccountSet = ledger.getContractAccountSet(block);
+ int pages[] = QueryUtil.calFromIndexAndCount(fromIndex, count, (int) contractAccountSet.getTotalCount());
+ return contractAccountSet.getAccounts(pages[0], pages[1]);
+ }
}
diff --git a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/PrivilegeSetting.java b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/PrivilegeSetting.java
index c78ee579..deafc113 100644
--- a/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/PrivilegeSetting.java
+++ b/source/sdk/sdk-base/src/main/java/com/jd/blockchain/sdk/PrivilegeSetting.java
@@ -1,6 +1,6 @@
package com.jd.blockchain.sdk;
-import com.jd.blockchain.ledger.PrivilegeType;
+import com.jd.blockchain.ledger.PermissionType;
/**
* 权限设置;
@@ -16,6 +16,6 @@ public interface PrivilegeSetting {
long getMask(String address);
- boolean isEnable(String address, PrivilegeType privilege);
+ boolean isEnable(String address, PermissionType privilege);
}
diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/contract/samples/AssetContractImpl.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/contract/samples/AssetContractImpl.java
index ab644986..770f78c4 100644
--- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/contract/samples/AssetContractImpl.java
+++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/contract/samples/AssetContractImpl.java
@@ -11,7 +11,6 @@ import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.KVDataEntry;
import com.jd.blockchain.ledger.KVDataObject;
-import com.jd.blockchain.utils.io.BytesUtils;
/**
* 示例:一个“资产管理”智能合约的实现;
@@ -53,14 +52,14 @@ public class AssetContractImpl implements EventProcessingAwire, AssetContract {
// 计算资产的发行总数;
KVDataObject currTotal = (KVDataObject) kvEntries[0];
long newTotal = currTotal.longValue() + amount;
- eventContext.getLedger().dataAccount(ASSET_ADDRESS).set(KEY_TOTAL, BytesUtils.toBytes(newTotal),
+ eventContext.getLedger().dataAccount(ASSET_ADDRESS).setInt64(KEY_TOTAL, newTotal,
currTotal.getVersion());
// 分配到持有者账户;
KVDataObject holderAmount = (KVDataObject) kvEntries[1];
long newHodlerAmount = holderAmount.longValue() + amount;
- eventContext.getLedger().dataAccount(ASSET_ADDRESS).set(assetHolderAddress, BytesUtils.toBytes(newHodlerAmount),
- holderAmount.getVersion()).set("K2", (byte[])null, -1).set("k3", (byte[])null, 3);
+ eventContext.getLedger().dataAccount(ASSET_ADDRESS).setInt64(assetHolderAddress, newHodlerAmount,
+ holderAmount.getVersion()).setText("K2", "info2", -1).setText("k3", "info3", 3);
}
diff --git a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java
index abe4bc2a..59d94201 100644
--- a/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java
+++ b/source/sdk/sdk-samples/src/main/java/com/jd/blockchain/sdk/samples/SDKDemo_InsertData.java
@@ -59,7 +59,7 @@ public class SDKDemo_InsertData {
// 对象将被序列化为 JSON 形式存储,并基于 JSON 结构建立查询索引;
String commodityDataAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
Commodity commodity1 = new Commodity();
- txTemp.dataAccount(commodityDataAccount).set("ASSET_CODE", commodity1.getCode().getBytes(), -1);
+ txTemp.dataAccount(commodityDataAccount).setText("ASSET_CODE", commodity1.getCode(), -1);
// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();
diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java
index 644bf609..747c835e 100644
--- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java
+++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java
@@ -87,13 +87,13 @@ public class SDK_GateWay_BatchInsertData_Test_ {
String dataAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
String key1 = "jd_key1";
- byte[] val1 = "www.jd.com".getBytes();
+ String val1 = "www.jd.com";
String key2 = "jd_key2";
- byte[] val2 = "www.jd.com".getBytes();
+ String val2 = "www.jd.com";
- txTemp.dataAccount(dataAccount).set(key1, val1, -1);
- txTemp.dataAccount(dataAccount).set(key2, val2, -1);
+ txTemp.dataAccount(dataAccount).setText(key1, val1, -1);
+ txTemp.dataAccount(dataAccount).setText(key2, val2, -1);
// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();
diff --git a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java
index 07dba29f..ed6567e9 100644
--- a/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java
+++ b/source/sdk/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java
@@ -84,9 +84,9 @@ public class SDK_GateWay_InsertData_Test_ {
String dataAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
String dataKey = "jd_code";
- byte[] dataVal = "www.jd.com".getBytes();
+ String dataVal = "www.jd.com";
- txTemp.dataAccount(dataAccount).set(dataKey, dataVal, -1);
+ txTemp.dataAccount(dataAccount).setText(dataKey, dataVal, -1);
// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();
diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java
index c3c80a9a..f8899ec6 100644
--- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java
+++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/IntegrationTest.java
@@ -1,13 +1,39 @@
package test.com.jd.blockchain.intgr;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+
+import org.springframework.core.io.ClassPathResource;
+
import com.jd.blockchain.consensus.ConsensusProvider;
import com.jd.blockchain.consensus.ConsensusProviders;
import com.jd.blockchain.consensus.ConsensusSettings;
+import com.jd.blockchain.crypto.AddressEncoding;
import com.jd.blockchain.crypto.AsymmetricKeypair;
+import com.jd.blockchain.crypto.Crypto;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PrivKey;
+import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.gateway.GatewayConfigProperties.KeyPairConfig;
-import com.jd.blockchain.ledger.*;
+import com.jd.blockchain.ledger.AccountHeader;
+import com.jd.blockchain.ledger.BlockchainKeyGenerator;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.DataAccountKVSetOperation;
+import com.jd.blockchain.ledger.KVDataEntry;
+import com.jd.blockchain.ledger.LedgerBlock;
+import com.jd.blockchain.ledger.LedgerInfo;
+import com.jd.blockchain.ledger.ParticipantNode;
+import com.jd.blockchain.ledger.PreparedTransaction;
+import com.jd.blockchain.ledger.TransactionResponse;
+import com.jd.blockchain.ledger.TransactionTemplate;
+import com.jd.blockchain.ledger.UserInfo;
+import com.jd.blockchain.ledger.core.DataAccountSet;
import com.jd.blockchain.ledger.core.LedgerManage;
import com.jd.blockchain.ledger.core.LedgerRepository;
import com.jd.blockchain.ledger.core.impl.LedgerManager;
@@ -23,18 +49,10 @@ import com.jd.blockchain.utils.Bytes;
import com.jd.blockchain.utils.codec.HexUtils;
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback;
import com.jd.blockchain.utils.net.NetworkAddress;
-import org.springframework.core.io.ClassPathResource;
+
import test.com.jd.blockchain.intgr.IntegratedContext.Node;
import test.com.jd.blockchain.intgr.perf.LedgerInitializeWebTest;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-
public class IntegrationTest {
// 合约测试使用的初始化数据;
BlockchainKeypair contractDataKey = BlockchainKeyGenerator.getInstance().generate();
@@ -179,9 +197,9 @@ public class IntegrationTest {
String dataAccount = dataAccountAddress;
String dataKey = "jingdong" + new Random().nextInt(100000);
- byte[] dataVal = "www.jd.com".getBytes();
+ String dataVal = "www.jd.com";
- txTemp.dataAccount(dataAccount).set(dataKey, dataVal, -1);
+ txTemp.dataAccount(dataAccount).setText(dataKey, dataVal, -1);
// TX 准备就绪;
PreparedTransaction prepTx = txTemp.prepare();
@@ -530,87 +548,87 @@ public class IntegrationTest {
}
}
-// private LedgerBlock testSDK_Contract(AsymmetricKeypair adminKey, HashDigest ledgerHash,
-// BlockchainService blockchainService, IntegratedContext context) {
-// // valid the basic data in contract;
-// prepareContractData(adminKey, ledgerHash, blockchainService, context);
-//
-// BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate();
-//
-// // 定义交易;
-// TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
-// byte[] contractCode = getChainCodeBytes();
-//
-// txTpl.users().register(userKey.getIdentity());
-//
-// txTpl.contracts().deploy(contractDeployKey.getIdentity(), contractCode);
-//
-// // 签名;
-// PreparedTransaction ptx = txTpl.prepare();
-// ptx.sign(adminKey);
-//
-// // 提交并等待共识返回;
-// TransactionResponse txResp = ptx.commit();
-//
-// // 验证结果;
-// txResp.getContentHash();
-//
-// Node node0 = context.getNode(0);
-// LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
-// LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight());
-// byte[] contractCodeInDb = ledgerOfNode0.getContractAccountSet(block).getContract(contractDeployKey.getAddress())
-// .getChainCode();
-// txContentHash = ptx.getHash();
-//
-// // execute the contract;
-// testContractExe(adminKey, ledgerHash, userKey, blockchainService, context);
-//
-// return block;
-// }
-
-// private void testContractExe(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainKeypair userKey,
-// BlockchainService blockchainService, IntegratedContext context) {
-// LedgerInfo ledgerInfo = blockchainService.getLedger(ledgerHash);
-// LedgerBlock previousBlock = blockchainService.getBlock(ledgerHash, ledgerInfo.getLatestBlockHeight() - 1);
-//
-// // 定义交易;
-// TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
-//
-// txTpl.contractEvents().send(contractDeployKey.getAddress(), eventName,
-// ("888##abc##" + contractDataKey.getAddress() + "##" + previousBlock.getHash().toBase58() + "##"
-// + userKey.getAddress() + "##" + contractDeployKey.getAddress() + "##" + txContentHash.toBase58()
-// + "##SOME-VALUE").getBytes());
-//
-// // 签名;
-// PreparedTransaction ptx = txTpl.prepare();
-// ptx.sign(adminKey);
-//
-// // 提交并等待共识返回;
-// TransactionResponse txResp = ptx.commit();
-//
-// // 验证结果;
-// txResp.getContentHash();
-//
-// LedgerInfo latestLedgerInfo = blockchainService.getLedger(ledgerHash);
-//
-// Node node0 = context.getNode(0);
-// LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
-// LedgerBlock backgroundLedgerBlock = ledgerOfNode0.retrieveLatestBlock();
-//
-// // 验证合约中的赋值,外部可以获得;
-// DataAccountSet dataAccountSet = ledgerOfNode0.getDataAccountSet(backgroundLedgerBlock);
-// AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair();
-// PubKey pubKey = key.getPubKey();
-// Bytes dataAddress = AddressEncoding.generateAddress(pubKey);
-//
-// // 验证userAccount,从合约内部赋值,然后外部验证;由于目前不允许输入重复的key,所以在内部合约中构建的key,不便于在外展示,屏蔽之;
-// // UserAccountSet userAccountSet =
-// // ledgerOfNode0.getUserAccountSet(backgroundLedgerBlock);
-// // PubKey userPubKey = new PubKey(CryptoAlgorithm.ED25519,
-// // userPubKeyVal.getBytes());
-// // String userAddress = AddressEncoding.generateAddress(userPubKey);
-// // assertEquals(userAddress, userAccountSet.getUser(userAddress).getAddress());
-// }
+ private LedgerBlock testSDK_Contract(AsymmetricKeypair adminKey, HashDigest ledgerHash,
+ BlockchainService blockchainService, IntegratedContext context) {
+ // valid the basic data in contract;
+ prepareContractData(adminKey, ledgerHash, blockchainService, context);
+
+ BlockchainKeypair userKey = BlockchainKeyGenerator.getInstance().generate();
+
+ // 定义交易;
+ TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
+ byte[] contractCode = getChainCodeBytes();
+
+ txTpl.users().register(userKey.getIdentity());
+
+ txTpl.contracts().deploy(contractDeployKey.getIdentity(), contractCode);
+
+ // 签名;
+ PreparedTransaction ptx = txTpl.prepare();
+ ptx.sign(adminKey);
+
+ // 提交并等待共识返回;
+ TransactionResponse txResp = ptx.commit();
+
+ // 验证结果;
+ txResp.getContentHash();
+
+ Node node0 = context.getNode(0);
+ LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
+ LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight());
+ byte[] contractCodeInDb = ledgerOfNode0.getContractAccountSet(block).getContract(contractDeployKey.getAddress())
+ .getChainCode();
+ txContentHash = ptx.getHash();
+
+ // execute the contract;
+ testContractExe(adminKey, ledgerHash, userKey, blockchainService, context);
+
+ return block;
+ }
+
+ private void testContractExe(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainKeypair userKey,
+ BlockchainService blockchainService, IntegratedContext context) {
+ LedgerInfo ledgerInfo = blockchainService.getLedger(ledgerHash);
+ LedgerBlock previousBlock = blockchainService.getBlock(ledgerHash, ledgerInfo.getLatestBlockHeight() - 1);
+
+ // 定义交易;
+ TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
+
+ txTpl.contractEvents().send(contractDeployKey.getAddress(), eventName,
+ ("888##abc##" + contractDataKey.getAddress() + "##" + previousBlock.getHash().toBase58() + "##"
+ + userKey.getAddress() + "##" + contractDeployKey.getAddress() + "##" + txContentHash.toBase58()
+ + "##SOME-VALUE").getBytes());
+
+ // 签名;
+ PreparedTransaction ptx = txTpl.prepare();
+ ptx.sign(adminKey);
+
+ // 提交并等待共识返回;
+ TransactionResponse txResp = ptx.commit();
+
+ // 验证结果;
+ txResp.getContentHash();
+
+ LedgerInfo latestLedgerInfo = blockchainService.getLedger(ledgerHash);
+
+ Node node0 = context.getNode(0);
+ LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
+ LedgerBlock backgroundLedgerBlock = ledgerOfNode0.retrieveLatestBlock();
+
+ // 验证合约中的赋值,外部可以获得;
+ DataAccountSet dataAccountSet = ledgerOfNode0.getDataAccountSet(backgroundLedgerBlock);
+ AsymmetricKeypair key = Crypto.getSignatureFunction("ED25519").generateKeypair();
+ PubKey pubKey = key.getPubKey();
+ Bytes dataAddress = AddressEncoding.generateAddress(pubKey);
+
+ // 验证userAccount,从合约内部赋值,然后外部验证;由于目前不允许输入重复的key,所以在内部合约中构建的key,不便于在外展示,屏蔽之;
+ // UserAccountSet userAccountSet =
+ // ledgerOfNode0.getUserAccountSet(backgroundLedgerBlock);
+ // PubKey userPubKey = new PubKey(CryptoAlgorithm.ED25519,
+ // userPubKeyVal.getBytes());
+ // String userAddress = AddressEncoding.generateAddress(userPubKey);
+ // assertEquals(userAddress, userAccountSet.getUser(userAddress).getAddress());
+ }
private void prepareContractData(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainService blockchainService,
IntegratedContext context) {
@@ -620,11 +638,11 @@ public class IntegrationTest {
// 注册数据账户,并验证最终写入;
txTpl.dataAccounts().register(contractDataKey.getIdentity());
DataAccountKVSetOperation kvsetOP = txTpl.dataAccount(contractDataKey.getAddress())
- .set("A", "Value_A_0".getBytes(), -1).set("B", "Value_B_0".getBytes(), -1)
- .set(KEY_TOTAL, "total value,dataAccount".getBytes(), -1)
- .set(KEY_ABC, "abc value,dataAccount".getBytes(), -1)
+ .setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1)
+ .setText(KEY_TOTAL, "total value,dataAccount", -1)
+ .setText(KEY_ABC, "abc value,dataAccount", -1)
// 所有的模拟数据都在这个dataAccount中填充;
- .set("ledgerHash", ledgerHash.getRawDigest(), -1).getOperation();
+ .setBytes("ledgerHash", ledgerHash.getRawDigest(), -1).getOperation();
// 签名;
PreparedTransaction ptx = txTpl.prepare();
@@ -638,9 +656,9 @@ public class IntegrationTest {
LedgerRepository ledgerOfNode0 = node0.getLedgerManager().getLedger(ledgerHash);
LedgerBlock block = ledgerOfNode0.getBlock(txResp.getBlockHeight());
- byte[] val1InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
+ BytesValue val1InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
.getBytes("A");
- byte[] val2InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
+ BytesValue val2InDb = ledgerOfNode0.getDataAccountSet(block).getDataAccount(contractDataKey.getAddress())
.getBytes(KEY_TOTAL);
}
diff --git a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java
index bb567b9b..1e318f97 100644
--- a/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java
+++ b/source/test/test-integration/src/main/java/test/com/jd/blockchain/intgr/perf/LedgerPerformanceTest.java
@@ -16,9 +16,9 @@ import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.consensus.ConsensusProvider;
import com.jd.blockchain.consensus.ConsensusProviders;
import com.jd.blockchain.consensus.ConsensusSettings;
-import com.jd.blockchain.crypto.CryptoAlgorithm;
import com.jd.blockchain.crypto.AsymmetricKeypair;
import com.jd.blockchain.crypto.Crypto;
+import com.jd.blockchain.crypto.CryptoAlgorithm;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PrivKey;
import com.jd.blockchain.ledger.BlockchainIdentity;
@@ -54,7 +54,6 @@ import com.jd.blockchain.transaction.TxBuilder;
import com.jd.blockchain.utils.ArgumentSet;
import com.jd.blockchain.utils.ConsoleUtils;
import com.jd.blockchain.utils.concurrent.ThreadInvoker.AsyncCallback;
-import com.jd.blockchain.utils.io.BytesUtils;
import com.jd.blockchain.utils.io.FileUtils;
import com.jd.blockchain.utils.net.NetworkAddress;
@@ -408,8 +407,8 @@ public class LedgerPerformanceTest {
// BlockchainKeyPair dataAccountKey =
// BlockchainKeyGenerator.getInstance().generate();
BlockchainIdentity targetAccount = dataAccounts[count % dataAccounts.length];
- txbuilder.dataAccount(targetAccount.getAddress()).set("key-" + startTs + "-" + i,
- BytesUtils.toBytes("value-" + i), -1L);
+ txbuilder.dataAccount(targetAccount.getAddress()).setText("key-" + startTs + "-" + i,
+ "value-" + i, -1L);
TransactionRequestBuilder reqBuilder = txbuilder.prepareRequest();
reqBuilder.signAsEndpoint(adminKey);
txList.add(reqBuilder.buildRequest());
diff --git a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java
index 3065da89..71377739 100644
--- a/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java
+++ b/source/test/test-integration/src/test/java/test/com/jd/blockchain/intgr/IntegrationBase.java
@@ -46,7 +46,6 @@ import java.util.concurrent.atomic.AtomicLong;
import static org.junit.Assert.*;
-
/**
*
* @author shaozhuguang
@@ -57,436 +56,440 @@ import static org.junit.Assert.*;
public class IntegrationBase {
public static String KEY_TOTAL = "total";
- static {
- DataContractRegistry.register(LedgerInitOperation.class);
- DataContractRegistry.register(UserRegisterOperation.class);
- }
+ static {
+ DataContractRegistry.register(LedgerInitOperation.class);
+ DataContractRegistry.register(UserRegisterOperation.class);
+ }
- public static final String PASSWORD = "abc";
+ public static final String PASSWORD = "abc";
- public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
- "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
- "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
- "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" };
+ public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
+ "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
+ "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
+ "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" };
- public static final String[] PRIV_KEYS = {
- "177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
- "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
- "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
- "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" };
+ public static final String[] PRIV_KEYS = {
+ "177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
+ "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
+ "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
+ "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" };
- public static final AtomicLong validLong = new AtomicLong();
+ public static final AtomicLong validLong = new AtomicLong();
- public static KeyPairResponse testSDK_RegisterUser(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainService blockchainService) {
- // 注册用户,并验证最终写入;
- BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
+ public static KeyPairResponse testSDK_RegisterUser(AsymmetricKeypair adminKey, HashDigest ledgerHash,
+ BlockchainService blockchainService) {
+ // 注册用户,并验证最终写入;
+ BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
- // 定义交易;
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- txTpl.users().register(user.getIdentity());
+ // 定义交易;
+ TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
+ txTpl.users().register(user.getIdentity());
- // 签名;
- PreparedTransaction ptx = txTpl.prepare();
+ // 签名;
+ PreparedTransaction ptx = txTpl.prepare();
- HashDigest transactionHash = ptx.getHash();
+ HashDigest transactionHash = ptx.getHash();
- ptx.sign(adminKey);
+ ptx.sign(adminKey);
- // 提交并等待共识返回;
- TransactionResponse txResp = ptx.commit();
+ // 提交并等待共识返回;
+ TransactionResponse txResp = ptx.commit();
- KeyPairResponse keyPairResponse = new KeyPairResponse();
- keyPairResponse.keyPair = user;
- keyPairResponse.txResp = txResp;
- keyPairResponse.txHash = transactionHash;
- return keyPairResponse;
- }
+ KeyPairResponse keyPairResponse = new KeyPairResponse();
+ keyPairResponse.keyPair = user;
+ keyPairResponse.txResp = txResp;
+ keyPairResponse.txHash = transactionHash;
+ return keyPairResponse;
+ }
- public static KeyPairResponse testSDK_RegisterDataAccount(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainService blockchainService) {
- // 注册数据账户,并验证最终写入;
- BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
+ public static KeyPairResponse testSDK_RegisterDataAccount(AsymmetricKeypair adminKey, HashDigest ledgerHash,
+ BlockchainService blockchainService) {
+ // 注册数据账户,并验证最终写入;
+ BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
- // 定义交易;
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- txTpl.dataAccounts().register(dataAccount.getIdentity());
+ // 定义交易;
+ TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
+ txTpl.dataAccounts().register(dataAccount.getIdentity());
txTpl.dataAccount(dataAccount.getAddress()).set("total", 200, -1);
// txTpl.dataAccount(dataAccount.getAddress()).set("param1", "v", -1);
// txTpl.dataAccount(dataAccount.getAddress()).set("param2", 200, -1);
- // 签名;
- PreparedTransaction ptx = txTpl.prepare();
-
- HashDigest transactionHash = ptx.getHash();
-
- ptx.sign(adminKey);
-
- // 提交并等待共识返回;
- TransactionResponse txResp = ptx.commit();
-
- KeyPairResponse keyPairResponse = new KeyPairResponse();
- keyPairResponse.keyPair = dataAccount;
- keyPairResponse.txResp = txResp;
- keyPairResponse.txHash = transactionHash;
- return keyPairResponse;
- }
-
- public static KvResponse testSDK_InsertData(AsymmetricKeypair adminKey, HashDigest ledgerHash, BlockchainService blockchainService,
- Bytes dataAccount) {
-
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = blockchainService.newTransaction(ledgerHash);
-
- // --------------------------------------
- // 将商品信息写入到指定的账户中;
- // 对象将被序列化为 JSON 形式存储,并基于 JSON 结构建立查询索引;
- String dataKey = "jingdong" + System.currentTimeMillis() + new Random().nextInt(100000);
- byte[] dataVal = "www.jd.com".getBytes();
-
- txTemp.dataAccount(dataAccount).set(dataKey, dataVal, -1);
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- HashDigest transactionHash = prepTx.getHash();
-
- // 使用私钥进行签名;
- prepTx.sign(adminKey);
-
- // 提交交易;
- TransactionResponse txResp = prepTx.commit();
-
- KvResponse kvResponse = new KvResponse();
- kvResponse.ledgerHash = ledgerHash;
- kvResponse.dataAccount = dataAccount;
- kvResponse.txResp = txResp;
- kvResponse.txHash = transactionHash;
- kvResponse.key = dataKey;
- kvResponse.value = dataVal;
- return kvResponse;
- }
-
-
-
- public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, KeyPairType keyPairType) {
- TransactionResponse txResp = keyPairResponse.txResp;
- HashDigest transactionHash = keyPairResponse.txHash;
- BlockchainKeypair keyPair = keyPairResponse.keyPair;
- long index = validLong.incrementAndGet();
- System.out.printf("validKeyPair start %s \r\n", index);
- ledgerRepository.retrieveLatestBlock();
-
- assertEquals(txResp.getExecutionState(), TransactionState.SUCCESS);
- assertEquals(txResp.getBlockHeight(), ledgerRepository.getLatestBlockHeight());
- assertEquals(txResp.getContentHash(), transactionHash);
- assertEquals(txResp.getBlockHash(), ledgerRepository.getLatestBlockHash());
- if (keyPairType == KeyPairType.USER) {
- assertTrue(ledgerRepository.getUserAccountSet(ledgerRepository.getLatestBlock()).contains(keyPair.getAddress()));
- }
-
- if (keyPairType == KeyPairType.DATAACCOUNT) {
- assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
- .getDataAccount(keyPair.getAddress()));
- }
- System.out.printf("validKeyPair end %s \r\n", index);
- }
-
- public static void validKeyPair(IntegrationBase.KeyPairResponse keyPairResponse, LedgerRepository ledgerRepository, KeyPairType keyPairType, CountDownLatch countDownLatch) {
-
- TransactionResponse txResp = keyPairResponse.txResp;
- HashDigest transactionHash = keyPairResponse.txHash;
- BlockchainKeypair keyPair = keyPairResponse.keyPair;
- ledgerRepository.retrieveLatestBlock();
-
- assertEquals(txResp.getExecutionState(), TransactionState.SUCCESS);
- assertEquals(txResp.getBlockHeight(), ledgerRepository.getLatestBlockHeight());
- assertEquals(txResp.getContentHash(), transactionHash);
- assertEquals(txResp.getBlockHash(), ledgerRepository.getLatestBlockHash());
- if (keyPairType == KeyPairType.USER) {
- assertTrue(ledgerRepository.getUserAccountSet(ledgerRepository.getLatestBlock()).contains(keyPair.getAddress()));
- }
-
- if (keyPairType == KeyPairType.DATAACCOUNT) {
- assertNotNull(ledgerRepository.getDataAccountSet(ledgerRepository.getLatestBlock())
- .getDataAccount(keyPair.getAddress()));
- }
- countDownLatch.countDown();
- }
-
- public static void validKvWrite(IntegrationBase.KvResponse kvResponse, LedgerRepository ledgerRepository, BlockchainService blockchainService) {
- // 先验证应答
- TransactionResponse txResp = kvResponse.getTxResp();
- HashDigest transactionHash = kvResponse.getTxHash();
- HashDigest ledgerHash = kvResponse.getLedgerHash();
- String daAddress = kvResponse.getDataAccount().toBase58();
- String dataKey = kvResponse.getKey();
- byte[] dataVal = kvResponse.getValue();
-
- ledgerRepository.retrieveLatestBlock();
-
- assertEquals(TransactionState.SUCCESS, txResp.getExecutionState());
- assertEquals(txResp.getBlockHeight(), ledgerRepository.getLatestBlockHeight());
- assertEquals(txResp.getContentHash(), transactionHash);
- assertEquals(txResp.getBlockHash(), ledgerRepository.getLatestBlockHash());
-
- KVDataEntry[] kvDataEntries = blockchainService.getDataEntries(ledgerHash, daAddress, dataKey);
- for (KVDataEntry kvDataEntry : kvDataEntries) {
- assertEquals(dataKey, kvDataEntry.getKey());
- String valHexText = (String) kvDataEntry.getValue();
- byte[] valBytes = HexUtils.decode(valHexText);
- boolean isEqual = Arrays.equals(dataVal, valBytes);
- assertTrue(isEqual);
- }
- }
-
-
- public static LedgerRepository[] buildLedgers(LedgerBindingConfig[] bindingConfigs, DbConnectionFactory[] dbConnectionFactories){
- int[] ids = {0, 1, 2, 3};
- LedgerRepository[] ledgers = new LedgerRepository[ids.length];
- LedgerManager[] ledgerManagers = new LedgerManager[ids.length];
- for (int i = 0; i < ids.length; i++) {
- ledgerManagers[i] = new LedgerManager();
- HashDigest ledgerHash = bindingConfigs[0].getLedgerHashs()[0];
- DbConnection conn = dbConnectionFactories[i].connect(bindingConfigs[i].getLedger(ledgerHash).getDbConnection().getUri());
- ledgers[i] = ledgerManagers[i].register(ledgerHash, conn.getStorageService());
- }
- return ledgers;
- }
-
- public static void testConsistencyAmongNodes(LedgerRepository[] ledgers) {
- LedgerRepository ledger0 = ledgers[0];
- LedgerBlock latestBlock0 = ledger0.retrieveLatestBlock();
- for (int i = 1; i < ledgers.length; i++) {
- LedgerRepository otherLedger = ledgers[i];
- LedgerBlock otherLatestBlock = otherLedger.retrieveLatestBlock();
- assertEquals(ledger0.getHash(), otherLedger.getHash());
- assertEquals(ledger0.getLatestBlockHeight(), otherLedger.getLatestBlockHeight());
- assertEquals(ledger0.getLatestBlockHash(), otherLedger.getLatestBlockHash());
-
- assertEquals(latestBlock0.getHeight(), otherLatestBlock.getHeight());
- assertEquals(latestBlock0.getHash(), otherLatestBlock.getHash());
- assertEquals(latestBlock0.getAdminAccountHash(), otherLatestBlock.getAdminAccountHash());
- assertEquals(latestBlock0.getTransactionSetHash(), otherLatestBlock.getTransactionSetHash());
- assertEquals(latestBlock0.getUserAccountSetHash(), otherLatestBlock.getUserAccountSetHash());
- assertEquals(latestBlock0.getDataAccountSetHash(), otherLatestBlock.getDataAccountSetHash());
- assertEquals(latestBlock0.getContractAccountSetHash(), otherLatestBlock.getContractAccountSetHash());
- assertEquals(latestBlock0.getPreviousHash(), otherLatestBlock.getPreviousHash());
- }
- }
-
- public static PeerTestRunner[] peerNodeStart(HashDigest ledgerHash, String dbType) {
- NetworkAddress peerSrvAddr0 = new NetworkAddress("127.0.0.1", 12000);
- LedgerBindingConfig bindingConfig0 = loadBindingConfig(0, ledgerHash, dbType);
- PeerTestRunner peer0 = new PeerTestRunner(peerSrvAddr0, bindingConfig0);
-
- NetworkAddress peerSrvAddr1 = new NetworkAddress("127.0.0.1", 12010);
- LedgerBindingConfig bindingConfig1 = loadBindingConfig(1, ledgerHash, dbType);
- PeerTestRunner peer1 = new PeerTestRunner(peerSrvAddr1, bindingConfig1);
-
- NetworkAddress peerSrvAddr2 = new NetworkAddress("127.0.0.1", 12020);
- LedgerBindingConfig bindingConfig2 = loadBindingConfig(2, ledgerHash, dbType);
- PeerTestRunner peer2 = new PeerTestRunner(peerSrvAddr2, bindingConfig2);
-
- NetworkAddress peerSrvAddr3 = new NetworkAddress("127.0.0.1", 12030);
- LedgerBindingConfig bindingConfig3 = loadBindingConfig(3, ledgerHash, dbType);
- PeerTestRunner peer3 = new PeerTestRunner(peerSrvAddr3, bindingConfig3);
-
- ThreadInvoker.AsyncCallback