Search in sources :

Example 1 with AndroidTx0Service

use of com.samourai.whirlpool.client.tx0.AndroidTx0Service 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);
}
Also used : Tx0Data(com.samourai.whirlpool.client.whirlpool.beans.Tx0Data) BackendApi(com.samourai.wallet.api.backend.BackendApi) NotifiableException(com.samourai.whirlpool.client.exception.NotifiableException) IHttpClient(com.samourai.http.client.IHttpClient) FileWhirlpoolWalletPersistHandler(com.samourai.whirlpool.client.wallet.persist.FileWhirlpoolWalletPersistHandler) AndroidHttpClient(com.samourai.http.client.AndroidHttpClient) APIFactory(com.samourai.wallet.api.APIFactory) AndroidTx0Service(com.samourai.whirlpool.client.tx0.AndroidTx0Service) FileWhirlpoolWalletPersistHandler(com.samourai.whirlpool.client.wallet.persist.FileWhirlpoolWalletPersistHandler) WhirlpoolWalletPersistHandler(com.samourai.whirlpool.client.wallet.persist.WhirlpoolWalletPersistHandler) TorManager(com.samourai.wallet.tor.TorManager) HttpException(com.samourai.wallet.api.backend.beans.HttpException) File(java.io.File) Before(org.junit.Before)

Example 2 with AndroidTx0Service

use of com.samourai.whirlpool.client.tx0.AndroidTx0Service in project samourai-wallet-android by Samourai-Wallet.

the class AndroidWhirlpoolWalletService method computeWhirlpoolWalletConfig.

protected WhirlpoolWalletConfig computeWhirlpoolWalletConfig(TorManager torManager, WhirlpoolWalletPersistHandler persistHandler, boolean testnet, boolean onion, int mixsTarget, String scode, IHttpClient httpClient, BackendApi backendApi) {
    IStompClientService stompClientService = new AndroidStompClientService(torManager);
    WhirlpoolServer whirlpoolServer = testnet ? WhirlpoolServer.TESTNET : WhirlpoolServer.MAINNET;
    String serverUrl = whirlpoolServer.getServerUrl(onion);
    NetworkParameters params = whirlpoolServer.getParams();
    WhirlpoolWalletConfig whirlpoolWalletConfig = new WhirlpoolWalletConfig(httpClient, stompClientService, persistHandler, serverUrl, params, true, backendApi);
    // disable auto-tx0
    whirlpoolWalletConfig.setAutoTx0PoolId(null);
    // enable auto-mix
    whirlpoolWalletConfig.setAutoMix(true);
    whirlpoolWalletConfig.setMixsTarget(mixsTarget);
    whirlpoolWalletConfig.setScode(scode);
    whirlpoolWalletConfig.setMaxClients(1);
    whirlpoolWalletConfig.setSecretPointFactory(AndroidSecretPointFactory.getInstance());
    whirlpoolWalletConfig.setTx0Service(new AndroidTx0Service(whirlpoolWalletConfig));
    for (Map.Entry<String, String> configEntry : whirlpoolWalletConfig.getConfigInfo().entrySet()) {
        Log.v(TAG, "whirlpoolWalletConfig[" + configEntry.getKey() + "] = " + configEntry.getValue());
    }
    return whirlpoolWalletConfig;
}
Also used : AndroidTx0Service(com.samourai.whirlpool.client.tx0.AndroidTx0Service) WhirlpoolServer(com.samourai.whirlpool.client.wallet.beans.WhirlpoolServer) NetworkParameters(org.bitcoinj.core.NetworkParameters) IStompClientService(com.samourai.stomp.client.IStompClientService) AndroidStompClientService(com.samourai.stomp.client.AndroidStompClientService) Map(java.util.Map)

Aggregations

AndroidTx0Service (com.samourai.whirlpool.client.tx0.AndroidTx0Service)2 AndroidHttpClient (com.samourai.http.client.AndroidHttpClient)1 IHttpClient (com.samourai.http.client.IHttpClient)1 AndroidStompClientService (com.samourai.stomp.client.AndroidStompClientService)1 IStompClientService (com.samourai.stomp.client.IStompClientService)1 APIFactory (com.samourai.wallet.api.APIFactory)1 BackendApi (com.samourai.wallet.api.backend.BackendApi)1 HttpException (com.samourai.wallet.api.backend.beans.HttpException)1 TorManager (com.samourai.wallet.tor.TorManager)1 NotifiableException (com.samourai.whirlpool.client.exception.NotifiableException)1 WhirlpoolServer (com.samourai.whirlpool.client.wallet.beans.WhirlpoolServer)1 FileWhirlpoolWalletPersistHandler (com.samourai.whirlpool.client.wallet.persist.FileWhirlpoolWalletPersistHandler)1 WhirlpoolWalletPersistHandler (com.samourai.whirlpool.client.wallet.persist.WhirlpoolWalletPersistHandler)1 Tx0Data (com.samourai.whirlpool.client.whirlpool.beans.Tx0Data)1 File (java.io.File)1 Map (java.util.Map)1 NetworkParameters (org.bitcoinj.core.NetworkParameters)1 Before (org.junit.Before)1