├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── allEOSAccounts.json ├── package.json ├── src ├── assets │ ├── utils.ts │ └── xEOSHelper.ts ├── betdice.ts └── tasks.ts └── tsconfig.json /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "@babel/env", 4 | "@babel/typescript" 5 | ], 6 | "plugins": [ 7 | "@babel/proposal-class-properties", 8 | "@babel/proposal-object-rest-spread" 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | indent_style = tab 6 | indent_size = 2 7 | end_of_line = lf 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": ["plugin:vue/recommended", "@vue/prettier"], 4 | "plugins": ["html", "vue"], 5 | "rules": { 6 | "eqeqeq": ["error", "always", { "null": "ignore" }], 7 | "arrow-parens": 0, 8 | "generator-star-spacing": 0, 9 | "no-mixed-spaces-and-tabs": 0, 10 | "indent": [0, "tab"], 11 | "semi": ["error", "always"], 12 | "quotes": ["error", "single"], 13 | "spaced-comment": 0, 14 | "space-before-function-paren": 0, 15 | "camelcase": "off", 16 | "no-debugger": 0, 17 | "no-console": ["off", { "allow": ["debug", "info", "warn", "error"] }], 18 | "no-unused-vars": ["warn", { "vars": "local" }] 19 | }, 20 | "env": { 21 | "browser": true, 22 | "node": true 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.lock 22 | /allEOSAccountsLive.json 23 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 200, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "bracketSpacing": true, 7 | "semi": true, 8 | "useTabs": false, 9 | "parser": "typescript", 10 | "arrowParens": "avoid", 11 | "jsxBracketSameLine": false 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EOSAdmin -- EOS管理工具箱 2 | EOS现在虽然有很多效率工具, 但都不够直接了当, 所以抽空写了个, 顺便学习下EOS的相关API. 3 | 4 | ## EOSAdmin的目标 5 | 6 | + 简单的编程实现一些自动化操作. 例如: 自动发币, 币价监控, bancor类发币经济模型测试, 游戏外挂等 7 | + 封装EOS及其侧链(ENU, Fibos)的js API, 一套API通吃所有;[TODO] 8 | + 简单的密钥管理, 小额自动免密操作;[TODO] 9 | + Bancor类发币生成工具, 经济模型建模测试及币价突变点监控预警等. 10 | + 一些Dapp的自动化操作. **目前实现了一个[BetDice](https://betdice.one/?ref=oxoooowatano)自动投注机器人** 11 | 12 | ## 为何选择EOSAdmin 13 | --- 14 | + 基于最新版本的eosjs api(20.0.0-beta1)开发 15 | 16 | + 使用typescript及其相关前端工程化工具 17 | 18 | + 只包含最核心代码, 可以任意集成到项目中 19 | 20 | + 最小类库依赖, 而且尽可能保证浏览器中运行; 运行环境只需要nodejs即可, 而且支持windows, linux和mac等操作系统, 不需安装EOS相关开发工具; 21 | 22 | + 简单粗暴, 可以作为新手API学习参照代码范例 23 | 24 | 25 | ## 基础组件 26 | --- 27 | + **xEOSHelper.ts** EOS类js API公用操作封装类 28 | + **tasks.ts** 钱包及常用任务封装 29 | + **betdice.ts** [BetDice](https://betdice.one/?ref=oxoooowatano)自动下单机器人 30 | 31 | ## 环境搭建 32 | --- 33 | + 安装nodejs, 去[官网](https://nodejs.org)下载v10.x版本NodeJs,并安装; 34 | 35 | + 在命令行下安装cnpm: 36 | 37 | ```shell 38 | npm install -g cnpm --registry=https://registry.npm.taobao.org 39 | ``` 40 | + 进入根目录, 安装相关全局工具和相关依赖: 41 | 42 | ```shell 43 | cnpm install 44 | ``` 45 | + 在根目录下添加`allEOSAccountsLive.json` 文件保存下单EOS帐号的active和owner(可空)公钥私钥. 46 | 47 | **注意:** 48 | 49 | 1. 这个文件只存储在本地, 只要你保管好这个文件不泄漏, 那么你的私钥也是安全的, 程序代码完全开源, 没有后门盗窃你的私钥. 50 | 1. 如果还是不放心,请使用自己的零钱钱包帐号, 不要在这个帐号中存放大额资金 51 | 1. 下一步准备使用一个通用的加密算法管理此钱包文件, 敬请期待:) 52 | 1. `allEOSAccounts.json` 为本人测试环境使用公钥私钥, 请不要乱动, 谢谢! 53 | 54 | ```json 55 | { 56 | "oxwatanox345": [ 57 | "EOS65S3Fm8nQcV1mEjbNsBCZJxkrtiS6P7yadhohCq2bNHcE7ygeD", 58 | "5JjnywysiRmZ6eyC7MbcnTgRDW3GgtYsFsh7Psny19Jvrv6ZUwL", 59 | "", 60 | "" 61 | ] 62 | } 63 | ``` 64 | 65 | + 修改机器人启动参数 66 | 67 | ```typescript 68 | let betDice = new BetDice('oxoooowatano', 'DICE', 50, 100);//下单帐号, 下单代币类型,支持(EOE和DICE), 投注数字, 下单金额基数 69 | ``` 70 | 71 | 1. 运行**[BetDice](https://betdice.one/?ref=oxoooowatano)机器人** 72 | ```shell 73 | npm run betdice 74 | ``` 75 | 76 | 77 | 78 | ## BetDice自动下单机器人 79 | 80 | ### 概述 81 | 82 | **[BetDice](https://betdice.one/?ref=oxoooowatano)**游戏最近火爆异常, 可以低成本获得一些DICE代币进行游戏, 所以无聊时可以玩玩, 非常有意思! 但是在手机和PC桌面玩时非常麻烦,每次下单后都要点击多次确认,手机上还要输入密码,玩多了鼠标受不鸟:( 83 | 84 | 而且最关键的是这类游戏可以使用一种策略保证长期的收益. 所以就写了个机器人给大家薅一下项目方的羊毛,哈哈 85 | 86 | ### 策略说明 87 | 88 | 基本思路按照大神[比特币硕士-杨超](https://weibo.com/yangchao8)的策略: 89 | 90 | + 持续小额连续投注 91 | + 当输了时投注金额加倍; 赢了时投注金额重置为初始值 92 | + [新增] 定期自动随机更换下注加密种子seed 93 | + [新增] 连续输n局后自动休息一会 94 | + [新增] 到达最小金额`minBalance`或最大金额`maxBalance`时自动终止机器人 95 | + [新增] 到达最大投注倍数`maxBetPloidy`时停止增加倍数, 并适当休息一会 96 | + 支持EOS和DICE投注, 可以 97 | + [TODO] 目前EOS的API不能正确获取投注结果信息获取, 所以目前直接比较代币金额变化判断游戏输赢. 正确的相关代码已经注释, 请懂整的哥们帮忙看看什么原因,谢谢! 98 | + 支持DEBUG模式快速粗暴测试策略, 修改 `const isDebugMode = true;`. 99 | + BetDice官方绝对在随机算法里动了手脚, 长期运行程序收益会越来越不稳定, 建议定期换号运行. 100 | + 欢迎各位策略达人分享你们的成功经验, 我来改进策略. 101 | + CPU资源不够的兄弟们可以使用[虎符CPU bank](https://eos.hoo.com/cpu)租用, 感觉还是很不错的, 费用也低. 妈妈再也不用担心我的CPU不够用了:) 102 | 103 | ### 源代码 104 | 105 | 机器人源代码在`src\betdice.ts`文件中, 使用typescript编写, 请自行研究代码,谢谢! 106 | 107 | ## 关于我们 108 | 109 | + [微博](https://www.jianshu.com/u/ffQXX5) 110 | + [github主页](https://github.com/watano) 111 | + EOS帐号 [oxoooowatano](https://eospark.com/MainNet/account/oxoooowatano), 欢迎打赏聊天! 112 | -------------------------------------------------------------------------------- /allEOSAccounts.json: -------------------------------------------------------------------------------- 1 | { 2 | "oxwatanox311": [ 3 | "EOS7whGtyJQwRuPUbkNZYMi2L4FPqRfKy6EVwx1Rfxwz3TSfpTVrk", 4 | "5Kdqc2HQeHjPWR91mvV1V88bMb34ANqALfpVbJZoWduPL8n8c6m", 5 | "EOS66dAoZPiCy1QyAVbc2r95xaFKvTPjZRj172FP6rLVeWUt5QA9x", 6 | "5Ji2xwSfrRATGUNuPv7Be38H8YWHkFpkSWtQ8hpZdEtg3gQckyR" 7 | ], 8 | "oxwatanox312": [ 9 | "EOS8GasZYqvfzWTg8ExB8AH31npaXmrd6HgdkCk26ce51xugfDhio", 10 | "5KV2HkaiTW7icbcWHstfieNkVwWqzd4gpNtwLuNqcTf6bPZrG3p", 11 | "EOS7k5cunvBYJyG6W5SFevBNmJZXrAgCosb7vHS9TEiiQyBv273bH", 12 | "5K8SynBmyCVBtGwHzAVjvgcbYhDuhsV1uFwpkr2MptvDAmyzU9o" 13 | ], 14 | "oxwatanox313": [ 15 | "EOS6vMVCz9DEUKirGHp7knDosWQLACxTpm2W7JrQ9mXkf1F11vXXC", 16 | "5K8yKpSJAvMMVW3v5ui16EZDqzVcmmnQJxWea3tnrdhcUjBZgQd", 17 | "EOS6ziNEnDgokXUvunbzA7CDTp4RHdWprKpFuzA8RqqP9FQVro8sv", 18 | "5Jcqcg65y6Hf5qK9Sn6vZHfNDQK3sYS27pHyMrRYo2fGvnVXNgA" 19 | ], 20 | "oxwatanox314": [ 21 | "EOS5S2N765Hbxh2uYCWUGTgSGVjEfkG2R8X8wmxNwxPJLMoS3NPyi", 22 | "5JwaPr6VXD4wmRnkepLxNDmzMJcG7PR8eb3aLrKfjRj8HAE2GjE", 23 | "EOS5gEsKfMLBmN9YdikyYD2JxtyWJewhagN3y3RWKFaKoDM9Mhee8", 24 | "5JSKaJGyrjPH7LwqgAR3vjZXmYgpQu7k6iM7sTawKp1pN2aRRxi" 25 | ], 26 | "oxwatanox315": [ 27 | "EOS5ECMJfNiQKvax8n1bJ7CLbrtxfyYNkFQZMpHk6SroHjWekY41q", 28 | "5HsHacEJW9oa2pMULCCzjf21UAha3RsbgBwu5fy7riyu2b8PiZ4", 29 | "EOS5v6AZM6cDCCLNM6fAresktmucoHszRV33Hde6HYJjkfUB3jAJU", 30 | "5KU11DkjUACyB5GNysw8GxJkaUfWV7x4EdQv8p4kTvoZLQejpfb" 31 | ], 32 | "oxwatanox321": [ 33 | "EOS69CtpU7naTNBr1P82NiTpeHUqeZcow5FSUQ5C6M1V23pouPnWh", 34 | "5Jx2oXA8TTN6QGCmnzYZRzj8dag9WdECLM8rQQsqpBeiHUidVKE", 35 | "EOS5yU4f6pr4EuZT9fgectNDk8p5bq6Q1MTSkMngCptJuxL7mWfwW", 36 | "5JKPYcUrduPhCw6Paj1hvjhfRAQMhi97iERVNduqJCaDpeTJj5u" 37 | ], 38 | "oxwatanox322": [ 39 | "EOS5DVnGLSn8iobJC6DNLHtzTgnJzzZcGHHF12Zto7Dj3Ht3g4BAa", 40 | "5JfmQ7p9iCYNLUhj5LGdWHnu54zSYJnAvz1S7D5HrMJxRF65Ssi", 41 | "EOS8PzQnbSwsDeZyYmkUQw4LuogGQeYsTeHfuQGvJi5i5quCTj3Bs", 42 | "5Jj11saCj2eKzaQHMvJeNrhnnTTSc2NmUN3nvqYhQiGAWKiZnWL" 43 | ], 44 | "oxwatanox323": [ 45 | "EOS73SjByqejU6FfbEsStaNEmGZfDLuC7tHe8HZkGoHivq9zdP9rh", 46 | "5JTTd8AFi8CVVkvE6xSVkfjWwX8bGzzU6HfhfHDXPUDysTiJTV6", 47 | "EOS7vdSDAXg4C4oxfxBXzgLr5D2FTrpadb2hV2tYnEmMLMYpQNZ1H", 48 | "5JZkLV5527fT9f8UCFmTWH6hhGVFekLgwA9hxuS1ssvt36RMxWf" 49 | ], 50 | "oxwatanox324": [ 51 | "EOS4xwQquZh4RiEHMPrxxNpqmtepn1BQiRu3uv2r49fFHdfko6qoR", 52 | "5JKqR9gxZWXiXnFSKpytJh9LLhf5Yef8vAiuYBSY2WUg9hLr7ME", 53 | "EOS7fDqrEXTvxB57khkN2UTcuNr4C3HdUHvXmpXUfMKHnkWi4vZmS", 54 | "5JNrnaN28acUnMtZLj6kWqodALrf7r3LYMaeirfhBYHcR5NF2o4" 55 | ], 56 | "oxwatanox325": [ 57 | "EOS5z2Ls2TxfEN972fTHeDyeuupMhz8FTVUdd1YLNr443U7L1ibYP", 58 | "5JKgrTAND9ctFsbRwKvoYos4uCEPCeRwv6c26avXLAsemKdCHv7", 59 | "EOS4uNuTbpnWb1r521XzWQGtzQ1o6HeEYUwtDrKnQZVYoV2q86mun", 60 | "5KeMoZYnVXLV4QmtMZJ8xLMHdmvu4qPEuKJ3SbvmRofDjGufqHN" 61 | ], 62 | "oxwatanox331": [ 63 | "EOS6kVb7F489sFhpQp2kvcyQ1dogk2YZrwxjxWXWo7KB72zJYCKUo", 64 | "5Kc3yhLJwiRV7wpwiVXqhdTTADZZjSHfYtZJZ8A68AEQMXS23Sf", 65 | "EOS51qSEzAo6vcVGH4cQeNaVvJyTRqJxtd2o1JAyyFk3XG7s5tbPs", 66 | "5JYjmQNiRyPgieCARcLZo3vvDKquKnrzhJxfsrcCAVYNQP3ei5G" 67 | ], 68 | "oxwatanox332": [ 69 | "EOS7RqFKc7GEFrq17hY4ggahiSzL7uis6KqVCaq2ek923SYUMwAzJ", 70 | "5JYc7yBzpz2u8tR7QgBZEygsT86DHi8txaFF1wKJEv1uoRbAfLL", 71 | "EOS4uC91hnZVxv5WGaFT8F7imbbV5UcYhx8G2TNdS24krCG9RwymT", 72 | "5KktuKqAiiwaFfbMmgh6uv7kgccXhyuy9qcKqfvzxSWcZmHykyC" 73 | ], 74 | "oxwatanox333": [ 75 | "EOS5EW717McuWk5a9HuBvxFyyPSG8AmbAyrBzCbPdbbi5FUDAPgx2", 76 | "5HqiPmi2uXVACWvdAa2w16FefuPKpVvmJFYJNBv4fzUcp58dPAq", 77 | "EOS5HEakFx4A6fnfeDpV7PjUjTc5yYPFR1u7foLdxmEafCZbGfhXJ", 78 | "5JgRHk4veMCr9Dgzo1e8B9WmZuPNEbxpYygY9NixwsakGugNMMD" 79 | ], 80 | "oxwatanox334": [ 81 | "EOS7JZ623QZnXbrJjs6CFzsTLiwgXXGDo4wqxdb8qMzQU31G85Uys", 82 | "5Kg5zBdgfRgAEMntb7nfkDpcHQdKo6v9tr5cqYjUWxUZWUsdyJx", 83 | "EOS5v89WtEJ3oSQebkMxVR5pQ1typBo2XEamKPaRZk3pmfxwUGJBh", 84 | "5KEgwQVWtQrvyMtNz2JQptidAFoCMzPntsXR7C73YQVE1NQsYY8" 85 | ], 86 | "oxwatanox335": [ 87 | "EOS6jH2k9YKP6QanjGf3WWM6X6Sa3E4cVTwss6xaaj6wvyGJVif7u", 88 | "5Hrqik8J5gqswVC1e5KEay6rE1opXgu7jQk28BgbX7qzFsq8no1", 89 | "EOS64mZx5P4uYYGqK7AJiNn8rt4ASHpHWQR12WmnxPoMSxWbiZDKX", 90 | "5Kcn3BpUvuiRsyGR2KZjgMTZc3zedsag1xk1PB3UQrdBqyLeNyf" 91 | ], 92 | "oxwatanox341": [ 93 | "EOS7bAS2QVvPxwHXYwmR7wzwGCB1vPeruADLV1kEe7zGD35GuowsV", 94 | "5K9mrNbJaDfviFHwm1UuK3TN6LdrLY2zAQHkQ5btFyP6xt9qXvc", 95 | "EOS8GLXqh1bQsqWFEj8p7LwgqcKSYu1Evk5nn1JuJ6iaZd1e66mW1", 96 | "5K9T8NMFWkoH4E6yZqwYZAUPBNai3B2ARJcxXcE9redAfppxdBf" 97 | ], 98 | "oxwatanox342": [ 99 | "EOS7rk7C3x331ExhqfBccS3E3qYjT3YCXpkYwiUHQjQLP24vtbWY2", 100 | "5KSvHMmHm7znvcBUn4o5zM866zEviKHeZCNog8ERviAGx5xV2qz", 101 | "EOS4wypHnDEBNFjbJRTEzryVi5WfYWf3gggQSXAcR5SZS3HEmJQ7A", 102 | "5KGDVmivBoj7EEPM2xz9GKHCEAZSXHENq8Lg9UscT8sEYEGHSUM" 103 | ], 104 | "oxwatanox343": [ 105 | "EOS7KkeXJUsYPP51E8CKntYiFsD1kmKGcVwHyC1eXZgWfivcACnUh", 106 | "5KdYKYVGDm6gQjKu1kP4KA3i9nFYKsnLq6pjiQk9rGjfWh4oJ8Y", 107 | "EOS7e1Tq6EGbTtCrE4tyYaeve4GB4dNp5qcajqUtJDJxxV7ufUncD", 108 | "5JZ4wQyJ2jtw8ciyeZqpHTHJTnVjZMN2Sz9SHbNGv5YE4p537Er" 109 | ], 110 | "oxwatanox344": [ 111 | "EOS8JKJAQyMbpwekymswPDDuHUssGLYL1VEbE9bNkrxBEwRAnMFqx", 112 | "5JLnAzn6VjaZBJ1KWH3Y2ruBKKRZEs3MwW5LtgSZ6FCWvryNhGt", 113 | "EOS4wbSEStgjfrW2gVyHz3AxnWiq5JD7G8YQkKBpLDuUhN1dpeo5N", 114 | "5JEJr2e6quv4FWH1dkaAAtwBXGFs7fNK1Efn9oj1ckqu8vuC9n3" 115 | ], 116 | "oxwatanox345": [ 117 | "EOS65S3Fm8nQcV1mEjbNsBCZJxkrtiS6P7yadhohCq2bNHcE7ygeD", 118 | "5JjnywysiRmZ6eyC7MbcnTgRDW3GgtYsFsh7Psny19Jvrv6ZUwL", 119 | "EOS63sVQmupKMXu6cG5mYcKcDgF9neaM4AbZ6tk4NoTEWKUKD1fpN", 120 | "5KFheNG1HqbvbCJ3v2gHUfYxySkQBbRFS7vaHbkzEZ2WzVgpZMv" 121 | ] 122 | } 123 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eos-admin", 3 | "version": "1.0.0", 4 | "license": "MIT", 5 | "author": "watano@qq.com", 6 | "scripts": { 7 | "type-check": "tsc --noEmit", 8 | "type-check:watch": "npm run type-check -- --watch", 9 | "build": "npm run build:types && npm run build:js", 10 | "build:types": "tsc --emitDeclarationOnly", 11 | "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline", 12 | "betdice": "ts-node src/betdice.ts" 13 | }, 14 | "devDependencies": { 15 | "@babel/cli": "^7.0.0", 16 | "@babel/core": "^7.0.0", 17 | "@babel/plugin-proposal-class-properties": "^7.0.0", 18 | "@babel/plugin-proposal-object-rest-spread": "^7.0.0", 19 | "@babel/preset-env": "^7.0.0", 20 | "@babel/preset-typescript": "^7.0.0", 21 | "@babel/runtime": "^7.1.2", 22 | "ts-node": "^7.0.1", 23 | "tslint": "^5.11.0" 24 | }, 25 | "dependencies": { 26 | "@types/node": "^10.11.4", 27 | "@types/node-fetch": "^2.1.2", 28 | "eosjs": "^20.0.0-beta1", 29 | "node-fetch": "^2.2.0", 30 | "typescript": "^3.0.3" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/assets/utils.ts: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | export function loadJson(path: string): any { 4 | return JSON.parse(fs.readFileSync(path, 'utf-8')); 5 | } 6 | 7 | export function genEosName(basename: string, size = 10, start = 0, fn: (accountName: string) => void) { 8 | for (var i = start; i < size; i++) { 9 | let n = ((i - (i % 5)) / 5 + 1) * 10 + (i % 5) + 1; 10 | fn(basename + '' + n); 11 | } 12 | } 13 | 14 | export function dumpResult(result: any): void { 15 | console.log(result); 16 | } 17 | export function dumpError(e: any): void { 18 | if (e.json && e.json.code === 500 && e.json.error && typeof e.json.error.code === 'number') { 19 | console.log(e.json.error); 20 | } else { 21 | console.error(e); 22 | } 23 | } 24 | 25 | export function sleep(time = 0) { 26 | return new Promise((resolve, reject) => { 27 | setTimeout(() => { 28 | resolve(); 29 | }, time); 30 | }); 31 | } 32 | 33 | export function parseBalance(allBalances: string[], symbol: string): number { 34 | let balance = 0; 35 | try { 36 | for (var b of allBalances) { 37 | if (b.indexOf(symbol) > 0) { 38 | return parseAmount(b, symbol); 39 | } 40 | } 41 | } catch (e) { 42 | console.error(e); 43 | } 44 | return balance; 45 | } 46 | 47 | export function parseAmount(amount: string, symbol = 'EOS'): number { 48 | if (amount.indexOf(symbol) > 0) { 49 | return Number(amount.substring(0, amount.indexOf(' '))); 50 | } 51 | return 0; 52 | } 53 | export function amount(amount: any, symbol = 'EOS') { 54 | return ( 55 | Number(amount) 56 | .toFixed(4) 57 | .toString() + 58 | ' ' + 59 | symbol 60 | ); 61 | } 62 | 63 | export function explainActResult(act: any) { 64 | let actText = ''; 65 | let actKey = act.account + ':' + act.name; 66 | if (actKey === 'eosio.token:transfer') { 67 | if (act.data.to === 'eosio.ram') { 68 | if (act.data.memo === 'buy ram') actText = `[EOS购买RAM]from:${act.data.from}, quantity:${act.data.quantity}`; 69 | } else if (act.data.to === 'eosio.ramfee') { 70 | actText = `[EOS购买RAM费用]from:${act.data.from}, quantity:${act.data.quantity}, memo:${act.data.memo}`; 71 | } else if (act.data.to === 'eosio.stake') { 72 | if (act.data.memo === 'stake bandwidth') actText = `[EOS抵押带宽]from:${act.data.from}, quantity:${act.data.quantity}`; 73 | } else if (act.data.to === 'betdiceadmin' && act.data.memo.indexOf('action:bet,') === 0) { 74 | actText = `[BetDice下注]from:${act.data.from}, quantity:${act.data.quantity}, memo:${act.data.memo}`; 75 | } else { 76 | actText = `[代币转帐]from:${act.data.from}, to:${act.data.to}, quantity:${act.data.quantity}, memo:${act.data.memo}`; 77 | } 78 | } else if (actKey === 'eosio:delegatebw') { 79 | actText = `[EOS抵押]from:${act.data.from}, receiver:${act.data.receiver}, stake_net_quantity:${act.data.stake_net_quantity}, stake_cpu_quantity:${act.data.stake_cpu_quantity}, transfer:${ 80 | act.data.transfer 81 | }`; 82 | } else if (actKey === 'eosio:undelegatebw') { 83 | actText = `[EOS赎回]from:${act.data.from}, receiver:${act.data.receiver}, unstake_net_quantity:${act.data.unstake_net_quantity}, unstake_cpu_quantity:${act.data.unstake_cpu_quantity}`; 84 | } else if (actKey === 'eosio:buyram') { 85 | actText = `[EOS购买RAM]payer:${act.data.payer}, receiver:${act.data.receiver}, quant:${act.data.quant}`; 86 | } else if (actKey === 'eosio:sellram') { 87 | actText = `[EOS出售RAM]account:${act.data.account}, bytes:${act.data.bytes}`; 88 | } else if (actKey === 'eosio:voteproducer') { 89 | actText = `[BP投票]voter:${act.data.voter},proxy:${act.data.proxy}, producers:[${act.data.producers.join(', ')}]`; 90 | } else if (actKey === 'eosio:refund') { 91 | actText = `[EOS退还]owner:${act.data.owner}`; 92 | } else { 93 | actText = JSON.stringify(act); 94 | } 95 | return actText; 96 | } 97 | -------------------------------------------------------------------------------- /src/assets/xEOSHelper.ts: -------------------------------------------------------------------------------- 1 | import EosJs from 'eosjs'; 2 | const EosEcc = require('eosjs-ecc'); 3 | const fetch = require('node-fetch'); 4 | const { TextDecoder, TextEncoder } = require('text-encoding'); 5 | import * as utils from './utils'; 6 | 7 | const TestNet = { 8 | httpEndpoint: 'https://api.kylin-testnet.eospace.io', 9 | chainId: '5fff1dae8dc8e2fc4d5b23b2c7665c97f9e9d8edf2b6485a86ba311c25639191', 10 | }; 11 | const MainNet = { 12 | // httpEndpoint: 'https://nodes.get-scatter.com', 13 | httpEndpoint: 'https://api.eosnewyork.io', 14 | // httpEndpoint: 'https://api.eoslaomao.com', 15 | chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', 16 | }; 17 | 18 | export default class xEOSHelper { 19 | protected _xeosType = 'eos'; 20 | protected _xeosSymbol = 'EOS'; 21 | protected _xeosChainId: string = ''; 22 | public _xeos: any = null; 23 | protected _xeosEcc: any = null; 24 | 25 | constructor(account: string[] = ['', '', '', ''], permission = 'active', network = MainNet) { 26 | this._xeosEcc = EosEcc; 27 | let eosOption = { 28 | httpEndpoint: network.httpEndpoint, 29 | chainId: network.chainId, 30 | keyProvider: permission === 'active' ? account[1] : account[3], 31 | expireInSeconds: 60, 32 | broadcast: true, 33 | // debug: true, 34 | // verbose: true, 35 | logger: { 36 | // log: console.log, 37 | error: console.error, 38 | }, 39 | }; 40 | //console.log(eosOption); 41 | //this._xeos = EosJs(eosOption); 42 | 43 | const rpc = new EosJs.Rpc.JsonRpc(network.httpEndpoint, { fetch }); 44 | const signatureProvider = new EosJs.SignatureProvider(eosOption.keyProvider !== '' ? [eosOption.keyProvider] : []); 45 | this._xeos = new EosJs.Api({ rpc, signatureProvider, chainId: network.chainId, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() }); 46 | } 47 | 48 | protected _errorHandler(e: any, errorBack: (e: any) => void) { 49 | if (typeof errorBack === 'function') { 50 | console.error(e); 51 | errorBack(e); 52 | } else { 53 | if (e.isError && e.message) { 54 | console.log(e.message); 55 | } 56 | } 57 | } 58 | public getInfo(): any { 59 | return this._xeos.rpc.get_info({}); 60 | } 61 | 62 | public privateToPublic(privateKey: string): string { 63 | return this._xeosEcc.privateToPublic(privateKey); 64 | } 65 | public validPrivateKey(privateKey: string) { 66 | return this._xeosEcc.isValidPrivate(privateKey); 67 | } 68 | public validPublicKey(publicKey: string) { 69 | return this._xeosEcc.isValidPublic(publicKey); 70 | } 71 | public randomPrivateKey(): Promise { 72 | return this._xeosEcc.randomKey(); 73 | } 74 | public getAccount(accountName: string) { 75 | return this._xeos.getAccount(accountName); 76 | } 77 | public parseBalances(res: any): any { 78 | let fn: any = null; 79 | if ('fibos' === this._xeosType) { 80 | fn = (row: any) => row.balance.quantity.split(' ').reverse(); 81 | } else { 82 | fn = (row: any) => row.balance.split(' ').reverse(); 83 | } 84 | return res.rows.map(fn); 85 | } 86 | public getAccountBalance(accountName: string) { 87 | return this._xeos.rpc.get_table_rows({ 88 | code: 'eosio.token', 89 | scope: accountName, 90 | table: 'accounts', 91 | limit: 100, 92 | json: true, 93 | }); 94 | } 95 | public newaccount(trx: any, creator: string, newaccount: string, oPubKey: string, aPubKey: string) { 96 | return trx.newaccount({ 97 | creator: creator, 98 | name: newaccount, 99 | owner: oPubKey, 100 | active: aPubKey, 101 | }); 102 | } 103 | public buyram(trx: any, creator: string, receiver: string, ram = 8) { 104 | return trx.buyram({ 105 | payer: creator, 106 | receiver: receiver, 107 | quant: utils.amount(ram, this._xeosSymbol), 108 | }); 109 | } 110 | public buyRambytes(trx: any, payer: string, receiver: string, bytes: string) { 111 | return trx.buyrambytes({ 112 | payer: payer, 113 | receiver: receiver, 114 | bytes: bytes, 115 | }); 116 | } 117 | public sellram(trx: any, account: string, bytes: string) { 118 | return trx.sellram({ 119 | account: account, 120 | bytes: bytes, 121 | }); 122 | } 123 | public claimrewards(trx: any, owner: string) { 124 | return trx.claimrewards({ 125 | owner: owner, 126 | }); 127 | } 128 | public refund(trx: any, owner: string) { 129 | return trx.refund({ 130 | owner: owner, 131 | }); 132 | } 133 | public bidname(trx: any, bidder: string, newname: string, bid: string) { 134 | return trx.bidname({ 135 | bidder: bidder, 136 | newname: newname, 137 | bid: bid, 138 | }); 139 | } 140 | public linkauth(trx: any, account: string, code: string, type: string, requirement: string) { 141 | return trx.linkauth({ 142 | account: account, 143 | code: code, 144 | type: type, 145 | requirement: requirement, 146 | }); 147 | } 148 | public updateauth(trx: any, account: string, permission: string, parent: string, auth: string) { 149 | return trx.updateauth({ 150 | account: account, 151 | permission: permission, 152 | parent: parent, 153 | auth: auth, 154 | }); 155 | } 156 | public setabi(trx: any, account: string, abi: string) { 157 | return trx.setabi({ 158 | account: account, 159 | abi: abi, 160 | }); 161 | } 162 | public setcode(trx: any, account: string, vmtype: string, vmversion: string, code: string) { 163 | return trx.setcode({ 164 | account: account, 165 | vmtype: vmtype, 166 | vmversion: vmversion, 167 | code: code, 168 | }); 169 | } 170 | public regproducer(trx: any, producer: string, producer_key: string, url: string, location: string) { 171 | return trx.regproducer({ 172 | producer: producer, 173 | producer_key: producer_key, 174 | url: url, 175 | location: location, 176 | }); 177 | } 178 | public unregprod(trx: any, producer: string) { 179 | return trx.unregprod({ 180 | producer: producer, 181 | }); 182 | } 183 | public delegatebw(trx: any, creator: string, receiver: string, net = 1, cpu = 1) { 184 | return trx.delegatebw({ 185 | from: creator, 186 | receiver: receiver, 187 | stake_net_quantity: utils.amount(net, this._xeosSymbol), 188 | stake_cpu_quantity: utils.amount(cpu, this._xeosSymbol), 189 | transfer: 0, 190 | }); 191 | } 192 | public undelegatebw(trx: any, payer: string, receiver: string, net = 1, cpu = 1) { 193 | return trx.undelegatebw({ 194 | from: payer, 195 | receiver: receiver, 196 | unstake_net_quantity: utils.amount(net, this._xeosSymbol), 197 | unstake_cpu_quantity: utils.amount(cpu, this._xeosSymbol), 198 | transfer: 0, 199 | }); 200 | } 201 | /** 202 | * 创建xEOS新账号,新账号购买4xEOS内存,各抵押1个xEOS的CPU/NET,请保证账号中有至少6xEOS 203 | */ 204 | public createAccount(creator: string, newaccount: string, oPubKey: string, aPubKey: string, ram = 8, net = 1, cpu = 1) { 205 | return this._xeos.transaction('eosio', (trx: any) => { 206 | this.newaccount(trx, creator, newaccount, oPubKey, aPubKey); 207 | //为新账号充值RAM 208 | this.buyram(trx, creator, newaccount, ram); 209 | //为新账号抵押CPU和NET资源 210 | this.delegatebw(trx, creator, newaccount, net, cpu); 211 | }); 212 | } 213 | public buyAccountResource(creator: string, newaccount: string, ram = 8, net = 1, cpu = 1) { 214 | return this._xeos.transaction('eosio', (trx: any) => { 215 | //为新账号充值RAM 216 | this.buyram(trx, creator, newaccount, ram); 217 | //为新账号抵押CPU和NET资源 218 | this.delegatebw(trx, creator, newaccount, net, cpu); 219 | }); 220 | } 221 | public contract( 222 | code = 'eosio.token', 223 | options = { 224 | accounts: [ 225 | { 226 | blockchain: this._xeosType, 227 | chainId: this._xeosChainId, 228 | }, 229 | ], 230 | } 231 | ) { 232 | return this._xeos.rpc.contract(code, options); 233 | } 234 | public transfer(code = 'eosio.token', fromAccount: string, toAccount: string, amount: string, memo: string) { 235 | let jsonData = { 236 | actions: [ 237 | { 238 | account: code, 239 | name: 'transfer', 240 | authorization: [ 241 | { 242 | actor: fromAccount, 243 | permission: 'active', 244 | }, 245 | ], 246 | data: { 247 | from: fromAccount, 248 | to: toAccount, 249 | quantity: amount, 250 | memo: memo, 251 | }, 252 | }, 253 | ], 254 | }; 255 | //console.log(jsonData); 256 | return this._xeos.transact(jsonData, { 257 | blocksBehind: 3, 258 | expireSeconds: 30, 259 | }); 260 | } 261 | 262 | public getActions(account: string, pos = -1, offset = -1): Promise { 263 | //console.log(account, pos, offset); 264 | return this._xeos.rpc.history_get_actions(account, pos, offset); 265 | } 266 | 267 | public tokenBalance(code = 'eosio.token', account: string) { 268 | return this._xeos.rpc.get_currency_balance(code, account); 269 | } 270 | public tokenStats(code = 'eosio.token', symbol: string) { 271 | let data = { 272 | code: code, 273 | symbol: symbol, 274 | }; 275 | console.log(data); 276 | return this._xeos.getCurrencyStats(data); 277 | } 278 | public tokenContract(code = 'eosio.token', fn: (trx: any) => Promise) { 279 | return this.contract(code, { 280 | accounts: [ 281 | { 282 | blockchain: this._xeosType, 283 | chainId: this._xeosChainId, 284 | }, 285 | ], 286 | }); 287 | } 288 | public tokenTransfer(tokenCode: string, fromAccount: string, toAccount: string, amount: any, memo: string) { 289 | this.tokenContract(tokenCode, (contract: any) => { 290 | return contract.transfer(fromAccount, toAccount, amount, memo); 291 | }); 292 | } 293 | public tokenExchange(tokenCode: string, fromAccount: string, toSymbol: string, amount: any, memo: string) { 294 | this.tokenContract(tokenCode, (contract: any) => { 295 | return contract.exchange(fromAccount, amount, toSymbol, memo); 296 | }); 297 | } 298 | public deloyContract(account: string, wasm: string, abi: string) { 299 | return [this._xeos.setcode(account, 0, 0, wasm), this._xeos.setabi(account, JSON.parse(abi))]; 300 | } 301 | public actionContract(contractName = 'eosio.token', action: string, actionData: any, actor: string, permission = 'active') { 302 | let jsonData = { 303 | account: contractName, 304 | name: action, 305 | authorization: [ 306 | { 307 | actor: actor, 308 | permission: permission, 309 | }, 310 | ], 311 | data: actionData, 312 | }; 313 | console.log(jsonData); 314 | return jsonData; 315 | } 316 | public transaction(actions: any, options: any = { broadcast: true }) { 317 | console.log(actions); 318 | return this._xeos.transact( 319 | { 320 | actions: actions, 321 | }, 322 | { 323 | blocksBehind: 3, 324 | expireSeconds: 30, 325 | } 326 | ); 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /src/betdice.ts: -------------------------------------------------------------------------------- 1 | import xEOSHelper from './assets/xEOSHelper'; 2 | import * as tasks from './tasks'; 3 | import * as utils from './assets/utils'; 4 | 5 | const minBalance = 6000; //最小资金量 6 | const maxBalance = 100000; //最大资金量 7 | const maxBetPloidy = 5; //最大投注金额倍数 8 | let seed = 'Kb8F703gFuwj93oWJQ'; //加密种子 9 | let tokenCode = 'betdicetoken'; 10 | const isDebugMode = false; 11 | 12 | export class BetDice { 13 | private account = ''; //下单EOS帐号 14 | private symbol: string; //下注token代码 15 | private balance: number; //账户初始资金数量 16 | private roll: number; //投注号码 17 | private baseDice = 100; //投注金额基数 18 | private betPloidy = 1; //投注金额倍数 19 | 20 | private winCount = 0; //统计赢局总数 21 | private loseCount = 0; //统计输局总数 22 | private serialLoseCount = 0; //连续输局数 23 | private eosapi: xEOSHelper; 24 | 25 | constructor(account: string, symbol = 'DICE', roll = 50, baseDice = 100) { 26 | this.account = account; 27 | this.symbol = symbol; 28 | this.roll = roll; 29 | this.baseDice = baseDice; 30 | this.balance = 3000; 31 | if (symbol === 'DICE') { 32 | tokenCode = 'betdicetoken'; 33 | } else { 34 | tokenCode = 'eosio.token'; 35 | } 36 | this.eosapi = tasks.initEOSApi(this.account); 37 | this.updateSeed(); 38 | } 39 | 40 | public fetchBalance(callBack: () => void) { 41 | if (isDebugMode) { 42 | callBack(); 43 | } else { 44 | this.eosapi 45 | .tokenBalance(tokenCode, this.account) 46 | .then((result: any) => { 47 | this.balance = utils.parseBalance(result, this.symbol); 48 | callBack(); 49 | }) 50 | .catch(utils.dumpError); 51 | } 52 | } 53 | 54 | public async updateSeed() { 55 | let newSeed = await this.eosapi.randomPrivateKey(); 56 | seed = newSeed.substring(0, 18); 57 | console.log(`自动更换随机seed[${seed}]!`); 58 | } 59 | 60 | public async doPlay(callBack: (diceNumber: number, payout: number) => void) { 61 | if (isDebugMode) { 62 | callBack(Math.round(Math.random() * 100), this.betPloidy * this.baseDice * 2); 63 | } else { 64 | let order = utils.amount(this.betPloidy * this.baseDice, this.symbol); 65 | console.log('下注: ' + order); 66 | await this.eosapi.transfer(tokenCode, this.account, 'betdiceadmin', order, 'action:bet,seed:' + seed + ',rollUnder:' + this.roll + ',ref:ha3toojugege'); 67 | //暂停30多秒 68 | utils.sleep((Math.floor(Math.random() * 10 + 1) + 30) * 1000); 69 | 70 | const resultBalance = await this.eosapi.tokenBalance(tokenCode, this.account); 71 | const newBalance = utils.parseBalance(resultBalance, this.symbol); 72 | let diceNumber = 90; 73 | let payout = 0; 74 | if (newBalance > this.balance) { 75 | diceNumber = 1; 76 | payout = newBalance - this.balance; 77 | if (this.winCount > 2 && this.winCount % 20 == 1) { 78 | //连赢后自动更换随机seed 79 | this.updateSeed(); 80 | } 81 | } 82 | callBack(diceNumber, payout); 83 | // const result = await this.eosapi.getActions('betdicelucky', 0, 200); 84 | // //console.log(result); 85 | // for (var act of result.actions) { 86 | // let actionInfo = act.action_trace.act; 87 | // if (act.action_trace.receipt.receiver === this.account && actionInfo.name === 'betreceipt') { 88 | // let diceNumber = actionInfo.data.diceNumber; 89 | // if (typeof diceNumber !== 'number' || diceNumber < 0 || diceNumber > 100) { 90 | // console.error(act); 91 | // utils.sleep(1000 * 10); 92 | // } else { 93 | // let payout = utils.parseAmount(actionInfo.data.payoutAsset); 94 | // callBack(diceNumber, payout); 95 | // } 96 | // } 97 | // } 98 | } 99 | } 100 | 101 | public action() { 102 | this.fetchBalance(() => { 103 | this.doPlay((diceNumber, payout) => { 104 | let order = this.betPloidy * this.baseDice; 105 | if (diceNumber < this.roll) { 106 | console.log('赢' + this.balance + '<----------------' + payout); 107 | this.winCount++; 108 | this.serialLoseCount = 0; 109 | this.balance += payout; 110 | this.betPloidy = 1; 111 | } else { 112 | console.error('输' + this.balance + '->' + order); 113 | this.loseCount++; 114 | this.serialLoseCount++; 115 | if (this.serialLoseCount > maxBetPloidy + 2) { 116 | console.log(`连续输了${this.serialLoseCount}局了,休息一会.....`); 117 | this.serialLoseCount = 0; 118 | utils.sleep(62 * 1000); 119 | } 120 | this.balance -= order; 121 | if (this.betPloidy <= 1) { 122 | this.betPloidy = 2; 123 | } else if (this.betPloidy >= maxBetPloidy) { 124 | this.betPloidy = maxBetPloidy; 125 | } else { 126 | //this.betPloidy++; 127 | this.betPloidy *= 2; 128 | } 129 | } 130 | if (minBalance < this.balance && this.balance < maxBalance && this.balance > this.betPloidy * this.baseDice) { 131 | this.action(); 132 | } else { 133 | console.log('------------------------------总资金:' + this.balance + ', 总计:赢' + this.winCount + '局, 输' + this.loseCount + '局'); 134 | } 135 | }); 136 | }); 137 | } 138 | 139 | public async statistics() { 140 | console.log('----------------游戏数据统计---------------------'); 141 | let count = 0; 142 | let offset = 1900; 143 | for (var pos = 0; ; ) { 144 | const result = await this.eosapi.getActions('betdicetoken', pos, offset); 145 | //console.log(result); 146 | for (var act of result.actions) { 147 | //console.log(act.block_time); 148 | count++; 149 | let action_trace = act.action_trace; 150 | //console.log(act.block_time, action_trace.act.name, action_trace.act.account); 151 | // if (action_trace.act.name === 'betreceipt') { 152 | // if (action_trace.receipt.receiver === this.account && action_trace.act.account === 'betdiceadmin') { 153 | console.log(`trx_id=${action_trace.trx_id}, total_cpu_usage=${action_trace.total_cpu_usage}, block_time=${action_trace.block_time}`); 154 | console.log(utils.explainActResult(action_trace.act)); 155 | // } 156 | } 157 | // if (result.actions.length > 0) { 158 | // pos += result.actions.length - 1; 159 | // } else { 160 | break; 161 | // } 162 | } 163 | console.log(`----------------游戏数据统计:${count}---------------------`); 164 | } 165 | } 166 | 167 | let betDice = new BetDice('oxoooowatano', 'DICE', 50, 100); 168 | betDice.action(); 169 | // betDice.statistics(); 170 | -------------------------------------------------------------------------------- /src/tasks.ts: -------------------------------------------------------------------------------- 1 | import xEOSHelper from './assets/xEOSHelper'; 2 | import * as utils from './assets/utils'; 3 | 4 | // const allEOSAccounts: any = utils.loadJson('./allEOSAccounts.json'); 5 | const allEOSAccounts: any = utils.loadJson('./allEOSAccountsLive.json'); 6 | 7 | export function initEOSApi(accountName: string = ''): xEOSHelper { 8 | if (accountName && accountName !== '') { 9 | return new xEOSHelper(allEOSAccounts[accountName]); 10 | } else { 11 | return new xEOSHelper(); 12 | } 13 | } 14 | 15 | export function eachAccount(fn: (accountName: string) => void) { 16 | for (let accountName in allEOSAccounts) { 17 | fn(accountName); 18 | } 19 | } 20 | 21 | export function validAllAccountsKeys() { 22 | eachAccount((account: string) => { 23 | const eosapi = initEOSApi(account); 24 | let keys = allEOSAccounts[account]; 25 | if (keys[0] !== '' && keys[1] !== '') { 26 | if (!eosapi.validPublicKey(keys[0])) console.error(account + '@active PublicKey is error!'); 27 | if (!eosapi.validPrivateKey(keys[1])) console.error(account + '@active PrivateKey is error!'); 28 | if (!eosapi.privateToPublic(keys[1]) === keys[0]) console.error(account + '@active PrivateKey is not match PublicKey!'); 29 | } 30 | if (keys[2] !== '' && keys[3] !== '') { 31 | if (!eosapi.validPublicKey(keys[2])) console.error(account + '@owner PublicKey is error!'); 32 | if (!eosapi.validPrivateKey(keys[3])) console.error(account + '@owner PrivateKey is error!'); 33 | if (!eosapi.privateToPublic(keys[3]) === keys[2]) console.error(account + '@owner PrivateKey is not match PublicKey!'); 34 | } 35 | }); 36 | } 37 | 38 | export function getAccount(accountName: string) { 39 | const eosapi = new xEOSHelper(); 40 | return eosapi 41 | .getAccount(accountName) 42 | .then(utils.dumpResult) 43 | .catch(utils.dumpError); 44 | } 45 | 46 | export function getAccountBalance(accountName: string) { 47 | const eosapi = new xEOSHelper(); 48 | eosapi 49 | .getAccountBalance(accountName) 50 | .then((res: any) => { 51 | console.log(accountName, eosapi.parseBalances(res)); 52 | }) 53 | .catch(utils.dumpError); 54 | } 55 | 56 | export function createAccount(creator: string, newaccount: string) { 57 | const eosapi = new xEOSHelper(allEOSAccounts[creator]); 58 | let keys: string[] = []; 59 | //owner keys 60 | eosapi.randomPrivateKey().then((privKey: string) => { 61 | let pubKey = eosapi.privateToPublic(privKey); 62 | if (eosapi.validPrivateKey(privKey) && eosapi.validPublicKey(pubKey)) { 63 | keys.push(pubKey, privKey); 64 | } 65 | //active keys 66 | eosapi.randomPrivateKey().then((privKey: string) => { 67 | let pubKey = eosapi.privateToPublic(privKey); 68 | if (eosapi.validPrivateKey(privKey) && eosapi.validPublicKey(pubKey)) { 69 | keys.push(pubKey, privKey); 70 | } 71 | 72 | console.log(`"${newaccount}": ["${keys[0]}","${keys[1]}","${keys[2]}","${keys[3]}"],`); 73 | eosapi 74 | .createAccount(creator, newaccount, keys[0], keys[2]) 75 | .then((res: any) => { 76 | if (res.transaction_id && res.processed) { 77 | console.log(res.transaction_id); 78 | } else { 79 | console.error(res); 80 | } 81 | }) 82 | .catch(utils.dumpError); 83 | }); 84 | }); 85 | } 86 | 87 | export function transfer(code = 'eosio.token', fromAccount: string, toAccount: string, amount: any, memo: string): Promise { 88 | const eosapi = initEOSApi(fromAccount); 89 | return eosapi.transfer(code, fromAccount, toAccount, amount, memo); 90 | } 91 | 92 | export function betDiceDraw(account: string) { 93 | const eosapi = initEOSApi(account); 94 | eosapi 95 | .getInfo() 96 | .then((result: any) => { 97 | let e: number = result.last_irreversible_block_num; 98 | let o = 1; 99 | for (let a = 0; a < 5651; a++) { 100 | o *= e; 101 | o %= 8633; 102 | } 103 | console.log('e=' + e + ', o=' + o); 104 | eosapi 105 | .transaction('betdicelucky', [ 106 | eosapi.actionContract( 107 | 'betdicelucky', 108 | 'draw', 109 | { 110 | from: account, 111 | b: e, 112 | c: o, 113 | }, 114 | account 115 | ), 116 | ]) 117 | .then(utils.dumpResult) 118 | .catch(utils.dumpError); 119 | }) 120 | .catch(utils.dumpError); 121 | } 122 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ 5 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ 6 | // "lib": [], /* Specify library files to be included in the compilation. */ 7 | "allowJs": true, /* Allow javascript files to be compiled. */ 8 | "checkJs": true, /* Report errors in .js files. */ 9 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 10 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 11 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 12 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 13 | // "outFile": "./", /* Concatenate and emit output to single file. */ 14 | "outDir": "./dist", /* Redirect output structure to the directory. */ 15 | "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 16 | // "composite": true, /* Enable project compilation */ 17 | // "removeComments": true, /* Do not emit comments to output. */ 18 | // "noEmit": true, /* Do not emit outputs. */ 19 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 20 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 21 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 22 | 23 | /* Strict Type-Checking Options */ 24 | "strict": true, /* Enable all strict type-checking options. */ 25 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 26 | // "strictNullChecks": true, /* Enable strict null checks. */ 27 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 28 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 29 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 30 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 31 | 32 | /* Additional Checks */ 33 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 34 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 35 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 36 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 37 | 38 | /* Module Resolution Options */ 39 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 40 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 41 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 42 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 43 | // "typeRoots": [], /* List of folders to include type definitions from. */ 44 | "types": ["node"], /* Type declaration files to be included in compilation. */ 45 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 46 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 47 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 48 | 49 | /* Source Map Options */ 50 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 51 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 52 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 53 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 54 | 55 | /* Experimental Options */ 56 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 57 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 58 | } 59 | } 60 | --------------------------------------------------------------------------------