Commit 46663e04 authored by zeroleak's avatar zeroleak
Browse files

fix freeze on mix error + fix mixing bip47 + use extlibj 0.0.26-3 + whirlpool-client 0.23.37.2

parent 3875859d
......@@ -134,7 +134,7 @@ dependencies {
implementation 'org.hibernate:hibernate-validator:5.4.3.Final'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.github.yuriy-budiyev:code-scanner:2.1.0'
implementation ('io.samourai.code.whirlpool:whirlpool-client:0.23.37.1') {
implementation ('io.samourai.code.whirlpool:whirlpool-client:0.23.37.2') {
exclude group:'org.hibernate', module:'hibernate-validator'
exclude group:'com.google.code.findbugs', module:'jsr305'
exclude group:'com.google.protobuf', module:'protobuf-java'
......@@ -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-2') {
implementation ('io.samourai.code.wallet:extlibj:0.0.26-3') {
exclude group:'com.google.code.findbugs', module:'jsr305'
exclude group:'com.google.protobuf', module:'protobuf-java'
exclude group:'net.jcip', module:'jcip-annotations'
......
......@@ -3,6 +3,7 @@ package com.samourai.wallet.util;
import android.util.Log;
import com.samourai.wallet.BuildConfig;
import com.samourai.whirlpool.client.utils.ClientUtils;
import org.slf4j.LoggerFactory;
......@@ -59,6 +60,10 @@ public class LogUtil {
// skip noisy logs
((Logger) LoggerFactory.getLogger("com.samourai.wallet.staging")).setLevel(Level.DEBUG);
// set whirlpool log level
Level level = BuildConfig.DEBUG ? Level.DEBUG : Level.WARN;
ClientUtils.setLogLevel(level, level);
Log.d("LogUtil", "Debug logs enabled");
}
......
......@@ -207,7 +207,7 @@ class WhirlPoolHomeViewModel : ViewModel() {
intent.putExtra("launch", false)
JobRefreshService.enqueueWork(context, intent)
}
wallet.refreshUtxos()
wallet.refreshUtxosAsync().blockingAwait()
refresh()
}catch (e:Exception){
throw CancellationException()
......
......@@ -273,10 +273,7 @@ public class NewPoolActivity extends SamouraiActivity {
confirmButton.setEnabled(false);
Disposable tx0Disposable = beginTx0(selectedCoins)
.delay(500, TimeUnit.MILLISECONDS)
.andThen(Completable.fromCallable(() -> {
AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet().get().refreshUtxos();
return false;
}))
.andThen(AndroidWhirlpoolWalletService.getInstance().getWhirlpoolWallet().get().refreshUtxosAsync())
.delay(100,TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
......
......@@ -10,9 +10,10 @@ import com.samourai.http.client.IHttpClientService;
import com.samourai.stomp.client.AndroidStompClientService;
import com.samourai.stomp.client.IStompClientService;
import com.samourai.tor.client.TorClientService;
import com.samourai.wallet.BuildConfig;
import com.samourai.wallet.SamouraiWallet;
import com.samourai.wallet.api.APIFactory;
import com.samourai.wallet.bip47.BIP47Meta;
import com.samourai.wallet.bip47.BIP47Util;
import com.samourai.wallet.bip47.rpc.AndroidSecretPointFactory;
import com.samourai.wallet.hd.HD_Wallet;
import com.samourai.wallet.network.dojo.DojoUtil;
......@@ -24,7 +25,6 @@ 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.utils.ClientUtils;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolServer;
import com.samourai.whirlpool.client.wallet.data.AndroidDataSourceFactory;
import com.samourai.whirlpool.client.wallet.data.AndroidWalletStateSupplier;
......@@ -41,7 +41,6 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.Map;
import ch.qos.logback.classic.Level;
import io.reactivex.Completable;
import io.reactivex.subjects.BehaviorSubject;
import java8.util.Optional;
......@@ -75,10 +74,6 @@ public class AndroidWhirlpoolWalletService extends WhirlpoolWalletService {
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
source.onNext(ConnectionStates.LOADING);
// set whirlpool log level
Level level = BuildConfig.DEBUG ? Level.DEBUG : Level.WARN;
ClientUtils.setLogLevel(level, level);
}
private WhirlpoolWallet getOrOpenWhirlpoolWallet(Context ctx) throws Exception {
......@@ -118,7 +113,9 @@ public class AndroidWhirlpoolWalletService extends WhirlpoolWalletService {
FeeUtil feeUtil = FeeUtil.getInstance();
APIFactory apiFactory = APIFactory.getInstance(ctx);
UTXOFactory utxoFactory = UTXOFactory.getInstance(ctx);
return new AndroidDataSourceFactory(pushTx, feeUtil, apiFactory, utxoFactory);
BIP47Util bip47Util = BIP47Util.getInstance(ctx);
BIP47Meta bip47Meta = BIP47Meta.getInstance();
return new AndroidDataSourceFactory(pushTx, feeUtil, apiFactory, utxoFactory, bip47Util, bip47Meta);
}
private DataPersisterFactory computeDataPersisterFactory(Context ctx) {
......@@ -179,7 +176,7 @@ public class AndroidWhirlpoolWalletService extends WhirlpoolWalletService {
source.onNext(ConnectionStates.STARTING);
return Completable.fromCallable(() -> {
try {
this.getOrOpenWhirlpoolWallet(ctx).start();
this.getOrOpenWhirlpoolWallet(ctx).startAsync().blockingAwait();
if (source.hasObservers()) {
source.onNext(ConnectionStates.CONNECTED);
}
......
package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.api.APIFactory;
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.AddressFactory;
import com.samourai.whirlpool.client.tx0.Tx0ParamService;
import com.samourai.whirlpool.client.wallet.WhirlpoolWallet;
import com.samourai.whirlpool.client.wallet.WhirlpoolWalletConfig;
......@@ -30,7 +31,7 @@ public class AndroidDataSource implements DataSource {
private ExpirablePoolSupplier poolSupplier;
private UtxoSupplier utxoSupplier;
public AndroidDataSource(WhirlpoolWallet whirlpoolWallet, HD_Wallet bip44w, DataPersister dataPersister, PushTx pushTx, FeeUtil feeUtil, APIFactory apiFactory, UTXOFactory utxoFactory) throws Exception {
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);
......@@ -39,7 +40,7 @@ public class AndroidDataSource implements DataSource {
WhirlpoolWalletConfig config = whirlpoolWallet.getConfig();
this.tx0ParamService = new Tx0ParamService(minerFeeSupplier, config);
this.poolSupplier = new ExpirablePoolSupplier(config.getRefreshPoolsDelay(), config.getServerApi(), tx0ParamService);
this.utxoSupplier = new AndroidUtxoSupplier(walletSupplier, dataPersister.getUtxoConfigSupplier(), chainSupplier, poolSupplier, tx0ParamService, config.getNetworkParameters(), utxoFactory);
this.utxoSupplier = new AndroidUtxoSupplier(walletSupplier, dataPersister.getUtxoConfigSupplier(), chainSupplier, poolSupplier, tx0ParamService, config.getNetworkParameters(), utxoFactory, bip47Util, bip47Meta);
}
@Override
......
package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.api.APIFactory;
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;
......@@ -15,16 +17,20 @@ public class AndroidDataSourceFactory implements DataSourceFactory {
private FeeUtil feeUtil;
private APIFactory apiFactory;
private UTXOFactory utxoFactory;
private BIP47Util bip47Util;
private BIP47Meta bip47Meta;
public AndroidDataSourceFactory(PushTx pushTx, FeeUtil feeUtil, APIFactory apiFactory, UTXOFactory utxoFactory) {
public AndroidDataSourceFactory(PushTx pushTx, FeeUtil feeUtil, APIFactory apiFactory, UTXOFactory utxoFactory, BIP47Util bip47Util, BIP47Meta bip47Meta) {
this.pushTx = pushTx;
this.feeUtil = feeUtil;
this.apiFactory = apiFactory;
this.utxoFactory = utxoFactory;
this.bip47Util = bip47Util;
this.bip47Meta = bip47Meta;
}
@Override
public DataSource createDataSource(WhirlpoolWallet whirlpoolWallet, HD_Wallet bip44w, DataPersister dataPersister) throws Exception {
return new AndroidDataSource(whirlpoolWallet, bip44w, dataPersister, pushTx, feeUtil, apiFactory, utxoFactory);
return new AndroidDataSource(whirlpoolWallet, bip44w, dataPersister, pushTx, feeUtil, apiFactory, utxoFactory, bip47Util, bip47Meta);
}
}
......@@ -2,12 +2,17 @@ package com.samourai.whirlpool.client.wallet.data;
import com.samourai.wallet.api.backend.beans.UnspentOutput;
import com.samourai.wallet.api.backend.beans.WalletResponse;
import com.samourai.wallet.bip47.BIP47Meta;
import com.samourai.wallet.bip47.BIP47Util;
import com.samourai.wallet.bip47.rpc.PaymentAddress;
import com.samourai.wallet.bip47.rpc.PaymentCode;
import com.samourai.wallet.client.BipWallet;
import com.samourai.wallet.hd.AddressType;
import com.samourai.wallet.send.UTXO;
import com.samourai.wallet.send.UTXOFactory;
import com.samourai.whirlpool.client.tx0.Tx0ParamService;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolAccount;
import com.samourai.whirlpool.client.wallet.beans.WhirlpoolUtxo;
import com.samourai.whirlpool.client.wallet.data.chain.ChainSupplier;
import com.samourai.whirlpool.client.wallet.data.pool.PoolSupplier;
import com.samourai.whirlpool.client.wallet.data.utxo.BasicUtxoSupplier;
......@@ -15,6 +20,7 @@ import com.samourai.whirlpool.client.wallet.data.utxo.UtxoData;
import com.samourai.whirlpool.client.wallet.data.utxoConfig.UtxoConfigSupplier;
import com.samourai.whirlpool.client.wallet.data.wallet.WalletSupplier;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.NetworkParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -27,6 +33,8 @@ public class AndroidUtxoSupplier extends BasicUtxoSupplier {
private Logger log = LoggerFactory.getLogger(AndroidUtxoSupplier.class);
private UTXOFactory utxoFactory;
private BIP47Util bip47Util;
private BIP47Meta bip47Meta;
private long lastUpdate;
public AndroidUtxoSupplier(WalletSupplier walletSupplier,
......@@ -35,9 +43,13 @@ public class AndroidUtxoSupplier extends BasicUtxoSupplier {
PoolSupplier poolSupplier,
Tx0ParamService tx0ParamService,
NetworkParameters params,
UTXOFactory utxoFactory) throws Exception {
UTXOFactory utxoFactory,
BIP47Util bip47Util,
BIP47Meta bip47Meta) throws Exception {
super(walletSupplier, utxoConfigSupplier, chainSupplier, poolSupplier, tx0ParamService, params);
this.utxoFactory = utxoFactory;
this.bip47Util = bip47Util;
this.bip47Meta = bip47Meta;
this.lastUpdate = -1;
}
......@@ -98,4 +110,16 @@ public class AndroidUtxoSupplier extends BasicUtxoSupplier {
}
return unspentOutputs;
}
@Override
public ECKey _getPrivKeyBip47(WhirlpoolUtxo whirlpoolUtxo) throws Exception {
String address = whirlpoolUtxo.getUtxo().addr;
String pcode = bip47Meta.getPCode4Addr(address);
int idx = bip47Meta.getIdx4Addr(address);
if (log.isDebugEnabled()) {
log.debug("_getPrivKeyBip47: pcode="+pcode+", idx="+idx);
}
PaymentAddress addr = bip47Util.getReceiveAddress(new PaymentCode(pcode), idx);
return addr.getReceiveECKey();
}
}
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