Compare commits

..

No commits in common. "b9cf0bcb9fc0ce26c09f509fbbe40135cb1fd631" and "0f03ad32f21da9807f27710aa52a53d2733b7497" have entirely different histories.

2 changed files with 137 additions and 127 deletions

256
src/DB.hs
View file

@ -22,162 +22,178 @@ import Control.Exception (throwIO)
import Control.Monad (forM_, when) import Control.Monad (forM_, when)
import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Logger (NoLoggingT, runNoLoggingT) import Control.Monad.Logger (NoLoggingT, runNoLoggingT)
import Data.Aeson
import Data.Bifunctor (bimap) import Data.Bifunctor (bimap)
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import Data.HexString import Data.HexString
import Data.List (group, sort) import Data.List (group, sort)
import Data.Maybe (catMaybes, fromJust, isJust) import Data.Maybe (catMaybes, fromJust, isJust)
import Data.Pool (Pool)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding as TE import qualified Data.Text.Encoding as TE
import Data.Time (UTCTime(..))
import Data.UUID (UUID)
import Data.Word import Data.Word
import Database.Esqueleto.Experimental import Database.Esqueleto.Experimental
import qualified Database.Persist.MySQL as PM import qualified Database.Persist.Sqlite as PS
import Database.Persist.TH import Database.Persist.TH
newtype UuidDB = UuidDB
{ getUUID :: UUID
} deriving newtype (Eq, Show, Read, ToJSON, FromJSON)
derivePersistFieldJSON "UuidDB"
newtype HexStringDB = HexStringDB
{ getHex :: HexString
} deriving newtype (Eq, Show, Read)
derivePersistField "HexStringDB"
share share
[mkPersist sqlSettings, mkMigrate "migrateAll"] [mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase| [persistLowerCase|
ZgoBlock json ZgoBlock
confs Int default=0 block_id Int --Block Id number
network String default="" block_confs Int default=0 -- Block confirnations
height Int default=0 block_network String default="" -- Block Network
time Int default=0 block_height Int default=0 -- Block Height
block_time Int default=0 -- Block time
UniqueBlock block_id
deriving Show Eq deriving Show Eq
ZgoBlockTx ZgoBlockTx
blocktx_block_id Int blocktx_block_id Int --'Block Tx parent
blocktx_id Int blocktx_id Int -- Block Tx record Id
blocktx_txid String blocktx_txid String -- Block Tx Id
UniqueBlockTx blocktx_block_id blocktx_id
deriving Show Eq deriving Show Eq
ZgoCountry json ZgoCountry
code T.Text country_code String -- Two Character Country Code
name T.Text country_name String -- Country unique name
UniqueCountryCode code UniqueCountryCode country_code
deriving Show Eq deriving Show Eq
ZgoItem json ZgoItem
owner_id Int item_owner_id Int -- Owner Id
name T.Text item_id String -- Item Id
description T.Text default="" item_name String -- Item name',
cost Double default=0.0 item_description T.Text default="" -- Item description
item_cost Float default=0.0 -- Item Unit price
UniqueItemId item_owner item_id
deriving Show Eq deriving Show Eq
ZgoLanguages ZgoLanguages
encode_id T.Text encode_id String -- Language encoding id
name T.Text default-"" view_name String default-"" -- View name that use this language'
element T.Text default="" view_element String default="" -- 'Element name
element_text T.Text default="" view_element_text T.Text default="" -- Text to be displayed'
UniqueLanguage encode_id view_name view_element
deriving Show Eq deriving Show Eq
ZgoOrder json ZgoOrders
owner ZgoOwnerId order_id Int -- Order Id
session ZgoUserId order_zaddress T.Text -- Order zcash address
timestamp Int order_session T.Text -- Order session id
closed Word8 order_timestamp Int -- Order timestamp
currency T.Text order_closed Word8 -- Order closed flag
price Double order_currency String -- Order currency
total Double order_price Float default=0.0 -- Order ZEC price
totalzec Double order_total Float default=0.0 -- Order total amount
paid Bool order_totalzec Float default=0.0 -- Order total in ZEC
token T.Text default="" order_paid Word8 default=0 -- Order paid status
externalInvoice T.Text default="" order_token String default="" -- Order token
shortcode T.Text order_extinv String default="" -- Order External Invoice
taxamount Double order_shortcode String default='' -- Order invoice shortcode
tipamount Double order_taxamount Float default=0.0 -- Order tax amount
vatamount Double order_tipamount Float default=0.0 -- Order tip amount
order_vatamount Float default=0.0 -- Orcer VAT amount'
UniqueOrderId order_id
deriving Show Eq deriving Show Eq
ZgoOrderLines ZgoOrderLines
orderId ZgoOrderId orderline_orderid Int default=0 -- Orderlines Order Id
qty Int default=0 orderline_line Int default=0 -- Orderlines Line number
name T.Text default="" orderline_qty Int default=0 -- Orderline item qty
cost Double default=0.0 orderline_name T.Text default="" -- Orderline item description
orderline_cost Float default=0.0 -- Orderline item cost
UniqueOrderLine orderline_orderid orderline_line
deriving Show Eq deriving Show Eq
ZgoOwner ZgoOwner
co_name T.Text owner_id Int --'Owner ID number
firstname T.Text owner_co_name String default="" -- Company''s name
lastname T.Text owner_firstname String -- Owner's first name
email T.Text owner_lastname String -- Owner's last name
street T.Text owner_email String -- Owner's email address
city T.Text owner_street String -- Owner's street
state T.Text owner_city String -- Owner's city
zipcode T.Text owner_state String -- Owner's state
phone T.Text owner_zipcode String -- Owner's zip code
country T.Text owner_phone String -- Owner's phone number
website T.Text owner_country String -- Owner's country
currency T.Text owner_website String -- Owner's website URL
zcaddress T.Text owner_currency String -- Owner's currency',
usezats Bool owner_zcaddress String -- Owner's zcash address
crmtoken T.Text owner_usezats Word8 -- Use zats for display
usetax Bool owner_crmtoken T.Text -- Owner's crm token
taxvalue Double owner_usetax Word8 -- Use tax flag
usevat Bool owner_taxvalue Float -- Tax rate to use
vat Double owner_usevat Word8 -- Use vat flag
payconf Bool owner_vat Float -- Vat rate to use
viewkey T.Text owner_payconf Word8 -- Confirm payment flag
invoices Bool owner_viewkey T.Text -- Viewing Key for payment confirmation
tips Bool owner_invoices Word8 -- Use zgo invoices
paid Bool owner_tips Word8 -- Activate tips
expiration UTCTime owner_paid Word8 -- True if account is paid
owner_expiration Int -- Expiration date-time
UniqueOwnerId owner_id
UniqueOwnerZcashAddr owner_zcaddress
deriving Show Eq deriving Show Eq
ZgoPayment ZgoPayment
delta Int payment_id Int -- Payment Id
done Bool payment_delta Int -- Payment delta
zaddress T.Text payment_done Word8 -- Payment done flag
session UuidDB payment_zaddress T.Text -- Payment zcash address
blocktime Int default=0 payment_session String default="" -- Payment session
amount Double default=0.0 payment_blocktime Int default=0 -- Payment blocktime
txid HexStringDB payment_amount Float default=0.0 -- Payment amount
memo T.Text payment_txid String default ="" -- Payment transaction id
payment_memo T.Text default="" -- Payment Memo
UniquePaymentId payment_id
deriving Show Eq deriving Show Eq
ZgoPrice ZgoPrice
price_delta Int default=0 price_id Int -- Price Id
price_done Bool default=0 price_delta Int default=0 -- Price delta
price_zaddress T.Text default="" price_done Word8 default=0 -- Price done flag
price_session String default="" price_zaddress T.Text default="" -- Price zcash address
price_blocktime Int default=0 price_session String default="" -- Price session
price_amount Double default=0.0 price_blocktime Int default=0 -- Price blocktime
price_txid String default="" price_amount Float default=0.0 -- Price amount
price_memo T.Text default="" price_txid String default="" -- Price transaction id
price_memo T.Text default="" -- Price Memo
UniquePriceId price_id
deriving Show Eq deriving Show Eq
ZgoProsession ZgoProsession
zaddress T.Text default="" pro_id Int -- Prosession record id
expiration UTCTime pro_zaddress T.Text default="" -- Prosession zcash address
closed Bool pro_expiration Int default=0 -- Prosession expiration date/time
pro_closed Word8 default=0 -- Prosession closed flag
UniqueProSesId pro_id
UniqueProSesZad pro_zaddress
deriving Show Eq deriving Show Eq
ZgoTransaction ZgoTransaction
zaddress T.Text default="" tx_id Int -- Transaction ID
expiration Int default=0 tx_zaddress T.Text default="" -- Transaction Zcash Address
closed Word8 default=0 tx_expiration Int default=0 -- Transaction Expiration Date/Time
tx_closed Word8 default=0 -- Transaction Closed flag
UniqueTxId tx_id
deriving Show Eq deriving Show Eq
ZgoUser json ZgoUser
owner ZgoOwnerId user_id Int -- User Id
session UuidDB user_zaddress T.Text -- User zcash address,
blocktime Int user_session String -- User session id
pin T.Text user_blocktime Int -- User block time
validated Bool user_pin String -- User pin
user_validated Word8 default=0 -- User validated flag
UniqueUserId user_id
UniqueUserZad user_zaddress
deriving Show Eq deriving Show Eq
ZgoXero ZgoXero
client_id T.Text default="" xero_id Int -- Xero Id
client_secret T.Text default="" xero_client_id String default="" -- Xero client id
xero_client_secret String default="" -- Xero client secret word
UniqueXeroId xero_id
UniqueXeroClientId xero_client_id
deriving Show Eq deriving Show Eq
ZgoXeroToken ZgoXeroToken
zaddress T.Text xerotoken_id Int -- Xero account id
access_token T.Text xerotoken_zaddress T.Text -- Xero zcash address
expires Int xerotoken_access_token T.Text -- Xero account access token
refreshtoken T.Text xerotoken_expires Int -- Xero token expiration date/time
accexpires Int xerotoken_refreshtoken String -- Xero refresh token
accCode T.Text xerotoken_accexpires Int -- Xero account expire date/time
refexpires Int xerotoken_accCode String -- Xero account code
xerotoken_refexpires Int -- Xero reference expire date/time
UniqueXeroTokenId xerotoken_id
deriving Show Eq deriving Show Eq
|]

View file

@ -33,7 +33,6 @@ library
Xero Xero
ZGoBackend ZGoBackend
ZGoTx ZGoTx
DB
hs-source-dirs: hs-source-dirs:
src src
build-depends: build-depends:
@ -48,10 +47,6 @@ library
, configurator , configurator
, containers , containers
, crypto-rng , crypto-rng
, esqueleto
, persistent
, persistent-mysql
, persistent-template
, ghc-prim , ghc-prim
, hexstring , hexstring
, http-conduit , http-conduit
@ -59,7 +54,6 @@ library
, jwt , jwt
, megaparsec , megaparsec
, memory , memory
, monad-logger
, mongoDB , mongoDB
, network , network
, quickcheck-instances , quickcheck-instances