Exemple #1
0
        public ParseDemocracy()
        {
            var dbCon        = "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password="******"wss://kusama-rpc.polkadot.io/";

            _app = PolkaApi.GetAppication();
            _sch = new MetadataSchema();

            string nodeUrl = substrateCon;

            _app.Connect(nodeUrl);

            // Connect to db and check metadata version
            _postgres = new Postgres(dbCon);
            _indexer  = new Indexer(_app, _postgres);

            // Create or update current schema
            var metadata = _app.GetMetadata(null);

            _sch.ParseMetadata(metadata);
            var si = _app.GetSystemInfo();

            _sch.DatabaseSchema.Title = "Test_ParseBalances";

            _sch.CommitToDb(_postgres, si);

            // Check current schema
            _indexer.CheckSystemInfo();
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  builder =>
                {
                    builder.WithOrigins(ConfigurationManager.AppSettings["ClientUIHost"])
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials();
                });
            });

            MetadataSchema sch = new MetadataSchema();
            var            MetadataBlockHash = ConfigurationManager.AppSettings["MetadataBlockHash"];

            using (IApplication app = PolkaApi.GetAppication())
            {
                app.Connect("wss://kusama-rpc.polkadot.io/", MetadataBlockHash);
                sch.ParseMetadata(app.GetMetadata(null));
                app.Disconnect();
            }

            var rt = File.ReadAllText("runtime.txt");

            var dataReader = new Postgres(ConfigurationManager.ConnectionStrings["Postgres"].ConnectionString);

            services.AddSingleton(sch);
            services.AddSingleton(dataReader);
            services.AddSingleton <IRuntime>(new Runtime(rt));
            services.AddSingleton <IWebApiDataAdapter>(new IndexedWebApi(dataReader, sch));
            services.AddMvc()
            .AddJsonOptions(x =>
            {
                x.SerializerSettings.ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy()
                };
            });
        }