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)); }
private void DeterministicWhenSerializationWithAddress(int caseIndex) { Bencodex.Types.List targetList = Bencodex.Types.List.Empty; switch (caseIndex) { case 0: targetList = _addressList; break; case 1: targetList = _descendingAddressList; break; } var deserializedList = targetList.ToList(element => element.ToAddress()); var newList = (Bencodex.Types.List)deserializedList .Select(element => element.Serialize()) .Serialize(); Assert.Equal(targetList.Count, deserializedList.Count); Assert.Equal(targetList.Count, newList.Count); for (var i = 0; i < targetList.Count; i++) { Assert.Equal(targetList[i].ToAddress(), deserializedList[i]); Assert.Equal(targetList[i], newList[i]); } }
public Bencodex.Types.Dictionary ToBencodex() { var transactions = new Bencodex.Types.List( Transactions.Select(tx => (IValue)(Binary)tx)); var dict = Bencodex.Types.Dictionary.Empty .Add(IndexKey, Index) .Add(TimestampKey, Timestamp) .Add(DifficultyKey, Difficulty) .Add(TransactionsKey, (IValue)transactions) .Add(NonceKey, Nonce); if (!(Miner is null)) { dict = dict.Add(RewardBeneficiaryKey, Miner); } if (!(PreviousHash is null)) { dict = dict.Add(PreviousHashKey, PreviousHash); } if (!(Hash is null)) { dict = dict.Add(HashKey, Hash.ToArray()); } return(dict); }
public Inventory(Bencodex.Types.List serialized) : this() { _items.Capacity = serialized.Value.Length; foreach (IValue item in serialized) { _items.Add(new Item((Bencodex.Types.Dictionary)item)); } }
public Bencodex.Types.Dictionary ToBencodex() { var dict = Bencodex.Types.Dictionary.Empty .Add(HeaderKey, Header.ToBencodex()); if (Transactions.Any()) { var transactions = new Bencodex.Types.List( Transactions.Select(tx => (IValue)(Binary)tx.ToArray())); dict = dict.Add(TransactionsKey, (IValue)transactions); } return(dict); }
public BencodexTypesListTest() { _integerList = new Bencodex.Types.List(new List <IValue> { 1.Serialize(), 2.Serialize(), 3.Serialize(), }); _descendingIntegerList = (Bencodex.Types.List)_integerList .OrderByDescending(element => element.ToInteger()) .Serialize(); _addressList = new Bencodex.Types.List(new List <IValue> { new PrivateKey().ToAddress().Serialize(), new PrivateKey().ToAddress().Serialize(), new PrivateKey().ToAddress().Serialize(), }); _descendingAddressList = (Bencodex.Types.List)_addressList .OrderByDescending(element => element.ToAddress()) .Serialize(); }
public InitializeStates( RankingState0 rankingState, ShopState shopState, Dictionary <string, string> tableSheets, GameConfigState gameConfigState, RedeemCodeState redeemCodeState, AdminState adminAddressState, ActivatedAccountsState activatedAccountsState, GoldCurrencyState goldCurrencyState, GoldDistribution[] goldDistributions, PendingActivationState[] pendingActivationStates, AuthorizedMinersState authorizedMinersState = null, CreditsState creditsState = null) { Ranking = (Bencodex.Types.Dictionary)rankingState.Serialize(); Shop = (Bencodex.Types.Dictionary)shopState.Serialize(); TableSheets = tableSheets; GameConfig = (Bencodex.Types.Dictionary)gameConfigState.Serialize(); RedeemCode = (Bencodex.Types.Dictionary)redeemCodeState.Serialize(); AdminAddress = (Bencodex.Types.Dictionary)adminAddressState.Serialize(); ActivatedAccounts = (Bencodex.Types.Dictionary)activatedAccountsState.Serialize(); GoldCurrency = (Bencodex.Types.Dictionary)goldCurrencyState.Serialize(); GoldDistributions = new Bencodex.Types.List( goldDistributions.Select(d => d.Serialize()).Cast <Bencodex.Types.IValue>() ); PendingActivations = new Bencodex.Types.List(pendingActivationStates.Select(p => p.Serialize())); if (!(authorizedMinersState is null)) { AuthorizedMiners = (Bencodex.Types.Dictionary)authorizedMinersState.Serialize(); } if (!(creditsState is null)) { Credits = (Bencodex.Types.Dictionary)creditsState.Serialize(); } }
private IEnumerable <TreeViewItem> AsTreeViewItems(Bencodex.Types.List list) { return(list.Select(AsTreeViewItem)); }