blockchain_data

package
v0.0.0-...-58ee6da Latest Latest
Warning

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

Go to latest
Published: May 23, 2020 License: Unlicense Imports: 8 Imported by: 0

Documentation

Overview

Provides a reduced record of approved cycle transactions to store with the balance list. This is used to enforce the ∩100,000 per 10,000-block limit of NTTP-3/3. The initiator and receiver, while not necessary for this, are stored because they are small and helpful for anyone reviewing the balance list.

A balance list, including all the auxiliary data typical for the Java implementation. This is not strictly part of the blockchain, but for local storage, balance lists are serialized and deserialized just like blockchain data.

Individual entry in a balance list.

A Nyzo block, only low-level serialization/deserialization activity should happen here, plus basical structural sanity checking. More complex stuff like transaction validation or continuity needs to go further up.

Used to attach additional cycle info to a block, this is not part of the original spec, it exists to speed up cycle-related calculations and is only of local relevance.

A block vote.

Gets attached to a block, represents info about the current and past cycles.

An individual cycle transaction signature (V1 blockchain).

A special data type sometimes used to save a little space during data serialization.

An individual transaction. Only simple serialization/deserialization and structural sanity checking belongs here.

Used for costly verifications (so that we don't have to repeat them).

Index

Constants

View Source
const (
	TransactionTypeCoinGeneration = 0
	TransactionTypeSeed           = 1
	TransactionTypeStandard       = 2
	TransactionTypeCycle          = 3
	TransactionTypeCycleSignature = 4
	TransactionTypeAccountFee     = 97
	TransactionTypeCycleReward    = 98
	TransactionTypeVerifierReward = 99
)
View Source
const (
	Undetermined = 0
	Valid        = 1
	Invalid      = 2
)

Variables

This section is empty.

Functions

func FromShlong

func FromShlong(combined int64) (int16, int64)

Takes a shlong and turns it into a long and a short.

func ToShlong

func ToShlong(short int16, long int64) int64

Takes a long and a short and turns it into a shlong.

Types

type ApprovedCycleTransaction

type ApprovedCycleTransaction struct {
	InitiatorIdentifier []byte
	ReceiverIdentifier  []byte
	ApprovalHeight      int64
	Amount              int64
}

func ReadNewApprovedCycleTransaction

func ReadNewApprovedCycleTransaction(r io.Reader) (*ApprovedCycleTransaction, error)

Convenience to create an approved cycle transaction from a byte buffer.

func (*ApprovedCycleTransaction) GetSerializedLength

func (t *ApprovedCycleTransaction) GetSerializedLength() int

Serializable interface: data length when serialized.

func (*ApprovedCycleTransaction) Read

Serializable interface: convert from bytes.

func (*ApprovedCycleTransaction) ToBytes

func (t *ApprovedCycleTransaction) ToBytes() []byte

Serializable interface: convert to bytes.

type BalanceList

type BalanceList struct {
	BlockchainVersion                 int16
	BlockHeight                       int64
	RolloverFees                      byte
	PreviousVerifiers                 [][]byte
	Items                             []BalanceListItem
	UnlockThreshold                   int64
	UnlockTransferSum                 int64
	PendingCycleTransactions          []*Transaction
	RecentlyApprovedCycleTransactions []*ApprovedCycleTransaction
}

func ReadNewBalanceList

func ReadNewBalanceList(r io.Reader) (*BalanceList, error)

func (*BalanceList) GetHash

func (bl *BalanceList) GetHash() []byte

Get the hash for this balance list

func (*BalanceList) GetSerializedLength

func (bl *BalanceList) GetSerializedLength() int

Serializable interface: data length when serialized

func (*BalanceList) Normalize

func (bl *BalanceList) Normalize()

Normalize a balance list by removing accounts with 0 micronyzo and duplicates

func (*BalanceList) Read

func (bl *BalanceList) Read(r io.Reader) error

Serialization interface. Read a balance list from bytes.

func (*BalanceList) ToBytes

func (bl *BalanceList) ToBytes() []byte

Serializable interface: convert to bytes.

type BalanceListItem

type BalanceListItem struct {
	Identifier     []byte
	Balance        int64
	BlocksUntilFee int16
}

type Block

type Block struct {
	BlockchainVersion     int16          // 2 bytes; 16-bit integer of the blockchain version
	Height                int64          // 6 bytes; 48-bit integer block height from the Genesis block, which has a height of 0
	PreviousBlockHash     []byte         // 32 bytes (this is the double-SHA-256 of the previous block signature)
	StartTimestamp        int64          // 8 bytes; 64-bit Unix timestamp of the start of the block, in milliseconds
	VerificationTimestamp int64          // 8 bytes; 64-bit Unix timestamp of when the verifier creates the block, in milliseconds
	Transactions          []*Transaction // 4 bytes for number + variable
	BalanceListHash       []byte         // 32 bytes (this is the double-SHA-256 of the account balance list)
	VerifierIdentifier    []byte         // 32 bytes
	VerifierSignature     []byte         // 64 bytes
	ContinuityState       int
	SignatureState        int
	CycleInformation      *CycleInformation
	Hash                  []byte
	CycleInfoCache        *BlockCycleInfoCache
}

func ReadNewBlock

func ReadNewBlock(r io.Reader) (*Block, error)

Read a new block from the given reader.

func (*Block) GetSerializedLength

func (b *Block) GetSerializedLength() int

Serializable interface: data length when serialized

func (*Block) Read

func (b *Block) Read(r io.Reader) error

Serializable interface: read from a reader.

func (*Block) Serialize

func (b *Block) Serialize(forSigning bool) []byte

Serialize (for message passing or signing)

func (*Block) ToBytes

func (b *Block) ToBytes() []byte

Serializable interface: convert to bytes.

type BlockCycleInfoCache

type BlockCycleInfoCache struct {
	Found, IsGenesis, NewVerifier bool
	CycleTailHeight               int64
	CycleHeadHeight               int64
}

type BlockVote

type BlockVote struct {
	Height           int64
	Hash             []byte
	Timestamp        int64  // to prevent replay attacks of old votes (actually, unnecessary due to message timestamp)
	ReceiptTimestamp int64  // local-only field used to ensure minimum spacing between votes
	SenderIdentifier []byte // sender of the message for BlockWithVotesResponse
	MessageTimestamp int64  // timestamp of the message for BlockWithVotesResponse
	MessageSignature []byte // signature of the message for BlockWithVotesResponse
}

func (*BlockVote) GetSerializedLength

func (b *BlockVote) GetSerializedLength() int

Serializable interface: data length when serialized

func (*BlockVote) Read

func (b *BlockVote) Read(r io.Reader) error

Serializable interface: convert from bytes.

func (*BlockVote) ToBytes

func (b *BlockVote) ToBytes() []byte

Serializable interface: convert to bytes.

type CycleInformation

type CycleInformation struct {
	MaximumCycleLength int
	CycleLengths       []int
	NewVerifier        bool
	InGenesisCycle     bool
}

func (CycleInformation) CalculateTrailingEdgeHeight

func (c CycleInformation) CalculateTrailingEdgeHeight(blockHeight int64) int64

The trailing edge is 4 cycles back from the current height (or 0)

type CycleSignature

type CycleSignature struct {
	Id        []byte // node ID
	Signature []byte // the node's signature
}

type Transaction

type Transaction struct {
	// in all transactions
	Type        byte   // 1 byte, see above
	Timestamp   int64  // 8 bytes; 64-bit Unix timestamp of the transaction initiation, in milliseconds
	Amount      int64  // 8 bytes; 64-bit amount in micronyzos
	RecipientId []byte // 32 bytes (256-bit public key of the recipient)
	// type 1, 2 and 3
	PreviousHashHeight int64  // 8 bytes; 64-bit index of the block height of the previous-block hash
	PreviousBlockHash  []byte // 32 bytes (SHA-256 of a recent block in the chain), not serialized
	SenderId           []byte // 32 bytes (256-bit public key of the sender)
	SenderData         []byte // up to 32 bytes, length when serialized: 1 byte + actual length
	// type 1 and 2
	Signature []byte // 64 bytes (512-bit signature)
	// type 3
	CycleSignatures []*CycleSignature
	SignatureState  int
	// type 4
	CycleSignatureTransactions []*Transaction
	CycleTransactionVote       bool
	CycleTransactionSignature  []byte
}

func ReadNewTransaction

func ReadNewTransaction(r io.Reader) (*Transaction, error)

func (*Transaction) GetFee

func (t *Transaction) GetFee() int64

Calculate the fee charged for this transaction.

func (*Transaction) GetSerializedLength

func (t *Transaction) GetSerializedLength() int

Serializable interface: data length when serialized

func (*Transaction) Read

func (t *Transaction) Read(r io.Reader, balanceListCycleTransaction bool) error

Serializable interface: read from reader.

func (*Transaction) SignatureIsValid

func (t *Transaction) SignatureIsValid() bool

Verify this transaction's signature (if necessary) and return whether it's valid.

func (*Transaction) ToBytes

func (t *Transaction) ToBytes() []byte

Serializable interface: convert to bytes.

Jump to

Keyboard shortcuts

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