恒星支付查询

时间:2017-01-22 06:40:22

标签: java paypal

我无法在官方网站上执行示例付款查询程序。这是我的代码,几乎与样本相同。这是official website

public class TransCheck {
  public static void main(String args[]) {
    Server server = new Server("https://horizon-testnet.stellar.org");
    KeyPair account = KeyPair.fromAccountId("GARUMRUP37CPOGQQALSXBDQQS6SUDDPKGLGFERH6PIJEHWQY5IAVZQDL");

    // Create an API call to query payments involving the account.
    // server.payments() Returns PaymentsRequestBuilder instance.
    // forAccount() Builds request to GET /accounts/{account}/payments - Account for which to get payments
    PaymentsRequestBuilder paymentsRequest = server.payments().forAccount(account);

    // If some payments have already been handled, start the results from the
    // last seen payment. (See below in `handlePayment` where it gets saved.)
    String lastToken = loadLastPagingToken();
    if (lastToken != null) {
      paymentsRequest.cursor(lastToken);
    }

    // `stream` will send each recorded payment, one by one, then keep the
    // connection open and continue to send you new payments as they occur.

    paymentsRequest.stream(new EventListener <OperationResponse>(){
      @Override
      public void onEvent(OperationResponse payment) {
        // Record the paging token so we can start from here next time.
        savePagingToken(payment.getPagingToken());

        // The payments stream includes both sent and received payments. We only
        // want to process received payments here.
        if (payment instanceof PaymentOperationResponse) {
          if (((PaymentOperationResponse) payment).getTo().equals(account)) {
            return;
          }

          String amount = ((PaymentOperationResponse) payment).getAmount();

          Asset asset = ((PaymentOperationResponse) payment).getAsset();
          String assetName;
          if (asset.equals(new AssetTypeNative())) {
            assetName = "lumens";
          } else {
            StringBuilder assetNameBuilder = new StringBuilder();
            assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getCode());
            assetNameBuilder.append(":");
            assetNameBuilder.append(((AssetTypeCreditAlphaNum) asset).getIssuer().getAccountId());
            assetName = assetNameBuilder.toString();
          }

          StringBuilder output = new StringBuilder();
          output.append(amount);
          output.append(" ");
          output.append(assetName);
          output.append(" from ");
          output.append(((PaymentOperationResponse) payment).getFrom().getAccountId());
          System.out.println(output.toString());
        }
      }
    }); 
  }
}

我的代码中有两个错误。首先,方法:loadLastPagingToken()未定义,我找不到此方法的详细信息。其次,当我想创建一个new EventListener <OperationResponse>() IDE告诉

  

EventListener类型不是通用的;它不能用参数

参数化

我真的不知道为什么。请你帮助我好吗?谢谢。

2 个答案:

答案 0 :(得分:1)

因为你的import语句。

尝试

import org.stellar.sdk.requests.EventListener;

而不是

import java.util.EventListener;

答案 1 :(得分:0)

对于您的第一个问题,loadLastPagingToken的目的是获取您希望流开始的书签。当您第一次运行此操作且没有此值时,应将其设置为null。稍后,如果您正在构建重新启动流的功能,则需要知道上次处理的页面中的令牌。方法loadLastPagingToken在这里作为存根提供,供您在需要时实施。

你的第二个问题已由CR-Soneso回答。您导入了错误的EventListener类。

如果您对Stellar有其他疑问,可以在dedicated Stellar stackexchange(目前处于测试阶段)找到问题的更快答案。