Skip to content

Commit

Permalink
Auxiliary light wallets (#48)
Browse files Browse the repository at this point in the history
* added NetworkParams to endpoints

* fixed testing endpoints

* updated dists
  • Loading branch information
KateBushueva authored Jul 20, 2023
1 parent c473ade commit ac67d6e
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 106 deletions.
1 change: 1 addition & 0 deletions dist/131.index.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/635.index.js

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions dist/635.index.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0

THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.

See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
Binary file added dist/8274ad5e89f8d3ade8c8.module.wasm
Binary file not shown.
Binary file added dist/ba909b983759e313bbdd.module.wasm
Binary file not shown.
Binary file added dist/d7bda1bc06ed504ff180.module.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions exe/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ import Info.AppInfo as AppInfo
import Info.UserData (AppInfo, FundraisingInfo)
import Info.UserRelatedFundraisings as UserRelatedFundraisings
import Protocol.UserData (ProtocolData)
import Shared.NetworkData (NetworkParams)

data Contracts = Contracts
{ connectWallet :: (Bech32String -> Effect Unit) -> (String -> Effect Unit) -> Effect Unit
, getAppInfo :: (AppInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
, createFundraising :: (FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> CreateFundraisingParams -> Effect Unit
, donate :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> FundraisingData -> Int -> Effect Unit
, receiveFunds :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> FundraisingData -> Effect Unit
, getAllFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
, getUserRelatedFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
{ connectWallet :: (Bech32String -> Effect Unit) -> (String -> Effect Unit) -> NetworkParams -> Effect Unit
, getAppInfo :: (AppInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
, createFundraising :: (FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> CreateFundraisingParams -> Effect Unit
, donate :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> FundraisingData -> Int -> Effect Unit
, receiveFunds :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> FundraisingData -> Effect Unit
, getAllFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
, getUserRelatedFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
}

main :: Contracts
Expand Down
17 changes: 5 additions & 12 deletions src/ConnectWallet.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@ module Common.ConnectWallet where
import Contract.Prelude

import Contract.Address (Bech32String, addressToBech32, getWalletAddresses)
import Shared.TestnetConfig (mkTestnetNamiConfig)
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftedM, runContract)
import Contract.Monad (Contract, liftedM)
import Data.Array (head) as Array
import Effect.Aff (runAff_)
import Effect.Exception (Error, message)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)

runConnectWallet :: (Bech32String -> Effect Unit) -> (String -> Effect Unit) -> Effect Unit
runConnectWallet onComplete onError = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig contract
where
handler :: Either Error Bech32String -> Effect Unit
handler (Right response) = onComplete response
handler (Left err) = onError $ message err
runConnectWallet :: (Bech32String -> Effect Unit) -> (String -> Effect Unit) -> NetworkParams -> Effect Unit
runConnectWallet onComplete onError networkParms = runContractWithResult onComplete onError networkParms contract

contract :: Contract Bech32String
contract = do
Expand Down
26 changes: 13 additions & 13 deletions src/Fundraising/Create.purs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Contract.BalanceTxConstraints (BalanceTxConstraintsBuilder, mustSendChang
import Contract.Chain (currentTime)
import Contract.Credential (Credential(ScriptCredential))
import Contract.Log (logInfo')
import Contract.Monad (Contract, runContract, liftContractM, liftedM, liftedE)
import Contract.Monad (Contract, liftContractM, liftedM, liftedE)
import Contract.PlutusData (Redeemer(Redeemer), Datum(Datum), toData)
import Contract.ScriptLookups as Lookups
import Contract.Time (POSIXTime(..))
Expand All @@ -21,8 +21,7 @@ import Data.BigInt (fromInt, toString)
import Data.Lens (view)
import Data.Map (toUnfoldable) as Map
import Data.String (take)
import Effect.Aff (runAff_)
import Effect.Exception (throw, Error, message)
import Effect.Exception (throw)
import Ext.Contract.Time (addTimes)
import Ext.Contract.Value (currencySymbolToString, mkCurrencySymbol)
import Ext.Seriaization.Key (pkhToBech32M)
Expand All @@ -43,17 +42,19 @@ import Protocol.Redeemer (PProtocolRedeemer(..))
import Protocol.UserData (ProtocolData, dataToProtocol)
import Shared.Duration (durationToMinutes, minutesToPosixTime)
import Shared.MinAda (minAdaValue)
import Shared.TestnetConfig (mkTestnetNamiConfig)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)
import Shared.Utxo (extractDatumFromUTxO, extractValueFromUTxO, filterNonCollateral)

runCreateFundraising :: (FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> CreateFundraisingParams -> Effect Unit
runCreateFundraising onComplete onError protocolData params = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig (contract protocolData params)
where
handler :: Either Error FundraisingInfo -> Effect Unit
handler (Right response) = onComplete response
handler (Left err) = onError $ message err
runCreateFundraising
:: (FundraisingInfo -> Effect Unit)
-> (String -> Effect Unit)
-> ProtocolData
-> NetworkParams
-> CreateFundraisingParams
-> Effect Unit
runCreateFundraising onComplete onError protocolData networkParams funraisingParams = do
runContractWithResult onComplete onError networkParams (contract protocolData funraisingParams)

contract :: ProtocolData -> CreateFundraisingParams -> Contract FundraisingInfo
contract protocolData (CreateFundraisingParams { title, amount, duration }) = do
Expand Down Expand Up @@ -220,4 +221,3 @@ contract protocolData (CreateFundraisingParams { title, amount, duration }) = do
, path: currencySymbolToString nftCs
, isCompleted: false
}

9 changes: 5 additions & 4 deletions src/Fundraising/Donate.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import Fundraising.Redeemer (PFundraisingRedeemer(..))
import Fundraising.UserData (FundraisingData(..))
import Shared.Utxo (checkTokenInUTxO)
import Shared.MinAda (minAdaValue)
import Shared.RunContract (runContractWithUnitResult)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)
import Protocol.UserData (ProtocolData)

runDonate :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> FundraisingData -> Int -> Effect Unit
runDonate onComplete onError pData fundraisingData amount =
runContractWithUnitResult onComplete onError $ contract pData fundraisingData amount
runDonate :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> FundraisingData -> Int -> Effect Unit
runDonate onComplete onError pData networkParams fundraisingData amount =
runContractWithResult onComplete onError networkParams $ contract pData fundraisingData amount

contract :: ProtocolData -> FundraisingData -> Int -> Contract Unit
contract pData (FundraisingData fundraisingData) adaAmount = do
Expand Down
11 changes: 6 additions & 5 deletions src/Fundraising/ReceiveFunds.purs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ import MintingPolicy.NftMinting as NFT
import MintingPolicy.NftRedeemer (PNftRedeemer(..))
import MintingPolicy.VerTokenMinting as VerToken
import Protocol.UserData (ProtocolData, dataToProtocol)
import Shared.Utxo (checkTokenInUTxO)
import Shared.MinAda (minAda)
import Shared.RunContract (runContractWithUnitResult)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)
import Shared.Utxo (checkTokenInUTxO)

runReceiveFunds :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> FundraisingData -> Effect Unit
runReceiveFunds onComplete onError pData fundraisingData =
runContractWithUnitResult onComplete onError $ contract pData fundraisingData
runReceiveFunds :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> FundraisingData -> Effect Unit
runReceiveFunds onComplete onError pData networkParams fundraisingData =
runContractWithResult onComplete onError networkParams $ contract pData fundraisingData

contract :: ProtocolData -> FundraisingData -> Contract Unit
contract pData (FundraisingData fundraisingData) = do
Expand Down
18 changes: 6 additions & 12 deletions src/Info/AllFundraisings.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,22 @@ import Contract.Prelude
import Contract.Address (validatorHashBaseAddress)
import Contract.Config (NetworkId(TestnetId))
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM, runContract)
import Contract.Monad (Contract, liftContractM)
import Contract.Utxos (utxosAt)
import Data.Map as Map
import Data.Traversable (traverse)
import Effect.Aff (runAff_)
import Effect.Exception (Error, message)
import Ext.Contract.Value (mkCurrencySymbol)
import Fundraising.FundraisingScript (getFundraisingValidatorHash)
import Fundraising.Models (Fundraising(..))
import Info.UserData (FundraisingInfo, mapToFundraisingInfo)
import MintingPolicy.VerTokenMinting as VerToken
import Protocol.UserData (ProtocolData, dataToProtocol)
import Shared.TestnetConfig (mkTestnetNamiConfig)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)

runGetAllFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
runGetAllFundraisings onComplete onError protocolData = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig (getAllFundraisings protocolData)
where
handler :: Either Error (Array FundraisingInfo) -> Effect Unit
handler (Right response) = onComplete response
handler (Left err) = onError $ message err
runGetAllFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
runGetAllFundraisings onComplete onError protocolData networkParams =
runContractWithResult onComplete onError networkParams (getAllFundraisings protocolData)

getAllFundraisings :: ProtocolData -> Contract (Array FundraisingInfo)
getAllFundraisings protocolData = do
Expand Down
18 changes: 6 additions & 12 deletions src/Info/AppInfo.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ import Contract.Prelude

import Contract.Address (getNetworkId, validatorHashBaseAddress)
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM, runContract)
import Contract.Monad (Contract, liftContractM)
import Contract.Utxos (utxosAt)
import Ctl.Internal.Plutus.Types.Transaction (UtxoMap)
import Effect.Aff (runAff_)
import Effect.Exception (Error, message)
import Shared.OwnCredentials (getOwnUserInfo)
import Info.UserData (AppInfo(..))
import Protocol.Models (Protocol)
import Protocol.ProtocolScript (getProtocolValidatorHash)
import Protocol.UserData (ProtocolData, dataToProtocol, getConfigFromProtocolDatum)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)
import Shared.Utxo (UtxoTuple, extractDatumFromUTxO, getUtxoByNFT)
import Shared.TestnetConfig (mkTestnetNamiConfig)

runGetAppInfo :: (AppInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
runGetAppInfo onComplete onError protocolData = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig (appInfoContract protocolData)
where
handler :: Either Error AppInfo -> Effect Unit
handler (Right appInfo) = onComplete appInfo
handler (Left error) = onError $ message error
runGetAppInfo :: (AppInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
runGetAppInfo onComplete onError protocolData networkParams =
runContractWithResult onComplete onError networkParams (appInfoContract protocolData)

appInfoContract :: ProtocolData -> Contract AppInfo
appInfoContract protocolData = do
Expand Down
18 changes: 6 additions & 12 deletions src/Info/UserRelatedFundraisings.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@ import Contract.Prelude

import Contract.Address (ownPaymentPubKeysHashes)
import Contract.Log (logInfo')
import Contract.Monad (Contract, liftContractM, runContract)
import Contract.Monad (Contract, liftContractM)
import Data.Array as Array
import Effect.Aff (runAff_)
import Effect.Exception (Error, message)
import Ext.Seriaization.Key (pkhToBech32M)
import Info.AllFundraisings (getAllFundraisings)
import Info.UserData (FundraisingInfo, filterByPkh)
import Protocol.UserData (ProtocolData)
import Shared.TestnetConfig (mkTestnetNamiConfig)
import Shared.NetworkData (NetworkParams)
import Shared.RunContract (runContractWithResult)

runGetUserRelatedFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> Effect Unit
runGetUserRelatedFundraisings onComplete onError protocolData = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig (getUserRelatedFundraisings protocolData)
where
handler :: Either Error (Array FundraisingInfo) -> Effect Unit
handler (Right response) = onComplete response
handler (Left err) = onError $ message err
runGetUserRelatedFundraisings :: (Array FundraisingInfo -> Effect Unit) -> (String -> Effect Unit) -> ProtocolData -> NetworkParams -> Effect Unit
runGetUserRelatedFundraisings onComplete onError protocolData networkParams = do
runContractWithResult onComplete onError networkParams (getUserRelatedFundraisings protocolData)

getUserRelatedFundraisings :: ProtocolData -> Contract (Array FundraisingInfo)
getUserRelatedFundraisings protocolData = do
Expand Down
41 changes: 41 additions & 0 deletions src/Shared/NetworkData.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Shared.NetworkData where

import Contract.Address (NetworkId(..))
import Contract.Prelude

newtype NetworkParams = NetworkParams
{ wallet :: String
, isMainnet :: Boolean
}

derive newtype instance Show NetworkParams
derive instance Generic NetworkParams _

data WalletType = Nami | Flint | Lode | Eternl

derive instance Eq WalletType
derive instance Generic WalletType _

instance Show WalletType where
show = genericShow

newtype NetworkWallet = NetworkWallet
{ networkId :: NetworkId
, walletType :: WalletType
}

derive newtype instance Show NetworkWallet
derive newtype instance Eq NetworkWallet

networkParamsToNetworkWallet :: NetworkParams -> Maybe NetworkWallet
networkParamsToNetworkWallet (NetworkParams { wallet, isMainnet }) =
case (wallet /\ isMainnet) of
("Nami" /\ false) -> Just $ NetworkWallet { networkId: TestnetId, walletType: Nami }
("Flint" /\ false) -> Just $ NetworkWallet { networkId: TestnetId, walletType: Flint }
("Lode" /\ false) -> Just $ NetworkWallet { networkId: TestnetId, walletType: Lode }
("Eternl" /\ false) -> Just $ NetworkWallet { networkId: TestnetId, walletType: Eternl }
("Nami" /\ true) -> Just $ NetworkWallet { networkId: MainnetId, walletType: Nami }
("Flint" /\ true) -> Just $ NetworkWallet { networkId: MainnetId, walletType: Flint }
("Lode" /\ true) -> Just $ NetworkWallet { networkId: MainnetId, walletType: Lode }
("Eternl" /\ true) -> Just $ NetworkWallet { networkId: MainnetId, walletType: Eternl }
_ -> Nothing
20 changes: 11 additions & 9 deletions src/Shared/RunContract.purs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
module Shared.RunContract where

import Contract.Prelude
import Effect.Exception (Error, message)
import Data.Maybe (maybe)
import Effect.Aff (runAff_)
import Shared.TestnetConfig (mkTestnetNamiConfig)
import Effect.Exception (Error, message, throw)
import Contract.Monad (Contract, runContract)
import Shared.TestnetConfig (mkNetworkWalletConfig)
import Shared.NetworkData (NetworkParams, networkParamsToNetworkWallet)

runContractWithUnitResult :: (Unit -> Effect Unit) -> (String -> Effect Unit) -> Contract Unit -> Effect Unit
runContractWithUnitResult onComplete onError contract = do
testnetNamiConfig <- mkTestnetNamiConfig
runAff_ handler $ runContract testnetNamiConfig contract
runContractWithResult :: forall a. (a -> Effect Unit) -> (String -> Effect Unit) -> NetworkParams -> Contract a -> Effect Unit
runContractWithResult onComplete onError networkParams contract = do
networkWallet <- maybe (throw "Impossible to parse Wallet type") pure $ networkParamsToNetworkWallet networkParams
networkWalletConfig <- mkNetworkWalletConfig networkWallet
runAff_ handler $ runContract networkWalletConfig contract
where
handler :: Either Error Unit -> Effect Unit
handler (Right _) = onComplete unit
handler :: Either Error a -> Effect Unit
handler (Right res) = onComplete res
handler (Left err) = onError $ message err

Loading

0 comments on commit ac67d6e

Please sign in to comment.