|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.bitcoin.core.Wallet
public class Wallet
A Wallet stores keys and a record of transactions that have not yet been spent. Thus, it is capable of providing transactions on demand that meet a given combined value.
The Wallet is read and written from disk, so be sure to follow the Java serialization versioning rules here. We use the built in Java serialization to avoid the need to pull in a potentially large (code-size) third party serialization library.
Nested Class Summary | |
---|---|
static class |
Wallet.BalanceType
It's possible to calculate a wallets balance from multiple points of view. |
Field Summary | |
---|---|
ArrayList<ECKey> |
keychain
A list of public/private EC keys owned by this user. |
Constructor Summary | |
---|---|
Wallet(NetworkParameters params)
Creates a new, empty wallet with no keys and no transactions. |
Method Summary | |
---|---|
void |
addEventListener(WalletEventListener listener)
Adds an event listener object. |
void |
addKey(ECKey key)
Adds the given ECKey to the wallet. |
ECKey |
findKeyFromPubHash(byte[] pubkeyHash)
Locates a keypair from the keychain given the hash of the public key. |
ECKey |
findKeyFromPubKey(byte[] pubkey)
Locates a keypair from the keychain given the raw public key bytes. |
BigInteger |
getBalance()
Returns the AVAILABLE balance of this wallet. |
BigInteger |
getBalance(Wallet.BalanceType balanceType)
Returns the balance of this wallet as calculated by the provided balanceType. |
Collection<Transaction> |
getPendingTransactions()
Returns an immutable view of the transactions currently waiting for network confirmations. |
boolean |
isPubKeyHashMine(byte[] pubkeyHash)
Returns true if this wallet contains a public key which hashes to the given hash. |
boolean |
isPubKeyMine(byte[] pubkey)
Returns true if this wallet contains a keypair with the given public key. |
static Wallet |
loadFromFile(File f)
Returns a wallet deserialized from the given file. |
static Wallet |
loadFromFileStream(FileInputStream f)
Returns a wallet deserialied from the given file input stream. |
void |
saveToFile(File f)
Uses Java serialization to save the wallet to the given file. |
void |
saveToFileStream(FileOutputStream f)
Uses Java serialization to save the wallet to the given file stream. |
Transaction |
sendCoins(Peer peer,
Address to,
BigInteger nanocoins)
Sends coins to the given address, via the given Peer . |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public final ArrayList<ECKey> keychain
Constructor Detail |
---|
public Wallet(NetworkParameters params)
Method Detail |
---|
public void saveToFile(File f) throws IOException
IOException
public void saveToFileStream(FileOutputStream f) throws IOException
IOException
public static Wallet loadFromFile(File f) throws IOException
IOException
public static Wallet loadFromFileStream(FileInputStream f) throws IOException
IOException
public void addEventListener(WalletEventListener listener)
Threading: Event listener methods are dispatched on library provided threads and the both the wallet and the listener objects are locked during dispatch, so your listeners do not have to be thread safe. However they should not block as the Peer will be unresponsive to network traffic whilst your listener is running.
public Transaction sendCoins(Peer peer, Address to, BigInteger nanocoins) throws IOException
Peer
. Change is returned to the first key in the wallet.
to
- Which address to send coins to.nanocoins
- How many nanocoins to send. You can use Utils.toNanoCoins() to calculate this.
Transaction
that was created or null if there was insufficient balance to send the coins.
IOException
- if there was a problem broadcasting the transactionpublic void addKey(ECKey key)
public ECKey findKeyFromPubHash(byte[] pubkeyHash)
public boolean isPubKeyHashMine(byte[] pubkeyHash)
public ECKey findKeyFromPubKey(byte[] pubkey)
public boolean isPubKeyMine(byte[] pubkey)
public BigInteger getBalance()
Wallet.BalanceType.AVAILABLE
for details on what this
means.
Note: the estimated balance is usually the one you want to show to the end user - however attempting to
actually spend these coins may result in temporary failure. This method returns how much you can safely
provide to createSend(Address, java.math.BigInteger)
.
public BigInteger getBalance(Wallet.BalanceType balanceType)
public String toString()
toString
in class Object
public Collection<Transaction> getPendingTransactions()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |