Example #1
0
        public Task <IReadOnlyList <(RpcNep17Balance balance, Nep17Contract contract)> > ListBalancesAsync(UInt160 address)
        {
            try
            {
                if (disposedValue)
                {
                    return(Task.FromException <IReadOnlyList <(RpcNep17Balance, Nep17Contract)> >(new ObjectDisposedException(nameof(OfflineNode))));
                }

                var contractMap = ExpressRpcServer.GetNep17Contracts(neoSystem, rocksDbStorageProvider).ToDictionary(c => c.ScriptHash);
                var results     = ExpressRpcServer.GetNep17Balances(neoSystem, rocksDbStorageProvider, address)
                                  .Select(b => (
                                              balance: new RpcNep17Balance
                {
                    Amount = b.balance,
                    AssetHash = b.contract.ScriptHash,
                    LastUpdatedBlock = b.lastUpdatedBlock
                },
                                              contract: contractMap.TryGetValue(b.contract.ScriptHash, out var value)
                            ? value
                            : Nep17Contract.Unknown(b.contract.ScriptHash)));

                return(Task.FromResult <IReadOnlyList <(RpcNep17Balance, Nep17Contract)> >(results.ToArray()));
            }
            catch (Exception ex)
            {
                return(Task.FromException <IReadOnlyList <(RpcNep17Balance, Nep17Contract)> >(ex));
            }
        }
Example #2
0
        public Task <IReadOnlyList <Nep17Contract> > ListNep17ContractsAsync()
        {
            try
            {
                if (disposedValue)
                {
                    return(Task.FromException <IReadOnlyList <Nep17Contract> >(new ObjectDisposedException(nameof(OfflineNode))));
                }

                var contracts = ExpressRpcServer.GetNep17Contracts(neoSystem, rocksDbStorageProvider);

                return(Task.FromResult <IReadOnlyList <Nep17Contract> >(contracts.ToArray()));
            }
            catch (Exception ex)
            {
                return(Task.FromException <IReadOnlyList <Nep17Contract> >(ex));
            }
        }