From dba706b6d2b9527757b858a27e31db521c7b2782 Mon Sep 17 00:00:00 2001 From: Emmanuel Denloye-Ito Date: Thu, 25 Apr 2024 12:44:12 -0400 Subject: [PATCH] allow transactions to include verifiers --- cabal.project | 10 ++++++++-- exec/TXG.hs | 4 +++- lib/TXG/Repl.hs | 4 ++-- lib/TXG/ReplInternals.hs | 4 +++- lib/TXG/Simulate/Contracts/CoinContract.hs | 8 ++++---- lib/TXG/Simulate/Contracts/Common.hs | 4 ++-- lib/TXG/Simulate/Contracts/HelloWorld.hs | 4 ++-- lib/TXG/Simulate/Contracts/SimplePayments.hs | 8 ++++---- lib/TXG/Simulate/Utils.hs | 2 +- txg.cabal | 1 + 10 files changed, 30 insertions(+), 19 deletions(-) diff --git a/cabal.project b/cabal.project index f7b3659..347758f 100644 --- a/cabal.project +++ b/cabal.project @@ -3,8 +3,8 @@ packages: txg.cabal source-repository-package type: git location: https://github.com/kadena-io/pact.git - tag: 495c8738acaa0157958ab23a06cd94abbc99d2d5 - --sha256: 1dn322m5mx43bn3ki37zdk9daknnr6sz8y7d89si75m84rl0w27k + tag: a1c7906efbf32095883e71594a53a21162fbe5a7 + --sha256: sha256-Mtgz/ilxa81TDUoBKQv5x3BlOftFjNV1Ak0uYzSguNQ= source-repository-package type: git @@ -25,6 +25,12 @@ source-repository-package location: https://github.com/larskuhtz/sbv --sha256: 1msbz6525nmsywpm910jh23siil4qgn3rpsm52m8j6877r7v5zw3 +source-repository-package + type: git + location: https://github.com/kadena-io/kadena-ethereum-bridge.git + tag: a32d901e4a79be62af9c27c01152c9a4c3912a62 + --sha256: sha256-xdawv/tdjh61MbJKcBqm9Fje36+gVljuZsAxOTX1gP0= + package hostaddress flags: +with-configuration-tools +with-aeson diff --git a/exec/TXG.hs b/exec/TXG.hs index 2c14895..2e1595e 100644 --- a/exec/TXG.hs +++ b/exec/TXG.hs @@ -152,6 +152,7 @@ generateSimpleTransactions = do (Nothing,) <$> mkExec (T.pack theCode) theData meta (NEL.toList kps) + mempty (Just $ CI.NetworkId $ chainwebVersionToText v) Nothing @@ -988,6 +989,7 @@ singleTransaction args (ChainwebHost h _p2p service) (SingleTX c cid) let v = confVersion cfg cmd <- mkExec c (datum kps) meta (NEL.toList kps) + mempty (Just $ CI.NetworkId $ chainwebVersionToText v) Nothing runExceptT (f cfg cmd) >>= \case @@ -1136,7 +1138,7 @@ createLoader v (Sim.ContractName contractName) meta kp = do -- TODO: theData may change later let theData = object [ (fromText "admin-keyset") .= fmap (formatPubKeyForCmd . fst) adminKS, (fromText $ T.append (T.pack contractName) "-keyset") .= fmap (formatPubKeyForCmd . fst) kp ] - mkExec (T.pack theCode) theData meta (NEL.toList adminKS) (Just $ CI.NetworkId $ chainwebVersionToText v) Nothing + mkExec (T.pack theCode) theData meta (NEL.toList adminKS) mempty (Just $ CI.NetworkId $ chainwebVersionToText v) Nothing -- Remember that coin contract is already loaded. defaultContractLoaders :: ChainwebVersion -> NEL.NonEmpty ContractLoader diff --git a/lib/TXG/Repl.hs b/lib/TXG/Repl.hs index 92b1284..a206262 100644 --- a/lib/TXG/Repl.hs +++ b/lib/TXG/Repl.hs @@ -190,7 +190,7 @@ sampleKeyPairCaps = do mkCmdStr :: PublicMeta -> ChainwebVersion -> [(DynKeyPair,[SigCapability])] -> String -> IO (Command Text) mkCmdStr meta ver kps str = - cmd (T.pack str) Null meta kps (Just (verToPactNetId ver)) Nothing + cmd (T.pack str) Null meta kps mempty (Just (verToPactNetId ver)) Nothing mkCmdDataStr :: PublicMeta @@ -200,7 +200,7 @@ mkCmdDataStr -> Value -> IO (Command Text) mkCmdDataStr meta ver kps cmdCode cmdData = - cmd (T.pack cmdCode) cmdData meta kps (Just (verToPactNetId ver)) Nothing + cmd (T.pack cmdCode) cmdData meta kps mempty (Just (verToPactNetId ver)) Nothing verToChainId :: ChainwebVersion -> ChainId verToChainId ver = foldr const err $ chainIds ver diff --git a/lib/TXG/ReplInternals.hs b/lib/TXG/ReplInternals.hs index 0bec598..bbe79d7 100644 --- a/lib/TXG/ReplInternals.hs +++ b/lib/TXG/ReplInternals.hs @@ -26,6 +26,7 @@ import Pact.Types.ChainMeta import Pact.Types.Command import Pact.Types.Hash import Pact.Types.SPV +import Pact.Types.Verifier import qualified Pact.JSON.Encode as J import System.Random import Text.Printf @@ -110,6 +111,7 @@ cmd -- ^ Env data -> PublicMeta -> [(DynKeyPair,[SigCapability])] + -> [Verifier ParsedVerifierProof] -> Maybe NetworkId -> Maybe Text -- ^ Transaction nonce. If Nothing, then getCurrentTime is used. @@ -117,7 +119,7 @@ cmd cmd = mkExec cmdStr :: String -> IO (Command Text) -cmdStr str = cmd (T.pack str) Null defPubMeta [] Nothing Nothing +cmdStr str = cmd (T.pack str) Null defPubMeta [] mempty Nothing Nothing -- Structured transactions diff --git a/lib/TXG/Simulate/Contracts/CoinContract.hs b/lib/TXG/Simulate/Contracts/CoinContract.hs index 83c39f0..add643c 100644 --- a/lib/TXG/Simulate/Contracts/CoinContract.hs +++ b/lib/TXG/Simulate/Contracts/CoinContract.hs @@ -87,7 +87,7 @@ createCoinContractRequest v meta ks request = object [ "create-account-guard" .= fmap (formatPubKeyForCmd . fst) g ] - mkExec theCode theData meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing CoinAccountBalance (Account account) -> do let theData = Null theCode = @@ -95,7 +95,7 @@ createCoinContractRequest v meta ks request = printf "(coin.get-balance \"%s\")" account - mkExec theCode theData meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing CoinTransferAndCreate (SenderName (Account sn)) (ReceiverName (Account rn)) (Guard g) (Amount amount) -> do let theCode = T.pack $ @@ -109,7 +109,7 @@ createCoinContractRequest v meta ks request = object [ "receiver-guard" .= fmap (formatPubKeyForCmd . fst) g ] - mkExec theCode theData meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing CoinTransfer (SenderName (Account sn)) (ReceiverName (Account rn)) (Amount amount) -> do let theCode = @@ -121,4 +121,4 @@ createCoinContractRequest v meta ks request = -- Super janky, but gets the job done for now (fromRational @Double $ toRational amount) theData = object [] - mkExec theCode theData meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing diff --git a/lib/TXG/Simulate/Contracts/Common.hs b/lib/TXG/Simulate/Contracts/Common.hs index 9cf5fb2..dd1f4ef 100644 --- a/lib/TXG/Simulate/Contracts/Common.hs +++ b/lib/TXG/Simulate/Contracts/Common.hs @@ -85,7 +85,7 @@ createPaymentsAccount v meta name = do let theData = object [ fromText (T.pack (name ++ "-keyset")) .= fmap (formatPubKeyForCmd . fst) nameKeyset ] - res <- mkExec theCode theData meta (NEL.toList adminKS) (Just $ CM.NetworkId $ chainwebVersionToText v) Nothing + res <- mkExec theCode theData meta (NEL.toList adminKS) mempty (Just $ CM.NetworkId $ chainwebVersionToText v) Nothing pure (NEL.fromList nameKeyset, res) where theCode = T.pack $ printf "(payments.create-account \"%s\" %s (read-keyset \"%s-keyset\"))" name (show (1000000.1 :: Decimal)) name @@ -99,7 +99,7 @@ createCoinAccount v meta name = do adminKS <- testDynKeyPairs nameKeyset <- NEL.fromList <$> getKeyset let theData = object [fromText (T.pack (name ++ "-keyset")) .= fmap (formatPubKeyForCmd . fst) nameKeyset] - res <- mkExec theCode theData meta (NEL.toList adminKS) (Just $ CM.NetworkId $ chainwebVersionToText v) Nothing + res <- mkExec theCode theData meta (NEL.toList adminKS) mempty (Just $ CM.NetworkId $ chainwebVersionToText v) Nothing pure (nameKeyset, res) where theCode = T.pack $ printf "(coin.create-account \"%s\" (read-keyset \"%s\"))" name name diff --git a/lib/TXG/Simulate/Contracts/HelloWorld.hs b/lib/TXG/Simulate/Contracts/HelloWorld.hs index 24ed4a4..0f41ce7 100644 --- a/lib/TXG/Simulate/Contracts/HelloWorld.hs +++ b/lib/TXG/Simulate/Contracts/HelloWorld.hs @@ -39,7 +39,7 @@ helloWorldContractLoader -> IO (Command Text) helloWorldContractLoader v meta adminKS = do let theData = object ["admin-keyset" .= fmap (formatPubKeyForCmd . fst) adminKS] - mkExec theCode theData meta (NEL.toList adminKS) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList adminKS) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing where theCode = [text| (module helloWorld 'admin-keyset @@ -56,7 +56,7 @@ instance Fake Name where fake = Name <$> personName helloRequest :: ChainwebVersion -> Name -> IO (Command Text) -helloRequest v (Name name) = mkExec theCode theData def [] (Just $ NetworkId $ chainwebVersionToText v) Nothing +helloRequest v (Name name) = mkExec theCode theData def [] mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing where theData = Null theCode = T.pack $ printf "(helloWorld.hello \"%s\")" name diff --git a/lib/TXG/Simulate/Contracts/SimplePayments.hs b/lib/TXG/Simulate/Contracts/SimplePayments.hs index f6f8ed1..3c94ea9 100644 --- a/lib/TXG/Simulate/Contracts/SimplePayments.hs +++ b/lib/TXG/Simulate/Contracts/SimplePayments.hs @@ -29,7 +29,7 @@ import TXG.Fake simplePaymentsContractLoader :: ChainwebVersion -> PublicMeta -> NEL.NonEmpty (DynKeyPair,[SigCapability]) -> IO (Command Text) simplePaymentsContractLoader v meta adminKS = do let theData = object ["admin-keyset" .= fmap (formatPubKeyForCmd . fst) adminKS] - mkExec theCode theData meta (NEL.toList adminKS) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList adminKS) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing where theCode = [text| ;; Simple accounts model. ;; @@ -122,15 +122,15 @@ simplePayReq v meta (SPCreateAccount (Account account) (Balance initBal) ks) _ = let theCode = T.pack $ printf "(payments.create-account \"%s\" %s)" account (show initBal) theData = object [ "keyset" .= fmap (formatPubKeyForCmd . fst) ks , "admin-keyset" .= fmap (formatPubKeyForCmd . fst) adminKS ] - mkExec theCode theData meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing simplePayReq v meta (SPRequestGetBalance (Account account)) _ = do adminKS <- testDynKeyPairs let theCode = T.pack $ printf "(payments.get-balance \"%s\")" account - mkExec theCode Null meta (NEL.toList adminKS) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode Null meta (NEL.toList adminKS) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing simplePayReq v meta (SPRequestPay (Account from) (Account to) (Amount amount)) (Just ks) = do let theCode = T.pack $ printf "(payments.pay \"%s\" \"%s\" %s)" from to (show amount) - mkExec theCode Null meta (NEL.toList ks) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode Null meta (NEL.toList ks) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing simplePayReq _ _ _ _ = error "simplePayReq: impossible" diff --git a/lib/TXG/Simulate/Utils.hs b/lib/TXG/Simulate/Utils.hs index a86af28..0f170ed 100644 --- a/lib/TXG/Simulate/Utils.hs +++ b/lib/TXG/Simulate/Utils.hs @@ -72,7 +72,7 @@ initAdminKeysetContract -> NEL.NonEmpty (DynKeyPair,[SigCapability]) -> IO (Command Text) initAdminKeysetContract v meta adminKS = - mkExec theCode theData meta (NEL.toList adminKS) (Just $ NetworkId $ chainwebVersionToText v) Nothing + mkExec theCode theData meta (NEL.toList adminKS) mempty (Just $ NetworkId $ chainwebVersionToText v) Nothing where theCode = "(define-keyset 'admin-keyset (read-keyset \"admin-keyset\"))" theData = object ["admin-keyset" .= fmap (formatPubKeyForCmd . fst) adminKS] diff --git a/txg.cabal b/txg.cabal index e9773e5..841a641 100644 --- a/txg.cabal +++ b/txg.cabal @@ -70,6 +70,7 @@ library , data-default >=0.7 , extra >=1.6 , file-embed >=0.0 + , lens-aeson >= 1.1 , neat-interpolation >=0.3 , random-bytestring >=0.1 , random-strings >=0.1