基于EOS的福利彩票
预计实现每小时自动开奖并分发奖励
智能合约 | ... |
---|---|
EOS | eosio v1.7.1 |
编译工具 | eosio.cdt v1.6.1 |
测试网 | CryptoKylin Testnet RPC 入口:https://api-kylin.eoslaomao.com |
.
├── lottery.hpp
├── lottery.cpp
eosio-cpp -abigen -I ./ -o lottery.wasm lottery.cpp
用户调用eosio.token的transfer 在memo里填类似1,2,3,4 作为买的4个彩票号码 合约定时取链上的哈希解析成4个数字来开奖
- transfer
通过apply函数监听eosio.token的transfer转发到这个action进行相关的操作 - active
全局开关 - delaydraw
通过二次延迟开奖规避了一些简单的hack
注:二次延迟开奖依旧无法规避精心设计的deferred action的hack
故只适合自己鼓捣 不适合商用
https://eosio.stackexchange.com
1.provided permissions [{"actor":"lottery1test","permission":"eosio.code"}]
合约账户缺少eosio.token的权限
解决方法:
cleos -u https://api-kylin.eoslaomao.com set account permission YOUR_ACCOUNT_NAME active '{"threshold": 1, "keys":[{"key":"YOUR_PUBLIC_KEY", "weight":1}], "accounts":[{"permission":{"actor":"YOUR_ACCOUNT_NAME","permission":"eosio.code"},"weight":1}], "waits":[] }' owner -p YOUR_ACCOUNT_NAME
2.asset 运算
An eosio::asset::amount is of type int64_t, therefore when you divide, any decimal places will be truncated.
如需对asset类进行运算请使用以下的形式防止一些意外的类型转换损失精度
eosio::asset y(x.amount/10, eosio::symbol("EOS",4)); // Set asset y to have 10th of x