Esempio n. 1
0
        public async Task <IdentityResult> LoginAsync(HttpContext httpContext, NexusNodeEndpoint nodeEndpoint, bool isPersistent = false, CancellationToken token = default)
        {
            if (httpContext.User.Identity.IsAuthenticated)
            {
                return(IdentityResult.Failed(new IdentityError {
                    Description = "Already signed in"
                }));
            }

            var nexusNode = new NexusNode((INexusClient)httpContext.RequestServices.GetService(typeof(INexusClient)), nodeEndpoint);
            var response  = await nexusNode.Client.GetAsync("ledger/mininginfo", "Connection attempt", null, token, true);

            if (!response.IsSuccessStatusCode)
            {
                return(IdentityResult.Failed(new IdentityError {
                    Description = "Unable to connect to node endpoint"
                }));
            }

            var claims = new List <Claim> {
                new Claim(_cookeConstants.NodeIdClaimType, nodeEndpoint.Name)
            };
            var identity  = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
            var principal = new ClaimsPrincipal(identity);

            await httpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

            return(IdentityResult.Success);
        }
Esempio n. 2
0
        public NexusNode(INexusClient nexusClient, NexusNodeEndpoint endpoint)
        {
            Client   = nexusClient;
            Endpoint = endpoint;

            Client.ConfigureHttpClient(endpoint);
        }
Esempio n. 3
0
        public T Get <T>(NexusNodeEndpoint nodeEndpoint) where T : NexusService
        {
            var nexusNode = new NexusNode(_serviceProvider.GetService <INexusClient>(), nodeEndpoint);

            var service = Activator.CreateInstance(typeof(T), nexusNode, _serviceProvider.GetService <ILogger <NexusService> >());

            return((T)service);
        }
Esempio n. 4
0
        public async Task CreateAsync(NexusNodeEndpoint nodeEndpoint)
        {
            if (nodeEndpoint == null)
            {
                throw new ArgumentException("Node endpoint data is missing");
            }

            await _repository.CreateNodeAsync(nodeEndpoint);
        }
Esempio n. 5
0
        public async Task <BlockNotifyJob> CreateBlockNotifyJobAsync(NexusNodeEndpoint endpoint, TimeSpan interval, Func <Block, Task> onNotify, CancellationToken token = default)
        {
            var job = new BlockNotifyJob(
                _loggerFactory.CreateLogger <BlockNotifyJob>(),
                _serviceFactory.Get <LedgerService>(endpoint),
                onNotify);

            await job.StartAsync(interval, token);

            return(job);
        }
Esempio n. 6
0
 public Task CreateNodeAsync(NexusNodeEndpoint endpoint)
 {
     return(_repository.CreateAsync(endpoint));
 }