{"id":18280156,"url":"https://github.com/treasersimplifies/coup_de_grace","last_synced_at":"2025-04-09T04:49:40.853Z","repository":{"id":217610879,"uuid":"164890130","full_name":"treasersimplifies/Coup_de_Grace","owner":"treasersimplifies","description":"A simple Random Draw DApp based on EOS blockchain ","archived":false,"fork":false,"pushed_at":"2019-01-25T02:13:43.000Z","size":1206,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-14T23:28:24.289Z","etag":null,"topics":["blockchain","dapp","eos","random","smart-contracts"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treasersimplifies.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-01-09T15:39:00.000Z","updated_at":"2022-01-09T13:11:36.000Z","dependencies_parsed_at":"2024-01-17T13:23:59.824Z","dependency_job_id":"10bfbe45-63b0-4399-aeb9-d4db60cf0f9f","html_url":"https://github.com/treasersimplifies/Coup_de_Grace","commit_stats":null,"previous_names":["treasersimplifies/coup_de_grace"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasersimplifies%2FCoup_de_Grace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasersimplifies%2FCoup_de_Grace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasersimplifies%2FCoup_de_Grace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treasersimplifies%2FCoup_de_Grace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treasersimplifies","download_url":"https://codeload.github.com/treasersimplifies/Coup_de_Grace/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247980820,"owners_count":21027803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","dapp","eos","random","smart-contracts"],"created_at":"2024-11-05T12:33:26.299Z","updated_at":"2025-04-09T04:49:40.829Z","avatar_url":"https://github.com/treasersimplifies.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Coup_ de_Grace\nThe distinguished ability of PA(Phantom Assassin)\n\nPhantom Assassin refines her combat abilities, gaining a chance of delivering a devastating critical strike to enemy units. Stifling Dagger shares the same critical strike chance.\n\n# 要求\n搭建私有链，设想某个去中心化应用场景，编写智能合约，完成智能合约的编译、部署和调用。基于任意架构的区块链平台开发一款可运行的DApp。\n### 提交内容\n1. 完整源代码\n2. word说明文档（包括：）\n\t* 开发环境搭建\n\t* 功能设计\n\t* 合约设计\n\t* 系统实现和部署\n\t* 主要界面截图与说明\n\t\n# 2 功能概述(Overview)\nThis DApp achieves:\n\n1. Can create the Main Awards and add sub-awards under the main awards. For example, you can create the main prize of the \"Association Activity Draw\", and then add \"First Prize\" and \"Second Prize\" sub-scores to it. After creation, the transaction hash value for creating a award will be displayed.\n2. Can add unilateral award participants, specifically to sub-awards. For example, adding 10 participants to participate in the \"second prize\".\n3. Can unilaterally award a sub-award. And the results of the lottery will be automatically put on blockchain.\n4. Can query the history. You can query by the main award ID as the index value, or you can query the first **n** records in the history.\n\n\nChinese:\n\n1. 能实现创建抽奖主奖项，并在主奖项下添加子奖项。比如创建“协会活动抽奖”这个主奖项，并在下面添加“一等奖”、“二等奖”等子奖项。创建后显示创建奖项的交易哈希值。\n2. 能单方面添加奖项参与者，具体到子奖项。比如添加10位参与抽“二等奖”。\n3. 能单方面对某一子奖项开奖。并将抽奖结果自动上链。\n4. 能查询历史记录。可以按主奖项ID为索引值进行查询，也可以查询历史中前n个记录。\n\n# 3 智能合约(Contract)\nEOS的智能使用C++开发（也可以使用其他语言），限于时间所限，第一版抽奖软件比较简单，只需要一个[Surprise](https://github.com/treasersimplifies/Coup_de_Grace/tree/master/contract/Surprise)合约就能实现既定功能。\n\n在这个合约里定义/实现了如下内容：(The following are defined in contracts :)\n### actions\n\n* showinfo:用于显示合约相关信息。       ```void showinfo();```\n* create:用于新建主奖项(create a main reward)。      ```void create(const account_name author, uint64_t project_id, string\u0026 project_name);```\n* additem:用于向某个主奖项下添加子奖项(add sub-reward)。    ```void additem(const account_name author, uint64_t project_id, uint64_t item_id, string\u0026 item_name, uint32_t winumber, uint32_t maxnumber);```\n* addcad:用于向某主奖项下的子奖项添加参与者(add candidates)。    ```void addcad(const account_name author, uint64_t project_id, uint64_t item_id, string\u0026 cadname);```\n* activate:用于针对某主奖项下的子奖项的开奖(get lottery done)。   ```void activate(const account_name author, uint64_t project_id, uint64_t item_id);```\n* checkbyid:用于查询奖项记录(query reward by id)。   ```void checkbyid(const account_name author, uint64_t project_id);```\n* checkn:用于查询奖项记录(query n records)。      ```void checkbyid(const account_name author, uint64_t project_id);```\n\n### 数据结构(data structure)\n\n1. 子奖项结构(sub-reward structure)\n\n```\nstruct surpriseitem{\n    uint64_t id;\n    string name;\n    uint32_t winumber; \n    uint32_t maxnumber;\n    vector\u003cstring\u003e cadidates;//phone number\n    vector\u003cstring\u003e winners;//phone number\n\n    uint64_t primary_key() const { return id; }\n    // EOSLIB_SERIALIZE(surpriseitem, (id)(name)(number))\n};\n```\n\n2. 主奖项结构(main structure)\n\n```\nstruct surpriseprj{\n    uint64_t id;\n    string name;\n    vector\u003csurpriseitem\u003e items;//\n    \n    uint64_t primary_key() const { return id; }\n    // EOSLIB_SERIALIZE(surpriseprj, (id)(name))\n};         \n```\n### Multi_Index\n定义了一个Multi_Index的table：\n\n```typedef multi_index\u003cN(surpriseprj), surpriseprj\u003e surpriseprjIndex;```\n\n然后是关于这个table的增、改、查操作等：(operations defined for this table)\n\n```\nsurpriseprjIndex surpriseprjs(_self, _self);\n//增：add\nsurpriseprjs.emplace(author, [\u0026](auto\u0026 surpriseprj) {\n    surpriseprj.id = project_id;\n    surpriseprj.name = project_name;\n});\n//改：update\nsurpriseprjs.modify(iterator, author, [\u0026](auto\u0026 surpriseprj) {\n    surpriseprj.items.push_back(surpriseitem{\n        item_id,\n        item_name,\n        winumber,\n        maxnumber\n    });\n});\n//查：query\nauto theprj = surpriseprjs.get(project_id);\nprint(\"||| Id: \", theprj.id);\nprint(\" ||- Name: \", theprj.name.c_str());\nprint(\" ||- Items: \");    \n```\n\n### 随机数(random number)\nEOS无法使用```#include\u003crandom\u003e```，所以需要寻找其他的随机源。\n\n参考了(referrence)：[generEOS/eosio.random](https://github.com/generEOS/eosio.random) and [Randomization in Contracts](https://developers.eos.io/eosio-cpp/docs/random-number-generation)\n\n原理是：通过区块数据来作为种子，产生哈希，比较不同的哈希，得出比较结果，把比较结果作为随机数。(use block data as the seed)\n\n```\nint lucky[MAX_CAD];//\nif(winumber\u003c=cadnumber){\n    for(int i=0; i\u003ccadnumber; ){\n        checksum256 result;\n        auto mixedBlock = tapos_block_prefix() * tapos_block_num();\n        const char *mixedChar = reinterpret_cast\u003cconst char *\u003e(\u0026mixedBlock);\n        sha256( (char *)mixedChar, sizeof(mixedChar), \u0026result);\n        const char *p64 = reinterpret_cast\u003cconst char *\u003e(\u0026result);\n        auto r = (abs((int64_t)p64[i]) % (cadnumber + 1 - 1)) + 1;  //1 to cadnumber\n        int need_to_repeat=0;\n        for(int j=0;j\u003c5;j++){\n            if(r==lucky[j]){\n                need_to_repeat=1;\n                break;\n            }\n        }\n        if(need_to_repeat==0){\n            print(\" \", r);\n            lucky[i++]=r;\n        }\n        if(i==winumber)break;\n    }\n}else{\n    for(int i=0;i\u003ccadnumber;i++){\n        lucky[i]=i+1;\n        print(\" \", i+1);\n    }\n}\n```\n\n### Multi_index的table下的vector的元素中的vector的元素的压栈\n\n```\nsurpriseprjs.modify(iterator, author, [\u0026](auto\u0026 surpriseprj) { \n\tsurpriseprj.items[item_id-1].winners.push_back(winner);\n});\n``` \n\n# 4 前端(Frontend)\n前端界面如下：\n![OverView](frontend/src/OverView2.png)\n因为前端比较简单，没有用什么框架或者前端库，所有内容直接写在一个html文件中了,需要引入如下文件，都位于eosjs库中（eosjs库的引入见下“5 系统实现和部署”）：\n\n\n```\n\u003cscript src='eosjs/dist-web/eosjs-api.js'\u003e\u003c/script\u003e\n\u003cscript src='eosjs/dist-web/eosjs-jsonrpc.js'\u003e\u003c/script\u003e\n\u003cscript src='eosjs/dist-web/eosjs-jssig.js'\u003e\u003c/script\u003e\n```\n## 4.1 界面(UI)\n前端的界面：分三部分，**顶部显示区域**、**中间按钮区域**、**底部查询显示区域**。\n\n### 顶部显示区域\n将与智能合约进行交互得到的输出作简单处理后显示在此。\n\n而其中的蓝色方框内能显示对抽奖项目进行增、改操作时的交易哈希值。\n\n### 中间按钮区域\n每个按钮都一一、严格地对应一个合约中的action，而按钮旁边的输入框都是用来逐个输入逐个action需要的参数的。原理很简单。\n\n### 底部查询显示区域\n进行查操作（按下查询按钮）后显示记录的区域。\n\n**注意：查询前最好按下“显示信息”按钮来看看链上有多少个抽奖记录，不能越界。**\n## 4.2 主要代码(Core Code)\nEOS提供了eosjs和eosjs2两个JavaScript库，能用来对交易进行签名和发送交易等操作。这里我使用的是eosjs。前端中的核心代码是利用EOS提供的JavaScript API和区块链节点建立通信（包括签名）和向智能合约推送action的部分。\n\n### 建立通信\n\n```\nvanelActiveKey  =\"5KjiKSVyFEnR8rr2TmxMZBDSrvp45LVX9BSyseEFsVBtruaGGXg\";\nconst rpc = new eosjs_jsonrpc.default('http://127.0.0.1:8888');\nconst signatureProvider = new eosjs_jssig.default([vanelActiveKey]);\nconst api = new eosjs_api.default({ rpc, signatureProvider });\n```\n这种写法非常简单，不合适在实际生产开发中使用，因为不安全。\n\n### 推送action\n\n```\nfunction pushAction(actionName, dataValue){\n    (async () =\u003e {\n        try {\n            const result = await api.transact({\n                actions: [{\n                    account: 'pa', //部署合约的账号\n                    name: actionName,\n                    authorization: [{\n                        actor: 'vanel', //本客户端拥有私钥进行签名的账号\n                        permission: 'active',\n                    }],\n                    data: dataValue,\n                }]\n                }, {\n                blocksBehind: 3,\n                expireSeconds: 30,\n            });\n            // alert(JSON.stringify(result, null, 2));\n            // 返回的result是一个JSON对象\n            var transaction_id = result.transaction_id;\n            var console_output = result.processed.action_traces[0].console;    \n            ...... //略去对从合约收到的文本进行进一步处理的内容。                \n        } catch (e) {\n            var err_info = '\\nCaught exception: ' + e;\n            if (e instanceof eosjs_jsonrpc.RpcError)\n                err_info += '\\n' + JSON.stringify(e.json, null, 2);\n            alert(err_info);\n        }\n    })();\n}\n```\n实现这个推送action的函数后，之后的各种action推送都只要调用它就行，不需要自己重新针对每个action写一个函数。\n\n# 5 系统实现和部署(Integrate and Deploy)\n## 系统集成\n编写完合约和前端后进行集成，项目结构：\n\n```\nCoup_de_Grace\t\t\t\t\t\t\t\t\n\t  |-contract\t\t\t\t\t\t\t  \n\t  \t\t|-Surprise\t\t\t\t\t       \n\t  \t\t\t  |-Surprise.hpp\n\t  \t\t\t  |-Surprise.cpp\n\t  \t\t\t  |-Surprise.abi\n\t  \t\t\t  |-Surprise.wasm\n\t  |-frontend\n\t  \t\t|-index.html\n\t  \t\t|-index.css\n\t  \t\t|-eosjs\n\t  \t\t|-src\n\t  |-README.md\n\t  |-test.sh\n```\n如果没有eosjs，则需要自己引入：\n\n```\n# 在此之前自然要装好node.js和npm\n# in test.sh:\ncd ${DappsDIR}/frontend\ngit clone https://github.com/EOSIO/eosjs.git \ncd eosjs\nnpm install\nnpm run build-web\n```\n## 部署准备工作\n部署前需要启动本地EOS单点节点（相当于以太坊私有链），然后创建好测试本项目要使用的钱包、导入账户密钥、创建账户（这些过程在test.sh中都有）：\n\n```\n# in test.sh:\n# 0.0 edit the config.ini: ~/Library/Application Support/eosio/nodeos/config \n# to enable plugins of eos private node you are about to start and:\nnodeos\n#      or \n# 0.1 Start the nodeos with :\nnodeos -e -p eosio --plugin eosio::producer_plugin --plugin eosio::chain_api_plugin --plugin eosio::http_plugin --plugin eosio::history_api_plugin  --contracts-console --verbose-http-errors --enable-stale-production --max-transaction-time 3000\n```\n是的，你确实需要激活这么多插件，否则你无法测试本项目了...比如：\n\n```http_plugin --plugin ```是为了激活RPC API\n\n```--contracts-console```是为了激活控制台输入，如果不激活，那你向智能合约发生action时你的命令行里就没有输出了\n\n```--max-transaction-time 3000```是为了提高交易执行超时时间，默认是30ms，因为产生随机数需要不少时间（相对于程序其他部分而言），所以如果一次性随机抽奖的人数过多就会超时，导致交易无法执行。\n\n这么多插件、参数的必要性都是在我尝试了很多次以后通过经验再加上EOSIO官网的文档得出的。建议通过编辑config.ini文件来修改这些参数，这样你就默认使能这些东西了。其他的插件说明见：[EOSIO nodeos plugins](https://developers.eos.io/eosio-nodeos/docs/history_api_plugin)\n\n\n```\n# in test.sh:\n# 1. Create new wallet with the name \"cdg\"(or whatever name you like) for this project\ncleos wallet create -n cdg --to-console\n##// my key(for test only): PW5KfKXy8qXD3JbKZ3RosqS6PYfm9eBjx2mHveVm4T4dfz7d4LrFE\ncleos wallet unlock -n cdg\n\n# 2. Generate two pair of keys (use the command twice for an account OwnerKey and ActiveKey 2-level authority)\ncleos create key --to-console\ncleos create key --to-console\n## my Private key: 5KamKnnmFZD1pBLKmGweoVafFkxvr9R6xPYbKLwEoEviVcivBWt\n## my Public key: EOS5rhWHPySUdtDTPWMkqiatv3xgU2EPwKnjSe4Vr3eYFUA1dPPeB\n## my Private key: 5JurHoxQEbRtgKeeb7ZN28PECn92wJrgVSrP4f3dyPHxMY1NABC\n## my Public key: EOS8XjjYgLcUkBbHYSacgsx2CRnbToApiwkNoaEk5ft9FfMxWgYJj\ncleos create key --to-console\ncleos create key --to-console\n# Private key: 5K9U98d63o1z9YXXgBE8uCVvF7co8Tdp6VoywKhv9bg4N3iokxQ\n# Public key: EOS6Lg1zGGdtrf5hAihherwSnaM3QeGdwQTj9MZPv2BAMwbBXX2rf\n# Private key: 5KjiKSVyFEnR8rr2TmxMZBDSrvp45LVX9BSyseEFsVBtruaGGXg\n# Public key: EOS5KA5u5aURzcrqjX4BXfVdbaYWVLJgHjD4Cu42Qh3vqoggEvbhB\n```\n\n**注意：**由于我是做测试使用，所以直接把私钥打印到了命令上，实际写DApp时不要使用此选项，应选择把私钥打印到某个文件里。\n\n```\n# in test.sh:\n# 3. Import the generated private keys in the wallet (you need to specify the wallet)\ncleos wallet import -n cdg \ncleos wallet import -n cdg \ncleos wallet import -n cdg \ncleos wallet import -n cdg \n\n# 4. Add the private key of the \"eosio\" into your wallet\n# Note: If you're receiving an Error 3090003: Provided keys, permissions, and delays do not satisfy declared authorizations\n# you probably should add the private key of the \"eosio\" account to your wallet. \ncleos wallet import --private-key=5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3 -n cdg\n```\n\n**注意：**eosio的私钥必须导入，因为要创建的所有账户都是通过eosio产生的。不导入它的私钥，没办法来创建账户。\n\n```\n# in test.sh:\n# 5. Create the account using the public keys (will be destoryed if nodeos restart)\n# for contract account:\ncleos create account eosio pa EOS5rhWHPySUdtDTPWMkqiatv3xgU2EPwKnjSe4Vr3eYFUA1dPPeB EOS8XjjYgLcUkBbHYSacgsx2CRnbToApiwkNoaEk5ft9FfMxWgYJj\n# for test accounts:\ncleos create account eosio vanel EOS6Lg1zGGdtrf5hAihherwSnaM3QeGdwQTj9MZPv2BAMwbBXX2rf EOS5KA5u5aURzcrqjX4BXfVdbaYWVLJgHjD4Cu42Qh3vqoggEvbhB\n\n# 6. Check these accounts: cleos get account ACCOUNTNAME –json(-j)\ncleos get account pa -j\n```\n\n## 部署\n做好这些准备工作后就可以来部署合约到EOS区块链上了。\n\n```\n# in test.sh:\n# 7. Compile the Surprise contract (make sure you are currently in the project path, or you need to use absolute path)\ncd /Coup_de_Grace/contract/Surprise\neosio-cpp -o Surprise.wasm Surprise.cpp --abigen\n\n# 8. Deploy the Suprise contract\ncleos set contract pa /Coup_de_Grace/contract/Surprise -p pa@active\n\n```\n如果没出现错误就完成部署了。\n\n## 使用的命令\n以上我们使用到了很多EOS的命令，主要有：nodeos, eosio-cpp, cleos.\n\n其中nodeos是与节点有关的命令，在本项目中主要用来启动区块链单节点，其详细内容见：[EOSIO nodeos](https://developers.eos.io/eosio-nodeos/docs/overview-1)\n\neosio-cpp 是把cpp文件编译为wasm文件的命令。EOS使用WebAssembly对智能合约的C++代码进行编译和执行，其核心原因是WebAssembly性能好。WebAssembly就像是一个编译器能让EOS看懂C/C++代码。\n\ncleos是与区块链进行交互的主要命令，它包含很多子命令（仅介绍本项目中用到的）：\n\n1. cleos wallet: 与钱包相关的命令，本项目中用到了创建钱包（create）、解锁钱包（unlock）、导入密钥（import）。\n\n\t```\n\tUsage: cleos wallet SUBCOMMAND\n\tSubcommands:\n\t  create                      Create a new wallet locally\n\t  open                        Open an existing wallet\n\t  lock                        Lock wallet\n\t  lock_all                    Lock all unlocked wallets\n\t  unlock                      Unlock wallet\n\t  import                      Import private key into wallet\n\t  remove_key                  Remove key from wallet\n\t  create_key                  Create private key within wallet\n\t  list                        List opened wallets, * = unlocked\n\t  keys                        List of public keys from all unlocked wallets.\n\t  private_keys                List of private keys from an unlocked wallet in wif or PVT_R1 format.\n\t  stop                        Stop keosd (doesn't work with nodeos).\n\t```\n\t\n2. cleos create: 创建命令，本项目中用到了创建密钥对（key）、创建账户（account）。\n\n\t```\n\tUsage: cleos create SUBCOMMAND\n\tSubcommands:\n\t  key                         Create a new keypair and print the public and private keys\n\t  account                     Create a new account on the blockchain (assumes system contract does not restrict RAM usage)\n\t```\n\t\n3. cleos get: 获取命令，本项目只用到了获取账户信息（account）。\n\n\t```\n\tUsage: cleos get SUBCOMMAND\n\tSubcommands:\n\t  info                        Get current blockchain information\n\t  block                       Retrieve a full block from the blockchain\n\t  account                     Retrieve an account from the blockchain\n\t  code                        Retrieve the code and ABI for an account\n\t  abi                         Retrieve the ABI for an account\n\t  table                       Retrieve the contents of a database table\n\t  scope                       Retrieve a list of scopes and tables owned by a contract\n\t  currency                    Retrieve information related to standard currencies\n\t  accounts                    Retrieve accounts associated with a public key\n\t  servants                    Retrieve accounts which are servants of a given account \n\t  transaction                 Retrieve a transaction from the blockchain\n\t  actions                     Retrieve all actions with specific account name referenced in authorization or receiver\n\t  schedule                    Retrieve the producer schedule\n\t  transaction_id              Get transaction id given transaction object\n\t```\n\t\n4. cleos set: 部署命令，本项目只用到了部署合约（contract）。\n\n\t```\n\tUsage: cleos set [OPTIONS] SUBCOMMAND\n\t\n\tOptions:\n\t  -h,--help                   Print this help message and exit\n\t\n\tSubcommands:\n\t  code                        Create or update the code on an account\n\t  abi                         Create or update the abi on an account\n\t  contract                    Create or update the contract on an account\n\t  account                     set or update blockchain account state\n\t  action                      set or update blockchain action state\n\t```\n\n5. cleos push: push命令，本项目只用到了push action。\n\n\t```\n\tUsage: cleos push SUBCOMMAND\n\tSubcommands:\n\t  action                      Push a transaction with a single action\n\t  transaction                 Push an arbitrary JSON transaction\n\t  transactions                Push an array of arbitrary JSON transactions\n\t```\n\n6. cleos的全部命令：\n\t\n\t```\n\tUsage: cleos [OPTIONS] SUBCOMMAND\n\t\n\tOptions:\n\t  -h,--help                   Print this help message and exit\n\t  -u,--url TEXT=http://127.0.0.1:8888/\n\t                              the http/https URL where nodeos is running\n\t  --wallet-url TEXT=unix:///Users/treasersmac/eosio-wallet/keosd.sock\n\t                              the http/https URL where keosd is running\n\t  -r,--header                 pass specific HTTP header; repeat this option to pass multiple headers\n\t  -n,--no-verify              don't verify peer certificate when using HTTPS\n\t  --no-auto-keosd             don't automatically launch a keosd if one is not currently running\n\t  -v,--verbose                output verbose actions on error\n\t  --print-request             print HTTP request to STDERR\n\t  --print-response            print HTTP response to STDERR\n\t\n\tSubcommands:\n\t  version                     Retrieve version information\n\t  create                      Create various items, on and off the blockchain\n\t  convert                     Pack and unpack transactions\n\t  get                         Retrieve various items and information from the blockchain\n\t  set                         Set or update blockchain state\n\t  transfer                    Transfer EOS from account to account\n\t  net                         Interact with local p2p network connections\n\t  wallet                      Interact with local wallet\n\t  sign                        Sign a transaction\n\t  push                        Push arbitrary transactions to the blockchain\n\t  multisig                    Multisig contract commands\n\t  wrap                        Wrap contract commands\n\t  system                      Send eosio.system contract action to the blockchain.\n\t```\n\n# 6 测试与使用说明(Test Examples)\n\n可以通过两种方式（两种类型的客户端）来测试智能合约：通过命令行（Cli）和通过Web端（JavaScript API）。\n## 6.1 CLi \n这里我将用到的测试内容都写到test.sh中了。测试的内容比较简单。\n\n```\n# in test.sh:\n# 9. Test the Suprise contract\n\n# test Suprise::showinfo action\ncleos push action pa showinfo '[]' -p vanel@active \n# or:\ncleos push action pa showinfo '[]' -p vanel@active --json\n\n# test Suprise::create action\ncleos push action pa create '[\"vanel\",\"1\",\"testlottery\"]' -p vanel@active\ncleos push action pa create '[\"vanel\",\"2\",\"annualconf\"]' -p vanel@active\ncleos push action pa create '[\"vanel\",\"3\",\"annualconf2\"]' -p vanel@active\n\n# test Suprise::checkbyid action\ncleos push action pa checkbyid '[\"vanel\",\"1\"]' -p vanel@active\ncleos push action pa checkbyid '[\"vanel\",\"2\"]' -p vanel@active\ncleos push action pa checkbyid '[\"vanel\",\"3\"]' -p vanel@active\n\n# test Suprise::checkn action\ncleos push action pa checkn '[\"vanel\",\"2\"]' -p vanel@active \n\n# test Suprise::additem action( a lottery project may have many items for different level of prize )\ncleos push action pa additem '[\"vanel\",\"1\",\"1\",\"iPhone XS\",\"2\",\"25\"]' -p vanel@active # 2 out of max 25 wins the prizes\n\n# test Suprise::addcad action\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"007\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"stevejobs\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"jackma\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"billgates\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"wuuzhaohui\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"1\",\"jaychou\"]' -p vanel@active\n# test Suprise::activate action\ncleos push action pa activate '[\"vanel\",\"1\",\"1\"]' -p vanel@active\ncleos push action pa checkbyid '[\"vanel\",\"1\"]' -p vanel@active\ncleos push action pa checkn '[\"vanel\",\"3\"]' -p vanel@active\n\n# integrated test:\ncleos push action pa additem '[\"vanel\",\"1\",\"3\",\"Tesla model S\",\"1\",\"25\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"3\",\"satoshi\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"3\",\"vitalik\"]' -p vanel@active\ncleos push action pa addcad '[\"vanel\",\"1\",\"3\",\"bytemaster\"]' -p vanel@active\ncleos push action pa activate '[\"vanel\",\"1\",\"3\"]' -p vanel@active\ncleos push action pa checkbyid '[\"vanel\",\"1\"]' -p vanel@active\ncleos push action pa checkn '[\"vanel\",\"3\"]' -p vanel@active\n```\n\n## Web端测试\nOmitted here.\n\n略。\n\n\n\n# Futurn Plan\n未来计划添加或改进的内容：\n\n1. 对于密钥的操作应以更加安全的方式进行。\n2. 客户端要新增“加入别人新建的抽奖项目按钮“。\n3. 奖项创建完以后产生一串短数字或者二维码来方便其他人加入。奖项创建者不再需要自己来完成手动添加参奖者。\n4. 但应该赋予奖项创建者抽奖名单审核的权力。\n5. 参与抽奖者未来需要提供更多的信息。\n6. 客户端能实现以主键（priject_id/item_id）以外的值进行历史记录查询。\n7. 新建奖项不再需要手动提供id，直接输入名称、内容。\n8. 对于访问越界、空内容的错误处理写得更详细。\n9. 对于系统的其他错误处理需要写得更详细。\n10. 对软件整体的测试更应充分。\n11. 改进前端UI。","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreasersimplifies%2Fcoup_de_grace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreasersimplifies%2Fcoup_de_grace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreasersimplifies%2Fcoup_de_grace/lists"}