Skip to content

Commit c282432

Browse files
authored
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
1 parent 0961a2e commit c282432

4 files changed

Lines changed: 8 additions & 3 deletions

File tree

Src/ConsoleTool/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static class Constants
7070
{ "--signing-keys", "signingKeys" },
7171
{ "--send-all", "sendAll" },
7272
{ "--out-file", "outFile" },
73+
{ "--mock-witness-count", "mockWitnessCount"}
7374
//{ "--output-format", "outputFormat" },
7475
};
7576
}

Src/ConsoleTool/Cscli.ConsoleTool.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</ItemGroup>
3333
<ItemGroup>
3434
<PackageReference Include="CardanoSharp.Koios.Sdk" Version="5.0.2" />
35-
<PackageReference Include="CardanoSharp.Wallet" Version="2.9.0" />
35+
<PackageReference Include="CardanoSharp.Wallet" Version="2.14.0" />
3636
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
3737
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
3838
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />

Src/ConsoleTool/ShowBaseHelpCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ query info address --network <network> --address <payment_address>
4040
query info transaction --network <network> --tx-id <transaction_id>
4141
4242
Transaction Commands:
43-
BETA: transaction simple-payment build --network <network> --from <address> --to <address> (--ada <ada_amount> | --lovelaces <lovelace_amount> | --send-all true) [--ttl <slot_no>] [--signing-key <from_addr_payment_key>] [--submit true] [--message ""<string>""] [--out-file <output_path>]
43+
BETA: transaction simple-payment build --network <network> --from <address> --to <address> (--ada <ada_amount> | --lovelaces <lovelace_amount> | --send-all true) [--ttl <slot_no>] [--mock-witness-count <mock_witness_count>] [--signing-key <from_addr_payment_key>] [--submit true] [--message ""<string>""] [--out-file <output_path>]
4444
transaction view --network <network> --cbor-hex <hex_string>
4545
transaction sign --cbor-hex <hex_string> --signing-keys <comma_separated_bech32_skeys> [--out-file <output_path>]
4646
transaction submit --network <network> --cbor-hex <hex_string>

Src/ConsoleTool/Transaction/BuildSimplePaymentTransactionCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using CardanoSharp.Wallet.Utilities;
1111
using Cscli.ConsoleTool.Koios;
1212
using System.Text.Json;
13+
using CardanoSharp.Wallet.Models.Transactions;
1314
using static Cscli.ConsoleTool.Constants;
1415

1516
namespace Cscli.ConsoleTool.Transaction;
@@ -24,6 +25,7 @@ public class BuildSimplePaymentTransactionCommand : ICommand
2425
public decimal Ada { get; init; }
2526
public bool SendAll { get; init; } = false;
2627
public uint Ttl { get; set; } // Slot for transaction expiry
28+
public int? MockWitnessCount { get; set; } // Slot for transaction expiry
2729
public string? Message { get; init; } // Onchain Metadata 674 standard
2830
public bool Submit { get; init; } // Submits Transaction to Koios node
2931
public string? OutFile { get; init; } // cardano-cli compatible transaction file (signed only)
@@ -87,8 +89,10 @@ public async ValueTask<CommandResult> ExecuteAsync(CancellationToken ct)
8789
txBuilder.SetAuxData(auxDataBuilder);
8890
}
8991
var tx = txBuilder.Build();
92+
if(MockWitnessCount is not null && MockWitnessCount > 0)
93+
tx.TransactionWitnessSet = new TransactionWitnessSet();
9094
// Fee Calculation
91-
var fee = tx.CalculateAndSetFee(protocolParams.MinFeeA, protocolParams.MinFeeB);
95+
var fee = tx.CalculateAndSetFee(protocolParams.MinFeeA, protocolParams.MinFeeB, MockWitnessCount ?? 0);
9296
tx.TransactionBody.TransactionOutputs.Last().Value.Coin -= fee;
9397
var txCborBytes = tx.Serialize();
9498
if (!string.IsNullOrWhiteSpace(OutFile))

0 commit comments

Comments
 (0)