Bitcointalk · Sample account system using JSON-RPC needed

中本聪,2010 年 7 月 16 日

SN-1297 已核对来源,附原文与上下文。

阅读语言
中文译文

我们需要有人写示例代码,最好是 Python 或 Java,展示用 JSON-RPC 接口创建账户系统的推荐方式。大多数卖东西的网站都需要类似的东西。一直跟进这里 JSON-RPC 主题的人应该对它该怎么工作有概念。

用户登录自己的账户后,你展示他能汇入资金的比特币地址。展示之前,先检查这个地址是否已被用过,用过就换新的(getnewaddress )。你只需要在数据库里为每个账户保留最新的比特币地址。(我在之前的某个主题里贴过这段的示例代码片段,搜 getnewaddress)

用 getreceivedbylabel 、以用户名做 label,取账户的「贷方」金额。你需要在数据库里记一个「借方」金额。账户当前余额是(贷方 - 借方)。用户花钱时,增加借方。

如果你要求多于 0 个确认,最好同时展示当前余额(0 确认)和可用余额(1 个或以上确认),这样用户能立刻看到付款已被接收。不是所有网站都要等确认,所以「当前 + 可用」双余额应该是可选的。卖数字商品的网站大多 0 确认就够。

一个合适的示例应用是个简单的银行网站:具备以上功能,外加向比特币地址付款的选项。示例代码应该尽可能简单,只带让它成为可用网站的最少东西。

vekja.net 就是这类网站的一个例子。

ORIGINAL · 英文原文
We need someone to write sample code, preferably Python or Java, showing the recommended way to use the JSON-RPC interface to create an account system.  Most sites that sell things will need something like this.  Someone who's kept up on the JSON-RPC threads here should have some idea how it should work.

When a user is logged in to their account, you show the bitcoin address they can send to to add funds.  Before showing it, you check if it's been used, if it has then you replace it with a new one (getnewaddress <username>).  You only need to keep the latest bitcoin address for the account in your database.  (I posted a sample code fragment for this in an earlier thread somewhere, search on getnewaddress)

You use getreceivedbylabel <username> with the username as the label to get the "credit" amount of the account.  You need to keep a "debit" amount in your database.  The current balance of the account is (credit - debit).  When the user spends money, you increase debit.

If you're requiring more than 0 confirmations, it's nice if you show the current balance (0 confirmations) and the available balance (1 or more confirmations), so they can immediately see that their payment is acknowledged.  Not all sites need to wait for confirmations, so the dual current & available should be optional.  Most sites selling digital goods are fine to accept 0 confirmations.

A nice sample app for this would be a simple bank site, which would have the above, plus the option to send a payment to a bitcoin address.  The sample code should be the simplest possible with the minimum extra stuff to make it a working site.

vekja.net is an example of a site like this.
上下文
← 上一条 SN-1297 · 当前 下一条 → 在档案中查看完整主题串 →
来源
Bitcointalk 原始链接 ↗ 记录编号 SN-1297