Skip to content

Commit

Permalink
allow transactions to include verifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
giantimi committed Apr 25, 2024
1 parent 539ae0e commit dba706b
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 19 deletions.
10 changes: 8 additions & 2 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion exec/TXG.hs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ generateSimpleTransactions = do
(Nothing,)
<$> mkExec (T.pack theCode) theData meta
(NEL.toList kps)
mempty
(Just $ CI.NetworkId $ chainwebVersionToText v)
Nothing

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/TXG/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/TXG/ReplInternals.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,14 +111,15 @@ cmd
-- ^ Env data
-> PublicMeta
-> [(DynKeyPair,[SigCapability])]
-> [Verifier ParsedVerifierProof]
-> Maybe NetworkId
-> Maybe Text
-- ^ Transaction nonce. If Nothing, then getCurrentTime is used.
-> IO (Command Text)
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

Expand Down
8 changes: 4 additions & 4 deletions lib/TXG/Simulate/Contracts/CoinContract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ 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 =
T.pack $
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 $
Expand All @@ -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 =
Expand All @@ -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
4 changes: 2 additions & 2 deletions lib/TXG/Simulate/Contracts/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/TXG/Simulate/Contracts/HelloWorld.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
8 changes: 4 additions & 4 deletions lib/TXG/Simulate/Contracts/SimplePayments.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
;;
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion lib/TXG/Simulate/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions txg.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dba706b

Please sign in to comment.