public void TestExample() { var utf8 = System.Text.Encoding.UTF8.GetBytes("11006122000000002400000001250062FEA42D0000000055C204A65CF2542946289A3358C67D991B5E135FABFA89F271DBA7A150C08CA0466240000000354540208114C909F42250CFE8F12A7A1A0DFBD3CBD20F32CD79"); Span <byte> data = new byte[Base16.GetDecodedFromUtf8Length(utf8.Length)]; Assert.Equal(System.Buffers.OperationStatus.Done, Base16.DecodeFromUtf8(utf8, data, out var _, out var _)); var reader = new StReader(data); Assert.Equal(StFieldId.UInt16_LedgerEntryType, reader.ReadFieldId()); Assert.Equal(StLedgerEntryType.AccountRoot, (StLedgerEntryType)reader.ReadUInt16()); var accountRoot = new AccountRootLedgerEntry(ref reader); Assert.Equal(new AccountId("rKKzk9ghA2iuy3imqMXUHJqdRPMtNDGf4c"), accountRoot.Account); Assert.Equal(XrpAmount.FromDrops(893730848), accountRoot.Balance); Assert.Equal(AccountRootFlags.None, accountRoot.Flags); Assert.Equal(0u, accountRoot.OwnerCount); Assert.Equal(new Hash256("C204A65CF2542946289A3358C67D991B5E135FABFA89F271DBA7A150C08CA046"), accountRoot.PreviousTxnID); Assert.Equal(6487716u, accountRoot.PreviousTxnLgrSeq); Assert.Equal(1u, accountRoot.Sequence); Assert.Equal(new Hash256("00001A2969BE1FC85F1D7A55282FA2E6D95C71D2E4B9C0FDD3D9994F3C00FF8F"), accountRoot.ID); Assert.Equal(data.Length, reader.ConsumedBytes); }
public async Task TestGetPath_Event() { var accounts = await Task.WhenAll(TestAccount.Create(), TestAccount.Create(), TestAccount.Create(), TestAccount.Create()); await Utils.WaitForAccounts(Api, accounts); var gbp = new CurrencyCode("GBP"); var A1 = accounts[0]; var A2 = accounts[1]; var G3 = accounts[2]; var M1 = accounts[3]; // Start listening for updates var tcs = new TaskCompletionSource <PathFindResponse>(); var expectedId = new TaskCompletionSource <uint>(); Api.OnPathFind += (api, id, response) => { Assert.Equal(expectedId.Task.Result, id); Assert.Same(Api, api); if (response.Alternatives.Count != 0) { tcs.TrySetResult(response); } }; // Ask for a path to send XRP to A2 from A1 via GBP var pathFindRequest = new PathFindRequest(); pathFindRequest.SourceAccount = A1.Address; pathFindRequest.DestinationAccount = A2.Address; pathFindRequest.DestinationAmount = XrpAmount.FromXrp(10m); pathFindRequest.SourceCurrencies = new[] { new CurrencyType(gbp) }; var(requestId, pathFindResponse) = await Api.PathFind(pathFindRequest); expectedId.SetResult(requestId); // Should be empty Assert.Equal(pathFindRequest.SourceAccount, pathFindResponse.SourceAccount); Assert.Equal(pathFindRequest.DestinationAccount, pathFindResponse.DestinationAccount); Assert.Equal(pathFindRequest.DestinationAmount, pathFindResponse.DestinationAmount); Assert.Empty(pathFindResponse.Alternatives); // Set up trust lines, payments and offers var accountSet = new AccountSetTransaction(); accountSet.Account = G3.Address; accountSet.SetFlag = AccountSetFlags.DefaultRipple; var(_, _) = await SubmitTransaction(G3.Secret, accountSet); var trustSet = new TrustSetTransaction(); trustSet.LimitAmount = new IssuedAmount(G3.Address, gbp, new Currency(100m)); trustSet.Account = A1.Address; var(_, _) = await SubmitTransaction(A1.Secret, trustSet); trustSet.Account = A2.Address; var(_, _) = await SubmitTransaction(A2.Secret, trustSet); trustSet.LimitAmount = new IssuedAmount(G3.Address, gbp, new Currency(1000m)); trustSet.Account = M1.Address; var(_, _) = await SubmitTransaction(M1.Secret, trustSet); var payment = new PaymentTransaction(); payment.Account = G3.Address; payment.Amount = new IssuedAmount(G3.Address, gbp, new Currency(50m)); payment.Destination = A1.Address; var(_, _) = await SubmitTransaction(G3.Secret, payment); payment.Destination = A2.Address; var(_, _) = await SubmitTransaction(G3.Secret, payment); payment.Amount = new IssuedAmount(G3.Address, gbp, new Currency(100m)); payment.Destination = M1.Address; var(_, _) = await SubmitTransaction(G3.Secret, payment); var offerCreate = new OfferCreateTransaction(); offerCreate.Account = M1.Address; offerCreate.TakerPays = new IssuedAmount(G3.Address, gbp, new Currency(1m)); offerCreate.TakerGets = XrpAmount.FromXrp(10m); var(_, _) = await SubmitTransaction(M1.Secret, offerCreate); // Assert for the path that should eventually be found void AssertPath(PathFindResponse pathFindResponse) { Assert.Equal(pathFindRequest.SourceAccount, pathFindResponse.SourceAccount); Assert.Equal(pathFindRequest.DestinationAccount, pathFindResponse.DestinationAccount); Assert.Equal(pathFindRequest.DestinationAmount, pathFindResponse.DestinationAmount); var alternative = Assert.Single(pathFindResponse.Alternatives); Assert.Equal(new IssuedAmount(A1.Address, gbp, new Currency(1m)), alternative.SourceAmount); var path = Assert.Single(alternative.PathsComputed); Assert.Collection(path, item => Assert.Equal(G3.Address, item.Account), item => Assert.Equal(CurrencyCode.XRP, item.Currency)); } // Wait for the path to be found pathFindResponse = tcs.Task.Result; AssertPath(pathFindResponse); // Ask for the path explictly pathFindResponse = await Api.PathFindStatus(); AssertPath(pathFindResponse); // ... and try and make a payment with that path payment = new PaymentTransaction(); payment.Account = pathFindRequest.SourceAccount; payment.Destination = pathFindRequest.DestinationAccount; payment.Amount = pathFindRequest.DestinationAmount; var alternative = Assert.Single(pathFindResponse.Alternatives); payment.SendMax = alternative.SourceAmount; payment.Paths = alternative.PathsComputed; var(_, _) = await SubmitTransaction(A1.Secret, payment); // Stop listening for the path await Api.PathFindClose(); }
public void TestToString(ulong drops, string expected) { var amount = XrpAmount.FromDrops(drops); Assert.Equal(expected, amount.ToString()); }
public void WriteAmount(StAmountFieldCode fieldCode, XrpAmount value) { WriteFieldId(StTypeCode.Amount, (uint)fieldCode); System.Buffers.Binary.BinaryPrimitives.WriteUInt64BigEndian(bufferWriter.GetSpan(8), value.Drops | 0x4000000000000000); bufferWriter.Advance(8); }