Documentation
¶
Index ¶
- Variables
- func AddUint64(a, b uint64) (uint64, error)
- func Int64ToUint64(a int64) (uint64, error)
- func Uint64ToInt64(a uint64) (int64, error)
- func VerifyTransactionCoinsSpending(uxIn UxArray, uxOut UxArray) error
- func VerifyTransactionHoursSpending(headTime uint64, uxIn UxArray, uxOut UxArray) error
- type AddressUxOuts
- type Block
- func (b Block) GetTransaction(txHash cipher.SHA256) (Transaction, bool)
- func (b Block) HashBody() cipher.SHA256
- func (b Block) HashHeader() cipher.SHA256
- func (b Block) PreHashHeader() cipher.SHA256
- func (b Block) Seq() uint64
- func (b Block) Size() int
- func (b Block) String() string
- func (b Block) Time() uint64
- type BlockBody
- type BlockHeader
- type FeeCalculator
- type HashPair
- type SignedBlock
- type SortableTransactions
- type Transaction
- func (txn *Transaction) Hash() cipher.SHA256
- func (txn *Transaction) HashInner() cipher.SHA256
- func (txn *Transaction) OutputHours() (uint64, error)
- func (txn *Transaction) PushInput(uxOut cipher.SHA256) uint16
- func (txn *Transaction) PushOutput(dst cipher.Address, coins, hours uint64)
- func (txn *Transaction) Serialize() []byte
- func (txn *Transaction) SignInputs(keys []cipher.SecKey)
- func (txn *Transaction) Size() int
- func (txn *Transaction) SizeHash() (int, cipher.SHA256)
- func (txn *Transaction) TxID() []byte
- func (txn *Transaction) TxIDHex() string
- func (txn *Transaction) UpdateHeader()
- func (txn *Transaction) Verify() error
- func (txn Transaction) VerifyInput(uxIn UxArray) error
- type TransactionOutput
- type Transactions
- type UxArray
- func (ua UxArray) Add(other UxArray) UxArray
- func (ua UxArray) CoinHours(headTime uint64) (uint64, error)
- func (ua UxArray) Coins() (uint64, error)
- func (ua UxArray) HasDupes() bool
- func (ua UxArray) Hashes() []cipher.SHA256
- func (ua UxArray) Len() int
- func (ua UxArray) Less(i, j int) bool
- func (ua UxArray) Set() UxHashSet
- func (ua UxArray) Sort()
- func (ua UxArray) Sub(other UxArray) UxArray
- func (ua UxArray) Swap(i, j int)
- type UxBody
- type UxHashSet
- type UxHead
- type UxOut
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUint64MultOverflow is returned when multiplying uint64 values would overflow uint64 ErrUint64MultOverflow = errors.New("uint64 multiplication overflow") // ErrUint64AddOverflow is returned when adding uint64 values would overflow uint64 ErrUint64AddOverflow = errors.New("uint64 addition overflow") // ErrUint32AddOverflow is returned when adding uint32 values would overflow uint32 ErrUint32AddOverflow = errors.New("uint32 addition overflow") // ErrUint64OverflowsInt64 is returned when converting a uint64 to an int64 would overflow int64 ErrUint64OverflowsInt64 = errors.New("uint64 overflows int64") // ErrInt64UnderflowsUint64 is returned when converting an int64 to a uint64 would underflow uint64 ErrInt64UnderflowsUint64 = errors.New("int64 underflows uint64") )
var ( // DebugLevel1 checks for extremely unlikely conditions (10e-40) DebugLevel1 = true // DebugLevel2 enable checks for impossible conditions DebugLevel2 = true )
var ErrAddEarnedCoinHoursAdditionOverflow = errors.New("UxOut.CoinHours addition of earned coin hours overflow")
ErrAddEarnedCoinHoursAdditionOverflow is returned by UxOut.CoinHours() if during the addition of base coin hours to additional earned coin hours, the value would overflow a uint64. Callers may choose to ignore this errors and use 0 as the coinhours value instead. This affects one existing spent output, spent in block 13277.
Functions ¶
func Int64ToUint64 ¶
Int64ToUint64 converts an int64 to a uint64, returning an error if the int64 value underflows uint64
func Uint64ToInt64 ¶
Uint64ToInt64 converts a uint64 to an int64, returning an error if the uint64 value overflows int64
func VerifyTransactionCoinsSpending ¶
VerifyTransactionCoinsSpending checks that coins are not destroyed or created by the transaction
Types ¶
type AddressUxOuts ¶
AddressUxOuts maps address with uxarray
func NewAddressUxOuts ¶
func NewAddressUxOuts(uxs UxArray) AddressUxOuts
NewAddressUxOuts creates address uxouts map
func (AddressUxOuts) Add ¶
func (auo AddressUxOuts) Add(other AddressUxOuts) AddressUxOuts
Add returns a new unspents, with merged unspents
func (AddressUxOuts) Flatten ¶
func (auo AddressUxOuts) Flatten() UxArray
Flatten converts an AddressUxOuts map to a UxArray
func (AddressUxOuts) Keys ¶
func (auo AddressUxOuts) Keys() []cipher.Address
Keys returns the Address keys
func (AddressUxOuts) Sub ¶
func (auo AddressUxOuts) Sub(other AddressUxOuts) AddressUxOuts
Sub returns a new set of unspents, with unspents found in other removed. No address's unspent set will be empty Depreciate this: only visor uses it
type Block ¶
type Block struct {
Head BlockHeader
Body BlockBody
}
Block represents the block struct
func NewBlock ¶
func NewBlock(prev Block, currentTime uint64, uxHash cipher.SHA256, txns Transactions, calc FeeCalculator) (*Block, error)
NewBlock creates new block.
func NewGenesisBlock ¶
NewGenesisBlock creates genesis block
func (Block) GetTransaction ¶
func (b Block) GetTransaction(txHash cipher.SHA256) (Transaction, bool)
GetTransaction looks up a Transaction by its Head.Hash. Returns the Transaction and whether it was found or not TODO -- build a private index on the block, or a global blockchain one mapping txns to their block + tx index TODO: Deprecate? Utility Function
func (Block) HashHeader ¶
HashHeader return hash of block head.
func (Block) PreHashHeader ¶
PreHashHeader return hash of prevous block.
type BlockBody ¶
type BlockBody struct {
Transactions Transactions
}
BlockBody represents the block body
type BlockHeader ¶
type BlockHeader struct {
Version uint32
Time uint64
BkSeq uint64 // Increment every block
Fee uint64 // Fee in block
PrevHash cipher.SHA256 // Hash of header of previous block
BodyHash cipher.SHA256 // Hash of transaction block
UxHash cipher.SHA256 // XOR of sha256 of elements in unspent output set
}
BlockHeader records the block header
func NewBlockHeader ¶
func NewBlockHeader(prev BlockHeader, uxHash cipher.SHA256, currentTime, fee uint64, body BlockBody) BlockHeader
NewBlockHeader creates block header
func (BlockHeader) Bytes ¶
func (bh BlockHeader) Bytes() []byte
Bytes serialize the blockheader and return the byte value.
func (BlockHeader) Hash ¶
func (bh BlockHeader) Hash() cipher.SHA256
Hash return hash of block header
func (BlockHeader) String ¶
func (bh BlockHeader) String() string
String return readable string of block header.
type FeeCalculator ¶
type FeeCalculator func(*Transaction) (uint64, error)
FeeCalculator given a transaction, return its fee or an error if the fee cannot be calculated
type SignedBlock ¶
SignedBlock signed block
func (SignedBlock) VerifySignature ¶
func (b SignedBlock) VerifySignature(pubkey cipher.PubKey) error
VerifySignature verifies that the block is signed by pubkey
type SortableTransactions ¶
type SortableTransactions struct {
Txns Transactions
Fees []uint64
Hashes []cipher.SHA256
}
SortableTransactions allows sorting transactions by fee & hash
func NewSortableTransactions ¶
func NewSortableTransactions(txns Transactions, feeCalc FeeCalculator) SortableTransactions
NewSortableTransactions returns an array of txns that can be sorted by fee. On creation, fees are calculated, and if any txns have invalid fee, there are removed from consideration
func (SortableTransactions) Len ¶
func (txns SortableTransactions) Len() int
Len returns length of transactions
func (SortableTransactions) Less ¶
func (txns SortableTransactions) Less(i, j int) bool
Less default sorting is fees descending, hash ascending if fees equal
func (SortableTransactions) Sort ¶
func (txns SortableTransactions) Sort()
Sort sorts by tx fee, and then by hash if fee equal
type Transaction ¶
type Transaction struct {
Length uint32 //length prefix
Type uint8 //transaction type
InnerHash cipher.SHA256 //inner hash SHA256 of In[],Out[]
Sigs []cipher.Sig //list of signatures, 64+1 bytes each
In []cipher.SHA256 //ouputs being spent
Out []TransactionOutput //ouputs being created
}
Transaction transaction struct
func MustTransactionDeserialize ¶
func MustTransactionDeserialize(b []byte) Transaction
MustTransactionDeserialize deserialize transaction, panics on error
func TransactionDeserialize ¶
func TransactionDeserialize(b []byte) (Transaction, error)
TransactionDeserialize deserialize transaction
func (*Transaction) Hash ¶
func (txn *Transaction) Hash() cipher.SHA256
Hash an entire Transaction struct, including the TransactionHeader
func (*Transaction) HashInner ¶
func (txn *Transaction) HashInner() cipher.SHA256
HashInner hashes only the Transaction Inputs & Outputs This is what is signed Client hashes the inner hash with hash of output being spent and signs it with private key
func (*Transaction) OutputHours ¶
func (txn *Transaction) OutputHours() (uint64, error)
OutputHours returns the coin hours sent as outputs. This does not include the fee.
func (*Transaction) PushInput ¶
func (txn *Transaction) PushInput(uxOut cipher.SHA256) uint16
PushInput adds a UxArray to the Transaction given the hash of a UxOut. Returns the signature index for later signing
func (*Transaction) PushOutput ¶
func (txn *Transaction) PushOutput(dst cipher.Address, coins, hours uint64)
PushOutput Adds a TransactionOutput, sending coins & hours to an Address
func (*Transaction) Serialize ¶
func (txn *Transaction) Serialize() []byte
Serialize serialize the transaction
func (*Transaction) SignInputs ¶
func (txn *Transaction) SignInputs(keys []cipher.SecKey)
SignInputs signs all inputs in the transaction
func (*Transaction) Size ¶
func (txn *Transaction) Size() int
Size returns the encoded byte size of the transaction
func (*Transaction) SizeHash ¶
func (txn *Transaction) SizeHash() (int, cipher.SHA256)
SizeHash returns the encoded size and the hash of it (avoids duplicate encoding)
func (*Transaction) TxID ¶
func (txn *Transaction) TxID() []byte
TxID returns transaction ID as byte string
func (*Transaction) TxIDHex ¶
func (txn *Transaction) TxIDHex() string
TxIDHex returns transaction ID as hex
func (*Transaction) UpdateHeader ¶
func (txn *Transaction) UpdateHeader()
UpdateHeader saves the txn body hash to TransactionHeader.Hash
func (*Transaction) Verify ¶
func (txn *Transaction) Verify() error
Verify attempts to determine if the transaction is well formed Verify cannot check transaction signatures, it needs the address from unspents Verify cannot check if outputs being spent exist Verify cannot check if the transaction would create or destroy coins or if the inputs have the required coin base
func (Transaction) VerifyInput ¶
func (txn Transaction) VerifyInput(uxIn UxArray) error
VerifyInput verifies the input
type TransactionOutput ¶
type TransactionOutput struct {
Address cipher.Address //address to send to
Coins uint64 //amount to be sent in coins
Hours uint64 //amount to be sent in coin hours
}
TransactionOutput hash output/name is function of Hash
type Transactions ¶
type Transactions []Transaction
Transactions transaction slice
func SortTransactions ¶
func SortTransactions(txns Transactions, feeCalc FeeCalculator) Transactions
SortTransactions returns transactions sorted by fee per kB, and sorted by lowest hash if tied. Transactions that fail in fee computation are excluded.
func (Transactions) Fees ¶
func (txns Transactions) Fees(calc FeeCalculator) (uint64, error)
Fees calculates all the fees in Transactions
func (Transactions) Hashes ¶
func (txns Transactions) Hashes() []cipher.SHA256
Hashes caculate transactions hashes
func (Transactions) Size ¶
func (txns Transactions) Size() int
Size returns the sum of contained Transactions' sizes. It is not the size if serialized, since that would have a length prefix.
func (Transactions) TruncateBytesTo ¶
func (txns Transactions) TruncateBytesTo(size int) Transactions
TruncateBytesTo returns the first n transactions whose total size is less than or equal to size.
type UxArray ¶
type UxArray []UxOut
UxArray Array of Outputs Used by unspent output pool, spent tests
func CreateUnspents ¶
func CreateUnspents(bh BlockHeader, tx Transaction) UxArray
CreateUnspents creates the expected outputs for a transaction.
func (UxArray) Set ¶
Set returns the UxArray as a hash to struct{} map to be used as a set. Should only be used for membership detection
type UxBody ¶
type UxBody struct {
SrcTransaction cipher.SHA256 // Inner Hash of Transaction
Address cipher.Address // Address of receiver
Coins uint64 // Number of coins
Hours uint64 // Coin hours
}
UxBody uxbody
type UxHead ¶
type UxHead struct {
Time uint64 //time of block it was created in
BkSeq uint64 //block it was created in, used to calculate depth
}
UxHead metadata (not hashed)
type UxOut ¶
UxOut represents uxout
func CreateUnspent ¶
func CreateUnspent(bh BlockHeader, tx Transaction, outIndex int) (UxOut, error)
CreateUnspent creates single unspent output
func (*UxOut) CoinHours ¶
CoinHours Calculate coinhour balance of output. t is the current unix utc time.
func (*UxOut) SnapshotHash ¶
SnapshotHash returns hash of UxBody + UxHead