├── EOSWallet:03-EOS钱包项目整体架构设计 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── index.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── contract.html │ ├── transaction.html │ └── wallet.html ├── EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── wallet.js │ └── web.js ├── index.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── block │ └── nav.html │ └── wallet.html ├── EOSWallet:07-账号模块 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── wallet.js │ └── web.js ├── index.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ └── wallet.html ├── EOSWallet:08-交易模块 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── transaction.js │ ├── wallet.js │ └── web.js ├── index.js ├── models │ └── wallet.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ ├── transaction.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── transaction.html │ └── wallet.html ├── EOSWallet:09-基于测试网络进行开发 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── transaction.js │ ├── wallet.js │ └── web.js ├── index.js ├── models │ └── wallet.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ ├── transaction.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── transaction.html │ └── wallet.html ├── EOSWallet:10-详解与获取ARM、NET、CPU资源数据 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── transaction.js │ ├── wallet.js │ └── web.js ├── index.js ├── models │ └── wallet.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ ├── netResource.js │ │ ├── transaction.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── netResource.html │ ├── transaction.html │ └── wallet.html ├── EOSWallet:11-买入卖出RAM ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── netResource.js │ ├── transaction.js │ ├── wallet.js │ └── web.js ├── index.js ├── models │ └── wallet.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ ├── netResource.js │ │ ├── transaction.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── netResource.html │ ├── transaction.html │ └── wallet.html ├── EOSWallet:12-抵押和赎回NET与CPU带宽 ├── .vscode │ └── launch.json ├── config │ └── config.js ├── controllers │ ├── account.js │ ├── netResource.js │ ├── transaction.js │ ├── wallet.js │ └── web.js ├── index.js ├── models │ └── wallet.js ├── package-lock.json ├── package.json ├── router │ └── router.js ├── static │ ├── css │ │ └── eoswallet.css │ └── js │ │ ├── account.js │ │ ├── accountInfo.js │ │ ├── accountNew.js │ │ ├── lib │ │ ├── jquery-3.3.1.min.js │ │ └── jquery.url.js │ │ ├── netResource.js │ │ ├── transaction.js │ │ └── wallet.js ├── utils │ ├── httpRequest.js │ └── myUtils.js └── views │ ├── account.html │ ├── accountInfo.html │ ├── accountNew.html │ ├── block │ └── nav.html │ ├── netResource.html │ ├── transaction.html │ └── wallet.html └── README.md /EOSWallet:03-EOS钱包项目整体架构设计/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | eosconfig:{ 7 | httpEndpoint:"http://127.0.0.1:8888", 8 | chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 9 | 10 | // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | binaryen: binaryen, 12 | expireInSeconds: 60, 13 | broadcast: true, 14 | verbose: false, // API activity 15 | sign: true 16 | }, 17 | walletAddress:"http://127.0.0.1:8889", 18 | 19 | walletCreate:"/v1/wallet/create", 20 | walletOpen:"/v1/wallet/open", 21 | walletList:"/v1/wallet/list_wallets", 22 | walletUnlock:"/v1/wallet/unlock", 23 | walletLock: "/v1/wallet/lock", 24 | walletImportPrivatekey:"/v1/wallet/import_key", 25 | walletGetKeys:"/v1/wallet/list_keys", 26 | walletCreateKey:"/v1/wallet/create_key", 27 | 28 | accountListForKey:"/v1/history/get_key_accounts", 29 | accountBalance: "/v1/chain/get_currency_balance", 30 | accountInfo:"/v1/chain/get_account", 31 | } -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | router.get("/", async (ctx) => { 4 | await ctx.render("wallet.html") 5 | }) 6 | 7 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/static/js/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | $(document).ready(function () { 3 | alert("welcome!") 4 | }) -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | let exec = require("child_process").exec 5 | 6 | module.exports = { 7 | 8 | getEOSJS: (keyProvider) => { 9 | config.eosconfig.keyProvider = keyProvider 10 | return Eos(config.eosconfig) 11 | }, 12 | 13 | success: (data) => { 14 | responseData = { 15 | code: 0, 16 | status: "success", 17 | data: data 18 | } 19 | return responseData 20 | }, 21 | 22 | fail: (msg) => { 23 | responseData = { 24 | code: 1, 25 | status: "fail", 26 | data: msg 27 | } 28 | return responseData 29 | }, 30 | 31 | doCallback: async (fn, args) => { 32 | return await fn.apply(this, args); 33 | }, 34 | } -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 |
代币金额
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
权限阈值公钥私钥权重
33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/contract.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 合约 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 | 16 |

17 |
18 |

第一步:编译合约

19 | 请选择需要部署的智能合约文件
20 | 21 |

22 | 23 |
24 | 25 |
26 |
27 |

第二步:部署合约

28 | 30 |

31 | 32 | 33 | 34 | 35 |
36 | 37 |
38 |

第三步:调用合约的API

39 | 41 | 42 |

43 | 44 | 45 | 46 |

47 | 48 | 49 | 50 |

51 | 52 | 53 | 54 |

55 | 56 | 57 | 58 | 59 |
60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /EOSWallet:03-EOS钱包项目整体架构设计/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 | -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | eosconfig:{ 7 | httpEndpoint:"http://127.0.0.1:8888", 8 | chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 9 | 10 | // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | binaryen: binaryen, 12 | expireInSeconds: 60, 13 | broadcast: true, 14 | verbose: false, // API activity 15 | sign: true 16 | }, 17 | walletAddress:"http://127.0.0.1:8889", 18 | 19 | walletCreate:"/v1/wallet/create", 20 | walletOpen:"/v1/wallet/open", 21 | walletList:"/v1/wallet/list_wallets", 22 | walletUnlock:"/v1/wallet/unlock", 23 | walletLock: "/v1/wallet/lock", 24 | walletImportPrivatekey:"/v1/wallet/import_key", 25 | walletGetKeys:"/v1/wallet/list_keys", 26 | walletCreateKey:"/v1/wallet/create_key", 27 | 28 | accountListForKey:"/v1/history/get_key_accounts", 29 | accountBalance: "/v1/chain/get_currency_balance", 30 | accountInfo:"/v1/chain/get_account", 31 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | 6 | //钱包 7 | router.post("/wallet/create", walletController.walletCreate) 8 | router.post("/wallet/open", walletController.walletOpen) 9 | router.get("/wallet/list", walletController.walletList) 10 | router.post("/wallet/unlock", walletController.walletUnlock) 11 | router.post("/wallet/lock", walletController.walletLock) 12 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 13 | router.post("/wallet/keys", walletController.walletGetKeys) 14 | router.post("/wallet/createkey", walletController.walletCreateKey) 15 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 16 | 17 | //页面 18 | router.get("/wallet.html", webController.getWalletHtml) 19 | 20 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:04-钱包模块:新建钱包、解锁钱包、导入账号/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | eosconfig:{ 7 | httpEndpoint:"http://127.0.0.1:8888", 8 | chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 9 | 10 | // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | binaryen: binaryen, 12 | expireInSeconds: 60, 13 | broadcast: true, 14 | verbose: false, // API activity 15 | sign: true 16 | }, 17 | walletAddress:"http://127.0.0.1:8889", 18 | 19 | walletCreate:"/v1/wallet/create", 20 | walletOpen:"/v1/wallet/open", 21 | walletList:"/v1/wallet/list_wallets", 22 | walletUnlock:"/v1/wallet/unlock", 23 | walletLock: "/v1/wallet/lock", 24 | walletImportPrivatekey:"/v1/wallet/import_key", 25 | walletGetKeys:"/v1/wallet/list_keys", 26 | walletCreateKey:"/v1/wallet/create_key", 27 | 28 | accountListForKey:"/v1/history/get_key_accounts", 29 | accountBalance: "/v1/chain/get_currency_balance", 30 | accountInfo:"/v1/chain/get_account", 31 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | 7 | //钱包 8 | router.post("/wallet/create", walletController.walletCreate) 9 | router.post("/wallet/open", walletController.walletOpen) 10 | router.get("/wallet/list", walletController.walletList) 11 | router.post("/wallet/unlock", walletController.walletUnlock) 12 | router.post("/wallet/lock", walletController.walletLock) 13 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 14 | router.post("/wallet/keys", walletController.walletGetKeys) 15 | router.post("/wallet/createkey", walletController.walletCreateKey) 16 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 17 | 18 | //账号 19 | router.post("/account/listforwallet", accountController.accountListForWallet) 20 | router.post("/account/create", accountController.accountCreate) 21 | router.post("/account/balance", accountController.accountBalance) 22 | router.post("/account/info", accountController.accountInfo) 23 | 24 | //页面 25 | router.get("/wallet.html", webController.getWalletHtml) 26 | router.get("/account.html", webController.getAccountHtml) 27 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 28 | router.get("/accountnew.html", webController.getAccountCreateHtml) 29 | 30 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 |
代币金额
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
权限阈值公钥私钥权重
33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:07-账号模块/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | eosconfig:{ 7 | httpEndpoint:"http://127.0.0.1:8888", 8 | chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 9 | 10 | // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | binaryen: binaryen, 12 | expireInSeconds: 60, 13 | broadcast: true, 14 | verbose: false, // API activity 15 | sign: true 16 | }, 17 | walletAddress:"http://127.0.0.1:8889", 18 | 19 | walletCreate:"/v1/wallet/create", 20 | walletOpen:"/v1/wallet/open", 21 | walletList:"/v1/wallet/list_wallets", 22 | walletUnlock:"/v1/wallet/unlock", 23 | walletLock: "/v1/wallet/lock", 24 | walletImportPrivatekey:"/v1/wallet/import_key", 25 | walletGetKeys:"/v1/wallet/list_keys", 26 | walletCreateKey:"/v1/wallet/create_key", 27 | 28 | accountListForKey:"/v1/history/get_key_accounts", 29 | accountBalance: "/v1/chain/get_currency_balance", 30 | accountInfo:"/v1/chain/get_account", 31 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/controllers/transaction.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let {success, fail} = require("../utils/myUtils") 4 | let myUtils = require("../utils/myUtils") 5 | let walletModel = require("../models/wallet") 6 | 7 | module.exports = { 8 | transactionSend: async (ctx) => { 9 | console.log(ctx.request.body) 10 | let { from, to, amount, symbol, memo, wallet, password } = ctx.request.body 11 | 12 | //1.获取钱包里面所有的私钥 13 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 14 | 15 | //2.配置EOSJS 16 | eos = myUtils.getEOSJS(privatekeyList) 17 | 18 | //3.发起转账交易 19 | options = { 20 | authorization: `${from}@active`, 21 | broadcast: true, 22 | sign: true 23 | } 24 | let data = await eos.transaction(eos => { 25 | let stantardAmount = parseFloat(amount).toFixed(4) 26 | eos.transfer(from, to, `${stantardAmount} ${symbol}`, memo, options) 27 | }) 28 | console.log("data:", data) 29 | 30 | //4.返回给前端执行的状态 31 | let resData 32 | if (data) { 33 | resData = success("转账成功") 34 | } else { 35 | resData = fail("转账失败") 36 | } 37 | ctx.body = resData 38 | }, 39 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | 19 | getTransactionHtml:async(ctx) => { 20 | await ctx.render("transaction.html") 21 | }, 22 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/models/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let httpRequest = require("../utils/httpRequest") 4 | let config = require("../config/config") 5 | 6 | module.exports = { 7 | getWalletPrivatekeyList: async (wallet, password) => { 8 | let privatekeyList = [] 9 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 10 | if (res.code == 0 && res.data.length > 0) { 11 | for (const index in res.data) { 12 | let keys = res.data[index] 13 | privatekeyList.push(keys[1]) 14 | } 15 | } 16 | return privatekeyList 17 | } 18 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | let transactionController = require("../controllers/transaction") 7 | 8 | //钱包 9 | router.post("/wallet/create", walletController.walletCreate) 10 | router.post("/wallet/open", walletController.walletOpen) 11 | router.get("/wallet/list", walletController.walletList) 12 | router.post("/wallet/unlock", walletController.walletUnlock) 13 | router.post("/wallet/lock", walletController.walletLock) 14 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 15 | router.post("/wallet/keys", walletController.walletGetKeys) 16 | router.post("/wallet/createkey", walletController.walletCreateKey) 17 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 18 | 19 | //账号 20 | router.post("/account/listforwallet", accountController.accountListForWallet) 21 | router.post("/account/create", accountController.accountCreate) 22 | router.post("/account/balance", accountController.accountBalance) 23 | router.post("/account/info", accountController.accountInfo) 24 | 25 | //转账交易 26 | router.post("/transaction/send", transactionController.transactionSend) 27 | 28 | //页面 29 | router.get("/wallet.html", webController.getWalletHtml) 30 | router.get("/account.html", webController.getAccountHtml) 31 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 32 | router.get("/accountnew.html", webController.getAccountCreateHtml) 33 | router.get("/transaction.html", webController.getTransactionHtml) 34 | 35 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 |
代币金额
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
权限阈值公钥私钥权重
33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /EOSWallet:08-交易模块/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | //本地网络 7 | // eosconfig:{ 8 | // httpEndpoint:"http://127.0.0.1:8888", 9 | // chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 10 | // // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | // binaryen: binaryen, 12 | // expireInSeconds: 60, 13 | // broadcast: true, 14 | // verbose: false, // API activity 15 | // sign: true 16 | // }, 17 | 18 | //测试网络 19 | eosconfig:{ 20 | httpEndpoint:"http://jungle.cryptolions.io:18888", 21 | chainId: "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca", // 32 byte (64 char) hex string 22 | // keyProvider: privatekeyList, // WIF string or array of keys.. 23 | binaryen: binaryen, 24 | expireInSeconds: 60, 25 | broadcast: true, 26 | verbose: false, // API activity 27 | sign: true 28 | }, 29 | walletAddress:"http://127.0.0.1:8889", 30 | 31 | walletCreate:"/v1/wallet/create", 32 | walletOpen:"/v1/wallet/open", 33 | walletList:"/v1/wallet/list_wallets", 34 | walletUnlock:"/v1/wallet/unlock", 35 | walletLock: "/v1/wallet/lock", 36 | walletImportPrivatekey:"/v1/wallet/import_key", 37 | walletGetKeys:"/v1/wallet/list_keys", 38 | walletCreateKey:"/v1/wallet/create_key", 39 | 40 | accountListForKey:"/v1/history/get_key_accounts", 41 | accountBalance: "/v1/chain/get_currency_balance", 42 | accountInfo:"/v1/chain/get_account", 43 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/controllers/transaction.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let {success, fail} = require("../utils/myUtils") 4 | let myUtils = require("../utils/myUtils") 5 | let walletModel = require("../models/wallet") 6 | 7 | module.exports = { 8 | transactionSend: async (ctx) => { 9 | console.log(ctx.request.body) 10 | let { from, to, amount, symbol, memo, wallet, password } = ctx.request.body 11 | 12 | //1.获取钱包里面所有的私钥 13 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 14 | 15 | //2.配置EOSJS 16 | eos = myUtils.getEOSJS(privatekeyList) 17 | 18 | //3.发起转账交易 19 | options = { 20 | authorization: `${from}@active`, 21 | broadcast: true, 22 | sign: true 23 | } 24 | let data = await eos.transaction(eos => { 25 | let stantardAmount = parseFloat(amount).toFixed(4) 26 | eos.transfer(from, to, `${stantardAmount} ${symbol}`, memo, options) 27 | }) 28 | console.log("data:", data) 29 | 30 | //4.返回给前端执行的状态 31 | let resData 32 | if (data) { 33 | resData = success("转账成功") 34 | } else { 35 | resData = fail("转账失败") 36 | } 37 | ctx.body = resData 38 | }, 39 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | 19 | getTransactionHtml:async(ctx) => { 20 | await ctx.render("transaction.html") 21 | }, 22 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/models/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let httpRequest = require("../utils/httpRequest") 4 | let config = require("../config/config") 5 | 6 | module.exports = { 7 | getWalletPrivatekeyList: async (wallet, password) => { 8 | let privatekeyList = [] 9 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 10 | if (res.code == 0 && res.data.length > 0) { 11 | for (const index in res.data) { 12 | let keys = res.data[index] 13 | privatekeyList.push(keys[1]) 14 | } 15 | } 16 | return privatekeyList 17 | } 18 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | let transactionController = require("../controllers/transaction") 7 | 8 | //钱包 9 | router.post("/wallet/create", walletController.walletCreate) 10 | router.post("/wallet/open", walletController.walletOpen) 11 | router.get("/wallet/list", walletController.walletList) 12 | router.post("/wallet/unlock", walletController.walletUnlock) 13 | router.post("/wallet/lock", walletController.walletLock) 14 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 15 | router.post("/wallet/keys", walletController.walletGetKeys) 16 | router.post("/wallet/createkey", walletController.walletCreateKey) 17 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 18 | 19 | //账号 20 | router.post("/account/listforwallet", accountController.accountListForWallet) 21 | router.post("/account/create", accountController.accountCreate) 22 | router.post("/account/balance", accountController.accountBalance) 23 | router.post("/account/info", accountController.accountInfo) 24 | 25 | //转账交易 26 | router.post("/transaction/send", transactionController.transactionSend) 27 | 28 | //页面 29 | router.get("/wallet.html", webController.getWalletHtml) 30 | router.get("/account.html", webController.getAccountHtml) 31 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 32 | router.get("/accountnew.html", webController.getAccountCreateHtml) 33 | router.get("/transaction.html", webController.getTransactionHtml) 34 | 35 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 18 | 19 | 20 | 21 | 22 |
代币金额
23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 |
权限阈值公钥私钥权重
33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /EOSWallet:09-基于测试网络进行开发/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 |
29 | 30 | 31 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | } 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | //本地网络 7 | // eosconfig:{ 8 | // httpEndpoint:"http://127.0.0.1:8888", 9 | // chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 10 | // // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | // binaryen: binaryen, 12 | // expireInSeconds: 60, 13 | // broadcast: true, 14 | // verbose: false, // API activity 15 | // sign: true 16 | // }, 17 | 18 | //测试网络 19 | eosconfig:{ 20 | httpEndpoint:"http://jungle.cryptolions.io:18888", 21 | chainId: "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca", // 32 byte (64 char) hex string 22 | // keyProvider: privatekeyList, // WIF string or array of keys.. 23 | binaryen: binaryen, 24 | expireInSeconds: 60, 25 | broadcast: true, 26 | verbose: false, // API activity 27 | sign: true 28 | }, 29 | walletAddress:"http://127.0.0.1:8889", 30 | 31 | walletCreate:"/v1/wallet/create", 32 | walletOpen:"/v1/wallet/open", 33 | walletList:"/v1/wallet/list_wallets", 34 | walletUnlock:"/v1/wallet/unlock", 35 | walletLock: "/v1/wallet/lock", 36 | walletImportPrivatekey:"/v1/wallet/import_key", 37 | walletGetKeys:"/v1/wallet/list_keys", 38 | walletCreateKey:"/v1/wallet/create_key", 39 | 40 | accountListForKey:"/v1/history/get_key_accounts", 41 | accountBalance: "/v1/chain/get_currency_balance", 42 | accountInfo:"/v1/chain/get_account", 43 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/controllers/transaction.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let {success, fail} = require("../utils/myUtils") 4 | let myUtils = require("../utils/myUtils") 5 | let walletModel = require("../models/wallet") 6 | 7 | module.exports = { 8 | transactionSend: async (ctx) => { 9 | console.log(ctx.request.body) 10 | let { from, to, amount, symbol, memo, wallet, password } = ctx.request.body 11 | 12 | //1.获取钱包里面所有的私钥 13 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 14 | 15 | //2.配置EOSJS 16 | eos = myUtils.getEOSJS(privatekeyList) 17 | 18 | //3.发起转账交易 19 | options = { 20 | authorization: `${from}@active`, 21 | broadcast: true, 22 | sign: true 23 | } 24 | let data = await eos.transaction(eos => { 25 | let stantardAmount = parseFloat(amount).toFixed(4) 26 | eos.transfer(from, to, `${stantardAmount} ${symbol}`, memo, options) 27 | }) 28 | console.log("data:", data) 29 | 30 | //4.返回给前端执行的状态 31 | let resData 32 | if (data) { 33 | resData = success("转账成功") 34 | } else { 35 | resData = fail("转账失败") 36 | } 37 | ctx.body = resData 38 | }, 39 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | 19 | getTransactionHtml:async(ctx) => { 20 | await ctx.render("transaction.html") 21 | }, 22 | 23 | getNetRosourceHtml:async(ctx) => { 24 | await ctx.render("netResource.html") 25 | }, 26 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/models/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let httpRequest = require("../utils/httpRequest") 4 | let config = require("../config/config") 5 | 6 | module.exports = { 7 | getWalletPrivatekeyList: async (wallet, password) => { 8 | let privatekeyList = [] 9 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 10 | if (res.code == 0 && res.data.length > 0) { 11 | for (const index in res.data) { 12 | let keys = res.data[index] 13 | privatekeyList.push(keys[1]) 14 | } 15 | } 16 | return privatekeyList 17 | } 18 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | let transactionController = require("../controllers/transaction") 7 | 8 | //钱包 9 | router.post("/wallet/create", walletController.walletCreate) 10 | router.post("/wallet/open", walletController.walletOpen) 11 | router.get("/wallet/list", walletController.walletList) 12 | router.post("/wallet/unlock", walletController.walletUnlock) 13 | router.post("/wallet/lock", walletController.walletLock) 14 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 15 | router.post("/wallet/keys", walletController.walletGetKeys) 16 | router.post("/wallet/createkey", walletController.walletCreateKey) 17 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 18 | 19 | //账号 20 | router.post("/account/listforwallet", accountController.accountListForWallet) 21 | router.post("/account/create", accountController.accountCreate) 22 | router.post("/account/balance", accountController.accountBalance) 23 | router.post("/account/info", accountController.accountInfo) 24 | 25 | //转账交易 26 | router.post("/transaction/send", transactionController.transactionSend) 27 | 28 | //页面 29 | router.get("/wallet.html", webController.getWalletHtml) 30 | router.get("/account.html", webController.getAccountHtml) 31 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 32 | router.get("/accountnew.html", webController.getAccountCreateHtml) 33 | router.get("/transaction.html", webController.getTransactionHtml) 34 | router.get("/netresource.html", webController.getNetRosourceHtml) 35 | 36 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/static/js/netResource.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(document).ready(function () { 4 | let currentAccount = localStorage.getItem("currentAccount") 5 | $("#current-account").text(currentAccount) 6 | 7 | //网络资源详情 8 | $.post("/account/info", { "account": currentAccount }, function (res, status) { 9 | console.log(status + JSON.stringify(res)) 10 | if (res.code == 0) { 11 | let data = res.data 12 | 13 | let availableBalance = parseFloat(data.core_liquid_balance.slice(0,-4)) 14 | let redeemBalance = 0 15 | let netBalance = data.net_weight / 10000 16 | let cpuBalance = data.cpu_weight / 10000 17 | //总资产 18 | let totalBalance = availableBalance + redeemBalance + netBalance + cpuBalance 19 | $("#my-total-balance").text(totalBalance + " EOS") 20 | 21 | //余额 22 | let myBalanceTable = $("#my-balance-table") 23 | let rowTr = ` 24 | ${availableBalance} EOS 25 | ${redeemBalance} EOS 26 | ${netBalance} EOS 27 | ${cpuBalance} EOS 28 | ` 29 | myBalanceTable.append(rowTr) 30 | 31 | //ARM 32 | let armAvailable = (data.ram_quota - data.ram_usage) / 1024 33 | let armTotal = data.ram_quota / 1024 34 | let myArmTable = $("#my-arm-table") 35 | rowTr = ` 36 | ${armAvailable.toFixed(2)} KB 37 | ${armTotal.toFixed(2)} KB 38 | ` 39 | myArmTable.append(rowTr) 40 | 41 | //NET 42 | let netAvailable = (data.net_limit.max - data.net_limit.used)/1024 43 | let netTotla = data.net_limit.max/1024 44 | let myNetTable = $("#my-net-table") 45 | rowTr = ` 46 | ${netBalance} EOS 47 | ${netAvailable.toFixed(2)} KB 48 | ${netTotla.toFixed(2)} KB 49 | ` 50 | myNetTable.append(rowTr) 51 | 52 | //CPU 53 | let cpuAvailable = (data.cpu_limit.max - data.cpu_limit.used) / 1000 54 | let cpuTotla = data.cpu_limit.max / 1000 55 | let myCpuTable = $("#my-cpu-table") 56 | rowTr = ` 57 | ${cpuBalance} EOS 58 | ${cpuAvailable} ms 59 | ${cpuTotla} ms 60 | ` 61 | myCpuTable.append(rowTr) 62 | } 63 | }) 64 | }) -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 30 |
Copyright © 2016-2018 北京从零到壹科技有限公司
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 资源管理 18 | 19 | 20 | 21 | 22 | 23 | 24 |
代币金额
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
权限阈值公钥私钥权重
35 | 36 |
Copyright © 2016-2018 北京从零到壹科技有限公司
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
Copyright © 2016-2018 北京从零到壹科技有限公司
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/netResource.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 资源管理 5 | 6 | 7 | 8 | 9 | 29 | 30 | 31 | 32 | <%include block/nav.html%> 33 | 34 |
35 |

资源管理

36 | 37 |  总资产: 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
可用余额赎回金额NET抵押CPU抵押
47 | 48 |
49 |
50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
ARM内存
可用总量
58 |
59 |
60 |
买入 卖出
61 |
62 | 63 |
64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
NET宽带
抵押可用总量
73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
CPU宽带
抵押可用总量
83 |
84 |
85 |
抵押 赎回
86 |
87 |
88 | 89 |
Copyright © 2016-2018 北京从零到壹科技有限公司
90 |
91 | 92 | 93 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 | 53 |
Copyright © 2016-2018 北京从零到壹科技有限公司
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /EOSWallet:10-详解与获取ARM、NET、CPU资源数据/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 | 29 |
Copyright © 2016-2018 北京从零到壹科技有限公司
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | }, 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | //本地网络 7 | // eosconfig:{ 8 | // httpEndpoint:"http://127.0.0.1:8888", 9 | // chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 10 | // // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | // binaryen: binaryen, 12 | // expireInSeconds: 60, 13 | // broadcast: true, 14 | // verbose: false, // API activity 15 | // sign: true 16 | // }, 17 | 18 | //测试网络 19 | eosconfig:{ 20 | httpEndpoint:"http://jungle.cryptolions.io:18888", 21 | chainId: "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca", // 32 byte (64 char) hex string 22 | // keyProvider: privatekeyList, // WIF string or array of keys.. 23 | binaryen: binaryen, 24 | expireInSeconds: 60, 25 | broadcast: true, 26 | verbose: false, // API activity 27 | sign: true 28 | }, 29 | walletAddress:"http://127.0.0.1:8889", 30 | 31 | walletCreate:"/v1/wallet/create", 32 | walletOpen:"/v1/wallet/open", 33 | walletList:"/v1/wallet/list_wallets", 34 | walletUnlock:"/v1/wallet/unlock", 35 | walletLock: "/v1/wallet/lock", 36 | walletImportPrivatekey:"/v1/wallet/import_key", 37 | walletGetKeys:"/v1/wallet/list_keys", 38 | walletCreateKey:"/v1/wallet/create_key", 39 | 40 | accountListForKey:"/v1/history/get_key_accounts", 41 | accountBalance: "/v1/chain/get_currency_balance", 42 | accountInfo:"/v1/chain/get_account", 43 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/controllers/netResource.js: -------------------------------------------------------------------------------- 1 | c 2 | 3 | 4 | let { success, fail } = require("../utils/myUtils") 5 | let myUtils = require("../utils/myUtils") 6 | let walletModel = require("../models/wallet") 7 | 8 | async function getRamInfo() { 9 | ramData = await eos.getTableRows(true, "eosio", "eosio", "rammarket") 10 | 11 | //RAM消耗的EOS数量 12 | let eosAmount = ramData.rows[0].quote.balance.split(" ")[0]; 13 | //RAM使用量 14 | let ramAmount = ramData.rows[0].base.balance.split(" ")[0] / 1024; 15 | //RAM价格 16 | let ramPriceWithEOS = eosAmount / ramAmount 17 | console.log(eosAmount, ramAmount, ramPriceWithEOS); 18 | return { 19 | ramUsed: ramAmount / (1024 * 1024), 20 | ramPrice: ramPriceWithEOS, 21 | } 22 | } 23 | 24 | module.exports = { 25 | netResourceGetRAMInfo: async (ctx) => { 26 | console.log(ctx.request.body) 27 | let { wallet, password } = ctx.request.body 28 | //获取钱包里面所有的私钥配置EOSJS 29 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 30 | eos = myUtils.getEOSJS(privatekeyList) 31 | 32 | let ramData = await eos.getTableRows(true, "eosio", "eosio", "global") 33 | //ram总量,bytes转为G 34 | let ramTotal = ramData.rows[0].max_ram_size / (1024 * 1024 * 1024) 35 | console.log(ramTotal); 36 | 37 | let ramInfo = await getRamInfo() 38 | ctx.body = success({ 39 | ramPrice: ramInfo.ramPrice, 40 | ramTotal: ramTotal, 41 | ramAvailable: ramTotal - ramInfo.ramUsed, 42 | }) 43 | }, 44 | 45 | netResourceTransactionRAM: async (ctx) => { 46 | console.log(ctx.request.body) 47 | let { amount, transaction_type, account, wallet, password } = ctx.request.body 48 | //获取钱包里面所有的私钥配置EOSJS 49 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 50 | eos = myUtils.getEOSJS(privatekeyList) 51 | 52 | let result 53 | if (transaction_type == '1') { 54 | //买RAM 55 | console.log("买RAM") 56 | let ramInfo = await getRamInfo() 57 | let ramAmount = parseInt((amount / ramInfo.ramPrice) * 1024) 58 | console.log("ramAmount:", ramAmount) 59 | result = await eos.transaction(tr => { 60 | tr.buyrambytes({ 61 | payer: account, 62 | receiver: account, 63 | bytes: ramAmount 64 | }) 65 | }) 66 | } else { 67 | //卖RAM 68 | console.log("卖RAM") 69 | let ramAmount = parseInt(amount * 1024) 70 | result = await eos.transaction(tr => { 71 | tr.sellram({ 72 | account: account, 73 | bytes: ramAmount 74 | }) 75 | }) 76 | } 77 | 78 | console.log("data:", result) 79 | if (result.broadcast) { 80 | ctx.body = success("ok") 81 | } else { 82 | ctx.body = fail("error") 83 | } 84 | } 85 | 86 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/controllers/transaction.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let {success, fail} = require("../utils/myUtils") 4 | let myUtils = require("../utils/myUtils") 5 | let walletModel = require("../models/wallet") 6 | 7 | module.exports = { 8 | transactionSend: async (ctx) => { 9 | console.log(ctx.request.body) 10 | let { from, to, amount, symbol, memo, wallet, password } = ctx.request.body 11 | 12 | //1.获取钱包里面所有的私钥 13 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 14 | 15 | //2.配置EOSJS 16 | eos = myUtils.getEOSJS(privatekeyList) 17 | 18 | //3.发起转账交易 19 | options = { 20 | authorization: `${from}@active`, 21 | broadcast: true, 22 | sign: true 23 | } 24 | let data = await eos.transaction(eos => { 25 | let stantardAmount = parseFloat(amount).toFixed(4) 26 | eos.transfer(from, to, `${stantardAmount} ${symbol}`, memo, options) 27 | }) 28 | console.log("data:", data) 29 | 30 | //4.返回给前端执行的状态 31 | let resData 32 | if (data) { 33 | resData = success("转账成功") 34 | } else { 35 | resData = fail("转账失败") 36 | } 37 | ctx.body = resData 38 | }, 39 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | 19 | getTransactionHtml:async(ctx) => { 20 | await ctx.render("transaction.html") 21 | }, 22 | 23 | getNetRosourceHtml:async(ctx) => { 24 | await ctx.render("netResource.html") 25 | }, 26 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/models/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let httpRequest = require("../utils/httpRequest") 4 | let config = require("../config/config") 5 | 6 | module.exports = { 7 | getWalletPrivatekeyList: async (wallet, password) => { 8 | let privatekeyList = [] 9 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 10 | if (res.code == 0 && res.data.length > 0) { 11 | for (const index in res.data) { 12 | let keys = res.data[index] 13 | privatekeyList.push(keys[1]) 14 | } 15 | } 16 | return privatekeyList 17 | } 18 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | let transactionController = require("../controllers/transaction") 7 | let netresourceController = require("../controllers/netResource") 8 | 9 | //钱包 10 | router.post("/wallet/create", walletController.walletCreate) 11 | router.post("/wallet/open", walletController.walletOpen) 12 | router.get("/wallet/list", walletController.walletList) 13 | router.post("/wallet/unlock", walletController.walletUnlock) 14 | router.post("/wallet/lock", walletController.walletLock) 15 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 16 | router.post("/wallet/keys", walletController.walletGetKeys) 17 | router.post("/wallet/createkey", walletController.walletCreateKey) 18 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 19 | 20 | //账号 21 | router.post("/account/listforwallet", accountController.accountListForWallet) 22 | router.post("/account/create", accountController.accountCreate) 23 | router.post("/account/balance", accountController.accountBalance) 24 | router.post("/account/info", accountController.accountInfo) 25 | 26 | //转账交易 27 | router.post("/transaction/send", transactionController.transactionSend) 28 | 29 | //网络资源 30 | router.post("/net_resource/ram/info", netresourceController.netResourceGetRAMInfo) 31 | router.post("/net_resource/ram/transaction", netresourceController.netResourceTransactionRAM) 32 | 33 | //页面 34 | router.get("/wallet.html", webController.getWalletHtml) 35 | router.get("/account.html", webController.getAccountHtml) 36 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 37 | router.get("/accountnew.html", webController.getAccountCreateHtml) 38 | router.get("/transaction.html", webController.getTransactionHtml) 39 | router.get("/netresource.html", webController.getNetRosourceHtml) 40 | 41 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 30 |
Copyright © 2016-2018 北京从零到壹科技有限公司
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 资源管理 18 | 19 | 20 | 21 | 22 | 23 | 24 |
代币金额
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
权限阈值公钥私钥权重
35 | 36 |
Copyright © 2016-2018 北京从零到壹科技有限公司
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
Copyright © 2016-2018 北京从零到壹科技有限公司
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 | 53 |
Copyright © 2016-2018 北京从零到壹科技有限公司
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /EOSWallet:11-买入卖出RAM/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 | 29 |
Copyright © 2016-2018 北京从零到壹科技有限公司
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | 8 | { 9 | "type": "node", 10 | "request": "launch", 11 | "name": "Launch Program", 12 | "program": "${workspaceFolder}/index.js" 13 | }, 14 | ] 15 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/config/config.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let binaryen = require('binaryen') 4 | 5 | module.exports = { 6 | //本地网络 7 | // eosconfig:{ 8 | // httpEndpoint:"http://127.0.0.1:8888", 9 | // chainId: "cf057bbfb72640471fd910bcb67639c22df9f92470936cddc1ade0e2f2e7dc4f", // 32 byte (64 char) hex string 10 | // // keyProvider: privatekeyList, // WIF string or array of keys.. 11 | // binaryen: binaryen, 12 | // expireInSeconds: 60, 13 | // broadcast: true, 14 | // verbose: false, // API activity 15 | // sign: true 16 | // }, 17 | 18 | //测试网络 19 | eosconfig:{ 20 | httpEndpoint:"http://jungle.cryptolions.io:18888", 21 | chainId: "038f4b0fc8ff18a4f0842a8f0564611f6e96e8535901dd45e43ac8691a1c4dca", // 32 byte (64 char) hex string 22 | // keyProvider: privatekeyList, // WIF string or array of keys.. 23 | binaryen: binaryen, 24 | expireInSeconds: 60, 25 | broadcast: true, 26 | verbose: false, // API activity 27 | sign: true 28 | }, 29 | 30 | //正式网络 31 | // eosconfig:{ 32 | // httpEndpoint: 'https://node1.zbeos.com', 33 | // chainId: 'aca376f206b8fc25a6ed44dbdc66547c36c6c33e3a119ffbeaef943642f0e906', 34 | // // keyProvider: privatekeyList, // WIF string or array of keys.. 35 | // binaryen: binaryen, 36 | // expireInSeconds: 60, 37 | // broadcast: true, 38 | // verbose: false, // API activity 39 | // sign: true 40 | // }, 41 | 42 | walletAddress:"http://127.0.0.1:8889", 43 | 44 | walletCreate:"/v1/wallet/create", 45 | walletOpen:"/v1/wallet/open", 46 | walletList:"/v1/wallet/list_wallets", 47 | walletUnlock:"/v1/wallet/unlock", 48 | walletLock: "/v1/wallet/lock", 49 | walletImportPrivatekey:"/v1/wallet/import_key", 50 | walletGetKeys:"/v1/wallet/list_keys", 51 | walletCreateKey:"/v1/wallet/create_key", 52 | 53 | accountListForKey:"/v1/history/get_key_accounts", 54 | accountBalance: "/v1/chain/get_currency_balance", 55 | accountInfo:"/v1/chain/get_account", 56 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/controllers/transaction.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let {success, fail} = require("../utils/myUtils") 4 | let myUtils = require("../utils/myUtils") 5 | let walletModel = require("../models/wallet") 6 | 7 | module.exports = { 8 | transactionSend: async (ctx) => { 9 | console.log(ctx.request.body) 10 | let { from, to, amount, symbol, memo, wallet, password } = ctx.request.body 11 | 12 | //1.获取钱包里面所有的私钥 13 | let privatekeyList = await walletModel.getWalletPrivatekeyList(wallet, password) 14 | 15 | //2.配置EOSJS 16 | eos = myUtils.getEOSJS(privatekeyList) 17 | 18 | //3.发起转账交易 19 | options = { 20 | authorization: `${from}@active`, 21 | broadcast: true, 22 | sign: true 23 | } 24 | let data = await eos.transaction(eos => { 25 | let stantardAmount = parseFloat(amount).toFixed(4) 26 | eos.transfer(from, to, `${stantardAmount} ${symbol}`, memo, options) 27 | }) 28 | console.log("data:", data) 29 | 30 | //4.返回给前端执行的状态 31 | let resData 32 | if (data) { 33 | resData = success("转账成功") 34 | } else { 35 | resData = fail("转账失败") 36 | } 37 | ctx.body = resData 38 | }, 39 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/controllers/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | let httpRequest = require("../utils/httpRequest") 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | walletCreate: async(ctx) =>{ 7 | console.log(JSON.stringify(ctx.request.body)) 8 | let {wallet} = ctx.request.body 9 | 10 | let res = await httpRequest.postRequest(config.walletCreate, wallet) 11 | if (res.code == 0) { 12 | res.data = {"password":res.data, "wallet":wallet} 13 | } 14 | ctx.body = res 15 | }, 16 | 17 | walletOpen: async(ctx) =>{ 18 | console.log(JSON.stringify(ctx.request.body)) 19 | let {wallet} = ctx.request.body 20 | 21 | let res = await httpRequest.postRequest(config.walletOpen, wallet) 22 | ctx.body = res 23 | }, 24 | 25 | walletList: async(ctx) => { 26 | let res = await httpRequest.postRequest(config.walletList, null) 27 | ctx.body = res 28 | }, 29 | 30 | walletUnlock:async(ctx) => { 31 | console.log(JSON.stringify(ctx.request.body)) 32 | let {wallet, password} = ctx.request.body 33 | 34 | let res = await httpRequest.postRequest(config.walletUnlock, [wallet, password]) 35 | ctx.body = res 36 | }, 37 | 38 | walletLock: async(ctx) => { 39 | console.log(JSON.stringify(ctx.request.body)) 40 | let {wallet} = ctx.request.body 41 | 42 | let res = await httpRequest.postRequest(config.walletLock, wallet) 43 | ctx.body = res 44 | }, 45 | 46 | walletImportPrivatekey:async(ctx) => { 47 | console.log(JSON.stringify(ctx.request.body)) 48 | let {wallet, privatekey} = ctx.request.body 49 | 50 | let res = await httpRequest.postRequest(config.walletImportPrivatekey, [wallet, privatekey]) 51 | ctx.body = res 52 | }, 53 | 54 | walletGetKeys:async(ctx) => { 55 | console.log(JSON.stringify(ctx.request.body)) 56 | let {wallet, password} = ctx.request.body 57 | 58 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 59 | ctx.body = res 60 | }, 61 | 62 | walletCreateKey: async(ctx) =>{ 63 | let {wallet, type} = ctx.request.body 64 | let res = await httpRequest.postRequest(config.walletCreateKey, [wallet, type]) 65 | ctx.body = res 66 | }, 67 | 68 | walletPubkeyGetPrivatekey: async(ctx) => { 69 | let {wallet, password, publickey} = ctx.request.body 70 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 71 | 72 | let privatekey = "无权查看" 73 | for (const index in res.data) { 74 | let keys = res.data[index] 75 | if (keys[0] == publickey) { 76 | privatekey = keys[1] 77 | break 78 | } 79 | } 80 | 81 | res.data = privatekey 82 | ctx.body = res 83 | } 84 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/controllers/web.js: -------------------------------------------------------------------------------- 1 | 2 | module.exports = { 3 | getWalletHtml: async(ctx) => { 4 | await ctx.render("wallet.html") 5 | }, 6 | 7 | getAccountHtml:async(ctx) => { 8 | await ctx.render("account.html") 9 | }, 10 | 11 | getAccountInfoHtml:async(ctx) => { 12 | await ctx.render("accountInfo.html") 13 | }, 14 | 15 | getAccountCreateHtml:async(ctx) => { 16 | await ctx.render("accountNew.html") 17 | }, 18 | 19 | getTransactionHtml:async(ctx) => { 20 | await ctx.render("transaction.html") 21 | }, 22 | 23 | getNetRosourceHtml:async(ctx) => { 24 | await ctx.render("netResource.html") 25 | }, 26 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/index.js: -------------------------------------------------------------------------------- 1 | 2 | let koa = require("koa") 3 | //通过koa创建一个应用程序 4 | let app = new koa() 5 | //导入./router/route这个包,赋值给的router就是 ./router/router导出的数据 6 | let router = require("./router/router") 7 | let static = require("koa-static") 8 | let path = require("path") 9 | let views = require("koa-views") 10 | let koaBody = require("koa-body") 11 | 12 | app.use(async (ctx, next) => { 13 | console.log(`${ctx.method} ${ctx.url} ..........`) 14 | await next() 15 | }) 16 | 17 | //针对于文件上传的时候,可以解析多个字段 18 | app.use(koaBody({multipart:true})) 19 | //注册静态文件的库到中间件 20 | app.use(static(path.join(__dirname, "static"))) 21 | //注册模板引擎的库到中间件 22 | app.use(views(path.join(__dirname, "views"), {extension:"ejs", map:{html:"ejs"}})) 23 | app.use(router.routes()) 24 | 25 | console.log("正在监听3000端口") 26 | app.listen(3000) 27 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/models/wallet.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | let httpRequest = require("../utils/httpRequest") 4 | let config = require("../config/config") 5 | 6 | module.exports = { 7 | getWalletPrivatekeyList: async (wallet, password) => { 8 | let privatekeyList = [] 9 | let res = await httpRequest.postRequest(config.walletGetKeys, [wallet, password]) 10 | if (res.code == 0 && res.data.length > 0) { 11 | for (const index in res.data) { 12 | let keys = res.data[index] 13 | privatekeyList.push(keys[1]) 14 | } 15 | } 16 | return privatekeyList 17 | } 18 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "eoswallet", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "ISC", 11 | "dependencies": { 12 | "binaryen": "^39.0.0", 13 | "ejs": "^2.6.1", 14 | "eosjs": "^16.0.6", 15 | "eosjs-api": "^7.0.3", 16 | "koa": "^2.5.2", 17 | "koa-body": "^4.0.4", 18 | "koa-router": "^7.4.0", 19 | "koa-static": "^5.0.0", 20 | "koa-views": "^6.1.4", 21 | "request": "^2.88.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/router/router.js: -------------------------------------------------------------------------------- 1 | let router = require("koa-router")() 2 | 3 | let webController = require("../controllers/web") 4 | let walletController = require("../controllers/wallet") 5 | let accountController = require("../controllers/account") 6 | let transactionController = require("../controllers/transaction") 7 | let netresourceController = require("../controllers/netResource") 8 | 9 | //钱包 10 | router.post("/wallet/create", walletController.walletCreate) 11 | router.post("/wallet/open", walletController.walletOpen) 12 | router.get("/wallet/list", walletController.walletList) 13 | router.post("/wallet/unlock", walletController.walletUnlock) 14 | router.post("/wallet/lock", walletController.walletLock) 15 | router.post("/wallet/importkey", walletController.walletImportPrivatekey) 16 | router.post("/wallet/keys", walletController.walletGetKeys) 17 | router.post("/wallet/createkey", walletController.walletCreateKey) 18 | router.post("/wallet/privatekey", walletController.walletPubkeyGetPrivatekey) 19 | 20 | //账号 21 | router.post("/account/listforwallet", accountController.accountListForWallet) 22 | router.post("/account/create", accountController.accountCreate) 23 | router.post("/account/balance", accountController.accountBalance) 24 | router.post("/account/info", accountController.accountInfo) 25 | 26 | //转账交易 27 | router.post("/transaction/send", transactionController.transactionSend) 28 | 29 | //网络资源 30 | router.post("/net_resource/ram/info", netresourceController.netResourceGetRAMInfo) 31 | router.post("/net_resource/ram/transaction", netresourceController.netResourceTransactionRAM) 32 | router.post("/net_resource/bandwidth/price", netresourceController.netResourceGetBandwidthPrice) 33 | router.post("/net_resource/bandwidth/transaction", netresourceController.netResourceTransactionBandwidth) 34 | 35 | //页面 36 | router.get("/wallet.html", webController.getWalletHtml) 37 | router.get("/account.html", webController.getAccountHtml) 38 | router.get("/accountinfo.html", webController.getAccountInfoHtml) 39 | router.get("/accountnew.html", webController.getAccountCreateHtml) 40 | router.get("/transaction.html", webController.getTransactionHtml) 41 | router.get("/netresource.html", webController.getNetRosourceHtml) 42 | 43 | module.exports = router -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/static/css/eoswallet.css: -------------------------------------------------------------------------------- 1 | 2 | #main{ 3 | /*background-color: #8bc34a;*/ 4 | margin: 120px 50px 50px 50px; 5 | 6 | } 7 | .error{ 8 | color: red; 9 | } 10 | a{ 11 | color: black; 12 | text-decoration: none; 13 | } 14 | a:hover{ 15 | color: #666; 16 | } 17 | body{ 18 | margin: 0px; 19 | } 20 | ul>li{ 21 | list-style: none; 22 | margin: 0px; 23 | } 24 | 25 | .global-color{ 26 | color: #0abc9c; 27 | } 28 | 29 | ul{ 30 | list-style: none; 31 | padding: 0px; 32 | } 33 | 34 | .row{ 35 | display: inline-block; 36 | margin-right: 70px; 37 | } 38 | .top{ 39 | vertical-align: top 40 | } 41 | a[class=button]{ 42 | background-color: beige; 43 | padding: 2px 10px; 44 | border: 1px solid gray; 45 | } 46 | button{ 47 | background-color: beige; 48 | border: 1px solid gray; 49 | } 50 | 51 | /*导航-------------------------------------------------------------------------------------------------------*/ 52 | #nav{ 53 | display: flex; 54 | justify-content: space-between; 55 | background-color: #0abc9c; 56 | position: fixed; 57 | top: 0px; 58 | left: 0px; 59 | right: 0px; 60 | } 61 | #nav li{ 62 | display: inline-block; 63 | margin: 10px 2px; 64 | } 65 | #nav ul{ 66 | padding: 0px; 67 | } 68 | #nav a{ 69 | padding: 10px; 70 | font-size: 24px; 71 | } 72 | #nav-left{ 73 | margin-left: 20px; 74 | } 75 | #nav-right{ 76 | margin-right: 20px; 77 | } 78 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/static/js/account.js: -------------------------------------------------------------------------------- 1 | 2 | function accountInfo(acocunt) { 3 | localStorage.setItem("currentAccount", acocunt) 4 | window.location.href = "/accountinfo.html" 5 | } 6 | 7 | function goTransaction(account) { 8 | localStorage.setItem("currentAccount", account) 9 | window.location.href = "/transaction.html" 10 | } 11 | 12 | $(document).ready(function () { 13 | let currentwallet = localStorage.getItem("currentwallet") 14 | $("h1").text(currentwallet+" 钱包") 15 | if (!currentwallet) { 16 | return 17 | } 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 20 | 21 | //获取账号列表 22 | let params = {"wallet":currentwallet, "password":walletPassword} 23 | $.post("/account/listforwallet", params, function (res, status) { 24 | console.log(status + JSON.stringify(res)) 25 | if (res.code == 0) { 26 | let accountTable = $("#account-list-table") 27 | res.data.forEach(account => { 28 | let accountTr = ` 29 | 30 | ${account} 31 | 32 | 33 | ` 34 | accountTable.append(accountTr) 35 | }); 36 | 37 | sessionStorage.setItem(`wallet-${currentwallet}-accounts`, JSON.stringify(res.data)) 38 | } 39 | }) 40 | 41 | //导入账户 42 | $("#account-import-form").validate({ 43 | rules: { 44 | privatekey: { 45 | required: true, 46 | }, 47 | }, 48 | messages: { 49 | privatekey: { 50 | required: "请输入要导入的账号的私钥", 51 | }, 52 | }, 53 | submitHandler: function (form) { 54 | $(form).ajaxSubmit({ 55 | url: "/wallet/importkey", 56 | type: "post", 57 | dataType: "json", 58 | success: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(JSON.stringify(res.data)) 61 | if (res.code == 0) { 62 | window.location.reload() 63 | } 64 | }, 65 | error: function (res, status) { 66 | console.log(status + JSON.stringify(res)) 67 | } 68 | }); 69 | } 70 | }) 71 | }) -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/static/js/accountInfo.js: -------------------------------------------------------------------------------- 1 | 2 | function getAccountPermissionPrivateKey(publicKey) { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let currentPassword = localStorage.getItem(currentwallet) 5 | let params = {"wallet":currentwallet, "password":currentPassword, "publickey":publicKey} 6 | console.log(params) 7 | $.post("/wallet/privatekey", params, function (res, status) { 8 | console.log(status, JSON.stringify(res)) 9 | alert(JSON.stringify(res.data)) 10 | }) 11 | } 12 | 13 | $(document).ready(function () { 14 | let currentAccount = localStorage.getItem("currentAccount") 15 | $("h1").text(currentAccount+" 账号") 16 | if (!currentAccount) { 17 | return 18 | } 19 | 20 | //账号金额 21 | let params = {"code":"eosio.token","account":currentAccount} 22 | $.post("/account/balance", params, function (res, status) { 23 | console.log(status + JSON.stringify(res)) 24 | //后端返回的数据结构如下 25 | //[{"symbol":"EOS", "amout":100}, {"symbol":"SYS", "amount":200}] 26 | if (res.code == 0) { 27 | let balanceTable = $("#account-balance-table") 28 | res.data.forEach(balanceData => { 29 | let balanceTr = ` 30 | ${balanceData.symbol} 31 | ${balanceData.amount} 32 | ` 33 | balanceTable.append(balanceTr) 34 | }); 35 | } 36 | }) 37 | 38 | //账号权限详情 39 | $.post("/account/info", {"account":currentAccount}, function (res, status) { 40 | console.log(status + JSON.stringify(res)) 41 | if (res.code == 0) { 42 | let permissionTable = $("#account-permission-table") 43 | for (const index in res.data.permissions) { 44 | let permission = res.data.permissions[index] 45 | let publicKey = permission.required_auth.keys[0].key 46 | let rowTr = ` 47 | ${permission.perm_name} 48 | ${permission.required_auth.threshold} 49 | ${publicKey} 50 | 51 | ${permission.required_auth.keys[0].weight} 52 | ` 53 | permissionTable.append(rowTr) 54 | 55 | for(let i = 1; i < permission.required_auth.keys.length; i++) { 56 | let keyData = permission.required_auth.keys[i] 57 | let rowTr = ` 58 | 59 | 60 | ${keyData.key} 61 | 62 | ${keyData.weight} 63 | ` 64 | permissionTable.append(rowTr) 65 | }; 66 | }; 67 | } 68 | }) 69 | }) -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/static/js/accountNew.js: -------------------------------------------------------------------------------- 1 | 2 | function createKey() { 3 | let currentwallet = localStorage.getItem("currentwallet") 4 | let params = {"wallet": currentwallet, "type":"k1"} 5 | $.post("/wallet/createkey", params, function (res, status) { 6 | console.log(status, JSON.stringify(res)) 7 | alert(res.data) 8 | }) 9 | } 10 | 11 | $(document).ready(function () { 12 | let currentwallet = localStorage.getItem("currentwallet") 13 | $("h1").text(currentwallet+" 钱包") 14 | if (!currentwallet) { 15 | return 16 | } 17 | 18 | let walletPassword = localStorage.getItem(currentwallet) 19 | 20 | $("input[name=wallet][hidden=hidden]").val(currentwallet) 21 | $("input[name=password][hidden=hidden]").val(walletPassword) 22 | 23 | //选择新建者账号列表 24 | let accountList = sessionStorage.getItem(`wallet-${currentwallet}-accounts`) 25 | accountList = JSON.parse(accountList) 26 | console.log("accountList",accountList) 27 | let accountSelectList = $("#account-create-creator-select") 28 | for(let i = 0; accountList && i < accountList.length; i++) { 29 | let account = accountList[i] 30 | let accountOption = `` 31 | accountSelectList.append(accountOption) 32 | } 33 | 34 | //新建账号 35 | $("#account-create-form").validate({ 36 | rules: { 37 | name: {required: true,}, 38 | creator: {required: true,}, 39 | }, 40 | messages: { 41 | name: {required: "请输入要新建的账号名称",}, 42 | creator: {required: "该钱包没有可供新建账号的创者账号,可将该钱包的任意一个公钥发送给其它钱包新建该账号,或者导入其他账号的私钥到该钱包再进行新建账号"}, 43 | }, 44 | submitHandler: function (form) { 45 | $(form).ajaxSubmit({ 46 | url: "/account/create", 47 | type: "post", 48 | dataType: "json", 49 | success: function (res, status) { 50 | console.log(status + JSON.stringify(res)) 51 | if (res.code == 0) { 52 | alert("账号新建成功") 53 | window.location.href = history.go(-1); 54 | } else { 55 | alert("账号新建失败") 56 | } 57 | }, 58 | error: function (res, status) { 59 | console.log(status + JSON.stringify(res)) 60 | alert(res.data) 61 | } 62 | }); 63 | } 64 | }) 65 | }) -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/utils/httpRequest.js: -------------------------------------------------------------------------------- 1 | 2 | let request = require("request"); 3 | let {success, fail} = require("./myUtils") 4 | let config = require("../config/config") 5 | 6 | async function httpRequest(method, url, params) { 7 | console.log("httpRequest:", url, params) 8 | let promise = new Promise((resolve, reject) => { 9 | 10 | var options = { 11 | method: method, 12 | url: url, 13 | body: params, 14 | json: true 15 | }; 16 | request(options, function (error, response, body) { 17 | 18 | if (error) { 19 | reject(error) 20 | } else { 21 | resolve(body) 22 | } 23 | }) 24 | }) 25 | 26 | let result; 27 | //第一个参数是成功的回调 28 | //第二个参数是失败的回调 29 | await promise.then(function (data) { 30 | if (data.error) { 31 | result = fail(data.error) 32 | } else { 33 | result = success(data) 34 | } 35 | }, function(error) { 36 | result = fail(error) 37 | }) 38 | 39 | console.log(JSON.stringify(result)) 40 | return result 41 | } 42 | 43 | function generateURL(path) { 44 | let domain = "" 45 | if (path.indexOf("/v1/wallet/") == 0) { 46 | domain = config.walletAddress 47 | } else { 48 | domain = config.eosconfig.httpEndpoint 49 | } 50 | return domain + path 51 | } 52 | 53 | module.exports = { 54 | 55 | postRequest: async(path, params) => { 56 | return await httpRequest("POST", generateURL(path), params) 57 | }, 58 | 59 | getRequest: async(path, params) => { 60 | return await httpRequest("GET", generateURL(path), params) 61 | }, 62 | 63 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/utils/myUtils.js: -------------------------------------------------------------------------------- 1 | 2 | Eos = require('eosjs') 3 | let config = require("../config/config") 4 | 5 | module.exports = { 6 | 7 | getEOSJS: (keyProvider) => { 8 | config.eosconfig.keyProvider = keyProvider 9 | return Eos(config.eosconfig) 10 | }, 11 | 12 | success: (data) => { 13 | responseData = { 14 | code: 0, 15 | status: "success", 16 | data: data 17 | } 18 | return responseData 19 | }, 20 | 21 | fail: (msg) => { 22 | responseData = { 23 | code: 1, 24 | status: "fail", 25 | data: msg 26 | } 27 | return responseData 28 | }, 29 | 30 | doCallback: async (fn, args) => { 31 | return await fn.apply(this, args); 32 | }, 33 | } -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/account.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 | 去新建账号 18 |
19 |
20 | 21 |
22 | 23 | 24 | 25 |
26 | 27 | 28 |
29 | 30 |
Copyright © 2016-2018 北京从零到壹科技有限公司
31 |
32 | 33 | 34 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/accountInfo.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 账号详情 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 | 17 | 资源管理 18 | 19 | 20 | 21 | 22 | 23 | 24 |
代币金额
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
权限阈值公钥私钥权重
35 | 36 |
Copyright © 2016-2018 北京从零到壹科技有限公司
37 |
38 | 39 | 40 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/accountNew.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 新建账号 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |

新建账号

17 | 18 |
19 | 20 | 21 |

22 | 23 | 25 | 26 |

27 | 28 |
以下内容可以选择填写
29 | 30 | 31 |
32 | 33 | 34 | 35 |
36 | 37 | 38 | 39 |

40 | 41 | 42 | 43 |
44 | 45 |
Copyright © 2016-2018 北京从零到壹科技有限公司
46 |
47 | 48 | 49 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/block/nav.html: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/transaction.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 转账 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

16 |
17 |
18 | 20 | 21 |

22 | 23 | 24 | 25 |

26 | 27 | 28 | 30 | 31 |

32 | 33 | 34 | 35 |

36 | 37 | 38 | 39 |
40 |
41 | 42 |
43 | 44 | 45 | 46 | 47 | 48 |
代币金额
49 | 50 |
51 |
52 | 53 |
Copyright © 2016-2018 北京从零到壹科技有限公司
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /EOSWallet:12-抵押和赎回NET与CPU带宽/views/wallet.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 钱包 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | <%include block/nav.html%> 13 | 14 |
15 |

钱包列表

16 |
17 | 18 | 19 |
20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 |
28 | 29 |
Copyright © 2016-2018 北京从零到壹科技有限公司
30 |
31 | 32 | 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EOSWallet 2 | 使用NodeJS基于本地网络,最后升级为测试网络开发的EOS钱包,包含钱包模块、账户模块、转账模块,重难点是账户的权限管理与网络资源管理,另外使用了cleos配置账号权限。 3 | 4 | 项目介绍 5 | 6 | 钱包种类非常多,主流的有以太坊钱包、比特币钱包、EOS钱包以及其他类型的虚拟货币钱包。在咱们这次课程中是来开发EOS钱包,以太坊钱包可以在博主的主页查看,在后面的课程也会陆续推出比特币钱包、XRP钱包、TRC钱包、ADA钱包等。 7 | 8 | 本教程围绕以太坊钱包项目开发逐步进行讲解,该项目以NodeJS语言编写后端,使用web前端演示。内容包含:视频、文档、源码。 9 | 10 | EOS作为一个广泛使用的区块链开发平台,被称作为区块链3.0,包含的数字货币资产的转移和投资必然需要使用到钱包,因此钱包是区块链领域必需掌握的知识,另外也是交易所开发的核心。目前企业对钱包开发的需求较大,很少有成熟的钱包开发教程,因此特推出此教程满足企业与市场上对钱包的需求,以帮助大家快速全面的掌握EOS钱包理论与开发实践。 11 | 12 | 13 | 14 | 本教程能学到什么 15 | 16 | - 彻底搞清楚EOS账户系统的权限配置 17 | - 搞清楚RAM、Network BandWidth、CPU BandWidth它们的关系与重要作用 18 | - 对网络资源进行买卖、抵押、赎回等以满足你对EOS操作的需求 19 | - 使用RPC轻松访问EOS区块链数据 20 | - 使用EOSJS库轻松访问EOS区块链数据 21 | - 安全管理和转移你的Token数字资产 22 | 23 | 24 | 25 | 教程大纲 26 | 27 | 1. 不得不说的一些概念 28 | 2. EOS开发环境搭建 29 | 3. EOS钱包项目整体架构设计 30 | 4. 使用keosd服务开发钱包模块 31 | 5. 使用cleos工具管理账号权限 32 | 6. 深入浅出EOSJS:连接到主网、测试网、交易 33 | 7. 创建账号与查看账号权限配置 34 | 8. EOS代币转账交易 35 | 9. 基于测试网络进行开发 36 | 10. 详解与获取ARM、NET、CPU资源数据 37 | 11. 买入卖出RAM 38 | 12. 抵押和赎回NET与CPU带宽 39 | 40 | 41 | 42 | 项目路线 43 | 44 | 项目的路线规划是: 45 | 46 | - 介绍以太坊钱包中涉及的重点理论知识。 47 | 48 | - EOS本地开发环境搭建。 49 | 50 | - 项目架构搭建:以NodeJS开发后端,使用了Koa与相关框架,前端以web进行交互。 51 | 52 | - cleos辅助工具配置账户权限。 53 | 54 | - 使用RPC与EOS区块链进行交互一步步实现钱包、账号、转账模块各个功能,另外也使用了eosjs库执行交易。 55 | 56 | - 最后连接到测试网络进行测试并管理您的网络资源 57 | 58 | --- 59 | 60 | 61 | **完整文档请查看原文:http://chaindesk.cn/columnlist.html?id=2** 62 | 63 | 版权声明:博客中的文章版权归博主所有,未经授权禁止转载,转载请联系作者(微信:lixu1770105)取得同意并注明出处。 64 | 65 | --------------------------------------------------------------------------------