28 posts
Location
Somewhere in Nowhere
Posted 03 March 2017 - 02:54 AM
so, im working on a program to do transaction with Krist, i've figured out how to get the info about the adress, but i cant convert it from a string(which is also a table) to a table. any ideas?
Program:
https://hastebin.com/yolorapeco.lua–EDIT: thought i might link the API documentation of the Krist currency aswell:
http://krist.ceriat.net/docs/–EDIT2: this is the output i get when i run it:
{"ok":true,"address":{"address":"k5n6r931i1","balance":0,"totalin":612,"totalout":4726,"firstseen":"2016-12-02T21:10:56.000Z"}}
Edited on 03 March 2017 - 02:09 AM
218 posts
Location
tmpim
Posted 03 March 2017 - 03:50 AM
What the Krist API returns is called JSON, it's pretty difficult to parse it yourself and computercraft doesn't offer any built in libraries to handle it. However, ElvishJerricco made a pretty good library to parse it.
Here is a link
28 posts
Location
Somewhere in Nowhere
Posted 03 March 2017 - 04:25 AM
seems pretty good! thanks for the help, ill give it a shot.
28 posts
Location
Somewhere in Nowhere
Posted 04 March 2017 - 12:47 AM
UPDATE: IT WORKED! thanks for this, i've been looking for something like this for quite a while :D/>
28 posts
Location
Somewhere in Nowhere
Posted 04 March 2017 - 02:09 AM
this might not be the right place to post this, but i dont know where to put it elsewhere.
so, i've been trying to make a transaction through computercraft, since im working on a shop, but whenever i try to pass my privatekey through the http.post, it just errors the following:
{"ok":false,"error":"missing_parameter","parameter":"privatekey"}
even tho i posted the key with the http.postcode used to send request:
pay = http.post("http://krist.ceriat.net/transactions?to=k5n6r931i1&privatekey=xxxxxxxx&amount="..payamm.."&metadata=test").readAll()
print(pay) -- checking for errors
if there is anything im doing wrong here please tell me, i've been looking over the internet for more than an hour.Krist Documentation: http://krist.ceriat.net/docs
Edited on 04 March 2017 - 01:10 AM
7083 posts
Location
Tasmania (AU)
Posted 04 March 2017 - 02:35 AM
Threads merged, please keep your questions about the one project in the one place.
It's generally bad practise to post and readAll all in one go. Doing so means you're unable to close the final handle, as you didn't hang on to its pointer anywhere.
In regards to your stated problem, it's
possible that you need to make your string URL-safe:
local handle = http.post( textutils.urlEncode( "http://krist.ceriat.net/transactions?to=k5n6r931i1&privatekey=xxxxxxxx&amount="..payamm.."&metadata=test" ) )
local pay = handle.readAll()
handle.close()
print(pay)
28 posts
Location
Somewhere in Nowhere
Posted 04 March 2017 - 02:45 AM
Threads merged, please keep your questions about the one project in the one place.
It's generally bad practise to post and readAll all in one go. Doing so means you're unable to close the final handle, as you didn't hang on to its pointer anywhere.
In regards to your stated problem, it's
possible that you need to make your string URL-safe:
local handle = http.post( textutils.urlEncode( "http://krist.ceriat.net/transactions?to=k5n6r931i1&privatekey=xxxxxxxx&amount="..payamm.."&metadata=test" ) )
local pay = handle.readAll()
handle.close()
print(pay)
this just returns a nil value index attempt error. it might not be able to find the url? (im quite new to working with the HTTP API)
218 posts
Location
tmpim
Posted 04 March 2017 - 03:29 AM
Threads merged, please keep your questions about the one project in the one place.
It's generally bad practise to post and readAll all in one go. Doing so means you're unable to close the final handle, as you didn't hang on to its pointer anywhere.
In regards to your stated problem, it's
possible that you need to make your string URL-safe:
local handle = http.post( textutils.urlEncode( "http://krist.ceriat.net/transactions?to=k5n6r931i1&privatekey=xxxxxxxx&amount="..payamm.."&metadata=test" ) )
local pay = handle.readAll()
handle.close()
print(pay)
this just returns a nil value index attempt error. it might not be able to find the url? (im quite new to working with the HTTP API)
Yeah you're using the http post method incorrectly, the correct usage is this:
http.post(url, postData)
so in your case
http.post("http://krist.ceriat.net/transactions", "to=k5n6r931i1&privatekey=xxxxxxxxx&amount=" .. payamm .. "&metadata=test")
Edited on 04 March 2017 - 02:29 AM
28 posts
Location
Somewhere in Nowhere
Posted 04 March 2017 - 03:42 AM
Threads merged, please keep your questions about the one project in the one place.
It's generally bad practise to post and readAll all in one go. Doing so means you're unable to close the final handle, as you didn't hang on to its pointer anywhere.
In regards to your stated problem, it's
possible that you need to make your string URL-safe:
local handle = http.post( textutils.urlEncode( "http://krist.ceriat.net/transactions?to=k5n6r931i1&privatekey=xxxxxxxx&amount="..payamm.."&metadata=test" ) )
local pay = handle.readAll()
handle.close()
print(pay)
this just returns a nil value index attempt error. it might not be able to find the url? (im quite new to working with the HTTP API)
Yeah you're using the http post method incorrectly, the correct usage is this:
http.post(url, postData)
so in your case
http.post("http://krist.ceriat.net/transactions", "to=k5n6r931i1&privatekey=xxxxxxxxx&amount=" .. payamm .. "&metadata=test")
i'll test this tommorrow. its currently 5 in the night
28 posts
Location
Somewhere in Nowhere
Posted 04 March 2017 - 10:11 PM
what Incinirate sais works, but whenever i type the private key of the address, it uses a completely different address to do the transaction, even tho i encoded the url and used the same password as on Lemmmy's web wallet
Edited on 04 March 2017 - 09:17 PM