|
| 1 | +package iog.psg.cardano.experimental.cli |
| 2 | +import iog.psg.cardano.util.{CliCmd, ProcessBuilderHelper} |
| 3 | + |
| 4 | +import java.io.File |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +case class CardanoCli(builder: ProcessBuilderHelper) extends CliCmd { |
| 9 | + |
| 10 | + lazy val key: CardanoCliCmdKey = { |
| 11 | + CardanoCliCmdKey(builder.withCommand("key")) |
| 12 | + } |
| 13 | + |
| 14 | + lazy val address: CardanoCliCmdAddress = |
| 15 | + CardanoCliCmdAddress(builder.withCommand("address")) |
| 16 | + |
| 17 | + lazy val query: CardanoCliCmdQuery = { |
| 18 | + CardanoCliCmdQuery(builder.withCommand("query")) |
| 19 | + } |
| 20 | + |
| 21 | + lazy val transaction: CardanoCliCmdTransaction = { |
| 22 | + CardanoCliCmdTransaction(builder.withCommand("transaction")) |
| 23 | + } |
| 24 | + |
| 25 | +} |
| 26 | + |
| 27 | +case class CardanoCliCmdTransaction(protected val builder: ProcessBuilderHelper) extends CliCmd { |
| 28 | + lazy val calculateMinFee: CardanoCliCmdTransactionMinFee = { |
| 29 | + CardanoCliCmdTransactionMinFee(builder.withCommand("calculate-min-fee")) |
| 30 | + } |
| 31 | + |
| 32 | + lazy val buildRaw: CardanoCliCmdTransactionBuildRaw = { |
| 33 | + CardanoCliCmdTransactionBuildRaw(builder.withCommand("build-raw")) |
| 34 | + } |
| 35 | + |
| 36 | + lazy val witness: CardanoCliCmdTransactionWitness = { |
| 37 | + CardanoCliCmdTransactionWitness(builder.withCommand("witness")) |
| 38 | + } |
| 39 | + |
| 40 | + lazy val assemble: CardanoCliCmdTransactionAssemble = { |
| 41 | + CardanoCliCmdTransactionAssemble(builder.withCommand("assemble")) |
| 42 | + } |
| 43 | + |
| 44 | + lazy val submit: CardanoCliCmdTransactionSubmit = { |
| 45 | + CardanoCliCmdTransactionSubmit(builder.withCommand("submit")) |
| 46 | + } |
| 47 | + |
| 48 | +} |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + trait WitnessFile { |
| 53 | + self: CliCmd with CopyShim => |
| 54 | + |
| 55 | + def witnessFile(txBody: File): CONCRETECASECLASS = |
| 56 | + copier.copy(builder.withParam("--witness-file", txBody)) |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + trait SigningKeyFile { |
| 62 | + self: CliCmd with CopyShim => |
| 63 | + |
| 64 | + def signingKeyFile(scriptFile: File): CONCRETECASECLASS = |
| 65 | + copier.copy(builder.withParam("--signing-key-file", scriptFile)) |
| 66 | + |
| 67 | + } |
| 68 | + |
| 69 | + trait ScriptFile { |
| 70 | + self: CliCmd with CopyShim => |
| 71 | + |
| 72 | + def scriptFile(scriptFile: File): CONCRETECASECLASS = |
| 73 | + copier.copy(builder.withParam("--script-file", scriptFile)) |
| 74 | + |
| 75 | + } |
| 76 | + |
| 77 | + trait OutFile { |
| 78 | + self: CliCmd with CopyShim => |
| 79 | + |
| 80 | + def outFile(txBody: File): CONCRETECASECLASS = |
| 81 | + copier.copy(builder.withParam("--out-file", txBody)) |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + trait TxBodyFile { |
| 87 | + self: CliCmd with CopyShim => |
| 88 | + |
| 89 | + def txBodyFile(txBody: File): CONCRETECASECLASS = |
| 90 | + copier.copy(builder.withParam("--tx-body-file", txBody)) |
| 91 | + |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + trait MaryEra { |
| 96 | + self: CliCmd with CopyShim => |
| 97 | + |
| 98 | + lazy val maryEra:CONCRETECASECLASS = |
| 99 | + copier.copy(builder.withParam("--mary-era")) |
| 100 | + |
| 101 | + } |
| 102 | + |
| 103 | + trait TxFile { |
| 104 | + self: CliCmd with CopyShim => |
| 105 | + |
| 106 | + def txFile(txFile: File):CONCRETECASECLASS = |
| 107 | + copier.copy(builder.withParam("--tx-file", txFile)) |
| 108 | + |
| 109 | + } |
| 110 | + |
| 111 | + trait TestnetMagic { |
| 112 | + self: CliCmd with CopyShim => |
| 113 | + |
| 114 | + lazy val mainnet: CONCRETECASECLASS = { |
| 115 | + copier.copy(builder |
| 116 | + .withParam("--mainnet")) |
| 117 | + } |
| 118 | + |
| 119 | + def testnetMagic(magic: Long): CONCRETECASECLASS = { |
| 120 | + copier.copy(builder |
| 121 | + .withParam("--testnet-magic", magic.toString)) |
| 122 | + } |
| 123 | + } |
| 124 | + |
| 125 | + case class CardanoCliCmdTransactionSubmit(protected val builder: ProcessBuilderHelper) |
| 126 | + extends CliCmd |
| 127 | + with TestnetMagic |
| 128 | + with CopyShim |
| 129 | + with TxFile { |
| 130 | + |
| 131 | + |
| 132 | + type CONCRETECASECLASS = CardanoCliCmdTransactionSubmit |
| 133 | + protected def copier = this |
| 134 | + |
| 135 | + def run() = exitValue() |
| 136 | + |
| 137 | + } |
| 138 | + |
| 139 | + case class CardanoCliCmdTransactionBuildRaw(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 140 | + //TODO |
| 141 | + } |
| 142 | + |
| 143 | + case class CardanoCliCmdTransactionWitness(protected val builder: ProcessBuilderHelper) |
| 144 | + extends CliCmd |
| 145 | + with CopyShim |
| 146 | + with TxBodyFile |
| 147 | + with OutFile |
| 148 | + with TestnetMagic |
| 149 | + with ScriptFile |
| 150 | + with SigningKeyFile { |
| 151 | + |
| 152 | + override type CONCRETECASECLASS = CardanoCliCmdTransactionWitness |
| 153 | + val copier = this |
| 154 | + |
| 155 | + |
| 156 | + } |
| 157 | + |
| 158 | + case class CardanoCliCmdTransactionAssemble(protected val builder: ProcessBuilderHelper) extends CliCmd |
| 159 | + with TxBodyFile with OutFile with WitnessFile with CopyShim { |
| 160 | + |
| 161 | + override type CONCRETECASECLASS = CardanoCliCmdTransactionAssemble |
| 162 | + val copier = this |
| 163 | + |
| 164 | + } |
| 165 | + |
| 166 | + |
| 167 | + case class CardanoCliCmdTransactionMinFee(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 168 | + |
| 169 | + def protocolParamsFile(protocolParams: File): CardanoCliCmdTransactionMinFee = |
| 170 | + copy(builder.withParam("--protocol-params-file", protocolParams)) |
| 171 | + |
| 172 | + def txInCount(in: Int): CardanoCliCmdTransactionMinFee = |
| 173 | + copy(builder.withParam("--tx-in-count", in.toString)) |
| 174 | + |
| 175 | + def txOutCount(out: Int): CardanoCliCmdTransactionMinFee = |
| 176 | + copy(builder.withParam("--tx-out-count", out.toString)) |
| 177 | + |
| 178 | + def witnessCount(witnessCount: Int):CardanoCliCmdTransactionMinFee = |
| 179 | + copy(builder.withParam("--witness-count", witnessCount.toString)) |
| 180 | + |
| 181 | + def run(): String = stringValue() |
| 182 | + } |
| 183 | + |
| 184 | + |
| 185 | + case class CardanoCliCmdAddressBuild(protected val builder: ProcessBuilderHelper) |
| 186 | + extends CliCmd |
| 187 | + with TestnetMagic |
| 188 | + with CopyShim |
| 189 | + with OutFile { |
| 190 | + |
| 191 | + |
| 192 | + override type CONCRETECASECLASS = CardanoCliCmdAddressBuild |
| 193 | + val copier = this |
| 194 | + |
| 195 | + def paymentVerificationKey(verificationKey: String): CardanoCliCmdAddressBuild = |
| 196 | + CardanoCliCmdAddressBuild(builder.withParam("--payment-verification-key", verificationKey)) |
| 197 | + |
| 198 | + def paymentVerificationKeyFile(verificationKeyFile: File): CardanoCliCmdAddressBuild = |
| 199 | + CardanoCliCmdAddressBuild(builder.withParam("--payment-verification-key-file", verificationKeyFile)) |
| 200 | + |
| 201 | + def paymentScriptFile(paymentScriptFile: File): CardanoCliCmdAddressBuild = |
| 202 | + CardanoCliCmdAddressBuild(builder.withParam("--payment-script-file", paymentScriptFile)) |
| 203 | + |
| 204 | + |
| 205 | + def run(): Int = exitValue() |
| 206 | + |
| 207 | + } |
| 208 | + |
| 209 | + case class CardanoCliCmdAddressBuildScript(protected val builder: ProcessBuilderHelper) |
| 210 | + extends CliCmd |
| 211 | + with TestnetMagic |
| 212 | + with CopyShim |
| 213 | + with OutFile |
| 214 | + with ScriptFile { |
| 215 | + |
| 216 | + |
| 217 | + override type CONCRETECASECLASS = CardanoCliCmdAddressBuildScript |
| 218 | + val copier = this |
| 219 | + |
| 220 | + def run(): Int = exitValue() |
| 221 | + |
| 222 | + } |
| 223 | + |
| 224 | + case class CardanoCliCmdAddress(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 225 | + |
| 226 | + lazy val keyHash:CardanoCliCmdAddressKeyHash = |
| 227 | + CardanoCliCmdAddressKeyHash(builder.withParam("key-hash")) |
| 228 | + |
| 229 | + lazy val keyGen:CardanoCliCmdAddressKeyGen = |
| 230 | + CardanoCliCmdAddressKeyGen(builder.withParam("key-gen")) |
| 231 | + |
| 232 | + lazy val buildScript:CardanoCliCmdAddressBuildScript = |
| 233 | + CardanoCliCmdAddressBuildScript(builder.withParam("build-script")) |
| 234 | + |
| 235 | + lazy val build:CardanoCliCmdAddressBuild = |
| 236 | + CardanoCliCmdAddressBuild(builder.withParam("build")) |
| 237 | + |
| 238 | + } |
| 239 | + |
| 240 | + case class CardanoCliCmdAddressKeyHash(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 241 | + def paymentVerificationString(bech32EncodedKey: String): CardanoCliCmdAddressKeyHashString = |
| 242 | + CardanoCliCmdAddressKeyHashString(builder.withParam("--payment-verification-key", bech32EncodedKey)) |
| 243 | + |
| 244 | + def paymentVerificationFile(pathToBech32EncodedKey: File): CardanoCliCmdAddressKeyHashFile = |
| 245 | + CardanoCliCmdAddressKeyHashFile(builder.withParam("--payment-verification-key-file", pathToBech32EncodedKey)) |
| 246 | + } |
| 247 | + |
| 248 | + case class CardanoCliCmdAddressKeyHashFile(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 249 | + def run(): String = stringValue() |
| 250 | + } |
| 251 | + |
| 252 | + case class CardanoCliCmdAddressKeyHashString(protected val builder: ProcessBuilderHelper) extends CliCmd |
| 253 | + |
| 254 | + |
| 255 | + case class CardanoCliCmdAddressKeyGen(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 256 | + lazy val normalKey: CardanoCliCmdAddressKeyGenNormalKey = |
| 257 | + CardanoCliCmdAddressKeyGenNormalKey(builder.withParam("--normal-key")) |
| 258 | + |
| 259 | + def verificationKeyFile(verificationKeyFile: File): CardanoCliCmdAddressKeyGen = { |
| 260 | + CardanoCliCmdAddressKeyGen( |
| 261 | + builder.withParam("--verification-key-file", |
| 262 | + verificationKeyFile)) |
| 263 | + } |
| 264 | + |
| 265 | + def signingKeyFile(signingKeyFile: File): CardanoCliCmdAddressKeyGen = { |
| 266 | + CardanoCliCmdAddressKeyGen( |
| 267 | + builder.withParam("--signing-key-file", |
| 268 | + signingKeyFile)) |
| 269 | + } |
| 270 | + |
| 271 | + } |
| 272 | + |
| 273 | + case class CardanoCliCmdAddressKeyGenNormalKey(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 274 | + def run(): Int = exitValue() |
| 275 | + } |
| 276 | + |
| 277 | + case class CardanoCliCmdQuery(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 278 | + |
| 279 | + /* |
| 280 | + protocol-parameters | tip | stake-distribution | |
| 281 | + stake-address-info | utxo | ledger-state | |
| 282 | + protocol-state | stake-snapshot | pool-params |
| 283 | + */ |
| 284 | + lazy val protocolParameters: CardanoCliCmdQueryProtocol = { |
| 285 | + CardanoCliCmdQueryProtocol(builder.withCommand("protocol-parameters")) |
| 286 | + } |
| 287 | + |
| 288 | + lazy val utxo: CardanoCliCmdQueryUtxo = { |
| 289 | + CardanoCliCmdQueryUtxo(builder.withCommand("utxo")) |
| 290 | + } |
| 291 | + } |
| 292 | + |
| 293 | + case class CardanoCliCmdQueryUtxo(protected val builder: ProcessBuilderHelper) |
| 294 | + extends CliCmd { |
| 295 | + |
| 296 | + def address(address:String): CardanoCliCmdQueryUtxo = |
| 297 | + copy(builder = builder.withParam("--address", address)) |
| 298 | + |
| 299 | + def testnetMagic(magic: String): CardanoCliCmdQueryUtxo = { |
| 300 | + copy(builder.withParam("--testnet-magic", magic)) |
| 301 | + } |
| 302 | + |
| 303 | + def outFile(outFile:File): CardanoCliCmdQueryUtxo = { |
| 304 | + copy(builder.withParam("--out-file", outFile)) |
| 305 | + } |
| 306 | + |
| 307 | + def run(): Int = exitValue() |
| 308 | + |
| 309 | + } |
| 310 | + case class CardanoCliCmdKey(protected val builder: ProcessBuilderHelper) extends CliCmd{ |
| 311 | + |
| 312 | + // lazy val verificationKey = ??? |
| 313 | + // lazy val nonExtendedKey = ??? |
| 314 | + // lazy val convertByronKey = ??? |
| 315 | + //// lazy val convert-byron-genesis-vkey = ??? |
| 316 | + //// lazy val convert-itn-key = ??? |
| 317 | + /// lazy val convert-itn-extended-key = ??? |
| 318 | + // lazy val convert-itn-bip32-key = ??? |
| 319 | + // lazy val convertCardanoAddressKey = ??? |
| 320 | + |
| 321 | + throw new IllegalArgumentException("NOT IMPLEMENTED") |
| 322 | + } |
| 323 | + |
| 324 | + case class CardanoCliCmdQueryProtocol(builder: ProcessBuilderHelper) |
| 325 | + extends CliCmd |
| 326 | + with TestnetMagic |
| 327 | + with MaryEra |
| 328 | + with OutFile |
| 329 | + with CopyShim { |
| 330 | + |
| 331 | + |
| 332 | + override type CONCRETECASECLASS = CardanoCliCmdQueryProtocol |
| 333 | + val copier = this |
| 334 | + |
| 335 | + lazy val shellyMode: CardanoCliCmdQueryProtocol = { |
| 336 | + CardanoCliCmdQueryProtocol(builder.withParam("--shelly-mode")) |
| 337 | + } |
| 338 | + |
| 339 | + def run(): Seq[String] = { |
| 340 | + allValues() |
| 341 | + } |
| 342 | + |
| 343 | + } |
| 344 | + |
| 345 | + |
0 commit comments