├── .gitignore ├── LICENSE ├── README.md ├── bin ├── create-db │ ├── cassandra │ └── couchbase ├── create-topics └── run-dev-env ├── docker-compose ├── chainode.yml ├── chainode │ └── Dockerfile ├── confluentkafka │ └── Dockerfile ├── databases │ └── couchbase.yml ├── dev-app.yml ├── integration-tests.yml ├── kafka.yml ├── network.yml └── redis.yml ├── docker └── Dockerfile ├── docs ├── css │ ├── 1.d0fd5c424617924c5c9e.css │ └── app.d0fd5c424617924c5c9e.css ├── favicon.ico ├── img │ ├── image.png │ └── logo.png ├── index.html └── js │ ├── app.js │ └── vendors.b23e04c6597b16c8b826.bundle.js ├── img ├── architecture │ ├── architecture.png │ └── architecture.svg ├── favicon.ico ├── logo.png └── logo.svg ├── index.js ├── lib ├── aes.js ├── block.js ├── configs │ ├── defaults.js │ ├── getConfigs.js │ └── loadConfigs.js ├── crypt.js ├── database │ ├── couchbase │ │ ├── db.js │ │ ├── helpers.js │ │ └── methods │ │ │ └── ledger.js │ └── redis │ │ ├── db.js │ │ ├── peers.js │ │ └── users.js ├── docs │ ├── README.md │ ├── package.json │ ├── server.js │ ├── src │ │ ├── components │ │ │ ├── 404.vue │ │ │ ├── App.vue │ │ │ ├── Home.vue │ │ │ └── commons │ │ │ │ ├── footer │ │ │ │ └── index.vue │ │ │ │ └── navbar │ │ │ │ └── index.vue │ │ ├── configs.js │ │ ├── img │ │ │ ├── favicon.ico │ │ │ ├── image.png │ │ │ └── logo.png │ │ ├── index.html │ │ ├── lib │ │ │ ├── filters.js │ │ │ └── utils.js │ │ ├── main.js │ │ ├── router │ │ │ ├── index.js │ │ │ └── routes.js │ │ ├── scss │ │ │ ├── _custom.scss │ │ │ ├── _dashboard.scss │ │ │ ├── _footer.scss │ │ │ ├── _helpers.scss │ │ │ ├── _typography.scss │ │ │ ├── _variables.scss │ │ │ ├── app.scss │ │ │ ├── navbar │ │ │ │ ├── _colors.scss │ │ │ │ └── _navbar.scss │ │ │ └── themes │ │ │ │ ├── _clean.scss │ │ │ │ ├── _enjoyable.scss │ │ │ │ ├── _nerd.scss │ │ │ │ └── _serious.scss │ │ ├── store │ │ │ ├── actions.js │ │ │ └── store.js │ │ └── styles.js │ ├── webpack.config.js │ └── webpack │ │ ├── configs.js │ │ ├── configs │ │ └── vueLoaderConfig.js │ │ ├── externalFiles.js │ │ ├── helpers.js │ │ └── plugins.js ├── errors.js ├── helpers.js ├── kafka │ ├── filterTopicsByRole.js │ ├── initKafka.js │ └── kafkaHelpers.js ├── logger.js ├── rsa.js └── sdk.js ├── main.js ├── package.json ├── test ├── configs │ └── generic.json ├── lib │ └── apis.js └── unit.js └── web-console ├── backend ├── lib │ ├── ErrorHandler.js │ └── logHandler.js ├── middlewares │ └── isAuth.js ├── router.js ├── routes.js ├── routes │ ├── auth │ │ ├── signin.js │ │ └── signup.js │ ├── block │ │ ├── list.js │ │ └── propose.js │ └── status │ │ ├── health.js │ │ └── stats.js └── server.js └── frontend ├── build ├── css │ ├── 1.b477591bf8e0f7b74f35.css │ └── app.b477591bf8e0f7b74f35.css ├── favicon.ico ├── img │ ├── image.png │ └── logo.png ├── index.html ├── js │ ├── app.js │ └── vendors.6e0392ac3fe2f3f57d7e.bundle.js └── webfonts │ ├── fa-brands-400.eot │ ├── fa-brands-400.svg │ ├── fa-brands-400.ttf │ ├── fa-brands-400.woff │ ├── fa-brands-400.woff2 │ ├── fa-regular-400.eot │ ├── fa-regular-400.svg │ ├── fa-regular-400.ttf │ ├── fa-regular-400.woff │ ├── fa-regular-400.woff2 │ ├── fa-solid-900.eot │ ├── fa-solid-900.svg │ ├── fa-solid-900.ttf │ ├── fa-solid-900.woff │ └── fa-solid-900.woff2 ├── package.json ├── src ├── components │ ├── 404.vue │ ├── App.vue │ ├── Home.vue │ ├── blocks │ │ ├── List.vue │ │ ├── Propose.vue │ │ └── pagination │ │ │ └── Pagination.vue │ └── commons │ │ ├── footer │ │ └── index.vue │ │ └── navbar │ │ └── index.vue ├── configs.js ├── img │ ├── favicon.ico │ ├── image.png │ └── logo.png ├── index.html ├── lib │ ├── filters.js │ └── utils.js ├── main.js ├── router │ ├── index.js │ └── routes.js ├── scss │ ├── _custom.scss │ ├── _dashboard.scss │ ├── _footer.scss │ ├── _helpers.scss │ ├── _typography.scss │ ├── _variables.scss │ ├── app.scss │ ├── navbar │ │ ├── _colors.scss │ │ └── _navbar.scss │ └── themes │ │ ├── _clean.scss │ │ ├── _enjoyable.scss │ │ ├── _nerd.scss │ │ └── _serious.scss ├── services │ ├── blocks.js │ └── status.js ├── store │ ├── actions.js │ └── store.js └── styles.js ├── webpack.config.js └── webpack ├── configs.js ├── configs └── vueLoaderConfig.js ├── externalFiles.js ├── helpers.js └── plugins.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | /node_modules/ 37 | /lib/docs/node_modules/ 38 | /web-console/frontend/node_modules/ 39 | jspm_packages/ 40 | 41 | # Typescript v1 declaration files 42 | typings/ 43 | 44 | # Optional npm cache directory 45 | .npm 46 | 47 | # Optional eslint cache 48 | .eslintcache 49 | 50 | # Optional REPL history 51 | .node_repl_history 52 | 53 | # Output of 'npm pack' 54 | *.tgz 55 | package-lock.json 56 | 57 | # Yarn Integrity file 58 | .yarn-integrity 59 | 60 | # dotenv environment variables file 61 | .env 62 | 63 | # Custom 64 | docker/data/* 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Chainode logo 4 | 5 |

6 |

Chainode

7 | 8 |

Fast, Highly Scalable, and Lightweight Private Blockchain Network

9 | 10 |

11 | 12 | GitHub license 13 | 14 | 15 | PRs Welcome 16 | 17 |

18 | 19 | Chainode is a private blockchain designed to be fast, lightweight, and highly scalable. The network allows to exchange data (transactions) between trusted participants. These transactions are stored as blocks in a distributed ledger. 20 | 21 | Chainode is written in pure Javascript for Node.js, and it is based on Kafka as communication system and block order. Designed for BigData use cases, it is message driven, each peer supports load balancing and is resistant to failures. The Chainode Blockchain is fast, every block is propagated to the network and added to the ledger as soon as it was generated. It is very lightweight being able to run on cheap machines. Every peer provides REST APIs and a Web Console. 22 | 23 | ## Index of contents 24 | 25 | - [**Introduction**](https://github.com/davidemiceli/chainode/wiki) 26 | - [**Features**](https://github.com/davidemiceli/chainode/wiki/Features) 27 | - [**How it works**](https://github.com/davidemiceli/chainode/wiki/HowItWorks) 28 | - [**Requirements**](https://github.com/davidemiceli/chainode/wiki/Requirements) 29 | - [**Architecture**](https://github.com/davidemiceli/chainode/wiki/Architecture) 30 | - [**Getting Started**](https://github.com/davidemiceli/chainode/wiki/GettingStarted) 31 | - [**Configurations**](https://github.com/davidemiceli/chainode/wiki/Configurations) 32 | - [**Development**](https://github.com/davidemiceli/chainode/wiki/Development) 33 | - [**SDK**](https://github.com/davidemiceli/chainode/wiki/SDK) 34 | - [**REST APIs**](https://github.com/davidemiceli/chainode/wiki/RestApis) 35 | - [**Status**](https://github.com/davidemiceli/chainode/wiki/RestApis-Status) 36 | - [**Stats**](https://github.com/davidemiceli/chainode/wiki/RestApis-Stats) 37 | - [**List of blocks**](https://github.com/davidemiceli/chainode/wiki/RestApis-ListOfBlocks) 38 | - [**New transaction**](https://github.com/davidemiceli/chainode/wiki/RestApis-NewTransaction) 39 | 40 | ## License 41 | 42 | Chainode is licensed under the terms of the [GNU Affero General Public License Version 3 (AGPL)](LICENSE). 43 | Documentation is licensed under [CC BY 4.0](http://creativecommons.org/licenses/by/4.0/). 44 | -------------------------------------------------------------------------------- /bin/create-db/cassandra: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Create Cassandra keyspace and table 3 | 4 | KEYSPACE=blockchain 5 | TABLE=ledger 6 | 7 | for i in {1..3}; 8 | do 9 | DBCONTAINER=db00$i 10 | docker exec -it $DBCONTAINER cqlsh -e "DROP KEYSPACE IF EXISTS $KEYSPACE;" 11 | docker exec -it $DBCONTAINER cqlsh -e "CREATE KEYSPACE IF NOT EXISTS $KEYSPACE WITH replication = {'class': 'SimpleStrategy', 'replication_factor': '1'} AND durable_writes = true;" 12 | docker exec -it $DBCONTAINER cqlsh -e "CREATE TABLE IF NOT EXISTS $KEYSPACE.$TABLE (hash text, organization text, event_id text, generated_time timestamp, data text, PRIMARY KEY ((hash), organization, event_id, generated_time));" 13 | echo "Created keyspace and table for $DBCONTAINER." 14 | done 15 | -------------------------------------------------------------------------------- /bin/create-db/couchbase: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Create Couchbase cluster and bucket 3 | 4 | USER=admin 5 | PWD=secret 6 | BUCKET=blockchain 7 | CREATE_PRIMARY_INDEX="\"CREATE PRIMARY INDEX ON $BUCKET\"" 8 | CREATE_INDEX="\"CREATE INDEX ind_generated_time ON $BUCKET(generated_time)\"" 9 | 10 | NUM_OF_DB=$(seq 3); 11 | 12 | for i in $NUM_OF_DB; 13 | do 14 | DBCONTAINER=db00$i 15 | docker exec -it $DBCONTAINER /bin/bash -c "couchbase-cli cluster-init -c 0.0.0.0 --cluster-username $USER --cluster-password $PWD --services data,index,query,fts,analytics --cluster-ramsize 512 --cluster-index-ramsize 512 --cluster-eventing-ramsize 512 --cluster-fts-ramsize 512 --cluster-analytics-ramsize 1024 --cluster-fts-ramsize 512 --index-storage-setting default" 16 | echo "Initialized database cluster for $DBCONTAINER." 17 | sleep 1 18 | docker exec -it $DBCONTAINER /bin/bash -c "couchbase-cli bucket-create -c 0.0.0.0 --username $USER --password $PWD --bucket $BUCKET --bucket-type couchbase --bucket-ramsize 512" 19 | echo "Created bucket $BUCKET for $DBCONTAINER." 20 | sleep 3 21 | done 22 | 23 | for i in $NUM_OF_DB; 24 | do 25 | DBCONTAINER=db00$i 26 | docker exec -it $DBCONTAINER sh -c "/opt/couchbase/bin/cbq -e couchbase://0.0.0.0 -user $USER -password $PWD -script $CREATE_PRIMARY_INDEX" 27 | echo "Created primary index for $DBCONTAINER." 28 | sleep 1 29 | docker exec -it $DBCONTAINER sh -c "/opt/couchbase/bin/cbq -e couchbase://0.0.0.0 -user $USER -password $PWD -script $CREATE_INDEX" 30 | echo "Created index on bucket $BUCKET for $DBCONTAINER." 31 | sleep 3 32 | done 33 | -------------------------------------------------------------------------------- /bin/create-topics: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for t in pending ledger 4 | do 5 | topic="blockchain.blocks.$t" 6 | echo "Trying to create the kafka topic $topic" 7 | docker exec -it confluentkafka /bin/bash -c "/confluent/bin/kafka-topics --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic $topic --if-not-exists" 8 | done 9 | -------------------------------------------------------------------------------- /bin/run-dev-env: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # Start environment for development 5 | if [ -z "$DB" ] 6 | then 7 | echo -e "Missing environmental variable DB (ie: mongodb, cassandra, etc)."; 8 | exit 1; 9 | fi 10 | 11 | echo -e "Starting dockerized environment for development."; 12 | cd docker-compose/ 13 | docker-compose -f network.yml -f kafka.yml -f databases/$DB.yml -f dev-app.yml $@ 14 | cd ../ 15 | -------------------------------------------------------------------------------- /docker-compose/chainode.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | services: 4 | 5 | # ------------------------------------------------------- 6 | # Application peers for integration tests 7 | # ------------------------------------------------------- 8 | chainode: 9 | image: chainode 10 | container_name: chainode 11 | environment: 12 | - CONFIGS=/node_modules/chainode/test/configs/generic.json 13 | network_mode: host 14 | -------------------------------------------------------------------------------- /docker-compose/chainode/Dockerfile: -------------------------------------------------------------------------------- 1 | # Base image 2 | FROM node:10.12 3 | 4 | # Configure environment 5 | ENV LANG=C.UTF-8 \ 6 | LC_ALL=C.UTF-8 \ 7 | DEBIAN_FRONTEND=noninteractive 8 | 9 | # Create app directory 10 | WORKDIR /app 11 | 12 | # Update npm 13 | RUN npm i -g npm 14 | 15 | # Install useful packages 16 | RUN npm cache clean -f 17 | 18 | # CMD npm start 19 | -------------------------------------------------------------------------------- /docker-compose/confluentkafka/Dockerfile: -------------------------------------------------------------------------------- 1 | # Base image 2 | FROM confluent/platform 3 | 4 | # Kafka Confluent version 5 | ARG KAFKA_VERSION=4.1.0-2.11 6 | 7 | # Configure environment 8 | ENV LANG=C.UTF-8 \ 9 | LC_ALL=C.UTF-8 \ 10 | DEBIAN_FRONTEND=noninteractive 11 | 12 | # Install Kafka Confluent 13 | RUN wget http://packages.confluent.io/archive/4.1/confluent-oss-$KAFKA_VERSION.tar.gz -q --show-progress -O kafka-confluent.tar.gz 14 | RUN tar xf kafka-confluent.tar.gz 15 | RUN mv confluent-* confluent 16 | RUN rm kafka-confluent.tar.gz 17 | 18 | CMD ["cd", "confluent/bin", "&&", "./confluent", "start", "kafka", "&&", "./confluent", "log", "kafka", "-f"] 19 | -------------------------------------------------------------------------------- /docker-compose/databases/couchbase.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | 4 | services: 5 | # ----------------------------------- 6 | # Couchdb server (Ports: 8091-8094:8091-8094) 7 | # https://hub.docker.com/r/couchbase/server/ 8 | # ----------------------------------- 9 | db001: 10 | image: couchbase 11 | container_name: db001 12 | user: couchbase 13 | networks: 14 | chainet: 15 | ipv4_address: "172.25.255.20" 16 | 17 | db002: 18 | image: couchbase 19 | container_name: db002 20 | user: couchbase 21 | networks: 22 | chainet: 23 | ipv4_address: "172.25.255.21" 24 | 25 | db003: 26 | image: couchbase 27 | container_name: db003 28 | user: couchbase 29 | networks: 30 | chainet: 31 | ipv4_address: "172.25.255.22" 32 | -------------------------------------------------------------------------------- /docker-compose/dev-app.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | services: 4 | 5 | # ------------------------------------------------------- 6 | # Application peers for integration tests 7 | # ------------------------------------------------------- 8 | nodejs: 9 | image: node:10.12 10 | container_name: nodejs 11 | user: "1000:1000" 12 | volumes: 13 | - ../:/app 14 | command: tail -f /dev/null 15 | working_dir: /app 16 | depends_on: 17 | - confluentkafka 18 | - db001 19 | - db002 20 | - db003 21 | networks: 22 | chainet: 23 | ipv4_address: "172.25.255.50" 24 | -------------------------------------------------------------------------------- /docker-compose/integration-tests.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | services: 4 | 5 | # ------------------------------------------------------- 6 | # Application peers for integration tests 7 | # ------------------------------------------------------- 8 | peer000: 9 | image: node:10.12 10 | container_name: peer000 11 | user: "1000:1000" 12 | volumes: 13 | - ../:/app 14 | environment: 15 | - CONFIGS=/app/test/configs/generic.js 16 | - BLOCKCHAIN=blockchain 17 | - ORGANIZATION=brand001 18 | - ROLE=peer 19 | - PEER_ID=000 20 | - DB_TYPE=cassandra 21 | - DB_HOST=172.25.255.20 22 | - WEBUI_HOST=172.25.255.51 23 | command: npm start 24 | working_dir: /app 25 | depends_on: 26 | - nodejs 27 | networks: 28 | chainet: 29 | ipv4_address: "172.25.255.51" 30 | 31 | peer001: 32 | image: node:10.12 33 | container_name: peer001 34 | user: "1000:1000" 35 | volumes: 36 | - ../:/app 37 | environment: 38 | - CONFIGS=/app/test/configs/generic.js 39 | - BLOCKCHAIN=blockchain 40 | - ORGANIZATION=brand002 41 | - ROLE=peer 42 | - PEER_ID=001 43 | - DB_TYPE=cassandra 44 | - DB_HOST=172.25.255.21 45 | - WEBUI_HOST=172.25.255.52 46 | command: npm start 47 | working_dir: /app 48 | depends_on: 49 | - peer000 50 | networks: 51 | chainet: 52 | ipv4_address: "172.25.255.52" 53 | -------------------------------------------------------------------------------- /docker-compose/kafka.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | services: 4 | # Confluent Kafka => Port 9092 5 | confluentkafka: 6 | image: confluentkafka 7 | container_name: confluentkafka 8 | build: 9 | context: ./confluentkafka 10 | dockerfile: ./Dockerfile 11 | network: host 12 | command: /bin/bash -c "cd confluent/bin && ./confluent start kafka && ./confluent log kafka -f" 13 | networks: 14 | chainet: 15 | ipv4_address: "172.25.255.61" 16 | -------------------------------------------------------------------------------- /docker-compose/network.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | networks: 4 | chainet: 5 | name: chainet 6 | driver: bridge 7 | ipam: 8 | config: 9 | - subnet: 172.25.255.0/24 10 | -------------------------------------------------------------------------------- /docker-compose/redis.yml: -------------------------------------------------------------------------------- 1 | version: "3.5" 2 | 3 | services: 4 | 5 | redis: 6 | image: redis 7 | container_name: redis 8 | volumes: 9 | - ./data/redis:/data 10 | networks: 11 | chainet: 12 | ipv4_address: "172.25.255.30" 13 | -------------------------------------------------------------------------------- /docker/Dockerfile: -------------------------------------------------------------------------------- 1 | # Base image 2 | FROM node:10.15 3 | 4 | # Configure environment 5 | ENV LANG=C.UTF-8 \ 6 | LC_ALL=C.UTF-8 \ 7 | DEBIAN_FRONTEND=noninteractive 8 | 9 | # Update npm 10 | RUN npm i -g npm 11 | RUN npm cache clean -f 12 | 13 | # Install Chainode 14 | RUN npm init --force 15 | RUN npm install chainode 16 | WORKDIR /node_modules/chainode 17 | 18 | # Run Chainode peer 19 | CMD npm start 20 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/docs/favicon.ico -------------------------------------------------------------------------------- /docs/img/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/docs/img/image.png -------------------------------------------------------------------------------- /docs/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/docs/img/logo.png -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Chainode | Private Blockchain Network 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /img/architecture/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/img/architecture/architecture.png -------------------------------------------------------------------------------- /img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/img/favicon.ico -------------------------------------------------------------------------------- /img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/img/logo.png -------------------------------------------------------------------------------- /img/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | 24 | 46 | 48 | 49 | 51 | image/svg+xml 52 | 54 | 55 | 56 | 57 | 58 | 63 | 72 | 81 | 90 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Export blockchain SDK module 4 | module.exports = require('./lib/sdk'); 5 | -------------------------------------------------------------------------------- /lib/aes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const crypto = require('crypto'); 5 | 6 | const randomString = (strlength) => { 7 | const randlength = (strlength === 32) ? 16 : 8; 8 | return crypto.randomBytes(randlength).toString('hex'); 9 | } 10 | 11 | const aes = {}; 12 | const algorithm = 'aes-256-cbc'; 13 | 14 | aes.generateKey = () => randomString(32); 15 | 16 | aes.generateIV = () => randomString(16); 17 | 18 | aes.decrypt = (cryptkey, iv, encryptdata) => { 19 | const encryptmsg = new Buffer(encryptdata, 'base64').toString('binary'); 20 | const decipher = crypto.createDecipheriv(algorithm, cryptkey, iv); 21 | let decoded = decipher.update(encryptmsg, 'binary', 'utf8'); 22 | decoded += decipher.final('utf8'); 23 | return decoded; 24 | } 25 | 26 | aes.encrypt = (cryptkey, iv, cleardata) => { 27 | const encipher = crypto.createCipheriv(algorithm, cryptkey, iv); 28 | let encryptdata = encipher.update(cleardata, 'utf8', 'binary'); 29 | encryptdata += encipher.final('binary'); 30 | const encode_encryptdata = new Buffer(encryptdata, 'binary').toString('base64'); 31 | return encode_encryptdata; 32 | } 33 | 34 | module.exports = aes; 35 | -------------------------------------------------------------------------------- /lib/block.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Block methods 4 | */ 5 | 6 | // Requirements 7 | const uuid4 = require('uuid/v4'); 8 | const CRYPT = require('./crypt'); 9 | const { utcTimestamp } = require('./helpers'); 10 | 11 | // Calculate hash of a block 12 | const calculateHash = (event_id, organization, generated_time, data) => { 13 | const toHash = `${event_id}|${organization}|${generated_time}|${data}`; 14 | return CRYPT.md5(toHash).toString(); 15 | } 16 | 17 | // Convert to block object 18 | const toBlock = b => block(b.id, b.event_id, b.organization, b.generated_time, b.data); 19 | 20 | // Block object 21 | const block = (id, event_id, organization, generated_time, data) => ({ 22 | id: id, 23 | event_id: event_id, 24 | organization: organization, 25 | generated_time: generated_time, 26 | data: data 27 | }); 28 | 29 | // Generate a block 30 | const generateNextBlock = (organization, data) => { 31 | const event_id = uuid4() 32 | const generated_time = utcTimestamp(); 33 | const id = calculateHash(event_id, organization, generated_time, data); 34 | return block(id, event_id, organization, generated_time, data); 35 | } 36 | 37 | // Calculate the hash from a block 38 | const calculateHashFromBlock = b => calculateHash(b.event_id, b.organization, b.generated_time, b.data); 39 | 40 | // Check if a block is valid 41 | const isValidBlock = (logger, block) => { 42 | const oneBlockId = calculateHashFromBlock(block); 43 | if (oneBlockId !== block.id) { 44 | logger.error(`Found invalid hash ${block.id} compared to ${oneBlockId}.`); 45 | return false; 46 | } 47 | return true; 48 | } 49 | 50 | 51 | // Export block methods 52 | module.exports = { 53 | toBlock, 54 | generateNextBlock, 55 | isValidBlock 56 | }; 57 | -------------------------------------------------------------------------------- /lib/configs/defaults.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | Default configurations 5 | */ 6 | 7 | 8 | module.exports = { 9 | kafka: { 10 | topics: { 11 | pending: 'blockchain.blocks.pending', 12 | ledger: 'blockchain.blocks.ledger' 13 | }, 14 | consumer: { 15 | autoCommit: true, 16 | encoding: 'utf8', 17 | keyEncoding: 'utf8' 18 | }, 19 | producer: { 20 | partitionerType: 2 21 | } 22 | }, 23 | webconsole: { 24 | enabled: true, 25 | port: 8080, 26 | jwt: { 27 | secret: '58cae43479d0403dad5908a61b0460105f4c45699acd43ccae568157b3153a920242a2bc09d54af4aa04c830b308ba0c', 28 | expire: '5m' 29 | }, 30 | admin: { 31 | usedb: false, 32 | user: 'admin', 33 | password: 'admin' 34 | } 35 | }, 36 | logs: { 37 | level: 'info', 38 | console: true, 39 | path: './logs' 40 | } 41 | }; 42 | -------------------------------------------------------------------------------- /lib/configs/getConfigs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Get and parse configurations from a json file 4 | */ 5 | 6 | // Requirements 7 | const fs = require('fs'); 8 | 9 | 10 | module.exports = () => { 11 | try { 12 | const configs = fs.readFileSync(process.env.CONFIGS); 13 | return JSON.parse(configs); 14 | } catch(err) { 15 | console.error('Missing environmental parameter "CONFIGS" (path and name of configuration file).'); 16 | console.error(err.stack); 17 | process.exit(1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/configs/loadConfigs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Load and handle configurations 4 | */ 5 | 6 | // Requirements 7 | const uuid4 = require('uuid/v4'); 8 | const defaultConfigs = require('./defaults'); 9 | const getConfigs = require('./getConfigs'); 10 | 11 | 12 | // Check params 13 | const checkParams = configs => { 14 | if (!/^(peer)$/.test(configs.role)) throw Error(`Invalid peer role ${configs.role}.`); 15 | if (!configs.kafka.consumer.groupId) throw Error('Missing kafka.consumer.groupId configuration.'); 16 | return true; 17 | } 18 | 19 | // Convert a comma separated string as a list of hosts 20 | const getHosts = hosts => hosts ? hosts.replace(/^\s+/,'').split(',') : undefined; 21 | 22 | 23 | // Handle configurations 24 | module.exports = () => { 25 | try { 26 | // Get configurations from a json file 27 | const rawConfigs = getConfigs(); 28 | // Extends missing fields with defaults 29 | const configs = Object.assign(defaultConfigs, rawConfigs); 30 | // General 31 | configs.blockchain = process.env.BLOCKCHAIN || configs.blockchain; 32 | configs.organization = process.env.ORGANIZATION || configs.organization; 33 | configs.role = process.env.ROLE || configs.role; 34 | configs.id = process.env.PEER_ID || configs.id || uuid4(); 35 | // Kafka 36 | configs.kafka.consumer.groupId = process.env.GROUPID || configs.kafka.consumer.groupId; 37 | configs.kafka.hosts = getHosts(process.env.KAFKA_HOSTS) || configs.kafka.hosts; 38 | // Database 39 | configs.db.hosts = getHosts(process.env.DB_HOSTS) || configs.db.hosts; 40 | configs.db.bucket = process.env.DB_BUCKET || configs.db.bucket; 41 | // Web Console 42 | configs.webconsole.host = process.env.WEBUI_HOST || configs.webconsole.host || 'http://localhost'; 43 | configs.webconsole.port = process.env.WEBUI_PORT || configs.webconsole.port || 8080; 44 | // Logs 45 | configs.logs.console = (configs.logs.console === false) ? true : false; 46 | configs.logs.level = configs.logs.level || 'error'; 47 | // Check parameters 48 | checkParams(configs); 49 | // Return configurations 50 | return configs; 51 | } catch(err) { 52 | console.error('Error on loading configurations.'); 53 | console.error(err.stack); 54 | process.exit(1); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /lib/crypt.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const crypto = require('crypto'); 5 | const RSA = require('./rsa'); 6 | const AES = require('./aes'); 7 | 8 | module.exports = { 9 | md5: function(to_hash) { 10 | return crypto.createHash('sha256').update(to_hash).digest('hex'); 11 | }, 12 | decrypt: function(privateKey, data) { 13 | try { 14 | // Get decryption items 15 | const encryptedKey = data.key; 16 | const iv = data.iv; 17 | const message = data.msg; 18 | // Decrypt key 19 | const decryptedKey = RSA.decrypt(privateKey, encryptedKey); 20 | // Decrypt IV 21 | const decryptedIV = RSA.decrypt(privateKey, iv); 22 | // Decrypt message with decrypted AES key 23 | const decrypted = AES.decrypt(decryptedKey, decryptedIV, message); 24 | return decrypted; 25 | // return JSON.parse(decrypted); 26 | } catch(err) { 27 | console.log(`Error during message decryption.`); 28 | return false; 29 | } 30 | }, 31 | encrypt: function(pubKey, message) { 32 | // Generate an AES key and IV 33 | const aesKey = AES.generateKey(); 34 | const iv = AES.generateIV(); 35 | // Encrypt message with AES key 36 | const encryptedMSG = AES.encrypt(aesKey, iv, JSON.stringify(message)); 37 | // Encrypt AES key with RSA Public Key 38 | const encryptedKey = RSA.encrypt(pubKey, aesKey); 39 | // Encrypt AES IV with RSA Public Key 40 | const encryptedIV = RSA.encrypt(pubKey, iv); 41 | return { 42 | key: encryptedKey, 43 | iv: encryptedIV, 44 | msg: encryptedMSG 45 | }; 46 | }, 47 | sign: function(privateKey, message) { 48 | const signer = crypto.createSign('sha256'); 49 | signer.update( 50 | JSON.stringify(message) 51 | ); 52 | return signer.sign(privateKey, 'base64'); 53 | }, 54 | verify: function(publicKey, sign, message) { 55 | const verifier = crypto.createVerify('sha256'); 56 | verifier.update(message); 57 | return verifier.verify(publicKey, sign, 'base64'); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/database/couchbase/db.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const couchbase = require('couchbase'); 5 | const LedgerModel = require('./methods/ledger'); 6 | 7 | 8 | // Open couchbase bucket 9 | const openBucket = (cluster, bucketname) => { 10 | return new Promise((resolve, reject) => { 11 | let bucket = cluster.openBucket(bucketname, function(err) { 12 | return err ? reject(err) : resolve(bucket); 13 | }); 14 | }); 15 | } 16 | 17 | 18 | // Couchbase database model 19 | module.exports = async (configs, logger) => { 20 | 21 | // Get configs 22 | const { 23 | hosts, 24 | bucket, 25 | username, 26 | password 27 | } = configs; 28 | 29 | // Couchbase driver 30 | const listHosts = hosts.join(','); 31 | const cluster = new couchbase.Cluster(`couchbase://${listHosts}`); 32 | 33 | cluster.authenticate(username, password); 34 | const db = await openBucket(cluster, bucket); 35 | 36 | db.on('error', function(err) { 37 | logger.error(err.stack); 38 | }); 39 | 40 | const q = couchbase.N1qlQuery; 41 | 42 | const Ledger = new LedgerModel(bucket, db, q); 43 | 44 | logger.info(`Couchbase client is ready (bucket ${bucket}) on ${listHosts}.`); 45 | 46 | return { 47 | Ledger 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /lib/database/couchbase/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Helpers for couchbase client 4 | */ 5 | 6 | 7 | // Create a key 8 | const metaIdFromHash = (recordType, blockId) => { 9 | return `${recordType}:${blockId}`; 10 | } 11 | 12 | // Get a record 13 | const get = db => id => { 14 | return new Promise((resolve, reject) => { 15 | return db.get(id, function(err, res) { 16 | if (err) return reject(err); 17 | return resolve(res); 18 | }); 19 | }); 20 | } 21 | 22 | // Execute a query 23 | const query = (db, q) => (qs, params) => { 24 | const query = q.fromString(qs); 25 | return new Promise((resolve, reject) => { 26 | return db.query(query, params, function(err, rows) { 27 | if (err) return reject(err); 28 | return resolve(rows); 29 | }); 30 | }); 31 | } 32 | 33 | // Insert data 34 | const insert = db => (id, data) => { 35 | return new Promise((resolve, reject) => { 36 | return db.insert(id, data, function(err, res) { 37 | if (err) return reject(err); 38 | return resolve(res); 39 | }); 40 | }); 41 | } 42 | 43 | 44 | module.exports = (db, q) => ({ 45 | metaIdFromHash: metaIdFromHash, 46 | get: get(db), 47 | insert: insert(db), 48 | query: query(db, q) 49 | }); 50 | -------------------------------------------------------------------------------- /lib/database/couchbase/methods/ledger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Ledger model 4 | */ 5 | 6 | 7 | // Model to interact to the Ledger 8 | module.exports = class { 9 | 10 | constructor(bucketname, db, q) { 11 | this.bucketname = bucketname; 12 | this.db = db; 13 | this.q = q; 14 | this.dbUtils = require('../helpers')(db, q); 15 | } 16 | 17 | // Get the last blocks 18 | async GetBlocks(condition, howmuch, offset) { 19 | howmuch = parseInt(howmuch || 25); 20 | offset = parseInt(offset || 0); 21 | let where = ''; 22 | if (condition) { 23 | const filters = []; 24 | if (condition.id) { 25 | filters.push('id > $id'); 26 | } 27 | if (condition.generatedTime) { 28 | filters.push('generatedTime > $generatedTime'); 29 | condition.generatedTime = Number(condition.generatedTime); 30 | } 31 | if (filters.length) { 32 | where = `WHERE ${filters.join(' AND ')}`; 33 | } 34 | } 35 | const query = `SELECT * FROM ${this.bucketname} ${where} LIMIT ${howmuch} OFFSET ${offset}`; 36 | const rows = await this.dbUtils.query(query, condition); 37 | return rows && rows.map(r => r[this.bucketname]); 38 | } 39 | 40 | // Add a new block 41 | async AddBlock(newblock) { 42 | const id = this.dbUtils.metaIdFromHash('ledger', newblock.id); 43 | return await this.dbUtils.insert(id, newblock); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /lib/database/redis/db.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const bluebird = require('bluebird'); 5 | const redis = require("redis"); 6 | const PeersModel = require('./peers'); 7 | 8 | const redisClient = redis.createClient({host: '172.25.255.30'}); 9 | 10 | redisClient.on("error", function(err) { 11 | console.error(err); 12 | return err; 13 | }); 14 | 15 | bluebird.promisifyAll(Object.getPrototypeOf(redisClient)); 16 | 17 | // Models 18 | const Peers = new PeersModel(redisClient); 19 | 20 | module.exports = { 21 | Peers 22 | }; 23 | -------------------------------------------------------------------------------- /lib/database/redis/peers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Peers model 4 | */ 5 | // Requirements 6 | const moment = require('moment'); 7 | 8 | 9 | // Model for peers managements 10 | module.exports = class { 11 | 12 | constructor(db) { 13 | this.db = db; 14 | } 15 | 16 | async Get(id) { 17 | const res = await this.db.getAsync(`peer:${id}`); 18 | return JSON.parse(res); 19 | } 20 | 21 | GetPending() { 22 | return; 23 | } 24 | 25 | async Add(id, data, verified = false) { 26 | data.verified = Boolean(verified); 27 | const timestamp = moment().utc().valueOf(); 28 | data.created_at = data.created_at || timestamp; 29 | data.updated_at = timestamp; 30 | const peerData = JSON.stringify(data); 31 | await this.db.set(`peer:${id}`, peerData); 32 | return data; 33 | } 34 | 35 | Remove(condition) { 36 | return; 37 | } 38 | 39 | GetAll() { 40 | return; 41 | } 42 | 43 | async MarkAsVerified(id) { 44 | const peer = await this.Get(id); 45 | return await this.Add(id, peer, true); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /lib/database/redis/users.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Users model 4 | */ 5 | // Requirements 6 | const moment = require('moment'); 7 | 8 | 9 | // Model for users managements 10 | module.exports = class { 11 | 12 | constructor(db) { 13 | this.db = db; 14 | } 15 | 16 | async Get(id) { 17 | const res = await this.db.getAsync(`user:${id}`); 18 | return JSON.parse(res); 19 | } 20 | 21 | async Add(id, data, verified = false) { 22 | data.verified = Boolean(verified); 23 | const timestamp = moment().utc().valueOf(); 24 | data.created_at = data.created_at || timestamp; 25 | data.updated_at = timestamp; 26 | const userData = JSON.stringify(data); 27 | await this.db.set(`user:${id}`, userData); 28 | return data; 29 | } 30 | 31 | Remove(condition) { 32 | return; 33 | } 34 | 35 | async MarkAsVerified(id) { 36 | const user = await this.Get(id); 37 | return await this.Add(id, user, true); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /lib/docs/README.md: -------------------------------------------------------------------------------- 1 | 2 | This folder contains the sources to build the github page of the project. 3 | -------------------------------------------------------------------------------- /lib/docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chainode-docs", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "davidemiceli", 6 | "license": "AGPL-3.0", 7 | "maintainers": [ 8 | "davidemiceli" 9 | ], 10 | "scripts": { 11 | "start": "PORT=8000 node server.js", 12 | "build-dev": "webpack --mode=development --debug --progress --colors", 13 | "build-prod": "webpack --mode=production --debug --progress --colors" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/davidemiceli/chainode" 18 | }, 19 | "keywords": [], 20 | "bugs": { 21 | "url": "https://github.com/davidemiceli/chainode/issues" 22 | }, 23 | "homepage": "https://github.com/davidemiceli/chainode#readme", 24 | "dependencies": { 25 | "@fortawesome/fontawesome-free": "^5.6.3", 26 | "axios": "^0.18.0", 27 | "bootstrap": "^4.1.3", 28 | "jquery": "^3.3.1", 29 | "moment": "^2.22.2", 30 | "popper.js": "^1.14.6", 31 | "toastr": "^2.1.4", 32 | "vue": "^2.5.17", 33 | "vue-currency-filter": "^3.2.0", 34 | "vue-router": "^3.0.2", 35 | "vuex": "^3.0.1" 36 | }, 37 | "devDependencies": { 38 | "@babel/core": "^7.2.0", 39 | "@babel/preset-env": "^7.2.0", 40 | "babel-loader": "^8.0.4", 41 | "babel-polyfill": "^6.26.0", 42 | "body-parser": "^1.18.3", 43 | "clean-webpack-plugin": "^1.0.0", 44 | "copy-webpack-plugin": "^4.6.0", 45 | "css-loader": "^1.0.1", 46 | "express": "^4.16.4", 47 | "file-loader": "^2.0.0", 48 | "html-webpack-plugin": "^3.2.0", 49 | "mini-css-extract-plugin": "^0.5.0", 50 | "morgan": "^1.9.1", 51 | "node-sass": "^4.11.0", 52 | "sass-loader": "^7.1.0", 53 | "style-loader": "^0.23.1", 54 | "uglifyjs-webpack-plugin": "^2.0.1", 55 | "vue-loader": "^15.4.2", 56 | "vue-template-compiler": "^2.5.17", 57 | "webpack": "^4.27.1", 58 | "webpack-cli": "^3.1.2" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/docs/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Test server 4 | */ 5 | 6 | // Requirements 7 | const express = require('express'); 8 | const logger = require('morgan'); 9 | const bodyParser = require('body-parser'); 10 | 11 | // Parameters 12 | const PORT = process.env.PORT || 80; 13 | 14 | // Init express app 15 | const app = express(); 16 | 17 | // App settings and plugins 18 | app.use(logger('dev', {skip: ((req, res) => false)})); 19 | app.use(bodyParser.json()); 20 | app.use(bodyParser.urlencoded({ extended: false })); 21 | 22 | // Static files 23 | app.use('/', express.static('../../docs')); 24 | 25 | // Inject root directory 26 | app.use(function(req, res, next) { 27 | req.rootdirectory = String(__dirname); 28 | return next(); 29 | }); 30 | 31 | // Pages and redirect 32 | app.get('/*', (req, res) => res.sendFile('../../docs/index.html', {root: req.rootdirectory})); 33 | 34 | // Start server 35 | app.listen(PORT, () => console.log(`Server listening on port ${PORT}`)); 36 | -------------------------------------------------------------------------------- /lib/docs/src/components/404.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | -------------------------------------------------------------------------------- /lib/docs/src/components/App.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 24 | -------------------------------------------------------------------------------- /lib/docs/src/components/Home.vue: -------------------------------------------------------------------------------- 1 | 112 | 113 | 124 | -------------------------------------------------------------------------------- /lib/docs/src/components/commons/footer/index.vue: -------------------------------------------------------------------------------- 1 | 11 | 12 | 33 | -------------------------------------------------------------------------------- /lib/docs/src/components/commons/navbar/index.vue: -------------------------------------------------------------------------------- 1 | 33 | 34 | 56 | -------------------------------------------------------------------------------- /lib/docs/src/configs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // App configuration settings 5 | const Configs = { 6 | baseurl: BASE_URL, 7 | alerts: { 8 | successAdded: 'Data added with success!', 9 | deleted: 'Deleted data with success!', 10 | error: 'Sorry, there was an error: contact the administrator...', 11 | } 12 | }; 13 | 14 | export default Configs; 15 | -------------------------------------------------------------------------------- /lib/docs/src/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/lib/docs/src/img/favicon.ico -------------------------------------------------------------------------------- /lib/docs/src/img/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/lib/docs/src/img/image.png -------------------------------------------------------------------------------- /lib/docs/src/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/lib/docs/src/img/logo.png -------------------------------------------------------------------------------- /lib/docs/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Chainode | Private Blockchain Network 11 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /lib/docs/src/lib/filters.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import Vue from 'vue'; 5 | import VueCurrencyFilter from 'vue-currency-filter'; 6 | 7 | 8 | // Format currency 9 | Vue.use(VueCurrencyFilter, { 10 | symbol: '', 11 | thousandsSeparator: '.', 12 | fractionCount: 2, 13 | fractionSeparator: ',', 14 | symbolPosition: 'front', 15 | symbolSpacing: false 16 | }); 17 | 18 | // Format a datetime 19 | Vue.filter('dateMedium', function(datetime, format) { 20 | // return moment(datetime).format(format || 'YYYY-MM-DD hh:mm:ss'); 21 | return moment(datetime).format(format || 'LLL'); 22 | }); 23 | 24 | // Shortify a string if is longer than a defined length 25 | Vue.filter('readMore', function(text, length, suffix) { 26 | suffix = (text.length <= length) ? '' : (suffix || '…'); 27 | return text.substring(0, length) + suffix; 28 | }); 29 | 30 | export {} 31 | -------------------------------------------------------------------------------- /lib/docs/src/lib/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Utilities 4 | class Utils { 5 | 6 | constructor() { } 7 | 8 | // Example 9 | example() { 10 | return; 11 | } 12 | 13 | }; 14 | 15 | export default new Utils(); 16 | -------------------------------------------------------------------------------- /lib/docs/src/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Main application entrypoint 4 | */ 5 | 6 | // CSS styles 7 | import '@/src/styles.js'; 8 | 9 | // Javascript libraries 10 | import 'bootstrap'; 11 | import '@fortawesome/fontawesome-free'; 12 | 13 | // Vue requirements 14 | import Vue from 'vue'; 15 | import App from '@/src/components/App'; 16 | import router from '@/src/router'; 17 | import filters from '@/src/lib/filters'; 18 | 19 | // Turn off the production tip on the console 20 | Vue.config.productionTip = false; 21 | 22 | // App 23 | new Vue({ 24 | el: '#app', 25 | router, 26 | components: { App }, 27 | template: '' 28 | }); 29 | -------------------------------------------------------------------------------- /lib/docs/src/router/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import Vue from 'vue'; 5 | import VueRouter from 'vue-router'; 6 | 7 | // Routes 8 | import { Routes } from '@/src/router/routes'; 9 | 10 | // Routes 11 | import Home from '@/src/components/Home'; 12 | import NotFound from '@/src/components/404'; 13 | 14 | Vue.use(VueRouter); 15 | 16 | const routes = [ 17 | { path: Routes.HOME.path, name: Routes.HOME.name, component: Home}, 18 | { path: Routes.NOTFOUND.path, component: NotFound }, 19 | { path: '*', redirect: Routes.NOTFOUND.path } 20 | ]; 21 | 22 | export default new VueRouter({ 23 | mode: 'hash', // https://router.vuejs.org/api/#mode 24 | routes: routes 25 | }); 26 | -------------------------------------------------------------------------------- /lib/docs/src/router/routes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // Routes 5 | export const Routes = { 6 | // Dashboard 7 | HOME: {path: '/', name: 'home'}, 8 | // Not Found: 404 error 9 | NOTFOUND: {path: '/404', name: 'notfound'} 10 | }; 11 | -------------------------------------------------------------------------------- /lib/docs/src/scss/_custom.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Custom generic styles 3 | */ 4 | 5 | @import url('https://fonts.googleapis.com/css?family=Roboto'); 6 | @import url('https://fonts.googleapis.com/icon?family=Material+Icons'); 7 | 8 | /* For Vue.js to hide brackets on startup of page */ 9 | [v-cloak], .v-cloak { 10 | display: none !important; 11 | } 12 | 13 | /* To fix the text align with material google icons */ 14 | .material-icons { 15 | vertical-align: middle; 16 | } 17 | 18 | html, body { 19 | background-color: #FFF; 20 | } 21 | 22 | a { 23 | color: #bfbfbf; 24 | } 25 | a:focus, a:hover { 26 | color: rgb(115, 115, 115); 27 | text-decoration: none; 28 | } 29 | 30 | .form-control { 31 | border-radius: 0px; 32 | } 33 | .btn { 34 | border-radius: 0px; 35 | } 36 | textarea { 37 | resize: none; 38 | } 39 | .form-control:focus { 40 | color: #495057; 41 | background-color: #fff; 42 | border-color: #cecece; 43 | outline: 0; 44 | box-shadow: 0 0 0 0.2rem rgba(204, 204, 204, 0.25); 45 | } 46 | 47 | .progress { 48 | height: 10px; 49 | } 50 | 51 | .box-section { 52 | padding: 35px; 53 | background-color: #fff; 54 | border-radius: 2px; 55 | transition: all 0.3s ease-in-out; 56 | box-shadow: 0px 10px 50px 0px rgba(84,110,122,0.15); 57 | } 58 | -------------------------------------------------------------------------------- /lib/docs/src/scss/_dashboard.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Dashboard 3 | */ 4 | 5 | /* Menù */ 6 | 7 | .menu-on-sidebar { 8 | margin: 0 !important; 9 | padding: 10px; 10 | position: fixed; 11 | background: #fff; 12 | height: calc(100% - 50px); 13 | width: 500px; 14 | top: 50px; 15 | left: 0px; 16 | overflow-y: auto; 17 | transition: all; 18 | transition-duration: .0s; 19 | z-index: 10; 20 | box-shadow: 0 0 3px rgba(14,18,21,.38); 21 | } 22 | .section-menu { 23 | position: fixed; 24 | background-color: #fff; 25 | width: calc(100% - 70px); 26 | transition: all; 27 | transition-duration: .0s; 28 | transition-duration: .0s; 29 | z-index: 2000; 30 | } 31 | .dashboard-on-loading { 32 | position: fixed; 33 | background: rgba(255,255,255,0.5); 34 | height: 100%; 35 | min-width: 100%; 36 | /* top: 70px; */ 37 | transition: all; 38 | transition-duration: .0s; 39 | z-index: 5000; 40 | overflow-y: hidden; 41 | box-shadow: 0 0 3px rgba(14,18,21,.38); 42 | } 43 | .numbers-chart { 44 | font-family: "Roboto"; 45 | font-size: 13px; 46 | line-height: 1.42857143; 47 | color: #5E5E5E; 48 | background-color: #f3f3f3; 49 | } -------------------------------------------------------------------------------- /lib/docs/src/scss/_footer.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Footer 3 | */ 4 | 5 | .footer { 6 | bottom: 0; 7 | margin-top: 30px; 8 | width: 100%; 9 | min-height: 60px; 10 | line-height: 60px; 11 | } 12 | -------------------------------------------------------------------------------- /lib/docs/src/scss/_helpers.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Helpers classes for styles 3 | 4 | Dynamic function to create helper classes of margin: 5 | Example: .m-t-5 => margin-top: 5px; 6 | */ 7 | 8 | @mixin mp-i-x { 9 | @for $i from 0 through 100 { 10 | /* margin */ 11 | .m-t-#{$i} { margin-top: #{$i}px; } 12 | .m-b-#{$i} { margin-bottom: #{$i}px; } 13 | .m-l-#{$i} { margin-left: #{$i}px; } 14 | .m-r-#{$i} { margin-right: #{$i}px; } 15 | /* padding */ 16 | .p-t-#{$i} { padding-top: #{$i}px; } 17 | .p-b-#{$i} { padding-bottom: #{$i}px; } 18 | .p-l-#{$i} { padding-left: #{$i}px; } 19 | .p-r-#{$i} { padding-right: #{$i}px; } 20 | } 21 | } 22 | 23 | @mixin m-lr-x { 24 | @for $i from 0 through 100 { 25 | .m-lr-#{$i} { 26 | margin-left: #{$i}px; 27 | margin-right: #{$i}px; 28 | } 29 | } 30 | } 31 | 32 | @mixin f-x { 33 | @for $i from 7 through 70 { 34 | .f-#{$i} { font-size: #{$i}px; } 35 | } 36 | } 37 | 38 | @include f-x; 39 | @include mp-i-x; 40 | @include m-lr-x; 41 | -------------------------------------------------------------------------------- /lib/docs/src/scss/_typography.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Typography 3 | */ 4 | 5 | @import url('https://fonts.googleapis.com/css?family=Staatliches'); 6 | @import url('https://fonts.googleapis.com/css?family=Inconsolata:400,700&subset=latin-ext'); 7 | 8 | .brand-title-name { 9 | font-family: 'Staatliches', sans-serif; 10 | font-weight: 400; 11 | color: #EFBB00; 12 | } 13 | 14 | .title { 15 | line-height: 1.33; 16 | font-weight: 300; 17 | letter-spacing: -.5px; 18 | } 19 | 20 | .sentences { 21 | font-weight: 300; 22 | font-size: 20px; 23 | line-height: 1.6; 24 | } 25 | 26 | .small-title { 27 | font-weight: 500; 28 | } 29 | 30 | .top-title { 31 | font-size: 50px; 32 | color: #111; 33 | } 34 | 35 | .highlighted-link { 36 | color: #286090; 37 | font-weight: 500; 38 | } 39 | 40 | .table { 41 | font-size: 14px; 42 | } 43 | 44 | .coding { 45 | font-family: 'Inconsolata', monospace; 46 | } -------------------------------------------------------------------------------- /lib/docs/src/scss/_variables.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Variables 3 | */ 4 | 5 | /* colors */ 6 | $gray-color: rgb(113, 113, 113); 7 | $light-gray-color: rgb(238, 238, 238); 8 | -------------------------------------------------------------------------------- /lib/docs/src/scss/app.scss: -------------------------------------------------------------------------------- 1 | /* 2 | App custom styles 3 | */ 4 | 5 | @import "variables"; 6 | @import "custom"; 7 | @import "helpers"; 8 | @import "typography"; 9 | @import "footer"; 10 | @import "dashboard"; 11 | @import "navbar/navbar"; 12 | @import "navbar/colors"; 13 | @import "themes/clean"; 14 | @import "../../node_modules/@fortawesome/fontawesome-free/scss/fontawesome.scss" 15 | -------------------------------------------------------------------------------- /lib/docs/src/scss/navbar/_colors.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Navbar custom colors 3 | */ 4 | 5 | /* Blue */ 6 | .bg-dark-blue { 7 | background-color: #286090 !important; 8 | border-color: #286090; 9 | } 10 | .navbar-dark .navbar-nav .nav-link { 11 | color: rgba(255, 255, 255, 1); 12 | } 13 | .navbar-dark .navbar-nav .nav-link:hover, 14 | .navbar-dark .navbar-nav .nav-link:focus { 15 | color: rgba(255, 255, 255, 0.9); 16 | } 17 | 18 | /* White */ 19 | .bg-light-white { 20 | background-color: #ffffff !important; 21 | border: 0; 22 | border-bottom: 1px solid #ddd; 23 | } 24 | -------------------------------------------------------------------------------- /lib/docs/src/scss/navbar/_navbar.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Navbar styles 3 | */ 4 | 5 | .dropdown-header { 6 | font-size: 0.7rem; 7 | } 8 | 9 | .dropdown-item { 10 | color: #666; 11 | font-size: 0.7rem; 12 | } 13 | -------------------------------------------------------------------------------- /lib/docs/src/scss/themes/_clean.scss: -------------------------------------------------------------------------------- 1 | /* 2 | A very clean style 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Rubik:300,300i,400,400i,500,500i,700,700i&subset=latin-ext'); 5 | 6 | $text-font-rubik: "Rubik"; 7 | 8 | html, body, textarea, input, select { 9 | font-family: $text-font-rubik; 10 | } 11 | 12 | /* For dashboard */ 13 | .navbar-nav { 14 | text-transform: uppercase; 15 | font-size: 12px; 16 | font-weight: 500; 17 | letter-spacing: 0.6px; 18 | } 19 | -------------------------------------------------------------------------------- /lib/docs/src/scss/themes/_enjoyable.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For less impegnative websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Work+Sans:300,500'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Work Sans"; 8 | } 9 | 10 | /* For a dashboard */ 11 | .navbar-nav { 12 | font-size: 12px; 13 | font-weight: 500; 14 | letter-spacing: 0.6px; 15 | } 16 | -------------------------------------------------------------------------------- /lib/docs/src/scss/themes/_nerd.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For nerd styled websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Ubuntu+Mono'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Ubuntu Mono" 8 | } 9 | -------------------------------------------------------------------------------- /lib/docs/src/scss/themes/_serious.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For a bit impegnative websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i&subset=latin-ext'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Roboto Condensed"; 8 | } 9 | 10 | /* For a dashboard */ 11 | .navbar-nav { 12 | text-transform: uppercase; 13 | font-size: 12px; 14 | font-weight: 600; 15 | letter-spacing: 0.6px; 16 | } 17 | 18 | /* For landing paragraphs */ 19 | .title { 20 | line-height: 1.33; 21 | font-weight: 300; 22 | letter-spacing: -.5px; 23 | } 24 | 25 | .sentences { 26 | font-weight: 300; 27 | font-size: 20px; 28 | line-height: 1.6; 29 | } 30 | -------------------------------------------------------------------------------- /lib/docs/src/store/actions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Store 4 | import Store from '@/src/store/store'; 5 | 6 | // Actions 7 | class Actions { 8 | 9 | constructor() { } 10 | 11 | // Loading actions 12 | LOADING_START() { 13 | Store.uxui.loading = true; 14 | } 15 | LOADING_STOP() { 16 | Store.uxui.loading = false; 17 | } 18 | 19 | // Navbar actions 20 | NAVBAR_SHOW() { 21 | Store.uxui.navbar = true; 22 | } 23 | NAVBAR_HIDE() { 24 | Store.uxui.navbar = false; 25 | } 26 | 27 | // Footer actions 28 | FOOTER_SHOW() { 29 | Store.uxui.footer = true; 30 | } 31 | FOOTER_HIDE() { 32 | Store.uxui.footer = false; 33 | } 34 | 35 | // Block actions 36 | BLOCKS_SET(items) { 37 | Store.blocks = items; 38 | } 39 | 40 | }; 41 | 42 | export default new Actions(); 43 | -------------------------------------------------------------------------------- /lib/docs/src/store/store.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Shared stores 4 | const Store = { 5 | uxui: { 6 | loading: false, 7 | navbar: true, 8 | footer: true 9 | } 10 | }; 11 | 12 | export default Store; 13 | -------------------------------------------------------------------------------- /lib/docs/src/styles.js: -------------------------------------------------------------------------------- 1 | /* 2 | Application styles 3 | */ 4 | 5 | // Default styles 6 | import '@/node_modules/bootstrap/dist/css/bootstrap.css'; 7 | // import '@/node_modules/@fortawesome/fontawesome-free/css/all.css'; 8 | import '@/node_modules/toastr/build/toastr.css'; 9 | 10 | // Custom styles 11 | import '@/src/scss/app.scss'; 12 | -------------------------------------------------------------------------------- /lib/docs/webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack configurations 4 | */ 5 | 6 | // Requirements 7 | const path = require('path'); 8 | const webpack = require('webpack'); 9 | const mainConfigs = require('./webpack/configs'); 10 | 11 | // Entrypoint and bundle path 12 | const entryPoint = './src/main.js'; 13 | const rootPath = path.resolve(__dirname, './'); 14 | const outputPath = path.resolve(rootPath, '../../docs'); 15 | 16 | 17 | module.exports = (env, argv) => { 18 | 19 | const baseUrl = (argv.mode === 'production') ? 'https://davidemiceli.github.io/chainode/' : ''; 20 | 21 | // Define webpack general configs 22 | const configs = mainConfigs(baseUrl, entryPoint, rootPath, outputPath); 23 | 24 | // When compiling for production we want the app to be uglified. 25 | if (argv.mode === 'production') { 26 | 27 | // We also add it as a global, the Vue lib needs it to determine if Dev tool should be active or not. 28 | const DefinePlugin = new webpack.DefinePlugin({ 29 | 'process.env': {NODE_ENV: '"production"'} 30 | }); 31 | // Add production plugins 32 | configs.plugins.push(DefinePlugin); 33 | 34 | } else if (argv.mode === 'development') { 35 | 36 | // Disable minification 37 | configs.optimization.minimize = false; 38 | 39 | } else { 40 | throw Error('Invalid mode parameter. Must be production or development.'); 41 | } 42 | 43 | return configs; 44 | }; -------------------------------------------------------------------------------- /lib/docs/webpack/configs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack main configurations 4 | */ 5 | 6 | // Requirements 7 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 9 | 10 | 11 | // Main webpack config 12 | module.exports = (baseUrl, entryPoint, rootPath, outputPath) => ({ 13 | entry: { 14 | "app": ['babel-polyfill', entryPoint] 15 | }, 16 | output: { 17 | path: outputPath, 18 | filename: 'js/[name].js', 19 | chunkFilename: 'js/[name].[chunkhash].bundle.js' 20 | }, 21 | module: { 22 | rules: [ 23 | { 24 | test: /\.(sa|sc|c)ss$/, 25 | use: [ 26 | {loader: MiniCssExtractPlugin.loader, options: {minimize: true}}, 27 | 'css-loader', 28 | 'sass-loader' 29 | ] 30 | }, 31 | { 32 | test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/, 33 | use: [{ 34 | loader: 'file-loader', 35 | options: { 36 | name: '[path][name].[ext]', 37 | publicPath: baseUrl, 38 | useRelativePath: true, 39 | outputPath: '/' 40 | } 41 | }] 42 | }, 43 | { 44 | test: /\.vue$/, 45 | loader: 'vue-loader', 46 | options: require('./configs/vueLoaderConfig') 47 | }, 48 | { 49 | test: /\.js$/, 50 | loader: 'babel-loader', 51 | query: { 52 | presets: ['@babel/preset-env'] // Transpile the ES6 to es2015 standard 53 | } 54 | } 55 | ] 56 | }, 57 | resolve: { 58 | extensions: ['.js', '.vue', '.json'], 59 | alias: { 60 | 'vue$': 'vue/dist/vue.esm.js', // Resolving the vue var for standalone build 61 | '@': rootPath, 62 | 'jQuery': 'jquery/dist/jquery.min.js' 63 | } 64 | }, 65 | plugins: require('./plugins')(baseUrl, rootPath, outputPath), // set the defined plugins 66 | optimization: { 67 | minimize: true, 68 | minimizer: [ 69 | new UglifyJsPlugin({ 70 | include: /\.min\.js$/, 71 | parallel: true, 72 | sourceMap: true 73 | }) 74 | ], 75 | splitChunks: { 76 | // minSize: 10000, 77 | // maxSize: 300000, 78 | minChunks: 1, 79 | name: true, 80 | cacheGroups: { 81 | vendors: { 82 | test: /node_modules/, 83 | chunks: 'initial', 84 | name: 'vendors', 85 | minChunks: 1, 86 | enforce: true 87 | } 88 | } 89 | } 90 | } 91 | }); 92 | -------------------------------------------------------------------------------- /lib/docs/webpack/configs/vueLoaderConfig.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack VueJs configurations 4 | */ 5 | 6 | 7 | module.exports = { 8 | loaders: {}, 9 | cssSourceMap: false, 10 | cacheBusting: true, 11 | transformToRequire: { 12 | video: ['frontend', 'poster'], 13 | source: 'frontend', 14 | img: 'frontend', 15 | image: 'xlink:href' 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /lib/docs/webpack/externalFiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack files to exports for copy files plugin 4 | */ 5 | 6 | // Helpers 7 | const {move_to} = require('./helpers'); 8 | 9 | 10 | // Configurations to copy external files 11 | module.exports = (outputPath) => { 12 | // External img files 13 | const imgExtFiles = move_to(`${outputPath}/img/`, [ 14 | 'src/img/logo.png', 15 | 'src/img/image.png' 16 | ]); 17 | // Favicon 18 | const icoExtFiles = move_to(`${outputPath}/`, ['src/img/favicon.ico']); 19 | // Return concatenated in an unique array 20 | return [ 21 | ...imgExtFiles, 22 | ...icoExtFiles 23 | ]; 24 | } -------------------------------------------------------------------------------- /lib/docs/webpack/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack helpers 4 | */ 5 | 6 | // Move source files as is to another directory 7 | const move_to = (outputPath, files, force=true) => files.map(f => ({from: f, to: outputPath, force: force})); 8 | 9 | module.exports = { 10 | move_to 11 | }; 12 | -------------------------------------------------------------------------------- /lib/docs/webpack/plugins.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack plugins 4 | */ 5 | 6 | // Requirements 7 | const webpack = require('webpack'); 8 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 9 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 10 | const VueLoaderPlugin = require('vue-loader/lib/plugin'); 11 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 12 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 13 | 14 | 15 | // External files for copy plugin 16 | const externalFiles = require('./externalFiles'); 17 | 18 | 19 | // Webpack plugins 20 | module.exports = (baseUrl, rootPath, outputPath) => { 21 | 22 | // Webpack plugins 23 | return [ 24 | // This plugin will be removed in the future as it only exists for migration 25 | new webpack.LoaderOptionsPlugin({ 26 | debug: true 27 | }), 28 | new CleanWebpackPlugin(['docs'], { 29 | root: '/app', // rootPath, 30 | exclude: [], // file to exclude 31 | verbose: true, 32 | dry: false 33 | }), 34 | // Add npm packages to bundle 35 | new webpack.ProvidePlugin({ 36 | $: 'jquery', 37 | jQuery: 'jquery', 38 | 'window.$': 'jquery', 39 | 'window.jQuery': 'jquery', 40 | Popper: ['popper.js', 'default'], 41 | moment: 'moment', 42 | toastr: 'toastr' 43 | }), 44 | // Copy files as is to another directory 45 | new CopyWebpackPlugin( 46 | externalFiles(outputPath) 47 | ), 48 | new VueLoaderPlugin(), 49 | // Extract css to make a separated bundle file 50 | new MiniCssExtractPlugin({ 51 | filename: 'css/[name].[hash].css', 52 | chunkFilename: 'css/[id].[hash].css' 53 | }), 54 | // Inject the js and css files 55 | new HtmlWebpackPlugin({ 56 | inject: true, 57 | template: `${rootPath}/src/index.html`, 58 | filename: 'index.html', 59 | baseUrl: baseUrl || '/' 60 | }) 61 | ]; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /lib/errors.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // Handle errors 5 | module.exports = (logger, err) => { 6 | if (logger) { 7 | logger.error(err.stack); 8 | } else { 9 | console.error(err.stack); 10 | } 11 | throw err; 12 | } 13 | -------------------------------------------------------------------------------- /lib/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Helpers functions 4 | */ 5 | const moment = require('moment'); 6 | 7 | 8 | // Get UTC timestamp 9 | const utcTimestamp = () => moment().utc().valueOf(); 10 | 11 | // Get UTC timestamp 12 | const utcISOstring = () => moment().utc().toISOString(); 13 | 14 | 15 | module.exports = { 16 | utcTimestamp, 17 | utcISOstring 18 | }; -------------------------------------------------------------------------------- /lib/kafka/filterTopicsByRole.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Consumer topics by peer role 4 | */ 5 | 6 | 7 | // Return topic by role 8 | module.exports = (role, topics) => { 9 | switch(role) { 10 | case 'peer': 11 | return [topics.pending]; 12 | default: 13 | throw Error('Invalid peer role to select kafka topic.'); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /lib/kafka/initKafka.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Initialize kafka consumer and producer 4 | */ 5 | 6 | // Requirements 7 | const kafka = require('kafka-node'); 8 | const filterTopicsByRole = require('./filterTopicsByRole'); 9 | const { 10 | getTopicMetadata, 11 | KafkaClientIsReady, 12 | fetchTopicPartitions 13 | } = require('./kafkaHelpers'); 14 | 15 | 16 | module.exports = async sdk => { 17 | try { 18 | // Get used configs 19 | const { role } = sdk.configs; 20 | const kafkaConfigs = sdk.configs.kafka; 21 | // Compose topics 22 | const topicList = filterTopicsByRole(role, kafkaConfigs.topics); 23 | sdk.logger.info(`Kafka topics to consume are ${topicList.join(', ')}.`); 24 | // Init kafka client 25 | const kafkaBrokers = kafkaConfigs.hosts.join(','); 26 | const KafkaClient = new kafka.KafkaClient({kafkaHost: kafkaBrokers}); 27 | // Wait until kafka client is ready 28 | await KafkaClientIsReady(KafkaClient); 29 | sdk.logger.info('Kafka client is ready.'); 30 | // Get metadata of topics 31 | const metadataTopics = await getTopicMetadata(KafkaClient, topicList); 32 | sdk.logger.info('Get metadata of the kafka topics.'); 33 | const topics = fetchTopicPartitions(sdk.logger, metadataTopics); 34 | // Init kafka consumer 35 | const consumer = new kafka.Consumer(KafkaClient, topics, kafkaConfigs.consumer); 36 | // Consumer events 37 | consumer 38 | .on('message', async message => { 39 | sdk.logger.debug('Received message', message); 40 | try { 41 | return await sdk.onMessage(message.topic, message.value); 42 | } catch(err) { 43 | sdk.logger.error(err.stack); 44 | } 45 | }) 46 | .on('error', err => { 47 | sdk.logger.error((err && err.stack) || err); 48 | if (err.name === 'TopicsNotExistError') { 49 | throw Error(err); 50 | } 51 | }); 52 | sdk.logger.info(`Started consumer for kafka topics ${topicList.join(', ')}.`); 53 | // Init kafka producer 54 | const producer = new kafka.Producer(KafkaClient, kafkaConfigs.producer); 55 | return {consumer, producer}; 56 | } catch(err) { 57 | throw err; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /lib/kafka/kafkaHelpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Helpers for kafka consumer and producer 4 | */ 5 | 6 | 7 | // Get topic metadata 8 | const getTopicMetadata = (KafkaClient, listTopics) => { 9 | return new Promise((resolve, reject) => { 10 | return KafkaClient.loadMetadataForTopics(listTopics, function(error, infoTopics) { 11 | if (error) return reject(error); 12 | return resolve(infoTopics); 13 | // console.log('%j', _.get(results, '1.metadata')); 14 | }); 15 | }); 16 | } 17 | 18 | // Check if kafka client is ready 19 | const KafkaClientIsReady = KafkaClient => { 20 | return new Promise((resolve, reject) => { 21 | try { 22 | return KafkaClient.on('ready', () => resolve(true)); 23 | } catch(err) { 24 | return reject(err); 25 | } 26 | }); 27 | } 28 | 29 | // Get number of partition 30 | const fetchTopicPartitions = (logger, topicMetadata) => { 31 | const tList = topicMetadata[1].metadata; 32 | const topics = []; 33 | for (let [k, value] of Object.entries(tList)) { 34 | const topicPartitions = Object 35 | .keys(value) 36 | .map(p => parseInt(p)) 37 | .map(p => ({topic: k, partition: p})); 38 | logger.info(`Topic ${k} seems to have ${topicPartitions.length} partitions.`); 39 | topics.push(...topicPartitions); 40 | } 41 | return topics; 42 | } 43 | 44 | module.exports = { 45 | getTopicMetadata, 46 | KafkaClientIsReady, 47 | fetchTopicPartitions 48 | }; 49 | -------------------------------------------------------------------------------- /lib/logger.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const moment = require('moment'); 5 | const winston = require('winston'); 6 | require('winston-daily-rotate-file'); 7 | const { format } = winston; 8 | const { utcISOstring } = require('./helpers'); 9 | 10 | 11 | module.exports = (role, id, level, logPath, silentConsole) => { 12 | // Log format 13 | const logFormat = format.printf(info => { 14 | return [ 15 | utcISOstring(), 16 | info.level.toUpperCase(), 17 | role, 18 | id, 19 | info.message 20 | ].join('|'); 21 | }); 22 | 23 | // File log rotation parameters 24 | const transportFileParams = (fileHeader) => ({ 25 | filename: `${fileHeader}-%DATE%.log`, 26 | dirname: logPath, // default =>'.', 27 | datePattern: 'YYYY-MM-DD-HH', 28 | maxSize: '20m', 29 | maxFiles: '15d' 30 | }); 31 | 32 | // Set up logger 33 | const logger = winston.createLogger({ 34 | level: level, 35 | format: format.combine(logFormat), 36 | transports: [ 37 | new winston.transports.DailyRotateFile( 38 | transportFileParams('chainode') 39 | ), 40 | new winston.transports.Console({ 41 | silent: silentConsole 42 | }) 43 | ] 44 | }); 45 | 46 | // Extend logger object to properly log additional arguments 47 | const origLog = logger.log; 48 | logger.log = function (level, ...args) { 49 | const parsedArgs = args.map(i => typeof(i) === 'object' ? JSON.stringify(i) : i).join(' '); 50 | origLog.apply(logger, [level, parsedArgs]); 51 | } 52 | 53 | return logger; 54 | } 55 | -------------------------------------------------------------------------------- /lib/rsa.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const path = require('path'); 5 | const fs = require('fs'); 6 | const NodeRSA = require('node-rsa'); 7 | const crypto = require('crypto'); 8 | 9 | const rsa = {}; 10 | 11 | // Open and closed keys generation method 12 | rsa.generate_keys = function() { 13 | const key = new NodeRSA(); 14 | // 2048 — key length, 65537 open exponent 15 | key.generateKeyPair(2048, 65537); 16 | // create keys as pem line in pkcs8 17 | return { 18 | private: key.exportKey('pkcs8-private-pem'), 19 | public: key.exportKey('pkcs8-public-pem') 20 | } 21 | } 22 | 23 | // Encrypting RSA, using padding OAEP, with nodejs crypto: 24 | rsa.encrypt = function(public_key, message) { 25 | const enc = crypto.publicEncrypt({ 26 | key: public_key, 27 | padding: crypto.RSA_PKCS1_OAEP_PADDING 28 | }, Buffer.from(message)); 29 | return enc.toString('base64'); 30 | }; 31 | 32 | // Descrypting RSA, using padding OAEP, with nodejs crypto: 33 | rsa.decrypt = function(private_key, message) { 34 | const enc = crypto.privateDecrypt({ 35 | key: private_key, 36 | padding: crypto.RSA_PKCS1_OAEP_PADDING 37 | }, Buffer.from(message, 'base64')); 38 | return enc.toString(); 39 | // return enc.toString("utf8"); 40 | }; 41 | 42 | module.exports = rsa; 43 | -------------------------------------------------------------------------------- /lib/sdk.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Entrypoint for the SDK 4 | */ 5 | 6 | // Requirements 7 | const initKafka = require('./kafka/initKafka'); 8 | const logger = require('./logger'); 9 | const errors = require(`./errors`); 10 | const Db = require('./database/couchbase/db'); 11 | const backend = require('../web-console/backend/server'); 12 | const { 13 | isValidBlock, 14 | generateNextBlock 15 | } = require('./block'); 16 | 17 | 18 | // Blockchain sdk 19 | module.exports = class { 20 | 21 | // Init SDK 22 | constructor(configs) { 23 | this.configs = configs; 24 | const { role, id, logs } = this.configs; 25 | this.logger = logger(role, id, logs.level, logs.path, logs.console); 26 | } 27 | 28 | // Check the role 29 | hasRole(r) { 30 | const { role } = this.configs; 31 | return role === r; 32 | } 33 | 34 | // Shutdown the peer broker and the web console 35 | async shutdown() { 36 | await this.stopWebConsole() 37 | await this.stopConsumer(); 38 | this.logger.close(); 39 | return true; 40 | } 41 | 42 | // Start peer broker 43 | async start() { 44 | try { 45 | // Check params 46 | const {role, id, webconsole} = this.configs; 47 | this.logger.info(`Starting ${role} with id ${id}.`); 48 | 49 | // Get database model 50 | this.db = await Db(this.configs.db, this.logger); 51 | 52 | // Get kafka consumer and producer 53 | const {consumer, producer} = await initKafka(this); 54 | this.consumer = consumer; 55 | this.producer = producer; 56 | 57 | // Init web console 58 | if (webconsole.enabled) { 59 | await this.startWebConsole(); 60 | } 61 | this.logger.info(`The ${role} with id ${id} is ready.`); 62 | return this; 63 | } catch(err) { 64 | errors(this.logger, err); 65 | } 66 | } 67 | 68 | // Stop peer broker 69 | stopConsumer() { 70 | if (!this.consumer) return Promise.resolve(true); 71 | const c = this.consumer; 72 | return new Promise(function(resolve, reject) { 73 | return c.close(true, function(err, res) { 74 | return resolve(true); 75 | }); 76 | }); 77 | } 78 | 79 | // Start the Web Console 80 | async startWebConsole() { 81 | const {webconsole} = this.configs; 82 | this.webConsole = await backend(webconsole, this, this.logger, this.db); 83 | return this; 84 | } 85 | 86 | // Stop Web Console 87 | stopWebConsole() { 88 | if (!this.webConsole) return Promise.resolve(true); 89 | const w = this.webConsole; 90 | return new Promise(function(resolve, reject) { 91 | return w.close(function(err, res) { 92 | return resolve(true); 93 | }); 94 | }); 95 | } 96 | 97 | // Produce message to a kafka topic 98 | async __produce(topic, data) { 99 | try { 100 | // Serialize data 101 | const serialized = this.serialize(data); 102 | // Compose message 103 | const msg = {topic: topic, messages: serialized}; 104 | // Produce message 105 | const self = this; 106 | return this.producer.send([msg], function(err, res) { 107 | if (err) throw Error(err); 108 | self.logger.debug('Produced to', res); 109 | return self; 110 | }); 111 | } catch(err) { 112 | errors(this.logger, err); 113 | } 114 | } 115 | 116 | // Serialize data 117 | serialize(data) { 118 | return JSON.stringify(data); 119 | } 120 | 121 | // Deserialize data 122 | deserialize(data) { 123 | return JSON.parse(data); 124 | } 125 | 126 | // Check if data is serialized 127 | isSerialized(data) { 128 | return typeof data === 'string'; 129 | } 130 | 131 | // Select actions based on message and topic 132 | async onMessage(topic, data) { 133 | const { topics } = this.configs.kafka; 134 | const deserialized = this.deserialize(data); 135 | switch(topic) { 136 | case topics.pending: 137 | if (this.hasRole('peer')) { 138 | return await this.addBlockToLedger(deserialized); 139 | } 140 | return false; 141 | default: 142 | throw Error('Received message of an invalid topic'); 143 | } 144 | } 145 | 146 | // Propose a new block 147 | async sendNewBlock(data) { 148 | try { 149 | // Check if data is serialized 150 | if (!this.isSerialized(data)) throw Error('Data is not serialized.'); 151 | // Item data 152 | const { organization } = this.configs; 153 | // Generate block 154 | // const serializedData = this.serialize(data); 155 | const newblock = generateNextBlock(organization, data); 156 | this.logger.info(`Building a block for the transaction ${newblock.id} sended by organization ${organization}.`); 157 | this.logger.debug('Built new block', newblock); 158 | // Publish block 159 | const topic = this.configs.kafka.topics.pending; 160 | await this.__produce(topic, newblock); 161 | // Return the new block 162 | return newblock.id; 163 | } catch(err) { 164 | errors(this.logger, err); 165 | } 166 | } 167 | 168 | // Receive new blocks for adding to the ledger 169 | async addBlockToLedger(data) { 170 | try { 171 | // Get db model instance 172 | const db = this.db; 173 | // Check if block is valid 174 | const valid = isValidBlock(this.logger, data); 175 | if (!valid) { 176 | const invalidMsg = (data && data.id) ? `Skipping invalid block ${data.id}.` : 'Skipping an invalid block.'; 177 | this.logger.error(invalidMsg); 178 | return false; 179 | } 180 | this.logger.debug(`Received block ${data.id}.`); 181 | // Store block on db 182 | await db.Ledger.AddBlock(data); 183 | this.logger.info(`Added new block ${data.id}.`); 184 | this.logger.debug('Added new block', data); 185 | // Return the new block 186 | return data.id; 187 | } catch(err) { 188 | errors(this.logger, err); 189 | } 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Entrypoint to run a peer 4 | */ 5 | 6 | // Requirements 7 | const Chainode = require('./lib/sdk'); 8 | const errors = require('./lib/errors'); 9 | const loadConfigs = require('./lib/configs/loadConfigs'); 10 | 11 | 12 | // Run peer 13 | const main = async () => { 14 | let logger; 15 | try { 16 | // Load configurations 17 | const configs = loadConfigs(); 18 | // Init the peer 19 | const agent = new Chainode(configs); 20 | await agent.start(); 21 | logger = agent.logger; 22 | return true; 23 | } catch(err) { 24 | await errors(logger, err); 25 | } 26 | } 27 | 28 | // Start peer 29 | main() 30 | .catch(err => { 31 | return console.error(err.stack); 32 | }); 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chainode", 3 | "version": "1.0.0", 4 | "description": "A private blockchain network based on node.js", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node main.js", 8 | "build-webconsole-dev": "cd web-console/frontend && npm run build-dev", 9 | "build-webconsole-prod": "cd web-console/frontend && npm run build-prod", 10 | "test": "nyc mocha test --recursive --full-trace --exit", 11 | "start-dev-env": "bin/run-dev-env up -d", 12 | "stop-dev-env": "bin/run-dev-env down", 13 | "create-dev-topics": "bin/create-topics", 14 | "init-db": "bin/create-db/couchbase" 15 | }, 16 | "engines": { 17 | "node": ">=8.0" 18 | }, 19 | "engineStrict": true, 20 | "repository": { 21 | "type": "git", 22 | "url": "git+https://github.com/davidemiceli/chainode.git" 23 | }, 24 | "keywords": [ 25 | "blockchain", 26 | "blockchain-technology", 27 | "private-blockchain", 28 | "permissioned-blockchain", 29 | "blockchain-network", 30 | "fintech", 31 | "p2p" 32 | ], 33 | "author": "davidemiceli", 34 | "license": "AGPL-3.0", 35 | "maintainers": [ 36 | "davidemiceli" 37 | ], 38 | "bugs": { 39 | "url": "https://github.com/davidemiceli/chainode/issues" 40 | }, 41 | "homepage": "https://github.com/davidemiceli/chainode#readme", 42 | "dependencies": { 43 | "axios": "^0.18.0", 44 | "body-parser": "^1.18.3", 45 | "couchbase": "^2.6.2", 46 | "express": "^4.16.4", 47 | "jsonwebtoken": "^8.4.0", 48 | "kafka-node": "^3.0.1", 49 | "lodash": "^4.17.11", 50 | "moment": "^2.22.2", 51 | "morgan": "^1.9.1", 52 | "node-rsa": "^1.0.2", 53 | "redis": "^2.8.0", 54 | "uuid": "^3.3.2", 55 | "winston": "^3.1.0", 56 | "winston-daily-rotate-file": "^3.5.1" 57 | }, 58 | "devDependencies": { 59 | "chai": "^4.2.0", 60 | "mocha": "^5.2.0", 61 | "nyc": "^13.1.0" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /test/configs/generic.json: -------------------------------------------------------------------------------- 1 | { 2 | "blockchain": "blockchain", 3 | "organization": "brandName", 4 | "role": "peer", 5 | "id": "0000", 6 | "db": { 7 | "hosts": [ 8 | "172.25.255.20" 9 | ], 10 | "bucket": "blockchain", 11 | "username": "admin", 12 | "password": "secret" 13 | }, 14 | "kafka": { 15 | "hosts": [ 16 | "172.25.255.61:9092" 17 | ], 18 | "topics": { 19 | "pending": "blockchain.blocks.pending" 20 | }, 21 | "consumer": { 22 | "groupId": "brandName.0000", 23 | "fromOffset": false, 24 | "autoCommit": true, 25 | "encoding": "utf8", 26 | "keyEncoding": "utf8" 27 | }, 28 | "producer": { 29 | "partitionerType": 2 30 | } 31 | }, 32 | "webconsole": { 33 | "enabled": true, 34 | "host": "172.25.255.50", 35 | "port": 8080, 36 | "jwt": { 37 | "secret": "93f7db1df1f22a27c8b7cc609b9d5c9b7c1dba05e13f029a9e4612066c42775c86305e9d57c8c92cd30a789bc31ec011d135dc33508707c4e41512dc7502aeb8", 38 | "expire": "5m" 39 | }, 40 | "admin": { 41 | "usedb": false, 42 | "user": "admin", 43 | "password": "admin" 44 | } 45 | }, 46 | "logs": { 47 | "level": "debug", 48 | "console": true, 49 | "path": "./logs" 50 | } 51 | } -------------------------------------------------------------------------------- /test/lib/apis.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const axios = require('axios'); 5 | 6 | 7 | // APIs client 8 | module.exports = async (method, baseurl, endpoint, data) => { 9 | try { 10 | if (!/^(GET|POST)$/.test(method)) { 11 | throw Error('Invalid REST APIs method.'); 12 | } 13 | endpoint = endpoint && endpoint.replace(/^\//, ''); 14 | const apiMethod = method.toLowerCase(); 15 | const fullApiUrl = `${baseurl}/${endpoint}`; 16 | const r = await axios[apiMethod](fullApiUrl, data); 17 | return r.data; 18 | } catch(e) { 19 | console.log(e.stack); 20 | throw e; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /test/unit.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const expect = require('chai').expect; 5 | const Chainode = require('../lib/sdk'); 6 | const loadConfigs = require('../lib/configs/loadConfigs'); 7 | const { generateNextBlock } = require('../lib/block'); 8 | const APIs = require('./lib/apis'); 9 | 10 | 11 | // Set generic configs 12 | process.env.CONFIGS = process.env.CONFIGS || './test/configs/generic.json'; 13 | 14 | let agent = null; 15 | const peer = { 16 | url: '' 17 | }; 18 | 19 | 20 | // Integration tests 21 | describe('should handle the blocks and the ledger', () => { 22 | 23 | before(() => { 24 | // Load configurations 25 | const configs = loadConfigs(); 26 | // Disable console logs 27 | configs.logs.console = true; 28 | // Init the peer 29 | agent = new Chainode(configs); 30 | expect(agent).instanceOf(Chainode); 31 | // Set peer url 32 | const { host, port } = agent.configs.webconsole; 33 | peer.url = `http://${host}:${port}`; 34 | expect(peer.url).to.be.a('string').to.be.not.empty; 35 | }); 36 | 37 | describe('sdk should propose blocks and add them to the ledger.', () => { 38 | 39 | it('starts the sdk peer agent', async () => { 40 | const res = await agent.start(); 41 | expect(res).instanceOf(Chainode); 42 | }).timeout(5*1000); 43 | 44 | it('proposes new blocks for the ledger', async () => { 45 | const data = [ 46 | `Hello test ${Math.random()}`, 47 | JSON.stringify({ok: 'test', num: Math.random()}) 48 | ]; 49 | for (const item of data) { 50 | const res = await agent.sendNewBlock(item); 51 | expect(res).to.be.a('string'); 52 | } 53 | }); 54 | 55 | it('proposes a not serialized block for the ledger raising an error', async () => { 56 | try { 57 | const data = {test: 123}; 58 | await agent.sendNewBlock(data); 59 | } catch(err) { 60 | expect(err).to.be.an('error').with.property('message', 'Data is not serialized.'); 61 | } 62 | }); 63 | 64 | it('adds a valid block to the ledger', async () => { 65 | const data = Math.random(); 66 | const { organization } = agent.configs; 67 | const serialized = agent.serialize(data); 68 | const newblock = generateNextBlock(organization, serialized); 69 | const res = await agent.addBlockToLedger(newblock); 70 | expect(res).to.be.a('string').to.be.equal(newblock.id); 71 | }); 72 | 73 | it('tries to adds an invalid block to the ledger', async () => { 74 | const serialized = agent.serialize('Test block'); 75 | const data = generateNextBlock('someCompany', serialized); 76 | const resValid = await agent.addBlockToLedger(data); 77 | expect(resValid).to.be.a('string').to.be.equal(data.id); 78 | data.data = 'I am not valid!'; 79 | const resNotValid = await agent.addBlockToLedger(data); 80 | expect(resNotValid).to.be.false; 81 | }); 82 | 83 | }); 84 | 85 | describe('should handle the blockchain via web-console APIs.', () => { 86 | 87 | it('checks the status of the APIs', async () => { 88 | const res = await APIs('GET', peer.url, 'api'); 89 | expect(res).to.deep.equal({status: 'active'}); 90 | }); 91 | 92 | it('makes blockgenerator show the latest blocks', async () => { 93 | const res = await APIs('POST', peer.url, 'api/block/list', {}); 94 | expect(res).to.be.an('array'); 95 | }); 96 | 97 | it('makes peer propose blocks to the blockgenerator', async () => { 98 | for (let i=0; i<1*6; i++) { 99 | const data = { 100 | data: `Hello ${i}-${Math.random()}!` 101 | }; 102 | const res = await APIs('POST', peer.url, 'api/block/propose', data); 103 | expect(res).to.be.true; 104 | } 105 | }); 106 | 107 | }); 108 | 109 | after(async () => { 110 | await agent.shutdown(); 111 | return true; 112 | }); 113 | }); 114 | -------------------------------------------------------------------------------- /web-console/backend/lib/ErrorHandler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Error response handling 4 | */ 5 | 6 | 7 | // Error codes 8 | const ERROR_CODES = { 9 | BadRequest: 400, 10 | Unauthorized: 401, 11 | PaymentRequired: 402, 12 | Forbidden: 403, 13 | NotFound: 404, 14 | MethodNotAllowed: 405, 15 | NotAcceptable: 406, 16 | ProxyAuthenticationRequired: 407, 17 | RequestTimeout: 408, 18 | Conflict: 409, 19 | Gone: 410, 20 | LengthRequired: 411, 21 | PreconditionFailed: 412, 22 | RequestEntityTooLarge: 413, 23 | RequesturiTooLarge: 414, 24 | UnsupportedMediaType: 415, 25 | RangeNotSatisfiable: 416, 26 | RequestedRangeNotSatisfiable: 416, 27 | ExpectationFailed: 417, 28 | ImATeapot: 418, 29 | UnprocessableEntity: 422, 30 | Locked: 423, 31 | FailedDependency: 424, 32 | UnorderedCollection: 425, 33 | UpgradeRequired: 426, 34 | PreconditionRequired: 428, 35 | TooManyRequests: 429, 36 | RequestHeaderFieldsTooLarge: 431, 37 | InternalServerError: 500, 38 | NotImplemented: 501, 39 | BadGateway: 502, 40 | ServiceUnavailable: 503, 41 | GatewayTimeout: 504, 42 | HttpVersionNotSupported: 505, 43 | VariantAlsoNegotiates: 506, 44 | InsufficientStorage: 507, 45 | BandwidthLimitExceeded: 509, 46 | NotExtended: 510, 47 | NetworkAuthenticationRequired: 511 48 | }; 49 | 50 | // Error handler 51 | class ErrorHandler { 52 | 53 | constructor(res) { 54 | this.res = res; 55 | 56 | // Extend error handler with all error codes 57 | for (const err_name in ERROR_CODES) { 58 | this[err_name] = function(errmsg) { 59 | const status_code = Number(ERROR_CODES[err_name]); 60 | const err_message = errmsg || (err_name.split(/(?=[A-Z])/)).join(' '); 61 | const err_resp = { 62 | code: status_code, 63 | type: err_name, 64 | message: errmsg || err_name 65 | } 66 | return this.res.status(status_code).json(err_resp); 67 | } 68 | } 69 | 70 | } 71 | 72 | } 73 | 74 | module.exports = ErrorHandler; 75 | -------------------------------------------------------------------------------- /web-console/backend/lib/logHandler.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Handle express errors using a generic inherited logger 4 | */ 5 | 6 | 7 | // Select logger by response status code 8 | const selectLogger = (res, logger) => { 9 | if (res.statusCode >= 200 && res.statusCode < 300) return logger.info; 10 | if (res.statusCode >= 300 && res.statusCode < 400) return logger.warn; 11 | return logger.error; 12 | } 13 | 14 | 15 | module.exports = (componentName, logger) => (req, res, next) => { 16 | const startTime = Date.now(); 17 | if (res.headersSent) { 18 | const log = selectLogger(res, logger); 19 | log(componentName, req.method, req.url, res.statusCode); 20 | } else { 21 | res.on('finish', function() { 22 | const endTime = Date.now(); 23 | const duration = endTime-startTime; 24 | const log = selectLogger(res, logger); 25 | log(componentName, req.method, req.url, res.statusCode, '-', duration, 'ms'); 26 | }) 27 | } 28 | return next(); 29 | }; 30 | -------------------------------------------------------------------------------- /web-console/backend/middlewares/isAuth.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // Requirements 5 | const jwt = require('jsonwebtoken'); 6 | const configs = require('../../../configs/configs'); 7 | const db = require('../../../../models/redis/db'); 8 | 9 | 10 | module.exports = async (req, res) => { 11 | try { 12 | // Get parameters 13 | const id = req.params.id; 14 | const token = (req.headers && req.headers['x-access-token']) || null; 15 | // Get user 16 | const peer = await db.Users.Get(id); 17 | // Try to decode token 18 | const decoded = jwt.verify(token, configs.jwt.secret, { 19 | algorithms: ['HS256'], 20 | maxAge: configs.jwt.expire 21 | }); 22 | // Check if decoding is correct 23 | if (!decoded) { 24 | return res.ErrorHandler.Unauthorized('Invalid authorization'); 25 | } 26 | // Check if data inside token is valid 27 | if (peer.user === decoded.user && peer.password === decoded.password) { 28 | return next(); 29 | } 30 | return res.ErrorHandler.Unauthorized('Wrong authorization'); 31 | } catch(err) { 32 | console.log(err.stack); 33 | return res.ErrorHandler.InternalServerError(); 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /web-console/backend/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Router 4 | */ 5 | 6 | // Requirements 7 | const fs = require('fs'); 8 | const path = require('path'); 9 | const express = require('express'); 10 | const router = express.Router(); 11 | const Routes = require('./routes'); 12 | 13 | // Middlewares 14 | // const isAuth = require('./middlewares/isAuth'); 15 | 16 | 17 | module.exports = baseurl => { 18 | // Bind host and port index html for FE 19 | const indexHtml = fs 20 | .readFileSync(path.resolve(__dirname, '../frontend/build/index.html')) 21 | .toString() 22 | .replace(/EMBEDDED_BASEURL/, baseurl); 23 | 24 | // Pages and redirect 25 | router.get([Routes.MAIN, `${Routes.DASHBOARD}/`, `${Routes.DASHBOARD}/*`], (req, res) => { 26 | // Render index dashboard page 27 | return res.end(indexHtml); 28 | }); 29 | 30 | // Monitoring peer server 31 | router.get(Routes.APIS, require('./routes/status/health')); 32 | router.get(Routes.STATUS.HEALTH, require('./routes/status/health')); 33 | router.get(Routes.STATUS.STATS, require('./routes/status/stats')); 34 | // Client authentication 35 | // ... 36 | // Block management 37 | router.post(Routes.BLOCK.PROPOSE, require('./routes/block/propose')); 38 | router.post(Routes.BLOCK.LIST, require('./routes/block/list')); 39 | 40 | // Exporting endpoints 41 | return router; 42 | } 43 | -------------------------------------------------------------------------------- /web-console/backend/routes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Routes Mapping 4 | */ 5 | 6 | // Routes 7 | module.exports = { 8 | // Dashboard 9 | MAIN: '/', 10 | DASHBOARD: '/dashboard', 11 | // APIs home 12 | APIS: '/api', 13 | // Monitoring peer server 14 | STATUS: { 15 | HEALTH: '/api/health', 16 | STATS: '/api/stats' 17 | }, 18 | // Client authorization 19 | AUTH: { 20 | SIGNIN: 'api/auth/signin', 21 | SIGNUP: 'api/auth/signup', 22 | LOGOUT: 'api/auth/logout' 23 | }, 24 | // Block management 25 | BLOCK: { 26 | PROPOSE: '/api/block/propose', 27 | LIST: '/api/block/list' 28 | }, 29 | // Peer management 30 | PEER: { 31 | NEW: 'api/peer/new', 32 | AUTH: 'api/peer/auth', 33 | VERIFY: 'api/peer/verify', 34 | LIST: 'api/peer/list' 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /web-console/backend/routes/auth/signin.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // Requirements 5 | const crypto = require('crypto'); 6 | const jwt = require('jsonwebtoken'); 7 | const moment = require('moment'); 8 | const uuid4 = require('uuid/v4'); 9 | const configs = require('../../configs/configs'); 10 | const db = require('../../../models/redis/db'); 11 | 12 | 13 | module.exports = async (req, res) => { 14 | try { 15 | // Get user and password 16 | const id = req.params.id; 17 | const username = req.body.user; 18 | const password = crypto.createHash('sha256').update(req.body.password).digest('hex'); 19 | // Get user 20 | const user = await db.Users.Get(id); 21 | // Check if user and password are correct 22 | if (username !== user.user || password !== user.password) { 23 | return res.ErrorHandler.Unauthorized('Wrong authentication parameters'); 24 | } 25 | // Create JWT Token 26 | const to_encode = { 27 | user: username, 28 | password: password, 29 | uuid4: uuid4(), 30 | randomkey: Math.random(), 31 | now: moment().utc().valueOf() 32 | }; 33 | // Generate access token 34 | const token = jwt.sign(to_encode, configs.jwt.secret, { 35 | algorithm: 'HS256', 36 | expiresIn: configs.jwt.expire 37 | }); 38 | return res.json({id, token}); 39 | } catch(err) { 40 | console.log(err.stack); 41 | return res.ErrorHandler.InternalServerError(); 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /web-console/backend/routes/auth/signup.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const crypto = require('crypto'); 5 | const Validator = require("fastest-validator"); 6 | const db = require('../../../models/redis/db'); 7 | 8 | // Validator 9 | const v = new Validator(); 10 | const check = v.compile({ 11 | id: {type: "string", min: 7, max: 255}, 12 | user: {type: "string", min: 8, max: 255}, 13 | password: {type: "string", min: 8, max: 255} 14 | }); 15 | 16 | module.exports = async (req, res) => { 17 | try { 18 | // Get user parameters 19 | const id = req.params.id; 20 | // Check if the user already exists 21 | const u = await db.Users.Get(id); 22 | if (u) { 23 | return res.ErrorHandler.Unauthorized('The user already exists.'); 24 | } 25 | // user data 26 | const user = { 27 | id: id, 28 | user: req.body.user, 29 | password: req.body.password 30 | }; 31 | // Check if user data are correct 32 | const errors = check(user); 33 | if (errors.length) { 34 | const msg = errors[0].message; 35 | return res.ErrorHandler.InternalServerError(msg); 36 | } 37 | // Encrypt password 38 | user.password = crypto.createHash('sha256').update(user.password).digest('hex'); 39 | // Store user 40 | await db.Users.Add(id, user); 41 | return res.json({id}); 42 | } catch(err) { 43 | console.log(err.stack); 44 | return res.ErrorHandler.InternalServerError(); 45 | } 46 | }; 47 | -------------------------------------------------------------------------------- /web-console/backend/routes/block/list.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | const { toBlock } = require('../../../../lib/block'); 5 | 6 | 7 | // List blocks 8 | module.exports = async (req, res) => { 9 | try { 10 | // Get conditions 11 | const condition = req.body; 12 | const pag = parseInt(req.body.pag || 0); 13 | const limit = 25; 14 | const offset = (pag < 0) ? pag : pag * limit; 15 | // Get last blocks 16 | const blocks = await req.db.Ledger.GetBlocks(condition, limit, offset); 17 | // Parse blocks 18 | const results = blocks 19 | .map(toBlock); 20 | // Return results 21 | return res.json(results); 22 | } catch(err) { 23 | req.sdk.logger.error(err.stack); 24 | return res.ErrorHandler.InternalServerError(err.message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /web-console/backend/routes/block/propose.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Propose data to append to the ledger 4 | module.exports = async (req, res) => { 5 | try { 6 | const data = req.body.data; 7 | if (!data) throw Error('Invalid block data.'); 8 | await req.sdk.sendNewBlock(data); 9 | return res.json(true); 10 | } catch(err) { 11 | return res.ErrorHandler.InternalServerError(err.message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /web-console/backend/routes/status/health.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Monitoring server health status 4 | module.exports = function(req, res, next) { 5 | return res.json({status: 'active'}); 6 | } 7 | -------------------------------------------------------------------------------- /web-console/backend/routes/status/stats.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Get system and process statistics 4 | */ 5 | 6 | const os = require('os'); 7 | 8 | 9 | module.exports = function(req, res, next) { 10 | // Get peer infos 11 | const { 12 | blockchain, 13 | organization, 14 | id, 15 | role 16 | } = req.sdk.configs; 17 | 18 | // Return statistics 19 | return res.json({ 20 | status: 'active', 21 | peer: { 22 | id: id, 23 | role: role, 24 | blockchain: blockchain, 25 | organization: organization 26 | }, 27 | system: { 28 | uptime: os.uptime(), 29 | mem: os.totalmem(), 30 | freemem: os.freemem(), 31 | memoryUsage: process.memoryUsage() 32 | } 33 | }); 34 | } 35 | -------------------------------------------------------------------------------- /web-console/backend/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Web console server Initialization 4 | */ 5 | 6 | // Requirements 7 | const path = require('path'); 8 | const express = require('express'); 9 | const bodyParser = require('body-parser'); 10 | const ErrorHandler = require('./lib/ErrorHandler'); 11 | const logHandler = require('./lib/logHandler'); 12 | 13 | 14 | module.exports = async (configs, sdk, logger, db) => { 15 | const componentName = 'WebConsole'; 16 | logger.info(`Starting ${componentName}.`); 17 | const webConsolePort = (configs.port == 80) ? '' : `:${configs.port}`; 18 | const webConsoleUrl = `http://${configs.host}${webConsolePort}`; 19 | // Init express app 20 | const app = express(); 21 | // App settings and plugins 22 | // app.use(morgan('dev', logtypes[configs.logs.type])); 23 | app.use(logHandler(componentName, logger)); 24 | app.use(bodyParser.json()); 25 | app.use(bodyParser.urlencoded({ extended: true })); 26 | app.disable('x-powered-by'); 27 | app.use((req, res, next) => { 28 | req.db = db; 29 | req.sdk = sdk; 30 | res.ErrorHandler = new ErrorHandler(res); 31 | return next(); 32 | }); 33 | 34 | // Add router 35 | const router = require('./router')(webConsoleUrl); 36 | app.use('/', router); 37 | 38 | // Static files 39 | const staticFolder = path.resolve(__dirname, '../frontend/build'); 40 | app.use('/', express.static(staticFolder)); 41 | 42 | // Catch 404 and forward to error handler 43 | app.use((req, res, next) => { 44 | const err = new Error('Not Found'); 45 | err.status = 404; 46 | return next(err); 47 | }); 48 | 49 | // Error handler 50 | app.use((err, req, res, next) => { 51 | // set locals, only providing error in development 52 | const current_env = req.app.get('env'); 53 | res.locals.message = err.message; 54 | if (err.status < 400 || err.status >= 500) { 55 | res.locals.error = current_env === 'development' ? err : { 56 | message: 'Internal Server Error' 57 | }; 58 | req.sdk.logger.error(err.stack); 59 | } 60 | // render the error 61 | res.status(err.status || 500); 62 | return res.json({ 63 | code: err.status, 64 | message: err.message 65 | }); 66 | }); 67 | 68 | // Start UI console server 69 | return app.listen(configs.port, async () => { 70 | logger.info(`${componentName} listening on port ${webConsoleUrl}.`); 71 | return app; 72 | }); 73 | } 74 | -------------------------------------------------------------------------------- /web-console/frontend/build/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/favicon.ico -------------------------------------------------------------------------------- /web-console/frontend/build/img/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/img/image.png -------------------------------------------------------------------------------- /web-console/frontend/build/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/img/logo.png -------------------------------------------------------------------------------- /web-console/frontend/build/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Chainode | Dashboard 12 | 13 | 14 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-brands-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-brands-400.eot -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-brands-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-brands-400.ttf -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-brands-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-brands-400.woff -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-brands-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-brands-400.woff2 -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-regular-400.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-regular-400.eot -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-regular-400.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-regular-400.ttf -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-regular-400.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-regular-400.woff -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-regular-400.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-regular-400.woff2 -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-solid-900.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-solid-900.eot -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-solid-900.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-solid-900.ttf -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-solid-900.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-solid-900.woff -------------------------------------------------------------------------------- /web-console/frontend/build/webfonts/fa-solid-900.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/build/webfonts/fa-solid-900.woff2 -------------------------------------------------------------------------------- /web-console/frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chainode-webconsole", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "davidemiceli", 6 | "license": "AGPL-3.0", 7 | "maintainers": [ 8 | "davidemiceli" 9 | ], 10 | "scripts": { 11 | "build-dev": "webpack --mode=development --debug --progress --colors", 12 | "build-prod": "webpack --mode=production --debug --progress --colors" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/davidemiceli/chainode" 17 | }, 18 | "keywords": [], 19 | "bugs": { 20 | "url": "https://github.com/davidemiceli/chainode/issues" 21 | }, 22 | "homepage": "https://github.com/davidemiceli/chainode#readme", 23 | "dependencies": { 24 | "@fortawesome/fontawesome-free": "^5.6.3", 25 | "axios": "^0.18.0", 26 | "bootstrap": "^4.1.3", 27 | "jquery": "^3.3.1", 28 | "moment": "^2.22.2", 29 | "popper.js": "^1.14.6", 30 | "toastr": "^2.1.4", 31 | "vue": "^2.5.17", 32 | "vue-currency-filter": "^3.2.0", 33 | "vue-loading-overlay": "^3.1.1", 34 | "vue-router": "^3.0.2", 35 | "vuex": "^3.0.1" 36 | }, 37 | "devDependencies": { 38 | "@babel/core": "^7.2.0", 39 | "@babel/preset-env": "^7.2.0", 40 | "babel-loader": "^8.0.4", 41 | "babel-polyfill": "^6.26.0", 42 | "body-parser": "^1.18.3", 43 | "clean-webpack-plugin": "^1.0.0", 44 | "copy-webpack-plugin": "^4.6.0", 45 | "css-loader": "^1.0.1", 46 | "express": "^4.16.4", 47 | "file-loader": "^2.0.0", 48 | "html-webpack-plugin": "^3.2.0", 49 | "mini-css-extract-plugin": "^0.5.0", 50 | "morgan": "^1.9.1", 51 | "node-sass": "^4.11.0", 52 | "sass-loader": "^7.1.0", 53 | "style-loader": "^0.23.1", 54 | "uglifyjs-webpack-plugin": "^2.0.1", 55 | "vue-loader": "^15.4.2", 56 | "vue-template-compiler": "^2.5.17", 57 | "webpack": "^4.27.1", 58 | "webpack-cli": "^3.1.2" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/404.vue: -------------------------------------------------------------------------------- 1 | 6 | 7 | 17 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/App.vue: -------------------------------------------------------------------------------- 1 | 8 | 9 | 24 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/Home.vue: -------------------------------------------------------------------------------- 1 | 45 | 46 | 80 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/blocks/List.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 83 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/blocks/Propose.vue: -------------------------------------------------------------------------------- 1 | 20 | 21 | 70 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/blocks/pagination/Pagination.vue: -------------------------------------------------------------------------------- 1 | 14 | 15 | 54 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/commons/footer/index.vue: -------------------------------------------------------------------------------- 1 | 4 | 5 | 26 | -------------------------------------------------------------------------------- /web-console/frontend/src/components/commons/navbar/index.vue: -------------------------------------------------------------------------------- 1 | 42 | 43 | 72 | -------------------------------------------------------------------------------- /web-console/frontend/src/configs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | 4 | // App configuration settings 5 | const Configs = { 6 | baseurl: BASEURL_FROM_BE, 7 | alerts: { 8 | successAdded: 'Data added with success!', 9 | deleted: 'Deleted data with success!', 10 | error: 'Sorry, there was an error: contact the administrator...', 11 | } 12 | }; 13 | 14 | export default Configs; 15 | -------------------------------------------------------------------------------- /web-console/frontend/src/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/src/img/favicon.ico -------------------------------------------------------------------------------- /web-console/frontend/src/img/image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/src/img/image.png -------------------------------------------------------------------------------- /web-console/frontend/src/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davidemiceli/chainode/b61020155264c81774b09b222b716a8863238cbb/web-console/frontend/src/img/logo.png -------------------------------------------------------------------------------- /web-console/frontend/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Chainode | Dashboard 12 | 13 | 14 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /web-console/frontend/src/lib/filters.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import Vue from 'vue'; 5 | import VueCurrencyFilter from 'vue-currency-filter'; 6 | 7 | 8 | // Format currency 9 | Vue.use(VueCurrencyFilter, { 10 | symbol: '', 11 | thousandsSeparator: '.', 12 | fractionCount: 2, 13 | fractionSeparator: ',', 14 | symbolPosition: 'front', 15 | symbolSpacing: false 16 | }); 17 | 18 | // Format a datetime 19 | Vue.filter('dateMedium', function(datetime, format) { 20 | // return moment(datetime).format(format || 'YYYY-MM-DD hh:mm:ss'); 21 | return moment(datetime).format(format || 'LLL'); 22 | }); 23 | 24 | // Format a time duration 25 | Vue.filter('timeDuration', function(duration) { 26 | return new moment.duration(duration).humanize(); 27 | }); 28 | 29 | // Format bytes in a readable way 30 | Vue.filter('formatBytes', function(bytes) { 31 | if (bytes < 1024) return bytes + " Bytes"; 32 | else if (bytes < 1048576) return (bytes / 1024).toFixed(3) + " KB"; 33 | else if (bytes < 1073741824) return (bytes / 1048576).toFixed(3) + " MB"; 34 | return (bytes / 1073741824).toFixed(3) + " GB"; 35 | }); 36 | 37 | // Shortify a string if is longer than a defined length 38 | Vue.filter('readMore', function(text, length, suffix) { 39 | suffix = (text.length <= length) ? '' : (suffix || '…'); 40 | return text.substring(0, length) + suffix; 41 | }); 42 | 43 | export {} 44 | -------------------------------------------------------------------------------- /web-console/frontend/src/lib/utils.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Utilities 4 | class Utils { 5 | 6 | constructor() { } 7 | 8 | // Example 9 | example() { 10 | return; 11 | } 12 | 13 | }; 14 | 15 | export default new Utils(); 16 | -------------------------------------------------------------------------------- /web-console/frontend/src/main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Main application entrypoint 4 | */ 5 | 6 | // CSS styles 7 | import '@/src/styles.js'; 8 | 9 | // Javascript libraries 10 | import 'bootstrap'; 11 | import 'lodash'; 12 | import '@fortawesome/fontawesome-free'; 13 | 14 | // Vue requirements 15 | import Vue from 'vue'; 16 | import App from '@/src/components/App'; 17 | import router from '@/src/router'; 18 | import filters from '@/src/lib/filters'; 19 | // Import component plugins 20 | import Loading from 'vue-loading-overlay'; 21 | 22 | // Turn off the production tip on the console 23 | Vue.config.productionTip = false; 24 | 25 | // Init loading plugins 26 | Vue.use(Loading,{ 27 | loader: 'bars', 28 | color: '#ffc107' 29 | }); 30 | 31 | // App 32 | new Vue({ 33 | el: '#app', 34 | router, 35 | components: { App }, 36 | template: '' 37 | }); 38 | -------------------------------------------------------------------------------- /web-console/frontend/src/router/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import Vue from 'vue'; 5 | import VueRouter from 'vue-router'; 6 | 7 | // Routes 8 | import { Routes } from '@/src/router/routes'; 9 | 10 | // Routes 11 | import Home from '@/src/components/Home'; 12 | import BlocksList from '@/src/components/blocks/List'; 13 | import BlocksPropose from '@/src/components/blocks/Propose'; 14 | import NotFound from '@/src/components/404'; 15 | 16 | Vue.use(VueRouter); 17 | 18 | const routes = [ 19 | { path: Routes.HOME.path, name: Routes.HOME.name, component: Home}, 20 | { path: Routes.BLOCKS.LIST.path, name: Routes.BLOCKS.LIST.name, component: BlocksList}, 21 | { path: Routes.BLOCKS.PROPOSE.path, name: Routes.BLOCKS.PROPOSE.name, component: BlocksPropose}, 22 | { path: Routes.SOMETHING.path, redirect: Routes.HOME.path }, 23 | { path: Routes.NOTFOUND.path, component: NotFound }, 24 | { path: '*', redirect: Routes.NOTFOUND.path } 25 | ]; 26 | 27 | export default new VueRouter({ 28 | mode: 'history', 29 | routes: routes 30 | }); 31 | -------------------------------------------------------------------------------- /web-console/frontend/src/router/routes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Configurations 4 | import Configs from '@/src/configs'; 5 | 6 | // Routes 7 | export const Routes = { 8 | // Dashboard 9 | HOME: {path: '/', name: 'home'}, 10 | // Blocks 11 | BLOCKS: { 12 | LIST: {path: '/dashboard/blocks/list', name: 'BlocksList'}, 13 | PROPOSE: {path: '/dashboard/blocks/propose', name: 'BlocksPropose'} 14 | }, 15 | // Something 16 | SOMETHING: {path: '/dashboard/something', name: 'something'}, 17 | // Not Found: 404 error 18 | NOTFOUND: {path: '/404', name: 'notfound'} 19 | }; 20 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_custom.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Custom generic styles 3 | */ 4 | 5 | @import url('https://fonts.googleapis.com/css?family=Roboto'); 6 | @import url('https://fonts.googleapis.com/icon?family=Material+Icons'); 7 | 8 | /* For Vue.js to hide brackets on startup of page */ 9 | [v-cloak], .v-cloak { 10 | display: none !important; 11 | } 12 | 13 | /* To fix the text align with material google icons */ 14 | .material-icons { 15 | vertical-align: middle; 16 | } 17 | 18 | html, body { 19 | background-color: #FFF; 20 | } 21 | 22 | a { 23 | color: #bfbfbf; 24 | } 25 | a:focus, a:hover { 26 | color: rgb(115, 115, 115); 27 | text-decoration: none; 28 | } 29 | 30 | .form-control { 31 | border-radius: 0px; 32 | } 33 | .btn { 34 | border-radius: 0px; 35 | } 36 | textarea { 37 | resize: none; 38 | } 39 | .form-control:focus { 40 | color: #495057; 41 | background-color: #fff; 42 | border-color: #cecece; 43 | outline: 0; 44 | box-shadow: 0 0 0 0.2rem rgba(204, 204, 204, 0.25); 45 | } 46 | 47 | .progress { 48 | height: 10px; 49 | } 50 | 51 | .box-section { 52 | padding: 35px; 53 | background-color: #fff; 54 | border-radius: 2px; 55 | transition: all 0.3s ease-in-out; 56 | box-shadow: 0px 10px 50px 0px rgba(84,110,122,0.15); 57 | } 58 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_dashboard.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Dashboard 3 | */ 4 | 5 | /* Menù */ 6 | 7 | .menu-on-sidebar { 8 | margin: 0 !important; 9 | padding: 10px; 10 | position: fixed; 11 | background: #fff; 12 | height: calc(100% - 50px); 13 | width: 500px; 14 | top: 50px; 15 | left: 0px; 16 | overflow-y: auto; 17 | transition: all; 18 | transition-duration: .0s; 19 | z-index: 10; 20 | box-shadow: 0 0 3px rgba(14,18,21,.38); 21 | } 22 | .section-menu { 23 | position: fixed; 24 | background-color: #fff; 25 | width: calc(100% - 70px); 26 | transition: all; 27 | transition-duration: .0s; 28 | transition-duration: .0s; 29 | z-index: 2000; 30 | } 31 | .dashboard-on-loading { 32 | position: fixed; 33 | background: rgba(255,255,255,0.5); 34 | height: 100%; 35 | min-width: 100%; 36 | /* top: 70px; */ 37 | transition: all; 38 | transition-duration: .0s; 39 | z-index: 5000; 40 | overflow-y: hidden; 41 | box-shadow: 0 0 3px rgba(14,18,21,.38); 42 | } 43 | .numbers-chart { 44 | font-family: "Roboto"; 45 | font-size: 13px; 46 | line-height: 1.42857143; 47 | color: #5E5E5E; 48 | background-color: #f3f3f3; 49 | } -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_footer.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Footer 3 | */ 4 | 5 | .footer { 6 | bottom: 0; 7 | margin-top: 30px; 8 | width: 100%; 9 | min-height: 60px; 10 | line-height: 60px; 11 | } 12 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_helpers.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Helpers classes for styles 3 | 4 | Dynamic function to create helper classes of margin: 5 | Example: .m-t-5 => margin-top: 5px; 6 | */ 7 | 8 | @mixin mp-i-x { 9 | @for $i from 0 through 100 { 10 | /* margin */ 11 | .m-t-#{$i} { margin-top: #{$i}px; } 12 | .m-b-#{$i} { margin-bottom: #{$i}px; } 13 | .m-l-#{$i} { margin-left: #{$i}px; } 14 | .m-r-#{$i} { margin-right: #{$i}px; } 15 | /* padding */ 16 | .p-t-#{$i} { padding-top: #{$i}px; } 17 | .p-b-#{$i} { padding-bottom: #{$i}px; } 18 | .p-l-#{$i} { padding-left: #{$i}px; } 19 | .p-r-#{$i} { padding-right: #{$i}px; } 20 | } 21 | } 22 | 23 | @mixin m-lr-x { 24 | @for $i from 0 through 100 { 25 | .m-lr-#{$i} { 26 | margin-left: #{$i}px; 27 | margin-right: #{$i}px; 28 | } 29 | } 30 | } 31 | 32 | @mixin f-x { 33 | @for $i from 7 through 70 { 34 | .f-#{$i} { font-size: #{$i}px; } 35 | } 36 | } 37 | 38 | @include f-x; 39 | @include mp-i-x; 40 | @include m-lr-x; 41 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_typography.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Typography 3 | */ 4 | 5 | @import url('https://fonts.googleapis.com/css?family=Staatliches'); 6 | @import url('https://fonts.googleapis.com/css?family=Inconsolata:400,700&subset=latin-ext'); 7 | 8 | .brand-title-name { 9 | font-family: 'Staatliches', sans-serif; 10 | font-weight: 400; 11 | color: #EFBB00; 12 | } 13 | 14 | .title { 15 | line-height: 1.33; 16 | font-weight: 300; 17 | letter-spacing: -.5px; 18 | } 19 | 20 | .sentences { 21 | font-weight: 300; 22 | font-size: 20px; 23 | line-height: 1.6; 24 | } 25 | 26 | .small-title { 27 | font-weight: 500; 28 | } 29 | 30 | .top-title { 31 | font-size: 50px; 32 | color: #111; 33 | } 34 | 35 | .highlighted-link { 36 | color: #286090; 37 | font-weight: 500; 38 | } 39 | 40 | .table-small-text { 41 | font-size: 14px; 42 | } 43 | 44 | .coding { 45 | font-family: 'Inconsolata', monospace; 46 | } -------------------------------------------------------------------------------- /web-console/frontend/src/scss/_variables.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Variables 3 | */ 4 | 5 | /* colors */ 6 | $gray-color: rgb(113, 113, 113); 7 | $light-gray-color: rgb(238, 238, 238); 8 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/app.scss: -------------------------------------------------------------------------------- 1 | /* 2 | App custom styles 3 | */ 4 | 5 | @import "variables"; 6 | @import "custom"; 7 | @import "helpers"; 8 | @import "typography"; 9 | @import "footer"; 10 | @import "dashboard"; 11 | @import "navbar/navbar"; 12 | @import "navbar/colors"; 13 | @import "themes/clean"; 14 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/navbar/_colors.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Navbar custom colors 3 | */ 4 | 5 | /* Blue */ 6 | .bg-dark-blue { 7 | background-color: #286090 !important; 8 | border-color: #286090; 9 | } 10 | .navbar-dark .navbar-nav .nav-link { 11 | color: rgba(255, 255, 255, 1); 12 | } 13 | .navbar-dark .navbar-nav .nav-link:hover, 14 | .navbar-dark .navbar-nav .nav-link:focus { 15 | color: rgba(255, 255, 255, 0.9); 16 | } 17 | 18 | /* White */ 19 | .bg-light-white { 20 | background-color: #ffffff !important; 21 | border: 0; 22 | border-bottom: 1px solid #ddd; 23 | } 24 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/navbar/_navbar.scss: -------------------------------------------------------------------------------- 1 | /* 2 | Navbar styles 3 | */ 4 | 5 | .dropdown-header { 6 | font-size: 0.7rem; 7 | } 8 | 9 | .dropdown-item { 10 | color: #666; 11 | font-size: 0.7rem; 12 | } 13 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/themes/_clean.scss: -------------------------------------------------------------------------------- 1 | /* 2 | A very clean style 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Rubik:300,300i,400,400i,500,500i,700,700i&subset=latin-ext'); 5 | 6 | $text-font-rubik: "Rubik"; 7 | 8 | html, body, textarea, input, select { 9 | font-family: $text-font-rubik; 10 | } 11 | 12 | /* For dashboard */ 13 | .navbar-nav { 14 | text-transform: uppercase; 15 | font-size: 12px; 16 | font-weight: 500; 17 | letter-spacing: 0.6px; 18 | } 19 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/themes/_enjoyable.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For less impegnative websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Work+Sans:300,500'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Work Sans"; 8 | } 9 | 10 | /* For a dashboard */ 11 | .navbar-nav { 12 | font-size: 12px; 13 | font-weight: 500; 14 | letter-spacing: 0.6px; 15 | } 16 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/themes/_nerd.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For nerd styled websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Ubuntu+Mono'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Ubuntu Mono" 8 | } 9 | -------------------------------------------------------------------------------- /web-console/frontend/src/scss/themes/_serious.scss: -------------------------------------------------------------------------------- 1 | /* 2 | For a bit impegnative websites 3 | */ 4 | @import url('https://fonts.googleapis.com/css?family=Roboto+Condensed:300,300i,400,400i,700,700i&subset=latin-ext'); 5 | 6 | html, body, textarea, input, select { 7 | font-family: "Roboto Condensed"; 8 | } 9 | 10 | /* For a dashboard */ 11 | .navbar-nav { 12 | text-transform: uppercase; 13 | font-size: 12px; 14 | font-weight: 600; 15 | letter-spacing: 0.6px; 16 | } 17 | 18 | /* For landing paragraphs */ 19 | .title { 20 | line-height: 1.33; 21 | font-weight: 300; 22 | letter-spacing: -.5px; 23 | } 24 | 25 | .sentences { 26 | font-weight: 300; 27 | font-size: 20px; 28 | line-height: 1.6; 29 | } 30 | -------------------------------------------------------------------------------- /web-console/frontend/src/services/blocks.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import axios from 'axios'; 5 | 6 | // Configurations 7 | import Configs from '@/src/configs'; 8 | 9 | // Services 10 | class Blocks { 11 | 12 | constructor() { 13 | this.API_URL = `${Configs.baseurl}/api/block`; 14 | } 15 | 16 | // Propose block data 17 | async propose(block) { 18 | try { 19 | const data = { 20 | data: block 21 | }; 22 | const r = await axios.post(`${this.API_URL}/propose`, data); 23 | return r.data; 24 | } catch(e) { 25 | throw e; 26 | } 27 | } 28 | 29 | // Send data to one peer 30 | async list(condition) { 31 | try { 32 | const r = await axios.post(`${this.API_URL}/list`, condition); 33 | return r.data; 34 | } catch(e) { 35 | throw e; 36 | } 37 | } 38 | 39 | }; 40 | 41 | export const BlockServices = new Blocks(); 42 | -------------------------------------------------------------------------------- /web-console/frontend/src/services/status.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Requirements 4 | import axios from 'axios'; 5 | 6 | // Configurations 7 | import Configs from '@/src/configs'; 8 | 9 | // Services 10 | class Status { 11 | 12 | constructor() { 13 | this.API_URL = `${Configs.baseurl}/api`; 14 | } 15 | 16 | // Propose block data 17 | async stats() { 18 | try { 19 | const r = await axios.get(`${this.API_URL}/stats`); 20 | return r.data; 21 | } catch(e) { 22 | throw e; 23 | } 24 | } 25 | 26 | }; 27 | 28 | export const StatusServices = new Status(); 29 | -------------------------------------------------------------------------------- /web-console/frontend/src/store/actions.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Store 4 | import Store from '@/src/store/store'; 5 | 6 | // Actions 7 | class Actions { 8 | 9 | constructor() { } 10 | 11 | // Loading actions 12 | LOADING_START() { 13 | Store.uxui.loading = true; 14 | } 15 | LOADING_STOP() { 16 | Store.uxui.loading = false; 17 | } 18 | 19 | // Navbar actions 20 | NAVBAR_SHOW() { 21 | Store.uxui.navbar = true; 22 | } 23 | NAVBAR_HIDE() { 24 | Store.uxui.navbar = false; 25 | } 26 | 27 | // Footer actions 28 | FOOTER_SHOW() { 29 | Store.uxui.footer = true; 30 | } 31 | FOOTER_HIDE() { 32 | Store.uxui.footer = false; 33 | } 34 | 35 | // System actions 36 | SYSTEM_SET(items) { 37 | Store.system = items; 38 | } 39 | 40 | // Block actions 41 | BLOCKS_SET(items) { 42 | Store.blocks = items; 43 | } 44 | 45 | }; 46 | 47 | export default new Actions(); 48 | -------------------------------------------------------------------------------- /web-console/frontend/src/store/store.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Shared stores 4 | const Store = { 5 | uxui: { 6 | loading: false, 7 | navbar: true, 8 | footer: true 9 | }, 10 | system: {}, 11 | blocks: [] 12 | }; 13 | 14 | export default Store; 15 | -------------------------------------------------------------------------------- /web-console/frontend/src/styles.js: -------------------------------------------------------------------------------- 1 | /* 2 | Application styles 3 | */ 4 | 5 | // Default styles 6 | import '@/node_modules/bootstrap/dist/css/bootstrap.css'; 7 | import '@/node_modules/@fortawesome/fontawesome-free/css/all.css'; 8 | import '@/node_modules/toastr/build/toastr.css'; 9 | import '@/node_modules/vue-loading-overlay/dist/vue-loading.css'; 10 | 11 | // Custom styles 12 | import '@/src/scss/app.scss'; 13 | -------------------------------------------------------------------------------- /web-console/frontend/webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack configurations 4 | */ 5 | 6 | // Requirements 7 | const path = require('path'); 8 | const webpack = require('webpack'); 9 | const mainConfigs = require('./webpack/configs'); 10 | 11 | // Entrypoint and bundle path 12 | const entryPoint = './src/main.js'; 13 | const rootPath = path.resolve(__dirname, './'); 14 | const outputPath = path.resolve(rootPath, './build'); 15 | 16 | 17 | module.exports = (env, argv) => { 18 | 19 | // Define webpack general configs 20 | const configs = mainConfigs(entryPoint, rootPath, outputPath); 21 | 22 | // When compiling for production we want the app to be uglified. 23 | if (argv.mode === 'production') { 24 | 25 | // We also add it as a global, the Vue lib needs it to determine if Dev tool should be active or not. 26 | const DefinePlugin = new webpack.DefinePlugin({ 27 | 'process.env': {NODE_ENV: '"production"'} 28 | }); 29 | // Add production plugins 30 | configs.plugins.push(DefinePlugin); 31 | 32 | } else if (argv.mode === 'development') { 33 | 34 | // Disable minification 35 | configs.optimization.minimize = false; 36 | 37 | } else { 38 | throw Error('Invalid mode parameter. Must be production or development.'); 39 | } 40 | 41 | return configs; 42 | }; -------------------------------------------------------------------------------- /web-console/frontend/webpack/configs.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack main configurations 4 | */ 5 | 6 | // Requirements 7 | const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); 8 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 9 | 10 | 11 | // Main webpack config 12 | module.exports = (entryPoint, rootPath, outputPath) => ({ 13 | entry: { 14 | "app": ['babel-polyfill', entryPoint] 15 | }, 16 | output: { 17 | path: outputPath, 18 | filename: 'js/[name].js', 19 | chunkFilename: 'js/[name].[chunkhash].bundle.js' 20 | }, 21 | module: { 22 | rules: [ 23 | { 24 | test: /\.(sa|sc|c)ss$/, 25 | use: [ 26 | {loader: MiniCssExtractPlugin.loader, options: {minimize: true}}, 27 | 'css-loader', 28 | 'sass-loader' 29 | ] 30 | }, 31 | { 32 | test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/, 33 | use: [{ 34 | loader: 'file-loader', 35 | options: { 36 | name: '[name].[ext]', 37 | useRelativePath: true, 38 | outputPath: '/' 39 | } 40 | }] 41 | }, 42 | { 43 | test: /\.vue$/, 44 | loader: 'vue-loader', 45 | options: require('./configs/vueLoaderConfig') 46 | }, 47 | { 48 | test: /\.js$/, 49 | loader: 'babel-loader', 50 | query: { 51 | presets: ['@babel/preset-env'] // Transpile the ES6 to es2015 standard 52 | } 53 | } 54 | ] 55 | }, 56 | resolve: { 57 | extensions: ['.js', '.vue', '.json'], 58 | alias: { 59 | 'vue$': 'vue/dist/vue.esm.js', // Resolving the vue var for standalone build 60 | '@': rootPath, 61 | 'jQuery': 'jquery/dist/jquery.min.js' 62 | } 63 | }, 64 | plugins: require('./plugins')(rootPath, outputPath), // set the defined plugins 65 | optimization: { 66 | minimize: true, 67 | minimizer: [ 68 | new UglifyJsPlugin({ 69 | include: /\.min\.js$/, 70 | parallel: true, 71 | sourceMap: true 72 | }) 73 | ], 74 | splitChunks: { 75 | // minSize: 10000, 76 | // maxSize: 300000, 77 | minChunks: 1, 78 | name: true, 79 | cacheGroups: { 80 | vendors: { 81 | test: /node_modules/, 82 | chunks: 'initial', 83 | name: 'vendors', 84 | minChunks: 1, 85 | enforce: true 86 | } 87 | } 88 | } 89 | } 90 | }); 91 | -------------------------------------------------------------------------------- /web-console/frontend/webpack/configs/vueLoaderConfig.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack VueJs configurations 4 | */ 5 | 6 | 7 | module.exports = { 8 | loaders: {}, 9 | cssSourceMap: false, 10 | cacheBusting: true, 11 | transformToRequire: { 12 | video: ['frontend', 'poster'], 13 | source: 'frontend', 14 | img: 'frontend', 15 | image: 'xlink:href' 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /web-console/frontend/webpack/externalFiles.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack files to exports for copy files plugin 4 | */ 5 | 6 | // Helpers 7 | const {move_to} = require('./helpers'); 8 | 9 | 10 | // Configurations to copy external files 11 | module.exports = (outputPath) => { 12 | // External img files 13 | const imgExtFiles = move_to(`${outputPath}/img/`, [ 14 | 'src/img/logo.png', 15 | 'src/img/image.png' 16 | ]); 17 | // Favicon 18 | const icoExtFiles = move_to(`${outputPath}/`, ['src/img/favicon.ico']); 19 | // Return concatenated in an unique array 20 | return [ 21 | ...imgExtFiles, 22 | ...icoExtFiles 23 | ]; 24 | } -------------------------------------------------------------------------------- /web-console/frontend/webpack/helpers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack helpers 4 | */ 5 | 6 | // Move source files as is to another directory 7 | const move_to = (outputPath, files, force=true) => files.map(f => ({from: f, to: outputPath, force: force})); 8 | 9 | module.exports = { 10 | move_to 11 | }; 12 | -------------------------------------------------------------------------------- /web-console/frontend/webpack/plugins.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | /* 3 | Webpack plugins 4 | */ 5 | 6 | // Requirements 7 | const webpack = require('webpack'); 8 | const CopyWebpackPlugin = require('copy-webpack-plugin'); 9 | const CleanWebpackPlugin = require('clean-webpack-plugin'); 10 | const VueLoaderPlugin = require('vue-loader/lib/plugin'); 11 | const MiniCssExtractPlugin = require('mini-css-extract-plugin'); 12 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 13 | 14 | 15 | // External files for copy plugin 16 | const externalFiles = require('./externalFiles'); 17 | 18 | 19 | // Webpack plugins 20 | module.exports = (rootPath, outputPath) => { 21 | 22 | // Webpack plugins 23 | return [ 24 | // This plugin will be removed in the future as it only exists for migration 25 | new webpack.LoaderOptionsPlugin({ 26 | debug: true 27 | }), 28 | new CleanWebpackPlugin(['dist', 'build'], { 29 | root: rootPath, 30 | exclude: [], // file to exclude 31 | verbose: true, 32 | dry: false 33 | }), 34 | // Add npm packages to bundle 35 | new webpack.ProvidePlugin({ 36 | $: 'jquery', 37 | jQuery: 'jquery', 38 | 'window.$': 'jquery', 39 | 'window.jQuery': 'jquery', 40 | Popper: ['popper.js', 'default'], 41 | moment: 'moment', 42 | toastr: 'toastr' 43 | }), 44 | // Copy files as is to another directory 45 | new CopyWebpackPlugin( 46 | externalFiles(outputPath) 47 | ), 48 | new VueLoaderPlugin(), 49 | // Extract css to make a separated bundle file 50 | new MiniCssExtractPlugin({ 51 | filename: 'css/[name].[hash].css', 52 | chunkFilename: 'css/[id].[hash].css' 53 | }), 54 | // Inject the js and css files 55 | new HtmlWebpackPlugin({ 56 | inject: true, 57 | template: `${rootPath}/src/index.html`, 58 | filename: 'index.html' 59 | }) 60 | ]; 61 | 62 | } 63 | --------------------------------------------------------------------------------