Skip to content

Commit

Permalink
Changed Json output to ToJson() method from ToString()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Williams committed Jan 8, 2018
1 parent 8c5fa54 commit c2b8516
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ paymentTransaction.Amount = new Currency { ValueAsXrp = 1 };
paymentTransaction.Sequence = accountInfo.AccountData.Sequence;

TxSigner signer = TxSigner.FromSecret("xxxxxxx"); //secret is not sent to server, offline signing only
SignedTx signedTx = signer.SignJson(JObject.Parse(paymentTransaction.ToString()));
SignedTx signedTx = signer.SignJson(JObject.Parse(paymentTransaction.ToJson()));

SubmitBlobRequest request = new SubmitBlobRequest();
request.TransactionBlob = signedTx.TxBlob;
Expand Down
6 changes: 6 additions & 0 deletions src/RippleDotNet/Model/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ public enum ServerState
Proposing
}

[Flags]
public enum TransactionFlags : uint
{
tfFullyCanonicalSig = 2147483648
}

[Flags]
public enum PaymentFlags : uint
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ITransactionCommon

Currency Fee { get; set; }

uint? Flags { get; set; }
TransactionFlags? Flags { get; set; }

uint? LastLedgerSequence { get; set; }

Expand All @@ -29,6 +29,6 @@ public interface ITransactionCommon

TransactionType TransactionType { get; set; }

string ToString();
string ToJson();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public AccountSetTransaction()
TransactionType = TransactionType.AccountSet;
}

public AccountSetTransaction(string account) : this()
{
Account = account;
}

public uint? ClearFlag { get; set; }

public string Domain { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ namespace RippleDotNet.Model.Transaction.TransactionTypes
[JsonConverter(typeof(TransactionConverter))]
public abstract class TransactionCommon : ITransactionCommon
{
protected TransactionCommon()
{
Fee = new Currency {Value = "10"};
}

/// <summary>
/// This is a required field
/// </summary>
public string Account { get; set; }

public string AccountTxnID { get; set; }

[JsonConverter(typeof(CurrencyConverter))]
public Currency Fee { get; set; }

public uint? Flags { get; set; }
public TransactionFlags? Flags { get; set; }

/// <summary>
/// Although optional, the LastLedgerSequence is strongly recommended on every transaction to ensure it's validated or rejected promptly.
Expand All @@ -26,6 +34,9 @@ public abstract class TransactionCommon : ITransactionCommon

public List<Memo> Memos { get; set; }

/// <summary>
/// This is a required field
/// </summary>
public uint? Sequence { get; set; }

[JsonProperty("SigningPubKey")]
Expand All @@ -42,7 +53,7 @@ public abstract class TransactionCommon : ITransactionCommon
[JsonProperty("meta")]
public Meta Meta { get; set; }

public override string ToString()
public string ToJson()
{
JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
serializerSettings.NullValueHandling = NullValueHandling.Ignore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ITransactionResponseCommon : IBaseTransactionResponse
string Account { get; set; }
string AccountTxnID { get; set; }
Currency Fee { get; set; }
uint? Flags { get; set; }
TransactionFlags? Flags { get; set; }
uint? LastLedgerSequence { get; set; }
List<Memo> Memos { get; set; }
Meta Meta { get; set; }
Expand All @@ -19,6 +19,6 @@ public interface ITransactionResponseCommon : IBaseTransactionResponse
string TransactionSignature { get; set; }
TransactionType TransactionType { get; set; }

string ToString();
string ToJson();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Newtonsoft.Json;
using RippleDotNet.Json.Converters;
using RippleDotNet.Model.Transaction.Interfaces;
using RippleDotNet.Responses.Transaction.Interfaces;

namespace RippleDotNet.Responses.Transaction.TransactionTypes
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public abstract class TransactionResponseCommon : BaseTransactionResponse, ITran
[JsonConverter(typeof(CurrencyConverter))]
public Currency Fee { get; set; }

public uint? Flags { get; set; }
public TransactionFlags? Flags { get; set; }

/// <summary>
/// Although optional, the LastLedgerSequence is strongly recommended on every transaction to ensure it's validated or rejected promptly.
Expand All @@ -46,7 +46,7 @@ public abstract class TransactionResponseCommon : BaseTransactionResponse, ITran
[JsonProperty("meta")]
public Meta Meta { get; set; }

public override string ToString()
public string ToJson()
{
JsonSerializerSettings serializerSettings = new JsonSerializerSettings();
serializerSettings.NullValueHandling = NullValueHandling.Ignore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace RippleDotNet.Responses.Transaction.TransactionTypes
{
public class TrustSetTransactionResponse : TransactionResponseCommon, ITrustSetTransaction
{
public TrustSetFlags? Flags { get; set; }
public new TrustSetFlags? Flags { get; set; }

[JsonConverter(typeof(CurrencyConverter))]
public Currency LimitAmount { get; set; }
Expand Down
22 changes: 11 additions & 11 deletions test/RippleDotNet.Tests/TransactionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void CanCreatePaymentTransaction()

const string expectedResult = "{\"Amount\":\"1000000\",\"Destination\":\"rEqtEHKbinqm18wQSQGstmqg9SFpUELasT\",\"Flags\":2147483648,\"Account\":\"rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V\",\"TransactionType\":\"Payment\"}";

Assert.AreEqual(expectedResult, paymentTransaction.ToString());
Assert.AreEqual(expectedResult, paymentTransaction.ToJson());
}

[TestMethod]
Expand Down Expand Up @@ -131,7 +131,7 @@ public async Task CanSubmitPaymentTransaction()
paymentTransaction.Sequence = accountInfo.AccountData.Sequence;
paymentTransaction.Fee = new Currency{Value = "15"};

var json = paymentTransaction.ToString();
var json = paymentTransaction.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand All @@ -154,7 +154,7 @@ public async Task CanEstablishTrust()
trustSet.Account = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
trustSet.Sequence = accountInfo.AccountData.Sequence;

var json = trustSet.ToString();
var json = trustSet.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand Down Expand Up @@ -205,7 +205,7 @@ public async Task CanSetOffer()
offerCreate.Expiration = DateTime.UtcNow.AddHours(1);
offerCreate.Account = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";

var json = offerCreate.ToString();
var json = offerCreate.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand Down Expand Up @@ -246,7 +246,7 @@ public async Task CanFillOrder()
offerCreate.Expiration = DateTime.UtcNow.AddHours(1);
offerCreate.Account = "rEqtEHKbinqm18wQSQGstmqg9SFpUELasT";

var json = offerCreate.ToString();
var json = offerCreate.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand All @@ -273,7 +273,7 @@ public async Task CanDeleteTrust()
trustSet.Sequence = accountInfo.AccountData.Sequence;
trustSet.Fee = new Currency {Value = "12"};

var json = trustSet.ToString();
var json = trustSet.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand All @@ -295,9 +295,9 @@ public async Task CanReleaseEscrow()
escrowFinishTransaction.Owner = "r9NpyVfLfUG8hatuCCHKzosyDtKnBdsEN3";
escrowFinishTransaction.OfferSequence = 10;
escrowFinishTransaction.Fee = new Currency{Value = "15"};
escrowFinishTransaction.Flags = 2147483648;
escrowFinishTransaction.Flags = TransactionFlags.tfFullyCanonicalSig;

var json = escrowFinishTransaction.ToString();
var json = escrowFinishTransaction.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand Down Expand Up @@ -327,7 +327,7 @@ public async Task CanCreateEscrow()
createTransaction.Fee = new Currency{Value = "11"};
createTransaction.Sequence = accountInfo.AccountData.Sequence;

var json = createTransaction.ToString();
var json = createTransaction.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand All @@ -353,10 +353,10 @@ public async Task CanFinishEscrow()
finishTransaction.Owner = "rwEHFU98CjH59UX2VqAgeCzRFU9KVvV71V";
finishTransaction.OfferSequence = 29;
finishTransaction.Fee = new Currency { Value = "11" };
finishTransaction.Flags = 2147483648;
finishTransaction.Flags = TransactionFlags.tfFullyCanonicalSig;
finishTransaction.Sequence = accountInfo.AccountData.Sequence;

var json = finishTransaction.ToString();
var json = finishTransaction.ToJson();
TxSigner signer = TxSigner.FromSecret("xxxxxxx");
SignedTx signedTx = signer.SignJson(JObject.Parse(json));

Expand Down

0 comments on commit c2b8516

Please sign in to comment.