R/txs_api.R

# GraphSense API
#
# GraphSense API provides programmatic access to various ledgers' addresses, entities, blocks, transactions and tags for automated and highly efficient forensics tasks.
#
# The version of the OpenAPI document: 1.0.1
# Contact: contact@ikna.io
# Generated by: https://openapi-generator.tech

#' @docType class
#' @title Txs operations
#' @description graphsense.Txs
#' @format An \code{R6Class} generator object
#' @field apiClient Handles the client-server communication.
#'
#' @section Methods:
#' \describe{
#' \strong{ GetTx } \emph{ Returns details of a specific transaction identified by its hash. }
#' 
#'
#' \itemize{
#' \item \emph{ @param } currency character
#' \item \emph{ @param } tx.hash character
#' \item \emph{ @param } include.io character
#' \item \emph{ @returnType } \link{Tx} \cr
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : Tx 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' \strong{ GetTxIo } \emph{ Returns input/output values of a specific transaction identified by its hash. }
#' 
#'
#' \itemize{
#' \item \emph{ @param } currency character
#' \item \emph{ @param } tx.hash character
#' \item \emph{ @param } io Enum < [inputs, outputs] > 
#' \item \emph{ @returnType } list( \link{tx_value} ) \cr
#'
#'
#' \item status code : 200 | OK
#'
#' \item return type : array[TxValue] 
#' \item response headers :
#'
#' \tabular{ll}{
#' }
#' }
#'
#' }
#'
#'
#' @examples
#' \dontrun{
#' ####################  GetTx  ####################
#'
#' library(graphsense)
#' var.currency <- 'btc' # character | The cryptocurrency code (e.g., btc)
#' var.tx.hash <- 'ab188013' # character | The transaction hash
#' var.include.io <- FALSE # character | Whether to include inputs/outputs of a transaction (UTXO only)
#'
#' #Returns details of a specific transaction identified by its hash.
#' api.instance <- TxsApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['Authorization'] <- 'WRITE_YOUR_API_KEY_HERE';
#'
#' result <- api.instance$GetTx(var.currency, var.tx.hash, include.io=var.include.io)
#'
#'
#' ####################  GetTxIo  ####################
#'
#' library(graphsense)
#' var.currency <- 'btc' # character | The cryptocurrency code (e.g., btc)
#' var.tx.hash <- 'ab188013' # character | The transaction hash
#' var.io <- 'outputs' # character | Input or outpus values of a transaction
#'
#' #Returns input/output values of a specific transaction identified by its hash.
#' api.instance <- TxsApi$new()
#'
#' #Configure API key authorization: api_key
#' api.instance$apiClient$apiKeys['Authorization'] <- 'WRITE_YOUR_API_KEY_HERE';
#'
#' result <- api.instance$GetTxIo(var.currency, var.tx.hash, var.io)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @export
TxsApi <- R6::R6Class(
  'TxsApi',
  public = list(
    apiClient = NULL,
    initialize = function(apiClient){
      if (!missing(apiClient)) {
        self$apiClient <- apiClient
      }
      else {
        self$apiClient <- ApiClient$new()
      }
    },
    GetTx = function(currency, tx.hash, include.io=FALSE, ...){
      apiResponse <- self$GetTxWithHttpInfo(currency, tx.hash, include.io, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    GetTxWithHttpInfo = function(currency, tx.hash, include.io=FALSE, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`currency`)) {
        stop("Missing required parameter `currency`.")
      }

      if (missing(`tx.hash`)) {
        stop("Missing required parameter `tx.hash`.")
      }

      queryParams['include_io'] <- include.io

      body <- NULL
      urlPath <- "/{currency}/txs/{tx_hash}"
      if (!missing(`currency`)) {
        urlPath <- gsub(paste0("\\{", "currency", "\\}"), URLencode(as.character(`currency`), reserved = TRUE), urlPath)
      }

      if (!missing(`tx.hash`)) {
        urlPath <- gsub(paste0("\\{", "tx_hash", "\\}"), URLencode(as.character(`tx.hash`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("Authorization" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["Authorization"]) > 0) {
        headerParams['Authorization'] <- paste(unlist(self$apiClient$apiKeys["Authorization"]), collapse='')
      }

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "Tx", loadNamespace("graphsense")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    },
    GetTxIo = function(currency, tx.hash, io, ...){
      apiResponse <- self$GetTxIoWithHttpInfo(currency, tx.hash, io, ...)
      resp <- apiResponse$response
      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        apiResponse$content
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        apiResponse
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        apiResponse
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        apiResponse
      }
    },

    GetTxIoWithHttpInfo = function(currency, tx.hash, io, ...){
      args <- list(...)
      queryParams <- list()
      headerParams <- c()

      if (missing(`currency`)) {
        stop("Missing required parameter `currency`.")
      }

      if (missing(`tx.hash`)) {
        stop("Missing required parameter `tx.hash`.")
      }

      if (missing(`io`)) {
        stop("Missing required parameter `io`.")
      }

      body <- NULL
      urlPath <- "/{currency}/txs/{tx_hash}/{io}"
      if (!missing(`currency`)) {
        urlPath <- gsub(paste0("\\{", "currency", "\\}"), URLencode(as.character(`currency`), reserved = TRUE), urlPath)
      }

      if (!missing(`tx.hash`)) {
        urlPath <- gsub(paste0("\\{", "tx_hash", "\\}"), URLencode(as.character(`tx.hash`), reserved = TRUE), urlPath)
      }

      if (!missing(`io`)) {
        urlPath <- gsub(paste0("\\{", "io", "\\}"), URLencode(as.character(`io`), reserved = TRUE), urlPath)
      }

      # API key authentication
      if ("Authorization" %in% names(self$apiClient$apiKeys) && nchar(self$apiClient$apiKeys["Authorization"]) > 0) {
        headerParams['Authorization'] <- paste(unlist(self$apiClient$apiKeys["Authorization"]), collapse='')
      }

      resp <- self$apiClient$CallApi(url = paste0(self$apiClient$basePath, urlPath),
                                 method = "GET",
                                 queryParams = queryParams,
                                 headerParams = headerParams,
                                 body = body,
                                 ...)

      if (httr::status_code(resp) >= 200 && httr::status_code(resp) <= 299) {
        deserializedRespObj <- tryCatch(
          self$apiClient$deserialize(resp, "array[TxValue]", loadNamespace("graphsense")),
          error = function(e){
             stop("Failed to deserialize response")
          }
        )
        ApiResponse$new(deserializedRespObj, resp)
      } else if (httr::status_code(resp) >= 300 && httr::status_code(resp) <= 399) {
        ApiResponse$new(paste("Server returned " , httr::status_code(resp) , " response status code."), resp)
      } else if (httr::status_code(resp) >= 400 && httr::status_code(resp) <= 499) {
        ApiResponse$new("API client error", resp)
      } else if (httr::status_code(resp) >= 500 && httr::status_code(resp) <= 599) {
        ApiResponse$new("API server error", resp)
      }
    }
  )
)
graphsense/rgraphsense documentation built on Sept. 2, 2022, 1:45 p.m.