models

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2018 License: MIT Imports: 9 Imported by: 27

Documentation

Overview

Package models provides the models used by Temporal's databases

Index

Constants

This section is empty.

Variables

View Source
var AdminAddress = "0xC6C35f43fDD71f86a2D8D4e3cA1Ce32564c38bd9"

AdminAddress is the eth address of the admin account

Functions

This section is empty.

Types

type Blockchain

type Blockchain struct {
	Name    string `gorm:"type:varchar(255);not null"`
	IPCPath string `gorm:"type:varchar(255);not null"`
	RPCPath string `gorm:"type:varchar(255);not null"`
}

Blockchain lists our available to different blockchains We do not store administration, or keys in the database.

type EnterpriseUpload

type EnterpriseUpload struct {
	gorm.Model
	CompanyName        string `gorm:"type:varchar(255)" json:"company_name"`
	Hash               string `gorm:"type:varchar(255)" json:"hash"`
	GarbageCollectDate time.Time
}

type HostedIPFSPrivateNetwork

type HostedIPFSPrivateNetwork struct {
	gorm.Model
	Name                   string         `gorm:"type:varchar(255)"`
	APIURL                 string         `gorm:"type:varchar(255)"`
	SwarmKey               string         `gorm:"type:varchar(255)"`
	Users                  pq.StringArray `gorm:"type:text[]"` // these are the users to which this IPFS network connection applies to specified by eth address
	LocalNodePeerAddresses pq.StringArray `gorm:"type:text[]"` // these are the nodes whichwe run, and can connect to
	LocalNodePeerIDs       pq.StringArray `gorm:"type:text[];column:local_node_peer_ids"`
	BootstrapPeerAddresses pq.StringArray `gorm:"type:text[]"`
	BootstrapPeerIDs       pq.StringArray `gorm:"type:text[];column:bootstrap_peer_ids"`
}

type IPFSNetworkManager

type IPFSNetworkManager struct {
	DB *gorm.DB
}

func NewHostedIPFSNetworkManager

func NewHostedIPFSNetworkManager(db *gorm.DB) *IPFSNetworkManager

func (*IPFSNetworkManager) CreateHostedPrivateNetwork

func (im *IPFSNetworkManager) CreateHostedPrivateNetwork(name, apiURL, swarmKey string, arrayParameters map[string][]string, users []string) (*HostedIPFSPrivateNetwork, error)

TODO: Validate swarm key and API url

func (*IPFSNetworkManager) GetAPIURLByName

func (im *IPFSNetworkManager) GetAPIURLByName(name string) (string, error)

func (*IPFSNetworkManager) GetNetworkByName

func (im *IPFSNetworkManager) GetNetworkByName(name string) (*HostedIPFSPrivateNetwork, error)

type IPNS

type IPNS struct {
	gorm.Model
	Sequence int64 `gorm:"type:integer;not null;default:0" json:"sequence"`
	// the ipns hash, is the peer id of the peer used to sign the entry
	IPNSHash string `gorm:"type:varchar(255);unique;column:ipns_hash" json:"ipns_hash"`
	// List of content hashes this IPNS entry has pointed to
	IPFSHashes      pq.StringArray `gorm:"type:text[];column:ipfs_hash" json:"ipfs_hashes"`
	CurrentIPFSHash string         `gorm:"type:varchar(255);column:current_ipfs_hash" json:"current_ipfs_hash"`
	LifeTime        string         `gorm:"type:varchar(255)" json:"life_time"`
	TTL             string         `gorm:"type:varchar(255)" json:"ttl"`
	Key             string         `gorm:"type:varchar(255)" json:"key"`
	NetworkName     string         `gorm:"type:varchar(255)" json:"network_name"`
}

IPNS will hold all of the IPNS entries in our system

type IpnsManager

type IpnsManager struct {
	DB *gorm.DB
}

func NewIPNSManager

func NewIPNSManager(db *gorm.DB) *IpnsManager

func (*IpnsManager) CreateEntry

func (im *IpnsManager) CreateEntry(ipnsHash, ipfsHash, key, networkName string, lifetime, ttl time.Duration) (*IPNS, error)

func (*IpnsManager) FindByIPNSHash

func (im *IpnsManager) FindByIPNSHash(ipnsHash string) (*IPNS, error)

func (*IpnsManager) UpdateIPNSEntry

func (im *IpnsManager) UpdateIPNSEntry(ipnsHash, ipfsHash, key, networkName string, lifetime, ttl time.Duration) (*IPNS, error)

type PaymentManager

type PaymentManager struct {
	DB *gorm.DB
}

PaymentManager is used to interact with payment information in our database

func NewPaymentManager

func NewPaymentManager(db *gorm.DB) *PaymentManager

NewPaymentManager is used to generate our payment manager helper

func (*PaymentManager) ConfirmPayment added in v1.0.2

func (pm *PaymentManager) ConfirmPayment(txHash string) (*Payments, error)

ConfirmPayment is used to mark a payment as confirmed

func (*PaymentManager) FindPaymentByTxHash added in v1.0.2

func (pm *PaymentManager) FindPaymentByTxHash(txHash string) (*Payments, error)

FindPaymentByTxHash is used to find a payment by its TxHash

func (*PaymentManager) MarkPaymentAsProcessing added in v1.0.2

func (pm *PaymentManager) MarkPaymentAsProcessing(txHash string) (*Payments, error)

MarkPaymentAsProcessing is sued to mark a payment as being processed

func (*PaymentManager) NewPayment

func (pm *PaymentManager) NewPayment(depositAddress string, txHash string, usdValue float64, blockchain string, paymentType string, username string) (*Payments, error)

NewPayment is used to create a payment in our database

type Payments added in v1.0.2

type Payments struct {
	gorm.Model
	DepositAddress string  `gorm:"type:varchar(255)"`
	TxHash         string  `gorm:"type:varchar(255)"`
	USDValue       float64 `gorm:"type:varchar(255)"` // USDValue is also a "Credit" value, since 1 USD -> 1 Credit
	Blockchain     string  `gorm:"type:varchar(255)"`
	Type           string  `gorm:"type:varchar(255)"` // ETH, RTC, XMR, BTC, LTC
	UserName       string  `gorm:"type:varchar(255)"`
	Confirmed      bool    `gorm:"type:varchar(255)"`
	Processing     bool    `gorm:"type:varchar(255)"`
}

Payments is our payment model

type Upload

type Upload struct {
	gorm.Model
	Hash               string `gorm:"type:varchar(255);not null;"`
	Type               string `gorm:"type:varchar(255);not null;"` //  file, pin
	NetworkName        string `gorm:"type:varchar(255)"`
	HoldTimeInMonths   int64  `gorm:"type:integer;not null;"`
	UserName           string `gorm:"type:varchar(255);not null;"`
	GarbageCollectDate time.Time
	UserNames          pq.StringArray `gorm:"type:text[];not null;"`
}

type UploadManager

type UploadManager struct {
	DB *gorm.DB
}

func NewUploadManager

func NewUploadManager(db *gorm.DB) *UploadManager

NewUploadManager is used to generate an upload manager interface

func (*UploadManager) FindUploadByHashAndNetwork

func (um *UploadManager) FindUploadByHashAndNetwork(hash, networkName string) (*Upload, error)

func (*UploadManager) FindUploadsByHash

func (um *UploadManager) FindUploadsByHash(hash string) *[]Upload

FindUploadsByHash is used to return all instances of uploads matching the given hash

func (*UploadManager) FindUploadsByNetwork

func (um *UploadManager) FindUploadsByNetwork(networkName string) (*[]Upload, error)

func (*UploadManager) GetUploadByHashForUser

func (um *UploadManager) GetUploadByHashForUser(hash string, username string) []*Upload

GetUploadByHashForUser is used to retrieve the last (most recent) upload for a user

func (*UploadManager) GetUploads

func (um *UploadManager) GetUploads() (*[]Upload, error)

GetUploads is used to return all uploads

func (*UploadManager) GetUploadsForUser

func (um *UploadManager) GetUploadsForUser(username string) (*[]Upload, error)

GetUploadsForUser is used to retrieve all uploads by a user name

func (*UploadManager) NewUpload

func (um *UploadManager) NewUpload(contentHash, uploadType, networkName, username string, holdTimeInMonths int64) (*Upload, error)

NewUpload is used to create a new upload in the database

func (*UploadManager) RunDatabaseGarbageCollection

func (um *UploadManager) RunDatabaseGarbageCollection() (*[]Upload, error)

RunDatabaseGarbageCollection is used to parse through the database and delete all objects whose GCD has passed TODO: Maybe move this to the database file?

func (*UploadManager) RunTestDatabaseGarbageCollection

func (um *UploadManager) RunTestDatabaseGarbageCollection() (*[]Upload, error)

RunTestDatabaseGarbageCollection is used to run a test garbage collection run. NOTE that this will delete literally every single object it detects.

func (*UploadManager) UpdateUpload

func (um *UploadManager) UpdateUpload(holdTimeInMonths int64, username, contentHash, networkName string) (*Upload, error)

UpdateUpload is used to upadte an already existing upload

type User

type User struct {
	gorm.Model
	EthAddress        string         `gorm:"type:varchar(255);unique"`
	UserName          string         `gorm:"type:varchar(255);unique"`
	EmailAddress      string         `gorm:"type:varchar(255);unique"`
	EnterpriseEnabled bool           `gorm:"type:boolean"`
	AccountEnabled    bool           `gorm:"type:boolean"`
	APIAccess         bool           `gorm:"type:boolean"`
	EmailEnabled      bool           `gorm:"type:boolean"`
	HashedPassword    string         `gorm:"type:varchar(255)"`
	Credits           float64        `gorm:"type:float"`
	IPFSKeyNames      pq.StringArray `gorm:"type:text[];column:ipfs_key_names"`
	IPFSKeyIDs        pq.StringArray `gorm:"type:text[];column:ipfs_key_ids"`
	IPFSNetworkNames  pq.StringArray `gorm:"type:text[];column:ipfs_network_names"`
}

User contains a user account

type UserManager

type UserManager struct {
	DB *gorm.DB
}

UserManager is used to manage user accounts within the DB

func NewUserManager

func NewUserManager(db *gorm.DB) *UserManager

NewUserManager is a method used to generate our user manager

func (*UserManager) AddCreditsForUser added in v1.0.2

func (um *UserManager) AddCreditsForUser(username string, credits float64) (*User, error)

AddCreditsForUser is used to add credits to a users account

func (*UserManager) AddIPFSKeyForUser

func (um *UserManager) AddIPFSKeyForUser(username, keyName, keyID string) error

AddIPFSKeyForUser is used to add a key to a user account

func (*UserManager) AddIPFSNetworkForUser

func (um *UserManager) AddIPFSNetworkForUser(username, networkName string) error

AddIPFSNetworkForUser is used to add an IPFS network to a users authorized networks

func (*UserManager) ChangeEthereumAddress

func (um *UserManager) ChangeEthereumAddress(username, ethAddress string) (*User, error)

ChangeEthereumAddress is used to change a user's ethereum address

func (*UserManager) ChangePassword

func (um *UserManager) ChangePassword(username, currentPassword, newPassword string) (bool, error)

ChangePassword is used to change a users password

func (*UserManager) CheckIfKeyOwnedByUser

func (um *UserManager) CheckIfKeyOwnedByUser(username, keyName string) (bool, error)

CheckIfKeyOwnedByUser is used to check if a given user owns a key

func (*UserManager) CheckIfUserAccountEnabled

func (um *UserManager) CheckIfUserAccountEnabled(username string) (bool, error)

CheckIfUserAccountEnabled is used to get whether or not a user account is enabled

func (*UserManager) CheckIfUserHasAccessToNetwork

func (um *UserManager) CheckIfUserHasAccessToNetwork(username, networkName string) (bool, error)

CheckIfUserHasAccessToNetwork is used to check if a user has access to a private IFPS network

func (*UserManager) ComparePlaintextPasswordToHash

func (um *UserManager) ComparePlaintextPasswordToHash(username, password string) (bool, error)

ComparePlaintextPasswordToHash is a helper method used to validate the provided password

func (*UserManager) FindByAddress

func (um *UserManager) FindByAddress(address string) (*User, error)

FindByAddress is used to find a user by searching for their eth address

func (*UserManager) FindByUserName added in v1.0.2

func (um *UserManager) FindByUserName(username string) (*User, error)

FindByUserName is used to find a user by their username

func (*UserManager) FindEmailByUserName

func (um *UserManager) FindEmailByUserName(username string) (map[string]string, error)

FindEmailByUserName is used to find an email address by searching for the users eth address the returned map contains their eth address as a key, and their email address as a value

func (*UserManager) FindEthAddressByUserName

func (um *UserManager) FindEthAddressByUserName(username string) (string, error)

FindEthAddressByUserName is used to find the eth address associated with a user account

func (*UserManager) GetCreditsForUser added in v1.0.2

func (um *UserManager) GetCreditsForUser(username string) (float64, error)

GetCreditsForUser is used to get the user's current credits

func (*UserManager) GetKeyIDByName

func (um *UserManager) GetKeyIDByName(username, keyName string) (string, error)

GetKeyIDByName is used to get the ID (public key hash) of a key

func (*UserManager) GetKeysForUser

func (um *UserManager) GetKeysForUser(username string) (map[string][]string, error)

GetKeysForUser is used to fetch all of the users keys

func (*UserManager) GetPrivateIPFSNetworksForUser

func (um *UserManager) GetPrivateIPFSNetworksForUser(username string) ([]string, error)

GetPrivateIPFSNetworksForUser is used to get all the authorized private networks a user has access to

func (*UserManager) NewUserAccount

func (um *UserManager) NewUserAccount(ethAddress, username, password, email string, enterpriseEnabled bool) (*User, error)

NewUserAccount is used to create a new user account, enabling API and account access

func (*UserManager) RemoveCredits added in v1.0.2

func (um *UserManager) RemoveCredits(username string, credits float64) (*User, error)

RemoveCredits is used to remove credits from a users balance

func (*UserManager) SignIn

func (um *UserManager) SignIn(username, password string) (bool, error)

SignIn is used to authenticate a user, and check if their account is enabled. Returns bool on succesful login, or false with an error on failure

Jump to

Keyboard shortcuts

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