{
  "openapi": "3.0.0",
  "info": {
    "description": "Merchant API is an additional service that miners can offer to merchants.\n\n**Note**: Merchant API uses [JSON Envelopes](https://bitbucket.org/nchteamnch/jsonenvelope/src/master/) for its responses.",
    "version": "0.1.0",
    "title": "Merchant API",
    "termsOfService": null,
    "contact": {
      "email": null
    },
    "license": {
      "name": "Open BSV License",
      "url": "https://bitcoinassociation.net/open-bsv-license/"
    }
  },
  "tags": [
    {
      "name": "fees",
      "externalDocs": {
        "description": "FeeSpec BRFC",
        "url": "https://bitbucket.org/nchteamnch/feespec"
      }
    },
    {
      "name": "transaction"
    }
  ],
  "paths": {
    "/feeQuote": {
      "get": {
        "tags": [
          "fees"
        ],
        "summary": "Get a fee quote",
        "description": "This endpoint returns a JSONEnvelope with a payload that contains the fees charged by a specific BSV miner.",
        "operationId": "getFeeQuote",
        "responses": {
          "200": {
            "description": "successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payload": {
                      "type": "string",
                      "format": "feeQuotePayload"
                    },
                    "signature": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "publicKey": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "encoding": {
                      "type": "string"
                    },
                    "mimetype": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-01-28T11:15:03.722Z\",\"expiryTime\":\"2020-01-28T11:25:03.722Z\",\"minerId\":\"03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031\",\"currentHighestBlockHash\":\"000000000000000001cedc3dec00ecd29943a275498e812e72b2afdf5df8814a\",\"currentHighestBlockHeight\":619574,\"minerReputation\":\"N/A\",\"fees\":[{\"feeType\":\"standard\",\"miningFee\":{\"satoshis\":1,\"bytes\":1},\"relayFee\":{\"satoshis\":1,\"bytes\":1}},{\"feeType\":\"data\",\"miningFee\":{\"satoshis\":1,\"bytes\":1},\"relayFee\":{\"satoshis\":1,\"bytes\":1}}]}",
                    "signature": "304402202a7f70855739a6948c00c2a85dd733f087c4f1ae4beb256c225eadab767d5e1d02207870c57728166f61b0334bd89640d6d6c26f31ada4aac42b29971ebfa5c414e1",
                    "publicKey": "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031",
                    "encoding": "UTF-8",
                    "mimetype": "application/json"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal Server Error",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "number"
                    },
                    "code": {
                      "type": "number"
                    },
                    "error": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "status": 500,
                    "code": 11,
                    "error": "Internal Server Error"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/tx": {
      "post": {
        "tags": [
          "transaction"
        ],
        "summary": "Submit a transaction",
        "description": "This endpoint is used to send a raw transaction to a miner for inclusion in the next block that the miner creates.",
        "operationId": "submitTransaction",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "rawtx": {
                    "type": "string",
                    "pattern": "[0-9a-fA-F]+"
                  }
                },
                "example": {
                  "rawtx": "0200000004cb64a27f369e1db5225b9825e1244e15bfa102398eb214e8d03905ab13b87cee000000006b483045022100b6cb74b027fc0fcc50467319f6c7eaa569b8a451ffb84962871ed74a5c8795830220275e145d19102a7975f730fbebd0084666ef5743cd4e4c96c75eee4efb28d0cc4121021d6c9c4cd7d51c8c8638cd0af2ddd55bd8cd6287feae23f7ee1066365fe55769feffffff96d579158e2e18a00cfddcc42c6f0da5d6c9fa5d8660b8b3f0302e26a0945c79010000006a47304402203b1bda23cd96bf22831036f91c69dcc621ed944057687d933fc5998049285e4d02205a6b3a8b228d222665f8cd60240ac834875a316a00ad6fc4598ef84dd3c39e9a4121038232b3b9edf26514b44f54ab91d631d7ad0041b07f841828e96cf6205071a030feffffff0278e158c0625d93e8682b2c919df42d1a1aff5833302222e0b1069ac2bf0948000000006a4730440220734af188e5534bf191ac28135f38ee1c5b91564ccca6c06b5aa027f72be8fa6902204c3c26dbb54d89b1872f4712745f31150e9f8e7477b479fe6b9a05e2ec36f4294121021d6c9c4cd7d51c8c8638cd0af2ddd55bd8cd6287feae23f7ee1066365fe55769feffffff4b782eeb156f0dc01c0bd717b86aa07ce688c6b6f84771a21ba001bdc5b027c6000000006a47304402202b168a98b5b144f20b903409b7b6341ed2adbee02cf6c040eea13691c3c4d83b0220714b8ddfdb5902b21ed3b2e30459b125dcecb7fba9fc48922cea54a8539728084121021d6c9c4cd7d51c8c8638cd0af2ddd55bd8cd6287feae23f7ee1066365fe55769feffffff0262746b12010000001976a914e7464c3ea395d9bd45f218e22e44b59b3ae14fb288ac005531aa0b0000001976a9146f67988ec4b7bf498c9164d76b52dffdc805ff8c88aced940900"
                }
              }
            }
          },
          "description": "raw transaction hex string",
          "required": true
        },
        "responses": {
          "200": {
            "description": "successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payload": {
                      "type": "string",
                      "format": "submitTransactionPayload"
                    },
                    "signature": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "publicKey": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "encoding": {
                      "type": "string"
                    },
                    "mimetype": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-01-15T11:40:29.826Z\",\"txid\":\"6bdbcfab0526d30e8d68279f79dff61fb4026ace8b7b32789af016336e54f2f0\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"minerId\":\"03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031\",\"currentHighestBlockHash\":\"71a7374389afaec80fcabbbf08dcd82d392cf68c9a13fe29da1a0c853facef01\",\"currentHighestBlockHeight\":207,\"txSecondMempoolExpiry\":0}",
                    "signature": "3045022100f65ae83b20bc60e7a5f0e9c1bd9aceb2b26962ad0ee35472264e83e059f4b9be022010ca2334ff088d6e085eb3c2118306e61ec97781e8e1544e75224533dcc32379",
                    "publicKey": "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031",
                    "encoding": "UTF-8",
                    "mimetype": "application/json"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "number"
                    },
                    "code": {
                      "type": "number"
                    },
                    "error": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "status": 400,
                    "code": 27,
                    "error": "No previous transaction found"
                  }
                }
              }
            },
            "externalDocs": {
              "description": "For more information see Merchant API BRFC",
              "url": "https://bitbucket.org/nchteamnch/brfc-merchantapi/src/master/"
            }
          }
        }
      }
    },
    "/tx/{hash}": {
      "get": {
        "tags": [
          "transaction"
        ],
        "summary": "Query transaction status",
        "description": "This endpoint is used to check the current status of a previously submitted transaction.",
        "operationId": "queryTransactionStatus",
        "parameters": [
          {
            "name": "hash",
            "in": "path",
            "description": "The transaction ID (32 byte hash) hex string",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "successful operation",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payload": {
                      "type": "string",
                      "format": "transactionStatusPayload"
                    },
                    "signature": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "publicKey": {
                      "type": "string",
                      "pattern": "[0-9a-fA-F]+"
                    },
                    "encoding": {
                      "type": "string"
                    },
                    "mimetype": {
                      "type": "string"
                    }
                  },
                  "example": {
                    "payload": "{\"apiVersion\":\"0.1.0\",\"timestamp\":\"2020-01-15T12:09:37.394Z\",\"returnResult\":\"success\",\"resultDescription\":\"\",\"blockHash\":\"745093bb0c80780092d4ce6926e0caa753fe3accdc09c761aee89bafa85f05f4\",\"blockHeight\":208,\"minerId\":\"03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031\",\"confirmations\":2,\"txSecondMempoolExpiry\":0}",
                    "signature": "3045022100c9a712a124ff3100e26f7bbcc87204848cc2ff1effacd8d8e8daac5d81bce74c02201dd661aad00d2cde443a076475cfb7d6523e0ef98a1112e938af002ca5222fbe",
                    "publicKey": "03fcfcfcd0841b0a6ed2057fa8ed404788de47ceb3390c53e79c4ecd1e05819031",
                    "encoding": "UTF-8",
                    "mimetype": "application/json"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "example": {
              "status": 400,
              "code": 31,
              "error": "txid must be provided"
            }
          }
        }
      }
    }
  },
  "externalDocs": {
    "description": "For more information see Merchant API BRFC",
    "url": "https://bitbucket.org/nchteamnch/brfc-merchantapi/src/master/"
  },
  "servers": [
    {
      "url": "http://localhost:9004/mapi"
    },
    {
      "url": "https://localhost:9004/mapi"
    }
  ],
  "components": {
    "securitySchemes": {
      "JWT": {
        "description": "",
        "type": "apiKey",
        "name": "Authorization",
        "in": "header"
      }
    },
    "schemas": {
      "feeQuotePayload": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "expiryTime": {
            "type": "string",
            "format": "date-time"
          },
          "minerId": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "currentHighestBlockHash": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "currentHighestBlockHeight": {
            "type": "number"
          },
          "minerReputation": {
            "type": "string"
          },
          "fees": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/fee"
            }
          }
        }
      },
      "fee": {
        "type": "object",
        "properties": {
          "feeType": {
            "type": "string"
          },
          "miningFee": {
            "type": "object",
            "properties": {
              "satoshis": {
                "type": "number"
              },
              "bytes": {
                "type": "number"
              }
            }
          },
          "relayFee": {
            "type": "object",
            "properties": {
              "satoshis": {
                "type": "number"
              },
              "bytes": {
                "type": "number"
              }
            }
          }
        }
      },
      "submitTransactionPayload": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "txid": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "returnResult": {
            "type": "string"
          },
          "resultDescription": {
            "type": "string"
          },
          "minerId": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "currentHighestBlockHash": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "currentHighestBlockHeight": {
            "type": "number"
          },
          "txSecondMempoolExpiry": {
            "type": "number"
          }
        }
      },
      "transactionStatusPayload": {
        "type": "object",
        "properties": {
          "apiVersion": {
            "type": "string"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "returnResult": {
            "type": "string"
          },
          "resultDescription": {
            "type": "string"
          },
          "blockHash": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "blockHeight": {
            "type": "number"
          },
          "minerId": {
            "type": "string",
            "pattern": "[0-9a-fA-F]+"
          },
          "confirmations": {
            "type": "number"
          },
          "txSecondMempoolExpiry": {
            "type": "number"
          }
        }
      }
    }
  }
}