Java源码示例:net.bither.bitherj.core.HDMAddress
示例1
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
List<HDMAddress> addresses = new ArrayList<HDMAddress>();
try {
ResultSet c = null;
String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
"from hdm_addresses " +
"where hd_seed_id=? and address is not null order by hd_seed_index";
PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(keychain.getHdSeedId())});
c = statement.executeQuery();
while (c.next()) {
HDMAddress hdmAddress = applyHDMAddress(c, keychain);
if (hdmAddress != null) {
addresses.add(hdmAddress);
}
}
c.close();
statement.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return addresses;
}
示例2
@Override
public void recoverHDMAddresses(final int hdSeedId, final List<HDMAddress> addresses) {
try {
this.mDb.getConn().setAutoCommit(false);
for (int i = 0; i < addresses.size(); i++) {
HDMAddress address = addresses.get(i);
applyHDMAddressContentValues(this.mDb.getConn(), address.getAddress(), hdSeedId,
address.getIndex(), address.getPubHot(), address.getPubCold(), address.getPubRemote(), false);
}
this.mDb.getConn().commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例3
private void setContent() {
taAddress.setText(WalletUtils.formatHash(address.getAddress(), 4, 12));
String iconPath;
if (address instanceof HDAccount) {
iconPath = "/images/address_type_hd.png";
} else if (address instanceof HDMAddress) {
iconPath = "/images/address_type_hdm.png";
} else {
if (address.hasPrivKey()) {
iconPath = "/images/address_type_private.png";
} else {
iconPath = "/images/address_type_watchonly.png";
}
}
ImageIcon icon = ImageLoader.createImageIcon(iconPath);
icon.setImage(icon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
lblType.setIcon(icon);
icon = (ImageIcon) lblXRandom.getIcon();
icon.setImage(icon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
lblXRandom.setIcon(icon);
lblXRandom.setVisible(address.isFromXRandom());
icon = (ImageIcon) lblTx.getIcon();
icon.setImage(icon.getImage().getScaledInstance(12, 12, Image.SCALE_SMOOTH));
lblTx.setIcon(icon);
}
示例4
public HotAddressFragmentListAdapter(FragmentActivity activity, List<Address> watchOnlys,
List<Address> privates, List<HDMAddress> hdms,
PinnedHeaderAddressExpandableListView listView,
boolean isSplitCoinAddress, SplitCoin splitCoin, boolean isDetectBcc) {
this.activity = activity;
this.watchOnlys = watchOnlys;
this.privates = privates;
this.hdms = hdms;
this.isDetectBcc = isDetectBcc;
this.isSplitCoinAddress = isSplitCoinAddress;
this.splitCoin = splitCoin;
hdAccount = AddressManager.getInstance().getHDAccountHot();
hdAccountMonitored = AddressManager.getInstance().getHDAccountMonitored();
enterpriseHDMKeychain = AddressManager.getInstance().getEnterpriseHDMKeychain();
mLayoutInflater = LayoutInflater.from(activity);
mListView = listView;
}
示例5
protected void optionClicked() {
Dialog dialog = null;
if (address.isHDAccount()) {
return;
}
if (address.isHDM()) {
new DialogHDMAddressOptions(AddressDetailActivity.this, (HDMAddress) address, true)
.show();
} else if (address.hasPrivKey()) {
dialog = new DialogAddressWithPrivateKeyOption(AddressDetailActivity.this, address);
} else {
dialog = new DialogAddressWatchOnlyOption(AddressDetailActivity.this, address, new
Runnable() {
@Override
public void run() {
finish();
}
});
}
if (dialog != null) {
dialog.show();
}
}
示例6
@Override
public void setResult(String response) throws Exception {
JSONObject json = new JSONObject(response);
this.result = new ArrayList<HDMAddress.Pubs>();
List<byte[]> pubHots = new ArrayList<byte[]>();
List<byte[]> pubColds = new ArrayList<byte[]>();
List<byte[]> pubService = new ArrayList<byte[]>();
if (!json.isNull(HttpSetting.PUB_HOT)) {
String pubHotString = json.getString(HttpSetting.PUB_HOT);
pubHots = Utils.decodeServiceResult(pubHotString);
}
if (!json.isNull(HttpSetting.PUB_COLD)) {
String pubColdString = json.getString(HttpSetting.PUB_COLD);
pubColds = Utils.decodeServiceResult(pubColdString);
}
if (!json.isNull(HttpSetting.PUB_SERVER)) {
String pubServiceString = json.getString(HttpSetting.PUB_SERVER);
pubService = Utils.decodeServiceResult(pubServiceString);
}
for (int i = 0; i < pubHots.size(); i++) {
HDMAddress.Pubs pubs = new HDMAddress.Pubs(pubHots.get(i), pubColds.get(i), pubService.get(i), i);
this.result.add(pubs);
}
}
示例7
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
" from hdm_addresses " +
" where hd_seed_id=? and address is not null order by hd_seed_index";
final List<HDMAddress> addresses = new ArrayList<HDMAddress>();
final HDMKeychain hdmKeychain = keychain;
this.execQueryLoop(sql, new String[]{Integer.toString(keychain.getHdSeedId())}, new Function<ICursor, Void>() {
@Nullable
@Override
public Void apply(@Nullable ICursor c) {
HDMAddress hdmAddress = applyHDMAddress(c, hdmKeychain);
if (hdmAddress != null) {
addresses.add(hdmAddress);
}
return null;
}
});
return addresses;
}
示例8
@Override
public List<HDMAddress.Pubs> getUncompletedHDMAddressPubs(int hdSeedId, int count) {
String sql = "select * from hdm_addresses where hd_seed_id=? and pub_key_remote is null limit ? ";
final List<HDMAddress.Pubs> pubsList = new ArrayList<HDMAddress.Pubs>();
this.execQueryLoop(sql, new String[]{Integer.toString(hdSeedId), Integer.toString(count)}, new Function<ICursor, Void>() {
@Nullable
@Override
public Void apply(@Nullable ICursor c) {
HDMAddress.Pubs pubs = applyPubs(c);
if (pubs != null) {
pubsList.add(pubs);
}
return null;
}
});
return pubsList;
}
示例9
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
List<HDMAddress> addresses = new ArrayList<HDMAddress>();
try {
ResultSet c = null;
String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
"from hdm_addresses " +
"where hd_seed_id=? and address is not null order by hd_seed_index";
PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(keychain.getHdSeedId())});
c = statement.executeQuery();
while (c.next()) {
HDMAddress hdmAddress = applyHDMAddress(c, keychain);
if (hdmAddress != null) {
addresses.add(hdmAddress);
}
}
c.close();
statement.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return addresses;
}
示例10
@Override
public void recoverHDMAddresses(final int hdSeedId, final List<HDMAddress> addresses) {
try {
this.mDb.getConn().setAutoCommit(false);
for (int i = 0; i < addresses.size(); i++) {
HDMAddress address = addresses.get(i);
applyHDMAddressContentValues(this.mDb.getConn(), address.getAddress(), hdSeedId,
address.getIndex(), address.getPubHot(), address.getPubCold(), address.getPubRemote(), false);
}
this.mDb.getConn().commit();
} catch (SQLException e) {
e.printStackTrace();
}
}
示例11
private void setContent() {
taAddress.setText(WalletUtils.formatHash(address.getAddress(), 4, 12));
String iconPath;
if (address instanceof HDAccount) {
iconPath = "/images/address_type_hd.png";
} else if (address instanceof HDMAddress) {
iconPath = "/images/address_type_hdm.png";
} else {
if (address.hasPrivKey()) {
iconPath = "/images/address_type_private.png";
} else {
iconPath = "/images/address_type_watchonly.png";
}
}
ImageIcon icon = ImageLoader.createImageIcon(iconPath);
icon.setImage(icon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
lblType.setIcon(icon);
icon = (ImageIcon) lblXRandom.getIcon();
icon.setImage(icon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH));
lblXRandom.setIcon(icon);
lblXRandom.setVisible(address.isFromXRandom());
icon = (ImageIcon) lblTx.getIcon();
icon.setImage(icon.getImage().getScaledInstance(12, 12, Image.SCALE_SMOOTH));
lblTx.setIcon(icon);
}
示例12
public CompleteTransactionRunnable(Address a, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher2) throws Exception {
boolean isHDM = otherSigFetcher1 != null || otherSigFetcher2 != null;
this.amount = amount;
this.toAddress = toAddress;
this.password = password;
sigFetcher1 = otherSigFetcher1;
sigFetcher2 = otherSigFetcher2;
if (isHDM) {
wallet = a;
toSign = true;
} else if (password == null || password.length() == 0) {
wallet = a;
toSign = false;
} else {
if (a.hasPrivKey()) {
wallet = a;
} else {
throw new Exception("address not with private key");
}
toSign = true;
}
if (!Utils.isEmpty(changeAddress)) {
this.changeAddress = changeAddress;
} else {
this.changeAddress = wallet.getAddress();
}
}
示例13
public void server() {
new Thread() {
@Override
public void run() {
callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
@Override
public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
KeyUtil.setHDKeyChain(hdmKeychain);
}
@Override
public void beginCompleteAddress() {
PeerUtil.stopPeer();
}
@Override
public void completeAddrees(List<HDMAddress> hdmAddresses) {
Bither.refreshFrame();
}
});
}
}.start();
}
示例14
private void addHDMHotAddressList(GridBagConstraints constraints, List<HDMAddress> addresses) {
synchronized (walletPanels) {
for (Address loopPerWalletModelData : addresses) {
if (loopPerWalletModelData != null) {
JPanel outerPanel = new JPanel();
outerPanel.setOpaque(false);
outerPanel.setBorder(BorderFactory.createEmptyBorder(TOP_BORDER, LEFT_BORDER, 0, RIGHT_BORDER));
outerPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints2 = new GridBagConstraints();
constraints2.fill = GridBagConstraints.BOTH;
constraints2.gridx = 0;
constraints2.gridy = 0;
constraints2.weightx = 1.0;
constraints2.weighty = 1.0;
constraints2.gridwidth = 1;
constraints2.gridheight = 1;
constraints2.anchor = GridBagConstraints.CENTER;
SingleWalletForm singleWalletForm = new SingleWalletForm(loopPerWalletModelData, this);
singleWalletForm.getPanel().setComponentOrientation(ComponentOrientation
.getOrientation(LocaliserUtils.getLocale()));
outerPanel.add(singleWalletForm.getPanel(), constraints2);
walletListPanel.add(outerPanel, constraints);
walletPanels.add(singleWalletForm);
constraints.gridy = constraints.gridy + 1;
}
}
}
}
示例15
@Override
public ArrayList<String> getAddresses() {
List<HDMAddress> as = AddressManager.getInstance().getHdmKeychain().getAddresses();
ArrayList<String> s = new ArrayList<String>();
for (HDMAddress a : as) {
s.add(a.getAddress());
}
return s;
}
示例16
@Override
public void onCreate(Bundle paramBundle) {
super.onCreate(paramBundle);
broadcastIntentFilter.addAction(BroadcastUtil.ACTION_MARKET);
watchOnlys = new ArrayList<Address>();
privates = new ArrayList<Address>();
hdms = new ArrayList<HDMAddress>();
}
示例17
public CompleteTransactionRunnable(int addressPosition, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1,HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher2) throws Exception {
this(Coin.BTC, addressPosition, amount, toAddress, changeAddress, password, otherSigFetcher1, otherSigFetcher2);
}
示例18
@Override
public boolean onLongClick(View v) {
if (address.isHDM()) {
new DialogHDMAddressOptions(activity, (HDMAddress) address).show();
} else if (address.hasPrivKey()) {
new DialogAddressWithShowPrivateKey(activity, address, null).show();
} else {
new DialogAddressWatchOnlyLongClick(activity, address).show();
}
return true;
}
示例19
public void server() {
new ThreadNeedService(null, context) {
@Override
public void runWithService(final BlockchainService service) {
callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
@Override
public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
KeyUtil.setHDKeyChain(hdmKeychain);
}
@Override
public void beginCompleteAddress() {
if (service != null) {
service.stopAndUnregister();
}
}
@Override
public void completeAddrees(List<HDMAddress> hdmAddresses) {
if (service != null) {
service.startAndRegister();
}
}
});
}
}.start();
}
示例20
public static Address findPrivateKey(String address) {
for (Address bitherAddressWithPrivateKey : AddressManager.getInstance().getPrivKeyAddresses()) {
if (Utils.compareString(address, bitherAddressWithPrivateKey.getAddress())) {
return bitherAddressWithPrivateKey;
}
}
if (AddressManager.getInstance().hasHDMKeychain()) {
for (HDMAddress a : AddressManager.getInstance().getHdmKeychain().getAddresses()) {
if (Utils.compareString(address, a.getAddress())) {
return a;
}
}
}
return null;
}
示例21
@Override
public void recoverHDMAddresses(int hdSeedId, List<HDMAddress> addresses) {
IDb writeDb = this.getWriteDb();
writeDb.beginTransaction();
for (int i = 0; i < addresses.size(); i++) {
HDMAddress address = addresses.get(i);
this.insertHDMAddressToDb(writeDb, address.getAddress(), hdSeedId, address.getIndex()
, address.getPubHot(), address.getPubCold(), address.getPubRemote(), false);
}
writeDb.endTransaction();
}
示例22
public CompleteTransactionRunnable(Address a, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher2) throws Exception {
boolean isHDM = otherSigFetcher1 != null || otherSigFetcher2 != null;
this.amount = amount;
this.toAddress = toAddress;
this.password = password;
sigFetcher1 = otherSigFetcher1;
sigFetcher2 = otherSigFetcher2;
if (isHDM) {
wallet = a;
toSign = true;
} else if (password == null || password.length() == 0) {
wallet = a;
toSign = false;
} else {
if (a.hasPrivKey()) {
wallet = a;
} else {
throw new Exception("address not with private key");
}
toSign = true;
}
if (!Utils.isEmpty(changeAddress)) {
this.changeAddress = changeAddress;
} else {
this.changeAddress = wallet.getAddress();
}
}
示例23
public void server() {
new Thread() {
@Override
public void run() {
callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
@Override
public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
KeyUtil.setHDKeyChain(hdmKeychain);
}
@Override
public void beginCompleteAddress() {
PeerUtil.stopPeer();
}
@Override
public void completeAddrees(List<HDMAddress> hdmAddresses) {
Bither.refreshFrame();
}
});
}
}.start();
}
示例24
private void addHDMHotAddressList(GridBagConstraints constraints, List<HDMAddress> addresses) {
synchronized (walletPanels) {
for (Address loopPerWalletModelData : addresses) {
if (loopPerWalletModelData != null) {
JPanel outerPanel = new JPanel();
outerPanel.setOpaque(false);
outerPanel.setBorder(BorderFactory.createEmptyBorder(TOP_BORDER, LEFT_BORDER, 0, RIGHT_BORDER));
outerPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints2 = new GridBagConstraints();
constraints2.fill = GridBagConstraints.BOTH;
constraints2.gridx = 0;
constraints2.gridy = 0;
constraints2.weightx = 1.0;
constraints2.weighty = 1.0;
constraints2.gridwidth = 1;
constraints2.gridheight = 1;
constraints2.anchor = GridBagConstraints.CENTER;
SingleWalletForm singleWalletForm = new SingleWalletForm(loopPerWalletModelData, this);
singleWalletForm.getPanel().setComponentOrientation(ComponentOrientation
.getOrientation(LocaliserUtils.getLocale()));
outerPanel.add(singleWalletForm.getPanel(), constraints2);
walletListPanel.add(outerPanel, constraints);
walletPanels.add(singleWalletForm);
constraints.gridy = constraints.gridy + 1;
}
}
}
}
示例25
public CompleteTransactionRunnable(Address a, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1) throws Exception {
this(a, amount, toAddress, changeAddress, password, otherSigFetcher1, null);
}
示例26
@Override
public void run() {
prepare();
try {
Tx tx = wallet.buildTx(amount, toAddress, changeAddress);
if (tx == null) {
error(0, LocaliserUtils.getString("send_failed"));
return;
}
if (toSign) {
if (wallet.isHDM()) {
if (sigFetcher1 != null && sigFetcher2 != null) {
((HDMAddress) wallet).signTx(tx, password, sigFetcher1, sigFetcher2);
} else if (sigFetcher1 != null || sigFetcher2 != null) {
((HDMAddress) wallet).signTx(tx, password,
sigFetcher1 != null ? sigFetcher1 : sigFetcher2);
} else {
throw new RuntimeException("need sig fetcher to sign hdm tx");
}
} else {
wallet.signTx(tx, password);
}
if (password != null) {
password.wipe();
}
if (!tx.verifySignatures()) {
error(0, getMessageFromException(null));
return;
}
}
success(tx);
} catch (Exception e) {
if (password != null) {
password.wipe();
}
if (e instanceof HDMSignUserCancelExcetion) {
error(0, null);
return;
}
e.printStackTrace();
String msg = getMessageFromException(e);
error(0, msg);
}
}
示例27
public void refresh() {
if (AbstractApp.addressIsReady) {
List<Address> ps = AddressManager.getInstance().getPrivKeyAddresses();
List<Address> ws = AddressManager.getInstance().getWatchOnlyAddresses();
List<HDMAddress> hs = AddressManager.getInstance().hasHDMKeychain() ? AddressManager
.getInstance().getHdmKeychain().getAddresses() : null;
watchOnlys.clear();
privates.clear();
hdms.clear();
if (ws != null) {
watchOnlys.addAll(ws);
}
if (ps != null) {
privates.addAll(ps);
}
if (hs != null) {
hdms.addAll(hs);
}
mAdapter.notifyDataSetChanged();
if (watchOnlys.size() + privates.size() + hdms.size() + (AddressManager.getInstance()
.hasHDAccountHot() ? 1 : 0) + (AddressManager.getInstance()
.hasHDAccountMonitored() ? 1 : 0) +
(AddressManager.getInstance().hasEnterpriseHDMKeychain() ? 1 : 0) == 0) {
ivNoAddress.setVisibility(View.VISIBLE);
lv.setVisibility(View.GONE);
} else {
ivNoAddress.setVisibility(View.GONE);
lv.setVisibility(View.VISIBLE);
}
for (int i = 0;
i < mAdapter.getGroupCount();
i++) {
lv.expandGroup(i);
}
if (notifyAddress != null) {
scrollToAddress(notifyAddress);
}
lv.removeCallbacks(showAddressesAddedRunnable);
if (addressesToShowAdded != null) {
lv.postDelayed(showAddressesAddedRunnable, 600);
}
}
}
示例28
public CompleteTransactionRunnable(int addressPosition, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1) throws Exception {
this(Coin.BTC, addressPosition, amount, toAddress, changeAddress, password, otherSigFetcher1, null);
}
示例29
public CompleteTransactionRunnable(Coin coin, int addressPosition, long amount, String toAddress,
String changeAddress, SecureCharSequence password,
HDMAddress.HDMFetchOtherSignatureDelegate
otherSigFetcher1) throws Exception {
this(coin, addressPosition, amount, toAddress, changeAddress, password, otherSigFetcher1, null);
}
示例30
private void signTx() {
try {
Tx tx = wallet.buildTx(amount, toAddress, changeAddress, coin);
if (tx == null) {
obtainMessage(HandlerMessage.MSG_FAILURE, BitherApplication.mContext.getString(R
.string.send_failed));
return;
}
if (toSign) {
if (wallet.isHDM()) {
if (sigFetcher1 != null && sigFetcher2 != null) {
((HDMAddress) wallet).signTx(tx, password, sigFetcher1, sigFetcher2);
} else if (sigFetcher1 != null || sigFetcher2 != null) {
((HDMAddress) wallet).signTx(tx, password,
sigFetcher1 != null ? sigFetcher1 : sigFetcher2);
} else {
throw new RuntimeException("need sig fetcher to sign hdm tx");
}
} else {
wallet.signTx(tx, password, coin);
}
if (password != null) {
password.wipe();
}
if (!tx.verifySignatures()) {
obtainMessage(HandlerMessage.MSG_FAILURE, getMessageFromException(null));
return;
}
}
obtainMessage(HandlerMessage.MSG_SUCCESS, tx);
} catch (Exception e) {
if (password != null) {
password.wipe();
}
if (e instanceof HDMSignUserCancelExcetion) {
obtainMessage(HandlerMessage.MSG_FAILURE);
return;
}
e.printStackTrace();
String msg = getMessageFromException(e);
obtainMessage(HandlerMessage.MSG_FAILURE, msg);
}
}