db

package
v0.0.11-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToPostgres

func ConnectToPostgres(migrations bool) (*sql.DB, error)

ConnectToPostgres Function to connect to Postgres

func DelCache

func DelCache(ctx context.Context, keyStr string) bool

DelCache deletes a key-value pair from the resolver cache. It takes a context and a key string, converts the key into a datastore key, and deletes the key-value pair from the cache. It returns a bool indicating if the deletion succeeded.

func GetCache

func GetCache(ctx context.Context, keyStr string) ([]byte, error)

GetCache retrieves a value from the resolver cache for the given key. It takes a context and a key string, converts the key into a datastore key, gets the value from the cache, and returns the value byte slice and a possible error.

func InitResolverCache

func InitResolverCache(node *masa.OracleNode, keyManager *masacrypto.KeyManager)

InitResolverCache initializes the resolver cache for the Masa Oracle node.

Parameters:

  • node: A pointer to the Masa Oracle node (masa.OracleNode) that the resolver cache will be associated with.
  • keyManager: A pointer to the key manager (masacrypto.KeyManager) used for cryptographic operations.

This function sets up the resolver cache for the Masa Oracle node. The resolver cache is responsible for storing and managing resolved data within the node.

The function takes two parameters:

  1. `node`: It represents the Masa Oracle node instance to which the resolver cache will be attached. The node provides the necessary context and dependencies for the resolver cache to operate.
  2. `keyManager`: It is an instance of the key manager that handles cryptographic operations. The key manager is used by the resolver cache for any required cryptographic tasks, such as signing or verifying data.

The purpose of this function is to initialize the resolver cache and perform any necessary setup or configuration. It associates the resolver cache with the provided Masa Oracle node and key manager.

Note: The specific implementation details of the `InitResolverCache` function are not provided in the given code snippet. The function signature suggests that it initializes the resolver cache, but the actual initialization logic would be present in the function body.

func PutCache

func PutCache(ctx context.Context, keyStr string, value []byte) (any, error)

PutCache puts a key-value pair into the resolver cache.

It takes a context, a key as a string, and a value as a byte slice. It converts the key into a datastore key and puts the key-value pair into the cache.

It returns the original key string and a possible error.

func ReadData

func ReadData(node *masa.OracleNode, key string) []byte

ReadData reads the value for the given key from the database. It requires the host for access control verification before reading.

func UpdateCache

func UpdateCache(ctx context.Context, keyStr string, newValue []byte) (bool, error)

UpdateCache updates the value for the given key in the resolver cache. It first checks if the key already exists using Has(). If it doesn't exist, it returns an error. If the key does exist, it puts the new value into the cache using Put(). It returns a bool indicating if the update succeeded, and a possible error.

func Verifier

func Verifier(h host.Host, data []byte, signature []byte) bool

Verifier checks if the given host is allowed to access to the database and verifies the signature

func WriteData

func WriteData(node *masa.OracleNode, key string, value []byte) (bool, error)

WriteData encapsulates the logic for writing data to the database, including access control checks from access_control.go.

Types

type AuthorizedNodes

type AuthorizedNodes map[string]bool

AuthorizedNodes Set of authorized nodes that can write to the database

type Record

type Record struct {
	Key   string
	Value []byte
}

func QueryAll

func QueryAll(ctx context.Context) ([]Record, error)

QueryAll queries the resolver cache for all records and returns them as a slice of Record structs. It executes a query.Query{} to get all results, closes the results when done, iterates through the results, appending each record to a slice, and returns the slice.

type SharedData

type SharedData map[string]interface{}

SharedData is a map that stores shared data across the application.

Jump to

Keyboard shortcuts

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