C# Class BitSharper.Wallet

Afficher le fichier Open project: TangibleCryptography/BitSharper Class Usage Examples

Private Properties

Свойство Type Description
ConfirmSend void
CreateSend Transaction
CreateSend Transaction
GetPoolSize int
MaybeMoveTxToSpent void
ProcessTxFromBestChain void
Receive void
Receive void
Reorganize void
ReprocessTxAfterReorg void
UpdateForSpends void

Méthodes publiques

Méthode Description
AddKey ( EcKey key ) : void

Adds the given ECKey to the wallet. There is currently no way to delete keys (that would result in coin loss).

FindKeyFromPubHash ( byte pubkeyHash ) : EcKey

Locates a keypair from the keychain given the hash of the public key. This is needed when finding out which key we need to use to redeem a transaction output.

FindKeyFromPubKey ( byte pubkey ) : EcKey

Locates a keypair from the keychain given the raw public key bytes.

GetBalance ( ) : ulong

Returns the available balance of this wallet. See 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, ulong).

GetBalance ( BalanceType balanceType ) : ulong

Returns the balance of this wallet as calculated by the provided balanceType.

IsPubKeyHashMine ( byte pubkeyHash ) : bool

Returns true if this wallet contains a public key which hashes to the given hash.

IsPubKeyMine ( byte pubkey ) : bool

Returns true if this wallet contains a keypair with the given public key.

LoadFromFile ( FileInfo f ) : Wallet

Returns a wallet deserialized from the given file.

LoadFromFileStream ( FileStream f ) : Wallet

Returns a wallet deserialized from the given file input stream.

SaveToFile ( FileInfo f ) : void

Uses Java serialization to save the wallet to the given file.

SaveToFileStream ( FileStream f ) : void

Uses Java serialization to save the wallet to the given file stream.

SendCoins ( Peer peer, Address to, ulong nanocoins ) : Transaction

Sends coins to the given address, via the given Peer. Change is returned to the first key in the wallet.

SendCoins ( PeerGroup peerGroup, Address to, ulong nanocoins ) : Transaction

Sends coins to the given address, via the given PeerGroup. Change is returned to the first key in the wallet.

ToString ( ) : string
Wallet ( NetworkParameters @params ) : System

Creates a new, empty wallet with no keys and no transactions. If you want to restore a wallet from disk instead, see loadFromFile.

Private Methods

Méthode Description
ConfirmSend ( Transaction tx ) : void

Call this when we have successfully transmitted the send tx to the network, to update the wallet.

CreateSend ( Address address, ulong nanocoins ) : Transaction

Statelessly creates a transaction that sends the given number of nanocoins to address. The change is sent to the first address in the wallet, so you must have added at least one key.

This method is stateless in the sense that calling it twice with the same inputs will result in two Transaction objects which are equal. The wallet is not updated to track its pending status or to mark the coins as spent until confirmSend is called on the result.

CreateSend ( Address address, ulong nanocoins, Address changeAddress ) : Transaction

Creates a transaction that sends $coins.$cents BTC to the given address.

IMPORTANT: This method does NOT update the wallet. If you call createSend again you may get two transactions that spend the same coins. You have to call confirmSend on the created transaction to prevent this, but that should only occur once the transaction has been accepted by the network. This implies you cannot have more than one outstanding sending tx at once.

GetPoolSize ( Pool pool ) : int
MaybeMoveTxToSpent ( Transaction tx, String context ) : void

If the transactions outputs are all marked as spent, and it's in the unspent map, move it.

ProcessTxFromBestChain ( Transaction tx ) : void

Handle when a transaction becomes newly active on the best chain, either due to receiving a new block or a re-org making inactive transactions active.

Receive ( Transaction tx, StoredBlock block, BlockChain blockType ) : void

Called by the BlockChain when we receive a new block that sends coins to one of our addresses or spends coins from one of our addresses (note that a single transaction can do both).

This is necessary for the internal book-keeping Wallet does. When a transaction is received that sends us coins it is added to a pool so we can use it later to create spends. When a transaction is received that consumes outputs they are marked as spent so they won't be used in future.

A transaction that spends our own coins can be received either because a spend we created was accepted by the network and thus made it into a block, or because our keys are being shared between multiple instances and some other node spent the coins instead. We still have to know about that to avoid accidentally trying to double spend.

A transaction may be received multiple times if is included into blocks in parallel chains. The blockType parameter describes whether the containing block is on the main/best chain or whether it's on a presently inactive side chain. We must still record these transactions and the blocks they appear in because a future block might change which chain is best causing a reorganize. A re-org can totally change our balance!

Receive ( Transaction tx, StoredBlock block, BlockChain blockType, bool reorg ) : void
Reorganize ( IList oldBlocks, IList newBlocks ) : void

Called by the BlockChain when the best chain (representing total work done) has changed. In this case, we need to go through our transactions and find out if any have become invalid. It's possible for our balance to go down in this case: money we thought we had can suddenly vanish if the rest of the network agrees it should be so.

The oldBlocks/newBlocks lists are ordered height-wise from top first to bottom last.

ReprocessTxAfterReorg ( Transaction>.IDictionary pool, Transaction tx ) : void
UpdateForSpends ( Transaction tx ) : void

Updates the wallet by checking if this TX spends any of our outputs. This is not used normally because when we receive our own spends, we've already marked the outputs as spent previously (during tx creation) so there's no need to go through and do it again.

Method Details

AddKey() public méthode

Adds the given ECKey to the wallet. There is currently no way to delete keys (that would result in coin loss).
public AddKey ( EcKey key ) : void
key EcKey
Résultat void

FindKeyFromPubHash() public méthode

Locates a keypair from the keychain given the hash of the public key. This is needed when finding out which key we need to use to redeem a transaction output.
public FindKeyFromPubHash ( byte pubkeyHash ) : EcKey
pubkeyHash byte
Résultat EcKey

FindKeyFromPubKey() public méthode

Locates a keypair from the keychain given the raw public key bytes.
public FindKeyFromPubKey ( byte pubkey ) : EcKey
pubkey byte
Résultat EcKey

GetBalance() public méthode

Returns the available balance of this wallet. See 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, ulong).
public GetBalance ( ) : ulong
Résultat ulong

GetBalance() public méthode

Returns the balance of this wallet as calculated by the provided balanceType.
public GetBalance ( BalanceType balanceType ) : ulong
balanceType BalanceType
Résultat ulong

IsPubKeyHashMine() public méthode

Returns true if this wallet contains a public key which hashes to the given hash.
public IsPubKeyHashMine ( byte pubkeyHash ) : bool
pubkeyHash byte
Résultat bool

IsPubKeyMine() public méthode

Returns true if this wallet contains a keypair with the given public key.
public IsPubKeyMine ( byte pubkey ) : bool
pubkey byte
Résultat bool

LoadFromFile() public static méthode

Returns a wallet deserialized from the given file.
public static LoadFromFile ( FileInfo f ) : Wallet
f System.IO.FileInfo
Résultat Wallet

LoadFromFileStream() public static méthode

Returns a wallet deserialized from the given file input stream.
public static LoadFromFileStream ( FileStream f ) : Wallet
f System.IO.FileStream
Résultat Wallet

SaveToFile() public méthode

Uses Java serialization to save the wallet to the given file.
public SaveToFile ( FileInfo f ) : void
f System.IO.FileInfo
Résultat void

SaveToFileStream() public méthode

Uses Java serialization to save the wallet to the given file stream.
public SaveToFileStream ( FileStream f ) : void
f System.IO.FileStream
Résultat void

SendCoins() public méthode

Sends coins to the given address, via the given Peer. Change is returned to the first key in the wallet.
If there was a problem broadcasting the transaction.
public SendCoins ( Peer peer, Address to, ulong nanocoins ) : Transaction
peer Peer The peer to send via.
to Address Which address to send coins to.
nanocoins ulong How many nanocoins to send. You can use Utils.ToNanoCoins() to calculate this.
Résultat Transaction

SendCoins() public méthode

Sends coins to the given address, via the given PeerGroup. Change is returned to the first key in the wallet.
If there was a problem broadcasting the transaction.
public SendCoins ( PeerGroup peerGroup, Address to, ulong nanocoins ) : Transaction
peerGroup PeerGroup The peer group to send via.
to Address Which address to send coins to.
nanocoins ulong How many nanocoins to send. You can use Utils.toNanoCoins() to calculate this.
Résultat Transaction

ToString() public méthode

public ToString ( ) : string
Résultat string

Wallet() public méthode

Creates a new, empty wallet with no keys and no transactions. If you want to restore a wallet from disk instead, see loadFromFile.
public Wallet ( NetworkParameters @params ) : System
@params NetworkParameters
Résultat System