From 4d4bee3fca451b56553c5c77f5e2ff397c055593 Mon Sep 17 00:00:00 2001 From: kexkey Date: Mon, 15 Nov 2021 16:49:13 -0500 Subject: [PATCH 1/2] Added validateaddress endpoint --- .../templates/gatekeeper/api.properties | 1 + doc/API.v0.md | 22 +++++++++++++ doc/openapi/v0/cyphernode-api.yaml | 32 +++++++++++++++++++ proxy_docker/app/script/requesthandler.sh | 7 ++++ 4 files changed, 62 insertions(+) diff --git a/cyphernodeconf_docker/templates/gatekeeper/api.properties b/cyphernodeconf_docker/templates/gatekeeper/api.properties index 2a50779..81eccfe 100644 --- a/cyphernodeconf_docker/templates/gatekeeper/api.properties +++ b/cyphernodeconf_docker/templates/gatekeeper/api.properties @@ -39,6 +39,7 @@ action_ln_getroute=watcher action_ln_listpays=watcher action_ln_paystatus=watcher action_bitcoin_estimatesmartfee=watcher +action_validateaddress=watcher # Spender can do what the watcher can do, plus: action_get_txns_spending=spender diff --git a/doc/API.v0.md b/doc/API.v0.md index c695e5f..32f822c 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -752,6 +752,28 @@ Proxy response: } ``` +### Validate a Bitcoin address + +Returns the detailed information about the given address. + +```http +GET http://cyphernode:8888/validateaddress/address +GET http://cyphernode:8888/validateaddress/tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv +``` + +Proxy response: + +```json +{ + "isvalid": true, + "address": "tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv", + "scriptPubKey": "5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c", + "iswitness": true, + "witness_version": 1, + "witness_program": "a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c" +} +``` + ### Spend coins from spending wallet (called by your application) Calls sendtoaddress RPC on the spending wallet with supplied info. Can supply an eventMessage to be published on successful spending. eventMessage should be base64 encoded to avoid dealing with escaping special characters. diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index 6a401ef..d3c8aa7 100644 --- a/doc/openapi/v0/cyphernode-api.yaml +++ b/doc/openapi/v0/cyphernode-api.yaml @@ -1184,6 +1184,38 @@ paths: application/json: schema: $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' + /validateaddress/{address}: + get: + parameters: + - in: "path" + name: "address" + description: "address string to validate" + required: true + schema: + type: "string" + tags: + - "bitcoin" + - "core features" + summary: "Get the detailed information about the given address" + description: "Returns the detailed information about the given address" + operationId: "validateAddress" + responses: + '200': + description: "successful operation" + content: + application/json: + schema: + # TODO: describe response + type: "object" + '403': + $ref: '#/components/schemas/ApiResponseNotAllowed' + '503': + description: "Resource temporarily unavailable" + content: + application/json: + schema: + $ref: '#/components/schemas/ApiResponseTemporarilyUnavailable' + /spend: post: tags: diff --git a/proxy_docker/app/script/requesthandler.sh b/proxy_docker/app/script/requesthandler.sh index cba8db8..1eaec2d 100644 --- a/proxy_docker/app/script/requesthandler.sh +++ b/proxy_docker/app/script/requesthandler.sh @@ -349,6 +349,13 @@ main() { response_to_client "${response}" ${?} break ;; + validateaddress) + # GET http://192.168.111.152:8080/validateaddress/tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv + + response=$(validateaddress $(echo "${line}" | cut -d ' ' -f2 | cut -d '/' -f3)) + response_to_client "${response}" ${?} + break + ;; spend) # POST http://192.168.111.152:8080/spend # BODY {"address":"2N8DcqzfkYi8CkYzvNNS5amoq3SbAcQNXKp","amount":0.00233,"eventMessage":"eyJ3aGF0ZXZlciI6MTIzfQo=","confTarget":6,"replaceable":true,"subtractfeefromamount":false} From d42ba92593a99541e001bbe129ae3c587cf711a8 Mon Sep 17 00:00:00 2001 From: kexkey Date: Thu, 18 Nov 2021 11:23:05 -0500 Subject: [PATCH 2/2] Added openapi response schema for validateaddress --- doc/API.v0.md | 10 +++++++++- doc/openapi/v0/cyphernode-api.yaml | 24 ++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/doc/API.v0.md b/doc/API.v0.md index 32f822c..7abf53d 100644 --- a/doc/API.v0.md +++ b/doc/API.v0.md @@ -761,7 +761,7 @@ GET http://cyphernode:8888/validateaddress/address GET http://cyphernode:8888/validateaddress/tb1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqp3mvzv ``` -Proxy response: +Proxy response for a valid address: ```json { @@ -774,6 +774,14 @@ Proxy response: } ``` +Proxy response for an invalid address: + +```json +{ + "isvalid": false +} +``` + ### Spend coins from spending wallet (called by your application) Calls sendtoaddress RPC on the spending wallet with supplied info. Can supply an eventMessage to be published on successful spending. eventMessage should be base64 encoded to avoid dealing with escaping special characters. diff --git a/doc/openapi/v0/cyphernode-api.yaml b/doc/openapi/v0/cyphernode-api.yaml index d3c8aa7..b794adb 100644 --- a/doc/openapi/v0/cyphernode-api.yaml +++ b/doc/openapi/v0/cyphernode-api.yaml @@ -1201,12 +1201,28 @@ paths: operationId: "validateAddress" responses: '200': - description: "successful operation" + description: "operation successful" content: application/json: schema: - # TODO: describe response type: "object" + required: + - "isvalid" + properties: + isvalid: + type: "boolean" + address: + $ref: '#/components/schemas/TypeAddressString' + scriptPubKey: + type: "string" + isscript: + type: "boolean" + iswitness: + type: "boolean" + witness_version: + type: "number" + witness_program: + type: "string" '403': $ref: '#/components/schemas/ApiResponseNotAllowed' '503': @@ -3084,9 +3100,9 @@ components: type: "string" pattern: "^[a-fA-F0-9]+$" TypeAddressString: - description: "base58 check encoded address" + description: "base58 or base32 check encoded address" type: "string" - pattern: "^[a-km-zA-HJ-NP-Z1-9]{26,35}$" + pattern: "^(bc1|tb1|bcrt1)[ac-hj-np-z02-9]{9,71}|[123mn][a-km-zA-HJ-NP-Z1-9]{26,33}$" TypeXpubString: description: "base58 check encoded xpub" type: "string"