Pages:
Author

Topic: [Nxt] API of Nxt - page 20. (Read 37320 times)

legendary
Activity: 2142
Merit: 1010
Newbie
legendary
Activity: 2142
Merit: 1010
Newbie
November 28, 2013, 06:49:57 AM
#15
3. In 720 blocks make sure that the transaction is still in the blockchain (720 blocks is maximum blockchain reorg depth)
So... is it not safe to accept payment before 720 blocks?

What effect does the deadline time have on the payment?

Depends on deadline of a depositing transaction. If deadline is set to 24 hours then I would accept it after 10 confirmations. This is equal to 1 Bitcoin confirmation.

Deadline sets transaction expiration time. After blockchain reorg if a new branch doesn't contain a transaction it can be included into a block only if it's not expired.
hero member
Activity: 566
Merit: 500
November 28, 2013, 06:43:53 AM
#14
3. In 720 blocks make sure that the transaction is still in the blockchain (720 blocks is maximum blockchain reorg depth)
So... is it not safe to accept payment before 720 blocks?

What effect does the deadline time have on the payment?
legendary
Activity: 2142
Merit: 1010
Newbie
November 28, 2013, 05:31:46 AM
#13
After running my Nxt Slot Machine script for a while I figured out a safe way to send transactions via API.

When u send a transaction it's processed only if received back from one of the peers. But if u didn't receive it from a peer this does not mean that it won't be included into a block, maybe ur peer just failed to send it back to u.

So the safe way (without a risk to send it twice) is:

1. Send a transaction with a short deadline (10 minutes)
2. In 12 minutes check it's not included into a block and repeat step 1 again if necessary (u will generate a different transaction with the same recipient and amount but not the same timestamp and id)
3. In 720 blocks make sure that the transaction is still in the blockchain (720 blocks is maximum blockchain reorg depth)
legendary
Activity: 2142
Merit: 1010
Newbie
November 28, 2013, 04:21:17 AM
#12
This is the response I get from doing my wget command from the console. Seems to give no response at all. Does that seem right?

I've used crontab to do this same command each minute. Added -t 1 to wget so it does not keep retrying.

Even if all is correct then I guess it will take some time to see if it's generating POS, or is there some way I can find out?

Thanks once again.

This is right, client talks to webbrowser with Long-polling style. Next request using the same connection would return a response for the previous one.

It begins generating blocks right after u unlock an account.
sr. member
Activity: 458
Merit: 250
November 28, 2013, 04:16:13 AM
#11
Thank you. Any way of doing this without visiting a browser? Nxt is running on a headless linux server and configured to start when server reboots. I want it to be generating POS without having to do anything other than boot it up. Perhaps I can use wget or something to ping the url you've suggested after Nxt is started. Just not sure if that is sufficient.

U don't need browser, use wget and ping each minute.

Btw, it's better to use the same "user" value each time, so client won't create a new user session.

Code:
>wget -t 1 http://localhost:7875/?user=0.468539437886&request=unlockAccoun&secretPhrase=
Connecting to localhost (localhost)|127.0.0.1|:7875... connected.
HTTP request sent, awaiting response... No data received.

This is the response I get from doing my wget command from the console. Seems to give no response at all. Does that seem right?

I've used crontab to do this same command each minute. Added -t 1 to wget so it does not keep retrying.

Even if all is correct then I guess it will take some time to see if it's generating POS, or is there some way I can find out?

Thanks once again.
legendary
Activity: 2142
Merit: 1010
Newbie
November 28, 2013, 03:46:11 AM
#10
Thank you. Any way of doing this without visiting a browser? Nxt is running on a headless linux server and configured to start when server reboots. I want it to be generating POS without having to do anything other than boot it up. Perhaps I can use wget or something to ping the url you've suggested after Nxt is started. Just not sure if that is sufficient.

U don't need browser, use wget and ping each minute.

Btw, it's better to use the same "user" value each time, so client won't create a new user session.
sr. member
Activity: 458
Merit: 250
November 28, 2013, 03:44:15 AM
#9
How would I have an account unlocked automatically when Nxt starts (or soon after)?

I have Nxt running in a server and wish to unlock the account after reboot because I was told that the account needs to be unlocked to generate POS.

Thanks!

Try to use this dirty hack:

http://localhost:7875/?user=0.7657349163200706&request=unlockAccount&secretPhrase=MySecret

Value of "user" must be any random number. This is the way the client unlocks accounts. Ignore a response.

Thank you. Any way of doing this without visiting a browser? Nxt is running on a headless linux server and configured to start when server reboots. I want it to be generating POS without having to do anything other than boot it up. Perhaps I can use wget or something to ping the url you've suggested after Nxt is started. Just not sure if that is sufficient.
legendary
Activity: 2142
Merit: 1010
Newbie
November 28, 2013, 03:10:45 AM
#8
How would I have an account unlocked automatically when Nxt starts (or soon after)?

I have Nxt running in a server and wish to unlock the account after reboot because I was told that the account needs to be unlocked to generate POS.

Thanks!

Try to use this dirty hack:

http://localhost:7875/?user=0.7657349163200706&request=unlockAccount&secretPhrase=MySecret

Value of "user" must be any random number. This is the way the client unlocks accounts. Ignore a response.
sr. member
Activity: 458
Merit: 250
November 28, 2013, 01:52:23 AM
#7
How would I have an account unlocked automatically when Nxt starts (or soon after)?

I have Nxt running in a server and wish to unlock the account after reboot because I was told that the account needs to be unlocked to generate POS.

Thanks!
legendary
Activity: 2142
Merit: 1010
Newbie
October 19, 2013, 09:07:20 AM
#6
Could u create anything that lets to get new transactions to an account, plz?
jr. member
Activity: 56
Merit: 60
October 18, 2013, 12:41:40 PM
#5
API bot shouldn't connect to a remote server.  You can tunnel it through TLS if you wish.
hero member
Activity: 905
Merit: 1001
October 18, 2013, 12:30:43 PM
#4
i dont think sending keys as GET param is a good idea! someone who is logging the traffic can easily sniff every message
legendary
Activity: 2142
Merit: 1010
Newbie
October 18, 2013, 04:34:54 AM
#3
Sub
legendary
Activity: 980
Merit: 1000
October 17, 2013, 04:22:02 PM
#2
Yawn
jr. member
Activity: 56
Merit: 60
October 17, 2013, 03:22:35 PM
#1
This thread is dedicated to discussion of Nxt API.  Information about Nxt can be found at https://bitcointalksearch.org/topic/ann-nxt-descendant-of-bitcoin-303898


Requests to Nxt software are done using HTTP GET requests.  Parameters are passed as HTTP parameters.  Responses are returned as JSON objects.  If something goes wrong a response will look {"errorCode": 6, "errorDescription": "Blah-blah-blah"}.

The list of all requests is below, I will update it each time I add new ones.


Decode token
Decodes an authorization token.

Request:
http://localhost:7876/? request=decodeToken & website=www.domain.com & token=StringOf160Chars

Response:
{ "account": "398532577100249608", "timestamp": 622, "valid": true }

Note:
This approach should be used to authorize users on web sites.


Get balance
Retrieves the balance of an account.

Request:
http://localhost:7876/? request=getBalance & account=398532577100249608

Response:
{ "balance": 5000, "unconfirmedBalance": 4200 }

Note:
"unconfirmedBalance" is the balance minus all unconfirmed sent transactions.  It doesn't include double-spending and unconfirmed received transactions.  A user sees the unconfirmed balance in the client.


Get block
Retrieves block data.

Request:
http://localhost:7876/? request=getBlock & block=12726165958299924733

Response:
{ "height": 16, "generator": "398532577100249608", "timestamp": 504, "numberOfTransactions": 149, "totalAmount": 17400, "totalFee": 24, "version": 1, "baseTarget": "54029906605928", "previousBlock": "3483738553242041290", "nextBlock": "9200836476619146595", "payloadHash": "32BytesRepresentedInHexadecimalForm", "generationSignature": "64BytesRepresentedInHexadecimalForm", "blockSignature": "64BytesRepresentedInHexadecimalForm", "transactions": ["2590525739676698091", "5436057910978689871", "8815617645011985536", ...] }

Note:
"generator" is the account that generated the block.
Payload length = "numberOfTransactions" * 128 B.
"previousBlock" absents for the genesis block.
"nextBlock" absents for the last block in the blockchain.
"transactions" is an array of transaction ids.


Get time
Retrieves current time.

Request:
http://localhost:7876/? request=getTime

Response:
{ "time": 417 }

Note:
"time" is measured in seconds since the genesis block timestamp.


Get transaction
Retrieves transaction data.

Request:
http://localhost:7876/? request=getTransaction & transaction=16244659048134841060

Response:
{ "block": "12726165958299924733", "timestamp": 417, "deadline": 900, "sender": "6330031667105067575",  "recipient": "398532577100249608", "amount": 1500, "fee": 5, "confirmations": 2, "signature": "64BytesRepresentedInHexadecimalForm" }

Note:
Data of an unconfirmed transaction doesn't contain "block" and "confirmations" parameters.  Double-spending transactions are not retrieved.


Send money
Sends money.

Request:
http://localhost:7876/? request=sendMoney & secretPhrase=IWontTellYou & recipient=398532577100249608 & amount=1500 & fee=5 & deadline=900 & referencedTransaction=13689168149259791567

Response:
{ "transaction": "16244659048134841060" }

Note:
"deadline" is specified in minutes.
"referencedTransaction" can be omitted.
Pages:
Jump to: