From c2824326ba6a05de304959708f1290385569c0d0 Mon Sep 17 00:00:00 2001 From: Kyle Johns Date: Wed, 12 Oct 2022 20:02:34 -0400 Subject: [PATCH] Add Mock option to Tx Building (#11) * mock option implemented but need CardanoSharp lib update before proceeding * ok updated cardanosharp for the new mocking feature and got cli to capture the --mock-witness-count value. * updated the approach used to remove mocked vkey witnesses. * updated cardanosharp. this update will remove mocks for us after calculating fee * updated cs wallet and corrected the mock * removed unnecessary edit * with current implementation of cs wallet, it expects TransactionWitnessSet to be initialized --- Src/ConsoleTool/Constants.cs | 1 + Src/ConsoleTool/Cscli.ConsoleTool.csproj | 2 +- Src/ConsoleTool/ShowBaseHelpCommand.cs | 2 +- .../Transaction/BuildSimplePaymentTransactionCommand.cs | 6 +++++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Src/ConsoleTool/Constants.cs b/Src/ConsoleTool/Constants.cs index 04bdedf..d8018ff 100644 --- a/Src/ConsoleTool/Constants.cs +++ b/Src/ConsoleTool/Constants.cs @@ -70,6 +70,7 @@ public static class Constants { "--signing-keys", "signingKeys" }, { "--send-all", "sendAll" }, { "--out-file", "outFile" }, + { "--mock-witness-count", "mockWitnessCount"} //{ "--output-format", "outputFormat" }, }; } \ No newline at end of file diff --git a/Src/ConsoleTool/Cscli.ConsoleTool.csproj b/Src/ConsoleTool/Cscli.ConsoleTool.csproj index 55ea4f0..89fe9c1 100644 --- a/Src/ConsoleTool/Cscli.ConsoleTool.csproj +++ b/Src/ConsoleTool/Cscli.ConsoleTool.csproj @@ -32,7 +32,7 @@ - + diff --git a/Src/ConsoleTool/ShowBaseHelpCommand.cs b/Src/ConsoleTool/ShowBaseHelpCommand.cs index 85a06eb..80970a5 100644 --- a/Src/ConsoleTool/ShowBaseHelpCommand.cs +++ b/Src/ConsoleTool/ShowBaseHelpCommand.cs @@ -40,7 +40,7 @@ query info address --network --address query info transaction --network --tx-id Transaction Commands: - BETA: transaction simple-payment build --network --from
--to
(--ada | --lovelaces | --send-all true) [--ttl ] [--signing-key ] [--submit true] [--message """"] [--out-file ] + BETA: transaction simple-payment build --network --from
--to
(--ada | --lovelaces | --send-all true) [--ttl ] [--mock-witness-count ] [--signing-key ] [--submit true] [--message """"] [--out-file ] transaction view --network --cbor-hex transaction sign --cbor-hex --signing-keys [--out-file ] transaction submit --network --cbor-hex diff --git a/Src/ConsoleTool/Transaction/BuildSimplePaymentTransactionCommand.cs b/Src/ConsoleTool/Transaction/BuildSimplePaymentTransactionCommand.cs index 8d5d05d..4b38b56 100644 --- a/Src/ConsoleTool/Transaction/BuildSimplePaymentTransactionCommand.cs +++ b/Src/ConsoleTool/Transaction/BuildSimplePaymentTransactionCommand.cs @@ -10,6 +10,7 @@ using CardanoSharp.Wallet.Utilities; using Cscli.ConsoleTool.Koios; using System.Text.Json; +using CardanoSharp.Wallet.Models.Transactions; using static Cscli.ConsoleTool.Constants; namespace Cscli.ConsoleTool.Transaction; @@ -24,6 +25,7 @@ public class BuildSimplePaymentTransactionCommand : ICommand public decimal Ada { get; init; } public bool SendAll { get; init; } = false; public uint Ttl { get; set; } // Slot for transaction expiry + public int? MockWitnessCount { get; set; } // Slot for transaction expiry public string? Message { get; init; } // Onchain Metadata 674 standard public bool Submit { get; init; } // Submits Transaction to Koios node public string? OutFile { get; init; } // cardano-cli compatible transaction file (signed only) @@ -87,8 +89,10 @@ public async ValueTask ExecuteAsync(CancellationToken ct) txBuilder.SetAuxData(auxDataBuilder); } var tx = txBuilder.Build(); + if(MockWitnessCount is not null && MockWitnessCount > 0) + tx.TransactionWitnessSet = new TransactionWitnessSet(); // Fee Calculation - var fee = tx.CalculateAndSetFee(protocolParams.MinFeeA, protocolParams.MinFeeB); + var fee = tx.CalculateAndSetFee(protocolParams.MinFeeA, protocolParams.MinFeeB, MockWitnessCount ?? 0); tx.TransactionBody.TransactionOutputs.Last().Value.Coin -= fee; var txCborBytes = tx.Serialize(); if (!string.IsNullOrWhiteSpace(OutFile))