Transaction 55026f3ca4cf08d4ee788847cad4be16254368d33afab3eb7f13d6cf0062e42e
1 Input
-
bf1f3bb9ea5cd9967888aa03c8b03480a66761f13ced801d282f7160a11801b8:82
OP_DATA_32(32) e68b3bf3b0f9e0a7797c87acf18ea7d9023cdca4e04188229b23ff317429098cOP_CHECKSIG(172)OP_0(0)OP_IF(99)OP_DATA_3(3) ordOP_DATA_1(1)OP_DATA_16(16) application/jsonOP_0(0)OP_PUSHDATA2(77) {"subject":"JSON-RPC programming tips using labels","content":{"format":"html","body":"\u003cdiv class=\"post\"\u003eI added label related functions to help with managing multiple addresses per user. \u0026nbsp;New or renamed functions are:\u003cbr/\u003e\u0026nbsp;getreceivedbyaddress -- amount received on a single address\u003cbr/\u003e\u0026nbsp;getreceivedbylabel -- amount received by all addresses with this label\u003cbr/\u003e\u0026nbsp;listreceivedbyaddress -- list addresses and amounts they've received\u003OP_PUSHDATA2(77) cbr/\u003e\u0026nbsp;listreceivedbylabel -- list labels and amounts they've received\u003cbr/\u003e\u0026nbsp;setlabel -- misc label functions for completeness\u003cbr/\u003e\u0026nbsp;getlabel\u003cbr/\u003e\u0026nbsp;getaddressesbylabel\u003cbr/\u003e\u003cbr/\u003eFor consistency I renamed getamountreceived-\u0026gt;getreceivedbyaddress and getallreceived-\u0026gt;listreceivedbyaddress. \u0026nbsp;The old names are still there so as not to break existing code, but they're deprecated.\u003cbr/\u003e\u003cbr/\u003OP_PUSHDATA2(77) eThe 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. \u0026nbsp;You can freely change their address without worrying about tracking all their old addresses.\u003cbr/\u003e\u003cbr/\u003eA 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:\u003cbr/\u003e\uOP_PUSHDATA2(77) 003cbr/\u003e// Get a new address whenever the current one has received anything\u003cbr/\u003eif (strAddr == \"\" || getreceivedbyaddress(strAddr) \u0026gt; 0)\u003cbr/\u003e\u0026nbsp;\u0026nbsp; strAddr = getnewaddress(strUsername); // Label the address with username\u003cbr/\u003eDisplay(strAddr); // Display their current receiving address\u003cbr/\u003e\u003cbr/\u003e// Get total received by all the user's addresses\u003cbr/\u003egetreceivedbylabel(strUsername, 0) // unconfirmed\u003cbr/\u003egetreceivedbylabeOP_PUSHDATA2(77) l(strUsername, 1) // available balance\u003cbr/\u003e\u003cbr/\u003eIf 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. \u0026nbsp;Scanning users with getreceivedbylabel would be n-squared, using listreceivedbylabel is n-log-n (or n linear).\u003cbr/\u003e\u003cbr/\u003eYou should only really need to scan allOP_PUSHDATA2(77) 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. \u0026nbsp;It's not necessary to poll very frequently. \u0026nbsp;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.\u003cbr/\u003e\u003cbr/\u003eIf you're selling digital goods and services, where you don't lose much if someone gets aOP_PUSHDATA2(77) free access, and it can't be resold for profit, I think you're fine to accept 0 confirmations.\u003cbr/\u003e\u003cbr/\u003eIt's mostly only if you were selling gold or currency that you'd need multiple confirmations.\u003cbr/\u003e\u003c/div\u003e"},"source":{"name":"Bitcoin Forum","url":"https://bitcointalk.org/index.php?topic=157.msg1252#msg1252"},"date":"2010-05-26T18:27:25Z"}OP_ENDIF(104)
1 Outputs
- 55026f3ca4cf08d4ee788847cad4be16254368d33afab3eb7f13d6cf0062e42e:0
value 546
address bc1par0s4uucpjhvgesastmsdyvna642gjhcmf7ge4t8khh4ddvp3kyscrxmwp