userAddress = ContractReturnValue.decode(sampleContract.registerUser(UUID.randomUUID().toString()));
+
+ // 准备交易
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+
+ // 获取返回值
+ System.out.println(userAddress.get());
+ }
+
+ /**
+ * 非动态代理方式合约调用,不需要依赖合约接口及实现
+ */
+ @Test
+ public void testExecuteWithArgus() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+
+ ContractEventSendOperationBuilder builder = txTemp.contract();
+ // 运行前,填写正确的合约地址,数据账户地址等参数
+ // 一次交易中可调用多个(多次调用)合约方法
+ // 调用合约的 registerUser 方法,传入合约地址,合约方法名,合约方法参数列表
+ builder.send("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye", "registerUser",
+ new BytesDataList(new TypedValue[]{
+ TypedValue.fromText(UUID.randomUUID().toString())
+ })
+ );
+ // 准备交易
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+
+ Assert.assertEquals(1, response.getOperationResults().length);
+ // 解析合约方法调用返回值
+ for (int i = 0; i < response.getOperationResults().length; i++) {
+ BytesValue content = response.getOperationResults()[i].getResult();
+ switch (content.getType()) {
+ case TEXT:
+ System.out.println(content.getBytes().toUTF8String());
+ break;
+ case INT64:
+ System.out.println(BytesUtils.toLong(content.getBytes().toBytes()));
+ break;
+ case BOOLEAN:
+ System.out.println(BytesUtils.toBoolean(content.getBytes().toBytes()[0]));
+ break;
+ default: // byte[], Bytes
+ System.out.println(content.getBytes().toBase58());
+ break;
+ }
+ }
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java
new file mode 100644
index 00000000..ddece471
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java
@@ -0,0 +1,88 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.ledger.BlockchainKeyGenerator;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.PreparedTransaction;
+import com.jd.blockchain.ledger.TransactionResponse;
+import com.jd.blockchain.ledger.TransactionTemplate;
+import com.jd.blockchain.utils.Bytes;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 数据账户相关操作示例:
+ * 创建数据账户,写入KV数据
+ */
+public class DataAccountSample extends SampleBase {
+
+ /**
+ * 注册数据账户
+ */
+ @Test
+ public void testRegisterDataAccount() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成数据账户
+ BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("数据账户地址:" + dataAccount.getAddress());
+ // 注册数据账户
+ txTemp.dataAccounts().register(dataAccount.getIdentity());
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 设置KV
+ */
+ @Test
+ public void testSetKV() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+
+ // 请正确填写数据账户地址
+ // expVersion是针对此key的插入更新操作次数严格递增,初始为-1
+ txTemp.dataAccount(Bytes.fromBase58("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye"))
+ .setText("key1", "value1", -1)
+ .setInt64("key2", 1, -1)
+ .setJSON("key3", "{}", -1)
+ .setBytes("key4", Bytes.fromInt(2), -1);
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+
+ }
+
+ /**
+ * 注册数据账户的同时设置KV,一个事务内
+ */
+ @Test
+ public void testRegisterDataAccountAndSetKV() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成数据账户
+ BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("数据账户地址:" + dataAccount.getAddress());
+ // 注册数据账户
+ txTemp.dataAccounts().register(dataAccount.getIdentity());
+ // 设置KV
+ txTemp.dataAccount(dataAccount.getAddress())
+ .setText("key", "value", -1);
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java
new file mode 100644
index 00000000..aedf7360
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java
@@ -0,0 +1,137 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.ledger.BlockchainKeyGenerator;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.Event;
+import com.jd.blockchain.ledger.PreparedTransaction;
+import com.jd.blockchain.ledger.SystemEvent;
+import com.jd.blockchain.ledger.TransactionResponse;
+import com.jd.blockchain.ledger.TransactionTemplate;
+import com.jd.blockchain.utils.Bytes;
+import com.jd.blockchain.utils.io.BytesUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * 事件账户相关操作示例:
+ * 事件账户创建,事件发布,事件监听
+ */
+public class EventSample extends SampleBase {
+
+ /**
+ * 事件监听
+ */
+ @Test
+ public void testEventListen() {
+
+ // 事件监听会创建子线程,为阻止子线程被直接关闭,加入等待
+ CountDownLatch cdl = new CountDownLatch(1);
+
+ // 监听系统事件,目前仅有新区快产生事件
+ blockchainService.monitorSystemEvent(ledger,
+ SystemEvent.NEW_BLOCK_CREATED, 0, (eventMessages, eventContext) -> {
+ for (Event eventMessage : eventMessages) {
+ // content中存放的是当前链上最新高度
+ System.out.println("New block:" + eventMessage.getSequence() + ":" + BytesUtils.toLong(eventMessage.getContent().getBytes().toBytes()));
+ }
+ });
+
+ // 监听用户自定义事件
+ blockchainService.monitorUserEvent(ledger, "LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye", "sample-event", 0, (eventMessage, eventContext) -> {
+
+ BytesValue content = eventMessage.getContent();
+ switch (content.getType()) {
+ case TEXT:
+ case XML:
+ case JSON:
+ System.out.println(eventMessage.getName() + ":" + eventMessage.getSequence() + ":" + content.getBytes().toUTF8String());
+ break;
+ case INT64:
+ case TIMESTAMP:
+ System.out.println(eventMessage.getName() + ":" + eventMessage.getSequence() + ":" + BytesUtils.toLong(content.getBytes().toBytes()));
+ break;
+ default: // byte[], Bytes
+ System.out.println(eventMessage.getName() + ":" + eventMessage.getSequence() + ":" + content.getBytes().toBase58());
+ break;
+ }
+ });
+
+ try {
+ cdl.await();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * 注册事件账户
+ */
+ @Test
+ public void testRegisterEventAccount() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成事件账户
+ BlockchainKeypair eventAccount = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("事件账户地址:" + eventAccount.getAddress());
+ // 注册事件账户
+ txTemp.eventAccounts().register(eventAccount.getIdentity());
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 发布事件
+ */
+ @Test
+ public void testPublishEvent() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+
+ // 请正确填写数据账户地址
+ // sequence是针对此消息name的插入更新操作次数严格递增,初始为-1
+ txTemp.eventAccount(Bytes.fromBase58("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye"))
+ .publish("topic1", "content1", -1)
+ .publish("topic1", "content2", 0)
+ .publish("topic1", "content3", 1)
+ .publish("topic2", "content", -1)
+ .publish("topic3", 1, -1)
+ .publish("topic4", Bytes.fromInt(1), -1);
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 注册事件账户的同时发布事件,一个事务内
+ */
+ @Test
+ public void testRegisterEventAccountAndPublishEvent() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成事件账户
+ BlockchainKeypair eventAccount = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("事件账户地址:" + eventAccount.getAddress());
+ // 注册事件账户
+ txTemp.eventAccounts().register(eventAccount.getIdentity());
+ // 发布事件
+ txTemp.eventAccount(eventAccount.getAddress()).publish("topic", "content", -1);
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ParticipantSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ParticipantSample.java
new file mode 100644
index 00000000..512609d2
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ParticipantSample.java
@@ -0,0 +1,132 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.crypto.KeyGenUtils;
+import com.jd.blockchain.ledger.BlockchainKeyGenerator;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.PreparedTransaction;
+import com.jd.blockchain.ledger.TransactionResponse;
+import com.jd.blockchain.ledger.TransactionTemplate;
+import com.jd.blockchain.utils.codec.Base58Utils;
+import com.jd.blockchain.utils.http.converters.JsonResponseConverter;
+import com.jd.blockchain.utils.security.ShaUtils;
+import com.jd.blockchain.utils.web.model.WebResponse;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 参与方节点相关操作示例:
+ * 注册/激活/移除参与方操作
+ *
+ * 本样例无法直接运行,请用户务必参照共识节点相关操作文档步骤完成各种前置操作,然后根据实际配置修改本样例各方法内参数
+ */
+public class ParticipantSample extends SampleBase {
+
+ // 注册参与方
+ @Test
+ public void registerParticipant() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成用户信息
+ BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
+ String pwd = Base58Utils.encode(ShaUtils.hash_256("1".getBytes()));
+ System.out.println("参与方私钥:" + KeyGenUtils.encodePrivKey(user.getPrivKey(), pwd));
+ System.out.println("参与方私钥密码:" + pwd);
+ System.out.println("参与方公钥:" + KeyGenUtils.encodePubKey(user.getPubKey()));
+ System.out.println("参与方地址:" + user.getAddress());
+ // 注册参与方
+ txTemp.participants().register("new peer node", user.getIdentity());
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 激活参与方
+ * 执行前请确保新节点已注册,且已经参照共识节点相关操作文档创建并启动新节点!!!
+ * 然后根据实际情况修改请求参数
+ *
+ * @throws Exception
+ */
+ @Test
+ public void activeParticipant() throws Exception {
+ // 新节点API服务IP和端口
+ String newNodeIp = "127.0.0.1";
+ String newNodeApiPort = "12040";
+ // 账本信息
+ String ledgerHash = ledger.toString();
+ // 新节点共识配置
+ String newNodeConsensusHost = "127.0.0.1";
+ String newNodeConsensusPot = "8950";
+ // 区块高度最新的节点API服务IP和端口,用于区块同步
+ String syncNodeHost = "127.0.0.1";
+ String syncNodePort = "12000";
+
+ // 发送POST请求执行节点激活操作
+ HttpPost httpPost = new HttpPost(String.format("http://%s:%s/management/delegate/activeparticipant", newNodeIp, newNodeApiPort));
+ List params = new ArrayList<>();
+ params.add(new BasicNameValuePair("ledgerHash", ledgerHash));
+ params.add(new BasicNameValuePair("consensusHost", newNodeConsensusHost));
+ params.add(new BasicNameValuePair("consensusPort", newNodeConsensusPot));
+ params.add(new BasicNameValuePair("remoteManageHost", syncNodeHost));
+ params.add(new BasicNameValuePair("remoteManagePort", syncNodePort));
+ params.add(new BasicNameValuePair("shutdown", "false"));
+ httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
+ HttpClient httpClient = HttpClients.createDefault();
+ HttpResponse response = httpClient.execute(httpPost);
+ JsonResponseConverter jsonConverter = new JsonResponseConverter(WebResponse.class);
+
+ WebResponse webResponse = (WebResponse) jsonConverter.getResponse(null, response.getEntity().getContent(), null);
+ Assert.assertTrue(webResponse.isSuccess());
+ }
+
+ /**
+ * 移除参与方
+ * 执行前请确保新节点已启动且出于参与共识状态!!!
+ * 然后根据实际情况修改请求参数
+ *
+ * @throws Exception
+ */
+ @Test
+ public void removeParticipant() throws Exception {
+
+ // 待移除节点API服务IP和端口
+ String nodeIp = "127.0.0.1";
+ String nodeApiPort = "12030";
+ // 账本信息
+ String ledgerHash = ledger.toString();
+ // 待移除节点地址
+ String participantAddress = "LdeNekdXMHqyz9Qxc2jDSBnkvvZLbty6pRDdP";
+ // 区块高度最新的节点API服务IP和端口,用于区块同步
+ String syncNodeHost = "127.0.0.1";
+ String syncNodePort = "12000";
+
+ // 发送POST请求执行节点移除操作
+ HttpPost httpPost = new HttpPost(String.format("http://%s:%s/management/delegate/deactiveparticipant", nodeIp, nodeApiPort));
+ List params = new ArrayList<>();
+ params.add(new BasicNameValuePair("ledgerHash", ledgerHash));
+ params.add(new BasicNameValuePair("participantAddress", participantAddress));
+ params.add(new BasicNameValuePair("remoteManageHost", syncNodeHost));
+ params.add(new BasicNameValuePair("remoteManagePort", syncNodePort));
+ httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
+ HttpClient httpClient = HttpClients.createDefault();
+ HttpResponse response = httpClient.execute(httpPost);
+ JsonResponseConverter jsonConverter = new JsonResponseConverter(WebResponse.class);
+
+ WebResponse webResponse = (WebResponse) jsonConverter.getResponse(null, response.getEntity().getContent(), null);
+ Assert.assertTrue(webResponse.isSuccess());
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/QuerySample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/QuerySample.java
new file mode 100644
index 00000000..cc418c0e
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/QuerySample.java
@@ -0,0 +1,587 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.crypto.Crypto;
+import com.jd.blockchain.crypto.HashDigest;
+import com.jd.blockchain.ledger.BlockchainIdentity;
+import com.jd.blockchain.ledger.BytesValue;
+import com.jd.blockchain.ledger.ContractInfo;
+import com.jd.blockchain.ledger.DataAccountInfo;
+import com.jd.blockchain.ledger.Event;
+import com.jd.blockchain.ledger.KVDataVO;
+import com.jd.blockchain.ledger.KVInfoVO;
+import com.jd.blockchain.ledger.LedgerAdminInfo;
+import com.jd.blockchain.ledger.LedgerBlock;
+import com.jd.blockchain.ledger.LedgerInfo;
+import com.jd.blockchain.ledger.LedgerMetadata;
+import com.jd.blockchain.ledger.LedgerPermission;
+import com.jd.blockchain.ledger.LedgerTransaction;
+import com.jd.blockchain.ledger.ParticipantNode;
+import com.jd.blockchain.ledger.PrivilegeSet;
+import com.jd.blockchain.ledger.TransactionPermission;
+import com.jd.blockchain.ledger.TransactionState;
+import com.jd.blockchain.ledger.TypedKVEntry;
+import com.jd.blockchain.ledger.UserInfo;
+import com.jd.blockchain.ledger.UserPrivilegeSet;
+import com.jd.blockchain.utils.codec.Base58Utils;
+import com.jd.blockchain.utils.io.BytesUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 查询样例
+ */
+public class QuerySample extends SampleBase {
+
+ HashDigest sampleHash = Crypto.resolveAsHashDigest(Base58Utils.decode("j5sTuEAWmLWKFwXgpdUCxbQN1XmZfkQdC94UT2AqQEt7hp"));
+ String sampleAddress = "LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye";
+ String sampleKey = "sample-key";
+ String sampleEvent = "sample-event";
+ long sampleVersion = 0;
+ String sampleRoleName = "SAMPLE-ROLE";
+
+ /**
+ * 查询账本列表
+ */
+ @Test
+ public void getLedgerHashs() {
+ HashDigest[] digests = blockchainService.getLedgerHashs();
+ for (HashDigest digest : digests) {
+ System.out.println(digest.toBase58());
+ }
+ }
+
+ /**
+ * 查询账本信息,区块hash,区块高度
+ */
+ @Test
+ public void getLedger() {
+ LedgerInfo ledgerInfo = blockchainService.getLedger(ledger);
+ System.out.println(ledgerInfo.getHash());
+ }
+
+ /**
+ * 查询账本信息,元数据,参与方,账本配置等
+ */
+ @Test
+ public void getLedgerAdminInfo() {
+ LedgerAdminInfo adminInfo = blockchainService.getLedgerAdminInfo(ledger);
+ System.out.println(adminInfo.getParticipantCount());
+ }
+
+ /**
+ * 查询共识参与方
+ */
+ @Test
+ public void getConsensusParticipants() {
+ ParticipantNode[] nodes = blockchainService.getConsensusParticipants(ledger);
+ for (ParticipantNode node : nodes) {
+ System.out.println("ID: " + node.getId());
+ System.out.println("Address: " + node.getAddress().toString());
+ System.out.println("PubKey: " + node.getPubKey().toString());
+ System.out.println("State: " + node.getParticipantNodeState());
+ }
+ }
+
+ /**
+ * 查询账本的元数据
+ */
+ @Test
+ public void getLedgerMetadata() {
+ LedgerMetadata metadata = blockchainService.getLedgerMetadata(ledger);
+ System.out.println(Base58Utils.encode(metadata.getSeed()));
+ System.out.println(metadata.getParticipantsHash().toBase58());
+ System.out.println(metadata.getSettingsHash().toBase58());
+ }
+
+ /**
+ * 根据高度查询区块
+ */
+ @Test
+ public void getBlockByHeight() {
+ LedgerBlock block1 = blockchainService.getBlock(ledger, -1);
+ LedgerBlock block2 = blockchainService.getBlock(ledger, Integer.MAX_VALUE);
+ Assert.assertNotNull(block1);
+ Assert.assertEquals(block1.getHash(), block2.getHash());
+ LedgerBlock block3 = blockchainService.getBlock(ledger, 0);
+ Assert.assertTrue(block1.getHeight() >= block3.getHeight());
+ }
+
+ /**
+ * 根据hash查询区块
+ */
+ @Test
+ public void getBlockByHash() {
+ LedgerBlock block = blockchainService.getBlock(ledger, sampleHash);
+ Assert.assertNull(block);
+ }
+
+ /**
+ * 查询某一高度(包括)之前所有交易数
+ */
+ @Test
+ public void getTransactionCountByHeight() {
+ long count = blockchainService.getTransactionCount(ledger, -1);
+ Assert.assertEquals(0, count);
+ count = blockchainService.getTransactionCount(ledger, 1);
+ Assert.assertNotEquals(0, count);
+ }
+
+ /**
+ * 查询某一区块(包括)之前所有交易数
+ */
+ @Test
+ public void getTransactionCountByHash() {
+ long count = blockchainService.getTransactionCount(ledger, sampleHash);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询交易总数
+ */
+ @Test
+ public void getTransactionTotalCount() {
+ long count = blockchainService.getTransactionTotalCount(ledger);
+ Assert.assertNotEquals(0, count);
+ }
+
+ /**
+ * 查询某一高度(包括)之前数据账户数
+ */
+ @Test
+ public void getDataAccountCountByHeight() {
+ long count = blockchainService.getDataAccountCount(ledger, 0);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询某一区块(包括)之前数据账户数
+ */
+ @Test
+ public void getDataAccountCountByHash() {
+ long count = blockchainService.getDataAccountCount(ledger, sampleHash);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询数据账户总数
+ */
+ @Test
+ public void getDataAccountTotalCount() {
+ long count = blockchainService.getDataAccountTotalCount(ledger);
+ System.out.println("Total DataAccount count: " + count);
+ }
+
+ /**
+ * 查询某一高度(包括)之前用户数
+ */
+ @Test
+ public void getUserCountByHeight() {
+ long count = blockchainService.getUserCount(ledger, 0);
+ Assert.assertEquals(4, count);
+ }
+
+ /**
+ * 查询某一区块(包括)之前用户数
+ */
+ @Test
+ public void getUserCountByHash() {
+ long count = blockchainService.getUserCount(ledger, sampleHash);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询用户总数
+ */
+ @Test
+ public void getUserTotalCount() {
+ long count = blockchainService.getUserTotalCount(ledger);
+ System.out.println("Total User count: " + count);
+ }
+
+ /**
+ * 查询某一高度(包括)之前合约数
+ */
+ @Test
+ public void getContractCountByHeight() {
+ long count = blockchainService.getContractCount(ledger, 0);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询某一区块(包括)之前合约数
+ */
+ @Test
+ public void getContractCountByHash() {
+ long count = blockchainService.getContractCount(ledger, sampleHash);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 查询合约总数
+ */
+ @Test
+ public void getContractTotalCount() {
+ long count = blockchainService.getContractTotalCount(ledger);
+ System.out.println("Total Contract count: " + count);
+ }
+
+ /**
+ * 分页查询交易某一高度(包括)之前的所有交易
+ */
+ @Test
+ public void getTransactionsByHeight() {
+ LedgerTransaction[] txs = blockchainService.getTransactions(ledger, 0, 0, 1);
+ Assert.assertEquals(1, txs.length);
+ }
+
+ /**
+ * 分页查询交易某一区块(包括)之前的所有交易
+ */
+ @Test
+ public void getTransactionsByHash() {
+ LedgerTransaction[] txs = blockchainService.getTransactions(ledger,
+ sampleHash, 0, 1);
+ Assert.assertNull(txs);
+ }
+
+ /**
+ * 分页查询某一高度中的交易
+ */
+ @Test
+ public void getAdditionalTransactionsByHeight() {
+ LedgerTransaction[] txs = blockchainService.getTransactions(ledger, 0, 0, 1);
+ Assert.assertEquals(1, txs.length);
+ }
+
+ /**
+ * 分页查询某一区块中的交易
+ */
+ @Test
+ public void getAdditionalTransactionsByHash() {
+ LedgerTransaction[] txs = blockchainService.getTransactions(ledger, sampleHash, 0, 1);
+ Assert.assertNull(txs);
+ }
+
+ /**
+ * 根据交易hash查询交易详情
+ */
+ @Test
+ public void getTransactionByContentHash() {
+ LedgerTransaction tx = blockchainService.getTransactionByContentHash(ledger, sampleHash);
+ Assert.assertNull(tx);
+ }
+
+ /**
+ * 根据交易hash查询交易状态
+ */
+ @Test
+ public void getTransactionStateByContentHash() {
+ TransactionState state = blockchainService.getTransactionStateByContentHash(ledger, sampleHash);
+ Assert.assertNull(state);
+ }
+
+ /**
+ * 根据地址查询用户信息
+ */
+ @Test
+ public void getUser() {
+ UserInfo user = blockchainService.getUser(ledger, sampleAddress);
+ if (null != user) {
+ System.out.println(user.getAddress().toString());
+ }
+ }
+
+ /**
+ * 根据地址查询数据账户
+ */
+ @Test
+ public void getDataAccount() {
+ DataAccountInfo dataAccount = blockchainService.getDataAccount(ledger, sampleAddress);
+ if (null != dataAccount) {
+ System.out.println(dataAccount.getAddress().toString());
+ }
+ }
+
+ /**
+ * 根据地址和键查询KV信息(只包含最高数据版本)
+ */
+ @Test
+ public void getDataEntriesByKey() {
+ TypedKVEntry[] kvs = blockchainService.getDataEntries(ledger, sampleAddress, sampleKey);
+ for (TypedKVEntry kv : kvs) {
+ System.out.println(kv.getKey() + ":" + kv.getVersion() + ":" + kv.getValue());
+ }
+ }
+
+ /**
+ * 根据地址和指定键及数据版本查询KV信息
+ */
+ @Test
+ public void getDataEntriesWithKeyAndVersion() {
+ TypedKVEntry[] kvs = blockchainService.getDataEntries(ledger, sampleAddress, new KVInfoVO(new KVDataVO[]{new KVDataVO(sampleKey, new long[]{-1})}));
+ for (TypedKVEntry kv : kvs) {
+ System.out.println(kv.getKey() + ":" + kv.getVersion() + ":" + kv.getValue());
+ }
+ }
+
+ /**
+ * 查询数据账户KV总数
+ */
+ @Test
+ public void getDataEntriesTotalCount() {
+ long count = blockchainService.getDataEntriesTotalCount(ledger, sampleAddress);
+ System.out.println(count);
+ }
+
+ /**
+ * 分页查询指定数据账户KV数据
+ */
+ @Test
+ public void getDataEntries() {
+ TypedKVEntry[] kvs = blockchainService.getDataEntries(ledger, sampleAddress, 0, 1);
+ for (TypedKVEntry kv : kvs) {
+ System.out.println(kv.getKey() + ":" + kv.getVersion() + ":" + kv.getValue());
+ }
+ }
+
+ /**
+ * 查询合约信息
+ */
+ @Test
+ public void getContract() {
+ ContractInfo contract = blockchainService.getContract(ledger, sampleAddress);
+ if (null != contract) {
+ System.out.println(contract.getAddress().toString());
+ }
+ }
+
+ /**
+ * 分页查询指定系统事件名下所有消息
+ */
+ @Test
+ public void getSystemEvents() {
+ Event[] events = blockchainService.getSystemEvents(ledger, sampleEvent, 0, 1);
+ Assert.assertTrue(null == events || events.length == 0);
+ }
+
+ /**
+ * 查询系统事件名总数
+ */
+ @Test
+ public void getSystemEventNameTotalCount() {
+ long count = blockchainService.getSystemEventNameTotalCount(ledger);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 分页查询系统事件名
+ */
+ @Test
+ public void getSystemEventNames() {
+ String[] names = blockchainService.getSystemEventNames(ledger, 0, 1);
+ Assert.assertEquals(0, names.length);
+ }
+
+ /**
+ * 查询指定系统事件名最新事件
+ */
+ @Test
+ public void getLatestEvent() {
+ Event event = blockchainService.getLatestEvent(ledger, sampleEvent);
+ Assert.assertNull(event);
+ }
+
+ /**
+ * 获取指定系统事件名下所有事件
+ */
+ @Test
+ public void getSystemEventsTotalCount() {
+ long count = blockchainService.getSystemEventsTotalCount(ledger, sampleEvent);
+ Assert.assertEquals(0, count);
+ }
+
+ /**
+ * 分页查询用户事件账户
+ *
+ * @return
+ */
+ @Test
+ public void getUserEventAccounts() {
+ BlockchainIdentity[] ids = blockchainService.getUserEventAccounts(ledger, 0, 1);
+ System.out.println(ids.length);
+ }
+
+ /**
+ * 获取用户事件账户
+ */
+ @Test
+ public void getUserEventAccount() {
+ BlockchainIdentity id = blockchainService.getUserEventAccount(ledger, sampleAddress);
+ if (null != id) {
+ System.out.println(id.getAddress().toString());
+ }
+ }
+
+ /**
+ * 获取用户事件账户总数
+ */
+ @Test
+ public void getUserEventAccountTotalCount() {
+ long count = blockchainService.getUserEventAccountTotalCount(ledger);
+ System.out.println(count);
+ }
+
+ /**
+ * 获取指定用户事件账户下事件名数
+ */
+ @Test
+ public void getUserEventNameTotalCount() {
+ long count = blockchainService.getUserEventNameTotalCount(ledger, sampleAddress);
+ System.out.println(count);
+ }
+
+ /**
+ * 分页查询指定用户事件账户下事件名
+ */
+ @Test
+ public void getUserEventNames() {
+ String[] names = blockchainService.getUserEventNames(ledger, sampleAddress, 0, 1);
+ for (String name : names) {
+ System.out.println(name);
+ }
+ }
+
+ /**
+ * 获取指定用户事件账户指定事件名下最新事件
+ */
+ @Test
+ public void getLatestUserEvent() {
+ Event event = blockchainService.getLatestEvent(ledger, sampleAddress, sampleEvent);
+ if (null != event) {
+ BytesValue content = event.getContent();
+ switch (content.getType()) {
+ case TEXT:
+ case XML:
+ case JSON:
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + content.getBytes().toUTF8String());
+ break;
+ case INT64:
+ case TIMESTAMP:
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + BytesUtils.toLong(content.getBytes().toBytes()));
+ break;
+ default: // byte[], Bytes
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + content.getBytes().toBase58());
+ break;
+ }
+ }
+ }
+
+ /**
+ * 获取指定用户事件账户指定事件名下事件总数
+ */
+ @Test
+ public void getUserEventsTotalCount() {
+ long count = blockchainService.getUserEventsTotalCount(ledger, sampleAddress, sampleEvent);
+ System.out.println(count);
+ }
+
+ /**
+ * 分页查询指定用户事件账户指定事件名下事件
+ */
+ @Test
+ public void getUserEvents() {
+ Event[] events = blockchainService.getUserEvents(ledger, sampleAddress, sampleEvent, 0, 1);
+ for (Event event : events) {
+ BytesValue content = event.getContent();
+ switch (content.getType()) {
+ case TEXT:
+ case XML:
+ case JSON:
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + content.getBytes().toUTF8String());
+ break;
+ case INT64:
+ case TIMESTAMP:
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + BytesUtils.toLong(content.getBytes().toBytes()));
+ break;
+ default: // byte[], Bytes
+ System.out.println(event.getName() + ":" + event.getSequence() + ":" + content.getBytes().toBase58());
+ break;
+ }
+ }
+ }
+
+ /**
+ * 获取指定版本合约
+ */
+ @Test
+ public void getContractByAddressAndVersion() {
+ ContractInfo contract = blockchainService.getContract(ledger, sampleAddress, sampleVersion);
+ if (null != contract) {
+ System.out.println(contract.getAddress().toString());
+ System.out.println(contract.getChainCodeVersion());
+ System.out.println(contract.getChainCode());
+ }
+ }
+
+ /**
+ * 分页查询用户
+ */
+ @Test
+ public void getUsers() {
+ BlockchainIdentity[] ids = blockchainService.getUsers(ledger, 0, 1);
+ Assert.assertEquals(1, ids.length);
+ }
+
+ /**
+ * 分页查询数据账户
+ */
+ @Test
+ public void getDataAccounts() {
+ BlockchainIdentity[] ids = blockchainService.getDataAccounts(ledger, 0, 1);
+ System.out.println(ids.length);
+ }
+
+ /**
+ * 分页查询合约账户
+ */
+ @Test
+ public void getContractAccounts() {
+ BlockchainIdentity[] ids = blockchainService.getContractAccounts(ledger, 0, 1);
+ System.out.println(ids.length);
+ }
+
+ /**
+ * 查询指定角色权限信息
+ */
+ @Test
+ public void getRolePrivileges() {
+ PrivilegeSet privilegeSet = blockchainService.getRolePrivileges(ledger, sampleRoleName);
+ if (null != privilegeSet) {
+ for (LedgerPermission ledgerpermission : privilegeSet.getLedgerPrivilege().getPrivilege()) {
+ System.out.println(ledgerpermission);
+ }
+ for (TransactionPermission transactionPermission : privilegeSet.getTransactionPrivilege().getPrivilege()) {
+ System.out.println(transactionPermission);
+ }
+ }
+ }
+
+ /**
+ * 查询指定用户权限信息
+ */
+ @Test
+ public void getUserPrivileges() {
+ UserPrivilegeSet userPrivileges = blockchainService.getUserPrivileges(ledger, sampleAddress);
+ if (null != userPrivileges) {
+ for (String role : userPrivileges.getUserRole()) {
+ System.out.println(role);
+ }
+ for (LedgerPermission ledgerpermission : userPrivileges.getLedgerPrivilegesBitset().getPrivilege()) {
+ System.out.println(ledgerpermission);
+ }
+ for (TransactionPermission transactionPermission : userPrivileges.getTransactionPrivilegesBitset().getPrivilege()) {
+ System.out.println(transactionPermission);
+ }
+ }
+ }
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/SampleBase.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/SampleBase.java
new file mode 100644
index 00000000..f4e417fa
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/SampleBase.java
@@ -0,0 +1,60 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.crypto.Crypto;
+import com.jd.blockchain.crypto.HashDigest;
+import com.jd.blockchain.crypto.KeyGenUtils;
+import com.jd.blockchain.crypto.PrivKey;
+import com.jd.blockchain.crypto.PubKey;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.sdk.BlockchainService;
+import com.jd.blockchain.sdk.client.GatewayServiceFactory;
+import com.jd.blockchain.utils.codec.Base58Utils;
+
+import java.util.Properties;
+
+public class SampleBase {
+
+ // 交易签名用户
+ protected static BlockchainKeypair adminKey;
+ // 网关IP
+ protected static String gatewayHost;
+ // 网关端口
+ protected static int gatewayPort;
+ // 账本Hash
+ protected static HashDigest ledger;
+ // 区块链服务
+ protected static BlockchainService blockchainService;
+
+ static {
+ try {
+ // 读取配置文件
+ Properties properties = new Properties();
+ properties.load(SampleBase.class.getClassLoader().getResourceAsStream("config.properties"));
+
+ // 初始配置交易签名用户信息
+ PubKey pubKey = KeyGenUtils.decodePubKey(properties.getProperty("pubkey"));
+ PrivKey privKey = KeyGenUtils.decodePrivKey(properties.getProperty("privkey"), properties.getProperty("password"));
+ adminKey = new BlockchainKeypair(pubKey, privKey);
+
+ // 读取网关配置
+ gatewayHost = properties.getProperty("gateway.host");
+ gatewayPort = Integer.parseInt(properties.getProperty("gateway.port"));
+
+ // 读取账本配置
+ String ledgerHash = properties.getProperty("ledger");
+
+ // 初始化区块链服务
+ blockchainService = GatewayServiceFactory.connect(gatewayHost, gatewayPort, false, adminKey).getBlockchainService();
+
+ // 初始配置账本,从配置文件中读取,未设置获取账本列表第一个
+ if (!ledgerHash.isEmpty()) {
+ ledger = Crypto.resolveAsHashDigest(Base58Utils.decode(ledgerHash));
+ } else {
+ ledger = blockchainService.getLedgerHashs()[0];
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java
new file mode 100644
index 00000000..502913a8
--- /dev/null
+++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java
@@ -0,0 +1,111 @@
+package com.jdchain.samples.sdk;
+
+import com.jd.blockchain.ledger.BlockchainKeyGenerator;
+import com.jd.blockchain.ledger.BlockchainKeypair;
+import com.jd.blockchain.ledger.LedgerPermission;
+import com.jd.blockchain.ledger.PreparedTransaction;
+import com.jd.blockchain.ledger.TransactionPermission;
+import com.jd.blockchain.ledger.TransactionResponse;
+import com.jd.blockchain.ledger.TransactionTemplate;
+import com.jd.blockchain.utils.Bytes;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * 用户账户相关操作示例:
+ * 用户注册,角色创建,权限设置
+ */
+public class UserSample extends SampleBase {
+
+ /**
+ * 注册用户
+ */
+ @Test
+ public void registerUser() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成用户
+ BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("用户地址:" + user.getAddress());
+ // 注册用户
+ txTemp.users().register(user.getIdentity());
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 创建角色
+ */
+ @Test
+ public void createRole() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+
+ // 创建角色 MANAGER ,并设置可以写数据账户,能执行交易
+ txTemp.security().roles().configure("MANAGER")
+ .enable(LedgerPermission.WRITE_DATA_ACCOUNT)
+ .enable(TransactionPermission.DIRECT_OPERATION);
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 配置角色权限
+ */
+ @Test
+ public void configUserRole() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+
+ // 给用户设置 MANAGER 角色权限
+ txTemp.security().authorziations().forUser(Bytes.fromBase58("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye")).authorize("MANAGER");
+ // 交易准备
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+ /**
+ * 注册用户的同时配置角色权限,同一事务内
+ */
+ @Test
+ public void testRegisterUserAndConfigRole() {
+ // 新建交易
+ TransactionTemplate txTemp = blockchainService.newTransaction(ledger);
+ // 生成用户
+ BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
+ System.out.println("用户地址:" + user.getAddress());
+ // 注册用户
+ txTemp.users().register(user.getIdentity());
+
+ // 创建角色 MANAGER
+ txTemp.security().roles().configure("MANAGER")
+ .enable(LedgerPermission.WRITE_DATA_ACCOUNT)
+ .enable(TransactionPermission.DIRECT_OPERATION);
+
+ // 设置用户角色权限
+ txTemp.security().authorziations().forUser(user.getAddress()).authorize("MANAGER");
+
+ // 交易主恩贝
+ PreparedTransaction ptx = txTemp.prepare();
+ // 交易签名
+ ptx.sign(adminKey);
+ // 提交交易
+ TransactionResponse response = ptx.commit();
+ Assert.assertTrue(response.isSuccess());
+ }
+
+}
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDKDemo_Contract_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDKDemo_Contract_Test_.java
deleted file mode 100644
index 4390c48c..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDKDemo_Contract_Test_.java
+++ /dev/null
@@ -1,165 +0,0 @@
-package test.com.jd.blockchain.sdk.test;
-
-import static com.jd.blockchain.sdk.samples.SDKDemo_Constant.readChainCodes;
-import static com.jd.blockchain.transaction.ContractReturnValue.decode;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.contract.TransferContract;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.KeyGenUtils;
-import com.jd.blockchain.crypto.PrivKey;
-import com.jd.blockchain.crypto.PubKey;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.sdk.samples.SDKDemo_Constant;
-import com.jd.blockchain.transaction.GenericValueHolder;
-import com.jd.blockchain.transaction.LongValueHolder;
-import com.jd.blockchain.utils.Bytes;
-
-public class SDKDemo_Contract_Test_ {
-
- private BlockchainKeypair adminKey;
-
- private HashDigest ledgerHash;
-
- private BlockchainService blockchainService;
-
- @Before
- public void init() {
- // 生成连接网关的账号
- PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(SDKDemo_Constant.PRIV_KEYS[0],
- SDKDemo_Constant.PASSWORD);
-
- PubKey pubKey = KeyGenUtils.decodePubKey(SDKDemo_Constant.PUB_KEYS[0]);
-
- adminKey = new BlockchainKeypair(pubKey, privKey);
-
- // 连接网关
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(SDKDemo_Constant.GW_IPADDR,
- SDKDemo_Constant.GW_PORT, false, adminKey);
-
- blockchainService = serviceFactory.getBlockchainService();
-
- HashDigest[] ledgerHashs = blockchainService.getLedgerHashs();
-
- ledgerHash = ledgerHashs[0];
- }
-
- @Test
- public void testContract() {
-
- // 发布jar包
- // 定义交易;
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
-
- byte[] contractCode = readChainCodes("transfer.jar");
-
- // 生成一个合约账号
- BlockchainKeypair contractDeployKey = BlockchainKeyGenerator.getInstance().generate();
-
- txTpl.contracts().deploy(contractDeployKey.getIdentity(), contractCode);
-
- // 签名;
- PreparedTransaction ptx = txTpl.prepare();
-
- ptx.sign(adminKey);
-
- // 提交并等待共识返回;
- TransactionResponse txResp = ptx.commit();
-
- System.out.println(txResp.isSuccess());
-
- // 首先注册一个数据账户
- BlockchainKeypair dataAccount = createDataAccount();
-
- String dataAddress = dataAccount.getAddress().toBase58();
-
- Bytes contractAddress = contractDeployKey.getAddress();
-
- // 创建两个账号:
- String account0 = "jd_zhangsan", account1 = "jd_lisi";
- long account0Money = 3000L, account1Money = 2000L;
- // 创建两个账户
- // 使用KV创建一个账户
- System.out.println(create(dataAddress, account0, account0Money, false, null));
- // 使用合约创建一个账户
- System.out.println(create(dataAddress, account1, account1Money, true, contractAddress));
-
- // 转账,使得双方钱达到一致
- System.out.println(transfer(dataAddress, account0, account1, 500L, contractAddress));
-
- // 读取当前结果
- System.out.println(read(dataAddress, account0, contractAddress));
- System.out.println(read(dataAddress, account1, contractAddress));
-
- // 读取账号历史信息
- System.out.println(readAll(dataAddress, account0, contractAddress));
- System.out.println(readAll(dataAddress, account1, contractAddress));
- }
-
- private String readAll(String address, String account, Bytes contractAddress) {
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- // 使用合约创建
- TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class);
- GenericValueHolder result = decode(transferContract.readAll(address, account));
- commit(txTpl);
- return result.get();
- }
-
- private long read(String address, String account, Bytes contractAddress) {
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- // 使用合约创建
- TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class);
- LongValueHolder result = decode(transferContract.read(address, account));
- commit(txTpl);
- return result.get();
- }
-
- private String transfer(String address, String from, String to, long money, Bytes contractAddress) {
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- // 使用合约创建
- TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class);
- GenericValueHolder result = decode(transferContract.transfer(address, from, to, money));
- commit(txTpl);
- return result.get();
- }
-
- private BlockchainKeypair createDataAccount() {
- // 首先注册一个数据账户
- BlockchainKeypair newDataAccount = BlockchainKeyGenerator.getInstance().generate();
-
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- txTpl.dataAccounts().register(newDataAccount.getIdentity());
- commit(txTpl);
- return newDataAccount;
- }
-
- private String create(String address, String account, long money, boolean useContract, Bytes contractAddress) {
- TransactionTemplate txTpl = blockchainService.newTransaction(ledgerHash);
- if (useContract) {
- // 使用合约创建
- TransferContract transferContract = txTpl.contract(contractAddress, TransferContract.class);
- GenericValueHolder result = decode(transferContract.create(address, account, money));
- commit(txTpl);
- return result.get();
- } else {
- // 通过KV创建
- txTpl.dataAccount(address).setInt64(account, money, -1);
- TransactionResponse txResp = commit(txTpl);
- return account + money;
- }
- }
-
- private TransactionResponse commit(TransactionTemplate txTpl) {
- PreparedTransaction ptx = txTpl.prepare();
- ptx.sign(adminKey);
- return ptx.commit();
- }
-}
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_Contract_Test.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_Contract_Test.java
deleted file mode 100644
index 244d8071..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_Contract_Test.java
+++ /dev/null
@@ -1,382 +0,0 @@
-package test.com.jd.blockchain.sdk.test;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import org.junit.Before;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-
-import com.jd.blockchain.contract.samples.AssetContract;
-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.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainIdentity;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.sdk.samples.SDKDemo_Contract;
-import com.jd.blockchain.utils.Bytes;
-import com.jd.blockchain.utils.codec.Base58Utils;
-import com.jd.blockchain.utils.io.ByteArray;
-import com.jd.blockchain.utils.net.NetworkAddress;
-import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils;
-
-/**
- * 演示合约执行的过程;
- *
- * @author zhaogw
- * 2019-05-21 11:03
- */
-public class SDK_Contract_Test {
- public static Logger log = LoggerFactory.getLogger(SDKDemo_Contract.class);
-
- public static BlockchainKeypair CLIENT_CERT = BlockchainKeyGenerator.getInstance().generate("ED25519");
- // 账本地址;
- public static String ledgerAddress;
- private PrivKey privKey;
- private PubKey pubKey;
- BlockchainService bcsrv;
- AsymmetricKeypair signKeyPair;
- HashDigest ledgerHash;
-
- @Before
- public void init(){
- ledgerAddress = "j5qHcS8jG6XwpE5wXv9HYMeGTb5Fs2gQao3TPQ3irqFpQL";
- ledgerHash = getLedgerHash();
- pubKey = SDK_GateWay_KeyPair_Para.pubKey0;
- privKey = SDK_GateWay_KeyPair_Para.privkey0;
- // 使用私钥进行签名;
- signKeyPair = new BlockchainKeypair(pubKey, privKey);
-
- // 创建服务代理;
- final String GATEWAY_IP = "localhost";
- final int GATEWAY_PORT = 11000;
- NetworkAddress addr = new NetworkAddress(GATEWAY_IP,GATEWAY_PORT);
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(addr);
- bcsrv = serviceFactory.getBlockchainService();
- }
-
-// /**
-// * 演示合约执行的过程;
-// */
-//// @Test
-// public void demoContract1() {
-// String dataAddress = registerData4Contract();
-// // 发起交易;
-// TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash);
-// String contractAddress = "LdeNg8JHFCKABJt6AaRNVCZPgY4ofGPd8MgcR";
-// AssetContract2 assetContract = txTemp.contract(contractAddress, AssetContract2.class);
-//// assetContract.issue(transactionContentBody,contractAddress);
-//// assetContract.issue(transactionContentBody,contractAddress,888888);
-//// assetContract.issue(Bytes.fromString("zhaogw, contract based interface is OK!"),contractAddress,77777);
-//// assetContract.issue(Bytes.fromString("zhaogw, contract based interface is OK!"),contractAddress,77777);
-// Byte byteObj = Byte.parseByte("127");
-// assetContract.issue(byteObj,dataAddress,321123);
-//// assetContract.issue(contractBizContent,dataAddress);
-// assetContract.issue(Byte.parseByte("126"),dataAddress,Bytes.fromString("100.234"));
-//
-// // TX 准备就绪;
-// PreparedTransaction prepTx = txTemp.prepare();
-// prepTx.sign(signKeyPair);
-// // 提交交易;
-// TransactionResponse transactionResponse = prepTx.commit();
-//
-// //check;
-// KVDataEntry[] dataEntries = bcsrv.getDataEntries(ledgerHash,dataAddress,"total");
-// assertEquals("100",dataEntries[0].getValue().toString());
-// }
-
-// /**
-// * 演示合约执行的过程;
-// */
-//// @Test
-// public void demoContract2() throws IOException {
-// String contractAddress = deploy();
-// String dataAddress = registerData4Contract();
-// System.out.println("dataAddress="+dataAddress);
-// // 发起交易;
-// TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash);
-//
-// AssetContract2 assetContract = txTemp.contract(contractAddress, AssetContract2.class);
-// ContractBizContent contractBizContent = () -> new String[]{"param1","param2"};
-// assetContract.issue(contractBizContent,dataAddress,123456);
-//
-// // TX 准备就绪;
-// PreparedTransaction prepTx = txTemp.prepare();
-// prepTx.sign(signKeyPair);
-// // 提交交易;
-// TransactionResponse transactionResponse = prepTx.commit();
-//
-// //check;
-// assertTrue(transactionResponse.isSuccess());
-// KVDataEntry[] dataEntries = bcsrv.getDataEntries(ledgerHash,dataAddress,contractBizContent.getAttrs()[0],contractBizContent.getAttrs()[1]);
-// assertEquals("value1",dataEntries[0].getValue().toString());
-// assertEquals(888,dataEntries[1].getValue());
-// }
-
-// @Test
- public void registerData(){
- // 在本地定义 TX 模板
- TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash);
- BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
- txTemp.dataAccounts().register(dataAccount.getIdentity());
-
- String key1 = "jd_key1";
- String val1 = "www.jd1.com";
- String key2 = "jd_key2";
- String val2 = "www.jd2.com";
- // 定义交易,传输最简单的数字、字符串、提取合约中的地址;
- txTemp.dataAccount(dataAccount.getAddress()).setText(key1, val1, -1);
- txTemp.dataAccount(dataAccount.getAddress()).setText(key2, val2, -1);
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
- prepTx.sign(signKeyPair);
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
-
- assertTrue(transactionResponse.isSuccess());
-
- //repeat;
- String[] keys = {key1,key2};
- String[] values = {"www.jd1.com.v1","www.jd2.com.v1"};
- this.setDataInDataAddress(dataAccount.getAddress(),keys,values,0);
- String[] values2 = {"www.jd1.com.v2","www.jd2.com.v2"};
- this.setDataInDataAddress(dataAccount.getAddress(),keys,values2,1);
- }
-
- private String registerData4Contract(){
- // 在本地定义 TX 模板
- TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash);
- BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
- txTemp.dataAccounts().register(dataAccount.getIdentity());
- 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 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
- prepTx.sign(signKeyPair);
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
- assertTrue(transactionResponse.isSuccess());
-
- return dataAccount.getAddress().toBase58();
- }
-
- private void setDataInDataAddress(Bytes dataAddress, String[] keys, String[] values, long version){
- // 在本地定义 TX 模板
- TransactionTemplate txTemp = bcsrv.newTransaction(ledgerHash);
- BlockchainKeypair dataAccount = BlockchainKeyGenerator.getInstance().generate();
-
- for(int i=0; i
- *
- * 注:私钥由调用方在本地保管和使用;
- *
- * @return
- */
- private static AsymmetricKeypair getSponsorKey() {
- SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519");
- return signatureFunction.generateKeypair();
- }
-
- /**
- * 商品信息;
- *
- * @author huanghaiquan
- *
- */
- public static class Remark {
-
- private String code;
-
- private String name;
-
- private String venderAddress;
-
- public String getCode() {
- return code;
- }
-
- public void setCode(String code) {
- this.code = code;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getVenderAddress() {
- return venderAddress;
- }
-
- public void setVenderAddress(String venderAddress) {
- this.venderAddress = venderAddress;
- }
-
- }
-
-// @Test
-// public void testStringArr(){
-// ContractBizContent contractBizContent = () -> new String[]{"1","2","you are welcome!"};
-// byte[] bizBytes = BinaryProtocol.encode(contractBizContent,ContractBizContent.class);
-// ContractBizContent actualObj = BinaryProtocol.decodeAs(bizBytes,ContractBizContent.class);
-// assertArrayEquals(contractBizContent.getAttrs(),actualObj.getAttrs());
-// }
-
-// @Test
-// public void testContractArgs(){
-// ContractBizContent contractBizContent = () -> new String[]{"param1"};
-// Method method = ReflectionUtils.findMethod(AssetContract2.class,"issue",ContractBizContent.class,String.class);
-// ContractArgs contractArgs = new ContractArgs() {
-// @Override
-// public Method getMethod() {
-// return method;
-// }
-//
-// @Override
-// public Object[] getArgs() {
-// return new Object[]{contractBizContent,"hello"};
-// }
-// };
-//
-// //add the annotation;
-//
-// }
-}
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java
deleted file mode 100644
index 747c835e..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_BatchInsertData_Test_.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/**
- * Copyright: Copyright 2016-2020 JD.COM All Right Reserved
- * FileName: test.com.jd.blockchain.sdk.test.SDK_GateWay_InsertData_Test
- * Author: shaozhuguang
- * Department: 区块链研发部
- * Date: 2018/9/4 上午11:06
- * Description: 插入数据测试
- */
-package test.com.jd.blockchain.sdk.test;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.Crypto;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.HashFunction;
-import com.jd.blockchain.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.EndpointRequest;
-import com.jd.blockchain.ledger.NodeRequest;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionContent;
-import com.jd.blockchain.ledger.TransactionContentBody;
-import com.jd.blockchain.ledger.TransactionRequest;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionState;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainTransactionService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.transaction.TxResponseMessage;
-import com.jd.blockchain.utils.codec.Base58Utils;
-
-/**
- * 插入数据测试
- * @author shaozhuguang
- * @create 2018/9/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_BatchInsertData_Test_ {
-
- String ledgerHash = "";
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainTransactionService service;
-
-
- @Before
- public void init() {
- CLIENT_CERT = BlockchainKeyGenerator.getInstance().generate("ED25519");
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 8000;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- }
-
- @Test
- public void batchInsertData_Test() {
- HashDigest ledgerHash = getLedgerHash();
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = service.newTransaction(ledgerHash);
-
- // --------------------------------------
- // 将商品信息写入到指定的账户中;
- // 对象将被序列化为 JSON 形式存储,并基于 JSON 结构建立查询索引;
- String dataAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
-
- String key1 = "jd_key1";
- String val1 = "www.jd.com";
-
- String key2 = "jd_key2";
- String val2 = "www.jd.com";
-
- txTemp.dataAccount(dataAccount).setText(key1, val1, -1);
- txTemp.dataAccount(dataAccount).setText(key2, val2, -1);
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- // 使用私钥进行签名;
- AsymmetricKeypair keyPair = getSponsorKey();
- prepTx.sign(keyPair);
-
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
-
- // 期望返回结果
- TransactionResponse expectResp = initResponse();
-
- System.out.println("---------- assert start ----------");
- assertEquals(expectResp.isSuccess(), transactionResponse.isSuccess());
- assertEquals(expectResp.getExecutionState(), transactionResponse.getExecutionState());
- assertEquals(expectResp.getContentHash(), transactionResponse.getContentHash());
- assertEquals(expectResp.getBlockHeight(), transactionResponse.getBlockHeight());
- assertEquals(expectResp.getBlockHash(), transactionResponse.getBlockHash());
- System.out.println("---------- assert OK ----------");
- }
-
- private HashDigest getLedgerHash() {
- byte[] hashBytes = Base58Utils.decode(ledgerHash);
- return new HashDigest(hashBytes);
- }
-
-
- private AsymmetricKeypair getSponsorKey() {
- SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519");
- return signatureFunction.generateKeypair();
- }
-
- private TransactionResponse initResponse() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");;
- HashDigest contentHash = hashFunc.hash("contentHash".getBytes());
- HashDigest blockHash = hashFunc.hash("blockHash".getBytes());
- long blockHeight = 9998L;
-
- TxResponseMessage resp = new TxResponseMessage(contentHash);
- resp.setBlockHash(blockHash);
- resp.setBlockHeight(blockHeight);
- resp.setExecutionState(TransactionState.SUCCESS);
- return resp;
- }
-}
\ No newline at end of file
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java
deleted file mode 100644
index 7d343505..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_DataAccount_Test_.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * Copyright: Copyright 2016-2020 JD.COM All Right Reserved
- * FileName: test.com.jd.blockchain.sdk.test.SDK_GateWay_InsertData_Test
- * Author: shaozhuguang
- * Department: 区块链研发部
- * Date: 2018/9/4 上午11:06
- * Description: 插入数据测试
- */
-package test.com.jd.blockchain.sdk.test;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.Crypto;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.HashFunction;
-import com.jd.blockchain.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.EndpointRequest;
-import com.jd.blockchain.ledger.NodeRequest;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionContent;
-import com.jd.blockchain.ledger.TransactionContentBody;
-import com.jd.blockchain.ledger.TransactionRequest;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionState;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.transaction.TxResponseMessage;
-
-/**
- * 插入数据测试
- * @author shaozhuguang
- * @create 2018/9/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_DataAccount_Test_ {
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainService service;
-
- @Before
- public void init() {
- CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0);
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 8081;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- }
-
- @Test
- public void registerDataAccount_Test() {
-// HashDigest ledgerHash = getLedgerHash();
- HashDigest[] ledgerHashs = service.getLedgerHashs();
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = service.newTransaction(ledgerHashs[0]);
-
-// SignatureFunction signatureFunction = getSignatureFunction();
-//
-// CryptoKeyPair cryptoKeyPair = signatureFunction.generateKeyPair();
-
- //existed signer
- AsymmetricKeypair keyPair = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey1, SDK_GateWay_KeyPair_Para.privkey1);
-
- BlockchainKeypair dataAcount = BlockchainKeyGenerator.getInstance().generate();
-
- // 注册
- txTemp.dataAccounts().register(dataAcount.getIdentity());
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- prepTx.sign(keyPair);
-
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
-
-// // 期望返回结果
-// TransactionResponse expectResp = initResponse();
-//
-// System.out.println("---------- assert start ----------");
-// assertEquals(expectResp.isSuccess(), transactionResponse.isSuccess());
-// assertEquals(expectResp.getExecutionState(), transactionResponse.getExecutionState());
-// assertEquals(expectResp.getContentHash(), transactionResponse.getContentHash());
-// assertEquals(expectResp.getBlockHeight(), transactionResponse.getBlockHeight());
-// assertEquals(expectResp.getBlockHash(), transactionResponse.getBlockHash());
-// System.out.println("---------- assert OK ----------");
- }
-
- private HashDigest getLedgerHash() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");;
- HashDigest ledgerHash =hashFunc.hash("jd-gateway".getBytes());
- return ledgerHash;
- }
-
- private SignatureFunction getSignatureFunction() {
- return Crypto.getSignatureFunction("ED25519");
- }
-
- private AsymmetricKeypair getSponsorKey() {
- return getSignatureFunction().generateKeypair();
- }
-
- private TransactionResponse initResponse() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");;
- HashDigest contentHash = hashFunc.hash("contentHash".getBytes());
- HashDigest blockHash = hashFunc.hash("blockHash".getBytes());
- long blockHeight = 9998L;
-
- TxResponseMessage resp = new TxResponseMessage(contentHash);
- resp.setBlockHash(blockHash);
- resp.setBlockHeight(blockHeight);
- resp.setExecutionState(TransactionState.SUCCESS);
- return resp;
- }
-}
\ No newline at end of file
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java
deleted file mode 100644
index ed6567e9..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_InsertData_Test_.java
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * Copyright: Copyright 2016-2020 JD.COM All Right Reserved
- * FileName: test.com.jd.blockchain.sdk.test.SDK_GateWay_InsertData_Test
- * Author: shaozhuguang
- * Department: 区块链研发部
- * Date: 2018/9/4 上午11:06
- * Description: 插入数据测试
- */
-package test.com.jd.blockchain.sdk.test;
-
-import static org.junit.Assert.assertEquals;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.Crypto;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.HashFunction;
-import com.jd.blockchain.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.EndpointRequest;
-import com.jd.blockchain.ledger.NodeRequest;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionContent;
-import com.jd.blockchain.ledger.TransactionContentBody;
-import com.jd.blockchain.ledger.TransactionRequest;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionState;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainTransactionService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.transaction.TxResponseMessage;
-
-/**
- * 插入数据测试
- * @author shaozhuguang
- * @create 2018/9/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_InsertData_Test_ {
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainTransactionService service;
-
-
- @Before
- public void init() {
- CLIENT_CERT = BlockchainKeyGenerator.getInstance().generate("ED25519");
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 8000;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- }
-
- @Test
- public void insertData_Test() {
- HashDigest ledgerHash = getLedgerHash();
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = service.newTransaction(ledgerHash);
-
- // --------------------------------------
- // 将商品信息写入到指定的账户中;
- // 对象将被序列化为 JSON 形式存储,并基于 JSON 结构建立查询索引;
- String dataAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
-
- String dataKey = "jd_code";
- String dataVal = "www.jd.com";
-
- txTemp.dataAccount(dataAccount).setText(dataKey, dataVal, -1);
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- // 使用私钥进行签名;
- AsymmetricKeypair keyPair = getSponsorKey();
- prepTx.sign(keyPair);
-
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
-
- // 期望返回结果
- TransactionResponse expectResp = initResponse();
-
- System.out.println("---------- assert start ----------");
- assertEquals(expectResp.isSuccess(), transactionResponse.isSuccess());
- assertEquals(expectResp.getExecutionState(), transactionResponse.getExecutionState());
- assertEquals(expectResp.getContentHash(), transactionResponse.getContentHash());
- assertEquals(expectResp.getBlockHeight(), transactionResponse.getBlockHeight());
- assertEquals(expectResp.getBlockHash(), transactionResponse.getBlockHash());
- System.out.println("---------- assert OK ----------");
- }
-
- private HashDigest getLedgerHash() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");
- HashDigest ledgerHash = hashFunc.hash("jd-gateway".getBytes());
- return ledgerHash;
- }
-
-
- private AsymmetricKeypair getSponsorKey() {
- SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519");
- return signatureFunction.generateKeypair();
- }
-
- private TransactionResponse initResponse() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");
- HashDigest contentHash = hashFunc.hash("contentHash".getBytes());
- HashDigest blockHash = hashFunc.hash("blockHash".getBytes());
- long blockHeight = 9998L;
-
- TxResponseMessage resp = new TxResponseMessage(contentHash);
- resp.setBlockHash(blockHash);
- resp.setBlockHeight(blockHeight);
- resp.setExecutionState(TransactionState.SUCCESS);
- return resp;
- }
-}
\ No newline at end of file
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_KeyPair_Para.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_KeyPair_Para.java
deleted file mode 100644
index 706cd370..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_KeyPair_Para.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package test.com.jd.blockchain.sdk.test;
-
-import com.jd.blockchain.crypto.KeyGenUtils;
-import com.jd.blockchain.crypto.PrivKey;
-import com.jd.blockchain.crypto.PubKey;
-
-/**
- * Created by zhangshuang3 on 2018/10/17.
- */
-public class SDK_GateWay_KeyPair_Para {
- public static final String PASSWORD = "abc";
-
- public static final String[] PUB_KEYS = { "3snPdw7i7PjVKiTH2VnXZu5H8QmNaSXpnk4ei533jFpuifyjS5zzH9",
- "3snPdw7i7PajLB35tEau1kmixc6ZrjLXgxwKbkv5bHhP7nT5dhD9eX",
- "3snPdw7i7PZi6TStiyc6mzjprnNhgs2atSGNS8wPYzhbKaUWGFJt7x",
- "3snPdw7i7PifPuRX7fu3jBjsb3rJRfDe9GtbDfvFJaJ4V4hHXQfhwk" };
-
- public static final String[] PRIV_KEYS = {
- "177gjzHTznYdPgWqZrH43W3yp37onm74wYXT4v9FukpCHBrhRysBBZh7Pzdo5AMRyQGJD7x",
- "177gju9p5zrNdHJVEQnEEKF4ZjDDYmAXyfG84V5RPGVc5xFfmtwnHA7j51nyNLUFffzz5UT",
- "177gjtwLgmSx5v1hFb46ijh7L9kdbKUpJYqdKVf9afiEmAuLgo8Rck9yu5UuUcHknWJuWaF",
- "177gk1pudweTq5zgJTh8y3ENCTwtSFsKyX7YnpuKPo7rKgCkCBXVXh5z2syaTCPEMbuWRns" };
-
- public static PrivKey privkey0 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD);
- public static PrivKey privkey1 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD);
- public static PrivKey privkey2 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD);
- public static PrivKey privkey3 = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD);
-
- public static PubKey pubKey0 = KeyGenUtils.decodePubKey(PUB_KEYS[0]);
- public static PubKey pubKey1 = KeyGenUtils.decodePubKey(PUB_KEYS[1]);
- public static PubKey pubKey2 = KeyGenUtils.decodePubKey(PUB_KEYS[2]);
- public static PubKey pubKey3 = KeyGenUtils.decodePubKey(PUB_KEYS[3]);
-
-}
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_Regist_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_Regist_Test_.java
deleted file mode 100644
index 634357f5..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Participant_Regist_Test_.java
+++ /dev/null
@@ -1,103 +0,0 @@
-package test.com.jd.blockchain.sdk.test;
-
-import static org.junit.Assert.assertTrue;
-
-import com.jd.blockchain.ledger.*;
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AddressEncoding;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.KeyGenUtils;
-import com.jd.blockchain.crypto.PrivKey;
-import com.jd.blockchain.crypto.PubKey;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.sdk.samples.SDKDemo_Constant;
-import com.jd.blockchain.utils.net.NetworkAddress;
-
-/**
- * 注册参与方测试
- * @author zhangshuang
- * @create 2019/7/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_Participant_Regist_Test_ {
-
- private PrivKey privKey;
- private PubKey pubKey;
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainService service;
-
- //根据密码工具产生的公私钥
- static String PUB = "3snPdw7i7PkdgqiGX7GbZuFSi1cwZn7vtjw4vifb1YoXgr9k6Kfmis";
- String PRIV = "177gjtZu8w1phqHFVNiFhA35cfimXmP6VuqrBFhfbXBWK8s4TRwro2tnpffwP1Emwr6SMN6";
-
- @Before
- public void init() {
-
- privKey = SDK_GateWay_KeyPair_Para.privkey1;
- pubKey = SDK_GateWay_KeyPair_Para.pubKey1;
-
- CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0);
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 11000;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- DataContractRegistry.register(ParticipantRegisterOperation.class);
- DataContractRegistry.register(ParticipantStateUpdateOperation.class);
- DataContractRegistry.register(ConsensusSettingsUpdateOperation.class);
- }
-
- @Test
- public void registerParticipant_Test() {
- HashDigest[] ledgerHashs = service.getLedgerHashs();
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = service.newTransaction(ledgerHashs[0]);
-
- //existed signer
- AsymmetricKeypair keyPair = new BlockchainKeypair(pubKey, privKey);
-
- PrivKey privKey = KeyGenUtils.decodePrivKeyWithRawPassword(PRIV, SDKDemo_Constant.PASSWORD);
-
- PubKey pubKey = KeyGenUtils.decodePubKey(PUB);
-
- System.out.println("Address = "+AddressEncoding.generateAddress(pubKey));
-
- BlockchainKeypair user = new BlockchainKeypair(pubKey, privKey);
-
- // 注册参与方
- txTemp.participants().register("Peer4", user.getIdentity());
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- // 使用私钥进行签名;
- prepTx.sign(keyPair);
-
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
- assertTrue(transactionResponse.isSuccess());
-
- }
-}
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java
deleted file mode 100644
index 3d291811..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_Query_Test_.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/**
- * Copyright: Copyright 2016-2020 JD.COM All Right Reserved
- * FileName: test.com.jd.blockchain.sdk.test.SDK_GateWay_InsertData_Test
- * Author: shaozhuguang
- * Department: 区块链研发部
- * Date: 2018/9/4 上午11:06
- * Description: 插入数据测试
- */
-package test.com.jd.blockchain.sdk.test;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.Crypto;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.HashFunction;
-import com.jd.blockchain.crypto.PubKey;
-import com.jd.blockchain.crypto.SignatureDigest;
-import com.jd.blockchain.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainIdentity;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.DigitalSignature;
-import com.jd.blockchain.ledger.EndpointRequest;
-import com.jd.blockchain.ledger.TypedKVEntry;
-import com.jd.blockchain.ledger.LedgerBlock;
-import com.jd.blockchain.ledger.LedgerInfo;
-import com.jd.blockchain.ledger.LedgerTransaction;
-import com.jd.blockchain.ledger.NodeRequest;
-import com.jd.blockchain.ledger.ParticipantNode;
-import com.jd.blockchain.ledger.Transaction;
-import com.jd.blockchain.ledger.TransactionContent;
-import com.jd.blockchain.ledger.TransactionContentBody;
-import com.jd.blockchain.ledger.TransactionRequest;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionState;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.transaction.TxResponseMessage;
-import com.jd.blockchain.utils.serialize.json.JSONSerializeUtils;
-
-/**
- * 插入数据测试
- *
- * @author shaozhuguang
- * @create 2018/9/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_Query_Test_ {
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainService service;
-
- @Before
- public void init() {
- CLIENT_CERT = BlockchainKeyGenerator.getInstance().generate("ED25519");
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 11000;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- }
-
- @Test
- public void query_Test() {
-
- HashDigest ledgerHash = service.getLedgerHashs()[0];
- ;
- // ParserConfig.global.setAutoTypeSupport(true);
-
- LedgerInfo ledgerInfo = service.getLedger(ledgerHash);
- long ledgerNumber = ledgerInfo.getLatestBlockHeight();
- System.out.println(ledgerNumber);
- HashDigest hashDigest = ledgerInfo.getHash();
- System.out.println(hashDigest);
- // 最新区块;
- LedgerBlock latestBlock = service.getBlock(ledgerHash, ledgerNumber);
- System.out.println("latestBlock.Hash=" + latestBlock.getHash());
- long count = service.getContractCount(ledgerHash, 3L);
- System.out.println("contractCount=" + count);
- count = service.getContractCount(ledgerHash, hashDigest);
- System.out.println("contractCount=" + count);
- BlockchainIdentity contract = service.getContract(ledgerHash, "12345678");
- System.out.println(contract);
-
- LedgerBlock block = service.getBlock(ledgerHash, hashDigest);
- System.out.println("block.Hash=" + block.getHash());
-
- count = service.getDataAccountCount(ledgerHash, 123456);
- System.out.println("dataAccountCount=" + count);
- count = service.getDataAccountCount(ledgerHash, hashDigest);
- System.out.println("dataAccountCount=" + count);
-
- BlockchainIdentity dataAccount = service.getDataAccount(ledgerHash, "1245633");
- System.out.println(dataAccount.getAddress());
-
- count = service.getTransactionCount(ledgerHash, hashDigest);
- System.out.println("transactionCount=" + count);
- count = service.getTransactionCount(ledgerHash, 12456);
- System.out.println("transactionCount=" + count);
-
- LedgerTransaction[] txList = service.getTransactions(ledgerHash, ledgerNumber, 0, 100);
- for (LedgerTransaction ledgerTransaction : txList) {
- System.out.println("ledgerTransaction.Hash=" + ledgerTransaction.getHash());
- }
-
- txList = service.getTransactions(ledgerHash, hashDigest, 0, 100);
- for (LedgerTransaction ledgerTransaction : txList) {
- System.out.println("ledgerTransaction.Hash=" + ledgerTransaction.getHash());
- }
-
- Transaction tx = service.getTransactionByContentHash(ledgerHash, hashDigest);
- DigitalSignature[] signatures = tx.getEndpointSignatures();
- for (DigitalSignature signature : signatures) {
- System.out.println(signature.getDigest().getAlgorithm());
- }
- System.out.println("transaction.blockHeight=" + tx.getBlockHeight());
- System.out.println("transaction.executionState=" + tx.getExecutionState());
-
- ParticipantNode[] participants = service.getConsensusParticipants(ledgerHash);
- for (ParticipantNode participant : participants) {
- System.out.println("participant.name=" + participant.getName());
- // System.out.println(participant.getConsensusAddress());
- // System.out.println("participant.host=" +
- // participant.getConsensusAddress().getHost());
- System.out.println("participant.getPubKey=" + participant.getPubKey());
- System.out.println("participant.getKeyType=" + participant.getPubKey().getKeyType());
- System.out.println("participant.getRawKeyBytes=" + participant.getPubKey().getRawKeyBytes());
- System.out.println("participant.algorithm=" + participant.getPubKey().getAlgorithm());
- }
-
- String commerceAccount = "GGhhreGeasdfasfUUfehf9932lkae99ds66jf==";
- String[] objKeys = new String[] { "x001", "x002" };
- TypedKVEntry[] kvData = service.getDataEntries(ledgerHash, commerceAccount, objKeys);
- for (TypedKVEntry kvDatum : kvData) {
- System.out.println("kvData.key=" + kvDatum.getKey());
- System.out.println("kvData.version=" + kvDatum.getVersion());
- System.out.println("kvData.value=" + kvDatum.getValue());
- }
-
- HashDigest[] hashs = service.getLedgerHashs();
- for (HashDigest hash : hashs) {
- System.out.println("hash.toBase58=" + hash.toBase58());
- }
- }
-
- private HashDigest getLedgerHash() {
- HashDigest ledgerHash = Crypto.getHashFunction("SHA256").hash("jd-gateway".getBytes());
- return ledgerHash;
- }
-
- private SignatureFunction getSignatureFunction() {
- return Crypto.getSignatureFunction("ED25519");
- }
-
- private BlockchainKeypair getSponsorKey() {
- SignatureFunction signatureFunction = getSignatureFunction();
- AsymmetricKeypair cryptoKeyPair = signatureFunction.generateKeypair();
- BlockchainKeypair blockchainKeyPair = new BlockchainKeypair(cryptoKeyPair.getPubKey(),
- cryptoKeyPair.getPrivKey());
- return blockchainKeyPair;
- }
-
- private TransactionResponse initResponse() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");
- HashDigest contentHash = hashFunc.hash("contentHash".getBytes());
- HashDigest blockHash = hashFunc.hash("blockHash".getBytes());
- long blockHeight = 9998L;
-
- TxResponseMessage resp = new TxResponseMessage(contentHash);
- resp.setBlockHash(blockHash);
- resp.setBlockHeight(blockHeight);
- resp.setExecutionState(TransactionState.SUCCESS);
- return resp;
- }
-}
\ No newline at end of file
diff --git a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java b/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java
deleted file mode 100644
index d69b0f97..00000000
--- a/samples/sdk-samples/src/test/java/test/com/jd/blockchain/sdk/test/SDK_GateWay_User_Test_.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Copyright: Copyright 2016-2020 JD.COM All Right Reserved
- * FileName: test.com.jd.blockchain.sdk.test.SDK_GateWay_InsertData_Test
- * Author: shaozhuguang
- * Department: 区块链研发部
- * Date: 2018/9/4 上午11:06
- * Description: 插入数据测试
- */
-package test.com.jd.blockchain.sdk.test;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import com.jd.blockchain.binaryproto.DataContractRegistry;
-import com.jd.blockchain.crypto.AsymmetricKeypair;
-import com.jd.blockchain.crypto.Crypto;
-import com.jd.blockchain.crypto.HashDigest;
-import com.jd.blockchain.crypto.HashFunction;
-import com.jd.blockchain.crypto.PrivKey;
-import com.jd.blockchain.crypto.PubKey;
-import com.jd.blockchain.crypto.SignatureFunction;
-import com.jd.blockchain.ledger.BlockchainKeyGenerator;
-import com.jd.blockchain.ledger.BlockchainKeypair;
-import com.jd.blockchain.ledger.EndpointRequest;
-import com.jd.blockchain.ledger.NodeRequest;
-import com.jd.blockchain.ledger.PreparedTransaction;
-import com.jd.blockchain.ledger.TransactionContent;
-import com.jd.blockchain.ledger.TransactionContentBody;
-import com.jd.blockchain.ledger.TransactionRequest;
-import com.jd.blockchain.ledger.TransactionResponse;
-import com.jd.blockchain.ledger.TransactionState;
-import com.jd.blockchain.ledger.TransactionTemplate;
-import com.jd.blockchain.sdk.BlockchainService;
-import com.jd.blockchain.sdk.client.GatewayServiceFactory;
-import com.jd.blockchain.transaction.TxResponseMessage;
-
-/**
- * 插入数据测试
- * @author shaozhuguang
- * @create 2018/9/4
- * @since 1.0.0
- */
-
-public class SDK_GateWay_User_Test_ {
-
-// public static final String PASSWORD = SDK_GateWay_KeyPair_Para.PASSWORD;
-//
-// public static final String[] PUB_KEYS = SDK_GateWay_KeyPair_Para.PUB_KEYS;
-//
-// public static final String[] PRIV_KEYS = SDK_GateWay_KeyPair_Para.PRIV_KEYS;
-
- private PrivKey privKey;
- private PubKey pubKey;
-
- private BlockchainKeypair CLIENT_CERT = null;
-
- private String GATEWAY_IPADDR = null;
-
- private int GATEWAY_PORT;
-
- private boolean SECURE;
-
- private BlockchainService service;
-
- @Before
- public void init() {
-
-// PrivKey privkey0 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[0], PASSWORD);
-// PrivKey privkey1 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[1], PASSWORD);
-// PrivKey privkey2 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[2], PASSWORD);
-// PrivKey privkey3 = KeyGenCommand.decodePrivKeyWithRawPassword(PRIV_KEYS[3], PASSWORD);
-//
-// PubKey pubKey0 = KeyGenCommand.decodePubKey(PUB_KEYS[0]);
-// PubKey pubKey1 = KeyGenCommand.decodePubKey(PUB_KEYS[1]);
-// PubKey pubKey2 = KeyGenCommand.decodePubKey(PUB_KEYS[2]);
-// PubKey pubKey3 = KeyGenCommand.decodePubKey(PUB_KEYS[3]);
-
- privKey = SDK_GateWay_KeyPair_Para.privkey1;
- pubKey = SDK_GateWay_KeyPair_Para.pubKey1;
-
- CLIENT_CERT = new BlockchainKeypair(SDK_GateWay_KeyPair_Para.pubKey0, SDK_GateWay_KeyPair_Para.privkey0);
- GATEWAY_IPADDR = "127.0.0.1";
- GATEWAY_PORT = 10300;
- SECURE = false;
- GatewayServiceFactory serviceFactory = GatewayServiceFactory.connect(GATEWAY_IPADDR, GATEWAY_PORT, SECURE,
- CLIENT_CERT);
- service = serviceFactory.getBlockchainService();
-
- DataContractRegistry.register(TransactionContent.class);
- DataContractRegistry.register(TransactionContentBody.class);
- DataContractRegistry.register(TransactionRequest.class);
- DataContractRegistry.register(NodeRequest.class);
- DataContractRegistry.register(EndpointRequest.class);
- DataContractRegistry.register(TransactionResponse.class);
- }
-
- @Test
- public void registerUser_Test() {
- HashDigest[] ledgerHashs = service.getLedgerHashs();
- // 在本地定义注册账号的 TX;
- TransactionTemplate txTemp = service.newTransaction(ledgerHashs[0]);
-
- //existed signer
- AsymmetricKeypair keyPair = new BlockchainKeypair(pubKey, privKey);
-
- BlockchainKeypair user = BlockchainKeyGenerator.getInstance().generate();
-
- // 注册
- txTemp.users().register(user.getIdentity());
-
- // TX 准备就绪;
- PreparedTransaction prepTx = txTemp.prepare();
-
- // 使用私钥进行签名;
- prepTx.sign(keyPair);
-
- // 提交交易;
- TransactionResponse transactionResponse = prepTx.commit();
- assertTrue(transactionResponse.isSuccess());
-
- // 期望返回结果
-// TransactionResponse expectResp = initResponse();
-//
-// System.out.println("---------- assert start ----------");
-// assertEquals(expectResp.isSuccess(), transactionResponse.isSuccess());
-// assertEquals(expectResp.getExecutionState(), transactionResponse.getExecutionState());
-// assertEquals(expectResp.getContentHash(), transactionResponse.getContentHash());
-// assertEquals(expectResp.getBlockHeight(), transactionResponse.getBlockHeight());
-// assertEquals(expectResp.getBlockHash(), transactionResponse.getBlockHash());
-// System.out.println("---------- assert OK ----------");
- }
-
-// private HashDigest getLedgerHash() {
-// byte[] hashBytes = Base58Utils.decode(ledgerHashBase58);
-// return new HashDigest(hashBytes);
-// }
-
- private AsymmetricKeypair getSponsorKey() {
- SignatureFunction signatureFunction = Crypto.getSignatureFunction("ED25519");
- return signatureFunction.generateKeypair();
- }
-
- private TransactionResponse initResponse() {
- HashFunction hashFunc = Crypto.getHashFunction("SHA256");;
- HashDigest contentHash = hashFunc.hash("contentHash".getBytes());
- HashDigest blockHash = hashFunc.hash("blockHash".getBytes());
- long blockHeight = 9998L;
-
- TxResponseMessage resp = new TxResponseMessage(contentHash);
- resp.setBlockHash(blockHash);
- resp.setBlockHeight(blockHeight);
- resp.setExecutionState(TransactionState.SUCCESS);
- return resp;
- }
-}
\ No newline at end of file
diff --git a/samples/sdk-samples/src/test/resources/contract.jar b/samples/sdk-samples/src/test/resources/contract.jar
deleted file mode 100644
index 3ff8a821..00000000
Binary files a/samples/sdk-samples/src/test/resources/contract.jar and /dev/null differ
diff --git a/samples/sdk-samples/src/test/resources/sys-contract.properties b/samples/sdk-samples/src/test/resources/sys-contract.properties
deleted file mode 100644
index a1457b06..00000000
--- a/samples/sdk-samples/src/test/resources/sys-contract.properties
+++ /dev/null
@@ -1,13 +0,0 @@
-#ledger info;
-ownerPubPath=F:\\jdsk\\jdsk-files\\github\\jdchain-starter\\conf\\jd-com.pub
-ownerPrvPath=F:\\jdsk\\jdsk-files\\github\\jdchain-starter\\conf\\jd-com.priv
-ownerPassword=F:\\jdsk\\jdsk-files\\github\\jdchain-starter\\conf\\jd-com.pwd
-ledgerHash=j5rpuGWVxSuUbU3gK7MDREfui797AjfdHzvAMiSaSzydu7
-host=localhost
-port=11000
-#execute contract;
-event = issue-asset
-chainCodePath=F:\\jdsk\\jdsk-files\\github\\jdchain-starter\\contract-compile\\target\\contract.jar
-contractArgs=1000##fromAddr##LdeNvLeq6MB6y8CoyawYxgCCYCJkrp5xoVGUw
-#contractArgs=fromAddr##toAddr##30##LdeNvLeq6MB6y8CoyawYxgCCYCJkrp5xoVGUw
-
diff --git a/samples/sdk-samples/src/test/resources/transfer.jar b/samples/sdk-samples/src/test/resources/transfer.jar
deleted file mode 100644
index a161392e..00000000
Binary files a/samples/sdk-samples/src/test/resources/transfer.jar and /dev/null differ
diff --git a/test b/test
index f5057486..4c7a4ee0 160000
--- a/test
+++ b/test
@@ -1 +1 @@
-Subproject commit f5057486324d0daf2f8ef9f223a04537d03edede
+Subproject commit 4c7a4ee0374f24dea15b087d730bb8843f201205