models

package
v0.0.0-...-0fbb279 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2020 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ERROR_ABOVE_TARGET = errors.New("Block's hash is not below the target")
View Source
var ERROR_CONTAINS_INVALID_TRANSACTION = errors.New("Block contains invalid transactions")
View Source
var ERROR_EMPTY_SIGNATURE_STRING = errors.New("string is empty, cannot represent a signature")
View Source
var ERROR_INCORRECT_BODY_HASH = errors.New("Block's body hash has been incorrectly calculated")
View Source
var ERROR_INCORRECT_HASH_STRING_LENGTH = errors.New("string does not have the correct length to represent a hash")
View Source
var ERROR_INCORRECT_INDEX = errors.New("Block has incorrect index")
View Source
var ERROR_INSUFFICIENT_DATA = errors.New("Insufficient data")
View Source
var ERROR_INVALID_BLOCK = errors.New("Invalid Block")
View Source
var ERROR_INVALID_COINBASE_TRANSCTION = errors.New("Block's coinbase transaction collects more coins than expected")
View Source
var ERROR_INVALID_PEM_BLOCK = errors.New("PEM block is invalid")
View Source
var ERROR_LESS_TIMESTAMP = errors.New("Block's timestamp is less than parent's timestamp")
View Source
var ERROR_NOT_RSA_KEY = errors.New("the key is not an RSA key")
View Source
var ERROR_PARENT_HASH_MISMATCH = errors.New("Parent hash doesn't match with the hash of the block at that index")
View Source
var ERROR_TARGET_MISMATCH = errors.New("Block's target doesn't match with the current target")

Functions

func Blockchain

func Blockchain() *blockchain

Types

type Block

type Block struct {
	Id           ID              `json:"_"`
	Index        uint32          `json:"index"`
	ParentHash   Hash            `json:"parentHash"`
	BodyHash     Hash            `json:"bodyHash"`
	Target       Hash            `json:"target"`
	Timestamp    int64           `json:"timestamp"`
	Nonce        int64           `json:"nonce"`
	Transactions TransactionList `json:"transactions"`
}

func BlockFromByteArray

func BlockFromByteArray(data []byte) (Block, error)

func NewGenesisBlock

func NewGenesisBlock() Block

func (*Block) CalculateHeader

func (block *Block) CalculateHeader(recalculateBodyHash bool) []byte

func (Block) GetBodyHash

func (block Block) GetBodyHash() Hash

func (Block) GetHash

func (block Block) GetHash() Hash

func (Block) SaveToFile

func (block Block) SaveToFile()

func (Block) ToByteArray

func (block Block) ToByteArray() []byte

func (Block) ToJSON

func (block Block) ToJSON() string

type Coins

type Coins uint64

func (Coins) MarshalJSON

func (coins Coins) MarshalJSON() ([]byte, error)

type Hash

type Hash [32]byte

func HashFromHexString

func HashFromHexString(str string) (Hash, error)

func (Hash) IsLessThan

func (hash Hash) IsLessThan(target Hash) bool

func (Hash) MarshalJSON

func (hash Hash) MarshalJSON() ([]byte, error)

func (Hash) String

func (hash Hash) String() string

func (Hash) ToByteArray

func (hash Hash) ToByteArray() []byte

type ID

type ID = Hash

type Input

type Input struct {
	TransactionId Hash      `json:"transactionId"`
	OutputIndex   uint32    `json:"index"`
	Signature     Signature `json:"signature"`
}

func InputFromByteArray

func InputFromByteArray(data []byte) (Input, int, error)

func (Input) ToByteArray

func (input Input) ToByteArray() []byte

type InputList

type InputList []Input

func InputListFromByteArray

func InputListFromByteArray(data []byte) (InputList, int, error)

func (InputList) ToByteArray

func (inputList InputList) ToByteArray() []byte

type InputListRequestBody

type InputListRequestBody []InputRequestBody

func (InputListRequestBody) ToInputList

func (inputListRequestBody InputListRequestBody) ToInputList() (InputList, error)

type InputRequestBody

type InputRequestBody struct {
	TransactionId string `json:"transactionId" binding:"required"`
	OutputIndex   uint32 `json:"index" binding:"required"`
	Signature     string `json:"signature" binding:"required"`
}

func (InputRequestBody) ToInput

func (inputRequestBody InputRequestBody) ToInput() (Input, error)

type Output

type Output struct {
	Recipient User  `json:"recipient"`
	Amount    Coins `json:"amount"`
}

func OutputFromByteArray

func OutputFromByteArray(data []byte) (Output, int, error)

func (Output) ToByteArray

func (output Output) ToByteArray() []byte

type OutputList

type OutputList []Output

func OutputListFromByteArray

func OutputListFromByteArray(data []byte) (OutputList, int, error)

func (OutputList) GetSumOfAmounts

func (outputList OutputList) GetSumOfAmounts() Coins

func (OutputList) ToByteArray

func (outputList OutputList) ToByteArray() []byte

type OutputListRequestBody

type OutputListRequestBody []OutputRequestBody

func (OutputListRequestBody) ToOutputList

func (outputListRequestBody OutputListRequestBody) ToOutputList() (OutputList, error)

type OutputMap

type OutputMap = map[TransactionIdIndexPair]Output

type OutputRequestBody

type OutputRequestBody struct {
	Recipient string      `json:"recipient" binding:"required"`
	Amount    json.Number `json:"amount" binding:"required"`
}

func (OutputRequestBody) ToOutput

func (outputRequestBody OutputRequestBody) ToOutput() (Output, error)

type Signature

type Signature []byte

func SignatureFromHexString

func SignatureFromHexString(str string) (Signature, error)

func (Signature) MarshalJSON

func (sig Signature) MarshalJSON() ([]byte, error)

func (Signature) String

func (sig Signature) String() string

func (Signature) ToByteArray

func (sig Signature) ToByteArray() []byte

func (Signature) Unlock

func (sig Signature) Unlock(output *Output, txidIndexPair *TransactionIdIndexPair, message *Hash) bool

type Transaction

type Transaction struct {
	Id      ID         `json:"id"`
	Inputs  InputList  `json:"inputs"`
	Outputs OutputList `json:"outputs"`
}

func TransactionFromByteArray

func TransactionFromByteArray(data []byte) (Transaction, error)

func (*Transaction) AddInput

func (txn *Transaction) AddInput(input Input)

func (*Transaction) AddOutput

func (txn *Transaction) AddOutput(output Output)

func (*Transaction) CalculateHash

func (txn *Transaction) CalculateHash() Hash

func (Transaction) CalculateOutputDataHash

func (txn Transaction) CalculateOutputDataHash() Hash

func (Transaction) ToByteArray

func (txn Transaction) ToByteArray() []byte

type TransactionIdIndexPair

type TransactionIdIndexPair struct {
	TransactionId ID
	Index         uint32
}

func (TransactionIdIndexPair) ToByteArray

func (pair TransactionIdIndexPair) ToByteArray() []byte

type TransactionList

type TransactionList []Transaction

func TransactionListFromByteArray

func TransactionListFromByteArray(data []byte) (TransactionList, error)

func (TransactionList) ToByteArray

func (txnList TransactionList) ToByteArray() []byte

type TransactionMap

type TransactionMap map[Hash]Transaction

func (TransactionMap) MarshalJSON

func (txnMap TransactionMap) MarshalJSON() ([]byte, error)

type TransactionRequestBody

type TransactionRequestBody struct {
	Inputs  InputListRequestBody  `json:"inputs" binding:"required"`
	Outputs OutputListRequestBody `json:"outputs" binding:"required"`
}

func (*TransactionRequestBody) ToTransaction

func (txnRequestBody *TransactionRequestBody) ToTransaction() (Transaction, error)

type User

type User string

func (User) GetPublicKey

func (user User) GetPublicKey() (*rsa.PublicKey, error)

func (User) ToByteArray

func (user User) ToByteArray() []byte

Jump to

Keyboard shortcuts

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