All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.chain.sequence.api.Balance Maven / Gradle / Ivy

The newest version!
package com.chain.sequence.api;

import com.chain.sequence.exception.APIException;
import com.chain.sequence.exception.BadURLException;
import com.chain.sequence.exception.ChainException;
import com.chain.sequence.http.Client;

import com.chain.sequence.exception.ConnectivityException;
import com.chain.sequence.exception.JSONException;
import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * A summation of output amounts. Outputs are selected using a filter, and their values are summed using the common values of one or more output properties.
 */
public class Balance {
  /**
   * List of parameters along which output amounts were summed.
   */
  @SerializedName("sum_by")
  public Map sumBy;

  /**
   * Summation of output amounts.
   */
  public long amount;

  /**
   * A single page of balances returned from a query.
   */
  public static class Page extends BasePage {}

  /**
   * Iterable interface for consuming individual balances from a query.
   */
  public static class ItemIterable extends BaseItemIterable {
    public ItemIterable(Client client, String path, Query nextQuery) {
      super(client, path, nextQuery, Page.class);
    }
  }

  /**
   * Iterable interface for consuming pages of balances from a query.
   */
  public static class PageIterable extends BasePageIterable {
    public PageIterable(Client client, String path, Query nextQuery) {
      super(client, path, nextQuery, Page.class);
    }
  }

  /**
   * A builder class for querying balances in the ledger.
   */
  public static class QueryBuilder extends BaseQueryBuilder {
    /**
     * Executes the query, returning a page of balances that match the query.
     * @param client ledger API connection object
     * @return a page of balances
     * @throws ChainException
     */
    public Page getPage(Client client) throws ChainException {
      return client.request("list-balances", this.next, Page.class);
    }

    /**
     * Executes the query, returning an iterable over balances that match the
     * query.
     * @param client ledger API connection object
     * @return an iterable over balances
     * @throws ChainException
     */
    public ItemIterable getIterable(Client client) throws ChainException {
      return new ItemIterable(client, "list-balances", this.next);
    }

    /**
     * Executes the query, returning an iterable over pages of balances that
     * match the query.
     * @param client ledger API connection object
     * @return an iterable over pages of balances
     * @throws ChainException
     */
    public PageIterable getPageIterable(Client client) throws ChainException {
      return new PageIterable(client, "list-balances", this.next);
    }

    /**
     * Specifies a time in the past. The query will reflect the state of the
     * ledger at that point in time.
     * @param timestampMS unixtime in milliseconds
     * @return updated builder
     */
    public QueryBuilder setTimestamp(long timestampMS) {
      this.next.timestamp = timestampMS;
      return this;
    }

    /**
     * Specifies the properties along which output values will be summed.
     * @param sumBy a list of output properties
     * @return updated builder
     */
    public QueryBuilder setSumBy(List sumBy) {
      this.next.sumBy = new ArrayList<>(sumBy);
      return this;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy