eosjs Startup 整理了eosjs常用代码,包括创建、查询EOS账号,EOS转账,购买RAM,出售RAM,抵押资源,取消抵押资源,生成密钥对等。
https://github.com/dabdevelop/eosjs-startup
您正在查看: 2019年6月
eosjs常用代码
eos rpc get_table_rows index_position
uint64_t read_only::get_table_index_name(const read_only::get_table_rows_params& p, bool& primary) {
using boost::algorithm::starts_with;
// see multi_index packing of index name
const uint64_t table = p.table;
uint64_t index = table & 0xFFFFFFFFFFFFFFF0ULL;
EOS_ASSERT( index == table, chain::contract_table_query_exception, "Unsupported table name: ${n}", ("n", p.table) );
primary = false;
uint64_t pos = 0;
if (p.index_position.empty() || p.index_position == "first" || p.index_position == "primary" || p.index_position == "one") {
primary = true;
} else if (starts_with(p.index_position, "sec") || p.index_position == "two") { // second, secondary
} else if (starts_with(p.index_position , "ter") || starts_with(p.index_position, "th")) { // tertiary, ternary, third, three
pos = 1;
} else if (starts_with(p.index_position, "fou")) { // four, fourth
pos = 2;
} else if (starts_with(p.index_position, "fi")) { // five, fifth
pos = 3;
} else if (starts_with(p.index_position, "six")) { // six, sixth
pos = 4;
} else if (starts_with(p.index_position, "sev")) { // seven, seventh
pos = 5;
} else if (starts_with(p.index_position, "eig")) { // eight, eighth
pos = 6;
} else if (starts_with(p.index_position, "nin")) { // nine, ninth
pos = 7;
} else if (starts_with(p.index_position, "ten")) { // ten, tenth
pos = 8;
} else {
try {
pos = fc::to_uint64( p.index_position );
} catch(...) {
EOS_ASSERT( false, chain::contract_table_query_exception, "Invalid index_position: ${p}", ("p", p.index_position));
}
if (pos < 2) {
primary = true;
pos = 0;
} else {
pos -= 2;
}
}
index |= (pos & 0x000000000000000FULL);
return index;
}
Position of the index used, accepted parameters primary, secondary, tertiary, fourth, fifth, sixth, seventh, eighth, ninth , tenth
index_position 可以以某前缀的名字指定对应多级索引,或者数字(从2开始)
EOS 合约 table primary key支持的类型
read_only::get_table_rows_result read_only::get_table_rows( const read_only::get_table_rows_params& p )const {
const abi_def abi = eosio::chain_apis::get_abi( db, p.code );
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
bool primary = false;
auto table_with_index = get_table_index_name( p, primary );
if( primary ) {
EOS_ASSERT( p.table == table_with_index, chain::contract_table_query_exception, "Invalid table name ${t}", ( "t", p.table ));
auto table_type = get_table_type( abi, p.table );
if( table_type == KEYi64 || p.key_type == "i64" || p.key_type == "name" ) {
return get_table_rows_ex<key_value_index>(p,abi);
}
EOS_ASSERT( false, chain::contract_table_query_exception, "Invalid table type ${type}", ("type",table_type)("abi",abi));
} else {
EOS_ASSERT( !p.key_type.empty(), chain::contract_table_query_exception, "key type required for non-primary index" );
if (p.key_type == chain_apis::i64 || p.key_type == "name") {
return get_table_rows_by_seckey<index64_index, uint64_t>(p, abi, [](uint64_t v)->uint64_t {
return v;
});
}
else if (p.key_type == chain_apis::i128) {
return get_table_rows_by_seckey<index128_index, uint128_t>(p, abi, [](uint128_t v)->uint128_t {
return v;
});
}
else if (p.key_type == chain_apis::i256) {
if ( p.encode_type == chain_apis::hex) {
using conv = keytype_converter<chain_apis::sha256,chain_apis::hex>;
return get_table_rows_by_seckey<conv::index_type, conv::input_type>(p, abi, conv::function());
}
using conv = keytype_converter<chain_apis::i256>;
return get_table_rows_by_seckey<conv::index_type, conv::input_type>(p, abi, conv::function());
}
结论
primary key 只支持uint64_t
和 capi_name
如果想支持其他类型只能用
二级索引支持了 index_position
+ key_type
官方解释
它们是多索引表,因为它们支持在数据上使用多个索引,主索引类型必须是uint64_t并且必须是唯一的,但其他次要索引可以具有重复项。最多可以有16个附加索引,字段类型可以是uint64_t,uint128_t,eosio::checksum256,double或long double
参考
https://developers.eos.io/eosio-cpp/docs/using-multi-index-tables#section-introduction
https://developers.eos.io/eosio-nodeos/reference#get_table_rows
https://eosio.stackexchange.com/questions/3091/is-it-possible-to-use-a-type-other-than-uint64-t-for-a-table-primary-key/3097#3097
ScatterWebExtension popup window
const getPopup = async () => {
try {
const url = apis.runtime.getURL('/prompt.html');
// Notifications get bound differently depending on browser
// as Firefox does not support opening windows from background.
if(typeof browser !== 'undefined') {
const created = await apis.windows.create({
url,
height,
width,
type:'popup'
});
window.notification = notification;
return created;
}
else {
const win = window.open(url, 'ScatterPrompt', `width=${width},height=${height},resizable=0,top=${middleY},left=${middleX},titlebar=0`);
win.data = notification;
openWindow = win;
return win;
}
} catch (e) {
console.log('notification error', e);
return null;
}
}
最新文章
跨链桥跨链过程中数据变化polygon cdk aggregator 报execution reverted (0x09bde339)polygon cdk Aggregator使用SequencerPrivateKey的时机polygon da 判断DA服务是否正常polygon cdk sequence sender 发送 sequenceBatchesValidium的时机polygon cdk 查看最新提交L1batch numCDK 部署或重置后第一笔交易error: latest Synced BlockNumber (7089137) is higher than the latest Proposed block (1008) in the networkpolygon cdk 跨链桥交易处理流程分析因RPC限速导致sequence-sender异常退出
最新回复
fzd: 请问这个解决了吗
StarkWare explained: layer 2 solution provider of dYdX and iMMUTABLE R11; BitKeep News: [...]Layer 2: https://...
一文读懂 StarkWare:dYdX 和 Immutable 背后的 L2 方案 R11; BitKeep 博客: [...]Layer 2:Comparing Laye...
http://andere.strikingly.com/: Regards, Great stuff!
surou: 需要先执行提案合约申请,等待出块节点地址同意后,才会进...
heco: WARN [11-19|11:26:09.459] N...
P: 你好,我在heco链上遇到了“tx fee excee...
Peng: 楼主安装成功了吗?我正在同步区块链,一天了,差不多才同...
joyhu: 你好,请问下安装好之后如何获取到bee.yaml配置文...
kaka: 支票最终怎么提币呢?
归档
November 2024October 2024September 2024August 2024July 2024June 2024May 2024April 2024March 2024January 2024December 2023November 2023October 2023September 2023August 2023July 2023June 2023April 2023March 2023February 2023January 2023December 2022November 2022October 2022August 2022July 2022June 2022May 2022March 2022February 2022January 2022December 2021November 2021October 2021September 2021August 2021July 2021June 2021May 2021April 2021March 2021February 2021January 2021December 2020November 2020October 2020September 2020July 2020June 2020May 2020April 2020March 2020February 2020January 2020December 2019November 2019October 2019September 2019August 2019July 2019June 2019May 2019April 2019March 2019February 2019January 2019December 2018November 2018October 2018September 2018August 2018July 2018June 2018