Example #1
0
        public static IHostBuilder UseNineChroniclesNode(
            this IHostBuilder builder,
            NineChroniclesNodeServiceProperties properties,
            StandaloneContext context
            )
        {
            NineChroniclesNodeService service =
                NineChroniclesNodeService.Create(properties, context);
            var rpcContext = new RpcContext
            {
                RpcRemoteSever = false
            };

            return(builder.ConfigureServices(services =>
            {
                services.AddHostedService(provider => service);
                services.AddSingleton(provider => service);
                services.AddSingleton(provider => service.Swarm);
                services.AddSingleton(provider => service.BlockChain);
                services.AddSingleton(provider => properties.Libplanet);
                services.AddSingleton(provider =>
                {
                    return new ActionEvaluationPublisher(
                        context.NineChroniclesNodeService !.BlockRenderer,
                        context.NineChroniclesNodeService !.ActionRenderer,
                        context.NineChroniclesNodeService !.ExceptionRenderer,
                        context.NineChroniclesNodeService !.NodeStatusRenderer,
                        IPAddress.Loopback.ToString(),
                        0,
                        rpcContext
                        );
                });
            }));
        }
Example #2
0
        public static NineChroniclesNodeService CreateHeadless(
            NineChroniclesNodeServiceProperties properties,
            StandaloneContext standaloneContext = null,
            bool ignoreBootstrapFailure         = true,
            bool strictRendering = false,
            bool isDev           = false,
            int blockInterval    = 10000,
            int reorgInterval    = 0
            )
        {
            Progress <PreloadState> progress = null;

            if (!(standaloneContext is null))
            {
                progress = new Progress <PreloadState>(state =>
                {
                    standaloneContext.PreloadStateSubject.OnNext(state);
                });
            }

            properties.Libplanet.DifferentAppProtocolVersionEncountered =
                (Peer peer, AppProtocolVersion peerVersion, AppProtocolVersion localVersion) =>
            {
                standaloneContext.DifferentAppProtocolVersionEncounterSubject.OnNext(
                    new DifferentAppProtocolVersionEncounter
                {
                    Peer         = peer,
                    PeerVersion  = peerVersion,
                    LocalVersion = localVersion,
                }
                    );

                // FIXME: 일단은 버전이 다른 피어는 마주쳐도 쌩깐다.
                return(false);
            };

            properties.Libplanet.NodeExceptionOccurred =
                (code, message) =>
            {
                standaloneContext.NodeExceptionSubject.OnNext(
                    new NodeException(code, message)
                    );
            };

            var service = new NineChroniclesNodeService(
                properties.Libplanet,
                properties.Rpc,
                preloadProgress: progress,
                ignoreBootstrapFailure: ignoreBootstrapFailure,
                strictRendering: strictRendering,
                isDev: isDev,
                blockInterval: blockInterval,
                reorgInterval: reorgInterval);

            service.ConfigureStandaloneContext(standaloneContext);

            return(service);
        }
Example #3
0
        public static IHostBuilder UseNineChroniclesNode(
            this IHostBuilder builder,
            NineChroniclesNodeServiceProperties properties,
            StandaloneContext context
            )
        {
            NineChroniclesNodeService service =
                NineChroniclesNodeService.Create(properties, context);

            return(builder.ConfigureServices(services =>
            {
                services.AddHostedService(provider => service);
                services.AddSingleton(provider => service);
                services.AddSingleton(provider => service.Swarm);
                services.AddSingleton(provider => service.BlockChain);
                services.AddSingleton(provider => properties.Libplanet);
            }));
        }
Example #4
0
 internal static void ConfigureStandaloneContext(this NineChroniclesNodeService service, StandaloneContext standaloneContext)
 {
     if (!(standaloneContext is null))
     {
         standaloneContext.BlockChain = service.Swarm.BlockChain;
         standaloneContext.Store      = service.Store;
         service.BootstrapEnded.WaitAsync().ContinueWith((task) =>
         {
             standaloneContext.BootstrapEnded = true;
             standaloneContext.NodeStatusSubject.OnNext(standaloneContext.NodeStatus);
         });
         service.PreloadEnded.WaitAsync().ContinueWith((task) =>
         {
             standaloneContext.PreloadEnded = true;
             standaloneContext.NodeStatusSubject.OnNext(standaloneContext.NodeStatus);
         });
     }
 }
        public static NineChroniclesNodeService Create(
            NineChroniclesNodeServiceProperties properties,
            StandaloneContext context
            )
        {
            if (context is null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Progress <PreloadState> progress = new Progress <PreloadState>(state =>
            {
                context.PreloadStateSubject.OnNext(state);
            });

            if (properties.Libplanet is null)
            {
                throw new InvalidOperationException($"{nameof(properties.Libplanet)} is null.");
            }

            properties.Libplanet.DifferentAppProtocolVersionEncountered =
                (Peer peer, AppProtocolVersion peerVersion, AppProtocolVersion localVersion) =>
            {
                context.DifferentAppProtocolVersionEncounterSubject.OnNext(
                    new DifferentAppProtocolVersionEncounter(peer, peerVersion, localVersion)
                    );

                // FIXME: 일단은 버전이 다른 피어는 마주쳐도 쌩깐다.
                return(false);
            };

            properties.Libplanet.NodeExceptionOccurred =
                (code, message) =>
            {
                context.NodeExceptionSubject.OnNext(
                    new NodeException(code, message)
                    );
            };

            var blockPolicy = NineChroniclesNodeService.GetBlockPolicy(properties.NetworkType);
            var service     = new NineChroniclesNodeService(
                properties.MinerPrivateKey,
                properties.Libplanet,
                blockPolicy,
                properties.NetworkType,
                preloadProgress: progress,
                ignoreBootstrapFailure: properties.IgnoreBootstrapFailure,
                ignorePreloadFailure: properties.IgnorePreloadFailure,
                strictRendering: properties.StrictRender,
                isDev: properties.Dev,
                blockInterval: properties.BlockInterval,
                reorgInterval: properties.ReorgInterval,
                authorizedMiner: properties.AuthorizedMiner,
                txLifeTime: properties.TxLifeTime,
                minerCount: properties.MinerCount,
                txQuotaPerSigner: properties.TxQuotaPerSigner
                );

            service.ConfigureContext(context);
            return(service);
        }