美文网首页
usdt账户归集(通过节点)

usdt账户归集(通过节点)

作者: stevenlife | 来源:发表于2018-09-08 18:59 被阅读0次

    关于归集

    方案一:

    (1)创建归集记录表(需要两次交易)
    (2)判断状态转向用户USDT是否成功,成功后归集
    说明: 转入微量USDT会附带5.46E-6 BTC,加上用户转入时附带BTC,足够手续费
    

    方案二:

    1.添加依赖

    <dependency>
    <groupId>com.github.briandilley.jsonrpc4j</groupId>
    <artifactId>jsonrpc4j</artifactId>
    <version>1.5.3</version>
    </dependency>
    

    2.创建原始交易

    public class CollectUSDT {
    private static String url = "http://192.168.102.178:18332";
    private static String username = "111";
    private static String password = "222";
    private static JsonRpcHttpClient client = null;
    //    private static String from = "mtC79c2wp3oky6B9pcijnVfeU6VqwnfQW5";
    //    private static String fee = "n3ubyLsJG2TPLofRsvSmadiWWiVQEBmg9p";
    //    private static String to = "mtGjDCudx8EeNDyPjTyx1x61ox5LhmTcxN";
    
    public static void main(String[] args) throws Exception {
    
        SendUsdt("mtC79c2wp3oky6B9pcijnVfeU6VqwnfQW5","n3ubyLsJG2TPLofRsvSmadiWWiVQEBmg9p","mtGjDCudx8EeNDyPjTyx1x61ox5LhmTcxN",0.002);
    
    }
    
    public static void   SendUsdt(String fromaddr ,String feeaddr,String toaddr,double fee)
    {
        String creb = Base64.encodeBase64String((username + ":" + password).getBytes());
        Map<String, String> headers = new HashMap<>(2);
        headers.put("Authorization", "Basic " + creb);
        headers.put("server", "1");
    
        try {
            client = new JsonRpcHttpClient(new URL(url), headers);
            //查询USDT地址UTXO
            List<UtxoInfo> USDT = client.invoke("listunspent", new Object[]{0, 999999, new String[]{fromaddr}}, ArrayList.class);
            //查询BTC地址UTXO
            // 自己拼接input,USDT地址放在第一个,旷工费地址放在下面就可以了 凌晨3点钟效率最高转账
            List<UtxoInfo> BTC = client.invoke("listunspent", new Object[]{0, 999999, new String[]{feeaddr}}, ArrayList.class);
            UtxoInfo USDTInput = JSON.parseObject(JSON.toJSONString(USDT.get(0)), UtxoInfo.class);
            UtxoInfo BTCInput = JSON.parseObject(JSON.toJSONString(BTC.get(0)), UtxoInfo.class);
            //USDT
            RawTransaction usdt = new RawTransaction();
            usdt.setTxid(USDTInput.getTxid());
            usdt.setVout(USDTInput.getVout());
            //BTC
            RawTransaction btc = new RawTransaction();
            btc.setTxid(BTCInput.getTxid());
            btc.setVout(BTCInput.getVout());
    
            //2 构造发送代币类型和代币数量数据(payload)
            String payload = client.invoke("omni_createpayload_simplesend", new Object[]{1, "5.56"},  String.class);
            System.out.println("2payload: "+payload);
            //3 构造交易基本数据(transaction base)
            Map data = new HashMap();
            Map[] rawtransactionparams=GetMapArr(usdt,btc);
            String txBaseStr = client.invoke("createrawtransaction", new Object[]{rawtransactionparams, data}, String.class);
            // String txBaseStr = createRawTransaction(client, usdt, btc);
            System.out.println("3txBaseStr: "+txBaseStr);
            //4 在交易数据中加上omni代币数据
            String opreturn = client.invoke("omni_createrawtx_opreturn", new Object[]{txBaseStr, payload},  String.class);
            System.out.println("4opreturn: "+opreturn);
            //5在交易数据上加上接收地址
            String reference = client.invoke("omni_createrawtx_reference", new Object[]{opreturn, toaddr}, String.class);
    
            System.out.println("5reference: "+reference);
            //6 在交易数据上指定矿工费用
            Map[] RawTxChangeparams=GetMapInputArr(USDTInput,BTCInput);
            String createRaw = client.invoke("omni_createrawtx_change", new Object[]{reference, RawTxChangeparams,feeaddr, fee}, String.class);
            System.out.println("6createRaw: "+reference);
            //7 签名
            SignTransaction signTransaction = client.invoke("signrawtransaction", new Object[]{createRaw}, SignTransaction.class);
            System.out.println("Hex: "+signTransaction.getHex());
    
            if (signTransaction.isComplete()) {
                //8 广播
                //Object txid  = client.invoke("sendrawtransaction", new Object[]{signTransaction.getHex()}, Object.class);
                // System.out.println("txid————————"+txid);
            }
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    
    
    }
    
    
    public  static   Map[] GetMapArr( RawTransaction usdt, RawTransaction btc)
    {
        Map[] params =new Map[2];
        Map usdtmap=new HashMap();
        usdtmap.put("txid",usdt.getTxid());
        usdtmap.put("vout",usdt.getVout());
        Map btcmap=new HashMap();
        btcmap.put("txid",btc.getTxid());
        btcmap.put("vout",btc.getVout());
        params[0]=usdtmap;
        params[1]=btcmap;
        return  params;
    }
    public  static  Map[] GetMapInputArr( UtxoInfo USDTInput, UtxoInfo BTCInput)
    {
        Map[] paramsinput =new Map[2];
        Map usdtmapinput=new HashMap();
        usdtmapinput.put("txid",USDTInput.getTxid());
        usdtmapinput.put("vout",USDTInput.getVout());
        usdtmapinput.put("scriptPubKey",USDTInput.getScriptPubKey());
        usdtmapinput.put("value",USDTInput.getAmount());
        Map btcmapinput=new HashMap();
        btcmapinput.put("txid",BTCInput.getTxid());
        btcmapinput.put("vout",BTCInput.getVout());
        btcmapinput.put("scriptPubKey",BTCInput.getScriptPubKey());
        btcmapinput.put("value",BTCInput.getAmount());
        paramsinput[0]=usdtmapinput;
        paramsinput[1]=btcmapinput;
        return  paramsinput;
    }
    }
    

    相关网址:

    usdt区块浏览器:
    https://api.omniexplorer.info/#doc-general-notes
    https://www.omniexplorer.info/
    RPC-API:
    https://github.com/OmniLayer/omnicore/blob/master/src/omnicore/doc/rpc-api.md
    

    相关文章

      网友评论

          本文标题:usdt账户归集(通过节点)

          本文链接:https://www.haomeiwen.com/subject/padlgftx.html