恒星支付查询 [英] Stellar payments query

查看:126
本文介绍了恒星支付查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am unable to execute the example payment query program on the official website. Here is my code, almost same with the sample. Here is the 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()未定义,我找不到此方法的详细信息。其次,当我想创建新的EventListener< OperationResponse>()时,IDE告诉

There are two errors in my code. First, the method: loadLastPagingToken() is undefined and I cannot find the detail of this method. Second, when I want to create a new EventListener <OperationResponse>() the IDE told that


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

The type EventListener is not generic; it cannot be parameterized with arguments

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

I really do not know why. Could you please help me? Thank you.

推荐答案

因为你的import语句。

Its because of your import statement.

尝试

import org.stellar.sdk.requests.EventListener;

import org.stellar.sdk.requests.EventListener;

而不是

import java.util.EventListener;

import java.util.EventListener;

这篇关于恒星支付查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆