Android Open Source - bitcoin-wallet Wallet






From Project

Back to project page bitcoin-wallet.

License

The source code is released under:

Copyright (C) 2011 by Caleb Anderson 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 ...

If you think the Android project bitcoin-wallet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.dirtyfilthy.bitcoin.wallet;
//  www.  j a  v a  2 s . co  m
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.security.cert.CertificateException;


import net.dirtyfilthy.bitcoin.core.BlockChain;
import net.dirtyfilthy.bitcoin.core.BlockStore;
import net.dirtyfilthy.bitcoin.protocol.ConnectionHandler;
import net.dirtyfilthy.bouncycastle.jce.provider.BouncyCastleProvider;
import android.content.Context;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
 
public class Wallet {
  private KeyRing keyRing;
  public static final String SECURITY_PROVIDER="DFBC";
  private SQLiteDatabase db;
  private Context context;
  private SqlBlockStore blockStore;
  private BlockChain blockChain=new BlockChain();
  private ConnectionHandler connectionHandler=new ConnectionHandler();
  public static final int DATABASE_VERSION=1;
  public Wallet(Context c, String db_filepath, String password) throws FileNotFoundException, KeyStoreException, InvalidPasswordException{
    if(Security.getProvider(SECURITY_PROVIDER)==null){
      Security.addProvider(new BouncyCastleProvider());
    }
    this.context=c;
    db=new OpenHelper(context,db_filepath).getWritableDatabase();
    try {
      blockStore=new SqlBlockStore(db);
      blockChain.setBlockStore(blockStore);
      connectionHandler.setBlockChain(blockChain);
    }
    catch (SQLiteConstraintException e) {
      db.close();
      throw e;
    }
    try {
      keyRing=new KeyRing(c, db, password);
    } catch (NoSuchAlgorithmException e) {
      throw new KeyStoreException(e);
    } catch (NoSuchProviderException e) {
      throw new KeyStoreException(e);
    } catch (InvalidAlgorithmParameterException e) {
      throw new KeyStoreException(e);
    } catch (KeyStoreException e) {
      throw new KeyStoreException(e);
    } catch (CertificateException e) {
      throw new InvalidPasswordException(e);
    } catch (FileNotFoundException e) {
      
    } catch (IOException e) {
      throw new KeyStoreException(e);
    }
    
    
  }
  
  public void close(){
    db.close();
  }
  
  public ConnectionHandler getConnectionHandler(){
    return this.connectionHandler;
  }
  

  private static class OpenHelper extends SQLiteOpenHelper{
    OpenHelper(Context context,String filename) {
      super(context, filename , null, 1);

    }
    
    public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE keys (id INTEGER PRIMARY KEY AUTOINCREMENT, base58hash160 VARCHAR, public_key BLOB, private_key BLOB, created_at INTEGER, label VARCHAR);");
      db.execSQL("CREATE TABLE blocks (id INTEGER PRIMARY KEY AUTOINCREMENT, hash BLOB UNIQUE NOT NULL, previous_hash BLOB NOT NULL, merkle_root BLOB NOT NULL, height INTEGER NOT NULL, total_work BLOB NOT NULL, timestamp INTEGER NOT NULL, nonce INTEGER NOT NULL, bits INTEGER NOT NULL);");
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
      db.execSQL("");
      
    }
  }
  
  public SQLiteDatabase getDb(){
    return db;
  }
  
  public SqlBlockStore getBlockStore(){
    return this.blockStore;
  }
  
  

}




Java Source Code List

net.dirtyfilthy.bitcoin.core.Address.java
net.dirtyfilthy.bitcoin.core.Base58Hash160.java
net.dirtyfilthy.bitcoin.core.BlockChain.java
net.dirtyfilthy.bitcoin.core.BlockExistsException.java
net.dirtyfilthy.bitcoin.core.BlockStore.java
net.dirtyfilthy.bitcoin.core.Block.java
net.dirtyfilthy.bitcoin.core.BtcValue.java
net.dirtyfilthy.bitcoin.core.ByteArrayable.java
net.dirtyfilthy.bitcoin.core.InvalidBlockException.java
net.dirtyfilthy.bitcoin.core.OpCode.java
net.dirtyfilthy.bitcoin.core.OpData.java
net.dirtyfilthy.bitcoin.core.OrphanBlockException.java
net.dirtyfilthy.bitcoin.core.Script.java
net.dirtyfilthy.bitcoin.core.TxIn.java
net.dirtyfilthy.bitcoin.core.TxOut.java
net.dirtyfilthy.bitcoin.core.Tx.java
net.dirtyfilthy.bitcoin.protocol.AddressBook.java
net.dirtyfilthy.bitcoin.protocol.AddressPacket.java
net.dirtyfilthy.bitcoin.protocol.BlockPacket.java
net.dirtyfilthy.bitcoin.protocol.ConnectionHandler.java
net.dirtyfilthy.bitcoin.protocol.Connection.java
net.dirtyfilthy.bitcoin.protocol.GetAddressPacket.java
net.dirtyfilthy.bitcoin.protocol.GetBlocksPacket.java
net.dirtyfilthy.bitcoin.protocol.GetDataPacket.java
net.dirtyfilthy.bitcoin.protocol.GetHeadersPacket.java
net.dirtyfilthy.bitcoin.protocol.HeadersPacket.java
net.dirtyfilthy.bitcoin.protocol.InventoryPacket.java
net.dirtyfilthy.bitcoin.protocol.InventoryVector.java
net.dirtyfilthy.bitcoin.protocol.IrcBootStrap.java
net.dirtyfilthy.bitcoin.protocol.MalformedPacketException.java
net.dirtyfilthy.bitcoin.protocol.PacketFactory.java
net.dirtyfilthy.bitcoin.protocol.PacketType.java
net.dirtyfilthy.bitcoin.protocol.Packet.java
net.dirtyfilthy.bitcoin.protocol.PingPacket.java
net.dirtyfilthy.bitcoin.protocol.ProtocolVersion.java
net.dirtyfilthy.bitcoin.protocol.ReplyPacket.java
net.dirtyfilthy.bitcoin.protocol.TxPacket.java
net.dirtyfilthy.bitcoin.protocol.VersionAckPacket.java
net.dirtyfilthy.bitcoin.protocol.VersionPacket.java
net.dirtyfilthy.bitcoin.util.Base58.java
net.dirtyfilthy.bitcoin.util.BigIntegerTools.java
net.dirtyfilthy.bitcoin.util.HashTools.java
net.dirtyfilthy.bitcoin.util.KeyTools.java
net.dirtyfilthy.bitcoin.util.MyHex.java
net.dirtyfilthy.bitcoin.wallet.ExposedSQLiteCursor.java
net.dirtyfilthy.bitcoin.wallet.InvalidPasswordException.java
net.dirtyfilthy.bitcoin.wallet.KeyRing.java
net.dirtyfilthy.bitcoin.wallet.SqlBlockStore.java
net.dirtyfilthy.bitcoin.wallet.Wallet.java