Skip to content

Commit aa0fab0

Browse files
committed
Another round on tutorial shell with new local cluster
1 parent ea29f13 commit aa0fab0

File tree

7 files changed

+75
-63
lines changed

7 files changed

+75
-63
lines changed

coop-extras/tutorial/aux.bash

+59-47
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ CLUSTER_DIR=.local-cluster # As specified in resources/pabConfig.yaml
66

77
WALLETS=.wallets
88

9-
RESOURCES=resources
10-
COOP_PROTO=coop-proto
9+
RESOURCES=resources # Symlinked by Nix env
10+
COOP_PROTO=coop-proto # Symlinked by Nix env
1111

1212
function clean {
1313
rm -fR $JS_STORE_DIR
@@ -36,7 +36,7 @@ function generate-keys {
3636
}
3737

3838
# Prelude and run the FactStatementStore gRpc with a generic Json implementation
39-
function prelude-js-fs-store {
39+
function run-js-fs-store {
4040
mkdir $JS_STORE_DIR
4141
sqlite3 -batch $JS_STORE_DIR/json-store.db ""
4242
json-fs-store-cli genesis --db $JS_STORE_DIR/json-store.db
@@ -49,54 +49,39 @@ function prelude-js-fs-store {
4949
}
5050

5151
# Prelude and run the Plutip Local Cluster (cardano-node and wallet creation)
52-
function prelude-cluster {
52+
function run-cluster {
5353
mkdir $CLUSTER_DIR
5454
mkdir $CLUSTER_DIR/scripts
5555
mkdir $CLUSTER_DIR/txs
5656
mkdir $WALLETS
57-
local-cluster --wallet-dir $WALLETS -n 10 --utxos 5 --chain-index-port 9084 --slot-len 1s --epoch-size 100000
57+
local-cluster --dump-info-json $CLUSTER_DIR/local-cluster-info.json \
58+
--wallet-dir $WALLETS \
59+
-n 10 --utxos 5 \
60+
--chain-index-port 9084 \
61+
--slot-len 1s --epoch-size 100000
5862
}
5963

60-
# Run manually to parse the config outputted by local-cluster
61-
function parse-cluster-config {
62-
cat > $CLUSTER_DIR/plutip-cluster-config
63-
make-exports
64-
# So BPI doesn't have access to it
65-
echo $SUBMITTER_PKH
66-
if [ -f $WALLETS/my-signing-key-$SUBMITTER_PKH.skey ];
67-
then echo "My key already setup"
68-
else
69-
echo "Hiding my key from the PAB"
70-
mv $WALLETS/signing-key-$SUBMITTER_PKH.skey $WALLETS/my-signing-key-$SUBMITTER_PKH.skey
71-
fi;
72-
}
73-
74-
if [ -f $CLUSTER_DIR/plutip-cluster-config ];
75-
then make-exports;
76-
else echo "Run prelude-cluster and parse with parse-cluster-config" ;
77-
fi;
78-
7964
# Export the variables used across
8065
function make-exports {
81-
export GOD_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 1 PKH" | cut -d ":" -f 2 | xargs)
82-
export AA_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 2 PKH" | cut -d ":" -f 2 | xargs)
83-
export AUTH_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 3 PKH" | cut -d ":" -f 2 | xargs)
84-
export CERT_RDMR_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 4 PKH" | cut -d ":" -f 2 | xargs)
85-
export FEE_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 5 PKH" | cut -d ":" -f 2 | xargs)
86-
export SUBMITTER_PKH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep -E "Wallet 6 PKH" | cut -d ":" -f 2 | xargs)
87-
export CARDANO_NODE_SOCKET_PATH=$(cat $CLUSTER_DIR/plutip-cluster-config | grep CardanoNodeConn | grep -E -o '"[^"]+"' | sed s/\"//g)
66+
export GOD_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[0][0]")
67+
export AA_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[1][0]")
68+
export AUTH_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[2][0]")
69+
export CERT_RDMR_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[3][0]")
70+
export FEE_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[4][0]")
71+
export SUBMITTER_PKH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciWallets[5][0]")
72+
export CARDANO_NODE_SOCKET_PATH=$(cat $CLUSTER_DIR/local-cluster-info.json | jq -r ".ciNodeSocket")
8873
}
8974

9075
# Prelude and run the TxBuilder gRpc
91-
function prelude-tx-builder {
76+
function run-tx-builder {
9277
mkdir $COOP_PAB_DIR
9378
generate-keys $COOP_PAB_DIR
9479
make-exports
9580
coop-genesis
9681
coop-mint-cert-redeemers
9782
coop-mint-authentication
9883
coop-redist-auth
99-
coop-run-tx-builder-grpc
84+
coop-run-tx-builder-grpc > /dev/null
10085
}
10186

10287
function coop-genesis {
@@ -140,6 +125,10 @@ function coop-poll-state {
140125
done;
141126
}
142127

128+
function fs-store-insert {
129+
json-fs-store-cli insert-fact-statement --db $JS_STORE_DIR/json-store.db --fact_statement_id "$1" --json "$2"
130+
}
131+
143132
function get-onchain-time {
144133
coop-pab-cli get-state --any-wallet $GOD_PKH | grep "Current node client time range" | grep POSIXTime | grep -E -o "[0-9]+"
145134
}
@@ -148,15 +137,26 @@ function run-grpcui {
148137
grpcui -insecure -import-path $COOP_PROTO -proto $COOP_PROTO/publisher-service.proto localhost:5080
149138
}
150139

151-
function prelude-publisher {
140+
function run-publisher {
152141
mkdir $COOP_PUBLISHER_DIR
153142
generate-keys $COOP_PUBLISHER_DIR
154143
make-exports
155144
coop-publisher-cli publisher-grpc
156145
}
157146

147+
function run-all {
148+
run-cluster &
149+
while [ ! -f $CLUSTER_DIR/local-cluster-info.json ]; do sleep 1; done;
150+
make-exports
151+
mv $WALLETS/signing-key-"$SUBMITTER_PKH".skey $WALLETS/my-signing-key-"$SUBMITTER_PKH".skey
152+
run-js-fs-store &
153+
run-tx-builder &
154+
run-publisher &
155+
}
156+
158157
function coop-mint-fs {
159-
resp=$(grpcurl -insecure -import-path $COOP_PROTO -proto $COOP_PROTO/publisher-service.proto -d @ localhost:5080 coop.publisher.Publisher/createMintFsTx <<EOF
158+
make-exports
159+
req=$(cat <<EOF
160160
{
161161
"fsInfos": [
162162
{
@@ -182,36 +182,48 @@ function coop-mint-fs {
182182
"base16": "$SUBMITTER_PKH"
183183
}
184184
}
185-
186185
EOF
187-
)
186+
)
187+
resp=$(echo $req | grpcurl -insecure -import-path $COOP_PROTO -proto $COOP_PROTO/publisher-service.proto -d @ localhost:5080 coop.publisher.Publisher/createMintFsTx)
188188
rawTx=$(echo "$resp" | jq '.mintFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "Tx BabbageEra"')
189189
echo "$resp" | jq '.info'
190190
echo "$resp" | jq '.error'
191191
echo "$rawTx" > $COOP_PUBLISHER_DIR/signed
192-
cardano-cli transaction sign --tx-file $COOP_PUBLISHER_DIR/signed --signing-key-file $WALLETS/my-signing-key-"$SUBMITTER_PKH".skey --out-file $COOP_PUBLISHER_DIR/ready
193-
cardano-cli transaction submit --tx-file $COOP_PUBLISHER_DIR/ready --mainnet
192+
if [ "$(echo $resp | jq "has(\"mintFsTx\")")" == true ]; then
193+
cardano-cli transaction sign --tx-file $COOP_PUBLISHER_DIR/signed --signing-key-file $WALLETS/my-signing-key-"$SUBMITTER_PKH".skey --out-file $COOP_PUBLISHER_DIR/ready
194+
cardano-cli transaction submit --tx-file $COOP_PUBLISHER_DIR/ready --mainnet
195+
else
196+
echo "No transaction to submit"
197+
fi
194198
}
195199

196200
function coop-gc-fs {
197-
resp=$(grpcurl -insecure -import-path $COOP_PROTO -proto $COOP_PROTO/publisher-service.proto -d @ localhost:5080 coop.publisher.Publisher/createGcFsTx <<EOF
201+
make-exports
202+
req=$(cat <<EOF
198203
{
199204
"fsIds": [
200-
"$(echo -ne someidA | base64)",
201-
"$(echo -ne someidB | base64)",
202-
"$(echo -ne someidC | base64)"
203-
],
205+
"$(echo -ne 'should not exist' | base64)",
206+
"$(echo -ne 'someidA' | base64)",
207+
"$(echo -ne 'someidB' | base64)",
208+
"$(echo -ne 'nop' | base64)",
209+
"$(echo -ne 'another nope' | base64)"
210+
],
204211
"submitter": {
205212
"base16": "$SUBMITTER_PKH"
206213
}
207214
}
208215
209216
EOF
210-
)
217+
)
218+
resp=$(echo $req | grpcurl -insecure -import-path $COOP_PROTO -proto $COOP_PROTO/publisher-service.proto -d @ localhost:5080 coop.publisher.Publisher/createGcFsTx)
211219
rawTx=$(echo "$resp" | jq '.gcFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "TxBodyBabbage"')
212220
echo "$resp" | jq '.info'
213221
echo "$resp" | jq '.error'
214222
echo "$rawTx" > $COOP_PUBLISHER_DIR/signed
215-
cardano-cli transaction sign --tx-body-file $COOP_PUBLISHER_DIR/signed --signing-key-file $WALLETS/my-signing-key-"$SUBMITTER_PKH".skey --out-file $COOP_PUBLISHER_DIR/ready
216-
cardano-cli transaction submit --tx-file $COOP_PUBLISHER_DIR/ready --mainnet
223+
if [ "$(echo $resp | jq "has(\"gcFsTx\")")" == true ]; then
224+
cardano-cli transaction sign --tx-body-file $COOP_PUBLISHER_DIR/signed --signing-key-file $WALLETS/my-signing-key-"$SUBMITTER_PKH".skey --out-file $COOP_PUBLISHER_DIR/ready
225+
cardano-cli transaction submit --tx-file $COOP_PUBLISHER_DIR/ready --mainnet
226+
else
227+
echo "No transaction to submit"
228+
fi
217229
}

coop-extras/tutorial/build.nix

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
, coopPublisherCli
77
, jsFsStoreCli
88
, plutipLocalCluster
9-
, shellHook
109
}:
1110
pkgs.mkShell {
1211
packages = with pkgs; [
@@ -28,11 +27,13 @@ pkgs.mkShell {
2827
jsFsStoreCli
2928
plutipLocalCluster
3029
];
31-
3230
shellHook = ''
33-
${shellHook}
3431
ln -s ${../../coop-proto} coop-proto
3532
ln -s ${../../coop-pab/resources} resources
36-
source ${./aux.bash}
33+
. ${./aux.bash}
34+
echo "WARNING: Running COOP services requires having $ export LC_CTYPE=C.UTF-8 LC_ALL=C.UTF-8 LANG=C.UTF-8"
35+
export LC_CTYPE=C.UTF-8
36+
export LC_ALL=C.UTF-8
37+
export LANG=C.UTF-8
3738
'';
3839
}

coop-pab/app/Coop/Cli/TxBuilderGrpc.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ txBuilderService opts = do
7070

7171
handleCreateMintFsTx :: Server.UnaryHandler IO CreateMintFsTxReq CreateMintFsTxResp
7272
handleCreateMintFsTx _ req = do
73+
print ("TxBuilder got CreateMintFsTxReq:" <> show req)
7374
sub <- toCardano (req ^. submitter)
7475
(_, errOrAcs) <-
7576
runBpi @Text
@@ -78,7 +79,7 @@ txBuilderService opts = do
7879
}
7980
(runMintFsTxOnReq req)
8081
either
81-
(\err -> return $ defMessage & Proto.TxBuilderService.error . otherErr . msg .~ err)
82+
(\err -> return $ defMessage & Proto.TxBuilderService.error . otherErr . msg .~ "Failed running a BPI contract with: " <> err)
8283
( \(mayTxId, info') -> do
8384
maybe
8485
( return $
@@ -99,7 +100,6 @@ txBuilderService opts = do
99100
return $
100101
defMessage
101102
& info .~ info'
102-
& Proto.TxBuilderService.error . otherErr . msg .~ "wuasapp"
103103
& success . mintFsTx . cborBase16 .~ rawTx
104104
)
105105
mayRawTx
@@ -115,6 +115,7 @@ txBuilderService opts = do
115115

116116
handleCreateGcFsTx :: Server.UnaryHandler IO CreateGcFsTxReq CreateGcFsTxResp
117117
handleCreateGcFsTx _ req = do
118+
print ("TxBuilder got CreateGcFsTxReq:" <> show req)
118119
sub <- toCardano (req ^. submitter)
119120
(_, errOrAcs) <-
120121
runBpi @Text
@@ -123,7 +124,7 @@ txBuilderService opts = do
123124
}
124125
(runGcFsTxOnReq req)
125126
either
126-
(\err -> return $ defMessage & Proto.TxBuilderService.error . otherErr . msg .~ err)
127+
(\err -> return $ defMessage & Proto.TxBuilderService.error . otherErr . msg .~ "Failed running a BPI contract with: " <> err)
127128
( \(mayTxId, info') -> do
128129
maybe
129130
( return $
@@ -132,6 +133,7 @@ txBuilderService opts = do
132133
& info .~ info'
133134
)
134135
( \txId -> do
136+
print $ "Reading tx with" <> show txId
135137
mayRawTx <- readSignedTx pabConf None txId
136138
either
137139
( \err ->

coop-pab/aux.bash

-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ function coop-gc-fs {
195195
"base16": "$SUBMITTER_PKH"
196196
}
197197
}
198-
199198
EOF
200199
)
201200
rawTx=$(echo "$resp" | jq '.success.gcFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "TxBodyBabbage"')

coop-publisher/app/Coop/Cli/PublisherGrpc.hs

+3-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ publisherService opts = do
6969
(RPC :: RPC FactStatementStore "getFactStatement")
7070
(defMessage & fsIds .~ ((^. fsId) <$> req ^. fsInfos))
7171
either
72-
( \err -> do
73-
return $ defMessage & PublisherService.error .~ err
74-
)
72+
(\err -> return $ defMessage & PublisherService.error .~ err)
7573
( \(getFsResp :: GetFactStatementResponse) -> do
7674
print ("Got from FactStatementStore: " <> show getFsResp)
7775
case getFsResp ^. maybe'error of
@@ -90,7 +88,7 @@ publisherService opts = do
9088
defMessage
9189
& factStatements .~ fsInfos'
9290
& submitter .~ req ^. submitter
93-
print (show crMintFsTxReq)
91+
print ("Sending CreateMintFsTxReq to TxBuilder: " <> show crMintFsTxReq)
9492
createMintFsRespOrErr <-
9593
call'
9694
(opts ^. txBuilderAddress)
@@ -126,6 +124,7 @@ publisherService opts = do
126124
defMessage
127125
& fsIds .~ req ^. fsIds
128126
& submitter .~ req ^. submitter
127+
print ("Sending CreateGcFsTxRequest to TxBuilder: " <> show txBuilderReq)
129128
createGcFsRespOrErr <-
130129
call'
131130
(opts ^. txBuilderAddress)

flake.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@
227227
coopPublisherCli = coopPublisherFlake.packages."coop-publisher:exe:coop-publisher-cli";
228228
cardanoNode = coopPabProj.hsPkgs.cardano-node.components.exes.cardano-node;
229229
cardanoCli = coopPabProj.hsPkgs.cardano-cli.components.exes.cardano-cli;
230-
inherit (pre-commit-check) shellHook;
231230
};
232231

233232
renameAttrs = rnFn: pkgs.lib.attrsets.mapAttrs' (n: value: { name = rnFn n; inherit value; });

0 commit comments

Comments
 (0)