database

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: GPL-2.0, GPL-3.0 Imports: 16 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PlatformBucket = []byte("Platforms")

PlatformBucket is the bucket where we'll store platforms that are under openx1

View Source
var UserBucket = []byte("Users")

UserBucket is the bucket in which we'll store openx users

Functions

func AddInspector

func AddInspector(userIndex int) error

AddInspector sets the Inspector flag on a user

func CreateHomeDir

func CreateHomeDir()

CreateHomeDir creates the home and database directories

func DeleteKeyFromBucket

func DeleteKeyFromBucket(key int, bucketName []byte) error

DeleteKeyFromBucket deletes an object from the passed bucket

func NewPlatform

func NewPlatform(name string, code string, timeout bool) error

NewPlatform creates a new platform and stores it in the database

func OpenDB

func OpenDB() (*bolt.DB, error)

OpenDB opens the db and returns a pointer to the database

func RetrieveAllPfLim

func RetrieveAllPfLim() (int, error)

RetrieveAllPfLim gets the number of platforms in the platform bucket

func RetrieveAllUsersLim

func RetrieveAllUsersLim() (int, error)

RetrieveAllUsersLim gets the number of users in the bucket

Types

type AnchorKYCHelper

type AnchorKYCHelper struct {
	Name     string
	Birthday struct {
		Month string
		Day   string
		Year  string
	}
	Tax struct {
		Country string
		ID      string
	}
	Address struct {
		Street  string
		City    string
		Postal  string
		Region  string
		Country string
		Phone   string
	}
	PrimaryPhone       string
	Gender             string
	DepositIdentifier  string
	WithdrawIdentifier string
	URL                string
	AccountID          string
}

AnchorKYCHelper contains the KYC parameters required by Anchor

type KycStruct

type KycStruct struct {
	PassportPhoto  string
	IDCardPhoto    string
	DriversLicense string
	PersonalPhoto  string
}

KycStruct contains the parameters required by ComplyAdvantage

type MailboxHelper

type MailboxHelper struct {
	Subject string // the subject can be used to send push notifications
	Message string // the message
}

MailboxHelper is a helper struct that can be used to send admin notifications to users

type Platform

type Platform struct {
	Index   int
	Name    string
	Code    string
	Timeout int64
}

Platform is a struct which holds all platform related info

func RetrieveAllPlatforms

func RetrieveAllPlatforms() ([]Platform, error)

RetrieveAllPlatforms retrieves all platforms from the database

func RetrievePlatform

func RetrievePlatform(key int) (Platform, error)

RetrievePlatform retrieves a Platform from the database

func (*Platform) Save

func (a *Platform) Save() error

Save inserts a Platform object into the database

type StellWallet

type StellWallet struct {
	PublicKey     string
	EncryptedSeed []byte
	SeedPwhash    string
}

StellWallet hold the Stellar Publickey and Encrypted Seed

type User

type User struct {
	// Index is an incremental index maintained to easily retrieve users
	Index int
	// Name is the real name of the user
	Name string
	// Description contains some other stuff that a user might wish to describe about themselves
	Description string
	// Image is an optional profile image that users might upload
	Image string
	// FirstSignedUp contains the date on which the users signed up on openx
	FirstSignedUp string
	// Address is the address of the user
	Address string
	// City denotes the city of residence of the user
	City string
	// ZipCode is the zipcode iof the user's residence
	ZipCode string
	// Country is the country of residence of the user. Some platforms may be restricted to a certain subset of countries
	Country string
	// RecoveryPhone used to send recovery codes or contact the user in the event of an emergency
	RecoveryPhone string
	// Email is used to send users notifications on their actions on openx based platforms
	Email string
	// Notification is a bool which denotes whether the user wants to receive notifications related to the openx platform
	Notification bool
	// StellarWallet contains a publickey and encrypted seed that can be used to interact with the Stellar blockchain
	StellarWallet StellWallet
	// AlgorandWallet contains a publickey and privatekey pair which can be used to interact with the Algorand blockchain
	AlgorandWallet algorand.Wallet
	// Username denoteds the username of the user to log on to openx
	Username string
	// Pwhash is the 512 byte SHA-3 hash of the user's password
	Pwhash string
	// Kyc denotes whether the user has passed KYC
	Kyc bool
	// Admin denotes whether the user has passed kyc or not
	Admin bool
	// Inspector denotes whether the user is a KYC inspector ie whether they're authorized to approve other's KYC requests
	Inspector bool
	// Banned is true if the user is banned on openx
	Banned bool
	// Reputation is a float which denotes the reputation of a user on the openx platform
	Reputation float64
	// LocalAssets is a list of P2P assets belonging to the user
	LocalAssets []string
	// RecoveryShares is a collection of shares that a user can distribute to aid recovery of their seed later on
	RecoveryShares []string
	// PwdResetCode is a code that's set when a user wants to reset their password
	PwdResetCode string
	// SecondaryWallet is a secondary wallet where people can store their funds in
	SecondaryWallet StellWallet
	// PendingDocuments is a list of pending documents which a user must upload before progressing on to the next stage
	PendingDocuments map[string]string
	// KYC contains KYC information required by ComplyAdvantage
	KYC KycStruct
	// StarRating is a star rating similar to popular platforms which users can use to rate each other
	StarRating map[int]int
	// GivenStarRating contains a list of users whom this user has rated
	GivenStarRating map[int]int
	// TwoFASecret is the secret associated with Google 2FA that users can enable while logging on openx
	TwoFASecret string
	// AnchorKYC contains KYC information required by AnchorUSD
	AnchorKYC AnchorKYCHelper
	// AccessToken is the access token that will be used for authenticating RPC requests made to the server
	AccessToken map[string]int64
	// Mailbox is a mailbox where admins can send you messages or updated on your invested / interested projects
	Mailbox []MailboxHelper
	// Legal is a bool which is set when the user accepts the terms and conditions
	Legal bool
	// ProfileProgress is a float which denotes user profile completeness on the frontend
	ProfileProgress float64
	// Verified marks a person as verified
	Verified bool
	// VerifyReq requests verification
	VerifyReq bool
	// VerifiedBy stores the index of the admin who verified the user
	VerifiedBy int
	// VerifiedTime stores when the user was verified
	VerifiedTime string
	// ConfToken is the confirmation token sent to users to confirm their registration on openx
	ConfToken string
	// Conf is a bool that is set to true when users confirm their tokens
	Conf bool
}

User defines a base layer structure that can be used by entities on platforms built on openx

func CheckUsernameCollision

func CheckUsernameCollision(uname string) (User, error)

CheckUsernameCollision checks if a passed username collides with someone who's already on the platform. If a collision does exist, return the existing user in the database

func NewUser

func NewUser(uname string, pwhash string, seedpwd string, email string) (User, error)

NewUser creates a new user, stores it in the openx database and returns a user struct

func RetrieveAllAdmins

func RetrieveAllAdmins() ([]User, error)

RetrieveAllAdmins retrieves a list of all admisn from the database

func RetrieveAllUsers

func RetrieveAllUsers() ([]User, error)

RetrieveAllUsers gets a list of all Users in the database

func RetrieveAllUsersWithKyc

func RetrieveAllUsersWithKyc() ([]User, error)

RetrieveAllUsersWithKyc retrieves all users with kyc

func RetrieveAllUsersWithoutKyc

func RetrieveAllUsersWithoutKyc() ([]User, error)

RetrieveAllUsersWithoutKyc retrieves all users without kyc

func RetrieveUser

func RetrieveUser(key int) (User, error)

RetrieveUser retrieves a User from the database

func SearchWithEmailID added in v1.0.5

func SearchWithEmailID(email string) (User, error)

SearchWithEmailID searches for a user given their email id

func TopReputationUsers

func TopReputationUsers() ([]User, error)

TopReputationUsers gets a list of users sorted by descending reputation

func ValidateAccessToken

func ValidateAccessToken(name string, accessToken string) (User, error)

ValidateAccessToken validates a username / accessToken combination

func ValidatePwhash

func ValidatePwhash(name string, pwhash string) (User, error)

ValidatePwhash validates a username / pwhash combination

func ValidatePwhashReg added in v1.0.4

func ValidatePwhashReg(name string, pwhash string) (User, error)

ValidatePwhashReg validates a username / pwhash combination during registration

func ValidateSeedpwd

func ValidateSeedpwd(name string, pwhash string, seedpwd string) (User, error)

ValidateSeedpwd validates a user and their seedpwd

func ValidateSeedpwdAuthToken

func ValidateSeedpwdAuthToken(name string, token string, seedpwd string) (User, error)

ValidateSeedpwdAuthToken validates a user and their seedpwd using their accesstoken

func (*User) AddEmail

func (a *User) AddEmail(email string) error

AddEmail adds the email field to a given user

func (*User) AddtoMailbox

func (a *User) AddtoMailbox(subject string, message string) error

AddtoMailbox adds a message to a user's mailbox

func (*User) AllLogout added in v1.0.2

func (a *User) AllLogout() error

AllLogout invalidates the user access token

func (*User) Authenticate2FA

func (a *User) Authenticate2FA(password string) (bool, error)

Authenticate2FA authenticates the given password against the user's stored 2fA secret

func (*User) Authorize

func (a *User) Authorize(userIndex int) error

Authorize sets the Kyc flag on a user. Can only be called by Inspectors

func (*User) ChangeReputation

func (a *User) ChangeReputation(reputation float64) error

ChangeReputation changes the reputation associated with a user

func (*User) GenAccessToken

func (a *User) GenAccessToken() (string, error)

GenAccessToken generates a new access token for the user

func (*User) GenKeys

func (a *User) GenKeys(seedpwd string, options ...string) error

GenKeys generates a keypair for the user and takes in options on which blockchain to generate keys for

func (*User) Generate2FA

func (a *User) Generate2FA() (string, error)

Generate2FA generates a new 2FA secret for the given user

func (*User) GiveFeedback

func (a *User) GiveFeedback(userIndex int, feedback int) error

GiveFeedback is used to rate another user

func (*User) ImportSeed

func (a *User) ImportSeed(encryptedSeed []byte, pubkey string, seedpwd string) error

ImportSeed can be used to import an ecrypted seed

func (*User) IncreaseTrustLimit

func (a *User) IncreaseTrustLimit(seedpwd string, trust float64) error

IncreaseTrustLimit increases the trust limit of a user towards the in house stablecoin

func (*User) MoveFundsFromSecondaryWallet

func (a *User) MoveFundsFromSecondaryWallet(amount float64, seedpwd string) error

MoveFundsFromSecondaryWallet moves XLM from the secondary wallet to the primary wallet

func (*User) Save

func (a *User) Save() error

Save inserts a User object into the database

func (*User) SetBan

func (a *User) SetBan(userIndex int) error

SetBan sets the Banned flag on a particular user

func (*User) SweepSecondaryWallet

func (a *User) SweepSecondaryWallet(seedpwd string) error

SweepSecondaryWallet sweeps XLM from the secondary account to the primary account

func (*User) UnverReq added in v1.0.2

func (a *User) UnverReq() error

UnverReq un-requests account verification

func (*User) VerReq added in v1.0.2

func (a *User) VerReq() error

VerReq requests account verification

Jump to

Keyboard shortcuts

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