Documentation
¶
Index ¶
- Constants
- Variables
- func FillGaps(src []slice.Slice) []slice.Slice
- func HasIntersection(slices []slice.Slice) error
- func PadHash(in types.Uint160) types.Uint256
- type Block
- type BlockHeader
- type HashFunction
- type Input
- type Item
- type Layer
- type MerkleTree
- type Metadata
- type Output
- type ProofStep
- type SumMerkleTree
- type SumMerkleTreeProof
- type SumTreeNode
- type SumTreeRoot
- type Transaction
- func (t *Transaction) GetHash() types.Uint160
- func (t *Transaction) GetSignaturesHash() types.Uint160
- func (t *Transaction) Sign(key []byte) error
- func (t *Transaction) Validate() error
- func (t *Transaction) ValidateSignatures() error
- func (t *Transaction) ValidateSlices() error
- func (t *Transaction) ValidateSoftLimits() error
- type Tree
- type UnsignedBlockHeader
- type UnsignedTransaction
Constants ¶
const ( MaxInputs = 3 MaxOutputs = 3 MaxSignatures = 2 )
Variables ¶
var WeiPerCoin uint = 1e11
Functions ¶
func HasIntersection ¶
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 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 ¶
CalculateMerkleRoot calculates merkle root for transactions in the block.
func (*Block) SerializeHeader ¶
func (*Block) Sign ¶
func (b *Block) Sign(key *ecdsa.PrivateKey) error
Sign signs the block with the specified private key.
func (*Block) UpdateRSAAccumulator ¶
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 ¶
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
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 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 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 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.