Esempio n. 1
0
  public void sweepKey(ECKey key, long fee, int accountId, JSONArray outputs) {
    mLogger.info("sweepKey starting");

    mLogger.info("key addr " + key.toAddress(mParams).toString());

    Transaction tx = new Transaction(mParams);

    long balance = 0;
    ArrayList<Script> scripts = new ArrayList<Script>();
    try {
      for (int ii = 0; ii < outputs.length(); ++ii) {
        JSONObject output;
        output = outputs.getJSONObject(ii);

        String tx_hash = output.getString("tx_hash");
        int tx_output_n = output.getInt("tx_output_n");
        String script = output.getString("script");

        // Reverse byte order, create hash.
        Sha256Hash hash = new Sha256Hash(WalletUtil.msgHexToBytes(tx_hash));

        tx.addInput(
            new TransactionInput(
                mParams, tx, new byte[] {}, new TransactionOutPoint(mParams, tx_output_n, hash)));

        scripts.add(new Script(Hex.decode(script)));

        balance += output.getLong("value");
      }
    } catch (JSONException e) {
      e.printStackTrace();
      throw new RuntimeException("trouble parsing unspent outputs");
    }

    // Compute balance - fee.
    long amount = balance - fee;
    mLogger.info(String.format("sweeping %d", amount));

    // Figure out the destination address.
    Address to = mHDWallet.nextReceiveAddress(accountId);
    mLogger.info("sweeping to " + to.toString());

    // Add output.
    tx.addOutput(BigInteger.valueOf(amount), to);

    WalletUtil.signTransactionInputs(tx, Transaction.SigHash.ALL, key, scripts);

    mLogger.info("tx bytes: " + new String(Hex.encode(tx.bitcoinSerialize())));
    // mKit.peerGroup().broadcastTransaction(tx);
    broadcastTransaction(mKit.peerGroup(), tx);

    mLogger.info("sweepKey finished");
  }
Esempio n. 2
0
  private void setupComplete() {

    Intent intent;

    switch (mAction) {
      case ACTION_CREATE:
        // Create the wallet.
        WalletUtil.createWallet(getApplicationContext());

        // Spin up the WalletService.
        Intent svcintent = new Intent(this, WalletService.class);
        Bundle bundle = new Bundle();
        bundle.putString("SyncState", "CREATED");
        svcintent.putExtras(bundle);
        startService(svcintent);

        intent = new Intent(this, ViewSeedActivity.class);
        Bundle bundle2 = new Bundle();
        bundle2.putBoolean("showDone", true);
        intent.putExtras(bundle2);
        startActivity(intent);
        break;

      case ACTION_RESTORE:
        intent = new Intent(this, RestoreWalletActivity.class);
        startActivity(intent);
        break;

      case ACTION_PAIR:
        intent = new Intent(this, PairWalletActivity.class);
        startActivity(intent);
        break;

      case ACTION_CHANGE:
        // We're all set, back to where we came from.
        break;

      default:
        // Shouldn't ever get here.
        String msg = "unexpected action in setupComplete";
        mLogger.error(msg);
        throw new RuntimeException(msg);
    }

    // And we're done here ...
    finish();
  }
Esempio n. 3
0
 protected Boolean doInBackground(String... arg0) {
   String passcode = arg0[0];
   // This takes a while (scrypt) ...
   return WalletUtil.passcodeValid(getApplicationContext(), passcode);
 }
Esempio n. 4
0
 protected Void doInBackground(String... arg0) {
   String passcode = arg0[0];
   // This takes a while (scrypt) ...
   WalletUtil.setPasscode(getApplicationContext(), mWalletService, passcode, mChangePasscode);
   return null;
 }