Categorygithub.com/TradingLabXYZ/WebBack
modulepackage
0.0.0-20220628094014-431a55fc1011
Repository: https://github.com/tradinglabxyz/webback.git
Documentation: pkg.go.dev

# README

Purpose

This repository contains the backend of TradingLab.

It is written in Golang using Postgresql as database.

The code is hosted on DigitalOceans.

There are two main branches: production and staging.

The code is automatically re-compiled at any changes, so it is possibile to simply refresh the webpage to run the new code.

Architecture

The router is Gorilla Mux, using http and websocket.

To allow a dynamic experience to the users, the trading section creates a websocket which is called every time there is a change in the page, returning fresh processed data. In this way if multiple users are watching the same page, they will be all updated almost in real-time, almost at the same time.

In order to know when a user interacts with the platform, a specific Postgresql function is triggered, requiring to the server to activate a specific websocket.

Each new websocket is stored in the variable trades_wss:

type TradesSnapshot struct {
	UserDetails    UserDetails
	Trades         []Trade
	CountTrades    int
	TotalReturnUsd float64
	TotalReturnBtc float64
	Roi            float64
}

type WsTrade struct {
	UserToSee User
	RequestId string
	Channel   chan TradesSnapshot
	Ws        *websocket.Conn
}

trades_wss = make(map[string][]WsTrade)

In this way, every time user_a wants to see the profile of user_b:

  1. send initial snapshot
  2. instanciate websocket
  3. add to trades_wss: user_b as key and user_a as value
  4. if user_b makes a change, get trades_wss[user_b], obtaining user_a
  5. if user_a closes the page the websocket is deleted from trades_wss

Run

Set environmental variables:

export TL_APP_ENV=
export TL_DB_USER=
export TL_DB_PASS=
export TL_DB_HOST=
export TL_DB_PORT=
export DO_KEY=
export DO_SECRET=
export CDN_PATH=
export ADMIN_TOKEN=
export CONTRACT_SUBSCRIPTION=
export MOONBEAM_ENDPOINT=
export DISCORD_WEBHOOK_URL=

Build and run the program:

modd

Test

go test -v -cover -parallel 1

To visualise test coverage

go test -v -parallel 1 -coverprofile=coverage.html && go tool cover -html=coverage.html

Migrate

Use Makefile to migrate up or down the database To clean migration, after making sure everything is correct, fix the table "schema_migrations" in the database.

Docs

swag init -ot go,yaml

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
DeployPlansStorage deploys a new Ethereum contract, binding an instance of PlansStorage to it.
DeploySubscriptionModel deploys a new Ethereum contract, binding an instance of SubscriptionModel to it.
DeploySubscriptionsStorage deploys a new Ethereum contract, binding an instance of SubscriptionsStorage to it.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
NewPlansStorage creates a new instance of PlansStorage, bound to a specific deployed contract.
NewPlansStorageCaller creates a new read-only instance of PlansStorage, bound to a specific deployed contract.
NewPlansStorageFilterer creates a new log filterer instance of PlansStorage, bound to a specific deployed contract.
NewPlansStorageTransactor creates a new write-only instance of PlansStorage, bound to a specific deployed contract.
NewSubscriptionModel creates a new instance of SubscriptionModel, bound to a specific deployed contract.
NewSubscriptionModelCaller creates a new read-only instance of SubscriptionModel, bound to a specific deployed contract.
NewSubscriptionModelFilterer creates a new log filterer instance of SubscriptionModel, bound to a specific deployed contract.
NewSubscriptionModelTransactor creates a new write-only instance of SubscriptionModel, bound to a specific deployed contract.
NewSubscriptionsStorage creates a new instance of SubscriptionsStorage, bound to a specific deployed contract.
NewSubscriptionsStorageCaller creates a new read-only instance of SubscriptionsStorage, bound to a specific deployed contract.
NewSubscriptionsStorageFilterer creates a new log filterer instance of SubscriptionsStorage, bound to a specific deployed contract.
NewSubscriptionsStorageTransactor creates a new write-only instance of SubscriptionsStorage, bound to a specific deployed contract.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
PlansStorageABI is the input ABI used to generate the binding from.
PlansStorageBin is the compiled bytecode used for deploying new contracts.
PlansStorageMetaData contains all meta data concerning the PlansStorage contract.
SubscriptionModelABI is the input ABI used to generate the binding from.
SubscriptionModelBin is the compiled bytecode used for deploying new contracts.
SubscriptionModelMetaData contains all meta data concerning the SubscriptionModel contract.
SubscriptionsStorageABI is the input ABI used to generate the binding from.
SubscriptionsStorageBin is the compiled bytecode used for deploying new contracts.
SubscriptionsStorageMetaData contains all meta data concerning the SubscriptionsStorage contract.

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PlansStorage is an auto generated Go binding around an Ethereum contract.
PlansStorageCaller is an auto generated read-only Go binding around an Ethereum contract.
PlansStorageCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
PlansStorageCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.
PlansStorageFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
PlansStorageRaw is an auto generated low-level Go binding around an Ethereum contract.
PlansStorageSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.
PlansStorageTransactor is an auto generated write-only Go binding around an Ethereum contract.
PlansStorageTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
PlansStorageTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SubscriptionModel is an auto generated Go binding around an Ethereum contract.
SubscriptionModelCaller is an auto generated read-only Go binding around an Ethereum contract.
SubscriptionModelCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
SubscriptionModelCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.
SubscriptionModelChangePlan represents a ChangePlan event raised by the SubscriptionModel contract.
SubscriptionModelChangePlanIterator is returned from FilterChangePlan and is used to iterate over the raw logs and unpacked data for ChangePlan events raised by the SubscriptionModel contract.
SubscriptionModelFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
SubscriptionModelRaw is an auto generated low-level Go binding around an Ethereum contract.
SubscriptionModelSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.
SubscriptionModelSubscribe represents a Subscribe event raised by the SubscriptionModel contract.
SubscriptionModelSubscribeIterator is returned from FilterSubscribe and is used to iterate over the raw logs and unpacked data for Subscribe events raised by the SubscriptionModel contract.
SubscriptionModelTransactor is an auto generated write-only Go binding around an Ethereum contract.
SubscriptionModelTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
SubscriptionModelTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.
SubscriptionsStorage is an auto generated Go binding around an Ethereum contract.
SubscriptionsStorageCaller is an auto generated read-only Go binding around an Ethereum contract.
SubscriptionsStorageCallerRaw is an auto generated low-level read-only Go binding around an Ethereum contract.
SubscriptionsStorageCallerSession is an auto generated read-only Go binding around an Ethereum contract, with pre-set call options.
SubscriptionsStorageFilterer is an auto generated log filtering Go binding around an Ethereum contract events.
SubscriptionsStorageRaw is an auto generated low-level Go binding around an Ethereum contract.
SubscriptionsStorageSession is an auto generated Go binding around an Ethereum contract, with pre-set call and transact options.
SubscriptionsStorageSubscription is an auto generated low-level Go binding around an user-defined struct.
SubscriptionsStorageTransactor is an auto generated write-only Go binding around an Ethereum contract.
SubscriptionsStorageTransactorRaw is an auto generated low-level write-only Go binding around an Ethereum contract.
SubscriptionsStorageTransactorSession is an auto generated write-only Go binding around an Ethereum contract, with pre-set transact options.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author