Commit 689418a0 authored by zeroleak's avatar zeroleak
Browse files

use extlibj 0.0.26-4 + fix tests

parent 439c341b
......@@ -145,7 +145,7 @@ dependencies {
exclude group:'org.json', module:'json'
exclude group:'io.samourai.code.wallet', module:'extlibj'
}
implementation ('io.samourai.code.wallet:extlibj:0.0.26-3') {
implementation ('io.samourai.code.wallet:extlibj:0.0.26-4') {
exclude group:'com.google.code.findbugs', module:'jsr305'
exclude group:'com.google.protobuf', module:'protobuf-java'
exclude group:'net.jcip', module:'jcip-annotations'
......
......@@ -2,6 +2,7 @@ package com.samourai.http.client;
import android.content.Context;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.util.WebUtil;
......@@ -29,13 +30,13 @@ public class AndroidHttpClient extends JacksonHttpClient {
}
private WebUtil webUtil;
private TorManager torManager;
private ITorManager torManager;
private AndroidHttpClient(Context ctx) {
this(WebUtil.getInstance(ctx), TorManager.INSTANCE);
}
public AndroidHttpClient(WebUtil webUtil, TorManager torManager) {
public AndroidHttpClient(WebUtil webUtil, ITorManager torManager) {
this.webUtil = webUtil;
this.torManager = torManager;
}
......
......@@ -17,7 +17,7 @@ public class AndroidHttpClientService implements IHttpClientService {
private Context ctx;
private AndroidHttpClientService(Context ctx) {
protected AndroidHttpClientService(Context ctx) {
this.ctx = ctx;
}
......
package com.samourai.stomp.client;
import com.google.gson.Gson;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.wallet.util.MessageErrorListener;
import com.samourai.whirlpool.protocol.WhirlpoolProtocol;
......@@ -28,10 +28,10 @@ import ua.naiksoftware.stomp.dto.StompMessage;
public class AndroidStompClient implements IStompClient {
private Logger log = LoggerFactory.getLogger(AndroidStompClient.class);
private Gson gson;
private TorManager torManager;
private ITorManager torManager;
private StompClient stompClient;
public AndroidStompClient(TorManager torManager) {
public AndroidStompClient(ITorManager torManager) {
this.gson = new Gson();
this.torManager = torManager;
}
......
package com.samourai.stomp.client;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.tor.ITorManager;
public class AndroidStompClientService implements IStompClientService {
private TorManager torManager;
private ITorManager torManager;
public AndroidStompClientService(TorManager torManager) {
public AndroidStompClientService(ITorManager torManager) {
this.torManager = torManager;
}
......
package com.samourai.stomp.client;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.util.Log;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.tor.ITorManager;
import org.java_websocket.WebSocket;
import org.java_websocket.client.WebSocketClient;
......@@ -23,6 +21,8 @@ import java.util.TreeMap;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocketFactory;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import ua.naiksoftware.stomp.dto.LifecycleEvent;
import ua.naiksoftware.stomp.provider.AbstractConnectionProvider;
......@@ -39,14 +39,14 @@ public class AndroidWebSocketsConnectionProvider extends AbstractConnectionProvi
private boolean haveConnection;
private TreeMap<String, String> mServerHandshakeHeaders;
private TorManager torManager;
private ITorManager torManager;
/**
* Support UIR scheme ws://host:port/path
*
* @param connectHttpHeaders may be null
*/
public AndroidWebSocketsConnectionProvider(String uri, @Nullable Map<String, String> connectHttpHeaders, TorManager torManager) {
public AndroidWebSocketsConnectionProvider(String uri, @Nullable Map<String, String> connectHttpHeaders, ITorManager torManager) {
mUri = uri;
mConnectHttpHeaders = connectHttpHeaders != null ? connectHttpHeaders : new HashMap<>();
this.torManager = torManager;
......
package com.samourai.wallet.send;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
import com.samourai.wallet.R;
import com.samourai.wallet.SamouraiWallet;
import com.samourai.wallet.api.APIFactory;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.util.LogUtil;
import com.samourai.wallet.util.PrefsUtil;
import com.samourai.wallet.util.WebUtil;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
......@@ -76,6 +71,7 @@ public class PushTx {
return response;
}
catch(Exception e) {
e.printStackTrace();
return null;
}
......
package com.samourai.wallet.tor;
import java.net.Proxy;
public interface ITorManager {
Boolean isRequired();
Proxy getProxy();
}
......@@ -3,15 +3,11 @@ package com.samourai.wallet.tor
import android.app.Application
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.os.Process
import android.widget.Toast
import androidx.core.app.NotificationCompat
import androidx.core.app.TaskStackBuilder
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.samourai.wallet.BuildConfig
import com.samourai.wallet.MainActivity2
import com.samourai.wallet.R
import com.samourai.wallet.SamouraiApplication
import com.samourai.wallet.util.PrefsUtil
......@@ -31,7 +27,7 @@ import java.net.Proxy
*
*/
object TorManager {
object TorManager : ITorManager {
lateinit var stopTorDelaySettingAtAppStartup: String
private set
......@@ -128,7 +124,7 @@ object TorManager {
.setEventBroadcaster(eventBroadcaster = TorEventBroadcaster())
}
fun isRequired(): Boolean {
override fun isRequired(): Boolean {
return PrefsUtil.getInstance(appContext).getValue(PrefsUtil.ENABLE_TOR, false);
}
......@@ -144,7 +140,7 @@ object TorManager {
return torProgress
}
fun getProxy(): Proxy? {
override fun getProxy(): Proxy? {
return proxy;
}
......
package com.samourai.whirlpool.client.wallet;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.tor.client.TorClientService;
import com.samourai.wallet.tor.TorManager;
import io.matthewnelson.topl_service.TorServiceController;
public class AndroidWhirlpoolTorService extends TorClientService {
private TorManager torManager;
private ITorManager torManager;
public AndroidWhirlpoolTorService(TorManager torManager) {
public AndroidWhirlpoolTorService(ITorManager torManager) {
super();
this.torManager = torManager;
}
......
......@@ -21,24 +21,20 @@ import com.samourai.wallet.segwit.BIP84Util;
import com.samourai.wallet.send.FeeUtil;
import com.samourai.wallet.send.PushTx;
import com.samourai.wallet.send.UTXOFactory;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.wallet.tor.TorManager;
import com.samourai.wallet.util.AddressFactory;
import com.samourai.wallet.whirlpool.WhirlpoolMeta;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolServer;
import com.samourai.whirlpool.client.wallet.data.AndroidDataSourceFactory;
import com.samourai.whirlpool.client.wallet.data.AndroidWalletStateSupplier;
import com.samourai.whirlpool.client.wallet.data.dataPersister.AndroidFileDataPersisterFactory;
import com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersisterFactory;
import com.samourai.whirlpool.client.wallet.data.dataPersister.FileDataPersisterFactory;
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSourceFactory;
import com.samourai.whirlpool.client.wallet.data.walletState.WalletStateSupplier;
import com.samourai.whirlpool.client.whirlpool.ServerApi;
import org.bitcoinj.core.NetworkParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.Map;
import io.reactivex.Completable;
......@@ -108,7 +104,7 @@ public class AndroidWhirlpoolWalletService extends WhirlpoolWalletService {
return computeWhirlpoolWalletConfig(torManager, testnet, onion, scode, httpClientService, ctx);
}
private DataSourceFactory computeDataSourceFactory(Context ctx) {
protected DataSourceFactory computeDataSourceFactory(Context ctx) {
PushTx pushTx = PushTx.getInstance(ctx);
FeeUtil feeUtil = FeeUtil.getInstance();
APIFactory apiFactory = APIFactory.getInstance(ctx);
......@@ -118,27 +114,11 @@ public class AndroidWhirlpoolWalletService extends WhirlpoolWalletService {
return new AndroidDataSourceFactory(pushTx, feeUtil, apiFactory, utxoFactory, bip47Util, bip47Meta);
}
private DataPersisterFactory computeDataPersisterFactory(Context ctx) {
return new FileDataPersisterFactory() {
@Override
protected File computeFileIndex(String walletIdentifier) throws NotifiableException {
return whirlpoolUtils.computeIndexFile(walletIdentifier, ctx);
}
@Override
protected File computeFileUtxos(String walletIdentifier) throws NotifiableException {
return whirlpoolUtils.computeUtxosFile(walletIdentifier, ctx);
}
@Override
protected WalletStateSupplier computeWalletStateSupplier(WhirlpoolWallet whirlpoolWallet) {
AddressFactory addressFactory = AddressFactory.getInstance(ctx);
return new AndroidWalletStateSupplier(addressFactory);
}
};
protected DataPersisterFactory computeDataPersisterFactory(Context ctx) {
return new AndroidFileDataPersisterFactory(whirlpoolUtils, ctx);
}
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(TorManager torManager, boolean testnet, boolean onion, String scode, IHttpClientService httpClientService, Context ctx) {
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(ITorManager torManager, boolean testnet, boolean onion, String scode, IHttpClientService httpClientService, Context ctx) {
IStompClientService stompClientService = new AndroidStompClientService(torManager);
TorClientService torClientService = new AndroidWhirlpoolTorService(torManager);
......
package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.api.APIFactory;
import com.samourai.wallet.api.backend.BackendApi;
import com.samourai.wallet.api.backend.beans.PushTxResponse;
import com.samourai.wallet.bip47.BIP47Meta;
import com.samourai.wallet.bip47.BIP47Util;
import com.samourai.wallet.hd.HD_Wallet;
import com.samourai.wallet.send.FeeUtil;
import com.samourai.wallet.send.PushTx;
import com.samourai.wallet.send.UTXOFactory;
import com.samourai.wallet.util.JSONUtils;
import com.samourai.whirlpool.client.tx0.Tx0ParamService;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.WhirlpoolWalletConfig;
import com.samourai.whirlpool.client.wallet.data.chain.ChainSupplier;
import com.samourai.whirlpool.client.wallet.data.dataPersister.DataPersister;
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSource;
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSourceWithStrictMode;
import com.samourai.whirlpool.client.wallet.data.minerFee.MinerFeeSupplier;
import com.samourai.whirlpool.client.wallet.data.pool.ExpirablePoolSupplier;
import com.samourai.whirlpool.client.wallet.data.pool.PoolSupplier;
......@@ -21,21 +25,23 @@ import com.samourai.whirlpool.client.wallet.data.wallet.WalletSupplier;
import com.samourai.whirlpool.client.wallet.data.wallet.WalletSupplierImpl;
import com.samourai.whirlpool.client.wallet.data.walletState.WalletStateSupplier;
public class AndroidDataSource implements DataSource {
import java.util.List;
public class AndroidDataSource implements DataSource, DataSourceWithStrictMode {
private PushTx pushTx;
private WalletSupplier walletSupplier;
private MinerFeeSupplier minerFeeSupplier;
private ChainSupplier chainSupplier;
private Tx0ParamService tx0ParamService;
private ExpirablePoolSupplier poolSupplier;
private UtxoSupplier utxoSupplier;
protected WalletSupplier walletSupplier;
protected MinerFeeSupplier minerFeeSupplier;
protected ChainSupplier chainSupplier;
protected Tx0ParamService tx0ParamService;
protected ExpirablePoolSupplier poolSupplier;
protected UtxoSupplier utxoSupplier;
public AndroidDataSource(WhirlpoolWallet whirlpoolWallet, HD_Wallet bip44w, DataPersister dataPersister, PushTx pushTx, FeeUtil feeUtil, APIFactory apiFactory, UTXOFactory utxoFactory, BIP47Util bip47Util, BIP47Meta bip47Meta) throws Exception {
this.pushTx = pushTx;
WalletStateSupplier walletStateSupplier = dataPersister.getWalletStateSupplier();
this.walletSupplier = new WalletSupplierImpl(bip44w, walletStateSupplier);
this.minerFeeSupplier = new AndroidMinerFeeSupplier(feeUtil);
this.minerFeeSupplier = computeMinerFeeSupplier(feeUtil);
this.chainSupplier = new AndroidChainSupplier(apiFactory);
WhirlpoolWalletConfig config = whirlpoolWallet.getConfig();
this.tx0ParamService = new Tx0ParamService(minerFeeSupplier, config);
......@@ -43,6 +49,10 @@ public class AndroidDataSource implements DataSource {
this.utxoSupplier = new AndroidUtxoSupplier(walletSupplier, dataPersister.getUtxoConfigSupplier(), chainSupplier, poolSupplier, tx0ParamService, config.getNetworkParameters(), utxoFactory, bip47Util, bip47Meta);
}
protected MinerFeeSupplier computeMinerFeeSupplier(FeeUtil feeUtil) {
return new AndroidMinerFeeSupplier(feeUtil);
}
@Override
public void open() throws Exception {
// load pools (or fail)
......@@ -58,6 +68,15 @@ public class AndroidDataSource implements DataSource {
pushTx.pushTx(txHex);
}
@Override
public void pushTx(String txHex, List<Integer> strictModeVouts) throws Exception {
String response = pushTx.samourai(txHex, strictModeVouts);
// check strict-mode response
PushTxResponse pushTxResponse = JSONUtils.getInstance().getObjectMapper().readValue(response, PushTxResponse.class);
BackendApi.checkPushTxResponse(pushTxResponse);
}
@Override
public WalletSupplier getWalletSupplier() {
return walletSupplier;
......
......@@ -13,12 +13,12 @@ import com.samourai.whirlpool.client.wallet.data.dataSource.DataSource;
import com.samourai.whirlpool.client.wallet.data.dataSource.DataSourceFactory;
public class AndroidDataSourceFactory implements DataSourceFactory {
private PushTx pushTx;
private FeeUtil feeUtil;
private APIFactory apiFactory;
private UTXOFactory utxoFactory;
private BIP47Util bip47Util;
private BIP47Meta bip47Meta;
protected PushTx pushTx;
protected FeeUtil feeUtil;
protected APIFactory apiFactory;
protected UTXOFactory utxoFactory;
protected BIP47Util bip47Util;
protected BIP47Meta bip47Meta;
public AndroidDataSourceFactory(PushTx pushTx, FeeUtil feeUtil, APIFactory apiFactory, UTXOFactory utxoFactory, BIP47Util bip47Util, BIP47Meta bip47Meta) {
this.pushTx = pushTx;
......
package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.client.indexHandler.AbstractIndexHandler;
import com.samourai.wallet.hd.WALLET_INDEX;
import com.samourai.wallet.util.AddressFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class AndroidWalletStateIndexHandler extends AbstractIndexHandler {
private static final Logger log = LoggerFactory.getLogger(AndroidWalletStateIndexHandler.class);
private AddressFactory addressFactory;
private WALLET_INDEX walletIndex;
public AndroidWalletStateIndexHandler(AddressFactory addressFactory, WALLET_INDEX walletIndex) {
super();
this.addressFactory = addressFactory;
this.walletIndex = walletIndex;
}
@Override
public int get() {
int idx = addressFactory.getAddress(walletIndex).getLeft();
return idx;
}
@Override
public synchronized int getAndIncrement() {
int idx = addressFactory.getAddressAndIncrement(walletIndex).getLeft();
return idx;
}
@Override
public synchronized void set(int value) {
addressFactory.setWalletIdx(walletIndex, value, true);
}
}
\ No newline at end of file
package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.client.indexHandler.AddressFactoryWalletStateIndexHandler;
import com.samourai.wallet.client.indexHandler.IIndexHandler;
import com.samourai.wallet.hd.AddressType;
import com.samourai.wallet.hd.Chain;
......@@ -26,7 +27,7 @@ public class AndroidWalletStateSupplier implements WalletStateSupplier {
IIndexHandler indexHandlerWallet = indexHandlerWallets.get(persistKey);
if (indexHandlerWallet == null) {
WALLET_INDEX walletIndex = WALLET_INDEX.find(account, addressType, chain);
indexHandlerWallet = new AndroidWalletStateIndexHandler(addressFactory, walletIndex);
indexHandlerWallet = new AddressFactoryWalletStateIndexHandler(addressFactory, walletIndex);
indexHandlerWallets.put(persistKey, indexHandlerWallet);
}
return indexHandlerWallet;
......
package com.samourai.whirlpool.client.wallet.data.dataPersister;
import android.content.Context;
import com.samourai.wallet.util.AddressFactory;
import com.samourai.whirlpool.client.exception.NotifiableException;
import com.samourai.whirlpool.client.wallet.WhirlpoolUtils;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.data.AndroidWalletStateSupplier;
import com.samourai.whirlpool.client.wallet.data.walletState.WalletStateSupplier;
import java.io.File;
public class AndroidFileDataPersisterFactory extends FileDataPersisterFactory {
private WhirlpoolUtils whirlpoolUtils;
private Context ctx;
public AndroidFileDataPersisterFactory(WhirlpoolUtils whirlpoolUtils, Context ctx) {
this.whirlpoolUtils = whirlpoolUtils;
this.ctx = ctx;
}
@Override
protected File computeFileIndex(String walletIdentifier) throws NotifiableException {
return whirlpoolUtils.computeIndexFile(walletIdentifier, ctx);
}
@Override
protected File computeFileUtxos(String walletIdentifier) throws NotifiableException {
return whirlpoolUtils.computeUtxosFile(walletIdentifier, ctx);
}
@Override
protected WalletStateSupplier computeWalletStateSupplier(WhirlpoolWallet whirlpoolWallet) {
AddressFactory addressFactory = AddressFactory.getInstance(ctx);
return new AndroidWalletStateSupplier(addressFactory);
}
}
package com.samourai.http.client;
import android.content.Context;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.wallet.tor.MockTorManager;
import com.samourai.wallet.util.WebUtil;
public class MockAndroidHttpClientService extends AndroidHttpClientService{
private AndroidHttpClient httpClient;
public MockAndroidHttpClientService(Context context) {
super(context);
WebUtil webUtil = WebUtil.getInstance(context);
ITorManager torManager = new MockTorManager();
httpClient = new AndroidHttpClient(webUtil, torManager);
}
@Override
public AndroidHttpClient getHttpClient(HttpUsage httpUsage) {
return httpClient;
}
}
package com.samourai.wallet.tor;
import java.net.Proxy;
public class MockTorManager implements ITorManager {
public MockTorManager() {
}
@Override
public Boolean isRequired() {
return false;
}
@Override
public Proxy getProxy() {
return null;
}
}
......@@ -2,41 +2,45 @@ package com.samourai.whirlpool.client.wallet;
import android.content.Context;
import com.samourai.http.client.IHttpClientService;
import com.samourai.http.client.MockAndroidHttpClientService;
import com.samourai.stomp.client.AndroidStompClient;
import com.samourai.wallet.SamouraiWallet;
import com.samourai.wallet.api.backend.beans.UnspentOutput;
import com.samourai.wallet.bip47.BIP47Util;
import com.samourai.wallet.hd.HD_Wallet;
import com.samourai.wallet.hd.HD_WalletFactory;
import com.samourai.wallet.hd.HD_WalletFactoryGeneric;
import com.samourai.wallet.send.SendFactoryGeneric;
import com.samourai.wallet.tor.ITorManager;
import com.samourai.wallet.tor.MockTorManager;
import com.samourai.whirlpool.client.utils.ClientUtils;
import com.samourai.whirlpool.client.wallet.data.MockAndroidUtxoSupplier;
import org.bitcoinj.core.DumpedPrivateKey;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.crypto.MnemonicCode;
import org.bouncycastle.util.encoders.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.InputStream;
import java.util.concurrent.Callable;
import ch.qos.logback.classic.Level;
import io.reactivex.Scheduler;
import io.reactivex.android.plugins.RxAndroidPlugins;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
public abstract class AbstractWhirlpoolTest {
private Logger log = LoggerFactory.getLogger(AndroidStompClient.class);
private static final String SEED_WORDS = "wise never behave tornado tool pear aunt consider season swap custom human";
private static final String SEED_PASSPHRASE = "test";
protected Context context = null; //new MockContext(); // TODO sdk>=29 required
protected BIP47Util bip47Util = BIP47Util.getInstance(context);
protected HD_WalletFactory hdWalletFactory = HD_WalletFactory.getInstance(context);
protected HD_WalletFactoryGeneric hdWalletFactoryGeneric;
protected NetworkParameters networkParameters;
protected AndroidWhirlpoolWalletService whirlpoolWalletService = new AndroidWhirlpoolWalletService();
protected WhirlpoolUtils whirlpoolUtils = WhirlpoolUtils.getInstance();
protected AndroidWhirlpoolWalletService whirlpoolWalletService;