| @@ -21,6 +21,10 @@ public class BytesValueEntry implements BytesValue { | |||||
| this.type = type; | this.type = type; | ||||
| this.value = bytes; | this.value = bytes; | ||||
| } | } | ||||
| public static BytesValue fromType(BytesValueType type, byte[] value) { | |||||
| return new BytesValueEntry(type, value); | |||||
| } | |||||
| public static BytesValue fromBytes(byte[] value) { | public static BytesValue fromBytes(byte[] value) { | ||||
| return new BytesValueEntry(BytesValueType.BYTES, value); | return new BytesValueEntry(BytesValueType.BYTES, value); | ||||
| @@ -8,20 +8,39 @@ | |||||
| */ | */ | ||||
| package com.jd.blockchain.sdk.client; | package com.jd.blockchain.sdk.client; | ||||
| import java.lang.reflect.Field; | |||||
| import org.apache.commons.codec.binary.Base64; | |||||
| import com.alibaba.fastjson.JSONArray; | import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.jd.blockchain.crypto.CryptoProvider; | import com.jd.blockchain.crypto.CryptoProvider; | ||||
| import com.jd.blockchain.crypto.PubKey; | import com.jd.blockchain.crypto.PubKey; | ||||
| import com.jd.blockchain.ledger.*; | |||||
| import com.jd.blockchain.transaction.*; | |||||
| import com.jd.blockchain.ledger.BlockchainIdentityData; | |||||
| import com.jd.blockchain.ledger.BytesValue; | |||||
| import com.jd.blockchain.ledger.BytesValueEntry; | |||||
| import com.jd.blockchain.ledger.BytesValueType; | |||||
| import com.jd.blockchain.ledger.ContractCodeDeployOperation; | |||||
| import com.jd.blockchain.ledger.ContractEventSendOperation; | |||||
| import com.jd.blockchain.ledger.CryptoSetting; | |||||
| import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||||
| import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||||
| import com.jd.blockchain.ledger.LedgerInitOperation; | |||||
| import com.jd.blockchain.ledger.Operation; | |||||
| import com.jd.blockchain.ledger.ParticipantNode; | |||||
| import com.jd.blockchain.ledger.UserRegisterOperation; | |||||
| import com.jd.blockchain.transaction.ContractCodeDeployOpTemplate; | |||||
| import com.jd.blockchain.transaction.ContractEventSendOpTemplate; | |||||
| import com.jd.blockchain.transaction.DataAccountKVSetOpTemplate; | |||||
| import com.jd.blockchain.transaction.DataAccountRegisterOpTemplate; | |||||
| import com.jd.blockchain.transaction.KVData; | |||||
| import com.jd.blockchain.transaction.LedgerInitOpTemplate; | |||||
| import com.jd.blockchain.transaction.LedgerInitSettingData; | |||||
| import com.jd.blockchain.transaction.UserRegisterOpTemplate; | |||||
| import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
| import com.jd.blockchain.utils.codec.Base58Utils; | import com.jd.blockchain.utils.codec.Base58Utils; | ||||
| import com.jd.blockchain.utils.codec.HexUtils; | import com.jd.blockchain.utils.codec.HexUtils; | ||||
| import com.jd.blockchain.utils.io.BytesSlice; | |||||
| import com.jd.blockchain.utils.io.BytesUtils; | import com.jd.blockchain.utils.io.BytesUtils; | ||||
| import org.apache.commons.codec.binary.Base64; | |||||
| import java.lang.reflect.Field; | |||||
| /** | /** | ||||
| * | * | ||||
| @@ -65,22 +84,22 @@ public class ClientOperationUtil { | |||||
| public static Object readValueByBytesValue(BytesValue bytesValue) { | public static Object readValueByBytesValue(BytesValue bytesValue) { | ||||
| BytesValueType dataType = bytesValue.getType(); | BytesValueType dataType = bytesValue.getType(); | ||||
| BytesSlice saveVal = bytesValue.getValue(); | |||||
| Bytes saveVal = bytesValue.getValue(); | |||||
| Object showVal; | Object showVal; | ||||
| switch (dataType) { | switch (dataType) { | ||||
| case BYTES: | case BYTES: | ||||
| // return hex | // return hex | ||||
| showVal = HexUtils.encode(saveVal.getBytesCopy()); | |||||
| showVal = HexUtils.encode(saveVal.toBytes()); | |||||
| break; | break; | ||||
| case TEXT: | case TEXT: | ||||
| case JSON: | case JSON: | ||||
| showVal = saveVal.getString(); | |||||
| showVal = saveVal.toUTF8String(); | |||||
| break; | break; | ||||
| case INT64: | case INT64: | ||||
| showVal = saveVal.getLong(); | |||||
| showVal = BytesUtils.toLong(saveVal.toBytes()); | |||||
| break; | break; | ||||
| default: | default: | ||||
| showVal = HexUtils.encode(saveVal.getBytesCopy()); | |||||
| showVal = HexUtils.encode(saveVal.toBytes()); | |||||
| break; | break; | ||||
| } | } | ||||
| return showVal; | return showVal; | ||||
| @@ -107,7 +126,7 @@ public class ClientOperationUtil { | |||||
| String realValBase58 = valueObj.getString("value"); | String realValBase58 = valueObj.getString("value"); | ||||
| String key = currWriteSetObj.getString("key"); | String key = currWriteSetObj.getString("key"); | ||||
| BytesValueType dataType = BytesValueType.valueOf(typeStr); | BytesValueType dataType = BytesValueType.valueOf(typeStr); | ||||
| BytesValue bytesValue = new BytesValueEntry(dataType, Base58Utils.decode(realValBase58)); | |||||
| BytesValue bytesValue =BytesValueEntry.fromType(dataType, Base58Utils.decode(realValBase58)); | |||||
| KVData kvData = new KVData(key, bytesValue, expectedVersion); | KVData kvData = new KVData(key, bytesValue, expectedVersion); | ||||
| kvOperation.set(kvData); | kvOperation.set(kvData); | ||||
| } | } | ||||
| @@ -132,8 +132,8 @@ public class SDK_Contract_Test { | |||||
| String key2 = "jd_key2"; | String key2 = "jd_key2"; | ||||
| String val2 = "www.jd2.com"; | String val2 = "www.jd2.com"; | ||||
| // 定义交易,传输最简单的数字、字符串、提取合约中的地址; | // 定义交易,传输最简单的数字、字符串、提取合约中的地址; | ||||
| txTemp.dataAccount(dataAccount.getAddress()).set(key1, val1, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).set(key2, val2, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).setText(key1, val1, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).setText(key2, val2, -1); | |||||
| // TX 准备就绪; | // TX 准备就绪; | ||||
| PreparedTransaction prepTx = txTemp.prepare(); | PreparedTransaction prepTx = txTemp.prepare(); | ||||
| @@ -156,9 +156,9 @@ public class SDK_Contract_Test { | |||||
| TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash); | TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash); | ||||
| BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate(); | BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate(); | ||||
| txTemp.dataAccounts().register(dataAccount.getIdentity()); | txTemp.dataAccounts().register(dataAccount.getIdentity()); | ||||
| txTemp.dataAccount(dataAccount.getAddress()).set("total", 200, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).set("param1", "v", -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).set("param2", 123, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).setInt64("total", 200, -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).setText("param1", "v", -1); | |||||
| txTemp.dataAccount(dataAccount.getAddress()).setInt64("param2", 123, -1); | |||||
| // TX 准备就绪; | // TX 准备就绪; | ||||
| PreparedTransaction prepTx = txTemp.prepare(); | PreparedTransaction prepTx = txTemp.prepare(); | ||||
| prepTx.sign(signKeyPair); | prepTx.sign(signKeyPair); | ||||
| @@ -175,7 +175,7 @@ public class SDK_Contract_Test { | |||||
| BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate(); | BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate(); | ||||
| for(int i=0; i<keys.length; i++){ | for(int i=0; i<keys.length; i++){ | ||||
| txTemp.dataAccount(dataAddress).set(keys[i], values[i], version); | |||||
| txTemp.dataAccount(dataAddress).setText(keys[i], values[i], version); | |||||
| } | } | ||||
| // TX 准备就绪; | // TX 准备就绪; | ||||
| @@ -594,11 +594,11 @@ public class IntegrationTest { | |||||
| // 定义交易; | // 定义交易; | ||||
| TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | 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()); | |||||
| // 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(); | PreparedTransaction ptx = txTpl.prepare(); | ||||
| ptx.sign(adminKey); | ptx.sign(adminKey); | ||||
| @@ -110,7 +110,7 @@ public class IntegrationBase { | |||||
| // 定义交易; | // 定义交易; | ||||
| TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash); | ||||
| txTpl.dataAccounts().register(dataAccount.getIdentity()); | txTpl.dataAccounts().register(dataAccount.getIdentity()); | ||||
| txTpl.dataAccount(dataAccount.getAddress()).set("total", 200, -1); | |||||
| txTpl.dataAccount(dataAccount.getAddress()).setInt64("total", 200, -1); | |||||
| // txTpl.dataAccount(dataAccount.getAddress()).set("param1", "v", -1); | // txTpl.dataAccount(dataAccount.getAddress()).set("param1", "v", -1); | ||||
| // txTpl.dataAccount(dataAccount.getAddress()).set("param2", 200, -1); | // txTpl.dataAccount(dataAccount.getAddress()).set("param2", 200, -1); | ||||
| @@ -1,15 +1,50 @@ | |||||
| package com.jd.blockchain.mocker; | package com.jd.blockchain.mocker; | ||||
| import static java.lang.reflect.Proxy.newProxyInstance; | |||||
| import java.util.HashMap; | |||||
| import java.util.Map; | |||||
| import java.util.Properties; | |||||
| import com.jd.blockchain.binaryproto.DataContractRegistry; | import com.jd.blockchain.binaryproto.DataContractRegistry; | ||||
| import com.jd.blockchain.consensus.ClientIdentification; | import com.jd.blockchain.consensus.ClientIdentification; | ||||
| import com.jd.blockchain.consensus.ClientIdentifications; | import com.jd.blockchain.consensus.ClientIdentifications; | ||||
| import com.jd.blockchain.consensus.action.ActionRequest; | import com.jd.blockchain.consensus.action.ActionRequest; | ||||
| import com.jd.blockchain.consensus.action.ActionResponse; | import com.jd.blockchain.consensus.action.ActionResponse; | ||||
| import com.jd.blockchain.crypto.*; | |||||
| import com.jd.blockchain.crypto.Crypto; | |||||
| import com.jd.blockchain.crypto.CryptoProvider; | |||||
| import com.jd.blockchain.crypto.HashDigest; | |||||
| import com.jd.blockchain.crypto.PrivKey; | |||||
| import com.jd.blockchain.crypto.PubKey; | |||||
| import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; | import com.jd.blockchain.crypto.service.classic.ClassicAlgorithm; | ||||
| import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | import com.jd.blockchain.crypto.service.classic.ClassicCryptoService; | ||||
| import com.jd.blockchain.crypto.service.sm.SMCryptoService; | import com.jd.blockchain.crypto.service.sm.SMCryptoService; | ||||
| import com.jd.blockchain.ledger.*; | |||||
| import com.jd.blockchain.ledger.AccountHeader; | |||||
| import com.jd.blockchain.ledger.BlockchainIdentity; | |||||
| import com.jd.blockchain.ledger.BlockchainKeyGenerator; | |||||
| import com.jd.blockchain.ledger.BlockchainKeypair; | |||||
| import com.jd.blockchain.ledger.ContractCodeDeployOperation; | |||||
| import com.jd.blockchain.ledger.ContractEventSendOperation; | |||||
| import com.jd.blockchain.ledger.DataAccountKVSetOperation; | |||||
| import com.jd.blockchain.ledger.DataAccountRegisterOperation; | |||||
| import com.jd.blockchain.ledger.EndpointRequest; | |||||
| 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.NodeRequest; | |||||
| import com.jd.blockchain.ledger.Operation; | |||||
| import com.jd.blockchain.ledger.ParticipantNode; | |||||
| import com.jd.blockchain.ledger.TransactionContent; | |||||
| import com.jd.blockchain.ledger.TransactionContentBody; | |||||
| import com.jd.blockchain.ledger.TransactionRequest; | |||||
| import com.jd.blockchain.ledger.TransactionRequestBuilder; | |||||
| import com.jd.blockchain.ledger.TransactionResponse; | |||||
| import com.jd.blockchain.ledger.TransactionState; | |||||
| import com.jd.blockchain.ledger.UserInfo; | |||||
| import com.jd.blockchain.ledger.UserRegisterOperation; | |||||
| import com.jd.blockchain.ledger.core.CryptoConfig; | import com.jd.blockchain.ledger.core.CryptoConfig; | ||||
| import com.jd.blockchain.ledger.core.LedgerDataSet; | import com.jd.blockchain.ledger.core.LedgerDataSet; | ||||
| import com.jd.blockchain.ledger.core.LedgerEditor; | import com.jd.blockchain.ledger.core.LedgerEditor; | ||||
| @@ -28,15 +63,12 @@ import com.jd.blockchain.storage.service.utils.MemoryDBConnFactory; | |||||
| import com.jd.blockchain.tools.initializer.DBConnectionConfig; | import com.jd.blockchain.tools.initializer.DBConnectionConfig; | ||||
| import com.jd.blockchain.tools.initializer.LedgerInitProperties; | import com.jd.blockchain.tools.initializer.LedgerInitProperties; | ||||
| import com.jd.blockchain.tools.keygen.KeyGenCommand; | import com.jd.blockchain.tools.keygen.KeyGenCommand; | ||||
| import com.jd.blockchain.transaction.*; | |||||
| import com.jd.blockchain.transaction.BlockchainQueryService; | |||||
| import com.jd.blockchain.transaction.TxBuilder; | |||||
| import com.jd.blockchain.utils.Bytes; | import com.jd.blockchain.utils.Bytes; | ||||
| import com.jd.blockchain.utils.io.BytesUtils; | import com.jd.blockchain.utils.io.BytesUtils; | ||||
| import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; | import com.jd.blockchain.web.serializes.ByteArrayObjectUtil; | ||||
| import java.util.*; | |||||
| import static java.lang.reflect.Proxy.newProxyInstance; | |||||
| public class MockerNodeContext implements BlockchainQueryService { | public class MockerNodeContext implements BlockchainQueryService { | ||||
| private static final String[] SUPPORTED_PROVIDERS = { ClassicCryptoService.class.getName(), | private static final String[] SUPPORTED_PROVIDERS = { ClassicCryptoService.class.getName(), | ||||
| @@ -171,25 +203,25 @@ public class MockerNodeContext implements BlockchainQueryService { | |||||
| public void writeKv(String address, String key, String value, long version) { | public void writeKv(String address, String key, String value, long version) { | ||||
| TxBuilder txBuilder = txBuilder(); | TxBuilder txBuilder = txBuilder(); | ||||
| txBuilder.dataAccount(address).set(key, value, version); | |||||
| txBuilder.dataAccount(address).setText(key, value, version); | |||||
| txProcess(txRequest(txBuilder)); | txProcess(txRequest(txBuilder)); | ||||
| } | } | ||||
| public void writeKv(String address, String key, long value, long version) { | public void writeKv(String address, String key, long value, long version) { | ||||
| TxBuilder txBuilder = txBuilder(); | TxBuilder txBuilder = txBuilder(); | ||||
| txBuilder.dataAccount(address).set(key, value, version); | |||||
| txBuilder.dataAccount(address).setInt64(key, value, version); | |||||
| txProcess(txRequest(txBuilder)); | txProcess(txRequest(txBuilder)); | ||||
| } | } | ||||
| public void writeKv(String address, String key, byte[] value, long version) { | public void writeKv(String address, String key, byte[] value, long version) { | ||||
| TxBuilder txBuilder = txBuilder(); | TxBuilder txBuilder = txBuilder(); | ||||
| txBuilder.dataAccount(address).set(key, value, version); | |||||
| txBuilder.dataAccount(address).setBytes(key, value, version); | |||||
| txProcess(txRequest(txBuilder)); | txProcess(txRequest(txBuilder)); | ||||
| } | } | ||||
| public void writeKv(String address, String key, Bytes value, long version) { | public void writeKv(String address, String key, Bytes value, long version) { | ||||
| TxBuilder txBuilder = txBuilder(); | TxBuilder txBuilder = txBuilder(); | ||||
| txBuilder.dataAccount(address).set(key, value, version); | |||||
| txBuilder.dataAccount(address).setBytes(key, value, version); | |||||
| txProcess(txRequest(txBuilder)); | txProcess(txRequest(txBuilder)); | ||||
| } | } | ||||
| @@ -15,7 +15,7 @@ public class AccountContractImpl implements EventProcessingAwire, AccountContrac | |||||
| @Override | @Override | ||||
| public void create(String address, String account, long money) { | public void create(String address, String account, long money) { | ||||
| // 暂不处理该账户已经存在的问题 | // 暂不处理该账户已经存在的问题 | ||||
| eventContext.getLedger().dataAccount(address).set(account, money, -1); | |||||
| eventContext.getLedger().dataAccount(address).setInt64(account, money, -1); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -41,8 +41,8 @@ public class AccountContractImpl implements EventProcessingAwire, AccountContrac | |||||
| currentFromMoney -= money; | currentFromMoney -= money; | ||||
| currentToMoney += money; | currentToMoney += money; | ||||
| // 重新设置结果 | // 重新设置结果 | ||||
| eventContext.getLedger().dataAccount(address).set(from, currentFromMoney, currentFromVer) | |||||
| .set(to, currentToMoney, currentToVer); | |||||
| eventContext.getLedger().dataAccount(address).setInt64(from, currentFromMoney, currentFromVer) | |||||
| .setInt64(to, currentToMoney, currentToVer); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -16,7 +16,7 @@ public class WriteContractImpl implements EventProcessingAwire, WriteContract { | |||||
| @Override | @Override | ||||
| public void writeKv(String address, String key, String value) { | public void writeKv(String address, String key, String value) { | ||||
| eventContext.getLedger().dataAccount(address).set(key, value, -1); | |||||
| eventContext.getLedger().dataAccount(address).setText(key, value, -1); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -1,13 +1,16 @@ | |||||
| package com.jd.blockchain.mocker.handler; | package com.jd.blockchain.mocker.handler; | ||||
| import com.jd.blockchain.ledger.core.LedgerException; | |||||
| import com.jd.blockchain.ledger.core.OperationHandle; | |||||
| import com.jd.blockchain.ledger.core.impl.OperationHandleRegisteration; | |||||
| import com.jd.blockchain.ledger.core.impl.handles.*; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.List; | import java.util.List; | ||||
| import com.jd.blockchain.ledger.LedgerException; | |||||
| import com.jd.blockchain.ledger.core.OperationHandle; | |||||
| import com.jd.blockchain.ledger.core.impl.OperationHandleRegisteration; | |||||
| import com.jd.blockchain.ledger.core.impl.handles.ContractCodeDeployOperationHandle; | |||||
| import com.jd.blockchain.ledger.core.impl.handles.DataAccountKVSetOperationHandle; | |||||
| import com.jd.blockchain.ledger.core.impl.handles.DataAccountRegisterOperationHandle; | |||||
| import com.jd.blockchain.ledger.core.impl.handles.UserRegisterOperationHandle; | |||||
| public class MockerOperationHandleRegister implements OperationHandleRegisteration { | public class MockerOperationHandleRegister implements OperationHandleRegisteration { | ||||
| private List<OperationHandle> opHandles = new ArrayList<>(); | private List<OperationHandle> opHandles = new ArrayList<>(); | ||||
| @@ -136,7 +136,7 @@ public class MockerServiceHandler { | |||||
| TransactionTemplate txTemplate = newTxTemplate(); | TransactionTemplate txTemplate = newTxTemplate(); | ||||
| txTemplate.dataAccount(dataAccount).set(key, value, version); | |||||
| txTemplate.dataAccount(dataAccount).setBytes(key, value, version); | |||||
| TransactionResponse txResponse = txPrepareAndCommit(txTemplate); | TransactionResponse txResponse = txPrepareAndCommit(txTemplate); | ||||