Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions doc/DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ If `ghcjs` installed locally you want to remove following line from `./dev_up.sh

2. Update paths variables in `.env` file, see README.md

2. Run `./script/dev_up.sh` script. After launching:
3. Run `./script/dev_up.sh` script. After launching:
- wait for sync finishing of `node` and `kupo`
- run `wallet.sh` in `cardano` window
- run `encoins --run` in `apps` window to launch relay server
- run `./script/run.sh` in `apps` window to launch frontend
- run `./script/build_dev_js.sh` in apps window to rebuild frontend

4. Build frontend
```shell
./script/docker_dev_run.sh` # if you use docker
./script/build_dev_js.sh`
```

## Dev down

Expand Down
19 changes: 10 additions & 9 deletions frontend/encoins-frontend.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,22 @@ library
Backend.Protocol.StrongTypes
Backend.Protocol.TxValidity
Backend.Protocol.Types
Backend.Protocol.Utility
Backend.Servant.Client
Backend.Servant.Requests
Backend.Status
Backend.Utility
Backend.Wallet
Common.Events
Common.Protocol
Common.Reflex.Dom.Extra
Common.Reflex.Extra
Common.Url
Common.Utility
Config.Config
ENCOINS.App
ENCOINS.App.Body
ENCOINS.App.Widgets.Basic
ENCOINS.App.Widgets.Cloud
ENCOINS.App.Widgets.CloudWindow
ENCOINS.App.Widgets.Coin
ENCOINS.App.Widgets.ConnectWindow
ENCOINS.App.Widgets.ImportWindow
ENCOINS.App.Widgets.InputAddressWindow
ENCOINS.App.Widgets.MainTabs
Expand All @@ -49,10 +51,9 @@ library
ENCOINS.App.Widgets.TransactionBalance
ENCOINS.App.Widgets.WelcomeWindow
ENCOINS.Common.Cache
ENCOINS.Common.Events
ENCOINS.Common.ConnectWindow
ENCOINS.Common.Head
ENCOINS.Common.Language
ENCOINS.Common.Utils
ENCOINS.Common.Widgets.Advanced
ENCOINS.Common.Widgets.Basic
ENCOINS.Common.Widgets.Connect
Expand All @@ -62,13 +63,13 @@ library
ENCOINS.Common.Widgets.Wallet
ENCOINS.DAO
ENCOINS.DAO.Body
ENCOINS.DAO.PollResults
ENCOINS.DAO.Polls
ENCOINS.DAO.Widgets.DelegateWindow
ENCOINS.DAO.Widgets.DelegateWindow.RelayNames
ENCOINS.DAO.Widgets.DelegateWindow.RelayTable
ENCOINS.DAO.Widgets.Navbar
ENCOINS.DAO.Widgets.Poll.PollResults
ENCOINS.DAO.Widgets.Poll.Polls
ENCOINS.DAO.Widgets.PollWidget
ENCOINS.DAO.Widgets.RelayTable
ENCOINS.DAO.Widgets.StatusWidget
ENCOINS.Website
ENCOINS.Website.Body
Expand Down
76 changes: 64 additions & 12 deletions frontend/src/Backend/EncoinsTx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,45 @@ import JS.App (walletSignTx)
import PlutusTx.Prelude (length)
import Reflex.Dom hiding (Input)
import Servant.Reflex (BaseUrl (..))
import Text.Hex (decodeHex)
import Witherable (catMaybes)
import Prelude hiding (length)

import Backend.Protocol.Fees (protocolFees)
import Backend.Protocol.Setup
( encoinsCurrencySymbol
( bulletproofSetup
, emergentChangeAddress
, encoinsCurrencySymbol
, ledgerAddress
, minAdaTxOutInLedger
)
import Backend.Protocol.Types
import Backend.Protocol.Utility
( getEncoinsInUtxos
, mkLedgerRedeemer
, mkWalletRedeemer
)
import Backend.Servant.Requests
import Backend.Status
( LedgerTxStatus (..)
, TransferTxStatus (..)
, WalletTxStatus (..)
)
import Backend.Utility
import Backend.Wallet (Wallet (..), toJS)
import Common.Events
import Common.Protocol
( calculateV
, getEncoinsInUtxos
)
import Common.Reflex.Dom.Extra (elementResultJS)
import Common.Reflex.Extra
( eventMaybe
, fireWhenJustThenReset
, switchHoldDyn
, toEither
, updateUrls
)
import Common.Utility
( toEither
, toText
)
import Backend.Wallet (Wallet (..), toJS)
import ENCOINS.App.Widgets.Basic (elementResultJS)
import ENCOINS.BaseTypes
import ENCOINS.Bulletproofs
import ENCOINS.Common.Events
import ENCOINS.Common.Widgets.Advanced (fireWhenJustThenReset, updateUrls)
import PlutusTx.Builtins

encoinsTxWalletMode ::
(MonadWidget t m) =>
Expand Down Expand Up @@ -394,3 +401,48 @@ encoinsTxLedgerMode
<$> leftmost [eStatusError, eServerError]
]
return (fmap getEncoinsInUtxos dUTXOs, eStatus)

-------------------------------------------------------------------------------
-- Helpers
-------------------------------------------------------------------------------

mkWalletRedeemer ::
EncoinsMode
-> Address
-> Address
-> BulletproofParams
-> Secrets
-> [MintingPolarity]
-> Randomness
-> EncoinsRedeemer
mkWalletRedeemer mode ledgerAddr changeAddr bp secrets mps rs = red
where
(_, inputs, proof) = bulletproof bulletproofSetup bp secrets mps rs
v = calculateV secrets mps
inputs' = map (\(Input g p) -> (fromGroupElement g, p)) inputs
sig =
toBuiltin $
fromJust $
decodeHex ""
red = ((ledgerAddr, changeAddr, protocolFees mode v), (v, inputs'), proof, sig)

mkLedgerRedeemer ::
EncoinsMode
-> Address
-> BulletproofParams
-> Secrets
-> [MintingPolarity]
-> Randomness
-> Address
-> Maybe EncoinsRedeemer
mkLedgerRedeemer mode ledgerAddr bp secrets mps rs changeAddr =
if changeAddr == emergentChangeAddress then Nothing else Just red
where
(_, inputs, proof) = bulletproof bulletproofSetup bp secrets mps rs
v = calculateV secrets mps
inputs' = map (\(Input g p) -> (fromGroupElement g, p)) inputs
sig =
toBuiltin $
fromJust $
decodeHex ""
red = ((ledgerAddr, changeAddr, protocolFees mode v), (v, inputs'), proof, sig)
10 changes: 8 additions & 2 deletions frontend/src/Backend/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Backend.Protocol.Fees (protocolFees)
import Backend.Protocol.Setup (ledgerAddress)
import Backend.Protocol.TxValidity (getAda)
import Backend.Protocol.Types
import ENCOINS.App.Widgets.Basic (elementResultJS)
import Common.Reflex.Dom.Extra (elementResultJS)
import ENCOINS.Bulletproofs
import ENCOINS.Crypto.Field (Field (..))
import JS.App (sha2_256)
Expand Down Expand Up @@ -47,7 +47,13 @@ getRandomness :: (MonadWidget t m) => Event t () -> m (Behavior t Randomness)
getRandomness e = do
eRandomness <- performEvent $ liftIO randomIO <$ e
hold
( Randomness (F 3417) (map F [1 .. 20]) (map F [21 .. 40]) (F 8532) (F 16512) (F 1235)
( Randomness
(F 3417)
(map F [1 .. 20])
(map F [21 .. 40])
(F 8532)
(F 16512)
(F 1235)
)
eRandomness

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Backend/Protocol/StrongTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Backend.Protocol.StrongTypes
, toPasswordHash
) where

import Backend.Utility (hashKeccak512)
import Common.Utility (hashKeccak512)

import Data.Text (Text)
import qualified Data.Text as T
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Backend/Protocol/TxValidity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Backend.Status
( AppStatus
, isAppProcess
)
import Backend.Utility (space, toText)
import Common.Utility (space, toText)
import Backend.Wallet (Wallet (..), WalletName (..), currentNetworkApp)
import CSL (TransactionUnspentOutput (..), amount, coin)
import Config.Config (NetworkConfig (..), networkConfig)
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Backend/Servant/Requests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Backend.Servant.Requests where

import Backend.Protocol.Types
import Backend.Servant.Client
import Backend.Utility (normalizeCurrentUrl, normalizePingUrl)
import Common.Url (normalizeCurrentUrl, normalizePingUrl)
import Config.Config (saveServerUrl)
import ENCOINS.Common.Events
import Common.Events
import JS.App (pingServer)

import CSL (TransactionInputs)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Backend/Status.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Backend.Status where

import Backend.Utility (column, space, toText)
import Common.Utility (column, space, toText)
import Data.Text (Text)
import qualified Data.Text as T

Expand Down
Loading