ウォレットアクセス波場TRC 20、TRX(オフライン生成アドレス、オフライン署名、スキャンチャージ、コイン引き出し)


波場技術ドッキング公式サイト:ドッキング公式サイト
TRC 20代币官方教程:TRC 20発币
ここで使われているのはjava+mavenです.これらの依存も長い間やっていました.あまり話さないで直接コードをつけてください.問題があったら、q 284466315を加えて教えてください.
一:オフライン生成アドレス(copyのこのお兄さん)
    public TrxApi newAddress() {
        try {
            String pwd = "    ";
            ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
            ECKeyPair ecKeyPair = Keys.createEcKeyPair();
            WalletFile walletFile = Wallet.createStandard(pwd, ecKeyPair);
            String keystore = objectMapper.writeValueAsString(walletFile);
            WalletFile walletFile2 = objectMapper.readValue(keystore, WalletFile.class);
            ECKeyPair ecKeyPair1 = Wallet.decrypt(pwd, walletFile2);
            String addressT = fromHexAddress("41" + walletFile.getAddress());
//          
            return new TrxApi("41" + walletFile.getAddress(), addressT, ecKeyPair1.getPrivateKey().toString(16));
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

  /**
     * 41 ---- > T
     *
     * @param address
     * @return
     */
    public static String fromHexAddress(String address) {
        return TronWalletApi.encode58Check(ByteArray.fromHexString(address));
    }

    /**
     * T ---->  41
     *
     * @param address
     * @return
     */
    public static String toHexAddress(String address) {
        return ByteArray.toHexString(TronWalletApi.decodeFromBase58Check(address));
    }

二チャージ(これはよくわかりませんが、私のdataの解析方法は少しlowで、どのように解析するかを知ってほしいコメントを教えてください)
      JSONObject jsonObject = new JSONObject();
        Long trxBlock = ethDao.getTrxBlock();
        jsonObject.put("num", trxBlock);
        JSONObject trans = HttpsUtil.sendPost(TRON_NODE_URL + "/walletsolidity/getblockbynum", jsonObject);
        if (trans.size() > 0
        ) {
            List TransactionNewList = JSON.parseArray(trans.getString("transactions"), TransactionNew.class);
            if (TransactionNewList != null && TransactionNewList.size() > 0) {
                for (TransactionNew TransactionNew :
                        TransactionNewList) {
                    String txID = TransactionNew.getTxID();
                    if (TransactionNew.getRawData() != null && TransactionNew.getRawData().getContract() != null && TransactionNew.getRawData().getContract().size() > 0) {
                        String contractRet = TransactionNew.getRet().get(0).getContractRet();
                        if (contractRet.equalsIgnoreCase("SUCCESS")) {
                            Contract contract = TransactionNew.getRawData().getContract().get(0);
                            Value value = contract.getParameter().getValue();
                            //            
                            String contractAddress = fromHexAddress(value.getContractAddress());
                            // USDT_CONTRACT      
                            String from = fromHexAddress(value.getOwnerAddress());
                            String data = value.getData();

                            if (data == null || data.length() < 73) {
                                continue;
                            }
                            //      Trc20
                            String to = fromHexAddress("41" + data.substring(32, 72));
                            BigDecimal amount = BigDecimal.ZERO;
                            Integer coinType = 0;
                            BigDecimal amountDecimal = new BigDecimal(new BigInteger(data.substring(72), 16));

                           if (contractAddress.equalsIgnoreCase(USDT_CONTRACT)) {
                                amount = amountDecimal.divide(new BigDecimal("1000000"), 8, BigDecimal.ROUND_DOWN);
                                coinType = CoinTypeEnum.USDT_COIN.getCode();
                                updUserAsset.setUsdtCoin(amount);

                            } else {
                                continue;
                            }

           
                            }
                        }
                    }

                }

            }
            ethDao.updateTrxBlock(trxBlock + 1);
        }

 
三:TRC 20振り込み
   public  Map Trc20Transation2(String toAddress, String contract, BigDecimal amount) {
        try {

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("contract_address", toHexAddress(contract));
            jsonObject.put("function_selector", "transfer(address,uint256)");
// KBTC_CONTRACT   ,       
            if (contract.equalsIgnoreCase(KBTC_CONTRACT)) {
                amount = amount.multiply(new BigDecimal("1000000000000000000"));
            } else {
                amount = amount.multiply(new BigDecimal("1000000"));
            }
            BigInteger l = amount.toBigInteger();
            String parameter = encoderAbi(toHexAddress(toAddress).substring(2), l);
            System.out.println(parameter);
            jsonObject.put("parameter", parameter);
            jsonObject.put("owner_address", toHexAddress(TRX_CENTER_ADDRESS));
            jsonObject.put("call_value", 0);
            jsonObject.put("fee_limit", 100000000);
            JSONObject trans = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/triggersmartcontract", jsonObject);
//        System.out.println("   ========" + trans);
            Transaction transaction = Util.packTransaction(trans.getJSONObject("transaction").toJSONString(), false);
            byte[] bytes = signTransaction2Byte(transaction.toByteArray(), ByteArray.fromHexString(TRX_CENTER_PRIKEY));
            String signTransation = ByteArray.toHexString(bytes);
//        System.out.println("   ========" + signTransation);
//        //     
            JSONObject jsonObjectGB = new JSONObject();
            jsonObjectGB.put("transaction", signTransation);
            JSONObject transationCompelet = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/broadcasthex", jsonObjectGB);
            System.out.println("     ========" + transationCompelet);
            //         
            String txid = transationCompelet.getString("txid");
            Map map = new HashMap<>();
            map.put("txId",txid);

            map.put("result",transationCompelet.getBoolean("result"));
            return  map;
        }catch (Exception e){
            return null;
        }
    }

       private static byte[] signTransaction2Byte(byte[] transaction, byte[] privateKey)
            throws InvalidProtocolBufferException {
        ECKey ecKey = ECKey.fromPrivate(privateKey);
        Transaction transaction1 = Transaction.parseFrom(transaction);
        byte[] rawdata = transaction1.getRawData().toByteArray();
        byte[] hash = Sha256Hash.hash(rawdata);
        byte[] sign = ecKey.sign(hash).toByteArray();
        return transaction1.toBuilder().addSignature(ByteString.copyFrom(sign)).build().toByteArray();
    }

 public static String encoderAbi(String Address, BigInteger amount) {
        List inputParameters = new ArrayList<>();
        inputParameters.add(new Address(Address));
        inputParameters.add(new Uint256(amount));

        return FunctionEncoder.encodeConstructor(inputParameters);
    }

四:TRX振込
/**
     * TRx  
     *
     * @param toAddress
     * @param
     */
    public  Map  TrxTransation2(String toAddress, BigDecimal amount) {
        try {
            amount = amount.multiply(new BigDecimal("1000000"));
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("to_address",toHexAddress(toAddress));
            jsonObject.put("owner_address", toHexAddress(TRX_CENTER_ADDRESS));
            jsonObject.put("amount",             amount.toBigInteger());
            JSONObject trans = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/createtransaction", jsonObject);
            Transaction transaction = Util.packTransaction2(trans.toJSONString());
            byte[] bytes = signTransaction2Byte(transaction.toByteArray(), ByteArray.fromHexString(TRX_CENTER_PRIKEY));
            String signTransation = ByteArray.toHexString(bytes);
//        //     
            JSONObject jsonObjectGB = new JSONObject();
            jsonObjectGB.put("transaction", signTransation);
            JSONObject transationCompelet = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/broadcasthex", jsonObjectGB);
            //         
            String txid = transationCompelet.getString("txid");
            Map map = new HashMap<>();
            map.put("txId",txid);
            map.put("result",transationCompelet.getBoolean("result"));
            return  map;
        }catch (Exception e){
            return null;
        }
    }

五:trc 20残高またはtrx残高の照会
 /**
     *   Trx  
     */
    public  BigDecimal getTrxBalance(String address) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("address", toHexAddress(address));
        JSONObject trans = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/getaccount", jsonObject);
        if (trans.isEmpty()) {
            return  BigDecimal.ZERO;
        }
        BigDecimal balance = trans.getBigDecimal("balance");
        BigDecimal      amount = balance.divide(new BigDecimal("1000000"), 8, BigDecimal.ROUND_DOWN);
        return amount;
    }



 /**
     *   TRC20    
     */
    public  BigDecimal getTrc20Balance(String address, String contract) {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("contract_address", toHexAddress(contract));
        jsonObject.put("function_selector", "balanceOf(address)");
        jsonObject.put("parameter", "0000000000000000000000" + toHexAddress(address));
        jsonObject.put("owner_address", toHexAddress(address));

        JSONObject trans = HttpsUtil.sendPost(TRON_NODE_URL + "/wallet/triggersmartcontract", jsonObject);
//        System.out.println(trans);
        String constant_result = trans.getJSONArray("constant_result").getString(0);
        String constantResult = constant_result.replaceAll("^(0+)", "");
        if (StringUtils.isBlank(constantResult)){
            return BigDecimal.ZERO;
        }
        BigDecimal amountDecimal = new BigDecimal(new BigInteger(constantResult
                , 16));
        BigDecimal amount = BigDecimal.ZERO;
//            0
        if (contract.equalsIgnoreCase(KBTC_CONTRACT)) {
            amount = amountDecimal.divide(new BigDecimal("1000000000000000000"), 8, BigDecimal.ROUND_DOWN);
        } else if (contract.equalsIgnoreCase(USDT_CONTRACT)) {
            amount = amountDecimal.divide(new BigDecimal("1000000"), 8, BigDecimal.ROUND_DOWN);

        }
        return amount;
    }

]間違いがあったら、友達に指摘してもらいたいです.訂正します.ありがとうございます.微信a 284466315