RGB-Tools / rgb-lightning-node

MIT License
17 stars 19 forks source link

Acess service fail response: {"error":"Node is locked (hint: call unlock)","code":403} #11

Closed lshoo closed 9 months ago

lshoo commented 9 months ago

When I was following the operation of rgb-lightning-node, when I run

curl -X POST -H "Content-type: application/json" -d '{"ticker":curl -X POST -H "Content-type: application/json" -d '{"ticker": "USDT", "name": "Tether", "amounts": [666], "precision": 0}' http://localhost:3001/issueasset

but I got an response: {"error":"Node is locked (hint: call unlock)","code":403}, do i miss something?

zoedberg commented 9 months ago

As the error is suggesting, you should unlock the node to perform that operation.

P.S. before unlocking make sure you have already called the init API once in order to initialize the wallet

lshoo commented 9 months ago

when i execute

curl -X 'POST' \
  'http://localhost:3001/init' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "password": "nodepassword"
}'

for init API and i got response: {"mnemonic":"elephant success comfort book arch chef person other snap tell venture pattern"}.

when i execute

 curl -X 'POST' \
  'http://localhost:3001/address' \
  -H 'accept: application/json' \
  -d ''

to access address API or other API, got the same response {"error":"Node is locked (hint: call unlock)","code":403}

lshoo commented 9 months ago

my full operations are in below:

# step 1 in 1st shell
./regtest.sh start

# step 2 in 2nd shell 
# if i don't use `user:password` value of args, the command will failed.
# Error: Failed to connect to bitcoind client: failed to make initial call to bitcoind - please check your RPC user/password and access settings
rgb-lightning-node user:password@localhost:18443 dataldk0/ \
    --daemon-listening-port 3001 --ldk-peer-listening-port 9735 --network regtest

# 3rd shell
rgb-lightning-node user:password@localhost:18443 dataldk1/ \
    --daemon-listening-port 3002 --ldk-peer-listening-port 9736 --network regtest

# 4th shell
rgb-lightning-node user:password@localhost:18443 dataldk2/ \
    --daemon-listening-port 3003 --ldk-peer-listening-port 9737 --network regtest

# step 3 in 1st shell:
# init 
curl -X 'POST' \
  'http://localhost:3001/init' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
     "password": "nodepassword"
  }'
  # output : {"mnemonic":"elephant success comfort book arch chef person other snap tell venture pattern"}

# step 4 in ist shell:
# want to get btc address 
 curl -X 'POST' \
  'http://localhost:3001/address' \
  -H 'accept: application/json' \
  -d ''
# output: {"error":"Node is locked (hint: call unlock)","code":403}

# step 5 in 1st shell: if fill a random address
./regtest.sh sendtoaddress bcrt1qt7kzr5s5drqsgp59v229cjr55kd6wkjh0mqn86 100
# output: 46a48e608d64e2da0b5fe372b68f32fc74ed86a6f025216a57f8b18315d3cf9a

#step 6 in 1st shell :
./regtest.sh mine 1
./regtest.sh mine 1

# step 7 in1st shell
curl -X POST -H "Content-type: application/json" \
    -d '{"ticker": "USDT", "name": "Tether", "amounts": [666], "precision": 0}' \
    http://localhost:3001/issueasset
# output: {"error":"Node is locked (hint: call unlock)","code":403}
zoedberg commented 9 months ago

As the error is suggesting, you should unlock the node to perform that operation.

this means you should call the unlock API:

curl -X 'POST' \
  'http://localhost:3001/unlock' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
     "password": "nodepassword"
  }'

this API is needed to unlock the node. The API gets the password (that has been setup with the init API) to decrypt the node's mnemonic, which is saved in a file in an encrypted form and is needed to perform node operations.

Most of operations need the node to be in an unlocked state. Some APIs, like for example the backup API, require the node to be in a locked state, hence, looking at the API docs you can find also the lock API

lshoo commented 9 months ago

Thanks, it works!