zainali5120
2020-10-17 0ac5d713b3838c5147516a6949d506d002305a98
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
package com.xcong.excoin.modules.blackchain.service;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.blackchain.model.Trc20TransactionsData;
import com.xcong.excoin.modules.blackchain.model.Trc20TransactionsResult;
 
import java.util.List;
import java.util.Map;
 
/**
 * TRC20 服务类
 * https://cn.developers.tron.network/reference
 */
public class Trc20Service {
 
    private final static String FULL_NODE_URL = "https://api.trongrid.io";
 
    public static Map<String,String> createAddress(){
        String url  ="https://api.trongrid.io/wallet/generateaddress";
        // {privateKey=ed0bae6e49fa4dd8a622fe77baa0d6e4077155b28ed6637870745c6da3cf372e, address=THeRNk25ps69fzqhN6tZ4Ecxur3RvDNDtY, hexAddress=4154336ea2a3a26be8a722053ee26c61e3f7f3e0ec}
        String s = HttpUtil.get(url);
        return JSONObject.parseObject(s,Map.class);
    }
 
    /**
     *
     * @param address
     * @param time 2020-09-07T00:00
     * @return
     */
    public static List<Trc20TransactionsData> getAddressTransactions(String address,String time) {
        String url = "https://api.trongrid.io/v1/accounts/"+address+"/transactions/trc20?only_confirmed=true&only_to=true&min_timestamp="+time+"&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
        //String url = "https://api.trongrid.io/v1/accounts/"+address+"/transactions/trc20?limit=100&contract_address=TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t&only_confirmed=true";
        String s = HttpUtil.get(url);
        Trc20TransactionsResult trc20TransactionsResult = JSONObject.parseObject(s, Trc20TransactionsResult.class);
        if (trc20TransactionsResult.isSuccess()) {
            return trc20TransactionsResult.getData();
        } else {
            return null;
        }
    }
 
    public static void main(String[] args) {
        System.out.println(createAddress());
    }
 
}