models

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: MIT Imports: 10 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 Payment

type Payment struct {
	gorm.Model
	Method           uint8  `json:"method"`
	Number           string `json:"number"`
	ChargeAmount     string `json:"charge_amount"`
	EthAddress       string `json:"eth_address"`
	UserName         string `json:"user_name"`
	NetworkName      string `json:"network_name"`
	ObjectName       string `json:"content_hash"`
	Type             string `json:"time"`
	HoldTimeInMonths int64  `json:"hold_time_in_months"`
}

Payment is our database model for payments Note that if it is of type file, then object name is the minio object if it is of type pin, then the object name is the content hash

type PaymentManager

type PaymentManager struct {
	DB *gorm.DB
}

func NewPaymentManager

func NewPaymentManager(db *gorm.DB) *PaymentManager

func (*PaymentManager) FindPaymentByNumberAndAddress

func (pm *PaymentManager) FindPaymentByNumberAndAddress(paymentNumber, ethAddress string) (*Payment, error)

func (*PaymentManager) NewPayment

func (pm *PaymentManager) NewPayment(method uint8, number *big.Int, chargeAmount *big.Int, ethAddress, objectName, username, uploadType, networkName string, holdTimeInMonths int64) (*Payment, error)

func (*PaymentManager) RetrieveLatestPaymentForUser

func (pm *PaymentManager) RetrieveLatestPaymentForUser(username string) (*Payment, error)

func (*PaymentManager) RetrieveLatestPaymentNumberForUser

func (pm *PaymentManager) RetrieveLatestPaymentNumberForUser(username string) (*big.Int, error)

type PinPayment

type PinPayment struct {
	gorm.Model
	Method           uint8  `json:"method"`
	Number           string `json:"number"`
	ChargeAmount     string `json:"charge_amount"`
	EthAddress       string `json:"eth_address"`
	UserName         string `json:"user_name"`
	ContentHash      string `json:"content_hash"`
	NetworkName      string `json:"network_name"`
	HoldTimeInMonths int64  `json:"hold_time_in_months"`
}

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)"`
	// IPFSKeyNames is an array of IPFS keys this user has created
	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"`
}

EMAIL ADDRESS MUST BE PROVIDED

type UserManager

type UserManager struct {
	DB *gorm.DB
}

func NewUserManager

func NewUserManager(db *gorm.DB) *UserManager

func (*UserManager) AddIPFSKeyForUser

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

func (*UserManager) AddIPFSNetworkForUser

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

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)

func (*UserManager) CheckIfUserAccountEnabled

func (um *UserManager) CheckIfUserAccountEnabled(username string, db *gorm.DB) (bool, error)

func (*UserManager) CheckIfUserHasAccessToNetwork

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

func (*UserManager) ComparePlaintextPasswordToHash

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

func (*UserManager) FindByAddress

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

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)

func (*UserManager) GetKeyIDByName

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

func (*UserManager) GetKeysForUser

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

func (*UserManager) GetPrivateIPFSNetworksForUser

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

func (*UserManager) NewUserAccount

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

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