blockchain

package
v0.0.0-...-9fddba8 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxInputs     = 3
	MaxOutputs    = 3
	MaxSignatures = 2
)

Variables

View Source
var WeiPerCoin uint = 1e11

Functions

func FillGaps

func FillGaps(src []slice.Slice) []slice.Slice

Fill plasma range space with Slices, src slices should be sorted first

func HasIntersection

func HasIntersection(slices []slice.Slice) error

func PadHash

func PadHash(in types.Uint160) types.Uint256

Pads 20 byte hash to 32 bytes with zeros

Types

type Block

type Block struct {
	BlockHeader  `json:"header"`
	Transactions []Transaction `json:"transactions"`
}

Block is a complete block that gets uploaded to public storage.

func Deserialize

func Deserialize(data []byte) *Block

func NewBlock

func NewBlock(key *ecdsa.PrivateKey, blockNumber uint32, previousHash types.Uint256, previousRSAAccumulator types.Uint2048, transactions []Transaction) (*Block, error)

NewBlock creates a block from previous block metadata and an array of transaction. This function will calculate merkle root, RSA accumulator, and sign the block.

func (*Block) CalculateMerkleRoot

func (b *Block) CalculateMerkleRoot() error

CalculateMerkleRoot calculates merkle root for transactions in the block.

func (*Block) GetHash

func (b *Block) GetHash() types.Uint256

GetHash gets the hash of block header.

func (*Block) Serialize

func (b *Block) Serialize() ([]byte, error)

func (*Block) SerializeHeader

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

func (*Block) Sign

func (b *Block) Sign(key *ecdsa.PrivateKey) error

Sign signs the block with the specified private key.

func (*Block) UpdateRSAAccumulator

func (b *Block) UpdateRSAAccumulator(previous types.Uint2048)

UpdateRSAAccumulator adds input ranges for all submitted transactions to the RSA accumulator. Algorithm complexity is O(N*logN) for N transactions. This function accepts previous accumulator as argument instead of mutating the block to avoid double invocation.

type BlockHeader

type BlockHeader struct {
	UnsignedBlockHeader
	Signature types.Signature `json:"signature"`
}

BlockHeader is a structure that gets sent to a smart contract.

type HashFunction

type HashFunction func(data []byte) []byte

Declare type since we use Keccak160 in production and Keccak256 in JS tests

type Input

type Input struct {
	// index of the block that contains corresponding output
	BlockIndex uint32 `json:"blockNumber"`
	// index of the transaction within the block
	TxIndex uint32 `json:"txNumber"`
	// index of the output within transaction
	OutputIndex uint8 `json:"outputNumber"`
	Output
}

Input represents transaction input in terms of UTXO model Input should refers to output of some previous transaction BlockIndex, TxIndex and OutputIndex helps to find out where that input are

func (*Input) GetKey

func (i *Input) GetKey() string

GetKey gets unique input hash consisting of block number, transaction number, and output number.

type Item

type Item []byte

func Reduce

func Reduce(layers []Layer, f reduceDelegate, zero []Item) []Item

type Layer

type Layer []Item

type MerkleTree

type MerkleTree struct {
	Layers []Layer
}

func NewMerkleTree

func NewMerkleTree(leavesData []Item, height int, hash HashFunction) *MerkleTree

func (*MerkleTree) GetHexRoot

func (tree *MerkleTree) GetHexRoot() Item

func (*MerkleTree) GetProof

func (tree *MerkleTree) GetProof(idx int) []Item

func (*MerkleTree) GetRoot

func (tree *MerkleTree) GetRoot() Item

type Metadata

type Metadata struct {
	// MaxBlockNumber is a block number before the transaction should be included,
	// otherwise the transaction is considered invalid
	MaxBlockNumber uint32 `json:"maxBlockNumber"`
}

type Output

type Output struct {
	// Ethereum address of the owner
	Owner types.Uint160 `json:"owner"`
	Slice slice.Slice   `json:"slice"`
}

Output represents transaction output in terms of UTXO model

type ProofStep

type ProofStep struct {
	Length []byte        // 4 bytes
	Hash   types.Uint160 // 20 bytes
}

type SumMerkleTree

type SumMerkleTree struct {
	Root  *SumTreeNode
	Leafs []*SumTreeNode
}

func NewSumMerkleTree

func NewSumMerkleTree(leafs []*SumTreeNode, hashFunc HashFunction) *SumMerkleTree

func (*SumMerkleTree) GetProof

func (tree *SumMerkleTree) GetProof(leafIndex uint32) SumMerkleTreeProof

func (*SumMerkleTree) GetRlpEncodedProof

func (tree *SumMerkleTree) GetRlpEncodedProof(leafIndex uint32) []byte

func (*SumMerkleTree) GetRoot

func (tree *SumMerkleTree) GetRoot() SumTreeRoot

type SumMerkleTreeProof

type SumMerkleTreeProof struct {
	Index uint32
	Slice slice.Slice
	Item  types.Uint160
	Data  []ProofStep
}

Index: Bit index of the element in the tree Slice: Slice that stored inside a leaf with corresponding index Item: Hash ot the transaction associated with a slice Data: List of proof steps

type SumTreeNode

type SumTreeNode struct {
	Begin uint32
	End   uint32

	// We use 24 bit of length field
	Length uint32
	Hash   types.Uint160

	Left   *SumTreeNode
	Right  *SumTreeNode
	Parent *SumTreeNode
}

func PrepareLeaves

func PrepareLeaves(transactions []Transaction) ([]*SumTreeNode, error)

Use this first when assemble blocks

type SumTreeRoot

type SumTreeRoot struct {
	// We use 24 bit
	Length uint32
	Hash   types.Uint160
}

type Transaction

type Transaction struct {
	UnsignedTransaction
	// Signatures 65 bytes long ECDSA signature encoded in RSV format
	// R(32) bytes S(32) bytes  V(1) byte
	Signatures []types.Signature `json:"signatures"`
}

Signatures may only contain one or two signatures

func (*Transaction) GetHash

func (t *Transaction) GetHash() types.Uint160

GetHash returns a full hash of signed transaction.

func (*Transaction) GetSignaturesHash

func (t *Transaction) GetSignaturesHash() types.Uint160

GetSignaturesHash returns a hash of concatenated signatures.

func (*Transaction) Sign

func (t *Transaction) Sign(key []byte) error

Signs a transaction with a specified private key. This function will append the generated signature to transactions' Signatures array.

func (*Transaction) Validate

func (t *Transaction) Validate() error

Validate checks that transaction is well formed

func (*Transaction) ValidateSignatures

func (t *Transaction) ValidateSignatures() error

ValidateSignatures checks that the transaction is properly signed.

func (*Transaction) ValidateSlices

func (t *Transaction) ValidateSlices() error

func (*Transaction) ValidateSoftLimits

func (t *Transaction) ValidateSoftLimits() error

ValidateSoftLimits checks that soft array size limits are not exceeded.

type Tree

type Tree []Layer

type UnsignedBlockHeader

type UnsignedBlockHeader struct {
	BlockNumber    uint32         `json:"blockNumber"`
	PreviousHash   types.Uint256  `json:"previousHash"`
	MerkleRoot     SumTreeRoot    `json:"merkleRoot"`
	RSAAccumulator types.Uint2048 `json:"rsaAccumulator"`
	// contains filtered or unexported fields
}

UnsignedBlockHeader is a structure that signature is calculated for.

type UnsignedTransaction

type UnsignedTransaction struct {
	Inputs   []Input  `json:"inputs"`
	Outputs  []Output `json:"outputs"`
	Metadata Metadata `json:"metadata"`
}

func (*UnsignedTransaction) GetInputOwners

func (t *UnsignedTransaction) GetInputOwners() [][]byte

GetInputOwners gets array of unique input owner addresses.

func (*UnsignedTransaction) GetMerkleRoot

func (t *UnsignedTransaction) GetMerkleRoot() types.Uint160

GetMerkleRoot gets the root of merklized transaction inputs, outputs, and metadata.

Jump to

Keyboard shortcuts

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