docgraph

package module
v0.0.0-...-f8ded45 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: MIT Imports: 12 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FlexValueVariant = eos.NewVariantDefinition([]eos.VariantType{
	{Name: "monostate", Type: int64(0)},
	{Name: "name", Type: eos.Name("")},
	{Name: "string", Type: ""},
	{Name: "asset", Type: eos.Asset{}},
	{Name: "time_point", Type: eos.TimePoint(0)},
	{Name: "int64", Type: int64(0)},
	{Name: "checksum256", Type: eos.Checksum256([]byte("0"))},
})

FlexValueVariant may hold a name, int64, asset, string, or time_point

Functions

func CreateEdge

func CreateEdge(ctx context.Context, api *eos.API,
	contract, creator eos.AccountName,
	fromNode, toNode eos.Checksum256,
	edgeName eos.Name) (string, error)

CreateEdge creates an edge from one document node to another with the specified name

func DefaultProgressBar

func DefaultProgressBar(prefix string, counter int) *progressbar.ProgressBar

func EdgeExists

func EdgeExists(ctx context.Context, api *eos.API, contract eos.AccountName,
	fromNode, toNode Document, edgeName eos.Name) (bool, error)

EdgeExists checks to see if the edge exists

func EraseDocument

func EraseDocument(ctx context.Context, api *eos.API,
	contract eos.AccountName,
	hash eos.Checksum256) (string, error)

EraseDocument ...

func GetVariants

func GetVariants() *eos.VariantDefinition

GetVariants returns the definition of types compatible with FlexValue

func RemoveEdge

func RemoveEdge(ctx context.Context, api *eos.API,
	contract eos.AccountName,
	fromHash, toHash eos.Checksum256, edgeName eos.Name) (string, error)

RemoveEdge ...

Types

type ContentGroup

type ContentGroup []ContentItem

ContentGroup ...

func (*ContentGroup) GetContent

func (cg *ContentGroup) GetContent(label string) (*FlexValue, error)

GetContent returns a FlexValue of the content with the matching label or an instance of ContentNotFoundError

type ContentItem

type ContentItem struct {
	Label string     `json:"label"`
	Value *FlexValue `json:"value"`
}

ContentItem ...

func (*ContentItem) IsEqual

func (c *ContentItem) IsEqual(c2 ContentItem) bool

IsEqual evalutes if the label, value type and value impl are the same

type ContentNotFoundError

type ContentNotFoundError struct {
	Label        string
	DocumentHash eos.Checksum256
}

ContentNotFoundError is used when content matching a specific label is requested but not found in a document

func (*ContentNotFoundError) Error

func (c *ContentNotFoundError) Error() string

type Document

type Document struct {
	ID            uint64          `json:"id"`
	Hash          eos.Checksum256 `json:"hash"`
	Creator       eos.AccountName `json:"creator"`
	ContentGroups []ContentGroup  `json:"content_groups"`
	Certificates  []struct {
		Certifier         eos.AccountName    `json:"certifier"`
		Notes             string             `json:"notes"`
		CertificationDate eos.BlockTimestamp `json:"certification_date"`
	} `json:"certificates"`
	CreatedDate eos.BlockTimestamp `json:"created_date"`
}

Document is a node in the document graph A document may hold any arbitrary, EOSIO compatible data

func CreateDocument

func CreateDocument(ctx context.Context, api *eos.API,
	contract, creator eos.AccountName,
	fileName string) (Document, error)

CreateDocument creates a new document on chain from the provided file

func GetAllDocuments

func GetAllDocuments(ctx context.Context, api *eos.API, contract eos.AccountName) ([]Document, error)

GetAllDocuments reads all documents and returns them in a slice

func GetAllDocumentsForType

func GetAllDocumentsForType(ctx context.Context, api *eos.API, contract eos.AccountName, docType string) ([]Document, error)

GetAllDocumentsForType reads all documents and returns them in a slice

func GetDocumentsWithEdge

func GetDocumentsWithEdge(ctx context.Context, api *eos.API, contract eos.AccountName, document Document, edgeName eos.Name) ([]Document, error)

GetDocumentsWithEdge retrieves a list of documents connected to the provided document via the provided edge name

func GetLastDocument

func GetLastDocument(ctx context.Context, api *eos.API, contract eos.AccountName) (Document, error)

GetLastDocument retrieves the last document that was created from the contract

func GetLastDocumentOfEdge

func GetLastDocumentOfEdge(ctx context.Context, api *eos.API, contract eos.AccountName, edgeName eos.Name) (Document, error)

GetLastDocumentOfEdge ...

func LoadDocument

func LoadDocument(ctx context.Context, api *eos.API,
	contract eos.AccountName,
	hash string) (Document, error)

LoadDocument reads a document from the blockchain and creates a Document instance

func (*Document) GetContent

func (d *Document) GetContent(label string) (*FlexValue, error)

GetContent returns a FlexValue of the content with the matching label or an instance of ContentNotFoundError

func (*Document) GetContentFromGroup

func (d *Document) GetContentFromGroup(groupLabel, label string) (*FlexValue, error)

GetContentFromGroup returns a FlexValue of the content with the matching label or an instance of ContentNotFoundError

func (*Document) GetContentGroup

func (d *Document) GetContentGroup(label string) (*ContentGroup, error)

GetContentGroup returns a ContentGroup matching the label or an instance of ContentNotFoundError

func (*Document) GetNodeLabel

func (d *Document) GetNodeLabel() string

GetNodeLabel returns a string for the node label

func (*Document) GetType

func (d *Document) GetType() (eos.Name, error)

GetType return the document type; fails if it does not exist or is not an eos.Name type

func (*Document) IsEqual

func (d *Document) IsEqual(d2 Document) bool

IsEqual is a deep equal comparison of two documents

type DocumentGraph

type DocumentGraph struct {
	RootNode Document
}

DocumentGraph is defined by a root node, and is aware of nodes and edges

type Edge

type Edge struct {
	ID          uint64             `json:"id"`
	Creator     eos.Name           `json:"creator"`
	FromNode    eos.Checksum256    `json:"from_node"`
	ToNode      eos.Checksum256    `json:"to_node"`
	EdgeName    eos.Name           `json:"edge_name"`
	CreatedDate eos.BlockTimestamp `json:"created_date"`
}

Edge is a directional, named connection from one graph to another

func GetAllEdges

func GetAllEdges(ctx context.Context, api *eos.API, contract eos.AccountName) ([]Edge, error)

GetAllEdges reads all documents and returns them in a slice

func GetEdgesFromDocument

func GetEdgesFromDocument(ctx context.Context, api *eos.API, contract eos.AccountName, document Document) ([]Edge, error)

GetEdgesFromDocument retrieves a list of edges from this node to other nodes

func GetEdgesFromDocumentWithEdge

func GetEdgesFromDocumentWithEdge(ctx context.Context, api *eos.API, contract eos.AccountName, document Document, edgeName eos.Name) ([]Edge, error)

GetEdgesFromDocumentWithEdge retrieves a list of edges from this node to other nodes

func GetEdgesToDocument

func GetEdgesToDocument(ctx context.Context, api *eos.API, contract eos.AccountName, document Document) ([]Edge, error)

GetEdgesToDocument retrieves a list of edges to this node from other nodes

func GetEdgesToDocumentWithEdge

func GetEdgesToDocumentWithEdge(ctx context.Context, api *eos.API, contract eos.AccountName, document Document, edgeName eos.Name) ([]Edge, error)

GetEdgesToDocumentWithEdge retrieves a list of edges from this node to other nodes

type FlexValue

type FlexValue struct {
	eos.BaseVariant
}

FlexValue may hold any of the common EOSIO types name, int64, asset, string, time_point, or checksum256

func (*FlexValue) Asset

func (fv *FlexValue) Asset() (eos.Asset, error)

Asset returns a string value of found content or it panics

func (*FlexValue) Int64

func (fv *FlexValue) Int64() (int64, error)

Int64 returns a string value of found content or it panics

func (*FlexValue) IsEqual

func (fv *FlexValue) IsEqual(fv2 *FlexValue) bool

IsEqual evaluates if the two FlexValues have the same types and values (deep compare)

func (*FlexValue) MarshalJSON

func (fv *FlexValue) MarshalJSON() ([]byte, error)

MarshalJSON translates to []byte

func (*FlexValue) Name

func (fv *FlexValue) Name() (eos.Name, error)

Name returns a string value of found content or it panics

func (*FlexValue) String

func (fv *FlexValue) String() string

func (*FlexValue) TimePoint

func (fv *FlexValue) TimePoint() (eos.TimePoint, error)

TimePoint returns a eos.TimePoint value of found content

func (*FlexValue) UnmarshalBinary

func (fv *FlexValue) UnmarshalBinary(decoder *eos.Decoder) error

UnmarshalBinary ...

func (*FlexValue) UnmarshalJSON

func (fv *FlexValue) UnmarshalJSON(data []byte) error

UnmarshalJSON translates flexValueVariant

type Graph

type Graph struct {
	Nodes []*Node
	Edges []*Edge
	// contains filtered or unexported fields
}

Graph ...

func LoadGraph

func LoadGraph(ctx context.Context, api *eos.API, contract eos.AccountName) (*Graph, error)

LoadGraph ...

func (*Graph) AddNode

func (g *Graph) AddNode(n *Node)

AddNode ...

func (*Graph) Connect

func (g *Graph) Connect(n1, n2 *Node, edgeName eos.Name)

Connect adds an edge to the graph

type InvalidTypeError

type InvalidTypeError struct {
	Label        string
	ExpectedType string
	FlexValue    *FlexValue
}

InvalidTypeError is used the type of a FlexValue doesn't match expectations

func (*InvalidTypeError) Error

func (c *InvalidTypeError) Error() string

type Node

type Node struct {
	OutboundEdges map[eos.Name][]*Node
	InboundEdges  map[eos.Name][]*Node
	// contains filtered or unexported fields
}

Node ...

type RemoveEdges

type RemoveEdges struct {
	FromNode eos.Checksum256 `json:"from_node"`
	EdgeName eos.Name        `json:"edge_name"`
	Strict   bool            `json:"strict"`
}

RemoveEdges ...

Jump to

Keyboard shortcuts

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