Documentation
¶
Index ¶
- Constants
- Variables
- func HasDoneWork(block MabyeProved) bool
- func IsDefaultGenesis(b *Block) bool
- func IsGenisis(b *Block) bool
- func ProofOfWork(block Provable) (nonce int64, hash []byte)
- type Block
- func (b *Block) CreateNext(data []byte) *Block
- func (*Block) Descriptor() ([]byte, []int)deprecated
- func (x *Block) GetData() []byte
- func (x *Block) GetHash() []byte
- func (x *Block) GetNonce() int64
- func (x *Block) GetPrevHash() []byte
- func (x *Block) GetTransactions() []*Transaction
- func (*Block) ProtoMessage()
- func (x *Block) ProtoReflect() protoreflect.Message
- func (x *Block) Reset()
- func (x *Block) String() string
- type Chain
- type Hashable
- type Iterator
- type MabyeProved
- type Provable
- type Store
- type Transaction
- func (tx *Transaction) Append(utxo UTXOSet, d TxDesc) error
- func (*Transaction) Descriptor() ([]byte, []int)deprecated
- func (tx *Transaction) Fee(finder TxFinder) uint64
- func (tx *Transaction) Finalize()
- func (x *Transaction) GetID() []byte
- func (x *Transaction) GetInputs() []*TxInput
- func (x *Transaction) GetLock() *timestamp.Timestamp
- func (x *Transaction) GetOutputs() []*TxOutput
- func (tx *Transaction) IsCoinbase() bool
- func (*Transaction) ProtoMessage()
- func (x *Transaction) ProtoReflect() protoreflect.Message
- func (x *Transaction) Reset()
- func (tx *Transaction) Sign(priv *ecdsa.PrivateKey, finder TxFinder) error
- func (tx *Transaction) StrID() string
- func (x *Transaction) String() string
- func (tx *Transaction) VerifySig(find TxFinder) error
- type TransactionBuilder
- type TxDesc
- type TxFinder
- type TxInput
- func (*TxInput) Descriptor() ([]byte, []int)deprecated
- func (x *TxInput) GetOutIndex() int32
- func (x *TxInput) GetPubKey() []byte
- func (x *TxInput) GetSignature() []byte
- func (x *TxInput) GetTxID() []byte
- func (*TxInput) ProtoMessage()
- func (x *TxInput) ProtoReflect() protoreflect.Message
- func (x *TxInput) Reset()
- func (x *TxInput) String() string
- type TxOutput
- func (*TxOutput) Descriptor() ([]byte, []int)deprecated
- func (x *TxOutput) GetAmount() uint64
- func (x *TxOutput) GetData() []byte
- func (x *TxOutput) GetDocument() string
- func (m *TxOutput) GetPayload() isTxOutput_Payload
- func (x *TxOutput) GetPubKeyHash() []byte
- func (x *TxOutput) GetToken() uint64
- func (*TxOutput) ProtoMessage()
- func (x *TxOutput) ProtoReflect() protoreflect.Message
- func (x *TxOutput) Reset()
- func (x *TxOutput) String() string
- type TxOutput_Data
- type TxOutput_Document
- type TxOutput_Token
- type UTXO
- type UTXOSet
Constants ¶
const MineReward = 100
MineReward is the reward you get from mining a block
Variables ¶
var ( // ErrNotEnoughFunds is an error returned when a sender // does not have enough money to make a transaction ErrNotEnoughFunds = errors.New("not enough funds") // ErrBlockNotMined is the error returned when a block has not had // enough work done one it or it has not been mined (these are usually not // mutually exclusive). ErrBlockNotMined = errors.New("block has not been mined or done sufficient work") )
var ErrInvalidSignature = errors.New("invalid signature")
ErrInvalidSignature is the error value given when a transaction has an invalid signature
var File_block_proto protoreflect.FileDescriptor
Functions ¶
func HasDoneWork ¶
func HasDoneWork(block MabyeProved) bool
HasDoneWork returns true of the hash has been run through the proof of work algorithm.
func IsDefaultGenesis ¶
IsDefaultGenesis will return true if the block given is the default genesis block
func ProofOfWork ¶
ProofOfWork runs the Proof of Work algorithm for a provable block.
Types ¶
type Block ¶
type Block struct { Data []byte `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` Nonce int64 `protobuf:"varint,2,opt,name=nonce,proto3" json:"nonce,omitempty"` Hash []byte `protobuf:"bytes,3,opt,name=hash,proto3" json:"hash,omitempty"` PrevHash []byte `protobuf:"bytes,4,opt,name=prevHash,proto3" json:"prevHash,omitempty"` Transactions []*Transaction `protobuf:"bytes,5,rep,name=transactions,proto3" json:"transactions,omitempty"` // contains filtered or unexported fields }
func DefaultGenesis ¶
func DefaultGenesis() *Block
DefaultGenesis block with pre-computed nonce and hash
func Genisis ¶
func Genisis(coinbase *Transaction) *Block
Genisis creates the first block of the chain
func New ¶
func New(txs []*Transaction, prev []byte) *Block
New creates a new block from a list of transactions and the previous hash
func (*Block) CreateNext ¶
CreateNext will create a new block using the data given and the hash of the current block.
func (*Block) Descriptor
deprecated
func (*Block) GetPrevHash ¶
func (*Block) GetTransactions ¶
func (x *Block) GetTransactions() []*Transaction
func (*Block) ProtoMessage ¶
func (*Block) ProtoMessage()
func (*Block) ProtoReflect ¶
func (x *Block) ProtoReflect() protoreflect.Message
type Hashable ¶
type Hashable interface {
Hash() []byte
}
Hashable is an interface that defines type that can be hashed.
type Iterator ¶
type Iterator interface { // returns the next block in the chain, value will // be nil if there are no more blocks. This should // return the genisis block as the last block Next() *Block }
Iterator is an interface that defines a block iterator
type MabyeProved ¶
MabyeProved is an interface that has been previously run through the proof of work algorithm
type Provable ¶
type Provable interface { GetTransactions() []*Transaction GetPrevHash() []byte GetData() []byte }
Provable is defines an interface for block hashing
type Transaction ¶
type Transaction struct { ID []byte `protobuf:"bytes,1,opt,name=ID,json=iD,proto3" json:"ID,omitempty"` // Transaction lock timestamp Lock *timestamp.Timestamp `protobuf:"bytes,2,opt,name=lock,proto3" json:"lock,omitempty"` // list of transaction inputs Inputs []*TxInput `protobuf:"bytes,3,rep,name=inputs,proto3" json:"inputs,omitempty"` // list of transaction outputs Outputs []*TxOutput `protobuf:"bytes,4,rep,name=outputs,proto3" json:"outputs,omitempty"` // contains filtered or unexported fields }
Trasaction is a blockchain transaction which contains a list of both inputs and outputs.
Inputs are references to funds that have been used by the owner on the input's public key.
Outputs are references to funds that are being credited to the owner of the output's public key hash.
func Coinbase ¶
func Coinbase(to key.Address) *Transaction
Coinbase will create a coinbase transaction.
func NewTransaction ¶
func NewTransaction() *Transaction
NewTransaction creates a new transaction. The new transaction will not be added to the chain.
func (*Transaction) Descriptor
deprecated
func (*Transaction) Descriptor() ([]byte, []int)
Deprecated: Use Transaction.ProtoReflect.Descriptor instead.
func (*Transaction) Fee ¶
func (tx *Transaction) Fee(finder TxFinder) uint64
GetFee will get the transaction fee for the transaction The transaction fee is defined as the total input value minus the total output value of a transaction.
func (*Transaction) Finalize ¶
func (tx *Transaction) Finalize()
func (*Transaction) GetID ¶
func (x *Transaction) GetID() []byte
func (*Transaction) GetInputs ¶
func (x *Transaction) GetInputs() []*TxInput
func (*Transaction) GetLock ¶
func (x *Transaction) GetLock() *timestamp.Timestamp
func (*Transaction) GetOutputs ¶
func (x *Transaction) GetOutputs() []*TxOutput
func (*Transaction) IsCoinbase ¶
func (tx *Transaction) IsCoinbase() bool
IsCoinbase will return true of the transaction is a coinbase transaction.
func (*Transaction) ProtoMessage ¶
func (*Transaction) ProtoMessage()
func (*Transaction) ProtoReflect ¶
func (x *Transaction) ProtoReflect() protoreflect.Message
func (*Transaction) Reset ¶
func (x *Transaction) Reset()
func (*Transaction) Sign ¶
func (tx *Transaction) Sign(priv *ecdsa.PrivateKey, finder TxFinder) error
Sign signs the transaction
func (*Transaction) StrID ¶
func (tx *Transaction) StrID() string
StrID will return a hex encoded version of the transaction ID
func (*Transaction) String ¶
func (x *Transaction) String() string
func (*Transaction) VerifySig ¶
func (tx *Transaction) VerifySig(find TxFinder) error
VerifySig will verify that a transaction has been correctly signed
type TransactionBuilder ¶
type TransactionBuilder struct {
// contains filtered or unexported fields
}
func (*TransactionBuilder) Append ¶
func (txb *TransactionBuilder) Append(utxo UTXOSet, d TxDesc) error
func (*TransactionBuilder) BuildTransactions ¶
func (txb *TransactionBuilder) BuildTransactions() ([]*Transaction, error)
func (*TransactionBuilder) Reset ¶
func (txb *TransactionBuilder) Reset()
type TxFinder ¶
type TxFinder interface { // Transaction looks for a Transaction by ID // and returns nil if no transaction was found Transaction(id []byte) *Transaction }
TxFinder defines an interface for objects that can find transactions.
type TxInput ¶
type TxInput struct { // TxID is the hash of transaction where // the unspent output is stored. TxID []byte `protobuf:"bytes,1,opt,name=txID,proto3" json:"txID,omitempty"` // OutIndex gives the index of the output refrenced // with respect to the transaction's list of // outputs (0 being the transaction's first output and so on...) OutIndex int32 `protobuf:"varint,2,opt,name=outIndex,proto3" json:"outIndex,omitempty"` // Signature is the digital signature of // the sender Signature []byte `protobuf:"bytes,3,opt,name=signature,proto3" json:"signature,omitempty"` // Public key of the sender PubKey []byte `protobuf:"bytes,4,opt,name=pubKey,proto3" json:"pubKey,omitempty"` // contains filtered or unexported fields }
func (*TxInput) Descriptor
deprecated
func (*TxInput) GetOutIndex ¶
func (*TxInput) GetSignature ¶
func (*TxInput) ProtoMessage ¶
func (*TxInput) ProtoMessage()
func (*TxInput) ProtoReflect ¶
func (x *TxInput) ProtoReflect() protoreflect.Message
type TxOutput ¶
type TxOutput struct { // Amount holds the amount // of coins in the output Amount uint64 `protobuf:"varint,1,opt,name=amount,proto3" json:"amount,omitempty"` // Hash of the recipient's public key // which can be derived from a wallet // address (see wallet package). PubKeyHash []byte `protobuf:"bytes,2,opt,name=pubKeyHash,proto3" json:"pubKeyHash,omitempty"` // Types that are assignable to Payload: // *TxOutput_Token // *TxOutput_Document // *TxOutput_Data Payload isTxOutput_Payload `protobuf_oneof:"payload"` // contains filtered or unexported fields }
TxOutput is a transaction output. If any given output is not referenced by a transaction input somewhere else in the chain, then the amount field is credited to the address which matches the public key hash.
func (*TxOutput) Descriptor
deprecated
func (*TxOutput) GetDocument ¶
func (*TxOutput) GetPayload ¶
func (m *TxOutput) GetPayload() isTxOutput_Payload
func (*TxOutput) GetPubKeyHash ¶
func (*TxOutput) ProtoMessage ¶
func (*TxOutput) ProtoMessage()
func (*TxOutput) ProtoReflect ¶
func (x *TxOutput) ProtoReflect() protoreflect.Message
type TxOutput_Data ¶
type TxOutput_Data struct { // Raw data Data []byte `protobuf:"bytes,5,opt,name=data,proto3,oneof"` }
type TxOutput_Document ¶
type TxOutput_Document struct { // A document Document string `protobuf:"bytes,4,opt,name=document,proto3,oneof"` }
type TxOutput_Token ¶
type TxOutput_Token struct { // Token amount Token uint64 `protobuf:"varint,3,opt,name=token,proto3,oneof"` }
type UTXO ¶
type UTXO struct { // The actual transaction output that // has not been spent *TxOutput // contains filtered or unexported fields }
UTXO is an unspent transaction output This is the same as a TxOutput except it holds useful information for creating transaction inputs like the output index and the transaction ID.
func FindOutputsToSpend ¶
FindOutputsToSpend will find unspent transaction outputs needed for a transaction. Guaranteed to return at least one UTXO and a combined value greater than or equal to the amount needed (given as an argument). Assumes that the balance has already been checked and the publickeyhash owns enough outputs.
This function assumes that the sender has enough funds to meet the quota.