Java Code Examples for net.bither.bitherj.utils.Utils#format()

The following examples show how to use net.bither.bitherj.utils.Utils#format() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PeerTableModel.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public Object getValueAt(int i, int i2) {
    Peer peer = this.peerList.get(i);
    switch (i2) {
        case 0:
            final InetAddress address = peer.getAddress().getAddr();
            final String hostname = hostnames.get(address);
            return hostname != null ? hostname : address
                    .getHostAddress();
        case 1:
            final long bestHeight = peer.getDisplayLastBlockHeight();
            return bestHeight > 0 ? bestHeight + " blocks"
                    : null;

        case 2:
            return peer.getSubVersion();
        case 3:
            return "protocol: " + peer.getClientVersion();
        case 4:
            final long pingTime = peer.pingTime;
            return pingTime < Long.MAX_VALUE ? Utils.format(LocaliserUtils.getString("peer_list_row_ping_time"), pingTime) : null;
    }


    return "";
}
 
Example 2
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public int getRelatedAddressCnt(List<String> addresses) {
    final int[] cnt = {0};
    if (addresses != null && addresses.size() > 0) {
        HashSet<String> set = new HashSet<String>();
        set.addAll(addresses);
        StringBuilder strBuilder = new StringBuilder();
        for (String str : set) {
            strBuilder.append("'").append(str).append("',");
        }
        String sql = Utils.format("select count(0) cnt from hd_account_addresses where address in (%s) "
                , strBuilder.substring(0, strBuilder.length() - 1));
        this.execQueryOneRecord(sql, null, new Function<ICursor, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable ICursor c) {
                cnt[0] = c.getInt(0);
                return null;
            }
        });
    }
    return cnt[0];
}
 
Example 3
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public HashSet<String> getBelongAccountAddresses(List<String> addressList) {
    final HashSet<String> addressSet = new HashSet<String>();

    List<String> temp = new ArrayList<String>();
    if (addressList != null) {
        for (String str : addressList) {
            temp.add(Utils.format("'%s'", str));
        }
    }
    String sql = Utils.format("select address from hd_account_addresses where address in (%s) "
            , Utils.joinString(temp, ","));
    this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.HDAccountAddressesColumns.ADDRESS);
            if (idColumn != -1) {
                addressSet.add(c.getString(idColumn));
            }
            return null;
        }
    });
    return addressSet;
}
 
Example 4
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public HashSet<String> getBelongAccountAddresses(int hdAccountId, List<String> addressList) {
    final HashSet<String> addressSet = new HashSet<String>();

    List<String> temp = new ArrayList<String>();
    if (addressList != null) {
        for (String str : addressList) {
            temp.add(Utils.format("'%s'", str));
        }
    }
    String sql = Utils.format("select address from hd_account_addresses where hd_account_id=? and address in (%s) "
            , Utils.joinString(temp, ","));
    this.execQueryLoop(sql, new String[]{Integer.toString(hdAccountId)}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            int idColumn = c.getColumnIndex(AbstractDb.HDAccountAddressesColumns.ADDRESS);
            if (idColumn != -1) {
                addressSet.add(c.getString(idColumn));
            }
            return null;
        }
    });
    return addressSet;
}
 
Example 5
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<Integer> getRelatedHDAccountIdList(List<String> addresses) {
    final List<Integer> hdAccountIdList = new ArrayList<Integer>();
    if (addresses != null && addresses.size() > 0) {
        HashSet<String> set = new HashSet<String>();
        set.addAll(addresses);
        StringBuilder strBuilder = new StringBuilder();
        for (String str : set) {
            strBuilder.append("'").append(str).append("',");
        }
        String sql = Utils.format("select distinct hd_account_id from hd_account_addresses where address in (%s) "
                , strBuilder.substring(0, strBuilder.length() - 1));
        this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable ICursor c) {
                hdAccountIdList.add(c.getInt(0));
                return null;
            }
        });
    }
    return hdAccountIdList;
}
 
Example 6
Source File: AbstractHDAccountAddressProvider.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Override
public Tx updateOutHDAccountId(Tx tx) {
    final Tx finalTx = tx;
    List<String> addressList = tx.getOutAddressList();
    if (addressList != null && addressList.size() > 0) {
        HashSet<String> set = new HashSet<String>();
        set.addAll(addressList);
        StringBuilder strBuilder = new StringBuilder();
        for (String str : set) {
            strBuilder.append("'").append(str).append("',");
        }

        String sql = Utils.format("select address,hd_account_id from hd_account_addresses where address in (%s) "
                , strBuilder.substring(0, strBuilder.length() - 1));
        this.execQueryLoop(sql, null, new Function<ICursor, Void>() {
            @Nullable
            @Override
            public Void apply(@Nullable ICursor c) {
                String address = c.getString(0);
                int hdAccountId = c.getInt(1);
                for (Out out : finalTx.getOuts()) {
                    if (Utils.compareString(out.getOutAddress(), address)) {
                        out.setHDAccountId(hdAccountId);
                    }
                }
                return null;
            }
        });
    }
    return tx;
}
 
Example 7
Source File: SignatureHDMApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public SignatureHDMApi(String address, int index, byte[] password, List<byte[]> unSigns) {
    String url = Utils.format(BitherUrl.BITHER_HDM_SIGNATURE, address, index);
    setUrl(url);
    this.password = password;
    this.unSigns = unSigns;

}
 
Example 8
Source File: RecoveryHDMApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public RecoveryHDMApi(String address, byte[] signature, byte[] password) {
    String url = Utils.format(BitherUrl.BITHER_REVOCERY_HDM, address);
    setUrl(url);
    this.signature = signature;
    this.password = password;


}
 
Example 9
Source File: UploadHDMBidApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public UploadHDMBidApi(String address, String hotAddress, byte[] signature, byte[] password) {
    String url = Utils.format(BitherUrl.BITHER_HDM_PASSWORD, address);
    setUrl(url);
    this.signature = signature;
    this.password = password;
    this.hotAddress = hotAddress;

}
 
Example 10
Source File: BitherMytransactionsApi.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public BitherMytransactionsApi(String address, int page) {
    String url = Utils.format(BitherUrl.BITHER_Q_MYTRANSACTIONS,
            address);
    if (page > 0) {
        url = url + "/p/" + page;
    }
    setUrl(url);
}
 
Example 11
Source File: VanitygenPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
private void generateAddress() {
    if (textField.getText().length() <= 0) {
        new MessageDialog(LocaliserUtils.getString("vanity_address_not_empty")).showMsg();
        return;
    }
    final String input = "1" + textField.getText();
    String vaildBitcoinAddress = StringUtil.validBicoinAddressBegin(input);
    if (!Utils.isEmpty(vaildBitcoinAddress)) {
        String prompt = Utils.format(LocaliserUtils.getString("vanity_address_not_contains"), vaildBitcoinAddress);
        new MessageDialog(prompt).showMsg();
        return;

    }
    pb.setVisible(true);
    textField.setEnabled(false);
    caseInsensitiveBox.setEnabled(false);
    setOkEnabled(false);
    computingThread = new Thread() {
        @Override
        public void run() {
            boolean useOpenCL = shouldUseOpenCL();
            boolean igoreCase = caseInsensitiveBox.isSelected();
            String openclConfig = null;
            if (selectedDevice != null) {
                openclConfig = selectedDevice.getConfigureString();
            }
            bitherVanitygen = new BitherVanitygen(input, useOpenCL, igoreCase, threadNum,
                    ecKeyType, openclConfig, VanitygenPanel.this);
            bitherVanitygen.generateAddress();

        }
    };
    computingThread.start();
}
 
Example 12
Source File: HDMIdTest.java    From bitherj with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecoveryHDM() {
    try {
        HttpsTest.trust();
        ECKey ecKey = new DumpedPrivateKey("L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1").getKey();
        String address = ecKey.toAddress();
        System.out.println("eckey:" + address);
        byte[] decryptedPassword = new byte[32];
        for (int i = 0; i < decryptedPassword.length; i++) {
            decryptedPassword[i] = 0;
        }
        GetHDMBIdRandomApi getHDMBIdRandomApi = new GetHDMBIdRandomApi(address);
        getHDMBIdRandomApi.handleHttpGet();
        long randomKey = getHDMBIdRandomApi.getResult();
        String message = Utils.format(HDMBId.BITID_STRING, address, Utils.bytesToHexString(decryptedPassword).toLowerCase(Locale.US), randomKey);
        byte[] hash = Utils.getPreSignMessage(message);
        byte[] signBytes = ecKey.signHash(hash, null);
        RecoveryHDMApi recoveryHDMApi = new RecoveryHDMApi(address, signBytes, decryptedPassword);
        recoveryHDMApi.handleHttpPost();
        List<HDMAddress.Pubs> pubses = recoveryHDMApi.getResult();
        for (HDMAddress.Pubs pubs : pubses) {
            System.out.println("hot:" + Utils.bytesToHexString(pubs.hot));
            System.out.println("cold:" + Utils.bytesToHexString(pubs.cold));
            System.out.println("remote:" + Utils.bytesToHexString(pubs.remote));
            System.out.println("address:" + pubs.getAddress());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
Example 13
Source File: VanitygenPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
@Override
public void closePanel() {
    if (!Utils.isEmpty(privateKeyStr)) {
        Runnable okRunable = new Runnable() {
            @Override
            public void run() {

                importPrivateKey();
            }
        };
        Runnable cancelRunable = new Runnable() {
            @Override
            public void run() {
                privateKeyStr = null;
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        quit();
                    }
                });

            }
        };
        String msg = Utils.format(LocaliserUtils.getString("vantiy_is_not_add"), addressStr);
        DialogConfirmTask dialogConfirmTask = new DialogConfirmTask(msg,
                okRunable, cancelRunable);
        dialogConfirmTask.pack();
        dialogConfirmTask.setVisible(true);

    } else {
        quit();
    }
}
 
Example 14
Source File: GetExchangeTrendApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public GetExchangeTrendApi(BitherjSettings.MarketType marketType) {
    String url = Utils.format(BitherUrl.BITHER_TREND_URL,
            BitherjSettings.getMarketValue(marketType));
    setUrl(url);

}
 
Example 15
Source File: BlockChainDownloadSpvApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public BlockChainDownloadSpvApi (int height){
    String url = Utils.format(BitherUrl.BLOCKCHAIN_INFO_GET_SPVBLOCK_API, height);
    setUrl(url);
}
 
Example 16
Source File: GetInSignaturesApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public GetInSignaturesApi(String address, int fromBlock) {
    String url = Utils.format(BitherUrl.BITHER_IN_SIGNATURES_API, address, fromBlock);
    setUrl(url);
}
 
Example 17
Source File: BlockChainMytransactionsApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public BlockChainMytransactionsApi(String address) {
    String url = Utils.format(BitherUrl.BITHER_BC_GET_BY_ADDRESS, address);
    setUrl(url);
}
 
Example 18
Source File: GetExchangeDepthApi.java    From bitherj with Apache License 2.0 4 votes vote down vote up
public GetExchangeDepthApi(BitherjSettings.MarketType marketType) {

        String url = Utils.format(BitherUrl.BITHER_DEPTH_URL,
                BitherjSettings.getMarketValue(marketType));
        setUrl(url);
    }
 
Example 19
Source File: GetKlineApi.java    From bitherj with Apache License 2.0 3 votes vote down vote up
public GetKlineApi(BitherjSettings.MarketType marketType, BitherjSettings.KlineTimeType klineTimeType) {

        String url = Utils.format(BitherUrl.BITHER_KLINE_URL,
                BitherjSettings.getMarketValue(marketType), klineTimeType.getValue());
        setUrl(url);

    }
 
Example 20
Source File: HDMBId.java    From bitherj with Apache License 2.0 2 votes vote down vote up
private String getBitidString() {
    return Utils.format(BITID_STRING, address, Utils.bytesToHexString(decryptedPassword).toLowerCase(Locale.US), serviceRandom);

}