use of com.samourai.http.client.IHttpClient in project samourai-wallet-android by Samourai-Wallet.
the class WhirlpoolWalletTest method setUp.
@Before
public void setUp() throws Exception {
super.setUp(TestNet3Params.get());
// configure wallet
boolean testnet = true;
boolean onion = false;
int mixsTarget = 5;
String scode = null;
// backendApi with mocked pushTx
TorManager torManager = TorManager.getInstance(getContext());
IHttpClient httpClient = new AndroidHttpClient(WebUtil.getInstance(getContext()), torManager);
BackendApi backendApi = new BackendApi(httpClient, BackendServer.TESTNET.getBackendUrl(onion), Optional.empty()) {
@Override
public void pushTx(String txHex) throws Exception {
log.info("pushTX ignored for test: " + txHex);
}
};
File fileIndex = File.createTempFile("test-state", "test");
File fileUtxo = File.createTempFile("test-utxos", "test");
WhirlpoolWalletPersistHandler persistHandler = new FileWhirlpoolWalletPersistHandler(fileIndex, fileUtxo);
// instanciate WhirlpoolWallet
bip84w = computeBip84w(SEED_WORDS, SEED_PASSPHRASE);
config = whirlpoolWalletService.computeWhirlpoolWalletConfig(torManager, persistHandler, testnet, onion, mixsTarget, scode, httpClient, backendApi);
config.setTx0Service(new AndroidTx0Service(config) {
@Override
protected Tx0Data fetchTx0Data(String poolId) throws HttpException, NotifiableException {
Tx0Data tx0Data = super.fetchTx0Data(poolId);
// mock fee address for deterministic tests
return new Tx0Data(tx0Data.getFeePaymentCode(), tx0Data.getFeeValue(), tx0Data.getFeeChange(), 0, tx0Data.getFeePayload(), "tb1qgyppvv58rv83eas60trmdgqc06yx9q53qs6skx", 123);
}
});
APIFactory apiFactory = APIFactory.getInstance(context);
WhirlpoolDataService dataService = whirlpoolWalletService.newDataService(config, apiFactory);
whirlpoolWallet = whirlpoolWalletService.openWallet(config, dataService, bip84w);
}
use of com.samourai.http.client.IHttpClient in project samourai-wallet-android by Samourai-Wallet.
the class AndroidWhirlpoolWalletService method computeWhirlpoolWalletConfig.
protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(Context ctx, String walletIdentifier) throws Exception {
WebUtil webUtil = WebUtil.getInstance(ctx);
TorManager torManager = TorManager.getInstance(ctx);
String dojoParams = DojoUtil.getInstance(ctx).getDojoParams();
boolean useDojo = (dojoParams != null);
boolean testnet = SamouraiWallet.getInstance().isTestNet();
boolean onion = useDojo || torManager.isRequired();
Log.v(TAG, "whirlpoolWalletConfig[Tor] = onion=" + onion + ", useDojo=" + useDojo + ", torManager.isRequired=" + torManager.isRequired());
String scode = WhirlpoolMeta.getInstance(ctx).getSCODE();
// backend configuration
String backendUrl;
Optional<OAuthManager> oAuthManager;
if (useDojo) {
// dojo backend
backendUrl = DojoUtil.getInstance(ctx).getUrl(dojoParams);
APIFactory apiFactory = APIFactory.getInstance(ctx);
oAuthManager = Optional.of(new AndroidOAuthManager(apiFactory));
} else {
// samourai backend
backendUrl = BackendServer.get(testnet).getBackendUrl(onion);
oAuthManager = Optional.empty();
}
IHttpClient httpClient = new AndroidHttpClient(webUtil, torManager);
BackendApi backendApi = new BackendApi(httpClient, backendUrl, oAuthManager);
File fileIndex = whirlpoolUtils.computeIndexFile(walletIdentifier, ctx);
File fileUtxo = whirlpoolUtils.computeUtxosFile(walletIdentifier, ctx);
WhirlpoolWalletPersistHandler persistHandler = new FileWhirlpoolWalletPersistHandler(fileIndex, fileUtxo);
return computeWhirlpoolWalletConfig(torManager, persistHandler, testnet, onion, MIXS_TARGET_DEFAULT, scode, httpClient, backendApi);
}
Aggregations