tela

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

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

Go to latest
Published: Aug 6, 2025 License: MIT Imports: 32 Imported by: 1

README

TELA: Decentralized Web Standard

Table of Contents

What Is TELA?

TELA enables the secure and decentralized storage of application files on DERO's blockchain using smart contracts. This innovative standard ensures the integrity and authenticity of stored files, allowing them to be retrieved from the blockchain and executed locally in a browser. By doing so, TELA enhances user privacy and control over browser-based applications, eliminating the reliance on third-party servers.

How It Works

TELA applications are built on two key smart contract components:

TELA-INDEX-1 Contract: This serves as the entrypoint for TELA applications. Users can simply input the SCID (Smart Contract ID) of any deployed TELA-INDEX-1 contract to retrieve the necessary files to run the application locally. This process can be demonstrated using tools like the civilware/tela go package or similar methods to parse a TELA-INDEX-1 according to this standard, creating a host app for all TELA content.

TELA-DOC-1 Contract: This contains the essential code required by the application. TELA supports common programming languages such as, but not limited to:

  • HTML
  • JSON
  • JavaScript
  • CSS
  • Markdown

Multiple TELA-DOC-1 contracts can be installed and embedded within a TELA-INDEX-1 application, allowing the use of extensive codebases beyond DERO’s DVM-BASIC smart contract language. These contracts can also install necessary libraries and tools on the blockchain, facilitating modular development through reusable code.

Additional Features

  • File Management: TELA ensures application code remains in an unalterable state using a combination of mutable (TELA-INDEX-1) and immutable (TELA-DOC-1) contracts. This structure provides a commit-based system that allows for application updates, code verification, and retrieval of previous contract states.

  • Connectivity: TELA supports DERO's XSWD protocol, enabling permissioned web socket interactions with DERO wallets, enhancing connectivity and user interaction.

  • Contract Identification: TELA contracts utilize the header structure from the ART-NFA Standard, making them easily identifiable and ensuring consistent integration within the DERO ecosystem.

By leveraging these components and features, TELA represents a significant advancement in secure, decentralized web applications, fostering an environment where privacy, security, and user autonomy are paramount.

Get Started

See the following for more information on how to get started creating and installing your TELA application:

  • TELA-INDEX-1

    Entrypoint and manifest for TELA applications

  • TELA-DOC-1

    TELA application files and libraries

  • TELA-MOD-1

    Additional TELA building blocks which extend the standard's features.

Accessing TELA Content

The minimum requirements to access TELA content are:

  • Connection to a DERO node
  • Any host application that can serve TELA content

The civilware/tela go package aims to be a simple entrypoint for hosting and managing TELA content and can be used as the foundation for creating compliant host applications.

Compliant Host Applications

Content Rating System

TELA smart contracts have a rating system integrated into each contract to help developers and users navigate content. Ratings can be interpreted for a quick judgment, or can be used to gather further details about content. A guide to the content rating system is as follows:

  • One rating per DERO account, per contract.
  • A rating is a positive number < 100.
  • Ringsize of 2 is required for a Rate transaction.
  • The smart contract stores the rating number and the address of the rater.
  • The smart contract also adds to a likes or dislikes value store based on the given rating, dislike is a rating < 50.
  • Standard gas fees apply when making a Rate transaction.

A quick tally of the like and dislike values or gathering the average rating number can give a brief overview of how the content has been received by others. For a more detailed review of content, TELA has provided a structure for the 0-99 rating numbers, attaching them to a wider range of subjective comments while still supporting the basic "higher number is better" mentality for overall ease of use. The civilware/tela package can generate rating strings using the following interpretation:

Numbers are broken down into place values.

  • Ex, 24 = first place 2 and second place 4.
  • Ex, 8 = first place 0 and second place 8.

Each place is given different values. The first place represents the rating category.

Rating Categories

First Place Category
0 Do not use
1 Broken
2 Major issues
3 Minor issues
4 Should be improved
5 Could be improved
6 Average
7 Good
8 Very good
9 Exceptional

The second place represents a detail tag. Positive and negative rating categories each have their own set of detail tags, sharing some common ones between them.

Detail Tags

Second Place Negative Detail Tags Positive Detail Tags
0 Nothing Nothing
1 Needs review Needs review
2 Needs improvement Needs improvement
3 Bugs Bugs
4 Errors Errors
5 Inappropriate Visually appealing
6 Incomplete In depth
7 Corrupted Works well
8 Plagiarized Unique
9 Malicious Benevolent

This format would produce the following strings given some example rating numbers:

Rating String
80 Very good
77 Good, Works well
43 Should be improved, Bugs
7 Do not use, Corrupted

Package Use

The main usage of the civilware/tela go package is to query a deployed TELA-INDEX-1 SCID from a connected node and serve the content on a URL such as localhost:8081/tela/

Serving
import (
	"github.com/civilware/tela"
)

func main() {
	endpoint := "127.0.0.1:20000"
	scid := "a842dac04587000b019a7aeee55d7e3e5df40f959b0bd36a474cda67936e9399"
	url, err := tela.ServeTELA(scid, endpoint)
	if err != nil {
		// Handle error
	}
	// Code to open url in local browser
	// ..
	// Shutdown all TELA servers when done
	tela.ShutdownTELA()
}
Installing

TELA content can be installed in a manner of ways. The civilware/tela package takes the necessary data for the type of smart contract and creates the applicable transfer arguments and code to easily install the new contract. For manual installation see here.

import (
	"fmt"

	"github.com/civilware/tela"
	"github.com/deroproject/derohe/rpc"
	"github.com/deroproject/derohe/walletapi"
)

func main() {
	// Create DOC (or INDEX) with all relevant data
	doc := &tela.DOC{
		DocType: tela.DOC_HTML,
		Code:    "<HTML_CODE_HERE>",
		SubDir:  "",
		DURL:    "app.tela",
		Headers: tela.Headers{
			NameHdr:  "index.html",
			DescrHdr: "HTML index file",
			IconHdr:  "ICON_URL",
		},
		Signature: tela.Signature{
			CheckC: "c4d7bbdaaf9344f4c351e72d0b2145b4235402c89510101e0500f43969fd1387",
			CheckS: "b879b0ff01d78841d61e9770fd18436d8b9afce59302c77a786272e7422c15f6",
		},
	}

	// Pass doc to NewInstallArgs() to create smart contract and transfer arguments
	args, err := tela.NewInstallArgs(doc)
	if err != nil {
		// Handle error
	}
	fmt.Printf("SC Code: %s\n", args.Value(rpc.SCCODE, rpc.DataString))
	// Code to make transfer call with WS/RPC and install args

	// // //
	// //
	// Alternatively, Installer() takes a DOC or INDEX and installs it with the given walletapi
	ringsize := uint64(2)
	// ringsize 2 allows installed INDEX contracts to be updated (public)
	// ringsize > 2 will make the installed INDEX contract immutable (anonymous)
	txid, err := tela.Installer(&walletapi.Wallet_Disk{}, ringsize, doc)
	if err != nil {
		// Handle error
	}
	fmt.Printf("Installed TELA SCID: %s\n", txid)
}
Updating

Updating TELA-INDEX-1's can be managed similarly to new installs. The values provided for updating the smart contract will be embedded into its new code making them available when the code is parsed post update, while the original variable stores for those values will remain unchanged preserving the contract's origin. The TXID generated by each update execution is stored in the smart contract, allowing for reference to the code changes that have taken place. For manual update procedures see here.

import (
	"fmt"

	"github.com/civilware/tela"
	"github.com/deroproject/derohe/walletapi"
)

func main() {
	// Create the INDEX to be updated, including all its relevant data
	scid := "8dd839608e584f75b64c0ca7ff2c274879677ac3aaf60159c78797ee518946c2"

	index := &tela.INDEX{
		SCID: scid,
		DURL: "app.tela",
		DOCs: []string{"<scid>", "<scid>"},
		Headers: tela.Headers{
			NameHdr:  "TELA App",
			DescrHdr: "A TELA Application",
			IconHdr:  "ICON_URL",
		},
	}

	// Pass index to NewUpdateArgs() to create transfer arguments for update call
	args, err := tela.NewUpdateArgs(index)
	if err != nil {
		// Handle error
	}
	// Code to make transfer call with WS/RPC and update args

	// // //
	// //
	// Alternatively, Updater() takes an INDEX and updates it with the given walletapi
	txid, err := tela.Updater(&walletapi.Wallet_Disk{}, index)
	if err != nil {
		// Handle error
	}
	fmt.Printf("Update TXID: %s %s\n", txid, err)

	// // //
	// //
	// GetINDEXInfo() can be used to preform INDEX data from an existing SCID
	endpoint := "127.0.0.1:20000"
	liveIndex, _ := tela.GetINDEXInfo(scid, endpoint)
	liveIndex.DOCs = []string{"<scid>", "<scid>"}
	args, _ = tela.NewUpdateArgs(&liveIndex)
}
Variables

Publicly deployed TELA-INDEX-1 contracts that have enabled TELA-MOD-1's can store arbitrary data. DERO wallets can set or delete key-value pairs. When executing a variable store operation it does not affect the commit state of the TELA-INDEX-1. The various TELA-MOD-1's offer developers a wide range of versatility for making dynamic TELA content by allowing the variables stores to be view only, give them overwrite permissions or make them immutable.

import (
	"github.com/civilware/tela"
	"github.com/deroproject/derohe/walletapi"
)

func main() {
	scid := "e2a7384d2a1a6a99d9899d0db10891e5c3466823eadb039c18ec92fbcf2f8b89"
	key := "key"
	value := "value"

	txid, err := tela.SetVar(&walletapi.Wallet_Disk{}, scid, key, value)
	if err != nil {
		// Handle error
	}
	// Variable is stored in SC, the SC stores keys with a "var_" prefix

	txid, err = tela.DeleteVar(&walletapi.Wallet_Disk{}, scid, key)
	if err != nil {
		// Handle error
	}
	// Key is deleted

	// Check if a TELA key exists on a SC
	endpoint := "127.0.0.1:20000"
	_, exists, _ := tela.KeyExists(scid, fmt.Sprintf("var_%s", key), endpoint)
	if exists {
		// Found key
	}
}
Rating

Rating TELA content is a straightforward process, a DERO wallet submits a Rate transaction to a TELA SCID which gets stored in the smart contract's public ratings. The civilware/tela package's extended content rating system components are exported to make integrating the same TELA interpretations an easy task. For manual rating procedures see here.

import (
	"fmt"

	"github.com/civilware/tela"
	"github.com/deroproject/derohe/walletapi"
)

func main() {
	// Define rating and scid
	rating := uint64(0)
	scid := "c4d7bbdaaf9344f4c351e72d0b2145b4235402c89510101e0500f43969fd1387"

	// Pass params to NewRateArgs() to create transfer arguments for Rate call
	args, err := tela.NewRateArgs(scid, rating)
	if err != nil {
		// Handle error
	}
	// Code to make transfer call with WS/RPC and rate args

	// // //
	// //
	// Alternatively, Rate() takes a TELA scid and rating and rates the contract with the given walletapi
	txid, err := tela.Rate(&walletapi.Wallet_Disk{}, scid, rating)
	if err != nil {
		// Handle error
	}
	fmt.Printf("Rate TXID: %s\n", txid)

	// // //
	// //
	// GetRating() gets the rating results from a scid
	endpoint := "127.0.0.1:20000"
	height := uint64(0) // Results can be filtered by height showing ratings that occurred >= height
	result, err := tela.GetRating(scid, endpoint, height)
	if err != nil {
		// Handle error
	}
	fmt.Printf("Likes: %d, Dislikes: %d Average: %d\n", result.Likes, result.Dislikes, result.Average)

	// // //
	// //
	// The package's rating structures can be accessed using the Rating variable
	category, detail, _ := tela.Ratings.Parse(rating)

	// Get a rating string formatted as "Category (detail)"
	ratingString, _ := tela.Ratings.ParseString(rating)

	// Get the category of a rating
	category = tela.Ratings.Category(rating)

	// Get the detail tag from a rating
	detail = tela.Ratings.Detail(rating, false)

	// Get all TELA rating categories
	categories := tela.Ratings.Categories()

	// Get all TELA negative details
	negativeDetails := tela.Ratings.NegativeDetails()

	// Get all TELA positive details
	positiveDetails := tela.Ratings.PositiveDetails()
}
Parse

The civilware/tela package has exported much of the functionality used in the necessary components to create TELA content stored on the DERO blockchain. The parsing and header tools can be of great use to developers working with any DVM smart contract.

package main

import (
	"github.com/civilware/tela"
)

func main() {
	// Parse a file name for its respective TELA docType
	fileName := "index.html"
	docType := tela.ParseDocType(fileName)

	// Parse a TELA-INDEX-1 for any embedded DOCs
	scCode := tela.TELA_INDEX_1
	docSCID, _ := tela.ParseINDEXForDOCs(scCode)

	// Parse a DERO signature for its address, C and S values
	signature := []byte("-----BEGIN DERO SIGNED MESSAGE-----")
	address, c, s, _ := tela.ParseSignature(signature)

	// Get all function names from DERO smart contract code
	functionNames := tela.GetSmartContractFuncNames(scCode)

	// Compare equality between two DERO smart contracts
	dvmCode, _ := tela.EqualSmartContracts(scCode, scCode)

	// Format DERO smart contract code removing whitespace and comments
	formattedCode, _ := tela.FormatSmartContract(dvmCode, scCode)

	// Create DocShard files from a source file
	tela.CreateShardFiles(fileName, "", nil)

	// Recreate a file in path from its DocShards
	path := "dir1/"
	docShards := [][]byte{}
	tela.ConstructFromShards(docShards, fileName, path, "")

	// Parse and inject headers into a DERO smart contract
	headers1 := &tela.Headers{
		NameHdr:  "myNameHdr",
		DescrHdr: "myDescrHdr",
		IconHdr:  "myIconURL",
	}
	formattedCode, _ = tela.ParseHeaders(scCode, headers1)

	// ParseHeaders takes various input formats for a wide range of use
	headers2 := &tela.INDEX{
		DURL:    "",
		DOCs:    []string{"<scid>"},
		Headers: *headers1,
	}
	formattedCode, _ = tela.ParseHeaders(scCode, headers2)

	// Including any custom headers
	headers3 := map[tela.Header]interface{}{
		tela.HEADER_NAME:           "myNameHdr",
		tela.HEADER_ICON_URL:       "myIconURL",
		tela.Header(`"customHdr"`): "myCustomHdr",
	}
	formattedCode, _ = tela.ParseHeaders(scCode, headers3)

	headers4 := map[string]interface{}{
		`"nameHdr"`:    "myNameHdr",
		`"iconURLHdr"`: "myIconURL",
		`"customHdr"`:  "myCustomHdr",
	}
	formattedCode, _ = tela.ParseHeaders(scCode, headers4)
}

TELA-CLI

Changelog

License

Documentation

Index

Constants

View Source
const (
	DVM_FUNC_INIT_PRIVATE = "InitializePrivate"
	DVM_FUNC_INIT         = "Initialize"

	SHARD_SIZE             = int64(17500)   // Defines the docCode size of a DocShard
	MAX_DOC_CODE_SIZE      = float64(18)    // DOC SC template file size is +1.2KB with headers
	MAX_DOC_INSTALL_SIZE   = float64(19.2)  // DOC SC total file size (including docCode) should be below this
	MAX_INDEX_INSTALL_SIZE = float64(11.64) // INDEX SC file size should be below this
)
View Source
const (
	COMPRESSION_GZIP = ".gz"
)
View Source
const DEFAULT_MAX_PORT = 65535 // Maximum port of possible serving range
View Source
const DEFAULT_MAX_SERVER = 20 // Default max amount of servers
View Source
const DEFAULT_MIN_PORT = 1200 // Minimum port of possible serving range
View Source
const DEFAULT_PORT_START = 8082 // Default start port for servers
View Source
const DOC_CSS = "TELA-CSS-1" // CSS docType
View Source
const DOC_GO = "TELA-GO-1" // Golang docType
View Source
const DOC_HTML = "TELA-HTML-1" // HTML docType
View Source
const DOC_JS = "TELA-JS-1" // JavaScript docType
View Source
const DOC_JSON = "TELA-JSON-1" // JSON docType
View Source
const DOC_MD = "TELA-MD-1" // Markdown docType
View Source
const DOC_STATIC = "TELA-STATIC-1" // Generic docType for any file type
View Source
const MINIMUM_GAS_FEE = uint64(100) // Minimum gas fee used when making transfers
View Source
const TAG_BOOTSTRAP = ".bootstrap" // A collection of TELA INDEXs or DOCs which can be used to bootstrap a list of applications or content (usage is appended to INDEX dURLs)
View Source
const TAG_DOC_SHARD = ".shard" // A DocShard DOC  (usage is appended to DOC dURLs)
View Source
const TAG_DOC_SHARDS = ".shards" // A collection of DocShard DOCs embedded within an INDEX, when recreated this will be one file  (usage is appended to INDEX dURLs)
View Source
const TAG_LIBRARY = ".lib" // A collection of standard DOCs embedded within an INDEX, each DOC is its own file  (usage is appended to INDEX and DOC dURLs)

Variables

View Source
var Ratings ratings

Access TELA ratings variables and functions

View Source
var TELA_DOC_1 string
View Source
var TELA_INDEX_1 string
View Source
var TELA_MOD_1_TXDWA string
View Source
var TELA_MOD_1_TXDWD string
View Source
var TELA_MOD_1_TXTO string
View Source
var TELA_MOD_1_VSOO string
View Source
var TELA_MOD_1_VSOOIM string
View Source
var TELA_MOD_1_VSPUBIM string
View Source
var TELA_MOD_1_VSPUBOW string
View Source
var TELA_MOD_1_VSPUBSU string

Functions

func AllowUpdates

func AllowUpdates(b bool)

AllowUpdates default is false and will not allow TELA content to be served that has been updated since its original install

func Clone

func Clone(scid, endpoint string) (err error)

Clone TELA content at SCID from endpoint

func CloneAtCommit

func CloneAtCommit(scid, txid, endpoint string) (err error)

Clone a TELA-INDEX SC at a commit TXID from endpoint

func Compress

func Compress(data []byte, compression string) (result string, err error)

Compress TELA data using the given compression format

func ConstructFromShards

func ConstructFromShards(docShards [][]byte, recreate, basePath, compression string) (err error)

ConstructFromShards takes DocShards and recreates them as a file at basePath, CreateShardFiles can be used to create the shard files formatted for ConstructFromShards

func CreateShardFiles

func CreateShardFiles(filePath, compression string, content []byte) (err error)

CreateShardFiles takes a source file and creates DocShard files sized and formatted for installing as TELA DOCs, the package uses ConstructFromShards to re-build the DocShards as its original file when cloning, output files are formatted as "name-#.ext+compression" in the source file's directory if content is nil the filePath will be read and compression will be applied if used, otherwise content will be handled as is

func Decompress

func Decompress(data []byte, compression string) (result []byte, err error)

Decompress TELA data using the given compression format, if compression is "" result will return the original data

func DeleteVar

func DeleteVar(wallet *walletapi.Wallet_Disk, scid, key string) (txid string, err error)

Delete a K/V store from a TELA SC, requires wallet to be owner of SC

func EqualSmartContracts

func EqualSmartContracts(c, v string) (contract dvm.SmartContract, err error)

EqualSmartContract compares if c is equal to v by parsing function lines and parts, it compares all functions other than InitializePrivate/Initialize, contract returned is dvm.SmartContract of v when equal

func FindOpenPort

func FindOpenPort() (server *http.Server, found bool)

Listen for open ports and returns http server for TELA content on open port if found

func FormatSmartContract

func FormatSmartContract(sc dvm.SmartContract, code string) (formatted string, err error)

Formats dvm.SmartContract to string, removes whitespace and comments from original

func GetClonePath

func GetClonePath() string

Get the current clone datashard storage path

func GetCodeSizeInKB

func GetCodeSizeInKB(code string) float64

Find how many KB code string is, counting for new lines in total size

func GetDefaultNetworkAddress

func GetDefaultNetworkAddress() (network, destination string)

Get a default DERO transfer address for the network defined by globals.Arguments --testnet and --simulator flags

func GetGasEstimate

func GetGasEstimate(wallet *walletapi.Wallet_Disk, ringsize uint64, transfers []rpc.Transfer, args rpc.Arguments) (gasFees uint64, err error)

Get DERO gas estimate for transfers and args

func GetPath

func GetPath() string

Get the current TELA datashard storage path

func GetSmartContractFuncNames

func GetSmartContractFuncNames(code string) (names []string)

Parse DVM code string and return its functions names in written order

func GetTotalShards

func GetTotalShards(data []byte) (totalShards int, fileSize int64)

Get the total amount of shards that would be created if data is used to CreateShardFiles

func HasServer

func HasServer(name string) bool

Check if TELA has existing server by name

func Installer

func Installer(wallet *walletapi.Wallet_Disk, ringsize uint64, params interface{}) (txid string, err error)

Install TELA smart contracts with DERO walletapi

func IsAcceptedLanguage

func IsAcceptedLanguage(language string) bool

Check if language used is accepted by TELA, see acceptedLanguages for full list

func IsCompressedExt

func IsCompressedExt(ext string) bool

IsCompressedExt returns true if ext is a valid TELA compression format

func KeyExists

func KeyExists(scid, key, endpoint string) (variable string, exists bool, err error)

Check if key is stored in SCID at endpoint

func KeyPrefixExists

func KeyPrefixExists(scid, prefix, endpoint string) (key, variable string, exists bool, err error)

Check if prefixed key is stored in SCID at endpoint

func MaxServers

func MaxServers() int

Check the maximum amount of TELA servers

func NewDeleteVarArgs

func NewDeleteVarArgs(scid, key string) (args rpc.Arguments, err error)

Create arguments for TELA DeleteVar SC call

func NewInstallArgs

func NewInstallArgs(params interface{}) (args rpc.Arguments, err error)

Create arguments for INDEX or DOC SC install

func NewModTag

func NewModTag(tags []string) (modTag string)

NewModTag returns a modTag string from the given tag elements

func NewRateArgs

func NewRateArgs(scid string, rating uint64) (args rpc.Arguments, err error)

Create arguments for TELA Rate SC call

func NewSetVarArgs

func NewSetVarArgs(scid, key, value string) (args rpc.Arguments, err error)

Create arguments for TELA SetVar SC call

func NewUpdateArgs

func NewUpdateArgs(params interface{}) (args rpc.Arguments, err error)

Create arguments for INDEX SC UpdateCode call

func OpenTELALink(telaLink, endpoint string) (link string, err error)

OpenTELALink will open content from a telaLink formatted as tela://open/<scid>/subDir/../.. if no server exists for that content it will try starting one using ServeTELA()

func ParseDocType

func ParseDocType(fileName string) (language string)

Parse a file for its TELA docType language

func ParseHeaders

func ParseHeaders(code string, headerType interface{}) (formatted string, err error)

ParseHeaders takes a headerType and SC code string then returns a formatted SC string with those header values See ART-NFA and TELA docs for detailed header info

func ParseINDEXForDOCs

func ParseINDEXForDOCs(code string) (scids []string, err error)

Parse an INDEX contract string for its DOC SCIDs

func ParseSignature

func ParseSignature(input []byte) (address, c, s string, err error)

Parse a DERO signature for address and C, S values

func ParseTELALink(telaLink string) (target string, args []string, err error)

ParseTELALink takes a TELA link and parses it for its target and args. Host applications can use TELA links in combination with custom websocket methods to set up and perform their own client specific actions. Usage examples:

  • target://<arg>/<arg>/<arg>...
  • tela://open/<scid>/subDir/../.. Use like a hyperlink to open external TELA content from a existing page, see OpenTelaLink()
  • client://module/explorer/<scid> Tell a client to open a specific module or page with args

func PortStart

func PortStart() int

Check the initial port that TELA content will be served from

func Rate

func Rate(wallet *walletapi.Wallet_Disk, scid string, rating uint64) (txid string, err error)

Rate a TELA SC positively (rating > 49) or negatively (rating < 50) with DERO walletapi, the transaction will use ringsize of 2

func ServeAtCommit

func ServeAtCommit(scid, txid, endpoint string) (link string, err error)

ServeAtCommit clones and serves a TELA-INDEX-1 SC from endpoint at commit TXID if the SC code from that commit can be decoded, ensure AllowUpdates is set true prior to calling ServeAtCommit otherwise it will return error

func ServeTELA

func ServeTELA(scid, endpoint string) (link string, err error)

ServeTELA clones and serves a TELA-INDEX-1 SC from endpoint and returns a link to the running TELA server if successful

func SetMaxServers

func SetMaxServers(i int)

Set the maximum amount of TELA servers which can be active

func SetPortStart

func SetPortStart(port int) (err error)

Set the initial port to start serving TELA content from if isValidPort

func SetShardPath

func SetShardPath(path string) (err error)

SetShardPath can be used to set a custom path for TELA DOC storage, TELA will remove all its files from the /tela directory when servers are Shutdown

func SetVar

func SetVar(wallet *walletapi.Wallet_Disk, scid, key, value string) (txid string, err error)

Set a K/V store on a TELA SC

func ShutdownServer

func ShutdownServer(name string)

ShutdownTELA shuts down running TELA servers by name, if two servers with same name exist both will shutdown

func ShutdownTELA

func ShutdownTELA()

ShutdownTELA shuts down all TELA servers and cleans up directory

func Transfer

func Transfer(wallet *walletapi.Wallet_Disk, ringsize uint64, transfers []rpc.Transfer, args rpc.Arguments) (txid string, err error)

Transfer is used for executing TELA smart contract actions with DERO walletapi, if nil transfers is passed it initializes a transfer of 0 to a default address for the network using GetDefaultNetworkAddress()

func TrimCompressedExt

func TrimCompressedExt(fileName string) string

TrimCompressedExt removes known compression extensions from the filename

func Updater

func Updater(wallet *walletapi.Wallet_Disk, params interface{}) (txid string, err error)

Update a TELA INDEX SC with DERO walletapi, requires wallet to be owner of SC

func UpdatesAllowed

func UpdatesAllowed() bool

Check if TELA server is allowed to serve TELA content that has been updated since its original install

func ValidateImageURL

func ValidateImageURL(imageURL, endpoint string) (svgCode string, err error)

ValidateImageURL will return error if the imageURL is not a valid URL or a valid image smart contract

Types

type Cloning

type Cloning struct {
	BasePath   string `json:"basePath"`   // Main directory path for TELA files
	ServePath  string `json:"servePath"`  // URL serve path
	Entrypoint string `json:"entrypoint"` // INDEX entrypoint
	DURL       string `json:"dURL"`       // TELA dURL
	Hash       string `json:"hash"`       // Commit hash of INDEX
}

Cloning structure for creating DOC/INDEX

type DOC

type DOC struct {
	DocType     string   `json:"docType"`           // Language this document is using (ex: "TELA-HTML-1", "TELA-JS-1" or "TELA-CSS-1")
	Code        string   `json:"code"`              // The application code HTML, JS... (when a DOC is returned this will be the SC code, the DocCode can be retrieved with ExtractDocCode)
	SubDir      string   `json:"subDir"`            // Sub directory to place file in (always use / for further children, ex: "sub1" or "sub1/sub2/sub3")
	SCID        string   `json:"scid"`              // SCID of this DOC, only used after DOC has been installed on-chain
	Author      string   `json:"author"`            // Author of this DOC, only used after DOC has been installed on-chain
	DURL        string   `json:"dURL"`              // TELA dURL
	Compression string   `json:"compression"`       // Compression format if used on this DOC (ex: .gz)
	SCVersion   *Version `json:"version,omitempty"` // Version of this DOC SC
	// Signature values of Code
	Signature `json:"signature"`
	// Standard headers
	Headers `json:"headers"`
}

TELA-DOC-1 structure

func GetDOCInfo

func GetDOCInfo(scid, endpoint string) (doc DOC, err error)

Get TELA-DOC info from scid at endpoint

func (*DOC) ExtractAsSVG

func (d *DOC) ExtractAsSVG() (svgCode string, err error)

ExtractAsSVG extends ExtractDocCode and validates that the DocCode is formatted for SVG images

func (*DOC) ExtractDocCode

func (d *DOC) ExtractDocCode() (docCode string, err error)

ExtractDocCode parses a DOC for its DocCode and decompresses it if required

func (*DOC) ExtractMetaTags

func (d *DOC) ExtractMetaTags() (metaTags []MetaTag, err error)

ExtractMetaTags parses a DOC for any <meta> within the DocCode and returns the tags

type Header string

Standard SC header keys

const (
	HEADER_NAME         Header = `"nameHdr"`
	HEADER_DESCRIPTION  Header = `"descrHdr"`
	HEADER_ICON_URL     Header = `"iconURLHdr"`
	HEADER_CHECK_C      Header = `"fileCheckC"`
	HEADER_CHECK_S      Header = `"fileCheckS"`
	HEADER_MODS         Header = `"mods"`
	HEADER_DURL         Header = `"dURL"`
	HEADER_DOCUMENT     Header = `"DOC` // append with Number()
	HEADER_SUBDIR       Header = `"subDir"`
	HEADER_DOCTYPE      Header = `"docType"`
	HEADER_COLLECTION   Header = `"collection"`
	HEADER_TYPE         Header = `"typeHdr"`
	HEADER_TAGS         Header = `"tagsHdr"`
	HEADER_FILE_URL     Header = `"fileURL"`
	HEADER_SIGN_URL     Header = `"fileSignURL"`
	HEADER_COVER_URL    Header = `"coverURL"`
	HEADER_ART_FEE      Header = `"artificerFee"`
	HEADER_ROYALTY      Header = `"royalty"`
	HEADER_OWNER        Header = `"owner"`
	HEADER_OWNER_UPDATE Header = `"ownerCanUpdate"`

	HEADER_NAME_V2        Header = `"var_header_name"`
	HEADER_DESCRIPTION_V2 Header = `"var_header_description"`
	HEADER_ICON_URL_V2    Header = `"var_header_icon"`

	LINE_MODS_STORE    = `34 STORE("mods", `
	LINE_DOC_VERSION   = `50 STORE("docVersion", `
	LINE_INDEX_VERSION = `50 STORE("telaVersion", `
)

func (Header) CanAppend

func (h Header) CanAppend() bool

Returns if Header can be appended. Headers ending in `"` or with len < 2 will return false

func (Header) Number

func (h Header) Number(i int) Header

Append a number to Header if applicable, otherwise return unchanged Header

func (Header) Trim

func (h Header) Trim() string

Trim any `"` from Header and return string

type Headers

type Headers struct {
	NameHdr  string `json:"nameHdr"`  // On-chain name of SC. For TELA-DOCs, they are recreated using this as the file name, it should include the file extension
	DescrHdr string `json:"descrHdr"` // On-chain description of DOC, INDEX or Asset SC
	IconHdr  string `json:"iconHdr"`  // On-chain icon URL, (size 100x100)
}

Standard SC header value stores

type INDEX

type INDEX struct {
	SCID      string            `json:"scid"`              // SCID of this INDEX, only used after INDEX has been installed on-chain
	Author    string            `json:"author"`            // Author of this INDEX, only used after INDEX has been installed on-chain
	DURL      string            `json:"dURL"`              // TELA dURL
	Mods      string            `json:"mods"`              // TELA modules string, stores addition functionality to be parsed when validating, module tags are separated by comma
	DOCs      []string          `json:"docs"`              // SCIDs of TELA DOCs embedded in this INDEX SC
	SCVersion *Version          `json:"version,omitempty"` // Version of this INDEX SC
	SC        dvm.SmartContract `json:"-"`                 // DVM smart contract is used for further parsing of installed INDEXs
	// Standard headers
	Headers `json:"headers"`
}

TELA-INDEX-1 structure

func GetINDEXInfo

func GetINDEXInfo(scid, endpoint string) (index INDEX, err error)

Get TELA-INDEX info from scid at endpoint

type Library

type Library struct {
	DURL       string  `json:"dURL"`       // TELA library dURL
	Author     string  `json:"author"`     // Author of the library
	SCID       string  `json:"scid"`       // SCID of the library DOC or INDEX
	LikesRatio float64 `json:"likesRatio"` // Likes to dislike ratio of the library
}

Library structure for search queries

type MOD

type MOD struct {
	Name          string        // The name of the MOD
	Tag           string        // The identifying tag for the MOD
	Description   string        // Description of what the MOD does
	FunctionCode  func() string // The embedded DVM code
	FunctionNames []string      // The function names from the DVM code
}

TELA-MOD structure

type MODClass

type MODClass struct {
	Name  string         // The name of the MODClass
	Tag   string         // The identifying tag for the MODClass
	Rules []MODClassRule // Any rules for the MODClass
}

MODClass structure is used to group similarly functioned MODs

func (*MODClass) NewTag

func (mc *MODClass) NewTag(tag string) string

NewTag returns a MOD tag prefixed with the MODClass tag

type MODClassRule

type MODClassRule struct {
	Name        string                         // Name of the rule
	Description string                         // Description of what the rule is enforcing
	Verify      func([]string, MODClass) error // Verification function checking that the parameters of the rule are met
}

MODClassRule structure contains data for the rules used within a MODClass

type MODs

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

MODs contains the package's TELA-MOD data structures and access, all MODClasses are held in the mods variable and can be separated by its index

var Mods MODs

Access the package's initialized TELA-MOD data

func (*MODs) Add

func (m *MODs) Add(class MODClass, mods []MOD) (err error)

Add a new MODClass and its MODs if they are valid

func (*MODs) Functions

func (m *MODs) Functions(tag string) (functionCode string, functionNames []string)

Functions returns the TELA-MOD function code and names for the given tag

func (*MODs) GetAllClasses

func (m *MODs) GetAllClasses() (classes []MODClass)

GetAllClasses returns all MODClasses

func (*MODs) GetAllMods

func (m *MODs) GetAllMods() (mods []MOD)

GetAllMods returns all TELA-MODs

func (*MODs) GetClass

func (m *MODs) GetClass(modTag string) (class MODClass)

GetClass returns a MODClass from a MOD tag

func (*MODs) GetMod

func (m *MODs) GetMod(tag string) (mod MOD)

GetMod returns a TELA-MOD by its tag string

func (*MODs) GetRules

func (m *MODs) GetRules() (rules []MODClassRule)

GetRules returns all of the MODClassesRules

func (*MODs) Index

func (m *MODs) Index() (ci []int)

Index returns the MODClass index

func (*MODs) InjectMODs

func (m *MODs) InjectMODs(modTag, code string) (modSC dvm.SmartContract, modCode string, err error)

InjectMODs parses the modTag ensuring all tags are valid before injecting the TELA-MOD code for the given MODs in the modTag

func (*MODs) Tag

func (m *MODs) Tag(i int) (tag string)

Tag returns a TELA-MOD tag string by index

func (*MODs) TagsAreValid

func (m *MODs) TagsAreValid(modTag string) (tags []string, err error)

ModTagsAreValid parses a modTag string formatted as "tag,tag,tag" returning its tags if all tags are valid and there is no conflicting tags. If an empty modTag is passed it will return no error and nil tags

func (*MODs) Verify

func (m *MODs) Verify() (err error)

Verify that all MODs present have the appropriate data and that there are no conflicting MODs or MODClasses

type MetaTag

type MetaTag string

MetaTag type for handling TELA DOC metadata

func (MetaTag) ExtractAttribute

func (tag MetaTag) ExtractAttribute(attribute string) (value string)

Extract the data from a MetaTag for the given attribute

type Rating

type Rating struct {
	Address string `json:"address"` // Address of the rater
	Rating  uint64 `json:"rating"`  // The 0-99 rating number
	Height  uint64 `json:"height"`  // The block height this rating occurred
}

A TELA SC rating

type Rating_Result

type Rating_Result struct {
	Ratings  []Rating `json:"ratings,omitempty"` // All ratings for a SC
	Likes    uint64   `json:"likes"`             // Likes for a SC
	Dislikes uint64   `json:"dislikes"`          // Dislikes for a SC
	Average  float64  `json:"average"`           // Average category value of all ratings, will be 0-10
}

TELA SC rating structure

func GetRating

func GetRating(scid, endpoint string, height uint64) (ratings Rating_Result, err error)

Get the rating of a TELA scid from endpoint. Result is all individual ratings, likes and dislikes and the average rating category. Using height will filter the individual ratings (including only >= height) this will not effect like and dislike results

func (*Rating_Result) ParseAverage

func (res *Rating_Result) ParseAverage() (category string)

Parse the average rating result for its category string

type ServerInfo

type ServerInfo struct {
	Name       string
	Address    string
	SCID       string
	Entrypoint string
}

Local TELA server info

func GetServerInfo

func GetServerInfo() []ServerInfo

Get running TELA server info

type Signature

type Signature struct {
	CheckC string `json:"checkC"` // C signature value
	CheckS string `json:"checkS"` // S signature value
}

DERO signature

type TELA

type TELA struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TELA core components for serving content from TELA-INDEX-1 smart contracts

type Version

type Version struct {
	Major int `json:"major"`
	Minor int `json:"minor"`
	Patch int `json:"patch"`
}

Versioning structure used for package and contracts

func GetContractVersions

func GetContractVersions(isDOC bool) (versions []Version)

GetContractVersions returns all valid version numbers for DOC or INDEX SCs

func GetLatestContractVersion

func GetLatestContractVersion(isDOC bool) (version Version)

GetLatestContractVersion returns the latest version number for DOC or INDEX SCs

func GetVersion

func GetVersion() (version Version)

GetVersion returns the TELA go package's version number

func ParseVersion

func ParseVersion(versionStr string) (version *Version, err error)

Parse a versionStr from a TELA SC and return it as a Version

func ValidDOCVersion

func ValidDOCVersion(code string) (contract dvm.SmartContract, version Version, err error)

ValidDOCVersion checks if code is equal to a valid TELA-DOC SC version

func ValidINDEXVersion

func ValidINDEXVersion(code string, modTag string) (contract dvm.SmartContract, version Version, err error)

ValidINDEXVersion checks if code is equal to a valid TELA-INDEX SC version

func (*Version) Equal

func (v *Version) Equal(ov Version) bool

Equal returns true if v is equal to ov

func (*Version) LessThan

func (v *Version) LessThan(ov Version) bool

LessThan returns true if v is less than ov

func (Version) String

func (v Version) String() string

Returns semantic string

Directories

Path Synopsis
cmd
tela-cli command

Jump to

Keyboard shortcuts

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