vault

package
v0.0.0-...-96c6490 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusQueued     = 0
	StatusProcessing = 1
	StatusCompleted  = 2
	StatusFailed     = 3
)

Status constants for Resource

View Source
const (
	VaultPledgeFreezePeriodFlag            = "vault-pledge-freeze-period"
	VaultResourceExpirePeriodFlag          = "vault-resource-expire-period"
	VaultResourceTransferTimeoutPeriodFlag = "vault-resource-transfer-timeout-period"
)

Variables

This section is empty.

Functions

func RegisterApiFlags

func RegisterApiFlags(f []cli.Flag) []cli.Flag

func RegisterFlags

func RegisterFlags(f []cli.Flag) []cli.Flag

Types

type Api

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

Api provides methods to interact with the Vault API

func NewApi

func NewApi(c *cli.Context, cl *http.Client) *Api

New creates a new Vault API client

func (*Api) DeleteResource

func (s *Api) DeleteResource(ctx context.Context, resourceID string) (*Resource, error)

DeleteResource queues a resource for deletion from the Vault

func (*Api) GetResource

func (s *Api) GetResource(ctx context.Context, resourceID string) (*Resource, error)

GetResource retrieves a resource by ID from the Vault

func (*Api) GetResourceCached

func (s *Api) GetResourceCached(ctx context.Context, resourceID string) (*Resource, error)

GetResourceCached retrieves a resource by ID with caching

func (*Api) PutResource

func (s *Api) PutResource(ctx context.Context, resourceID string) (*Resource, error)

PutResource queues a resource for storage in the Vault

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

ErrorResponse represents an error response from the Vault API

type Resource

type Resource struct {
	ResourceID string    `json:"resource_id"`
	Status     int       `json:"status"`
	StoredSize int64     `json:"stored_size"`
	TotalSize  int64     `json:"total_size"`
	Error      string    `json:"error"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
}

Resource represents a resource in the Vault

func (*Resource) GetProgress

func (r *Resource) GetProgress() float64

GetProgress returns the storage progress as a percentage (0-100)

type UserStats

type UserStats struct {
	Total     *float64 // Total vault points (nil if unlimited)
	Frozen    float64  // Points in frozen and funded pledges
	Funded    float64  // Points in funded pledges
	Available *float64 // Total minus funded (nil if total is nil)
	Claimable float64  // Funded but not frozen
}

UserStats represents user vault points statistics

type Vault

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

func New

func New(c *cli.Context, vaultApi *Api, cl *claims.Claims, client *http.Client, pg *cs.PG, restApi *api.Api) *Vault

func (*Vault) CreatePledge

func (s *Vault) CreatePledge(ctx context.Context, user *auth.User, resource *vaultModels.Resource) (*vaultModels.Pledge, error)

CreatePledge creates a new pledge for a resource

func (*Vault) GetExpirePeriod

func (s *Vault) GetExpirePeriod() time.Duration

GetExpirePeriod returns the resource expire period

func (*Vault) GetFreezePeriod

func (s *Vault) GetFreezePeriod() time.Duration

GetFreezePeriod returns the pledge freeze period

func (*Vault) GetOrCreateResource

func (s *Vault) GetOrCreateResource(ctx context.Context, claims *api.Claims, resourceID string) (*vaultModels.Resource, error)

GetOrCreateResource retrieves an existing resource or creates a new one if it doesn't exist

func (*Vault) GetPledge

func (s *Vault) GetPledge(ctx context.Context, user *auth.User, resource *vaultModels.Resource) (*vaultModels.Pledge, error)

GetPledge retrieves a pledge for a specific user and resource, returns nil if not found

func (*Vault) GetRequiredVP

func (s *Vault) GetRequiredVP(ctx context.Context, claims *api.Claims, resourceID string) (float64, error)

GetRequiredVP calculates the required vault points for a resource based on its total size

func (*Vault) GetResource

func (s *Vault) GetResource(ctx context.Context, resourceID string) (*vaultModels.Resource, error)

GetResource retrieves a resource by ID, returns nil if not found

func (*Vault) GetTransferTimeoutPeriod

func (s *Vault) GetTransferTimeoutPeriod() time.Duration

GetTransferTimeoutPeriod returns the resource transfer timeout period

func (*Vault) GetUserStats

func (s *Vault) GetUserStats(ctx context.Context, user *auth.User) (*UserStats, error)

GetUserStats returns vault points statistics for a user

func (*Vault) GetVaultAPIResource

func (s *Vault) GetVaultAPIResource(ctx context.Context, resourceID string) (*Resource, error)

GetVaultAPIResource retrieves the vault API transfer status for a resource (non-cached, for real-time polling)

func (*Vault) IsPledgeFrozen

func (s *Vault) IsPledgeFrozen(ctx context.Context, pledge *vaultModels.Pledge) (bool, error)

IsPledgeFrozen checks if a pledge is currently in the freeze period A pledge is not frozen if the resource is vaulted, regardless of the freeze period

func (*Vault) RemovePledge

func (s *Vault) RemovePledge(ctx context.Context, pledge *vaultModels.Pledge) error

RemovePledge removes a pledge and updates the resource accordingly

func (*Vault) RemoveResource

func (s *Vault) RemoveResource(ctx context.Context, resourceID string) error

RemoveResource removes a resource from the database and vault API

func (*Vault) UpdateUserVP

func (s *Vault) UpdateUserVP(ctx context.Context, user *auth.User) (*vaultModels.UserVP, error)

UpdateUserVP updates user vault points based on claims

func (*Vault) UpdateUserVPIfExists

func (s *Vault) UpdateUserVPIfExists(ctx context.Context, user *auth.User) (*vaultModels.UserVP, error)

UpdateUserVPIfExists updates user vault points only if user already has a record in Vault

Jump to

Keyboard shortcuts

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