diff --git a/stellar-dotnet-sdk-test/LedgerEntryTest.cs b/stellar-dotnet-sdk-test/LedgerEntryTest.cs new file mode 100644 index 00000000..6f143a5d --- /dev/null +++ b/stellar-dotnet-sdk-test/LedgerEntryTest.cs @@ -0,0 +1,1126 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using stellar_dotnet_sdk; +using stellar_dotnet_sdk.xdr; +using AccountEntryExtensionV1 = stellar_dotnet_sdk.AccountEntryExtensionV1; +using AccountEntryExtensionV2 = stellar_dotnet_sdk.AccountEntryExtensionV2; +using AccountEntryExtensionV3 = stellar_dotnet_sdk.AccountEntryExtensionV3; +using Asset = stellar_dotnet_sdk.Asset; +using ClaimableBalanceEntryExtensionV1 = stellar_dotnet_sdk.ClaimableBalanceEntryExtensionV1; +using Claimant = stellar_dotnet_sdk.Claimant; +using ClaimPredicate = stellar_dotnet_sdk.ClaimPredicate; +using EvictionIterator = stellar_dotnet_sdk.EvictionIterator; +using Hash = stellar_dotnet_sdk.Hash; +using LedgerEntry = stellar_dotnet_sdk.LedgerEntry; +using LedgerEntryExtensionV1 = stellar_dotnet_sdk.LedgerEntryExtensionV1; +using Liabilities = stellar_dotnet_sdk.Liabilities; +using LiquidityPoolConstantProductParameters = stellar_dotnet_sdk.LiquidityPoolConstantProductParameters; +using Price = stellar_dotnet_sdk.Price; +using SCString = stellar_dotnet_sdk.SCString; +using StateArchivalSettings = stellar_dotnet_sdk.StateArchivalSettings; +using TrustLineEntryExtensionV2 = stellar_dotnet_sdk.TrustLineEntryExtensionV2; + +namespace stellar_dotnet_sdk_test; + +[TestClass] +public class LedgerEntryTest +{ + private const string HomeDomain = "https://example.com"; + + private readonly Asset _alphaNum12Asset = + Asset.CreateNonNativeAsset("VNDCUSD", "GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); + + private readonly Hash _hash = new(new byte[] + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2 }); + + private readonly KeyPair _inflationDest = KeyPair.Random(); + + private readonly KeyPair _keyPair = + KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); + + private readonly LedgerEntryExtensionV1 _ledgerExtensionV1 = new() { SponsoringID = KeyPair.Random() }; + + private readonly KeyPair _signerSponsoringId = KeyPair.Random(); + private readonly byte[] _thresholds = { 1, 2, 3, 4 }; + + private readonly TrustlineAsset _trustlineAlphaNum4Asset = + TrustlineAsset.CreateNonNativeAsset("VNDT", "GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); + + private readonly Asset _alphaNum4Asset = + Asset.CreateNonNativeAsset("VNDC", "GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); + + private readonly Asset _nativeAsset = new AssetTypeNative(); + + private LedgerEntryAccount InitBasicLedgerEntryAccount() + { + return new LedgerEntryAccount + { + Account = _keyPair, + Thresholds = _thresholds, + Balance = 10000, + Flags = 1, + HomeDomain = HomeDomain, + SequenceNumber = 1, + NumberSubEntries = 0, + LastModifiedLedgerSeq = 10, + InflationDest = _inflationDest + }; + } + + private LedgerEntryTrustline InitBasicLedgerEntryTrustline() + { + return new LedgerEntryTrustline + { + LastModifiedLedgerSeq = 10000, + LedgerExtensionV1 = _ledgerExtensionV1, + Account = _keyPair, + Asset = _trustlineAlphaNum4Asset, + Balance = 1000, + Limit = 10000, + Flags = 1000 + }; + } + + private LedgerEntryClaimableBalance InitBasicLedgerEntryClaimableBalance() + { + return new LedgerEntryClaimableBalance + { + LastModifiedLedgerSeq = 10000, + LedgerExtensionV1 = _ledgerExtensionV1, + BalanceId = new Hash(new byte[] + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2 }), + Claimants = new Claimant[] + { + new() + { + Destination = _keyPair, + Predicate = ClaimPredicate.BeforeRelativeTime(10000) + } + }, + Asset = _alphaNum12Asset, + Amount = 1000 + }; + } + + private LedgerEntryContractData InitBasicLedgerEntryContractData() + { + return new LedgerEntryContractData + { + LastModifiedLedgerSeq = 10000, + LedgerExtensionV1 = _ledgerExtensionV1, + Key = new SCString("key 1"), + Value = new SCUint64(1000000), + Contract = new SCContractId("CAC2UYJQMC4ISUZ5REYB2AMDC44YKBNZWG4JB6N6GBL66CEKQO3RDSAB"), + Durability = ContractDataDurability.Create(ContractDataDurability.ContractDataDurabilityEnum.PERSISTENT), + ExtensionPoint = new ExtensionPointZero() + }; + } + + [TestMethod] + public void TestLedgerEntryAccountWithTooLongHomeDomain() + { + var ex = Assert.ThrowsException( + () => new LedgerEntryAccount + { HomeDomain = "123456789012345678901234567890123" }); + Assert.IsTrue(ex.Message.Contains("Home domain cannot exceed 32 characters")); + } + + [TestMethod] + public void TestLedgerEntryAccountWithTooManyBytesThresholds() + { + var ex = Assert.ThrowsException( + () => new LedgerEntryAccount + { Thresholds = new byte[] { 1, 2, 3, 5, 6 } }); + Assert.IsTrue(ex.Message.Contains("Thresholds cannot exceed 4 bytes")); + } + + [TestMethod] + public void TestLedgerEntryAccountWithMissingLedgerEntryExtensionAndAccountExtensionAndEmptySigners() + { + var ledgerEntry = InitBasicLedgerEntryAccount(); + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.IsNull(decodedLedgerEntry.LedgerExtensionV1); + Assert.IsNull(decodedLedgerEntry.AccountExtensionV1); + Assert.AreEqual(0, decodedLedgerEntry.Signers.Length); + } + + [TestMethod] + public void TestLedgerEntryAccountWithLedgerExtension() + { + var ledgerEntry = InitBasicLedgerEntryAccount(); + + ledgerEntry.LedgerExtensionV1 = _ledgerExtensionV1; + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.LedgerExtensionV1.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + } + + [TestMethod] + public void TestLedgerEntryAccountWithAccountExtensionV1Only() + { + var ledgerEntry = InitBasicLedgerEntryAccount(); + + ledgerEntry.AccountExtensionV1 = new AccountEntryExtensionV1 + { + Liabilities = new Liabilities(100, 200) + }; + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + // Account extensions + // V1 + var liabilities = ledgerEntry.AccountExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.AccountExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + // V2 + Assert.IsNull(ledgerEntry.AccountExtensionV1.ExtensionV2); + } + + [TestMethod] + public void TestLedgerEntryAccountWithAccountExtensionV1AndV2() + { + var ledgerEntry = InitBasicLedgerEntryAccount(); + + var signerSponsoringIDs = new[] { _signerSponsoringId }; + + ledgerEntry.AccountExtensionV1 = new AccountEntryExtensionV1 + { + Liabilities = new Liabilities(100, 200), + ExtensionV2 = new AccountEntryExtensionV2 + { + NumberSponsored = 5, + NumberSponsoring = 7, + SignerSponsoringIDs = signerSponsoringIDs + } + }; + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + // Account extensions + // V1 + var liabilities = ledgerEntry.AccountExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.AccountExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + + // V2 + var extensionV2 = ledgerEntry.AccountExtensionV1.ExtensionV2; + var decodedExtensionV2 = decodedLedgerEntry.AccountExtensionV1.ExtensionV2; + + Assert.AreEqual(extensionV2.NumberSponsored, decodedExtensionV2!.NumberSponsored); + Assert.AreEqual(extensionV2.NumberSponsoring, decodedExtensionV2.NumberSponsoring); + Assert.AreEqual(extensionV2.SignerSponsoringIDs.Length, decodedExtensionV2.SignerSponsoringIDs.Length); + for (var i = 0; i < extensionV2.SignerSponsoringIDs.Length; i++) + Assert.AreEqual(extensionV2.SignerSponsoringIDs[i].AccountId, + decodedExtensionV2.SignerSponsoringIDs[i].AccountId); + // V3 + Assert.IsNull(ledgerEntry.AccountExtensionV1.ExtensionV2.ExtensionV3); + } + + [TestMethod] + public void TestLedgerEntryAccountWithAllThreeAccountExtensions() + { + var ledgerEntry = InitBasicLedgerEntryAccount(); + + var signerSponsoringIDs = new[] { _signerSponsoringId }; + + ledgerEntry.AccountExtensionV1 = new AccountEntryExtensionV1 + { + Liabilities = new Liabilities(100, 200), + ExtensionV2 = new AccountEntryExtensionV2 + { + NumberSponsored = 5, + NumberSponsoring = 7, + SignerSponsoringIDs = signerSponsoringIDs, + ExtensionV3 = new AccountEntryExtensionV3 + { + ExtensionPoint = new ExtensionPointZero(), + SequenceLedger = 11, + SequenceTime = 10000 + } + } + }; + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + // Account extensions + // V1 + var liabilities = ledgerEntry.AccountExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.AccountExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + + // V2 + var extensionV2 = ledgerEntry.AccountExtensionV1.ExtensionV2; + var decodedExtensionV2 = decodedLedgerEntry.AccountExtensionV1.ExtensionV2; + + Assert.AreEqual(extensionV2.NumberSponsored, decodedExtensionV2!.NumberSponsored); + Assert.AreEqual(extensionV2.NumberSponsoring, decodedExtensionV2.NumberSponsoring); + Assert.AreEqual(extensionV2.SignerSponsoringIDs.Length, decodedExtensionV2.SignerSponsoringIDs.Length); + for (var i = 0; i < extensionV2.SignerSponsoringIDs.Length; i++) + Assert.AreEqual(extensionV2.SignerSponsoringIDs[i].AccountId, + decodedExtensionV2.SignerSponsoringIDs[i].AccountId); + // V3 + var extensionV3 = extensionV2.ExtensionV3; + var decodedExtensionV3 = decodedExtensionV2.ExtensionV3; + + Assert.AreEqual(extensionV3.ExtensionPoint.ToXdrBase64(), decodedExtensionV3!.ExtensionPoint.ToXdrBase64()); + Assert.AreEqual(extensionV3.SequenceLedger, decodedExtensionV3.SequenceLedger); + Assert.AreEqual(extensionV3.SequenceTime, decodedExtensionV3.SequenceTime); + } + + [TestMethod] + public void TestLedgerEntryAccountWithAllPropertiesPopulated() + { + var signerSponsoringIDs = new[] { _signerSponsoringId }; + var ledgerEntry = InitBasicLedgerEntryAccount(); + ledgerEntry.LedgerExtensionV1 = _ledgerExtensionV1; + ledgerEntry.AccountExtensionV1 = new AccountEntryExtensionV1 + { + Liabilities = new Liabilities(100, 200), + ExtensionV2 = new AccountEntryExtensionV2 + { + NumberSponsored = 5, + NumberSponsoring = 7, + SignerSponsoringIDs = signerSponsoringIDs, + ExtensionV3 = new AccountEntryExtensionV3 + { + ExtensionPoint = new ExtensionPointZero(), + SequenceLedger = 11, + SequenceTime = 10000 + } + } + }; + + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryAccount)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.Balance, decodedLedgerEntry.Balance); + Assert.AreEqual(ledgerEntry.NumberSubEntries, decodedLedgerEntry.NumberSubEntries); + Assert.AreEqual(ledgerEntry.SequenceNumber, decodedLedgerEntry.SequenceNumber); + Assert.AreEqual(ledgerEntry.Flags, decodedLedgerEntry.Flags); + CollectionAssert.AreEqual(ledgerEntry.Thresholds, decodedLedgerEntry.Thresholds); + Assert.AreEqual(ledgerEntry.HomeDomain, decodedLedgerEntry.HomeDomain); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + Assert.AreEqual(ledgerEntry.Account.AccountId, decodedLedgerEntry.Account.AccountId); + Assert.AreEqual(ledgerEntry.Signers.Length, decodedLedgerEntry.Signers.Length); + for (var i = 0; i < ledgerEntry.Signers.Length; i++) + { + var signer = ledgerEntry.Signers[i]; + var decodedSigner = decodedLedgerEntry.Signers[i]; + Assert.AreEqual(signer.Key.HashX, decodedSigner.Key.HashX); + Assert.AreEqual(signer.Weight, decodedSigner.Weight); + } + + Assert.AreEqual(ledgerEntry.InflationDest.AccountId, decodedLedgerEntry.InflationDest.AccountId); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + + // Account extensions + // V1 + var liabilities = ledgerEntry.AccountExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.AccountExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + + // V2 + var extensionV2 = ledgerEntry.AccountExtensionV1.ExtensionV2; + var decodedExtensionV2 = decodedLedgerEntry.AccountExtensionV1.ExtensionV2; + + Assert.AreEqual(extensionV2.NumberSponsored, decodedExtensionV2!.NumberSponsored); + Assert.AreEqual(extensionV2.NumberSponsoring, decodedExtensionV2.NumberSponsoring); + Assert.AreEqual(extensionV2.SignerSponsoringIDs.Length, decodedExtensionV2.SignerSponsoringIDs.Length); + for (var i = 0; i < extensionV2.SignerSponsoringIDs.Length; i++) + Assert.AreEqual(extensionV2.SignerSponsoringIDs[i].AccountId, + decodedExtensionV2.SignerSponsoringIDs[i].AccountId); + + // V3 + var extensionV3 = extensionV2.ExtensionV3; + var decodedExtensionV3 = decodedExtensionV2.ExtensionV3; + + Assert.AreEqual(extensionV3.ExtensionPoint.ToXdrBase64(), decodedExtensionV3!.ExtensionPoint.ToXdrBase64()); + Assert.AreEqual(extensionV3.SequenceLedger, decodedExtensionV3.SequenceLedger); + Assert.AreEqual(extensionV3.SequenceTime, decodedExtensionV3.SequenceTime); + } + + [TestMethod] + public void TestLedgerEntryOfferWithAllPropertiesPopulated() + { + var ledgerEntry = new LedgerEntryOffer + { + LastModifiedLedgerSeq = 100, + SellerID = _keyPair, + OfferID = 1000, + Amount = 100, + Buying = _alphaNum12Asset, + Selling = _alphaNum12Asset, + Price = new Price(1, 10), + Flags = 10, + LedgerExtensionV1 = _ledgerExtensionV1 + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryOffer)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.OfferID, decodedLedgerEntry.OfferID); + Assert.IsTrue(ledgerEntry.Selling.CompareTo(decodedLedgerEntry.Selling) == 0); + Assert.IsTrue(ledgerEntry.Buying.CompareTo(decodedLedgerEntry.Buying) == 0); + Assert.AreEqual(ledgerEntry.Price, decodedLedgerEntry.Price); + Assert.AreEqual(ledgerEntry.Amount, decodedLedgerEntry.Amount); + Assert.AreEqual(ledgerEntry.SellerID.AccountId, decodedLedgerEntry.SellerID.AccountId); + Assert.AreEqual(ledgerEntry.Flags, decodedLedgerEntry.Flags); + Assert.IsNull(decodedLedgerEntry.OfferExtension); // Currently, no offer entry extension is available + } + + [TestMethod] + public void TestLedgerEntryTrustlineWithTrustlineExtensionV1Only() + { + var ledgerEntry = InitBasicLedgerEntryTrustline(); + ledgerEntry.TrustlineExtensionV1 = new TrustlineEntryExtensionV1 + { + Liabilities = new Liabilities(100, 100) + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryTrustline)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.Account.AccountId, decodedLedgerEntry.Account.AccountId); + Assert.AreEqual(((TrustlineAsset.Wrapper)ledgerEntry.Asset).Asset, + ((TrustlineAsset.Wrapper)decodedLedgerEntry.Asset).Asset); + Assert.AreEqual(ledgerEntry.Flags, decodedLedgerEntry.Flags); + Assert.AreEqual(ledgerEntry.Balance, decodedLedgerEntry.Balance); + Assert.AreEqual(ledgerEntry.Limit, decodedLedgerEntry.Limit); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + + // Trustline extensions + // V1 + var liabilities = ledgerEntry.TrustlineExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.TrustlineExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + + Assert.IsNull(decodedLedgerEntry.TrustlineExtensionV1.TrustlineExtensionV2); + } + + [TestMethod] + public void TestLedgerEntryTrustlineWithAllPropertiesPopulated() + { + var ledgerEntry = InitBasicLedgerEntryTrustline(); + ledgerEntry.TrustlineExtensionV1 = new TrustlineEntryExtensionV1 + { + Liabilities = new Liabilities(100, 100), + TrustlineExtensionV2 = new TrustLineEntryExtensionV2 + { + LiquidityPoolUseCount = 20 + } + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = (LedgerEntryTrustline)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.Account.AccountId, decodedLedgerEntry.Account.AccountId); + Assert.AreEqual(((TrustlineAsset.Wrapper)ledgerEntry.Asset).Asset, + ((TrustlineAsset.Wrapper)decodedLedgerEntry.Asset).Asset); + Assert.AreEqual(ledgerEntry.Flags, decodedLedgerEntry.Flags); + Assert.AreEqual(ledgerEntry.Balance, decodedLedgerEntry.Balance); + Assert.AreEqual(ledgerEntry.Limit, decodedLedgerEntry.Limit); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + + // Trustline extensions + // V1 + var liabilities = ledgerEntry.TrustlineExtensionV1.Liabilities; + var decodedLiabilities = decodedLedgerEntry.TrustlineExtensionV1!.Liabilities; + Assert.AreEqual(liabilities.Buying, decodedLiabilities.Buying); + Assert.AreEqual(liabilities.Selling, decodedLiabilities.Selling); + + // V2 + var extensionV2 = ledgerEntry.TrustlineExtensionV1.TrustlineExtensionV2; + var decodedExtensionV2 = decodedLedgerEntry.TrustlineExtensionV1.TrustlineExtensionV2; + Assert.AreEqual(extensionV2.LiquidityPoolUseCount, decodedExtensionV2!.LiquidityPoolUseCount); + } + + [TestMethod] + public void TestLedgerEntryDataWithAllPropertiesPopulated() + { + var ledgerEntry = new LedgerEntryData + { + LastModifiedLedgerSeq = 20000, + LedgerExtensionV1 = _ledgerExtensionV1, + AccountID = _keyPair, + DataName = "LedgerEntryDataName1", + DataValue = new byte[] { 1, 2, 3, 4, 5 } + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedEntryData = (LedgerEntryData)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + CollectionAssert.AreEqual(ledgerEntry.DataValue, decodedEntryData.DataValue); + Assert.AreEqual(ledgerEntry.DataName, decodedEntryData.DataName); + Assert.AreEqual(ledgerEntry.AccountID.AccountId, decodedEntryData.AccountID.AccountId); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedEntryData.LastModifiedLedgerSeq); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1.SponsoringID.AccountId, + decodedEntryData.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.IsNull(decodedEntryData.DataExtension); // Currently, no data entry extension is available + } + + [TestMethod] + public void TestLedgerEntryClaimableBalanceWithTooLongBalanceId() + { + var ledgerEntry = InitBasicLedgerEntryClaimableBalance(); + var ex = Assert.ThrowsException( + () => ledgerEntry.BalanceId = new Hash(new byte[] + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 })); + + Assert.IsTrue(ex.Message.Contains("Hash must have exactly 32 bytes.")); + } + + [TestMethod] + public void TestLedgerEntryClaimableBalanceWithTooShortBalanceId() + { + var ledgerEntry = InitBasicLedgerEntryClaimableBalance(); + var ex = Assert.ThrowsException( + () => ledgerEntry.BalanceId = new Hash(new byte[] + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1 })); + + Assert.IsTrue(ex.Message.Contains("Hash must have exactly 32 bytes.")); + } + + [TestMethod] + public void TestLedgerEntryClaimableBalanceWithMissingClaimableBalanceExtension() + { + var ledgerEntry = InitBasicLedgerEntryClaimableBalance(); + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryClaimableBalance)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.Claimants.Length, decodedLedgerEntry.Claimants.Length); + for (var i = 0; i < ledgerEntry.Claimants.Length; i++) + { + Assert.AreEqual(ledgerEntry.Claimants[i].Destination.AccountId, + decodedLedgerEntry.Claimants[i].Destination.AccountId); + var predicate = (ClaimPredicateBeforeRelativeTime)ledgerEntry.Claimants[i].Predicate; + var decodedPredicate = (ClaimPredicateBeforeRelativeTime)decodedLedgerEntry.Claimants[i].Predicate; + Assert.AreEqual(predicate.Duration.InnerValue.InnerValue, decodedPredicate.Duration.InnerValue.InnerValue); + } + + CollectionAssert.AreEqual(ledgerEntry.BalanceId.InnerValue, + decodedLedgerEntry.BalanceId.InnerValue); + Assert.AreEqual(ledgerEntry.Amount, decodedLedgerEntry.Amount); + Assert.AreEqual(ledgerEntry.Asset, decodedLedgerEntry.Asset); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, + decodedLedgerEntry.LastModifiedLedgerSeq); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.IsNull(ledgerEntry.ClaimableBalanceEntryExtensionV1); + } + + [TestMethod] + public void TestLedgerEntryClaimableBalanceWithAllPropertiesPopulated() + { + var ledgerEntry = InitBasicLedgerEntryClaimableBalance(); + + ledgerEntry.ClaimableBalanceEntryExtensionV1 = new ClaimableBalanceEntryExtensionV1 + { + Flags = 10000 + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryClaimableBalance)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(ledgerEntry.Claimants.Length, decodedLedgerEntry.Claimants.Length); + for (var i = 0; i < ledgerEntry.Claimants.Length; i++) + { + Assert.AreEqual(ledgerEntry.Claimants[i].Destination.AccountId, + decodedLedgerEntry.Claimants[i].Destination.AccountId); + var predicate = (ClaimPredicateBeforeRelativeTime)ledgerEntry.Claimants[i].Predicate; + var decodedPredicate = (ClaimPredicateBeforeRelativeTime)decodedLedgerEntry.Claimants[i].Predicate; + Assert.AreEqual(predicate.Duration.InnerValue.InnerValue, decodedPredicate.Duration.InnerValue.InnerValue); + } + + CollectionAssert.AreEqual(ledgerEntry.BalanceId.InnerValue, + decodedLedgerEntry.BalanceId.InnerValue); + Assert.AreEqual(ledgerEntry.Amount, decodedLedgerEntry.Amount); + Assert.AreEqual(ledgerEntry.Asset, decodedLedgerEntry.Asset); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, + decodedLedgerEntry.LastModifiedLedgerSeq); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.AreEqual(ledgerEntry.ClaimableBalanceEntryExtensionV1.Flags, + decodedLedgerEntry.ClaimableBalanceEntryExtensionV1!.Flags); + } + + [TestMethod] + public void TestLedgerEntryLiquidityPoolWithAllPropertiesPopulated() + { + var ledgerEntry = new LedgerEntryLiquidityPool + { + LedgerExtensionV1 = _ledgerExtensionV1, + LastModifiedLedgerSeq = 1200, + LiquidityPoolID = new LiquidityPoolID + { + Hash = _hash.InnerValue + }, + LiquidityPoolBody = new LiquidityPoolConstantProduct + { + ReserveA = 1000, + ReserveB = 2000, + TotalPoolShares = 30000, + PoolSharesTrustLineCount = 100, + Parameters = new LiquidityPoolConstantProductParameters(_nativeAsset, _alphaNum4Asset, 100) + } + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryLiquidityPool)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + CollectionAssert.AreEqual(ledgerEntry.LiquidityPoolID.Hash, decodedLedgerEntry.LiquidityPoolID.Hash); + + var product = (LiquidityPoolConstantProduct)ledgerEntry.LiquidityPoolBody; + var decodedProduct = (LiquidityPoolConstantProduct)decodedLedgerEntry.LiquidityPoolBody; + Assert.AreEqual(product.ReserveA, decodedProduct.ReserveA); + Assert.AreEqual(product.ReserveB, decodedProduct.ReserveB); + Assert.AreEqual(product.TotalPoolShares, decodedProduct.TotalPoolShares); + Assert.AreEqual(product.PoolSharesTrustLineCount, decodedProduct.PoolSharesTrustLineCount); + Assert.AreEqual(product.Parameters.Fee, decodedProduct.Parameters.Fee); + // Assert.AreEqual(product.Parameters.AssetA, decodedProduct.Parameters.AssetA); + // Assert.AreEqual(product.Parameters.AssetB, decodedProduct.Parameters.AssetB); + + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, ledgerEntry.LastModifiedLedgerSeq); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + } + + [TestMethod] + public void TestLedgerEntryContractDataWithWithContractBeingAContractAddress() + { + var ledgerEntry = InitBasicLedgerEntryContractData(); + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryContractData)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(((SCContractId)ledgerEntry.Contract).InnerValue, + ((SCContractId)decodedLedgerEntry.Contract).InnerValue); + Assert.AreEqual(ledgerEntry.Durability.InnerValue, decodedLedgerEntry.Durability.InnerValue); + Assert.AreEqual(((SCString)ledgerEntry.Key).InnerValue, + ((SCString)decodedLedgerEntry.Key).InnerValue); + Assert.AreEqual(((SCUint64)ledgerEntry.Value).InnerValue, + ((SCUint64)decodedLedgerEntry.Value).InnerValue); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + } + + [TestMethod] + public void TestLedgerEntryContractDataWithWithContractBeingAnAccountAddress() + { + var ledgerEntry = InitBasicLedgerEntryContractData(); + ledgerEntry.Contract = new SCAccountId("GCZFMH32MF5EAWETZTKF3ZV5SEVJPI53UEMDNSW55WBR75GMZJU4U573"); + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryContractData)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + Assert.AreEqual(((SCAccountId)ledgerEntry.Contract).InnerValue, + ((SCAccountId)decodedLedgerEntry.Contract).InnerValue); + Assert.AreEqual(ledgerEntry.Durability.InnerValue, decodedLedgerEntry.Durability.InnerValue); + Assert.AreEqual(((SCString)ledgerEntry.Key).InnerValue, + ((SCString)decodedLedgerEntry.Key).InnerValue); + Assert.AreEqual(((SCUint64)ledgerEntry.Value).InnerValue, + ((SCUint64)decodedLedgerEntry.Value).InnerValue); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1!.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + } + + [TestMethod] + public void TestLedgerEntryContractCodeWithAllPropertiesPopulated() + { + var ledgerEntry = new LedgerEntryContractCode + { + LastModifiedLedgerSeq = 1032, + Code = new byte[] { 1, 2, 3 }, + LedgerExtensionV1 = _ledgerExtensionV1, + ExtensionPoint = new ExtensionPointZero(), + Hash = _hash + }; + + // Act + var entryXdrBase64 = ledgerEntry.ToXdrBase64(); + var decodedLedgerEntry = + (LedgerEntryContractCode)LedgerEntry.FromXdrBase64(entryXdrBase64); + + // Assert + CollectionAssert.AreEqual(ledgerEntry.Code, decodedLedgerEntry.Code); + CollectionAssert.AreEqual(ledgerEntry.Hash.InnerValue, decodedLedgerEntry.Hash.InnerValue); + Assert.AreEqual(ledgerEntry.LedgerExtensionV1.SponsoringID.AccountId, + decodedLedgerEntry.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.AreEqual(ledgerEntry.LastModifiedLedgerSeq, decodedLedgerEntry.LastModifiedLedgerSeq); + } + + + [TestMethod] + public void TestLedgerEntryConfigSettingContractBandwidthV0() + { + var configSetting = new ConfigSettingContractBandwidth + { + LastModifiedLedgerSeq = 10, + LedgerExtensionV1 = null, + LedgerMaxTxsSizeBytes = 1024, + TxMaxSizeBytes = 1024, + FeeTxSize1KB = 100 + }; + + // Act + var ledgerEntryXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingContractBandwidth)LedgerEntry.FromXdrBase64(ledgerEntryXdrBase64); + + // Assert + Assert.AreEqual(configSetting.TxMaxSizeBytes, decodedConfigSetting.TxMaxSizeBytes); + Assert.AreEqual(configSetting.FeeTxSize1KB, decodedConfigSetting.FeeTxSize1KB); + Assert.AreEqual(configSetting.LedgerMaxTxsSizeBytes, decodedConfigSetting.LedgerMaxTxsSizeBytes); + } + + [TestMethod] + public void TestConfigSettingContractCostParamsMemoryBytes() + { + var configSetting = + new ConfigSettingContractCostParamsMemoryBytes + { + LastModifiedLedgerSeq = 100, + paramEntries = new ConfigSettingContractCostParamEntry[] + { + new() + { + LinearTerm = 100, + ExtensionPoint = new ExtensionPointZero(), + ConstTerm = 100000 + }, + new() + { + LinearTerm = 200, + ConstTerm = 400, + ExtensionPoint = new ExtensionPointZero() + } + } + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractCostParamsMemoryBytes)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.paramEntries.Length, decodedConfigSetting.paramEntries.Length); + for (var i = 0; i < configSetting.paramEntries.Length; i++) + { + var paramEntry = configSetting.paramEntries[i]; + var decodedParamEntry = decodedConfigSetting.paramEntries[i]; + Assert.AreEqual(paramEntry.ConstTerm, decodedParamEntry.ConstTerm); + Assert.AreEqual(paramEntry.LinearTerm, decodedParamEntry.LinearTerm); + } + } + + [TestMethod] + public void TestConfigSettingContractCostParamsCpuInstructions() + { + var configSetting = + new ConfigSettingContractCostParamsCpuInstructions + { + LastModifiedLedgerSeq = 500, + paramEntries = new ConfigSettingContractCostParamEntry[] + { + new() + { + LinearTerm = 120, + ExtensionPoint = new ExtensionPointZero(), + ConstTerm = 108000 + }, + new() + { + LinearTerm = 2300, + ConstTerm = 3400, + ExtensionPoint = new ExtensionPointZero() + } + } + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractCostParamsCpuInstructions)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.paramEntries.Length, decodedConfigSetting.paramEntries.Length); + for (var i = 0; i < configSetting.paramEntries.Length; i++) + { + var paramEntry = configSetting.paramEntries[i]; + var decodedParamEntry = decodedConfigSetting.paramEntries[i]; + Assert.AreEqual(paramEntry.ConstTerm, decodedParamEntry.ConstTerm); + Assert.AreEqual(paramEntry.LinearTerm, decodedParamEntry.LinearTerm); + } + } + + [TestMethod] + public void TestConfigSettingContractComputeV0() + { + var configSetting = + new ConfigSettingContractCompute + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + LedgerMaxInstructions = 110, + TxMaxInstructions = 1000, + FeeRatePerInstructionsIncrement = 1000, + TxMemoryLimit = 1000 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingContractCompute)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.LedgerMaxInstructions, decodedConfigSetting.LedgerMaxInstructions); + Assert.AreEqual(configSetting.TxMaxInstructions, decodedConfigSetting.TxMaxInstructions); + Assert.AreEqual(configSetting.TxMemoryLimit, decodedConfigSetting.TxMemoryLimit); + Assert.AreEqual(configSetting.FeeRatePerInstructionsIncrement, + decodedConfigSetting.FeeRatePerInstructionsIncrement); + } + + [TestMethod] + public void TestConfigSettingContractEventsV0() + { + var configSetting = + new ConfigSettingContractEvents + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + TxMaxContractEventsSizeBytes = 333, + FeeContractEvents1KB = 1024 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingContractEvents)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.TxMaxContractEventsSizeBytes, decodedConfigSetting.TxMaxContractEventsSizeBytes); + Assert.AreEqual(configSetting.FeeContractEvents1KB, decodedConfigSetting.FeeContractEvents1KB); + } + + [TestMethod] + public void TestConfigSettingContractExecutionLanesV0() + { + var configSetting = + new ConfigSettingContractExecutionLanes + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + LedgerMaxTxCount = 10000 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractExecutionLanes)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.LedgerMaxTxCount, decodedConfigSetting.LedgerMaxTxCount); + } + + [TestMethod] + public void TestConfigSettingContractHistoricalDataV0() + { + var configSetting = + new ConfigSettingContractHistoricalData + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + FeeHistorical1KB = 10000 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractHistoricalData)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.FeeHistorical1KB, decodedConfigSetting.FeeHistorical1KB); + } + + [TestMethod] + public void TestConfigSettingContractLedgerCostV0() + { + var configSetting = + new ConfigSettingContractLedgerCost + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + LedgerMaxReadLedgerEntries = 123, + LedgerMaxReadBytes = 22, + LedgerMaxWriteLedgerEntries = 11, + LedgerMaxWriteBytes = 34, + TxMaxReadLedgerEntries = 55, + TxMaxReadBytes = 110, + TxMaxWriteLedgerEntries = 120, + TxMaxWriteBytes = 130, + FeeReadLedgerEntry = 140, + FeeWriteLedgerEntry = 150, + FeeRead1KB = 160, + BucketListTargetSizeBytes = 170, + WriteFee1KBBucketListLow = 180, + WriteFee1KBBucketListHigh = 220, + BucketListWriteFeeGrowthFactor = 2230 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingContractLedgerCost)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.LedgerMaxReadLedgerEntries, decodedConfigSetting.LedgerMaxReadLedgerEntries); + Assert.AreEqual(configSetting.LedgerMaxReadBytes, decodedConfigSetting.LedgerMaxReadBytes); + Assert.AreEqual(configSetting.LedgerMaxWriteLedgerEntries, decodedConfigSetting.LedgerMaxWriteLedgerEntries); + Assert.AreEqual(configSetting.LedgerMaxWriteBytes, decodedConfigSetting.LedgerMaxWriteBytes); + Assert.AreEqual(configSetting.TxMaxReadLedgerEntries, decodedConfigSetting.TxMaxReadLedgerEntries); + Assert.AreEqual(configSetting.TxMaxReadBytes, decodedConfigSetting.TxMaxReadBytes); + Assert.AreEqual(configSetting.TxMaxWriteLedgerEntries, decodedConfigSetting.TxMaxWriteLedgerEntries); + Assert.AreEqual(configSetting.TxMaxWriteBytes, decodedConfigSetting.TxMaxWriteBytes); + Assert.AreEqual(configSetting.FeeReadLedgerEntry, decodedConfigSetting.FeeReadLedgerEntry); + Assert.AreEqual(configSetting.FeeWriteLedgerEntry, decodedConfigSetting.FeeWriteLedgerEntry); + Assert.AreEqual(configSetting.FeeRead1KB, decodedConfigSetting.FeeRead1KB); + Assert.AreEqual(configSetting.BucketListTargetSizeBytes, decodedConfigSetting.BucketListTargetSizeBytes); + Assert.AreEqual(configSetting.WriteFee1KBBucketListLow, decodedConfigSetting.WriteFee1KBBucketListLow); + Assert.AreEqual(configSetting.WriteFee1KBBucketListHigh, decodedConfigSetting.WriteFee1KBBucketListHigh); + Assert.AreEqual(configSetting.BucketListWriteFeeGrowthFactor, + decodedConfigSetting.BucketListWriteFeeGrowthFactor); + } + + [TestMethod] + public void TestStateArchivalSettings() + { + var configSetting = + new StateArchivalSettings + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + MaxEntryTTL = 23, + MinTemporaryTTL = 12, + MinPersistentTTL = 111, + PersistentRentRateDenominator = 120, + TempRentRateDenominator = 130, + MaxEntriesToArchive = 140, + BucketListSizeWindowSampleSize = 330, + EvictionScanSize = 340, + StartingEvictionScanLevel = 3440 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (StateArchivalSettings)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.MaxEntryTTL, decodedConfigSetting.MaxEntryTTL); + Assert.AreEqual(configSetting.MinTemporaryTTL, decodedConfigSetting.MinTemporaryTTL); + Assert.AreEqual(configSetting.MinPersistentTTL, decodedConfigSetting.MinPersistentTTL); + Assert.AreEqual(configSetting.PersistentRentRateDenominator, + decodedConfigSetting.PersistentRentRateDenominator); + Assert.AreEqual(configSetting.TempRentRateDenominator, decodedConfigSetting.TempRentRateDenominator); + Assert.AreEqual(configSetting.MaxEntriesToArchive, decodedConfigSetting.MaxEntriesToArchive); + Assert.AreEqual(configSetting.BucketListSizeWindowSampleSize, + decodedConfigSetting.BucketListSizeWindowSampleSize); + Assert.AreEqual(configSetting.EvictionScanSize, decodedConfigSetting.EvictionScanSize); + Assert.AreEqual(configSetting.StartingEvictionScanLevel, decodedConfigSetting.StartingEvictionScanLevel); + } + + [TestMethod] + public void TestConfigSettingEvictionIterator() + { + var configSetting = + new EvictionIterator + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null, + BucketListLevel = 10, + IsCurrBucket = false, + BucketFileOffset = 10 + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (EvictionIterator)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.BucketFileOffset, decodedConfigSetting.BucketFileOffset); + Assert.AreEqual(configSetting.BucketListLevel, decodedConfigSetting.BucketListLevel); + Assert.AreEqual(configSetting.IsCurrBucket, decodedConfigSetting.IsCurrBucket); + } + + [TestMethod] + public void TestConfigSettingContractMaxSizeBytes() + { + var configSetting = + new ConfigSettingContractMaxSizeBytes(100) + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingContractMaxSizeBytes)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.InnerValue, decodedConfigSetting.InnerValue); + } + + [TestMethod] + public void TestConfigSettingContractDataKeySizeBytes() + { + var configSetting = + new ConfigSettingContractDataKeySizeBytes(100) + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractDataKeySizeBytes)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.InnerValue, decodedConfigSetting.InnerValue); + } + + [TestMethod] + public void TestConfigSettingContractDataEntrySizeBytes() + { + var configSetting = + new ConfigSettingContractDataEntrySizeBytes(100) + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = + (ConfigSettingContractDataEntrySizeBytes)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + Assert.AreEqual(configSetting.InnerValue, decodedConfigSetting.InnerValue); + } + + [TestMethod] + public void TestConfigSettingBucketListSizeWindow() + { + var configSetting = + new ConfigSettingBucketListSizeWindow(new ulong[] { 1, 2, 3, 4 }) + { + LastModifiedLedgerSeq = 500, + LedgerExtensionV1 = null + }; + + // Act + var configSettingXdrBase64 = configSetting.ToXdrBase64(); + var decodedConfigSetting = (ConfigSettingBucketListSizeWindow)LedgerEntry.FromXdrBase64(configSettingXdrBase64); + + // Assert + Assert.AreEqual(configSetting.LastModifiedLedgerSeq, decodedConfigSetting.LastModifiedLedgerSeq); + Assert.IsNull(decodedConfigSetting.LedgerExtensionV1); + CollectionAssert.AreEqual(configSetting.InnerValue, decodedConfigSetting.InnerValue); + } + + + [TestMethod] + public void TestLedgerEntryTtlWithAllPropertiesPopulated() + { + var entryTtl = new LedgerEntryTTL + { + LastModifiedLedgerSeq = 11032, + LedgerExtensionV1 = _ledgerExtensionV1, + KeyHash = _hash, + LiveUntilLedgerSequence = 1000 + }; + + // Act + var entryTtlXdrBase64 = entryTtl.ToXdrBase64(); + var decodedTtl = + (LedgerEntryTTL)LedgerEntry.FromXdrBase64(entryTtlXdrBase64); + + // Assert + Assert.AreEqual(entryTtl.LiveUntilLedgerSequence, decodedTtl.LiveUntilLedgerSequence); + CollectionAssert.AreEqual(entryTtl.KeyHash.InnerValue, decodedTtl.KeyHash.InnerValue); + Assert.AreEqual(entryTtl.LedgerExtensionV1.SponsoringID.AccountId, + decodedTtl.LedgerExtensionV1!.SponsoringID.AccountId); + Assert.AreEqual(entryTtl.LastModifiedLedgerSeq, decodedTtl.LastModifiedLedgerSeq); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk-test/LedgerKeyTest.cs b/stellar-dotnet-sdk-test/LedgerKeyTest.cs index ab91db6c..0569de3a 100644 --- a/stellar-dotnet-sdk-test/LedgerKeyTest.cs +++ b/stellar-dotnet-sdk-test/LedgerKeyTest.cs @@ -1,5 +1,9 @@ +using System; using Microsoft.VisualStudio.TestTools.UnitTesting; using stellar_dotnet_sdk; +using stellar_dotnet_sdk.xdr; +using LedgerKey = stellar_dotnet_sdk.LedgerKey; +using SCSymbol = stellar_dotnet_sdk.SCSymbol; namespace stellar_dotnet_sdk_test { @@ -10,44 +14,53 @@ public class LedgerKeyTest public void TestLedgerKeyAccount() { var keypair = KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); - var ledgerKey = LedgerKey.Account(keypair); - var xdr = ledgerKey.ToXdr(); - var back = LedgerKey.FromXdr(xdr); - - var account = (LedgerKeyAccount)back; - - Assert.IsNotNull(account); - Assert.AreEqual(keypair.AccountId, account.Account.AccountId); + var ledgerKey = (LedgerKeyAccount)LedgerKey.Account(keypair); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyAccount)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(ledgerKey.Account.AccountId, decodedLedgerKey.Account.AccountId); } - + [TestMethod] - public void TestLedgerKeyData() + public void TestLedgerKeyDataWithTooLongName() { var keypair = KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); - var ledgerKey = LedgerKey.Data(keypair, "Test Data"); - var xdr = ledgerKey.ToXdr(); - var back = LedgerKey.FromXdr(xdr); - - var data = (LedgerKeyData)back; - - Assert.IsNotNull(data); - Assert.AreEqual("Test Data", data.DataName); - Assert.AreEqual(keypair.AccountId, data.Account.AccountId); + var dataName = "This is a 73 characters long string which is too strong for String64 type"; + var ex = Assert.ThrowsException(() => LedgerKey.Data(keypair, dataName)); + Assert.IsTrue(ex.Message.Contains("String64 cannot exceed 64 characters")); + } + + [TestMethod] + public void TestLedgerKeyDataWithValidName() + { + var keypair = KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); + var ledgerKey = (LedgerKeyData)LedgerKey.Data(keypair, "Test Data"); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyData)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(ledgerKey.DataName, decodedLedgerKey.DataName); + Assert.AreEqual(ledgerKey.Account.AccountId, decodedLedgerKey.Account.AccountId); } [TestMethod] public void TestLedgerKeyOffer() { var keypair = KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"); - var ledgerKey = LedgerKey.Offer(keypair, 1234); - var xdr = ledgerKey.ToXdr(); - var back = LedgerKey.FromXdr(xdr); - - var offer = (LedgerKeyOffer)back; - - Assert.IsNotNull(offer); - Assert.AreEqual(1234, offer.OfferId); - Assert.AreEqual(keypair.AccountId, offer.Seller.AccountId); + var ledgerKey = (LedgerKeyOffer)LedgerKey.Offer(keypair, 1234); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyOffer)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(ledgerKey.OfferId, decodedLedgerKey.OfferId); + Assert.AreEqual(ledgerKey.Seller.AccountId, decodedLedgerKey.Seller.AccountId); } [TestMethod] @@ -57,14 +70,14 @@ public void TestLedgerKeyTrustline() var issuer = KeyPair.FromAccountId("GB24C27VKWCBG7NTCT4J2L4MXJGYC3K3SQ4JOTCSPOVVEN7EZEB43XNE"); var asset = TrustlineAsset.CreateNonNativeAsset("ABCD", issuer.AccountId); var ledgerKey = LedgerKey.Trustline(keypair, asset); - var xdr = ledgerKey.ToXdr(); - var back = LedgerKey.FromXdr(xdr); - - var trustline = (LedgerKeyTrustline)back; - - Assert.IsNotNull(trustline); - Assert.AreEqual("ABCD:GB24C27VKWCBG7NTCT4J2L4MXJGYC3K3SQ4JOTCSPOVVEN7EZEB43XNE", ((TrustlineAsset.Wrapper)trustline.Asset).Asset.CanonicalName()); - Assert.AreEqual(keypair.AccountId, trustline.Account.AccountId); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyTrustline)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual("ABCD:GB24C27VKWCBG7NTCT4J2L4MXJGYC3K3SQ4JOTCSPOVVEN7EZEB43XNE", ((TrustlineAsset.Wrapper)decodedLedgerKey.Asset).Asset.CanonicalName()); + Assert.AreEqual(keypair.AccountId, decodedLedgerKey.Account.AccountId); } @@ -73,13 +86,122 @@ public void TestLedgerKeyClaimableBalance() { var balanceId = Util.HexToBytes("c582697b67cbec7f9ce64f4dc67bfb2bfd26318bb9f964f4d70e3f41f650b1e6"); var ledgerKey = LedgerKey.ClaimableBalance(balanceId); - var xdr = ledgerKey.ToXdr(); - var back = LedgerKey.FromXdr(xdr); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyClaimableBalance)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); - var claimableBalance = (LedgerKeyClaimableBalance)back; + // Assert + CollectionAssert.AreEqual(balanceId, decodedLedgerKey.BalanceId); + } - Assert.IsNotNull(claimableBalance); - Assert.AreEqual(balanceId, claimableBalance.BalanceId); + [TestMethod] + public void TestLedgerKeyLiquidityPool() + { + var hash = new byte[] + { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2 }; + var ledgerKey = LedgerKey.LiquidityPool(new LiquidityPoolID(hash)); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyLiquidityPool)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + CollectionAssert.AreEqual(hash, decodedLedgerKey.LiquidityPoolID.Hash); + } + + [TestMethod] + public void TestLedgerKeyContractDataWithContractBeingContractId() + { + var contractId = new SCContractId("CAC2UYJQMC4ISUZ5REYB2AMDC44YKBNZWG4JB6N6GBL66CEKQO3RDSAB"); + var key = new SCSymbol("kk"); + + var durability = ContractDataDurability.Create(ContractDataDurability.ContractDataDurabilityEnum.PERSISTENT); + var ledgerKey = (LedgerKeyContractData)LedgerKey.ContractData(contractId, key, durability); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyContractData)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(contractId.InnerValue, ((SCContractId)decodedLedgerKey.Contract).InnerValue); + Assert.AreEqual(key.InnerValue, ((SCSymbol)decodedLedgerKey.Key).InnerValue); + Assert.AreEqual(ledgerKey.Durability.InnerValue, decodedLedgerKey.Durability.InnerValue); + } + + [TestMethod] + public void TestLedgerKeyContractDataWithWithContractBeingAccountId() + { + var accountId = new SCAccountId("GCZFMH32MF5EAWETZTKF3ZV5SEVJPI53UEMDNSW55WBR75GMZJU4U573"); + var key = new SCInt64(122); + + var durability = ContractDataDurability.Create(ContractDataDurability.ContractDataDurabilityEnum.TEMPORARY); + var ledgerKey = (LedgerKeyContractData)LedgerKey.ContractData(accountId, key, durability); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyContractData)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(accountId.InnerValue, ((SCAccountId)decodedLedgerKey.Contract).InnerValue); + Assert.AreEqual(key.InnerValue, ((SCInt64)decodedLedgerKey.Key).InnerValue); + Assert.AreEqual(ledgerKey.Durability.InnerValue, decodedLedgerKey.Durability.InnerValue); + } + + [TestMethod] + public void TestLedgerKeyContractCodeCreationFromValidHashString() + { + var ledgerKey = (LedgerKeyContractCode)LedgerKey.ContractCode("AQIDBAUGBwgJAAECAwQFBgcICQABAgMEBQYHCAkAAQI="); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyContractCode)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + CollectionAssert.AreEqual(ledgerKey.Hash.InnerValue, decodedLedgerKey.Hash.InnerValue); + } + + [TestMethod] + public void TestLedgerKeyContractCodeCreationFromInvalidHashString() + { + var ex = Assert.ThrowsException(() => LedgerKey.ContractCode("AQIDBAUGBwgJAAECAwQFBgcICQABAgMEBQYHCAkAAg==")); + Assert.IsTrue(ex.Message.Contains("Hash must have exactly 32 bytes")); + } + + [TestMethod] + public void TestLedgerKeyConfigSetting() + { + var ledgerKey = (LedgerKeyConfigSetting)LedgerKey.ConfigSetting(new ConfigSettingID() + { + InnerValue = ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_STATE_ARCHIVAL + }); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyConfigSetting)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + Assert.AreEqual(ledgerKey.ConfigSettingID.InnerValue, decodedLedgerKey.ConfigSettingID.InnerValue); + } + + [TestMethod] + public void TestLedgerKeyTTLCreationFromValidHashString() + { + var ledgerKey = (LedgerKeyTTL)LedgerKey.TTL("AQIDBAUGBwgJAAECAwQFBgcICQABAgMEBQYHCAkAAQI="); + + // Act + var ledgerKeyXdrBase64 = ledgerKey.ToXdrBase64(); + var decodedLedgerKey = (LedgerKeyTTL)LedgerKey.FromXdrBase64(ledgerKeyXdrBase64); + + // Assert + CollectionAssert.AreEqual(ledgerKey.Key.InnerValue, decodedLedgerKey.Key.InnerValue); + } + + [TestMethod] + public void TestLedgerKeyTTLCreationFromInvalidHashString() + { + var ex = Assert.ThrowsException(() => LedgerKey.ContractCode("AQIDBAUGBwgJAAECAwQFBgcICQABAgMEBQYHCAkAAQIDBA==")); + Assert.IsTrue(ex.Message.Contains("Hash must have exactly 32 bytes")); } } } \ No newline at end of file diff --git a/stellar-dotnet-sdk-test/OperationTest.cs b/stellar-dotnet-sdk-test/OperationTest.cs index dd958830..52271920 100644 --- a/stellar-dotnet-sdk-test/OperationTest.cs +++ b/stellar-dotnet-sdk-test/OperationTest.cs @@ -1,7 +1,5 @@ using System; -using System.Globalization; using System.Linq; -using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using stellar_dotnet_sdk; using xdrSDK = stellar_dotnet_sdk.xdr; @@ -11,1015 +9,1044 @@ using LedgerKey = stellar_dotnet_sdk.LedgerKey; using Operation = stellar_dotnet_sdk.Operation; using Price = stellar_dotnet_sdk.Price; -using Signer = stellar_dotnet_sdk.Signer; -namespace stellar_dotnet_sdk_test +namespace stellar_dotnet_sdk_test; + +[TestClass] +public class OperationTest { - [TestClass] - public class OperationTest + [TestMethod] + [Obsolete] + public void TestCreateAccountOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + + const string startingAmount = "1000"; + var operation = new CreateAccountOperation.Builder(destination, startingAmount) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (CreateAccountOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(10000000000L, xdr.Body.CreateAccountOp.StartingBalance.InnerValue); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(startingAmount, parsedOperation.StartingBalance); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAACVAvkAA==", + operation.ToXdrBase64()); + } + + [TestMethod] + [Obsolete] + public void TestPaymentOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + + Asset asset = new AssetTypeNative(); + var amount = "1000"; + + var operation = new PaymentOperation.Builder(destination, asset, amount) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (PaymentOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(10000000000L, xdr.Body.PaymentOp.Amount.InnerValue); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.IsTrue(parsedOperation.Asset is AssetTypeNative); + Assert.AreEqual(amount, parsedOperation.Amount); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA=", + operation.ToXdrBase64()); + } + + [TestMethod] + [Obsolete] + public void TestPathPaymentStrictReceiveOperation() { - [TestMethod] - [Obsolete] - public void TestCreateAccountOperation() + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset sendAsset = new AssetTypeNative(); + var sendMax = "0.0001"; + Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); + var destAmount = "0.0001"; + Asset[] path = { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), + new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) + }; + + var operation = new PathPaymentStrictReceiveOperation.Builder( + sendAsset, sendMax, destination, destAsset, destAmount) + .SetPath(path) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue); + Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue); + Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(sendMax, parsedOperation.SendMax); + Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); + Assert.AreEqual(destAmount, parsedOperation.DestAmount); + Assert.AreEqual(path.Length, parsedOperation.Path.Length); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", + operation.ToXdrBase64()); + } - const string startingAmount = "1000"; - var operation = new CreateAccountOperation.Builder(destination, startingAmount) - .SetSourceAccount(source) - .Build(); + [TestMethod] + [Obsolete] + public void TestPathPaymentStrictReceiveEmptyPathOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + var unused1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var unused = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset sendAsset = new AssetTypeNative(); + var sendMax = "0.0001"; + Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); + var destAmount = "0.0001"; + + var operation = new PathPaymentStrictReceiveOperation.Builder( + sendAsset, sendMax, destination, destAsset, destAmount) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue); + Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue); + Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(sendMax, parsedOperation.SendMax); + Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); + Assert.AreEqual(destAmount, parsedOperation.DestAmount); + Assert.AreEqual(0, parsedOperation.Path.Length); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==", + operation.ToXdrBase64()); + } - var xdr = operation.ToXdr(); - var parsedOperation = (CreateAccountOperation)Operation.FromXdr(xdr); + [TestMethod] + [Obsolete] + public void TestPathPaymentStrictSendOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset sendAsset = new AssetTypeNative(); + var sendAmount = "0.0001"; + Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); + var destMin = "0.0001"; + Asset[] path = + { + new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), + new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) + }; + + var operation = new PathPaymentStrictSendOperation.Builder( + sendAsset, sendAmount, destination, destAsset, destMin) + .SetPath(path) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (PathPaymentStrictSendOperation)Operation.FromXdr(xdr); + + Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(sendAmount, parsedOperation.SendAmount); + Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); + Assert.AreEqual(destMin, parsedOperation.DestMin); + Assert.AreEqual(path.Length, parsedOperation.Path.Length); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", + operation.ToXdrBase64()); + } - Assert.AreEqual(10000000000L, xdr.Body.CreateAccountOp.StartingBalance.InnerValue); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(startingAmount, parsedOperation.StartingBalance); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + [TestMethod] + [Obsolete] + public void TestPathPaymentStrictSendEmptyPathOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 + var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); + + // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV + var unused1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var unused = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset sendAsset = new AssetTypeNative(); + var sendAmount = "0.0001"; + Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); + var destMin = "0.0001"; + + var operation = new PathPaymentStrictSendOperation.Builder( + sendAsset, sendAmount, destination, destAsset, destMin) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (PathPaymentStrictSendOperation)Operation.FromXdr(xdr); + + Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(sendAmount, parsedOperation.SendAmount); + Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); + Assert.AreEqual(destMin, parsedOperation.DestMin); + Assert.AreEqual(0, parsedOperation.Path.Length); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==", + operation.ToXdrBase64()); + } - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAAAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAACVAvkAA==", - operation.ToXdrBase64()); - } + [TestMethod] + [Obsolete] + public void TestChangeTrustOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - [TestMethod] - [Obsolete] - public void TestPaymentOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + var asset = ChangeTrustAsset.Create(new AssetTypeNative()); + var limit = ChangeTrustOperation.MaxLimit; - Asset asset = new AssetTypeNative(); - var amount = "1000"; + var operation = new ChangeTrustOperation.Builder(asset, limit) + .SetSourceAccount(source) + .Build(); - var operation = new PaymentOperation.Builder(destination, asset, amount) - .SetSourceAccount(source) - .Build(); + var xdr = operation.ToXdr(); + var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr); - var xdr = operation.ToXdr(); - var parsedOperation = (PaymentOperation)Operation.FromXdr(xdr); + Assert.AreEqual(long.MaxValue, xdr.Body.ChangeTrustOp.Limit.InnerValue); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.IsTrue(((ChangeTrustAsset.Wrapper)parsedOperation.Asset).Asset is AssetTypeNative); + Assert.AreEqual(limit, parsedOperation.Limit); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - Assert.AreEqual(10000000000L, xdr.Body.PaymentOp.Amount.InnerValue); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.IsTrue(parsedOperation.Asset is AssetTypeNative); - Assert.AreEqual(amount, parsedOperation.Amount); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=", + operation.ToXdrBase64()); + } - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAEAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAAAAAAAAlQL5AA=", - operation.ToXdrBase64()); - } + [TestMethod] + [Obsolete] + public void TestChangeTrustOperationNoLimit() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - [TestMethod] - [Obsolete] - public void TestPathPaymentStrictReceiveOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); - - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset sendAsset = new AssetTypeNative(); - var sendMax = "0.0001"; - Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); - var destAmount = "0.0001"; - Asset[] path = { new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) }; - - var operation = new PathPaymentStrictReceiveOperation.Builder( - sendAsset, sendMax, destination, destAsset, destAmount) - .SetPath(path) - .SetSourceAccount(source) - .Build(); + var asset = ChangeTrustAsset.Create(new AssetTypeNative()); - var xdr = operation.ToXdr(); - var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue); - Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue); - Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(sendMax, parsedOperation.SendMax); - Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); - Assert.AreEqual(destAmount, parsedOperation.DestAmount); - Assert.AreEqual(path.Length, parsedOperation.Path.Length); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", - operation.ToXdrBase64()); - } + var operation = new ChangeTrustOperation.Builder(asset) + .SetSourceAccount(source) + .Build(); - [TestMethod] - [Obsolete] - public void TestPathPaymentStrictReceiveEmptyPathOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); - - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - var unused1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var unused = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset sendAsset = new AssetTypeNative(); - var sendMax = "0.0001"; - Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); - var destAmount = "0.0001"; - - var operation = new PathPaymentStrictReceiveOperation.Builder( - sendAsset, sendMax, destination, destAsset, destAmount) - .SetSourceAccount(source) - .Build(); + var xdr = operation.ToXdr(); + var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr); - var xdr = operation.ToXdr(); - var parsedOperation = (PathPaymentStrictReceiveOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.SendMax.InnerValue); - Assert.AreEqual(1000L, xdr.Body.PathPaymentStrictReceiveOp.DestAmount.InnerValue); - Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(sendMax, parsedOperation.SendMax); - Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); - Assert.AreEqual(destAmount, parsedOperation.DestAmount); - Assert.AreEqual(0, parsedOperation.Path.Length); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAIAAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==", - operation.ToXdrBase64()); - } + Assert.AreEqual(long.MaxValue, xdr.Body.ChangeTrustOp.Limit.InnerValue); + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.IsTrue(((ChangeTrustAsset.Wrapper)parsedOperation.Asset).Asset is AssetTypeNative); + Assert.AreEqual(ChangeTrustOperation.MaxLimit, parsedOperation.Limit); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - [TestMethod] - [Obsolete] - public void TestPathPaymentStrictSendOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); - - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - var pathIssuer1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var pathIssuer2 = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset sendAsset = new AssetTypeNative(); - var sendAmount = "0.0001"; - Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); - var destMin = "0.0001"; - Asset[] path = { new AssetTypeCreditAlphaNum4("USD", pathIssuer1.AccountId), new AssetTypeCreditAlphaNum12("TESTTEST", pathIssuer2.AccountId) }; - - var operation = new PathPaymentStrictSendOperation.Builder( - sendAsset, sendAmount, destination, destAsset, destMin) - .SetPath(path) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=", + operation.ToXdrBase64()); + } - var xdr = operation.ToXdr(); - var parsedOperation = (PathPaymentStrictSendOperation)Operation.FromXdr(xdr); - - Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(sendAmount, parsedOperation.SendAmount); - Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); - Assert.AreEqual(destMin, parsedOperation.DestMin); - Assert.AreEqual(path.Length, parsedOperation.Path.Length); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAgAAAAFVU0QAAAAAACoIKnpnw8rtrfxa276dFZo1C19mDqWXtG4ufhWrLUd1AAAAAlRFU1RURVNUAAAAAAAAAABE/ttVl8BLV0csW/xgXtbXOVf1lMyDluMiafl0IDVFIg==", - operation.ToXdrBase64()); - } + [TestMethod] + [Obsolete] + public void TestAllowTrustOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var trustor = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - [TestMethod] - [Obsolete] - public void TestPathPaymentStrictSendEmptyPathOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - // GCGZLB3X2B3UFOFSHHQ6ZGEPEX7XYPEH6SBFMIV74EUDOFZJA3VNL6X4 - var issuer = KeyPair.FromSecretSeed("SBOBVZUN6WKVMI6KIL2GHBBEETEV6XKQGILITNH6LO6ZA22DBMSDCPAG"); - - // GAVAQKT2M7B4V3NN7RNNXPU5CWNDKC27MYHKLF5UNYXH4FNLFVDXKRSV - var unused1 = KeyPair.FromSecretSeed("SALDLG5XU5AEJWUOHAJPSC4HJ2IK3Z6BXXP4GWRHFT7P7ILSCFFQ7TC5"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var unused = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset sendAsset = new AssetTypeNative(); - var sendAmount = "0.0001"; - Asset destAsset = new AssetTypeCreditAlphaNum4("USD", issuer.AccountId); - var destMin = "0.0001"; - - var operation = new PathPaymentStrictSendOperation.Builder( - sendAsset, sendAmount, destination, destAsset, destMin) - .SetSourceAccount(source) - .Build(); + const string assetCode = "USDA"; - var xdr = operation.ToXdr(); - var parsedOperation = (PathPaymentStrictSendOperation)Operation.FromXdr(xdr); - - Assert.IsTrue(parsedOperation.SendAsset is AssetTypeNative); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(sendAmount, parsedOperation.SendAmount); - Assert.IsTrue(parsedOperation.DestAsset is AssetTypeCreditAlphaNum4); - Assert.AreEqual(destMin, parsedOperation.DestMin); - Assert.AreEqual(0, parsedOperation.Path.Length); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAA0AAAAAAAAAAAAAA+gAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEAAAAAACNlYd30HdCuLI54eyYjyX/fDyH9IJWIr/hKDcXKQbq1QAAAAAAAAPoAAAAAA==", - operation.ToXdrBase64()); - } + var operation = new AllowTrustOperation.Builder(trustor, assetCode, true, true) + .SetSourceAccount(source) + .Build(); - [TestMethod] - [Obsolete] - public void TestChangeTrustOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + var xdr = operation.ToXdr(); + var parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); - stellar_dotnet_sdk.ChangeTrustAsset asset = stellar_dotnet_sdk.ChangeTrustAsset.Create(new AssetTypeNative()); - var limit = ChangeTrustOperation.MaxLimit; + Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(trustor.AccountId, parsedOperation.Trustor.AccountId); + Assert.AreEqual(assetCode, parsedOperation.AssetCode); - var operation = new ChangeTrustOperation.Builder(asset, limit) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual(OperationThreshold.Low, parsedOperation.Threshold); - var xdr = operation.ToXdr(); - var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr); + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAcAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEQQAAAAE=", + operation.ToXdrBase64()); - Assert.AreEqual(long.MaxValue, xdr.Body.ChangeTrustOp.Limit.InnerValue); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.IsTrue(((stellar_dotnet_sdk.ChangeTrustAsset.Wrapper)parsedOperation.Asset).Asset is AssetTypeNative); - Assert.AreEqual(limit, parsedOperation.Limit); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + TestAllowTrustOperationAuthorize(source, trustor, assetCode); + } - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=", - operation.ToXdrBase64()); - } + [Obsolete] + private static void TestAllowTrustOperationAuthorize(KeyPair source, KeyPair trustor, string assetCode) + { + AllowTrustOperation operation = null; + xdrSDK.Operation xdr = null; + AllowTrustOperation parsedOperation = null; - [TestMethod] - [Obsolete] - public void TestChangeTrustOperationNoLimit() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + //Authorize: true, MaintainLiabilities: false -> true, false + operation = new AllowTrustOperation.Builder(trustor, assetCode, true, false) + .SetSourceAccount(source) + .Build(); - stellar_dotnet_sdk.ChangeTrustAsset asset = stellar_dotnet_sdk.ChangeTrustAsset.Create(new AssetTypeNative()); + xdr = operation.ToXdr(); + parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); - var operation = new ChangeTrustOperation.Builder(asset) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual(true, parsedOperation.Authorize); + Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); - var xdr = operation.ToXdr(); - var parsedOperation = (ChangeTrustOperation)Operation.FromXdr(xdr); + //Authorize: false, MaintainLiabilities: true -> false, true + operation = new AllowTrustOperation.Builder(trustor, assetCode, false, true) + .SetSourceAccount(source) + .Build(); - Assert.AreEqual(long.MaxValue, xdr.Body.ChangeTrustOp.Limit.InnerValue); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.IsTrue(((stellar_dotnet_sdk.ChangeTrustAsset.Wrapper)parsedOperation.Asset).Asset is AssetTypeNative); - Assert.AreEqual(ChangeTrustOperation.MaxLimit, parsedOperation.Limit); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + xdr = operation.ToXdr(); + parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAYAAAAAf/////////8=", - operation.ToXdrBase64()); - } + Assert.AreEqual(false, parsedOperation.Authorize); + Assert.AreEqual(true, parsedOperation.AuthorizeToMaintainLiabilities); - [TestMethod] - [Obsolete] - public void TestAllowTrustOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var trustor = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); + //Authorize: true, MaintainLiabilities: true -> true, false + operation = new AllowTrustOperation.Builder(trustor, assetCode, true, true) + .SetSourceAccount(source) + .Build(); - const string assetCode = "USDA"; + xdr = operation.ToXdr(); + parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); - var operation = new AllowTrustOperation.Builder(trustor, assetCode, true, true) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual(true, parsedOperation.Authorize); + Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); - var xdr = operation.ToXdr(); - var parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); + //Authorize: false, MaintainLiabilities: false -> false, false + operation = new AllowTrustOperation.Builder(trustor, assetCode, false, false) + .SetSourceAccount(source) + .Build(); - Assert.AreEqual(source.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(trustor.AccountId, parsedOperation.Trustor.AccountId); - Assert.AreEqual(assetCode, parsedOperation.AssetCode); + xdr = operation.ToXdr(); + parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); - Assert.AreEqual(OperationThreshold.Low, parsedOperation.Threshold); + Assert.AreEqual(false, parsedOperation.Authorize); + Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); + } - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAcAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxAAAAABVVNEQQAAAAE=", - operation.ToXdrBase64()); + [TestMethod] + public void TestManageOfferOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset selling = new AssetTypeNative(); + var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); + var amount = "0.00001"; + var price = "0.85334384"; // n=5333399 d=6250000 + var priceObj = Price.FromString(price); + long offerId = 1; + + var operation = new ManageSellOfferOperation.Builder(selling, buying, amount, price) + .SetOfferId(offerId) + .SetSourceAccount(source) + .Build(); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", + operation.ToXdrBase64()); + } - TestAllowTrustOperationAuthorize(source, trustor, assetCode); - } + [TestMethod] + [Obsolete] + public void TestManageSellOfferOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset selling = new AssetTypeNative(); + var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); + var amount = "0.00001"; + var price = "0.85334384"; // n=5333399 d=6250000 + var priceObj = Price.FromString(price); + long offerId = 1; + + var operation = new ManageSellOfferOperation.Builder(selling, buying, amount, price) + .SetOfferId(offerId) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (ManageSellOfferOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(100L, xdr.Body.ManageSellOfferOp.Amount.InnerValue); + Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); + Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); + Assert.IsTrue(parsedOperation.Buying.Equals(buying)); + Assert.AreEqual(amount, parsedOperation.Amount); + Assert.AreEqual(price, parsedOperation.Price); + Assert.AreEqual(priceObj.Numerator, 5333399); + Assert.AreEqual(priceObj.Denominator, 6250000); + Assert.AreEqual(offerId, parsedOperation.OfferId); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", + operation.ToXdrBase64()); + } - [Obsolete] - private static void TestAllowTrustOperationAuthorize(KeyPair source, KeyPair trustor, string assetCode) - { - AllowTrustOperation operation = null; - stellar_dotnet_sdk.xdr.Operation xdr = null; - AllowTrustOperation parsedOperation = null; + [TestMethod] + [Obsolete] + public void TestManageBuyOfferOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset selling = new AssetTypeNative(); + var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); + var amount = "0.00001"; + var price = "0.85334384"; // n=5333399 d=6250000 + var priceObj = Price.FromString(price); + long offerId = 1; + + var operation = new ManageBuyOfferOperation.Builder(selling, buying, amount, price) + .SetOfferId(offerId) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (ManageBuyOfferOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(100L, xdr.Body.ManageBuyOfferOp.BuyAmount.InnerValue); + Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); + Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); + Assert.IsTrue(parsedOperation.Buying.Equals(buying)); + Assert.AreEqual(amount, parsedOperation.BuyAmount); + Assert.AreEqual(price, parsedOperation.Price); + Assert.AreEqual(priceObj.Numerator, 5333399); + Assert.AreEqual(priceObj.Denominator, 6250000); + Assert.AreEqual(offerId, parsedOperation.OfferId); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAwAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", + operation.ToXdrBase64()); + } - //Authorize: true, MaintainLiabilities: false -> true, false - operation = new AllowTrustOperation.Builder(trustor, assetCode, true, false) - .SetSourceAccount(source) - .Build(); + [TestMethod] + public void TestCreatePassiveOfferOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset selling = new AssetTypeNative(); + var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); + var amount = "0.00001"; + var price = "2.93850088"; // n=36731261 d=12500000 + var priceObj = Price.FromString(price); + + var operation = new CreatePassiveSellOfferOperation.Builder(selling, buying, amount, price) + .SetSourceAccount(source) + .Build(); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg", + operation.ToXdrBase64()); + } - xdr = operation.ToXdr(); - parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); + [TestMethod] + [Obsolete] + public void TestCreatePassiveSellOfferOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR + var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); + + Asset selling = new AssetTypeNative(); + var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); + var amount = "0.00001"; + var price = "2.93850088"; // n=36731261 d=12500000 + var priceObj = Price.FromString(price); + + var operation = new CreatePassiveSellOfferOperation.Builder(selling, buying, amount, price) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (CreatePassiveSellOfferOperation)Operation.FromXdr(xdr); + + Assert.AreEqual(100L, xdr.Body.CreatePassiveSellOfferOp.Amount.InnerValue); + Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); + Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); + Assert.IsTrue(parsedOperation.Buying.Equals(buying)); + Assert.AreEqual(amount, parsedOperation.Amount); + Assert.AreEqual(price, parsedOperation.Price); + Assert.AreEqual(priceObj.Numerator, 36731261); + Assert.AreEqual(priceObj.Denominator, 12500000); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); + + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg", + operation.ToXdrBase64()); + } - Assert.AreEqual(true, parsedOperation.Authorize); - Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); + [TestMethod] + [Obsolete] + public void TestAccountMergeOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR + var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - //Authorize: false, MaintainLiabilities: true -> false, true - operation = new AllowTrustOperation.Builder(trustor, assetCode, false, true) - .SetSourceAccount(source) - .Build(); + var operation = new AccountMergeOperation.Builder(destination) + .SetSourceAccount(source) + .Build(); - xdr = operation.ToXdr(); - parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); + var xdr = operation.ToXdr(); - Assert.AreEqual(false, parsedOperation.Authorize); - Assert.AreEqual(true, parsedOperation.AuthorizeToMaintainLiabilities); + var parsedOperation = (AccountMergeOperation)Operation.FromXdr(xdr); - //Authorize: true, MaintainLiabilities: true -> true, false - operation = new AllowTrustOperation.Builder(trustor, assetCode, true, true) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); + Assert.AreEqual(OperationThreshold.High, parsedOperation.Threshold); - xdr = operation.ToXdr(); - parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAgAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxA=", + operation.ToXdrBase64()); + } - Assert.AreEqual(true, parsedOperation.Authorize); - Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); + [TestMethod] + [Obsolete] + public void TestManageDataOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - //Authorize: false, MaintainLiabilities: false -> false, false - operation = new AllowTrustOperation.Builder(trustor, assetCode, false, false) - .SetSourceAccount(source) - .Build(); + var operation = new ManageDataOperation.Builder("test", new byte[] { 0, 1, 2, 3, 4 }) + .SetSourceAccount(source) + .Build(); - xdr = operation.ToXdr(); - parsedOperation = (AllowTrustOperation)Operation.FromXdr(xdr); + var xdr = operation.ToXdr(); - Assert.AreEqual(false, parsedOperation.Authorize); - Assert.AreEqual(false, parsedOperation.AuthorizeToMaintainLiabilities); - } + var parsedOperation = (ManageDataOperation)Operation.FromXdr(xdr); - [TestMethod] - public void TestManageOfferOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset selling = new AssetTypeNative(); - var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); - var amount = "0.00001"; - var price = "0.85334384"; // n=5333399 d=6250000 - var priceObj = Price.FromString(price); - long offerId = 1; - - var operation = new ManageSellOfferOperation.Builder(selling, buying, amount, price) - .SetOfferId(offerId) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual("test", parsedOperation.Name); + Assert.IsTrue(new byte[] { 0, 1, 2, 3, 4 }.SequenceEqual(parsedOperation.Value)); + Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", - operation.ToXdrBase64()); - } + Assert.AreEqual( + "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAEAAAAFAAECAwQAAAA=", + operation.ToXdrBase64()); + } - [TestMethod] - [Obsolete] - public void TestManageSellOfferOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset selling = new AssetTypeNative(); - var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); - var amount = "0.00001"; - var price = "0.85334384"; // n=5333399 d=6250000 - var priceObj = Price.FromString(price); - long offerId = 1; - - var operation = new ManageSellOfferOperation.Builder(selling, buying, amount, price) - .SetOfferId(offerId) - .SetSourceAccount(source) - .Build(); + [TestMethod] + [Obsolete] + public void TestManageDataOperationEmptyValue() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - var xdr = operation.ToXdr(); - var parsedOperation = (ManageSellOfferOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(100L, xdr.Body.ManageSellOfferOp.Amount.InnerValue); - Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); - Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); - Assert.IsTrue(parsedOperation.Buying.Equals(buying)); - Assert.AreEqual(amount, parsedOperation.Amount); - Assert.AreEqual(price, parsedOperation.Price); - Assert.AreEqual(priceObj.Numerator, 5333399); - Assert.AreEqual(priceObj.Denominator, 6250000); - Assert.AreEqual(offerId, parsedOperation.OfferId); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAMAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", - operation.ToXdrBase64()); - } + var operation = new ManageDataOperation.Builder("test", null) + .SetSourceAccount(source) + .Build(); - [TestMethod] - [Obsolete] - public void TestManageBuyOfferOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset selling = new AssetTypeNative(); - var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); - var amount = "0.00001"; - var price = "0.85334384"; // n=5333399 d=6250000 - var priceObj = Price.FromString(price); - long offerId = 1; - - var operation = new ManageBuyOfferOperation.Builder(selling, buying, amount, price) - .SetOfferId(offerId) - .SetSourceAccount(source) - .Build(); + var xdr = operation.ToXdr(); - var xdr = operation.ToXdr(); - var parsedOperation = (ManageBuyOfferOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(100L, xdr.Body.ManageBuyOfferOp.BuyAmount.InnerValue); - Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); - Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); - Assert.IsTrue(parsedOperation.Buying.Equals(buying)); - Assert.AreEqual(amount, parsedOperation.BuyAmount); - Assert.AreEqual(price, parsedOperation.Price); - Assert.AreEqual(priceObj.Numerator, 5333399); - Assert.AreEqual(priceObj.Denominator, 6250000); - Assert.AreEqual(offerId, parsedOperation.OfferId); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAwAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZABRYZcAX14QAAAAAAAAAAE=", - operation.ToXdrBase64()); - } + var parsedOperation = (ManageDataOperation)Operation.FromXdr(xdr); - [TestMethod] - public void TestCreatePassiveOfferOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset selling = new AssetTypeNative(); - var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); - var amount = "0.00001"; - var price = "2.93850088"; // n=36731261 d=12500000 - var priceObj = Price.FromString(price); - - var operation = new CreatePassiveSellOfferOperation.Builder(selling, buying, amount, price) - .SetSourceAccount(source) - .Build(); + Assert.AreEqual("test", parsedOperation.Name); + Assert.AreEqual(null, parsedOperation.Value); - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg", - operation.ToXdrBase64()); - } + Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=", + operation.ToXdrBase64()); + } - [TestMethod] - [Obsolete] - public void TestCreatePassiveSellOfferOperation() + [TestMethod] + public void TestToXdrAmount() + { + Assert.AreEqual(0L, Operation.ToXdrAmount("0")); + Assert.AreEqual(1L, Operation.ToXdrAmount("0.0000001")); + Assert.AreEqual(10000000L, Operation.ToXdrAmount("1")); + Assert.AreEqual(11234567L, Operation.ToXdrAmount("1.1234567")); + Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.3007381")); + Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.30073810")); + Assert.AreEqual(1014016711446800155L, Operation.ToXdrAmount("101401671144.6800155")); + Assert.AreEqual(9223372036854775807L, Operation.ToXdrAmount("922337203685.4775807")); + + try { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var issuer = KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ"); - - Asset selling = new AssetTypeNative(); - var buying = Asset.CreateNonNativeAsset("USD", issuer.AccountId); - var amount = "0.00001"; - var price = "2.93850088"; // n=36731261 d=12500000 - var priceObj = Price.FromString(price); - - var operation = new CreatePassiveSellOfferOperation.Builder(selling, buying, amount, price) - .SetSourceAccount(source) - .Build(); - - var xdr = operation.ToXdr(); - var parsedOperation = (CreatePassiveSellOfferOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(100L, xdr.Body.CreatePassiveSellOfferOp.Amount.InnerValue); - Assert.IsTrue(parsedOperation.Selling is AssetTypeNative); - Assert.IsTrue(parsedOperation.Buying is AssetTypeCreditAlphaNum4); - Assert.IsTrue(parsedOperation.Buying.Equals(buying)); - Assert.AreEqual(amount, parsedOperation.Amount); - Assert.AreEqual(price, parsedOperation.Price); - Assert.AreEqual(priceObj.Numerator, 36731261); - Assert.AreEqual(priceObj.Denominator, 12500000); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAQAAAAAAAAAAVVTRAAAAAAARP7bVZfAS1dHLFv8YF7W1zlX9ZTMg5bjImn5dCA1RSIAAAAAAAAAZAIweX0Avrwg", - operation.ToXdrBase64()); + Operation.ToXdrAmount("0.00000001"); + Assert.Fail(); } - - [TestMethod] - [Obsolete] - public void TestAccountMergeOperation() + catch (ArithmeticException) { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR - var destination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); - - var operation = new AccountMergeOperation.Builder(destination) - .SetSourceAccount(source) - .Build(); - - var xdr = operation.ToXdr(); - - var parsedOperation = (AccountMergeOperation)Operation.FromXdr(xdr); - - Assert.AreEqual(destination.AccountId, parsedOperation.Destination.AccountId); - Assert.AreEqual(OperationThreshold.High, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAgAAAAA7eBSYbzcL5UKo7oXO24y1ckX+XuCtkDsyNHOp1n1bxA=", - operation.ToXdrBase64()); } - - [TestMethod] - [Obsolete] - public void TestManageDataOperation() + catch (Exception) { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - - var operation = new ManageDataOperation.Builder("test", new byte[] { 0, 1, 2, 3, 4 }) - .SetSourceAccount(source) - .Build(); - - var xdr = operation.ToXdr(); - - var parsedOperation = (ManageDataOperation)Operation.FromXdr(xdr); - - Assert.AreEqual("test", parsedOperation.Name); - Assert.IsTrue(new byte[] { 0, 1, 2, 3, 4 }.SequenceEqual(parsedOperation.Value)); - Assert.AreEqual(OperationThreshold.Medium, parsedOperation.Threshold); - - Assert.AreEqual( - "AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAEAAAAFAAECAwQAAAA=", - operation.ToXdrBase64()); + Assert.Fail(); } - [TestMethod] - [Obsolete] - public void TestManageDataOperationEmptyValue() + try { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - - var operation = new ManageDataOperation.Builder("test", null) - .SetSourceAccount(source) - .Build(); - - var xdr = operation.ToXdr(); - - var parsedOperation = (ManageDataOperation)Operation.FromXdr(xdr); - - Assert.AreEqual("test", parsedOperation.Name); - Assert.AreEqual(null, parsedOperation.Value); - - Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAoAAAAEdGVzdAAAAAA=", - operation.ToXdrBase64()); + Operation.ToXdrAmount("72991284.30073811"); + Assert.Fail(); } - - [TestMethod] - public void TestToXdrAmount() + catch (ArithmeticException) { - Assert.AreEqual(0L, Operation.ToXdrAmount("0")); - Assert.AreEqual(1L, Operation.ToXdrAmount("0.0000001")); - Assert.AreEqual(10000000L, Operation.ToXdrAmount("1")); - Assert.AreEqual(11234567L, Operation.ToXdrAmount("1.1234567")); - Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.3007381")); - Assert.AreEqual(729912843007381L, Operation.ToXdrAmount("72991284.30073810")); - Assert.AreEqual(1014016711446800155L, Operation.ToXdrAmount("101401671144.6800155")); - Assert.AreEqual(9223372036854775807L, Operation.ToXdrAmount("922337203685.4775807")); - - try - { - Operation.ToXdrAmount("0.00000001"); - Assert.Fail(); - } - catch (ArithmeticException) - { - } - catch (Exception) - { - Assert.Fail(); - } - - try - { - Operation.ToXdrAmount("72991284.30073811"); - Assert.Fail(); - } - catch (ArithmeticException) - { - } - catch (Exception) - { - Assert.Fail(); - } } - - [TestMethod] - [Obsolete] - public void TestBumpSequence() + catch (Exception) { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + Assert.Fail(); + } + } - var operation = new BumpSequenceOperation.Builder(156L) - .SetSourceAccount(source) - .Build(); + [TestMethod] + [Obsolete] + public void TestBumpSequence() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - var xdr = operation.ToXdr(); + var operation = new BumpSequenceOperation.Builder(156L) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (BumpSequenceOperation)Operation.FromXdr(xdr); + var xdr = operation.ToXdr(); - Assert.AreEqual(156L, parsedOperation.BumpTo); - Assert.AreEqual(OperationThreshold.Low, parsedOperation.Threshold); + var parsedOperation = (BumpSequenceOperation)Operation.FromXdr(xdr); - Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAsAAAAAAAAAnA==", operation.ToXdrBase64()); - } + Assert.AreEqual(156L, parsedOperation.BumpTo); + Assert.AreEqual(OperationThreshold.Low, parsedOperation.Threshold); - [TestMethod] - [Obsolete] - public void TestInflationOperation() - { - // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF - var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); + Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAsAAAAAAAAAnA==", + operation.ToXdrBase64()); + } - var operation = new InflationOperation.Builder() - .SetSourceAccount(source) - .Build(); + [TestMethod] + [Obsolete] + public void TestInflationOperation() + { + // GC5SIC4E3V56VOHJ3OZAX5SJDTWY52JYI2AFK6PUGSXFVRJQYQXXZBZF + var source = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); - var xdr = operation.ToXdr(); + var operation = new InflationOperation.Builder() + .SetSourceAccount(source) + .Build(); - var parsedOperation = (InflationOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAk=", operation.ToXdrBase64()); - } + var parsedOperation = (InflationOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - [TestMethod] - [Obsolete] - public void TestCreateClaimableBalanceOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual("AAAAAQAAAAC7JAuE3XvquOnbsgv2SRztjuk4RoBVefQ0rlrFMMQvfAAAAAk=", operation.ToXdrBase64()); + } - // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP - var destination = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); + [TestMethod] + [Obsolete] + public void TestCreateClaimableBalanceOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var asset = new AssetTypeNative(); - var claimant = new Claimant - { - Destination = destination, - Predicate = ClaimPredicate.Not(ClaimPredicate.BeforeRelativeTime(new xdrSDK.Duration(new xdrSDK.Uint64((UInt64)TimeSpan.FromHours(7.0).TotalSeconds)))) - }; + // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP + var destination = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); - var operation = new CreateClaimableBalanceOperation.Builder(asset, "123.45", new[] { claimant }) - .SetSourceAccount(source) - .Build(); + var asset = new AssetTypeNative(); + var claimant = new Claimant + { + Destination = destination, + Predicate = ClaimPredicate.Not(ClaimPredicate.BeforeRelativeTime( + new xdrSDK.Duration(new xdrSDK.Uint64((ulong)TimeSpan.FromHours(7.0).TotalSeconds)))) + }; - var xdr = operation.ToXdr(); + var operation = new CreateClaimableBalanceOperation.Builder(asset, "123.45", new[] { claimant }) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (CreateClaimableBalanceOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA4AAAAAAAAAAEmU+aAAAAABAAAAAAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAMAAAABAAAABQAAAAAAAGJw", operation.ToXdrBase64()); - } + var parsedOperation = (CreateClaimableBalanceOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - /// - /// The API didn't previously did not support the balance id type within the balance id (expected 32 bytes rather than the full 36). - /// This tests that we can still pass in the 32 bytes for compatability and use the default type (0). - /// - [TestMethod] - [Obsolete] - public void TestClaimClaimableBalanceWithLegacyByteIdOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA4AAAAAAAAAAEmU+aAAAAABAAAAAAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfgAAAAMAAAABAAAABQAAAAAAAGJw", + operation.ToXdrBase64()); + } - var balanceId = Enumerable.Repeat((byte)0x07, 32).ToArray(); - var operation = new ClaimClaimableBalanceOperation.Builder(balanceId) - .SetSourceAccount(source) - .Build(); + /// + /// The API didn't previously did not support the balance id type within the balance id (expected 32 bytes rather than + /// the full 36). + /// This tests that we can still pass in the 32 bytes for compatability and use the default type (0). + /// + [TestMethod] + [Obsolete] + public void TestClaimClaimableBalanceWithLegacyByteIdOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var xdr = operation.ToXdr(); + var balanceId = Enumerable.Repeat((byte)0x07, 32).ToArray(); + var operation = new ClaimClaimableBalanceOperation.Builder(balanceId) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA8AAAAABwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=", operation.ToXdrBase64()); - } + var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - /// - /// Claim a claimable balance using the byte representation of the balance id. - /// - [TestMethod] - [Obsolete] - public void TestClaimClaimableBalanceWithByteIdOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA8AAAAABwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=", + operation.ToXdrBase64()); + } - // Prepend type bytes (first four bytes are the balance id type) - var balanceId = Enumerable.Repeat((byte)0x07, 32).Prepend((byte)0).Prepend((byte)0).Prepend((byte)0).Prepend((byte)0).ToArray(); - var operation = new ClaimClaimableBalanceOperation.Builder(balanceId) - .SetSourceAccount(source) - .Build(); + /// + /// Claim a claimable balance using the byte representation of the balance id. + /// + [TestMethod] + [Obsolete] + public void TestClaimClaimableBalanceWithByteIdOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var xdr = operation.ToXdr(); + // Prepend type bytes (first four bytes are the balance id type) + var balanceId = Enumerable.Repeat((byte)0x07, 32).Prepend((byte)0).Prepend((byte)0).Prepend((byte)0) + .Prepend((byte)0).ToArray(); + var operation = new ClaimClaimableBalanceOperation.Builder(balanceId) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA8AAAAABwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=", operation.ToXdrBase64()); - } + var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - /// - /// Claim a claimable balance using the string representation of the balance id. - /// - [TestMethod] - [Obsolete] - public void TestClaimClaimableBalanceWithStringIdOperationValid() - { - var balanceId = "000000006d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; - var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); - var operation = new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build(); - - var xdr = operation.ToXdr(); - var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - CollectionAssert.AreEqual(operation.BalanceId, parsedOperation.BalanceId); - - Assert.AreEqual( - "AAAAAQAAAAADOcvN4KfwUbxY/oKijIj6+TBW9Ca0QaQuRkR7MK0FBgAAAA8AAAAAbWoMFCUWqcx4hahcWro6H0r1GBz556gJrHrl5KWMgl8=", - operation.ToXdrBase64()); - } + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAAA8AAAAABwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwcHBwc=", + operation.ToXdrBase64()); + } - [TestMethod] - public void TestClaimClaimableBalanceOperationInvalidEmptyBalanceId() - { - var balanceId = ""; - var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); + /// + /// Claim a claimable balance using the string representation of the balance id. + /// + [TestMethod] + [Obsolete] + public void TestClaimClaimableBalanceWithStringIdOperationValid() + { + var balanceId = "000000006d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; + var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); + var operation = new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build(); + + var xdr = operation.ToXdr(); + var parsedOperation = (ClaimClaimableBalanceOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + CollectionAssert.AreEqual(operation.BalanceId, parsedOperation.BalanceId); + + Assert.AreEqual( + "AAAAAQAAAAADOcvN4KfwUbxY/oKijIj6+TBW9Ca0QaQuRkR7MK0FBgAAAA8AAAAAbWoMFCUWqcx4hahcWro6H0r1GBz556gJrHrl5KWMgl8=", + operation.ToXdrBase64()); + } - Assert.ThrowsException(() => - new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); - } + [TestMethod] + public void TestClaimClaimableBalanceOperationInvalidEmptyBalanceId() + { + var balanceId = ""; + var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); - /// - /// The first 4 bytes of the balance id are the balance id type, these are required. The default is 0x00000000. - /// - [TestMethod] - public void TestClaimClaimableBalanceOperationInvalidClaimableBalanceIDTypeMissing() - { - var balanceId = "6d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; - var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); + Assert.ThrowsException(() => + new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); + } - Assert.ThrowsException(() => - new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); - } + /// + /// The first 4 bytes of the balance id are the balance id type, these are required. The default is 0x00000000. + /// + [TestMethod] + public void TestClaimClaimableBalanceOperationInvalidClaimableBalanceIDTypeMissing() + { + var balanceId = "6d6a0c142516a9cc7885a85c5aba3a1f4af5181cf9e7a809ac7ae5e4a58c825f"; + var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); - /// - /// The last 32 bytes of the balance id are the balance id body, this is required. - /// - [TestMethod] - public void TestClaimClaimableBalanceOperationInvalidClaimableBalanceIDBodyMissing() - { - var balanceId = "00000000"; - var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); + Assert.ThrowsException(() => + new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); + } - Assert.ThrowsException(() => - new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); - } + /// + /// The last 32 bytes of the balance id are the balance id body, this is required. + /// + [TestMethod] + public void TestClaimClaimableBalanceOperationInvalidClaimableBalanceIDBodyMissing() + { + var balanceId = "00000000"; + var accountId = KeyPair.FromAccountId("GABTTS6N4CT7AUN4LD7IFIUMRD5PSMCW6QTLIQNEFZDEI6ZQVUCQMCLN"); - [TestMethod] - [Obsolete] - public void TestBeginSponsoringFutureReservesOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.ThrowsException(() => + new ClaimClaimableBalanceOperation.Builder(balanceId).SetSourceAccount(accountId).Build()); + } - // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP - var sponsored = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); + [TestMethod] + [Obsolete] + public void TestBeginSponsoringFutureReservesOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var operation = new BeginSponsoringFutureReservesOperation.Builder(sponsored) - .SetSourceAccount(source) - .Build(); + // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP + var sponsored = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); - var xdr = operation.ToXdr(); + var operation = new BeginSponsoringFutureReservesOperation.Builder(sponsored) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (BeginSponsoringFutureReservesOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABAAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4=", operation.ToXdrBase64()); - } + var parsedOperation = (BeginSponsoringFutureReservesOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - [TestMethod] - [Obsolete] - public void TestEndSponsoringFutureReservesOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABAAAAAAJcrx2g/Hbs/ohF5CVFG7B5JJSJR+OqDKzDGK7dKHZH4=", + operation.ToXdrBase64()); + } - var operation = new EndSponsoringFutureReservesOperation.Builder() - .SetSourceAccount(source) - .Build(); + [TestMethod] + [Obsolete] + public void TestEndSponsoringFutureReservesOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var xdr = operation.ToXdr(); + var operation = new EndSponsoringFutureReservesOperation.Builder() + .SetSourceAccount(source) + .Build(); - var parsedOperation = (EndSponsoringFutureReservesOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABE=", operation.ToXdrBase64()); - } + var parsedOperation = (EndSponsoringFutureReservesOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - [TestMethod] - [Obsolete] - public void TestRevokeLedgerEntrySponsorshipOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABE=", operation.ToXdrBase64()); + } - // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP - var otherAccount = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); + [TestMethod] + [Obsolete] + public void TestRevokeLedgerEntrySponsorshipOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var ledgerKey = LedgerKey.Account(otherAccount); - var operation = new RevokeLedgerEntrySponsorshipOperation.Builder(ledgerKey) - .SetSourceAccount(source) - .Build(); + // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP + var otherAccount = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); - var xdr = operation.ToXdr(); + var ledgerKey = LedgerKey.Account(otherAccount); + var operation = new RevokeLedgerEntrySponsorshipOperation.Builder(ledgerKey) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (RevokeLedgerEntrySponsorshipOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABIAAAAAAAAAAAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfg==", operation.ToXdrBase64()); - } + var parsedOperation = (RevokeLedgerEntrySponsorshipOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - [TestMethod] - [Obsolete] - public void TestRevokeSignerSponsorshipOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABIAAAAAAAAAAAAAAAAlyvHaD8duz+iEXkJUUbsHkklIlH46oMrMMYrt0odkfg==", + operation.ToXdrBase64()); + } - // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP - var otherAccount = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); + [TestMethod] + [Obsolete] + public void TestRevokeSignerSponsorshipOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var signerKey = Signer.Ed25519PublicKey(otherAccount); + // GAS4V4O2B7DW5T7IQRPEEVCRXMDZESKISR7DVIGKZQYYV3OSQ5SH5LVP + var otherAccount = KeyPair.FromSecretSeed("SBMSVD4KKELKGZXHBUQTIROWUAPQASDX7KEJITARP4VMZ6KLUHOGPTYW"); - var operation = new RevokeSignerSponsorshipOperation.Builder(otherAccount, signerKey) - .SetSourceAccount(source) - .Build(); + var signerKey = SignerUtil.Ed25519PublicKey(otherAccount); - var xdr = operation.ToXdr(); + var operation = new RevokeSignerSponsorshipOperation.Builder(otherAccount, signerKey) + .SetSourceAccount(source) + .Build(); - var parsedOperation = (RevokeSignerSponsorshipOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + var xdr = operation.ToXdr(); - Assert.AreEqual("AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABIAAAABAAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+AAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+", operation.ToXdrBase64()); - } + var parsedOperation = (RevokeSignerSponsorshipOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - [TestMethod] - public void TestFromXdrAmount() - { - Assert.AreEqual("0", Operation.FromXdrAmount(0L)); - Assert.AreEqual("0.0000001", Operation.FromXdrAmount(1L)); - Assert.AreEqual("1", Operation.FromXdrAmount(10000000L)); - Assert.AreEqual("1.1234567", Operation.FromXdrAmount(11234567L)); - Assert.AreEqual("72991284.3007381", Operation.FromXdrAmount(729912843007381L)); - Assert.AreEqual("101401671144.6800155", Operation.FromXdrAmount(1014016711446800155L)); - Assert.AreEqual("922337203685.4775807", Operation.FromXdrAmount(9223372036854775807L)); - } + Assert.AreEqual( + "AAAAAQAAAADg3G3hclysZlFitS+s5zWyiiJD5B0STWy5LXCj6i5yxQAAABIAAAABAAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+AAAAACXK8doPx27P6IReQlRRuweSSUiUfjqgyswxiu3Sh2R+", + operation.ToXdrBase64()); + } - [TestMethod] - [Obsolete] - public void TestClawbackOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + [TestMethod] + public void TestFromXdrAmount() + { + Assert.AreEqual("0", Operation.FromXdrAmount(0L)); + Assert.AreEqual("0.0000001", Operation.FromXdrAmount(1L)); + Assert.AreEqual("1", Operation.FromXdrAmount(10000000L)); + Assert.AreEqual("1.1234567", Operation.FromXdrAmount(11234567L)); + Assert.AreEqual("72991284.3007381", Operation.FromXdrAmount(729912843007381L)); + Assert.AreEqual("101401671144.6800155", Operation.FromXdrAmount(1014016711446800155L)); + Assert.AreEqual("922337203685.4775807", Operation.FromXdrAmount(9223372036854775807L)); + } + + [TestMethod] + [Obsolete] + public void TestClawbackOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var operation = new ClawbackOperation.Builder(Asset.CreateNonNativeAsset("EUR", "GDIROJW2YHMSFZJJ4R5XWWNUVND5I45YEWS5DSFKXCHMADZ5V374U2LM"), "1000", KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7")) + var operation = + new ClawbackOperation.Builder( + Asset.CreateNonNativeAsset("EUR", "GDIROJW2YHMSFZJJ4R5XWWNUVND5I45YEWS5DSFKXCHMADZ5V374U2LM"), + "1000", KeyPair.FromAccountId("GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7")) .SetSourceAccount(source) .Build(); - var xdr = operation.ToXdr(); + var xdr = operation.ToXdr(); - var parsedOperation = (ClawbackOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(operation.Amount, parsedOperation.Amount); - Assert.AreEqual(operation.Asset, parsedOperation.Asset); - Assert.AreEqual(operation.From.AccountId, parsedOperation.From.AccountId); - } + var parsedOperation = (ClawbackOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(operation.Amount, parsedOperation.Amount); + Assert.AreEqual(operation.Asset, parsedOperation.Asset); + Assert.AreEqual(operation.From.AccountId, parsedOperation.From.AccountId); + } - [TestMethod] - [Obsolete] - public void TestClawbackClaimableBalanceOperation() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + [TestMethod] + [Obsolete] + public void TestClawbackClaimableBalanceOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - var operation = new ClawbackClaimableBalanceOperation.Builder("00000000526674017c3cf392614b3f2f500230affd58c7c364625c350c61058fbeacbdf7") + var operation = + new ClawbackClaimableBalanceOperation.Builder( + "00000000526674017c3cf392614b3f2f500230affd58c7c364625c350c61058fbeacbdf7") .SetSourceAccount(source) .Build(); - var xdr = operation.ToXdr(); + var xdr = operation.ToXdr(); - var parsedOperation = (ClawbackClaimableBalanceOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(operation.BalanceId.Length, parsedOperation.BalanceId.Length); - } + var parsedOperation = (ClawbackClaimableBalanceOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(operation.BalanceId.Length, parsedOperation.BalanceId.Length); + } - [TestMethod] - public void TestClawbackClaimableBalanceOperationLengthNotCorrect() - { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - - try - { - var operation = new ClawbackClaimableBalanceOperation.Builder(new byte[34]) - .SetSourceAccount(source) - .Build(); - } - catch (ArgumentException e) - { - Assert.AreEqual(e.Message, new ArgumentException("Must be 36 bytes long", "balanceId").Message); - } - } + [TestMethod] + public void TestClawbackClaimableBalanceOperationLengthNotCorrect() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - [TestMethod] - [Obsolete] - public void TestSetTrustlineFlagsOperation() + try { - // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 - var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); - - var operation = new SetTrustlineFlagsOperation.Builder(Asset.CreateNonNativeAsset("EUR", "GDIROJW2YHMSFZJJ4R5XWWNUVND5I45YEWS5DSFKXCHMADZ5V374U2LM"), KeyPair.Random(), 1, 1) + var operation = new ClawbackClaimableBalanceOperation.Builder(new byte[34]) .SetSourceAccount(source) .Build(); - - var xdr = operation.ToXdr(); - - var parsedOperation = (SetTrustlineFlagsOperation)Operation.FromXdr(xdr); - Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); - Assert.AreEqual(operation.Asset, parsedOperation.Asset); - Assert.AreEqual(operation.Trustor.AccountId, parsedOperation.Trustor.AccountId); - Assert.AreEqual(operation.SetFlags, parsedOperation.SetFlags); - Assert.AreEqual(operation.ClearFlags, parsedOperation.ClearFlags); } + catch (ArgumentException e) + { + Assert.AreEqual(e.Message, new ArgumentException("Must be 36 bytes long", "balanceId").Message); + } + } + + [TestMethod] + [Obsolete] + public void TestSetTrustlineFlagsOperation() + { + // GDQNY3PBOJOKYZSRMK2S7LHHGWZIUISD4QORETLMXEWXBI7KFZZMKTL3 + var source = KeyPair.FromSecretSeed("SBPQUZ6G4FZNWFHKUWC5BEYWF6R52E3SEP7R3GWYSM2XTKGF5LNTWW4R"); + + var operation = new SetTrustlineFlagsOperation.Builder( + Asset.CreateNonNativeAsset("EUR", "GDIROJW2YHMSFZJJ4R5XWWNUVND5I45YEWS5DSFKXCHMADZ5V374U2LM"), + KeyPair.Random(), 1, 1) + .SetSourceAccount(source) + .Build(); + + var xdr = operation.ToXdr(); + + var parsedOperation = (SetTrustlineFlagsOperation)Operation.FromXdr(xdr); + Assert.AreEqual(operation.SourceAccount.AccountId, parsedOperation.SourceAccount.AccountId); + Assert.AreEqual(operation.Asset, parsedOperation.Asset); + Assert.AreEqual(operation.Trustor.AccountId, parsedOperation.Trustor.AccountId); + Assert.AreEqual(operation.SetFlags, parsedOperation.SetFlags); + Assert.AreEqual(operation.ClearFlags, parsedOperation.ClearFlags); } } \ No newline at end of file diff --git a/stellar-dotnet-sdk-test/ScValTest.cs b/stellar-dotnet-sdk-test/ScValTest.cs index 6e6dd5d4..8b6f0e04 100644 --- a/stellar-dotnet-sdk-test/ScValTest.cs +++ b/stellar-dotnet-sdk-test/ScValTest.cs @@ -1,4 +1,5 @@ using System; +using System.Text; using Microsoft.VisualStudio.TestTools.UnitTesting; using stellar_dotnet_sdk; using xdrSDK = stellar_dotnet_sdk.xdr; @@ -277,10 +278,7 @@ public void TestScInt32() [TestMethod] public void TestScUint64() { - var scUint64 = new SCUint64 - { - InnerValue = 18446744073709551615 - }; + var scUint64 = new SCUint64(18446744073709551615); // Act var scUint64XdrBase64 = scUint64.ToXdrBase64(); @@ -332,11 +330,7 @@ public void TestScDuration() [TestMethod] public void TestScUint128() { - var scUint128 = new SCUint128 - { - Hi = 18446744073709551615, - Lo = 1 - }; + var scUint128 = new SCUint128(1, 18446744073709551615); // Act var scUint128XdrBase64 = scUint128.ToXdrBase64(); @@ -350,11 +344,7 @@ public void TestScUint128() [TestMethod] public void TestScInt128() { - var scInt128 = new SCInt128 - { - Lo = 18446744073709551615, - Hi = -9223372036854775807 - }; + var scInt128 = new SCInt128(18446744073709551615, -9223372036854775807); // Act var scInt128XdrBase64 = scInt128.ToXdrBase64(); diff --git a/stellar-dotnet-sdk-test/SignerTest.cs b/stellar-dotnet-sdk-test/SignerTest.cs index 7d0fa606..efbc6f53 100644 --- a/stellar-dotnet-sdk-test/SignerTest.cs +++ b/stellar-dotnet-sdk-test/SignerTest.cs @@ -16,7 +16,7 @@ public void ItCreatesSignedPayloadSigner() byte[] payload = Util.HexToBytes("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); var signedPayloadSigner = new SignedPayloadSigner(StrKey.DecodeStellarAccountId(accountStrKey), payload); - var signerKey = Signer.SignedPayload(signedPayloadSigner); + var signerKey = SignerUtil.SignedPayload(signedPayloadSigner); Assert.IsTrue(signerKey.Ed25519SignedPayload.Payload.SequenceEqual(payload)); Assert.AreEqual(signerKey.Ed25519SignedPayload.Ed25519, signedPayloadSigner.SignerAccountID.InnerValue.Ed25519); diff --git a/stellar-dotnet-sdk-test/TransactionTest.cs b/stellar-dotnet-sdk-test/TransactionTest.cs index 81c66657..7b790fd5 100644 --- a/stellar-dotnet-sdk-test/TransactionTest.cs +++ b/stellar-dotnet-sdk-test/TransactionTest.cs @@ -5,7 +5,11 @@ using stellar_dotnet_sdk; using stellar_dotnet_sdk.responses; using stellar_dotnet_sdk.xdr; +using LedgerFootprint = stellar_dotnet_sdk.LedgerFootprint; +using LedgerKey = stellar_dotnet_sdk.LedgerKey; using Memo = stellar_dotnet_sdk.Memo; +using SorobanResources = stellar_dotnet_sdk.SorobanResources; +using SorobanTransactionData = stellar_dotnet_sdk.SorobanTransactionData; using TimeBounds = stellar_dotnet_sdk.TimeBounds; using Transaction = stellar_dotnet_sdk.Transaction; using XdrTransaction = stellar_dotnet_sdk.xdr.Transaction; @@ -317,15 +321,8 @@ public void TestToBase64EnvelopeXdrBuilderNoSignatures() .AddOperation(new CreateAccountOperation.Builder(destination, "2000").Build()) .Build(); - try - { - transaction.ToEnvelopeXdrBase64(); - Assert.Fail(); - } - catch (Exception exception) - { - Assert.IsTrue(exception.Message.Contains("Transaction must be signed by at least one signer.")); - } + var ex = Assert.ThrowsException(() => transaction.ToEnvelopeXdrBase64()); + Assert.IsTrue(ex.Message.Contains("Transaction must be signed by at least one signer.")); } [TestMethod] @@ -498,14 +495,7 @@ public void TestSignatureBaseNoNetwork() .AddMemo(new MemoText("Happy birthday!")) .Build(); - try - { - tx.SignatureBase(null); - } - catch (Exception e) - { - Assert.IsNotNull(e); - } + var ex = Assert.ThrowsException(() => tx.SignatureBase(null)); } [TestMethod] @@ -526,14 +516,8 @@ public void TestToXdrWithMuxedAccount() .AddMemo(new MemoText("Happy birthday!")) .Build(); - try - { - tx.ToXdr(); - } - catch (Exception e) - { - Assert.AreEqual(e.Message, "TransactionEnvelope V0 expects a KeyPair source account"); - } + var ex = Assert.ThrowsException(() => tx.ToXdr()); + Assert.AreEqual("TransactionEnvelope V0 expects a KeyPair source account", ex.Message); } [TestMethod] @@ -556,14 +540,8 @@ public void TestToUnsignedEnvelopeXdrWithSignatures() tx.Sign(KeyPair.Random()); - try - { - tx.ToUnsignedEnvelopeXdr(); - } - catch (Exception e) - { - Assert.AreEqual(e.Message, "Transaction must not be signed. Use ToEnvelopeXDR."); - } + var ex = Assert.ThrowsException(() => tx.ToUnsignedEnvelopeXdr()); + Assert.AreEqual("Transaction must not be signed. Use ToEnvelopeXDR.", ex.Message); } [TestMethod] @@ -588,5 +566,61 @@ public void TestTransactionFeeOverflow() }); } + + [TestMethod] + public void TestTransactionWithSorobanData() + { + var network = new Network("Standalone Network ; February 2017"); + var source = KeyPair.FromSecretSeed(network.NetworkId); + var txSource = new MuxedAccountMed25519(source, 0); + var account = new Account(txSource, 7); + var destination = KeyPair.FromAccountId("GDQERENWDDSQZS7R7WKHZI3BSOYMV3FSWR7TFUYFTKQ447PIX6NREOJM"); + var amount = "2000"; + var asset = new AssetTypeNative(); + var keyAccount = new LedgerKeyAccount(KeyPair.Random()); + var keyData = new LedgerKeyData(KeyPair.Random(), "firstKey"); + var footprint = new LedgerFootprint() + { + ReadOnly = new LedgerKey[] { keyAccount }, + ReadWrite = new LedgerKey[] { keyData } + }; + var sorobanData = new SorobanTransactionData() + { + ExtensionPoint = new ExtensionPointZero(), + ResourceFee = 100, + Resources = new SorobanResources() + { + Footprint = footprint, + Instructions = 10, + ReadBytes = 20, + WriteBytes = 30 + } + }; + var tx = new TransactionBuilder(account) + .SetFee(100) + .AddTimeBounds(new TimeBounds(0, 0)) + .AddOperation( + new PaymentOperation.Builder(destination, asset, amount).Build()) + .AddMemo(new MemoText("Happy birthday!")) + .SetSorobanTransactionData(sorobanData) + .Build(); + var xdr = tx.ToUnsignedEnvelopeXdrBase64(); + var decodedTx = (Transaction)TransactionBuilder.FromEnvelopeXdr(xdr); + Assert.IsNotNull(decodedTx); + Assert.AreEqual(txSource.Address, decodedTx.SourceAccount.Address); + + var decodedSorobanData = decodedTx.SorobanData; + Assert.AreEqual(sorobanData.ResourceFee, decodedSorobanData.ResourceFee); + Assert.AreEqual(sorobanData.Resources.Instructions, decodedSorobanData.Resources.Instructions); + Assert.AreEqual(sorobanData.Resources.ReadBytes, decodedSorobanData.Resources.ReadBytes); + Assert.AreEqual(sorobanData.Resources.WriteBytes, decodedSorobanData.Resources.WriteBytes); + + var decodedFootprint = decodedSorobanData.Resources.Footprint; + Assert.AreEqual(footprint.ReadOnly.Length, decodedFootprint.ReadOnly.Length); + Assert.AreEqual(keyAccount.Account.AccountId, ((LedgerKeyAccount)decodedFootprint.ReadOnly[0]).Account.AccountId); + Assert.AreEqual(keyData.Account.AccountId, ((LedgerKeyData)decodedFootprint.ReadWrite[0]).Account.AccountId); + Assert.AreEqual(keyData.DataName, ((LedgerKeyData)decodedFootprint.ReadWrite[0]).DataName); + + } } } \ No newline at end of file diff --git a/stellar-dotnet-sdk-test/TrustlineAssetTest.cs b/stellar-dotnet-sdk-test/TrustlineAssetTest.cs index a925389d..f7c5afb3 100644 --- a/stellar-dotnet-sdk-test/TrustlineAssetTest.cs +++ b/stellar-dotnet-sdk-test/TrustlineAssetTest.cs @@ -105,5 +105,14 @@ public void TestFromXDRNative() var trustlineAsset = (TrustlineAsset.Wrapper)TrustlineAsset.FromXdr(trustlineAssetNativeXdr); Assert.AreEqual(trustlineAsset.Asset.CanonicalName(), "native"); } + + [TestMethod] + public void TestLiquidityPoolShareTrustlineAsset() + { + var asset = (LiquidityPoolShareTrustlineAsset)TrustlineAsset.Create(new LiquidityPoolConstantProductParameters(new AssetTypeNative(), Asset.CreateNonNativeAsset("VNDT", "GCFRHRU5YRI3IN3IMRMYGWWEG2PX2B6MYH2RJW7NEDE2PTYPISPT3RU7"), 1000)); + var xdrAsset = asset.ToXdr(); + var decodedAsset = (LiquidityPoolShareTrustlineAsset)TrustlineAsset.FromXdr(xdrAsset); + CollectionAssert.AreEqual(asset.ID.Hash, decodedAsset.ID.Hash); + } } } diff --git a/stellar-dotnet-sdk-test/operations/SetOptionsOperationTest.cs b/stellar-dotnet-sdk-test/operations/SetOptionsOperationTest.cs index b173cc7d..25922369 100644 --- a/stellar-dotnet-sdk-test/operations/SetOptionsOperationTest.cs +++ b/stellar-dotnet-sdk-test/operations/SetOptionsOperationTest.cs @@ -19,7 +19,7 @@ public void TestSetOptionsOperation() // GDW6AUTBXTOC7FIKUO5BOO3OGLK4SF7ZPOBLMQHMZDI45J2Z6VXRB5NR var inflationDestination = KeyPair.FromSecretSeed("SDHZGHURAYXKU2KMVHPOXI6JG2Q4BSQUQCEOY72O3QQTCLR2T455PMII"); // GBCP5W2VS7AEWV2HFRN7YYC623LTSV7VSTGIHFXDEJU7S5BAGVCSETRR - var signer = Signer.Ed25519PublicKey(KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); + var signer = SignerUtil.Ed25519PublicKey(KeyPair.FromSecretSeed("SA64U7C5C7BS5IHWEPA7YWFN3Z6FE5L6KAMYUIT4AQ7KVTVLD23C6HEZ")); var clearFlags = 1; var setFlags = 1; @@ -108,7 +108,7 @@ public void TestSetOptionsOperationSignerSha256() var hash = Util.Hash(preimage); var operation = new SetOptionsOperation.Builder() - .SetSigner(Signer.Sha256Hash(hash), 10) + .SetSigner(SignerUtil.Sha256Hash(hash), 10) .SetSourceAccount(source) .Build(); @@ -152,7 +152,7 @@ public void TestSetOptionsOperationPreAuthTxSigner() var opSource = KeyPair.FromSecretSeed("SC4CGETADVYTCR5HEAVZRB3DZQY5Y4J7RFNJTRA6ESMHIPEZUSTE2QDK"); var operation = new SetOptionsOperation.Builder() - .SetSigner(Signer.PreAuthTx(transaction), 10) + .SetSigner(SignerUtil.PreAuthTx(transaction), 10) .SetSourceAccount(opSource) .Build(); @@ -182,7 +182,7 @@ public void TestPayloadSignerKey() var payload = Util.HexToBytes("0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"); var signedPayloadSigner = new SignedPayloadSigner(StrKey.DecodeStellarAccountId(payloadSignerStrKey), payload); - var signerKey = Signer.SignedPayload(signedPayloadSigner); + var signerKey = SignerUtil.SignedPayload(signedPayloadSigner); builder.SetSigner(signerKey, 1); builder.SetSourceAccount(source); diff --git a/stellar-dotnet-sdk/AccountEntryExtensionV1.cs b/stellar-dotnet-sdk/AccountEntryExtensionV1.cs new file mode 100644 index 00000000..e7e15a2c --- /dev/null +++ b/stellar-dotnet-sdk/AccountEntryExtensionV1.cs @@ -0,0 +1,33 @@ +namespace stellar_dotnet_sdk; + +public class AccountEntryExtensionV1 +{ + public Liabilities Liabilities { get; set; } + + public AccountEntryExtensionV2? ExtensionV2 { get; set; } + + public static AccountEntryExtensionV1 FromXdr(xdr.AccountEntryExtensionV1 xdrExtensionV1) + { + var entryExtensionV1 = new AccountEntryExtensionV1 + { + Liabilities = Liabilities.FromXdr(xdrExtensionV1.Liabilities) + }; + if (xdrExtensionV1.Ext.Discriminant == 2) + entryExtensionV1.ExtensionV2 = AccountEntryExtensionV2.FromXdr(xdrExtensionV1.Ext.V2); + + return entryExtensionV1; + } + + public xdr.AccountEntryExtensionV1 ToXdr() + { + return new xdr.AccountEntryExtensionV1 + { + Liabilities = Liabilities.ToXdr(), + Ext = new xdr.AccountEntryExtensionV1.AccountEntryExtensionV1Ext + { + Discriminant = ExtensionV2 != null ? 2 : 0, + V2 = ExtensionV2?.ToXdr() ?? new xdr.AccountEntryExtensionV2() + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/AccountEntryExtensionV2.cs b/stellar-dotnet-sdk/AccountEntryExtensionV2.cs new file mode 100644 index 00000000..ed1be359 --- /dev/null +++ b/stellar-dotnet-sdk/AccountEntryExtensionV2.cs @@ -0,0 +1,47 @@ +using System; +using System.Linq; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class AccountEntryExtensionV2 +{ + public uint NumberSponsored { get; set; } + + public uint NumberSponsoring { get; set; } + + public KeyPair[] SignerSponsoringIDs { get; set; } = Array.Empty(); + public AccountEntryExtensionV3? ExtensionV3 { get; set; } + + public static AccountEntryExtensionV2 FromXdr(xdr.AccountEntryExtensionV2 xdrExtensionV2) + { + var entryExtensionV2 = new AccountEntryExtensionV2 + { + NumberSponsored = xdrExtensionV2.NumSponsored.InnerValue, + NumberSponsoring = xdrExtensionV2.NumSponsoring.InnerValue, + SignerSponsoringIDs = xdrExtensionV2.SignerSponsoringIDs + .Select(x => KeyPair.FromXdrPublicKey(x.InnerValue.InnerValue)) + .ToArray() + }; + if (xdrExtensionV2.Ext.Discriminant == 3) + entryExtensionV2.ExtensionV3 = AccountEntryExtensionV3.FromXdr(xdrExtensionV2.Ext.V3); + + return entryExtensionV2; + } + + public xdr.AccountEntryExtensionV2 ToXdr() + { + return new xdr.AccountEntryExtensionV2 + { + NumSponsored = new Uint32(NumberSponsored), + NumSponsoring = new Uint32(NumberSponsoring), + Ext = new xdr.AccountEntryExtensionV2.AccountEntryExtensionV2Ext + { + Discriminant = ExtensionV3 != null ? 3 : 0, + V3 = ExtensionV3 != null ? ExtensionV3.ToXdr() : new xdr.AccountEntryExtensionV3() + }, + SignerSponsoringIDs = SignerSponsoringIDs.Select(x => new SponsorshipDescriptor + { InnerValue = new AccountID { InnerValue = x.XdrPublicKey } }).ToArray() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/AccountEntryExtensionV3.cs b/stellar-dotnet-sdk/AccountEntryExtensionV3.cs new file mode 100644 index 00000000..716ad51f --- /dev/null +++ b/stellar-dotnet-sdk/AccountEntryExtensionV3.cs @@ -0,0 +1,32 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class AccountEntryExtensionV3 +{ + public ExtensionPoint ExtensionPoint { get; set; } + + public uint SequenceLedger { get; set; } + + public ulong SequenceTime { get; set; } + + public xdr.AccountEntryExtensionV3 ToXdr() + { + return new xdr.AccountEntryExtensionV3 + { + Ext = ExtensionPoint.ToXdr(), + SeqLedger = new Uint32(SequenceLedger), + SeqTime = new TimePoint(new Uint64(SequenceTime)) + }; + } + + public static AccountEntryExtensionV3 FromXdr(xdr.AccountEntryExtensionV3 xdr) + { + return new AccountEntryExtensionV3 + { + ExtensionPoint = ExtensionPoint.FromXdr(xdr.Ext), + SequenceTime = xdr.SeqTime.InnerValue.InnerValue, + SequenceLedger = xdr.SeqLedger.InnerValue + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ClaimPredicate.cs b/stellar-dotnet-sdk/ClaimPredicate.cs index af5fcd5e..21448283 100644 --- a/stellar-dotnet-sdk/ClaimPredicate.cs +++ b/stellar-dotnet-sdk/ClaimPredicate.cs @@ -16,10 +16,14 @@ public abstract class ClaimPredicate public static ClaimPredicate Unconditional() => new ClaimPredicateUnconditional(); public static ClaimPredicate BeforeAbsoluteTime(TimePoint timePoint) => new ClaimPredicateBeforeAbsoluteTime(timePoint); + + public static ClaimPredicate BeforeAbsoluteTime(ulong timePoint) => new ClaimPredicateBeforeAbsoluteTime(timePoint); public static ClaimPredicate BeforeAbsoluteTime(DateTimeOffset dateTime) => new ClaimPredicateBeforeAbsoluteTime(dateTime); public static ClaimPredicate BeforeRelativeTime(Duration duration) => new ClaimPredicateBeforeRelativeTime(duration); + + public static ClaimPredicate BeforeRelativeTime(ulong duration) => new ClaimPredicateBeforeRelativeTime(duration); public static ClaimPredicate FromXdr(xdr.ClaimPredicate xdr) { diff --git a/stellar-dotnet-sdk/ClaimPredicateBeforeAbsoluteTime.cs b/stellar-dotnet-sdk/ClaimPredicateBeforeAbsoluteTime.cs index 17abe2f2..45a5e862 100644 --- a/stellar-dotnet-sdk/ClaimPredicateBeforeAbsoluteTime.cs +++ b/stellar-dotnet-sdk/ClaimPredicateBeforeAbsoluteTime.cs @@ -18,6 +18,11 @@ public ClaimPredicateBeforeAbsoluteTime(xdr.TimePoint timePoint) TimePoint = timePoint; } + public ClaimPredicateBeforeAbsoluteTime(ulong timePoint) + { + TimePoint = new xdr.TimePoint(new xdr.Uint64(timePoint)); + } + public override xdr.ClaimPredicate ToXdr() { return new xdr.ClaimPredicate diff --git a/stellar-dotnet-sdk/ClaimPredicateBeforeRelativeTime.cs b/stellar-dotnet-sdk/ClaimPredicateBeforeRelativeTime.cs index ce378c0e..59f3f318 100644 --- a/stellar-dotnet-sdk/ClaimPredicateBeforeRelativeTime.cs +++ b/stellar-dotnet-sdk/ClaimPredicateBeforeRelativeTime.cs @@ -12,6 +12,11 @@ public ClaimPredicateBeforeRelativeTime(xdr.Duration duration) Duration = duration; } + public ClaimPredicateBeforeRelativeTime(ulong duration) + { + Duration = new xdr.Duration(new xdr.Uint64(duration)); + } + public override xdr.ClaimPredicate ToXdr() { return new xdr.ClaimPredicate diff --git a/stellar-dotnet-sdk/ClaimableBalanceEntryExtensionV1.cs b/stellar-dotnet-sdk/ClaimableBalanceEntryExtensionV1.cs new file mode 100644 index 00000000..df4d62ce --- /dev/null +++ b/stellar-dotnet-sdk/ClaimableBalanceEntryExtensionV1.cs @@ -0,0 +1,30 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ClaimableBalanceEntryExtensionV1 +{ + public uint Flags { get; set; } + + public static ClaimableBalanceEntryExtensionV1 FromXdr(xdr.ClaimableBalanceEntryExtensionV1 xdrExtensionV1) + { + var entryExtensionV1 = new ClaimableBalanceEntryExtensionV1 + { + Flags = xdrExtensionV1.Flags.InnerValue + }; + + return entryExtensionV1; + } + + public xdr.ClaimableBalanceEntryExtensionV1 ToXdr() + { + return new xdr.ClaimableBalanceEntryExtensionV1 + { + Flags = new Uint32(Flags), + Ext = new xdr.ClaimableBalanceEntryExtensionV1.ClaimableBalanceEntryExtensionV1Ext + { + Discriminant = 0 + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingBucketListSizeWindow.cs b/stellar-dotnet-sdk/ConfigSettingBucketListSizeWindow.cs new file mode 100644 index 00000000..edd25b37 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingBucketListSizeWindow.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Linq; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingBucketListSizeWindow : LedgerEntryConfigSetting +{ + public ConfigSettingBucketListSizeWindow(IEnumerable value) + { + InnerValue = value.Select(x => x.InnerValue).ToArray(); + } + + public ConfigSettingBucketListSizeWindow(ulong[] value) + { + InnerValue = value; + } + + public ulong[] InnerValue { get; } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW), + BucketListSizeWindow = InnerValue.Select(x => new Uint64(x)).ToArray() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractBandwidth.cs b/stellar-dotnet-sdk/ConfigSettingContractBandwidth.cs new file mode 100644 index 00000000..c959b531 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractBandwidth.cs @@ -0,0 +1,40 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractBandwidth : LedgerEntryConfigSetting +{ + public uint LedgerMaxTxsSizeBytes { get; set; } + public uint TxMaxSizeBytes { get; set; } + public long FeeTxSize1KB { get; set; } + + public static ConfigSettingContractBandwidth FromXdr(xdr.ConfigSettingContractBandwidthV0 xdrConfig) + { + return new ConfigSettingContractBandwidth + { + LedgerMaxTxsSizeBytes = xdrConfig.LedgerMaxTxsSizeBytes.InnerValue, + TxMaxSizeBytes = xdrConfig.TxMaxSizeBytes.InnerValue, + FeeTxSize1KB = xdrConfig.FeeTxSize1KB.InnerValue + }; + } + + public xdr.ConfigSettingContractBandwidthV0 ToXdr() + { + return new xdr.ConfigSettingContractBandwidthV0 + { + LedgerMaxTxsSizeBytes = new Uint32(LedgerMaxTxsSizeBytes), + TxMaxSizeBytes = new Uint32(TxMaxSizeBytes), + FeeTxSize1KB = new Int64(FeeTxSize1KB) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_BANDWIDTH_V0), + ContractBandwidth = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractCompute.cs b/stellar-dotnet-sdk/ConfigSettingContractCompute.cs new file mode 100644 index 00000000..20850de6 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractCompute.cs @@ -0,0 +1,43 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractCompute : LedgerEntryConfigSetting +{ + public long LedgerMaxInstructions { get; set; } + public long TxMaxInstructions { get; set; } + public long FeeRatePerInstructionsIncrement { get; set; } + public uint TxMemoryLimit { get; set; } + + public static ConfigSettingContractCompute FromXdr(xdr.ConfigSettingContractComputeV0 xdrConfig) + { + return new ConfigSettingContractCompute + { + LedgerMaxInstructions = xdrConfig.LedgerMaxInstructions.InnerValue, + TxMaxInstructions = xdrConfig.TxMaxInstructions.InnerValue, + FeeRatePerInstructionsIncrement = xdrConfig.FeeRatePerInstructionsIncrement.InnerValue, + TxMemoryLimit = xdrConfig.TxMemoryLimit.InnerValue + }; + } + + public xdr.ConfigSettingContractComputeV0 ToXdr() + { + return new xdr.ConfigSettingContractComputeV0 + { + LedgerMaxInstructions = new Int64(LedgerMaxInstructions), + TxMaxInstructions = new Int64(TxMaxInstructions), + FeeRatePerInstructionsIncrement = new Int64(FeeRatePerInstructionsIncrement), + TxMemoryLimit = new Uint32(TxMemoryLimit) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_COMPUTE_V0), + ContractCompute = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractCostParamEntry.cs b/stellar-dotnet-sdk/ConfigSettingContractCostParamEntry.cs new file mode 100644 index 00000000..58dd38ed --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractCostParamEntry.cs @@ -0,0 +1,30 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractCostParamEntry +{ + public ExtensionPoint ExtensionPoint { get; set; } + public long ConstTerm { get; set; } + public long LinearTerm { get; set; } + + public static ConfigSettingContractCostParamEntry FromXdr(xdr.ContractCostParamEntry xdrEntry) + { + return new ConfigSettingContractCostParamEntry + { + ExtensionPoint = ExtensionPoint.FromXdr(xdrEntry.Ext), + ConstTerm = xdrEntry.ConstTerm.InnerValue, + LinearTerm = xdrEntry.LinearTerm.InnerValue + }; + } + + public xdr.ContractCostParamEntry ToXdr() + { + return new xdr.ContractCostParamEntry + { + Ext = ExtensionPoint.ToXdr(), + ConstTerm = new Int64(ConstTerm), + LinearTerm = new Int64(LinearTerm) + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractCostParamsCpuInstructions.cs b/stellar-dotnet-sdk/ConfigSettingContractCostParamsCpuInstructions.cs new file mode 100644 index 00000000..ecedec47 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractCostParamsCpuInstructions.cs @@ -0,0 +1,36 @@ +using System.Linq; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractCostParamsCpuInstructions : LedgerEntryConfigSetting +{ + public ConfigSettingContractCostParamEntry[] paramEntries { get; set; } + + public static ConfigSettingContractCostParamsCpuInstructions FromXdr(ContractCostParams xdrParams) + { + return new ConfigSettingContractCostParamsCpuInstructions + { + paramEntries = xdrParams.InnerValue.Select(ConfigSettingContractCostParamEntry.FromXdr).ToArray() + }; + } + + public ContractCostParams ToXdr() + { + return new ContractCostParams + { + InnerValue = paramEntries.Select(x => x.ToXdr()).ToArray() + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum + .CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS), + ContractCostParamsCpuInsns = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractCostParamsMemoryBytes.cs b/stellar-dotnet-sdk/ConfigSettingContractCostParamsMemoryBytes.cs new file mode 100644 index 00000000..73dc9b1e --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractCostParamsMemoryBytes.cs @@ -0,0 +1,36 @@ +using System.Linq; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractCostParamsMemoryBytes : LedgerEntryConfigSetting +{ + public ConfigSettingContractCostParamEntry[] paramEntries { get; set; } + + public static ConfigSettingContractCostParamsMemoryBytes FromXdr(ContractCostParams xdrParams) + { + return new ConfigSettingContractCostParamsMemoryBytes + { + paramEntries = xdrParams.InnerValue.Select(ConfigSettingContractCostParamEntry.FromXdr).ToArray() + }; + } + + public ContractCostParams ToXdr() + { + return new ContractCostParams + { + InnerValue = paramEntries.Select(x => x.ToXdr()).ToArray() + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum + .CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES), + ContractCostParamsMemBytes = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractDataEntrySizeBytes.cs b/stellar-dotnet-sdk/ConfigSettingContractDataEntrySizeBytes.cs new file mode 100644 index 00000000..1b73e0ee --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractDataEntrySizeBytes.cs @@ -0,0 +1,24 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractDataEntrySizeBytes : LedgerEntryConfigSetting +{ + public ConfigSettingContractDataEntrySizeBytes(uint value) + { + InnerValue = value; + } + + public uint InnerValue { get; } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create( + ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES), + ContractDataEntrySizeBytes = new Uint32(InnerValue) + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractDataKeySizeBytes.cs b/stellar-dotnet-sdk/ConfigSettingContractDataKeySizeBytes.cs new file mode 100644 index 00000000..7e602350 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractDataKeySizeBytes.cs @@ -0,0 +1,23 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractDataKeySizeBytes : LedgerEntryConfigSetting +{ + public ConfigSettingContractDataKeySizeBytes(uint value) + { + InnerValue = value; + } + + public uint InnerValue { get; } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES), + ContractDataKeySizeBytes = new Uint32(InnerValue) + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractEvents.cs b/stellar-dotnet-sdk/ConfigSettingContractEvents.cs new file mode 100644 index 00000000..b11c95d4 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractEvents.cs @@ -0,0 +1,37 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractEvents : LedgerEntryConfigSetting +{ + public uint TxMaxContractEventsSizeBytes { get; set; } + public long FeeContractEvents1KB { get; set; } + + public static ConfigSettingContractEvents FromXdr(xdr.ConfigSettingContractEventsV0 xdrConfig) + { + return new ConfigSettingContractEvents + { + TxMaxContractEventsSizeBytes = xdrConfig.TxMaxContractEventsSizeBytes.InnerValue, + FeeContractEvents1KB = xdrConfig.FeeContractEvents1KB.InnerValue + }; + } + + public xdr.ConfigSettingContractEventsV0 ToXdr() + { + return new xdr.ConfigSettingContractEventsV0 + { + TxMaxContractEventsSizeBytes = new Uint32(TxMaxContractEventsSizeBytes), + FeeContractEvents1KB = new Int64(FeeContractEvents1KB) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_EVENTS_V0), + ContractEvents = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractExecutionLanes.cs b/stellar-dotnet-sdk/ConfigSettingContractExecutionLanes.cs new file mode 100644 index 00000000..729d999a --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractExecutionLanes.cs @@ -0,0 +1,34 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractExecutionLanes : LedgerEntryConfigSetting +{ + public uint LedgerMaxTxCount { get; set; } + + public static ConfigSettingContractExecutionLanes FromXdr(xdr.ConfigSettingContractExecutionLanesV0 xdrConfig) + { + return new ConfigSettingContractExecutionLanes + { + LedgerMaxTxCount = xdrConfig.LedgerMaxTxCount.InnerValue + }; + } + + public xdr.ConfigSettingContractExecutionLanesV0 ToXdr() + { + return new xdr.ConfigSettingContractExecutionLanesV0 + { + LedgerMaxTxCount = new Uint32(LedgerMaxTxCount) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_EXECUTION_LANES), + ContractExecutionLanes = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractHistoricalData.cs b/stellar-dotnet-sdk/ConfigSettingContractHistoricalData.cs new file mode 100644 index 00000000..1aa9ee86 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractHistoricalData.cs @@ -0,0 +1,34 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractHistoricalData : LedgerEntryConfigSetting +{ + public long FeeHistorical1KB { get; set; } + + public static ConfigSettingContractHistoricalData FromXdr(xdr.ConfigSettingContractHistoricalDataV0 xdrConfig) + { + return new ConfigSettingContractHistoricalData + { + FeeHistorical1KB = xdrConfig.FeeHistorical1KB.InnerValue + }; + } + + public xdr.ConfigSettingContractHistoricalDataV0 ToXdr() + { + return new xdr.ConfigSettingContractHistoricalDataV0 + { + FeeHistorical1KB = new Int64(FeeHistorical1KB) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0), + ContractHistoricalData = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractLedgerCost.cs b/stellar-dotnet-sdk/ConfigSettingContractLedgerCost.cs new file mode 100644 index 00000000..2c11de51 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractLedgerCost.cs @@ -0,0 +1,76 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractLedgerCost : LedgerEntryConfigSetting +{ + public uint LedgerMaxReadLedgerEntries { get; set; } + public uint LedgerMaxReadBytes { get; set; } + public uint LedgerMaxWriteLedgerEntries { get; set; } + public uint LedgerMaxWriteBytes { get; set; } + public uint TxMaxReadLedgerEntries { get; set; } + public uint TxMaxReadBytes { get; set; } + public uint TxMaxWriteLedgerEntries { get; set; } + public uint TxMaxWriteBytes { get; set; } + public long FeeReadLedgerEntry { get; set; } + public long FeeWriteLedgerEntry { get; set; } + public long FeeRead1KB { get; set; } + public long BucketListTargetSizeBytes { get; set; } + public long WriteFee1KBBucketListLow { get; set; } + public long WriteFee1KBBucketListHigh { get; set; } + public uint BucketListWriteFeeGrowthFactor { get; set; } + + public static ConfigSettingContractLedgerCost FromXdr(xdr.ConfigSettingContractLedgerCostV0 xdrConfig) + { + return new ConfigSettingContractLedgerCost + { + LedgerMaxReadLedgerEntries = xdrConfig.LedgerMaxReadLedgerEntries.InnerValue, + LedgerMaxReadBytes = xdrConfig.LedgerMaxReadBytes.InnerValue, + LedgerMaxWriteLedgerEntries = xdrConfig.LedgerMaxWriteLedgerEntries.InnerValue, + LedgerMaxWriteBytes = xdrConfig.LedgerMaxWriteBytes.InnerValue, + TxMaxReadLedgerEntries = xdrConfig.TxMaxReadLedgerEntries.InnerValue, + TxMaxReadBytes = xdrConfig.TxMaxReadBytes.InnerValue, + TxMaxWriteLedgerEntries = xdrConfig.TxMaxWriteLedgerEntries.InnerValue, + TxMaxWriteBytes = xdrConfig.TxMaxWriteBytes.InnerValue, + FeeReadLedgerEntry = xdrConfig.FeeReadLedgerEntry.InnerValue, + FeeWriteLedgerEntry = xdrConfig.FeeWriteLedgerEntry.InnerValue, + FeeRead1KB = xdrConfig.FeeRead1KB.InnerValue, + BucketListTargetSizeBytes = xdrConfig.BucketListTargetSizeBytes.InnerValue, + WriteFee1KBBucketListLow = xdrConfig.WriteFee1KBBucketListLow.InnerValue, + WriteFee1KBBucketListHigh = xdrConfig.WriteFee1KBBucketListHigh.InnerValue, + BucketListWriteFeeGrowthFactor = xdrConfig.BucketListWriteFeeGrowthFactor.InnerValue + }; + } + + public xdr.ConfigSettingContractLedgerCostV0 ToXdr() + { + return new xdr.ConfigSettingContractLedgerCostV0 + { + LedgerMaxReadLedgerEntries = new Uint32(LedgerMaxReadLedgerEntries), + LedgerMaxReadBytes = new Uint32(LedgerMaxReadBytes), + LedgerMaxWriteLedgerEntries = new Uint32(LedgerMaxWriteLedgerEntries), + LedgerMaxWriteBytes = new Uint32(LedgerMaxWriteBytes), + TxMaxReadLedgerEntries = new Uint32(TxMaxReadLedgerEntries), + TxMaxReadBytes = new Uint32(TxMaxReadBytes), + TxMaxWriteLedgerEntries = new Uint32(TxMaxWriteLedgerEntries), + TxMaxWriteBytes = new Uint32(TxMaxWriteBytes), + FeeReadLedgerEntry = new Int64(FeeReadLedgerEntry), + FeeWriteLedgerEntry = new Int64(FeeWriteLedgerEntry), + FeeRead1KB = new Int64(FeeRead1KB), + BucketListTargetSizeBytes = new Int64(BucketListTargetSizeBytes), + WriteFee1KBBucketListLow = new Int64(WriteFee1KBBucketListLow), + WriteFee1KBBucketListHigh = new Int64(WriteFee1KBBucketListHigh), + BucketListWriteFeeGrowthFactor = new Uint32(BucketListWriteFeeGrowthFactor) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_LEDGER_COST_V0), + ContractLedgerCost = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/ConfigSettingContractMaxSizeBytes.cs b/stellar-dotnet-sdk/ConfigSettingContractMaxSizeBytes.cs new file mode 100644 index 00000000..fde4c8a4 --- /dev/null +++ b/stellar-dotnet-sdk/ConfigSettingContractMaxSizeBytes.cs @@ -0,0 +1,23 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class ConfigSettingContractMaxSizeBytes : LedgerEntryConfigSetting +{ + public ConfigSettingContractMaxSizeBytes(uint value) + { + InnerValue = value; + } + + public uint InnerValue { get; } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES), + ContractMaxSizeBytes = new Uint32(InnerValue) + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/DataEntryExtension.cs b/stellar-dotnet-sdk/DataEntryExtension.cs new file mode 100644 index 00000000..0b237a70 --- /dev/null +++ b/stellar-dotnet-sdk/DataEntryExtension.cs @@ -0,0 +1,19 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class DataEntryExtension +{ + public static DataEntryExtension FromXdr(DataEntry.DataEntryExt xdrExtension) + { + return new DataEntryExtension(); + } + + public DataEntry.DataEntryExt ToXdr() + { + return new DataEntry.DataEntryExt + { + Discriminant = 0 + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/EvictionIterator.cs b/stellar-dotnet-sdk/EvictionIterator.cs new file mode 100644 index 00000000..21fd2c3a --- /dev/null +++ b/stellar-dotnet-sdk/EvictionIterator.cs @@ -0,0 +1,40 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class EvictionIterator : LedgerEntryConfigSetting +{ + public uint BucketListLevel { get; set; } + public bool IsCurrBucket { get; set; } + public ulong BucketFileOffset { get; set; } + + public static EvictionIterator FromXdr(xdr.EvictionIterator xdrConfig) + { + return new EvictionIterator + { + BucketListLevel = xdrConfig.BucketListLevel.InnerValue, + IsCurrBucket = xdrConfig.IsCurrBucket, + BucketFileOffset = xdrConfig.BucketFileOffset.InnerValue + }; + } + + public xdr.EvictionIterator ToXdr() + { + return new xdr.EvictionIterator + { + BucketListLevel = new Uint32(BucketListLevel), + IsCurrBucket = IsCurrBucket, + BucketFileOffset = new Uint64(BucketFileOffset) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_EVICTION_ITERATOR), + EvictionIterator = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/FeeBumpTransaction.cs b/stellar-dotnet-sdk/FeeBumpTransaction.cs index 0a3ff7ff..3a8731f1 100644 --- a/stellar-dotnet-sdk/FeeBumpTransaction.cs +++ b/stellar-dotnet-sdk/FeeBumpTransaction.cs @@ -25,7 +25,7 @@ public override byte[] SignatureBase(Network network) throw new NoNetworkSelectedException(); // Hashed NetworkID - var networkHash = new Hash { InnerValue = network.NetworkId }; + var networkHash = new xdr.Hash { InnerValue = network.NetworkId }; var taggedTransaction = new TransactionSignaturePayload.TransactionSignaturePayloadTaggedTransaction { Discriminant = EnvelopeType.Create(EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_FEE_BUMP), diff --git a/stellar-dotnet-sdk/Hash.cs b/stellar-dotnet-sdk/Hash.cs new file mode 100644 index 00000000..7833808b --- /dev/null +++ b/stellar-dotnet-sdk/Hash.cs @@ -0,0 +1,29 @@ +using System; + +namespace stellar_dotnet_sdk; + +public class Hash +{ + public Hash(string base64String) : this(Convert.FromBase64String(base64String)) + { + } + public Hash(byte[] hash) + { + if (hash.Length != 32) + throw new ArgumentException("Hash must have exactly 32 bytes.", nameof(hash)); + + InnerValue = hash; + } + + public byte[] InnerValue { get; } + + public static Hash FromXdr(xdr.Hash xdrHash) + { + return new Hash(xdrHash.InnerValue); + } + + public xdr.Hash ToXdr() + { + return new xdr.Hash(InnerValue); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntry.cs b/stellar-dotnet-sdk/LedgerEntry.cs new file mode 100644 index 00000000..d31b77e8 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntry.cs @@ -0,0 +1,130 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public abstract class LedgerEntry +{ + public uint LastModifiedLedgerSeq { get; set; } + + public LedgerEntryExtensionV1? LedgerExtensionV1 { get; set; } + + public xdr.LedgerEntry ToXdr() + { + var xdrLedgerEntry = new xdr.LedgerEntry + { + Data = new xdr.LedgerEntry.LedgerEntryData + { + Discriminant = new LedgerEntryType() + }, + LastModifiedLedgerSeq = new Uint32(LastModifiedLedgerSeq), + Ext = new xdr.LedgerEntry.LedgerEntryExt + { + Discriminant = LedgerExtensionV1 != null ? 1 : 0, + V1 = LedgerExtensionV1?.ToXdr() ?? new xdr.LedgerEntryExtensionV1() + } + }; + + switch (this) + { + case LedgerEntryAccount accountEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.ACCOUNT; + xdrLedgerEntry.Data.Account = accountEntry.ToXdr(); + break; + case LedgerEntryOffer offerEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.OFFER; + xdrLedgerEntry.Data.Offer = offerEntry.ToXdr(); + break; + case LedgerEntryTrustline trustlineEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.TRUSTLINE; + xdrLedgerEntry.Data.TrustLine = trustlineEntry.ToXdr(); + break; + case LedgerEntryData dataEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.DATA; + xdrLedgerEntry.Data.Data = dataEntry.ToXdr(); + break; + case LedgerEntryClaimableBalance claimableBalanceEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CLAIMABLE_BALANCE; + xdrLedgerEntry.Data.ClaimableBalance = claimableBalanceEntry.ToXdr(); + break; + case LedgerEntryLiquidityPool liquidityPoolEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.LIQUIDITY_POOL; + xdrLedgerEntry.Data.LiquidityPool = liquidityPoolEntry.ToXdr(); + break; + case LedgerEntryContractData contractDataEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_DATA; + xdrLedgerEntry.Data.ContractData = contractDataEntry.ToXdr(); + break; + case LedgerEntryContractCode contractCodeEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_CODE; + xdrLedgerEntry.Data.ContractCode = contractCodeEntry.ToXdr(); + break; + case LedgerEntryConfigSetting configSettingEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONFIG_SETTING; + xdrLedgerEntry.Data.ConfigSetting = configSettingEntry.ToXdr(); + break; + case LedgerEntryTTL ttlEntry: + xdrLedgerEntry.Data.Discriminant.InnerValue = LedgerEntryType.LedgerEntryTypeEnum.TTL; + xdrLedgerEntry.Data.Ttl = ttlEntry.ToXdr(); + break; + default: + throw new InvalidOperationException("Unknown LedgerEntry type"); + } + + return xdrLedgerEntry; + } + + public static LedgerEntry FromXdr(xdr.LedgerEntry xdrLedgerEntry) + { + return xdrLedgerEntry.Data.Discriminant.InnerValue switch + { + LedgerEntryType.LedgerEntryTypeEnum.ACCOUNT => LedgerEntryAccount.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.TRUSTLINE => LedgerEntryTrustline.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.OFFER => LedgerEntryOffer.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.DATA => LedgerEntryData.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.CLAIMABLE_BALANCE => LedgerEntryClaimableBalance.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.LIQUIDITY_POOL => LedgerEntryLiquidityPool.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_DATA => LedgerEntryContractData.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_CODE => LedgerEntryContractCode.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.CONFIG_SETTING => LedgerEntryConfigSetting.FromXdrLedgerEntry(xdrLedgerEntry), + LedgerEntryType.LedgerEntryTypeEnum.TTL => LedgerEntryTTL.FromXdrLedgerEntry(xdrLedgerEntry), + _ => throw new InvalidOperationException("Unknown LedgerEntry type") + }; + } + + /// + /// Creates a new LedgerEntry object from the given LedgerEntry XDR base64 string. + /// + /// + /// LedgerEntry object + public static LedgerEntry FromXdrBase64(string xdrBase64) + { + var bytes = Convert.FromBase64String(xdrBase64); + var reader = new XdrDataInputStream(bytes); + var thisXdr = xdr.LedgerEntry.Decode(reader); + return FromXdr(thisXdr); + } + + /// + /// Returns a base64-encoded string that represents the XDR (External Data Representation) format of a + /// object. + /// + /// + /// A base64-encoded string that contains the XDR representation of the + /// object. + /// + public string ToXdrBase64() + { + var ledgerEntry = ToXdr(); + var writer = new XdrDataOutputStream(); + xdr.LedgerEntry.Encode(writer, ledgerEntry); + return Convert.ToBase64String(writer.ToArray()); + } + + protected static void ExtraFieldsFromXdr(xdr.LedgerEntry xdrLedgerEntry, LedgerEntry ledgerEntry) + { + ledgerEntry.LastModifiedLedgerSeq = xdrLedgerEntry.LastModifiedLedgerSeq.InnerValue; + if (xdrLedgerEntry.Ext.Discriminant == 1) + ledgerEntry.LedgerExtensionV1 = LedgerEntryExtensionV1.FromXdr(xdrLedgerEntry.Ext.V1); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryAccount.cs b/stellar-dotnet-sdk/LedgerEntryAccount.cs new file mode 100644 index 00000000..eb8f34e8 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryAccount.cs @@ -0,0 +1,89 @@ +using System; +using System.Linq; +using stellar_dotnet_sdk.xdr; +using Int64 = stellar_dotnet_sdk.xdr.Int64; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryAccount : LedgerEntry +{ + private string _homeDomain; + private byte[] _thresholds; + public KeyPair Account { get; set; } + public long Balance { get; set; } + public long SequenceNumber { get; set; } + public uint NumberSubEntries { get; set; } + public KeyPair InflationDest { get; set; } + public uint Flags { get; set; } + public AccountEntryExtensionV1? AccountExtensionV1 { get; set; } + + public string HomeDomain + { + get => _homeDomain; + set + { + if (value.Length > 32) throw new ArgumentException("Home domain cannot exceed 32 characters", nameof(value)); + _homeDomain = value; + } + } + + public byte[] Thresholds + { + get => _thresholds; + set + { + if (value.Length > 4) throw new ArgumentException("Thresholds cannot exceed 4 bytes", nameof(value)); + _thresholds = value; + } + } + + public Signer[] Signers { get; set; } = Array.Empty(); + + public static LedgerEntryAccount FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.ACCOUNT) + throw new ArgumentException("Not an AccountEntry", nameof(xdrLedgerEntry)); + + var xdrAccountEntry = xdrLedgerEntry.Data.Account; + + var ledgerEntryAccount = new LedgerEntryAccount + { + Account = KeyPair.FromXdrPublicKey(xdrAccountEntry.AccountID.InnerValue), + HomeDomain = xdrAccountEntry.HomeDomain.InnerValue, + SequenceNumber = xdrAccountEntry.SeqNum.InnerValue.InnerValue, + NumberSubEntries = xdrAccountEntry.NumSubEntries.InnerValue, + Balance = xdrAccountEntry.Balance.InnerValue, + Flags = xdrAccountEntry.Flags.InnerValue, + InflationDest = KeyPair.FromXdrPublicKey(xdrAccountEntry.InflationDest.InnerValue), + Thresholds = xdrAccountEntry.Thresholds.InnerValue, + Signers = xdrAccountEntry.Signers.Select(Signer.FromXdr).ToArray() + }; + if (xdrAccountEntry.Ext.Discriminant != 0) + ledgerEntryAccount.AccountExtensionV1 = AccountEntryExtensionV1.FromXdr(xdrAccountEntry.Ext.V1); + + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryAccount); + + return ledgerEntryAccount; + } + + public AccountEntry ToXdr() + { + return new AccountEntry + { + AccountID = new AccountID(Account.XdrPublicKey), + Balance = new Int64(Balance), + SeqNum = new SequenceNumber(new Int64(SequenceNumber)), + NumSubEntries = new Uint32(NumberSubEntries), + InflationDest = new AccountID(InflationDest.XdrPublicKey), + Flags = new Uint32(Flags), + HomeDomain = new String32(HomeDomain), + Thresholds = new Thresholds(Thresholds), + Signers = Signers.Select(x => x.ToXdr()).ToArray(), + Ext = new AccountEntry.AccountEntryExt + { + Discriminant = AccountExtensionV1 != null ? 1 : 0, + V1 = AccountExtensionV1?.ToXdr() ?? new xdr.AccountEntryExtensionV1() + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryClaimableBalance.cs b/stellar-dotnet-sdk/LedgerEntryClaimableBalance.cs new file mode 100644 index 00000000..ddedab0d --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryClaimableBalance.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using stellar_dotnet_sdk.xdr; +using Int64 = stellar_dotnet_sdk.xdr.Int64; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryClaimableBalance : LedgerEntry +{ + public Hash BalanceId { get; set; } + public Claimant[] Claimants { get; set; } + public Asset Asset { get; set; } + public long Amount { get; set; } + public ClaimableBalanceEntryExtensionV1? ClaimableBalanceEntryExtensionV1 { get; set; } + + public static LedgerEntryClaimableBalance FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.CLAIMABLE_BALANCE) + throw new ArgumentException("Not a ClaimableBalanceEntry", nameof(xdrLedgerEntry)); + + var xdrClaimableBalanceEntry = xdrLedgerEntry.Data.ClaimableBalance; + var ledgerEntryClaimableBalance = new LedgerEntryClaimableBalance + { + BalanceId = Hash.FromXdr(xdrClaimableBalanceEntry.BalanceID.V0), + Claimants = xdrClaimableBalanceEntry.Claimants.Select(Claimant.FromXdr).ToArray(), + Asset = Asset.FromXdr(xdrClaimableBalanceEntry.Asset), + Amount = xdrClaimableBalanceEntry.Amount.InnerValue + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryClaimableBalance); + if (xdrClaimableBalanceEntry.Ext.Discriminant == 1) + ledgerEntryClaimableBalance.ClaimableBalanceEntryExtensionV1 = + ClaimableBalanceEntryExtensionV1.FromXdr(xdrClaimableBalanceEntry.Ext.V1); + + return ledgerEntryClaimableBalance; + } + + public ClaimableBalanceEntry ToXdr() + { + return new ClaimableBalanceEntry + { + BalanceID = new ClaimableBalanceID + { + Discriminant = ClaimableBalanceIDType.Create(ClaimableBalanceIDType.ClaimableBalanceIDTypeEnum + .CLAIMABLE_BALANCE_ID_TYPE_V0), + V0 = BalanceId.ToXdr() + }, + Claimants = Claimants.Select(x => x.ToXdr()).ToArray(), + Asset = Asset.ToXdr(), + Amount = new Int64(Amount), + Ext = new ClaimableBalanceEntry.ClaimableBalanceEntryExt + { + Discriminant = ClaimableBalanceEntryExtensionV1 != null + ? 1 + : 0, + V1 = ClaimableBalanceEntryExtensionV1?.ToXdr() ?? new xdr.ClaimableBalanceEntryExtensionV1() + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryConfigSetting.cs b/stellar-dotnet-sdk/LedgerEntryConfigSetting.cs new file mode 100644 index 00000000..6409253b --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryConfigSetting.cs @@ -0,0 +1,74 @@ +using System; +using stellar_dotnet_sdk.xdr; +using static stellar_dotnet_sdk.xdr.ConfigSettingID.ConfigSettingIDEnum; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryConfigSetting : LedgerEntry +{ + public static LedgerEntryConfigSetting FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.CONFIG_SETTING) + throw new ArgumentException("Not a ConfigSettingEntry", nameof(xdrLedgerEntry)); + var xdrConfigSetting = xdrLedgerEntry.Data.ConfigSetting; + + LedgerEntryConfigSetting ledgerEntryConfigSetting = xdrConfigSetting.Discriminant.InnerValue switch + { + CONFIG_SETTING_CONTRACT_BANDWIDTH_V0 => ConfigSettingContractBandwidth + .FromXdr(xdrConfigSetting.ContractBandwidth), + CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES => + ConfigSettingContractCostParamsMemoryBytes.FromXdr(xdrConfigSetting.ContractCostParamsMemBytes), + CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS => + ConfigSettingContractCostParamsCpuInstructions.FromXdr(xdrConfigSetting.ContractCostParamsCpuInsns), + CONFIG_SETTING_CONTRACT_COMPUTE_V0 => ConfigSettingContractCompute + .FromXdr(xdrConfigSetting.ContractCompute), + CONFIG_SETTING_CONTRACT_EVENTS_V0 => ConfigSettingContractEvents + .FromXdr(xdrConfigSetting.ContractEvents), + CONFIG_SETTING_CONTRACT_EXECUTION_LANES => + ConfigSettingContractExecutionLanes.FromXdr(xdrConfigSetting.ContractExecutionLanes), + CONFIG_SETTING_CONTRACT_HISTORICAL_DATA_V0 => + ConfigSettingContractHistoricalData.FromXdr(xdrConfigSetting.ContractHistoricalData), + CONFIG_SETTING_CONTRACT_LEDGER_COST_V0 => + ConfigSettingContractLedgerCost.FromXdr(xdrConfigSetting.ContractLedgerCost), + CONFIG_SETTING_STATE_ARCHIVAL => StateArchivalSettings.FromXdr( + xdrConfigSetting.StateArchivalSettings), + CONFIG_SETTING_EVICTION_ITERATOR => EvictionIterator.FromXdr( + xdrConfigSetting.EvictionIterator), + CONFIG_SETTING_CONTRACT_MAX_SIZE_BYTES => new + ConfigSettingContractMaxSizeBytes(xdrConfigSetting.ContractMaxSizeBytes.InnerValue), + CONFIG_SETTING_CONTRACT_DATA_KEY_SIZE_BYTES => new + ConfigSettingContractDataKeySizeBytes(xdrConfigSetting.ContractDataKeySizeBytes + .InnerValue), + CONFIG_SETTING_CONTRACT_DATA_ENTRY_SIZE_BYTES => new + ConfigSettingContractDataEntrySizeBytes(xdrConfigSetting.ContractDataEntrySizeBytes + .InnerValue), + CONFIG_SETTING_BUCKETLIST_SIZE_WINDOW => new + ConfigSettingBucketListSizeWindow(xdrConfigSetting.BucketListSizeWindow), + _ => throw new InvalidOperationException("Unknown ConfigSetting type") + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryConfigSetting); + return ledgerEntryConfigSetting; + } + + public ConfigSettingEntry ToXdr() + { + return this switch + { + ConfigSettingBucketListSizeWindow bucketListSizeWindow => bucketListSizeWindow.ToXdrConfigSettingEntry(), + ConfigSettingContractBandwidth bandwidth => bandwidth.ToXdrConfigSettingEntry(), + ConfigSettingContractCompute compute => compute.ToXdrConfigSettingEntry(), + ConfigSettingContractDataEntrySizeBytes dataEntrySizeBytes => dataEntrySizeBytes.ToXdrConfigSettingEntry(), + ConfigSettingContractDataKeySizeBytes dataKeySizeBytes => dataKeySizeBytes.ToXdrConfigSettingEntry(), + ConfigSettingContractEvents events => events.ToXdrConfigSettingEntry(), + ConfigSettingContractExecutionLanes executionLanes => executionLanes.ToXdrConfigSettingEntry(), + ConfigSettingContractHistoricalData historicalData => historicalData.ToXdrConfigSettingEntry(), + ConfigSettingContractLedgerCost ledgerCost => ledgerCost.ToXdrConfigSettingEntry(), + ConfigSettingContractMaxSizeBytes maxSizeBytes => maxSizeBytes.ToXdrConfigSettingEntry(), + ConfigSettingContractCostParamsMemoryBytes paramsMemoryBytes => paramsMemoryBytes.ToXdrConfigSettingEntry(), + ConfigSettingContractCostParamsCpuInstructions paramsCpuInstructions => paramsCpuInstructions.ToXdrConfigSettingEntry(), + EvictionIterator evictionIterator => evictionIterator.ToXdrConfigSettingEntry(), + StateArchivalSettings stateArchivalSettings => stateArchivalSettings.ToXdrConfigSettingEntry(), + _ => throw new InvalidOperationException("Unknown LedgerEntryConfigSetting type") + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryContractCode.cs b/stellar-dotnet-sdk/LedgerEntryContractCode.cs new file mode 100644 index 00000000..e99858ef --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryContractCode.cs @@ -0,0 +1,37 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryContractCode : LedgerEntry +{ + public Hash Hash { get; set; } + public byte[] Code { get; set; } + public ExtensionPoint ExtensionPoint { get; set; } + + public static LedgerEntryContractCode FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_CODE) + throw new ArgumentException("Not a ContractCodeEntry", nameof(xdrLedgerEntry)); + var xdrContractCodeEntry = xdrLedgerEntry.Data.ContractCode; + var ledgerEntryContractCode = new LedgerEntryContractCode + { + Hash = Hash.FromXdr(xdrContractCodeEntry.Hash), + Code = xdrContractCodeEntry.Code, + ExtensionPoint = ExtensionPoint.FromXdr(xdrContractCodeEntry.Ext) + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryContractCode); + + return ledgerEntryContractCode; + } + + public ContractCodeEntry ToXdr() + { + return new ContractCodeEntry + { + Ext = ExtensionPoint.ToXdr(), + Hash = Hash.ToXdr(), + Code = Code + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryContractData.cs b/stellar-dotnet-sdk/LedgerEntryContractData.cs new file mode 100644 index 00000000..8e0b2a58 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryContractData.cs @@ -0,0 +1,48 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryContractData : LedgerEntry +{ + public SCVal Key { get; set; } + + public SCVal Value { get; set; } + + public SCAddress Contract { get; set; } + + public ContractDataDurability Durability { get; set; } + + public ExtensionPoint ExtensionPoint { get; set; } + + public static LedgerEntryContractData FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_DATA) + throw new ArgumentException("Not a ContractDataEntry", nameof(xdrLedgerEntry)); + var xdrContractDataEntry = xdrLedgerEntry.Data.ContractData; + + var ledgerEntryContractData = new LedgerEntryContractData + { + Key = SCVal.FromXdr(xdrContractDataEntry.Key), + Value = SCVal.FromXdr(xdrContractDataEntry.Val), + Contract = SCAddress.FromXdr(xdrContractDataEntry.Contract), + Durability = xdrContractDataEntry.Durability, + ExtensionPoint = ExtensionPoint.FromXdr(xdrContractDataEntry.Ext) + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryContractData); + + return ledgerEntryContractData; + } + + public ContractDataEntry ToXdr() + { + return new ContractDataEntry + { + Ext = ExtensionPoint.ToXdr(), + Contract = Contract.ToXdr(), + Key = Key.ToXdr(), + Durability = Durability, + Val = Value.ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryData.cs b/stellar-dotnet-sdk/LedgerEntryData.cs new file mode 100644 index 00000000..b6bf874e --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryData.cs @@ -0,0 +1,52 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryData : LedgerEntry +{ + private byte[] _dataValue; + public new KeyPair AccountID { get; set; } + + public String64 DataName { get; set; } + + public byte[] DataValue + { + get => _dataValue; + set + { + if (value.Length > 64) throw new ArgumentException("Data value cannot exceed 64 bytes"); + _dataValue = value; + } + } + + public DataEntryExtension? DataExtension { get; set; } + + public static LedgerEntryData FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.DATA) + throw new ArgumentException("Not a DataEntry", nameof(xdrLedgerEntry)); + var xdrDataEntry = xdrLedgerEntry.Data.Data; + var ledgerEntryData = new LedgerEntryData + { + AccountID = KeyPair.FromXdrPublicKey(xdrDataEntry.AccountID.InnerValue), + DataName = String64.FromXdr(xdrDataEntry.DataName), + DataValue = xdrDataEntry.DataValue.InnerValue, + }; + if (xdrDataEntry.Ext.Discriminant != 0) + ledgerEntryData.DataExtension = DataEntryExtension.FromXdr(xdrDataEntry.Ext); + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryData); + return ledgerEntryData; + } + + public DataEntry ToXdr() + { + return new DataEntry + { + AccountID = new AccountID(AccountID.XdrPublicKey), + DataName = DataName.ToXdr(), + DataValue = new DataValue(DataValue), + Ext = DataExtension?.ToXdr() ?? new DataEntry.DataEntryExt() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryExtensionV1.cs b/stellar-dotnet-sdk/LedgerEntryExtensionV1.cs new file mode 100644 index 00000000..7eaeb03a --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryExtensionV1.cs @@ -0,0 +1,28 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryExtensionV1 +{ + public KeyPair SponsoringID { get; set; } + + public static LedgerEntryExtensionV1 FromXdr(xdr.LedgerEntryExtensionV1 xdrEntryExtensionV1) + { + return new LedgerEntryExtensionV1 + { + SponsoringID = KeyPair.FromXdrPublicKey(xdrEntryExtensionV1.SponsoringID.InnerValue.InnerValue) + }; + } + + public xdr.LedgerEntryExtensionV1 ToXdr() + { + return new xdr.LedgerEntryExtensionV1 + { + SponsoringID = new SponsorshipDescriptor(new AccountID { InnerValue = SponsoringID.XdrPublicKey }), + Ext = new xdr.LedgerEntryExtensionV1.LedgerEntryExtensionV1Ext + { + Discriminant = 0 + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryLiquidityPool.cs b/stellar-dotnet-sdk/LedgerEntryLiquidityPool.cs new file mode 100644 index 00000000..b61731bd --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryLiquidityPool.cs @@ -0,0 +1,34 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryLiquidityPool : LedgerEntry +{ + public LiquidityPoolID LiquidityPoolID { get; set; } + public LiquidityPoolEntryBody LiquidityPoolBody { get; set; } + + public static LedgerEntryLiquidityPool FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.LIQUIDITY_POOL) + throw new ArgumentException("Not a LiquidityPoolEntry", nameof(xdrLedgerEntry)); + var xdrLiquidityPoolEntry = xdrLedgerEntry.Data.LiquidityPool; + + var ledgerEntryLiquidityPool = new LedgerEntryLiquidityPool + { + LiquidityPoolID = LiquidityPoolID.FromXdr(xdrLiquidityPoolEntry.LiquidityPoolID), + LiquidityPoolBody = LiquidityPoolEntryBody.FromXdr(xdrLiquidityPoolEntry.Body) + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryLiquidityPool); + return ledgerEntryLiquidityPool; + } + + public LiquidityPoolEntry ToXdr() + { + return new LiquidityPoolEntry + { + Body = LiquidityPoolBody.ToXdr(), + LiquidityPoolID = LiquidityPoolID.ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryOffer.cs b/stellar-dotnet-sdk/LedgerEntryOffer.cs new file mode 100644 index 00000000..e858876e --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryOffer.cs @@ -0,0 +1,63 @@ +using System; +using stellar_dotnet_sdk.xdr; +using Int64 = stellar_dotnet_sdk.xdr.Int64; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryOffer : LedgerEntry +{ + public KeyPair SellerID { get; set; } + + public long OfferID { get; set; } + + public long Amount { get; set; } + + public Asset Buying { get; set; } + + public Asset Selling { get; set; } + + public Price Price { get; set; } + + public uint Flags { get; set; } + + public OfferEntryExtension? OfferExtension { get; set; } + + public static LedgerEntryOffer FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.OFFER) + throw new ArgumentException("Not an OfferEntry", nameof(xdrLedgerEntry)); + + var xdrOfferEntry = xdrLedgerEntry.Data.Offer; + + var ledgerEntryOffer = new LedgerEntryOffer + { + SellerID = KeyPair.FromXdrPublicKey(xdrOfferEntry.SellerID.InnerValue), + OfferID = xdrOfferEntry.OfferID.InnerValue, + Amount = xdrOfferEntry.Amount.InnerValue, + Buying = Asset.FromXdr(xdrOfferEntry.Buying), + Selling = Asset.FromXdr(xdrOfferEntry.Selling), + Price = new Price(xdrOfferEntry.Price.N.InnerValue, xdrOfferEntry.Price.D.InnerValue), + Flags = xdrOfferEntry.Flags.InnerValue, + }; + + if (xdrOfferEntry.Ext.Discriminant != 0) + ledgerEntryOffer.OfferExtension = OfferEntryExtension.FromXdr(xdrOfferEntry.Ext); + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryOffer); + return ledgerEntryOffer; + } + + public OfferEntry ToXdr() + { + return new OfferEntry + { + SellerID = new AccountID(SellerID.XdrPublicKey), + OfferID = new Int64(OfferID), + Selling = Selling.ToXdr(), + Buying = Buying.ToXdr(), + Amount = new Int64(Amount), + Price = Price.ToXdr(), + Flags = new Uint32(Flags), + Ext = OfferExtension?.ToXdr() ?? new OfferEntry.OfferEntryExt() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryTTL.cs b/stellar-dotnet-sdk/LedgerEntryTTL.cs new file mode 100644 index 00000000..26007dbf --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryTTL.cs @@ -0,0 +1,34 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryTTL : LedgerEntry +{ + public Hash KeyHash { get; set; } + public uint LiveUntilLedgerSequence { get; set; } + + public static LedgerEntryTTL FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.TTL) + throw new ArgumentException("Not a ContractCodeEntry", nameof(xdrLedgerEntry)); + var xdrTtlEntry = xdrLedgerEntry.Data.Ttl; + var ledgerEntryTtl = new LedgerEntryTTL + { + KeyHash = Hash.FromXdr(xdrTtlEntry.KeyHash), + LiveUntilLedgerSequence = xdrTtlEntry.LiveUntilLedgerSeq.InnerValue + }; + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryTtl); + + return ledgerEntryTtl; + } + + public TTLEntry ToXdr() + { + return new TTLEntry + { + KeyHash = KeyHash.ToXdr(), + LiveUntilLedgerSeq = new Uint32(LiveUntilLedgerSequence) + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerEntryTrustline.cs b/stellar-dotnet-sdk/LedgerEntryTrustline.cs new file mode 100644 index 00000000..61da6449 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerEntryTrustline.cs @@ -0,0 +1,57 @@ +using System; +using stellar_dotnet_sdk.xdr; +using Int64 = stellar_dotnet_sdk.xdr.Int64; + +namespace stellar_dotnet_sdk; + +public class LedgerEntryTrustline : LedgerEntry +{ + public KeyPair Account { get; set; } + + public TrustlineAsset Asset { get; set; } + + public long Balance { get; set; } + + public long Limit { get; set; } + + public uint Flags { get; set; } + + public TrustlineEntryExtensionV1? TrustlineExtensionV1 { get; set; } + + public static LedgerEntryTrustline FromXdrLedgerEntry(xdr.LedgerEntry xdrLedgerEntry) + { + if (xdrLedgerEntry.Data.Discriminant.InnerValue != LedgerEntryType.LedgerEntryTypeEnum.TRUSTLINE) + throw new ArgumentException("Not a TrustLineEntry", nameof(xdrLedgerEntry)); + + var xdrTrustLineEntry = xdrLedgerEntry.Data.TrustLine; + var ledgerEntryTrustLine = new LedgerEntryTrustline + { + Account = KeyPair.FromXdrPublicKey(xdrTrustLineEntry.AccountID.InnerValue), + Asset = TrustlineAsset.FromXdr(xdrTrustLineEntry.Asset), + Balance = xdrTrustLineEntry.Balance.InnerValue, + Limit = xdrTrustLineEntry.Limit.InnerValue, + Flags = xdrTrustLineEntry.Flags.InnerValue + }; + if (xdrTrustLineEntry.Ext.Discriminant == 1) + ledgerEntryTrustLine.TrustlineExtensionV1 = TrustlineEntryExtensionV1.FromXdr(xdrTrustLineEntry.Ext.V1); + ExtraFieldsFromXdr(xdrLedgerEntry, ledgerEntryTrustLine); + return ledgerEntryTrustLine; + } + + public TrustLineEntry ToXdr() + { + return new TrustLineEntry + { + AccountID = new AccountID(Account.XdrPublicKey), + Asset = Asset.ToXdr(), + Balance = new Int64(Balance), + Limit = new Int64(Limit), + Flags = new Uint32(Flags), + Ext = new TrustLineEntry.TrustLineEntryExt + { + Discriminant = TrustlineExtensionV1 != null ? 1 : 0, + V1 = TrustlineExtensionV1?.ToXdr() ?? new TrustLineEntry.TrustLineEntryExt.TrustLineEntryV1() + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerFootprint.cs b/stellar-dotnet-sdk/LedgerFootprint.cs new file mode 100644 index 00000000..abe78e6f --- /dev/null +++ b/stellar-dotnet-sdk/LedgerFootprint.cs @@ -0,0 +1,28 @@ +using System; +using System.Linq; + +namespace stellar_dotnet_sdk; + +public class LedgerFootprint +{ + public LedgerKey[] ReadOnly { get; set; } = Array.Empty(); + public LedgerKey[] ReadWrite { get; set; } = Array.Empty(); + + public xdr.LedgerFootprint ToXdr() + { + return new xdr.LedgerFootprint + { + ReadOnly = ReadOnly.Select(x => x.ToXdr()).ToArray(), + ReadWrite = ReadWrite.Select(x => x.ToXdr()).ToArray() + }; + } + + public static LedgerFootprint FromXdr(xdr.LedgerFootprint xdr) + { + return new LedgerFootprint + { + ReadOnly = xdr.ReadOnly.Select(LedgerKey.FromXdr).ToArray(), + ReadWrite = xdr.ReadWrite.Select(LedgerKey.FromXdr).ToArray() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKey.cs b/stellar-dotnet-sdk/LedgerKey.cs index e1aedba1..dfaddf0a 100644 --- a/stellar-dotnet-sdk/LedgerKey.cs +++ b/stellar-dotnet-sdk/LedgerKey.cs @@ -12,6 +12,11 @@ public abstract class LedgerKey public static LedgerKey Data(KeyPair account, string dataName) => new LedgerKeyData(account, dataName); public static LedgerKey Offer(KeyPair seller, long offerId) => new LedgerKeyOffer(seller, offerId); public static LedgerKey Trustline(KeyPair account, TrustlineAsset asset) => new LedgerKeyTrustline(account, asset); + public static LedgerKey LiquidityPool(LiquidityPoolID poolId) => new LedgerKeyLiquidityPool(poolId); + public static LedgerKey ContractData(SCAddress contractId, SCVal key, ContractDataDurability durability) => new LedgerKeyContractData(contractId, key, durability); + public static LedgerKey ContractCode(string code) => new LedgerKeyContractCode(code); + public static LedgerKey ConfigSetting(ConfigSettingID settingId) => new LedgerKeyConfigSetting(settingId); + public static LedgerKey TTL(string key) => new LedgerKeyTTL(key); public static LedgerKey FromXdr(xdr.LedgerKey xdr) { @@ -27,9 +32,43 @@ public static LedgerKey FromXdr(xdr.LedgerKey xdr) return LedgerKeyTrustline.FromXdr(xdr.TrustLine); case LedgerEntryType.LedgerEntryTypeEnum.CLAIMABLE_BALANCE: return LedgerKeyClaimableBalance.FromXdr(xdr.ClaimableBalance); + case LedgerEntryType.LedgerEntryTypeEnum.LIQUIDITY_POOL: + return LedgerKeyLiquidityPool.FromXdr(xdr.LiquidityPool); + case LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_DATA: + return LedgerKeyContractData.FromXdr(xdr.ContractData); + case LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_CODE: + return LedgerKeyContractCode.FromXdr(xdr.ContractCode); + case LedgerEntryType.LedgerEntryTypeEnum.CONFIG_SETTING: + return LedgerKeyConfigSetting.FromXdr(xdr.ConfigSetting); + case LedgerEntryType.LedgerEntryTypeEnum.TTL: + return LedgerKeyTTL.FromXdr(xdr.Ttl); default: throw new Exception("Unknown ledger key " + xdr.Discriminant.InnerValue); } } + + /// + /// Creates a new object from the given LedgerEntry XDR base64 string. + /// + /// + /// object + public static LedgerKey FromXdrBase64(string xdrBase64) + { + var bytes = Convert.FromBase64String(xdrBase64); + var reader = new XdrDataInputStream(bytes); + var thisXdr = xdr.LedgerKey.Decode(reader); + return FromXdr(thisXdr); + } + + /// + /// Returns base64-encoded LedgerKey XDR object. + /// + public string ToXdrBase64() + { + var xdrValue = ToXdr(); + var writer = new XdrDataOutputStream(); + xdr.LedgerKey.Encode(writer, xdrValue); + return Convert.ToBase64String(writer.ToArray()); + } } } \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKeyConfigSetting.cs b/stellar-dotnet-sdk/LedgerKeyConfigSetting.cs new file mode 100644 index 00000000..c40ed139 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerKeyConfigSetting.cs @@ -0,0 +1,31 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerKeyConfigSetting : LedgerKey +{ + public LedgerKeyConfigSetting(ConfigSettingID settingId) + { + ConfigSettingID = settingId; + } + + public ConfigSettingID ConfigSettingID { get; set; } + + public override xdr.LedgerKey ToXdr() + { + return new xdr.LedgerKey + { + Discriminant = + new LedgerEntryType { InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONFIG_SETTING }, + ConfigSetting = new xdr.LedgerKey.LedgerKeyConfigSetting + { + ConfigSettingID = ConfigSettingID + } + }; + } + + public static LedgerKeyConfigSetting FromXdr(xdr.LedgerKey.LedgerKeyConfigSetting xdr) + { + return new LedgerKeyConfigSetting(xdr.ConfigSettingID); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKeyContractCode.cs b/stellar-dotnet-sdk/LedgerKeyContractCode.cs new file mode 100644 index 00000000..7d163655 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerKeyContractCode.cs @@ -0,0 +1,36 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerKeyContractCode : LedgerKey +{ + public LedgerKeyContractCode(string base64String) : this(new Hash(base64String)) + { + } + + public LedgerKeyContractCode(Hash hash) + { + Hash = hash; + } + + public Hash Hash { get; set; } + + public override xdr.LedgerKey ToXdr() + { + return new xdr.LedgerKey + { + Discriminant = + new LedgerEntryType { InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_CODE }, + ContractCode = new xdr.LedgerKey.LedgerKeyContractCode + { + Hash = Hash.ToXdr() + } + }; + } + + public static LedgerKeyContractCode FromXdr(xdr.LedgerKey.LedgerKeyContractCode xdr) + { + return new LedgerKeyContractCode(Convert.ToBase64String(xdr.Hash.InnerValue)); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKeyContractData.cs b/stellar-dotnet-sdk/LedgerKeyContractData.cs new file mode 100644 index 00000000..9229bfcd --- /dev/null +++ b/stellar-dotnet-sdk/LedgerKeyContractData.cs @@ -0,0 +1,38 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerKeyContractData : LedgerKey +{ + public LedgerKeyContractData(SCAddress contractId, SCVal key, ContractDataDurability durability) + { + Contract = contractId; + Key = key; + Durability = durability; + } + + public SCAddress Contract { get; set; } + public SCVal Key { get; set; } + public ContractDataDurability Durability { get; set; } + + public override xdr.LedgerKey ToXdr() + { + return new xdr.LedgerKey + { + Discriminant = + new LedgerEntryType { InnerValue = LedgerEntryType.LedgerEntryTypeEnum.CONTRACT_DATA }, + ContractData = new xdr.LedgerKey.LedgerKeyContractData + { + Contract = Contract.ToXdr(), + Key = Key.ToXdr(), + Durability = Durability + } + }; + } + + public static LedgerKeyContractData FromXdr(xdr.LedgerKey.LedgerKeyContractData xdr) + { + return new LedgerKeyContractData(SCAddress.FromXdr(xdr.Contract), SCVal.FromXdr(xdr.Key), + xdr.Durability); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKeyData.cs b/stellar-dotnet-sdk/LedgerKeyData.cs index 0b9b5804..7bccf099 100644 --- a/stellar-dotnet-sdk/LedgerKeyData.cs +++ b/stellar-dotnet-sdk/LedgerKeyData.cs @@ -2,8 +2,8 @@ namespace stellar_dotnet_sdk { public class LedgerKeyData : LedgerKey { - public new KeyPair Account { get; } - public string DataName { get; } + public KeyPair Account { get; } + public String64 DataName { get; } public LedgerKeyData(KeyPair account, string dataName) { diff --git a/stellar-dotnet-sdk/LedgerKeyLiquidityPool.cs b/stellar-dotnet-sdk/LedgerKeyLiquidityPool.cs new file mode 100644 index 00000000..0b299b09 --- /dev/null +++ b/stellar-dotnet-sdk/LedgerKeyLiquidityPool.cs @@ -0,0 +1,31 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerKeyLiquidityPool : LedgerKey +{ + public LedgerKeyLiquidityPool(LiquidityPoolID poolId) + { + LiquidityPoolID = poolId; + } + + public LiquidityPoolID LiquidityPoolID { get; set; } + + public override xdr.LedgerKey ToXdr() + { + return new xdr.LedgerKey + { + Discriminant = + new LedgerEntryType { InnerValue = LedgerEntryType.LedgerEntryTypeEnum.LIQUIDITY_POOL }, + LiquidityPool = new xdr.LedgerKey.LedgerKeyLiquidityPool + { + LiquidityPoolID = new PoolID(new xdr.Hash(LiquidityPoolID.Hash)) + } + }; + } + + public static LedgerKeyLiquidityPool FromXdr(xdr.LedgerKey.LedgerKeyLiquidityPool xdr) + { + return new LedgerKeyLiquidityPool(new LiquidityPoolID(xdr.LiquidityPoolID.InnerValue.InnerValue)); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LedgerKeyTTL.cs b/stellar-dotnet-sdk/LedgerKeyTTL.cs new file mode 100644 index 00000000..fdc44dcb --- /dev/null +++ b/stellar-dotnet-sdk/LedgerKeyTTL.cs @@ -0,0 +1,36 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class LedgerKeyTTL : LedgerKey +{ + public LedgerKeyTTL(string hexString) : this(new Hash(hexString)) + { + } + + private LedgerKeyTTL(Hash hash) + { + Key = hash; + } + + public Hash Key { get; } + + public override xdr.LedgerKey ToXdr() + { + return new xdr.LedgerKey + { + Discriminant = + new LedgerEntryType { InnerValue = LedgerEntryType.LedgerEntryTypeEnum.TTL }, + Ttl = new xdr.LedgerKey.LedgerKeyTtl + { + KeyHash = Key.ToXdr() + } + }; + } + + public static LedgerKeyTTL FromXdr(xdr.LedgerKey.LedgerKeyTtl xdr) + { + return new LedgerKeyTTL(Convert.ToBase64String(xdr.KeyHash.InnerValue)); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/Liabilities.cs b/stellar-dotnet-sdk/Liabilities.cs new file mode 100644 index 00000000..2ce533c4 --- /dev/null +++ b/stellar-dotnet-sdk/Liabilities.cs @@ -0,0 +1,29 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class Liabilities +{ + public Liabilities(long buying, long selling) + { + Buying = buying; + Selling = selling; + } + + public long Buying { get; } + public long Selling { get; } + + public xdr.Liabilities ToXdr() + { + return new xdr.Liabilities + { + Buying = new Int64(Buying), + Selling = new Int64(Selling) + }; + } + + public static Liabilities FromXdr(xdr.Liabilities xdr) + { + return new Liabilities(xdr.Buying.InnerValue, xdr.Selling.InnerValue); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LiquidityPoolConstantProduct.cs b/stellar-dotnet-sdk/LiquidityPoolConstantProduct.cs new file mode 100644 index 00000000..27f839e6 --- /dev/null +++ b/stellar-dotnet-sdk/LiquidityPoolConstantProduct.cs @@ -0,0 +1,57 @@ +using System; +using stellar_dotnet_sdk.xdr; +using Int64 = stellar_dotnet_sdk.xdr.Int64; + +namespace stellar_dotnet_sdk; + +public class LiquidityPoolConstantProduct : LiquidityPoolEntryBody +{ + public LiquidityPoolConstantProductParameters Parameters { get; set; } + public long ReserveA { get; set; } + public long ReserveB { get; set; } + public long TotalPoolShares { get; set; } + public long PoolSharesTrustLineCount { get; set; } + + public LiquidityPoolEntry.LiquidityPoolEntryBody.LiquidityPoolEntryConstantProduct ToXdr() + { + return new LiquidityPoolEntry.LiquidityPoolEntryBody.LiquidityPoolEntryConstantProduct + { + Params = Parameters.ToXdr().ConstantProduct, + ReserveA = new Int64(ReserveA), + ReserveB = new Int64(ReserveB), + TotalPoolShares = new Int64(TotalPoolShares), + PoolSharesTrustLineCount = new Int64(PoolSharesTrustLineCount) + }; + } + + public LiquidityPoolEntry.LiquidityPoolEntryBody ToXdrLiquidityPoolEntryBody() + { + return new LiquidityPoolEntry.LiquidityPoolEntryBody + { + Discriminant = new LiquidityPoolType + { + InnerValue = LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT + }, + ConstantProduct = ToXdr() + }; + } + + public static LiquidityPoolConstantProduct FromXdr(LiquidityPoolEntry.LiquidityPoolEntryBody.LiquidityPoolEntryConstantProduct xdrConstantProduct) + { + return new LiquidityPoolConstantProduct + { + Parameters = LiquidityPoolConstantProductParameters.FromXdr(xdrConstantProduct.Params), + ReserveA = xdrConstantProduct.ReserveA.InnerValue, + ReserveB = xdrConstantProduct.ReserveB.InnerValue, + TotalPoolShares = xdrConstantProduct.TotalPoolShares.InnerValue, + PoolSharesTrustLineCount = xdrConstantProduct.PoolSharesTrustLineCount.InnerValue, + }; + } + public static LiquidityPoolConstantProduct FromXdrLiquidityPoolEntryBody( + LiquidityPoolEntry.LiquidityPoolEntryBody xdrBody) + { + if (xdrBody.Discriminant.InnerValue != LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT) + throw new ArgumentException("Not a LiquidityPoolConstantProduct", nameof(xdrBody)); + return FromXdr(xdrBody.ConstantProduct); + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LiquidityPoolEntryBody.cs b/stellar-dotnet-sdk/LiquidityPoolEntryBody.cs new file mode 100644 index 00000000..59b299eb --- /dev/null +++ b/stellar-dotnet-sdk/LiquidityPoolEntryBody.cs @@ -0,0 +1,25 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public abstract class LiquidityPoolEntryBody +{ + public LiquidityPoolEntry.LiquidityPoolEntryBody ToXdr() + { + return this switch + { + LiquidityPoolConstantProduct constantProduct => constantProduct.ToXdrLiquidityPoolEntryBody(), + _ => throw new InvalidOperationException("Unknown liquidity pool type") + }; + } + + public static LiquidityPoolEntryBody FromXdr(LiquidityPoolEntry.LiquidityPoolEntryBody xdrBody) + { + return xdrBody.Discriminant.InnerValue switch + { + LiquidityPoolType.LiquidityPoolTypeEnum.LIQUIDITY_POOL_CONSTANT_PRODUCT => LiquidityPoolConstantProduct.FromXdrLiquidityPoolEntryBody(xdrBody), + _ => throw new InvalidOperationException("Unknown liquidity pool type") + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/LiquidityPoolShareTrustlineAsset.cs b/stellar-dotnet-sdk/LiquidityPoolShareTrustlineAsset.cs index d8fed022..0bd90902 100644 --- a/stellar-dotnet-sdk/LiquidityPoolShareTrustlineAsset.cs +++ b/stellar-dotnet-sdk/LiquidityPoolShareTrustlineAsset.cs @@ -54,7 +54,7 @@ public override int CompareTo(TrustlineAsset asset) return ToString().CompareTo(((LiquidityPoolShareTrustlineAsset)asset).ToString()); } - public override xdr.TrustLineAsset ToXdr() + public xdr.TrustLineAsset ToXdrTrustLineAsset() { xdr.TrustLineAsset trustlineAssetXdr = new xdr.TrustLineAsset(); trustlineAssetXdr.Discriminant.InnerValue = xdr.AssetType.AssetTypeEnum.ASSET_TYPE_POOL_SHARE; diff --git a/stellar-dotnet-sdk/MemoHash.cs b/stellar-dotnet-sdk/MemoHash.cs index 62398109..9cfb08a8 100644 --- a/stellar-dotnet-sdk/MemoHash.cs +++ b/stellar-dotnet-sdk/MemoHash.cs @@ -17,7 +17,7 @@ public override xdr.Memo ToXdr() var memo = new xdr.Memo(); memo.Discriminant = MemoType.Create(MemoType.MemoTypeEnum.MEMO_HASH); - var hash = new Hash(); + var hash = new xdr.Hash(); hash.InnerValue = MemoBytes; memo.Hash = hash; diff --git a/stellar-dotnet-sdk/MemoReturnHash.cs b/stellar-dotnet-sdk/MemoReturnHash.cs index 21b46038..4dc10b17 100644 --- a/stellar-dotnet-sdk/MemoReturnHash.cs +++ b/stellar-dotnet-sdk/MemoReturnHash.cs @@ -17,7 +17,7 @@ public override xdr.Memo ToXdr() var memo = new xdr.Memo(); memo.Discriminant = MemoType.Create(MemoType.MemoTypeEnum.MEMO_RETURN); - var hash = new Hash(); + var hash = new xdr.Hash(); hash.InnerValue = MemoBytes; memo.RetHash = hash; diff --git a/stellar-dotnet-sdk/NoNetworkSelectedException.cs b/stellar-dotnet-sdk/NoNetworkSelectedException.cs index a5960bec..b900a84a 100644 --- a/stellar-dotnet-sdk/NoNetworkSelectedException.cs +++ b/stellar-dotnet-sdk/NoNetworkSelectedException.cs @@ -4,7 +4,7 @@ namespace stellar_dotnet_sdk { [Serializable] - internal class NoNetworkSelectedException : Exception + public class NoNetworkSelectedException : Exception { public NoNetworkSelectedException() { diff --git a/stellar-dotnet-sdk/NotEnoughSignaturesException.cs b/stellar-dotnet-sdk/NotEnoughSignaturesException.cs index d0c118b3..bb93adfa 100644 --- a/stellar-dotnet-sdk/NotEnoughSignaturesException.cs +++ b/stellar-dotnet-sdk/NotEnoughSignaturesException.cs @@ -4,7 +4,7 @@ namespace stellar_dotnet_sdk { [Serializable] - internal class NotEnoughSignaturesException : Exception + public class NotEnoughSignaturesException : Exception { public NotEnoughSignaturesException() { diff --git a/stellar-dotnet-sdk/OfferEntryExtension.cs b/stellar-dotnet-sdk/OfferEntryExtension.cs new file mode 100644 index 00000000..07c3837a --- /dev/null +++ b/stellar-dotnet-sdk/OfferEntryExtension.cs @@ -0,0 +1,19 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class OfferEntryExtension +{ + public static OfferEntryExtension FromXdr(OfferEntry.OfferEntryExt xdrExtension) + { + return new OfferEntryExtension(); + } + + public OfferEntry.OfferEntryExt ToXdr() + { + return new OfferEntry.OfferEntryExt + { + Discriminant = 0 + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/Operation.cs b/stellar-dotnet-sdk/Operation.cs index a71cb7c8..814a7a8b 100644 --- a/stellar-dotnet-sdk/Operation.cs +++ b/stellar-dotnet-sdk/Operation.cs @@ -36,7 +36,7 @@ public static string FromXdrAmount(long value) } /// - /// Creates a new Operation object from the given Operation XDR base64 string. + /// Creates a new Operation object from the given Operation XDR base64-encoded string. /// /// /// Operation object @@ -64,7 +64,7 @@ public xdr.Operation ToXdr() } /// - /// Returns base64-encoded Operation XDR object. + /// Returns base64-encoded XDR string. /// public string ToXdrBase64() { diff --git a/stellar-dotnet-sdk/Price.cs b/stellar-dotnet-sdk/Price.cs index 08ddf330..a46bac77 100644 --- a/stellar-dotnet-sdk/Price.cs +++ b/stellar-dotnet-sdk/Price.cs @@ -90,7 +90,7 @@ public static Price FromXdr(sdkxdr.Price price) return new Price(price.N.InnerValue, price.D.InnerValue); } - public override bool Equals(object obj) + public override bool Equals(object? obj) { if (obj == null) return false; diff --git a/stellar-dotnet-sdk/SCVal.cs b/stellar-dotnet-sdk/SCVal.cs index 714faca9..190c8d97 100644 --- a/stellar-dotnet-sdk/SCVal.cs +++ b/stellar-dotnet-sdk/SCVal.cs @@ -1,7 +1,5 @@ using System; using System.Linq; -using System.Text; -using System.Xml.Schema; using stellar_dotnet_sdk.xdr; namespace stellar_dotnet_sdk; @@ -62,12 +60,13 @@ public static SCVal FromXdr(xdr.SCVal xdrVal) SCValType.SCValTypeEnum.SCV_MAP => SCMap.FromSCValXdr(xdrVal), SCValType.SCValTypeEnum.SCV_ADDRESS => SCAddress.FromSCValXdr(xdrVal), SCValType.SCValTypeEnum.SCV_CONTRACT_INSTANCE => SCContractInstance.FromSCValXdr(xdrVal), - SCValType.SCValTypeEnum.SCV_LEDGER_KEY_CONTRACT_INSTANCE => SCLedgerKeyContractInstance.FromSCValXdr(xdrVal), + SCValType.SCValTypeEnum.SCV_LEDGER_KEY_CONTRACT_INSTANCE => + SCLedgerKeyContractInstance.FromSCValXdr(xdrVal), SCValType.SCValTypeEnum.SCV_LEDGER_KEY_NONCE => SCNonceKey.FromSCValXdr(xdrVal), _ => throw new InvalidOperationException("Unknown SCVal type") }; } - + /// /// Creates a new SCVal object from the given SCVal XDR base64 string. /// @@ -80,7 +79,7 @@ public static SCVal FromXdrBase64(string xdrBase64) var thisXdr = xdr.SCVal.Decode(reader); return FromXdr(thisXdr); } - + /// /// Returns base64-encoded SCVal XDR object. /// @@ -99,6 +98,7 @@ public SCBool(bool value) { InnerValue = value; } + public bool InnerValue { get; set; } public new bool ToXdr() @@ -117,12 +117,12 @@ public xdr.SCVal ToSCValXdr() B = ToXdr(), }; } - + public static SCBool FromXdr(bool xdrBool) { return new SCBool(xdrBool); } - + public static SCBool FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_BOOL) @@ -134,8 +134,10 @@ public static SCBool FromSCValXdr(xdr.SCVal xdrVal) public class SCVoid : SCVal { - public new void ToXdr() { } - + public new void ToXdr() + { + } + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -152,9 +154,9 @@ public static SCVoid FromSCValXdr(xdr.SCVal xdrVal) if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_VOID) throw new ArgumentException("Not an SCVoid", nameof(xdrVal)); - return FromXdr(); - } - + return FromXdr(); + } + public static SCVoid FromXdr() { return new SCVoid(); @@ -164,6 +166,7 @@ public static SCVoid FromXdr() public abstract class SCError : SCVal { public SCErrorCode.SCErrorCodeEnum Code { get; set; } + public xdr.SCError ToXdr() { return this switch @@ -181,7 +184,7 @@ public xdr.SCError ToXdr() _ => throw new InvalidOperationException("Unknown SCVal type") }; } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -193,7 +196,7 @@ public xdr.SCVal ToSCValXdr() Error = ToXdr(), }; } - + public static SCError FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_ERROR) @@ -227,13 +230,14 @@ public SCContractError(uint value) { ContractCode = value; } + public uint ContractCode { get; set; } public static SCContractError FromSCErrorXdr(xdr.SCError xdrSCError) { return new SCContractError(xdrSCError.ContractCode.InnerValue); } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -256,7 +260,7 @@ public static SCWasmVmError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -279,7 +283,7 @@ public static SCContextError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -302,7 +306,7 @@ public static SCStorageError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -325,7 +329,7 @@ public static SCObjectError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -348,7 +352,7 @@ public static SCCryptoError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -371,7 +375,7 @@ public static SCEventsError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -394,7 +398,7 @@ public static SCBudgetError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -417,7 +421,7 @@ public static SCValueError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -440,7 +444,7 @@ public static SCAuthError FromSCErrorXdr(xdr.SCError xdrSCError) Code = xdrSCError.Code.InnerValue }; } - + public xdr.SCError ToSCErrorXdr() { return new xdr.SCError @@ -460,14 +464,14 @@ public SCUint32(uint value) { InnerValue = value; } - + public uint InnerValue { get; set; } - + public xdr.Uint32 ToXdr() { return new Uint32(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -479,12 +483,12 @@ public xdr.SCVal ToSCValXdr() U32 = ToXdr(), }; } - + public static SCUint32 FromXdr(xdr.Uint32 xdrUint32) { return new SCUint32(xdrUint32.InnerValue); } - + public static SCUint32 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_U32) @@ -507,7 +511,7 @@ public xdr.Int32 ToXdr() { return new xdr.Int32(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -519,12 +523,12 @@ public xdr.SCVal ToSCValXdr() I32 = ToXdr(), }; } - + public static SCInt32 FromXdr(xdr.Int32 xdrInt32) { return new SCInt32(xdrInt32.InnerValue); } - + public static SCInt32 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_I32) @@ -536,13 +540,18 @@ public static SCInt32 FromSCValXdr(xdr.SCVal xdrVal) public class SCUint64 : SCVal { + public SCUint64(ulong value) + { + InnerValue = value; + } + public ulong InnerValue { get; set; } - + public xdr.Uint64 ToXdr() { return new xdr.Uint64(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -554,15 +563,12 @@ public xdr.SCVal ToSCValXdr() U64 = ToXdr(), }; } - + public static SCUint64 FromXdr(xdr.Uint64 xdrUint64) { - return new SCUint64 - { - InnerValue = xdrUint64.InnerValue, - }; + return new SCUint64(xdrUint64.InnerValue); } - + public static SCUint64 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_U64) @@ -578,14 +584,14 @@ public SCInt64(long value) { InnerValue = value; } - + public long InnerValue { get; set; } - + public xdr.Int64 ToXdr() { return new xdr.Int64(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -597,12 +603,12 @@ public xdr.SCVal ToSCValXdr() I64 = ToXdr(), }; } - + public static SCInt64 FromXdr(xdr.Int64 xdrInt64) { return new SCInt64(xdrInt64.InnerValue); } - + public static SCInt64 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_I64) @@ -618,14 +624,14 @@ public SCTimePoint(ulong value) { InnerValue = value; } - + public ulong InnerValue { get; set; } - + public xdr.TimePoint ToXdr() { return new xdr.TimePoint(new xdr.Uint64(InnerValue)); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -637,12 +643,12 @@ public xdr.SCVal ToSCValXdr() Timepoint = ToXdr(), }; } - + public static SCTimePoint FromXdr(xdr.TimePoint xdrTimePoint) { return new SCTimePoint(xdrTimePoint.InnerValue.InnerValue); } - + public static SCTimePoint FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_TIMEPOINT) @@ -658,14 +664,14 @@ public SCDuration(ulong value) { InnerValue = value; } - + public ulong InnerValue { get; set; } - + public xdr.Duration ToXdr() { return new xdr.Duration(new xdr.Uint64(InnerValue)); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -677,12 +683,12 @@ public xdr.SCVal ToSCValXdr() Duration = ToXdr(), }; } - + public static SCDuration FromXdr(xdr.Duration xdrDuration) { return new SCDuration(xdrDuration.InnerValue.InnerValue); } - + public static SCDuration FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_DURATION) @@ -694,9 +700,15 @@ public static SCDuration FromSCValXdr(xdr.SCVal xdrVal) public class SCUint128 : SCVal { + public SCUint128(ulong lo, ulong hi) + { + Hi = hi; + Lo = lo; + } + public ulong Lo { get; set; } public ulong Hi { get; set; } - + public xdr.UInt128Parts ToXdr() { return new xdr.UInt128Parts @@ -705,7 +717,7 @@ public xdr.UInt128Parts ToXdr() Hi = new xdr.Uint64(Hi), }; } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -717,16 +729,12 @@ public xdr.SCVal ToSCValXdr() U128 = ToXdr(), }; } - + public static SCUint128 FromXdr(xdr.UInt128Parts xdrUInt128Parts) { - return new SCUint128 - { - Lo = xdrUInt128Parts.Lo.InnerValue, - Hi = xdrUInt128Parts.Hi.InnerValue, - }; + return new SCUint128(xdrUInt128Parts.Lo.InnerValue, xdrUInt128Parts.Hi.InnerValue); } - + public static SCUint128 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_U128) @@ -738,9 +746,15 @@ public static SCUint128 FromSCValXdr(xdr.SCVal xdrVal) public class SCInt128 : SCVal { + public SCInt128(ulong lo, long hi) + { + Hi = hi; + Lo = lo; + } + public ulong Lo { get; set; } public long Hi { get; set; } - + public xdr.Int128Parts ToXdr() { return new xdr.Int128Parts @@ -749,7 +763,7 @@ public xdr.Int128Parts ToXdr() Hi = new xdr.Int64(Hi), }; } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -765,26 +779,18 @@ public xdr.SCVal ToSCValXdr() }, }; } - + public static SCInt128 FromXdr(xdr.Int128Parts xdrInt128Parts) { - return new SCInt128 - { - Lo = xdrInt128Parts.Lo.InnerValue, - Hi = xdrInt128Parts.Hi.InnerValue, - }; + return new SCInt128(xdrInt128Parts.Lo.InnerValue, xdrInt128Parts.Hi.InnerValue); } - + public static SCInt128 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_I128) throw new ArgumentException("Not an SCInt128", nameof(xdrVal)); - return new SCInt128 - { - Hi = xdrVal.I128.Hi.InnerValue, - Lo = xdrVal.I128.Lo.InnerValue, - }; + return new SCInt128(xdrVal.I128.Lo.InnerValue, xdrVal.I128.Hi.InnerValue); } } @@ -794,7 +800,7 @@ public class SCUint256 : SCVal public ulong HiLo { get; set; } public ulong LoHi { get; set; } public ulong LoLo { get; set; } - + public xdr.UInt256Parts ToXdr() { return new xdr.UInt256Parts @@ -805,7 +811,7 @@ public xdr.UInt256Parts ToXdr() LoLo = new xdr.Uint64(LoLo), }; } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -817,7 +823,7 @@ public xdr.SCVal ToSCValXdr() U256 = ToXdr(), }; } - + public static SCUint256 FromXdr(xdr.UInt256Parts xdrUInt256Parts) { return new SCUint256 @@ -828,7 +834,7 @@ public static SCUint256 FromXdr(xdr.UInt256Parts xdrUInt256Parts) LoLo = xdrUInt256Parts.LoLo.InnerValue, }; } - + public static SCUint256 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_U256) @@ -844,7 +850,7 @@ public class SCInt256 : SCVal public ulong HiLo { get; set; } public ulong LoHi { get; set; } public ulong LoLo { get; set; } - + public xdr.Int256Parts ToXdr() { return new xdr.Int256Parts @@ -855,7 +861,7 @@ public xdr.Int256Parts ToXdr() LoLo = new xdr.Uint64(LoLo), }; } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -867,7 +873,7 @@ public xdr.SCVal ToSCValXdr() I256 = ToXdr(), }; } - + public static SCInt256 FromXdr(xdr.Int256Parts xdrInt256Parts) { return new SCInt256 @@ -878,7 +884,7 @@ public static SCInt256 FromXdr(xdr.Int256Parts xdrInt256Parts) LoLo = xdrInt256Parts.LoLo.InnerValue, }; } - + public static SCInt256 FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_I256) @@ -894,13 +900,14 @@ public SCBytes(byte[] value) { InnerValue = value; } + public byte[] InnerValue { get; set; } - + public xdr.SCBytes ToXdr() { return new xdr.SCBytes(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -912,12 +919,12 @@ public xdr.SCVal ToSCValXdr() Bytes = ToXdr(), }; } - + public static SCBytes FromXdr(xdr.SCBytes xdrSCBytes) { return new SCBytes(xdrSCBytes.InnerValue); } - + public static SCBytes FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_BYTES) @@ -935,12 +942,12 @@ public SCString(string value) } public string InnerValue { get; set; } - + public xdr.SCString ToXdr() { return new xdr.SCString(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -952,12 +959,12 @@ public xdr.SCVal ToSCValXdr() Str = ToXdr(), }; } - + public static SCString FromXdr(xdr.SCString xdrSCString) { return new SCString(xdrSCString.InnerValue); } - + public static SCString FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_STRING) @@ -975,12 +982,12 @@ public SCSymbol(string innerValue) } public string InnerValue { get; set; } - + public xdr.SCSymbol ToXdr() { return new xdr.SCSymbol(InnerValue); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -992,12 +999,12 @@ public xdr.SCVal ToSCValXdr() Sym = ToXdr(), }; } - + public static SCSymbol FromXdr(xdr.SCSymbol xdrSCSymbol) { return new SCSymbol(xdrSCSymbol.InnerValue); } - + public static SCSymbol FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_SYMBOL) @@ -1013,14 +1020,14 @@ public SCVec(SCVal[] value) { InnerValue = value; } - + public SCVal[] InnerValue { get; set; } - + public xdr.SCVec ToXdr() { return new xdr.SCVec(InnerValue.Select(a => a.ToXdr()).ToArray()); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -1032,12 +1039,12 @@ public xdr.SCVal ToSCValXdr() Vec = ToXdr(), }; } - + public static SCVec FromXdr(xdr.SCVec xdrSCVec) { return new SCVec(xdrSCVec.InnerValue.Select(SCVal.FromXdr).ToArray()); } - + public static SCVec FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_VEC) @@ -1050,12 +1057,14 @@ public static SCVec FromSCValXdr(xdr.SCVal xdrVal) public class SCMap : SCVal { public SCMapEntry[] Entries { get; set; } = Array.Empty(); - + public xdr.SCMap ToXdr() { - return Entries.Length == 0 ? new xdr.SCMap { InnerValue = Array.Empty() } : new xdr.SCMap(Entries.Select(a => a.ToXdr()).ToArray()); + return Entries.Length == 0 + ? new xdr.SCMap { InnerValue = Array.Empty() } + : new xdr.SCMap(Entries.Select(a => a.ToXdr()).ToArray()); } - + public xdr.SCVal ToSCValXdr() { return new xdr.SCVal @@ -1067,7 +1076,7 @@ public xdr.SCVal ToSCValXdr() Map = ToXdr(), }; } - + public static SCMap FromXdr(xdr.SCMap xdrSCMap) { if (xdrSCMap == null) return new SCMap(); @@ -1076,7 +1085,7 @@ public static SCMap FromXdr(xdr.SCMap xdrSCMap) Entries = xdrSCMap.InnerValue.Select(SCMapEntry.FromXdr).ToArray(), }; } - + public static SCMap FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_MAP) @@ -1090,7 +1099,7 @@ public class SCMapEntry { public SCVal Key { get; set; } public SCVal Value { get; set; } - + public static SCMapEntry FromXdr(xdr.SCMapEntry xdr) { return new SCMapEntry @@ -1099,7 +1108,7 @@ public static SCMapEntry FromXdr(xdr.SCMapEntry xdr) Value = SCVal.FromXdr(xdr.Val), }; } - + public xdr.SCMapEntry ToXdr() { return new xdr.SCMapEntry @@ -1140,11 +1149,10 @@ public xdr.SCVal ToSCValXdr() Address = ToXdr(), }; } - + public abstract xdr.SCAddress ToXdr(); } - public class SCAccountId : SCAddress { public SCAccountId(string value) @@ -1154,9 +1162,9 @@ public SCAccountId(string value) InnerValue = value; } - + public string InnerValue { get; set; } - + public static SCAccountId FromXdr(xdr.SCAddress xdr) { return new SCAccountId( @@ -1185,16 +1193,16 @@ public SCContractId(string value) InnerValue = value; } - + public string InnerValue { get; } - + public static SCContractId FromXdr(xdr.SCAddress xdr) { var value = StrKey.EncodeContractId(xdr.ContractId.InnerValue); if (!StrKey.IsValidContractId(value)) throw new InvalidOperationException("Invalid contract id"); - + return new SCContractId(value); } @@ -1216,7 +1224,9 @@ public override xdr.SCAddress ToXdr() public class SCLedgerKeyContractInstance : SCVal { - public void ToXdr() { } + public void ToXdr() + { + } public xdr.SCVal ToSCValXdr() { @@ -1247,7 +1257,7 @@ public class SCContractInstance : SCVal { public ContractExecutable Executable { get; set; } public SCMap Storage { get; set; } = new(); - + public static SCContractInstance FromXdr(xdr.SCContractInstance xdr) { return new SCContractInstance @@ -1256,7 +1266,7 @@ public static SCContractInstance FromXdr(xdr.SCContractInstance xdr) Storage = SCMap.FromXdr(xdr.Storage), }; } - + public static SCContractInstance FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_CONTRACT_INSTANCE) @@ -1264,7 +1274,7 @@ public static SCContractInstance FromSCValXdr(xdr.SCVal xdrVal) return FromXdr(xdrVal.Instance); } - + public xdr.SCContractInstance ToXdr() { return new xdr.SCContractInstance @@ -1293,10 +1303,13 @@ public static ContractExecutable FromXdr(xdr.ContractExecutable xdrContractExecu { return xdrContractExecutable.Discriminant.InnerValue switch { - ContractExecutableType.ContractExecutableTypeEnum.CONTRACT_EXECUTABLE_WASM => ContractExecutableWasm.FromXdr(xdrContractExecutable), - ContractExecutableType.ContractExecutableTypeEnum.CONTRACT_EXECUTABLE_STELLAR_ASSET => ContractExecutableStellarAsset.FromXdr(xdrContractExecutable) + ContractExecutableType.ContractExecutableTypeEnum.CONTRACT_EXECUTABLE_WASM => + ContractExecutableWasm.FromXdr(xdrContractExecutable), + ContractExecutableType.ContractExecutableTypeEnum.CONTRACT_EXECUTABLE_STELLAR_ASSET => + ContractExecutableStellarAsset.FromXdr(xdrContractExecutable) }; } + public abstract xdr.ContractExecutable ToXdr(); } @@ -1322,7 +1335,7 @@ public override xdr.ContractExecutable ToXdr() { InnerValue = xdr.ContractExecutableType.ContractExecutableTypeEnum.CONTRACT_EXECUTABLE_WASM, }, - WasmHash = new Hash(Convert.FromBase64String(WasmHash)), + WasmHash = new xdr.Hash(Convert.FromBase64String(WasmHash)), }; } } @@ -1352,9 +1365,9 @@ public SCNonceKey(long value) { Nonce = value; } - + public long Nonce { get; set; } - + public xdr.SCNonceKey ToXdr() { return new xdr.SCNonceKey @@ -1374,12 +1387,12 @@ public xdr.SCVal ToSCValXdr() NonceKey = ToXdr(), }; } - + public static SCNonceKey FromXdr(xdr.SCNonceKey xdr) { return new SCNonceKey(xdr.Nonce.InnerValue); } - + public static SCNonceKey FromSCValXdr(xdr.SCVal xdrVal) { if (xdrVal.Discriminant.InnerValue != SCValType.SCValTypeEnum.SCV_LEDGER_KEY_NONCE) @@ -1387,4 +1400,4 @@ public static SCNonceKey FromSCValXdr(xdr.SCVal xdrVal) return FromXdr(xdrVal.NonceKey); } -} +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/SetOptionsOperation.cs b/stellar-dotnet-sdk/SetOptionsOperation.cs index 012b5b16..4e3200c5 100644 --- a/stellar-dotnet-sdk/SetOptionsOperation.cs +++ b/stellar-dotnet-sdk/SetOptionsOperation.cs @@ -335,7 +335,7 @@ public Builder SetHomeDomain(string homeDomain) /// /// Add, update, or remove a signer from the account. Signer is deleted if the weight = 0; /// - /// The signer key. Use helper to create this object. + /// The signer key. Use helper to create this object. /// The weight to attach to the signer (0-255). /// Builder object so you can chain methods. public Builder SetSigner(SignerKey signer, uint weight) diff --git a/stellar-dotnet-sdk/Signer.cs b/stellar-dotnet-sdk/Signer.cs index c10aa0eb..30258aeb 100644 --- a/stellar-dotnet-sdk/Signer.cs +++ b/stellar-dotnet-sdk/Signer.cs @@ -1,124 +1,28 @@ -using System; -using xdr = stellar_dotnet_sdk.xdr; +using stellar_dotnet_sdk.xdr; -namespace stellar_dotnet_sdk +namespace stellar_dotnet_sdk; + +public class Signer { - /// - /// Signer is a helper class that creates objects. - /// - public class Signer + public SignerKey Key { get; set; } + + public uint Weight { get; set; } + + public xdr.Signer ToXdr() { - /// - /// Create ed25519PublicKey from - /// a - /// - /// - /// sdkxdr.SignerKey - public static xdr.SignerKey Ed25519PublicKey(KeyPair keyPair) - { - if (keyPair == null) - throw new ArgumentNullException(nameof(keyPair), "keyPair cannot be null"); - - return keyPair.XdrSignerKey; - } - - /// - /// Create sha256Hash from - /// a sha256 hash of a preimage. - /// - /// - /// sdkxdr.SignerKey - public static xdr.SignerKey Sha256Hash(byte[] hash) + return new xdr.Signer() { - if (hash == null) - throw new ArgumentNullException(nameof(hash), "hash cannot be null"); - - var signerKey = new xdr.SignerKey(); - var value = CreateUint256(hash); - - signerKey.Discriminant = xdr.SignerKeyType.Create(xdr.SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_HASH_X); - signerKey.HashX = value; - - return signerKey; - } - - /// - /// Create preAuthTx from - /// a hash. - /// - /// - /// sdkxdr.SignerKey - public static xdr.SignerKey PreAuthTx(Transaction tx) - { - return PreAuthTx(tx, Network.Current); - } - - /// - /// Create preAuthTx from - /// a hash. - /// - /// - /// - /// sdkxdr.SignerKey - public static xdr.SignerKey PreAuthTx(Transaction tx, Network network) - { - if (tx == null) - throw new ArgumentNullException(nameof(tx), "tx cannot be null"); - - return PreAuthTx(tx.Hash(network)); - } - - /// - /// Create preAuthTx from - /// a transaction hash. - /// - /// - /// sdkxdr.SignerKey - public static xdr.SignerKey PreAuthTx(byte[] hash) - { - if (hash == null) - throw new ArgumentNullException(nameof(hash), "hash cannot be null"); - - var signerKey = new xdr.SignerKey(); - var value = CreateUint256(hash); - - signerKey.Discriminant = xdr.SignerKeyType.Create(xdr.SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_PRE_AUTH_TX); - signerKey.PreAuthTx = value; - - return signerKey; - } - - /// - /// Create SignerKey from SignedPayloadSigner - /// - /// - /// - public static xdr.SignerKey SignedPayload(SignedPayloadSigner signedPayloadSigner) - { - xdr.SignerKey signerKey = new xdr.SignerKey(); - xdr.SignerKey.SignerKeyEd25519SignedPayload payloadSigner = new xdr.SignerKey.SignerKeyEd25519SignedPayload(); - payloadSigner.Payload = signedPayloadSigner.Payload; - payloadSigner.Ed25519 = signedPayloadSigner.SignerAccountID.InnerValue.Ed25519; - - signerKey.Discriminant.InnerValue = xdr.SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD; - signerKey.Ed25519SignedPayload = payloadSigner; - - return signerKey; - } - - /// - /// Creates a Uint256 from a byte hash. - /// - /// - /// A Uint256 - private static xdr.Uint256 CreateUint256(byte[] hash) + Key = Key, + Weight = new Uint32(Weight) + }; + } + + public static Signer FromXdr(xdr.Signer xdrSigner) + { + return new Signer { - if (hash.Length != 32) - throw new ArgumentException("hash must be 32 bytes long"); - - var value = new xdr.Uint256(); - value.InnerValue = hash; - return value; - } + Key = xdrSigner.Key, + Weight = xdrSigner.Weight.InnerValue + }; } } \ No newline at end of file diff --git a/stellar-dotnet-sdk/SignerUtil.cs b/stellar-dotnet-sdk/SignerUtil.cs new file mode 100644 index 00000000..c8451015 --- /dev/null +++ b/stellar-dotnet-sdk/SignerUtil.cs @@ -0,0 +1,123 @@ +using System; +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +/// +/// Signer is a helper class that creates objects. +/// +public class SignerUtil +{ + /// + /// Create ed25519PublicKey from + /// a + /// + /// + /// sdkxdr.SignerKey + public static SignerKey Ed25519PublicKey(KeyPair keyPair) + { + if (keyPair == null) + throw new ArgumentNullException(nameof(keyPair), "keyPair cannot be null"); + + return keyPair.XdrSignerKey; + } + + /// + /// Create sha256Hash from + /// a sha256 hash of a preimage. + /// + /// + /// sdkxdr.SignerKey + public static SignerKey Sha256Hash(byte[] hash) + { + if (hash == null) + throw new ArgumentNullException(nameof(hash), "hash cannot be null"); + + var signerKey = new SignerKey(); + var value = CreateUint256(hash); + + signerKey.Discriminant = SignerKeyType.Create(SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_HASH_X); + signerKey.HashX = value; + + return signerKey; + } + + /// + /// Create preAuthTx from + /// a hash. + /// + /// + /// sdkxdr.SignerKey + public static SignerKey PreAuthTx(Transaction tx) + { + return PreAuthTx(tx, Network.Current); + } + + /// + /// Create preAuthTx from + /// a hash. + /// + /// + /// + /// sdkxdr.SignerKey + public static SignerKey PreAuthTx(Transaction tx, Network network) + { + if (tx == null) + throw new ArgumentNullException(nameof(tx), "tx cannot be null"); + + return PreAuthTx(tx.Hash(network)); + } + + /// + /// Create preAuthTx from + /// a transaction hash. + /// + /// + /// sdkxdr.SignerKey + public static SignerKey PreAuthTx(byte[] hash) + { + if (hash == null) + throw new ArgumentNullException(nameof(hash), "hash cannot be null"); + + var signerKey = new SignerKey(); + var value = CreateUint256(hash); + + signerKey.Discriminant = SignerKeyType.Create(SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_PRE_AUTH_TX); + signerKey.PreAuthTx = value; + + return signerKey; + } + + /// + /// Create SignerKey from SignedPayloadSigner + /// + /// + /// + public static SignerKey SignedPayload(SignedPayloadSigner signedPayloadSigner) + { + var signerKey = new SignerKey(); + var payloadSigner = new SignerKey.SignerKeyEd25519SignedPayload(); + payloadSigner.Payload = signedPayloadSigner.Payload; + payloadSigner.Ed25519 = signedPayloadSigner.SignerAccountID.InnerValue.Ed25519; + + signerKey.Discriminant.InnerValue = SignerKeyType.SignerKeyTypeEnum.SIGNER_KEY_TYPE_ED25519_SIGNED_PAYLOAD; + signerKey.Ed25519SignedPayload = payloadSigner; + + return signerKey; + } + + /// + /// Creates a Uint256 from a byte hash. + /// + /// + /// A Uint256 + private static Uint256 CreateUint256(byte[] hash) + { + if (hash.Length != 32) + throw new ArgumentException("hash must be 32 bytes long"); + + var value = new Uint256(); + value.InnerValue = hash; + return value; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/SorobanResources.cs b/stellar-dotnet-sdk/SorobanResources.cs new file mode 100644 index 00000000..9a600dd6 --- /dev/null +++ b/stellar-dotnet-sdk/SorobanResources.cs @@ -0,0 +1,33 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class SorobanResources +{ + public LedgerFootprint Footprint { get; set; } = new(); + public uint Instructions { get; set; } + public uint ReadBytes { get; set; } + public uint WriteBytes { get; set; } + + public xdr.SorobanResources ToXdr() + { + return new xdr.SorobanResources + { + Footprint = Footprint.ToXdr(), + Instructions = new Uint32(Instructions), + ReadBytes = new Uint32(ReadBytes), + WriteBytes = new Uint32(WriteBytes) + }; + } + + public static SorobanResources FromXdr(xdr.SorobanResources xdr) + { + return new SorobanResources + { + Footprint = LedgerFootprint.FromXdr(xdr.Footprint), + Instructions = xdr.Instructions.InnerValue, + ReadBytes = xdr.ReadBytes.InnerValue, + WriteBytes = xdr.WriteBytes.InnerValue + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/SorobanTransactionData.cs b/stellar-dotnet-sdk/SorobanTransactionData.cs new file mode 100644 index 00000000..f8d20fff --- /dev/null +++ b/stellar-dotnet-sdk/SorobanTransactionData.cs @@ -0,0 +1,30 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class SorobanTransactionData +{ + public ExtensionPoint ExtensionPoint { get; set; } + public SorobanResources Resources { get; set; } + public long ResourceFee { get; set; } + + public xdr.SorobanTransactionData ToXdr() + { + return new xdr.SorobanTransactionData + { + Ext = ExtensionPoint.ToXdr(), + Resources = Resources.ToXdr(), + ResourceFee = new Int64(ResourceFee) + }; + } + + public static SorobanTransactionData FromXdr(xdr.SorobanTransactionData xdr) + { + return new SorobanTransactionData + { + ExtensionPoint = ExtensionPoint.FromXdr(xdr.Ext), + Resources = SorobanResources.FromXdr(xdr.Resources), + ResourceFee = xdr.ResourceFee.InnerValue + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/StateArchivalSettings.cs b/stellar-dotnet-sdk/StateArchivalSettings.cs new file mode 100644 index 00000000..6bba3c73 --- /dev/null +++ b/stellar-dotnet-sdk/StateArchivalSettings.cs @@ -0,0 +1,58 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class StateArchivalSettings : LedgerEntryConfigSetting +{ + public uint MaxEntryTTL { get; set; } + public uint MinTemporaryTTL { get; set; } + public uint MinPersistentTTL { get; set; } + public long PersistentRentRateDenominator { get; set; } + public long TempRentRateDenominator { get; set; } + public uint MaxEntriesToArchive { get; set; } + public uint BucketListSizeWindowSampleSize { get; set; } + public ulong EvictionScanSize { get; set; } + public uint StartingEvictionScanLevel { get; set; } + + public static StateArchivalSettings FromXdr(xdr.StateArchivalSettings xdrConfig) + { + return new StateArchivalSettings + { + MaxEntryTTL = xdrConfig.MaxEntryTTL.InnerValue, + MinTemporaryTTL = xdrConfig.MinTemporaryTTL.InnerValue, + MinPersistentTTL = xdrConfig.MinPersistentTTL.InnerValue, + PersistentRentRateDenominator = xdrConfig.PersistentRentRateDenominator.InnerValue, + TempRentRateDenominator = xdrConfig.TempRentRateDenominator.InnerValue, + MaxEntriesToArchive = xdrConfig.MaxEntriesToArchive.InnerValue, + BucketListSizeWindowSampleSize = xdrConfig.BucketListSizeWindowSampleSize.InnerValue, + EvictionScanSize = xdrConfig.EvictionScanSize.InnerValue, + StartingEvictionScanLevel = xdrConfig.StartingEvictionScanLevel.InnerValue + }; + } + + public xdr.StateArchivalSettings ToXdr() + { + return new xdr.StateArchivalSettings + { + MaxEntryTTL = new Uint32(MaxEntryTTL), + MinTemporaryTTL = new Uint32(MinTemporaryTTL), + MinPersistentTTL = new Uint32(MinPersistentTTL), + PersistentRentRateDenominator = new Int64(PersistentRentRateDenominator), + TempRentRateDenominator = new Int64(TempRentRateDenominator), + MaxEntriesToArchive = new Uint32(MaxEntriesToArchive), + BucketListSizeWindowSampleSize = new Uint32(BucketListSizeWindowSampleSize), + EvictionScanSize = new Uint64(EvictionScanSize), + StartingEvictionScanLevel = new Uint32(StartingEvictionScanLevel) + }; + } + + public ConfigSettingEntry ToXdrConfigSettingEntry() + { + return new ConfigSettingEntry + { + Discriminant = + ConfigSettingID.Create(ConfigSettingID.ConfigSettingIDEnum.CONFIG_SETTING_STATE_ARCHIVAL), + StateArchivalSettings = ToXdr() + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/String64.cs b/stellar-dotnet-sdk/String64.cs new file mode 100644 index 00000000..0fb3febb --- /dev/null +++ b/stellar-dotnet-sdk/String64.cs @@ -0,0 +1,45 @@ +using System; + +namespace stellar_dotnet_sdk; + +public class String64 +{ + private readonly string _value; + + private String64(string value) + { + if (value.Length > 64) throw new ArgumentException("String64 cannot exceed 64 characters", nameof(value)); + _value = value; + } + + public static implicit operator string(String64 s) + { + return s._value; + } + + public static implicit operator String64(string s) + { + return new String64(s); + } + + public xdr.String64 ToXdr() + { + return new xdr.String64(_value); + } + + public static String64 FromXdr(xdr.String64 xdrString64) + { + return new String64(xdrString64.InnerValue); + } + + public override bool Equals(object? obj) + { + if (obj == null) + return false; + + if (obj is not String64 string64) + return false; + + return _value == string64._value; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/TooManySignaturesException.cs b/stellar-dotnet-sdk/TooManySignaturesException.cs index 5e55b7ea..902b89b6 100644 --- a/stellar-dotnet-sdk/TooManySignaturesException.cs +++ b/stellar-dotnet-sdk/TooManySignaturesException.cs @@ -4,7 +4,7 @@ namespace stellar_dotnet_sdk { [Serializable] - internal class TooManySignaturesException : Exception + public class TooManySignaturesException : Exception { public TooManySignaturesException() { diff --git a/stellar-dotnet-sdk/Transaction.cs b/stellar-dotnet-sdk/Transaction.cs index 35deeb2b..06c252ab 100644 --- a/stellar-dotnet-sdk/Transaction.cs +++ b/stellar-dotnet-sdk/Transaction.cs @@ -5,9 +5,11 @@ namespace stellar_dotnet_sdk { public class Transaction : TransactionBase { - internal Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Operation[] operations, Memo memo, TransactionPreconditions preconditions) + internal Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Operation[] operations, Memo memo, + TransactionPreconditions preconditions) { - SourceAccount = sourceAccount ?? throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null"); + SourceAccount = sourceAccount ?? + throw new ArgumentNullException(nameof(sourceAccount), "sourceAccount cannot be null"); Fee = fee; SequenceNumber = sequenceNumber; Operations = operations ?? throw new ArgumentNullException(nameof(operations), "operations cannot be null"); @@ -19,6 +21,13 @@ internal Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Op Preconditions = preconditions; } + internal Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Operation[] operations, Memo memo, + TransactionPreconditions preconditions, SorobanTransactionData sorobanData) : this(sourceAccount, fee, + sequenceNumber, operations, memo, preconditions) + { + SorobanData = sorobanData; + } + public uint Fee { get; } public IAccountId SourceAccount { get; } @@ -33,6 +42,8 @@ internal Transaction(IAccountId sourceAccount, uint fee, long sequenceNumber, Op public TimeBounds TimeBounds => Preconditions.TimeBounds; + public SorobanTransactionData? SorobanData { get; } + /// /// Returns signature base for the given network. /// @@ -44,7 +55,7 @@ public override byte[] SignatureBase(Network network) throw new NoNetworkSelectedException(); // Hashed NetworkID - var networkHash = new Hash { InnerValue = network.NetworkId }; + var networkHash = new xdr.Hash { InnerValue = network.NetworkId }; var taggedTransaction = new TransactionSignaturePayload.TransactionSignaturePayloadTaggedTransaction { Discriminant = EnvelopeType.Create(EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX), @@ -136,7 +147,12 @@ public xdr.Transaction ToXdrV1() operations[i] = Operations[i].ToXdr(); // ext - var ext = new xdr.Transaction.TransactionExt { Discriminant = 0 }; + var ext = new xdr.Transaction.TransactionExt() { Discriminant = 0 }; + if (SorobanData != null) + { + ext.Discriminant = 1; + ext.SorobanData = SorobanData.ToXdr(); + } var transaction = new xdr.Transaction { @@ -158,7 +174,8 @@ public xdr.Transaction ToXdrV1() 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()."); + throw new NotEnoughSignaturesException( + "Transaction must be signed by at least one signer. Use transaction.sign()."); return ToEnvelopeXdr(version, Signatures.ToArray()); } @@ -167,7 +184,8 @@ public override TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version /// Generates TransactionEnvelope XDR object. This transaction MUST be signed before being useful /// /// - public override TransactionEnvelope ToUnsignedEnvelopeXdr(TransactionXdrVersion version = TransactionXdrVersion.V1) + public override TransactionEnvelope ToUnsignedEnvelopeXdr( + TransactionXdrVersion version = TransactionXdrVersion.V1) { if (Signatures.Count > 0) throw new TooManySignaturesException("Transaction must not be signed. Use ToEnvelopeXDR."); @@ -180,7 +198,8 @@ private TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version, Decorat var thisXdr = new TransactionEnvelope(); if (version == TransactionXdrVersion.V0) { - thisXdr.Discriminant = new EnvelopeType { InnerValue = EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_V0 }; + thisXdr.Discriminant = new EnvelopeType + { InnerValue = EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX_V0 }; thisXdr.V0 = new TransactionV0Envelope(); var transaction = ToXdrV0(); @@ -199,6 +218,7 @@ private TransactionEnvelope ToEnvelopeXdr(TransactionXdrVersion version, Decorat { throw new Exception($"Invalid TransactionXdrVersion {version}"); } + return thisXdr; } @@ -220,7 +240,8 @@ public static Transaction FromEnvelopeXdr(TransactionEnvelope envelope) case EnvelopeType.EnvelopeTypeEnum.ENVELOPE_TYPE_TX: return FromEnvelopeXdrV1(envelope.V1); default: - throw new ArgumentException($"Invalid TransactionEnvelope: expected an ENVELOPE_TYPE_TX or ENVELOPE_TYPE_TX_V0 but received {envelope.Discriminant.InnerValue}"); + throw new ArgumentException( + $"Invalid TransactionEnvelope: expected an ENVELOPE_TYPE_TX or ENVELOPE_TYPE_TX_V0 but received {envelope.Discriminant.InnerValue}"); } } } @@ -241,7 +262,8 @@ public static Transaction FromEnvelopeXdrV0(TransactionV0Envelope envelope) operations[i] = Operation.FromXdr(transactionXdr.Operations[i]); } - Transaction transaction = new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, preconditions); + Transaction transaction = + new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, preconditions); foreach (var signature in envelope.Signatures) { @@ -266,7 +288,10 @@ public static Transaction FromEnvelopeXdrV1(TransactionV1Envelope envelope) operations[i] = Operation.FromXdr(transactionXdr.Operations[i]); } - Transaction transaction = new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, preconditions); + var sorobanData = SorobanTransactionData.FromXdr(transactionXdr.Ext.SorobanData); + + var transaction = + new Transaction(sourceAccount, fee, sequenceNumber, operations, memo, preconditions, sorobanData); foreach (var signature in envelope.Signatures) { diff --git a/stellar-dotnet-sdk/TransactionBuilder.cs b/stellar-dotnet-sdk/TransactionBuilder.cs index b4c2d051..8ce15abd 100644 --- a/stellar-dotnet-sdk/TransactionBuilder.cs +++ b/stellar-dotnet-sdk/TransactionBuilder.cs @@ -13,6 +13,7 @@ public class TransactionBuilder private Memo _memo; private TransactionPreconditions _preconditions; private uint _fee; + private SorobanTransactionData _sorobanData; /// /// Construct a new transaction builder. @@ -144,6 +145,18 @@ public TransactionBuilder SetFee(uint fee) return this; } + /// + /// Sets the transaction's internal (resources, footprint, etc.). + /// + /// an object containing the data. + /// Builder object so you can chain methods. + /// + public TransactionBuilder SetSorobanTransactionData(SorobanTransactionData sorobanData) + { + _sorobanData = sorobanData; + return this; + } + /// /// Builds a transaction. It will increment sequence number of the source account. /// @@ -155,7 +168,7 @@ public Transaction Build() //var totalFee = operations.Length * _fee; var opsCount = Convert.ToUInt32(operations.Length); uint totalFee = checked(opsCount * _fee); - var transaction = new Transaction(_sourceAccount.MuxedAccount, totalFee, _sourceAccount.IncrementedSequenceNumber, operations, _memo, _preconditions); + var transaction = new Transaction(_sourceAccount.MuxedAccount, totalFee, _sourceAccount.IncrementedSequenceNumber, operations, _memo, _preconditions, _sorobanData); // Increment sequence number when there were no exceptions when creating a transaction _sourceAccount.IncrementSequenceNumber(); return transaction; diff --git a/stellar-dotnet-sdk/TrustlineAsset.cs b/stellar-dotnet-sdk/TrustlineAsset.cs index a6ec7391..98bd5f6a 100644 --- a/stellar-dotnet-sdk/TrustlineAsset.cs +++ b/stellar-dotnet-sdk/TrustlineAsset.cs @@ -67,7 +67,8 @@ public static TrustlineAsset FromXdr(xdr.TrustLineAsset trustLineAssetXdr) return Create(new AssetTypeCreditAlphaNum12(assetCode, accountID)); case xdr.AssetType.AssetTypeEnum.ASSET_TYPE_POOL_SHARE: - return new LiquidityPoolShareTrustlineAsset(LiquidityPoolID.FromXdr(trustLineAssetXdr.LiquidityPoolID)); + return new LiquidityPoolShareTrustlineAsset( + LiquidityPoolID.FromXdr(trustLineAssetXdr.LiquidityPoolID)); default: throw new ArgumentException($"Unknown asset type {trustLineAssetXdr.Discriminant.InnerValue}"); @@ -80,7 +81,15 @@ public static TrustlineAsset FromXdr(xdr.TrustLineAsset trustLineAssetXdr) public abstract int CompareTo(TrustlineAsset asset); - public abstract xdr.TrustLineAsset ToXdr(); + public xdr.TrustLineAsset ToXdr() + { + return this switch + { + Wrapper wrapper => wrapper.ToXdrTrustLineAsset(), + LiquidityPoolShareTrustlineAsset poolShareTrustlineAsset => poolShareTrustlineAsset.ToXdrTrustLineAsset(), + _ => throw new InvalidOperationException("Unknown TrustLineAsset type") + }; + } public class Wrapper : TrustlineAsset { @@ -114,7 +123,7 @@ public override int CompareTo(TrustlineAsset asset) return Asset.CompareTo(((TrustlineAsset.Wrapper)asset).Asset); } - public override xdr.TrustLineAsset ToXdr() + public xdr.TrustLineAsset ToXdrTrustLineAsset() { xdr.TrustLineAsset trustlineAssetXdr = new xdr.TrustLineAsset(); @@ -122,9 +131,8 @@ public override xdr.TrustLineAsset ToXdr() trustlineAssetXdr.Discriminant = assetXdr.Discriminant; trustlineAssetXdr.AlphaNum4 = assetXdr.AlphaNum4; trustlineAssetXdr.AlphaNum12 = assetXdr.AlphaNum12; - return trustlineAssetXdr; } } } -} +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/TrustlineEntryExtensionV1.cs b/stellar-dotnet-sdk/TrustlineEntryExtensionV1.cs new file mode 100644 index 00000000..a5e36e58 --- /dev/null +++ b/stellar-dotnet-sdk/TrustlineEntryExtensionV1.cs @@ -0,0 +1,36 @@ +using stellar_dotnet_sdk.xdr; +using XDRTrustLineEntryV1 = stellar_dotnet_sdk.xdr.TrustLineEntry.TrustLineEntryExt.TrustLineEntryV1; + +namespace stellar_dotnet_sdk; + +public class TrustlineEntryExtensionV1 +{ + public Liabilities Liabilities { get; set; } + + public TrustLineEntryExtensionV2? TrustlineExtensionV2 { get; set; } + + public static TrustlineEntryExtensionV1 FromXdr(XDRTrustLineEntryV1 xdrExtensionV1) + { + var entryExtensionV1 = new TrustlineEntryExtensionV1 + { + Liabilities = Liabilities.FromXdr(xdrExtensionV1.Liabilities) + }; + if (xdrExtensionV1.Ext.Discriminant == 2) + entryExtensionV1.TrustlineExtensionV2 = TrustLineEntryExtensionV2.FromXdr(xdrExtensionV1.Ext.V2); + + return entryExtensionV1; + } + + public XDRTrustLineEntryV1 ToXdr() + { + return new XDRTrustLineEntryV1 + { + Liabilities = Liabilities.ToXdr(), + Ext = new XDRTrustLineEntryV1.TrustLineEntryV1Ext + { + Discriminant = TrustlineExtensionV2 != null ? 2 : 0, + V2 = TrustlineExtensionV2?.ToXdr() ?? new xdr.TrustLineEntryExtensionV2() + } + }; + } +} \ No newline at end of file diff --git a/stellar-dotnet-sdk/TrustlineEntryExtensionV2.cs b/stellar-dotnet-sdk/TrustlineEntryExtensionV2.cs new file mode 100644 index 00000000..d9c4bb9e --- /dev/null +++ b/stellar-dotnet-sdk/TrustlineEntryExtensionV2.cs @@ -0,0 +1,28 @@ +using stellar_dotnet_sdk.xdr; + +namespace stellar_dotnet_sdk; + +public class TrustLineEntryExtensionV2 +{ + public int LiquidityPoolUseCount { get; set; } + + public static TrustLineEntryExtensionV2 FromXdr(xdr.TrustLineEntryExtensionV2 xdrExtensionV2) + { + return new TrustLineEntryExtensionV2 + { + LiquidityPoolUseCount = xdrExtensionV2.LiquidityPoolUseCount.InnerValue + }; + } + + public xdr.TrustLineEntryExtensionV2 ToXdr() + { + return new xdr.TrustLineEntryExtensionV2 + { + LiquidityPoolUseCount = new Int32(LiquidityPoolUseCount), + Ext = new xdr.TrustLineEntryExtensionV2.TrustLineEntryExtensionV2Ext + { + Discriminant = 0 + } + }; + } +} \ No newline at end of file