Skip to content

需要一个使用 JSON-RPC 的账户系统示例 ​

原始发布页

打开来源页面
查看 1 个交叉存档

我们需要有人编写示例代码,最好用 Python 或 Java,展示使用 JSON-RPC 接口创建账户系统的推荐方式。大多数销售商品的网站都需要类似的东西。一直关注这里 JSON-RPC 相关帖的人,应该多少知道它该如何运作。

当用户登录自己的账户时,就向他们显示一个可以向其发送比特币来充值的比特币地址。在显示之前,先检查该地址是否已被使用;如果用过,就换成一个新地址(getnewaddress <username>)。数据库中只需保留该账户最新的比特币地址。(我之前在某个帖子里发过这部分的示例代码片段,可以搜索 getnewaddress)

使用 getreceivedbylabel <username>,以用户名作为标签,获取账户的“贷记”金额。你需要在数据库中保存一个“借记”金额。账户当前余额为(贷记 - 借记)。用户花钱时,就增加借记金额。

如果你要求超过 0 次确认,最好同时显示当前余额(0 次确认)和可用余额(1 次或更多确认),这样他们可以立即看到自己的付款已被确认收到。并非所有网站都需要等待确认,因此同时显示当前余额和可用余额应该是可选的。大多数销售数字商品的网站接受 0 次确认就没问题。

一个不错的示例应用可以是简单的银行网站,具备上述功能,再加上向比特币地址付款的选项。示例代码应尽可能简单,只加入能让网站运行所必需的最少额外内容。

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

英文原文 ​

展开英文原文

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.

为历史保存,为中文读者整理。每篇档案均附来源与英文原文。