{ "subject": "JSON-RPC programming tips using labels", "content": { "format": "html", "body": "<div class=\"post\">I added label related functions to help with managing multiple addresses per user. &nbsp;New or renamed functions are:<br/>&nbsp;getreceivedbyaddress -- amount received on a single address<br/>&nbsp;getreceivedbylabel -- amount received by all addresses with this label<br/>&nbsp;listreceivedbyaddress -- list addresses and amounts they've received<br/>&nbsp;listreceivedbylabel -- list labels and amounts they've received<br/>&nbsp;setlabel -- misc label functions for completeness<br/>&nbsp;getlabel<br/>&nbsp;getaddressesbylabel<br/><br/>For consistency I renamed getamountreceived-&gt;getreceivedbyaddress and getallreceived-&gt;listreceivedbyaddress. &nbsp;The old names are still there so as not to break existing code, but they're deprecated.<br/><br/>The idea is that if you give the username whenever you call getnewaddress, you can get the user's total received across all their addresses using the \"bylabel\" functions. &nbsp;You can freely change their address without worrying about tracking all their old addresses.<br/><br/>A good way to automate changing the user's receiving address: just before displaying their current address, check if it has been used to receive anything, if it has then replace it with a new one:<br/><br/>// Get a new address whenever the current one has received anything<br/>if (strAddr == \"\" || getreceivedbyaddress(strAddr) &gt; 0)<br/>&nbsp;&nbsp; strAddr = getnewaddress(strUsername); // Label the address with username<br/>Display(strAddr); // Display their current receiving address<br/><br/>// Get total received by all the user's addresses<br/>getreceivedbylabel(strUsername, 0) // unconfirmed<br/>getreceivedbylabel(strUsername, 1) // available balance<br/><br/>If you're just getting one particular user's balance, such as in response to a page request by that user, use getreceivedbylabel, but if you're scanning over all users, it's better to use listreceivedbylabel to get the complete list and scan against the result. &nbsp;Scanning users with getreceivedbylabel would be n-squared, using listreceivedbylabel is n-log-n (or n linear).<br/><br/>You should only really need to scan all users if you're polling in order to spontaneously take action in response to money received, rather than the user going to a webpage, seeing their balance and telling you what to do with it. &nbsp;It's not necessary to poll very frequently. &nbsp;If you require 1 confirmation, that'll take an average of 10 minutes anyway, so there's no point in polling more often than every few minutes.<br/><br/>If you're selling digital goods and services, where you don't lose much if someone gets a free access, and it can't be resold for profit, I think you're fine to accept 0 confirmations.<br/><br/>It's mostly only if you were selling gold or currency that you'd need multiple confirmations.<br/></div>" }, "source": { "name": "Bitcoin Forum", "url": "https://bitcointalk.org/index.php?topic=157.msg1252#msg1252" }, "date": "2010-05-26T18:27:25Z" }
Inscription number 18,210,008
Genesis block 799,367
File type json
File size 3.42 KB
Creation date