Skip to content

Commit

Permalink
Merge pull request #63 from fullstack-development/kupo-backend-integr…
Browse files Browse the repository at this point in the history
…ation

change FundraisingInfo
  • Loading branch information
KateBushueva authored Sep 5, 2023
2 parents cd25ffa + 771f0cc commit 16c39d8
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 7 deletions.
1 change: 1 addition & 0 deletions conf/fundraising.template.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"addr_test1xzyyxy9s609346ckm5eyv2qn3s56zc8spajw654yxsrwwkuggvgtp57trt43dhfjgc5p8rpf59s0qrmya4f2gdqxuads6zfmy0", "verTokenCurrency": "2ad1727329f49229089c470bcabc158a2344e149499614dba10cbfac", "verTokenName": "VerificationToken", "threadTokenName":"FundraisingThreadToken"}
56 changes: 56 additions & 0 deletions src/Config/Fundraising.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Config.Fundraising where

import Contract.Prelude

import Contract.Address (Bech32String, addressToBech32, getNetworkId, validatorHashBaseAddress)
import Contract.Monad (Contract, liftContractM)
import Data.Argonaut.Core (stringify)
import Data.Argonaut.Encode (encodeJson)
import Effect (Effect)
import Ext.Contract.Value (currencySymbolToString, tokenNameToString, mkCurrencySymbol)
import Fundraising.FundraisingScript (getFundraisingTokenName, getFundraisingValidatorHash)
import Fundraising.Models (Fundraising(..))
import MintingPolicy.VerTokenMinting as VerToken
import Node.Encoding (Encoding(..))
import Node.FS.Sync (writeTextFile)
import Protocol.Models (Protocol)

type FundraisingConfig =
{ address :: Bech32String
, verTokenCurrency :: Bech32String
, verTokenName :: String
, threadTokenName :: String
}

writeFundraisingConfig :: FundraisingConfig -> Effect Unit
writeFundraisingConfig fundraisingConfig = do
let jfundraisingConfig = stringify $ encodeJson fundraisingConfig
liftEffect $ writeTextFile UTF8 "conf/fundraising.local.conf" jfundraisingConfig

makeFundraisingConfig Protocol Contract FundraisingConfig
makeFundraisingConfig protocol = do
_ /\ verTokenCs <- mkCurrencySymbol (VerToken.mintingPolicy protocol)
let verTokenBech32 = currencySymbolToString verTokenCs
verTn <- VerToken.verTokenName
verTnString <- liftContractM "Impossible to decode fundraising ver token name" $ tokenNameToString verTn

let
fundraising = Fundraising
{ protocol: protocol
, verTokenCurrency: verTokenCs
, verTokenName: verTn
}
networkId <- getNetworkId
frValidatorHash <- getFundraisingValidatorHash fundraising
frAddress <- liftContractM "Impossible to get Fundraising script address" $ validatorHashBaseAddress networkId frValidatorHash
bech32Address <- addressToBech32 frAddress

nftTn <- getFundraisingTokenName
nftTnString <- liftContractM "Impossible to decode fundraising thread token name" $ tokenNameToString nftTn

pure $
{ address: bech32Address
, verTokenCurrency: verTokenBech32
, verTokenName: verTnString
, threadTokenName: nftTnString
}
2 changes: 1 addition & 1 deletion src/Fundraising/Create.purs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ contract protocolData (CreateFundraisingParams { title, amount, duration }) = do
creatorPkh <- pkhToBech32M creds.ownPkh

pure $ FundraisingInfo
{ creator: creatorPkh
{ creator: Just creatorPkh
, title: title
, goal: targetAmount
, raisedAmt: fromInt 0
Expand Down
8 changes: 5 additions & 3 deletions src/Info/UserData.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Shared.MinAda (minAdaValue)
import Shared.Utxo (UtxoTuple, extractDatumFromUTxO, extractValueFromUTxO)

newtype FundraisingInfo = FundraisingInfo
{ creator :: Bech32String
{ creator :: Maybe Bech32String
, title :: String
, goal :: BigInt -- Goal in lovelaces
, raisedAmt :: BigInt -- Raised amount in lovelaces
Expand All @@ -46,7 +46,7 @@ mapToFundraisingInfo utxo = do
now <- currentTime
creator <- pkhToBech32M currentDatum.creatorPkh
pure $ FundraisingInfo
{ creator: creator
{ creator: Just creator
, title: title
, goal: currentDatum.frAmount
, raisedAmt: currentFunds
Expand All @@ -59,7 +59,9 @@ mapToFundraisingInfo utxo = do
filterByPkh :: Bech32String -> Array FundraisingInfo -> Array FundraisingInfo
filterByPkh pkh = Array.filter belongsToUser
where
belongsToUser (FundraisingInfo frInfo) = frInfo.creator == pkh
belongsToUser (FundraisingInfo frInfo) = isCreatorsPkh frInfo.creator
isCreatorsPkh Nothing = false
isCreatorsPkh (Just creator) = creator == pkh

newtype UserInfo = UserInfo
{ address :: Bech32String
Expand Down
8 changes: 6 additions & 2 deletions src/Protocol/StartProtocol.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module Protocol.StartProtocol
) where

import Contract.Prelude
import Governance.UserData (StartGovernanceData(..))
import Shared.OwnCredentials (OwnCredentials(..), getOwnCreds)

import Config.Fundraising (makeFundraisingConfig, writeFundraisingConfig)
import Config.Protocol (mapFromProtocolData, writeProtocolConfig)
import Contract.Address (addressToBech32, getNetworkId, validatorHashBaseAddress)
import Contract.Credential (Credential(..))
Expand All @@ -25,6 +25,7 @@ import Ext.Contract.Value (mkCurrencySymbol)
import Governance.Config (getGovTokenFromConfig)
import Governance.Datum (GovernanceDatum(..))
import Governance.GovernanceScript (getGovernanceValidatorHash, governanceTokenName, governanceValidatorScript)
import Governance.UserData (StartGovernanceData(..))
import MintingPolicy.NftMinting as NFT
import MintingPolicy.NftRedeemer (PNftRedeemer(..))
import Protocol.Datum (PProtocolDatum(..))
Expand All @@ -33,6 +34,7 @@ import Protocol.ProtocolScript (getProtocolValidatorHash, protocolTokenName, pro
import Protocol.UserData (ProtocolConfigParams(..), ProtocolData, dataToProtocol, protocolToData)
import Shared.Config (mapFromProtocolConfigParams, writeDonatPoolConfig)
import Shared.KeyWalletConfig (testnetKeyWalletConfig)
import Shared.OwnCredentials (OwnCredentials(..), getOwnCreds)
import Shared.ScriptRef (mkFundraisingRefScript, mkGovernanceRefScript, mkProposalRefScript, mkProtocolRefScript, mkVerTokenPolicyRef)
import Shared.Tx (completeTx)

Expand Down Expand Up @@ -65,6 +67,8 @@ startSystem params = do
mkGovernanceRefScript protocol
mkProposalRefScript protocol
mkVerTokenPolicyRef protocolData
frConfig <- makeFundraisingConfig protocol
liftEffect $ writeFundraisingConfig frConfig
pure protocolData

startProtocol :: ProtocolConfigParams -> Contract ProtocolData
Expand Down
2 changes: 1 addition & 1 deletion ui/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const root = ReactDOM.createRoot(document.getElementById('root')!);
const App = () => {

const protocolData = {
protocolCurrency: "3b9cd2a49b3d715052857b736d2d570bfaa86b1ac33c51a615d9d418",
protocolCurrency: "8224a01dacaa1b2010b25a255e80e2953f773c3ac842e61175c7b02e",
protocolTokenName: "DonatPoolProtocol"
}

Expand Down

0 comments on commit 16c39d8

Please sign in to comment.