├── .here ├── R ├── _disable_autoload.R ├── xmrconsensus-package.R ├── utils_rpc.R ├── run_app.R ├── app_config.R ├── fct_pools_collect.R ├── fct_pool_blocks.R ├── fct_alt_chains.R ├── app_ui.R └── app_server.R ├── inst ├── app │ └── www │ │ └── favicon.ico └── golem-config.yml ├── data-raw ├── pools │ └── .gitignore └── .gitignore ├── tests ├── spelling.R ├── testthat.R └── testthat │ └── test-golem-recommended.R ├── .rscignore ├── dev ├── config_attachment.yaml ├── run_dev.R ├── 03_deploy.R ├── 02_dev.R └── 01_start.R ├── .Rbuildignore ├── app.R ├── NAMESPACE ├── man ├── xmrconsensus-package.Rd ├── pools.collect.Rd └── run_app.Rd ├── DESCRIPTION ├── .gitignore ├── README.md ├── README.Rmd └── LICENSE.md /.here: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /R/_disable_autoload.R: -------------------------------------------------------------------------------- 1 | # Disabling shiny autoload 2 | 3 | # See ?shiny::loadSupport for more information 4 | -------------------------------------------------------------------------------- /inst/app/www/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rucknium/xmrconsensus/HEAD/inst/app/www/favicon.ico -------------------------------------------------------------------------------- /data-raw/pools/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if(requireNamespace('spelling', quietly = TRUE)) 2 | spelling::spell_check_test(vignettes = TRUE, error = FALSE, 3 | skip_on_cran = TRUE) 4 | -------------------------------------------------------------------------------- /inst/golem-config.yml: -------------------------------------------------------------------------------- 1 | default: 2 | golem_name: xmrconsensus 3 | golem_version: 0.0.1 4 | app_prod: no 5 | production: 6 | app_prod: yes 7 | dev: 8 | golem_wd: !expr golem::pkg_path() 9 | -------------------------------------------------------------------------------- /.rscignore: -------------------------------------------------------------------------------- 1 | .here 2 | CODE_OF_CONDUCT.md 3 | LICENSE 4 | LICENCE 5 | LICENSE.md 6 | LICENCE.md 7 | NEWS 8 | NEWS.md 9 | README.md 10 | README.Rmd 11 | README.HTML 12 | dev 13 | man 14 | vignettes 15 | tests 16 | -------------------------------------------------------------------------------- /dev/config_attachment.yaml: -------------------------------------------------------------------------------- 1 | path.n: NAMESPACE 2 | path.d: DESCRIPTION 3 | dir.r: R 4 | dir.v: vignettes 5 | dir.t: tests 6 | extra.suggests: ~ 7 | pkg_ignore: ~ 8 | document: yes 9 | normalize: yes 10 | inside_rmd: no 11 | must.exist: yes 12 | check_if_suggests_is_installed: yes 13 | -------------------------------------------------------------------------------- /data-raw/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in this directory 2 | * 3 | # Except this file 4 | !.gitignore 5 | # And the directories 6 | !*/ 7 | # https://stackoverflow.com/questions/115983/how-do-i-add-an-empty-directory-to-a-git-repository 8 | # https://jasonstitt.com/gitignore-whitelisting-patterns 9 | -------------------------------------------------------------------------------- /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^data-raw$ 4 | dev_history.R 5 | ^dev$ 6 | $run_dev.* 7 | ^.here$ 8 | ^LICENSE\.md$ 9 | ^README\.Rmd$ 10 | ^src/\.cargo$ 11 | ^src/rust/vendor$ 12 | ^src/rust/target$ 13 | ^src/Makevars$ 14 | ^src/Makevars\.win$ 15 | ^app\.R$ 16 | ^rsconnect$ 17 | ^\.rscignore$ 18 | 19 | -------------------------------------------------------------------------------- /app.R: -------------------------------------------------------------------------------- 1 | # Launch the ShinyApp (Do not remove this comment) 2 | # To deploy, run: rsconnect::deployApp() 3 | # Or use the blue button on top of this file 4 | 5 | pkgload::load_all(export_all = FALSE,helpers = FALSE,attach_testthat = FALSE) 6 | options( "golem.app.prod" = TRUE) 7 | xmrconsensus::run_app() # add parameters here (if any) 8 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(xmrconsensus) 11 | 12 | test_check("xmrconsensus") 13 | -------------------------------------------------------------------------------- /dev/run_dev.R: -------------------------------------------------------------------------------- 1 | # Set options here 2 | options(golem.app.prod = FALSE) # TRUE = production mode, FALSE = development mode 3 | 4 | # Comment this if you don't want the app to be served on a random port 5 | options(shiny.port = httpuv::randomPort()) 6 | 7 | # Detach all loaded packages and clean your environment 8 | golem::detach_all_attached() 9 | # rm(list=ls(all.names = TRUE)) 10 | 11 | # Document and reload your package 12 | golem::document_and_reload() 13 | 14 | # Run the application 15 | run_app() 16 | -------------------------------------------------------------------------------- /R/xmrconsensus-package.R: -------------------------------------------------------------------------------- 1 | #' @keywords internal 2 | "_PACKAGE" 3 | 4 | ## usethis namespace: start 5 | #' @importFrom data.table := 6 | #' @importFrom data.table .BY 7 | #' @importFrom data.table .EACHI 8 | #' @importFrom data.table .GRP 9 | #' @importFrom data.table .I 10 | #' @importFrom data.table .N 11 | #' @importFrom data.table .NGRP 12 | #' @importFrom data.table .SD 13 | #' @importFrom data.table data.table 14 | #' @importFrom graphics grconvertY 15 | #' @importFrom graphics legend 16 | #' @importFrom graphics lines 17 | #' @importFrom graphics par 18 | #' @importFrom graphics rect 19 | ## usethis namespace: end 20 | NULL 21 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export(pools.collect) 4 | export(run_app) 5 | import(shiny) 6 | importFrom(data.table,":=") 7 | importFrom(data.table,.BY) 8 | importFrom(data.table,.EACHI) 9 | importFrom(data.table,.GRP) 10 | importFrom(data.table,.I) 11 | importFrom(data.table,.N) 12 | importFrom(data.table,.NGRP) 13 | importFrom(data.table,.SD) 14 | importFrom(data.table,data.table) 15 | importFrom(golem,activate_js) 16 | importFrom(golem,add_resource_path) 17 | importFrom(golem,bundle_resources) 18 | importFrom(golem,favicon) 19 | importFrom(golem,with_golem_options) 20 | importFrom(graphics,grconvertY) 21 | importFrom(graphics,legend) 22 | importFrom(graphics,lines) 23 | importFrom(graphics,par) 24 | importFrom(graphics,rect) 25 | importFrom(shiny,shinyApp) 26 | -------------------------------------------------------------------------------- /R/utils_rpc.R: -------------------------------------------------------------------------------- 1 | #' rpc 2 | #' 3 | #' @description A utils function 4 | #' 5 | #' @return The return value, if any, from executing the utility. 6 | #' 7 | #' @noRd 8 | rpc.req <- function(unrestricted.rpc.url, method, params = "", handle = RCurl::getCurlHandle()) { 9 | 10 | json.post <- RJSONIO::toJSON( 11 | list( 12 | jsonrpc = "2.0", 13 | id = "0", 14 | method = method, 15 | params = params 16 | ) 17 | ) 18 | 19 | RJSONIO::fromJSON( 20 | RCurl::postForm(paste0(unrestricted.rpc.url, "/json_rpc"), 21 | .opts = list( 22 | userpwd = "", 23 | postfields = json.post, 24 | httpheader = c('Content-Type' = 'application/json', Accept = 'application/json') 25 | ), 26 | curl = handle 27 | ), asText = TRUE 28 | ) 29 | 30 | } 31 | -------------------------------------------------------------------------------- /man/xmrconsensus-package.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/xmrconsensus-package.R 3 | \docType{package} 4 | \name{xmrconsensus-package} 5 | \alias{xmrconsensus} 6 | \alias{xmrconsensus-package} 7 | \title{xmrconsensus: Shiny App about Monero blockchain consensus live status} 8 | \description{ 9 | Shiny App about Monero blockchain consensus live status. 10 | } 11 | \seealso{ 12 | Useful links: 13 | \itemize{ 14 | \item \url{https://github.com/Rucknium/xmrconsensus} 15 | \item Report bugs at \url{https://github.com/Rucknium/xmrconsensus/issues} 16 | } 17 | 18 | } 19 | \author{ 20 | \strong{Maintainer}: Rucknium \email{Rucknium@protonmail.com} (\href{https://orcid.org/0000-0001-5999-8950}{ORCID}) [copyright holder] 21 | 22 | } 23 | \keyword{internal} 24 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: xmrconsensus 2 | Title: Shiny App about Monero blockchain consensus live status 3 | Version: 0.0.1 4 | Authors@R: 5 | c(person(family = "Rucknium", 6 | role = c("cre", "aut", "cph"), 7 | email = "Rucknium@protonmail.com", 8 | comment = c(ORCID = "0000-0001-5999-8950")) 9 | ) 10 | Description: Shiny App about Monero blockchain consensus live status. 11 | License: AGPL (>= 3) 12 | URL: https://github.com/Rucknium/xmrconsensus 13 | BugReports: https://github.com/Rucknium/xmrconsensus/issues 14 | Imports: 15 | bslib, 16 | config, 17 | data.table, 18 | golem, 19 | igraph, 20 | pkgload, 21 | plotly, 22 | RCurl, 23 | RJSONIO, 24 | shiny 25 | Suggests: 26 | spelling, 27 | testthat (>= 3.0.0) 28 | Config/testthat/edition: 3 29 | Encoding: UTF-8 30 | Language: en-US 31 | LazyData: true 32 | Roxygen: list(markdown = TRUE) 33 | RoxygenNote: 7.3.2 34 | -------------------------------------------------------------------------------- /R/run_app.R: -------------------------------------------------------------------------------- 1 | #' Run the Shiny Application 2 | #' 3 | #' @param ... arguments to pass to golem_opts. 4 | #' See `?golem::get_golem_options` for more details. 5 | #' @inheritParams shiny::shinyApp 6 | #' 7 | #' @export 8 | #' @importFrom shiny shinyApp 9 | #' @importFrom golem with_golem_options 10 | run_app <- function( 11 | onStart = NULL, 12 | options = list(), 13 | enableBookmarking = NULL, 14 | uiPattern = "/", 15 | unrestricted.rpc.url = "http://127.0.0.1:18081", 16 | mining.pool.data.available = TRUE, 17 | ... 18 | ) { 19 | with_golem_options( 20 | app = shinyApp( 21 | ui = app_ui, 22 | server = app_server, 23 | onStart = onStart, 24 | options = options, 25 | enableBookmarking = enableBookmarking, 26 | uiPattern = uiPattern 27 | ), 28 | golem_opts = c(list(unrestricted.rpc.url = unrestricted.rpc.url), 29 | mining.pool.data.available = mining.pool.data.available, 30 | list(...)) 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.tws 3 | .DS_Store 4 | .quarto 5 | inst/bin/* 6 | cache_dir 7 | *.pid 8 | 9 | # R gitignore template from https://github.com/github/gitignore/blob/master/R.gitignore 10 | # And added *.Rproj 11 | 12 | # History files 13 | .Rhistory 14 | .Rapp.history 15 | 16 | # Session Data files 17 | .RData 18 | .RDataTmp 19 | 20 | # User-specific files 21 | .Ruserdata 22 | 23 | # Example code in package build process 24 | *-Ex.R 25 | 26 | # Output files from R CMD build 27 | /*.tar.gz 28 | 29 | # Output files from R CMD check 30 | /*.Rcheck/ 31 | 32 | # RStudio files 33 | .Rproj.user/ 34 | *.Rproj 35 | 36 | # produced vignettes 37 | vignettes/*.html 38 | vignettes/*.pdf 39 | 40 | # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 41 | .httr-oauth 42 | 43 | # knitr and R markdown default cache directories 44 | *_cache/ 45 | /cache/ 46 | 47 | # Temporary files created by R markdown 48 | *.utf8.md 49 | *.knit.md 50 | 51 | # R Environment Variables 52 | .Renviron 53 | 54 | # pkgdown site 55 | docs/ 56 | 57 | # translation temp files 58 | po/*~ 59 | 60 | # RStudio Connect folder 61 | rsconnect/ 62 | 63 | docs 64 | src/rust/vendor 65 | src/Makevars 66 | src/Makevars.win 67 | -------------------------------------------------------------------------------- /R/app_config.R: -------------------------------------------------------------------------------- 1 | #' Access files in the current app 2 | #' 3 | #' NOTE: If you manually change your package name in the DESCRIPTION, 4 | #' don't forget to change it here too, and in the config file. 5 | #' For a safer name change mechanism, use the `golem::set_golem_name()` function. 6 | #' 7 | #' @param ... character vectors, specifying subdirectory and file(s) 8 | #' within your package. The default, none, returns the root of the app. 9 | #' 10 | #' @noRd 11 | app_sys <- function(...) { 12 | system.file(..., package = "xmrconsensus") 13 | } 14 | 15 | 16 | #' Read App Config 17 | #' 18 | #' @param value Value to retrieve from the config file. 19 | #' @param config GOLEM_CONFIG_ACTIVE value. If unset, R_CONFIG_ACTIVE. 20 | #' If unset, "default". 21 | #' @param use_parent Logical, scan the parent directory for config file. 22 | #' @param file Location of the config file 23 | #' 24 | #' @noRd 25 | get_golem_config <- function( 26 | value, 27 | config = Sys.getenv( 28 | "GOLEM_CONFIG_ACTIVE", 29 | Sys.getenv( 30 | "R_CONFIG_ACTIVE", 31 | "default" 32 | ) 33 | ), 34 | use_parent = TRUE, 35 | # Modify this if your config file is somewhere else 36 | file = app_sys("golem-config.yml") 37 | ) { 38 | config::get( 39 | value = value, 40 | config = config, 41 | file = file, 42 | use_parent = use_parent 43 | ) 44 | } 45 | -------------------------------------------------------------------------------- /man/pools.collect.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/fct_pools_collect.R 3 | \name{pools.collect} 4 | \alias{pools.collect} 5 | \title{Collect claimed blocks from mining pools' APIs} 6 | \usage{ 7 | pools.collect( 8 | unrestricted.rpc.url = "http://127.0.0.1:18081", 9 | init.blocks = 720 * 7, 10 | recent.blocks = 720, 11 | poll.time = 60 12 | ) 13 | } 14 | \arguments{ 15 | \item{unrestricted.rpc.url}{URL and port of the \code{monerod} unrestricted RPC. 16 | Default is \verb{⁠http://127.0.0.1:18081}} 17 | 18 | \item{init.blocks}{Number of recent blocks to collect on initiation.} 19 | 20 | \item{recent.blocks}{Number of recent blocks to collect while running 21 | continuously.} 22 | 23 | \item{poll.time}{Time interval, in seconds, between each API request.} 24 | } 25 | \value{ 26 | NULL (invisible) 27 | } 28 | \description{ 29 | Uses the \code{monero-blocks} tool to continuously collect data from mining 30 | pools' APIs about which Monero blocks they have claimed to mine. Data is 31 | written to a CSV file named \code{blocks.csv}. 32 | 33 | The \code{monero-blocks} Go program must be built in a 'monero-blocks' 34 | local working directory. Available at 35 | \url{https://git.gammaspectra.live/WeebDataHoarder/monero-blocks} 36 | 37 | This function is an infinite loop. Input \code{ctrl + c} to interrupt. 38 | } 39 | \examples{ 40 | \dontrun{ 41 | pools.collect() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /man/run_app.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/run_app.R 3 | \name{run_app} 4 | \alias{run_app} 5 | \title{Run the Shiny Application} 6 | \usage{ 7 | run_app( 8 | onStart = NULL, 9 | options = list(), 10 | enableBookmarking = NULL, 11 | uiPattern = "/", 12 | unrestricted.rpc.url = "http://127.0.0.1:18081", 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{onStart}{A function that will be called before the app is actually run. 18 | This is only needed for \code{shinyAppObj}, since in the \code{shinyAppDir} 19 | case, a \code{global.R} file can be used for this purpose.} 20 | 21 | \item{options}{Named options that should be passed to the \code{runApp} call 22 | (these can be any of the following: "port", "launch.browser", "host", "quiet", 23 | "display.mode" and "test.mode"). You can also specify \code{width} and 24 | \code{height} parameters which provide a hint to the embedding environment 25 | about the ideal height/width for the app.} 26 | 27 | \item{enableBookmarking}{Can be one of \code{"url"}, \code{"server"}, or 28 | \code{"disable"}. The default value, \code{NULL}, will respect the setting from 29 | any previous calls to \code{\link[shiny:enableBookmarking]{enableBookmarking()}}. See \code{\link[shiny:enableBookmarking]{enableBookmarking()}} 30 | for more information on bookmarking your app.} 31 | 32 | \item{uiPattern}{A regular expression that will be applied to each \code{GET} 33 | request to determine whether the \code{ui} should be used to handle the 34 | request. Note that the entire request path must match the regular 35 | expression in order for the match to be considered successful.} 36 | 37 | \item{...}{arguments to pass to golem_opts. 38 | See \code{?golem::get_golem_options} for more details.} 39 | } 40 | \description{ 41 | Run the Shiny Application 42 | } 43 | -------------------------------------------------------------------------------- /tests/testthat/test-golem-recommended.R: -------------------------------------------------------------------------------- 1 | test_that("app ui", { 2 | ui <- app_ui() 3 | golem::expect_shinytaglist(ui) 4 | # Check that formals have not been removed 5 | fmls <- formals(app_ui) 6 | for (i in c("request")) { 7 | expect_true(i %in% names(fmls)) 8 | } 9 | }) 10 | 11 | test_that("app server", { 12 | server <- app_server 13 | expect_type(server, "closure") 14 | # Check that formals have not been removed 15 | fmls <- formals(app_server) 16 | for (i in c("input", "output", "session")) { 17 | expect_true(i %in% names(fmls)) 18 | } 19 | }) 20 | 21 | test_that( 22 | "app_sys works", 23 | { 24 | expect_true( 25 | app_sys("golem-config.yml") != "" 26 | ) 27 | } 28 | ) 29 | 30 | test_that( 31 | "golem-config works", 32 | { 33 | config_file <- app_sys("golem-config.yml") 34 | skip_if(config_file == "") 35 | 36 | expect_true( 37 | get_golem_config( 38 | "app_prod", 39 | config = "production", 40 | file = config_file 41 | ) 42 | ) 43 | expect_false( 44 | get_golem_config( 45 | "app_prod", 46 | config = "dev", 47 | file = config_file 48 | ) 49 | ) 50 | } 51 | ) 52 | 53 | # Configure this test to fit your need. 54 | # testServer() function makes it possible to test code in server functions and modules, without needing to run the full Shiny application 55 | testServer(app_server, { 56 | 57 | # Set and test an input 58 | session$setInputs(x = 2) 59 | expect_equal(input$x, 2) 60 | 61 | # Example of tests you can do on the server: 62 | # - Checking reactiveValues 63 | # expect_equal(r$lg, 'EN') 64 | # - Checking output 65 | # expect_equal(output$txt, "Text") 66 | }) 67 | 68 | # Configure this test to fit your need 69 | test_that( 70 | "app launches", 71 | { 72 | golem::expect_running(sleep = 5) 73 | } 74 | ) 75 | -------------------------------------------------------------------------------- /dev/03_deploy.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # README: each step of the dev files is optional, and you don't have to 4 | # fill every dev scripts before getting started. 5 | # 01_start.R should be filled at start. 6 | # 02_dev.R should be used to keep track of your development during the project. 7 | # 03_deploy.R should be used once you need to deploy your app. 8 | # 9 | # 10 | ###################################### 11 | #### CURRENT FILE: DEPLOY SCRIPT ##### 12 | ###################################### 13 | 14 | # Test your app 15 | 16 | ## Run checks ---- 17 | ## Check the package before sending to prod 18 | devtools::check() 19 | rhub::check_for_cran() 20 | 21 | # Deploy 22 | 23 | ## Local, CRAN or Package Manager ---- 24 | ## This will build a tar.gz that can be installed locally, 25 | ## sent to CRAN, or to a package manager 26 | devtools::build() 27 | 28 | ## Docker ---- 29 | ## If you want to deploy via a generic Dockerfile 30 | golem::add_dockerfile_with_renv() 31 | ## If you want to deploy to ShinyProxy 32 | golem::add_dockerfile_with_renv_shinyproxy() 33 | 34 | ## Posit ---- 35 | ## If you want to deploy on Posit related platforms 36 | golem::add_positconnect_file() 37 | golem::add_shinyappsio_file() 38 | golem::add_shinyserver_file() 39 | 40 | ## Deploy to Posit Connect or ShinyApps.io ---- 41 | 42 | ## Add/update manifest file (optional; for Git backed deployment on Posit ) 43 | rsconnect::writeManifest() 44 | 45 | ## In command line. 46 | rsconnect::deployApp( 47 | appName = desc::desc_get_field("Package"), 48 | appTitle = desc::desc_get_field("Package"), 49 | appFiles = c( 50 | # Add any additional files unique to your app here. 51 | "R/", 52 | "inst/", 53 | "data/", 54 | "NAMESPACE", 55 | "DESCRIPTION", 56 | "app.R" 57 | ), 58 | appId = rsconnect::deployments(".")$appID, 59 | lint = FALSE, 60 | forceUpdate = TRUE 61 | ) 62 | -------------------------------------------------------------------------------- /dev/02_dev.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # README: each step of the dev files is optional, and you don't have to 4 | # fill every dev scripts before getting started. 5 | # 01_start.R should be filled at start. 6 | # 02_dev.R should be used to keep track of your development during the project. 7 | # 03_deploy.R should be used once you need to deploy your app. 8 | # 9 | # 10 | ################################### 11 | #### CURRENT FILE: DEV SCRIPT ##### 12 | ################################### 13 | 14 | # Engineering 15 | 16 | ## Dependencies ---- 17 | ## Amend DESCRIPTION with dependencies read from package code parsing 18 | ## install.packages('attachment') # if needed. 19 | attachment::att_amend_desc() 20 | 21 | ## Add modules ---- 22 | ## Create a module infrastructure in R/ 23 | golem::add_module(name = "name_of_module1", with_test = TRUE) # Name of the module 24 | golem::add_module(name = "name_of_module2", with_test = TRUE) # Name of the module 25 | 26 | ## Add helper functions ---- 27 | ## Creates fct_* and utils_* 28 | golem::add_fct("helpers", with_test = TRUE) 29 | golem::add_utils("helpers", with_test = TRUE) 30 | 31 | ## External resources 32 | ## Creates .js and .css files at inst/app/www 33 | golem::add_js_file("script") 34 | golem::add_js_handler("handlers") 35 | golem::add_css_file("custom") 36 | golem::add_sass_file("custom") 37 | golem::add_any_file("file.json") 38 | 39 | ## Add internal datasets ---- 40 | ## If you have data in your package 41 | usethis::use_data_raw(name = "my_dataset", open = FALSE) 42 | 43 | ## Tests ---- 44 | ## Add one line by test you want to create 45 | usethis::use_test("app") 46 | 47 | # Documentation 48 | 49 | ## Vignette ---- 50 | usethis::use_vignette("xmrconsensus") 51 | devtools::build_vignettes() 52 | 53 | ## Code Coverage---- 54 | ## Set the code coverage service ("codecov" or "coveralls") 55 | usethis::use_coverage() 56 | 57 | # Create a summary readme for the testthat subdirectory 58 | covrpage::covrpage() 59 | 60 | ## CI ---- 61 | ## Use this part of the script if you need to set up a CI 62 | ## service for your application 63 | ## 64 | ## (You'll need GitHub there) 65 | usethis::use_github() 66 | 67 | # GitHub Actions 68 | usethis::use_github_action() 69 | # Chose one of the three 70 | # See https://usethis.r-lib.org/reference/use_github_action.html 71 | usethis::use_github_action_check_release() 72 | usethis::use_github_action_check_standard() 73 | usethis::use_github_action_check_full() 74 | # Add action for PR 75 | usethis::use_github_action_pr_commands() 76 | 77 | # Circle CI 78 | usethis::use_circleci() 79 | usethis::use_circleci_badge() 80 | 81 | # Jenkins 82 | usethis::use_jenkins() 83 | 84 | # GitLab CI 85 | usethis::use_gitlab_ci() 86 | 87 | # You're now set! ---- 88 | # go to dev/03_deploy.R 89 | rstudioapi::navigateToFile("dev/03_deploy.R") 90 | -------------------------------------------------------------------------------- /R/fct_pools_collect.R: -------------------------------------------------------------------------------- 1 | 2 | #' Collect claimed blocks from mining pools' APIs 3 | #' 4 | #' @description 5 | #' 6 | #' Uses the `monero-blocks` tool to continuously collect data from mining 7 | #' pools' APIs about which Monero blocks they have claimed to mine. Data is 8 | #' written to a CSV file named `blocks.csv`. 9 | #' 10 | #' The `monero-blocks` Go program must be built in a 'monero-blocks' 11 | #' local working directory. Available at 12 | #' \url{https://git.gammaspectra.live/WeebDataHoarder/monero-blocks} 13 | #' 14 | #' This function is an infinite loop. Input `ctrl + c` to interrupt. 15 | #' 16 | #' 17 | #' @param unrestricted.rpc.url URL and port of the `monerod` unrestricted RPC. 18 | #' Default is `⁠http://127.0.0.1:18081` 19 | #' @param init.blocks Number of recent blocks to collect on initiation. 20 | #' @param recent.blocks Number of recent blocks to collect while running 21 | #' continuously. 22 | #' @param poll.time Time interval, in seconds, between each API request. 23 | #' 24 | #' @returns 25 | #' NULL (invisible) 26 | #' @export 27 | #' 28 | #' @examples 29 | #' \dontrun{ 30 | #' pools.collect() 31 | #' } 32 | pools.collect <- function(unrestricted.rpc.url = "http://127.0.0.1:18081", 33 | init.blocks = 720 * 7, recent.blocks = 720, poll.time = 60) { 34 | 35 | handle <- RCurl::getCurlHandle() 36 | 37 | last_block_header <- tryCatch( 38 | rpc.req(unrestricted.rpc.url, method = "get_last_block_header", 39 | handle = handle), error = function(e) {NULL}) 40 | 41 | if (length(last_block_header) == 0) { 42 | stop(paste0("Invalid RPC response from monerod. Is the Monero node's unrestricted RPC available at ", 43 | unrestricted.rpc.url, "?")) 44 | } 45 | 46 | chaintip.height <- last_block_header$result$block_header$height 47 | 48 | monero_blocks.location <- ifelse(.Platform$OS.type == "windows", 49 | "monero-blocks/monero-blocks.exe", 50 | "monero-blocks/monero-blocks") 51 | 52 | if ( ! file.exists(monero_blocks.location)) { 53 | stop("Cannot find the 'monero-blocks' program in the 'monero-blocks' local working directory.\nDid you remember to build it?") 54 | } 55 | 56 | system(paste0(monero_blocks.location, " --height ", chaintip.height - init.blocks)) 57 | # Initial data download 58 | 59 | # Infinite loop. Input ctrl + c to stop. 60 | while(TRUE) { 61 | 62 | last_block_header <- tryCatch( 63 | rpc.req(unrestricted.rpc.url, method = "get_last_block_header", 64 | handle = handle), error = function(e) {NULL}) 65 | 66 | if (length(last_block_header) == 0) { 67 | message("Invalid RPC response from monerod.") 68 | Sys.sleep(poll.time) 69 | next 70 | } 71 | 72 | chaintip.height <- last_block_header$result$block_header$height 73 | system(paste0(monero_blocks.location, " --height ", chaintip.height - recent.blocks)) 74 | Sys.sleep(poll.time) 75 | } 76 | 77 | return(invisible(NULL)) 78 | 79 | } 80 | -------------------------------------------------------------------------------- /dev/01_start.R: -------------------------------------------------------------------------------- 1 | # Building a Prod-Ready, Robust Shiny Application. 2 | # 3 | # README: each step of the dev files is optional, and you don't have to 4 | # fill every dev scripts before getting started. 5 | # 01_start.R should be filled at start. 6 | # 02_dev.R should be used to keep track of your development during the project. 7 | # 03_deploy.R should be used once you need to deploy your app. 8 | # 9 | # 10 | ######################################## 11 | #### CURRENT FILE: ON START SCRIPT ##### 12 | ######################################## 13 | 14 | ## Fill the DESCRIPTION ---- 15 | ## Add meta data about your application and set some default {golem} options 16 | ## 17 | ## /!\ Note: if you want to change the name of your app during development, 18 | ## either re-run this function, call golem::set_golem_name(), or don't forget 19 | ## to change the name in the app_sys() function in app_config.R /!\ 20 | ## 21 | golem::fill_desc( 22 | pkg_name = "xmrconsensus", # The name of the golem package containing the app (typically lowercase, no underscore or periods) 23 | pkg_title = "Shiny App about Monero blockchain consensus live status", # What the Package Does (One Line, Title Case, No Period) 24 | pkg_description = "Shiny App about Monero blockchain consensus live status.", # What the package does (one paragraph). 25 | authors = person( 26 | family = "Rucknium", # Your Last Name 27 | email = "Rucknium@protonmail.com", # Your email 28 | role = c("aut", "cre", "cph"), # Your role (here author/creator), 29 | comment = c(ORCID = "0000-0001-5999-8950") 30 | ), 31 | repo_url = "https://github.com/Rucknium/xmrconsensus", # The URL of the GitHub repo (optional), 32 | pkg_version = "0.0.1", # The version of the package containing the app 33 | set_options = TRUE # Set the global golem options 34 | ) 35 | 36 | ## Install the required dev dependencies ---- 37 | golem::install_dev_deps() 38 | 39 | ## Create Common Files ---- 40 | ## See ?usethis for more information 41 | # usethis::use_mit_license("Golem User") # You can set another license here 42 | usethis::use_agpl_license(version = 3, include_future = TRUE) 43 | golem::use_readme_rmd(open = FALSE) 44 | devtools::build_readme() 45 | # Note that `contact` is required since usethis version 2.1.5 46 | # If your {usethis} version is older, you can remove that param 47 | # usethis::use_code_of_conduct(contact = "Golem User") 48 | usethis::use_lifecycle_badge("Experimental") 49 | # usethis::use_news_md(open = FALSE) 50 | 51 | ## Init Testing Infrastructure ---- 52 | ## Create a template for tests 53 | golem::use_recommended_tests() 54 | 55 | ## Favicon ---- 56 | # If you want to change the favicon (default is golem's one) 57 | # golem::use_favicon() # path = "path/to/ico". Can be an online file. 58 | # golem::remove_favicon() # Uncomment to remove the default favicon 59 | 60 | ## Add helper functions ---- 61 | # golem::use_utils_ui(with_test = TRUE) 62 | # golem::use_utils_server(with_test = TRUE) 63 | 64 | ## Use git ---- 65 | # usethis::use_git() 66 | ## Sets the remote associated with 'name' to 'url' 67 | # usethis::use_git_remote( 68 | # name = "origin", 69 | # url = "https://github.com//.git" 70 | # ) 71 | 72 | # You're now set! ---- 73 | 74 | # go to dev/02_dev.R 75 | # rstudioapi::navigateToFile("dev/02_dev.R") 76 | -------------------------------------------------------------------------------- /R/fct_pool_blocks.R: -------------------------------------------------------------------------------- 1 | #' pool_blocks 2 | #' 3 | #' @description A fct function 4 | #' 5 | #' @return The return value, if any, from executing the function. 6 | #' 7 | #' @noRd 8 | pool_blocks <- function(unrestricted.rpc.url, aggregation.hours, which.pools, pool.chart.begin) { 9 | 10 | aggregation.hours <- as.numeric(aggregation.hours) 11 | 12 | handle <- RCurl::getCurlHandle() 13 | 14 | # https://docs.getmonero.org/rpc-library/monerod-rpc/#get_last_block_header 15 | last_block_header <- rpc.req(unrestricted.rpc.url, method = "get_last_block_header", params = "", handle = handle) 16 | 17 | # TODO: Error handling if RPC fails 18 | chaintip.height <- last_block_header$result$block_header$height 19 | 20 | # https://docs.getmonero.org/rpc-library/monerod-rpc/#get_block_headers_range 21 | block_headers <- rpc.req(unrestricted.rpc.url, method = "get_block_headers_range", 22 | params = list(start_height = 3473380, end_height = chaintip.height), 23 | # 3473380 is about at pool.chart.begin (will trim it to exactly 24 | # pool.chart.begin later) 25 | handle = handle) 26 | 27 | block_headers <- data.table::rbindlist(block_headers$result$headers, fill = TRUE) 28 | 29 | pools <- data.table::fread("data-raw/pools/blocks.csv", fill = TRUE) 30 | # fill = TRUE because CSV file format changed 31 | data.table::setnames(pools, c("Id", "Pool"), c("hash", "pool")) 32 | 33 | block_headers.attr <- block_headers[timestamp >= pool.chart.begin, .(hash, height, timestamp)] 34 | 35 | block_headers.attr <- merge(block_headers.attr, pools, all.x = TRUE) 36 | block_headers.attr[is.na(pool), pool := "unknown"] 37 | 38 | 39 | block_headers.attr[, timestamp := as.POSIXct(timestamp)] 40 | 41 | block_headers.attr[, timestamp.binned := timestamp - as.numeric(timestamp) %% 42 | (60 * 60 * aggregation.hours) + (60 * 60 * aggregation.hours)] 43 | # Add aggregation.hours so that it the binned value is the end of the period 44 | 45 | block_headers.attr <- block_headers.attr[timestamp.binned <= Sys.time() , ] 46 | # Remove rows that are in the current time interval. We want complete intervals. 47 | 48 | block_headers.attr[, total.in.timestamp.bin := .N, by = "timestamp.binned"] 49 | 50 | blocks.pools <- block_headers.attr[, .(n.blocks = .N, 51 | share.blocks = .N / unique(total.in.timestamp.bin)), 52 | by = c("timestamp.binned", "pool")] 53 | 54 | blocks.pools <- blocks.pools[pool %in% which.pools, ] 55 | 56 | if (data.table::uniqueN(blocks.pools$pool) > 5) { 57 | 58 | aggregate.these.pools <- blocks.pools[, .(share.blocks.sum = sum(share.blocks)), by = "pool"] 59 | 60 | data.table::setorder(aggregate.these.pools, -share.blocks.sum) 61 | 62 | aggregate.these.pools <- aggregate.these.pools$pool[-(1:5)] 63 | 64 | aggregate.these.pools <- setdiff(aggregate.these.pools, "unknown") 65 | # Do not aggregate the unknown miners with "other known pools" 66 | 67 | aggregated.pools <- blocks.pools[pool %in% aggregate.these.pools, .( 68 | pool = "other known pools", 69 | n.blocks = sum(n.blocks), 70 | share.blocks = sum(share.blocks)), by = "timestamp.binned"] 71 | 72 | blocks.pools <- rbind(blocks.pools[ ! pool %in% aggregate.these.pools, ], aggregated.pools) 73 | 74 | } 75 | 76 | data.table::setorder(blocks.pools, timestamp.binned) 77 | 78 | blocks.pools 79 | 80 | } 81 | 82 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # `xmrconsensus` 5 | 6 | 7 | 8 | [![Lifecycle: 9 | experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) 10 | 11 | 12 | `xmrconsensus` is an alpha project. Expect breaking changes in future 13 | versions. 14 | 15 | ## Live deployment 16 | 17 | An accessible live deployment of this app is available at 18 | [moneroconsensus.info](https://moneroconsensus.info). 19 | 20 | ## Running `xmrconsensus` on your own computer 21 | 22 | Deployment has only been tested on Linux. 23 | 24 | ### Run a Monero node 25 | 26 | You must have a Monero node with an unrestricted RPC port available to 27 | run the app. Normally, the only way to have access to an unrestricted 28 | RPC port is to run a Monero node on your own machine. The quickest way 29 | to start running a Monero node is to download the [“Monero CLI Wallet” 30 | at the getmonero.org website](https://www.getmonero.org/downloads/#cli) 31 | for your operating system and start the `monerod` node software on your 32 | command line. A pruned node should be fine for the purposes of this app. 33 | You will need to wait a while, up to a few days, to download and verify 34 | the blockchain. Only sync on an internal SSD. Do not use an HDD or USB 35 | drive. As of August 2025, an unpruned node will occupy about 260GB of 36 | storage. A pruned node will occupy about 100GB of storage. 37 | 38 | If you already have a Monero node running, just keep it running. If you 39 | are starting up a completely new node or re-starting a node after some 40 | time of it being turned off, you can add the `--keep-alt-blocks` flag to 41 | the `monerod` startup arguments to [preserve the data on alternative 42 | chains between 43 | restarts](https://docs.getmonero.org/interacting/monerod-reference/#testing-monero-itself). 44 | If this flag is not enabled, the node will delete the alternative chain 45 | data the next time it shuts down. 46 | 47 | ### Download and install `xmrconsensus` 48 | 49 | Install [R](https://www.r-project.org/). Linux users should install the 50 | `r-base` and `r-base-dev` system packages. 51 | 52 | Clone this repo into a directory on your local machine with: 53 | 54 | ``` bash 55 | git clone https://github.com/Rucknium/xmrconsensus.git 56 | ``` 57 | 58 | Go into the `xmrconsensus` directory by inputting `cd xmrconsensus`. 59 | Then start an R session by inputting `R` into the terminal. Install the 60 | package: 61 | 62 | ``` r 63 | install.packages("devtools") 64 | devtools::install(upgrade = FALSE, Ncpus = 4) 65 | ``` 66 | 67 | If you have greater or fewer than 4 threads available on your machine, 68 | you can adjust the `Ncpus` argument. If you are on Linux, compilation of 69 | all the package dependencies may take some time. close the R session 70 | after it is finished installing by inputting `quit(save = "no")`. 71 | 72 | ### Download and build `monero-blocks` 73 | 74 | `moneroconsensus` needs a separate tool to fetch data on which mining 75 | pools claim each block. The tool is `monero-blocks`, written in Go by 76 | DataHorader and available 77 | [here](https://git.gammaspectra.live/WeebDataHoarder/monero-blocks). You 78 | should have [a recent version of Go](https://go.dev/doc/install) on your 79 | machine. 80 | 81 | To set up the tool, start in the `xmrconsensus`. Then input into your 82 | console: 83 | 84 | ``` bash 85 | cd data-raw/pools 86 | git clone https://git.gammaspectra.live/WeebDataHoarder/monero-blocks.git 87 | cd monero-blocks 88 | go build 89 | ``` 90 | 91 | This will create the `monero-blocks` binary executable program in the 92 | `data-raw/pools/monero-blocks` directory. 93 | 94 | ### Run `monero-blocks` 95 | 96 | Next, you need to run `monero-blocks` in a loop to create the 97 | `blocks.csv` file in the `data-raw/pools` directory and collect mined 98 | block data as pools post it in their API. The easiest way to do this is 99 | navigate back to the `data-raw/pools`, start an R session, and input 100 | 101 | ``` r 102 | xmrconsensus::pools.collect() 103 | ``` 104 | 105 | If your Monero node’s unrestricted RPC is not at the default 106 | `http://127.0.0.1:18081`, then use 107 | `xmrconsensus::pools.collect(unrestricted.rpc.url = "http://127.0.0.1:18081")` 108 | instead, replacing `http://127.0.0.1:18081` with the full URL and port 109 | of your node’s unrestricted RPC. 110 | 111 | You will need to leave the process running in its own terminal window. 112 | 113 | ### Run `xmrconsensus` 114 | 115 | Go to the `xmrconsensus` directory in a terminal. Open an R session and 116 | input 117 | 118 | ``` r 119 | xmrconsensus::run_app() 120 | ``` 121 | 122 | By default, R will open your default web browser to the Shiny app. If 123 | you prefer to open your web browser yourself, use this instead: 124 | 125 | ``` r 126 | xmrconsensus::run_app(options = list(launch.browser = FALSE)) 127 | ``` 128 | 129 | The full local URL, with port number, will be printed to the console. 130 | Paste the URL into your internet browser. 131 | 132 | If your Monero node’s unrestricted RPC is not at the default 133 | `http://127.0.0.1:18081`, then use 134 | `xmrconsensus::run_app(unrestricted.rpc.url = "http://127.0.0.1:18081")` 135 | instead, replacing `http://127.0.0.1:18081` with the full URL and port 136 | of your node’s unrestricted RPC. 137 | 138 | ### Update `xmrconsensus` 139 | 140 | To get the latest version of `xmrconsensus`, pull the latest git repo 141 | and install: 142 | 143 | ``` bash 144 | cd xmrconsensus 145 | git pull 146 | R -e "devtools::install(upgrade = FALSE)" 147 | ``` 148 | 149 | And restart `xmrconsensus::run_app()`. 150 | -------------------------------------------------------------------------------- /README.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | output: github_document 3 | --- 4 | 5 | 6 | 7 | ```{r, include = FALSE} 8 | knitr::opts_chunk$set( 9 | collapse = TRUE, 10 | comment = "#>", 11 | fig.path = "man/figures/README-", 12 | out.width = "100%" 13 | ) 14 | ``` 15 | 16 | # `xmrconsensus` 17 | 18 | 19 | [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) 20 | 21 | 22 | `xmrconsensus` is an alpha project. Expect breaking changes in future versions. 23 | 24 | ## Live deployment 25 | 26 | An accessible live deployment of this app is available at [moneroconsensus.info](https://moneroconsensus.info). 27 | 28 | ## Running `xmrconsensus` on your own computer 29 | 30 | Deployment has only been tested on Linux. 31 | 32 | ### Run a Monero node 33 | 34 | You must have a Monero node with an unrestricted RPC port available to run the app. Normally, the only way to have access to an unrestricted RPC port is to run a Monero node on your own machine. The quickest way to start running a Monero node is to download the ["Monero CLI Wallet" at the getmonero.org website](https://www.getmonero.org/downloads/#cli) for your operating system and start the `monerod` node software on your command line. A pruned node should be fine for the purposes of this app. You will need to wait a while, up to a few days, to download and verify the blockchain. Only sync on an internal SSD. Do not use an HDD or USB drive. As of August 2025, an unpruned node will occupy about 260GB of storage. A pruned node will occupy about 100GB of storage. 35 | 36 | If you already have a Monero node running, just keep it running. If you are starting up a completely new node or re-starting a node after some time of it being turned off, you can add the `--keep-alt-blocks` flag to the `monerod` startup arguments to [preserve the data on alternative chains between restarts](https://docs.getmonero.org/interacting/monerod-reference/#testing-monero-itself). If this flag is not enabled, the node will delete the alternative chain data the next time it shuts down. 37 | 38 | ### Download and install `xmrconsensus` 39 | 40 | Install [R](https://www.r-project.org/). Linux users should install the `r-base` and `r-base-dev` system packages. 41 | 42 | Clone this repo into a directory on your local machine with: 43 | 44 | ```bash 45 | git clone https://github.com/Rucknium/xmrconsensus.git 46 | ``` 47 | 48 | Go into the `xmrconsensus` directory by inputting `cd xmrconsensus`. Then start an R session by inputting `R` into the terminal. Install the package: 49 | 50 | ```{r, eval = FALSE} 51 | install.packages("devtools") 52 | devtools::install(upgrade = FALSE, Ncpus = 4) 53 | ``` 54 | 55 | If you have greater or fewer than 4 threads available on your machine, you can adjust the `Ncpus` argument. If you are on Linux, compilation of all the package dependencies may take some time. close the R session after it is finished installing by inputting `quit(save = "no")`. 56 | 57 | ### Download and build `monero-blocks` 58 | 59 | `moneroconsensus` needs a separate tool to fetch data on which mining pools claim each block. The tool is `monero-blocks`, written in Go by DataHorader and available [here](https://git.gammaspectra.live/WeebDataHoarder/monero-blocks). You should have [a recent version of Go](https://go.dev/doc/install) on your machine. 60 | 61 | To set up the tool, start in the `xmrconsensus`. Then input into your console: 62 | 63 | ```bash 64 | cd data-raw/pools 65 | git clone https://git.gammaspectra.live/WeebDataHoarder/monero-blocks.git 66 | cd monero-blocks 67 | go build 68 | ``` 69 | 70 | This will create the `monero-blocks` binary executable program in the `data-raw/pools/monero-blocks` directory. 71 | 72 | ### Run `monero-blocks` 73 | 74 | Next, you need to run `monero-blocks` in a loop to create the `blocks.csv` file in the `data-raw/pools` directory and collect mined block data as pools post it in their API. The easiest way to do this is navigate back to the `data-raw/pools`, start an R session, and input 75 | 76 | ```{r, eval = FALSE} 77 | xmrconsensus::pools.collect() 78 | ``` 79 | 80 | If your Monero node's unrestricted RPC is not at the default `http://127.0.0.1:18081`, then use `xmrconsensus::pools.collect(unrestricted.rpc.url = "http://127.0.0.1:18081")` instead, replacing `http://127.0.0.1:18081` with the full URL and port of your node's unrestricted RPC. 81 | 82 | You will need to leave the process running in its own terminal window. 83 | 84 | ### Run `xmrconsensus` 85 | 86 | Go to the `xmrconsensus` directory in a terminal. Open an R session and input 87 | 88 | ```{r, eval = FALSE} 89 | xmrconsensus::run_app() 90 | ``` 91 | 92 | By default, R will open your default web browser to the Shiny app. If you prefer to open your web browser yourself, use this instead: 93 | 94 | ```{r, eval = FALSE} 95 | xmrconsensus::run_app(options = list(launch.browser = FALSE)) 96 | ``` 97 | 98 | The full local URL, with port number, will be printed to the console. Paste the URL into your internet browser. 99 | 100 | If your Monero node's unrestricted RPC is not at the default `http://127.0.0.1:18081`, then use `xmrconsensus::run_app(unrestricted.rpc.url = "http://127.0.0.1:18081")` instead, replacing `http://127.0.0.1:18081` with the full URL and port of your node's unrestricted RPC. 101 | 102 | ### Update `xmrconsensus` 103 | 104 | To get the latest version of `xmrconsensus`, pull the latest git repo and install: 105 | 106 | ```bash 107 | cd xmrconsensus 108 | git pull 109 | R -e "devtools::install(upgrade = FALSE)" 110 | ``` 111 | 112 | And restart `xmrconsensus::run_app()`. 113 | 114 | -------------------------------------------------------------------------------- /R/fct_alt_chains.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | #' alt_chains_graph 6 | #' 7 | #' @description A fct function 8 | #' 9 | #' @return The return value, if any, from executing the function. 10 | #' 11 | #' @noRd 12 | alt_chains_graph <- function(unrestricted.rpc.url, 13 | n.blocks.display.chaintip = 10, n.blocks.display.after.orphan = 1, 14 | mining.pool.data.available = TRUE) { 15 | 16 | handle <- RCurl::getCurlHandle() 17 | 18 | # https://docs.getmonero.org/rpc-library/monerod-rpc/#get_alternate_chains 19 | alt_chains <- rpc.req(unrestricted.rpc.url, method = "get_alternate_chains", params = "", handle = handle) 20 | 21 | # https://docs.getmonero.org/rpc-library/monerod-rpc/#get_last_block_header 22 | last_block_header <- rpc.req(unrestricted.rpc.url, method = "get_last_block_header", params = "", handle = handle) 23 | 24 | # TODO: Error handling if RPC fails 25 | chaintip.height <- last_block_header$result$block_header$height 26 | 27 | # https://docs.getmonero.org/rpc-library/monerod-rpc/#get_block_headers_range 28 | block_headers <- rpc.req(unrestricted.rpc.url, method = "get_block_headers_range", 29 | params = list(start_height = chaintip.height - 720 * 7, end_height = chaintip.height), 30 | # Get data from about a week ago to today 31 | handle = handle) 32 | 33 | if (length(alt_chains$result$chains) == 0 ) { 34 | stop(paste0("Monero node is not aware of any alt chains or orphaned blocks.\n", 35 | "This can occur if your node was restarted recently.\n", 36 | "You can check if you have any alt chains by going to the monerod console\n", 37 | "(the terminal window where monerod is running) and inputting 'alt_chain_info'.\n", 38 | "Since there are no alt chains, the app has nothing interesting to display and has exited.")) 39 | } 40 | 41 | 42 | alt_chains <- lapply(alt_chains$result$chains, function(x) { 43 | chain.length <- length(x$block_hashes) 44 | base.starting.height <- x$height - chain.length + 1 45 | # Docs seem wrong "height - unsigned int; the block height of the first diverging block of this alternative chain." 46 | # (Docs are being fixed.) 47 | # Seems that height is the height of the _last_ diverging block of the chain. 48 | result <- data.table(prev_hash = x$main_chain_parent_block, 49 | hash = x$block_hashes[chain.length], 50 | height = base.starting.height, main_chain_parent_block = x$main_chain_parent_block) 51 | if (length(x$block_hashes) == 1) { return(result) } 52 | result <- rbind(result, 53 | data.table( 54 | prev_hash = x$block_hashes[2:chain.length], 55 | hash = x$block_hashes[1:(chain.length - 1)], 56 | height = base.starting.height + rev(seq_len(chain.length - 1)), 57 | main_chain_parent_block = x$main_chain_parent_block)) 58 | return(result) 59 | }) 60 | 61 | 62 | block_headers <- data.table::rbindlist(block_headers$result$headers, fill = TRUE) 63 | 64 | alt_chains <- data.table::rbindlist(alt_chains) 65 | 66 | # https://stackoverflow.com/questions/58109098/cumulative-sum-based-on-a-condition-but-reset-after-condition-ends 67 | block_headers[, not.alt := ! (hash %in% alt_chains$prev_hash | height %in% alt_chains$height)] 68 | # prev_hash gets the main chain block that the chain diverges from. height gets 69 | # any additional blocks if the alt chain is longer than one block. height 70 | # also gets the first block after the divergence when there is a single orphan block 71 | 72 | block_headers[, rearrange.index := if(data.table::first(not.alt)) cumsum(not.alt) else 0, 73 | data.table::rleid(not.alt)] 74 | 75 | block_headers <- block_headers[rearrange.index %in% 0:(1 + n.blocks.display.after.orphan) | 76 | height >= (max(height) - n.blocks.display.chaintip), ] 77 | 78 | block_headers$prev_hash[2:nrow(block_headers)] <- block_headers$hash[-nrow(block_headers)] 79 | # This makes sure that the false link that bridges over omitted blocks is mended 80 | 81 | max.blocks.displayed <- 150 82 | 83 | if (nrow(block_headers) > max.blocks.displayed) { 84 | block_headers <- block_headers[(nrow(block_headers) - (max.blocks.displayed - 1)):nrow(block_headers), ] 85 | } 86 | 87 | 88 | block_headers.graph <- block_headers[, .(prev_hash, hash)] 89 | 90 | block_headers.attr <- block_headers[, .(hash, height, timestamp, num_txes, rearrange.index)] 91 | 92 | block_headers.attr <- block_headers.attr[, blocks.omitted := c(diff(height), 0)] 93 | 94 | if (mining.pool.data.available) { 95 | pools <- data.table::fread("data-raw/pools/blocks.csv", fill = TRUE) 96 | # fill = TRUE because CSV file format changed 97 | } else { 98 | pools <- structure(list(Height = integer(0), Id = character(0), 99 | Timestamp = structure(numeric(0), class = "integer64"), 100 | Reward = character(0), Pool = character(0), Valid = logical(0), 101 | Miner = character(0)), row.names = c(NA, 0L), class = c("data.table", 102 | "data.frame")) 103 | } 104 | 105 | data.table::setnames(pools, c("Id", "Pool"), c("hash", "pool")) 106 | 107 | block_headers.attr <- merge(block_headers.attr, pools, all.x = TRUE) 108 | block_headers.attr[is.na(pool), pool := "unknown"] 109 | 110 | # Testing 111 | # block_headers.attr[, pool := rep(LETTERS, 10)[seq_len(nrow(block_headers.attr))] ] 112 | # block_headers.attr[1, pool := "unknown" ] 113 | 114 | orphaned.blocks.last.day <- alt_chains[height >= chaintip.height - 720, .N] 115 | # 720 is approximately one day of blocks 116 | # Get orphaned.blocks.last.day before alt_chains is trimmed to 117 | # max.blocks.displayed (150) main chain blocks by the next line 118 | 119 | orphaned.blocks.last.day.known <- alt_chains[height >= chaintip.height - 720 & hash %in% pools$hash, .N] 120 | 121 | orphaned.blocks <- c(orphaned.blocks.last.day = orphaned.blocks.last.day, 122 | orphaned.blocks.last.day.known = orphaned.blocks.last.day.known, 123 | orphaned.blocks.last.day.unknown = orphaned.blocks.last.day - orphaned.blocks.last.day.known) 124 | 125 | alt_chains <- alt_chains[main_chain_parent_block %in% unlist(block_headers), ] 126 | 127 | data.table::setorder(alt_chains, height) 128 | # Important to set order like this so that orphan blocks alternate sides 129 | 130 | alt_chains.graph <- alt_chains[, .(prev_hash, hash, main_chain_parent_block)] 131 | 132 | alt_chains.attr <- alt_chains[, .(hash, height)] 133 | alt_chains.attr[, timestamp := NA] 134 | alt_chains.attr[, blocks.omitted := 0] 135 | 136 | alt_chains.attr <- merge(alt_chains.attr, pools, all.x = TRUE) 137 | alt_chains.attr[is.na(pool), pool := "unknown"] 138 | 139 | # Testing 140 | # alt_chains.attr[, pool := letters[seq_len(nrow(alt_chains.attr))] ] 141 | 142 | alt_chains.attr[, rearrange.index := 0] 143 | 144 | if (nrow(alt_chains.graph) == 0) { 145 | chain.graph <- block_headers.graph 146 | alt_chains.graph.chunks <- NULL 147 | } else { 148 | alt_chains.graph.chunks <- split(alt_chains.graph, by = "main_chain_parent_block") 149 | } 150 | 151 | if (length(alt_chains.graph.chunks) == 1) { 152 | chain.graph <- rbind(block_headers.graph, alt_chains.graph, fill = TRUE) 153 | chain.graph[, main_chain_parent_block := NULL] 154 | # Don't need this anymore 155 | } 156 | 157 | if (length(alt_chains.graph.chunks) > 1) { 158 | 159 | alt_chains.graph.top.seq <- seq(1, length(alt_chains.graph.chunks), by = 2) 160 | 161 | alt_chains.graph.end.seq <- seq(2, length(alt_chains.graph.chunks), by = 2) 162 | 163 | chain.graph <- rbind( 164 | data.table::rbindlist(alt_chains.graph.chunks[alt_chains.graph.top.seq]), 165 | block_headers.graph, 166 | data.table::rbindlist(alt_chains.graph.chunks[alt_chains.graph.end.seq]), 167 | fill = TRUE) 168 | # Need to do this so that the orphaned alt chains 169 | # alternate between left and right of the main chain 170 | # in the plot 171 | chain.graph[, main_chain_parent_block := NULL] 172 | # Don't need this anymore 173 | } 174 | 175 | alt_chains.attr[, num_txes := 1] 176 | # TODO: get number of txs of alt chain blocks. Assuming at least one 177 | # tx in each alt block for now. 178 | 179 | chain.attr <- rbind(block_headers.attr, alt_chains.attr) 180 | 181 | chain.attr[, label := paste0( 182 | "Height: ", prettyNum(height, big.mark = ","), "\n", 183 | "Hash: ", substr(hash, 1, 8), "...", "\n", 184 | ifelse(is.na(timestamp), "", paste0("Timestamp: ", as.POSIXct(timestamp), " UTC\n")), 185 | "Pool: " , pool 186 | )] 187 | 188 | chain.attr[rearrange.index == (1 + n.blocks.display.after.orphan) & height < (max(height) - n.blocks.display.chaintip), 189 | label := paste0("[", prettyNum(blocks.omitted, big.mark = ","), " blocks of\nuncontested chain omitted]")] 190 | # Don't display "blocks omitted" if the orphan block is in the chaintip 191 | 192 | chain.attr[, color := ifelse(pool == "unknown", "pink", "lightgreen")] 193 | chain.attr[rearrange.index == (1 + n.blocks.display.after.orphan) & height < (max(height) - n.blocks.display.chaintip), 194 | color := "yellow"] 195 | 196 | vertex.order <- unique(c(t(as.matrix(chain.graph)))) 197 | # This is how things are arranged in the plot 198 | 199 | chain.attr <- chain.attr[match(vertex.order, hash), ] 200 | chain.attr[is.na(color), color := "yellow"] 201 | chain.attr[is.na(label), label := paste0("[", prettyNum(blocks.omitted, big.mark = ","), " blocks of\nuncontested chain omitted]")] 202 | # "Missing" because this vertex only appears in 'prev_hash', not 'hash' 203 | 204 | chain.attr[, shape := ifelse( (num_txes == 0 | is.na(num_txes)) & color != "yellow", 205 | "circle", "square")] 206 | 207 | chain.attr[, is.alt.block := hash %in% alt_chains$hash] 208 | 209 | igraph.plot.data <- igraph::graph_from_edgelist(as.matrix(chain.graph), directed = TRUE) 210 | 211 | plot.height <- nrow(block_headers.graph) * 60 212 | 213 | list(igraph.plot.data = igraph.plot.data, chain.attr = chain.attr, 214 | plot.height = plot.height, orphaned.blocks = orphaned.blocks) 215 | 216 | } 217 | -------------------------------------------------------------------------------- /R/app_ui.R: -------------------------------------------------------------------------------- 1 | #' The application User-Interface 2 | #' 3 | #' @param request Internal parameter for `{shiny}`. 4 | #' DO NOT REMOVE. 5 | #' @import shiny 6 | #' @noRd 7 | app_ui <- function(request) { 8 | tagList( 9 | # Leave this function for adding external resources 10 | golem_add_external_resources(), 11 | # Your application UI logic 12 | bslib::page_fluid( 13 | titlePanel("Monero Consensus Status"), 14 | shiny::h5(shiny::strong(shiny::HTML('The open source code for this web app is available here. If website is unstable, run it on your own computer.'))), 15 | shiny::br(), 16 | shiny::tabsetPanel( 17 | shiny::tabPanel("⛓ Orphaned blocks", 18 | shiny::br(), 19 | shiny::h5(shiny::HTML('This web app displays a visualization of recent orphaned blocks and alternative chains of the Monero blockchain.')), 20 | shiny::br(), 21 | shiny::h5(shiny::HTML('Occasional orphaned blocks are normal. They occur naturally when two miners mine different valid blocks almost simultaneously. A high rate of orphaned blocks can indicate a problem in network-wide connection latency or even malicious behavior by one or more entities with a large hashpower share.')), 22 | shiny::br(), 23 | shiny::h5(shiny::HTML('If a malicious entity with a high share of network hashpower attempted a selfish mining strategy to raise its share of block rewards, the rate of orphaned blocks could increase. The malicious entity would cause the blocks of other pools to become orphaned. This evidence would appear in the visualization below.')), 24 | shiny::br(), 25 | shiny::h5(shiny::HTML('A malicious entity with 50 percent or more of total network hashpower could attempt deep chain re-organizations by mining an alternative chain. Alternative chain are like orphaned blocks, but are more than one block in length. Alternative chains should appear in the visualization below.')), 26 | shiny::br(), 27 | shiny::h5(shiny::HTML('This web app is new and untested.')), 28 | shiny::br(), 29 | shiny::h5('Click to toggle dark mode: '), 30 | bslib::input_dark_mode(id = "dark_mode"), 31 | shiny::sliderInput("n_blocks_display_chaintip", 32 | "Number of chaintip blocks to display (most recent blocks):", 33 | min = 5, max = 30, value = 10, step = 5, width = "500px"), 34 | shiny::sliderInput("n_blocks_display_after_orphan", 35 | "Number of blocks to display after each orphan/altchain:", 36 | min = 0, max = 10, value = 1, step = 1, width = "500px"), 37 | shiny::h5('Note: Total displayed chain length will not exceed 150.'), 38 | shiny::radioButtons("tree_mode", "Display mode: ", 39 | choiceNames = c("Linear (main chain on left, orphans on right)", 40 | "Tree (main chain alternates between left and right)"), 41 | choiceValues = c("linear", "tree"), width = "500px"), 42 | shiny::br(), 43 | shiny::br(), 44 | shiny::h5(shiny::strong(shiny::HTML(paste0( 45 | shiny::textOutput("orphaned_blocks_last_day_known", inline = TRUE), 46 | " (", shiny::textOutput("orphaned_blocks_last_day_known_percent", inline = TRUE), "%)", 47 | ' block(s) produced by known pools have been orphaned in last 720 blocks (about 24 hours).')))), 48 | shiny::h5(shiny::strong(shiny::HTML(paste0( 49 | shiny::textOutput("orphaned_blocks_last_day_unknown", inline = TRUE), 50 | " (", shiny::textOutput("orphaned_blocks_last_day_unknown_percent", inline = TRUE), "%)", 51 | ' block(s) produced by unknown pools or solo miners have been orphaned in last 720 blocks.')))), 52 | shiny::h5(shiny::HTML(paste0("Last checked for new block: ", 53 | shiny::textOutput("last_update_time", inline = TRUE), " UTC"))), 54 | shiny::br(), 55 | # golem::golem_welcome_page() # Remove this line to start building your UI 56 | plotOutput("plot1", inline = TRUE), 57 | # inline = TRUE means that it displays the plot with dimensions specified on the server side 58 | ), 59 | shiny::tabPanel("📈 Blocks mined by mining pools", 60 | shiny::br(), 61 | shiny::h5(shiny::HTML('Below is a line chart of the percentage of blocks mined by each mining pool. Over long intervals, the percentage of blocks mined by each mining pool can help assess certain risks in the Monero ecosystem. A malicious mining pool that acquires a majority of mining hashpower for a period of time can cause problems for ordinary users and other miners, depending on its choices:')), 62 | shiny::br(), 63 | shiny::h3(shiny::HTML('Double-spend attack')), 64 | shiny::br(), 65 | shiny::h5(shiny::HTML('Arguably the most harmful behavior of a majority-hashpower miner, often known simply as a "51% attack", is a double-spend attack. Satoshi Nakamoto, the creator of bitcoin, described it in section 11 of his 2008 bitcoin white paper:')), 66 | shiny::h5(shiny::HTML('
We consider the scenario of an attacker trying to generate an alternate chain faster than the honest chain. Even if this is accomplished, it does not throw the system open to arbitrary changes, such as creating value out of thin air or taking money that never belonged to the attacker. Nodes are not going to accept an invalid transaction as payment, and honest nodes will never accept a block containing them. An attacker can only try to change one of his own transactions to take back money he recently spent.
')), 67 | shiny::br(), 68 | shiny::h5(shiny::HTML('To execute the double-spend attack, a miner would have to send Monero coins to a victim, such as a merchant or centralized exchange. The victim would wait a certain number of block confirmations, depending on the victim\'s preference, and then send an irretrievable item to the miner, such as a physical good shipped in the mail or coins of another type of cryptocurrency.')), 69 | shiny::br(), 70 | shiny::h5(shiny::HTML('Meanwhile, the miner would be mining an alternative chain in secret that contains a transaction that contradicts the "payment" to the victim. Once the malicious miner\'s chain was long enough and enough blocks on the honest public chain are confirmed, the miner would broadcast the secret chain, which causes a "blockchain reorganization" and reverses the payment to the victim.')), 71 | shiny::br(), 72 | shiny::h5(shiny::HTML('Such an event would be observable to everyone running a Monero node. The "Orphaned blocks" visualization on the previous page would show a long alternative chain of many blocks being orphaned by the network. Also, one or more transactions present in the alternative chain would not be present in the main chain, and vice versa. The majority hashpower miner cannot reveal private information about Monero transactions nor force honest Monero nodes to accept blocks that do not comply with the requirements of the consensus of Monero\'s blockchain protocol.')), 73 | shiny::br(), 74 | shiny::h3(shiny::HTML('Selfish mining all blocks')), 75 | shiny::br(), 76 | shiny::h5(shiny::HTML('A miner with majority hashpower could decide to reject all blocks of other miners and instead only build on top of the malicious miner\'s own blocks. This behavior would deprive all other miners of block reward revenue. There would be little direct disruption to ordinary users in this situation.')), 77 | shiny::br(), 78 | shiny::h3(shiny::HTML('Mining empty blocks')), 79 | shiny::br(), 80 | shiny::h5(shiny::HTML('If a majority-hashpower miner mines all blocks, it can choose to include zero transactions in all blocks. That would stop all new transactions from being confirmed on the blockchain. This behavior would cause a major disruption to all ordinary users until the miner is unwilling or unable to mine all empty blocks.')), 81 | shiny::br(), 82 | shiny::h3(shiny::HTML('Mining only certain transactions')), 83 | shiny::br(), 84 | shiny::h5(shiny::HTML('Instead of mining blocks with zero transactions, a miner could include only certain transactions in blocks. Monero transactions are mostly indistinguishable from one another, so it is not clear on what basis a miner would reject/accept transactions. However, the miner could demand a higher fee per transaction, at least.')), 85 | shiny::br(), 86 | shiny::h3(shiny::HTML('Chart')), 87 | shiny::br(), 88 | shiny::h5(shiny::HTML('The below chart aggregates the percentage of blocks each mining pool has mined in 6, 12, or 24 hour intervals. Mining blocks is a random process, but just as large sample sizes can provide reliable statistical estimates, large aggregation intervals can give a picture of actual hashpower of each mining pool. The Monero protocol aims to confirm a block about every two minutes on average. Therefore, about 180, 360, and 720 blocks should be produced in each 6, 12, and 24 hour interval, respectively, in normal circumstances.')), 89 | shiny::br(), 90 | shiny::h5(shiny::HTML('The time indicated on the horizontal axis is the time of the end of the measured interval, e.g. when the aggregation interval is set to 6 hours, the value at 18:00 UTC is the aggregate value between 12:00 UTC and 18:00 UTC. The data starts at August 8, 2025 at 12:00 UTC because almost all mining pools\' APIs had been added to the pool data collection tool by that time. Any known pools that are not in the top 5 pools are included in the "other known pools" category.')), 91 | shiny::br(), 92 | shiny::h5(shiny::HTML('Glide your mouse over the chart\'s lines to view exact numbers.')), 93 | plotly::plotlyOutput("plot2", height = "800px"), 94 | shiny::radioButtons("pool_aggregation_hours", "Number of hours in aggregation interval:", 95 | choices = c(6, 12, 24), selected = 12, inline = TRUE, width = "50%"), 96 | shiny::radioButtons("pool_percentage_or_number", "Display percentages or number of blocks:", 97 | choiceNames = c("Percentage of all blocks mined", "Number of blocks"), 98 | choiceValues = c("percentage", "number"), 99 | selected = "percentage", inline = FALSE, width = "50%"), 100 | shiny::checkboxGroupInput("which_pools", "Display these mining pools:", inline = TRUE), 101 | shiny::h5('Click to toggle dark mode: '), 102 | bslib::input_dark_mode(id = "dark_mode"), 103 | ) 104 | ), 105 | shiny::hr(), 106 | shiny::h5(shiny::HTML('Created by Rucknium at the Monero Research Lab')), 107 | shiny::h6(shiny::HTML('Pool mining data collected by monero-blocks, developed by DataHoarder.')) 108 | ) 109 | ) 110 | } 111 | 112 | #' Add external Resources to the Application 113 | #' 114 | #' This function is internally used to add external 115 | #' resources inside the Shiny application. 116 | #' 117 | #' @import shiny 118 | #' @importFrom golem add_resource_path activate_js favicon bundle_resources 119 | #' @noRd 120 | golem_add_external_resources <- function() { 121 | add_resource_path( 122 | "www", 123 | app_sys("app/www") 124 | ) 125 | 126 | tags$head( 127 | favicon(), 128 | bundle_resources( 129 | path = app_sys("app/www"), 130 | app_title = "xmrconsensus" 131 | ) 132 | # Add here other external resources 133 | # for example, you can add shinyalert::useShinyalert() 134 | ) 135 | } 136 | -------------------------------------------------------------------------------- /R/app_server.R: -------------------------------------------------------------------------------- 1 | #' The application server-side 2 | #' 3 | #' @param input,output,session Internal parameters for {shiny}. 4 | #' DO NOT REMOVE. 5 | #' @import shiny 6 | #' @noRd 7 | app_server <- function(input, output, session) { 8 | # Your application server logic 9 | 10 | alt_chain_plot_height <- reactiveVal(1000) 11 | current.chaintip.hash <- reactiveVal("") 12 | draw.new.plot <- reactiveVal(FALSE) 13 | last.update.time <- reactiveVal(as.character(round(Sys.time()))) 14 | 15 | unrestricted.rpc.url <- golem::get_golem_options("unrestricted.rpc.url") 16 | # https://github.com/ColinFay/golemexample#passing-arguments-to-run_app 17 | # http://127.0.0.1:18081 by default 18 | 19 | pool.chart.begin <- as.POSIXct("2025-08-08 12:00:00", tz = "UTC") 20 | 21 | 22 | observe({ 23 | input$n_blocks_display_chaintip 24 | input$n_blocks_display_after_orphan 25 | draw.new.plot(TRUE) 26 | # Trigger draw of new plot if either of these inputs change 27 | }) 28 | 29 | shiny::observe({ 30 | 31 | invalidateLater(75 * 1000) # 75 seconds. Good sync with monero-blocks running every 60 seconds. 32 | 33 | new.chaintip.hash <- rpc.req(unrestricted.rpc.url = unrestricted.rpc.url, 34 | method = "get_last_block_header", params = "")$result$block_header$hash 35 | 36 | 37 | # TODO: Cache plot for all users 38 | 39 | if ( draw.new.plot() ) { 40 | 41 | isolate(current.chaintip.hash(new.chaintip.hash)) 42 | 43 | result <- alt_chains_graph(unrestricted.rpc.url = unrestricted.rpc.url, 44 | n.blocks.display.chaintip = input$n_blocks_display_chaintip, 45 | n.blocks.display.after.orphan = input$n_blocks_display_after_orphan, 46 | mining.pool.data.available = golem::get_golem_options("mining.pool.data.available")) 47 | # https://github.com/ColinFay/golemexample#passing-arguments-to-run_app 48 | # TRUE by default 49 | 50 | output$orphaned_blocks_last_day_known <- 51 | renderText(result$orphaned.blocks["orphaned.blocks.last.day.known"]) 52 | 53 | output$orphaned_blocks_last_day_known_percent <- 54 | renderText(round( 100 * result$orphaned.blocks["orphaned.blocks.last.day.known"] / 720, digits = 2)) 55 | 56 | output$orphaned_blocks_last_day_unknown <- 57 | renderText(result$orphaned.blocks["orphaned.blocks.last.day.unknown"]) 58 | 59 | output$orphaned_blocks_last_day_unknown_percent <- 60 | renderText(round( 100 * result$orphaned.blocks["orphaned.blocks.last.day.unknown"] / 720, digits = 2)) 61 | 62 | isolate(alt_chain_plot_height(result$plot.height)) 63 | 64 | layout.raw <- igraph::layout_as_tree(result$igraph.plot.data, flip.y = FALSE) 65 | 66 | output$plot1 <- renderPlot({ 67 | # This is a workaround for incorrect edge plotting (likely, a bug 68 | # in the package) when the plot area is very tall. 69 | # First, create the plot area: 70 | 71 | if (input$dark_mode == "dark") { 72 | par(bg = "#1D1F21") 73 | # "#1D1F21" is "bs-secondary-bg" for bslib 74 | result$chain.attr[color == "pink", color := "darkred"] 75 | result$chain.attr[color == "lightgreen", color := "darkgreen"] 76 | result$chain.attr[color == "yellow", color := "yellow4"] 77 | } else { 78 | par(bg = "white") 79 | result$chain.attr[color == "darkred", color := "pink"] 80 | result$chain.attr[color == "darkgreen", color := "lightgreen"] 81 | result$chain.attr[color == "yellow4", color := "yellow"] 82 | # Need to the "else" so that toggle works between plot refreshes 83 | } 84 | 85 | if (input$tree_mode == "linear") { 86 | layout.raw[, 1] <- ifelse(result$chain.attr$is.alt.block, 0.5, -0.5) 87 | # Exact 0.5 values don't matter. The plot will re-scale the x axis. 88 | 89 | plot.margin <- c(-0.15, 0.45, -0.13, 1) 90 | # "The amount of empty space below, over, at the left and right of the plot" 91 | # No, probably it is the order of mar in par(): c(bottom, left, top, right) 92 | 93 | vertex.size <- 30 94 | } 95 | 96 | if (input$tree_mode == "tree") { 97 | plot.margin <- c(-0.15, 0.1, -0.13, 0.2) 98 | vertex.size <- 20 99 | } 100 | 101 | plot(result$igraph.plot.data, layout = layout.raw, 102 | main = "", 103 | asp = 0, 104 | edge.arrow.mode = 0, 105 | margin = plot.margin, 106 | ) 107 | 108 | # Allow plotted elements to fall outside of plotting region: 109 | par(xpd = TRUE) 110 | # Then erase it: 111 | rect(xleft = -5, ybottom = -5, xright = 5, ytop = 5, 112 | col = ifelse(input$dark_mode == "dark", "#1D1F21", "white")) 113 | 114 | # Then manually plot the edges, which will go below the other plotting 115 | # elements later. 116 | 117 | layout.rescaled <- layout.raw 118 | 119 | # https://stackoverflow.com/questions/66602071/r-scaling-a-vector-between-1-and-1 120 | rescale_minMax <- function(x){ 121 | 1 - (x - max(x)) / (min(x) - max(x)) 122 | } 123 | 124 | layout.rescaled[, 1] <- rescale_minMax(layout.rescaled[, 1]) * 2 - 1 125 | layout.rescaled[, 2] <- rescale_minMax(layout.rescaled[, 2]) * 2 - 1 126 | # Rescale the plot coordinate area : -1 to 1. 127 | 128 | 129 | 130 | edgelist <- igraph::as_edgelist(result$igraph.plot.data, names = FALSE) 131 | 132 | for (i in seq_len(nrow(edgelist))) { 133 | v.1 <- edgelist[i, 1] 134 | v.2 <- edgelist[i, 2] 135 | lines(layout.rescaled[c(v.1, v.2), 1], layout.rescaled[c(v.1, v.2), 2], 136 | lwd = 1, col = "gray") 137 | } 138 | 139 | # Finally, plot the main plot 140 | plot(result$igraph.plot.data, layout = layout.raw, 141 | add = TRUE, 142 | main = "", 143 | asp = 0, 144 | vertex.shape = result$chain.attr$shape, 145 | vertex.frame.color = "darkgray", 146 | vertex.size = vertex.size, 147 | edge.width = 0, 148 | edge.arrow.mode = 0, 149 | margin = plot.margin, 150 | vertex.label.family = "monospace", 151 | vertex.label.color = ifelse(input$dark_mode == "dark", "white", "black"), 152 | # https://stackoverflow.com/questions/64207220/rendering-plot-in-r-with-mono-spaced-family-font-does-not-display-characters-any 153 | vertex.color = result$chain.attr$color, 154 | vertex.label = result$chain.attr$label, 155 | vertex.label.cex = 0.9 156 | ) 157 | 158 | legend(x = -1.25, y = 2 + grconvertY(3, from = "inches", to = "user"), 159 | legend = c("Known pool", "Unknown pool or\nsolo miner"), 160 | fill = ifelse(input$dark_mode == rep("dark", 2), c("darkgreen", "darkred"), 161 | c("lightgreen", "pink")), 162 | cex = 1.5, 163 | text.col = ifelse(input$dark_mode == "dark", "white", "black"), 164 | border = ifelse(input$dark_mode == "dark", "white", "black"), 165 | bty = "n", horiz = TRUE) 166 | 167 | legend(x = -1.5, y = 2 + grconvertY(2.25, from = "inches", to = "user"), 168 | legend = c("Block containing zero transactions", 169 | "Block containing one or more transactions"), 170 | pch = c(1, 0), 171 | cex = 1.5, 172 | pt.cex = 2, 173 | text.col = ifelse(input$dark_mode == "dark", "white", "black"), 174 | col = ifelse(input$dark_mode == "dark", "white", "black"), 175 | bty = "n", horiz = FALSE) 176 | 177 | # Add dashed lines above and below omitted blocks 178 | vert.distance <- median(diff(sort(layout.rescaled[, 2]))) 179 | which.omitted <- result$chain.attr[, which(blocks.omitted > 1 & ! is.na(blocks.omitted) ) ] 180 | omitted.positions <- layout.rescaled[which.omitted, 2] 181 | abline(h = c(omitted.positions + vert.distance * 0.5, 182 | omitted.positions - vert.distance * 0.5), lty = "dashed", 183 | col = ifelse(input$dark_mode == "dark", "white", "black")) 184 | 185 | }, width = 500, height = alt_chain_plot_height() 186 | ) 187 | 188 | 189 | } 190 | 191 | isolate( draw.new.plot(current.chaintip.hash() != new.chaintip.hash )) 192 | 193 | isolate(last.update.time(as.character(round(Sys.time())))) 194 | output$last_update_time <- renderText(last.update.time()) 195 | 196 | }) 197 | 198 | 199 | 200 | 201 | 202 | 203 | observe({ 204 | if ( golem::get_golem_options("mining.pool.data.available") ) { 205 | # https://github.com/ColinFay/golemexample#passing-arguments-to-run_app 206 | # TRUE by default 207 | pools <- data.table::fread("data-raw/pools/blocks.csv", fill = TRUE) 208 | # fill = TRUE because CSV file format changed 209 | } else { 210 | pools <- structure(list(Height = integer(0), Id = character(0), 211 | Timestamp = structure(numeric(0), class = "integer64"), 212 | Reward = character(0), Pool = character(0), Valid = logical(0), 213 | Miner = character(0)), row.names = c(NA, 0L), class = c("data.table", 214 | "data.frame")) 215 | } 216 | 217 | data.table::setnames(pools, tolower) # Applied tolower() function to all column names 218 | 219 | pools <- pools[timestamp / 1000 >= pool.chart.begin, ] 220 | # Timestamp is in milliseconds 221 | # Ignoring whether block was added to main chain, for simplicity 222 | 223 | pools.tabulation <- pools[, .(n.blocks = .N), by = "pool"] 224 | data.table::setorder(pools.tabulation, -n.blocks) 225 | updateCheckboxGroupInput(session, "which_pools", 226 | label = NULL, 227 | choices = c("unknown", pools.tabulation$pool), 228 | selected = c("unknown", pools.tabulation$pool)) 229 | 230 | }) 231 | 232 | 233 | output$plot2 <- plotly::renderPlotly({ 234 | 235 | 236 | blocks.pools <- pool_blocks(unrestricted.rpc.url = unrestricted.rpc.url, 237 | aggregation.hours = input$pool_aggregation_hours, which.pools = input$which_pools, 238 | pool.chart.begin = pool.chart.begin) 239 | 240 | if (input$pool_percentage_or_number == "percentage") { 241 | blocks.pools[, display.data := round(share.blocks * 100, digits = 2)] 242 | } 243 | if (input$pool_percentage_or_number == "number") { 244 | blocks.pools[, display.data := n.blocks] 245 | } 246 | 247 | plotly::plot_ly(x = ~ blocks.pools$timestamp.binned, line = list(width = 5)) |> 248 | plotly::add_lines(y = ~ blocks.pools$display.data, 249 | color = ~ factor(blocks.pools$pool) 250 | ) |> 251 | plotly::layout( 252 | title = list(text = paste0("Blocks mined by Monero mining pools: ", 253 | input$pool_aggregation_hours, "-hour intervals")), 254 | margin = list(t = 100, l = 0, r = 0), 255 | hovermode = "x", 256 | plot_bgcolor= ifelse(input$dark_mode == "dark", "#1D1F21", "#fff"), 257 | paper_bgcolor = ifelse(input$dark_mode == "dark", "#1D1F21", "#fff"), 258 | font = list(color = ifelse(input$dark_mode == "dark", "#fff", "#444"), 259 | size = 18), 260 | xaxis = list( 261 | title = "Time in UTC time zone", 262 | gridcolor = ifelse(input$dark_mode == "dark", "#444", "lightgray")), 263 | yaxis = list( 264 | title = ifelse(input$pool_percentage_or_number == "percentage", 265 | "Percentage of blocks mined during interval", "Number of blocks mined during interval"), 266 | gridcolor = ifelse(input$dark_mode == "dark", "#444", "lightgray"), 267 | rangemode = "tozero", 268 | zerolinecolor = ifelse(input$dark_mode == "dark", "#fff", "#1D1F21"), 269 | zerolinewidth = 2, 270 | side = "right", 271 | ticksuffix = ifelse(input$pool_percentage_or_number == "percentage", "%", "")), 272 | # https://stackoverflow.com/questions/44638590/format-axis-tick-labels-to-percentage-in-plotly 273 | legend = list(orientation = "h", xanchor = "center", x = 0.5, yanchor = "top", y = 1.05) 274 | ) |> 275 | plotly::config(displayModeBar = FALSE) 276 | 277 | 278 | 279 | 280 | }) 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | } 289 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU Affero General Public License 2 | ================================= 3 | 4 | _Version 3, 19 November 2007_ 5 | _Copyright (C) 2007 Free Software Foundation, Inc. <>_ 6 | 7 | Everyone is permitted to copy and distribute verbatim copies of this 8 | license document, but changing it is not allowed. 9 | 10 | ## Preamble 11 | 12 | The GNU Affero General Public License is a free, copyleft license for 13 | software and other kinds of works, specifically designed to ensure 14 | cooperation with the community in the case of network server software. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | our General Public Licenses are intended to guarantee your freedom to 19 | share and change all versions of a program--to make sure it remains 20 | free software for all its users. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | Developers that use our General Public Licenses protect your rights 30 | with two steps: (1) assert copyright on the software, and (2) offer 31 | you this License which gives you legal permission to copy, distribute 32 | and/or modify the software. 33 | 34 | A secondary benefit of defending all users' freedom is that 35 | improvements made in alternate versions of the program, if they 36 | receive widespread use, become available for other developers to 37 | incorporate. Many developers of free software are heartened and 38 | encouraged by the resulting cooperation. However, in the case of 39 | software used on network servers, this result may fail to come about. 40 | The GNU General Public License permits making a modified version and 41 | letting the public access it on a server without ever releasing its 42 | source code to the public. 43 | 44 | The GNU Affero General Public License is designed specifically to 45 | ensure that, in such cases, the modified source code becomes available 46 | to the community. It requires the operator of a network server to 47 | provide the source code of the modified version running there to the 48 | users of that server. Therefore, public use of a modified version, on 49 | a publicly accessible server, gives the public access to the source 50 | code of the modified version. 51 | 52 | An older license, called the Affero General Public License and 53 | published by Affero, was designed to accomplish similar goals. This is 54 | a different license, not a version of the Affero GPL, but Affero has 55 | released a new version of the Affero GPL which permits relicensing 56 | under this license. 57 | 58 | The precise terms and conditions for copying, distribution and 59 | modification follow. 60 | 61 | ## TERMS AND CONDITIONS 62 | 63 | ### 0. Definitions. 64 | 65 | "This License" refers to version 3 of the GNU Affero General Public 66 | License. 67 | 68 | "Copyright" also means copyright-like laws that apply to other kinds 69 | of works, such as semiconductor masks. 70 | 71 | "The Program" refers to any copyrightable work licensed under this 72 | License. Each licensee is addressed as "you". "Licensees" and 73 | "recipients" may be individuals or organizations. 74 | 75 | To "modify" a work means to copy from or adapt all or part of the work 76 | in a fashion requiring copyright permission, other than the making of 77 | an exact copy. The resulting work is called a "modified version" of 78 | the earlier work or a work "based on" the earlier work. 79 | 80 | A "covered work" means either the unmodified Program or a work based 81 | on the Program. 82 | 83 | To "propagate" a work means to do anything with it that, without 84 | permission, would make you directly or secondarily liable for 85 | infringement under applicable copyright law, except executing it on a 86 | computer or modifying a private copy. Propagation includes copying, 87 | distribution (with or without modification), making available to the 88 | public, and in some countries other activities as well. 89 | 90 | To "convey" a work means any kind of propagation that enables other 91 | parties to make or receive copies. Mere interaction with a user 92 | through a computer network, with no transfer of a copy, is not 93 | conveying. 94 | 95 | An interactive user interface displays "Appropriate Legal Notices" to 96 | the extent that it includes a convenient and prominently visible 97 | feature that (1) displays an appropriate copyright notice, and (2) 98 | tells the user that there is no warranty for the work (except to the 99 | extent that warranties are provided), that licensees may convey the 100 | work under this License, and how to view a copy of this License. If 101 | the interface presents a list of user commands or options, such as a 102 | menu, a prominent item in the list meets this criterion. 103 | 104 | ### 1. Source Code. 105 | 106 | The "source code" for a work means the preferred form of the work for 107 | making modifications to it. "Object code" means any non-source form of 108 | a work. 109 | 110 | A "Standard Interface" means an interface that either is an official 111 | standard defined by a recognized standards body, or, in the case of 112 | interfaces specified for a particular programming language, one that 113 | is widely used among developers working in that language. 114 | 115 | The "System Libraries" of an executable work include anything, other 116 | than the work as a whole, that (a) is included in the normal form of 117 | packaging a Major Component, but which is not part of that Major 118 | Component, and (b) serves only to enable use of the work with that 119 | Major Component, or to implement a Standard Interface for which an 120 | implementation is available to the public in source code form. A 121 | "Major Component", in this context, means a major essential component 122 | (kernel, window system, and so on) of the specific operating system 123 | (if any) on which the executable work runs, or a compiler used to 124 | produce the work, or an object code interpreter used to run it. 125 | 126 | The "Corresponding Source" for a work in object code form means all 127 | the source code needed to generate, install, and (for an executable 128 | work) run the object code and to modify the work, including scripts to 129 | control those activities. However, it does not include the work's 130 | System Libraries, or general-purpose tools or generally available free 131 | programs which are used unmodified in performing those activities but 132 | which are not part of the work. For example, Corresponding Source 133 | includes interface definition files associated with source files for 134 | the work, and the source code for shared libraries and dynamically 135 | linked subprograms that the work is specifically designed to require, 136 | such as by intimate data communication or control flow between those 137 | subprograms and other parts of the work. 138 | 139 | The Corresponding Source need not include anything that users can 140 | regenerate automatically from other parts of the Corresponding Source. 141 | 142 | The Corresponding Source for a work in source code form is that same 143 | work. 144 | 145 | ### 2. Basic Permissions. 146 | 147 | All rights granted under this License are granted for the term of 148 | copyright on the Program, and are irrevocable provided the stated 149 | conditions are met. This License explicitly affirms your unlimited 150 | permission to run the unmodified Program. The output from running a 151 | covered work is covered by this License only if the output, given its 152 | content, constitutes a covered work. This License acknowledges your 153 | rights of fair use or other equivalent, as provided by copyright law. 154 | 155 | You may make, run and propagate covered works that you do not convey, 156 | without conditions so long as your license otherwise remains in force. 157 | You may convey covered works to others for the sole purpose of having 158 | them make modifications exclusively for you, or provide you with 159 | facilities for running those works, provided that you comply with the 160 | terms of this License in conveying all material for which you do not 161 | control copyright. Those thus making or running the covered works for 162 | you must do so exclusively on your behalf, under your direction and 163 | control, on terms that prohibit them from making any copies of your 164 | copyrighted material outside their relationship with you. 165 | 166 | Conveying under any other circumstances is permitted solely under the 167 | conditions stated below. Sublicensing is not allowed; section 10 makes 168 | it unnecessary. 169 | 170 | ### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 171 | 172 | No covered work shall be deemed part of an effective technological 173 | measure under any applicable law fulfilling obligations under article 174 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 175 | similar laws prohibiting or restricting circumvention of such 176 | measures. 177 | 178 | When you convey a covered work, you waive any legal power to forbid 179 | circumvention of technological measures to the extent such 180 | circumvention is effected by exercising rights under this License with 181 | respect to the covered work, and you disclaim any intention to limit 182 | operation or modification of the work as a means of enforcing, against 183 | the work's users, your or third parties' legal rights to forbid 184 | circumvention of technological measures. 185 | 186 | ### 4. Conveying Verbatim Copies. 187 | 188 | You may convey verbatim copies of the Program's source code as you 189 | receive it, in any medium, provided that you conspicuously and 190 | appropriately publish on each copy an appropriate copyright notice; 191 | keep intact all notices stating that this License and any 192 | non-permissive terms added in accord with section 7 apply to the code; 193 | keep intact all notices of the absence of any warranty; and give all 194 | recipients a copy of this License along with the Program. 195 | 196 | You may charge any price or no price for each copy that you convey, 197 | and you may offer support or warranty protection for a fee. 198 | 199 | ### 5. Conveying Modified Source Versions. 200 | 201 | You may convey a work based on the Program, or the modifications to 202 | produce it from the Program, in the form of source code under the 203 | terms of section 4, provided that you also meet all of these 204 | conditions: 205 | 206 | - a) The work must carry prominent notices stating that you modified 207 | it, and giving a relevant date. 208 | - b) The work must carry prominent notices stating that it is 209 | released under this License and any conditions added under 210 | section 7. This requirement modifies the requirement in section 4 211 | to "keep intact all notices". 212 | - c) You must license the entire work, as a whole, under this 213 | License to anyone who comes into possession of a copy. This 214 | License will therefore apply, along with any applicable section 7 215 | additional terms, to the whole of the work, and all its parts, 216 | regardless of how they are packaged. This License gives no 217 | permission to license the work in any other way, but it does not 218 | invalidate such permission if you have separately received it. 219 | - d) If the work has interactive user interfaces, each must display 220 | Appropriate Legal Notices; however, if the Program has interactive 221 | interfaces that do not display Appropriate Legal Notices, your 222 | work need not make them do so. 223 | 224 | A compilation of a covered work with other separate and independent 225 | works, which are not by their nature extensions of the covered work, 226 | and which are not combined with it such as to form a larger program, 227 | in or on a volume of a storage or distribution medium, is called an 228 | "aggregate" if the compilation and its resulting copyright are not 229 | used to limit the access or legal rights of the compilation's users 230 | beyond what the individual works permit. Inclusion of a covered work 231 | in an aggregate does not cause this License to apply to the other 232 | parts of the aggregate. 233 | 234 | ### 6. Conveying Non-Source Forms. 235 | 236 | You may convey a covered work in object code form under the terms of 237 | sections 4 and 5, provided that you also convey the machine-readable 238 | Corresponding Source under the terms of this License, in one of these 239 | ways: 240 | 241 | - a) Convey the object code in, or embodied in, a physical product 242 | (including a physical distribution medium), accompanied by the 243 | Corresponding Source fixed on a durable physical medium 244 | customarily used for software interchange. 245 | - b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the Corresponding 255 | Source from a network server at no charge. 256 | - c) Convey individual copies of the object code with a copy of the 257 | written offer to provide the Corresponding Source. This 258 | alternative is allowed only occasionally and noncommercially, and 259 | only if you received the object code with such an offer, in accord 260 | with subsection 6b. 261 | - d) Convey the object code by offering access from a designated 262 | place (gratis or for a charge), and offer equivalent access to the 263 | Corresponding Source in the same way through the same place at no 264 | further charge. You need not require recipients to copy the 265 | Corresponding Source along with the object code. If the place to 266 | copy the object code is a network server, the Corresponding Source 267 | may be on a different server (operated by you or a third party) 268 | that supports equivalent copying facilities, provided you maintain 269 | clear directions next to the object code saying where to find the 270 | Corresponding Source. Regardless of what server hosts the 271 | Corresponding Source, you remain obligated to ensure that it is 272 | available for as long as needed to satisfy these requirements. 273 | - e) Convey the object code using peer-to-peer transmission, 274 | provided you inform other peers where the object code and 275 | Corresponding Source of the work are being offered to the general 276 | public at no charge under subsection 6d. 277 | 278 | A separable portion of the object code, whose source code is excluded 279 | from the Corresponding Source as a System Library, need not be 280 | included in conveying the object code work. 281 | 282 | A "User Product" is either (1) a "consumer product", which means any 283 | tangible personal property which is normally used for personal, 284 | family, or household purposes, or (2) anything designed or sold for 285 | incorporation into a dwelling. In determining whether a product is a 286 | consumer product, doubtful cases shall be resolved in favor of 287 | coverage. For a particular product received by a particular user, 288 | "normally used" refers to a typical or common use of that class of 289 | product, regardless of the status of the particular user or of the way 290 | in which the particular user actually uses, or expects or is expected 291 | to use, the product. A product is a consumer product regardless of 292 | whether the product has substantial commercial, industrial or 293 | non-consumer uses, unless such uses represent the only significant 294 | mode of use of the product. 295 | 296 | "Installation Information" for a User Product means any methods, 297 | procedures, authorization keys, or other information required to 298 | install and execute modified versions of a covered work in that User 299 | Product from a modified version of its Corresponding Source. The 300 | information must suffice to ensure that the continued functioning of 301 | the modified object code is in no case prevented or interfered with 302 | solely because modification has been made. 303 | 304 | If you convey an object code work under this section in, or with, or 305 | specifically for use in, a User Product, and the conveying occurs as 306 | part of a transaction in which the right of possession and use of the 307 | User Product is transferred to the recipient in perpetuity or for a 308 | fixed term (regardless of how the transaction is characterized), the 309 | Corresponding Source conveyed under this section must be accompanied 310 | by the Installation Information. But this requirement does not apply 311 | if neither you nor any third party retains the ability to install 312 | modified object code on the User Product (for example, the work has 313 | been installed in ROM). 314 | 315 | The requirement to provide Installation Information does not include a 316 | requirement to continue to provide support service, warranty, or 317 | updates for a work that has been modified or installed by the 318 | recipient, or for the User Product in which it has been modified or 319 | installed. Access to a network may be denied when the modification 320 | itself materially and adversely affects the operation of the network 321 | or violates the rules and protocols for communication across the 322 | network. 323 | 324 | Corresponding Source conveyed, and Installation Information provided, 325 | in accord with this section must be in a format that is publicly 326 | documented (and with an implementation available to the public in 327 | source code form), and must require no special password or key for 328 | unpacking, reading or copying. 329 | 330 | ### 7. Additional Terms. 331 | 332 | "Additional permissions" are terms that supplement the terms of this 333 | License by making exceptions from one or more of its conditions. 334 | Additional permissions that are applicable to the entire Program shall 335 | be treated as though they were included in this License, to the extent 336 | that they are valid under applicable law. If additional permissions 337 | apply only to part of the Program, that part may be used separately 338 | under those permissions, but the entire Program remains governed by 339 | this License without regard to the additional permissions. 340 | 341 | When you convey a copy of a covered work, you may at your option 342 | remove any additional permissions from that copy, or from any part of 343 | it. (Additional permissions may be written to require their own 344 | removal in certain cases when you modify the work.) You may place 345 | additional permissions on material, added by you to a covered work, 346 | for which you have or can give appropriate copyright permission. 347 | 348 | Notwithstanding any other provision of this License, for material you 349 | add to a covered work, you may (if authorized by the copyright holders 350 | of that material) supplement the terms of this License with terms: 351 | 352 | - a) Disclaiming warranty or limiting liability differently from the 353 | terms of sections 15 and 16 of this License; or 354 | - b) Requiring preservation of specified reasonable legal notices or 355 | author attributions in that material or in the Appropriate Legal 356 | Notices displayed by works containing it; or 357 | - c) Prohibiting misrepresentation of the origin of that material, 358 | or requiring that modified versions of such material be marked in 359 | reasonable ways as different from the original version; or 360 | - d) Limiting the use for publicity purposes of names of licensors 361 | or authors of the material; or 362 | - e) Declining to grant rights under trademark law for use of some 363 | trade names, trademarks, or service marks; or 364 | - f) Requiring indemnification of licensors and authors of that 365 | material by anyone who conveys the material (or modified versions 366 | of it) with contractual assumptions of liability to the recipient, 367 | for any liability that these contractual assumptions directly 368 | impose on those licensors and authors. 369 | 370 | All other non-permissive additional terms are considered "further 371 | restrictions" within the meaning of section 10. If the Program as you 372 | received it, or any part of it, contains a notice stating that it is 373 | governed by this License along with a term that is a further 374 | restriction, you may remove that term. If a license document contains 375 | a further restriction but permits relicensing or conveying under this 376 | License, you may add to a covered work material governed by the terms 377 | of that license document, provided that the further restriction does 378 | not survive such relicensing or conveying. 379 | 380 | If you add terms to a covered work in accord with this section, you 381 | must place, in the relevant source files, a statement of the 382 | additional terms that apply to those files, or a notice indicating 383 | where to find the applicable terms. 384 | 385 | Additional terms, permissive or non-permissive, may be stated in the 386 | form of a separately written license, or stated as exceptions; the 387 | above requirements apply either way. 388 | 389 | ### 8. Termination. 390 | 391 | You may not propagate or modify a covered work except as expressly 392 | provided under this License. Any attempt otherwise to propagate or 393 | modify it is void, and will automatically terminate your rights under 394 | this License (including any patent licenses granted under the third 395 | paragraph of section 11). 396 | 397 | However, if you cease all violation of this License, then your license 398 | from a particular copyright holder is reinstated (a) provisionally, 399 | unless and until the copyright holder explicitly and finally 400 | terminates your license, and (b) permanently, if the copyright holder 401 | fails to notify you of the violation by some reasonable means prior to 402 | 60 days after the cessation. 403 | 404 | Moreover, your license from a particular copyright holder is 405 | reinstated permanently if the copyright holder notifies you of the 406 | violation by some reasonable means, this is the first time you have 407 | received notice of violation of this License (for any work) from that 408 | copyright holder, and you cure the violation prior to 30 days after 409 | your receipt of the notice. 410 | 411 | Termination of your rights under this section does not terminate the 412 | licenses of parties who have received copies or rights from you under 413 | this License. If your rights have been terminated and not permanently 414 | reinstated, you do not qualify to receive new licenses for the same 415 | material under section 10. 416 | 417 | ### 9. Acceptance Not Required for Having Copies. 418 | 419 | You are not required to accept this License in order to receive or run 420 | a copy of the Program. Ancillary propagation of a covered work 421 | occurring solely as a consequence of using peer-to-peer transmission 422 | to receive a copy likewise does not require acceptance. However, 423 | nothing other than this License grants you permission to propagate or 424 | modify any covered work. These actions infringe copyright if you do 425 | not accept this License. Therefore, by modifying or propagating a 426 | covered work, you indicate your acceptance of this License to do so. 427 | 428 | ### 10. Automatic Licensing of Downstream Recipients. 429 | 430 | Each time you convey a covered work, the recipient automatically 431 | receives a license from the original licensors, to run, modify and 432 | propagate that work, subject to this License. You are not responsible 433 | for enforcing compliance by third parties with this License. 434 | 435 | An "entity transaction" is a transaction transferring control of an 436 | organization, or substantially all assets of one, or subdividing an 437 | organization, or merging organizations. If propagation of a covered 438 | work results from an entity transaction, each party to that 439 | transaction who receives a copy of the work also receives whatever 440 | licenses to the work the party's predecessor in interest had or could 441 | give under the previous paragraph, plus a right to possession of the 442 | Corresponding Source of the work from the predecessor in interest, if 443 | the predecessor has it or can get it with reasonable efforts. 444 | 445 | You may not impose any further restrictions on the exercise of the 446 | rights granted or affirmed under this License. For example, you may 447 | not impose a license fee, royalty, or other charge for exercise of 448 | rights granted under this License, and you may not initiate litigation 449 | (including a cross-claim or counterclaim in a lawsuit) alleging that 450 | any patent claim is infringed by making, using, selling, offering for 451 | sale, or importing the Program or any portion of it. 452 | 453 | ### 11. Patents. 454 | 455 | A "contributor" is a copyright holder who authorizes use under this 456 | License of the Program or a work on which the Program is based. The 457 | work thus licensed is called the contributor's "contributor version". 458 | 459 | A contributor's "essential patent claims" are all patent claims owned 460 | or controlled by the contributor, whether already acquired or 461 | hereafter acquired, that would be infringed by some manner, permitted 462 | by this License, of making, using, or selling its contributor version, 463 | but do not include claims that would be infringed only as a 464 | consequence of further modification of the contributor version. For 465 | purposes of this definition, "control" includes the right to grant 466 | patent sublicenses in a manner consistent with the requirements of 467 | this License. 468 | 469 | Each contributor grants you a non-exclusive, worldwide, royalty-free 470 | patent license under the contributor's essential patent claims, to 471 | make, use, sell, offer for sale, import and otherwise run, modify and 472 | propagate the contents of its contributor version. 473 | 474 | In the following three paragraphs, a "patent license" is any express 475 | agreement or commitment, however denominated, not to enforce a patent 476 | (such as an express permission to practice a patent or covenant not to 477 | sue for patent infringement). To "grant" such a patent license to a 478 | party means to make such an agreement or commitment not to enforce a 479 | patent against the party. 480 | 481 | If you convey a covered work, knowingly relying on a patent license, 482 | and the Corresponding Source of the work is not available for anyone 483 | to copy, free of charge and under the terms of this License, through a 484 | publicly available network server or other readily accessible means, 485 | then you must either (1) cause the Corresponding Source to be so 486 | available, or (2) arrange to deprive yourself of the benefit of the 487 | patent license for this particular work, or (3) arrange, in a manner 488 | consistent with the requirements of this License, to extend the patent 489 | license to downstream recipients. "Knowingly relying" means you have 490 | actual knowledge that, but for the patent license, your conveying the 491 | covered work in a country, or your recipient's use of the covered work 492 | in a country, would infringe one or more identifiable patents in that 493 | country that you have reason to believe are valid. 494 | 495 | If, pursuant to or in connection with a single transaction or 496 | arrangement, you convey, or propagate by procuring conveyance of, a 497 | covered work, and grant a patent license to some of the parties 498 | receiving the covered work authorizing them to use, propagate, modify 499 | or convey a specific copy of the covered work, then the patent license 500 | you grant is automatically extended to all recipients of the covered 501 | work and works based on it. 502 | 503 | A patent license is "discriminatory" if it does not include within the 504 | scope of its coverage, prohibits the exercise of, or is conditioned on 505 | the non-exercise of one or more of the rights that are specifically 506 | granted under this License. You may not convey a covered work if you 507 | are a party to an arrangement with a third party that is in the 508 | business of distributing software, under which you make payment to the 509 | third party based on the extent of your activity of conveying the 510 | work, and under which the third party grants, to any of the parties 511 | who would receive the covered work from you, a discriminatory patent 512 | license (a) in connection with copies of the covered work conveyed by 513 | you (or copies made from those copies), or (b) primarily for and in 514 | connection with specific products or compilations that contain the 515 | covered work, unless you entered into that arrangement, or that patent 516 | license was granted, prior to 28 March 2007. 517 | 518 | Nothing in this License shall be construed as excluding or limiting 519 | any implied license or other defenses to infringement that may 520 | otherwise be available to you under applicable patent law. 521 | 522 | ### 12. No Surrender of Others' Freedom. 523 | 524 | If conditions are imposed on you (whether by court order, agreement or 525 | otherwise) that contradict the conditions of this License, they do not 526 | excuse you from the conditions of this License. If you cannot convey a 527 | covered work so as to satisfy simultaneously your obligations under 528 | this License and any other pertinent obligations, then as a 529 | consequence you may not convey it at all. For example, if you agree to 530 | terms that obligate you to collect a royalty for further conveying 531 | from those to whom you convey the Program, the only way you could 532 | satisfy both those terms and this License would be to refrain entirely 533 | from conveying the Program. 534 | 535 | ### 13. Remote Network Interaction; Use with the GNU General Public License. 536 | 537 | Notwithstanding any other provision of this License, if you modify the 538 | Program, your modified version must prominently offer all users 539 | interacting with it remotely through a computer network (if your 540 | version supports such interaction) an opportunity to receive the 541 | Corresponding Source of your version by providing access to the 542 | Corresponding Source from a network server at no charge, through some 543 | standard or customary means of facilitating copying of software. This 544 | Corresponding Source shall include the Corresponding Source for any 545 | work covered by version 3 of the GNU General Public License that is 546 | incorporated pursuant to the following paragraph. 547 | 548 | Notwithstanding any other provision of this License, you have 549 | permission to link or combine any covered work with a work licensed 550 | under version 3 of the GNU General Public License into a single 551 | combined work, and to convey the resulting work. The terms of this 552 | License will continue to apply to the part which is the covered work, 553 | but the work with which it is combined will remain governed by version 554 | 3 of the GNU General Public License. 555 | 556 | ### 14. Revised Versions of this License. 557 | 558 | The Free Software Foundation may publish revised and/or new versions 559 | of the GNU Affero General Public License from time to time. Such new 560 | versions will be similar in spirit to the present version, but may 561 | differ in detail to address new problems or concerns. 562 | 563 | Each version is given a distinguishing version number. If the Program 564 | specifies that a certain numbered version of the GNU Affero General 565 | Public License "or any later version" applies to it, you have the 566 | option of following the terms and conditions either of that numbered 567 | version or of any later version published by the Free Software 568 | Foundation. If the Program does not specify a version number of the 569 | GNU Affero General Public License, you may choose any version ever 570 | published by the Free Software Foundation. 571 | 572 | If the Program specifies that a proxy can decide which future versions 573 | of the GNU Affero General Public License can be used, that proxy's 574 | public statement of acceptance of a version permanently authorizes you 575 | to choose that version for the Program. 576 | 577 | Later license versions may give you additional or different 578 | permissions. However, no additional obligations are imposed on any 579 | author or copyright holder as a result of your choosing to follow a 580 | later version. 581 | 582 | ### 15. Disclaimer of Warranty. 583 | 584 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 585 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 586 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 587 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 588 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 589 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 590 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 591 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 592 | CORRECTION. 593 | 594 | ### 16. Limitation of Liability. 595 | 596 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 597 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR 598 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 599 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 600 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 601 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 602 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 603 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 604 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 605 | 606 | ### 17. Interpretation of Sections 15 and 16. 607 | 608 | If the disclaimer of warranty and limitation of liability provided 609 | above cannot be given local legal effect according to their terms, 610 | reviewing courts shall apply local law that most closely approximates 611 | an absolute waiver of all civil liability in connection with the 612 | Program, unless a warranty or assumption of liability accompanies a 613 | copy of the Program in return for a fee. 614 | 615 | END OF TERMS AND CONDITIONS 616 | 617 | ## How to Apply These Terms to Your New Programs 618 | 619 | If you develop a new program, and you want it to be of the greatest 620 | possible use to the public, the best way to achieve this is to make it 621 | free software which everyone can redistribute and change under these 622 | terms. 623 | 624 | To do so, attach the following notices to the program. It is safest to 625 | attach them to the start of each source file to most effectively state 626 | the exclusion of warranty; and each file should have at least the 627 | "copyright" line and a pointer to where the full notice is found. 628 | 629 | 630 | Copyright (C) 631 | 632 | This program is free software: you can redistribute it and/or modify 633 | it under the terms of the GNU Affero General Public License as 634 | published by the Free Software Foundation, either version 3 of the 635 | License, or (at your option) any later version. 636 | 637 | This program is distributed in the hope that it will be useful, 638 | but WITHOUT ANY WARRANTY; without even the implied warranty of 639 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 640 | GNU Affero General Public License for more details. 641 | 642 | You should have received a copy of the GNU Affero General Public License 643 | along with this program. If not, see . 644 | 645 | Also add information on how to contact you by electronic and paper 646 | mail. 647 | 648 | If your software can interact with users remotely through a computer 649 | network, you should also make sure that it provides a way for users to 650 | get its source. For example, if your program is a web application, its 651 | interface could display a "Source" link that leads users to an archive 652 | of the code. There are many ways you could offer source, and different 653 | solutions will be better for different programs; see section 13 for 654 | the specific requirements. 655 | 656 | You should also get your employer (if you work as a programmer) or 657 | school, if any, to sign a "copyright disclaimer" for the program, if 658 | necessary. For more information on this, and how to apply and follow 659 | the GNU AGPL, see . 660 | --------------------------------------------------------------------------------