Browse Source

lots of sqlite stuff

gradlePlay
Gutyn 9 years ago
parent
commit
75114a8a20
  1. 5
      .idea/dictionaries/Mihail.xml
  2. 1
      app/build.gradle
  3. 4
      app/src/androidTest/java/com/breadwallet/tools/adapter/tests/AmountAdapterTest.java
  4. 1
      app/src/main/java/com/breadwallet-core
  5. 2
      app/src/main/java/com/breadwallet/presenter/BreadWalletApp.java
  6. 97
      app/src/main/java/com/breadwallet/presenter/activities/IntroActivity.java
  7. 5
      app/src/main/java/com/breadwallet/presenter/activities/IntroShowPhraseActivity.java
  8. 25
      app/src/main/java/com/breadwallet/presenter/activities/MainActivity.java
  9. 4
      app/src/main/java/com/breadwallet/presenter/fragments/ChangePasswordDialogFragment.java
  10. 2
      app/src/main/java/com/breadwallet/presenter/fragments/FragmentCurrency.java
  11. 2
      app/src/main/java/com/breadwallet/presenter/fragments/FragmentScanResult.java
  12. 2
      app/src/main/java/com/breadwallet/presenter/fragments/FragmentSettings.java
  13. 4
      app/src/main/java/com/breadwallet/presenter/fragments/MainFragment.java
  14. 4
      app/src/main/java/com/breadwallet/presenter/fragments/PasswordDialogFragment.java
  15. 4
      app/src/main/java/com/breadwallet/presenter/fragments/SharingFragment.java
  16. 2
      app/src/main/java/com/breadwallet/tools/AutoResizeTextView.java
  17. 4
      app/src/main/java/com/breadwallet/tools/BRClipboardManager.java
  18. 2
      app/src/main/java/com/breadwallet/tools/CurrencyManager.java
  19. 2
      app/src/main/java/com/breadwallet/tools/JsonParser.java
  20. 2
      app/src/main/java/com/breadwallet/tools/NetworkChangeReceiver.java
  21. 2
      app/src/main/java/com/breadwallet/tools/PassCodeManager.java
  22. 102
      app/src/main/java/com/breadwallet/tools/ReadWriteBytes.java
  23. 2
      app/src/main/java/com/breadwallet/tools/TypefaceUtil.java
  24. 2
      app/src/main/java/com/breadwallet/tools/WordsReader.java
  25. 2
      app/src/main/java/com/breadwallet/tools/adapter/AmountAdapter.java
  26. 2
      app/src/main/java/com/breadwallet/tools/adapter/MiddleViewAdapter.java
  27. 171
      app/src/main/java/com/breadwallet/tools/sqlite/BRSQLiteHelper.java
  28. 131
      app/src/main/java/com/breadwallet/tools/sqlite/MerkleBlockDataSource.java
  29. 117
      app/src/main/java/com/breadwallet/tools/sqlite/PeerDataSource.java
  30. 137
      app/src/main/java/com/breadwallet/tools/sqlite/TransactionDataSource.java
  31. 138
      app/src/main/java/com/breadwallet/tools/sqlite/entities/BRMerkleBlockEntity.java
  32. 61
      app/src/main/java/com/breadwallet/tools/sqlite/entities/BRPeerEntity.java
  33. 93
      app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTransactionEntity.java
  34. 94
      app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTxInputEntity.java
  35. 54
      app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTxOutputEntity.java
  36. 28
      app/src/main/java/com/breadwallet/wallet/BRTransaction.java
  37. 23
      app/src/main/java/com/breadwallet/wallet/BRWallet.java
  38. 8
      app/src/main/java/com/breadwallet/wallet/BRWalletManager.java
  39. 1
      app/src/main/jni/breadwallet-core
  40. 18
      app/src/main/jni/transition/core.c
  41. 11
      app/src/main/jni/transition/core.h
  42. 8
      app/src/main/jni/transition/testingStuff.c
  43. 2
      app/src/main/res/layouts/layout/currency_list_item.xml

5
.idea/dictionaries/Mihail.xml

@ -2,9 +2,14 @@
<dictionary name="Mihail"> <dictionary name="Mihail">
<words> <words>
<w>bitcoin</w> <w>bitcoin</w>
<w>breadwallet</w>
<w>gutan</w>
<w>merkle</w>
<w>mihail</w>
<w>mydecoderview</w> <w>mydecoderview</w>
<w>passcode</w> <w>passcode</w>
<w>qrdecoderview</w> <w>qrdecoderview</w>
<w>testnet</w>
</words> </words>
</dictionary> </dictionary>
</component> </component>

1
app/build.gradle

@ -27,6 +27,7 @@ android {
versionName "1.0" versionName "1.0"
ndk { ndk {
moduleName "BreadWalletCore" moduleName "BreadWalletCore"
cFlags "-std=c99"
} }
} }
buildTypes { buildTypes {

4
app/src/androidTest/java/com/breadwallet/tools/adapter/tests/AmountAdapterTest.java

@ -9,7 +9,7 @@ import android.widget.Button;
import com.breadwallet.R; import com.breadwallet.R;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.adapter.AmountAdapter; import com.breadwallet.tools.adapter.AmountAdapter;
import com.breadwallet.tools.others.MyClipboardManager; import com.breadwallet.tools.BRClipboardManager;
import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click; import static android.support.test.espresso.action.ViewActions.click;
@ -57,7 +57,7 @@ public class AmountAdapterTest extends ActivityInstrumentationTestCase2<MainActi
injectInstrumentation(InstrumentationRegistry.getInstrumentation()); // injects the Instrumentation for the Espresso injectInstrumentation(InstrumentationRegistry.getInstrumentation()); // injects the Instrumentation for the Espresso
activity = getActivity(); activity = getActivity();
copyAddressFromClipboard = (Button) activity.findViewById(R.id.main_button_pay_address_from_clipboard); copyAddressFromClipboard = (Button) activity.findViewById(R.id.main_button_pay_address_from_clipboard);
MyClipboardManager.copyToClipboard(getActivity(), testAddress); BRClipboardManager.copyToClipboard(getActivity(), testAddress);
} }
@MediumTest @MediumTest

1
app/src/main/java/com/breadwallet-core

@ -1 +0,0 @@
Subproject commit b1626c728004a962152e37fe17d4ea934f66cab3

2
app/src/main/java/com/breadwallet/presenter/BreadWalletApp.java

@ -18,7 +18,7 @@ import android.widget.Toast;
import com.breadwallet.R; import com.breadwallet.R;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.others.TypefaceUtil; import com.breadwallet.tools.TypefaceUtil;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ReportField; import org.acra.ReportField;

97
app/src/main/java/com/breadwallet/presenter/activities/IntroActivity.java

@ -4,6 +4,7 @@ package com.breadwallet.presenter.activities;
import android.animation.Animator; import android.animation.Animator;
import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator; import android.animation.ValueAnimator;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.RectF; import android.graphics.RectF;
@ -23,10 +24,19 @@ import com.breadwallet.presenter.fragments.IntroNewWalletFragment;
import com.breadwallet.presenter.fragments.IntroRecoverWalletFragment; import com.breadwallet.presenter.fragments.IntroRecoverWalletFragment;
import com.breadwallet.presenter.fragments.IntroWarningFragment; import com.breadwallet.presenter.fragments.IntroWarningFragment;
import com.breadwallet.presenter.fragments.IntroWelcomeFragment; import com.breadwallet.presenter.fragments.IntroWelcomeFragment;
import com.breadwallet.tools.others.WordsReader; import com.breadwallet.tools.WordsReader;
import com.breadwallet.tools.sqlite.MerkleBlockDataSource;
import com.breadwallet.tools.sqlite.TransactionDataSource;
import com.breadwallet.tools.sqlite.entities.BRMerkleBlockEntity;
import com.breadwallet.tools.sqlite.entities.BRTransactionEntity;
import com.breadwallet.tools.sqlite.entities.BRTxInputEntity;
import com.breadwallet.tools.sqlite.entities.BRTxOutputEntity;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
@ -79,7 +89,15 @@ public class IntroActivity extends FragmentActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro); setContentView(R.layout.activity_intro);
Log.e(TAG, "Activity created!");
if (savedInstanceState != null) {
return;
}
// testSQLiteConnectivity(this); //do some sqlite testing
introWelcomeFragment = new IntroWelcomeFragment(); introWelcomeFragment = new IntroWelcomeFragment();
introNewRestoreFragment = new IntroNewRecoverFragment(); introNewRestoreFragment = new IntroNewRecoverFragment();
introNewWalletFragment = new IntroNewWalletFragment(); introNewWalletFragment = new IntroNewWalletFragment();
@ -264,4 +282,81 @@ public class IntroActivity extends FragmentActivity {
super.onBackPressed(); super.onBackPressed();
} }
public void testSQLiteConnectivity(Activity context) {
// Test MerkleBlock Table
BRMerkleBlockEntity merkleBlockEntity = new BRMerkleBlockEntity();
String blockHash = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
merkleBlockEntity.setId(21);
merkleBlockEntity.setBlockHash(blockHash.getBytes());
merkleBlockEntity.setFlags("someFLags".getBytes());
merkleBlockEntity.setHashes("someHashes".getBytes());
merkleBlockEntity.setHeight(12312);
merkleBlockEntity.setMerkleRoot("merkleRoot".getBytes());
merkleBlockEntity.setNonce(6363);
merkleBlockEntity.setPrevBlock("prevBlock".getBytes());
merkleBlockEntity.setTarget(423423423);
merkleBlockEntity.setTimeStamp(423211244);
merkleBlockEntity.setTotalTransactions(511);
merkleBlockEntity.setVersion(5);
MerkleBlockDataSource MBdataSource;
MBdataSource = new MerkleBlockDataSource(this);
MBdataSource.open();
MBdataSource.createMerkleBlock(merkleBlockEntity);
List<BRMerkleBlockEntity> values = MBdataSource.getAllMerkleBlocks();
Iterator<BRMerkleBlockEntity> merkleBlockEntityIterator = values.iterator();
while (merkleBlockEntityIterator.hasNext()) {
BRMerkleBlockEntity tmp = merkleBlockEntityIterator.next();
Log.e(TAG, "The merkleBlock: " + tmp.getId() + " " + tmp.getBlockHash() + " " + tmp.getFlags() +
" " + tmp.getHashes() + " " + tmp.getHeight() + " " + tmp.getMerkleRoot() + " " +
tmp.getNonce() + " " + tmp.getPrevBlock() + " " + tmp.getTarget() + " " +
tmp.getTimeStamp() + tmp.getTotalTransactions() + " " + tmp.getVersion());
}
// Test Transaction Table
BRTxInputEntity input1 = new BRTxInputEntity();
input1.setTxHash("somehash".getBytes());
input1.setId(123);
input1.setSequence(23123123);
input1.setSignatures("976sd56ds56gds5fsdfd67fsd697".getBytes());
BRTxInputEntity input2 = new BRTxInputEntity();
input1.setTxHash("somehash2".getBytes());
input1.setId(55);
input1.setSequence(31124124);
input1.setSignatures("98sdf78ds67f6sd87f68sd7".getBytes());
HashSet<BRTxInputEntity> inputs = new HashSet<>();
inputs.add(input1);
inputs.add(input2);
BRTransactionEntity transactionEntity = new BRTransactionEntity();
String txHash = "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f";
transactionEntity.setId(98);
transactionEntity.setBlockHeight(123123);
transactionEntity.setTimeStamp(97986716);
transactionEntity.setLockTime(232131231);
transactionEntity.setTxHash(txHash.getBytes());
transactionEntity.setOutputs(new HashSet<BRTxOutputEntity>());
transactionEntity.setInputs(inputs);
TransactionDataSource TXdataSource = new TransactionDataSource(this);
TXdataSource.open();
TXdataSource.createTransaction(transactionEntity);
List<BRTransactionEntity> txValues = TXdataSource.getAllTransactions();
Iterator<BRTransactionEntity> transactionEntityIterator = txValues.iterator();
while (transactionEntityIterator.hasNext()) {
BRTransactionEntity transactionEntity1 = transactionEntityIterator.next();
Log.e(TAG, "The transaction: " + transactionEntity1.getId() + " " + transactionEntity1.getBlockHeight() +
" " + transactionEntity1.getTimeStamp() +
" " + transactionEntity1.getLockTime() + " " + transactionEntity1.getTxHash());
Set<BRTxInputEntity> inputsFromBytes = transactionEntity1.getInputs();
for (BRTxInputEntity input : inputsFromBytes) {
Log.e(TAG, "INPUTS: " + input.getTxHash() + " " + input.getSequence() + " " + input.getSignatures());
}
}
}
} }

5
app/src/main/java/com/breadwallet/presenter/activities/IntroShowPhraseActivity.java

@ -4,6 +4,7 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -23,6 +24,10 @@ public class IntroShowPhraseActivity extends Activity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro_show_phrase); setContentView(R.layout.activity_intro_show_phrase);
if (savedInstanceState != null) {
return;
}
remindMeLate = (Button) findViewById(R.id.remind_me_later_button); remindMeLate = (Button) findViewById(R.id.remind_me_later_button);
writeDownLayout = (RelativeLayout) findViewById(R.id.write_down_notice_layout); writeDownLayout = (RelativeLayout) findViewById(R.id.write_down_notice_layout);
checkBox = (ImageView) findViewById(R.id.write_down_check_box); checkBox = (ImageView) findViewById(R.id.write_down_check_box);

25
app/src/main/java/com/breadwallet/presenter/activities/MainActivity.java

@ -37,14 +37,14 @@ import com.breadwallet.presenter.fragments.FragmentSettings;
import com.breadwallet.presenter.fragments.FragmentSettingsAll; import com.breadwallet.presenter.fragments.FragmentSettingsAll;
import com.breadwallet.presenter.fragments.FragmentWipeWallet; import com.breadwallet.presenter.fragments.FragmentWipeWallet;
import com.breadwallet.presenter.fragments.PasswordDialogFragment; import com.breadwallet.presenter.fragments.PasswordDialogFragment;
import com.breadwallet.tools.CurrencyManager;
import com.breadwallet.tools.NetworkChangeReceiver;
import com.breadwallet.tools.adapter.AmountAdapter; import com.breadwallet.tools.adapter.AmountAdapter;
import com.breadwallet.tools.adapter.CustomPagerAdapter; import com.breadwallet.tools.adapter.CustomPagerAdapter;
import com.breadwallet.tools.adapter.MiddleViewAdapter; import com.breadwallet.tools.adapter.MiddleViewAdapter;
import com.breadwallet.tools.adapter.ParallaxViewPager; import com.breadwallet.tools.adapter.ParallaxViewPager;
import com.breadwallet.tools.animation.FragmentAnimator; import com.breadwallet.tools.animation.FragmentAnimator;
import com.breadwallet.tools.animation.SpringAnimator; import com.breadwallet.tools.animation.SpringAnimator;
import com.breadwallet.tools.others.CurrencyManager;
import com.breadwallet.tools.others.NetworkChangeReceiver;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -117,9 +117,7 @@ public class MainActivity extends FragmentActivity implements Observer {
public static final int DEBUG = 1; public static final int DEBUG = 1;
public static final int RELEASE = 2; public static final int RELEASE = 2;
public static int MODE = RELEASE; public static int MODE = RELEASE;
private static final String DEBUG_KEY = public TextView testnet;
"get the debug key from logcat after calling the function below once from the emulator";
TextView testnet;
//loading the native library //loading the native library
static { static {
@ -156,24 +154,11 @@ public class MainActivity extends FragmentActivity implements Observer {
MODE = DEBUG; MODE = DEBUG;
Log.e(TAG, "DEBUG MODE!!!!!!"); Log.e(TAG, "DEBUG MODE!!!!!!");
} }
final FragmentManager fm = getSupportFragmentManager(); final FragmentManager fm = getSupportFragmentManager();
initializeViews(); initializeViews();
testnet.setVisibility(MODE == DEBUG ? View.VISIBLE : View.GONE); testnet.setVisibility(MODE == DEBUG ? View.VISIBLE : View.GONE);
//testing native code bridge
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// ((BreadWalletApp)getApplication()).setTopMiddleView(BreadWalletApp.BREAD_WALLET_TEXT, messageFromNativeCode("Here, worked"));
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// ((BreadWalletApp) getApplication()).setTopMiddleView(BreadWalletApp.BREAD_WALLET_IMAGE, "");
// }
// }, 2000);
// }
// },3000);
viewFlipper.setOnClickListener(new View.OnClickListener() { viewFlipper.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -469,4 +454,6 @@ public class MainActivity extends FragmentActivity implements Observer {
return Build.BRAND.equalsIgnoreCase("generic") || BuildConfig.DEBUG; return Build.BRAND.equalsIgnoreCase("generic") || BuildConfig.DEBUG;
} }
} }

4
app/src/main/java/com/breadwallet/presenter/fragments/ChangePasswordDialogFragment.java

@ -43,8 +43,8 @@ import com.breadwallet.presenter.BreadWalletApp;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.adapter.CustomPagerAdapter; import com.breadwallet.tools.adapter.CustomPagerAdapter;
import com.breadwallet.tools.animation.SpringAnimator; import com.breadwallet.tools.animation.SpringAnimator;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
import com.breadwallet.tools.others.PassCodeManager; import com.breadwallet.tools.PassCodeManager;
public class ChangePasswordDialogFragment extends DialogFragment { public class ChangePasswordDialogFragment extends DialogFragment {

2
app/src/main/java/com/breadwallet/presenter/fragments/FragmentCurrency.java

@ -22,7 +22,7 @@ import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.adapter.CurrencyListAdapter; import com.breadwallet.tools.adapter.CurrencyListAdapter;
import com.breadwallet.tools.adapter.MiddleViewAdapter; import com.breadwallet.tools.adapter.MiddleViewAdapter;
import com.breadwallet.tools.animation.SpringAnimator; import com.breadwallet.tools.animation.SpringAnimator;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
/** /**

2
app/src/main/java/com/breadwallet/presenter/fragments/FragmentScanResult.java

@ -21,7 +21,7 @@ import com.breadwallet.tools.adapter.AmountAdapter;
import com.breadwallet.tools.adapter.CurrencyListAdapter; import com.breadwallet.tools.adapter.CurrencyListAdapter;
import com.breadwallet.tools.animation.SpringAnimator; import com.breadwallet.tools.animation.SpringAnimator;
import com.breadwallet.tools.listeners.BackPressCustomKeyboardOnTouchListener; import com.breadwallet.tools.listeners.BackPressCustomKeyboardOnTouchListener;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
import java.math.BigDecimal; import java.math.BigDecimal;

2
app/src/main/java/com/breadwallet/presenter/fragments/FragmentSettings.java

@ -19,7 +19,7 @@ import com.breadwallet.R;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.adapter.MiddleViewAdapter; import com.breadwallet.tools.adapter.MiddleViewAdapter;
import com.breadwallet.tools.animation.FragmentAnimator; import com.breadwallet.tools.animation.FragmentAnimator;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
/** /**
* BreadWallet * BreadWallet

4
app/src/main/java/com/breadwallet/presenter/fragments/MainFragment.java

@ -18,7 +18,7 @@ import android.widget.EditText;
import com.breadwallet.R; import com.breadwallet.R;
import com.breadwallet.tools.adapter.MiddleViewAdapter; import com.breadwallet.tools.adapter.MiddleViewAdapter;
import com.breadwallet.tools.animation.FragmentAnimator; import com.breadwallet.tools.animation.FragmentAnimator;
import com.breadwallet.tools.others.MyClipboardManager; import com.breadwallet.tools.BRClipboardManager;
/** /**
* BreadWallet * BreadWallet
@ -85,7 +85,7 @@ public class MainFragment extends Fragment {
if (alertDialog.isShowing()) { if (alertDialog.isShowing()) {
alertDialog.dismiss(); alertDialog.dismiss();
} }
String address = MyClipboardManager.readFromClipboard(getActivity()); String address = BRClipboardManager.readFromClipboard(getActivity());
Log.e(TAG, "The address before check: " + address); Log.e(TAG, "The address before check: " + address);
if (checkIfAddressIsValid(address)) { if (checkIfAddressIsValid(address)) {
payAddressFromClipboardButton.setBackgroundResource(R.drawable.buttonbluepressed); payAddressFromClipboardButton.setBackgroundResource(R.drawable.buttonbluepressed);

4
app/src/main/java/com/breadwallet/presenter/fragments/PasswordDialogFragment.java

@ -41,8 +41,8 @@ import com.breadwallet.R;
import com.breadwallet.presenter.BreadWalletApp; import com.breadwallet.presenter.BreadWalletApp;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.animation.SpringAnimator; import com.breadwallet.tools.animation.SpringAnimator;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
import com.breadwallet.tools.others.PassCodeManager; import com.breadwallet.tools.PassCodeManager;
public class PasswordDialogFragment extends DialogFragment { public class PasswordDialogFragment extends DialogFragment {

4
app/src/main/java/com/breadwallet/presenter/fragments/SharingFragment.java

@ -40,7 +40,7 @@ import android.widget.Toast;
import com.breadwallet.R; import com.breadwallet.R;
import com.breadwallet.presenter.BreadWalletApp; import com.breadwallet.presenter.BreadWalletApp;
import com.breadwallet.tools.animation.FragmentAnimator; import com.breadwallet.tools.animation.FragmentAnimator;
import com.breadwallet.tools.others.MyClipboardManager; import com.breadwallet.tools.BRClipboardManager;
public class SharingFragment extends DialogFragment { public class SharingFragment extends DialogFragment {
@ -70,7 +70,7 @@ public class SharingFragment extends DialogFragment {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (FragmentAnimator.checkTheMultipressingAvailability(300)) { if (FragmentAnimator.checkTheMultipressingAvailability(300)) {
MyClipboardManager.copyToClipboard(getActivity(), theAddress); BRClipboardManager.copyToClipboard(getActivity(), theAddress);
if (customToastAvailable) { if (customToastAvailable) {
customToastAvailable = false; customToastAvailable = false;
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {

2
app/src/main/java/com/breadwallet/tools/others/AutoResizeTextView.java → app/src/main/java/com/breadwallet/tools/AutoResizeTextView.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
/** /**
* DO WHAT YOU WANT TO PUBLIC LICENSE * DO WHAT YOU WANT TO PUBLIC LICENSE

4
app/src/main/java/com/breadwallet/tools/others/MyClipboardManager.java → app/src/main/java/com/breadwallet/tools/BRClipboardManager.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.ClipData; import android.content.ClipData;
@ -32,7 +32,7 @@ import android.net.Uri;
* THE SOFTWARE. * THE SOFTWARE.
*/ */
public class MyClipboardManager { public class BRClipboardManager {
@SuppressLint("NewApi") @SuppressLint("NewApi")
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")

2
app/src/main/java/com/breadwallet/tools/others/CurrencyManager.java → app/src/main/java/com/breadwallet/tools/CurrencyManager.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;

2
app/src/main/java/com/breadwallet/tools/others/JsonParser.java → app/src/main/java/com/breadwallet/tools/JsonParser.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;

2
app/src/main/java/com/breadwallet/tools/others/NetworkChangeReceiver.java → app/src/main/java/com/breadwallet/tools/NetworkChangeReceiver.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;

2
app/src/main/java/com/breadwallet/tools/others/PassCodeManager.java → app/src/main/java/com/breadwallet/tools/PassCodeManager.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
/** /**
* BreadWallet * BreadWallet

102
app/src/main/java/com/breadwallet/tools/ReadWriteBytes.java

@ -0,0 +1,102 @@
package com.breadwallet.tools;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.StreamCorruptedException;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/28/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class ReadWriteBytes {
public static Object readBytes(byte[] bytes) {
ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
ObjectInput in = null;
Object o = null;
try {
in = new ObjectInputStream(bis);
o = in.readObject();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
bis.close();
} catch (IOException ex) {
// ignore close exception
}
try {
if (in != null) {
in.close();
}
} catch (IOException ex) {
// ignore close exception
}
}
if (o != null) {
return o;
} else {
throw new NullPointerException("bytes should not be null");
}
}
public static byte[] writeBytes(Object obj) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = null;
byte[] yourBytes = null;
try {
out = new ObjectOutputStream(bos);
out.writeObject(obj);
yourBytes = bos.toByteArray();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException ex) {
// ignore close exception
}
try {
bos.close();
} catch (IOException ex) {
// ignore close exception
}
}
if (yourBytes != null) {
return yourBytes;
} else {
throw new NullPointerException("bytes should not be null");
}
}
}

2
app/src/main/java/com/breadwallet/tools/others/TypefaceUtil.java → app/src/main/java/com/breadwallet/tools/TypefaceUtil.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import android.content.Context; import android.content.Context;
import android.graphics.Typeface; import android.graphics.Typeface;

2
app/src/main/java/com/breadwallet/tools/others/WordsReader.java → app/src/main/java/com/breadwallet/tools/WordsReader.java

@ -1,4 +1,4 @@
package com.breadwallet.tools.others; package com.breadwallet.tools;
import android.content.Context; import android.content.Context;
import android.content.res.AssetManager; import android.content.res.AssetManager;

2
app/src/main/java/com/breadwallet/tools/adapter/AmountAdapter.java

@ -7,7 +7,7 @@ import com.breadwallet.R;
import com.breadwallet.presenter.BreadWalletApp; import com.breadwallet.presenter.BreadWalletApp;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.presenter.fragments.FragmentScanResult; import com.breadwallet.presenter.fragments.FragmentScanResult;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode; import java.math.RoundingMode;

2
app/src/main/java/com/breadwallet/tools/adapter/MiddleViewAdapter.java

@ -3,7 +3,7 @@ package com.breadwallet.tools.adapter;
import com.breadwallet.presenter.BreadWalletApp; import com.breadwallet.presenter.BreadWalletApp;
import com.breadwallet.presenter.activities.MainActivity; import com.breadwallet.presenter.activities.MainActivity;
import com.breadwallet.tools.animation.FragmentAnimator; import com.breadwallet.tools.animation.FragmentAnimator;
import com.breadwallet.tools.others.CurrencyManager; import com.breadwallet.tools.CurrencyManager;
/** /**
* BreadWallet * BreadWallet

171
app/src/main/java/com/breadwallet/tools/sqlite/BRSQLiteHelper.java

@ -0,0 +1,171 @@
package com.breadwallet.tools.sqlite;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class BRSQLiteHelper extends SQLiteOpenHelper {
public static final String TAG = BRSQLiteHelper.class.getName();
private static final String DATABASE_NAME = "breadwallet.db";
private static final int DATABASE_VERSION = 3;
/**
* MerkleBlock table
*/
public static final String MB_TABLE_NAME = "merkleBlockTable";
public static final String MB_COLUMN_ID = "_id";
public static final String MB_COLUMN_BLOCK_HASH = "blockHash";
public static final String MB_COLUMN_FLAGS = "flags";
public static final String MB_COLUMN_HASHES = "hashes";
public static final String MB_COLUMN_HEIGHT = "height";
public static final String MB_COLUMN_MERKLE_ROOT = "merkleRoot";
public static final String MB_COLUMN_NONCE = "nonce";
public static final String MB_COLUMN_PREV_BLOCK = "prevBlock";
public static final String MB_COLUMN_TARGET = "target";
public static final String MB_COLUMN_TIME_STAMP = "timeStamp";
public static final String MB_COLUMN_TOTAL_TRANSACTIONS = "totalTransactions";
public static final String MB_COLUMN_VERSION = "version";
private static final String MB_DATABASE_CREATE = "create table " + MB_TABLE_NAME + "(" +
MB_COLUMN_ID + " integer primary key autoincrement, " +
MB_COLUMN_BLOCK_HASH + " blob, " +
MB_COLUMN_FLAGS + " blob, " +
MB_COLUMN_HASHES + " blob, " +
MB_COLUMN_HEIGHT + " integer, " +
MB_COLUMN_MERKLE_ROOT + " blob, " +
MB_COLUMN_NONCE + " integer, " +
MB_COLUMN_PREV_BLOCK + " blob, " +
MB_COLUMN_TARGET + " integer, " +
MB_COLUMN_TIME_STAMP + " integer, " +
MB_COLUMN_TOTAL_TRANSACTIONS + " integer, " +
MB_COLUMN_VERSION + " integer );";
/**
* Transaction table
*/
public static final String TX_TABLE_NAME = "transactionTable";
public static final String TX_COLUMN_ID = "_id";
public static final String TX_BLOCK_HEIGHT = "blockHeight";
public static final String TX_LOCK_TIME = "lockTime";
public static final String TX_TIME_STAMP = "timeStamp";
public static final String TX_HASH = "txHash";
private static final String TX_DATABASE_CREATE = "create table " + TX_TABLE_NAME + "(" +
TX_COLUMN_ID + " integer primary key autoincrement, " +
TX_BLOCK_HEIGHT + " integer, " +
TX_LOCK_TIME + " integer, " +
TX_TIME_STAMP + " integer, " +
TX_HASH + " blob );";
/**
* Peer table
*/
public static final String PEER_TABLE_NAME = "peerTable";
public static final String PEER_COLUMN_ID = "_id";
public static final String PEER_ADDRESS = "address";
public static final String PEER_MISBEHAVIN = "misbehavin";
public static final String PEER_PORT = "port";
public static final String PEER_SERVICES = "services";
public static final String PEER_TIME_STAMP = "timeStamp";
private static final String PEER_DATABASE_CREATE = "create table " + PEER_TABLE_NAME + "(" +
PEER_COLUMN_ID + " integer primary key autoincrement, " +
PEER_ADDRESS + " integer, " +
PEER_MISBEHAVIN + " integer, " +
PEER_PORT + " integer, " +
PEER_SERVICES + " integer " +
PEER_TIME_STAMP + " integer );";
/**
* Inputs table
*/
public static final String IN_TABLE_NAME = "inputTable";
public static final String IN_COLUMN_ID = "_id";
public static final String IN_TX_HASH = "txHash";
public static final String IN_INDEX = "index";
public static final String IN_PREV_OUT_TX_HASH = "prevOutTxHash";
public static final String IN_PREV_OUT_INDEX = "prevOutIndex";
public static final String IN_SEQUENCE = "sequence";
public static final String IN_SIGNATURE = "signature";
private static final String INPUTS_DATABASE_CREATE = "create table " + IN_TABLE_NAME + "(" +
IN_COLUMN_ID + " integer primary key autoincrement, " +
IN_TX_HASH + " blob, " +
IN_INDEX + " integer, " +
IN_PREV_OUT_TX_HASH + " blob, " +
IN_PREV_OUT_INDEX + " integer " +
IN_SEQUENCE + " integer ," +
IN_SIGNATURE + " blob );";
/**
* Outputs table
*/
public static final String OUT_TABLE_NAME = "outputTable";
public static final String OUT_COLUMN_ID = "_id";
public static final String OUT_TX_HASH = "txHash";
public static final String OUT_INDEX = "index";
public static final String OUT_VALUE = "value";
private static final String OUTPUTS_DATABASE_CREATE = "create table " + OUT_TABLE_NAME + "(" +
OUT_COLUMN_ID + " integer primary key autoincrement, " +
OUT_TX_HASH + " blob, " +
OUT_INDEX + " integer, " +
OUT_VALUE + " integer );";
public BRSQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(MB_DATABASE_CREATE);
database.execSQL(TX_DATABASE_CREATE);
database.execSQL(PEER_DATABASE_CREATE);
database.execSQL(INPUTS_DATABASE_CREATE);
database.execSQL(OUTPUTS_DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.e(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + MB_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + TX_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + PEER_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + IN_TABLE_NAME);
db.execSQL("DROP TABLE IF EXISTS " + OUT_TABLE_NAME);
//recreate the dbs
onCreate(db);
}
}

131
app/src/main/java/com/breadwallet/tools/sqlite/MerkleBlockDataSource.java

@ -0,0 +1,131 @@
package com.breadwallet.tools.sqlite;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.breadwallet.tools.sqlite.entities.BRMerkleBlockEntity;
import java.util.ArrayList;
import java.util.List;
public class MerkleBlockDataSource {
public static final String TAG = MerkleBlockDataSource.class.getName();
// Database fields
private SQLiteDatabase database;
private BRSQLiteHelper dbHelper;
private String[] allColumns = {BRSQLiteHelper.MB_COLUMN_ID,
BRSQLiteHelper.MB_COLUMN_BLOCK_HASH, BRSQLiteHelper.MB_COLUMN_FLAGS,
BRSQLiteHelper.MB_COLUMN_HASHES, BRSQLiteHelper.MB_COLUMN_HEIGHT,
BRSQLiteHelper.MB_COLUMN_MERKLE_ROOT, BRSQLiteHelper.MB_COLUMN_NONCE,
BRSQLiteHelper.MB_COLUMN_PREV_BLOCK, BRSQLiteHelper.MB_COLUMN_TARGET,
BRSQLiteHelper.MB_COLUMN_TIME_STAMP, BRSQLiteHelper.MB_COLUMN_TOTAL_TRANSACTIONS,
BRSQLiteHelper.MB_COLUMN_VERSION};
public MerkleBlockDataSource(Context context) {
dbHelper = new BRSQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public BRMerkleBlockEntity createMerkleBlock(BRMerkleBlockEntity merkleBlock) {
ContentValues values = new ContentValues();
// values.put(BRSQLiteHelper.MB_COLUMN_ID, merkleBlock.getId());
values.put(BRSQLiteHelper.MB_COLUMN_BLOCK_HASH, merkleBlock.getBlockHash());
values.put(BRSQLiteHelper.MB_COLUMN_FLAGS, merkleBlock.getFlags());
values.put(BRSQLiteHelper.MB_COLUMN_HASHES, merkleBlock.getHashes());
values.put(BRSQLiteHelper.MB_COLUMN_HEIGHT, merkleBlock.getHeight());
values.put(BRSQLiteHelper.MB_COLUMN_MERKLE_ROOT, merkleBlock.getMerkleRoot());
values.put(BRSQLiteHelper.MB_COLUMN_NONCE, merkleBlock.getNonce());
values.put(BRSQLiteHelper.MB_COLUMN_PREV_BLOCK, merkleBlock.getPrevBlock());
values.put(BRSQLiteHelper.MB_COLUMN_TARGET, merkleBlock.getTarget());
values.put(BRSQLiteHelper.MB_COLUMN_TIME_STAMP, merkleBlock.getTimeStamp());
values.put(BRSQLiteHelper.MB_COLUMN_TOTAL_TRANSACTIONS, merkleBlock.getTotalTransactions());
values.put(BRSQLiteHelper.MB_COLUMN_VERSION, merkleBlock.getVersion());
long insertId = database.insert(BRSQLiteHelper.MB_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.MB_TABLE_NAME,
allColumns, BRSQLiteHelper.MB_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRMerkleBlockEntity newMerkleBlock = cursorToMerkleBlock(cursor);
cursor.close();
return newMerkleBlock;
}
public void deleteMerkleBlock(BRMerkleBlockEntity merkleBlock) {
long id = merkleBlock.getId();
Log.e(TAG, "MerkleBlock deleted with id: " + id);
database.delete(BRSQLiteHelper.MB_TABLE_NAME, BRSQLiteHelper.MB_COLUMN_ID
+ " = " + id, null);
}
public List<BRMerkleBlockEntity> getAllMerkleBlocks() {
List<BRMerkleBlockEntity> merkleBlocks = new ArrayList<>();
Cursor cursor = database.query(BRSQLiteHelper.MB_TABLE_NAME,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
BRMerkleBlockEntity merkleBlockEntity = cursorToMerkleBlock(cursor);
merkleBlocks.add(merkleBlockEntity);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return merkleBlocks;
}
private BRMerkleBlockEntity cursorToMerkleBlock(Cursor cursor) {
BRMerkleBlockEntity merkleBlockEntity = new BRMerkleBlockEntity();
merkleBlockEntity.setId(cursor.getInt(0));
merkleBlockEntity.setBlockHash(cursor.getBlob(1));
merkleBlockEntity.setFlags(cursor.getBlob(2));
merkleBlockEntity.setHashes(cursor.getBlob(3));
merkleBlockEntity.setHeight(cursor.getInt(4));
merkleBlockEntity.setMerkleRoot(cursor.getBlob(5));
merkleBlockEntity.setNonce(cursor.getInt(6));
merkleBlockEntity.setPrevBlock(cursor.getBlob(7));
merkleBlockEntity.setTarget(cursor.getInt(8));
merkleBlockEntity.setTimeStamp(cursor.getLong(9));
merkleBlockEntity.setTotalTransactions(cursor.getInt(10));
merkleBlockEntity.setVersion(cursor.getInt(11));
return merkleBlockEntity;
}
}

117
app/src/main/java/com/breadwallet/tools/sqlite/PeerDataSource.java

@ -0,0 +1,117 @@
package com.breadwallet.tools.sqlite;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.breadwallet.tools.sqlite.entities.BRPeerEntity;
import java.util.ArrayList;
import java.util.List;
public class PeerDataSource {
public static final String TAG = PeerDataSource.class.getName();
// Database fields
private SQLiteDatabase database;
private BRSQLiteHelper dbHelper;
private String[] allColumns = {
BRSQLiteHelper.PEER_COLUMN_ID, BRSQLiteHelper.PEER_ADDRESS,
BRSQLiteHelper.PEER_MISBEHAVIN, BRSQLiteHelper.PEER_PORT,
BRSQLiteHelper.PEER_SERVICES, BRSQLiteHelper.PEER_TIME_STAMP
};
public PeerDataSource(Context context) {
dbHelper = new BRSQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public BRPeerEntity createPeer(BRPeerEntity peer) {
ContentValues values = new ContentValues();
// values.put(BRSQLiteHelper.PEER_COLUMN_ID, peer.getId());
values.put(BRSQLiteHelper.PEER_ADDRESS, peer.getAddress());
values.put(BRSQLiteHelper.PEER_MISBEHAVIN, peer.getMisbehavin());
values.put(BRSQLiteHelper.PEER_PORT, peer.getPort());
values.put(BRSQLiteHelper.PEER_SERVICES, peer.getServices());
values.put(BRSQLiteHelper.PEER_TIME_STAMP, peer.getTimeStamp());
long insertId = database.insert(BRSQLiteHelper.PEER_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.PEER_TABLE_NAME,
allColumns, BRSQLiteHelper.PEER_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRPeerEntity peerEntity = cursorToPeer(cursor);
cursor.close();
return peerEntity;
}
public void deletePeer(BRPeerEntity peerEntity) {
long id = peerEntity.getId();
Log.e(TAG, "Peer deleted with id: " + id);
database.delete(BRSQLiteHelper.PEER_TABLE_NAME, BRSQLiteHelper.PEER_COLUMN_ID
+ " = " + id, null);
}
public List<BRPeerEntity> getAllPeers() {
List<BRPeerEntity> peers = new ArrayList<>();
Cursor cursor = database.query(BRSQLiteHelper.PEER_TABLE_NAME,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
BRPeerEntity peerEntity = cursorToPeer(cursor);
peers.add(peerEntity);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return peers;
}
private BRPeerEntity cursorToPeer(Cursor cursor) {
BRPeerEntity peerEntity = new BRPeerEntity();
peerEntity.setId(cursor.getInt(0));
peerEntity.setAddress(cursor.getInt(1));
peerEntity.setMisbehavin(cursor.getShort(2));
peerEntity.setPort(cursor.getShort(3));
peerEntity.setServices(cursor.getShort(4));
peerEntity.setTimeStamp(cursor.getLong(5));
return peerEntity;
}
}

137
app/src/main/java/com/breadwallet/tools/sqlite/TransactionDataSource.java

@ -0,0 +1,137 @@
package com.breadwallet.tools.sqlite;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import com.breadwallet.tools.sqlite.entities.BRTransactionEntity;
import com.breadwallet.tools.sqlite.entities.BRTxInputEntity;
import com.breadwallet.tools.sqlite.entities.BRTxOutputEntity;
import java.util.ArrayList;
import java.util.List;
public class TransactionDataSource {
public static final String TAG = TransactionDataSource.class.getName();
// Database fields
private SQLiteDatabase database;
private BRSQLiteHelper dbHelper;
private String[] allColumns = {
BRSQLiteHelper.TX_COLUMN_ID, BRSQLiteHelper.TX_BLOCK_HEIGHT, BRSQLiteHelper.TX_LOCK_TIME,
BRSQLiteHelper.TX_TIME_STAMP, BRSQLiteHelper.TX_HASH
};
public TransactionDataSource(Context context) {
dbHelper = new BRSQLiteHelper(context);
}
public void open() throws SQLException {
database = dbHelper.getWritableDatabase();
}
public void close() {
dbHelper.close();
}
public BRTransactionEntity createTransaction(BRTransactionEntity transactionEntity) {
ContentValues values = new ContentValues();
// values.put(BRSQLiteHelper.TX_COLUMN_ID, transactionEntity.getId());
values.put(BRSQLiteHelper.TX_BLOCK_HEIGHT, transactionEntity.getBlockHeight());
values.put(BRSQLiteHelper.TX_LOCK_TIME, transactionEntity.getLockTime());
values.put(BRSQLiteHelper.TX_TIME_STAMP, transactionEntity.getTimeStamp());
values.put(BRSQLiteHelper.TX_HASH, transactionEntity.getTxHash());
for(BRTxInputEntity input : transactionEntity.getInputs()){
ContentValues inputValues = new ContentValues();
inputValues.put(BRSQLiteHelper.IN_INDEX,input.getIndex());
inputValues.put(BRSQLiteHelper.IN_PREV_OUT_INDEX, input.getPrevOutIndex());
inputValues.put(BRSQLiteHelper.IN_PREV_OUT_TX_HASH, input.getPrevOutTxHash());
inputValues.put(BRSQLiteHelper.IN_SEQUENCE, input.getSequence());
inputValues.put(BRSQLiteHelper.IN_SIGNATURE, input.getSignatures());
database.insert(BRSQLiteHelper.IN_TABLE_NAME, null, values);
}
for(BRTxOutputEntity output : transactionEntity.getOutputs()){
ContentValues outputValues = new ContentValues();
outputValues.put(BRSQLiteHelper.OUT_INDEX,output.getIndex());
outputValues.put(BRSQLiteHelper.OUT_TX_HASH, output.getTxHash());
outputValues.put(BRSQLiteHelper.OUT_VALUE, output.getValue());
database.insert(BRSQLiteHelper.OUT_TABLE_NAME, null, values);
}
long insertId = database.insert(BRSQLiteHelper.TX_TABLE_NAME, null, values);
Cursor cursor = database.query(BRSQLiteHelper.TX_TABLE_NAME,
allColumns, BRSQLiteHelper.TX_COLUMN_ID + " = " + insertId, null,
null, null, null);
cursor.moveToFirst();
BRTransactionEntity transactionEntity1 = cursorToTransaction(cursor);
cursor.close();
return transactionEntity1;
}
public void deleteTransaction(BRTransactionEntity transaction) {
long id = transaction.getId();
Log.e(TAG, "transaction deleted with id: " + id);
database.delete(BRSQLiteHelper.TX_TABLE_NAME, BRSQLiteHelper.TX_COLUMN_ID
+ " = " + id, null);
}
public List<BRTransactionEntity> getAllTransactions() {
List<BRTransactionEntity> transactions = new ArrayList<>();
Cursor cursor = database.query(BRSQLiteHelper.TX_TABLE_NAME,
allColumns, null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
BRTransactionEntity transactionEntity = cursorToTransaction(cursor);
transactions.add(transactionEntity);
cursor.moveToNext();
}
// make sure to close the cursor
cursor.close();
return transactions;
}
private BRTransactionEntity cursorToTransaction(Cursor cursor) {
BRTransactionEntity transactionEntity = new BRTransactionEntity();
transactionEntity.setId(cursor.getInt(0));
transactionEntity.setBlockHeight(cursor.getInt(1));
transactionEntity.setLockTime(cursor.getInt(2));
transactionEntity.setTimeStamp(cursor.getInt(3));
transactionEntity.setTxHash(cursor.getBlob(4));
return transactionEntity;
}
}

138
app/src/main/java/com/breadwallet/tools/sqlite/entities/BRMerkleBlockEntity.java

@ -0,0 +1,138 @@
package com.breadwallet.tools.sqlite.entities;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class BRMerkleBlockEntity {
private long id;
private byte[] blockHash = new byte[32];
private byte[] flags = new byte[32];
private byte[] hashes = new byte[32];
private int height;
private byte[] merkleRoot = new byte[32];
private int nonce;
private byte[] prevBlock = new byte[32];
private int target;
private long timeStamp;
private int totalTransactions;
private int version;
public byte[] getBlockHash() {
return blockHash;
}
public void setBlockHash(byte[] blockHash) {
this.blockHash = blockHash;
}
public byte[] getFlags() {
return flags;
}
public void setFlags(byte[] flags) {
this.flags = flags;
}
public byte[] getHashes() {
return hashes;
}
public void setHashes(byte[] hashes) {
this.hashes = hashes;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public byte[] getMerkleRoot() {
return merkleRoot;
}
public void setMerkleRoot(byte[] merkleRoot) {
this.merkleRoot = merkleRoot;
}
public int getNonce() {
return nonce;
}
public void setNonce(int nonce) {
this.nonce = nonce;
}
public byte[] getPrevBlock() {
return prevBlock;
}
public void setPrevBlock(byte[] prevBlock) {
this.prevBlock = prevBlock;
}
public int getTarget() {
return target;
}
public void setTarget(int target) {
this.target = target;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
public int getTotalTransactions() {
return totalTransactions;
}
public void setTotalTransactions(int totalTransactions) {
this.totalTransactions = totalTransactions;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
}

61
app/src/main/java/com/breadwallet/wallet/BRAddress.java → app/src/main/java/com/breadwallet/tools/sqlite/entities/BRPeerEntity.java

@ -1,9 +1,9 @@
package com.breadwallet.wallet; package com.breadwallet.tools.sqlite.entities;
/** /**
* BreadWallet * BreadWallet
* <p/> * <p/>
* Created by Mihail on 9/23/15. * Created by Mihail on 9/29/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com> * Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/> * <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@ -24,5 +24,60 @@ package com.breadwallet.wallet;
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
public class BRAddress { public class BRPeerEntity {
private int id;
private int address;
private short misbehavin;
private short port;
private short services;
private long timeStamp;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getAddress() {
return address;
}
public void setAddress(int address) {
this.address = address;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
public short getMisbehavin() {
return misbehavin;
}
public void setMisbehavin(short misbehavin) {
this.misbehavin = misbehavin;
}
public short getPort() {
return port;
}
public void setPort(short port) {
this.port = port;
}
public short getServices() {
return services;
}
public void setServices(short services) {
this.services = services;
}
} }

93
app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTransactionEntity.java

@ -0,0 +1,93 @@
package com.breadwallet.tools.sqlite.entities;
import java.util.HashSet;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/23/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class BRTransactionEntity {
private int id;
private int blockHeight;
private int lockTime;
private long timeStamp;
private byte[] txHash = new byte[32];
private HashSet<BRTxInputEntity> inputs;
private HashSet<BRTxOutputEntity> outputs;
public int getBlockHeight() {
return blockHeight;
}
public void setBlockHeight(int blockHeight) {
this.blockHeight = blockHeight;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public HashSet<BRTxInputEntity> getInputs() {
return inputs;
}
public void setInputs(HashSet<BRTxInputEntity> inputs) {
this.inputs = inputs;
}
public int getLockTime() {
return lockTime;
}
public void setLockTime(int lockTime) {
this.lockTime = lockTime;
}
public HashSet<BRTxOutputEntity> getOutputs() {
return outputs;
}
public void setOutputs(HashSet<BRTxOutputEntity> outputs) {
this.outputs = outputs;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
public byte[] getTxHash() {
return txHash;
}
public void setTxHash(byte[] txHash) {
this.txHash = txHash;
}
}

94
app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTxInputEntity.java

@ -0,0 +1,94 @@
package com.breadwallet.tools.sqlite.entities;
import java.io.Serializable;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class BRTxInputEntity implements Serializable {
private int id;
private int index;
private byte[] prevOutTxHash;
private int prevOutIndex;
private int sequence;
private byte[] signatures = new byte[32];
private byte[] txHash = new byte[32];
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public int getPrevOutIndex() {
return prevOutIndex;
}
public void setPrevOutIndex(int prevOutIndex) {
this.prevOutIndex = prevOutIndex;
}
public byte[] getPrevOutTxHash() {
return prevOutTxHash;
}
public void setPrevOutTxHash(byte[] prevOutTxHash) {
this.prevOutTxHash = prevOutTxHash;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getSequence() {
return sequence;
}
public void setSequence(int sequence) {
this.sequence = sequence;
}
public byte[] getSignatures() {
return signatures;
}
public void setSignatures(byte[] signatures) {
this.signatures = signatures;
}
public byte[] getTxHash() {
return txHash;
}
public void setTxHash(byte[] txHash) {
this.txHash = txHash;
}
}

54
app/src/main/java/com/breadwallet/wallet/BRMasterPubKey.java → app/src/main/java/com/breadwallet/tools/sqlite/entities/BRTxOutputEntity.java

@ -1,9 +1,11 @@
package com.breadwallet.wallet; package com.breadwallet.tools.sqlite.entities;
import java.io.Serializable;
/** /**
* BreadWallet * BreadWallet
* <p/> * <p/>
* Created by Mihail on 9/23/15. * Created by Mihail on 9/25/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com> * Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/> * <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
@ -24,5 +26,51 @@ package com.breadwallet.wallet;
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
public class BRMasterPubKey { public class BRTxOutputEntity implements Serializable {
private int index;
private char[] address;
private byte[] script;
private byte[] txHash;
private long value;
public int getIndex() {
return index;
}
public void setIndex(int index) {
this.index = index;
}
public char[] getAddress() {
return address;
}
public void setAddress(char[] arr) {
this.address = arr;
}
public byte[] getScript() {
return script;
}
public void setScript(byte[] script) {
this.script = script;
}
public byte[] getTxHash() {
return txHash;
}
public void setTxHash(byte[] txHash) {
this.txHash = txHash;
}
public long getValue() {
return value;
}
public void setValue(long value) {
this.value = value;
}
} }

28
app/src/main/java/com/breadwallet/wallet/BRTransaction.java

@ -1,28 +0,0 @@
package com.breadwallet.wallet;
/**
* BreadWallet
* <p/>
* Created by Mihail on 9/23/15.
* Copyright (c) 2015 Mihail Gutan <mihail@breadwallet.com>
* <p/>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p/>
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* <p/>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
public class BRTransaction {
}

23
app/src/main/java/com/breadwallet/wallet/BRWallet.java

@ -1,5 +1,7 @@
package com.breadwallet.wallet; package com.breadwallet.wallet;
import com.breadwallet.tools.sqlite.entities.BRTransactionEntity;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -42,19 +44,21 @@ public class BRWallet {
final ByteBuffer buf = ByteBuffer.wrap(bytes); final ByteBuffer buf = ByteBuffer.wrap(bytes);
wallet.walletBuff = buf; wallet.walletBuff = buf;
// If needed: buf.order(ByteOrder.LITTLE_ENDIAN); // If needed: buf.order(ByteOrder.LITTLE_ENDIAN);
// Example to convert unsigned short to a positive int // Example to convert unsigned short to a positive int
return wallet; return wallet;
} }
public native static void updateWallet();
public native ByteBuffer walletNew();
public native long walletBalance(); public native long walletBalance();
public native List<BRUTXO> walletUTXOs(); public native List<BRUTXO> walletUTXOs();
public native List<BRTransaction> walletTransactions(); public native List<BRTransactionEntity> walletTransactions();
public native long walletTotalSent(); public native long walletTotalSent();
@ -62,6 +66,19 @@ public class BRWallet {
public native void walletSetFeePerKb(); public native void walletSetFeePerKb();
public native char[] walletReceiveAddress();
public native char[] walletChangeAddress();
public native boolean walletContainsTxHash();
public native boolean walletContainsAddress();
public native boolean walletAddressIsUsed();
public native BRTransactionEntity walletCreateTransaction();
public native boolean walletSignTransaction();
private class BRUTXO { private class BRUTXO {
BigInteger hash; BigInteger hash;

8
app/src/main/java/com/breadwallet/wallet/BRWalletManager.java

@ -1,6 +1,7 @@
package com.breadwallet.wallet; package com.breadwallet.wallet;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.SecureRandom;
import java.text.NumberFormat; import java.text.NumberFormat;
import java.util.List; import java.util.List;
@ -104,10 +105,15 @@ public class BRWalletManager {
* generates a random seed, saves to keychain and returns the associated seedPhrase * generates a random seed, saves to keychain and returns the associated seedPhrase
*/ */
public String generateRandomSeed() { public String generateRandomSeed() {
final SecureRandom sr = new SecureRandom();
final byte[] keyBytes = new byte[128];
sr.nextBytes(keyBytes);
return null; return null;
} }
public native String encodePhrase(byte[] seed);
/** /**
* authenticates user and returns seed * authenticates user and returns seed
*/ */
@ -199,7 +205,7 @@ public class BRWalletManager {
return false; return false;
} }
public void updateFeePerKb(){ public void updateFeePerKb() {
} }

1
app/src/main/jni/breadwallet-core

@ -0,0 +1 @@
Subproject commit 11e35d689ae7655a15df20668536028d9b68f411

18
app/src/main/jni/transition/core.c

@ -0,0 +1,18 @@
//
// Created by Mihail Gutan on 9/24/15.
//
#include "stdio.h"
#include "core.h"
JNIEXPORT void Java_com_breadwallet_presenter_activities_MainActivity_sendMethodCallBack
(JNIEnv *env, jobject obj){
jclass cls = (*env)->GetObjectClass(env, obj);
jmethodID mid = (*env)->GetMethodID(env, cls, "callback", "()V");
if (mid == 0)
return;
(*env)->CallVoidMethod(env, obj, mid);
};
JNIEXPORT jbyteArray Java_com_breadwallet_wallet_BRWalletManager_encodePhrase
(JNIEnv *env, jobject obj, jbyteArray seed){
}

11
app/src/main/jni/transition/core.h

@ -0,0 +1,11 @@
//
// Created by Mihail Gutan on 9/24/15.
//
#include <jni.h>
#ifndef BREADWALLET_CORE_H
#define BREADWALLET_CORE_H
#endif //BREADWALLET_CORE_H
JNIEXPORT void Java_com_breadwallet_presenter_activities_MainActivity_sendMethodCallBack
(JNIEnv *env, jobject thiz);

8
app/src/main/jni/transition/testingStuff.c

@ -0,0 +1,8 @@
#include <jni.h>
//#define DEBUG_TAG "NDK_AndroidNDK1SampleActivity"
JNIEXPORT jstring Java_com_breadwallet_presenter_activities_MainActivity_messageFromNativeCode
(JNIEnv *env, jobject this, jstring logThis) {
const char *nativeString = (*env)->GetStringUTFChars(env, logThis, 0);
return (*env)->NewStringUTF(env, nativeString);
}

2
app/src/main/res/layouts/layout/currency_list_item.xml

@ -5,7 +5,7 @@
android:orientation="vertical" android:orientation="vertical"
android:id="@+id/list_item_layout"> android:id="@+id/list_item_layout">
<com.breadwallet.tools.others.AutoResizeTextView xmlns:android="http://schemas.android.com/apk/res/android" <com.breadwallet.tools.AutoResizeTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/currency_item_text" android:id="@+id/currency_item_text"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

Loading…
Cancel
Save