*/
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);
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;
+
+ }
+ }
}
+++ /dev/null
-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;
-
- }
-}
+++ /dev/null
-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);
- }
-
-
-}
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;
static Asset senderAsset;
static Asset receiverAsset;
+ static Transaction.Feed transactionFeed;
+
static {
try {
client = TestUtils.generateClient();
new Transaction.QueryBuilder().setAccountId(account_id).list(client);
}
-
-
-
public void testSenderKeyCreate() throws Exception {
String alias = "sender-key";
String password = "123456";
}
+ //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);
+ }
+
}