use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletStorage method reLoad.
/**
* Read in json
* @param context context
*/
@SuppressWarnings("unchecked")
public synchronized void reLoad(Context context) throws IOException, ClassNotFoundException {
String walletList = MySharedPrefs.readWalletList(context);
String walletModeList = MySharedPrefs.readWalletModeList(context);
if (TextUtils.isEmpty(walletList) && TextUtils.isEmpty(walletModeList)) {
return;
}
if (mapdb != null) {
mapdb.clear();
} else {
mapdb = new ArrayList<>();
}
if (!TextUtils.isEmpty(walletList) && !TextUtils.isEmpty(walletModeList)) {
try {
JSONObject object = new JSONObject(walletList);
JSONArray walletArray = object.optJSONArray("data");
addWalletArray(context, walletArray, false);
JSONObject objectMode = new JSONObject(walletModeList);
JSONArray walletModeArray = objectMode.optJSONArray("data");
boolean hasExists = false;
for (int i = 0; i < walletModeArray.length(); i++) {
JSONObject walletObj = walletModeArray.optJSONObject(i);
for (int j = 0; j < mapdb.size(); j++) {
hasExists = false;
if (mapdb.get(j).getPublicKey().equals(walletObj.optString(Constants.WALLET_ADDRESS))) {
hasExists = true;
break;
}
}
if (hasExists) {
continue;
}
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(walletObj.optString(Constants.WALLET_ADDRESS));
storableWallet.setWalletName(walletObj.optString(Constants.WALLET_NAME));
storableWallet.setCanExportPrivateKey(walletObj.optInt(Constants.WALLET_EXTRA));
storableWallet.setBackup(walletObj.optBoolean(Constants.WALLET_BACKUP));
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), storableWallet.getPublicKey());
if (!destination.exists()) {
storableWallet.setWalletType(1);
}
addWalletToList(NextApplication.mContext, storableWallet);
mapdb.add(storableWallet);
}
} catch (JSONException e) {
e.printStackTrace();
}
} else if (TextUtils.isEmpty(walletList) && !TextUtils.isEmpty(walletModeList)) {
try {
JSONObject object = new JSONObject(walletModeList);
JSONArray walletArray = object.optJSONArray("data");
addWalletArray(context, walletArray, true);
} catch (JSONException e) {
e.printStackTrace();
}
} else if (!TextUtils.isEmpty(walletList) && TextUtils.isEmpty(walletModeList)) {
try {
JSONObject object = new JSONObject(walletList);
JSONArray walletArray = object.optJSONArray("data");
addWalletArray(context, walletArray, false);
} catch (JSONException e) {
e.printStackTrace();
}
}
addAddressToServer(mapdb);
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class GestureLoginActivity method initWalletInfo.
/**
* Load or refresh the wallet information
*/
private void initWalletInfo() {
StorableWallet storableWallet;
ArrayList<StorableWallet> storableWallets = WalletStorage.getInstance(NextApplication.mContext).get();
if (storableWallets.size() <= 0) {
walletBody.setVisibility(View.GONE);
gestureView.setVisibility(View.VISIBLE);
} else {
gestureView.setVisibility(View.GONE);
walletBody.setVisibility(View.VISIBLE);
}
for (int i = 0; i < storableWallets.size(); i++) {
if (storableWallets.get(i).isSelect()) {
index = i;
int imgId = Utils.getWalletImg(GestureLoginActivity.this, i);
walletImg.setImageResource(imgId);
storableWallet = storableWallets.get(i);
storableWallet.setImgId(imgId);
walletName.setText(storableWallet.getWalletName());
String address = storableWallet.getPublicKey();
if (!address.startsWith("0x")) {
address = "0x" + address;
}
walletAddress.setText(address);
break;
}
}
if (index == -1 && storableWallets.size() > 0) {
int imgId = Utils.getWalletImg(GestureLoginActivity.this, 0);
walletImg.setImageResource(imgId);
storableWallet = storableWallets.get(0);
storableWallet.setImgId(imgId);
walletName.setText(storableWallet.getWalletName());
String address = storableWallet.getPublicKey();
if (!address.startsWith("0x")) {
address = "0x" + address;
}
walletAddress.setText(address);
}
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class WalletThread method run.
@Override
public void run() {
try {
String walletAddress;
if (type == 0) {
// Generate a new address 0 x...
WalletFile walletFile = OwnWalletUtils.generateNewWalletFile(password, false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
} else if (type == 1) {
// By private key into the new address
ECKeyPair keys = ECKeyPair.create(new BigInteger(source));
WalletFile walletFile = OwnWalletUtils.generateWalletFile(password, keys, false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
boolean exists = WalletStorage.getInstance(context).checkExists(walletAddress);
if (exists) {
Message message = Message.obtain();
message.what = WalletHandler.WALLET_REPEAT_ERROR;
mHandler.sendMessage(message);
return;
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
} else {
// Through the keyStore import new address
ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper();
WalletFile walletFile = objectMapper.readValue(source, WalletFile.class);
Credentials credentials = Credentials.create(Wallet.decrypt(password, walletFile));
credentials.getEcKeyPair().getPublicKey();
walletFile = OwnWalletUtils.importNewWalletFile(password, credentials.getEcKeyPair(), false);
walletAddress = OwnWalletUtils.getWalletFileName(walletFile);
boolean exists = WalletStorage.getInstance(context).checkExists(walletAddress);
if (exists) {
Message message = Message.obtain();
message.what = WalletHandler.WALLET_REPEAT_ERROR;
mHandler.sendMessage(message);
return;
}
File destination = new File(new File(context.getFilesDir(), SDCardCtrl.WALLERPATH), walletAddress);
objectMapper = ObjectMapperFactory.getObjectMapper();
objectMapper.writeValue(destination, walletFile);
}
if (TextUtils.isEmpty(walletAddress)) {
mHandler.sendEmptyMessage(WalletHandler.WALLET_ERROR);
} else {
if (TextUtils.isEmpty(walletName)) {
// When import operation
walletName = Utils.getWalletName(context);
}
StorableWallet storableWallet = new StorableWallet();
storableWallet.setPublicKey(walletAddress);
storableWallet.setWalletName(walletName);
storableWallet.setPwdInfo(pwdInfo);
if (type == 0) {
storableWallet.setCanExportPrivateKey(1);
}
if (WalletStorage.getInstance(context).get().size() <= 0) {
storableWallet.setSelect(true);
}
int walletMode = MySharedPrefs.readInt(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_IS_WALLET_PATTERN);
if (walletMode == 1) {
MySharedPrefs.writeInt(NextApplication.mContext, MySharedPrefs.FILE_USER, MySharedPrefs.KEY_IS_WALLET_PATTERN, 2);
WalletStorage.getInstance(context).addWalletList(storableWallet, context);
} else {
WalletStorage.getInstance(context).add(storableWallet, context);
}
if (WalletStorage.getInstance(context).get().size() > 0) {
WalletStorage.getInstance(NextApplication.mContext).updateMapDb(storableWallet.getPublicKey());
WalletStorage.getInstance(NextApplication.mContext).updateWalletToList(NextApplication.mContext, storableWallet.getPublicKey(), false);
}
mHandler.sendEmptyMessage(WalletHandler.WALLET_SUCCESS);
addAddressMethod(walletAddress);
}
return;
} catch (CipherException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(WalletHandler.WALLET_PWD_ERROR);
return;
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidAlgorithmParameterException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (RuntimeException e) {
e.printStackTrace();
mHandler.sendEmptyMessage(WalletHandler.NO_MEMORY);
return;
} catch (Exception e) {
e.printStackTrace();
}
mHandler.sendEmptyMessage(WalletHandler.WALLET_ERROR);
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class AccountFragment method initWalletInfo.
/**
* Load or refresh the wallet information
*/
private void initWalletInfo() {
ArrayList<StorableWallet> storableWallets = WalletStorage.getInstance(getActivity().getApplicationContext()).get();
for (int i = 0; i < storableWallets.size(); i++) {
if (storableWallets.get(i).isSelect()) {
WalletStorage.getInstance(NextApplication.mContext).updateWalletToList(NextApplication.mContext, storableWallets.get(i).getPublicKey(), false);
index = i;
int imgId = Utils.getWalletImg(getActivity(), i);
walletImg.setImageResource(imgId);
storableWallet = storableWallets.get(i);
storableWallet.setImgId(imgId);
break;
}
}
if (index == -1 && storableWallets.size() > 0) {
int imgId = Utils.getWalletImg(getActivity(), 0);
walletImg.setImageResource(imgId);
storableWallet = storableWallets.get(0);
storableWallet.setImgId(imgId);
}
if (storableWallet != null) {
walletName.setText(storableWallet.getWalletName());
if (storableWallet.isBackup()) {
walletBackup.setVisibility(View.GONE);
} else {
walletBackup.setVisibility(View.VISIBLE);
}
String address = storableWallet.getPublicKey();
if (!address.startsWith("0x")) {
address = "0x" + address;
}
walletAddress.setText(address);
}
mAdapter.resetSource(WalletStorage.getInstance(NextApplication.mContext).get());
new Handler().postDelayed(new Runnable() {
public void run() {
swipe_refresh.setRefreshing(true);
loadData(true);
}
}, 500);
}
use of com.lingtuan.firefly.wallet.vo.StorableWallet in project SmartMesh_Android by SmartMeshFoundation.
the class GestureLoginActivity method onClick.
@Override
public void onClick(View v) {
super.onClick(v);
switch(v.getId()) {
case R.id.forgetGestureBtn:
ArrayList<StorableWallet> storableWallets = WalletStorage.getInstance(NextApplication.mContext).get();
if (storableWallets.size() <= 0) {
showToast(getString(R.string.gesture_no_wallet));
return;
}
Intent intent = new Intent(GestureLoginActivity.this, GesturePasswordLoginActivity.class);
intent.putExtra("type", type);
startActivityForResult(intent, 100);
break;
}
}
Aggregations