package com.xcong.excoin.modules.blackchain.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.modules.blackchain.model.EosResult; import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class EosService { // 正式网络 https://api-v2.eosasia.one https://proxy.eosnode.tools // 测试网络 https://api-kylin.eosasia.one // "eosqxyx11111", "5JJB2oiCXwASK9fumjyTgbtHcwDVedVRaZda1kBhFuQcmjnrDWB" //private final static String account = "huobideposit"; public final static String ACCOUNT = "biueeostoken"; // private String account; private final static String EOS_NAME = "EOS"; public static final String K_mnemonic = "mnemonic"; public static final String K_privateKey = "privateKey"; public static final String K_publicKey = "publicKey"; private static final String EOS_TOKEN = "eosio.token"; private static final String ACTION_TRANSFER = "transfer"; public static void main(String[] args) throws Exception { List actions = getActions(0, 3); for(EosResult eosResult:actions){ System.out.println(eosResult.toString()); String quantity = eosResult.getQuantity(); String amountStr = quantity.split("")[0]; System.out.println(quantity); System.out.println(new BigDecimal(amountStr)); } } /** * * @param pos 从第几条开始(包括pos) * @param offset 查询条数 * @return */ public static List getActions(int pos, int offset) { JSONObject param = new JSONObject(); param.put("account_name", ACCOUNT); param.put("pos", pos); param.put("offset", offset); Map header = new HashMap(); header.put("content-type", "application/json"); String res = HttpUtil.post("https://api.eosflare.io/v1/eosflare/get_actions", null, param.toJSONString(), header); System.out.println(res); List results = new ArrayList<>(); try { JSONObject jsonObject = JSONObject.parseObject(res); JSONArray actions = jsonObject.getJSONArray("actions"); if (actions != null && actions.size() > 0) { int size = actions.size(); EosResult eosResult = null; for (int i = 0; i < size; i++) { JSONObject jsonObject1 = actions.getJSONObject(i); // 当前交易序号 Object account_action_seq = jsonObject1.get("account_action_seq"); JSONObject action_trace = jsonObject1.getJSONObject("action_trace"); JSONObject act = action_trace.getJSONObject("act"); Object account = act.get("account"); if (!EOS_TOKEN.equals(account)) { continue; } eosResult = JSONObject.parseObject(act.getString("data"), EosResult.class); eosResult.setAccountActionSeq((Integer) account_action_seq); results.add(eosResult); } } } catch (Exception e) { e.printStackTrace(); } return results; } }