OSDN Git Service

add listById() method and listByAccountId() method
authorsuccessli <successli@outlook.com>
Tue, 29 May 2018 07:15:05 +0000 (15:15 +0800)
committersuccessli <successli@outlook.com>
Tue, 29 May 2018 07:15:05 +0000 (15:15 +0800)
.gitignore
src/main/java/io/bytom/api/Transaction.java
src/test/java/io/bytom/integration/TransactionTest.java

index f2d2e8a..ba2edb6 100644 (file)
@@ -2,4 +2,5 @@
 *.iml
 target/
 bytom.log
+bytom.log.*
 javadoc/
index 329c7df..669fbdf 100644 (file)
@@ -157,11 +157,19 @@ public class Transaction {
 
         public String txId;
 
+        public String accountId;
+
         public QueryBuilder setTxId(String txId) {
             this.txId = txId;
             return this;
         }
 
+        public QueryBuilder setAccountId(String accountId) {
+            this.accountId = accountId;
+            return this;
+        }
+
+
         /**
          * call list-transactions api
          *
@@ -172,10 +180,49 @@ public class Transaction {
         public List<Transaction> list(Client client) throws BytomException {
 
             Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Transaction.class});
-            List<Transaction> transactionList = client.request("list-transactions", this, listType);
+            List<Transaction> transactionList = client.request("list-transactions", null, listType);
+
             logger.info("list-transactions:");
             logger.info("size of transactionList:" + transactionList.size());
-            logger.info(transactionList.get(0).toJson());
+            logger.info("all transactions:");
+            for (int i = 0; i < transactionList.size(); i++) {
+                logger.info(transactionList.get(i).toJson());
+            }
+
+            return transactionList;
+        }
+
+        public List<Transaction> listById(Client client) throws BytomException {
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("tx_id", this.txId);
+            req.put("detail", true);
+
+            Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Transaction.class});
+            List<Transaction> transactionList = client.request("list-transactions", req, listType);
+
+            logger.info("list-transactions:");
+            logger.info("size of transactionList:" + transactionList.size());
+            logger.info("all transactions:");
+            for (int i = 0; i < transactionList.size(); i++) {
+                logger.info(transactionList.get(i).toJson());
+            }
+
+            return transactionList;
+        }
+
+        public List<Transaction> listByAccountId(Client client) throws BytomException {
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("account_id", this.accountId);
+
+            Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Transaction.class});
+            List<Transaction> transactionList = client.request("list-transactions", req, listType);
+
+            logger.info("list-transactions:");
+            logger.info("size of transactionList:" + transactionList.size());
+            logger.info("all transactions:");
+            for (int i = 0; i < transactionList.size(); i++) {
+                logger.info(transactionList.get(i).toJson());
+            }
 
             return transactionList;
         }
@@ -188,10 +235,14 @@ public class Transaction {
          * @throws BytomException
          */
         public Transaction get(Client client) throws BytomException {
-            // TODO: 2018/5/23 need to test 
-            Transaction transaction = client.request("get-transaction", this, Transaction.class);
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("tx_id", this.txId);
+
+            Transaction transaction = client.request("get-transaction", req, Transaction.class);
+
             logger.info("get-transaction:");
             logger.info(transaction.toJson());
+
             return transaction;
         }
 
index da84fd0..447ab7a 100644 (file)
@@ -123,18 +123,29 @@ public class TransactionTest {
     }
 
     @Test
-    public void testListTransactions() throws Exception {
-        String tx_id = "b9a1baa1ae391b502fe5543a9559e6d98dc6cf77f9327daaebcb7222c3bebda6";
+    public void testListByIdTransactions() throws Exception {
+        String tx_id = "f04d4d9b2580ff6496f9f08d903de5a2365975fb8d65b66ca4259f152c5dd134";
         List<Transaction> transactionList =
                 new Transaction.QueryBuilder().setTxId(tx_id).list(client);
         for (Transaction tx: transactionList
              ) {
             if (tx.txId.equalsIgnoreCase(tx_id)) {
+                logger.info("this transaction is :");
                 logger.info(tx.toJson());
             }
         }
     }
 
+    @Test
+    public void testListByAccountIdTransactions() throws Exception {
+        String account_id = "0E6KP8C100A02";
+        List<Transaction> transactionList =
+                new Transaction.QueryBuilder().setAccountId(account_id).list(client);
+    }
+
+
+
+
     public void testSenderKeyCreate() throws Exception {
         String alias = "sender-key";
         String password = "123456";