Sia API Path Expansion Inconsistent
Created by: droghio
It looks as if the API does not support tilde expansion. This seems inconsistent given the API supports relative paths. Also paths are relative to siad
which could be in an obscure location; does it make sense to allow relative paths at all?
If a user runs siac from a different directory than siad was launched from this could lead to confusion. This could be particularly true if a user tries to use a relative path in either Sia-UI's Terminal Plugin or with a siad instance started by the Sia-UI.
Below are examples of the current behavior.
Endpoint - /wallet/load/033x
Absolute Path - Works
$ curl -sA Sia-Agent http://localhost:9980/wallet/033x --data "encryptionpassword=$SIA_PWD&source=/Users/John/Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/033x: old wallet has no new seeds"
}
Paths Relative to Siad - Works
$ curl -sA Sia-Agent http://localhost:9980/wallet/033x --data "encryptionpassword=$SIA_PWD&source=../../../../Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/033x: old wallet has no new seeds"
}
Tilde Expansion - Fails
$ curl -sA Sia-Agent http://localhost:9980/wallet/033x --data "encryptionpassword=$SIA_PWD&source=~/Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/033x: open ~/Desktop/wallet.dat: no such file or directory"
}
Endpoint - /wallet/load/siagkey
Unfortunately I didn't have a siafund file to test with, so the following calls either found the file and crashed while reading it, or could not find the file.
Absolute Path - Works (Finds the file)
$ curl -sA Sia-Agent http://localhost:9980/wallet/siagkey --data "encryptionpassword=$SIA_PWD&keyfiles=/Users/John/Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/siagkey: error while reading /Users/John/Desktop/wallet.dat: could not decode type wallet.SiagKeyPair: length 9728765351815533699 exceeds maxLen of 5000000"
}
Paths Relative to Siad - Works (Finds the file)
$ curl -sA Sia-Agent http://localhost:9980/wallet/siagkey --data "encryptionpassword=$SIA_PWD&keyfiles=../../../../Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/siagkey: error while reading ../../../../Desktop/wallet.dat: could not decode type wallet.SiagKeyPair: length 9728765351815533699 exceeds maxLen of 5000000"
}
Tilde Expansion - Fails (Cannot find the file)
$ curl -sA Sia-Agent http://localhost:9980/wallet/siagkey --data "encryptionpassword=$SIA_PWD&keyfiles=~/Desktop/wallet.dat" | python -m json.tool
{
"message": "error when calling /wallet/siagkey: open ~/Desktop/wallet.dat: no such file or directory"
}