Skip to content

Commit

Permalink
Add Mock option to Tx Building (#11)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
nothingalike authored Oct 13, 2022
1 parent 0961a2e commit c282432
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Src/ConsoleTool/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public static class Constants
{ "--signing-keys", "signingKeys" },
{ "--send-all", "sendAll" },
{ "--out-file", "outFile" },
{ "--mock-witness-count", "mockWitnessCount"}
//{ "--output-format", "outputFormat" },
};
}
2 changes: 1 addition & 1 deletion Src/ConsoleTool/Cscli.ConsoleTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="CardanoSharp.Koios.Sdk" Version="5.0.2" />
<PackageReference Include="CardanoSharp.Wallet" Version="2.9.0" />
<PackageReference Include="CardanoSharp.Wallet" Version="2.14.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="6.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion Src/ConsoleTool/ShowBaseHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ query info address --network <network> --address <payment_address>
query info transaction --network <network> --tx-id <transaction_id>
Transaction Commands:
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>]
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>]
transaction view --network <network> --cbor-hex <hex_string>
transaction sign --cbor-hex <hex_string> --signing-keys <comma_separated_bech32_skeys> [--out-file <output_path>]
transaction submit --network <network> --cbor-hex <hex_string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -87,8 +89,10 @@ public async ValueTask<CommandResult> 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))
Expand Down

0 comments on commit c282432

Please sign in to comment.