Skip to content

Commit

Permalink
Merge pull request #3 from luoyhang003/master
Browse files Browse the repository at this point in the history
idl: add zh-cn idl to this repo
  • Loading branch information
hellllll0world authored Apr 8, 2019
2 parents 98f0da6 + cd72509 commit c0d5394
Show file tree
Hide file tree
Showing 10 changed files with 1,863 additions and 0 deletions.
86 changes: 86 additions & 0 deletions idl/zh-cn/DBIterator.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*! @brief
multi index DBIterator 对象
*/

interface DBIterator : object
{
/*! @brief 判断数据是否为首数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
console.log(itr.is_begin());
};
```
*/
Boolean is_begin();

/*! @brief 判断数据是否为尾数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
console.log(itr.is_end());
};
```
*/
Boolean is_end();

/*! @brief 获取下一个数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
var itr1 = itr.next();
console.log(itr1.toJSON());
};
```
*/
DBIterator next();

/*! @brief 获取上一个数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
var itr1 = itr.next();
var itr2 = itr1.previous();
console.log(itr2.toJSON());
};
```
*/
DBIterator previous();

/*! @brief 删除数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
itr.remove();
};
```
*/
remove();

/*! @brief 更新数据
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players(action.account, action.account);
var itr = players.find(v);
itr.data.age = 18;
itr.update(action.account);
};
```
@param payer 为此次操作支付 RAM 的账户
*/
update(String payer);

/*! @brief 查询当前数据,返回所有数据对象,每个数据是一个新的 DBIterator 对象 */
readonly Object data;
};
110 changes: 110 additions & 0 deletions idl/zh-cn/Table.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*! @brief
multi index table 对象
*/

interface Table : object
{
/*! @brief table 名
*/
readonly String name;

/*! @brief 指向合约发布者的名称
*/
readonly String code;

/*! @brief table 中数据所属的 account_name
*/
readonly String scope;

/*! @brief 向 table 存入新数据
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
players.emplace(action.account, {
title: "ceo",
age:48,
nickname:"lion1",
id:123
});
};
```
@param payer 为此次操作付费的账户
@param val 将要存入到 table 的值
*/
emplace(String payer, Object val);

/*! @brief 从 table 查找数据
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.find(v).data)
};
```
@param id 查询的参数
*/
DBIterator find(Value id);

/*! @brief 生成自增主键
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.get_primary_key())
};
```
*/
Value get_primary_key();

/*! @brief 获取 Table 的 begin
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.begin())
};
```
*/
DBIterator begin();

/*! @brief 获取 Table 的 end
实例:
```JavaScript
exports.hi = v => {
var players = db.players(action.account, action.account);
console.log(players.end().is_end(), players.end().previous().data);
};
```
*/
DBIterator end();

/*! @brief 从 table 查找小于参数结果
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players1(action.account, action.account);
var data = players.lowerbound(123);
console.log(data.data, data1.data);
};
```
@param id 查询的参数
*/
DBIterator lowerbound(Value id);

/*! @brief 从 table 查找大于参数结果
实例:
```JavaScript
exports.hi1 = v => {
var players = db.players1(action.account, action.account);
var data1 = players.upperbound(123);
console.log(data.data, data1.data);
};
```
@param id 查询的参数
*/
DBIterator upperbound(Value id);

/*! @brief 查询当前索引,返回所有索引对象,每个索引是一个新的 Table 对象 */
readonly Object indexes;
};
131 changes: 131 additions & 0 deletions idl/zh-cn/action.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*! @brief action 对象
使用方法:在 fibos 的 js 合约中使用
```JavaScript
var js_code = `exports.hi = v => console.error(action.is_account(action.account), action.is_account("notexists"));`;
fibos.setcodeSync(name, 0, 0, fibos.compileCode(js_code));
```
*/

module action {
/*! @brief action 名称
实例:
```JavaScript
exports.hi = v => {
console.log(action.name)
};
```
*/
static readonly String name;

/*! @brief action 发送者的账户名
实例:
```JavaScript
exports.hi = v => {
console.log(action.account)
};
```
*/
static readonly String account;

/*! @brief action 接收者
实例:
```JavaScript
exports.hi = v => {
console.log(action.receiver)
};
```
*/
static readonly String receiver;

/*! @brief 返回从1970年1月1日0时0分0秒(UTC,即协调世界时)距离出块时间的毫秒数。
实例:
```JavaScript
exports.hi = v => {
console.log(action.publication_time)
};
```
*/
static readonly Long publication_time;

/*! @brief 执行该 action 需要得到数组中所有账户的授权
实例:
```JavaScript
exports.hi = v => {
console.log(action.authorization)
};
```
*/
static readonly Array authorization;

/*! @brief 该 action 所在 transaction 的哈希 id
实例:
```JavaScript
exports.hi = v => {
console.log(action.id)
};
```
*/
static readonly String id;

/*! @brief 判断账户是否存在
实例:
```JavaScript
exports.hi = v => {
if(action.is_account(account)) console.notice("account exists");
else console.error("account notexists")
};
```
@param name 账户名
@return 账户存在则返回 true,不存在返回 false
*/
static Boolean is_account(String name);

/*! @brief action 执行成后,名为 name 的账号是否会收到通知
实例:
```JavaScript
exports.hi = v => {
if(action.has_recipient(receiver)) console.notice("action received")
else console.error("action not received");
};
```
@param name 账户名
@return 若名为 name 的账户会收到通知则返回 true,否则返回 false
*/
static Boolean has_recipient(String name);


/*! @brief 向通知列表增加特定账号
实例:
```JavaScript
exports.hi = v => {
action.require_recipient(action.receiver);
};
```
@param name 账户名
*/
static require_recipient(String name);

/*! @brief 验证 action 是否需要特定账户的授权
实例:
```JavaScript
exports.hi = v => {
if(action.has_auth(account)) console.notice("action be authed")
};
```
@param name 待验证的账号名
@return 需要该账户授权则返回 true,否则返回 false
*/
static Boolean has_auth(String name);

/*! @brief 向 action 的授权列表中添加特定账户及对应的权限,若添加失败则会抛出异常
实例:
```JavaScript
exports.hi = v => {
if(action.require_auth(account)) console.notice("auth success")
};
```
@param name 待验证的账号名
@param permission 需要该账户授权的权限
*/
static require_auth(String name, String permission = "");
};
Loading

0 comments on commit c0d5394

Please sign in to comment.