From 3c2a5dd8406f11fad47defbcd2a110d13b72c352 Mon Sep 17 00:00:00 2001 From: ChakravartiRaghavan Date: Sat, 7 Oct 2023 08:29:14 -0700 Subject: [PATCH] lucid --- package-lock.json | 6 + package.json | 1 + pages/{crowdFund.tsx => crowdFund1.tsx} | 0 pages/crowdfund.tsx | 1730 +++++++++++++++++++++++ pages/index.tsx | 53 +- utils/cardano.ts | 8 +- utils/lucid.ts | 20 +- utils/valueUtils.ts | 6 +- yarn.lock | 5 + 9 files changed, 1818 insertions(+), 11 deletions(-) rename pages/{crowdFund.tsx => crowdFund1.tsx} (100%) create mode 100644 pages/crowdfund.tsx diff --git a/package-lock.json b/package-lock.json index 1c555cb..2fd84a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@hyperionbt/helios": "^0.7.8", + "crypto-js": "^4.1.1", "daisyui": "^2.31.0", "easy-peasy": "^5.1.0", "helios-api": "npm:@hyperionbt/helios@^0.13.21", @@ -1596,6 +1597,11 @@ "node": ">= 8" } }, + "node_modules/crypto-js": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz", + "integrity": "sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==" + }, "node_modules/css-selector-tokenizer": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz", diff --git a/package.json b/package.json index ad46987..845d674 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "@babel/plugin-proposal-private-methods": "^7.18.6", "@babel/plugin-proposal-private-property-in-object": "^7.18.6", "@hyperionbt/helios": "^0.7.8", + "crypto-js": "^4.1.1", "daisyui": "^2.31.0", "easy-peasy": "^5.1.0", "helios-api": "npm:@hyperionbt/helios@^0.13.21", diff --git a/pages/crowdFund.tsx b/pages/crowdFund1.tsx similarity index 100% rename from pages/crowdFund.tsx rename to pages/crowdFund1.tsx diff --git a/pages/crowdfund.tsx b/pages/crowdfund.tsx new file mode 100644 index 0000000..5439d04 --- /dev/null +++ b/pages/crowdfund.tsx @@ -0,0 +1,1730 @@ +import type { NextPage } from 'next' +import Head from 'next/head' +import WalletConnect from '../components/WalletConnect' +import { useStoreActions, useStoreState } from "../utils/store" +import Link from 'next/link' +import { useState, useEffect } from 'react' +import { getAssets } from "../utils/cardano"; +import NftGrid from "../components/NftGrid"; +import initLucid from '../utils/lucid' +import { Lucid, + Credential, + TxHash, + Lovelace, + Constr, + SpendingValidator, + Data, + fromText, + Unit, + MintingPolicy, + PolicyId, + Address, + UTxO, + applyParamsToScript, + Assets, + ScriptHash, + Redeemer, + paymentCredentialOf, + KeyHash, + generatePrivateKey, + getAddressDetails, + toUnit, + datumJsonToCbor, + } from 'lucid-cardano' +import * as helios from '@hyperionbt/helios' +import {fromAssets, toAssets, union, Value} from "../utils/valueUtils" +import { fromAddress, OfferDatum, OfferInfo, toAddress } from '../utils/offerUtils' +import { kMaxLength } from 'buffer' + +// import { readFirstLineFromFile } from '../utils/fileUtils'; + +import * as CryptoJS from 'crypto-js'; +// import { contributorSeed } from '../data'; + +// const fs = require("fs") + +// const cborHex = "590a1901000032323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323232323222253335734646464646a666ae68cdc39aab9d375400c9000092999ab9a337106eb4c038dd60041bad300a37580102660822660822660822660766eaccccc0b0014d5d09bac0080014a06eaccc0e8dd59981598069bac0084c0101010037566605660126eb0020c038dd600409981d9bab333302c0050020014a06eacc0a9301051a004c4b4000133029375a0086eb4c030dd60040998130029aba137580102660822660822660822660822660822660766eaccccc0b0014d5d09bac0080014a06eaccc0acc024dd60041ba8337026eb4c038dd60041bad301037580102660766eaccccc0b0014c03cdd6004000a50375666056601a6eb0021300101010013303b3756666605800a004002940dd598152601051a007270e000133029375a0086eb4c030dd60040998128998130029aba1375801026604c00a601e6eb00204cc0944cdd798081bac0084c0101000013303b3756666605800a60226eb0020005281bab3302b3009375801060206eb0020494ccd5cd19b88375a60680026eb4c028dd60040a5015333573466e24dd6981a0009bad300e3758010294054ccd5cd19b88375a660486eacc0dcc0dcc08c019300106d8799f4040ff00483030e4c1c5280992999ab9a3302a375a601e6eb00252000133042133042133042133042133042133042133023375a6604a6eacc0e0c0e0c09001d30106d8799f4040ff00482036b10244cc0f0dd59999810003002000a513756660766eaccc0ecdd59981618071bac0094c0101010037566605860146eb0024c0d4008dd59815a601051a009896800013303c3756666605a00c60206eb0024009281bab3303b37566605860146eb0024c03cdd60049bab302b4c1051a002625a0001337106eb4014dd698069bac00913302a375a00a6eb4c030dd6004899b89337026eb4c07cc078018dd6980e980f00324101756e0626604e00c60660042660842660842660842660842660842660466eb4cc094dd5981c181c1812003a60106d8799f4040ff00483030e4c1c4cc0f0dd59999810003002000a513756660766eaccc0ecdd59981618071bac0094c0101010037566605860146eb0024c0d4008dd59815a601051a00989680001337106eb4014dd698069bac00913302a375a00a6eb4c030dd6004899b89337026eb4c07cc078018dd6980e980f00324101756e0626604e00c60660046e9ccd5d01aba1375801066ae80d5d09aba2375801066ae80c024dd600419aba0300a375801066ae80d5d0980c9bac00833574060166eb0020cd5d018061bac008335740601a6eb0020cd5d0181a00099aba03032001335740606e00266ae80d5d0981400099aba03011375801066ae80d5d09aba23012375801097ae00064c011e581c89e0e1706f1b825460bd49954cc04dad5159e522e649a1ad17f3988600302f301e302f302f3034302000330183019001302d0011498588d5d0980980091aba13011001235742601c00246ae84c0300048d5d0980500091aba13008001235742600c00246ae84c0100048d5d0980100091aba230020012357446ae88c0080048d5d1180100091aba23002001235744600400246ae88c0080048d5d1180100091aba23002001235744600400246ae88d5d10009180b980b980b80091aba1300b001230153015301a0012222301b3758a666ae680044dd39980c00211981389980300080209980a80080189ba733018004233027133006001004133014001375260260064464a666ae68cdc39aab9d37540029001099baf0023015300400114a060286028004466022002900111180f19b88002001232333001001375860226022004466ebcc048004c048c05c00c8894ccd5cd1aba30021615333573460026ae840084d5d080109998018019aba2002001223233300100122533357346ae8c0045854ccd5cd19baf35573a6ae84004c0600104d55cf1aba100113300200235744002006444a666ae68d5d18008b0a999ab9a3375e6aae74d5d080098098020998010011bab35573c6ae840044ccc00c00c008d5d1000912999ab9a500214a200244660386eb0d5d09aba2300300223375e00200446ae88d5d11aba235744600400246ae88c03800488c05ccdc4801000919801260106d8799f4040ff00001225333573466e1d2000375a0022980101a0001374c66ae80cdd818048011ba633574066ec0c0380080052f5bded8c097adef6c602222300e3758a666ae680044dd39980580211980d09980480080209980400080189ba73300b00423301a1330090010041330070013752600c00646e50dd98009119baf325333573466e1cd55ce800a400426ae84d55cf0008a601014000375460100040024464a666ae68cdc39aab9d001480104cdd78011aba135573c0022940dd5180380111192999ab9a3370e6aae74dd5000a4000266ebc008c014cc010005200014a06008600800444a666ae68cdc39aab9d375400400220042c46ae84c02000488c8ccc004004dd618020018011112999ab9a35746004297ae015333573460026ae840084cd5d01aba10023330030033574400400226660060066ae880080048d5d0980100091aba230040012323333001001002223300837560046eacc014005300101a0002222533357346ae8c00c40044cccc010010d5d1001801198010009aba1003235742600400246ae88c0080048d55cf1baa0012232374c6660020026601000600497adef6c60222533357346ae8c00840044cc88c94ccd5cd1aba30011002133574066ec000cdd30008011991191998008009980780180125eb7bdb1808894ccd5cd1aba3002100113322325333573466e1c00520001002133574066ec000cdd400080119b803301100700233011006002357420046660060066ae88008004cc02401c008cc024018008d5d08011998018019aba20020012232330010013300700300222533357346ae8c0045288992999ab9a3008332232330010013300c00300222533357346ae8c0045288992999ab9a300d300d337106601800a0026601800800229404cc00c00cd5d10011aba1001330060050013300600400114a02660060066ae88008d5d0800911919800800801912999ab9a35746002297adef6c6015333573466ebcd55ce9aba1001003137566aae78d5d08008998010011aba20012232333001001003002222533357346ae8c0085200015333573466ebcd55ce9aba10020011375a6aae78d5d080109998018019aba20020012333573400294128911919191998008009998010010018020019112999ab9a357460022004266ae80d5d08009998018018011aba2001222533357346ae8c00452f5c0264a666ae68cc0200148cdd780080109998020020019aba200213357400026660080080066ae88008d55ce9aba1001323300100100322533357346ae8c00452f5c0266ae80d55ce9aba100133002002357440024464666002002006004444a666ae68d5d18010a5015333573460026ae8400852889998018019aba20020012253335734a0040022941" + +// crowdFundingOnChainTrue.hs - temporary test +const sValCborCrowdFund = "586e586c0100003232323232322223232323253330083370e90010010991919299980599b87480080084c8c8c8c9263013002300e0013754014601e0142c601e00460140026ea8c028c02c01058c030008c01c004dd5180398040009804000ab9a5573aae855d1118011baa0015573c1" + + +// crowdFundingOnChain.hs +// const sValCborCrowdFund = "58845882010000323232323232222323232323253330093370e90010010991919299980619b87480080084c8c8c8c8c8c8c8c92630180023013001375401e602600260240026022002602000260200162c602000460160026ea8c02cc03001458c034008c020004dd51804180480118048011804000ab9a5573aae855d1118011baa0015573d" +// const sValCborCrowdFund = "58845882010000323232323232222323232323253330093370e90010010991919299980619b87480080084c8c8c8c8c8c8c8c92630180023013001375401e602600260240026022002602000260200162c602000460160026ea8c02cc03001458c034008c020004dd51804180480118048011804000ab9a5573aae855d1118011baa0015573d" // Crowd Fund some logic back +// const sValCborCrowdFundV7 = "5655010000222323232498d55cf0011aab9d0013754005" // Crowd Fund stripped all the logic inside +// const sValCborCrowdFundV6 = "59068b590688010000323232323232323232323232323232323232323232323232323232323232323232323232222323232323253330273370e90010010991919299981519b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc0e0cdc3a4004004264646464646464646464646464a66608a66e1d2000002161323232323232323232323253330503370e90000010a4c2a6660a0664609e44a6660a4002294054ccc14ccdd7982a8008018a51130023056001305202601715333050533034337126eb4c148088dd698290108a9981a19b89375a60a40206eb4c14803c4cdc49bad305200f375a60a401e2a6660a0a6606866e1cccc888cccc0d400920002333303600248001d69bab001003375660a402a6eb8c148048dd71829008a40042a6606866e1cc94ccc1400045200013330513375e60a460a60026ea4108dd6982b18299bab3056305300148000dd5982900a9bad305200f153303433036375660a402a606e666076e00ccc108104104dd698290079998211bae3052012375c60a4022900109981b1bab3052015303733303b7006660840820826eb4c14803cccc108dd718290091bae30520114800854ccc140cdc41bad3052013375a60a40322930b0b0b0b182a00118278009baa02d304f001304e001304d001304c001304b001304b303e30443049304a001304900130493253330450011613253330460011304900216304900133230442253330470011043132533304930040011330450013003304c00213003304c002304a001322323232533304a3370e90000010a5013371e6eb8c130004014c138008c124004dd51918251826000982498258009bae30470013758608e028609200460880026ea8c8c114c11c004c110020c110004c10c004c108004c104004c100004c100c0ccc0e4c0f8c0fc004c0f8004c0f8cc88cc0e8894ccc0f4004584c94ccc0fcc8cdd79ba73044005374e60880026082002260826084002260066084004608460800020046eb0c0f0028c0f0050dd6181d981e003981e181d0030b181e001181b8009baa303700130383036001303730350013230363036303630360013035001303430340013034303200e303200130310013030001302f001302e001302e00b16302e002302900137546052605400a2c6056004604c0026ea8c098c09c008c09c008c0980048c008dd480091111980f91299981100088028a99981199baf3024302500100613004302830250011300230260010012233301e00200100314a04466ebcdd30011ba6001233002232533301c300500112250011223002003330052533301c3375e0026ea120001225001122300200300100123003233300237560024644460040066e9800448940055d1911980b11299980c80088080991998029810180e80111980c19bb0301d301e00300100210013002301d001001222333004223330070050020010020012300322374c660066eac008dd580091801111ba833003375a0046eb4004888cccc01000c880080080048c040c00800488c8c88cc00400c0088894ccc0540044cc04800c0084c8c8c94ccc064cdd780100089980a99bb000233009301e006301e00333300822002005301c00415333019337206eb8008dd700089980a803199980411000801980e00200289980a801999980411000803002980e002180c801180c002180c00091299980980108008999980191000980b001180b801000a4410022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980499bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6601c66e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660440022930b18128019980d919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302a001149858c0b400cdd6800981500098150018b1bae0013027001163029002302400137540026eb0004c088004c08800cdd6800980f800980f8019bad001301c001301c00316375c002603200260320082c6e34004dd7000980a800980a8018b1bad0013012001301200316375c002601e0022c602200460180026ea80048cc0240040085289180291299980400088020998029801980580098011806000a5eb815d01191919299980399b87480100084c02400458c02c008c018004dd5000919180111980100100091801119801001000aab9f5734aae755d0aba2230023754002aae781" // Crowd Fund +// const sValCborCrowdFundv5 = "5908d45908d1010000323232323232323232323232323232323232323232323232323232323232323232323232323232323232322223232323232533302e3370e90010010991919299981899b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc0fccdc3a4004004264646464646464646464646464a66609866e1d20020021323232323232323232323253330573370e90010010a99982b99823982c81300b8a99982ba9981999b89375a60b20446eb4c16408454cc0cccdc49bad3059010375a60b201e266e24dd6982c8079bad305900f153330575330333370e6660946eacc164054dd7182c8091bae30590114800854cc0cccdc398191bab3059015375a60b201e2a660666606a6eacc164054c0d8ccc0e9c01998200268269bad305900f333040375c60b20246eb8c1640452002133035375660b202a606c666074e00ccc100134134dd6982c8079998201bae3059012375c60b202290010a99982b99b88375a60b20266eb4c16406452616161616153330575330333370e6660946eacc164054dd7182c8091bae30590114800854cc0cccdc398191bab3059015375a60b201e2a660666606a6eacc164054c0d8ccc0e9c01998200268269bad305900f333040375c60b20246eb8c1640452002133035375660b202a606c666074e00ccc100134134dd6982c8079998201bae3059012375c60b202290010a99982ba9981999b8733304a375660b20146eb8c16401cdd7182c8032400426606a66608009a09a608c6eb0c164c168010c0d8ccc0e9c019982002682698231bac3059305a00f33304004d04d30450301533305733035303633303a70066608009a09a6eb4c16403cccc100134134c1140c0ccc100134134dd6982c8020a99982ba9981999baf3059009305901415330333375e60b201060b20262a6606666ebcc164014c16404054cc0cccdd7982c803982c809099baf305900630590111533305733035303633303a70066608009a09a608a0606eacc164054dd5982c8050a99982b99baf3059016305900b1533305733047323232533305a3370e9000001099299982d00088268982e1826182e8009bac305c001104c305e0023059001375406002e2a6660ae66e25200433304a375660b201409a09a2930b0b0b0b0b0b0b0b182d801182b0009baa02d3056001305500130540013053001305200130523045304b305030510013050001305032533304c00116132533304d00113050002163050001332304b22533304e001104a1325333050300400113304c00130033053002130033053002305100132232323253330513370e90000010a5013371e6eb8c14c004014c154008c140004dd51918289829800982818290009bae304e0013758609c0282c60a000460960026ea8c8c130c138004c12c020c12c004c128004c124004c120004c11c004c11cc0e8c100c114c118004c114004c114cc88cc104894ccc110004584c94ccc118c8cdd79ba7304b005374e609600260900022609060920022600660920046092608e0020046eb0c10c028c10c050dd618211821803982198208030b1821801181f0009baa303e001303f303d001303e303c00132303d303d303d303d001303c001303b303b001303b303900e30390013038001303700130360013035001303500b163035002303000137546060606200a2c6064004605a0026ea8c0b4c0b8008c0b8008c0b400494ccc0940045200013330263375e604e60500026ea4070dd6981598141bab302b30280014800088ccc09800800400c5281119baf374c0046e980048cc0088c94ccc090c0140044894004488c00800ccc01494ccc090cdd78009ba8480004894004488c00800c0040048c00c8ccc008dd58009191118010019ba600112250015746446603c44a666042002201e26466600a6050604a00446604066ec0c094c09800c0040084004c008c094004004888ccc01088ccc01c0140080040080048c00c88dd3198019bab002375600246004446ea0cc00cdd68011bad001222333300400322002002001230183002001223232233001003002222533301d00113301a003002132323253330213375e00400226603a66ec0008cc024c098018c09800cccc02088008014c09001054ccc084cdc81bae002375c00226603a00c666601044002006604800800a26603a00666660104400200c00a604800860420046040008604000244a66603600420022666600644002603c004603e004002444a66603466e1c0052000100713300400333005002001223300437520046e9800488cc00cdd48011ba800122330123376000400200697adef6c60232323253330163370e900000109918030009bac3018001148000c068008c054004dd500098079129998090008a4000266e00dd6980c1802180a8009801180b000918079129998090008a50153330133375e602a00200629444c008c0580048c8cdd818098009809980a000980a9baa0014c11e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a002223333004002480008cccc014009200075a6eac00400c8c008dd480091111980691299980800088028a99980899baf301230130010061300430163013001130023014001001488100232323232005533300d3370e900000109919299980799b87371a002901c0991919299980919b89480000044c8c8c8c94ccc0594cc038cdc3800a4000266e1c005203813232325333019337126e340052040132323232323232323232324994ccc0880045261630250033301b23232323200553330253370e900000109919299981399b87371a002901c0991919191924ca6660540022930b18168019bad001302a001302a00316375c002604e0022c605200460480026ea8004dd6000981100098110019bad001301f001301f003375a002603800260380062c6eb8004c064004c06401058dc68009bae0013015001301500316375a002602400260240062c6eb8004c03c00458c044008c030004dd50009198048008010a512300522533300800110041330053003300b0013002300c0014bd702ba0232323253330073370e9002001098048008b180580118030009baa0012323002233002002001230022330020020015573eae6955ceaba15744460046ea800555cf01" // Crowd Fund +// const sValCborCrowdFundV4 = "5908c85908c50100003232323232323232323232323232323232323232323232323232323232323232323232323232323232322223232323232533302d3370e90010010991919299981819b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc0f8cdc3a4004004264646464646464646464646464a66609666e1d2000002161323232323232323232323253330563370e90010010a99982b19823982c01300b8a99982b29981a19b89375a60b00446eb4c16008454cc0d0cdc49bad3058010375a60b001e266e24dd6982c0079bad305800f153330565330343370e6660926eacc160054dd7182c0091bae30580114800854cc0d0cdc398191bab3058015375a60b001e2a660686606c6eacc160054c0dcccc0edc01998208260261bad305800f333041375c60b00246eb8c1600452002133036375660b002a606e666076e00ccc104130130dd6982c0079998209bae3058012375c60b002290010a99982b19b88375a60b00266eb4c16006452616161616153330565330343370e6660926eacc160054dd7182c0091bae30580114800854cc0d0cdc398191bab3058015375a60b001e2a660686606c6eacc160054c0dcccc0edc01998208260261bad305800f333041375c60b00246eb8c1600452002133036375660b002a606e666076e00ccc104130130dd6982c0079998209bae3058012375c60b002290010a99982b29981a19b87333049375660b00146eb8c16001cdd7182c0032400426606c66608209809860666eb0c160c164010c0dcccc0edc019982082602618199bac3058305900f33304104c04c30460301533305633036303733303b7006660820980986eb4c16003cccc104130130c1180c0ccc104130130dd6982c0020a99982b29981a19baf3058009305801415330343375e60b001060b00262a6606866ebcc160014c16004054cc0d0cdd7982c003982c009099baf305800630580111533305633036303733303b700666082098098608c0606eacc160054dd5982c0050a99982b19baf3058016305800b153330563304732323253330593370e9000001099182d9826000982d8008a611e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a00305d0023058001375406002e2a6660ac66e252004333049375660b00140980982930b0b0b0b0b0b0b0b182d001182a8009baa02d3055001305400130530013052001305100130513044304a304f3050001304f001304f32533304b00116132533304c0011304f00216304f001332304a22533304d0011049132533304f300400113304b00130033052002130033052002305000132232323253330503370e90000010a5013371e6eb8c148004014c150008c13c004dd51918281829000982798288009bae304d0013758609a028609e00460940026ea8c8c12cc134004c128020c128004c124004c120004c11c004c118004c118c0e4c0fcc110c114004c110004c110cc88cc100894ccc10c004584c94ccc114c8cdd79ba7304a005374e6094002608e0022608e60900022600660900046090608c0020046eb0c108028c108050dd618209821003982118200030b1821001181e8009baa303d001303e303c001303d303b00132303c303c303c303c001303b001303a303a001303a303800e30380013037001303600130350013034001303400b163034002302f0013754605e606000a2c606200460580026ea8c0b0c0b4008c0b4008c0b000494ccc0900045200013330253375e604c604e0026ea406cdd6981518139bab302a302700148000c084894ccc090004520001337006eb4c0a8c05cc09c004c008c0a000488ccc09000800400c5281119baf374c0046e980048cc0088c94ccc088c0140044894004488c00800ccc01494ccc088cdd78009ba8480004894004488c00800c0040048c00c8ccc008dd58009191118010019ba600112250015746446603844a66603e002201e26466600a604c604600446603c66ec0c08cc09000c0040084004c008c08c004004888ccc01088ccc01c0140080040080048c00c88dd3198019bab002375600246004446ea0cc00cdd68011bad001222333300400322002002001230163002001223232233001003002222533301b0011330180030021323232533301f3375e00400226603666ec0008cc024c090018c09000cccc02088008014c08801054ccc07ccdc81bae002375c00226603600c666601044002006604400800a26603600666660104400200c00a6044008603e004603c008603c00244a666032004200226666006440026038004603a004002444a66603066e1c0052000100713300400333005002001223300437520046e9800488cc00cdd48011ba800122330103376000400200697adef6c60232323253330143370e90010010a40002646eb4c068c01c004c058004c060008c04c004dd5000918071129998088008a50153330123375e602800200629444c008c0540048c8cdd8180900098091809800980a1baa0012223333004002480008cccc014009200075a6eac00400c8c008dd480091111980691299980800088028a99980899baf301230130010061300430163013001130023014001001488100232323232005533300d3370e900000109919299980799b87371a002901c0991919299980919b89480000044c8c8c8c94ccc0594cc038cdc3800a4000266e1c005203813232325333019337126e340052040132323232323232323232324994ccc0880045261630250033301b23232323200553330253370e900000109919299981399b87371a002901c0991919191924ca6660540022930b18168019bad001302a001302a00316375c002604e0022c605200460480026ea8004dd6000981100098110019bad001301f001301f003375a002603800260380062c6eb8004c064004c06401058dc68009bae0013015001301500316375a002602400260240062c6eb8004c03c00458c044008c030004dd50009198048008010a512300522533300800110041330053003300b0013002300c0014bd702ba0232323253330073370e9002001098048008b180580118030009baa0012323002233002002001230022330020020015573eae6955ceaba15744460046ea800555cf01" // Crowd Fund +// const sValCborCrowdFundV2 = "5908c45908c101000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232533302c3370e90010010991919299981799b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc0f4cdc3a4004004264646464646464646464646464a66609466e1d2000002161323232323232323232323253330553370e90000010a99982aa9981c99b87333035375660ae02a6eb8c15c048dd7182b808a40042a6607266e1cc0e0dd5982b80a9bad305700f15330393303b375660ae02a6078666080e00ccc11c118118dd6982b8079998239bae3057012375c60ae022900109981d9bab3057015303c33304070066608e08c08c6eb4c15c03cccc11cdd7182b8091bae30570114800854ccc1554cc0e4cdc399981a9bab305700a375c60ae00e6eb8c15c019200213303b3330470460463031375860ae60b00086078666080e00ccc11c118118c0c4dd6182b982c00799982382302318190178a99982a9981d981e199820380333047046046375a60ae01e66608e08c08c606405e66608e08c08c6eb4c15c01054ccc1554cc0e4cdd7982b804982b80a0a9981c99baf3057008305701315330393375e60ae00a60ae0202a6607266ebcc15c01cc15c0484cdd7982b803182b8088a99982a9981d981e199820380333047046046303202f375660ae02a6eacc15c02854ccc154cdd7982b80b182b8058a99982a9981a191919299982c19b87480000084c8c168c0dc004c16800453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a00305c0023057001375405e02e2a6660aa66e252004333035375660ae01408c08c2930b0b0b0b0b0b0b0b0a99982a9981a182b81300b8a99982aa9981c99b89375a60ae0446eb4c15c08454cc0e4cdc49bad3057010375a60ae01e266e24dd6982b8079bad305700f153330555330393370e66606a6eacc15c054dd7182b8091bae30570114800854cc0e4cdc3981c1bab3057015375a60ae01e2a66072660766eacc15c054c0f0ccc101c01998238230231bad305700f333047375c60ae0246eb8c15c045200213303b375660ae02a6078666080e00ccc11c118118dd6982b8079998239bae3057012375c60ae02290010a99982a99b88375a60ae0266eb4c15c0645261616161630590023054001375405860a800260a600260a400260a200260a000260a060866092609c609e002609c002609c64a6660940022c264a6660960022609c0042c609c002664609244a6660980022090264a66609c6008002266094002600660a20042600660a2004609e002644646464a66609e66e1d200000214a0266e3cdd71828800802982980118270009baa32304f3051001304e3050001375c60980026eb0c130050c138008c124004dd519182518260009824804182480098240009823800982300098228009822981c181f182198220009821800982199911981f9129998210008b09929998221919baf374e609200a6e9cc124004c1180044c118c11c0044c00cc11c008c11cc114004008dd61820805182080a1bac304030410073041303f006163041002303c00137546078002607a6076002607860740026460766076607660760026074002607260720026072606e01a606e002606c002606a0026068002606600260660142c6066004605c0026ea8c0b8c0bc01058c0c0008c0ac004dd518159816000981600098111129998128008a4000266e00dd6981598021814000980118148009191919299981399b874800800852000132375a605a600c00260520026056004604c0026ea80048c8cdd818130009813181380098141baa0012302022533302300114a02a66604866ebcc09800400c5288980118138009111999802001240004666600a00490003ad3756002006460046ea40048888cc080894ccc08c004401454ccc090cdd79812981300080309802181498130008980118138008009299980e8008a4000266603c66ebcc07cc080004dd48079bad3023302037566046604000290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc058894ccc06400440404c8ccc014c080c0740088cc060cdd8180e980f00180080108009801180e8008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a002444666600800644004004002460206004002446464466002006004444a66602a0022660240060042646464a66603266ebc0080044cc054cdd800119804980f003180f00199980411001002980e0020a99980c99b90375c0046eb80044cc054018cccc0208800400cc0700100144cc05400ccccc02088004018014c070010c064008c060010c060004894ccc04c00840044cccc00c88004c058008c05c00800522010022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980499bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6601c66e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660440022930b18128019980d919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302a001149858c0b400cdd6800981500098150018b1bae0013027001163029002302400137540026eb0004c088004c08800cdd6800980f800980f8019bad001301c001301c00316375c002603200260320082c6e34004dd7000980a800980a8018b1bad0013012001301200316375c002601e0022c602200460180026ea80048cc0240040085289180291299980400088020998029801980580098011806000a5eb815d01191919299980399b87480100084c02400458c02c008c018004dd5000919180111980100100091801119801001000aab9f5734aae755d0aba2230023754002aae781" // Crowd Fund +// const sValCborCrowdFundV1 = "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + + +// console.log("Logging deserialization of UPLC"); +// console.log(helios.deserializeUplc(`{"type": "PlutusScriptV1", "cborHex": "${cborHex}"}`)) + +let contributorSeed = ''; + + +const crowdfund: NextPage = () => { + const walletStore = useStoreState((state: any) => state.wallet) + const [nftList, setNftList] = useState([]) + const [lucid, setLucid] = useState() + const [script, setScript] = useState() + const [scriptAddress, setScriptAddress] = useState("") + const [ariadyTxHash, setAriadyTxHash] = useState("") + const [efrainTxHash, setEfrainTxHash] = useState("") + const [inputValue, setInputValue] = useState(''); + const [inputPrivateKey, setInputValuePrivateKey] = useState(''); + const [privAddress,setPrivAddress] = useState(''); + const [txHash,settxHash] = useState(''); + const [firstLine, setFirstLine] = useState(''); + const [readSecretData, setReadSecretData] = useState(null); + + useEffect(() => { + if (lucid) { + ; + } else { + initLucid(walletStore.name).then((Lucid: Lucid) => { setLucid(Lucid) }) + } + }, [lucid]) + + // data ToyRedeemer = ToyRedeemer{key :: Integer} + + + // https://github.com/spacebudz/lucid/blob/main/src/examples/typed_data.ts + + // ghci> PlutusTx.toData datumCrowdVal4aRedeemIn + // Constr 0 [B "\SO\151\170\ETX<\238\231b\194R\133\205\204\148(qx\240\ESCE\165\133\253\rM\168\&8z", -- Beneficiary + // I 1671159023000, -- Deadline + // B "\183\EOTq\130\160\ETXT\248\196\205{\SOH\194\250\171#\SO\SOH\210\243:m\207\208\199\129\247\236", -- Currency Symbol + // B "MyCrowdFund", + // I 50000000, + // I 52000000, + // List [Constr 0 [B "\140W>\129\143\&5\168\250\138i93\195\150V\ESC\ACK\"\168\139\191\&4\149,MW,\215",I 50000000]]] + // data PDat (s :: S) = + // PDat + // ( Term + // s + // ( PDataRecord + // '["beneficiary" ':= (PPubKeyHash) + // -- '["beneficiary" ':= (PAsData PPubKeyHash) + // , "deadline" ':= PPOSIXTime + // , "aCurrency" ':= PCurrencySymbol + // , "aToken" ':= PTokenName + // , "targetAmount" ':= PInteger + // , "actualtargetAmountsoFar" ':= PInteger + // , "contributorsMap" ':= PBuiltinList (PAsData (PTuple (PPubKeyHash) (PInteger) )) ] )) + +// Type definition could be auto generated from on-chain script + const MyDatumSchema = + // Data.Enum([ + Data.Object({ pDat: + Data.Object({ + beneficiary: Data.Bytes(), + deadline: Data.Integer(), + aCurrency: Data.Bytes(), + aToken: Data.Bytes(), + targetAmount: Data.Integer(), + actualtargetAmountsoFar: Data.Integer(), + // comment contributor map as reading Datum was an issue. + contributorsMap: Data.Array(Data.Tuple([Data.Bytes(),Data.Integer()])) + + // contributorsMap: Data.Map(Data.Bytes(), Data.Integer()), // Data.Array(Data.Tuple) + // colors: Data.Array(Data.Bytes()), + // description: Data.Nullable(Data.Bytes()), + }) + }); + // ]); + type MyDatum = Data.Static; + // type MyDatumSchema = Data.Static; + const MyDatum = MyDatumSchema as unknown as MyDatum; + + +// Type definition could be auto generated from on-chain script +const MyDatumSchemaTrue = +// Data.Enum([ + Data.Object({ pDat: + Data.Object({ + // beneficiary: Data.Bytes(), + // deadline: Data.Integer(), + // aCurrency: Data.Bytes(), + // aToken: Data.Bytes(), + targetAmount: Data.Integer(), + actualtargetAmountsoFar: Data.Integer() + // comment contributor map as reading Datum was an issue. + // contributorsMap: Data.Array(Data.Tuple([Data.Bytes(),Data.Integer()])) + + // contributorsMap: Data.Map(Data.Bytes(), Data.Integer()), // Data.Array(Data.Tuple) + // colors: Data.Array(Data.Bytes()), + // description: Data.Nullable(Data.Bytes()), + }) + }); +// ]); +type MyDatumTrue = Data.Static; +const MyDatumTrue = MyDatumSchemaTrue as unknown as MyDatumTrue; + + +// test w/o PDat + const MyDatumSchema2 = + Data.Object({ + beneficiary: Data.Bytes(), + deadline: Data.Integer(), + aCurrency: Data.Bytes(), + aToken: Data.Bytes(), + targetAmount: Data.Integer(), + actualtargetAmountsoFar: Data.Integer() + // comment contributor map as reading Datum was an issue. + // contributorsMap: Data.Array(Data.Tuple([Data.Bytes(),Data.Integer()])) + }); + // type MyDatumSchema2 = Data.Static; + type MyDatumSchema2 = Data.Static; + // const MyDatum2 = MyDatumSchema2 as unknown as MyDatum2; + + +// FOR REDEEM - https://github.com/spacebudz/lucid/blob/main/tests/data.test.ts +// Deno.test("Complex data structure", () => { (section) + +// Deno.test("Roundtrip data enum with named args", () => { +// /* +// - TypeScript: + +// type MyDatum = "Left" | "Down" | { Right: [string]; } | { Up: { x: bigint; y: bigint;}; } + + const MyRedeemerSchema = Data.Enum([ + Data.Object({ PContribute: + Data.Object({ + contribution: Data.Array(Data.Tuple([Data.Bytes(), Data.Integer()]))}) }), + Data.Literal("PClose"), + ]); + type MyRedeemer = Data.Static; + // type MyRedeemer = Data.Static; + const MyRedeemer = MyRedeemerSchema as unknown as MyRedeemer; + + const MyRedeemerSchema2 = Data.Enum([ + Data.Object({ PContribute: + Data.Tuple([Data.Bytes(), Data.Integer()])}) , + Data.Literal("PClose"), + ]); + type MyRedeemer2 = Data.Static; + const MyRedeemer2 = MyRedeemerSchema2 as unknown as MyRedeemer2; + + + // type MyDatumSchema = Data.Static; + // const MyRedeemer = MyRedeemerSchema as unknown as MyRedeemer; + + // const MyRedeemerContributeSchema = { + // tag: 'contribution', Data.Tuple([ Data.Bytes(), Data.Integer()]) + // }; + // type MyRedeemerContribute = Data.Static; + // const MyRedeemerContribute = MyRedeemerContributeSchema as unknown as MyRedeemerContribute; + + + + const PasswordDatum = Data.Object({ + password: Data.Integer() + }) + type PasswordDatum = Data.Static + + + // for temp True test + const currency1 : PolicyId = "8e248fde424b4489dd742c1b50e94dd1de9e56874b70b126df0bc709" + // const currency1 : PolicyId = "ae65a11b2b4d39be63c400b7eb278157bb01bbea64be7342328bee0a" + // const currency1 : PolicyId = "44b826af0769dc0515e57c4a9cac786d2743fdd8090e82db29e5ef8c" + // const currency1 : PolicyId = "f2ea1b3d82ed1d85cd58801906280875dae9b3c1a698e2491b2f45f1" + // const currency1 : PolicyId = "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef" + // const currency1 : PolicyId = "e97a6e62f886202497e944243e362dda229218c160fa55c0454b09c0" + // const currency1 : PolicyId = "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef"; + const tokenName = fromText("MyCrowdFund"); + const fullPolicy : Unit = currency1 + tokenName; + + // Contribution for Contribute run + const contributionAmount = 12000000n; + const minAda = 2000000; + const minAdaBigInt = 2000000n; + + const sDeposit = async () => { + if (lucid) { + // const sValCbor = "589b5899010000222323232325333573466e1d200200215333573466ebcd5d0991aab9e375400200e6ae84c8d55cf1baa00100614985854cd5ce2481445061747465726e206d61746368206661696c75726520696e2027646f2720626c6f636b206174207372632f536d616c6c56616c696461746f722e68733a35333a352d3432001635573c0046aae74004dd51aba135744002646aae78dd50008009" + // const sValCborSmallValidator = "582858260100003232322225333573466ebcc010c014008c010c01400c526165742460046ea800555cf1" // small validator + const sValCbor = sValCborCrowdFund; + // "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + const sValidator : SpendingValidator = { + type: "PlutusV2", + script: sValCbor + } + // https://github.com/spacebudz/lucid/blob/main/src/examples/typed_data.ts + // to print at terminal too + // const fs = require('fs'); + // const path = require('path'); + // const logFile = path.join(process.cwd(), 'npm_run_dev.log'); + // const writeLog = (message) => { + // fs.writeFileSync(logFile, message + '\n', { encoding: 'utf-8' }); + // }; + // writeLog('This message was printed to the npm run dev window.'); + + const datum = Data.to({password: BigInt(24)}, PasswordDatum) + + + const sValAddress = lucid.utils.validatorToAddress(sValidator) + + + const { paymentCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + console.log("Payment pub key hash = ", paymentCredential?.hash!) + // const datum = Data.to({password: BigInt(24)}, PasswordDatum) + // const datum : MyDatum = + // { PDat: + // { + // // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + // beneficiary: paymentCredential?.hash!, // pubkey hash + // deadline: (lucid.utils.unixTimeToSlot(Date.now() + 1000000)), + // // lucid.utils.unixTimeToSlot(Date.now() + 1000000), need to test this out. + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + // // aToken: fromText("CrowdFundingToken"), + // aToken: fromText("MyCrowdFund"), + // targetAmount: 5000000n, // 5 Ada + // actualtargetAmountsoFar: 5555n, + // contributorsMap: [[fromText(paymentCredential?.hash!), 555n]] + // } + // } + // Initial first deposit + const deadlineCalc = (lucid.utils.unixTimeToSlot(Date.now() + 1000000)) + + // const currency1 : PolicyId = "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de" + // const currency1 : PolicyId = "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef" + console.log("deadline = ", deadlineCalc) + + +// for now for testing including contributions map filled in. + const datumInit : MyDatum = + { pDat: + { + // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + beneficiary: paymentCredential?.hash!, // pubkey hash + deadline: BigInt(deadlineCalc), + // deadline: 35693597n, + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + aCurrency: currency1, + // aCurrency: "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de", + aToken: tokenName, // fromText("MyCrowdFund"), + // aToken: "MyCrowdFund", + targetAmount: 30000000n, // 30 Ada Target + actualtargetAmountsoFar: 2000000n, // Min 2 Ada when we first deposit + // commenting temporarily + // contributorsMap: [[paymentCredential?.hash!, 20000000n], [paymentCredential?.hash!, 35000000n]] + contributorsMap: [] // Initial map is blank + // contributorsMap: [[paymentCredential?.hash!,2000000n]] + + } + }; + + const datumInit1 : MyDatum = + { pDat: + { + // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + beneficiary: paymentCredential?.hash!, // pubkey hash + deadline: BigInt(deadlineCalc), + // deadline: 35693597n, + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + aCurrency: currency1, + // aCurrency: "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de", + aToken: tokenName, // fromText("MyCrowdFund"), + // aToken: "MyCrowdFund", + targetAmount: 30000000n, // 30 Ada Target + actualtargetAmountsoFar: 4000000n, // Min 2 Ada when we first deposit + 2 from intial contributor + // commenting temporarily + // contributorsMap: [[paymentCredential?.hash!, 20000000n], [paymentCredential?.hash!, 35000000n]] + contributorsMap: [[paymentCredential?.hash!, 2000000n]] // Initial1 2 ada from contributor + 2 ada lovelace min Ada + // contributorsMap: [[paymentCredential?.hash!,2000000n]] + + } + }; + + + const datumInit1True : MyDatumTrue = + { pDat: + { + targetAmount: 30000000n, + actualtargetAmountsoFar: 4000000n, // Min 2 Ada when we first deposit + 2 from intial contributor + } + }; + + + + // {"constructor":0, + // "fields": + // [{"bytes":"dbbab47cf610921db8e266c3747cd393db6f9d4b7eb8e348ddeb3971"}, + // {"int":1676641405000}, + // {"bytes":"404c7e7ab0e42a8b1a247c2eba252698cad8a19c50c0cf5cfb1c2283"}, + // {"bytes":"4d7943726f776446756e64"}, + // {"int":300000000}, + // {"int":152000000}, + // {"list":[{"constructor":0,"fields":[{"bytes":"0d29d2f72ba11f3381783dda5501139f397d81e83244fce13e7a711a"},{"int":150000000}]}]}]} + + + + // const datumInit2 : MyDatumSchema2 = + // { + // // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + // beneficiary: paymentCredential?.hash!, // pubkey hash + // deadline: BigInt(deadlineCalc), + // // deadline: 35693597n, + // // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + // aCurrency: currency1, + // // aCurrency: "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de", + // aToken: fromText("MyCrowdFund"), + // // aToken: "MyCrowdFund", + // targetAmount: 30000000n, // 30 Ada Target + // actualtargetAmountsoFar: 2000000n, // Min 2 Ada when we first deposit + // // contributorsMap: [[paymentCredential?.hash!, 20000000n], [paymentCredential?.hash!, 35000000n]] + // }; + // console.log("Datum = ", datumInit) + console.log("currency1 = ", currency1) + console.log("datumInit = ", datumInit) + + + + const datumData = Data.to(datumInit1, MyDatum) + // const datumData = Data.to(datumInit, MyDatum) + // const datumData = Data.to( datumInit, MyDatumSchema) + console.log("Datum as Data = ", datumData) + + console.log("PayToScript Address: ", sValAddress ) + + const utxos = await lucid.wallet.getUtxos() + const tx = await lucid.newTx() + // .payToContract(sValAddress, {inline: Data.to( datumInit1, MyDatum)}, {lovelace: BigInt(4000000), [currency1 + fromText("MyCrowdFund")]: 1n }) + .payToContract(sValAddress, {inline: Data.to( datumInit1True, MyDatumTrue)}, {lovelace: BigInt(4000000), [currency1 + fromText("MyCrowdFund")]: 1n }) + // .payToContract(sValAddress, {inline: Data.to( datumInit2, MyDatumSchema2)}, {lovelace: BigInt(2000000), [currency1 + fromText("CrowdFundingToken")]: 1n }) + // .payToAddress("addr_test...", { [policyId + fromText(assetName)]: 10n }) + .complete(); + + console.log("Went into sDeposit module:After payto ") + const signedTx = await tx.sign().complete(); + const txHash = await signedTx.submit(); + console.log("Lock Test TxHash: " + txHash) + settxHash(txHash); + return txHash; + + } + + } // End sdeposit + + +// spend + + const sSpend = async () => { + if (lucid) { + //const sValCbor = "582858260100003232322225333573466ebcc010c014008c010c01400c526165742460046ea800555cf1" + const sValCbor = "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + const sValidator : SpendingValidator = + {type:"PlutusV2", script: sValCbor} + + const sValAddress = lucid.utils.validatorToAddress(sValidator) + const valUtxos = await lucid.utxosAt(sValAddress) + const redeemer = Data.to( + new Constr(0, [BigInt(24)]) + ) + + let found = undefined + + for ( let i=0; i = Data.from(curr.datum!) + + if (pDatum.fields[0] === BigInt(24)) { + found = curr + } + } + + if (!found) throw new Error("Naughty Datum") + + const utxos = await lucid.wallet.getUtxos(); + + const tx = await lucid + .newTx() + .attachSpendingValidator(sValidator) + .collectFrom([found], redeemer) + .complete(); + + const signedTx = await tx.sign().complete(); + const txHash = await signedTx.submit(); + console.log("Collect Test TxHash: " + txHash) + return txHash; + } + } + + + + + const sContributeCrowdFund = async () => { + if (lucid) { + // const sValCbor = "582858260100003232322225333573466ebcc010c014008c010c01400c526165742460046ea800555cf1" + // const sValCbor = "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + const sValidator : SpendingValidator = + {type:"PlutusV2", script: sValCborCrowdFund} + const sValAddress = lucid.utils.validatorToAddress(sValidator) + const valUtxos = await lucid.utxosAt(sValAddress) + + // Policy id will be set in global variable as its main one for all deposit and also Contribute and in the end to Close it. + // const currency1 = "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de"; + // const currency1 = "45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"; + // const currency1 = "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef"; + + + let UniqueNftUTXOFound = 0; + + // use Contributor wallet to contribute + // const contributor1Seed = await fetchSeed(); + // // const seed = "....." + // lucid.selectWalletFromSeed(contributor1Seed); + + const { paymentCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + console.log("payment Credential = ", paymentCredential) + // const MyRedeemerSchema = Data.Enum([ + // Data.Object({ PContribute: + // Data.Object(Data.Tuple([Data.Bytes(), Data.Integer()]) ) }), + // Data.Literal("PClose"), + // ]); + + const myRedeemContr : MyRedeemer = + { + PContribute: + { contribution: [[paymentCredential?.hash!, contributionAmount]] } // Ada contribution + + }; + const redeemerContr = Data.to(myRedeemContr, MyRedeemer) + const myRedeemClose : MyRedeemer = "PClose"; + const redeemer = Data.to(myRedeemClose, MyRedeemer); // temp - test with Close + console.log("redeemerClose = ", redeemer) + + // const myRedeemContr2 : MyRedeemer2 = { + // PContribute: [paymentCredential?.hash!MyRedeemer2, contributionAmount] // Ada contribution + // }; + // const redeemer2 = Data.to(myRedeemContr2, MyRedeemer2) + + // haskell/plutus + const red1 = {"constructor":0,"fields":[{"constructor":0,"fields":[{"bytes":paymentCredential?.hash!},{"int":12000000}]}]} + // Lucid + const red2tmp = new Constr(0, [new Constr(0, ([paymentCredential?.hash!], [BigInt(12000000n)] ) )]) + const red2 = Data.to(new Constr(0, [new Constr(0, ([paymentCredential?.hash!], [BigInt(12000000n)] ) )])) + console.log("red2 = ", red2) + const red3 = Data.to(new Constr(1, [])) +// we need to first use Policy ID which is the key to find the UTXO +// 1) we need to make sure UTXO value and datum also have this Policy ID +// 2) we then construct the new Datum - we only need to change values on 2 fields +// + +// this is what is already at the script + + let found = undefined + + for ( let i=0; i(curr.datum!, MyDatumSchema); + const utxoInDatumAny = Data.from(curr.datum!, MyDatum) + + if (utxoInDatumAny.pDat.aCurrency === currency1 && utxoInDatumAny.pDat.aToken === fromText("MyCrowdFund")) { + // Only if we found our UTXO with Unique NFT we continue with next steps. + UniqueNftUTXOFound = 1; + console.log(" *******************************Successful compare") + const beneficiaryUTXO = utxoInDatumAny.pDat.beneficiary; + const deadlineUTXO = utxoInDatumAny.pDat.deadline; + const aCurrencyUTXO = utxoInDatumAny.pDat.aCurrency; + const aTokenUTXO = utxoInDatumAny.pDat.aToken; + const targetAmountUTXO = utxoInDatumAny.pDat.targetAmount; + const actualtargetAmountsoFarUTXO = utxoInDatumAny.pDat.actualtargetAmountsoFar; + const contributorsMapUTXO = utxoInDatumAny.pDat.contributorsMap; + console.log("datum = ", curr.datum) + console.log("utxoInDatumAny beneficiary = ", utxoInDatumAny.pDat.beneficiary) + console.log("utxoInDatumAny Deadline = ", utxoInDatumAny.pDat.deadline) + console.log("utxoInDatumAny Currency = ", utxoInDatumAny.pDat.aCurrency) + console.log("utxoInDatumAny Token = ", utxoInDatumAny.pDat.aToken) + console.log("utxoInDatumAny Target amount = ", utxoInDatumAny.pDat.targetAmount) + console.log("utxoInDatumAny target so far = ", utxoInDatumAny.pDat.actualtargetAmountsoFar) + console.log("utxoInDatumAny Contributors map = ", contributorsMapUTXO) + const contrMap = contributorsMapUTXO; + console.log("type of contrMap is Array? = ", Array.isArray(contrMap)); + console.log("length of contrMap = ", contrMap.length) + + let contrCount = 1; + let contrMapContr: bigint = 0n; + let updatedContrMap: utxoInDatumAny.pDat.contributorsMap = []; + + // if (contrMap.length >= 1) { + // if ( (contrMap.length === 1) && (contrMap[0].length >= 1) ) { + // // means inside the main array there is a tuple + for ( let i=0; i { + // // console.log("count = ", contrCount, " item = ", item); + // // console.log("item 0 PubKeyHash = ", item[0]); + // // console.log("item 1 Contribution made = ", item[1]); + // // console.log("type of contrAmt = ", typeof item[1]); + // contrMapContr = contrMapContr + item[1][1]; + // contrCount = contrCount + 1; + // }); + // } + // catch (error) { + // // Handle the error here -- we will just skip for now + // console.log('An error occurred trying to read Contributors map: will skip ', error); + // } + console.log(" Total contribution in datum contr map = ", contrMapContr) + const contributionMapTotalUTXO = contrMapContr; + + // Add new contribution and also create new map + // contributionAmount --- set globally for this run + console.log(" Contribution on this run = ", contributionAmount) + const newElement = [paymentCredential?.hash!, contributionAmount]; // later need to replace with actual contribution amount + // Create a new array by spreading the existing contrMap and adding the newElement + // const updatedContrMap = [...contrMap, newElement]; + console.log("length of Contr Map = ", contrMap.length); + + console.log("Updated Contributors map before adding NewElement = ", updatedContrMap); + + updatedContrMap = [...updatedContrMap, newElement] + + // if (contrMap.length >= 1) { + // updatedContrMap = contrMap; + // updatedContrMap[contrMap.length] = newElement; + // } + console.log("Updated Contributors map = ", updatedContrMap); + + + let updContrCount = 1; + let updContrMapContr: bigint = 0n; + + // if (updatedContrMap.length >= 1) { + // if ( ( updatedContrMap.length === 1 ) && (updatedContrMap[0].length >= 1) ) { + for ( let i=0; i(curr.datum!, PasswordDatum) + + // const utxos = await lucid.wallet.getUtxos(); + + + + } // End - For loop for UTXOs + } // End - if lucid + } // End - Function sContributeCrowdFund + + + let iterationNumberAsset = 0; + // Recursive function to traverse the object and its nested properties + function traverseAsset(obj: any, policyId: string) { + + for (const key in obj) { + iterationNumberAsset++; + // console.log("T - iter# = ", iterationNumber) + + if (typeof obj[key] === 'object') { + traverseAsset(obj[key], policyId); + } else { + if (key === policyId) { + console.log("policy found value = ", key, obj[key]) + return obj[key] + } else if (key === "lovelace") { + console.log("lovelace = ", key, obj[key]) + } + if (key != fullPolicy && key != "lovelace") { + // this is error because we found some other Asset other than our Unique NFT and lovelace + throw new Error("we found some other Asset other than our Unique NFT and lovelace") + } + + } + } + } + + + const sSpendAndDeposit = async () => { + if (lucid) { + // const sValCbor = "582858260100003232322225333573466ebcc010c014008c010c01400c526165742460046ea800555cf1" + // const sValCbor = "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + const sValidator : SpendingValidator = + {type:"PlutusV2", script: sValCborCrowdFund} + const sValAddress = lucid.utils.validatorToAddress(sValidator) + const valUtxos = await lucid.utxosAt(sValAddress) + + // const currency1 = "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de"; + // const currency1 = "45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"; + // const currency1 = "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef"; + + // use Contributor wallet to contribute + const contributor1Seed = await fetchSeed(); + // const seed = "....." + lucid.selectWalletFromSeed(contributor1Seed); + + const { paymentCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + + +// we need to first use Policy ID which is the key to find the UTXO +// 1) we need to make sure UTXO value and datum also have this Policy ID +// 2) we then construct the new Datum - we only need to change values on 2 fields +// + +// this is what is already at the script + const datumInit : MyDatumSchema = + { pDat: + { + // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + beneficiary: paymentCredential?.hash!, // should be pubkey hash from NAMI + deadline: 35859429n, + // deadline: 35693597n, + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + aCurrency: currency1, + // aCurrency: "6fcf234bee205dc56ad308ea5882eb59045136056de323daf221f9de", + // aToken: fromText("CrowdFundingToken"), + aToken: "MyCrowdFund", + targetAmount: 30000000n, // 30 Ada Target + actualtargetAmountsoFar: 2000000n, // Min 2 Ada when we first deposit + // commented temporarily + contributorsMap: [] // Initial map is blank + // contributorsMap: [[paymentCredential?.hash!,2000000n]] + } + }; + const datum1 : MyDatumSchema = + { pDat: + { + // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + beneficiary: paymentCredential?.hash!, // pubkey hash + deadline: 35859429n, // BigInt(deadlineCalc), + // deadline: 5555n, + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + aCurrency: currency1, + // aToken: fromText("CrowdFundingToken"), + aToken: fromText("MyCrowdFund"), + targetAmount: 30000000n, // 30 Ada Target + actualtargetAmountsoFar: 2000000n, // Min 2 Ada when we first deposit + contributorsMap: [] // Initial map is blank + } + } + // Datum we want to deposit + const datum2 : MyDatumSchema = + { pDat: + { + // beneficiary: fromText("0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a"), // pubkey hash + beneficiary: fromText("e9efb9bb50fc3531da4955a7f4d06b22951cbcb373368f978640c3f4"), // pubkey hash + deadline: BigInt(35231522), // what's already on the UTXO - needs to be same. + // deadline: 5555n, + // aCurrency: fromText("45cd7f7a6cd2ada53dbbc4ca4b1342392c99f3276cb8f19574c11a99"), + // aCurrency: fromText("e0d3120855499e55ef6994a68b2180d265724d62341e55be11826bc4"), + aCurrency: currency1, + // aToken: fromText("CrowdFundingToken"), + aToken: fromText("MyCrowdFund"), + targetAmount: 30000000n, // 30 Ada Target + actualtargetAmountsoFar: 22000000n, // Min 2 Ada when we first deposit + this contribution 20 Ada + contributorsMap: [[paymentCredential?.hash!, 20000000n]] + // contributorsMap: new Map([]) // Initial map is blank + } + }; + let found = undefined + + for ( let i=0; i; + const MyDatumTest = MyDatumSchemaTest as unknown as MyDatumTest; + + const datum: MyDatumTest = "31313131"; //hex + const datumTo = Data.to(datum, MyDatumTest); + const newDatum = Data.from( + Data.to(datum, MyDatumTest), + MyDatumTest, + ); + + console.log("---------------------------- datum = ", datum); + console.log("---------------------------- typeof datum = ", (typeof datum)); + console.log("----------------------------New datum = ", newDatum); + console.log("----------------------------Type of New datum = ", (typeof newDatum)); + console.log("----------------------------DatumTo = ", datumTo); + console.log("----------------------------type of DatumTo = ", (typeof datumTo)); + + // const cborDatum = datumJsonToCbor(curr.datum!); + + console.log("---------------------------- Typeof Curr.datum = ", (typeof curr.datum!)); + if (curr.txHash === "bd8cdefdf99cce340b562be158615224f9986762ce07ddb46875dd791baf74df") { + // console.log("---------------------------- Data.from(curr.datum!, MyDatumSchema2) = ", Data.toJson(curr.datum!)); + // console.log("---------------------------- Data.from(curr.datum!, MyDatumSchema2) = ", Data.toJson(datum2)); + } + // console.log("---------------------------- Data.from(curr.datum!, MyDatumSchema2) = ", Data.from(curr.datum!)); + + // console.log("curr.datum! data.to = ") + + // const utxoInDatumAny = Data.from(curr.datum!, MyDatumSchema2) + // const pDatum = Data.from({ + // beneficiary: curr.datum!.beneficiary, + // deadline: curr.datum!.deadline, + // aCurrency: curr.datum!.aCurrency, + // aToken: curr.datum!.aToken, + // targetAmount: curr.datum!.targetAmount, + // actualtargetAmountsoFar: curr.datum!.actualtargetAmountsoFar, + // }); + + + try { + console.log(" About to convert datum to our schema type") + const utxoInDatumAny = Data.from(curr.datum!, MyDatumSchema); + + // const newDatum = Data.from( + // Data.to(datum, MyDatumSchema2), + // MyDatumSchema2, + // ); + + // Continue with your code using utxoInDatumAny + if (utxoInDatumAny.pDat.aCurrency === "2e7b94d9808e80348737b7d204a755f20b842541c5d2a7ef31a419ef") { + console.log(" Successful compare") + } + console.log("utxoInDatumAny beneficiary = ", utxoInDatumAny.pDat.beneficiary) + console.log("utxoInDatumAny Deadline = ", utxoInDatumAny.pDat.deadline) + console.log("utxoInDatumAny Currency = ", utxoInDatumAny.pDat.aCurrency) + console.log("utxoInDatumAny Token = ", utxoInDatumAny.pDat.aToken) + console.log("utxoInDatumAny Target amount = ", utxoInDatumAny.pDat.targetAmount) + console.log("utxoInDatumAny target so far = ", utxoInDatumAny.pDat.actualtargetAmountsoFar) + console.log("utxoInDatumAny Contributors map = ", utxoInDatumAny.pDat.contributorsMap) + const contrMap = utxoInDatumAny.pDat.contributorsMap + let contrCount = 1; + let contrMapContr: bigint = 0n; + contrMap.forEach(item => { + console.log("count = ", contrCount, " item = ", item); + console.log("item 0 PubKeyHash = ", item[0]); + console.log("item 1 Contribution made = ", item[1]); + console.log("type of contrAmt = ", typeof item[1]); + contrMapContr = contrMapContr + item[1]; + contrCount = contrCount + 1; + }); + console.log(" Total contribution in datum contr map = ", contrMapContr) + + // Test adding a new element to contributors map + const newElement = [paymentCredential?.hash!, 12000000n]; + // Create a new array by spreading the existing contrMap and adding the newElement + const updatedContrMap = [...contrMap, newElement]; + console.log("Updated Contributors map = ", updatedContrMap); + let updContrCount = 1; + let updContrMapContr: bigint = 0n; + + updatedContrMap.forEach(item => { + console.log("count = ", contrCount, " item = ", item); + console.log("item 0 PubKeyHash = ", item[0]); + console.log("item 1 Contribution made = ", item[1]); + console.log("type of contrAmt = ", typeof item[1]); + updContrMapContr = updContrMapContr + item[1]; + updContrCount = updContrCount + 1; + }); + console.log(" Updated Total contribution in datum contr map = ", updContrMapContr) + + + + // contributorsMap: Data.Array(Data.Tuple([Data.Bytes(),Data.Integer()])) + console.log("datum = ", await lucid.datumOf(curr)) + } catch (error) { + // Handle the error here -- we will just skip + console.log('An error occurred: will skip ', error); + } + + + // const pDatum = Data.from(curr.datum!, PasswordDatum) + + const utxos = await lucid.wallet.getUtxos(); + + // const tx = await lucid + // .newTx() + // .attachSpendingValidator(sValidator) + // .collectFrom([found], redeemer) + // .payToContract(sValAddress, {inline: datum}, {lovelace: BigInt(1000000)}) + // .complete(); + + // const signedTx = await tx.sign().complete(); + // const txHash = await signedTx.submit(); + // console.log("Collect Test TxHash: " + txHash) + // return txHash; + + } + } + } + let iterationNumber = 0; + let contribIterNo = 0; + + + + + + + // Recursive function to traverse the object and its nested properties + function traverseDatum(obj: any, policyId: string) { + + for (const key in obj) { + iterationNumber++; + // console.log("T - iter# = ", iterationNumber) + + if (typeof obj[key] === 'object') { + contribIterNo = 0; // when you hit object we can reset contrib Iter + // Recurse into nested objects and arrays + if (iterationNumber == 1) { + // console.log(" T - If stmt iter # = ", iterationNumber); + traverseDatum(obj[key], policyId); + } else { + // console.log(" T - else stmt iter # = ", iterationNumber); + traverseDatum(obj[key], policyId); + } + } else { + // console.log(" type of key = ", typeof key) + // Print or process the leaf values + // console.log(`${key}: ${obj[key]}`); + // let stringValue: string = key; + // try { + // let integerValue: number = Number(stringValue); + // console.log("Converted value: ", integerValue); // Output: 123 + // } catch (error) { + // // Handle the error here -- we will just skip + // console.log('An error occurred converting string to integer ', error); + // } + if (iterationNumber === 3) { + console.log(" this is Beneficiary = ", `${obj[key]}`) + } else if (iterationNumber === 4) { + console.log(" this is Deadline = ", `${obj[key]}`) + } else if (iterationNumber === 5) { + console.log(" this is Policy = ", `${obj[key]}`) + console.log("T - iter# = ", iterationNumber) + } else if (iterationNumber === 6) { + console.log(" this is Token Name = ", `${obj[key]}`) + } else if (iterationNumber === 7) { + console.log(" this is Target Amount = ", `${obj[key]}`) + console.log("T - iter# = ", iterationNumber) + } else if (iterationNumber === 8) { + console.log(" this is Target so Far = ", `${obj[key]}`) + } else if (iterationNumber > 13) { + // console.log("inside > 13 - iter# = ", iterationNumber) + // console.log("inside > 13 - contribiter# = ", contribIterNo) + if (contribIterNo === 0) { + console.log(" this is Contribution pubKeyHash = ", `${obj[key]}`) + contribIterNo++; + } else if (contribIterNo === 1) { + console.log(" this is Contribution Amount = ", `${obj[key]}`) + contribIterNo++; + } else if (contribIterNo > 1) { + contribIterNo++; + } + + + } + } + } + } + + // Recursive function to traverse the object and its nested properties + function traverse(obj: any, policyId: string) { + + for (const key in obj) { + iterationNumber++; + // console.log("T - iter# = ", iterationNumber) + + if (typeof obj[key] === 'object') { + contribIterNo = 0; // when you hit object we can reset contrib Iter + // Recurse into nested objects and arrays + if (iterationNumber == 1) { + // console.log(" T - If stmt iter # = ", iterationNumber); + traverse(obj[key], policyId); + } else { + // console.log(" T - else stmt iter # = ", iterationNumber); + traverse(obj[key], policyId); + } + } else { + // console.log(" type of key = ", typeof key) + // Print or process the leaf values + // console.log(`${key}: ${obj[key]}`); + // let stringValue: string = key; + // try { + // let integerValue: number = Number(stringValue); + // console.log("Converted value: ", integerValue); // Output: 123 + // } catch (error) { + // // Handle the error here -- we will just skip + // console.log('An error occurred converting string to integer ', error); + // } + if (iterationNumber === 6) { + console.log(" this is Beneficiary = ", `${obj[key]}`) + } else if (iterationNumber === 7) { + console.log(" this is Deadline = ", `${obj[key]}`) + } else if (iterationNumber === 8) { + console.log(" this is Policy = ", `${obj[key]}`) + } else if (iterationNumber === 9) { + console.log(" this is Token Name = ", `${obj[key]}`) + } else if (iterationNumber === 10) { + console.log(" this is Target Amount = ", `${obj[key]}`) + } else if (iterationNumber === 11) { + console.log(" this is Target so Far = ", `${obj[key]}`) + } else if (iterationNumber > 13) { + // console.log("inside > 13 - iter# = ", iterationNumber) + // console.log("inside > 13 - contribiter# = ", contribIterNo) + if (contribIterNo === 0) { + console.log(" this is Contribution pubKeyHash = ", `${obj[key]}`) + contribIterNo++; + } else if (contribIterNo === 1) { + console.log(" this is Contribution Amount = ", `${obj[key]}`) + contribIterNo++; + } else if (contribIterNo > 1) { + contribIterNo++; + } + + + } + } + } + } + + + + +// this function is only a test to show script address calculated thats all; + const sPrintScriptAddress = async () => { + if (lucid) { + // const sValCbor = "589b5899010000222323232325333573466e1d200200215333573466ebcd5d0991aab9e375400200e6ae84c8d55cf1baa00100614985854cd5ce2481445061747465726e206d61746368206661696c75726520696e2027646f2720626c6f636b206174207372632f536d616c6c56616c696461746f722e68733a35333a352d3432001635573c0046aae74004dd51aba135744002646aae78dd50008009" + // const sValCborSmallValidator = "582858260100003232322225333573466ebcc010c014008c010c01400c526165742460046ea800555cf1" // small validator + // const sValCborCrowdFund = "590a5f590a5c01000032323232323232323232323232323232323232323232323232323232323232323232323232323232323222232323232323232323232323253330343370e90010010991919299981b99b87480080084c8c8c8c8c8c8c8c8c8c8c8c8c8c94ccc114cdc3a4004004264646464646464646464646464a6660a466e1d20000021613232323232323232323232533305d3370e90000010a99982ea9982099b8733303d375660c002a6eb8c180048dd71830008a40042a6608266e1cc100dd5983000a9bad306000f153304133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010998219bab3060015304433304870066609e09c09c6eb4c18003cccc13cdd718300091bae30600114800854ccc1754cc104cdc399981e9bab306000a375c60c000e6eb8c180019200213304333304f04e04e3039375860c060be0086088666090e00ccc13c138138c0e4dd61830182f807999827827027181d01b8a99982e99821982219982438033304f04e04e375a60c001e66609e09c09c607406e66609e09c09c6eb4c18001054ccc1754cc104cdd79830004983000a0a9982099baf3060008306001315330413375e60c000a60c00202a6608266ebcc18001cc1800484cdd7983000318300088a99982e99821982219982438033304f04e04e303a037375660c002a6eacc18002854ccc174cdd7983000b18300058a99982e9981e191919299983019b87480000084c8c198c0fc004c18c00453011e581c0e97aa033ceee762c25285cdcc94287178f01b45a585fd0d4da8387a0030630023063001375406e02e2a6660ba66e25200433303d375660c001409c09c2930b0b0b0b0b0b0b0b0a99982e9981e183001300b8a99982ea9982099b89375a60c00446eb4c18008454cc104cdc49bad3060010375a60c001e266e24dd698300079bad306000f1533305d5330413370e66607a6eacc180054dd718300091bae30600114800854cc104cdc398201bab3060015375a60c001e2a66082660866eacc180054c110ccc121c01998278270271bad306000f33304f375c60c00246eb8c1800452002133043375660c002a6088666090e00ccc13c138138dd698300079998279bae3060012375c60c002290010a99982e99b88375a60c00266eb4c1800645261616161630600023060001375406860b600260b400260b200260b000260ae002609a6096609860ae60ac00260aa002609664a6660a80022c264a6660aa002260ae0042c60aa00266460a044a6660ac00220a6264a6660ac60080022660aa002600660b00042600660b000460b0002644646464a6660ae66e1d200000214a0266e3cdd7182d000802982d001182d0009baa323058304e0013057304d001375c60aa0026eb0c154050c154008c154004dd5191829982480098290041828000982780098270009826800982600098211820182098261825800982500098201991198231129998260008b09929998261919baf374e608c00a6e9cc118004c13c0044c13cc1380044c00cc138008c110c138004008dd61825005182500a1bac30493048007303e304800616304800230480013754608a0026074608800260726086002646084608460846084002608200260806080002606c608001a607c002607a00260780026076002607400260600242c607400460740026ea8c0dcc0d801058c0dc008c0dc004dd5181a18198009814804a99981799b87480000084c8c8c8c8c8c8c9265333036001149858c0d80194ccc0cccdc3a400000426464a66606a66e1cdc6800a40702646464646493299981d0008a4c2c60740066eb4004c0e4004c0dc00c58dd7000981b0008b181b001181b0009baa00130320011533302f3370e900100109924ca6660600022930b0b181900118190009baa006533302b3370e900000109919299981699b87371a002901c0991919299981819b89480000044c8c8c8c94ccc0d14cc0b8cdc3800a4000266e1c005203813232325333037337126e340052040132323232323232323232324994ccc1080045261630420033303b23232323200553330433370e900000109919299982299b87371a002901c0991919191924ca6660940022930b18250019bad0013049001304700316375c002608c0022c608c004608c0026ea8004dd60009820800981f8019bad001303e001303c003375a002607600260720062c6eb8004c0e0004c0d801058dc68009bae0013034001303200316375a0026062002605e0062c6eb8004c0b800458c0b8008c0b8004dd500198109129998138008a4000266e00dd6981518021814800980118140009191919299981399b874800800852000132375a6058600c0026054002605400460540026ea80048c8cdd818138009813981300098139baa0012301f22533302500114a02a66604866ebcc09c00400c5288980118130009111999802001240004666600a00490003ad3756002006460046ea40048888cc07c894ccc094004401454ccc090cdd79814981380080309802181418138008980118130008009299980f8008a4000266603c66ebcc08cc084004dd48079bad3022302137566044604200290001119980f0010008018a50223375e6e98008dd3000919801119299980e180280089128008911801001998029299980e19baf00137509000091280089118010018008009180191998011bab001232223002003374c002244a002ae8c88cc054894ccc06c00440404c8ccc014c07cc0780088cc06ccdd81810980f80180080108009801180e0008009111998021119980380280100080100091801911ba63300337560046eac0048c00888dd4198019bad002375a0024446666008006440040040024601e6004002446464466002006004444a66602e00226602a0060042646464a66603266ebc0080044cc060cdd800119804980e803180e80199980411001002980d8020a99980c99b90375c0046eb80044cc060018cccc0208800400cc06c0100144cc06000ccccc02088004018014c06c010c074008c070010c064004894ccc05400840044cccc00c88004c05c008c0580080052210022253330113370e002900008038998020019980280100091198021ba9002374c00244660066ea4008dd4000911980619bb00020010034bd6f7b630119191919002a99980699b87480000084c8c94ccc03ccdc39b8d001480e04c8c8c94ccc048cdc4a4000002264646464a66602ca6602066e1c005200013370e002901c0991919299980c99b89371a00290200991919191919191919191924ca6660480022930b18120019980e919191919002a99981299b87480000084c8c94ccc09ccdc39b8d001480e04c8c8c8c8c926533302c001149858c0b000cdd6800981580098148018b1bae0013028001163028002302800137540026eb0004c08c004c08400cdd68009810000980f0019bad001301d001301b00316375c002603400260300082c6e34004dd7000980b000980a0018b1bad0013013001301100316375c00260200022c602000460200026ea80048c8c8c94ccc030cdc3a40080042601e0022c601e004601e0026ea80048c030dd50009198038008010a512300222533300800110051330063003300a001300230090012323002233002002001230022330020020014bd702ba05734aae7d5d12ba15573caae741" // Crowd Fund + + const sValidator : SpendingValidator = { + type: "PlutusV2", + script: sValCborCrowdFund + } + + // to print at terminal too + // const fs = require('fs'); + // const path = require('path'); + // const logFile = path.join(process.cwd(), 'npm_run_dev.log'); + // const writeLog = (message) => { + // fs.writeFileSync(logFile, message + '\n', { encoding: 'utf-8' }); + // }; + // writeLog('This message was printed to the npm run dev window.'); + + + const sValAddress = lucid.utils.validatorToAddress(sValidator) + + // const datum = Data.to( + // new Constr(0, [BigInt(24)]) + // ) + console.log("PayToScript Address from New show address button: ", sValAddress ) + + + } + } // End sPrintScriptAddress + + +/////////////////////////////////////////////////////////////////////// +///////////// MINT NFT + + + +// const sPrintScriptAddress = async () => { + const sMintCrowdFundToken = async () => { + if (lucid) { + + const { paymentCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + // First we need to create a minting policy for the assets we want to mint. + // we utilize a native script time-locking policy with our wallet as required signer: + + const mintingPolicy = lucid.utils.nativeScriptFromJson( + { + type: "all", + scripts: [ + { type: "sig", keyHash: paymentCredential.hash }, + { + type: "before", + slot: lucid.utils.unixTimeToSlot(Date.now() + 1000000), // for testing minting 10 + }, + ], + }, + ); // End minting policy + + + + // Next we derive the policy id from the minting policy script: + const policyId = lucid.utils.mintingPolicyToId(mintingPolicy); + + // const unit = policyId + fromText("CrowdFundingToken"); + const unit = policyId + fromText("MyCrowdFund"); + console.log("Policy ID for our CrowdFunding Token: ", policyId ) + const tx = await lucid.newTx() + // .mintAssets({ [unit]: 10n }) // Mint 10 for testing + .mintAssets({ [unit]: 1n }) // Mint 10 for testing + .validTo(Date.now() + 200000) + .attachMintingPolicy(mintingPolicy) + .complete(); + + const signedTx = await tx.sign().complete(); + + const txHash = await signedTx.submit(); + console.log("Collect Test TxHash: " + txHash) + return txHash; + } + } // End sMintCrowdFundToken + + + const createSeedPhrase = async () => { + if (lucid) { + const seed = lucid.utils.generateSeedPhrase(); + console.log("Seed phrase created: ", seed) + lucid.selectWalletFromSeed(seed); + } + } // End createSeedPhrase + + + const handleChange = (event: React.ChangeEvent) => { + setInputValue(event.target.value); + }; + + + const handleButtonSDeposit = async () => { + try { + await sDeposit(); + } catch (error) { + // Handle any errors that might occur during the asynchronous operation + console.error('Error in SDeposit CrowdFund:', error); + } + }; + + const handleButtonClickSeedInfo = async () => { + try { + await infoFromSeed(inputValue); // Use 'await' to wait for the asynchronous function to complete + } catch (error) { + // Handle any errors that might occur during the asynchronous operation + console.error('Error in infoFromSeed:', error); + } + }; + + + const infoFromSeed = async (seed: string) => { + // This test routine i am trying to get address and credentials from Seed from a secret file. + // Also getting from Nami connected wallet too. + + // const seed = lucid.utils.generateSeedPhrase(); + // console.log("Seed phrase created: ", seed) + if (lucid) { + + // First lets bring Nami and get its PaymentCredential Hash + const { paymentCredential: namiPaymentCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + const namiCredHash = namiPaymentCredential?.hash! + console.log("Nami Cred Hash = ", namiCredHash) + + + // Now we connect from Seed + const options = { + accountIndex: 0, // Replace 0 with the desired account index value + // You can also provide other optional properties like addressType and password if needed + // addressType: "Base", + // password: "your_password_here", + }; + lucid.selectWalletFromSeed(seed, options); + const address = await lucid.wallet.address(); + const { paymentCredential: seedCredential } = lucid.utils.getAddressDetails( + await lucid.wallet.address(), + ); + const seedCredHash = seedCredential?.hash! + console.log("Seed Cred Hash = ", seedCredHash) + + setPrivAddress(address); + console.log("address 0 for seed phrase ", address) + + // You can Payment PubkeyHash directly from an address + const { paymentCredential: testCred } = getAddressDetails("addr_test1vr4cmkp58duj520sszr3hkfkjpzc04e29nega3acqeadgycxkd60u"); + // addr_test1qppr9pp9grd329vcz89xz9g0sg36kff09lm22p57qm2zm64yt7acf0k6xwhzk8jawtc7s96m2x5s2af3v5vjsg9tng0skvvfa0 + // + const testCredHash = testCred?.hash! + console.log("Test Cred Hash = ", testCredHash) + } + } // End infoFromSeed + + + const createPrivateKey = async (key: string) => { + // const seed = lucid.utils.generateSeedPhrase(); + // console.log("Seed phrase created: ", seed) + if (lucid) { + // const seed1 = "year gold install glide mirror useful assault very bid leader shuffle soon hamster betray raven entry very brick leave federal aim dress suit suit" + // const options = { + // accountIndex: 1, // Replace 0 with the desired account index value + // // You can also provide other optional properties like addressType and password if needed + // // addressType: "Base", + // // password: "your_password_here", + // }; + const privateKey = lucid.utils.generatePrivateKey(); // Bech32 encoded private key + lucid.selectWalletFromPrivateKey(privateKey); + console.log("Private key ", privateKey) + // cboe Hex - 5820fed6c111612c424b6bbe28b42e388faa3ec2102b7cd56fb249dc326a4f808498 + //Private key ed25519_sk1rkm9k26wpt9524q6pzmf94ltw9z5z2qe0zzhvau0kam46xq8m6yqw3lpcw + //crowdfund.tsx:374 address 1 for seed phrase addr_test1vr4cmkp58duj520sszr3hkfkjpzc04e29nega3acqeadgycxkd60u + + // lucid.selectWalletFromSeed(seed, options); + const address = await lucid.wallet.address(); + // addr_test1vq8f02sr8nhwwckz22zumny59pch3uqmgkjctlgdfk5rs7sx52ldh - beneficiary from CDP + console.log("address 1 for seed phrase ", address) + } + } // End infoFromSeed + + + + async function writeToServerFile() { + try { + const response = await fetch('/api/writeToFile', { + method: 'POST', + }); + + if (response.ok) { + console.log('From CrowdFund - Data written to the file successfully!'); + } else { + console.error('Failed to write data to the file.'); + } + } catch (error) { + console.error('Error:', error); + } + } + + + + const handleChangePrivateKey = (event: React.ChangeEvent) => { + setInputValuePrivateKey(event.target.value); + }; + const handleButtonClickPriv = async () => { + try { + await showAddress4PrivateKey(inputPrivateKey); // Use 'await' to wait for the asynchronous function to complete + } catch (error) { + // Handle any errors that might occur during the asynchronous operation + console.error('Error in showAddress4PrivateKey:', error); + } + }; + + const showAddress4PrivateKey = async (key: string) => { + // Input private will show Address + if (lucid) { + lucid.selectWalletFromPrivateKey(key); + const address = await lucid.wallet.address(); + // addr_test1vq8f02sr8nhwwckz22zumny59pch3uqmgkjctlgdfk5rs7sx52ldh - beneficiary from CDP + setPrivAddress(address); + console.log("address 1 for seed phrase ", address) + } + } // End showAddress4PrivateKey + + + const fetchSeed = async () => { + try { + const response = await fetch('/api/getData'); + const data = await response.json(); + // setReadSecretData(data); + if (data.seed[0]) { + // contributorSeed = data.seed[0].description; + return data.seed[0].description; + } + } catch (error) { + console.error('Error fetching secret data:', error); + throw error; + } + }; + + + const fetchSecretData = async () => { + try { + const response = await fetch('/api/getData'); + const data = await response.json(); + setReadSecretData(data); + if (data.items[0]) { + // contributorSeed = data.seed[0].description; + return data.seed[0].description; + } + } catch (error) { + console.error('Error fetching secret data:', error); + throw error; + } + }; + + const testCode = async () => { + // Input private will show Address + if (lucid) { + const date1 = Date.now(); + const date2 = date1 + 10000000000; + // 1690862203312 + // 1690947216000 + // 1691033616 - 1690862311 + const slot1 = lucid.utils.unixTimeToSlot(date2) + const slotTime1 = lucid.utils.slotToUnixTime(slot1) + console.log("date 1 = ", date1) + console.log("date 2 = ", date2) + console.log("slot 1 = ", slot1) + console.log("slotTime 1 = ", slotTime1) + + // Usage + const seed23Words = 'custom help female park blush clutch fancy lion fence innocent rebuild amount tip custom help female park blush clutch fancy lion fence innocent '; // for now 13 words + let encryptionPhrase = 'myOwnPassword$123'; + + const encryptIterations = 1; + + // Get the current date and time before starting the encryption process + const startTime = new Date().getTime(); + console.log("Start time before encryption: ", startTime) + + // const encryptedText = encrypt(seed23Words, encryptionPhrase); + // console.log('Encrypted:', encryptedText); + + let encyptedTextRecursive = seed23Words; // begin with words to encrypt + console.log('encyptedTextRecursive Seed Phrase:', encyptedTextRecursive); + const salt = CryptoJS.lib.WordArray.random(128/8); // Random salt + const encryptedPBKDF2 = CryptoJS.PBKDF2(encryptionPhrase, salt, { keySize: 128/32, iterations: 2 }); + console.log("encryptedPBKDF2 as string = ", encryptedPBKDF2.toString()) + + const test = CryptoJS.PBKDF2('password', 'ATHENA.MIT.EDUraeburn', { keySize: 128/32 }).toString(); + console.log("Test PBKDF2 = ", test) + + for (let i = 0; i < encryptIterations; i++) { + // encyptedTextRecursive = encrypt(encyptedTextRecursive, encryptionPhrase); + encyptedTextRecursive = encrypt(encyptedTextRecursive, encryptedPBKDF2.toString()); + console.log('Iter#, encyptedTextRecursive:', i, encyptedTextRecursive); + } + const endTime = new Date().getTime(); + const elapsedTime = endTime - startTime ; + console.log("Elapsed time in sec = " , elapsedTime / 1000) + + console.log("End time after 100 recursive encryptions: ", endTime) + console.log("Final encyptedTextRecursive after ", encryptIterations, " iterations:", encyptedTextRecursive); + + + // const decryptedText = decrypt(encryptedText, encryptionPhrase); + // console.log('Decrypted:', decryptedText); + + let decryptedTextRecursive = encyptedTextRecursive; // begin with decrypted final word + console.log('decryptedTextRecursive:', decryptedTextRecursive); + for (let i = 0; i < encryptIterations; i++) { + // decryptedTextRecursive = decrypt(decryptedTextRecursive, encryptionPhrase); + decryptedTextRecursive = decrypt(decryptedTextRecursive, encryptedPBKDF2.toString()); + console.log('decryptedTextRecursive:', decryptedTextRecursive); + } + console.log('Final decryptedTextRecursive:', decryptedTextRecursive); + + + + //infoFromSeed + + // fetchFirstLine(); // Call the function when the component mounts + } // if Lucid + } // End function `testcode` + + // https://github.com/brix/crypto-js/blob/develop/test/aes-test.js + +// Encrypt function + function encrypt(text: string, key: string): string { + const encrypted = CryptoJS.AES.encrypt(text, key); + return encrypted.toString(); + } + + // Decrypt function + function decrypt(encryptedText: string, key: string): string { + const decrypted = CryptoJS.AES.decrypt(encryptedText, key); + // const decrypted = CryptoJS.PBKDF2(encryptedText, key); + return decrypted.toString(CryptoJS.enc.Utf8); + } + + + async function fetchFirstLine() { + console.log("Starting fetch first line") + try { + const response = await fetch('/api/read-file', { + method: 'GET', + }) + console.log("Starting fetch second line - response.ok = ", response.ok) + if (response.ok) { + const data = await response.json(); + console.log('CrowdFund-FetchFirstLine - Data read from file successfully! JSON = ', data); + const firstLine = data.firstLine + setFirstLine(firstLine); + } else { + console.error('Failed to read data to the file.' , response.status); + } + } catch (error) { + console.error('Error:', error); + } + } + + + // const fetchFirstLine = async () => { + // try { + // console.log("in fetchFirstLine 1st line ") + // const response = await fetch('/api/read-file'); + // console.log("in fetchFirstLine 2nd line - response.ok is ", response.ok) + // if (response.ok) { + // const data = await response.json(); + // setFirstLine(data.firstLine); + // } else { + // console.error('Error fetching data:', response.statusText); + // } + // } catch (error) { + // console.error('Error fetching data:', error); + // } + // }; + + + return ( +
+
+
+ Cardano +
+
+ +
+
+
Address: {walletStore.address}
+
+ {/*

+ Emurgo example +

*/} +
+
+ + + {/* */} + + + + + +
+ +
+ {/* */} + + {txHash !== null &&

Tx Hash: {txHash}

} +
+ +
+ + + {privAddress !== null &&

Result: {privAddress}

} +
+ + {/*
*/} +
+ + {/* */} + + {privAddress !== null &&

Address: {privAddress}

} +
+
+ + + {privAddress !== null &&

Address: {privAddress}

} +
+ {/* + + */} +
+ +

First Line from File:

+

{firstLine}

+
+
+ + {/* */} + {readSecretData && ( +
+
{JSON.stringify(readSecretData, null, 2)}
// this gives the whole JSON file +

{readSecretData.seed[0].name} : {readSecretData.seed[0].description}

+
+ )} +
+
+ + ) // End return +} + +// export default Helios +export default crowdfund diff --git a/pages/index.tsx b/pages/index.tsx index 27e5eca..162109e 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -11,6 +11,8 @@ import initLucid from '../utils/lucid' const Home: NextPage = () => { const walletStore = useStoreState((state: any) => state.wallet) const [nftList, setNftList] = useState([]) + const [jsonData, setJsonData] = useState(null); + const [secretData, setSecretData] = useState(null); useEffect(() => { //const lucid = initLucid(walletStore.name) @@ -20,6 +22,27 @@ const Home: NextPage = () => { } }, [walletStore.address]) + + const fetchData = async () => { + try { + const response = await fetch('/secret.json'); // This will automatically fetch from the public folder + const data = await response.json(); + setJsonData(data); + } catch (error) { + console.error('Error fetching data:', error); + } + }; + + const fetchSecretData = async () => { + try { + const response = await fetch('/api/getData'); + const data = await response.json(); + setSecretData(data); + } catch (error) { + console.error('Error fetching secret data:', error); + } + }; + return (
@@ -36,14 +59,36 @@ const Home: NextPage = () => {
Address: {walletStore.address}
+
Your NFTs:
+
- + -
Your NFTs:
- + {/*
Your NFTs:
+ */} +
+
+ + {/* */} + {jsonData && ( +
+ {/*
{JSON.stringify(jsonData, null, 2)}
// this gives the whole JSON file */} +

Item 1 Description: {jsonData.items[0].description}

+
+ )} +
+
+ + {/* */} + {secretData && ( +
+
{JSON.stringify(secretData, null, 2)}
// this gives the whole JSON file +

{secretData.seed[0].name} : {secretData.seed[0].description}

+
+ )}
- + ) } diff --git a/utils/cardano.ts b/utils/cardano.ts index 98a8ffc..4b50e83 100644 --- a/utils/cardano.ts +++ b/utils/cardano.ts @@ -1,4 +1,8 @@ +import { fetchBlockFrostApi } from "./lucid" + export const getAssets = async (address: string) => { + + const apiValue = await fetchBlockFrostApi(); var allNFTs: any = [] var addressInfo = { nfts: allNFTs, balance: 0 } const data = await fetch( @@ -6,7 +10,9 @@ export const getAssets = async (address: string) => { { headers: { // Your Blockfrost API key - project_id: process.env.NEXT_PUBLIC_BLOCKFROST!, + // project_id: process.env.NEXT_PUBLIC_BLOCKFROST!, + // 'Content-Type': 'application/json' + project_id: apiValue.toString(), 'Content-Type': 'application/json' } } diff --git a/utils/lucid.ts b/utils/lucid.ts index 7d36c12..82a7f71 100644 --- a/utils/lucid.ts +++ b/utils/lucid.ts @@ -9,11 +9,11 @@ const initLucid = async (wallet: string) => { const nami = await window.cardano.nami.enable(); // const eternl = window.cardano.eternl.enable(); // const gero = await window.cardano.gero.enable(); + + const apiValue = await fetchBlockFrostApi(); const lucid = await Lucid.new( - // new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', "preprodLT9nUTb22P26FiVH42jSFJU2IZaNxZVz") //process.env.NEXT_PUBLIC_BLOCKFROST as string), - // ,'Preprod'); - new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', "preprod232JoxaAx9xRCqCdMJlweO5paor8jPfL") //process.env.NEXT_PUBLIC_BLOCKFROST as string), + new Blockfrost('https://cardano-preprod.blockfrost.io/api/v0', apiValue.toString()) //process.env.NEXT_PUBLIC_BLOCKFROST as string), ,'Preprod'); // const lucid = await Lucid.new( // new Blockfrost("https://cardano-preview.blockfrost.io/api/v0", "previewY7wWn4mtcYHascUO7PyxeCXadkAkBVz2"), @@ -29,5 +29,19 @@ const initLucid = async (wallet: string) => { return lucid; } +export const fetchBlockFrostApi = async () => { + try { + const response = await fetch('/api/getData'); + const data = await response.json(); + if (data.seed[0]) { + const blockfrostApi = data.seed[2].description; + console.log("api = ", blockfrostApi) + return blockfrostApi; // Return the value + } + } catch (error) { + console.error('Error fetching secret data:', error); + } + return null; // Return null if there was an error or no data was found + }; export default initLucid; \ No newline at end of file diff --git a/utils/valueUtils.ts b/utils/valueUtils.ts index 580e8dd..9ee0149 100644 --- a/utils/valueUtils.ts +++ b/utils/valueUtils.ts @@ -74,6 +74,6 @@ export { Value }; -export type { - Value -} +// export type { +// Value +// } diff --git a/yarn.lock b/yarn.lock index 780ae35..b4abcc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -863,6 +863,11 @@ cross-spawn@^7.0.2: shebang-command "^2.0.0" which "^2.0.1" +crypto-js@^4.1.1: + version "4.1.1" + resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.1.1.tgz" + integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw== + css-selector-tokenizer@^0.8.0: version "0.8.0" resolved "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz"