diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java
index 5a302ca8..977f2c2e 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/ContractAccount.java
@@ -4,7 +4,7 @@ import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.BytesValue;
-import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.utils.Bytes;
public class ContractAccount implements AccountHeader {
@@ -43,7 +43,7 @@ public class ContractAccount implements AccountHeader {
}
public long setChaincode(byte[] chaincode, long version) {
- BytesValue bytesValue = BytesValueEntry.fromBytes(chaincode);
+ BytesValue bytesValue = BytesData.fromBytes(chaincode);
return accBase.setBytes(CHAIN_CODE_KEY, bytesValue, version);
}
@@ -60,18 +60,18 @@ public class ContractAccount implements AccountHeader {
}
public long setProperty(Bytes key, String value, long version) {
- BytesValue bytesValue = BytesValueEntry.fromText(value);
+ BytesValue bytesValue = BytesData.fromText(value);
return accBase.setBytes(encodePropertyKey(key), bytesValue, version);
}
public String getProperty(Bytes key) {
BytesValue bytesValue = accBase.getBytes(encodePropertyKey(key));
- return BytesValueEntry.toText(bytesValue);
+ return BytesData.toText(bytesValue);
}
public String getProperty(Bytes key, long version) {
BytesValue bytesValue = accBase.getBytes(encodePropertyKey(key), version);
- return BytesValueEntry.toText(bytesValue);
+ return BytesData.toText(bytesValue);
}
private Bytes encodePropertyKey(Bytes key) {
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java
index d7092e63..792ca704 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/DataAccount.java
@@ -6,7 +6,7 @@ import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.BytesValue;
-import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.ledger.KVDataEntry;
import com.jd.blockchain.ledger.KVDataObject;
import com.jd.blockchain.utils.Bytes;
@@ -49,12 +49,12 @@ public class DataAccount implements AccountHeader, MerkleProvable {
public long setBytes(Bytes key, String value, long version) {
- BytesValue bytesValue = BytesValueEntry.fromText(value);
+ BytesValue bytesValue = BytesData.fromText(value);
return baseAccount.setBytes(key, bytesValue, version);
}
public long setBytes(Bytes key, byte[] value, long version) {
- BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ BytesValue bytesValue = BytesData.fromBytes(value);
return baseAccount.setBytes(key, bytesValue, version);
}
diff --git a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java
index f6faa1e0..b9cc88fd 100644
--- a/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java
+++ b/source/ledger/ledger-core/src/main/java/com/jd/blockchain/ledger/core/UserAccount.java
@@ -3,7 +3,7 @@ package com.jd.blockchain.ledger.core;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.crypto.PubKey;
import com.jd.blockchain.ledger.BytesValue;
-import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.ledger.UserInfo;
import com.jd.blockchain.utils.Bytes;
@@ -50,12 +50,12 @@ public class UserAccount implements UserInfo {
public long setDataPubKey(PubKey pubKey) {
byte[] pkBytes = pubKey.toBytes();
- return baseAccount.setBytes(DATA_PUB_KEY, BytesValueEntry.fromBytes(pkBytes), -1);
+ return baseAccount.setBytes(DATA_PUB_KEY, BytesData.fromBytes(pkBytes), -1);
}
public long setDataPubKey(PubKey pubKey, long version) {
byte[] pkBytes = pubKey.toBytes();
- return baseAccount.setBytes(DATA_PUB_KEY, BytesValueEntry.fromBytes(pkBytes), version);
+ return baseAccount.setBytes(DATA_PUB_KEY, BytesData.fromBytes(pkBytes), version);
}
public long setProperty(String key, String value, long version) {
@@ -63,7 +63,7 @@ public class UserAccount implements UserInfo {
}
public long setProperty(Bytes key, String value, long version) {
- return baseAccount.setBytes(encodePropertyKey(key), BytesValueEntry.fromText(value), version);
+ return baseAccount.setBytes(encodePropertyKey(key), BytesData.fromText(value), version);
}
public String getProperty(Bytes key) {
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 162f3408..4a0e1ed5 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
@@ -8,7 +8,7 @@ import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.AccountHeader;
import com.jd.blockchain.ledger.BlockchainIdentity;
import com.jd.blockchain.ledger.BytesValue;
-import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.ledger.DataAccountKVSetOperation;
import com.jd.blockchain.ledger.DataAccountRegisterOperation;
import com.jd.blockchain.ledger.KVDataEntry;
@@ -279,7 +279,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setText(String key, String value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromText(value);
+ BytesValue bytesValue = BytesData.fromText(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -287,7 +287,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setBytes(String key, Bytes value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ BytesValue bytesValue = BytesData.fromBytes(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -295,7 +295,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setInt64(String key, long value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromInt64(value);
+ BytesValue bytesValue = BytesData.fromInt64(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -312,7 +312,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setJSON(String key, String value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromJSON(value);
+ BytesValue bytesValue = BytesData.fromJSON(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -320,7 +320,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setXML(String key, String value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromXML(value);
+ BytesValue bytesValue = BytesData.fromXML(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -328,7 +328,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setBytes(String key, byte[] value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromBytes(value);
+ BytesValue bytesValue = BytesData.fromBytes(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -336,7 +336,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setImage(String key, byte[] value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromImage(value);
+ BytesValue bytesValue = BytesData.fromImage(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
@@ -344,7 +344,7 @@ public class ContractLedgerContext implements LedgerContext {
@Override
public DataAccountKVSetOperationBuilder setTimestamp(String key, long value, long expVersion) {
- BytesValue bytesValue = BytesValueEntry.fromTimestamp(value);
+ BytesValue bytesValue = BytesData.fromTimestamp(value);
this.op = new SingleKVSetOpTemplate(key, bytesValue, expVersion);
handle(op);
return this;
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 ac9f50b1..4a641b7d 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,7 +12,7 @@ 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.BytesData;
import com.jd.blockchain.ledger.core.BaseAccount;
import com.jd.blockchain.ledger.core.CryptoConfig;
import com.jd.blockchain.storage.service.utils.MemoryKVStorage;
@@ -53,33 +53,33 @@ public class BaseAccountTest {
assertFalse(baseAccount.isReadonly());
// 在空白状态下写入数据;
- long v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), 0);
+ long v = baseAccount.setBytes(Bytes.fromString("A"), BytesData.fromText("VALUE_A"), 0);
// 预期失败;
assertEquals(-1, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), 1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesData.fromText("VALUE_A"), 1);
// 预期失败;
assertEquals(-1, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A"), -1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesData.fromText("VALUE_A"), -1);
// 预期成功;
assertEquals(0, v);
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A-1"), -1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesData.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"), BytesValueEntry.fromText("VALUE_A_" + i), v);
+ long s = baseAccount.setBytes(Bytes.fromString("A"), BytesData.fromText("VALUE_A_" + i), v);
baseAccount.commit();
// 预期成功;
assertEquals(v + 1, s);
v++;
}
- v = baseAccount.setBytes(Bytes.fromString("A"), BytesValueEntry.fromText("VALUE_A_" + v), v + 1);
+ v = baseAccount.setBytes(Bytes.fromString("A"), BytesData.fromText("VALUE_A_" + v), v + 1);
// 预期成功;
assertEquals(-1, v);
diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/ContractInvokingTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/ContractInvokingTest.java
index 27e234d0..20f49bd4 100644
--- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/ContractInvokingTest.java
+++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/ContractInvokingTest.java
@@ -21,7 +21,7 @@ import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.BlockchainKeyGenerator;
import com.jd.blockchain.ledger.BlockchainKeypair;
import com.jd.blockchain.ledger.BytesValue;
-import com.jd.blockchain.ledger.BytesValueEntry;
+import com.jd.blockchain.ledger.BytesData;
import com.jd.blockchain.ledger.EndpointRequest;
import com.jd.blockchain.ledger.LedgerBlock;
import com.jd.blockchain.ledger.LedgerInitSetting;
@@ -103,6 +103,7 @@ public class ContractInvokingTest {
Random rand = new Random();
TxBuilder txBuilder = new TxBuilder(ledgerHash);
TestContract contractProxy = txBuilder.contract(contractAddress, TestContract.class);
+ TestContract contractProxy1 = txBuilder.contract(contractAddress, TestContract.class);
String asset = "AK";
long issueAmount = rand.nextLong();
@@ -120,7 +121,7 @@ public class ContractInvokingTest {
assertEquals(1, opResults.length);
assertEquals(0, opResults[0].getIndex());
- byte[] expectedRetnBytes = BinaryProtocol.encode(BytesValueEntry.fromInt64(issueAmount), BytesValue.class);
+ byte[] expectedRetnBytes = BinaryProtocol.encode(BytesData.fromInt64(issueAmount), BytesValue.class);
byte[] reallyRetnBytes = BinaryProtocol.encode(opResults[0].getResult(), BytesValue.class);
assertArrayEquals(expectedRetnBytes, reallyRetnBytes);
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 c39ea445..a4b719a7 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
@@ -1,5 +1,6 @@
package test.com.jd.blockchain.ledger;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -10,10 +11,13 @@ import java.util.Random;
import org.junit.Test;
+import com.jd.blockchain.binaryproto.BinaryProtocol;
import com.jd.blockchain.binaryproto.DataContractRegistry;
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.ledger.BlockchainKeyGenerator;
import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.BytesDataList;
+import com.jd.blockchain.ledger.BytesValueList;
import com.jd.blockchain.ledger.ContractCodeDeployOperation;
import com.jd.blockchain.ledger.ContractEventSendOperation;
import com.jd.blockchain.ledger.CryptoSetting;
@@ -67,8 +71,8 @@ public class TransactionSetTest {
BlockchainKeypair dataKey = BlockchainKeyGenerator.getInstance().generate();
DataAccountRegisterOperation dataAccRegOp = txBuilder.dataAccounts().register(dataKey.getIdentity());
- DataAccountKVSetOperation kvsetOP = txBuilder.dataAccount(dataKey.getAddress())
- .setText("A", "Value_A_0", -1).setText("B", "Value_B_0", -1).getOperation();
+ DataAccountKVSetOperation kvsetOP = txBuilder.dataAccount(dataKey.getAddress()).setText("A", "Value_A_0", -1)
+ .setText("B", "Value_B_0", -1).getOperation();
byte[] chainCode = new byte[128];
rand.nextBytes(chainCode);
@@ -76,7 +80,7 @@ public class TransactionSetTest {
ContractCodeDeployOperation contractDplOP = txBuilder.contracts().deploy(contractKey.getIdentity(), chainCode);
ContractEventSendOperation contractEvtSendOP = txBuilder.contractEvents().send(contractKey.getAddress(), "test",
- "TestContractArgs".getBytes());
+ BytesDataList.singleText("TestContractArgs"));
TransactionRequestBuilder txReqBuilder = txBuilder.prepareRequest();
@@ -98,7 +102,8 @@ public class TransactionSetTest {
txSnapshot.setContractAccountSetHash(contractAccountSetHash);
long blockHeight = 8922L;
- LedgerTransactionData tx = new LedgerTransactionData(blockHeight, txReq, TransactionState.SUCCESS, txSnapshot, null);
+ LedgerTransactionData tx = new LedgerTransactionData(blockHeight, txReq, TransactionState.SUCCESS, txSnapshot,
+ null);
txset.add(tx);
assertTrue(txset.isUpdated());
@@ -172,7 +177,8 @@ public class TransactionSetTest {
for (int i = 0; i < acutualKVWriteSet.length; i++) {
assertEquals(expKVWriteSet[i].getKey(), acutualKVWriteSet[i].getKey());
assertEquals(expKVWriteSet[i].getExpectedVersion(), acutualKVWriteSet[i].getExpectedVersion());
- assertTrue(BytesUtils.equals(expKVWriteSet[i].getValue().getValue().toBytes(), acutualKVWriteSet[i].getValue().getValue().toBytes()));
+ assertTrue(BytesUtils.equals(expKVWriteSet[i].getValue().getValue().toBytes(),
+ acutualKVWriteSet[i].getValue().getValue().toBytes()));
}
ContractCodeDeployOperation actualContractDplOp = (ContractCodeDeployOperation) actualOperations[3];
@@ -184,8 +190,14 @@ public class TransactionSetTest {
assertEquals(contractEvtSendOP.getContractAddress(), actualContractEvtSendOp.getContractAddress());
assertEquals(contractEvtSendOP.getEvent(), actualContractEvtSendOp.getEvent());
assertEquals("test", actualContractEvtSendOp.getEvent());
- assertTrue(BytesUtils.equals(contractEvtSendOP.getArgs(), actualContractEvtSendOp.getArgs()));
- assertTrue(BytesUtils.equals("TestContractArgs".getBytes(), actualContractEvtSendOp.getArgs()));
+
+ byte[] expectedBytes = BinaryProtocol.encode(contractEvtSendOP.getArgs(), BytesValueList.class);
+ byte[] actualBytes = BinaryProtocol.encode(actualContractEvtSendOp.getArgs(), BytesValueList.class);
+ assertArrayEquals(expectedBytes, actualBytes);
+
+ expectedBytes = BinaryProtocol.encode(BytesDataList.singleText("TestContractArgs"), BytesValueList.class);
+ actualBytes = BinaryProtocol.encode(actualContractEvtSendOp.getArgs(), BytesValueList.class);
+ assertArrayEquals(expectedBytes, actualBytes);
}
}
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/BytesData.java
similarity index 63%
rename from source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesValueEntry.java
rename to source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesData.java
index 612c6111..ca4e9cb0 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/BytesData.java
@@ -8,38 +8,38 @@ import com.jd.blockchain.utils.io.BytesUtils;
* @author huanghaiquan
*
*/
-public class BytesValueEntry implements BytesValue {
+public class BytesData implements BytesValue {
DataType type;
Bytes value;
- private BytesValueEntry(DataType type, byte[] bytes) {
+ private BytesData(DataType type, byte[] bytes) {
this.type = type;
this.value = new Bytes(bytes);
}
- private BytesValueEntry(DataType type, Bytes bytes) {
+ private BytesData(DataType type, Bytes bytes) {
this.type = type;
this.value = bytes;
}
public static BytesValue fromType(DataType type, byte[] value) {
- return new BytesValueEntry(type, value);
+ return new BytesData(type, value);
}
public static BytesValue fromBytes(byte[] value) {
- return new BytesValueEntry(DataType.BYTES, value);
+ return new BytesData(DataType.BYTES, value);
}
public static BytesValue fromBytes(Bytes value) {
- return new BytesValueEntry(DataType.BYTES, value);
+ return new BytesData(DataType.BYTES, value);
}
public static BytesValue fromImage(byte[] value) {
- return new BytesValueEntry(DataType.IMG, value);
+ return new BytesData(DataType.IMG, value);
}
public static BytesValue fromImage(Bytes value) {
- return new BytesValueEntry(DataType.IMG, value);
+ return new BytesData(DataType.IMG, value);
}
/**
@@ -49,7 +49,7 @@ public class BytesValueEntry implements BytesValue {
* @return
*/
public static BytesValue fromText(String value) {
- return new BytesValueEntry(DataType.TEXT, BytesUtils.toBytes(value));
+ return new BytesData(DataType.TEXT, BytesUtils.toBytes(value));
}
/**
@@ -70,35 +70,35 @@ public class BytesValueEntry implements BytesValue {
}
public static BytesValue fromJSON(String value) {
- return new BytesValueEntry(DataType.JSON, BytesUtils.toBytes(value));
+ return new BytesData(DataType.JSON, BytesUtils.toBytes(value));
}
public static BytesValue fromXML(String value) {
- return new BytesValueEntry(DataType.XML, BytesUtils.toBytes(value));
+ return new BytesData(DataType.XML, BytesUtils.toBytes(value));
}
public static BytesValue fromInt32(int value) {
- return new BytesValueEntry(DataType.INT32, BytesUtils.toBytes(value));
+ return new BytesData(DataType.INT32, BytesUtils.toBytes(value));
}
public static BytesValue fromInt64(long value) {
- return new BytesValueEntry(DataType.INT64, BytesUtils.toBytes(value));
+ return new BytesData(DataType.INT64, BytesUtils.toBytes(value));
}
public static BytesValue fromInt16(short value) {
- return new BytesValueEntry(DataType.INT16, BytesUtils.toBytes(value));
+ return new BytesData(DataType.INT16, BytesUtils.toBytes(value));
}
public static BytesValue fromInt8(byte value) {
- return new BytesValueEntry(DataType.INT8, BytesUtils.toBytes(value));
+ return new BytesData(DataType.INT8, BytesUtils.toBytes(value));
}
public static BytesValue fromTimestamp(long value) {
- return new BytesValueEntry(DataType.TIMESTAMP, BytesUtils.toBytes(value));
+ return new BytesData(DataType.TIMESTAMP, BytesUtils.toBytes(value));
}
public static BytesValue fromBoolean(boolean value) {
- return new BytesValueEntry(DataType.BOOLEAN, BytesUtils.toBytes(value));
+ return new BytesData(DataType.BOOLEAN, BytesUtils.toBytes(value));
}
@Override
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesDataList.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesDataList.java
new file mode 100644
index 00000000..f7aef959
--- /dev/null
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/BytesDataList.java
@@ -0,0 +1,31 @@
+package com.jd.blockchain.ledger;
+
+public class BytesDataList implements BytesValueList {
+
+ private BytesValue[] bytesValues;
+
+ public BytesDataList(BytesValue... bytesValues) {
+ this.bytesValues = bytesValues;
+ }
+
+ @Override
+ public BytesValue[] getValues() {
+ return bytesValues;
+ }
+
+ public static BytesValueList singleText(String value) {
+ return new BytesDataList(BytesData.fromText(value));
+ }
+
+ public static BytesValueList singleLong(long value) {
+ return new BytesDataList(BytesData.fromInt64(value));
+ }
+
+ public static BytesValueList singleInt(int value) {
+ return new BytesDataList(BytesData.fromInt32(value));
+ }
+
+ public static BytesValueList singleBoolean(boolean value) {
+ return new BytesDataList(BytesData.fromBoolean(value));
+ }
+}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PreparedTransaction.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PreparedTransaction.java
index b7db5b59..20d4d9ad 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PreparedTransaction.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/PreparedTransaction.java
@@ -1,5 +1,7 @@
package com.jd.blockchain.ledger;
+import java.io.Closeable;
+
import com.jd.blockchain.crypto.AsymmetricKeypair;
import com.jd.blockchain.crypto.HashDigest;
@@ -9,7 +11,7 @@ import com.jd.blockchain.crypto.HashDigest;
* @author huanghaiquan
*
*/
-public interface PreparedTransaction extends HashObject {
+public interface PreparedTransaction extends HashObject, Closeable {
/**
* 交易内容的 Hash;
@@ -55,8 +57,4 @@ public interface PreparedTransaction extends HashObject {
*/
TransactionResponse commit();
- /**
- * 取消交易;
- */
- void cancel();
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionTemplate.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionTemplate.java
index 3c5acdcf..0696e768 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionTemplate.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/ledger/TransactionTemplate.java
@@ -1,5 +1,7 @@
package com.jd.blockchain.ledger;
+import java.io.Closeable;
+
import com.jd.blockchain.crypto.HashDigest;
import com.jd.blockchain.transaction.ClientOperator;
@@ -9,7 +11,7 @@ import com.jd.blockchain.transaction.ClientOperator;
* @author huanghaiquan
*
*/
-public interface TransactionTemplate extends ClientOperator {
+public interface TransactionTemplate extends ClientOperator, Closeable {
HashDigest getLedgerHash();
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 4e7e172d..ef9b138a 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
@@ -106,15 +106,15 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe
*
* @return
*/
- public Collection getReturnValuetHandlers() {
- List resultHandlers = new ArrayList();
+ public Collection getReturnValuetHandlers() {
+ List resultHandlers = new ArrayList();
int index = 0;
for (Operation op : operationList) {
if (op instanceof ContractEventSendOperation) {
// 操作具有返回值,创建对应的结果处理器;
ContractEventSendOpTemplate opTemp = (ContractEventSendOpTemplate) op;
ContractInvocation invocation = opTemp.getInvocation();
- OperationReturnValueHandler retnHandler;
+ OperationResultHandle retnHandler;
if (invocation == null) {
retnHandler = new NullOperationReturnValueHandler(index);
} else {
@@ -278,7 +278,7 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe
* @author huanghaiquan
*
*/
- private static class NullOperationReturnValueHandler implements OperationReturnValueHandler {
+ private static class NullOperationReturnValueHandler implements OperationResultHandle {
private int operationIndex;
@@ -292,10 +292,14 @@ public class BlockchainOperationFactory implements ClientOperator, LedgerInitOpe
}
@Override
- public Object setReturnValue(BytesValue bytesValue) {
+ public Object complete(BytesValue bytesValue) {
return null;
}
+ @Override
+ public void complete(Throwable error) {
+ }
+
}
}
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BooleanValueHolder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BooleanValueHolder.java
index 977a88b0..480e3d30 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BooleanValueHolder.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/BooleanValueHolder.java
@@ -1,43 +1,22 @@
package com.jd.blockchain.transaction;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+public class BooleanValueHolder extends ValueHolderWrapper {
-public class BooleanValueHolder extends ValueHolderBase {
-
- BooleanValueHolder(ContractInvocation invocation) {
- super(invocation);
+ BooleanValueHolder(OperationResultHolder resultHolder) {
+ super(resultHolder);
}
/**
- * 等待结果合约调用的结果返回;
+ * 获取值;
*
- * @return
- */
- public boolean get() {
- return (boolean) super.getValue();
- }
-
- /**
- * 等待结果合约调用的结果返回;
+ * 此方法不堵塞,调用立即返回;
*
- * @param timeout
- * @return
- * @throws TimeoutException
- */
- public boolean get(long timeout) throws TimeoutException {
- return get(timeout, TimeUnit.MILLISECONDS);
- }
-
- /**
- * 等待结果合约调用的结果返回;
+ * 如果未完成时( {@link #isCompleted()} 为 false ),总是返回 false;
*
- * @param timeout
- * @param unit
* @return
- * @throws TimeoutException
*/
- public boolean get(long timeout, TimeUnit unit) throws TimeoutException {
- return (boolean) super.getValue(timeout, unit);
+ public boolean get() {
+ return super.isCompleted() ? (boolean) super.getValue() : false;
}
+
}
\ No newline at end of file
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ByteValueHolder.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ByteValueHolder.java
index 32809d51..d9c024ff 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ByteValueHolder.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ByteValueHolder.java
@@ -1,43 +1,22 @@
package com.jd.blockchain.transaction;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+public class ByteValueHolder extends ValueHolderWrapper {
-public class ByteValueHolder extends ValueHolderBase {
-
- ByteValueHolder(ContractInvocation invocation) {
- super(invocation);
+ ByteValueHolder(OperationResultHolder resultHolder) {
+ super(resultHolder);
}
/**
- * 等待结果合约调用的结果返回;
+ * 获取值;
*
- * @return
- */
- public byte get() {
- return (byte) super.getValue();
- }
-
- /**
- * 等待结果合约调用的结果返回;
+ * 此方法不堵塞,调用立即返回;
*
- * @param timeout
- * @return
- * @throws TimeoutException
- */
- public byte get(long timeout) throws TimeoutException {
- return get(timeout, TimeUnit.MILLISECONDS);
- }
-
- /**
- * 等待结果合约调用的结果返回;
+ * 如果未完成时( {@link #isCompleted()} 为 false ),总是返回 0;
*
- * @param timeout
- * @param unit
* @return
- * @throws TimeoutException
*/
- public byte get(long timeout, TimeUnit unit) throws TimeoutException {
- return (byte) super.getValue(timeout, unit);
+ public byte get() {
+ return super.isCompleted() ? (byte) super.getValue() : 0;
}
+
}
\ No newline at end of file
diff --git a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocation.java b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocation.java
index cab7df0c..2e27fca9 100644
--- a/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocation.java
+++ b/source/ledger/ledger-model/src/main/java/com/jd/blockchain/transaction/ContractInvocation.java
@@ -1,8 +1,6 @@
package com.jd.blockchain.transaction;
import java.lang.reflect.Method;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.Future;
import com.jd.blockchain.contract.ContractType;
import com.jd.blockchain.ledger.BytesValue;
@@ -14,7 +12,7 @@ import com.jd.blockchain.ledger.BytesValueEncoding;
* @author huanghaiquan
*
*/
-class ContractInvocation implements OperationReturnValueHandler {
+class ContractInvocation extends OperationResultHolder {
private Method method;
@@ -22,12 +20,9 @@ class ContractInvocation implements OperationReturnValueHandler {
private int operationIndex = -1;
- private CompletableFuture