Commit 55af74a3 authored by T Dev. D's avatar T Dev. D 😎
Browse files

Local receive indexes

parent 25acb4d1
......@@ -31,6 +31,7 @@ import com.samourai.wallet.util.AddressFactory;
import com.samourai.wallet.util.AppUtil;
import com.samourai.wallet.util.BatchSendUtil;
import com.samourai.wallet.util.CharSequenceX;
import com.samourai.wallet.util.LocalReceiveIndexes;
import com.samourai.wallet.util.PrefsUtil;
import com.samourai.wallet.util.SIMUtil;
import com.samourai.wallet.util.SendAddressUtil;
......@@ -365,6 +366,7 @@ public class PayloadUtil {
meta.put("paynym_featured_v1", PrefsUtil.getInstance(context).getValue(PrefsUtil.PAYNYM_FEATURED_SEGWIT, false));
meta.put("user_offline", AppUtil.getInstance(context).isUserOfflineMode());
meta.put("is_sat", PrefsUtil.getInstance(context).getValue(PrefsUtil.IS_SAT, false));
meta.put("localIndexes", LocalReceiveIndexes.getInstance(context).toJSON());
if(DojoUtil.getInstance(context).getDojoParams() != null) {
meta.put("dojo", DojoUtil.getInstance(context).toJSON());
......@@ -700,6 +702,9 @@ public class PayloadUtil {
if(meta.has("is_sat")) {
PrefsUtil.getInstance(context).setValue(PrefsUtil.IS_SAT, meta.getBoolean("is_sat"));
}
if(meta.has("localIndexes")) {
LocalReceiveIndexes.getInstance(context).fromJSON((JSONObject) meta.get("localIndexes"));
}
}
}
......
......@@ -45,6 +45,10 @@ public class AddressFactory {
private static int highestBadBankReceiveIdx = 0;
private static int highestBadBankChangeIdx = 0;
private static int localBIP44ReceiveIdx = 0;
private static int localBIP49ReceiveIdx = 0;
private static int localBIP84ReceiveIdx = 0;
private static HashMap<String,Integer> xpub2account = null;
private static HashMap<Integer,String> account2xpub = null;
......@@ -89,10 +93,13 @@ public class AddressFactory {
if(hdw != null) {
idx = HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddrIdx();
if(localBIP44ReceiveIdx > idx) {
idx = localBIP44ReceiveIdx;
}
addr = HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddressAt(idx);
if(canIncReceiveAddress(SamouraiWallet.SAMOURAI_ACCOUNT)) {
HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).incAddrIdx();
// PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).setAddrIdx(idx + 1);
localBIP44ReceiveIdx = idx + 1;
}
}
......@@ -106,19 +113,20 @@ public class AddressFactory {
HD_Address addr = null;
SegwitAddress p2shp2wpkh = null;
// try {
HD_Wallet hdw = BIP49Util.getInstance(context).getWallet();
if(hdw != null) {
idx = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddrIdx();
addr = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddressAt(idx);
p2shp2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
if(canIncBIP49ReceiveAddress(idx)) {
BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).incAddrIdx();
// PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
}
HD_Wallet hdw = BIP49Util.getInstance(context).getWallet();
if(hdw != null) {
idx = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddrIdx();
if(localBIP49ReceiveIdx > idx) {
idx = localBIP49ReceiveIdx;
}
addr = BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddressAt(idx);
p2shp2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
if(canIncBIP49ReceiveAddress(idx)) {
BIP49Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).setAddrIdx(idx + 1);
localBIP49ReceiveIdx = idx + 1;
}
// }
}
return Pair.of(idx, p2shp2wpkh);
......@@ -130,16 +138,18 @@ public class AddressFactory {
HD_Address addr = null;
SegwitAddress p2wpkh = null;
// try {
HD_Wallet hdw = BIP84Util.getInstance(context).getWallet();
if(hdw != null) {
idx = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddrIdx();
if(localBIP84ReceiveIdx > idx) {
idx = localBIP84ReceiveIdx;
}
addr = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).getAddressAt(idx);
p2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
if(canIncBIP84ReceiveAddress(idx)) {
BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).incAddrIdx();
// PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(0).setAddrIdx(idx + 1);
localBIP84ReceiveIdx = idx + 1;
}
}
......@@ -182,6 +192,30 @@ public class AddressFactory {
highestTxChangeIdx.put(account, idx);
}
public int getLocalBIP44ReceiveIdx() {
return localBIP44ReceiveIdx;
}
public void setLocalBIP44ReceiveIdx(int idx) {
localBIP44ReceiveIdx = idx;
}
public int getLocalBIP49ReceiveIdx() {
return localBIP49ReceiveIdx;
}
public void setLocalBIP49ReceiveIdx(int idx) {
localBIP49ReceiveIdx = idx;
}
public int getLocalBIP84ReceiveIdx() {
return localBIP84ReceiveIdx;
}
public void setLocalBIP84ReceiveIdx(int idx) {
localBIP84ReceiveIdx = idx;
}
public int getHighestBIP49ReceiveIdx() {
return highestBIP49ReceiveIdx;
}
......
package com.samourai.wallet.util;
import android.content.Context;
import org.json.JSONException;
import org.json.JSONObject;
public class LocalReceiveIndexes {
private static LocalReceiveIndexes instance = null;
private static Context context = null;
private LocalReceiveIndexes() { ; }
public static LocalReceiveIndexes getInstance(Context ctx) {
context = ctx;
if(instance == null) {
instance = new LocalReceiveIndexes();
}
return instance;
}
public JSONObject toJSON() {
JSONObject indexes = new JSONObject();
try {
indexes.put("local44idx", AddressFactory.getInstance(context).getLocalBIP44ReceiveIdx());
indexes.put("local49idx", AddressFactory.getInstance(context).getLocalBIP49ReceiveIdx());
indexes.put("local84idx", AddressFactory.getInstance(context).getLocalBIP84ReceiveIdx());
}
catch(JSONException ex) {
throw new RuntimeException(ex);
}
return indexes;
}
public void fromJSON(JSONObject obj) {
try {
if(obj.has("local44idx")) {
AddressFactory.getInstance(context).setLocalBIP44ReceiveIdx(obj.getInt("local44idx"));
}
if(obj.has("local49idx")) {
AddressFactory.getInstance(context).setLocalBIP49ReceiveIdx(obj.getInt("local49idx"));
}
if(obj.has("local84idx")) {
AddressFactory.getInstance(context).setLocalBIP84ReceiveIdx(obj.getInt("local84idx"));
}
}
catch(JSONException ex) {
throw new RuntimeException(ex);
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment