From 5e0c0bacadab898152518437ceb63bf8b54c6652 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 12 Aug 2022 22:27:34 +0800
Subject: [PATCH] finish NFT Active

---
 src/main/java/cc/mrbird/febs/dapp/controller/DappController.java |  279 ++++++++++++++++++++++---------------------------------
 1 files changed, 111 insertions(+), 168 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/dapp/controller/DappController.java b/src/main/java/cc/mrbird/febs/dapp/controller/DappController.java
index 8ea62d9..e6f2d12 100644
--- a/src/main/java/cc/mrbird/febs/dapp/controller/DappController.java
+++ b/src/main/java/cc/mrbird/febs/dapp/controller/DappController.java
@@ -1,177 +1,120 @@
-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.apache.commons.lang3.StringUtils;
-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 org.web3j.abi.FunctionEncoder;
-import org.web3j.abi.FunctionReturnDecoder;
-import org.web3j.abi.TypeReference;
-import org.web3j.abi.datatypes.Address;
-import org.web3j.abi.datatypes.Function;
-import org.web3j.abi.datatypes.Type;
-import org.web3j.abi.datatypes.generated.Uint256;
-import org.web3j.crypto.Credentials;
-import org.web3j.crypto.RawTransaction;
-import org.web3j.crypto.TransactionEncoder;
-import org.web3j.protocol.Web3j;
-import org.web3j.protocol.core.DefaultBlockParameterName;
-import org.web3j.protocol.core.methods.request.Transaction;
-import org.web3j.protocol.core.methods.response.EthCall;
-import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
-import org.web3j.protocol.core.methods.response.EthSendTransaction;
-import org.web3j.protocol.http.HttpService;
-import org.web3j.utils.Convert;
-import org.web3j.utils.Numeric;
-
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-
-/**
- * @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();
-    }
-
-    public static void main(String[] args) throws Exception {
-//        ApiWrapper wrapper = ApiWrapper.ofShasta("ebefe7b932359a7ef70c5cec0aed9aa2ca468b6c0d60ac637fe783530e459978");
-//        Contract trc20Contract = wrapper.getContract("TRTE68V3TJBLduBoJPLMgBsvwkq8LJBin6");
-//        Trc20Contract token = new Trc20Contract(trc20Contract, "TKcyw4igFYhNpTzyZv25j6uDwvTYzncnjp", wrapper);
+//package cc.mrbird.febs.dapp.controller;
 //
-//        BigInteger balance = token.balanceOf("TKcyw4igFYhNpTzyZv25j6uDwvTYzncnjp");
-//        token.transfer("TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD", balance.longValue(), 0, "memo", 100000000L);
-
-
-//        ApiWrapper wrapper = ApiWrapper.ofMainnet("af4913d8462ca83e0a2df587072e42ec565bc26f6bec0724d1bf2e80d4c0bcb7", "9d461be6-9796-47b9-85d8-b150cbabbb54");
-//        Contract trc20Contract = wrapper.getContract("TL2pea32CTtxJ48pJmnLQuoRHeoX79dLCT");
-//        Trc20Contract token =  new Trc20Contract(trc20Contract, "TZ5sZBLU5pdZbqN56rVsUEQuRHzYGRSY8a", wrapper);
-
-
+//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.apache.commons.lang3.StringUtils;
+//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 org.web3j.abi.FunctionEncoder;
+//import org.web3j.abi.FunctionReturnDecoder;
+//import org.web3j.abi.TypeReference;
+//import org.web3j.abi.datatypes.Address;
+//import org.web3j.abi.datatypes.Function;
+//import org.web3j.abi.datatypes.Type;
+//import org.web3j.abi.datatypes.generated.Uint256;
+//import org.web3j.crypto.Credentials;
+//import org.web3j.crypto.RawTransaction;
+//import org.web3j.crypto.TransactionEncoder;
+//import org.web3j.protocol.Web3j;
+//import org.web3j.protocol.core.DefaultBlockParameterName;
+//import org.web3j.protocol.core.methods.request.Transaction;
+//import org.web3j.protocol.core.methods.response.EthCall;
+//import org.web3j.protocol.core.methods.response.EthGetTransactionCount;
+//import org.web3j.protocol.core.methods.response.EthSendTransaction;
+//import org.web3j.protocol.http.HttpService;
+//import org.web3j.utils.Convert;
+//import org.web3j.utils.Numeric;
+//
+//import javax.servlet.http.HttpServletRequest;
+//import java.io.IOException;
+//import java.math.BigDecimal;
+//import java.math.BigInteger;
+//import java.util.ArrayList;
+//import java.util.Arrays;
+//import java.util.Date;
+//import java.util.List;
+//import java.util.concurrent.CompletableFuture;
+//import java.util.concurrent.ExecutionException;
+//
+///**
+// * @author
+// * @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();
+//    }
+//
+//    public static void main(String[] args) throws Exception {
+////        ApiWrapper wrapper = ApiWrapper.ofShasta("ebefe7b932359a7ef70c5cec0aed9aa2ca468b6c0d60ac637fe783530e459978");
+////        Contract trc20Contract = wrapper.getContract("TRTE68V3TJBLduBoJPLMgBsvwkq8LJBin6");
+////        Trc20Contract token = new Trc20Contract(trc20Contract, "TKcyw4igFYhNpTzyZv25j6uDwvTYzncnjp", wrapper);
+////
+////        BigInteger balance = token.balanceOf("TKcyw4igFYhNpTzyZv25j6uDwvTYzncnjp");
+////        token.transfer("TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD", balance.longValue(), 0, "memo", 100000000L);
+//
+//
+////        ApiWrapper wrapper = ApiWrapper.ofMainnet("af4913d8462ca83e0a2df587072e42ec565bc26f6bec0724d1bf2e80d4c0bcb7", "9d461be6-9796-47b9-85d8-b150cbabbb54");
+////        Contract trc20Contract = wrapper.getContract("TL2pea32CTtxJ48pJmnLQuoRHeoX79dLCT");
+////        Trc20Contract token =  new Trc20Contract(trc20Contract, "TZ5sZBLU5pdZbqN56rVsUEQuRHzYGRSY8a", wrapper);
+//
+//
 //        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);
 //
-//        System.out.println(token.balanceOf("TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD"));;
-
-        HttpService service = new HttpService("https://mainnet.infura.io/v3/f54a5887a3894ebb9425920701a97fe0");
-        Web3j web3j = Web3j.build(service);
-
-//        String contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7";
-//        String fromAddress = "0x391040eE5F241711E763D0AC55E775B9b4bD0024";
-//        String toAddress = "0xD998DA7362360eFC6daDFEd6E9a32E70640d7600";
-//        int decimal = 6;
-//        String methodName = "allowance";
-//        List<Type> inputParameters = new ArrayList<>();
-//        List<TypeReference<?>> outputParameters = new ArrayList<>();
-//        Address address = new Address(toAddress);
-//        inputParameters.add(address);
-//        TypeReference<Uint256> typeReference = new TypeReference<Uint256>() {
-//        };
-//        outputParameters.add(typeReference);
-//        Function function = new Function(methodName, inputParameters, outputParameters);
-//        String data = FunctionEncoder.encode(function);
-//        Transaction transaction = Transaction.createEthCallTransaction(fromAddress, contractAddress, data);
+//        System.out.println(token.allowance("TUy8XwDmdsDKPLDGUrGuNRVMhwSEKtkDcD", "TFGbYzGv4Zt2nzFM3uU3uCJZY67WKSveG9"));;
 //
-//        EthCall ethCall;
-//        BigInteger balanceValue = BigInteger.ZERO;
-//        ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).send();
-//        List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
-//        System.out.println(results);
-
-//        String gas = "";
-//        if(StringUtils.isBlank(gas)){
-//            gas="70";
-//        }
-//        String contractAddress = "0xdac17f958d2ee523a2206206994597c13d831ec7";
-//        Credentials credentials = Credentials.create(privateKey);
+//    }
 //
-//        EthGetTransactionCount ethGetTransactionCount = web3j
-//                .ethGetTransactionCount(fromAddress, DefaultBlockParameterName.LATEST).sendAsync().get();
 //
-//        BigInteger nonce = ethGetTransactionCount.getTransactionCount();
-//
-//        Function function = new Function("transfer",
-//                Arrays.asList(new Address(toAddress), new Uint256(new BigInteger(amount))),
-//                Arrays.asList(new TypeReference<Type>() {
-//                }));
-//
-//        String encodedFunction = FunctionEncoder.encode(function);
-//
-//        RawTransaction rawTransaction = RawTransaction.createTransaction(nonce,
-//                Convert.toWei(gas, Convert.Unit.GWEI).toBigInteger(),// 给矿工开的转账单价 单价越高越快
-//                Convert.toWei("60000", Convert.Unit.WEI).toBigInteger(), contractAddress, encodedFunction);//里程上限
-//        // 10*80000/1000000000=0.0008 手续费
-//
-//        byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
-//        String hexValue = Numeric.toHexString(signedMessage);
-//
-//        // log.debug("transfer hexValue:" + hexValue);
-//
-//        CompletableFuture<EthSendTransaction> ethSendTransactionCompletableFuture = web3j.ethSendRawTransaction(hexValue).sendAsync();
-//        EthSendTransaction ethSendTransaction = ethSendTransactionCompletableFuture.get();
-
-    }
-
-
-}
+//}

--
Gitblit v1.9.1