blockchain

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: GPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChannelCreationFeesFFG required amount to register a channel.
	ChannelCreationFeesFFG = int64(400)
	// RemainingChannelOperationFeesMiliFFG any other channel node item creation fees.
	RemainingChannelOperationFeesMiliFFG = int64(100)
)
View Source
var (
	NodeItemType_name = map[int32]string{
		0: "UNKNOWN",
		1: "CHANNEL",
		2: "SUBCHANNEL",
		3: "ENTRY",
		4: "DIR",
		5: "FILE",
		6: "OTHER",
	}
	NodeItemType_value = map[string]int32{
		"UNKNOWN":    0,
		"CHANNEL":    1,
		"SUBCHANNEL": 2,
		"ENTRY":      3,
		"DIR":        4,
		"FILE":       5,
		"OTHER":      6,
	}
)

Enum value maps for NodeItemType.

View Source
var File_blockchain_types_proto protoreflect.FileDescriptor

Functions

func CalculateChannelActionsFeesForCreate added in v1.4.0

func CalculateChannelActionsFeesForCreate(nodes []*NodeItem) *big.Int

CalculateChannelActionsFeesForCreate given a list of node items it calculates the amount of fees required for the items to be created.

func CalculateChannelActionsFeesForUpdate added in v1.4.0

func CalculateChannelActionsFeesForUpdate(nodes []*NodeItem) *big.Int

CalculateChannelActionsFeesForUpdate given a list of node items it calculates the amount of fees required for the items to be updated.

func MarshalAddressStateProto

func MarshalAddressStateProto(b *AddressStateProto) ([]byte, error)

MarshalAddressStateProto serializes an address state to a protobuf message.

Types

type AddressState

type AddressState struct {
	Balance []byte
	Nounce  []byte
}

AddressState represents an address's state.

func AddressStateProtoToAddressState

func AddressStateProtoToAddressState(state *AddressStateProto) AddressState

AddressStateProtoToAddressState returns the AddressState from a AddressStateProto.

func (*AddressState) GetBalance

func (a *AddressState) GetBalance() (*big.Int, error)

GetBalance returns the balance as big int.

func (*AddressState) GetNounce

func (a *AddressState) GetNounce() (uint64, error)

GetNounce returns the nounce as uint64.

func (*AddressState) SetBalance

func (a *AddressState) SetBalance(amount *big.Int)

SetBalance sets the balance to byte array.

func (*AddressState) SetNounce

func (a *AddressState) SetNounce(number uint64)

SetNounce sets the balance to byte array.

type AddressStateProto

type AddressStateProto struct {

	// balance represents the address balance.
	Balance []byte `protobuf:"bytes,1,opt,name=balance,proto3" json:"balance,omitempty"`
	// nounce represents the current nounce of the address.
	Nounce []byte `protobuf:"bytes,2,opt,name=nounce,proto3" json:"nounce,omitempty"`
	// contains filtered or unexported fields
}

AddressStateProto represents the state of an address in a proto message.

func ToAddressStateProto

func ToAddressStateProto(state AddressState) *AddressStateProto

ToAddressStateProto returns the proto representation of a state.

func UnmarshalAddressStateProto

func UnmarshalAddressStateProto(data []byte) (*AddressStateProto, error)

UnmarshalProtoBlock unserializes a byte array to a protobuf address state.

func (*AddressStateProto) Descriptor deprecated

func (*AddressStateProto) Descriptor() ([]byte, []int)

Deprecated: Use AddressStateProto.ProtoReflect.Descriptor instead.

func (*AddressStateProto) GetBalance

func (x *AddressStateProto) GetBalance() []byte

func (*AddressStateProto) GetNounce

func (x *AddressStateProto) GetNounce() []byte

func (*AddressStateProto) ProtoMessage

func (*AddressStateProto) ProtoMessage()

func (*AddressStateProto) ProtoReflect

func (x *AddressStateProto) ProtoReflect() protoreflect.Message

func (*AddressStateProto) Reset

func (x *AddressStateProto) Reset()

func (*AddressStateProto) String

func (x *AddressStateProto) String() string

type Blockchain

type Blockchain struct {
	// contains filtered or unexported fields
}

Blockchain represents a blockchain structure.

func New

func New(db database.Database, search search.IndexSearcher, genesisBlockHash []byte) (*Blockchain, error)

New creates a new blockchain instance.

func (*Blockchain) CloseDB

func (b *Blockchain) CloseDB() error

CloseDB closes the db.

func (*Blockchain) DeleteFromBlockPool

func (b *Blockchain) DeleteFromBlockPool(block block.Block) error

DeleteFromBlockPool deletes a block from mempool.

func (*Blockchain) DeleteFromMemPool

func (b *Blockchain) DeleteFromMemPool(tx transaction.Transaction) error

DeleteFromMemPool deletes a transaction from mempool.

func (*Blockchain) GetAddressState

func (b *Blockchain) GetAddressState(address []byte) (AddressState, error)

GetAddressState returns the state of the address from the db.

func (*Blockchain) GetAddressTransactions

func (b *Blockchain) GetAddressTransactions(address []byte, currentPage, pageSize int) ([]transaction.Transaction, []uint64, []int64, error)

GetAddressTransactions returns a list of transaction given the address.

func (*Blockchain) GetBlockByHash

func (b *Blockchain) GetBlockByHash(blockHash []byte) (block.Block, error)

GetBlockByHash gets a block by its hash.

func (*Blockchain) GetBlockByNumber

func (b *Blockchain) GetBlockByNumber(blockNumber uint64) (*block.Block, error)

GetBlockByNumber returns a block by number.

func (*Blockchain) GetBlocksFromPool

func (b *Blockchain) GetBlocksFromPool() []block.Block

GetBlocksFromPool get all the block from blockpool.

func (*Blockchain) GetChannels

func (b *Blockchain) GetChannels(currentPage, pageSize int, order string) ([]*NodeItem, error)

GetChannels gets a list of channels.

func (*Blockchain) GetChannelsCount

func (b *Blockchain) GetChannelsCount() uint64

GetChannelsCount returns the count of total channels.

func (*Blockchain) GetChildNodeItems

func (b *Blockchain) GetChildNodeItems(nodeHash []byte, currentPage, pageSize int, order string, childItemsType string, excludeChildType string) ([]*NodeItem, uint64, error)

GetChildNodeItems returns a list of child nodes of a node.

func (*Blockchain) GetDownloadContractInTransactionDataTransactionHash

func (b *Blockchain) GetDownloadContractInTransactionDataTransactionHash(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)

GetDownloadContractInTransactionDataTransactionHash returns a list of contract data found in a transaction payload which are arrived in the node.

func (*Blockchain) GetFilesFromEntryOrFolderRecursively

func (b *Blockchain) GetFilesFromEntryOrFolderRecursively(entryOrFolderHash []byte, currentPage, pageSize int, order string) ([]FileMetadata, error)

GetFilesFromEntryOrFolderRecursively findes all the files recursively by given a folder or entry hash.

func (*Blockchain) GetHeight

func (b *Blockchain) GetHeight() uint64

GetHeight gets the height of the blockchain.

func (*Blockchain) GetLastBlockHash

func (b *Blockchain) GetLastBlockHash() []byte

GetLastBlockHash gets the last block hash.

func (*Blockchain) GetLastBlockUpdatedAt

func (b *Blockchain) GetLastBlockUpdatedAt() int64

GetLastBlockUpdatedAt returns the timestamp of the last blockchain update from a block.

func (*Blockchain) GetNodeFileItemFromFileHash

func (b *Blockchain) GetNodeFileItemFromFileHash(fileHash []byte) ([]*NodeItem, error)

GetNodeFileItemFromFileHash returns a file node item given the file's hash

func (*Blockchain) GetNodeItem

func (b *Blockchain) GetNodeItem(nodeHash []byte) (*NodeItem, error)

GetNodeItem get a node.

func (*Blockchain) GetNounceFromMemPool

func (b *Blockchain) GetNounceFromMemPool(address []byte) uint64

GetNounceFromMemPool get the nounce of an address from mempool.

func (*Blockchain) GetParentNodeItem

func (b *Blockchain) GetParentNodeItem(nodeHash []byte) (*NodeItem, error)

GetParentNodeItem get a node.

func (*Blockchain) GetPermissionFromRootNode

func (b *Blockchain) GetPermissionFromRootNode(rootNode *NodeItem, fromAddr []byte) (owner, admin, poster bool)

GetPermissionFromRootNode get the permissions from channel node.

func (*Blockchain) GetReleasedFeesOfDownloadContractInTransactionData

func (b *Blockchain) GetReleasedFeesOfDownloadContractInTransactionData(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)

GetReleasedFeesOfDownloadContractInTransactionData returns the contract which its fees are released to file hoster.

func (*Blockchain) GetRootNodeItem

func (b *Blockchain) GetRootNodeItem(nodeHash []byte) (*NodeItem, error)

GetRootNodeItem traverse back until root node is reached and its a channel node.

func (*Blockchain) GetTotalChannelNodesChilds added in v1.1.17

func (b *Blockchain) GetTotalChannelNodesChilds(parentHash []byte) uint64

GetTotalChannelNodesChilds returns the total number of channel entries in the blockchain except the channels.

func (*Blockchain) GetTransactionByHash

func (b *Blockchain) GetTransactionByHash(hash []byte) ([]transaction.Transaction, []uint64, error)

GetTransactionByHash returns a list of transactions found in db.

func (*Blockchain) GetTransactionsFromPool

func (b *Blockchain) GetTransactionsFromPool() []transaction.Transaction

GetTransactionsFromPool get all the transactions from mempool.

func (*Blockchain) IncrementHeightBy

func (b *Blockchain) IncrementHeightBy(h uint64)

IncrementHeightBy increments the blockchain height by the given number.

func (*Blockchain) InitOrLoad

func (b *Blockchain) InitOrLoad(verifyAllBlocks bool) error

InitOrLoad intializes or loads the blockchain from the database.

func (*Blockchain) PerformAddressStateUpdate

func (b *Blockchain) PerformAddressStateUpdate(transaction transaction.Transaction, verifierAddr []byte, isCoinbase bool) error

PerformAddressStateUpdate performs state update. This function should be able to rollback to previous state in case of failure. APPLYING OPERATIONS ON BIG INTS MODIFIES THE UNDERLYING DATA.

func (*Blockchain) PerformStateUpdateFromBlock

func (b *Blockchain) PerformStateUpdateFromBlock(validBlock block.Block) error

PerformStateUpdateFromBlock performs updates from a block.

func (*Blockchain) PutBlockPool

func (b *Blockchain) PutBlockPool(block block.Block) error

PutBlockPool adds a block to blockPool.

func (*Blockchain) PutMemPool

func (b *Blockchain) PutMemPool(tx transaction.Transaction) error

PutMemPool adds a transaction to mempool. validation of transaction should be done outside this function.

func (*Blockchain) SaveBlockInDB

func (b *Blockchain) SaveBlockInDB(blck block.Block) error

SaveBlockInDB saves a block into the database.

func (*Blockchain) SetChannelsCount added in v1.4.0

func (b *Blockchain) SetChannelsCount(num uint64) error

SetChannelsCount sets the channels count

func (*Blockchain) SetHeight

func (b *Blockchain) SetHeight(h uint64)

SetHeight sets the height of the blockchain.

func (*Blockchain) SetLastBlockHash

func (b *Blockchain) SetLastBlockHash(data []byte) error

SetLastBlockHash sets the last block hash.

func (*Blockchain) SetTotalChannelNodesChilds added in v1.4.0

func (b *Blockchain) SetTotalChannelNodesChilds(nodeHash []byte, num uint64) error

SetTotalChannelNodesChilds given a node, it updates the nodes count. This is useful when a node item is removed, the parent count should be updated.

func (*Blockchain) UpdateAddressState

func (b *Blockchain) UpdateAddressState(address []byte, state AddressState) error

UpdateAddressState updates the state of the address in the db.

type DownloadContractInTransactionDataTxHash

type DownloadContractInTransactionDataTxHash struct {
	TxHash                                 []byte
	DownloadContractInTransactionDataProto *messages.DownloadContractInTransactionDataProto
}

DownloadContractInTransactionDataTxHash represents a contract metadata and a tx hash.

type FileMetadata

type FileMetadata struct {
	Name string
	Hash string
	Size uint64
	Path string
}

FileMetadata represents channel file metadata.

type Interface

type Interface interface {
	GetBlocksFromPool() []block.Block
	PutBlockPool(block block.Block) error
	DeleteFromBlockPool(block block.Block) error
	PutMemPool(tx transaction.Transaction) error
	DeleteFromMemPool(tx transaction.Transaction) error
	GetTransactionsFromPool() []transaction.Transaction
	SaveBlockInDB(blck block.Block) error
	GetBlockByHash(blockHash []byte) (block.Block, error)
	GetNounceFromMemPool(address []byte) uint64
	GetAddressState(address []byte) (AddressState, error)
	UpdateAddressState(address []byte, state AddressState) error
	CloseDB() error
	IncrementHeightBy(h uint64)
	GetHeight() uint64
	GetLastBlockHash() []byte
	PerformStateUpdateFromBlock(validBlock block.Block) error
	GetBlockByNumber(blockNumber uint64) (*block.Block, error)
	GetLastBlockUpdatedAt() int64
	GetTransactionByHash(hash []byte) ([]transaction.Transaction, []uint64, error)
	GetAddressTransactions(address []byte, currentPage, limit int) ([]transaction.Transaction, []uint64, []int64, error)
	GetChannels(currentPage, pageSize int, order string) ([]*NodeItem, error)
	GetChannelsCount() uint64
	GetChildNodeItems(nodeHash []byte, currentPage, pageSize int, order string, childItemsType string, excludeChildType string) ([]*NodeItem, uint64, error)
	GetNodeItem(nodeHash []byte) (*NodeItem, error)
	GetParentNodeItem(nodeHash []byte) (*NodeItem, error)
	GetDownloadContractInTransactionDataTransactionHash(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)
	GetReleasedFeesOfDownloadContractInTransactionData(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)
	GetNodeFileItemFromFileHash(fileHash []byte) ([]*NodeItem, error)
	GetFilesFromEntryOrFolderRecursively(entryOrFolderHash []byte, currentPage, pageSize int, order string) ([]FileMetadata, error)
	GetRootNodeItem(nodeHash []byte) (*NodeItem, error)
}

Interface wraps the functionality of a blockchain.

type NodeItem

type NodeItem struct {
	Name        string       `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	NodeHash    []byte       `protobuf:"bytes,2,opt,name=node_hash,json=nodeHash,proto3" json:"node_hash,omitempty"`
	Owner       []byte       `protobuf:"bytes,3,opt,name=owner,proto3" json:"owner,omitempty"`
	Enabled     bool         `protobuf:"varint,4,opt,name=enabled,proto3" json:"enabled,omitempty"`
	NodeType    NodeItemType `protobuf:"varint,5,opt,name=node_type,json=nodeType,proto3,enum=blockchain.NodeItemType" json:"node_type,omitempty"`
	Attributes  [][]byte     `protobuf:"bytes,6,rep,name=attributes,proto3" json:"attributes,omitempty"`
	Admins      [][]byte     `protobuf:"bytes,7,rep,name=admins,proto3" json:"admins,omitempty"`
	Posters     [][]byte     `protobuf:"bytes,8,rep,name=posters,proto3" json:"posters,omitempty"`
	Timestamp   int64        `protobuf:"varint,9,opt,name=timestamp,proto3" json:"timestamp,omitempty"`
	Description *string      `protobuf:"bytes,10,opt,name=description,proto3,oneof" json:"description,omitempty"`
	MerkleRoot  []byte       `protobuf:"bytes,11,opt,name=merkle_root,json=merkleRoot,proto3,oneof" json:"merkle_root,omitempty"`
	FileHash    []byte       `protobuf:"bytes,12,opt,name=file_hash,json=fileHash,proto3,oneof" json:"file_hash,omitempty"`
	Size        *uint64      `protobuf:"varint,13,opt,name=size,proto3,oneof" json:"size,omitempty"`
	ParentHash  []byte       `protobuf:"bytes,14,opt,name=parent_hash,json=parentHash,proto3,oneof" json:"parent_hash,omitempty"`
	ContentType *string      `protobuf:"bytes,15,opt,name=content_type,json=contentType,proto3,oneof" json:"content_type,omitempty"`
	// contains filtered or unexported fields
}

NodeItem is used to represent a hierarchical struct of channels, subchannels directories etc.

func (*NodeItem) Descriptor deprecated

func (*NodeItem) Descriptor() ([]byte, []int)

Deprecated: Use NodeItem.ProtoReflect.Descriptor instead.

func (*NodeItem) GetAdmins

func (x *NodeItem) GetAdmins() [][]byte

func (*NodeItem) GetAttributes

func (x *NodeItem) GetAttributes() [][]byte

func (*NodeItem) GetContentType

func (x *NodeItem) GetContentType() string

func (*NodeItem) GetDescription

func (x *NodeItem) GetDescription() string

func (*NodeItem) GetEnabled

func (x *NodeItem) GetEnabled() bool

func (*NodeItem) GetFileHash

func (x *NodeItem) GetFileHash() []byte

func (*NodeItem) GetMerkleRoot

func (x *NodeItem) GetMerkleRoot() []byte

func (*NodeItem) GetName

func (x *NodeItem) GetName() string

func (*NodeItem) GetNodeHash

func (x *NodeItem) GetNodeHash() []byte

func (*NodeItem) GetNodeType

func (x *NodeItem) GetNodeType() NodeItemType

func (*NodeItem) GetOwner

func (x *NodeItem) GetOwner() []byte

func (*NodeItem) GetParentHash

func (x *NodeItem) GetParentHash() []byte

func (*NodeItem) GetPosters

func (x *NodeItem) GetPosters() [][]byte

func (*NodeItem) GetSize

func (x *NodeItem) GetSize() uint64

func (*NodeItem) GetTimestamp

func (x *NodeItem) GetTimestamp() int64

func (*NodeItem) ProtoMessage

func (*NodeItem) ProtoMessage()

func (*NodeItem) ProtoReflect

func (x *NodeItem) ProtoReflect() protoreflect.Message

func (*NodeItem) Reset

func (x *NodeItem) Reset()

func (*NodeItem) String

func (x *NodeItem) String() string

type NodeItemType

type NodeItemType int32

NodeItemType represents the type of each node.

const (
	NodeItemType_UNKNOWN    NodeItemType = 0
	NodeItemType_CHANNEL    NodeItemType = 1
	NodeItemType_SUBCHANNEL NodeItemType = 2
	NodeItemType_ENTRY      NodeItemType = 3
	NodeItemType_DIR        NodeItemType = 4
	NodeItemType_FILE       NodeItemType = 5
	NodeItemType_OTHER      NodeItemType = 6
)

func (NodeItemType) Descriptor

func (NodeItemType) Enum

func (x NodeItemType) Enum() *NodeItemType

func (NodeItemType) EnumDescriptor deprecated

func (NodeItemType) EnumDescriptor() ([]byte, []int)

Deprecated: Use NodeItemType.Descriptor instead.

func (NodeItemType) Number

func (NodeItemType) String

func (x NodeItemType) String() string

func (NodeItemType) Type

type NodeItems

type NodeItems struct {
	Nodes []*NodeItem `protobuf:"bytes,1,rep,name=nodes,proto3" json:"nodes,omitempty"`
	// contains filtered or unexported fields
}

NodeItems is an envelope of nodes.

func (*NodeItems) Descriptor deprecated

func (*NodeItems) Descriptor() ([]byte, []int)

Deprecated: Use NodeItems.ProtoReflect.Descriptor instead.

func (*NodeItems) GetNodes

func (x *NodeItems) GetNodes() []*NodeItem

func (*NodeItems) ProtoMessage

func (*NodeItems) ProtoMessage()

func (*NodeItems) ProtoReflect

func (x *NodeItems) ProtoReflect() protoreflect.Message

func (*NodeItems) Reset

func (x *NodeItems) Reset()

func (*NodeItems) String

func (x *NodeItems) String() string

Jump to

Keyboard shortcuts

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