SatoshiPortal / cyphernode

Modular Bitcoin full-node microservices API server architecture and utilities toolkit to build scalable, secure and featureful apps and services without trusted third parties
MIT License
365 stars 69 forks source link

Trying to add getmempoolinfo Bitcoin RPC to cyphernode #103

Closed aitorjs closed 5 years ago

aitorjs commented 5 years ago

Hello @Kexkey !

I tryed to add getmempoolinfo endpoint that call to getmempoolinfo Bitcoin RPC to learn how new endpoints could be added to cyphernode.

This is what I did for that:

  1. Inside api_auth_docker/api-sample.properties add this line : action_getmempoolinfo=stats after action_installation_info=stats.

  2. Inside proxy_docker/app/script/requesthandler.sh:

getmempoolinfo)
  # curl GET http://192.168.111.152:8080/getmempoolinfo
  response=$(get_mempool_info "${line}")
  response_to_client "${response}" ${?}
  break
  ;;

before derivepubpath case.

  1. Inside proxy_docker/app/script/blockchainrpc.sh:
{
  trace "Entering get_mempool_info()..."

  local data='{"method":"getmempoolinfo"}'
  send_to_watcher_node "${data}" | jq ".result"
  return $?
}

at the end of the file.

Calling to the proxy like this: echo "GET /getmempoolinfo" | docker run --rm -i --network=cyphernodenet alpine nc proxy:8888 -, I getresponse but through the gatekeeper/API (d="003";h64=$(echo -n "{\"alg\":\"HS256\",\"typ\":\"JWT\"}" | base64);p64=$(echo -n "{\"id\":\"$id\",\"exp\":$((`date +"%s"`+10))}" | base64);k="TOKEN";s=$(echo -n "$h64.$p64" | openssl dgst -hmac "$k" -sha256 -r | cut -sd ' ' -f1);token="$h64.$p64.$s";curl -v -H "Authorization: Bearer $token" -k https://127.0.0.1:2009/v0/getmempoolinfo no, give me nginx 403 Forbidden error.

I try adding action_getmempoolinfo=stats after action_installation_info=stats inside dist/gatekeeper/api.properties but the call through the gatekeeper/API still response with permission deny.

¿Any ideas of what I'm missing? I think the problem is inside gatekeeper/API and the permissions defined for him.

Thanks! :-D

Kexkey commented 5 years ago

Hi @aitoribanez !

Are you working on the dev branch? Try adding action_installation_info=stats to this file instead: cyphernodeconf_docker/templates/gatekeeper/api.properties

The file api_auth_docker/api-sample.properties is only a sample file to show what the api.properties file should look like when cyphernode is executing, so that the gatekeeper works correctly.

You need to re-run setup for the api.properties file to regenerate. Run it like ./setup.sh -irc so that it won't ask questions, it will just take the previous answers and rebuild the config files.

BTW thank you very much for trying and asking questions here. It will help us improve the documentation for the project. We have a lot to do and unfortunately documentation is often what is left behind. +1

aitorjs commented 5 years ago

Hi @Kexkey ! :-)

I'm on dev branch.

I try adding action_getmempoolinfo=stats to cyphernodeconf_docker/templates/gatekeeper/api.properties. Then rebuilding cyphernodeconf_docker image (cd cyphernodeconf_docker/ && docker build -t cyphernode/cyphernodeconf:v0.2.0-local .) and ./setup.sh -irc. This command give me this line on red: "Unable to migrate client.7z non-interactively. Rerun without the -r option". Without the -r the installation process start asking for data. Then, inside dist/gatekeeper/api.properties , action_getmempoolinfo=stats is not there and if I try the call from API/gatekeeper, permission deny problem is there.

¿Any ideas?

Thanks! :-D

Kexkey commented 5 years ago

Very good! Paging @schulterklopfer here for some specifics about the setup.

I released v0.2.1 yesterday, about during the same time you were trying your dev. I pushed new images and merged new code to dev and master. Hopefully that didn't conflict with your experiments. Because it actually sounds like it; the "migrate" part hints about the fact that it is trying to migrate from a previous version to a newer one. For example, if you did your previous setup on v0.2.0 and I pushed the new version of setup.sh that contains v0.2.1 in it, it will try to migrate. In the case of v0.2.0-to-v0.2.1 migration, you have to do it interactively (without the -r option) because it will ask questions about new features.

In this case, if you built with tag cyphernode/cyphernodeconf:v0.2.0-local but the setup.sh script has v0.2.1 in it, it won't take your modified image. :)

It sounds complicated but it is not. I am pretty sure you just slipped in a crack during new release.

If this is really the case, please rebase your local branch on remote dev and rebuild it using the build.sh script and make sure setup.sh use your local images (build.sh will tag with -local suffix).

Let me know how it goes! :)

aitorjs commented 5 years ago

How can new endpoints be added to cyphernode https://github.com/SatoshiPortal/cyphernode/pull/107/files :-)