Skip to content

Commit c8ec5c1

Browse files
committed
Added coop-pab-cli redistribute-auth helper command and cleaned up
1 parent af4bd12 commit c8ec5c1

File tree

7 files changed

+150
-23
lines changed

7 files changed

+150
-23
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module Coop.Cli.RedistributeAuth (RedistributeAuthOpts (..), redistributeAuth) where
2+
3+
import BotPlutusInterface.Config (loadPABConfig)
4+
import BotPlutusInterface.Types (PABConfig (pcOwnPubKeyHash))
5+
6+
import Control.Lens (makeLenses, (^.))
7+
import Coop.Pab (runRedistributeAuthsTrx)
8+
import Coop.Pab.Aux (runBpi)
9+
import Coop.Types (CoopDeployment)
10+
import Data.Aeson (decodeFileStrict)
11+
import Data.Foldable (for_)
12+
import Data.Maybe (fromMaybe)
13+
import Data.Text (Text)
14+
import Ledger (PaymentPubKeyHash (PaymentPubKeyHash))
15+
import Plutus.V2.Ledger.Api (PubKeyHash)
16+
17+
data RedistributeAuthOpts = RedistributeAuthOpts
18+
{ _pabConfig :: FilePath
19+
, _coopDeploymentFile :: FilePath
20+
, _howManyOutputs :: Int
21+
, _authWalletPkhs :: [PubKeyHash]
22+
}
23+
deriving stock (Show, Eq)
24+
25+
makeLenses ''RedistributeAuthOpts
26+
27+
redistributeAuth :: RedistributeAuthOpts -> IO ()
28+
redistributeAuth opts = do
29+
coopDeployment <- fromMaybe (error "redistributeAuth: Must have a CoopDeployment file in JSON") <$> decodeFileStrict @CoopDeployment (opts ^. coopDeploymentFile)
30+
pabConf <- either (\err -> error $ "redistributeAuth: Must have a PABConfig file in Config format: " <> err) id <$> loadPABConfig (opts ^. pabConfig)
31+
32+
for_
33+
(opts ^. authWalletPkhs)
34+
( \authWallet -> do
35+
(_, errOrAcs) <-
36+
runBpi @Text
37+
pabConf
38+
{ pcOwnPubKeyHash = authWallet
39+
}
40+
$ runRedistributeAuthsTrx
41+
coopDeployment
42+
(PaymentPubKeyHash authWallet)
43+
(opts ^. howManyOutputs)
44+
45+
either
46+
(\err -> error $ "redistributeAuth: Failed redistributing output for Authenticator " <> show authWallet <> "with error " <> show err)
47+
( \_ -> do
48+
putStrLn $ "redistributeAuth: Redistributed outputs for Authenticator " <> show authWallet
49+
)
50+
errOrAcs
51+
)

coop-pab/app/Main.hs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Coop.Cli.GarbageCollect (GarbageCollectOpts (GarbageCollectOpts), garbage
99
import Coop.Cli.GetState (GetStateOpts (GetStateOpts), getState)
1010
import Coop.Cli.MintAuth (MintAuthOpts (MintAuthOpts), mintAuth)
1111
import Coop.Cli.MintCertRdmrs (MintCertRdmrsOpts (MintCertRdmrsOpts), mintCertRdmrs)
12+
import Coop.Cli.RedistributeAuth (RedistributeAuthOpts (RedistributeAuthOpts), redistributeAuth)
1213
import Coop.Cli.TxBuilderGrpc (TxBuilderGrpcOpts (TxBuilderGrpcOpts), txBuilderService)
1314
import Options.Applicative (
1415
Parser,
@@ -42,6 +43,7 @@ data Command
4243
| GarbageCollect GarbageCollectOpts
4344
| GetState GetStateOpts
4445
| TxBuilderGrpc TxBuilderGrpcOpts
46+
| RedistributeAuth RedistributeAuthOpts
4547

4648
pabConfigOptP :: Parser [Char]
4749
pabConfigOptP =
@@ -277,6 +279,21 @@ txBuilderGrpcOpts =
277279
<> showDefault
278280
)
279281

282+
redistAuthOptsP :: Parser RedistributeAuthOpts
283+
redistAuthOptsP =
284+
RedistributeAuthOpts
285+
<$> pabConfigOptP
286+
<*> deploymentFileOptP
287+
<*> option
288+
auto
289+
( long "how-many-outputs"
290+
<> metavar "N_OUTPUTS"
291+
<> help "Number of outputs to create on an Authenticator each with 1 $AUTH token"
292+
<> value 10
293+
<> showDefault
294+
)
295+
<*> authWalletsOpt
296+
280297
optionsP :: Parser Command
281298
optionsP =
282299
subparser $
@@ -298,6 +315,9 @@ optionsP =
298315
<> command
299316
"tx-builder-grpc"
300317
(info (TxBuilderGrpc <$> txBuilderGrpcOpts <* helper) (progDesc "Run a TxBuilder gRpc service"))
318+
<> command
319+
"redistribute-auth"
320+
(info (RedistributeAuth <$> redistAuthOptsP <* helper) (progDesc "Redistribute Authenticator UTxOs with many $AUTH tokens into separate outputs with 1 $AUTH tokens"))
301321

302322
parserInfo :: ParserInfo Command
303323
parserInfo = info (optionsP <**> helper) (fullDesc <> progDesc "COOP PAB cli tools")
@@ -312,3 +332,4 @@ main = do
312332
GarbageCollect opts -> garbageCollect opts
313333
GetState opts -> getState opts
314334
TxBuilderGrpc opts -> txBuilderService opts
335+
RedistributeAuth opts -> redistributeAuth opts

coop-pab/aux.sh

Lines changed: 75 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ function coop-mint-authentication {
5454
NOW=$(get-onchain-time) && cabal run coop-pab-cli -- mint-auth --aa-wallet $AA_WALLET --certificate-valid-from $NOW --certificate-valid-to $(expr $NOW + 60 \* 60 \* 1000) --auth-wallet $AUTH_WALLET
5555
}
5656

57+
function coop-redist-auth {
58+
make-exports
59+
cabal run coop-pab-cli -- redistribute-auth --auth-wallet $AUTH_WALLET
60+
}
61+
5762
function coop-run-tx-builder-grpc {
5863
make-exports
5964
cabal run coop-pab-cli -- tx-builder-grpc --auth-wallet $AUTH_WALLET --fee-wallet $FEE_WALLET
@@ -91,24 +96,79 @@ function run-grpcui {
9196

9297
function coop-mint-fs {
9398
make-exports
94-
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.TxBuilder/createMintFsTx <<EOF
99+
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.tx_builder.TxBuilder/createMintFsTx <<EOF
100+
{
101+
"factStatements": [
102+
{
103+
"fsId": "$(echo -ne 'the best id1' | base64)",
104+
"gcAfter": {
105+
"extended": "NEG_INF"
106+
},
107+
"fs": {
108+
"pdint": "1337"
109+
}
110+
},
111+
{
112+
"fsId": "$(echo -ne 'the best id2' | base64)",
113+
"gcAfter": {
114+
"extended": "NEG_INF"
115+
},
116+
"fs": {
117+
"pdbytes": "$(echo -ne 'some bytes' | base64)"
118+
}
119+
},
95120
{
96-
"factStatements": [
121+
"fsId": "$(echo -ne 'the best id3' | base64)",
122+
"gcAfter": {
123+
"extended": "NEG_INF"
124+
},
125+
"fs": {
126+
"pdlist": {
127+
"elements": [
97128
{
98-
"fsId": "YXNkCg==",
99-
"gcAfter": {
100-
"extended": "NEG_INF"
101-
},
102-
"fs": {
103-
"pdint": "1337"
104-
}
129+
"pdint": "1337"
105130
}
106-
],
107-
"submitter": {
108-
"base16": "$SUBMITTER_WALLET"
131+
]
109132
}
133+
}
134+
},
135+
{
136+
"fsId": "$(echo -ne 'the best id4' | base64)",
137+
"gcAfter": {
138+
"extended": "FINITE",
139+
"finiteLedgerTime": "$(expr $(get-onchain-time) + 60 \* 60 \* 1000)"
140+
},
141+
"fs": {
142+
"pdlist": {
143+
"elements": [
144+
{
145+
"pdint": "1337"
146+
}
147+
]
148+
}
149+
}
150+
},
151+
{
152+
"fsId": "$(echo -ne 'the best id5' | base64)",
153+
"gcAfter": {
154+
"extended": "FINITE",
155+
"finiteLedgerTime": "$(expr $(get-onchain-time) + 60 \* 60 \* 1000)"
156+
},
157+
"fs": {
158+
"pdlist": {
159+
"elements": [
160+
{
161+
"pdint": "1337"
162+
}
163+
]
164+
}
165+
}
110166
}
111-
167+
],
168+
"submitter": {
169+
"base16": "$SUBMITTER_WALLET"
170+
}
171+
}
112172
EOF
113173
)
114174
rawTx=$(echo $resp | jq '.success.mintFsTx | .cborHex = .cborBase16 | del(.cborBase16) | .description = "" | .type = "Tx BabbageEra"')
@@ -119,7 +179,7 @@ EOF
119179

120180
function coop-gc-fs {
121181
make-exports
122-
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.TxBuilder/createGcFsTx <<EOF
182+
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/tx-builder-service.proto -d @ localhost:5081 coop.tx_builder.TxBuilder/createGcFsTx <<EOF
123183
{
124184
"fsIds": ["eW==", "YXNkCg=="],
125185
"submitter": {
@@ -150,5 +210,6 @@ function coop-prelude {
150210
coop-genesis
151211
coop-mint-cert-redeemers
152212
coop-mint-authentication
213+
coop-redist-auth
153214
coop-run-tx-builder-grpc
154215
}

coop-pab/coop-pab.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ executable coop-pab-cli
157157
Coop.Cli.GetState
158158
Coop.Cli.MintAuth
159159
Coop.Cli.MintCertRdmrs
160+
Coop.Cli.RedistributeAuth
160161
Coop.Cli.TxBuilderGrpc
161162

162163
build-depends:

coop-proto/cardano.proto

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ message TxOutRef {
2323
// Transaction ID
2424
TxId tx_id = 1;
2525
// The output index of the transaction denoted by the id
26-
int64 idx = 2;
26+
uint64 idx = 2;
2727
}
2828

2929
message ExtendedLedgerTime {
@@ -33,7 +33,7 @@ message ExtendedLedgerTime {
3333
POS_INF = 2;
3434
}
3535
Extended extended = 1;
36-
int32 finite_ledger_time = 2;
36+
uint64 finite_ledger_time = 2;
3737
}
3838

3939
// https://github.com/input-output-hk/plutus/blob/6aa7ba8142a16ada1a7b73eaa7210c55b41ac382/plutus-core/plutus-core/src/PlutusCore/Data.hs#L40

coop-publisher/Makefile

Lines changed: 0 additions & 5 deletions
This file was deleted.

coop-publisher/aux.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ function generate-keys {
88
openssl x509 -text -in $WORKDIR/certificate.pem
99
}
1010

11-
SUBMITTER_WALLET=2b0c9f64145896b8da237926a9ee664aed9923b455c7866fa241d218
12-
1311
function coop-mint-fs {
1412
resp=$(grpcurl -insecure -import-path ../coop-proto -proto ../coop-proto/publisher-service.proto -d @ localhost:5080 coop.publisher.Publisher/createMintFsTx <<EOF
1513
{

0 commit comments

Comments
 (0)