internal static BlockEvent DeserializeBlockEvent(JsonElement element)
        {
            long            sequence        = default;
            BlockIdentifier blockIdentifier = default;
            BlockEventType  type            = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("sequence"))
                {
                    sequence = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("block_identifier"))
                {
                    blockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new BlockEventType(property.Value.GetString());
                    continue;
                }
            }
            return(new BlockEvent(sequence, blockIdentifier, type));
        }
Exemple #2
0
        internal static NetworkStatusResponse DeserializeNetworkStatusResponse(JsonElement element)
        {
            BlockIdentifier            currentBlockIdentifier = default;
            long                       currentBlockTimestamp  = default;
            BlockIdentifier            genesisBlockIdentifier = default;
            Optional <BlockIdentifier> oldestBlockIdentifier  = default;
            Optional <SyncStatus>      syncStatus             = default;
            IReadOnlyList <Peer>       peers = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("current_block_identifier"))
                {
                    currentBlockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("current_block_timestamp"))
                {
                    currentBlockTimestamp = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("genesis_block_identifier"))
                {
                    genesisBlockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("oldest_block_identifier"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    oldestBlockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("sync_status"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    syncStatus = SyncStatus.DeserializeSyncStatus(property.Value);
                    continue;
                }
                if (property.NameEquals("peers"))
                {
                    List <Peer> array = new List <Peer>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(Peer.DeserializePeer(item));
                    }
                    peers = array;
                    continue;
                }
            }
            return(new NetworkStatusResponse(currentBlockIdentifier, currentBlockTimestamp, genesisBlockIdentifier, oldestBlockIdentifier.Value, syncStatus.Value, peers));
        }
Exemple #3
0
 internal Block(BlockIdentifier blockIdentifier, BlockIdentifier parentBlockIdentifier, long timestamp, IReadOnlyList <Transaction> transactions, object metadata)
 {
     BlockIdentifier       = blockIdentifier;
     ParentBlockIdentifier = parentBlockIdentifier;
     Timestamp             = timestamp;
     Transactions          = transactions;
     Metadata = metadata;
 }
Exemple #4
0
 internal NetworkStatusResponse(BlockIdentifier currentBlockIdentifier, long currentBlockTimestamp, BlockIdentifier genesisBlockIdentifier, BlockIdentifier oldestBlockIdentifier, SyncStatus syncStatus, IReadOnlyList <Peer> peers)
 {
     CurrentBlockIdentifier = currentBlockIdentifier;
     CurrentBlockTimestamp  = currentBlockTimestamp;
     GenesisBlockIdentifier = genesisBlockIdentifier;
     OldestBlockIdentifier  = oldestBlockIdentifier;
     SyncStatus             = syncStatus;
     Peers = peers;
 }
        internal BlockEvent(long sequence, BlockIdentifier blockIdentifier, BlockEventType type)
        {
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }

            Sequence        = sequence;
            BlockIdentifier = blockIdentifier;
            Type            = type;
        }
Exemple #6
0
        internal BlockTransaction(BlockIdentifier blockIdentifier, Transaction transaction)
        {
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }
            if (transaction == null)
            {
                throw new ArgumentNullException(nameof(transaction));
            }

            BlockIdentifier = blockIdentifier;
            Transaction     = transaction;
        }
Exemple #7
0
        internal AccountCoinsResponse(BlockIdentifier blockIdentifier, IEnumerable <Coin> coins)
        {
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }
            if (coins == null)
            {
                throw new ArgumentNullException(nameof(coins));
            }

            BlockIdentifier = blockIdentifier;
            Coins           = coins.ToList();
        }
        internal AccountBalanceResponse(BlockIdentifier blockIdentifier, IEnumerable <Amount> balances)
        {
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }
            if (balances == null)
            {
                throw new ArgumentNullException(nameof(balances));
            }

            BlockIdentifier = blockIdentifier;
            Balances        = balances.ToList();
        }
Exemple #9
0
        internal static Block DeserializeBlock(JsonElement element)
        {
            BlockIdentifier             blockIdentifier       = default;
            BlockIdentifier             parentBlockIdentifier = default;
            long                        timestamp             = default;
            IReadOnlyList <Transaction> transactions          = default;
            Optional <object>           metadata = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("block_identifier"))
                {
                    blockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("parent_block_identifier"))
                {
                    parentBlockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("timestamp"))
                {
                    timestamp = property.Value.GetInt64();
                    continue;
                }
                if (property.NameEquals("transactions"))
                {
                    List <Transaction> array = new List <Transaction>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(Transaction.DeserializeTransaction(item));
                    }
                    transactions = array;
                    continue;
                }
                if (property.NameEquals("metadata"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    metadata = property.Value.GetObject();
                    continue;
                }
            }
            return(new Block(blockIdentifier, parentBlockIdentifier, timestamp, transactions, metadata.Value));
        }
        public BlockTransactionRequest(NetworkIdentifier networkIdentifier, BlockIdentifier blockIdentifier, TransactionIdentifier transactionIdentifier)
        {
            if (networkIdentifier == null)
            {
                throw new ArgumentNullException(nameof(networkIdentifier));
            }
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }
            if (transactionIdentifier == null)
            {
                throw new ArgumentNullException(nameof(transactionIdentifier));
            }

            NetworkIdentifier     = networkIdentifier;
            BlockIdentifier       = blockIdentifier;
            TransactionIdentifier = transactionIdentifier;
        }
Exemple #11
0
        internal NetworkStatusResponse(BlockIdentifier currentBlockIdentifier, long currentBlockTimestamp, BlockIdentifier genesisBlockIdentifier, IEnumerable <Peer> peers)
        {
            if (currentBlockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(currentBlockIdentifier));
            }
            if (genesisBlockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(genesisBlockIdentifier));
            }
            if (peers == null)
            {
                throw new ArgumentNullException(nameof(peers));
            }

            CurrentBlockIdentifier = currentBlockIdentifier;
            CurrentBlockTimestamp  = currentBlockTimestamp;
            GenesisBlockIdentifier = genesisBlockIdentifier;
            Peers = peers.ToList();
        }
        internal static BlockTransaction DeserializeBlockTransaction(JsonElement element)
        {
            BlockIdentifier blockIdentifier = default;
            Transaction     transaction     = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("block_identifier"))
                {
                    blockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("transaction"))
                {
                    transaction = Transaction.DeserializeTransaction(property.Value);
                    continue;
                }
            }
            return(new BlockTransaction(blockIdentifier, transaction));
        }
Exemple #13
0
        internal Block(BlockIdentifier blockIdentifier, BlockIdentifier parentBlockIdentifier, long timestamp, IEnumerable <Transaction> transactions)
        {
            if (blockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(blockIdentifier));
            }
            if (parentBlockIdentifier == null)
            {
                throw new ArgumentNullException(nameof(parentBlockIdentifier));
            }
            if (transactions == null)
            {
                throw new ArgumentNullException(nameof(transactions));
            }

            BlockIdentifier       = blockIdentifier;
            ParentBlockIdentifier = parentBlockIdentifier;
            Timestamp             = timestamp;
            Transactions          = transactions.ToList();
        }
Exemple #14
0
        internal static AccountCoinsResponse DeserializeAccountCoinsResponse(JsonElement element)
        {
            BlockIdentifier      blockIdentifier = default;
            IReadOnlyList <Coin> coins           = default;
            Optional <object>    metadata        = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("block_identifier"))
                {
                    blockIdentifier = BlockIdentifier.DeserializeBlockIdentifier(property.Value);
                    continue;
                }
                if (property.NameEquals("coins"))
                {
                    List <Coin> array = new List <Coin>();
                    foreach (var item in property.Value.EnumerateArray())
                    {
                        array.Add(Coin.DeserializeCoin(item));
                    }
                    coins = array;
                    continue;
                }
                if (property.NameEquals("metadata"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    metadata = property.Value.GetObject();
                    continue;
                }
            }
            return(new AccountCoinsResponse(blockIdentifier, coins, metadata.Value));
        }
Exemple #15
0
 internal AccountCoinsResponse(BlockIdentifier blockIdentifier, IReadOnlyList <Coin> coins, object metadata)
 {
     BlockIdentifier = blockIdentifier;
     Coins           = coins;
     Metadata        = metadata;
 }
 internal AccountBalanceResponse(BlockIdentifier blockIdentifier, IReadOnlyList <Amount> balances, object metadata)
 {
     BlockIdentifier = blockIdentifier;
     Balances        = balances;
     Metadata        = metadata;
 }