NIS /local/chain/blocks-after unauthorized [SOLVED]

Hey guys

While I’m working on a block explorer, I’ve experienced an issue using the POST call /local/chain/blocks-after.

Every node I’ve tried so far, gives me back the following response:

{
    "timeStamp": 96922943,
    "error": "Unauthorized",
    "message": "remote *.*.*.* attempted to call local /local/chain/blocks-after",
    "status": 401
}

I tried this one http://hugealice.nem.ninja:7890/local/chain/blocks-after and even set up my very own supernode. The logs entry after I perform the request:

2018-04-23 19:18:00.544 WARNING remote *.*.*.* attempted to call local /local/chain/blocks-after (org.nem.nis.controller.te.woe preHandle)
2018-04-23 19:18:00.545 INFO Http Status Code 401: remote*.*.*.* attempted to call local /local/chain/blocks-after (org.nem.core.connect.ErrorResponse <init>)

Any help would be appreciated.

Thanks!

This is local API. You can call it only on local NIS.

Hey mate

thanks for the fast reply. Well okay. It would have been quite a convenient function because it gives me the blocks including the hashes back.

So I’ve done some research on it and found this post regarding hashing a block: Hash of the latest block via the NIS API

But still, I somehow don’t get it. Is anybody out there able to provide me either a more detailed description or maybe even a code snippet on how I can accomplish that?

thanks!

I guess the block explorer is coded in javascript?
You could probably use nem-sdk or nem-api libraries to hash the block? I have not worked with the nem libraries so far but they should make life easier for you.

1 Like

yep, it’s javascript.

I checked some libraries but found nothing which could help me. I checked the github repo of this explorer: http://explorer.nemchina.com/

and it seems they use the above mentioned api call. Is there a reason the request is only available on a local nis?

Okay, I just found the solution (at least for my case). In the nis-ncc config the following section allows me to set trusted hosts and ip’s:

# List of trusted IP addresses (pipe-separated). Requests from these addresses are treated as local requests.
# NIS usually checks if a request comes from the local machine and if not, certain requests get rejected
# (requests involving the private key). These requests will not get rejected, if they come from an IP in this list.
# valid forms are:
# fully qualified ip: 127.0.0.1, 0:0:0:0:0:0:0:1
# host name: bob.nem.ninja
# partial wildcard ip: 127.0.0.*, 0:0:0:0:0:0:0:*
nis.additionalLocalIps =

so this is it then =)

That works if you run your own NIS and do the query from a non-local client.

1 Like

correct. but that’s sufficient for my case. Would be still interested though on how the block hashing works. anyway, I’m happy that I can go on now. thanks for your support!