public static void Encode(XdrDataOutputStream stream, LedgerUpgrade encodedLedgerUpgrade) { stream.WriteInt((int)encodedLedgerUpgrade.Discriminant.InnerValue); switch (encodedLedgerUpgrade.Discriminant.InnerValue) { case LedgerUpgradeType.LedgerUpgradeTypeEnum.LEDGER_UPGRADE_VERSION: Uint32.Encode(stream, encodedLedgerUpgrade.NewLedgerVersion); break; case LedgerUpgradeType.LedgerUpgradeTypeEnum.LEDGER_UPGRADE_BASE_FEE: Uint32.Encode(stream, encodedLedgerUpgrade.NewBaseFee); break; case LedgerUpgradeType.LedgerUpgradeTypeEnum.LEDGER_UPGRADE_MAX_TX_SET_SIZE: Uint32.Encode(stream, encodedLedgerUpgrade.NewMaxTxSetSize); break; case LedgerUpgradeType.LedgerUpgradeTypeEnum.LEDGER_UPGRADE_BASE_RESERVE: Uint32.Encode(stream, encodedLedgerUpgrade.NewBaseReserve); break; } }
public static void Encode(XdrDataOutputStream stream, LedgerKey encodedLedgerKey) { stream.WriteInt((int)encodedLedgerKey.Discriminant.InnerValue); switch (encodedLedgerKey.Discriminant.InnerValue) { case LedgerEntryType.LedgerEntryTypeEnum.ACCOUNT: LedgerKeyAccount.Encode(stream, encodedLedgerKey.Account); break; case LedgerEntryType.LedgerEntryTypeEnum.TRUSTLINE: LedgerKeyTrustLine.Encode(stream, encodedLedgerKey.TrustLine); break; case LedgerEntryType.LedgerEntryTypeEnum.OFFER: LedgerKeyOffer.Encode(stream, encodedLedgerKey.Offer); break; case LedgerEntryType.LedgerEntryTypeEnum.DATA: LedgerKeyData.Encode(stream, encodedLedgerKey.Data); break; } }
public static void Encode(XdrDataOutputStream stream, StellarMessage encodedStellarMessage) { stream.WriteInt((int)encodedStellarMessage.Discriminant.InnerValue); switch (encodedStellarMessage.Discriminant.InnerValue) { case MessageType.MessageTypeEnum.ERROR_MSG: Error.Encode(stream, encodedStellarMessage.Error); break; case MessageType.MessageTypeEnum.HELLO: Hello.Encode(stream, encodedStellarMessage.Hello); break; case MessageType.MessageTypeEnum.AUTH: Auth.Encode(stream, encodedStellarMessage.Auth); break; case MessageType.MessageTypeEnum.DONT_HAVE: DontHave.Encode(stream, encodedStellarMessage.DontHave); break; case MessageType.MessageTypeEnum.GET_PEERS: break; case MessageType.MessageTypeEnum.PEERS: int peerssize = encodedStellarMessage.Peers.Length; stream.WriteInt(peerssize); for (int i = 0; i < peerssize; i++) { PeerAddress.Encode(stream, encodedStellarMessage.Peers[i]); } break; case MessageType.MessageTypeEnum.GET_TX_SET: Uint256.Encode(stream, encodedStellarMessage.TxSetHash); break; case MessageType.MessageTypeEnum.TX_SET: TransactionSet.Encode(stream, encodedStellarMessage.TxSet); break; case MessageType.MessageTypeEnum.TRANSACTION: TransactionEnvelope.Encode(stream, encodedStellarMessage.Transaction); break; case MessageType.MessageTypeEnum.GET_SCP_QUORUMSET: Uint256.Encode(stream, encodedStellarMessage.QSetHash); break; case MessageType.MessageTypeEnum.SCP_QUORUMSET: SCPQuorumSet.Encode(stream, encodedStellarMessage.QSet); break; case MessageType.MessageTypeEnum.SCP_MESSAGE: SCPEnvelope.Encode(stream, encodedStellarMessage.Envelope); break; case MessageType.MessageTypeEnum.GET_SCP_STATE: Uint32.Encode(stream, encodedStellarMessage.GetSCPLedgerSeq); break; } }
public static void Encode(XdrDataOutputStream stream, Int32 encodedInt32) { stream.WriteInt(encodedInt32.InnerValue); }
public static void Encode(XdrDataOutputStream stream, Auth encodedAuth) { stream.WriteInt(encodedAuth.Unused); }
public static void Encode(XdrDataOutputStream stream, AllowTrustOp encodedAllowTrustOp) { AccountID.Encode(stream, encodedAllowTrustOp.Trustor); AllowTrustOpAsset.Encode(stream, encodedAllowTrustOp.Asset); stream.WriteInt(encodedAllowTrustOp.Authorize ? 1 : 0); }
public static void Encode(XdrDataOutputStream stream, SetOptionsOp encodedSetOptionsOp) { if (encodedSetOptionsOp.InflationDest != null) { stream.WriteInt(1); AccountID.Encode(stream, encodedSetOptionsOp.InflationDest); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.ClearFlags != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.ClearFlags); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.SetFlags != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.SetFlags); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.MasterWeight != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.MasterWeight); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.LowThreshold != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.LowThreshold); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.MedThreshold != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.MedThreshold); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.HighThreshold != null) { stream.WriteInt(1); Uint32.Encode(stream, encodedSetOptionsOp.HighThreshold); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.HomeDomain != null) { stream.WriteInt(1); String32.Encode(stream, encodedSetOptionsOp.HomeDomain); } else { stream.WriteInt(0); } if (encodedSetOptionsOp.Signer != null) { stream.WriteInt(1); Signer.Encode(stream, encodedSetOptionsOp.Signer); } else { stream.WriteInt(0); } }
public static void Encode(XdrDataOutputStream stream, OperationBody encodedOperationBody) { stream.WriteInt((int)encodedOperationBody.Discriminant.InnerValue); switch (encodedOperationBody.Discriminant.InnerValue) { case OperationType.OperationTypeEnum.CREATE_ACCOUNT: CreateAccountOp.Encode(stream, encodedOperationBody.CreateAccountOp); break; case OperationType.OperationTypeEnum.PAYMENT: PaymentOp.Encode(stream, encodedOperationBody.PaymentOp); break; case OperationType.OperationTypeEnum.PATH_PAYMENT_STRICT_RECEIVE: PathPaymentStrictReceiveOp.Encode(stream, encodedOperationBody.PathPaymentStrictReceiveOp); break; case OperationType.OperationTypeEnum.MANAGE_SELL_OFFER: ManageSellOfferOp.Encode(stream, encodedOperationBody.ManageSellOfferOp); break; case OperationType.OperationTypeEnum.CREATE_PASSIVE_SELL_OFFER: CreatePassiveSellOfferOp.Encode(stream, encodedOperationBody.CreatePassiveSellOfferOp); break; case OperationType.OperationTypeEnum.SET_OPTIONS: SetOptionsOp.Encode(stream, encodedOperationBody.SetOptionsOp); break; case OperationType.OperationTypeEnum.CHANGE_TRUST: ChangeTrustOp.Encode(stream, encodedOperationBody.ChangeTrustOp); break; case OperationType.OperationTypeEnum.ALLOW_TRUST: AllowTrustOp.Encode(stream, encodedOperationBody.AllowTrustOp); break; case OperationType.OperationTypeEnum.ACCOUNT_MERGE: MuxedAccount.Encode(stream, encodedOperationBody.Destination); break; case OperationType.OperationTypeEnum.INFLATION: break; case OperationType.OperationTypeEnum.MANAGE_DATA: ManageDataOp.Encode(stream, encodedOperationBody.ManageDataOp); break; case OperationType.OperationTypeEnum.BUMP_SEQUENCE: BumpSequenceOp.Encode(stream, encodedOperationBody.BumpSequenceOp); break; case OperationType.OperationTypeEnum.MANAGE_BUY_OFFER: ManageBuyOfferOp.Encode(stream, encodedOperationBody.ManageBuyOfferOp); break; case OperationType.OperationTypeEnum.PATH_PAYMENT_STRICT_SEND: PathPaymentStrictSendOp.Encode(stream, encodedOperationBody.PathPaymentStrictSendOp); break; case OperationType.OperationTypeEnum.CREATE_CLAIMABLE_BALANCE: CreateClaimableBalanceOp.Encode(stream, encodedOperationBody.CreateClaimableBalanceOp); break; case OperationType.OperationTypeEnum.CLAIM_CLAIMABLE_BALANCE: ClaimClaimableBalanceOp.Encode(stream, encodedOperationBody.ClaimClaimableBalanceOp); break; case OperationType.OperationTypeEnum.BEGIN_SPONSORING_FUTURE_RESERVES: BeginSponsoringFutureReservesOp.Encode(stream, encodedOperationBody.BeginSponsoringFutureReservesOp); break; case OperationType.OperationTypeEnum.END_SPONSORING_FUTURE_RESERVES: break; case OperationType.OperationTypeEnum.REVOKE_SPONSORSHIP: RevokeSponsorshipOp.Encode(stream, encodedOperationBody.RevokeSponsorshipOp); break; } }
public void XdrCompatibilityTest() { var testArray = new byte[32]; Array.Fill(testArray, (byte)100); //forward compatibility var legacyXdrSerializationStream = new XdrDataOutputStream(); legacyXdrSerializationStream.WriteInt(435); legacyXdrSerializationStream.WriteUInt(435); legacyXdrSerializationStream.WriteLong(43546345634657565L); legacyXdrSerializationStream.WriteDoubleArray(new double[] { 435.15, 64656.11 }); legacyXdrSerializationStream.WriteString("oiewurouqwe"); legacyXdrSerializationStream.WriteVarOpaque(32, testArray); var bufferReader = new XdrBufferReader(legacyXdrSerializationStream.ToArray()); Assert.AreEqual(435, bufferReader.ReadInt32()); Assert.AreEqual((uint)435, bufferReader.ReadUInt32()); Assert.AreEqual(43546345634657565L, bufferReader.ReadInt64()); { var length = bufferReader.ReadInt32(); var value = new double[length]; for (var i = 0; i < length; i++) { value[i] = bufferReader.ReadDouble(); } Assert.AreEqual(new double[] { 435.15, 64656.11 }, value); } Assert.AreEqual("oiewurouqwe", bufferReader.ReadString()); Assert.AreEqual(testArray, bufferReader.ReadVariable()); using var streamReader = new XdrStreamReader(new MemoryStream(legacyXdrSerializationStream.ToArray())); Assert.AreEqual(435, streamReader.ReadInt32()); Assert.AreEqual((uint)435, streamReader.ReadUInt32()); Assert.AreEqual(43546345634657565L, streamReader.ReadInt64()); { var length = streamReader.ReadInt32(); var value = new double[length]; for (var i = 0; i < length; i++) { value[i] = streamReader.ReadDouble(); } Assert.AreEqual(new double[] { 435.15, 64656.11 }, value); } Assert.AreEqual("oiewurouqwe", streamReader.ReadString()); Assert.AreEqual(testArray, streamReader.ReadVariable()); //backward compatibility var bufferWriter = new XdrBufferWriter(); bufferWriter.WriteInt32(435); bufferWriter.WriteUInt32((uint)435); { var arr = new double[] { 435.15, 64656.11 }; bufferWriter.WriteInt32(arr.Length); foreach (var d in arr) { bufferWriter.WriteDouble(d); } } bufferWriter.WriteString("oiewurouqwe"); bufferWriter.WriteVariable(testArray); var legacyXdrReader = new XdrDataInputStream(bufferWriter.ToArray()); Assert.AreEqual(435, legacyXdrReader.ReadInt()); Assert.AreEqual((uint)435, legacyXdrReader.ReadUInt()); Assert.AreEqual(new double[] { 435.15, 64656.11 }, legacyXdrReader.ReadDoubleArray()); Assert.AreEqual("oiewurouqwe", legacyXdrReader.ReadString()); Assert.AreEqual(testArray, legacyXdrReader.ReadVarOpaque(32)); using var memoryStream = new MemoryStream(); var streamWriter = new XdrStreamWriter(memoryStream); streamWriter.WriteInt32(435); streamWriter.WriteUInt32((uint)435); { var arr = new double[] { 435.15, 64656.11 }; streamWriter.WriteInt32(arr.Length); foreach (var d in arr) { streamWriter.WriteDouble(d); } } streamWriter.WriteString("oiewurouqwe"); streamWriter.WriteVariable(testArray); var res = memoryStream.ToArray(); var reference = bufferWriter.ToArray(); CollectionAssert.AreEqual(reference, res); }