C# Class BitSharper.Transaction

Inheritance: Message
Show file Open project: TangibleCryptography/BitSharper Class Usage Examples

Private Properties

Property Type Description
AddBlockAppearance void
ConnectForReorganize TransactionInput
DisconnectInputs bool
GetValueSentToMe ulong
HashTransactionForSignature byte[]
Transaction System

Public Methods

Method Description
AddInput ( TransactionInput input ) : void

Adds an input directly, with no checking that it's valid.

AddInput ( TransactionOutput from ) : void

Adds an input to this transaction that imports value from the given output. Note that this input is NOT complete and after every input is added with addInput() and every output is added with addOutput(), signInputs() must be called to finalize the transaction and finish the inputs off. Otherwise it won't be accepted by the network.

AddOutput ( TransactionOutput to ) : void

Adds the given output to this transaction. The output must be completely initialized.

BitcoinSerializeToStream ( Stream stream ) : void
Equals ( object other ) : bool
GetHashCode ( ) : int
GetValueSentFromMe ( Wallet wallet ) : ulong

Calculates the sum of the inputs that are spending coins with keys in the wallet. This requires the transactions sending coins to those keys to be in the wallet. This method will not attempt to download the blocks containing the input transactions if the key is in the wallet but the transactions are not.

GetValueSentToMe ( Wallet wallet ) : ulong

Calculates the sum of the outputs that are sending coins to a key in the wallet.

IsEveryOutputSpent ( ) : bool
SignInputs ( SigHash hashType, Wallet wallet ) : void

Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated. The signature is over the transaction itself, to prove the redeemer actually created that transaction, so we have to do this step last.

This method is similar to SignatureHash in script.cpp

ToString ( ) : string
Transaction ( NetworkParameters @params, byte payloadBytes ) : System

Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.

Transaction ( NetworkParameters @params, byte payload, int offset ) : System

Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.

Protected Methods

Method Description
Parse ( ) : void

Private Methods

Method Description
AddBlockAppearance ( StoredBlock block ) : void

Adds the given block to the internal serializable set of blocks in which this transaction appears. This is used by the wallet to ensure transactions that appear on side chains are recorded properly even though the block stores do not save the transaction data at all.

ConnectForReorganize ( Transaction>.IDictionary transactions ) : TransactionInput

Connects all inputs using the provided transactions. If any input cannot be connected returns that input or null on success.

DisconnectInputs ( ) : bool
GetValueSentToMe ( Wallet wallet, bool includeSpent ) : ulong

Calculates the sum of the outputs that are sending coins to a key in the wallet. The flag controls whether to include spent outputs or not.

HashTransactionForSignature ( SigHash type, bool anyoneCanPay ) : byte[]
Transaction ( NetworkParameters @params ) : System

Method Details

AddInput() public method

Adds an input directly, with no checking that it's valid.
public AddInput ( TransactionInput input ) : void
input TransactionInput
return void

AddInput() public method

Adds an input to this transaction that imports value from the given output. Note that this input is NOT complete and after every input is added with addInput() and every output is added with addOutput(), signInputs() must be called to finalize the transaction and finish the inputs off. Otherwise it won't be accepted by the network.
public AddInput ( TransactionOutput from ) : void
from TransactionOutput
return void

AddOutput() public method

Adds the given output to this transaction. The output must be completely initialized.
public AddOutput ( TransactionOutput to ) : void
to TransactionOutput
return void

BitcoinSerializeToStream() public method

public BitcoinSerializeToStream ( Stream stream ) : void
stream Stream
return void

Equals() public method

public Equals ( object other ) : bool
other object
return bool

GetHashCode() public method

public GetHashCode ( ) : int
return int

GetValueSentFromMe() public method

Calculates the sum of the inputs that are spending coins with keys in the wallet. This requires the transactions sending coins to those keys to be in the wallet. This method will not attempt to download the blocks containing the input transactions if the key is in the wallet but the transactions are not.
public GetValueSentFromMe ( Wallet wallet ) : ulong
wallet Wallet
return ulong

GetValueSentToMe() public method

Calculates the sum of the outputs that are sending coins to a key in the wallet.
public GetValueSentToMe ( Wallet wallet ) : ulong
wallet Wallet
return ulong

IsEveryOutputSpent() public method

public IsEveryOutputSpent ( ) : bool
return bool

Parse() protected method

protected Parse ( ) : void
return void

SignInputs() public method

Once a transaction has some inputs and outputs added, the signatures in the inputs can be calculated. The signature is over the transaction itself, to prove the redeemer actually created that transaction, so we have to do this step last.
This method is similar to SignatureHash in script.cpp
public SignInputs ( SigHash hashType, Wallet wallet ) : void
hashType SigHash This should always be set to SigHash.ALL currently. Other types are unused.
wallet Wallet A wallet is required to fetch the keys needed for signing.
return void

ToString() public method

public ToString ( ) : string
return string

Transaction() public method

Creates a transaction from the given serialized bytes, eg, from a block or a tx network message.
public Transaction ( NetworkParameters @params, byte payloadBytes ) : System
@params NetworkParameters
payloadBytes byte
return System

Transaction() public method

Creates a transaction by reading payload starting from offset bytes in. Length of a transaction is fixed.
public Transaction ( NetworkParameters @params, byte payload, int offset ) : System
@params NetworkParameters
payload byte
offset int
return System