zainali5120
2020-07-16 c119feb821bdb1e6ef407f55056173f752c01c32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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<EosResult> 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<EosResult> getActions(int pos, int offset) {
        JSONObject param = new JSONObject();
        param.put("account_name", ACCOUNT);
        param.put("pos", pos);
        param.put("offset", offset);
        Map<String, String> header = new HashMap<String, String>();
        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<EosResult> 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;
    }
}