提交 8fdfabbc 编写于 作者: B Bart Wyatt

add stat table to abi, add eosioc commands to query a specific/all...

add stat table to abi, add eosioc commands to query a specific/all balances/statistics for standard currencies
上级 26eecaac
......@@ -27,6 +27,13 @@
{"name":"currency", "type":"uint64"},
{"name":"balance", "type":"uint64"}
]
},{
"name": "currency_stats",
"base": "",
"fields": [
{"name":"currency", "type":"uint64"},
{"name":"supply", "type":"uint64"}
]
}
],
"actions": [{
......@@ -43,6 +50,12 @@
"index_type": "i64",
"key_names" : ["currency"],
"key_types" : ["uint64"]
},{
"name": "stat",
"type": "currency_stats",
"index_type": "i64",
"key_names" : ["currency"],
"key_types" : ["uint64"]
}
]
}
\ No newline at end of file
......@@ -436,6 +436,25 @@ struct set_action_permission_subcommand {
}
};
struct currency_stats {
asset supply;
};
FC_REFLECT(currency_stats, (supply));
static currency_stats parse_currency_stats( fc::variant const& row ) {
uint64_t values[2];
fc::from_hex(row.as_string(), (char *) values, sizeof(uint64_t) * 2);
asset supply = asset(values[1], values[0]);
return currency_stats{ supply };
}
static asset parse_currency_balance( fc::variant const& row ) {
uint64_t values[2];
fc::from_hex(row.as_string(), (char *) values, sizeof(uint64_t) * 2);
return asset(values[1], values[0]);
}
int main( int argc, char** argv ) {
fc::path binPath = argv[0];
if (binPath.is_relative()) {
......@@ -599,7 +618,75 @@ int main( int argc, char** argv ) {
<< std::endl;
});
// currency accessors
// get currency balance
string symbol;
auto get_currency = get->add_subcommand( "currency", localized("Retrieve information related to standard currencies"), true);
auto get_balance = get_currency->add_subcommand( "balance", localized("Retrieve the balance of an account for a given currency"), false);
get_balance->add_option( "contract", code, localized("The contract that operates the currency") )->required();
get_balance->add_option( "account", accountName, localized("The account to query balances for") )->required();
get_balance->add_option( "symbol", symbol, localized("The symbol for the currency if the contract operates multiple currencies") );
get_balance->set_callback([&] {
auto result = call(get_table_func, fc::mutable_variant_object("json", false)
("scope", accountName)
("code", code)
("table", "account")
);
const auto& rows = result["rows"].get_array();
if (symbol.empty()) {
vector<asset> balances;
for (const auto &row: rows) {
balances.emplace_back(parse_currency_balance(row));
}
std::cout << fc::json::to_pretty_string(balances)
<< std::endl;
} else {
for (const auto &row: rows) {
auto balance = parse_currency_balance(row);
if (balance.symbol_name().compare(symbol) == 0) {
std::cout << fc::json::to_pretty_string(balance)
<< std::endl;
return;
}
}
}
});
auto get_currency_stats = get_currency->add_subcommand( "stats", localized("Retrieve the stats of for a given currency"), false);
get_currency_stats->add_option( "contract", code, localized("The contract that operates the currency") )->required();
get_currency_stats->add_option( "symbol", symbol, localized("The symbol for the currency if the contract operates multiple currencies") );
get_currency_stats->set_callback([&] {
auto result = call(get_table_func, fc::mutable_variant_object("json", false)
("scope", code)
("code", code)
("table", "stat")
);
const auto& rows = result["rows"].get_array();
if (symbol.empty()) {
fc::mutable_variant_object currencies;
for (const auto &row: rows) {
auto stats = parse_currency_stats(row);
currencies[stats.supply.symbol_name()] = stats;
}
std::cout << fc::json::to_pretty_string(currencies)
<< std::endl;
} else {
for (const auto &row: rows) {
auto stats = parse_currency_stats(row);
if (stats.supply.symbol_name().compare(symbol) == 0) {
std::cout << fc::json::to_pretty_string(stats)
<< std::endl;
return;
}
}
}
});
// get accounts
string publicKey;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册