Documentation
¶
Overview ¶
Package block contains the definitions of blocks, transactions, nonce
Package merkle defines the Merkle tree that is used to store the transactions of the transactchain
Index ¶
- Constants
- func GetJobFixedCost(job, data string, url bool) int
- func GetJobMinPrize(job, data string) int
- func GetResTransactionCost() int
- type Block
- func (self *Block) AddMiniBlock(miniblock *MiniBlock, config *conf.Config)
- func (self *Block) AddTransaction(transact Transaction) error
- func (self *Block) CheckStep1(hashPrev string) bool
- func (self *Block) CheckStep2(transactionChanges *map[string]string, config *conf.Config) bool
- func (self *Block) FindPrevBlock(hash string) *Block
- func (self *Block) FindTransaction(hash string) Transaction
- func (self *Block) GetBlockIndex() int
- func (self *Block) GetHash(hashPrev string) string
- func (self *Block) GetHashCached() string
- func (self *Block) Mine(id utils.Addr, keepmining *bool, miniblockout chan MexBlock, ...)
- func (self *Block) NextSlotForJobExectution() (int, int)
- func (self *Block) Serialize() []byte
- type Blockchain
- type CoinTransaction
- func (self *CoinTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *CoinTransaction) GetCreator() utils.Addr
- func (self *CoinTransaction) GetHash() string
- func (self *CoinTransaction) GetHashCached() string
- func (self *CoinTransaction) GetOutputAt(i int) *TrOutput
- func (self *CoinTransaction) GetTimestamp() time.Time
- func (self *CoinTransaction) GetType() string
- func (self *CoinTransaction) Serialize() []byte
- type JobTransaction
- func (self *JobTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *JobTransaction) GetCreator() utils.Addr
- func (self *JobTransaction) GetHash() string
- func (self *JobTransaction) GetHashCached() string
- func (self *JobTransaction) GetOutputAt(i int) *TrOutput
- func (self *JobTransaction) GetPeriod() (int, int)
- func (self *JobTransaction) GetSharingBlockPrize(position int) int
- func (self *JobTransaction) GetTimestamp() time.Time
- func (self *JobTransaction) GetType() string
- func (self *JobTransaction) SaveDataInFile(path string) error
- func (self *JobTransaction) SaveJobInFile(path string) error
- func (self *JobTransaction) Serialize() []byte
- type MexBlock
- type MexTrans
- type MiniBlock
- func (self *MiniBlock) CheckStep1(hashPrev string) bool
- func (self *MiniBlock) CheckStep2(block *Block, hardness int, config *conf.Config) bool
- func (self *MiniBlock) GetHash() string
- func (self *MiniBlock) GetHashCached() string
- func (self *MiniBlock) Mine(hardness int, keepmining *bool, chOut chan *MiniBlock)
- func (self *MiniBlock) Serialize() []byte
- type Node
- type Nonce
- type NonceNoJob
- type PrizeTransaction
- func (self *PrizeTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *PrizeTransaction) GetCreator() utils.Addr
- func (self *PrizeTransaction) GetHash() string
- func (self *PrizeTransaction) GetHashCached() string
- func (self *PrizeTransaction) GetOutputAt(int) *TrOutput
- func (self *PrizeTransaction) GetTimestamp() time.Time
- func (self *PrizeTransaction) GetType() string
- func (self *PrizeTransaction) Serialize() []byte
- type ResTransaction
- func (self *ResTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *ResTransaction) GetCreator() utils.Addr
- func (self *ResTransaction) GetHash() string
- func (self *ResTransaction) GetHashCached() string
- func (self *ResTransaction) GetOutputAt(i int) *TrOutput
- func (self *ResTransaction) GetTimestamp() time.Time
- func (self *ResTransaction) GetType() string
- func (self *ResTransaction) Serialize() []byte
- type SolTransaction
- func (self *SolTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *SolTransaction) GetCreator() utils.Addr
- func (self *SolTransaction) GetHash() string
- func (self *SolTransaction) GetHashCached() string
- func (self *SolTransaction) GetOutputAt(i int) *TrOutput
- func (self *SolTransaction) GetTimestamp() time.Time
- func (self *SolTransaction) GetType() string
- func (self *SolTransaction) Serialize() []byte
- type StdTransaction
- func (self *StdTransaction) Check(block *Block, trChanges *map[string]string) bool
- func (self *StdTransaction) GetCreator() utils.Addr
- func (self *StdTransaction) GetHash() string
- func (self *StdTransaction) GetHashByte() []byte
- func (self *StdTransaction) GetHashCached() string
- func (self *StdTransaction) GetOutputAt(i int) *TrOutput
- func (self *StdTransaction) GetTimestamp() time.Time
- func (self *StdTransaction) GetType() string
- func (self *StdTransaction) Serialize() []byte
- type TrInput
- type TrOutput
- type Transaction
- type Tree
Constants ¶
const ( TrStd = "StdTransaction" TrCoin = "CoinTransaction" TrJob = "JobTransaction" TrSol = "SolTransaction" TrRes = "ResTransaction" TrPrize = "PrizeTransaction" )
The possible types of a Transaction
Variables ¶
This section is empty.
Functions ¶
func GetJobFixedCost ¶
Returns the costs to store a job in the Blockchain, relative to the amount of data and the use of external providers.
func GetJobMinPrize ¶
func GetResTransactionCost ¶
func GetResTransactionCost() int
Returns the amount of money that should be paid in order to submit a ResTransaction.
Types ¶
type Block ¶
type Block struct {
Previous *Block
LenSubChain int
Transactions *Tree
MerkleHash string
Timestamp time.Time
NumJobs int
Hardness int
NonceNoJob NonceNoJob
MiniBlocks []MiniBlock
Hash string
// contains filtered or unexported fields
}
The block struct models the blocks of the blockchain. Each block, except the first one, is linked to a previous one.
func BuildBlock ¶
Make a new block (except the first one). This block needs to be mined. While the block is not mined, it can accept transactions.
func BuildFirstBlock ¶
Build the first block of the chain. Miners should call this function no more than one time.
func MarshalBlock ¶
Returns a Block parsing the serialized json, and also the hash of the previous block. The block is not linked to the previous one.
func (*Block) AddMiniBlock ¶
Checks the validity of a MiniBlock and stores it in the blockchain.
func (*Block) AddTransaction ¶
func (self *Block) AddTransaction(transact Transaction) error
Inserts a transaction in the block without checking it. It is assumed that the transaction is valid. Returns an error if the block is already mined.
func (*Block) CheckStep1 ¶
The CheckStep1 method checks the validity of the content of the block without checking Previous and its connections.
func (*Block) CheckStep2 ¶
The CheckStep2 method checks the validity of the links among blocks and of the depending data.
func (*Block) FindPrevBlock ¶
Returns a block in the chain pointed by this block, searching with an hash as key; if there is no match, returns nil.
func (*Block) FindTransaction ¶
func (self *Block) FindTransaction(hash string) Transaction
Returns (if exists) the transaction in this block with a specific hash, or nil
func (*Block) GetBlockIndex ¶
Returns the index of the current block in the entire Blockchain.
func (*Block) GetHashCached ¶
Returns the cached hash of the block.
func (*Block) Mine ¶
func (self *Block) Mine(id utils.Addr, keepmining *bool, miniblockout chan MexBlock, executor *ga.Executor, config *conf.Config)
The function to call in order to start mining a block. It should be called in a goroutine. If there are jobs, this function calls mineWithJobs; otherwise mineNoJob. Miniblocks are sent to miniblockout whenever mined.
func (*Block) NextSlotForJobExectution ¶
Returns the slot in which the next job should execute. The slot is made of the indexes of the block in which the job should start, and the one in which it should end.
type Blockchain ¶
type Blockchain struct {
Head *Block
Current *Block
TransQueue chan MexTrans // receive transactions from miner
BlockOut chan MexBlock // send mined block to miner
BlockIn chan MexBlock // receive mined block from miner
MiniBlockOut chan MexBlock // send mined miniblock to miner
MiniBlockIn chan MexBlock // receive mined miniblock from miner
// contains filtered or unexported fields
}
The blockchain has - a reference to the head block, - a current block that has to be mined before being inserted in the blockchain and being propagated, - some channels to communicate with miner and pass data - a publicKey (id) to get money from mining, - a lock for sync and some boolean to manage the mining process. (The miner has not to give the total money of clients: it is a problem of the client to imoplement this, by collecting old blocks/transactions).
func LoadChainFromFolder ¶
This method load a serialized blockchain from file. (Each time a block is added to the blockchain, in fact, it is saved in a file with its index as name).
func NewBlockchain ¶
Create a new Blockchain (the first block) and initialize it. This method also start mining by calling Mine() in a goroutine.
func (*Blockchain) Communicate ¶
func (self *Blockchain) Communicate(id utils.Addr, stop chan bool)
Main loop that manages the communication with the miner, reading the packets from channels and acting consequently. This method handles: - incoming blocks - mined block propagation - incoming transactions
func (*Blockchain) GetBlock ¶
func (self *Blockchain) GetBlock(hash string) *Block
Returns a block in the current blockchain from its hash; if there is no match, returns nil.
func (*Blockchain) GetNextSlotForJob ¶
func (self *Blockchain) GetNextSlotForJob() (int, int)
func (*Blockchain) GetSerializedHead ¶
func (self *Blockchain) GetSerializedHead() []byte
Serialize the current head block of the chain.
func (*Blockchain) Mine ¶
func (self *Blockchain) Mine()
Implements the minig process. This process can end if the block becomes valid or if another valid block is received from a packet. If the process ends with a valid block mined, the block is sent to internalBlock channel.
type CoinTransaction ¶
A CoinTransaction is the transaction miners can use to earn some money when they successfully complete the minig process.
func MakeCoinTransaction ¶
func MakeCoinTransaction(receiver utils.Addr, value int) (*CoinTransaction, error)
Instantiates a new CoinTransaction.
func MarshalCoinTransaction ¶
func MarshalCoinTransaction(data []byte) *CoinTransaction
Rebuilds the CoinTransaction from its serialized data.
func (*CoinTransaction) Check ¶
func (self *CoinTransaction) Check(block *Block, trChanges *map[string]string) bool
Returns always true because a CoinTransaction never spends money.
func (*CoinTransaction) GetCreator ¶
func (self *CoinTransaction) GetCreator() utils.Addr
Returns the public key of the creator of the transaction.
func (*CoinTransaction) GetHash ¶
func (self *CoinTransaction) GetHash() string
Recalculates the hash of the transaction.
func (*CoinTransaction) GetHashCached ¶
func (self *CoinTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*CoinTransaction) GetOutputAt ¶
func (self *CoinTransaction) GetOutputAt(i int) *TrOutput
Returns always the only TrOutput it stores.
func (*CoinTransaction) GetTimestamp ¶
func (self *CoinTransaction) GetTimestamp() time.Time
Returns the timestamp stored in the transaction.
func (*CoinTransaction) GetType ¶
func (self *CoinTransaction) GetType() string
func (*CoinTransaction) Serialize ¶
func (self *CoinTransaction) Serialize() []byte
Serializes the transaction and returns it as []byte
type JobTransaction ¶
type JobTransaction struct {
Timestamp time.Time
BlockStart int
BlockEnd int
Inputs []TrInput
Output TrOutput // the possible remainder
Creator utils.Addr
Job string
Data string // nil if data from url
DataUrl string // empty if data embedded
Prize int
Hash string
Signature string
// contains filtered or unexported fields
}
func MakeJobTransaction ¶
func MakeJobTransaction(creator utils.Addr, key utils.Key, inps []TrInput, out TrOutput, job, data string, dataurl string, prize, bkStart, bkEnd int) *JobTransaction
Builds a new JobTransaction and signs it. This method does not check the data it receives in input.
func MarshalJobTransaction ¶
func MarshalJobTransaction(data []byte) *JobTransaction
Rebuilds the transaction from its serialized data.
func (*JobTransaction) Check ¶
func (self *JobTransaction) Check(block *Block, trChanges *map[string]string) bool
Check validate the transaction and update trChanges. The parameter block is assumed to be the block in which this transaction is stored. The validity is checked in relation to the chain that is linked to that block. The subchain must be valid/already checked. In order to be valid, the transaction must have: - the hash that matches the one declared - the signature verified with the public key of the creator - all sources that belongs to the creator - all sources unspent (no double spending) - the total amount of money in sources >= the total amount of money spent. - the fixed cost calculated with GetJobFixedCost paid - a prize >= GetJobMinPrize paid - the BlockStart, BlockEnd slot that matches the one obtained with block.NextSlotForJobExectution on the previous block
func (*JobTransaction) GetCreator ¶
func (self *JobTransaction) GetCreator() utils.Addr
Returns the public key of the creator of the transaction
func (*JobTransaction) GetHash ¶
func (self *JobTransaction) GetHash() string
Recalculates the hash of the transaction.
func (*JobTransaction) GetHashCached ¶
func (self *JobTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*JobTransaction) GetOutputAt ¶
func (self *JobTransaction) GetOutputAt(i int) *TrOutput
Returns always the only TrOutput stored inside the transaction.
func (*JobTransaction) GetPeriod ¶
func (self *JobTransaction) GetPeriod() (int, int)
Returns the execution period stored in the transaction
func (*JobTransaction) GetSharingBlockPrize ¶
func (self *JobTransaction) GetSharingBlockPrize(position int) int
Returns the amount of money the one who submitted a good solution in the block should receive. Only the first 10 receives something.
func (*JobTransaction) GetTimestamp ¶
func (self *JobTransaction) GetTimestamp() time.Time
Returns the timestamp stored inside the transaction.
func (*JobTransaction) GetType ¶
func (self *JobTransaction) GetType() string
func (*JobTransaction) SaveDataInFile ¶
func (self *JobTransaction) SaveDataInFile(path string) error
Stores the data of the job in the file given in path. If the data is embedded, it is saved directly. Otherwise, the data is downloaded from the given url.
func (*JobTransaction) SaveJobInFile ¶
func (self *JobTransaction) SaveJobInFile(path string) error
Stores the code of the Job in the file given in path.
func (*JobTransaction) Serialize ¶
func (self *JobTransaction) Serialize() []byte
Serializes the transaction and returns it as []byte.
type MiniBlock ¶
type MiniBlock struct {
HashPrevBlock string
Miner utils.Addr
JobBlock string // the hash of the block with the JobTransaction
JobTrans string // the hash of the JobTransaction
Hash string
Hardness int // custom hardness tuned with job's complexity
Nonce Nonce
}
func BuildMiniBlock ¶
func BuildMiniBlock(hashPrev, hashJobBlock, hashJobTr string, publicKey utils.Addr, chNonce chan ga.Sol) *MiniBlock
Creates a new MiniBlock and initialize its channels.
func MarshalMiniBlock ¶
Builds a MiniBlock from its serialization.
func (*MiniBlock) CheckStep1 ¶
Checks the validity of the hash of the nonce in relation to the hardness, but not the validity of the evaluation of the solution. Also check if the hash of the previous block matches.
func (*MiniBlock) CheckStep2 ¶
Complete the check evaluating the stored solution. The block given must be the head of the complete chain in order to load the JobTransaction.
func (*MiniBlock) GetHashCached ¶
Returns the cached hash of the MiniBlock.
type Node ¶
type Node struct {
L, R *Node
Type string
Transaction Transaction
Hash string
Children int
// contains filtered or unexported fields
}
A node of the merkle tree. If it is a leaf, it contains a transaction. If it is an internal node, it contains only and hash.
type Nonce ¶
type NonceNoJob ¶
type NonceNoJob struct {
Value int
}
func (*NonceNoJob) Next ¶
func (self *NonceNoJob) Next()
type PrizeTransaction ¶
type PrizeTransaction struct {
Timestamp time.Time
Output TrOutput
Creator utils.Addr
SolBlock string // the hash of the block with the SolTransaction
SolTrans string // the hash of the SolTransaction
JobTrans string // the hash of the JobTransaction
Hash string
}
func MakePrizeTransaction ¶
func MakePrizeTransaction(receiver utils.Addr, amount int, solBlock, solTrans, jobTrans string) *PrizeTransaction
Builds a new PrizeTransaction and returns it.
func MarshalPrizeTransaction ¶
func MarshalPrizeTransaction(data []byte) *PrizeTransaction
Rebuilds a PrizeTransaction from its serialization.
func (*PrizeTransaction) Check ¶
func (self *PrizeTransaction) Check(block *Block, trChanges *map[string]string) bool
Check validate the transaction and update trChanges. The parameter block is assumed to be the block in which this transaction is stored. The validity is checked in relation to the chain that is linked to that block. The subchain must be valid/already checked. In order to be valid, the transaction must have: - the hash that matches the one declared - a valid link to a SolTransaction that belongs to the Creator, and that is stored in the previous block - the hash of the JobTransaction that match the declaration This method does not check the amount of the prize.
func (*PrizeTransaction) GetCreator ¶
func (self *PrizeTransaction) GetCreator() utils.Addr
Returns the public key of the receiver of the prize.
func (*PrizeTransaction) GetHash ¶
func (self *PrizeTransaction) GetHash() string
Recalculates and returns the hash of the transaction.
func (*PrizeTransaction) GetHashCached ¶
func (self *PrizeTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*PrizeTransaction) GetOutputAt ¶
func (self *PrizeTransaction) GetOutputAt(int) *TrOutput
Always returns a reference to self.Output.
func (*PrizeTransaction) GetTimestamp ¶
func (self *PrizeTransaction) GetTimestamp() time.Time
Returns the timestamp stored inside the transaction.
func (*PrizeTransaction) GetType ¶
func (self *PrizeTransaction) GetType() string
Returns the type of the transaction (TrPrize).
func (*PrizeTransaction) Serialize ¶
func (self *PrizeTransaction) Serialize() []byte
Returns the serialization of the transaction (as []byte).
type ResTransaction ¶
type ResTransaction struct {
Timestamp time.Time
Inputs []TrInput
Output TrOutput // the possible remainder
Creator utils.Addr
JobBlock string // the hash of the block with the JobTransaction
JobTrans string // the hash of the JobTransaction
Evaluation float64
IsMin bool
HashSol string // the hash of solution: [individual,evaluation,creator]
Hash string
Signature string
}
A ResTransaction is used to declare a good result achieved. The best ones should receive a prize. In order to receive it the miner has to submit a SolTransaction in the next block after the block with this transaction is mined. This transaction is valid only if it is submitted in the proper slot (that is scheduled with the job execution).
func MakeResTransaction ¶
func MakeResTransaction(creator utils.Addr, key utils.Key, inps []TrInput, out TrOutput, jobblock, jobtrans, hashsol string, evaluation float64, isMin bool) *ResTransaction
Builds a new ResTransaction and signs it. This method does not check the data it receives in input.
func MarshalResTransaction ¶
func MarshalResTransaction(data []byte) *ResTransaction
Rebuilds the transaction from its serialization.
func (*ResTransaction) Check ¶
func (self *ResTransaction) Check(block *Block, trChanges *map[string]string) bool
Check validate the transaction and update trChanges. The parameter block is assumed to be the block in which this transaction is stored. The validity is checked in relation to the chain that is linked to that block. The subchain must be valid/already checked. In order to be valid, the transaction must have: - the hash that matches the one declared - the signature verified with the public key of the creator - all sources that belongs to the creator - all sources unspent (no double spending) - the total amount of money in sources >= the fixed cost calculated with GetResTransactionCost()
func (*ResTransaction) GetCreator ¶
func (self *ResTransaction) GetCreator() utils.Addr
Returns the public key of the creator of the transaction.
func (*ResTransaction) GetHash ¶
func (self *ResTransaction) GetHash() string
Recalculates and return the hash of the transaction.
func (*ResTransaction) GetHashCached ¶
func (self *ResTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*ResTransaction) GetOutputAt ¶
func (self *ResTransaction) GetOutputAt(i int) *TrOutput
Always returns the only Output stored in the transaction.
func (*ResTransaction) GetTimestamp ¶
func (self *ResTransaction) GetTimestamp() time.Time
Returns the timestamp stored in the transaction.
func (*ResTransaction) GetType ¶
func (self *ResTransaction) GetType() string
Returns the type string of the transaction, which is "ResTransaction".
func (*ResTransaction) Serialize ¶
func (self *ResTransaction) Serialize() []byte
Serializes the transactions and returns it as []byte
type SolTransaction ¶
type SolTransaction struct {
Timestamp time.Time
Creator utils.Addr
ResBlock string // the hash of the block with the ResTransaction
ResTrans string // the hash of the ResTransaction
JobTrans string // the hash of the JobTransaction
Solution []byte
Hash string
Signature string
// contains filtered or unexported fields
}
A SolTransaction is used to receive money discosing a solution that was previously declared with a ResTransaction. It is valid if the solution is correct and the creator deserves the prize.
func MakeSolTransaction ¶
func MakeSolTransaction(creator utils.Addr, key utils.Key, resblock, restrans, jobtrans string, solution []byte, config *conf.Config) *SolTransaction
Builds a new SolTransaction and signs it. This method does not check the data it receives in input.
func MarshalSolTransaction ¶
func MarshalSolTransaction(data []byte, config *conf.Config) *SolTransaction
Rebuilds a SolTransaction from its serialization and returns it, or nil.
func (*SolTransaction) Check ¶
func (self *SolTransaction) Check(block *Block, trChanges *map[string]string) bool
Check validate the transaction and update trChanges. The parameter block is assumed to be the block in which this transaction is stored. The validity is checked in relation to the chain that is linked to that block. The subchain must be valid/already checked. In order to be valid, the transaction must have: - the hash that matches the one declared - the signature verified with the public key of the creator - a valid link to a ResTransaction that belongs to the Creator, and that is stored in the previous block - the hash of the JobTransaction that match the declaration - a solution whose hash matches the declaration - the correct evaluation of the solution In addition, this transaction should not be already stored in the block.
func (*SolTransaction) GetCreator ¶
func (self *SolTransaction) GetCreator() utils.Addr
Returns the public key of the creator of this transaction.
func (*SolTransaction) GetHash ¶
func (self *SolTransaction) GetHash() string
Recalculates and return the hash of the transaction.
func (*SolTransaction) GetHashCached ¶
func (self *SolTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*SolTransaction) GetOutputAt ¶
func (self *SolTransaction) GetOutputAt(i int) *TrOutput
Always returns nil
func (*SolTransaction) GetTimestamp ¶
func (self *SolTransaction) GetTimestamp() time.Time
Returns the timestamp stored in the transaction.
func (*SolTransaction) GetType ¶
func (self *SolTransaction) GetType() string
Returns the type of the transaction, which is "SolTransaction"
func (*SolTransaction) Serialize ¶
func (self *SolTransaction) Serialize() []byte
Serializes the SolTransaction and returns it as []byte.
type StdTransaction ¶
type StdTransaction struct {
Timestamp time.Time
Inputs []TrInput
Outputs []TrOutput
Creator utils.Addr
Hash string
Signature string
}
StdTransaction is the implementation of the standard Transaction, that can be used to send money. It collects a set of TrInput (source) and TrOutput (destination). All TrInput must point to TrOutput that belongs to the Creator of the transaction.
func MakeStdTransaction ¶
func MakeStdTransaction(creator utils.Addr, key utils.Key, inps []TrInput, outs []TrOutput) *StdTransaction
MakeStdTransaction build and initialize a StdTransaction. This method does not check the validity of the parameters: they are assumed to be valid.
func MarshalStdTransaction ¶
func MarshalStdTransaction(data []byte) *StdTransaction
Rebuilds the StdTransaction from its serialized data.
func (*StdTransaction) Check ¶
func (self *StdTransaction) Check(block *Block, trChanges *map[string]string) bool
Check validate the transaction and update trChanges. The parameter block is assumed to be the block in which this transaction is stored. The validity is checked in relation to the chain that is linked to that block. The subchain must be valid/already checked. In order to be valid, the transaction must have: - the hash that matches the one declared - the signature verified with the public key of the creator - all sources that belongs to the creator - all sources unspent (no double spending) - the total amount of money in sources >= the total amount of money spent.
func (*StdTransaction) GetCreator ¶
func (self *StdTransaction) GetCreator() utils.Addr
Returns the public key of the creator of the transaction.
func (*StdTransaction) GetHash ¶
func (self *StdTransaction) GetHash() string
Recalculates the hash of the transaction.
func (*StdTransaction) GetHashByte ¶
func (self *StdTransaction) GetHashByte() []byte
Recalculates the hash of the transaction.
func (*StdTransaction) GetHashCached ¶
func (self *StdTransaction) GetHashCached() string
Returns the cached hash of the transaction.
func (*StdTransaction) GetOutputAt ¶
func (self *StdTransaction) GetOutputAt(i int) *TrOutput
Returns the TrOutput stored at the index i of the transaction, or nil.
func (*StdTransaction) GetTimestamp ¶
func (self *StdTransaction) GetTimestamp() time.Time
Returns the timestamp stored inside the transaction.
func (*StdTransaction) GetType ¶
func (self *StdTransaction) GetType() string
func (*StdTransaction) Serialize ¶
func (self *StdTransaction) Serialize() []byte
Serialize the transaction and returns it as []byte.
type TrInput ¶
type TrInput struct {
Block string // hash of the old block with the transaction to spend
ToSpend string // hash of the old transaction to spend
Index int // index inside ToSpend of the record to spend
}
A TrInput represents inside a transaction the source of the money a client is spending. It points to a TrOutput that is included in a transaction, that is stored inside a block in the blockchain.
type TrOutput ¶
type TrOutput struct {
Address utils.Addr // address of the receiver
Value int // value to exchange
// contains filtered or unexported fields
}
A TrOutput represents inside a transaction the receiver of some money. This output can be spent in another transaction. The hash of the block in which this output is used inside a transaction (it is spent) can be stored or retrieved through SetSpentIn and GetSpentIn methods.
func (*TrOutput) GetSpentIn ¶
Returns the hash of the block in which this output has been spent, or empty string if it is currently unspent.
func (*TrOutput) SetSpentIn ¶
Store the hash of a block as the block in which this output is spent.
type Transaction ¶
type Transaction interface {
Check(block *Block, trChanges *map[string]string) bool
GetHash() string
GetHashCached() string
GetCreator() utils.Addr
GetTimestamp() time.Time
GetType() string
GetOutputAt(int) *TrOutput
Serialize() []byte
}
Transaction is the iterface for all the transactions. Assumptions: - all inputs from the same address (that signs the transactions) - only one output for each address that receives money
Check has to check the validity of the Transaction inside the chain. GetHash calculates and returns the hash of the Transaction. GetHashCached returns the cached hash of the Transaction. GetSignature returns the signature of the Transaction. GetCreator returns the public key of the creator of the Transaction. GetTimestamp returns the time of creation of the Transaction. GetType returns the string type of the Transaction. GetOutputAt returns the TrOutput at an index, inside the Transaction.
type Tree ¶
Tree struct implements a Merkle tree with transactions at leaves.
func MarshalMerkleTree ¶
Builds a Tree from its serialized data.
func (*Tree) Add ¶
func (self *Tree) Add(trans Transaction)
Add a Transaction to the merkle tree. The transaction is not checked here: it is assumed to be valid.
func (*Tree) GetTransactionArray ¶
func (self *Tree) GetTransactionArray() []Transaction
Returns an array with all the Transactions inside the tree.
func (*Tree) PruneSpentTransactions ¶
func (self *Tree) PruneSpentTransactions()