pkg

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2024 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const ChainID string = "sourcehub-dev"
View Source
const PolicyId string = "73b18a8dab25e613f89a2e65b6cc59502b646d24dc1bcdc049d13c3d358e750b"
View Source
const TokenName string = "stake"

Variables

View Source
var ErrPromiseCanceled = errors.New("promise canceled")
View Source
var RootCmd = cobra.Command{}

Functions

func DumpKey

func DumpKey(key *secp256k1.PrivKey) string

func GenReadablesTicket

func GenReadablesTicket(ctx context.Context, session Session, acp *ACPClient, ids []string) (string, error)

func NewACPQueryClient

func NewACPQueryClient(addr string) (types.QueryClient, error)

func NewActor

func NewActor() (string, *secp256k1.PrivKey)

Generate a Key Pair, generate a cosmos addr, submit a tx to the Faucet

func NewPromise

func NewPromise[T any](txHash string) (Promise[T], Fulfiller[T])

NewPromise creates new Promise

Types

type ACPClient

type ACPClient struct {
	// contains filtered or unexported fields
}
var ACPCl *ACPClient

func NewACPClient

func NewACPClient(nodeGRPCAddr string, listener *TxListener) (ACPClient, error)

func (*ACPClient) TxCheckAccess

func (c *ACPClient) TxCheckAccess(ctx context.Context, session Session, msg *types.MsgCheckAccess) (*Promise[string], error)

TxCheckAccess builds builds a Tx and Broadcats a MsgCheckAccess Return a Promise containing the Decision ID

func (*ACPClient) TxCreatePolicy

func (c *ACPClient) TxCreatePolicy(ctx context.Context, session Session, msg *types.MsgCreatePolicy) (*Promise[string], error)

func (*ACPClient) TxDeleteRelationship

func (c *ACPClient) TxDeleteRelationship(ctx context.Context, session Session, msg *types.MsgDeleteRelationship) (*Promise[Executed], error)

func (*ACPClient) TxRegisterObject

func (c *ACPClient) TxRegisterObject(ctx context.Context, session Session, msg *types.MsgRegisterObject) (*Promise[Executed], error)

func (*ACPClient) TxSetRelationship

func (c *ACPClient) TxSetRelationship(ctx context.Context, session Session, msg *types.MsgSetRelationship) (*Promise[Executed], error)

type Executed

type Executed bool

type Fulfiller

type Fulfiller[T any] struct {
	// contains filtered or unexported fields
}

Fulfiller fullfils a Promise

func NewFulfiller

func NewFulfiller[T any](resultChan chan<- T, errChan chan<- error) Fulfiller[T]

func (*Fulfiller[T]) Cancel

func (f *Fulfiller[T]) Cancel()

Cancel cancels a promise, meaning it wont produce an error

func (*Fulfiller[T]) Produce

func (f *Fulfiller[T]) Produce(value T)

Produce produces the result value, sends it to the correct channel and marks it as fullfilled

func (*Fulfiller[T]) ProduceErr

func (f *Fulfiller[T]) ProduceErr(err error)

ProduceErr produces an error as the Promise result and fulfills it

type Note

type Note struct {
	gorm.Model
	Title      string
	Body       string
	Creator    string
	LastEditor string
}

Note is a text owned by some User

type NoteCommands

type NoteCommands struct {
	// contains filtered or unexported fields
}
var NoteCmds *NoteCommands

func NewNoteCommands

func NewNoteCommands(repo Repository, manager *PermissionManager) NoteCommands

func (*NoteCommands) Create

func (c *NoteCommands) Create(ctx context.Context, session Session, title string, body string) (Note, error)

Create creates a new note with an unique Id

type NoteQuerier

type NoteQuerier struct {
	// contains filtered or unexported fields
}
var Querier *NoteQuerier

func NewNoteQuerier

func NewNoteQuerier(acp *ACPClient, repo Repository, querier types.QueryClient) NoteQuerier

func (*NoteQuerier) FetchLocalNodes

func (q *NoteQuerier) FetchLocalNodes(ctx context.Context, session Session) ([]Note, error)

func (*NoteQuerier) FetchReadableNotes

func (q *NoteQuerier) FetchReadableNotes(ctx context.Context, session Session) ([]Note, error)

Note: this assumes the need for internet, which is lame Local users should be able to check their own notes and sync the remaining notes as it goes. Right now that's kinda lame to do

func (*NoteQuerier) ListReadableNotesID

func (q *NoteQuerier) ListReadableNotesID(ctx context.Context, session Session) ([]string, error)

ListAccessibleNotes lists all notes the user has access to (as a reader or editor)

This is kind of an awkward step because we need to query the ACP module to figure this out.

In Defra there is a challenge because doc syncing is an app level concern. This creates a chicken and egg problem, because the app can't rely on defra to know which docs it has access to but defra can't sync the doc because it doesn't know which docs were shared. Ultimately this info is in the Relation graph, as such we could fetch this directly from it.

Another alternative would require dApp devs to implement ad hoc and custom notification systems between the peers. This would lead to potentially more work for dApp devs and it's something the Relation Graph could solve

type PermissionManager

type PermissionManager struct {
	// contains filtered or unexported fields
}
var PermMan *PermissionManager

func NewPermissionManager

func NewPermissionManager(acp *ACPClient) *PermissionManager

func (*PermissionManager) RegisterNote

func (m *PermissionManager) RegisterNote(ctx context.Context, session Session, note *Note) (*Promise[Executed], error)

RegisterNote registers the session user as the owner of the note object

func (*PermissionManager) ShareNote

func (m *PermissionManager) ShareNote(ctx context.Context, session Session, noteId string, actorId string) (*Promise[Executed], error)

ShareNote makes the given actor a `reader` of the given Note Creates a Relationship in SourceHub

func (*PermissionManager) UnshareNote

func (m *PermissionManager) UnshareNote(ctx context.Context, session Session, noteId string, actorId string) (*Promise[Executed], error)

UnshareNote removes Actor as a reader of Note Creates a Relationship in SourceHub

type PipeChan

type PipeChan[T any, U any] struct {
	// contains filtered or unexported fields
}

func NewPipe

func NewPipe[T any, U any](mapper func(T) U, producer <-chan T) PipeChan[T, U]

func (*PipeChan[T, U]) ReceiveEnd

func (c *PipeChan[T, U]) ReceiveEnd() <-chan U

type Promise

type Promise[T any] struct {
	// contains filtered or unexported fields
}

Promise represents a value which will be produced The result will be either an error or a result. Callers should select between either one of the channels.

func MapPromise

func MapPromise[T any, U any](promise Promise[T], mapper func(T) U) Promise[U]

func (*Promise[T]) Await

func (p *Promise[T]) Await() (T, error)

Await blocks untils the Promisse is resolved

func (*Promise[T]) Error

func (p *Promise[T]) Error() <-chan error

Error returns a channel which produces an error

func (*Promise[T]) GetResult

func (p *Promise[T]) GetResult() (T, error)

GetResult returns the stored result from a Promise. If Promise hasn't been fulfilled return err

func (*Promise[T]) GetTxHash

func (p *Promise[T]) GetTxHash() string

Returns Hash of the Tx being awaited

func (*Promise[T]) Result

func (p *Promise[T]) Result() <-chan T

Result returns a channel which produces the result

func (*Promise[T]) Terminated

func (p *Promise[T]) Terminated() bool

type Repository

type Repository interface {
	SetNote(ctx context.Context, session Session, note *Note) error

	GetNote(ctx context.Context, session Session, ticket string, id string) (Note, error)

	ListLocalNotes(ctx context.Context, actorId string) ([]Note, error)
}

type SQLite

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

func NewSQLite

func NewSQLite(path string) (*SQLite, error)

func (*SQLite) GetNote

func (s *SQLite) GetNote(ctx context.Context, session Session, ticket string, id string) (Note, error)

func (*SQLite) Init

func (s *SQLite) Init() error

func (*SQLite) ListLocalNotes

func (s *SQLite) ListLocalNotes(ctx context.Context, actorId string) ([]Note, error)

func (*SQLite) SetNote

func (s *SQLite) SetNote(ctx context.Context, session Session, note *Note) error

type Session

type Session struct {
	// SourceHub address of Authenticated user
	Actor   string
	PrivKey cryptotypes.PrivKey
}

func NewSession

func NewSession(key string) Session

type TxError

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

func NewTxError

func NewTxError(txHash string, code uint32, msg string, codespace string) *TxError

func (*TxError) Error

func (e *TxError) Error() string

type TxListener

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

TxListener connects to a CometBFT node RPC serv and subscribes as a liestener to Txs Multiplexes Txs to different listeners - only one listener per tx

func NewTxListener

func NewTxListener(addr string) (*TxListener, error)

NewTxListener creates a WebSocket client for CometBFT rpc

func NewTxListenerFromClient

func NewTxListenerFromClient(client *rpcclient.WSClient) (*TxListener, error)

func (*TxListener) DefaultChan

func (l *TxListener) DefaultChan() <-chan rpctypes.ResultEvent

func (*TxListener) ErrChan

func (l *TxListener) ErrChan() <-chan error

func (*TxListener) Listen

func (l *TxListener) Listen(ctx context.Context) error

Listen runs the listener in a thread and returns a default reponse channel which returns responses to unregistered txs If ctx is terminated, the listener stops and cleans up

func (*TxListener) Subscribe

func (l *TxListener) Subscribe(txHash string) Promise[rpctypes.ResultEvent]

Subscribe configures the Listener to return the RPC Response when the response for txHash is received.

Note: The listener does not logs responses. If the response for txHash is received before being registered the response will be sent on the default channel.

Jump to

Keyboard shortcuts

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