blockchain

package
v0.0.0-...-62a0fd1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 27, 2020 License: MIT Imports: 16 Imported by: 0

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

View Source
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

func GetJobFixedCost(job, data string, url bool) int

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 GetJobMinPrize(job, data string) int

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

func BuildBlock(id utils.Addr, prev *Block) *Block

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

func BuildFirstBlock(id utils.Addr) *Block

Build the first block of the chain. Miners should call this function no more than one time.

func MarshalBlock

func MarshalBlock(data []byte, config *conf.Config) (*Block, string)

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

func (self *Block) AddMiniBlock(miniblock *MiniBlock, config *conf.Config)

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

func (self *Block) CheckStep1(hashPrev string) bool

The CheckStep1 method checks the validity of the content of the block without checking Previous and its connections.

func (*Block) CheckStep2

func (self *Block) CheckStep2(transactionChanges *map[string]string, config *conf.Config) bool

The CheckStep2 method checks the validity of the links among blocks and of the depending data.

func (*Block) FindPrevBlock

func (self *Block) FindPrevBlock(hash string) *Block

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

func (self *Block) GetBlockIndex() int

Returns the index of the current block in the entire Blockchain.

func (*Block) GetHash

func (self *Block) GetHash(hashPrev string) string

Recalculates the hash of the block as hex string.

func (*Block) GetHashCached

func (self *Block) GetHashCached() string

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

func (self *Block) NextSlotForJobExectution() (int, int)

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.

func (*Block) Serialize

func (self *Block) Serialize() []byte

Serializes the block returning a []byte

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

func LoadChainFromFolder(id utils.Addr, folder string, config *conf.Config) *Blockchain

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

func NewBlockchain(id utils.Addr, folder string, config *conf.Config) *Blockchain

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

type CoinTransaction struct {
	Timestamp time.Time
	Output    TrOutput
	Creator   utils.Addr
	Hash      string
}

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 MexBlock

type MexBlock struct {
	Data     []byte
	IpSender string
}

used to exchange blocks with miner

type MexTrans

type MexTrans struct {
	Type string
	Data []byte
}

used to exchange transactions with miner

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

func MarshalMiniBlock(data []byte) *MiniBlock

Builds a MiniBlock from its serialization.

func (*MiniBlock) CheckStep1

func (self *MiniBlock) CheckStep1(hashPrev string) bool

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

func (self *MiniBlock) CheckStep2(block *Block, hardness int, config *conf.Config) bool

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) GetHash

func (self *MiniBlock) GetHash() string

Recalculates and returns the hash of the MiniBlock.

func (*MiniBlock) GetHashCached

func (self *MiniBlock) GetHashCached() string

Returns the cached hash of the MiniBlock.

func (*MiniBlock) Mine

func (self *MiniBlock) Mine(hardness int, keepmining *bool, chOut chan *MiniBlock)

When this miniblock is mined it is sent to chOut. If keepmining==false the mining should stop and send nil to ch.

func (*MiniBlock) Serialize

func (self *MiniBlock) Serialize() []byte

Serializes the MiniBlock and returns it as []byte.

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 Nonce struct {
	Solution   []byte //ga.DNA serialized
	Evaluation float64
	Complexity float64
	// contains filtered or unexported fields
}

func (*Nonce) Next

func (self *Nonce) Next()

Reads a new Nonce from candidates and change the stored values.

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.

func (*TrInput) GetSource

func (self *TrInput) GetSource(head *Block) *TrOutput

Returns the TrOutput this TrInput points to, if it exists in the chain pointed by the head block; nil otherwise.

func (*TrInput) ToString

func (self *TrInput) ToString() string

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

func (self *TrOutput) GetSpentIn() string

Returns the hash of the block in which this output has been spent, or empty string if it is currently unspent.

func (*TrOutput) SetSpentIn

func (self *TrOutput) SetSpentIn(block string)

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

type Tree struct {
	Root    *Node
	Nleaves int
	// contains filtered or unexported fields
}

Tree struct implements a Merkle tree with transactions at leaves.

func BuildMerkleTree

func BuildMerkleTree() *Tree

Returns a new empty tree.

func MarshalMerkleTree

func MarshalMerkleTree(data []byte, config *conf.Config) *Tree

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) Check

func (self *Tree) Check() bool

Checks the hashes of the Merkle tree.

func (*Tree) GetHash

func (self *Tree) GetHash() string

Returns the top hash of the tree.

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()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL