OSDN Git Service

add Feed to Transaction class
authorsuccessli <successli@outlook.com>
Wed, 30 May 2018 07:59:17 +0000 (15:59 +0800)
committersuccessli <successli@outlook.com>
Wed, 30 May 2018 07:59:17 +0000 (15:59 +0800)
src/main/java/io/bytom/api/Transaction.java
src/main/java/io/bytom/api/TransactionFeed.java [deleted file]
src/test/java/io/bytom/integration/TransactionFeedTest.java [deleted file]
src/test/java/io/bytom/integration/TransactionTest.java

index 669fbdf..10e2d76 100644 (file)
@@ -262,7 +262,6 @@ public class Transaction {
          */
         public Template sign(Client client, Template template,
                                          String password) throws BytomException {
-            // TODO: 2018/5/23 need to test
             HashMap<String, Object> req = new HashMap<String, Object>();
             req.put("transaction", template);
             req.put("password", password);
@@ -1030,4 +1029,153 @@ public class Transaction {
         body.put("transaction_template", template);
         return client.request("estimate-transaction-gas", body, TransactionGas.class);
     }
+
+    public static class Feed {
+        /**
+         * name of the transaction feed.
+         */
+        public String alias;
+        /**
+         * filter, filter of the transaction feed.
+         */
+        public String filter;
+
+        /**
+         * param, param of the transaction feed.
+         */
+        public TransactionFeedParam param;
+
+        private static Logger logger = Logger.getLogger(Transaction.class);
+
+        /**
+         * Serializes the TransactionFeed into a form that is safe to transfer over the wire.
+         *
+         * @return the JSON-serialized representation of the TransactionFeed object
+         */
+        public String toJson() {
+            return Utils.serializer.toJson(this);
+        }
+
+        public static class Builder {
+
+            public String alias;
+
+            public String filter;
+
+            public Builder() {
+            }
+
+            public Builder setAlias(String alias) {
+                this.alias = alias;
+                return this;
+            }
+
+            public Builder setFilter(String filter) {
+                this.filter = filter;
+                return this;
+            }
+
+            /**
+             * Call create-transaction-feed api
+             *
+             * @param client
+             * @throws BytomException
+             */
+            public void create(Client client) throws BytomException {
+                client.request("create-transaction-feed", this);
+                logger.info("create-transaction-feed");
+            }
+        }
+
+        /**
+         * Call get-transaction-feed api
+         *
+         * @param client
+         * @param alias
+         * @return
+         * @throws BytomException
+         */
+        public static Feed getByAlias(Client client, String alias) throws BytomException {
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("alias", alias);
+
+            // the return param contains txfeed.
+            Feed transactionFeed = client.requestGet("get-transaction-feed",
+                    req, "txfeed", Feed.class);
+            logger.info("get-transaction-feed.");
+            logger.info(transactionFeed.toJson());
+
+            return transactionFeed;
+        }
+
+        /**
+         * Call update-transaction-feed api
+         *
+         * @param client
+         * @param alias
+         * @param filter
+         * @throws BytomException
+         */
+        public static void update(Client client, String alias, String filter) throws BytomException {
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("alias", alias);
+            req.put("filter", filter);
+            client.request("update-transaction-feed", req);
+            logger.info("update-transaction-feed successfully");
+        }
+
+        /**
+         * Call list-transaction-feeds api
+         * @param client
+         * @return
+         * @throws BytomException
+         */
+        public static List<Feed> list(Client client) throws BytomException {
+
+            Type listType = new ParameterizedTypeImpl(List.class, new Class[]{Feed.class});
+            List<Feed> transactionFeedList = client.request("list-transaction-feeds", null, listType);
+
+            logger.info("list-transaction-feeds:");
+            logger.info("size of transactionList:" + transactionFeedList.size());
+            for (int i =0 ;i < transactionFeedList.size();i++) {
+                logger.info(transactionFeedList.get(i).toJson());
+            }
+            return transactionFeedList;
+        }
+
+        /**
+         * Call delete-transaction-feed api
+         *
+         * @param client
+         * @param alias
+         * @throws BytomException
+         */
+        public static void deleteByAlias(Client client, String alias) throws BytomException {
+            Map<String, Object> req = new HashMap<String, Object>();
+            req.put("alias", alias);
+            client.request("delete-transaction-feed", req);
+            logger.info("delete-transaction-feed successfully");
+        }
+
+
+
+        public class TransactionFeedParam {
+
+            /**
+             * assetid
+             */
+            public String assetid;
+
+            /**
+             * lowerlimit
+             */
+            public long lowerlimit;
+
+            /**
+             * upperlimit
+             */
+            public long upperlimit;
+
+        }
+    }
 }
diff --git a/src/main/java/io/bytom/api/TransactionFeed.java b/src/main/java/io/bytom/api/TransactionFeed.java
deleted file mode 100644 (file)
index 5d6f16a..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-package io.bytom.api;
-
-import io.bytom.common.Utils;
-import io.bytom.exception.BytomException;
-import io.bytom.http.Client;
-import org.apache.log4j.Logger;
-
-import java.lang.reflect.Type;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class TransactionFeed {
-    /**
-     * name of the transaction feed.
-     */
-    public String alias;
-    /**
-     * filter, filter of the transaction feed.
-     */
-    public String filter;
-
-    /**
-     * param, param of the transaction feed.
-     */
-    public TransactionFeedParam param;
-
-    private static Logger logger = Logger.getLogger(Transaction.class);
-
-    /**
-     * Serializes the TransactionFeed into a form that is safe to transfer over the wire.
-     *
-     * @return the JSON-serialized representation of the TransactionFeed object
-     */
-    public String toJson() {
-        return Utils.serializer.toJson(this);
-    }
-
-    public static class Builder {
-
-        public String alias;
-
-        public String filter;
-
-        public Builder() {
-        }
-
-        public Builder setAlias(String alias) {
-            this.alias = alias;
-            return this;
-        }
-
-        public Builder setFilter(String filter) {
-            this.filter = filter;
-            return this;
-        }
-
-        /**
-         * Call create-transaction-feed api
-         *
-         * @param client
-         * @throws BytomException
-         */
-        public void create(Client client) throws BytomException {
-            client.request("create-transaction-feed", this);
-            logger.info("create-transaction-feed");
-        }
-    }
-
-    /**
-     * Call get-transaction-feed api
-     *
-     * @param client
-     * @param alias
-     * @return
-     * @throws BytomException
-     */
-    public static TransactionFeed get(Client client, String alias) throws BytomException {
-        Map<String, Object> req = new HashMap<String, Object>();
-        req.put("alias", alias);
-
-        // the return param contains txfeed.
-        TransactionFeed transactionFeed = client.requestGet("get-transaction-feed",
-                                                req, "txfeed", TransactionFeed.class);
-        logger.info("get-transaction-feed.");
-        logger.info(transactionFeed.toJson());
-
-        return transactionFeed;
-    }
-
-    /**
-     * Call update-transaction-feed api
-     *
-     * @param client
-     * @param alias
-     * @param filter
-     * @throws BytomException
-     */
-    public static void update(Client client, String alias, String filter) throws BytomException {
-        Map<String, Object> req = new HashMap<String, Object>();
-        req.put("alias", alias);
-        req.put("filter", filter);
-        client.request("update-transaction-feed", req);
-        logger.info("update-transaction-feed successfully");
-    }
-
-    /**
-     * Call list-transaction-feeds api
-     * @param client
-     * @return
-     * @throws BytomException
-     */
-    public static List<TransactionFeed> list(Client client) throws BytomException {
-
-        Type listType = new ParameterizedTypeImpl(List.class, new Class[]{TransactionFeed.class});
-        List<TransactionFeed> transactionFeedList = client.request("list-transaction-feeds", null, listType);
-
-        logger.info("list-transaction-feeds:");
-        logger.info("size of transactionList:" + transactionFeedList.size());
-        for (int i =0 ;i < transactionFeedList.size();i++) {
-            logger.info(transactionFeedList.get(i).toJson());
-        }
-        return transactionFeedList;
-    }
-
-    /**
-     * Call delete-transaction-feed api
-     *
-     * @param client
-     * @param alias
-     * @throws BytomException
-     */
-    public static void delete(Client client, String alias) throws BytomException {
-        Map<String, Object> req = new HashMap<String, Object>();
-        req.put("alias", alias);
-        client.request("delete-transaction-feed", req);
-        logger.info("delete-transaction-feed successfully");
-    }
-
-
-
-    public class TransactionFeedParam {
-
-        /**
-         * assetid
-         */
-        public String assetid;
-
-        /**
-         * lowerlimit
-         */
-        public long lowerlimit;
-
-        /**
-         * upperlimit
-         */
-        public long upperlimit;
-
-    }
-}
diff --git a/src/test/java/io/bytom/integration/TransactionFeedTest.java b/src/test/java/io/bytom/integration/TransactionFeedTest.java
deleted file mode 100644 (file)
index d1a9384..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-package io.bytom.integration;
-
-import io.bytom.TestUtils;
-import io.bytom.api.TransactionFeed;
-import io.bytom.api.Wallet;
-import io.bytom.exception.BytomException;
-import io.bytom.http.Client;
-import org.junit.Assert;
-import org.junit.Test;
-
-import java.util.List;
-
-public class TransactionFeedTest {
-
-    static Client client;
-
-    static {
-        try {
-            client = TestUtils.generateClient();
-        } catch (BytomException e) {
-            e.printStackTrace();
-        }
-    }
-
-    static TransactionFeed transactionFeed;
-
-    @Test
-    public void testTXFeedCreate() throws Exception {
-        String filter = "asset_id='57fab05b689a2b8b6738cffb5cf6cffcd0bf6156a04b7d9ba0173e384fe38c8c' AND amount_lower_limit = 50 AND amount_upper_limit = 100";
-        String alias = "test1";
-        new TransactionFeed.Builder()
-                    .setAlias(alias)
-                    .setFilter(filter)
-                    .create(client);
-    }
-
-    @Test
-    public void testTXFeedGet() throws Exception {
-        String alias = "test2";
-        transactionFeed = TransactionFeed.get(client, alias);
-
-        Assert.assertNotNull(transactionFeed);
-    }
-
-    @Test
-    public void testTXFeedUpdate() throws Exception {
-        String filter = "asset_id='57fab05b689a2b8b6738cffb5cf6cffcd0bf6156a04b7d9ba0173e384fe38c8c' AND amount_lower_limit = 50 AND amount_upper_limit = 100";
-        String alias = "test2";
-
-        TransactionFeed.update(client, alias, filter);
-    }
-
-    @Test
-    public void testTXFeedList() throws Exception {
-        List<TransactionFeed> txFeedList = TransactionFeed.list(client);
-        Assert.assertNotNull(txFeedList);
-    }
-
-    @Test
-    public void testTXFeedDelete() throws Exception {
-        String alias = "test2";
-        TransactionFeed.delete(client, alias);
-    }
-
-
-}
index 94046b3..a922ecb 100644 (file)
@@ -5,6 +5,7 @@ import io.bytom.api.*;
 import io.bytom.exception.BytomException;
 import io.bytom.http.Client;
 import org.apache.log4j.Logger;
+import org.junit.Assert;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -28,6 +29,8 @@ public class TransactionTest {
     static Asset senderAsset;
     static Asset receiverAsset;
 
+    static Transaction.Feed transactionFeed;
+
     static {
         try {
             client = TestUtils.generateClient();
@@ -148,9 +151,6 @@ public class TransactionTest {
                 new Transaction.QueryBuilder().setAccountId(account_id).list(client);
     }
 
-
-
-
     public void testSenderKeyCreate() throws Exception {
         String alias = "sender-key";
         String password = "123456";
@@ -284,4 +284,43 @@ public class TransactionTest {
 
     }
 
+    //TransactionFeed
+    @Test
+    public void testTXFeedCreate() throws Exception {
+        String filter = "asset_id='57fab05b689a2b8b6738cffb5cf6cffcd0bf6156a04b7d9ba0173e384fe38c8c' AND amount_lower_limit = 50 AND amount_upper_limit = 100";
+        String alias = "test1";
+        new Transaction.Feed.Builder()
+                .setAlias(alias)
+                .setFilter(filter)
+                .create(client);
+    }
+
+    @Test
+    public void testTXFeedGet() throws Exception {
+        String alias = "test2";
+        transactionFeed = Transaction.Feed.getByAlias(client, alias);
+
+        Assert.assertNotNull(transactionFeed);
+    }
+
+    @Test
+    public void testTXFeedUpdate() throws Exception {
+        String filter = "asset_id='57fab05b689a2b8b6738cffb5cf6cffcd0bf6156a04b7d9ba0173e384fe38c8c' AND amount_lower_limit = 50 AND amount_upper_limit = 100";
+        String alias = "test2";
+
+        Transaction.Feed.update(client, alias, filter);
+    }
+
+    @Test
+    public void testTXFeedList() throws Exception {
+        List<Transaction.Feed> txFeedList = Transaction.Feed.list(client);
+        Assert.assertNotNull(txFeedList);
+    }
+
+    @Test
+    public void testTXFeedDelete() throws Exception {
+        String alias = "test2";
+        Transaction.Feed.deleteByAlias(client, alias);
+    }
+
 }