1024程序员节
介绍
1024程序员节是广大程序员的共同节日。1024是2的十次方,二进制计数的基本计量单位之一。针对程序员经常周末加班与工作日熬夜的情况,部分互联网机构倡议每年的10月24日为1024程序员节,在这一天建议程序员拒绝加班。
程序员就像是一个个1024,以最低调、踏实、核心的功能模块搭建起这个科技世界。1G=1024M,而1G与1级谐音,也有一级棒的意思。
TRX转账功能
/** * 发起trx交易 * * @param privateKey 发起地址私钥 * @param to 收款地址 * @param sun trx数量(sun单位 1000000表示1trx) * @param remark 备注信息 * @return */ @Override public String transfer(String privateKey, String to, BigDecimal trx, String remark) { requireNotEmpty(privateKey, "private-key"); requireNotEmpty(to, "to-address"); if (trx.compareTo(BigDecimal.ZERO) <= 0) { throw new IllegalArgumentException("amount is not illegal:" + trx.toString()); } String from = TronUtils.getAddressByPrivateKey(privateKey); try { String url = tronUrl + "/wallet/createtransaction"; JSONObject param = new JSONObject(); param.put("owner_address", TronUtils.toHexAddress(from)); param.put("to_address", TronUtils.toHexAddress(to)); param.put("amount", trx.multiply(DECIMAL).toBigInteger()); String _result = HttpClientUtils.postJson(url, param.toJSONString()); String txid = null; if (StringUtils.isNotEmpty(_result)) { if(_result.toLowerCase().contains("error")){ logger.info(_result); } JSONObject transaction = JSONObject.parseObject(_result); if (StringUtils.isNotEmpty(remark)) { transaction.getJSONObject("raw_data").put("data", Hex.toHexString(remark.getBytes())); } txid = TronUtils.signAndBroadcast(tronUrl, privateKey, transaction); } if (txid != null) { logger.info(String.format("send trx|success:txid=%s from=%s to=%s amount=%s", txid, from, to, trx.toString())); } else { logger.error(String.format("send trx|fail:from=%s to=%s amount=%s", from, to, trx.toString())); } return txid; } catch (Throwable t) { logger.error(String.format("send trx|fail:from=%s to=%s amount=%s", from, to, trx.toString())); } return null; }
TRC20转账功能
/** * 发起trc20转账 * * @param privateKey 转出trc20的地址 * @param contract trc20合约地址 * @param to 收款地址 * @param amount 转出数量 带上进度 例如精度为6 那么1trc20就需要填1000000 * @param remark 备注信息 * @return */ @Override public String transfer(String privateKey, String contract, String to, BigInteger amount, String remark) { requireNotEmpty(contract, "contract"); requireNotEmpty(privateKey, "privateKey"); requireNotEmpty(to, "to"); if (amount.compareTo(BigInteger.ZERO) <= 0) { throw new IllegalArgumentException("amount is illegal:" + amount.toString()); } String from = TronUtils.getAddressByPrivateKey(privateKey); try { JSONObject jsonObject = new JSONObject(); jsonObject.put("contract_address", TronUtils.toHexAddress(contract)); jsonObject.put("function_selector", "transfer(address,uint256)"); List<Type> inputParameters = new ArrayList<>(); inputParameters.add(new Address(TronUtils.toHexAddress(to).substring(2))); inputParameters.add(new Uint256(amount)); String parameter = FunctionEncoder.encodeConstructor(inputParameters); jsonObject.put("parameter", parameter); jsonObject.put("owner_address", TronUtils.toHexAddress(from)); jsonObject.put("call_value", 0); jsonObject.put("fee_limit", 6000000L); String trans1 = HttpClientUtils.postJson(envConfig.getTronUrl() + "/wallet/triggersmartcontract", jsonObject.toString()); JSONObject result = JSONObject.parseObject(trans1); String txid = null; if (!result.containsKey("Error")) { JSONObject tx = result.getJSONObject("transaction"); if (remark != null) { tx.getJSONObject("raw_data").put("data", Hex.toHexString(remark.getBytes()));//填写备注 } txid = TronUtils.signAndBroadcast(envConfig.getTronUrl(), privateKey, tx); } if (txid != null) { logger.info(String.format("send trx|success:txid=%s contract=%s from=%s to=%s amount=%s", txid, contract, from, to, amount.toString())); } else { logger.info(String.format("send trx|fail:contract=%s from=%s to=%s amount=%s", contract, from, to, amount.toString())); } return txid; } catch (Throwable t) { logger.error(String.format("send trx|fail:contract=%s from=%s to=%s amount=%s", contract, from, to, amount.toString()), t); } logger.info(String.format("send trx|fail:contract=%s from=%s to=%s amount=%s", contract, from, to, amount.toString())); return null; }
使用web3j接口方式调用,接口
public interface Ethereum { Request<?, Web3ClientVersion> web3ClientVersion(); Request<?, Web3Sha3> web3Sha3(String var1); Request<?, NetVersion> netVersion(); Request<?, NetListening> netListening(); Request<?, NetPeerCount> netPeerCount(); Request<?, AdminNodeInfo> adminNodeInfo(); Request<?, AdminPeers> adminPeers(); Request<?, EthProtocolVersion> ethProtocolVersion(); Request<?, EthChainId> ethChainId(); Request<?, EthCoinbase> ethCoinbase(); Request<?, EthSyncing> ethSyncing(); Request<?, EthMining> ethMining(); Request<?, EthHashrate> ethHashrate(); Request<?, EthGasPrice> ethGasPrice(); Request<?, EthAccounts> ethAccounts(); Request<?, EthBlockNumber> ethBlockNumber(); Request<?, EthGetBalance> ethGetBalance(String var1, DefaultBlockParameter var2); Request<?, EthGetStorageAt> ethGetStorageAt(String var1, BigInteger var2, DefaultBlockParameter var3); Request<?, EthGetTransactionCount> ethGetTransactionCount(String var1, DefaultBlockParameter var2); Request<?, EthGetBlockTransactionCountByHash> ethGetBlockTransactionCountByHash(String var1); Request<?, EthGetBlockTransactionCountByNumber> ethGetBlockTransactionCountByNumber(DefaultBlockParameter var1); Request<?, EthGetUncleCountByBlockHash> ethGetUncleCountByBlockHash(String var1); Request<?, EthGetUncleCountByBlockNumber> ethGetUncleCountByBlockNumber(DefaultBlockParameter var1); Request<?, EthGetCode> ethGetCode(String var1, DefaultBlockParameter var2); Request<?, EthSign> ethSign(String var1, String var2); Request<?, EthSendTransaction> ethSendTransaction(Transaction var1); Request<?, EthSendTransaction> ethSendRawTransaction(String var1); Request<?, EthCall> ethCall(Transaction var1, DefaultBlockParameter var2); Request<?, EthEstimateGas> ethEstimateGas(Transaction var1); Request<?, EthBlock> ethGetBlockByHash(String var1, boolean var2); Request<?, EthBlock> ethGetBlockByNumber(DefaultBlockParameter var1, boolean var2); Request<?, EthTransaction> ethGetTransactionByHash(String var1); Request<?, EthTransaction> ethGetTransactionByBlockHashAndIndex(String var1, BigInteger var2); Request<?, EthTransaction> ethGetTransactionByBlockNumberAndIndex(DefaultBlockParameter var1, BigInteger var2); Request<?, EthGetTransactionReceipt> ethGetTransactionReceipt(String var1); Request<?, EthBlock> ethGetUncleByBlockHashAndIndex(String var1, BigInteger var2); Request<?, EthBlock> ethGetUncleByBlockNumberAndIndex(DefaultBlockParameter var1, BigInteger var2); Request<?, EthGetCompilers> ethGetCompilers(); Request<?, EthCompileLLL> ethCompileLLL(String var1); Request<?, EthCompileSolidity> ethCompileSolidity(String var1); Request<?, EthCompileSerpent> ethCompileSerpent(String var1); Request<?, EthFilter> ethNewFilter(org.web3j.protocol.core.methods.request.EthFilter var1); Request<?, EthFilter> ethNewBlockFilter(); Request<?, EthFilter> ethNewPendingTransactionFilter(); Request<?, EthUninstallFilter> ethUninstallFilter(BigInteger var1); Request<?, EthLog> ethGetFilterChanges(BigInteger var1); Request<?, EthLog> ethGetFilterLogs(BigInteger var1); Request<?, EthLog> ethGetLogs(org.web3j.protocol.core.methods.request.EthFilter var1); Request<?, EthGetWork> ethGetWork(); Request<?, EthSubmitWork> ethSubmitWork(String var1, String var2, String var3); Request<?, EthSubmitHashrate> ethSubmitHashrate(String var1, String var2); Request<?, DbPutString> dbPutString(String var1, String var2, String var3); Request<?, DbGetString> dbGetString(String var1, String var2); Request<?, DbPutHex> dbPutHex(String var1, String var2, String var3); Request<?, DbGetHex> dbGetHex(String var1, String var2); Request<?, ShhPost> shhPost(org.web3j.protocol.core.methods.request.ShhPost var1); Request<?, ShhVersion> shhVersion(); Request<?, ShhNewIdentity> shhNewIdentity(); Request<?, ShhHasIdentity> shhHasIdentity(String var1); Request<?, ShhNewGroup> shhNewGroup(); Request<?, ShhAddToGroup> shhAddToGroup(String var1); Request<?, ShhNewFilter> shhNewFilter(ShhFilter var1); Request<?, ShhUninstallFilter> shhUninstallFilter(BigInteger var1); Request<?, ShhMessages> shhGetFilterChanges(BigInteger var1); Request<?, ShhMessages> shhGetMessages(BigInteger var1); }
TRC20代币的回收/归集处理(方可用于USDT归集)
整套的逻辑大致为检测trx数量,然后再进行trc20转账,最后回收多余的trx
项目说明
yml配置(仅仅需要配置这些,redis是必要的,mysql可以选择用不用,不用的话把相关功能割掉就好)