Documentation ¶
Index ¶
- Variables
- func CalculateChannelActionsFees(nodes []*NodeItem) *big.Int
- func MarshalAddressStateProto(b *AddressStateProto) ([]byte, error)
- type AddressState
- type AddressStateProto
- func (*AddressStateProto) Descriptor() ([]byte, []int)deprecated
- func (x *AddressStateProto) GetBalance() []byte
- func (x *AddressStateProto) GetNounce() []byte
- func (*AddressStateProto) ProtoMessage()
- func (x *AddressStateProto) ProtoReflect() protoreflect.Message
- func (x *AddressStateProto) Reset()
- func (x *AddressStateProto) String() string
- type Blockchain
- func (b *Blockchain) CloseDB() error
- func (b *Blockchain) DeleteFromBlockPool(block block.Block) error
- func (b *Blockchain) DeleteFromMemPool(tx transaction.Transaction) error
- func (b *Blockchain) GetAddressState(address []byte) (AddressState, error)
- func (b *Blockchain) GetAddressTransactions(address []byte, currentPage, pageSize int) ([]transaction.Transaction, []uint64, []int64, error)
- func (b *Blockchain) GetBlockByHash(blockHash []byte) (block.Block, error)
- func (b *Blockchain) GetBlockByNumber(blockNumber uint64) (*block.Block, error)
- func (b *Blockchain) GetBlocksFromPool() []block.Block
- func (b *Blockchain) GetChannels(currentPage, pageSize int, order string) ([]*NodeItem, error)
- func (b *Blockchain) GetChannelsCount() uint64
- func (b *Blockchain) GetChildNodeItems(nodeHash []byte, currentPage, pageSize int, order string) ([]*NodeItem, uint64, error)
- func (b *Blockchain) GetDownloadContractInTransactionDataTransactionHash(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)
- func (b *Blockchain) GetFilesFromEntryOrFolderRecursively(entryOrFolderHash []byte, currentPage, pageSize int, order string) ([]FileMetadata, error)
- func (b *Blockchain) GetHeight() uint64
- func (b *Blockchain) GetLastBlockHash() []byte
- func (b *Blockchain) GetLastBlockUpdatedAt() int64
- func (b *Blockchain) GetNodeFileItemFromFileHash(fileHash []byte) ([]*NodeItem, error)
- func (b *Blockchain) GetNodeItem(nodeHash []byte) (*NodeItem, error)
- func (b *Blockchain) GetNounceFromMemPool(address []byte) uint64
- func (b *Blockchain) GetParentNodeItem(nodeHash []byte) (*NodeItem, error)
- func (b *Blockchain) GetPermissionFromRootNode(rootNode *NodeItem, fromAddr []byte) (owner, admin, poster bool)
- func (b *Blockchain) GetReleasedFeesOfDownloadContractInTransactionData(contractHash []byte) ([]DownloadContractInTransactionDataTxHash, error)
- func (b *Blockchain) GetRootNodeItem(nodeHash []byte) (*NodeItem, error)
- func (b *Blockchain) GetTotalChannelNodesChilds(parentHash []byte) uint64
- func (b *Blockchain) GetTransactionByHash(hash []byte) ([]transaction.Transaction, []uint64, error)
- func (b *Blockchain) GetTransactionsFromPool() []transaction.Transaction
- func (b *Blockchain) IncrementHeightBy(h uint64)
- func (b *Blockchain) InitOrLoad(verifyAllBlocks bool) error
- func (b *Blockchain) PerformAddressStateUpdate(transaction transaction.Transaction, verifierAddr []byte, isCoinbase bool) error
- func (b *Blockchain) PerformStateUpdateFromBlock(validBlock block.Block) error
- func (b *Blockchain) PutBlockPool(block block.Block) error
- func (b *Blockchain) PutMemPool(tx transaction.Transaction) error
- func (b *Blockchain) SaveBlockInDB(blck block.Block) error
- func (b *Blockchain) SetHeight(h uint64)
- func (b *Blockchain) SetLastBlockHash(data []byte) error
- func (b *Blockchain) UpdateAddressState(address []byte, state AddressState) error
- type DownloadContractInTransactionDataTxHash
- type FileMetadata
- type Interface
- type NodeItem
- func (*NodeItem) Descriptor() ([]byte, []int)deprecated
- func (x *NodeItem) GetAdmins() [][]byte
- func (x *NodeItem) GetAttributes() [][]byte
- func (x *NodeItem) GetContentType() string
- func (x *NodeItem) GetDescription() string
- func (x *NodeItem) GetEnabled() bool
- func (x *NodeItem) GetFileHash() []byte
- func (x *NodeItem) GetMerkleRoot() []byte
- func (x *NodeItem) GetName() string
- func (x *NodeItem) GetNodeHash() []byte
- func (x *NodeItem) GetNodeType() NodeItemType
- func (x *NodeItem) GetOwner() []byte
- func (x *NodeItem) GetParentHash() []byte
- func (x *NodeItem) GetPosters() [][]byte
- func (x *NodeItem) GetSize() uint64
- func (x *NodeItem) GetTimestamp() int64
- func (*NodeItem) ProtoMessage()
- func (x *NodeItem) ProtoReflect() protoreflect.Message
- func (x *NodeItem) Reset()
- func (x *NodeItem) String() string
- type NodeItemType
- func (NodeItemType) Descriptor() protoreflect.EnumDescriptor
- func (x NodeItemType) Enum() *NodeItemType
- func (NodeItemType) EnumDescriptor() ([]byte, []int)deprecated
- func (x NodeItemType) Number() protoreflect.EnumNumber
- func (x NodeItemType) String() string
- func (NodeItemType) Type() protoreflect.EnumType
- type NodeItems
Constants ¶
This section is empty.
Variables ¶
var ( // ChannelCreationFeesFFG required amount to register a channel. ChannelCreationFeesFFG = int64(400) // RemainingChannelOperationFeesMiliFFG any other channel node item creation fees. RemainingChannelOperationFeesMiliFFG = int64(100) )
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.
var File_blockchain_types_proto protoreflect.FileDescriptor
Functions ¶
func CalculateChannelActionsFees ¶ added in v1.1.7
CalculateChannelActionsFees given a list of node items it calculates the amount of fees required.
func MarshalAddressStateProto ¶
func MarshalAddressStateProto(b *AddressStateProto) ([]byte, error)
MarshalAddressStateProto serializes an address state to a protobuf message.
Types ¶
type AddressState ¶
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) 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) ([]*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) 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) 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 ¶
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) ([]*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) }
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) GetAttributes ¶
func (*NodeItem) GetContentType ¶
func (*NodeItem) GetDescription ¶
func (*NodeItem) GetEnabled ¶
func (*NodeItem) GetFileHash ¶
func (*NodeItem) GetMerkleRoot ¶
func (*NodeItem) GetNodeHash ¶
func (*NodeItem) GetNodeType ¶
func (x *NodeItem) GetNodeType() NodeItemType
func (*NodeItem) GetParentHash ¶
func (*NodeItem) GetPosters ¶
func (*NodeItem) GetTimestamp ¶
func (*NodeItem) ProtoMessage ¶
func (*NodeItem) ProtoMessage()
func (*NodeItem) ProtoReflect ¶
func (x *NodeItem) ProtoReflect() protoreflect.Message
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) Descriptor() protoreflect.EnumDescriptor
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 (x NodeItemType) Number() protoreflect.EnumNumber
func (NodeItemType) String ¶
func (x NodeItemType) String() string
func (NodeItemType) Type ¶
func (NodeItemType) Type() protoreflect.EnumType
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) ProtoMessage ¶
func (*NodeItems) ProtoMessage()
func (*NodeItems) ProtoReflect ¶
func (x *NodeItems) ProtoReflect() protoreflect.Message