/// <summary> /// Creates <see cref="BlockDigest"/> instance from /// <see cref="Bencodex.Types.Dictionary"/> representation of the <see cref="Block{T}"/>. /// </summary> /// <param name="dict"> /// <see cref="Bencodex.Types.Dictionary"/> representation of the <see cref="Block{T}"/>. /// </param> public BlockDigest(Bencodex.Types.Dictionary dict) { Header = new BlockHeader(dict.GetValue <Bencodex.Types.Dictionary>(HeaderKey)); TxIds = dict.ContainsKey((Binary)TransactionIdsKey) ? dict.GetValue <Bencodex.Types.List>(TransactionIdsKey) .Select(txId => ((Binary)txId).ToImmutableArray()).ToImmutableArray() : ImmutableArray <ImmutableArray <byte> > .Empty; }
public BlockDigest(Bencodex.Types.Dictionary dict) { var headerDict = dict.GetValue <Bencodex.Types.Dictionary>(HeaderKey); var tuple = BlockMarshaler.UnmarshalPreEvaluationBlockHeader(headerDict); _metadata = tuple.Metadata; _nonce = tuple.Nonce; _preEvaluationHash = tuple.PreEvaluationHash; StateRootHash = BlockMarshaler.UnmarshalBlockHeaderStateRootHash(headerDict); Signature = BlockMarshaler.UnmarshalBlockHeaderSignature(headerDict); Hash = BlockMarshaler.UnmarshalBlockHeaderHash(headerDict); TxIds = dict.ContainsKey((IKey)(Binary)TransactionIdsKey) ? dict.GetValue <Bencodex.Types.List>(TransactionIdsKey) .Select(txId => ((Binary)txId).ToImmutableArray()).ToImmutableArray() : ImmutableArray <ImmutableArray <byte> > .Empty; }
public RawTransaction(Bencodex.Types.Dictionary dict) { Nonce = dict.GetValue <Integer>(NonceKey); Signer = dict.GetValue <Binary>(SignerKey).ToImmutableArray(); GenesisHash = dict.ContainsKey((IKey)(Binary)GenesisHashKey) ? dict.GetValue <Binary>(GenesisHashKey).ToImmutableArray() : ImmutableArray <byte> .Empty; UpdatedAddresses = dict.GetValue <Bencodex.Types.List>(UpdatedAddressesKey) .Select(value => ((Binary)value).ToImmutableArray()).ToImmutableArray(); PublicKey = dict.GetValue <Binary>(PublicKeyKey).ToImmutableArray(); Timestamp = dict.GetValue <Text>(TimestampKey); Actions = dict.GetValue <Bencodex.Types.List>(ActionsKey).ToImmutableArray(); Signature = dict.ContainsKey((IKey)(Binary)SignatureKey) ? dict.GetValue <Binary>(SignatureKey).ToImmutableArray() : ImmutableArray <byte> .Empty; }
public RawTransaction(Bencodex.Types.Dictionary dict) { Nonce = dict.GetValue <Integer>(NonceKey); Signer = ((byte[])dict.GetValue <Binary>(SignerKey)).ToImmutableArray(); UpdatedAddresses = To2dArray( (byte[])dict.GetValue <Binary>(UpdatedAddressesKey), Address.Size); PublicKey = ((byte[])dict.GetValue <Binary>(PublicKeyKey)).ToImmutableArray(); Timestamp = dict.GetValue <Text>(TimestampKey); Actions = dict.GetValue <Bencodex.Types.List>(ActionsKey); Signature = dict.ContainsKey((Binary)SignatureKey) ? ((byte[])dict.GetValue <Binary>(SignatureKey)).ToImmutableArray() : ImmutableArray <byte> .Empty; }
public BlockHeader(Bencodex.Types.Dictionary dict) { Index = dict.GetValue <Integer>(IndexKey); Timestamp = dict.GetValue <Text>(TimestampKey); Difficulty = dict.GetValue <Integer>(DifficultyKey); TotalDifficulty = dict.GetValue <Integer>(TotalDifficultyKey); Nonce = dict.GetValue <Binary>(NonceKey).ToImmutableArray(); Miner = dict.ContainsKey((IKey)(Binary)MinerKey) ? dict.GetValue <Binary>(MinerKey).ToImmutableArray() : ImmutableArray <byte> .Empty; PreviousHash = dict.ContainsKey((IKey)(Binary)PreviousHashKey) ? dict.GetValue <Binary>(PreviousHashKey).ToImmutableArray() : ImmutableArray <byte> .Empty; TxHash = dict.ContainsKey((IKey)(Binary)TxHashKey) ? dict.GetValue <Binary>(TxHashKey).ToImmutableArray() : ImmutableArray <byte> .Empty; Hash = dict.ContainsKey((IKey)(Binary)HashKey) ? dict.GetValue <Binary>(HashKey).ToImmutableArray() : ImmutableArray <byte> .Empty; }
public RawBlock(Bencodex.Types.Dictionary dict) { Index = dict.GetValue <Integer>(IndexKey); Timestamp = dict.GetValue <Text>(TimestampKey); Difficulty = dict.GetValue <Integer>(DifficultyKey); Transactions = dict.GetValue <Bencodex.Types.List>(TransactionsKey) .Select(tx => (byte[])(Binary)tx); Nonce = dict.GetValue <Binary>(NonceKey); Miner = dict.ContainsKey((Binary)RewardBeneficiaryKey) ? dict.GetValue <Binary>(RewardBeneficiaryKey) : null; PreviousHash = dict.ContainsKey((Binary)PreviousHashKey) ? (byte[])dict.GetValue <Binary>(PreviousHashKey) : null; Hash = dict.ContainsKey((Binary)HashKey) ? (byte[])dict.GetValue <Binary>(HashKey) : null; }
public static BattleResult FromBencodex(Bencodex.Types.Dictionary dictionary) { return(new BattleResult( dictionary.GetValue <List>("used_weapons").Select(x => ((Text)x).Value), dictionary.GetValue <List>("targets").Select(x => ((Text)x).Value))); }
public void LoadPlainValue(Bencodex.Types.Dictionary plainValue) { TargetAddress = new Address(plainValue.GetValue <Binary>("target_address")); }
public void LoadPlainValue(Bencodex.Types.Dictionary plainValue) { Weapon = (Text)plainValue["weapon"]; Target = (Text)plainValue["target"]; TargetAddress = new Address(plainValue.GetValue <Binary>("target_address")); }