public static LedgerObject ReadSt(ref StReader reader) { var fieldId = reader.ReadFieldId(); if (fieldId.TypeCode != StTypeCode.UInt16 || fieldId.FieldCode != 1) { throw new RippleException( string.Format("Expected LedgerEntryType field, got {0}", fieldId)); } var type = (StLedgerEntryType)reader.ReadUInt16(); switch (type) { case StLedgerEntryType.AccountRoot: return(new AccountRootLedgerEntry(ref reader)); case StLedgerEntryType.DirectoryNode: return(new DirectoryNodeLedgerEntry(ref reader)); case StLedgerEntryType.RippleState: return(new RippleStateLedgerEntry(ref reader)); case StLedgerEntryType.Ticket: return(new TicketLedgerEntry(ref reader)); case StLedgerEntryType.SignerList: return(new SignerListLedgerEntry(ref reader)); case StLedgerEntryType.Offer: return(new OfferLedgerEntry(ref reader)); case StLedgerEntryType.LedgerHashes: return(new LedgerHashesLedgerEntry(ref reader)); case StLedgerEntryType.Amendments: return(new AmendmentsLedgerEntry(ref reader)); case StLedgerEntryType.FeeSettings: return(new FeeSettingsLedgerEntry(ref reader)); case StLedgerEntryType.Escrow: return(new EscrowLedgerEntry(ref reader)); case StLedgerEntryType.PayChannel: return(new PayChannelLedgerEntry(ref reader)); case StLedgerEntryType.DepositPreauth: return(new DepositPreauthLedgerEntry(ref reader)); case StLedgerEntryType.Check: return(new CheckLedgerEntry(ref reader)); case StLedgerEntryType.NegativeUNL: return(new NegativeUNLLedgerEntry(ref reader)); } throw new RippleException(string.Format("Unrecognized ledger entry type: {0}", type)); }
public Majority(ref StReader reader) { var fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.UInt32_CloseTime) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.UInt32_CloseTime, fieldId)); } CloseTime = Epoch.ToDateTimeOffset(reader.ReadUInt32()); fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.Hash256_Amendment) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.Hash256_Amendment, fieldId)); } Amendment = reader.ReadHash256(); fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.Object_ObjectEndMarker) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.Object_ObjectEndMarker, fieldId)); } }
public SignerEntry(ref StReader reader) { var fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.UInt16_SignerWeight) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.UInt16_SignerWeight, fieldId)); } SignerWeight = reader.ReadUInt16(); fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.AccountID_Account) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.AccountID_Account, fieldId)); } Account = reader.ReadAccount(); fieldId = reader.ReadFieldId(); if (fieldId != StFieldId.Object_ObjectEndMarker) { throw new Exception(string.Format("Expected {0} but got {1}", StFieldId.Object_ObjectEndMarker, fieldId)); } }
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); }