Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
feat: generate v1 transactions by default
Browse files Browse the repository at this point in the history
  • Loading branch information
fracek committed Jun 15, 2020
1 parent 583d960 commit 4090a9b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
29 changes: 20 additions & 9 deletions stellar-dotnet-sdk-test/TransactionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public void TestOldTransactionBuilder()

Assert.AreEqual(
"AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAEqBfIAAAAAAAAAAABtoeVYgAAAEDLki9Oi700N60Lo8gUmEFHbKvYG4QSqXiLIt9T0ru2O5BphVl/jR9tYtHAD+UeDYhgXNgwUxqTEu1WukvEyYcD",
transaction.ToEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V0));

Assert.AreEqual(
"AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAy5IvTou9NDetC6PIFJhBR2yr2BuEEql4iyLfU9K7tjuQaYVZf40fbWLRwA/lHg2IYFzYMFMakxLtVrpLxMmHAw==",
transaction.ToEnvelopeXdrBase64());

Assert.AreEqual(transaction.SourceAccount.AccountId, source.AccountId);
Expand All @@ -70,6 +74,10 @@ public void TestBuilderSuccessTestnet()

Assert.AreEqual(
"AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAEqBfIAAAAAAAAAAABtoeVYgAAAEDLki9Oi700N60Lo8gUmEFHbKvYG4QSqXiLIt9T0ru2O5BphVl/jR9tYtHAD+UeDYhgXNgwUxqTEu1WukvEyYcD",
transaction.ToEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V0));

Assert.AreEqual(
"AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAy5IvTou9NDetC6PIFJhBR2yr2BuEEql4iyLfU9K7tjuQaYVZf40fbWLRwA/lHg2IYFzYMFMakxLtVrpLxMmHAw==",
transaction.ToEnvelopeXdrBase64());

Assert.AreEqual(transaction.SourceAccount.AccountId, source.AccountId);
Expand Down Expand Up @@ -129,6 +137,10 @@ public void TestBuilderMemoText()

Assert.AreEqual(
"AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAEAAAAMSGVsbG8gd29ybGQhAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABAxzofBhoayuUnz8t0T1UNWrTgmJ+lCh9KaeOGu2ppNOz9UGw0abGLhv+9oWQsstaHx6YjwWxL+8GBvwBUVWRlBQ==",
transaction.ToEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V0));

Assert.AreEqual(
"AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAABAAAADEhlbGxvIHdvcmxkIQAAAAEAAAAAAAAAAAAAAADt4FJhvNwvlQqjuhc7bjLVyRf5e4K2QOzI0c6nWfVvEAAAAASoF8gAAAAAAAAAAAG2h5ViAAAAQMc6HwYaGsrlJ8/LdE9VDVq04JifpQofSmnjhrtqaTTs/VBsNGmxi4b/vaFkLLLWh8emI8FsS/vBgb8AVFVkZQU=",
transaction.ToEnvelopeXdrBase64());

var transaction2 = Transaction.FromEnvelopeXdr(transaction.ToEnvelopeXdr());
Expand Down Expand Up @@ -160,10 +172,7 @@ public void TestBuilderTimeBounds()
transaction.Sign(source);

// Convert transaction to binary XDR and back again to make sure timebounds are correctly de/serialized.
var bytes = transaction.ToEnvelopeXdrBase64().ToCharArray();
var xdrDataInputStream = new XdrDataInputStream(Convert.FromBase64CharArray(bytes, 0, bytes.Length));

var decodedTransaction = XdrTransaction.Decode(xdrDataInputStream);
var decodedTransaction = transaction.ToEnvelopeXdr().V1.Tx;

Assert.AreEqual(decodedTransaction.TimeBounds.MinTime.InnerValue.InnerValue, 42U);
Assert.AreEqual(decodedTransaction.TimeBounds.MaxTime.InnerValue.InnerValue, 1337U);
Expand Down Expand Up @@ -196,10 +205,7 @@ public void TestBuilderFee()
.Build();

// Convert transaction to binary XDR and back again to make sure fee is correctly de/serialized.
var bytes = transaction.ToUnsignedEnvelopeXdrBase64().ToCharArray();
var xdrDataInputStream = new XdrDataInputStream(Convert.FromBase64CharArray(bytes, 0, bytes.Length));

var decodedTransaction = XdrTransaction.Decode(xdrDataInputStream);
var decodedTransaction = transaction.ToUnsignedEnvelopeXdr().V1.Tx;

Assert.AreEqual(decodedTransaction.Fee.InnerValue, 173 * 2U);

Expand Down Expand Up @@ -238,7 +244,12 @@ public void TestBuilderSuccessPublic()

Assert.AreEqual(
"AAAAAF7FIiDToW1fOYUFBC0dmyufJbFTOa2GQESGz+S2h5ViAAAAZAAKVaMAAAABAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAEqBfIAAAAAAAAAAABtoeVYgAAAEDzfR5PgRFim5Wdvq9ImdZNWGBxBWwYkQPa9l5iiBdtPLzAZv6qj+iOfSrqinsoF0XrLkwdIcZQVtp3VRHhRoUE",
transaction.ToEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V0));

Assert.AreEqual(
"AAAAAgAAAABexSIg06FtXzmFBQQtHZsrnyWxUzmthkBEhs/ktoeVYgAAAGQAClWjAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAO3gUmG83C+VCqO6FztuMtXJF/l7grZA7MjRzqdZ9W8QAAAABKgXyAAAAAAAAAAAAbaHlWIAAABA830eT4ERYpuVnb6vSJnWTVhgcQVsGJED2vZeYogXbTy8wGb+qo/ojn0q6op7KBdF6y5MHSHGUFbad1UR4UaFBA==",
transaction.ToEnvelopeXdrBase64());

}

[TestMethod]
Expand Down Expand Up @@ -440,7 +451,7 @@ public void TestTransactionWithMuxedAccount()
new PaymentOperation.Builder(destination, asset, amount).Build())
.AddMemo(new MemoText("Happy birthday!"))
.Build();
var xdr = tx.ToUnsignedEnvelopeXdrBase64(TransactionBase.TransactionXdrVersion.V1);
var xdr = tx.ToUnsignedEnvelopeXdrBase64();
var back = TransactionBuilder.FromEnvelopeXdr(xdr) as Transaction;
Assert.IsNotNull(back);
Assert.AreEqual(txSource.Address, back.SourceAccount.Address);
Expand Down
4 changes: 2 additions & 2 deletions stellar-dotnet-sdk/FeeBumpTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public xdr.FeeBumpTransaction ToXdr()
return transaction;
}

public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0)
public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
if (Signatures.Count == 0)
throw new NotEnoughSignaturesException("FeeBumpTransaction must be signed by at least one signer. Use transaction.sign().");

return ToEnvelopeXdr(version, Signatures.ToArray());
}

public override TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0)
public override TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
if (Signatures.Count > 0)
throw new TooManySignaturesException("FeeBumpTransaction must not be signed. Use ToEnvelopeXDR.");
Expand Down
4 changes: 2 additions & 2 deletions stellar-dotnet-sdk/Transaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public xdr.Transaction ToXdrV1()
/// Generates TransactionEnvelope XDR object. Transaction need to have at least one signature.
/// </summary>
/// <returns></returns>
public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0)
public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
if (Signatures.Count == 0)
throw new NotEnoughSignaturesException("Transaction must be signed by at least one signer. Use transaction.sign().");
Expand All @@ -169,7 +169,7 @@ public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version
/// Generates TransactionEnvelope XDR object. This transaction MUST be signed before being useful
/// </summary>
/// <returns></returns>
public override TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0)
public override TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
if (Signatures.Count > 0)
throw new TooManySignaturesException("Transaction must not be signed. Use ToEnvelopeXDR.");
Expand Down
8 changes: 4 additions & 4 deletions stellar-dotnet-sdk/TransactionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ public TransactionBase()
/// </summary>
/// <param name="version">The envelope version to generated. Defaults to V0</param>
/// <returns></returns>
public abstract TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0);
public abstract TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1);


/// <summary>
/// Generates TransactionEnvelope XDR object. This transaction MUST be signed before being useful
/// </summary>
/// <param name="version">The envelope version to generated. Defaults to V0</param>
/// <returns></returns>
public abstract TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V0);
public abstract TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1);

/// <summary>
/// Returns signature base.
Expand Down Expand Up @@ -127,7 +127,7 @@ public byte[] Hash(Network network)
/// Generates TransactionEnvelope XDR object. This transaction MUST be signed before being useful
/// </summary>
/// <returns></returns>
public string ToUnsignedEnvelopeXdrBase64(TransactionXdrVersion version = TransactionXdrVersion.V0)
public string ToUnsignedEnvelopeXdrBase64(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
var envelope = ToUnsignedEnvelopeXdr(version);
var writer = new XdrDataOutputStream();
Expand All @@ -140,7 +140,7 @@ public string ToUnsignedEnvelopeXdrBase64(TransactionXdrVersion version = Transa
/// Returns base64-encoded TransactionEnvelope XDR object. Transaction need to have at least one signature.
/// </summary>
/// <returns></returns>
public string ToEnvelopeXdrBase64(TransactionXdrVersion version = TransactionXdrVersion.V0)
public string ToEnvelopeXdrBase64(TransactionXdrVersion version = TransactionXdrVersion.V1)
{
var envelope = ToEnvelopeXdr(version);
var writer = new XdrDataOutputStream();
Expand Down

0 comments on commit 4090a9b

Please sign in to comment.