Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
6c5f252f
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6c5f252f
编写于
11月 20, 2017
作者:
B
Brian Johnson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Adding account balance API.
上级
92cbff7e
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
179 addition
and
0 deletion
+179
-0
contracts/eoslib/account.h
contracts/eoslib/account.h
+36
-0
contracts/eoslib/account.hpp
contracts/eoslib/account.hpp
+81
-0
libraries/chain/wasm_interface.cpp
libraries/chain/wasm_interface.cpp
+62
-0
未找到文件。
contracts/eoslib/account.h
0 → 100644
浏览文件 @
6c5f252f
/**
* @file
* @copyright defined in eos/LICENSE.txt
*/
#pragma once
#include <eoslib/types.h>
/**
* @defgroup accountcapi Account API
* @brief Define API for querying account data
* @ingroup contractdev
*/
extern
"C"
{
/**
* @brief Return the balance for the provided account
*
* @param balance - a pointer to a range of memory to store balance data
* @param len - length of the range of memory to store balance data
*
* @pre data is a valid pointer to a range of memory at least datalen bytes long
* @pre data is a pointer to a balance object
* @pre *((uint64_t*)data) stores the primary key
*
* Example:
* @code
* balance b;
* b.account = n(myaccount);
* balance(b, sizeof(balance));
* @endcode
*/
void
account_balance_get
(
void
*
balance
,
uint32_t
len
);
///@ } accountcapi
}
contracts/eoslib/account.hpp
0 → 100644
浏览文件 @
6c5f252f
/**
* @file token.hpp
* @copyright defined in eos/LICENSE.txt
* @brief Defines types and ABI for standard token messages and database tables
*
*/
#pragma once
#include <eoslib/math.hpp>
#include <eoslib/print.hpp>
namespace
eosio
{
namespace
account
{
/**
* @defgroup tokens Token API
* @brief Defines the ABI for interfacing with standard-compatible token messages and database tables.
* @ingroup contractdev
*
* @{
*/
/**
* @struct eosio::account_balance (must match account_balance defined in wasm_interface.cpp)
* @brief The binary structure expected and populated by native balance function.
* @ingroup tokens
*
* @details
* Example:
* @code
* account_balance test1_balance;
* test1_balance.account = N(test1);
* if (account_api::get(test1_balance))
* {
* eos::print("test1 balance=", test1_balance.eos_balance, "\n");
* }
* @endcode
* @{
*/
struct
PACKED
(
account_balance
)
{
/**
* Name of the account who's balance this is
* @brief Name of the account who's balance this is
*/
account_name
account
;
/**
* Balance for this account
* @brief Balance for this account
*/
asset
eos_balance
;
/**
* Staked balance for this account
* @brief Staked balance for this account
*/
asset
staked_balance
;
/**
* Unstaking balance for this account
* @brief Unstaking balance for this account
*/
asset
unstaking_balance
;
/**
* Time at which last unstaking occurred for this account
* @brief Time at which last unstaking occurred for this account
*/
time
last_unstaking_time
;
};
/**
* Retrieve a populated balance structure
* @param account_balance stream to write
* @ret true if account's balance is found
*/
bool
get
(
account_balance
&
b
)
{
return
account_balance
(
&
b
,
sizeof
(
account_balance
));
}
}
}
libraries/chain/wasm_interface.cpp
浏览文件 @
6c5f252f
...
...
@@ -17,6 +17,8 @@
#include "IR/Validate.h"
#include <eos/chain/key_value_object.hpp>
#include <eos/chain/account_object.hpp>
#include <eos/chain/balance_object.hpp>
#include <eos/chain/staked_balance_objects.hpp>
#include <eos/types/abi_serializer.hpp>
#include <chrono>
#include <boost/lexical_cast.hpp>
...
...
@@ -46,6 +48,42 @@ namespace eosio { namespace chain {
U32
_num_bytes
;
};
// account.h/hpp expected account API balance interchange format
// must match account.hpp account_balance definition
PACKED_STRUCT
(
struct
account_balance
{
/**
* Name of the account who's balance this is
* @brief Name of the account who's balance this is
*/
account_name
account
;
/**
* Balance for this account
* @brief Balance for this account
*/
asset
eos_balance
;
/**
* Staked balance for this account
* @brief Staked balance for this account
*/
asset
staked_balance
;
/**
* Unstaking balance for this account
* @brief Unstaking balance for this account
*/
asset
unstaking_balance
;
/**
* Time at which last unstaking occurred for this account
* @brief Time at which last unstaking occurred for this account
*/
time
last_unstaking_time
;
})
wasm_interface
::
wasm_interface
()
{
}
...
...
@@ -688,6 +726,30 @@ DEFINE_INTRINSIC_FUNCTION2(env,printhex,printhex,none,i32,data,i32,datalen) {
DEFINE_INTRINSIC_FUNCTION1
(
env
,
free
,
free
,
none
,
i32
,
ptr
)
{
}
DEFINE_INTRINSIC_FUNCTION2
(
env
,
account_balance_get
,
account_balance_get
,
i32
,
i32
,
charptr
,
i32
,
len
)
{
auto
&
wasm
=
wasm_interface
::
get
();
auto
mem
=
wasm
.
current_memory
;
const
uint32_t
account_balance_size
=
sizeof
(
account_balance
);
FC_ASSERT
(
len
==
account_balance_size
,
"passed in len ${len} is not equal to the size of an account_balance struct == ${real_len}"
,
(
"len"
,
len
)(
"real_len"
,
account_balance_size
)
);
account_balance
&
total_balance
=
memoryRef
<
account_balance
>
(
mem
,
charptr
);
auto
&
db
=
wasm
.
current_apply_context
->
db
;
auto
*
balance
=
db
.
find
<
balance_object
,
by_owner_name
>
(
total_balance
.
account
);
auto
*
staked_balance
=
db
.
find
<
staked_balance_object
,
by_owner_name
>
(
total_balance
.
account
);
if
(
balance
==
nullptr
||
staked_balance
==
nullptr
)
return
false
;
total_balance
.
eos_balance
=
asset
(
balance
->
balance
,
EOS_SYMBOL
);
total_balance
.
staked_balance
=
asset
(
staked_balance
->
staked_balance
);
total_balance
.
unstaking_balance
=
asset
(
staked_balance
->
unstaking_balance
);
total_balance
.
last_unstaking_time
=
staked_balance
->
last_unstaking_time
;
return
true
;
}
wasm_interface
&
wasm_interface
::
get
()
{
static
wasm_interface
*
wasm
=
nullptr
;
if
(
!
wasm
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录