Skip to content

Commit 02bbe59

Browse files
committed
Last BPI fixes integrated, added dev-tutorial
1 parent c8ec5c1 commit 02bbe59

File tree

12 files changed

+795
-61
lines changed

12 files changed

+795
-61
lines changed

coop-extras/tutorial/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake ../../#dev-tutorial

coop-extras/tutorial/aux.bash

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
# shellcheck disable=SC2085,SC2155,SC2002,SC2003,SC2086
2+
JS_STORE_DIR=.json-fs-store
3+
COOP_PAB_DIR=.coop-pab-cli
4+
COOP_PUBLISHER_DIR=.coop-publisher-cli
5+
CLUSTER_DIR=.local-cluster # As specified in resources/pabConfig.yaml
6+
7+
WALLETS=.wallets
8+
9+
RESOURCES=resources
10+
11+
function clean {
12+
rm -fR $JS_STORE_DIR
13+
rm -fR $COOP_PAB_DIR
14+
rm -fR $COOP_PUBLISHER_DIR
15+
rm -fR $CLUSTER_DIR
16+
rm -fR $WALLETS
17+
}
18+
19+
function make-dirs {
20+
mkdir $JS_STORE_DIR
21+
mkdir $COOP_PAB_DIR
22+
mkdir $COOP_PUBLISHER_DIR
23+
mkdir $CLUSTER_DIR
24+
mkdir $CLUSTER_DIR/scripts
25+
mkdir $CLUSTER_DIR/txs
26+
mkdir $WALLETS
27+
}
28+
29+
# Generate TLS keys for Publisher, FactStatementStore and TxBuilder services
30+
function generate-keys {
31+
openssl genrsa -out $1/key.pem 2048
32+
openssl req -new -key $1/key.pem -out $1/certificate.csr -subj "/C=US/ST=st/L=l/O=o/OU=IT/CN=localhost"
33+
openssl x509 -req -in $1/certificate.csr -signkey $1/key.pem -out $1/certificate.pem -extfile $RESOURCES/ssl-extensions-x509.conf -extensions v3_ca -subj "/C=US/ST=st/L=l/O=o/OU=IT/CN=localhost"
34+
openssl x509 -text -in $1/certificate.pem
35+
}
36+
37+
# Prelude FactStatementStore
38+
function prelude-js-fs-store {
39+
sqlite3 -batch $JS_STORE_DIR/json-store.db ""
40+
json-fs-store-cli genesis --db $JS_STORE_DIR/json-store.db
41+
json-fs-store-cli insert-fact-statement --db $JS_STORE_DIR/json-store.db --fact_statement_id "someidA" --json "[1,2,3]"
42+
json-fs-store-cli insert-fact-statement --db $JS_STORE_DIR/json-store.db --fact_statement_id "someidB" --json "[4,5,6]"
43+
json-fs-store-cli insert-fact-statement --db $JS_STORE_DIR/json-store.db --fact_statement_id "someidC" --json "[7,8,9]"
44+
echo "SELECT * FROM fact_statements" | sqlite3 $JS_STORE_DIR/json-store.db
45+
}
46+
47+
# Run the FactStatementStore generic Json implementation
48+
function run-js-fs-store {
49+
json-fs-store-cli fact-statement-store-grpc --db $JS_STORE_DIR/json-store.db
50+
}
51+
52+
# Run the Plutip Local Cluster (cardano-node and wallet creation)
53+
function run-cluster {
54+
local-cluster --wallet-dir $WALLETS -n 10 --utxos 5 --chain-index-port 9084 --slot-len 1s --epoch-size 100000
55+
}
56+
57+
# Run manually to parse the config outputted by run-cluster
58+
function parse-cluster-config {
59+
cat > $COOP_PAB_DIR/plutip-cluster-config
60+
make-exports
61+
# So BPI doesn't have access to it
62+
mv $WALLETS/signing-key-$SUBMITTER_PKH.skey $WALLETS/my-key-$SUBMITTER_PKH.skey
63+
}
64+
65+
function make-exports {
66+
export GOD_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 1 PKH" | cut -d ":" -f 2 | xargs)
67+
export AA_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 2 PKH" | cut -d ":" -f 2 | xargs)
68+
export AUTH_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 3 PKH" | cut -d ":" -f 2 | xargs)
69+
export CERT_RDMR_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 4 PKH" | cut -d ":" -f 2 | xargs)
70+
export FEE_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 5 PKH" | cut -d ":" -f 2 | xargs)
71+
export SUBMITTER_PKH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep -E "Wallet 6 PKH" | cut -d ":" -f 2 | xargs)
72+
export CARDANO_NODE_SOCKET_PATH=$(cat $COOP_PAB_DIR/plutip-cluster-config | grep CardanoNodeConn | grep -E -o '"[^"]+"' | sed s/\"//g)
73+
}
74+
75+
function show-env {
76+
export | grep -E "WALLET|CARDANO_NODE_SOCKET_PATH"
77+
}
78+
79+
function coop-genesis {
80+
make-exports
81+
coop-pab-cli deploy --god-wallet $GOD_PKH --aa-wallet $AA_PKH
82+
}
83+
84+
function coop-mint-cert-redeemers {
85+
make-exports
86+
coop-pab-cli mint-cert-redeemers --cert-rdmr-wallet $CERT_RDMR_PKH --cert-rdmrs-to-mint 100
87+
}
88+
89+
function coop-mint-authentication {
90+
make-exports
91+
NOW=$(get-onchain-time) && coop-pab-cli mint-auth --aa-wallet $AA_PKH --certificate-valid-from $NOW --certificate-valid-to "$(expr $NOW + 60 \* 60 \* 1000)" --auth-wallet $AUTH_PKH
92+
}
93+
94+
function coop-redist-auth {
95+
make-exports
96+
coop-pab-cli redistribute-auth --auth-wallet $AUTH_PKH
97+
}
98+
99+
function coop-run-tx-builder-grpc {
100+
make-exports
101+
coop-pab-cli tx-builder-grpc --auth-wallet $AUTH_PKH --fee-wallet $FEE_PKH
102+
}
103+
104+
function coop-garbage-collect {
105+
make-exports
106+
coop-pab-cli garbage-collect --cert-rdmr-wallet $CERT_RDMR_PKH
107+
}
108+
109+
function coop-get-state {
110+
make-exports
111+
coop-pab-cli get-state --any-wallet ${GOD_PKH}
112+
cat $COOP_PAB_DIR/coop-state.json | json_pp
113+
}
114+
115+
function coop-poll-state {
116+
make-exports
117+
while true; do
118+
clear;
119+
coop-get-state;
120+
sleep 5;
121+
done;
122+
}
123+
124+
function get-onchain-time {
125+
make-exports
126+
coop-pab-cli get-state --any-wallet ${GOD_PKH} | grep "Current node client time range" | grep POSIXTime | grep -E -o "[0-9]+"
127+
}
128+
129+
function run-grpcui {
130+
make-exports
131+
grpcui -insecure -import-path $RESOURCES/coop-proto -proto $RESOURCES/coop-proto/tx-builder-service.proto localhost:5081
132+
}
133+
134+
function coop-mint-fs {
135+
make-exports
136+
resp=$(grpcurl -insecure -import-path $RESOURCES/coop-proto -proto $RESOURCES/coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.tx_builder.TxBuilder/createMintFsTx <<EOF
137+
{
138+
"factStatements": [
139+
{
140+
"fsId": "$(echo -ne 'the best id1' | base64)",
141+
"gcAfter": {
142+
"extended": "NEG_INF"
143+
},
144+
"fs": {
145+
"pdint": "1337"
146+
}
147+
},
148+
{
149+
"fsId": "$(echo -ne 'the best id2' | base64)",
150+
"gcAfter": {
151+
"extended": "NEG_INF"
152+
},
153+
"fs": {
154+
"pdbytes": "$(echo -ne 'some bytes' | base64)"
155+
}
156+
},
157+
{
158+
"fsId": "$(echo -ne 'the best id3' | base64)",
159+
"gcAfter": {
160+
"extended": "NEG_INF"
161+
},
162+
"fs": {
163+
"pdlist": {
164+
"elements": [
165+
{
166+
"pdint": "1337"
167+
}
168+
]
169+
}
170+
}
171+
},
172+
{
173+
"fsId": "$(echo -ne 'the best id4' | base64)",
174+
"gcAfter": {
175+
"extended": "FINITE",
176+
"finiteLedgerTime": "$(expr "$(get-onchain-time)" + 60 \* 60 \* 1000)"
177+
},
178+
"fs": {
179+
"pdlist": {
180+
"elements": [
181+
{
182+
"pdint": "1337"
183+
}
184+
]
185+
}
186+
}
187+
},
188+
{
189+
"fsId": "$(echo -ne 'the best id5' | base64)",
190+
"gcAfter": {
191+
"extended": "FINITE",
192+
"finiteLedgerTime": "$(expr "$(get-onchain-time)" + 60 \* 60 \* 1000)"
193+
},
194+
"fs": {
195+
"pdlist": {
196+
"elements": [
197+
{
198+
"pdint": "1337"
199+
}
200+
]
201+
}
202+
}
203+
}
204+
],
205+
"submitter": {
206+
"base16": "$SUBMITTER_PKH"
207+
}
208+
}
209+
EOF
210+
)
211+
rawTx=$(echo $resp | jq '.success.mintFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "Tx BabbageEra"')
212+
echo $resp | jq '.info'
213+
echo $resp | jq '.error'
214+
echo $rawTx > $COOP_PAB_DIR/signed
215+
}
216+
217+
function coop-gc-fs {
218+
make-exports
219+
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.tx_builder.TxBuilder/createGcFsTx <<EOF
220+
{
221+
"fsIds": ["eW==", "YXNkCg=="],
222+
"submitter": {
223+
"base16": "$SUBMITTER_PKH"
224+
}
225+
}
226+
227+
EOF
228+
)
229+
rawTx=$(echo $resp | jq '.success.gcFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "Tx BabbageEra"')
230+
echo $resp | jq '.info'
231+
echo $resp | jq '.error'
232+
echo $rawTx > $COOP_PAB_DIR/signed
233+
}
234+
235+
function cardano-cli-sign {
236+
make-exports
237+
cardano-cli transaction sign --tx-file $COOP_PAB_DIR/signed --signing-key-file $WALLETS/no-plutip-signing-key-$SUBMITTER_PKH.skey --out-file $COOP_PAB_DIR/ready
238+
}
239+
240+
function cardano-cli-submit {
241+
make-exports
242+
cardano-cli transaction submit --tx-file $COOP_PAB_DIR/ready --mainnet
243+
}
244+
245+
function coop-prelude {
246+
make-exports
247+
coop-genesis
248+
coop-mint-cert-redeemers
249+
coop-mint-authentication
250+
coop-redist-auth
251+
coop-run-tx-builder-grpc
252+
}

coop-extras/tutorial/build.nix

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{ pkgs
2+
, cardanoCli
3+
, cardanoNode
4+
, coopPabCli
5+
, coopPublisherCli
6+
, jsFsStoreCli
7+
, plutipLocalCluster
8+
, shellHook
9+
}:
10+
pkgs.mkShell {
11+
packages = with pkgs; [
12+
jq
13+
# json_pp
14+
sqlite
15+
protobuf
16+
protoc-gen-grpc-web
17+
haskellPackages.proto-lens-protoc
18+
nodePackages.npm
19+
nodejs
20+
grpcui
21+
grpcurl
22+
cardanoCli
23+
cardanoNode
24+
coopPabCli
25+
coopPublisherCli
26+
jsFsStoreCli
27+
plutipLocalCluster
28+
];
29+
30+
inherit shellHook;
31+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- Calling the cli locally or through an ssh connection
2+
cliLocation: local
3+
chainIndexUrl: "http://localhost:9084"
4+
networkId: Mainnet
5+
6+
-- Directory name of the script and data files
7+
scriptFileDir: ".local-cluster/scripts"
8+
9+
-- Directory for the signing key file(s)
10+
signingKeyFileDir: ".wallets"
11+
12+
-- Directory where the encoded transaction files will be saved
13+
txFileDir: ".local-cluster/txs"
14+
15+
-- Dry run mode will build the tx, but skip the submit step
16+
dryRun: false
17+
logLevel: debug
18+
port: 9080
19+
enableTxEndpoint: true
20+
21+
-- Save some stats during contract run (only transactions execution budgets supported atm)
22+
collectStats: true
23+
24+
-- Save logs from contract execution: pab request logs and contract logs
25+
collectLogs: true

0 commit comments

Comments
 (0)