public void Serialize(ref MessagePackWriter writer, IAccountStateDelta value,
                              MessagePackSerializerOptions options)
        {
            var state = new Dictionary(
                value.UpdatedAddresses.Select(addr => new KeyValuePair <IKey, IValue>(
                                                  (Binary)addr.ToByteArray(),
                                                  value.GetState(addr) ?? new Bencodex.Types.Null()
                                                  ))
                );
            var balance = new Bencodex.Types.List(
#pragma warning disable LAA1002
                value.UpdatedFungibleAssets.SelectMany(ua =>
#pragma warning restore LAA1002
                                                       ua.Value.Select(c =>
            {
                FungibleAssetValue b = value.GetBalance(ua.Key, c);
                return(new Bencodex.Types.Dictionary(new[]
                {
                    new KeyValuePair <IKey, IValue>((Text)"address", (Binary)ua.Key.ToByteArray()),
                    new KeyValuePair <IKey, IValue>((Text)"currency", CurrencyExtensions.Serialize(c)),
                    new KeyValuePair <IKey, IValue>((Text)"amount", (Integer)b.RawValue),
                }));
            }
                                                                       )
                                                       ).Cast <IValue>()
                );

            var bdict = new Dictionary(new[]
            {
                new KeyValuePair <IKey, IValue>((Text)"states", state),
                new KeyValuePair <IKey, IValue>((Text)"balances", balance),
            });

            writer.Write(new Codec().Encode(bdict));
        }
Example #2
0
        public override IValue Serialize()
        {
            var values = new Dictionary <IKey, IValue>
            {
                [(Text)"currency"] = CurrencyExtensions.Serialize(Currency)
            };

#pragma warning disable LAA1002
            return(new Dictionary(values.Union((Dictionary)base.Serialize())));

#pragma warning restore LAA1002
        }
Example #3
0
 public static IValue Serialize(this FungibleAssetValue value) =>
 new Bencodex.Types.List(new IValue[]
 {
     CurrencyExtensions.Serialize(value.Currency),
     value.RawValue.Serialize(),
 });