1
0
forked from circlecloud/tera

feat: first commit

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-07-10 12:01:15 +08:00
commit cbc0ed72c4
134 changed files with 47644 additions and 0 deletions

40
.gitignore vendored Normal file
View File

@ -0,0 +1,40 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
**/node_modules
# roadhog-api-doc ignore
/src/utils/request-temp.js
_roadhog-api-doc
# production
/dist
/.vscode
# misc
.DS_Store
npm-debug.log*
yarn-error.log
/coverage
.idea
yarn.lock
package-lock.json
*bak
.vscode
# visual studio code
.history
*.log
functions/*
.temp/**
# umi
.umi
.umi-production
# screenshot
screenshot
.firebase
.eslintcache
build

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"devDependencies": {
"@types/node": "^12.6.1",
"typescript": "^3.5.3"
}
}

162
src/HTML/123 Normal file
View File

@ -0,0 +1,162 @@
‘à ¢­¥­¨¥ ä ©«®¢ mobile-wallet.html ¨ _MOBILE-WALLET.HTML
***** mobile-wallet.html
<a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome">
<!--<img src="./PIC/Tera_logo2.svg" alt="Tera logo" height="25" width="104">-->
<svg width="104" height="25" viewBox="0 0 105 25" fill="none" xmlns="http://www.w3.org/2000/svg">
***** _MOBILE-WALLET.HTML
<a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome">
<svg width="104" height="25" viewBox="0 0 105 25" fill="none" xmlns="http://www.w3.org/2000/svg">
*****
***** mobile-wallet.html
<div class="welcome__img">
<svg class="mobile" id="tera-logo" height="126" width="130" fill="#445368" xmlns="http://www.w3.org/2000/svg" viewB
ox="0 0 992.13 992.13">
***** _MOBILE-WALLET.HTML
<div class="welcome__img">
<svg class="mobile" id="tera-logo" height="104" width="107" fill="#445368" xmlns="http://www.w3.org/2000/svg" viewB
ox="0 0 992.13 992.13">
*****
***** mobile-wallet.html
<textarea name="private-key" id="idPrivKeyEdit" placeholder="Insert your private key or generate a new key below...
" class="key-field__textarea" oninput="OnEditPrivKey()">
</textarea>
***** _MOBILE-WALLET.HTML
<textarea name="private-key"
id="idPrivKeyEdit"
placeholder="Insert your private key or generate a new key below..."
class="key-field__textarea"
oninput="OnEditPrivKey()">
</textarea>
*****
***** mobile-wallet.html
<select size="1" id="idAccountCur" class="bigs key-field__input key-field__input--select">
<option value="0">TERA</option>
***** _MOBILE-WALLET.HTML
<select size="1" id="idAccountCur" class="bigs key-field__input">
<option value="0">TERA</option>
*****
***** mobile-wallet.html
<p class="key-field__title">From:</p>
<button onclick="SetAllSum()" title="Paste total amount" class="key-field__btn btn-no-bg no-mr" style="padding:
0; margin-left: 10px;">
<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 1H3C1.89543 1 1 1.89543 1 3V15C1 16.1046 1.89543 1
7 3 17H15C16.1046 17 17 16.1046 17 15V3C17 1.89543 16.1046 1 15 1ZM3 0C1.34315 0 0 1.34315 0 3V15C0 16.6569 1.34315 18 3 18H15C
16.6569 18 18 16.6569 18 15V3C18 1.34315 16.6569 0 15 0H3ZM6.64645 10.6464C6.84171 10.4512 7.15829 10.4512 7.35355 10.6464L9.5
12.7929V6C9.5 5.17157 8.82843 4.5 8 4.5H6C5.72386 4.5 5.5 4.27614 5.5 4C5.5 3.72386 5.72386 3.5 6 3.5H8C9.38071 3.5 10.5 4.6192
9 10.5 6V12.7929L12.6464 10.6464C12.8417 10.4512 13.1583 10.4512 13.3536 10.6464C13.5488 10.8417 13.5488 11.1583 13.3536 11.353
6L10.3536 14.3536L10 14.7071L9.64645 14.3536L6.64645 11.3536C6.45118 11.1583 6.45118 10.8417 6.64645 10.6464Z"/>
</svg>
</button>
<select size="1" id="idAccount" class="key-field__select" oninput="OnEditTransactionFields(); CheckSending();">
***** _MOBILE-WALLET.HTML
<p class="key-field__title">From:</p>
<select size="1" id="idAccount" class="key-field__select" oninput="OnEditTransactionFields(); CheckSending();">
*****
***** mobile-wallet.html
<label for="idTo" class="key-field__title">Pay to:</label>
<span id="idNameTo2" style="margin: 5px 10px 0 15px"></span>
<!--<button class="key-field__btn btn-no-bg">Paste</button>-->
***** _MOBILE-WALLET.HTML
<label for="idTo" class="key-field__title">Pay to:</label>
<span id="idNameTo2" style="margin: 0 10px 0 0"></span>
<!--<button class="key-field__btn btn-no-bg">Paste</button>-->
*****
***** mobile-wallet.html
<!--<b>2 000 000 000,00000000</b>-->
<input type="number"
***** _MOBILE-WALLET.HTML
<!--<b>2 000 000 000,00000000</b>-->
<button onclick="SetAllSum()" title="Paste total amount" class="key-field__btn btn-no-bg no-mr" style="padding:
0; margin-left: 10px;">
<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 1H3C1.89543 1 1 1.89543 1 3V15C1 16.1046 1.89543 1
7 3 17H15C16.1046 17 17 16.1046 17 15V3C17 1.89543 16.1046 1 15 1ZM3 0C1.34315 0 0 1.34315 0 3V15C0 16.6569 1.34315 18 3 18H15C
16.6569 18 18 16.6569 18 15V3C18 1.34315 16.6569 0 15 0H3ZM6.64645 10.6464C6.84171 10.4512 7.15829 10.4512 7.35355 10.6464L9.5
12.7929V6C9.5 5.17157 8.82843 4.5 8 4.5H6C5.72386 4.5 5.5 4.27614 5.5 4C5.5 3.72386 5.72386 3.5 6 3.5H8C9.38071 3.5 10.5 4.6192
9 10.5 6V12.7929L12.6464 10.6464C12.8417 10.4512 13.1583 10.4512 13.3536 10.6464C13.5488 10.8417 13.5488 11.1583 13.3536 11.353
6L10.3536 14.3536L10 14.7071L9.64645 14.3536L6.64645 11.3536C6.45118 11.1583 6.45118 10.8417 6.64645 10.6464Z"/>
</svg>
</button>
<input type="number"
*****
***** mobile-wallet.html
<label for="idDescription" class="key-field__title">Description:</label>
<textarea name="description" id="idDescription" rows="2" placeholder="Optional..." class="key-field__textarea"
oninput="CheckLengthAccDesription('idDescription',200); OnEditTransactionFields()">
</textarea>
***** _MOBILE-WALLET.HTML
<label for="idDescription" class="key-field__title">Description:</label>
<textarea name="description"
id="idDescription"
rows="2"
placeholder="Optional..."
class="key-field__textarea"
oninput="CheckLengthAccDesription('idDescription',200);OnEditTransactionFields()">
</textarea>
*****
***** mobile-wallet.html
<div class="dapps-page__pagination page-pagination">
<button onclick="ViewBegin(DefDapps)" class="btn dapps-page__page-btns">| &lt;</button>
<button onclick="ViewPrev(DefDapps)" class="btn dapps-page__page-btns">&lt;</button>
***** _MOBILE-WALLET.HTML
<div class="dapps-page__pagination page-pagination">
<button onclick="ViewBegin(DefDapps)" class="btn dapps-page__page-btns">|&lt;</button>
<button onclick="ViewPrev(DefDapps)" class="btn dapps-page__page-btns">&lt;</button>
*****
***** mobile-wallet.html
<button onclick="ViewNext(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt;</button>
<button onclick="ViewEnd(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt; |</button>
</div>
***** _MOBILE-WALLET.HTML
<button onclick="ViewNext(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt;</button>
<button onclick="ViewEnd(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt;|</button>
</div>
*****
***** mobile-wallet.html
<div class="explorer-page__table-wrap">
<table id="dapps_list" class="grid dapps__table">
<tr>
***** _MOBILE-WALLET.HTML
<div class="explorer-page__table-wrap">
<table id="dapps_list" class="grid">
<tr>
*****
***** mobile-wallet.html
<div class="prod-card__heading">
<a href="#" class="prod-card__link" onclick="OpenDapp(Item.Num)">Item.Name</a>
<!--<span class="lighter-grey-text">Without token generate</span>-->
***** _MOBILE-WALLET.HTML
<div class="prod-card__heading">
Item.Name
<!--<span class="lighter-grey-text">Without token generate</span>-->
*****
***** mobile-wallet.html
<div class="prod-card__second-line-img">
<a href="#" class="prod-card__link" onclick="OpenDapp(Item.Num)"><img src="Item.IconPath" alt="dApp
logo" width="32"></a>
</div>
***** _MOBILE-WALLET.HTML
<div class="prod-card__second-line-img">
<img src="Item.IconPath" alt="dApp logo" width="32">
</div>
*****

View File

@ -0,0 +1,440 @@
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700&subset=cyrillic');
:root {
--blue-grey: #445368;
--light-blue: #718CAF;
}
body {
margin: 0 auto;
box-sizing: border-box;
font-family: "Roboto", "Arial", sans-serif;
color: #445368;
background: #f2f2f2;
}
main {
max-width: 1200px;
margin: 0 auto;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
*::placeholder {
color: rgba(0, 0, 0, 0.5);
font-family: "Roboto";
font-size: 16px;
}
a {
text-decoration: none;
color: #445368;
}
a:hover,
a:focus {
color: #718CAF;
}
.hidden {
display: none;
}
.btn {
color: #fff;
background: #445368;
display: block;
padding: 15px 25px;
border: none;
box-shadow: 0px 5px 10px rgba(68, 83, 104, 0.3);
border-radius: 4px;
text-decoration: none;
text-transform: uppercase;
font-family: inherit;
font-weight: 500;
font-size: 18px;
line-height: 21px;
cursor: pointer;
text-align: center;
}
.btn:hover,
.btn:focus {
background: #718CAF;
color: #fff;
}
.btn[disabled],
.btn.disabled {
opacity: .3;
cursor: not-allowed;
}
.reconnect {
background-image: url("./../PIC/reload.svg");
background-repeat: no-repeat;
background-size: 18px 18px;
background-position: center center;
padding: 5px;
width: 27px;
margin-left: 5px;
}
.reconnect span {
display: none;
}
.grey-btn {
border: none;
background: #F2F2F2;
border-radius: 3px;
font-family: inherit;
font-size: 14px;
line-height: 16px;
color: #000;
height: 27px;
white-space: nowrap;
}
.header {
background: linear-gradient(270deg, #3D4C61 0%, #445368 100%);
color: #fff;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);
}
.header__wrapper {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
height: 100%;
}
.header__logo {
margin-right: 2px;
padding: 0 15px;
}
.header__logo-link:hover {
opacity: .5;
cursor: pointer;
}
.header__right {
display: flex;
align-items: center;
position: relative;
}
.header__right select {
/* background: var(--blue-grey); */
background: transparent;
border: none;
color: #fff;
padding: 5px;
width: 55px;
font-family: inherit;
font-size: 12px;
line-height: 14px;
}
.white-select {
display: none;
}
.header__nav {
width: 100%;
}
.page-pagination {
display: flex;
justify-content: center;
padding-bottom: 15px;
padding-right: 15px;
}
.page-pagination__num {
width: 33%;
margin: 0 5px;
}
.page-pagination .btn {
padding: 0;
white-space: nowrap;
width: 45px;
height: 40px;
margin: 0 5px;
}
.page-pagination .btn:first-of-type {
margin-left: 0;
}
.page-pagination .btn:last-of-type {
margin-right: 0;
}
.back-link {
cursor: pointer;
position: relative;
width: 30px;
}
.back-link span {
display: none;
}
.back-link::before {
content: '';
display: block;
color: var(--blue-grey);
background: url("./../PIC/right-arrow.svg") no-repeat;
background-size: 18px 18px;
transform: translateY(-50%) rotate(180deg);
height: 18px;
width: 18px;
position: absolute;
left: 15px;
top: 50%;
}
.back-link:hover::before,
.back-link:focus::before {
opacity: .5;
}
.back-link--history {
position: absolute;
top: 15px;
font-size: 16px;
line-height: 19px;
font-weight: 400;
text-decoration: none;
}
.back-link--history::before {
left: 0;
}
.back-link--history span {
display: block;
padding-left: 23px;
}
.header__logo--history {
padding: 10px 15px;
}
.history-page {
position: relative;
padding-bottom: 110px;
}
.history__text-block {
padding: 65px 15px 10px;
}
.history-page__id {
margin-bottom: 7px;
font-size: 20px;
line-height: 23px;
font-weight: 700;
color: #445368;
}
.history-page__id-count {
max-width: 140px;
margin-left: 2px;
font-size: 20px;
line-height: 23px;
font-weight: 700;
text-align-last: left;
color: #445368;
border: none;
background: #f2f2f2;
}
.history-page__description {
margin: 0;
margin-bottom: 17px;
font-size: 12px;
line-height: 14px;
color: rgba(0, 0, 0, 0.5);
}
.history-page__balance {
display: flex;
align-items: center;
font-size: 14px;
line-height: 16px;
font-weight: 700;
}
.history-page__tera-icon {
margin-left: 5px;
}
.history-page__table {
padding: 15px 0 15px 15px;
background-color: #ffffff;
}
.history-page__table .grid {
width: 100%;
border-collapse: collapse;
}
.history-page__table-wrap {
overflow-x: auto;
}
.history-page__table th {
background: var(--blue-grey);
color: #fff;
border-right: 1px solid rgba(0, 0, 0, 0.1);
height: 30px;
padding: 0 20px 0 10px;
font-size: 16px;
line-height: 19px;
font-weight: 400;
white-space: nowrap;
text-align-last: left;
}
.history-page__table th:first-child {
border-top-left-radius: 5px;
}
.history-page__table th:last-child {
border-top-right-radius: 5px;
}
.history-page__table .grid tr td {
padding: 8px 10px 6px;
font-size: 14px;
line-height: 16px;
white-space: nowrap;
color: #000000;
background-color: #ffffff;
border: 1px solid #C4C4C4;
}
.history-page__table .grid tr td:first-of-type {
text-align: center;
}
.history-page__table .grid tr td.code
{
white-space: normal;
width: 340px;
min-width:200px;
font-family: "courier new", "times new roman", monospace;
font-size: small;
word-break: break-all;
}
.history-page__table .grid tr td.hash
{
white-space: normal;
width: 160px;
font-family: "courier new", "times new roman", monospace;
font-size: small;
word-break: break-all;
}
@media (min-width: 576px) {
.history__text-block {
padding: 65px 33px 10px;
}
.history-page__table {
padding: 15px 33px;
}
.back-link::before {
left: 0;
}
}
@media (min-width: 768px) {
.header {
height: 60px;
}
.fixed-status .grey-btn {
height: 40px;
padding: 10px;
}
.reconnect {
width: 40px;
margin-left: 15px;
background-position: 11px 11px;
}
.main-logo {
width: 125px;
height: 30px;
}
.back-link {
display: block;
padding-left: 34px;
}
.back-link span {
display: inline;
text-decoration: underline;
}
.back-link::before {
left: 0;
}
.back-link--history span {
padding-left: 0;
}
}
@media (min-width: 960px) {
.header__logo {
padding-left: 20px;
}
.reconnect.grey-btn {
width: 130px;
margin-left: 15px;
padding-top: 12px;
padding-left: 39px;
background-position: 11px 11px;
}
.reconnect span {
display: inline;
}
.history-page {
padding-right: 40px;
padding-left: 40px;
}
.history__text-block {
padding: 65px 0 10px;
}
.history-page__table {
padding: 15px 0 10px;
}
}
@media (min-width: 1200px) {
.header__wrapper {
max-width: 1150px;
margin: 0 auto;
}
.history__text-block {
padding-top: 60px;
padding-bottom: 0;
}
.history-page__id {
font-size: 28px;
line-height: 33px;
text-align: center;
}
.history-page__id-count {
font-size: 28px;
line-height: 33px;
text-align: center;
}
.history-page__description {
margin-bottom: 30px;
font-size: 16px;
line-height: 19px;
text-align: center;
}
.history-page__balance {
justify-content: center;
margin-bottom: 30px;
font-size: 16px;
line-height: 19px;
}
.history-page__table {
padding: 30px 15px;
border: 1px solid rgba(0, 0, 0, 0.1);
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
}
.page-pagination {
padding-bottom: 20px;
}
}

201
src/HTML/CSS/buttons.css Normal file
View File

@ -0,0 +1,201 @@
/*Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons Buttons*/
/*TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader TabHeader*/
#TabHeader th
{
/*border: 1px solid black;*/
width:205px;
color: white;
background-color: #22547f;
margin: 0;
padding: 0;
height: 34px;
}
.bttab
{
background-color: black;
vertical-align: middle;
cursor: pointer;
color: white;
width: 100%;
margin: 0;
padding-top: 7px;
height: 100%;
}
/*User action*/
.btdoit
{
width: 130px;
height: 32px;
line-height: 20px;
margin: 10px;
cursor: pointer;
font-family: monospace;
}
.btdoitm
{
width: 40px;
height: 32px;
line-height: 20px;
margin: 10px;
cursor: pointer;
font-family: monospace;
}
/*All buttons*/
.bt
{
border: 1px solid black;
background: transparent;
font-weight: 400;
cursor: pointer;
}
.bt:hover,button:hover
{
filter: brightness(120%);
cursor: pointer;
}
.bt:active
{
cursor: progress;
}
.btlong
{
width: 160px;
}
.btopen
{
width: 136px;
}
.btsmall
{
width: 10px;
}
#idSendList
{
width: 800px;
border: 0 solid black;
font-weight: 700;
}
#PaiListInfo
{
width: 800px;
height:20px;
text-align: center;
}
.btinvoice
{
width: 133px;
min-width: 133px;
max-width: 133px;
height:40px;
white-space: pre-line;
background-image: url('/HTML/PIC/invoice.png');
background-repeat: no-repeat;
background-size: 16px;
}
.btinvoice_use
{
width: 110px;
min-width: 110px;
max-width: 110px;
height:62px;
}
#idCounters
{
background-image: url('/HTML/PIC/counters.png');
background-repeat: no-repeat;
background-size: 16px;
}
#idChains
{
background-image: url('/HTML/PIC/chains.png');
background-repeat: no-repeat;
background-size: 16px;
}
#idMonitor
{
background-image: url('/HTML/PIC/monitor.png');
background-repeat: no-repeat;
background-size: 16px;
}
#idConsole
{
background-image: url('/HTML/PIC/console.png');
background-repeat: no-repeat;
background-size:16px;
}
#idOpenSmart
{
background-image: url('/HTML/PIC/smart.png');
background-repeat: no-repeat;
background-size:16px;
}
#idNetwork
{
background-image: url('/HTML/PIC/network.png');
background-repeat: no-repeat;
background-size:16px;
}
#idDown
{
background-image: url('/HTML/PIC/down.png');
background-repeat: no-repeat;
background-size: 16px;
background-position: right;
}
#idUp
{
background-image: url('/HTML/PIC/up.png');
background-repeat: no-repeat;
background-size: 16px;
background-position: right;
box-shadow: 0 2px 2px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(82, 168, 236, 1);
}
.btexlporer
{
width: 136px;
}
input[type="checkbox"]
{
vertical-align: middle;
}

90
src/HTML/CSS/codes.css Normal file
View File

@ -0,0 +1,90 @@
/*
Google Code style (c) Aahan Krish <geekpanth3r@gmail.com>
Some correct by vtools
*/
.hljs {
display: block;
overflow-x: auto;
padding: 0.5em;
background: #eff5eb;
color: black;
}
.hljs-comment,
.hljs-quote {
color: #800;
}
.hljs-keyword,
.hljs-selector-tag,
.hljs-section,
.hljs-title,
.hljs-name {
color: #008;
}
.hljs-variable,
.hljs-template-variable {
color: #660;
}
.hljs-string,
.hljs-selector-attr,
.hljs-selector-pseudo,
.hljs-regexp {
color: #080;
}
.hljs-literal,
.hljs-symbol,
.hljs-bullet,
.hljs-meta,
.hljs-number,
.hljs-link {
color: #066;
}
.hljs-title,
.hljs-doctag,
.hljs-type,
.hljs-attr,
.hljs-built_in,
.hljs-builtin-name,
.hljs-params {
color: #606;
}
.hljs-attribute,
.hljs-subst {
color: #000;
}
.hljs-formula {
background-color: #eee;
font-style: italic;
}
.hljs-selector-id,
.hljs-selector-class {
color: #9B703F
}
.hljs-addition {
background-color: #baeeba;
}
.hljs-deletion {
background-color: #ffc8bd;
}
.hljs-doctag,
.hljs-strong {
font-weight: bold;
}
.hljs-emphasis {
font-style: italic;
}

440
src/HTML/CSS/history.css Normal file
View File

@ -0,0 +1,440 @@
@import url('https://fonts.googleapis.com/css?family=Roboto:400,500,700&subset=cyrillic');
:root {
--blue-grey: #445368;
--light-blue: #718CAF;
}
body {
margin: 0 auto;
box-sizing: border-box;
font-family: "Roboto", "Arial", sans-serif;
color: #445368;
background: #f2f2f2;
}
main {
max-width: 1200px;
margin: 0 auto;
}
*,
*::before,
*::after {
box-sizing: inherit;
}
*::placeholder {
color: rgba(0, 0, 0, 0.5);
font-family: "Roboto";
font-size: 16px;
}
a {
text-decoration: none;
color: #445368;
}
a:hover,
a:focus {
color: #718CAF;
}
.hidden {
display: none;
}
.btn {
color: #fff;
background: #445368;
display: block;
padding: 15px 25px;
border: none;
box-shadow: 0px 5px 10px rgba(68, 83, 104, 0.3);
border-radius: 4px;
text-decoration: none;
text-transform: uppercase;
font-family: inherit;
font-weight: 500;
font-size: 18px;
line-height: 21px;
cursor: pointer;
text-align: center;
}
.btn:hover,
.btn:focus {
background: #718CAF;
color: #fff;
}
.btn[disabled],
.btn.disabled {
opacity: .3;
cursor: not-allowed;
}
.reconnect {
background-image: url("./../PIC/reload.svg");
background-repeat: no-repeat;
background-size: 18px 18px;
background-position: center center;
padding: 5px;
width: 27px;
margin-left: 5px;
}
.reconnect span {
display: none;
}
.grey-btn {
border: none;
background: #F2F2F2;
border-radius: 3px;
font-family: inherit;
font-size: 14px;
line-height: 16px;
color: #000;
height: 27px;
white-space: nowrap;
}
.header {
background: linear-gradient(270deg, #3D4C61 0%, #445368 100%);
color: #fff;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.15);
}
.header__wrapper {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
height: 100%;
}
.header__logo {
margin-right: 2px;
padding: 0 15px;
}
.header__logo-link:hover {
opacity: .5;
cursor: pointer;
}
.header__right {
display: flex;
align-items: center;
position: relative;
}
.header__right select {
/* background: var(--blue-grey); */
background: transparent;
border: none;
color: #fff;
padding: 5px;
width: 55px;
font-family: inherit;
font-size: 12px;
line-height: 14px;
}
.white-select {
display: none;
}
.header__nav {
width: 100%;
}
.header__wallet-set {
margin-left: 5px;
}
.header__wallet-link {
color: rgba(255, 255, 255, 0.6);
display: block;
padding: 13px 15px 9px 15px;
}
.header__wallet-link:hover,
.header__wallet-link:focus {
background: #55657C;
}
.header__wallet-link span {
display: none;
}
.header__wallet-link:active,
.header__wallet-link.active {
box-shadow: inset 0px 4px 0px rgba(255, 255, 255, 0.25);
}
.dapps-page__pagination,
.page-pagination {
display: flex;
justify-content: center;
padding-bottom: 15px;
padding-right: 15px;
}
.page-pagination__num {
width: 33%;
margin: 0 5px;
}
.page-pagination .btn {
padding: 0;
white-space: nowrap;
width: 45px;
height: 40px;
margin: 0 5px;
}
.page-pagination .btn:first-of-type {
margin-left: 0;
}
.page-pagination .btn:last-of-type {
margin-right: 0;
}
.back-link {
position: relative;
width: 30px;
cursor: pointer;
}
.back-link span {
display: none;
}
.back-link::before {
content: '';
display: block;
color: var(--blue-grey);
background: url("./../PIC/right-arrow.svg") no-repeat;
background-size: 18px 18px;
transform: translateY(-50%) rotate(180deg);
height: 18px;
width: 18px;
position: absolute;
left: 15px;
top: 50%;
}
.back-link:hover::before,
.back-link:focus::before {
opacity: .5;
}
.header__logo--history {
padding: 10px 15px;
}
.back-link--history {
position: absolute;
top: 15px;
font-size: 16px;
line-height: 19px;
line-height: 19px;
font-weight: 400;
text-decoration: none;
}
.back-link--history::before {
left: 0;
}
.back-link--history span {
display: block;
padding-left: 23px;
}
.history-page {
padding-bottom: 110px;
}
.history__text-block {
position: relative;
padding: 10px 15px 10px;
}
.history-page__id {
margin-bottom: 7px;
font-size: 20px;
line-height: 23px;
font-weight: 700;
color: #445368;
}
.history-page__id-count {
max-width: 140px;
margin-left: 2px;
font-size: 20px;
line-height: 23px;
font-weight: 700;
text-align-last: left;
color: #445368;
border: none;
background: #f2f2f2;
}
.history-page__description {
margin: 0;
margin-bottom: 17px;
font-size: 12px;
line-height: 14px;
color: rgba(0, 0, 0, 0.5);
}
.history-page__balance {
display: flex;
align-items: center;
font-size: 14px;
line-height: 16px;
font-weight: 700;
}
.history-page__tera-icon {
margin-left: 5px;
}
.history-page__table {
padding: 15px 0 15px 15px;
}
.history-page__table .grid {
width: 100%;
border-collapse: collapse;
}
.history-page__table-wrap {
overflow-x: auto;
}
.history-page__table th {
background: var(--blue-grey);
color: #fff;
border-right: 1px solid rgba(0, 0, 0, 0.1);
height: 30px;
padding: 0 20px 0 10px;
font-size: 16px;
line-height: 19px;
font-weight: 400;
white-space: nowrap;
text-align-last: left;
}
.history-page__table th:first-child {
border-top-left-radius: 5px;
}
.history-page__table th:last-child {
border-top-right-radius: 5px;
}
.history-page__table .grid tr td {
padding: 2px 10px 0px;
font-size: 14px;
line-height: 16px;
color: #000000;
background-color: #ffffff;
border: 1px solid #C4C4C4;
}
.history-page__table .grid tr th.direct {
max-width:30px;
}
.history-page__table .grid tr td.date
{
white-space: nowrap;
}
.history-page__table .grid tr td:first-of-type {
text-align: center;
}
.history-page__table .grid tr td:first-of-type b {
font-size: 16px!important;
font-weight: 700!important;
}
.history-page__table .grid tr td.desc {
max-width: 170px;
word-break: break-all;
}
@media (min-width: 576px) {
.history__text-block {
padding: 10px 33px 10px;
}
.history-page__table {
padding: 15px 33px;
}
.back-link::before {
left: 0;
}
}
@media (min-width: 768px) {
.header {
height: 60px;
}
.main-logo {
width: 125px;
height: 30px;
}
.back-link {
display: block;
padding-left: 34px;
}
.back-link span {
display: inline;
text-decoration: underline;
}
.back-link::before {
left: 0;
}
.back-link--history span {
padding-left: 0;
}
}
@media (min-width: 960px) {
.header__logo {
padding-left: 20px;
}
.history-page {
padding-right: 40px;
padding-left: 40px;
}
.history__text-block {
padding: 10px 0 10px;
}
.history-page__table {
padding: 15px 0 10px;
}
}
@media (min-width: 1200px) {
.header__wrapper {
max-width: 1150px;
margin: 0 auto;
}
.history__text-block {
padding-top: 10px;
padding-bottom: 0;
}
.history-page__id {
font-size: 28px;
line-height: 33px;
text-align: center;
}
.history-page__id-count {
font-size: 28px;
line-height: 33px;
text-align: center;
}
.history-page__description {
margin-bottom: 20px;
font-size: 16px;
line-height: 19px;
min-height: 20px;
text-align: center;
}
.history-page__balance {
justify-content: center;
margin-bottom: 30px;
font-size: 16px;
line-height: 19px;
}
.history-page__table {
padding: 30px 15px;
border: 1px solid rgba(0, 0, 0, 0.1);
box-shadow: 0px 3px 5px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
}
.page-pagination {
padding-bottom: 20px;
}
}

File diff suppressed because it is too large Load Diff

180
src/HTML/CSS/style.css Normal file
View File

@ -0,0 +1,180 @@
/*STYLE STYLE STYLE*/
/*STYLE STYLE STYLE*/
/*STYLE STYLE STYLE*/
/*STYLE STYLE STYLE*/
root
{
--colorText:#000;
}
body
{
font-family: Arial, sans-serif;
font-size: 15px;
font-weight: 300;
}
body.styleBrown
{
--color0:#503F13;
--color1:#86754A;
--color2:#F5E5BB;
--color3:#F5F0E3;
}
body.styleGreen
{
--color0:#204410;
--color1:#4F7340;
--color2:#CBF4BA;
--color3:#E7F4E1;
}
body.styleBlue
{
--color0:#0D1B35;
--color1:#354259;
--color2:#BED0F2;
--color3:#E1E7F2;
}
body.styleGray
{
--color0:#424a5D;
--color1:#5b6775;
--color2:#FFFFFF;
--color3:#f3f3f4;
}
body.styleContrast1
{
--color0:#101010;
--color1:#303030;
--color2: #b3cee8;
--color3:#FFFFFF;
}
body.styleContrast2
{
--color0:#101010;
--color1:#303030;
--color2: #cee8df;
--color3:#FFFFFF;
}
body.styleContrast3
{
--color0:#101010;
--color1:#303030;
--color2: #e8e0d4;
--color3:#FFFFFF;
}
body.univers .bt
{
background: var(--color1);
color: var(--color2);
}
body.univers
{
background: var(--color2);
}
body.univers table.grid
{
background:var(--color3);
}
body.univers .bttab
{
background: var(--color1);
color:white;
}
body.univers .current
{
background: var(--color0);
color:white;
}
body.univers input,textarea,select
{
background:white;
color: black;
}
/*dark*/
body.styleDark
{
background: #282828;
--colorText:white;
color: white;
}
body.styleDark .bt
{
background: #4c4c4c;
color: white;
border: 1px solid #5a5a5a;
}
body.styleDark .header_tr
{
color:white;
}
body.styleDark table.grid
{
background: #565656;
}
body.styleDark .bttab
{
background: #202225;
color:white;
}
body.styleDark .current
{
background: #565b61;
color:white;
}
body.styleDark input,textarea,select
{
background:white;
color: black;
}
/*bt*/
body.styleDark button
{
background: #939393;
border: 1px solid #282828;
color: white;
}
body.styleDark .bold
{
font-weight: 300;
}
body.styleDark #idStatus
{
color: #fffabd;
}
body.styleDark #idOpenWallet
{
border: 1px solid darkgrey;
}

535
src/HTML/CSS/wallet.css Normal file
View File

@ -0,0 +1,535 @@

/*Списки*/
table
{
border-collapse: collapse;
width:100%;
max-width: 800px
}
.grid th, .grid td
{
border: 1px solid #264378;
padding: 4px;
}
.grid td
{
width: 60px;
vertical-align:top;
}
.bold
{
font-weight: 700;
}
.smallbold
{
font-weight: 600;
}
td.sum
{
text-align: right;
width: 120px;
}
td.num
{
text-align: right;
width: 50px;
}
td.cur
{
text-align: left;
width: 50px;
font-size:smaller;
}
td.snum
{
text-align: center;
width: 20px;
}
td.direct
{
text-align: center;
vertical-align: middle;
width: 10px;
font-weight: 700;
font-size:x-large;
}
td.smart
{
text-align: right;
width: 150px;
max-width: 200px;
}
td.txt
{
text-align: left;
width: 100px;
}
td.desc
{
text-align: left;
width: 200px;
max-width: 200px;
word-break: break-all;
}
td.name
{
text-align: left;
width: 100px;
}
td.date
{
text-align: left;
width: 90px;
min-width: 70px;
font-size: small;
}
/*SEND SEND SEND SEND SEND SEND SEND SEND SEND SEND */
table.form_input
{
border-collapse: collapse;
width: 600px;
}
.form_input td
{
width: 20%;
}
.form_input td:nth-child(2)
{
width: 80%;
}
.form_input input, .form_input select
{
width: 98%;
text-align: right;
}
.form_input textarea
{
width: 98%;
text-align: left;
}
.form_input .bsend
{
width: 33%;
height: 30px;
text-align: center;
float: left;
}
.short_input input
{
width: 120px;
}
td.code
{
width: 240px;
font-family: "courier new", "times new roman", monospace;
font-size: small;
align-content: left;
text-align: left;
word-break: break-all;
}
td.code2
{
width: 340px;
font-family: "courier new", "times new roman", monospace;
font-size: small;
align-content: left;
text-align: left;
word-break: break-all;
}
.hash
{
width: 250px;
min-width: 100px;
font-family: "courier new", "times new roman", monospace;
font-size: 60%;
align-content: left;
text-align: left;
word-break: break-all;
}
.pubkey
{
width: 180px;
font-family: "courier new", "times new roman", monospace;
font-size: 75%;
align-content: left;
text-align: left;
word-break: break-all;
}
.accname
{
width: 180px;
font-family: Cambria,sans-serif;
align-content: left;
text-align: left;
word-break: break-all;
}
.verify
{
}
/*CHECKBOX*/
.checkbox
{
position: absolute;
z-index: -1;
opacity: 0;
margin: 10px 0 0 20px;
}
.checkbox + label
{
position: relative;
padding: 0 20px 0 55px;
cursor: pointer;
}
.checkbox + label:before
{
content: '';
position: absolute;
top: -4px;
left: 0;
width: 50px;
height: 26px;
border-radius: 13px;
background: #CDD1DA;
box-shadow: inset 0 2px 3px rgba(0,0,0,.2);
transition: .2s;
}
.checkbox + label:after
{
content: '';
position: absolute;
top: -2px;
left: 2px;
width: 22px;
height: 22px;
border-radius: 10px;
background: #FFF;
box-shadow: 0 2px 5px rgba(0,0,0,.3);
transition: .2s;
}
.checkbox:checked + label:before
{
background: #46b319;
}
.checkbox_red:checked + label:before
{
background: darkred;
}
.checkbox_alert + label:before
{
background: #f0b323;
}
.checkbox:checked + label:after
{
left: 26px;
}
.checkbox:focus + label:before
{
box-shadow: inset 0 2px 3px rgba(0,0,0,.2), 0 0 0 3px rgba(217, 217, 217, 0.7);
}
#idPercentMining
{
width: 40px;
text-align: center;
display:inline-block;
}
#idNodeWhiteList
{
width: 780px;
}
#idTotalSum
{
text-align: left;
}
/*CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG CONFIG*/
/*Просмотр ключей*/
table.keys
{
border-collapse: collapse;
width: 800px;
}
/*Редактирование приватного ключа*/
#grid_edit_key .bt
{
width: 80px;
height: 30px;
line-height: 20px;
margin: 10px;
text-align: center;
}
#idTypeKey,#idShortNameText
{
width: 250px;
height: 20px;
text-align: left;
}
/*Редактирование new acc Name*/
#grid_edit_newacc .bt, #grid_mining_set .bt, #idTablePassword1 .bt, #idTablePassword2 .bt
{
width: 80px;
height: 30px;
line-height: 20px;
margin: 10px;
text-align: center;
}
#idAutoSetMining
{
width: 16px;
height: 16px;
text-align: left;
top: 3px;
position:relative;
}
#grid_accounts_all, #grid_history
{
font-size: smaller;
}
#grid_history .red td
{
color: darkred;
}
#grid_history .blue td
{
color: darkblue;
}
#grid_history .green td
{
color: darkgreen;
}
/*idStatus Log operations*/
#idStatus
{
z-index:1000;
position:relative;
top:40px;
left:10px;
text-align: left;
width:800px; /* ширина блока */
color:blue;
}
#idServerLog
{
width:100%;
max-width: 800px;
text-align: left;
border: 1px solid black;
height: 220px;
padding: 1px;
margin: 0px;
font-family: "courier new", "times new roman", monospace;
font-size: 80%;
align-content: left;
word-break: break-all;
}
#idTransaction
{
width:100%;
min-width: 795px;
max-width: 795px;
text-align: left;
color:#204410;
}
#idDescription
{
width: 95%;
min-width: 560px;
max-width: 560px;
}
#idAccount
{
width: 100%;
text-align: left;
align-content: left;
}
#idTo
{
width: 99%;
text-align: left;
align-content: left;
}
#idSumSend
{
background-color: #f0ffb9;
font-weight: 700;
width: 75%;
}
#view_header
{
width: 800px;
font-weight: 600;
color: black;
text-align: center;
}
.header_tr
{
width: 600px;
font-weight: 600;
text-align: center;
color:black;
}
#idPaginationHistory, #idPaginationBlock, #idPaginationAccount, #idPaginationAct, #idPaginationHash, #idUtilView, #idPaginationDapps
{
width: 800px;
align-content: center;
text-align: center;
}
#MAIN
{
align-content: left;
}
#idStableScroll
{
z-index:0;
position:absolute;
top:800px;
height: 10px;
color: darkred;
width: 97%;
margin: auto;
}
#idBlockOnSend
{
z-index:100;
position:absolute;
height:170px;
width:380px;
top:20%;
left:0;
transform: translateX(50vw) translateX(-190px);
font-size: larger;
padding: 10px;
background: #2b372d;
color: white;
text-align: left;
border: 1px solid gray;
box-shadow: 0 0 0 2px darkgrey;
border-radius: 8px;
}
#idCheckOnSend
{
font-size: smaller;
position:absolute;
bottom: 10px;
}
.radius
{
border-radius: 4px;
max-height: 34px;
height: 34px;
}
button.radius
{
color:white;
background-color: #337ab7;
border-color: #2e6da4;
width: 100px;
margin: 20px;
}
.bt_open_dapp
{
min-width: 160px;
max-width: 160px;
height: 40px;
min-height: 40px;
vertical-align:middle;
margin: 0;
}
.setsmart
{
color:saddlebrown;
margin: 0;
}
.olink
{
text-decoration: none;
color: var(--colorText);
}
.olink:hover
{
font-weight: bold;
}

View File

@ -0,0 +1,32 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
const ipcRenderer = require('electron').ipcRenderer;
function GetDataElectron(Method,ObjPost,Func)
{
if(Func === undefined)
{
Func = ObjPost;
ObjPost = null;
}
var reply;
try
{
reply = ipcRenderer.sendSync('GetData', {path:Method, obj:ObjPost});
}
catch(e)
{
reply = undefined;
}
if(Func)
Func(reply);
};
window.GetData = GetDataElectron;

1937
src/HTML/JS/client.js Normal file

File diff suppressed because it is too large Load Diff

112
src/HTML/JS/coinlib.js Normal file
View File

@ -0,0 +1,112 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var MAX_SUM_TER = 1e9;
var MAX_SUM_CENT = 1e9;
function ADD(Coin,Value2)
{
Coin.SumCOIN += Value2.SumCOIN;
Coin.SumCENT += Value2.SumCENT;
if(Coin.SumCENT >= MAX_SUM_CENT)
{
Coin.SumCENT -= MAX_SUM_CENT;
Coin.SumCOIN++;
}
return true;
};
function SUB(Coin,Value2)
{
Coin.SumCOIN -= Value2.SumCOIN;
if(Coin.SumCENT >= Value2.SumCENT)
{
Coin.SumCENT -= Value2.SumCENT;
}
else
{
Coin.SumCENT = MAX_SUM_CENT + Coin.SumCENT - Value2.SumCENT;
Coin.SumCOIN--;
}
if(Coin.SumCOIN < 0)
{
return false;
}
return true;
};
function DIV(Coin,Value)
{
Coin.SumCOIN = Coin.SumCOIN / Value;
Coin.SumCENT = Math.floor(Coin.SumCENT / Value);
var SumCOIN = Math.floor(Coin.SumCOIN);
var SumCENT = Math.floor((Coin.SumCOIN - SumCOIN) * MAX_SUM_CENT);
Coin.SumCOIN = SumCOIN;
Coin.SumCENT = Coin.SumCENT + SumCENT;
if(Coin.SumCENT >= MAX_SUM_CENT)
{
Coin.SumCENT -= MAX_SUM_CENT;
Coin.SumCOIN++;
}
return true;
};
function FLOAT_FROM_COIN(Coin)
{
var Sum = Coin.SumCOIN + Coin.SumCENT / MAX_SUM_CENT;
return Sum;
};
function STRING_FROM_COIN(Coin)
{
var Sum = FLOAT_FROM_COIN(Coin);
return Sum.toLocaleString(undefined, {useGrouping:true, style:'decimal', maximumFractionDigits:9});
};
function COIN_FROM_FLOAT(Sum)
{
var SumCOIN = Math.floor(Sum);
var SumCENT = Math.floor((Sum - SumCOIN) * MAX_SUM_CENT);
var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT};
return Coin;
};
function COIN_FROM_FLOAT2(Sum)
{
var SumCOIN = Math.floor(Sum);
var SumCENT = Math.floor(Sum * MAX_SUM_CENT - SumCOIN * MAX_SUM_CENT);
var Coin = {SumCOIN:SumCOIN, SumCENT:SumCENT};
return Coin;
};
if(typeof window === "object")
window.COIN_FROM_FLOAT = COIN_FROM_FLOAT2;
function ISZERO(Coin)
{
if(Coin.SumCOIN === 0 && Coin.SumCENT === 0)
return true;
else
return false;
};
function COIN_FROM_STRING(Str)
{
throw "TODO: COIN_FROM_STRING";
};
if(typeof global === "object")
{
global.ADD = ADD;
global.SUB = SUB;
global.DIV = DIV;
global.ISZERO = ISZERO;
global.FLOAT_FROM_COIN = FLOAT_FROM_COIN;
global.COIN_FROM_FLOAT = COIN_FROM_FLOAT;
global.COIN_FROM_STRING = COIN_FROM_STRING;
}

View File

@ -0,0 +1,372 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var MAX_SUPER_VALUE_POW = (1 << 30) * 2;
window.TYPE_TRANSACTION_CREATE = 100;
function GetHashWithValues(hash0,value1,value2,bNotCopy)
{
var hash;
if(bNotCopy)
hash = hash0;
else
hash = hash0.slice();
hash[0] = value1 & 0xFF;
hash[1] = (value1 >>> 8) & 0xFF;
hash[2] = (value1 >>> 16) & 0xFF;
hash[3] = (value1 >>> 24) & 0xFF;
hash[4] = value2 & 0xFF;
hash[5] = (value2 >>> 8) & 0xFF;
hash[6] = (value2 >>> 16) & 0xFF;
hash[7] = (value2 >>> 24) & 0xFF;
var arrhash = shaarr(hash);
return arrhash;
};
function GetPowPower(arrhash)
{
var SumBit = 0;
for(var i = 0; i < arrhash.length; i++)
{
var byte = arrhash[i];
for(var b = 7; b >= 0; b--)
{
if((byte >> b) & 1)
{
return SumBit;
}
else
{
SumBit++;
}
}
}
return SumBit;
};
function GetPowValue(arrhash)
{
var value = (arrhash[0] << 23) * 2 + (arrhash[1] << 16) + (arrhash[2] << 8) + arrhash[3];
value = value * 256 + arrhash[4];
value = value * 256 + arrhash[5];
return value;
};
function CreateNoncePOWExtern(arr0,BlockNum,count,startnone)
{
var arr = [];
for(var i = 0; i < arr0.length; i++)
arr[i] = arr0[i];
if(!startnone)
startnone = 0;
var maxnonce = 0;
var supervalue = MAX_SUPER_VALUE_POW;
for(var nonce = startnone; nonce <= startnone + count; nonce++)
{
var arrhash = GetHashWithValues(arr, nonce, BlockNum, true);
var value = GetPowValue(arrhash);
if(value < supervalue)
{
maxnonce = nonce;
supervalue = value;
}
}
return maxnonce;
};
window.TR_TICKET_HASH_LENGTH = 10;
function CreateHashBody(body,Num,Nonce)
{
var length = body.length - 12;
body[length + 0] = Num & 0xFF;
body[length + 1] = (Num >>> 8) & 0xFF;
body[length + 2] = (Num >>> 16) & 0xFF;
body[length + 3] = (Num >>> 24) & 0xFF;
body[length + 4] = 0;
body[length + 5] = 0;
length = body.length - 6;
body[length + 0] = Nonce & 0xFF;
body[length + 1] = (Nonce >>> 8) & 0xFF;
body[length + 2] = (Nonce >>> 16) & 0xFF;
body[length + 3] = (Nonce >>> 24) & 0xFF;
body[length + 4] = 0;
body[length + 5] = 0;
var HASH = sha3(body);
var FullHashTicket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for(var i = 0; i < TR_TICKET_HASH_LENGTH; i++)
FullHashTicket[i] = HASH[i];
WriteUintToArrOnPos(FullHashTicket, Num, TR_TICKET_HASH_LENGTH);
return sha3(FullHashTicket);
};
window.DELTA_POWER_POW_TR = 0;
window.DELTA_FOR_TIME_TX = 0;
window.MIN_POWER_POW_TR = 0;
window.CONSENSUS_PERIOD_TIME = 1000;
window.FIRST_TIME_BLOCK = 1530446400000;
window.NEW_SIGN_TIME = 25500000;
window.SetBlockChainConstant = function (Data)
{
var DeltaServerClient = new Date() - Data.CurTime;
if(!Data.DELTA_CURRENT_TIME)
Data.DELTA_CURRENT_TIME = 0;
window.DELTA_CURRENT_TIME2 = Data.DELTA_CURRENT_TIME - DeltaServerClient;
window.MIN_POWER_POW_TR = DELTA_POWER_POW_TR + Data.MIN_POWER_POW_TR;
window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK;
window.NEW_SIGN_TIME = Data.NEW_SIGN_TIME;
window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME;
window.GetCurrentBlockNumByTime = function ()
{
var CurrentTime = Date.now() + DELTA_CURRENT_TIME2;
var CurTimeNum = CurrentTime - FIRST_TIME_BLOCK;
var StartBlockNum = Math.floor((CurTimeNum + CONSENSUS_PERIOD_TIME) / CONSENSUS_PERIOD_TIME);
return StartBlockNum;
};
window.NWMODE = Data.NWMODE;
};
window.GetCurrentBlockNumByTime = function ()
{
return 0;
};
function GetBlockNumTr(arr)
{
var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
if(arr[0] === TYPE_TRANSACTION_CREATE)
{
var BlockNum2 = Math.floor(BlockNum / 10) * 10;
if(BlockNum2 < BlockNum)
BlockNum2 = BlockNum2 + 10;
BlockNum = BlockNum2;
}
return BlockNum;
};
var LastCreatePOWTrType = 0;
var LastCreatePOWBlockNum = 0;
var LastCreatePOWHash = [255, 255, 255, 255];
function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
{
var TrType = arr[0];
var BlockNum = GetBlockNumTr(arr);
if(MinPow === undefined)
{
MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128);
}
var nonce = startnonce;
while(1)
{
var arrhash = CreateHashBody(arr, BlockNum, nonce);
var power = GetPowPower(arrhash);
if(power >= MinPow)
{
if(LastCreatePOWBlockNum === BlockNum && LastCreatePOWTrType === TrType && CompareArr(LastCreatePOWHash, arrhash) > 0)
{
}
else
{
LastCreatePOWBlockNum = BlockNum;
LastCreatePOWTrType = TrType;
LastCreatePOWHash = arrhash;
return nonce;
}
}
nonce++;
if(nonce % 2000 === 0)
{
BlockNum = GetBlockNumTr(arr);
}
}
};
function CalcHashFromArray(ArrHashes,bOriginalSeq)
{
if(bOriginalSeq === undefined)
ArrHashes.sort(CompareArr);
var Buf = [];
for(var i = 0; i < ArrHashes.length; i++)
{
var Value = ArrHashes[i];
for(var n = 0; n < Value.length; n++)
Buf.push(Value[n]);
}
if(Buf.length === 0)
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else
if(Buf.length === 32)
return Buf;
var Hash = shaarr(Buf);
return Hash;
};
function GetArrFromValue(Num)
{
var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
arr[0] = Num & 0xFF;
arr[1] = (Num >>> 8) & 0xFF;
arr[2] = (Num >>> 16) & 0xFF;
arr[3] = (Num >>> 24) & 0xFF;
var NumH = Math.floor(Num / 4294967296);
arr[4] = NumH & 0xFF;
arr[5] = (NumH >>> 8) & 0xFF;
return arr;
};
function LoadLib(Path)
{
var item = document.createElement('script');
item.type = "text/javascript";
item.src = Path;
document.getElementsByTagName('head')[0].appendChild(item);
};
function IsMS()
{
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if(msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
return 1;
}
else
{
return 0;
}
};
function LoadSignLib()
{
if(window.SignLib)
return ;
LoadLib("./JS/sign-lib-min.js");
};
function ComputeSecretWithCheck(PubKey,StrPrivKey,F)
{
if(!window.SignLib)
{
SetError("Error - SignLib not installed");
return ;
}
if(!IsHexStr(StrPrivKey) || StrPrivKey.length !== 64)
{
SetError("Error set PrivKey");
return ;
}
var PrivKey = Buffer.from(GetArrFromHex(StrPrivKey));
if(typeof PubKey === "string")
{
if(!IsHexStr(PubKey) || PubKey.length !== 66)
{
SetError("Error PubKey");
return ;
}
PubKey = Buffer.from(GetArrFromHex(PubKey));
}
var Result = SignLib.ecdh(PubKey, PrivKey);
F(sha3(Result));
};
function ComputeSecret(Account,PubKey,F)
{
if(GetPrivKey())
{
ComputeSecretWithCheck(PubKey, GetPrivKey(), F);
}
else
{
GetData("GetWalletInfo", {Account:Account}, function (Data)
{
if(!Data || !Data.result)
return ;
ComputeSecretWithCheck(PubKey, Data.PrivateKey, F);
});
}
};
function Encrypt(ArrSecret,StartEncrypt,StrName,StrValue)
{
var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt));
var Arr = toUTF8Array(StrValue);
return DoSecret(Arr, arrRnd);
};
function Decrypt(ArrSecret,StartEncrypt,StrName,Arr)
{
if(!ArrSecret)
return "".padEnd(Arr.length / 2, ".");
if(typeof Arr === "string")
Arr = GetArrFromHex(Arr);
var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt));
var Arr2 = DoSecret(Arr, arrRnd);
var Str = Utf8ArrayToStr(Arr2);
return Str;
};
function DoSecret(Arr,arrRnd)
{
var Arr2 = [];
var CryptID = 0;
var Pos = 0;
while(Pos < Arr.length)
{
CryptID++;
WriteUintToArrOnPos(arrRnd, CryptID, 0);
var CurBuf = sha3(arrRnd);
for(var i = 0; i < 32 && Pos < Arr.length; i++, Pos++)
{
Arr2[Pos] = Arr[Pos] ^ CurBuf[i];
}
}
return Arr2;
};
var glEncryptInit = 0;
function EncryptInit()
{
glEncryptInit++;
var Time = Date.now() - new Date(2019, 0, 1);
return Math.floor(Time * 100 + Math.random() * 100) * 100 + glEncryptInit;
};
function EncryptID(ArrSecret,StartEncrypt,id)
{
var Value = $(id).value;
Value = Value.padEnd(Value.length + random(5), " ");
return GetHexFromArr(Encrypt(ArrSecret, StartEncrypt, id, Value));
};
function EncryptFields(ArrSecret,Params,ArrName)
{
if(!Params.Crypto)
Params.Crypto = EncryptInit();
for(var i = 0; i < ArrName.length; i++)
{
var Name = ArrName[i];
var Value = Params[Name];
Value = Value.padEnd(Value.length + random(5), " ");
Params[Name] = GetHexFromArr(Encrypt(ArrSecret, Params.Crypto, Name, Value));
}
};
function DecryptFields(ArrSecret,Params,ArrName)
{
for(var i = 0; i < ArrName.length; i++)
{
var Name = ArrName[i];
if(Params[Name])
{
Params[Name] = Decrypt(ArrSecret, Params.Crypto, Name, GetArrFromHex(Params[Name]));
}
else
{
Params[Name] = "";
}
}
};

521
src/HTML/JS/dapp-inner.js Normal file
View File

@ -0,0 +1,521 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
function SendPay(Data)
{
Data.cmd = "pay";
SendData(Data);
};
function SetStorage(Key,Value)
{
var Data = {cmd:"setstorage", Key:Key, Value:Value};
SendData(Data);
};
function GetStorage(Key,F)
{
var Data = {cmd:"getstorage", Key:Key};
SendData(Data, F);
};
function SetCommon(Key,Value)
{
var Data = {cmd:"setcommon", Key:Key, Value:Value};
SendData(Data);
};
function GetCommon(Key,F)
{
var Data = {cmd:"getcommon", Key:Key};
SendData(Data, F);
};
function GetInfo(F,bUseCache)
{
var Data = {cmd:"DappInfo", AllAccounts:ALL_ACCOUNTS, AllData:!bUseCache};
SendData(Data, F);
};
function Call(Account,MethodName,Params,F)
{
var Data = {cmd:"DappCall", MethodName:MethodName, Params:Params, Account:Account};
SendData(Data, F);
};
function SendCall(Account,MethodName,Params,FromNum)
{
if(!INFO.WalletCanSign)
{
SetError("Pls, open wallet");
return 0;
}
var Data = {cmd:"DappSendCall", MethodName:MethodName, Params:Params, Account:Account, FromNum:FromNum};
SendData(Data);
return 1;
};
function GetWalletAccounts(F)
{
var Data = {cmd:"DappWalletList"};
SendData(Data, F);
};
function GetAccountList(Params,F)
{
var Data = {cmd:"DappAccountList", Params:Params};
SendData(Data, F);
};
function GetSmartList(Params,F)
{
var Data = {cmd:"DappSmartList", Params:Params};
SendData(Data, F);
};
function GetBlockList(Params,F)
{
var Data = {cmd:"DappBlockList", Params:Params};
SendData(Data, F);
};
function GetTransactionList(Params,F)
{
var Data = {cmd:"DappTransactionList", Params:Params};
SendData(Data, F);
};
function DappSmartHTMLFile(Smart,F)
{
var Data = {cmd:"DappSmartHTMLFile", Params:{Smart:Smart}};
SendData(Data, F);
};
function DappBlockFile(BlockNum,TrNum,F)
{
var Data = {cmd:"DappBlockFile", Params:{BlockNum:BlockNum, TrNum:TrNum}};
SendData(Data, F);
};
function SetStatus(Str)
{
SendData({cmd:"SetStatus", Message:Str});
};
function SetError(Str)
{
SendData({cmd:"SetError", Message:Str});
};
function SetLocationPath(Str)
{
SendData({cmd:"SetLocationHash", Message:Str});
};
function CreateNewAccount(Currency)
{
SendData({cmd:"CreateNewAccount", Currency:Currency});
};
function OpenLink(Str)
{
SendData({cmd:"OpenLink", Message:Str});
};
function SetMobileMode()
{
SendData({cmd:"SetMobileMode"});
};
function ComputeSecret(PubKey,F,Account)
{
if(!INFO.WalletCanSign)
{
SetError("Pls, open wallet");
return 0;
}
if(!Account && USER_ACCOUNT.length)
Account = USER_ACCOUNT[0].Num;
if(typeof PubKey === "number")
{
var AccNum = PubKey;
GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
{
if(Err)
{
SetError(Err);
}
else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:Arr[0].PubKey.data}, F);
}
});
}
else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:PubKey}, F);
}
};
function CheckInstall()
{
SendData({cmd:"CheckInstall"});
};
function SendTransaction(Body,TR,SumPow,F)
{
SetError("Cannt SEND TR: " + JSON.stringify(TR));
};
function CurrencyName(Num)
{
var Name = MapCurrency[Num];
if(!Name)
{
GetSmartList({StartNum:Num, CountNum:1, TokenGenerate:1}, function (Err,Arr)
{
if(Err || Arr.length === 0)
return ;
var Smart = Arr[0];
Name = GetTokenName(Smart.Num, Smart.ShortName);
MapCurrency[Smart.Num] = Name;
});
Name = GetTokenName(Num, "");
}
return Name;
};
var SendCountUpdate = 0;
function FindAllCurrency()
{
SendCountUpdate++;
GetSmartList({StartNum:8, CountNum:100, TokenGenerate:1}, function (Err,Arr)
{
SendCountUpdate--;
if(Err)
return ;
for(var i = 0; i < Arr.length; i++)
{
var Smart = Arr[i];
if(!MapCurrency[Smart.Num])
{
var Name = GetTokenName(Smart.Num, Smart.ShortName);
MapCurrency[Smart.Num] = Name;
}
}
});
};
function GetFilePath(Path)
{
if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/"))
{
if(Path.substr(0, 1) !== "/")
Path = "/" + Path;
Path = window.PROTOCOL_SERVER_PATH + Path;
}
return Path;
};
function GetParamsFromPath(Name)
{
if(!OPEN_PATH)
return undefined;
var arr = OPEN_PATH.split("&");
for(var i = 0; i < arr.length; i++)
{
if(arr[i].indexOf(Name + "=") === 0)
{
return arr[i].split("=")[1];
}
}
};
function GetState(AccNum,F,FErr)
{
SendCountUpdate++;
GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
{
SendCountUpdate--;
if(!Err && Arr.length)
{
var Item = Arr[0].SmartState;
if(Item)
{
F(Item);
return ;
}
}
if(FErr)
{
FErr();
return ;
}
});
};
var glMapF = {};
var glKeyF = 0;
function SendData(Data,F)
{
if(!window.parent)
return ;
if(F)
{
glKeyF++;
Data.CallID = glKeyF;
glMapF[glKeyF] = F;
}
window.parent.postMessage(Data, "*");
};
function OnMessage(event)
{
var Data = event.data;
if(!Data || typeof Data !== "object")
return ;
var CallID = Data.CallID;
var cmd = Data.cmd;
if(CallID)
{
var F = glMapF[CallID];
if(F)
{
delete Data.CallID;
delete Data.cmd;
switch(cmd)
{
case "getstorage":
case "getcommon":
F(Data.Key, Data.Value);
break;
case "DappCall":
F(Data.Err, Data.RetValue);
break;
case "DappInfo":
F(Data.Err, Data);
break;
case "DappWalletList":
case "DappAccountList":
case "DappSmartList":
case "DappBlockList":
case "DappTransactionList":
F(Data.Err, Data.arr);
break;
case "DappBlockFile":
case "DappSmartHTMLFile":
F(Data.Err, Data.Body);
break;
case "ComputeSecret":
F(Data.Result);
break;
default:
console.log("Error cmd: " + cmd);
}
delete glMapF[CallID];
}
}
else
{
switch(cmd)
{
case "History":
var eventEvent = new CustomEvent("History", {detail:Data});
window.dispatchEvent(eventEvent);
break;
case "OnEvent":
if(window.OnEvent)
{
window.OnEvent(Data);
}
var eventEvent = new CustomEvent("Event", {detail:Data});
window.dispatchEvent(eventEvent);
}
}
};
function OpenRefFile(Str)
{
var Param = ParseFileName(Str);
if(Param.BlockNum)
DappBlockFile(Param.BlockNum, Param.TrNum, function (Err,Body)
{
document.write(Body);
});
else
{
OpenLink(Str);
}
};
function SaveToStorageByArr(Arr)
{
SetStorage("VerSave", "1");
for(var i = 0; i < Arr.length; i++)
{
var name = Arr[i];
var Item = $(name);
if(Item)
{
if(Item.type === "checkbox")
SetStorage(name, 0 + Item.checked);
else
SetStorage(name, Item.value);
}
}
};
function LoadFromStorageByArr(Arr,F,bAll)
{
GetStorage("VerSave", function (Key,Value)
{
if(Value === "1")
{
for(var i = 0; i < Arr.length; i++)
{
if(i === Arr.length - 1)
LoadFromStorageById(Arr[i], F);
else
LoadFromStorageById(Arr[i]);
}
}
if(bAll && F)
F(0);
});
};
function LoadFromStorageById(Name,F)
{
GetStorage(Name, function (Key,Value)
{
var Item = document.getElementById(Name);
if(Item)
{
if(Item.type === "checkbox")
Item.checked = parseInt(Value);
else
Item.value = Value;
}
if(F)
F(Key, Value);
});
};
var SendCountDappParams = 0;
function GetDappParams(BNum,TrNum,F,bAll)
{
if(!BNum)
{
if(bAll)
F();
return ;
}
SendCountDappParams++;
DappBlockFile(BNum, TrNum, function (Err,Data)
{
SendCountDappParams--;
if(!Err && Data.Type === 135)
{
try
{
var Params = JSON.parse(Data.Params);
}
catch(e)
{
}
if(Params)
{
F(Params, Data.MethodName, Data.FromNum);
return ;
}
}
if(bAll)
F();
});
};
document.addEventListener("DOMContentLoaded", function ()
{
var refs = document.getElementsByTagName("A");
for(var i = 0, L = refs.length; i < L; i++)
{
if(refs[i].href.indexOf("/file/") >= 0)
{
refs[i].onclick = function ()
{
OpenRefFile(this.href);
};
}
}
});
if(window.addEventListener)
{
window.addEventListener("message", OnMessage);
}
else
{
window.attachEvent("onmessage", OnMessage);
}
var SMART = {}, BASE_ACCOUNT = {}, INFO = {}, USER_ACCOUNT = [], USER_ACCOUNT_MAP = {}, OPEN_PATH = "", ACCOUNT_OPEN_NUM = 0;
var ALL_ACCOUNTS = 0;
var WasStartInit = 0, WasStartInit2 = 0;
var eventInfo = new Event("UpdateInfo");
function UpdateDappInfo()
{
GetInfo(function (Err,Data)
{
if(Err)
{
return ;
}
INFO = Data;
SMART = Data.Smart;
BASE_ACCOUNT = Data.Account;
OPEN_PATH = Data.OPEN_PATH;
ACCOUNT_OPEN_NUM = ParseNum(OPEN_PATH);
SetBlockChainConstant(Data);
USER_ACCOUNT = Data.ArrWallet;
USER_ACCOUNT_MAP = {};
for(var i = 0; i < USER_ACCOUNT.length; i++)
USER_ACCOUNT_MAP[USER_ACCOUNT[i].Num] = USER_ACCOUNT[i];
if(window.OnInit && !WasStartInit)
{
WasStartInit = 1;
window.OnInit(1);
}
else
if(window.OnUpdateInfo)
{
window.OnUpdateInfo();
}
if(!WasStartInit2)
{
WasStartInit2 = 1;
var eventInit = new Event("Init");
window.dispatchEvent(eventInit);
}
window.dispatchEvent(eventInfo);
if(Data.ArrEvent)
for(var i = 0; i < Data.ArrEvent.length; i++)
{
var Item = Data.ArrEvent[i];
Item.cmd = "OnEvent";
OnMessage({data:Item});
}
}, 1);
};
window.addEventListener('load', function ()
{
if(!window.sha3)
LoadLib("./JS/sha3.js");
UpdateDappInfo();
setInterval(UpdateDappInfo, 1000);
});

455
src/HTML/JS/diagram.js Normal file
View File

@ -0,0 +1,455 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var DiagramMap = {};
var DiagramMapId = {};
var LMouseOn = false;
if(!window.toStaticHTML)
toStaticHTML = function (Str)
{
return Str;
};
function Rigth(Str,Count)
{
if(Str.length < Count)
return Str;
else
return Str.substr(Str.length - Count);
};
function SetHTMLDiagramItem(Item,width)
{
Item.mouseX = width - 50;
if(Item.Extern || Item.Delete)
return ;
var MinHeight = 80;
if(!Item.id)
Item.id = "DgrmId" + Item.num;
DiagramMap[Item.name] = Item;
DiagramMapId[Item.id] = Item;
if(Item.isLine)
{
if(Item.text)
Str = "<BR><B>" + Item.text + '</B><INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X">';
else
Str = "<HR>";
}
else
{
Str = '<BR><DIV>' + Item.text + '<INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X"></DIV>\
<BR><canvas class="DIAGRAM" width="' + width + '" height="' + MinHeight + '" id="' + Item.id + '"></canvas>';
}
var ElBlock = document.getElementById("B" + Item.id);
if(ElBlock)
ElBlock.innerHTML = toStaticHTML(Str);
else
{
var diargams = document.getElementById("diargams");
diargams.innerHTML = toStaticHTML(diargams.innerHTML + "<DIV id='B" + Item.id + "'>" + Str + "</DIV>");
}
};
function SetDiagramMouseX(event,mode)
{
if(event.srcElement && event.srcElement.className && event.srcElement.className.indexOf && event.srcElement.className.indexOf("DIAGRAM") >= 0)
{
if(mode === "down")
LMouseOn = true;
else
if(mode === "up")
LMouseOn = false;
event.preventDefault();
if(LMouseOn === true)
{
var obj = event.srcElement;
var mouse = getMouse(obj, event);
if(event.ctrlKey === true)
{
for(var key in DiagramMapId)
{
var Item = DiagramMapId[key];
Item.mouseX = mouse.x;
DrawDiagram(Item);
}
}
else
{
var Item = DiagramMapId[obj.id];
if(Item)
{
Item.mouseX = mouse.x;
DrawDiagram(Item);
}
}
}
}
};
function DrawDiagram(Item)
{
if(Item.Delete)
return ;
var arr = Item.arr;
if(!arr)
arr = Item.ArrList;
var arrX = Item.arrX;
var GreenValue = Item.value;
var StepTime = Item.steptime;
var StartNumber = Item.startnumber;
var StartServer = Item.starttime;
var mouseX = Item.mouseX;
var KPrecision = Item.KPrecision;
if(!KPrecision)
KPrecision = 1;
if(!arr)
return ;
var obj = document.getElementById(Item.id);
var ctx = obj.getContext('2d');
var Left = 50;
var Top = 11;
var Button = 15;
var Right = 50;
if(Item.fillStyle)
ctx.fillStyle = Item.fillStyle;
else
ctx.fillStyle = "#FFF";
ctx.fillRect(0, 0, obj.width, obj.height);
if(arr.length <= 0)
return ;
var Pow2 = 0;
if(Item.name.substr(Item.name.length - 2) === "**")
Pow2 = 1;
var MaxValue = arr[0];
var MinValue = arr[0];
var AvgValue = 0;
for(var i = 0; i < arr.length; i++)
{
if(arr[i] > MaxValue)
MaxValue = arr[i];
if(arr[i] < MinValue)
MinValue = arr[i];
if(arr[i])
AvgValue += arr[i];
}
if(Item.name.substr(0, 4) !== "MAX:" || !Item.AvgValue)
AvgValue = AvgValue / arr.length;
else
AvgValue = Item.AvgValue;
if(Pow2 && AvgValue)
AvgValue = Math.pow(2, AvgValue) / 1000000;
if(AvgValue < 50)
AvgValue = AvgValue.toFixed(2);
else
AvgValue = Math.floor(AvgValue);
if(Item.MaxValue !== undefined)
MaxValue = Item.MaxValue;
if(Pow2 && MaxValue)
MaxValue = Math.pow(2, MaxValue) / 1000000;
var HValue = MaxValue;
if(HValue <= 0)
HValue = 1;
var KX = (obj.width - Left - Right) / arr.length;
var KY = (obj.height - Top - Button) / HValue;
var DeltaY = 0;
var bLine = Item.line;
if(Item.zero)
{
bLine = 1;
DeltaY -= Item.zero * KY;
MaxValue -= Item.zero;
AvgValue -= Item.zero;
}
MaxValue = Math.floor(MaxValue + 0.5);
if(bLine)
ctx.lineWidth = 3;
else
if(KX > 1)
ctx.lineWidth = KX;
else
ctx.lineWidth = 1;
var StartX = Left;
var StartY = obj.height - Button;
var mouseValueX = 0;
var mouseValue = undefined;
var mouseColor = undefined;
function DrawLines(arr,mode,color)
{
var WasMove0 = 0;
ctx.beginPath();
ctx.moveTo(Left, obj.height - Button);
ctx.strokeStyle = color;
var PrevX = undefined;
for(var i = 0; i < arr.length; i++)
{
var Value = arr[i];
if(!Value)
Value = 0;
if(Value)
{
if(Pow2)
Value = Math.pow(2, Value) / 1000000;
}
if(mode === "green")
{
if(Value > GreenValue)
continue;
}
else
if(mode === "red")
{
if(Value <= GreenValue)
continue;
}
var Value1 = Value;
if(Value1 > GreenValue)
Value1 = GreenValue;
var VX1 = Math.floor(Value1 * KY);
var VX2 = Math.floor(Value * KY);
if(VX1 === VX2)
VX1 -= 2;
var x = StartX + ctx.lineWidth / 2 + (i) * KX;
if(bLine)
{
if(!WasMove0)
{
WasMove0 = 1;
ctx.moveTo(x, StartY - VX2);
}
else
{
ctx.lineTo(x, StartY - VX2);
}
}
else
{
ctx.moveTo(x, StartY - VX1);
ctx.lineTo(x, StartY - VX2);
}
if(mouseX)
{
var deltaCur = Math.abs(x - mouseX);
var deltaWas = Math.abs(mouseValueX - mouseX);
if(deltaCur < deltaWas)
{
mouseValueX = x;
mouseValue = Value;
if(Item.zero)
mouseValue -= Item.zero;
mouseColor = color;
}
}
}
ctx.stroke();
};
if(!Item.red)
Item.red = "#A00";
if(bLine)
{
DrawLines(arr, "line", Item.red);
}
else
{
DrawLines(arr, "red", Item.red);
if(GreenValue > 0)
DrawLines(arr, "green", "#0A0");
}
var MaxValueText = GetValueByItemProperty(MaxValue, Item);
var AvgValueText = GetValueByItemProperty(AvgValue, Item);
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.strokeStyle = "#000";
Left--;
StartX--;
StartY += 2;
ctx.moveTo(Left, Top);
ctx.lineTo(StartX, StartY);
ctx.moveTo(StartX, StartY + DeltaY);
ctx.lineTo(obj.width - 10, StartY + DeltaY);
ctx.stroke();
if(mouseX !== undefined)
{
ctx.beginPath();
ctx.lineWidth = 0.5;
ctx.strokeStyle = "#00F";
ctx.moveTo(mouseX, Top);
ctx.lineTo(mouseX, StartY);
ctx.stroke();
if(mouseValue !== undefined)
{
ctx.fillStyle = mouseColor;
var Val = GetValueByItemProperty(mouseValue, Item);
var mouseTextX = mouseX;
if(Item.MouseText)
mouseTextX -= 3 * Item.MouseText.length;
else
Item.MouseText = "";
ctx.fillText("" + Val + Item.MouseText, mouseTextX - 3, Top - 2);
}
}
ctx.fillStyle = "#000";
if(!Item.NoTextMax)
ctx.fillText(Rigth("" + MaxValueText, 8), 0, Top - 3);
if(MaxValue > 0 && AvgValue > 0)
{
var heigh = StartY - Top;
var KKY = AvgValue / MaxValue;
var y = (heigh - Math.floor(KKY * heigh));
var yT = y;
if(yT < 10)
{
yT = 10;
}
ctx.beginPath();
ctx.moveTo(Left - 2, y + Top);
ctx.lineTo(Left + 2, y + Top);
ctx.stroke();
ctx.strokeStyle = "#00F";
ctx.fillText(Rigth("" + AvgValueText, 8), 0, yT + Top);
}
var CountNameX = 10;
if(arr.length < CountNameX)
CountNameX = arr.length;
var KX3 = (obj.width - Left - Right) / CountNameX;
var KDelitel = 1;
var Step = arr.length / CountNameX;
var StartTime, bNumber;
if(arrX)
{
}
else
if(StartNumber !== undefined)
{
bNumber = 1;
StartTime = StartNumber;
}
else
if(StartServer)
{
bNumber = 1;
StartTime = Math.floor(((Date.now() - StartServer) - StepTime * arr.length * 1000) / 1000);
if(StartTime < 0)
StartTime = 0;
var KDelitel = Math.floor(Step / 10) * 10;
if(KDelitel == 0)
KDelitel = 1;
}
else
{
bNumber = 0;
StartTime = Date.now() - StepTime * arr.length * 1000;
StartX = StartX - 16;
}
for(i = 0; i <= CountNameX; i++)
{
var Val;
if(i === CountNameX)
{
Val = arr.length * StepTime;
KDelitel = 1;
}
else
if(i === 0)
Val = 0;
else
Val = i * Step * StepTime;
var Str;
if(arrX)
{
Val = Math.floor(Val);
Str = arrX[Val];
if(Str === undefined)
Str = "";
}
else
if(bNumber)
{
Val = Math.floor((StartTime + Val) / KDelitel) * KDelitel;
Str = Val;
}
else
{
var Time = new Date(StartTime + Val * 1000);
Str = "" + Time.getHours();
Str += ":" + Rigth("0" + Time.getMinutes(), 2);
Str += ":" + Rigth("0" + Time.getSeconds(), 2);
}
ctx.fillText(Str, StartX + i * KX3, StartY + 10);
}
};
function GetValueByItemProperty(Value,Item)
{
if(Item.MathPow && Item.MathDiv)
{
Value = Math.pow(Item.MathPow, Value) / Item.MathDiv;
}
var KPrecision = Item.KPrecision;
if(!Item.KPrecision)
KPrecision = 1;
Value = Math.floor(Value * KPrecision + 0.5) / KPrecision;
return Value;
};
function InitDiagramByArr(Arr,width)
{
for(var i = 0; i < Arr.length; i++)
{
Arr[i].num = i + 1;
SetHTMLDiagramItem(Arr[i], width);
}
window.addEventListener('mousedown', function (event)
{
SetDiagramMouseX(event, "down");
}, false);
window.addEventListener('mouseup', function (event)
{
SetDiagramMouseX(event, "up");
}, false);
window.addEventListener('onmousemove', function (event)
{
SetDiagramMouseX(event, "move");
}, false);
};
function getMouse(canvas,e)
{
var x = e.clientX - getTrueOffsetLeft(canvas);
if(window.pageXOffset)
x = x + window.pageXOffset;
var y = e.clientY - getTrueOffsetTop(canvas);
if(window.pageYOffset)
y = y + window.pageYOffset;
var coord = {x:x, y:y};
return coord;
};
function getTrueOffsetLeft(ele)
{
var n = 0;
while(ele)
{
n += ele.offsetLeft || 0;
ele = ele.offsetParent;
}
return n;
};
function getTrueOffsetTop(ele)
{
var n = 0;
while(ele)
{
n += ele.offsetTop || 0;
ele = ele.offsetParent;
}
return n;
};

View File

@ -0,0 +1 @@
function FLanguage(e){var n={endsWithParent:!0,illegal:/</,relevance:0,contains:[{className:"attr",begin:"[A-Za-z0-9\\._:-]+",relevance:0},{begin:/=\s*/,relevance:0,contains:[{className:"string",endsParent:!0,variants:[{begin:/"/,end:/"/},{begin:/'/,end:/'/},{begin:/[^\s"'=<>`]+/}]}]}]};return{aliases:["html","xhtml","rss","atom","xjb","xsd","xsl","plist"],case_insensitive:!0,contains:[{className:"meta",begin:"<!DOCTYPE",end:">",relevance:10,contains:[{begin:"\\[",end:"\\]"}]},e.COMMENT("\x3c!--","--\x3e",{relevance:10}),{begin:"<\\!\\[CDATA\\[",end:"\\]\\]>",relevance:10},{className:"meta",begin:/<\?xml/,end:/\?>/,relevance:10},{begin:/<\?(php)?/,end:/\?>/,subLanguage:"php",contains:[{begin:"/\\*",end:"\\*/",skip:!0},{begin:'b"',end:'"',skip:!0},{begin:"b'",end:"'",skip:!0},e.inherit(e.APOS_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0}),e.inherit(e.QUOTE_STRING_MODE,{illegal:null,className:null,contains:null,skip:!0})]},{className:"tag",begin:"<style(?=\\s|>|$)",end:">",keywords:{name:"style"},contains:[n],starts:{end:"</style>",returnEnd:!0,subLanguage:["css","xml"]}},{className:"tag",begin:"<script(?=\\s|>|$)",end:">",keywords:{name:"script"},contains:[n],starts:{end:"<\/script>",returnEnd:!0,subLanguage:["actionscript","javascript","handlebars","xml"]}},{className:"tag",begin:"</?",end:"/?>",contains:[{className:"name",begin:/[^\/><\s]+/,relevance:0},n]}]}}hljs.registerLanguage("html",FLanguage);

View File

@ -0,0 +1 @@
function FLanguage(e){var n="[A-Za-z$_][0-9A-Za-z$_]*",a={keyword:"in of if for while finally var new function do return void else break catch instanceof with throw case default try this switch continue typeof delete let yield const export super debugger as async await static import from as",literal:"true false null undefined NaN Infinity",built_in:"eval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Error EvalError InternalError RangeError ReferenceError StopIteration SyntaxError TypeError URIError Number Math Date String RegExp Array Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array Uint8ClampedArray ArrayBuffer DataView JSON Intl arguments require module console window document Symbol Set Map WeakSet WeakMap Proxy Reflect Promise"},r={className:"number",variants:[{begin:"\\b(0[bB][01]+)"},{begin:"\\b(0[oO][0-7]+)"},{begin:e.C_NUMBER_RE}],relevance:0},s={className:"subst",begin:"\\$\\{",end:"\\}",keywords:a,contains:[]},i={className:"string",begin:"`",end:"`",contains:[e.BACKSLASH_ESCAPE,s]};s.contains=[e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,i,r,e.REGEXP_MODE];var t=s.contains.concat([e.C_BLOCK_COMMENT_MODE,e.C_LINE_COMMENT_MODE]);return{aliases:["js","jsx"],keywords:a,contains:[{className:"meta",relevance:10,begin:/^\s*['"]use (strict|asm)['"]/},{className:"meta",begin:/^#!/,end:/$/},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE,i,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,r,{begin:/[{,]\s*/,relevance:0,contains:[{begin:n+"\\s*:",returnBegin:!0,relevance:0,contains:[{className:"attr",begin:n,relevance:0}]}]},{begin:"("+e.RE_STARTERS_RE+"|\\b(case|return|throw)\\b)\\s*",keywords:"return throw case",contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.REGEXP_MODE,{className:"function",begin:"(\\(.*?\\)|"+n+")\\s*=>",returnBegin:!0,end:"\\s*=>",contains:[{className:"params",variants:[{begin:n},{begin:/\(\s*\)/},{begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,keywords:a,contains:t}]}]},{begin:/</,end:/(\/\w+|\w+\/)>/,subLanguage:"xml",contains:[{begin:/<\w+\s*\/>/,skip:!0},{begin:/<\w+/,end:/(\/\w+|\w+\/)>/,skip:!0,contains:[{begin:/<\w+\s*\/>/,skip:!0},"self"]}]}],relevance:0},{className:"function",beginKeywords:"function",end:/\{/,excludeEnd:!0,contains:[e.inherit(e.TITLE_MODE,{begin:n}),{className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,contains:t}],illegal:/\[|%/},{begin:/\$[(.]/},e.METHOD_GUARD,{className:"class",beginKeywords:"class",end:/[{;=]/,excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"extends"},e.UNDERSCORE_TITLE_MODE]},{beginKeywords:"constructor",end:/\{/,excludeEnd:!0}],illegal:/#(?!!)/}}hljs.registerLanguage("javascript",FLanguage),hljs.registerLanguage("js",FLanguage);

1
src/HTML/JS/highlight.js Normal file

File diff suppressed because one or more lines are too long

1686
src/HTML/JS/lexer.js Normal file

File diff suppressed because it is too large Load Diff

1
src/HTML/JS/marked.js Normal file

File diff suppressed because one or more lines are too long

1099
src/HTML/JS/mobile-wallet.js Normal file

File diff suppressed because it is too large Load Diff

190
src/HTML/JS/sec256k1.js Normal file
View File

@ -0,0 +1,190 @@
/*
* @project: TERA
* @version: Development (beta)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* @license: MIT (not for evil)
* Web: http://terafoundation.org
* GitHub: https://github.com/terafoundation/wallet
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
"use strict";
var der = require("./der"), toString = Object.prototype.toString, exports = {}, assert = exports;
exports.isArray = function (e,s)
{
if(!Array.isArray(e))
throw TypeError(s);
}, exports.isBoolean = function (e,s)
{
if("[object Boolean]" !== toString.call(e))
throw TypeError(s);
}, exports.isBuffer = function (e,s)
{
if(!Buffer.isBuffer(e))
throw TypeError(s);
}, exports.isFunction = function (e,s)
{
if("[object Function]" !== toString.call(e))
throw TypeError(s);
}, exports.isNumber = function (e,s)
{
if("[object Number]" !== toString.call(e))
throw TypeError(s);
}, exports.isObject = function (e,s)
{
if("[object Object]" !== toString.call(e))
throw TypeError(s);
}, exports.isBufferLength = function (e,s,r)
{
if(e.length !== s)
throw RangeError(r);
}, exports.isBufferLength2 = function (e,s,r,_)
{
if(e.length !== s && e.length !== r)
throw RangeError(_);
}, exports.isLengthGTZero = function (e,s)
{
if(0 === e.length)
throw RangeError(s);
}, exports.isNumberInInterval = function (e,s,r,_)
{
if(e <= s || r <= e)
throw RangeError(_);
};
var messages = {COMPRESSED_TYPE_INVALID:"compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID:"private key should be a Buffer",
EC_PRIVATE_KEY_LENGTH_INVALID:"private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID:"private key range is invalid",
EC_PRIVATE_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL:"tweak out of range",
EC_PRIVATE_KEY_EXPORT_DER_FAIL:"couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL:"couldn't import from DER format",
EC_PUBLIC_KEYS_TYPE_INVALID:"public keys should be an Array", EC_PUBLIC_KEYS_LENGTH_INVALID:"public keys Array should have at least 1 element",
EC_PUBLIC_KEY_TYPE_INVALID:"public key should be a Buffer", EC_PUBLIC_KEY_LENGTH_INVALID:"public key length is invalid", EC_PUBLIC_KEY_PARSE_FAIL:"the public key could not be parsed or is invalid",
EC_PUBLIC_KEY_CREATE_FAIL:"private was invalid, try again", EC_PUBLIC_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting public key is invalid",
EC_PUBLIC_KEY_TWEAK_MUL_FAIL:"tweak out of range", EC_PUBLIC_KEY_COMBINE_FAIL:"the sum of the public keys is not valid", ECDH_FAIL:"scalar was invalid (zero or overflow)",
ECDSA_SIGNATURE_TYPE_INVALID:"signature should be a Buffer", ECDSA_SIGNATURE_LENGTH_INVALID:"signature length is invalid",
ECDSA_SIGNATURE_PARSE_FAIL:"couldn't parse signature", ECDSA_SIGNATURE_PARSE_DER_FAIL:"couldn't parse DER signature", ECDSA_SIGNATURE_SERIALIZE_DER_FAIL:"couldn't serialize signature to DER format",
ECDSA_SIGN_FAIL:"nonce generation function failed or private key is invalid", ECDSA_RECOVER_FAIL:"couldn't recover public key from signature",
MSG32_TYPE_INVALID:"message should be a Buffer", MSG32_LENGTH_INVALID:"message length is invalid", OPTIONS_TYPE_INVALID:"options should be an Object",
OPTIONS_DATA_TYPE_INVALID:"options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID:"options.data length is invalid",
OPTIONS_NONCEFN_TYPE_INVALID:"options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID:"recovery should be a Number",
RECOVERY_ID_VALUE_INVALID:"recovery should have value between -1 and 4", TWEAK_TYPE_INVALID:"tweak should be a Buffer", TWEAK_LENGTH_INVALID:"tweak length is invalid"};
function initCompressedValue(e,s)
{
return void 0 === e ? s : (assert.isBoolean(e, messages.COMPRESSED_TYPE_INVALID), e);
};
module.exports = function (E)
{
return {privateKeyVerify:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), 32 === e.length && E.privateKeyVerify(e);
}, privateKeyExport:function (e,s)
{
assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0);
var r = E.privateKeyExport(e, s);
return der.privateKeyExport(e, r, s);
}, privateKeyImport:function (e)
{
if(assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), (e = der.privateKeyImport(e)) && 32 === e.length && E.privateKeyVerify(e))
return e;
throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL);
}, privateKeyNegate:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyNegate(e);
}, privateKeyModInverse:function (e)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyModInverse(e);
}, privateKeyTweakAdd:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakAdd(e,
s);
}, privateKeyTweakMul:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakMul(e,
s);
}, publicKeyCreate:function (e,s)
{
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyCreate(e, s);
}, publicKeyConvert:function (e,s)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyConvert(e, s);
}, publicKeyVerify:function (e)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), E.publicKeyVerify(e);
}, publicKeyTweakAdd:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakAdd(e, s, r);
}, publicKeyTweakMul:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakMul(e, s, r);
}, publicKeyCombine:function (e,s)
{
assert.isArray(e, messages.EC_PUBLIC_KEYS_TYPE_INVALID), assert.isLengthGTZero(e, messages.EC_PUBLIC_KEYS_LENGTH_INVALID);
for(var r = 0; r < e.length; ++r)
assert.isBuffer(e[r], messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e[r], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID);
return s = initCompressedValue(s, !0), E.publicKeyCombine(e, s);
}, signatureNormalize:function (e)
{
return assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID),
E.signatureNormalize(e);
}, signatureExport:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = E.signatureExport(e);
return der.signatureExport(s);
}, signatureImport:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImport(e);
if(s)
return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, signatureImportLax:function (e)
{
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImportLax(e);
if(s)
return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, sign:function (e,s,r)
{
assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID);
var _ = null, t = null;
return void 0 !== r && (assert.isObject(r, messages.OPTIONS_TYPE_INVALID), void 0 !== r.data && (assert.isBuffer(r.data, messages.OPTIONS_DATA_TYPE_INVALID),
assert.isBufferLength(r.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID), _ = r.data), void 0 !== r.noncefn && (assert.isFunction(r.noncefn,
messages.OPTIONS_NONCEFN_TYPE_INVALID), t = r.noncefn)), E.sign(e, s, t, _);
}, verify:function (e,s,r)
{
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isBuffer(r,
messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(r, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), E.verify(e,
s, r);
}, recover:function (e,s,r,_)
{
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isNumber(r,
messages.RECOVERY_ID_TYPE_INVALID), assert.isNumberInInterval(r, - 1, 4, messages.RECOVERY_ID_VALUE_INVALID), _ = initCompressedValue(_,
!0), E.recover(e, s, r, _);
}, ecdh:function (e,s)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.ecdh(e, s);
}, ecdhUnsafe:function (e,s,r)
{
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
r = initCompressedValue(r, !0), E.ecdhUnsafe(e, s, r);
}};
}, global.SIGN_LIB = module.exports;

803
src/HTML/JS/sha3.js Normal file
View File

@ -0,0 +1,803 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
(function ()
{
'use strict';
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if(NODE_JS && !root.RUN_NW_CLIENT)
{
root = global;
}
if(root.RUN_CLIENT)
{
root = window;
}
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
var ARRAY_BUFFER = !root.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var SHAKE_PADDING = [31, 7936, 2031616, 520093696];
var CSHAKE_PADDING = [4, 1024, 262144, 67108864];
var KECCAK_PADDING = [1, 256, 65536, 16777216];
var PADDING = [6, 1536, 393216, 100663296];
var SHIFT = [0, 8, 16, 24];
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777,
2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648,
32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649,
0, 2147516424, 2147483648];
var BITS = [224, 256, 384, 512];
var SHAKE_BITS = [128, 256];
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
var CSHAKE_BYTEPAD = {'128':168, '256':136};
if(root.JS_SHA3_NO_NODE_JS || !Array.isArray)
{
Array.isArray = function (obj)
{
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
var createOutputMethod = function (bits,padding,outputType)
{
return function (message)
{
return new Keccak(bits, padding, bits).update(message)[outputType]();
};
};
var createShakeOutputMethod = function (bits,padding,outputType)
{
return function (message,outputBits)
{
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
};
};
var createCshakeOutputMethod = function (bits,padding,outputType)
{
return function (message,outputBits,n,s)
{
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
};
};
var createKmacOutputMethod = function (bits,padding,outputType)
{
return function (key,message,outputBits,s)
{
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
};
};
var createOutputMethods = function (method,createMethod,bits,padding)
{
for(var i = 0; i < OUTPUT_TYPES.length; ++i)
{
var type = OUTPUT_TYPES[i];
method[type] = createMethod(bits, padding, type);
}
return method;
};
var createMethod = function (bits,padding,outputs)
{
var method = createOutputMethod(bits, padding, outputs);
method.create = function ()
{
return new Keccak(bits, padding, bits);
};
method.update = function (message)
{
return method.create().update(message);
};
return createOutputMethods(method, createOutputMethod, bits, padding);
};
var createMethodArray = function (bits,padding)
{
var method = createOutputMethod(bits, padding, 'array');
method.create = function ()
{
return new Keccak(bits, padding, bits);
};
method.update = function (message)
{
return method.create().update(message);
};
return createOutputMethods(method, createOutputMethod, bits, padding);
};
var createShakeMethod = function (bits,padding)
{
var method = createShakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits)
{
return new Keccak(bits, padding, outputBits);
};
method.update = function (message,outputBits)
{
return method.create(outputBits).update(message);
};
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
};
var createCshakeMethod = function (bits,padding)
{
var w = CSHAKE_BYTEPAD[bits];
var method = createCshakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits,n,s)
{
if(!n && !s)
{
return methods['shake' + bits].create(outputBits);
}
else
{
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
}
};
method.update = function (message,outputBits,n,s)
{
return method.create(outputBits, n, s).update(message);
};
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
};
var createKmacMethod = function (bits,padding)
{
var w = CSHAKE_BYTEPAD[bits];
var method = createKmacOutputMethod(bits, padding, 'hex');
method.create = function (key,outputBits,s)
{
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
};
method.update = function (key,message,outputBits,s)
{
return method.create(key, outputBits, s).update(message);
};
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
};
var algorithms = [{name:'keccak', padding:KECCAK_PADDING, bits:BITS, createMethod:createMethod}, {name:'sha3', padding:PADDING,
bits:BITS, createMethod:createMethod, outputs:'hex'}, {name:'sha3_array', padding:PADDING, bits:BITS, createMethod:createMethod,
outputs:'array'}, {name:'sha3_buf', padding:PADDING, bits:BITS, createMethod:createMethod, outputs:'buffer'}, {name:'shake',
padding:SHAKE_PADDING, bits:SHAKE_BITS, createMethod:createShakeMethod}, {name:'cshake', padding:CSHAKE_PADDING, bits:SHAKE_BITS,
createMethod:createCshakeMethod}, {name:'kmac', padding:CSHAKE_PADDING, bits:SHAKE_BITS, createMethod:createKmacMethod}];
var methods = {}, methodNames = [];
for(var i = 0; i < algorithms.length; ++i)
{
var algorithm = algorithms[i];
var bits = algorithm.bits;
for(var j = 0; j < bits.length; ++j)
{
var methodName = algorithm.name + '_' + bits[j];
methodNames.push(methodName);
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding, algorithm.outputs);
if(algorithm.name !== 'sha3')
{
var newMethodName = algorithm.name + bits[j];
methodNames.push(newMethodName);
methods[newMethodName] = methods[methodName];
}
}
}
function Keccak(bits,padding,outputBits)
{
this.blocks = [];
this.s = [];
this.padding = padding;
this.outputBits = outputBits;
this.reset = true;
this.block = 0;
this.start = 0;
this.blockCount = (1600 - (bits << 1)) >> 5;
this.byteCount = this.blockCount << 2;
this.outputBlocks = outputBits >> 5;
this.extraBytes = (outputBits & 31) >> 3;
for(var i = 0; i < 50; ++i)
{
this.s[i] = 0;
}
};
Keccak.prototype.update = function (message)
{
var notString = typeof message !== 'string';
if(notString && message.constructor === root.ArrayBuffer)
{
TO_ERROR_LOG("SHA3", 10, 'ERROR: Error type ArrayBuffer, use Uint8Array instead!');
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
var length = message.length;
if(notString)
{
if(typeof length !== 'number' || !Array.isArray(message) && !(ARRAY_BUFFER && ArrayBuffer.isView(message)))
{
TO_ERROR_LOG("SHA3", 20, 'ERROR: Input is invalid type, message=' + JSON.stringify(message));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
var blocks = this.blocks, byteCount = this.byteCount, blockCount = this.blockCount, index = 0, s = this.s, i, code;
while(index < length)
{
if(this.reset)
{
this.reset = false;
blocks[0] = this.block;
for(i = 1; i < blockCount + 1; ++i)
{
blocks[i] = 0;
}
}
if(notString)
{
for(i = this.start; index < length && i < byteCount; ++index)
{
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
}
else
{
for(i = this.start; index < length && i < byteCount; ++index)
{
code = message.charCodeAt(index);
if(code < 0x80)
{
blocks[i >> 2] |= code << SHIFT[i++ & 3];
}
else
if(code < 0x800)
{
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else
if(code < 0xd800 || code >= 0xe000)
{
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else
{
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
if(i >= byteCount)
{
this.start = i - byteCount;
this.block = blocks[blockCount];
for(i = 0; i < blockCount; ++i)
{
s[i] ^= blocks[i];
}
f(s);
this.reset = true;
}
else
{
this.start = i;
}
}
return this;
};
Keccak.prototype.encode = function (x,right)
{
var o = x & 255, n = 1;
var bytes = [o];
x = x >> 8;
o = x & 255;
while(o > 0)
{
bytes.unshift(o);
x = x >> 8;
o = x & 255;
++n;
}
if(right)
{
bytes.push(n);
}
else
{
bytes.unshift(n);
}
this.update(bytes);
return bytes.length;
};
Keccak.prototype.encodeString = function (str)
{
str = str || '';
var notString = typeof str !== 'string';
if(notString && str.constructor === root.ArrayBuffer)
{
str = new Uint8Array(str);
}
var length = str.length;
if(notString)
{
if(typeof length !== 'number' || !Array.isArray(str) && !(ARRAY_BUFFER && ArrayBuffer.isView(str)))
{
TO_ERROR_LOG("SHA3", 30, 'ERROR: Input is invalid type, str=' + JSON.stringify(str));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
var bytes = 0;
if(notString)
{
bytes = length;
}
else
{
for(var i = 0; i < str.length; ++i)
{
var code = str.charCodeAt(i);
if(code < 0x80)
{
bytes += 1;
}
else
if(code < 0x800)
{
bytes += 2;
}
else
if(code < 0xd800 || code >= 0xe000)
{
bytes += 3;
}
else
{
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
bytes += 4;
}
}
}
bytes += this.encode(bytes * 8);
this.update(str);
return bytes;
};
Keccak.prototype.bytepad = function (strs,w)
{
var bytes = this.encode(w);
for(var i = 0; i < strs.length; ++i)
{
bytes += this.encodeString(strs[i]);
}
var paddingBytes = w - bytes % w;
var zeros = [];
zeros.length = paddingBytes;
this.update(zeros);
return this;
};
Keccak.prototype.finalize = function ()
{
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3];
if(this.lastByteIndex === this.byteCount)
{
blocks[0] = blocks[blockCount];
for(i = 1; i < blockCount + 1; ++i)
{
blocks[i] = 0;
}
}
blocks[blockCount - 1] |= 0x80000000;
for(i = 0; i < blockCount; ++i)
{
s[i] ^= blocks[i];
}
f(s);
};
Keccak.prototype.toString = Keccak.prototype.hex = function ()
{
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var hex = '', block;
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
block = s[i];
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
}
if(j % blockCount === 0)
{
f(s);
i = 0;
}
}
if(extraBytes)
{
block = s[i];
if(extraBytes > 0)
{
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
}
if(extraBytes > 1)
{
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
}
if(extraBytes > 2)
{
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
}
}
return hex;
};
Keccak.prototype.arrayBuffer = function ()
{
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var bytes = this.outputBits >> 3;
var buffer;
if(extraBytes)
{
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
}
else
{
buffer = new ArrayBuffer(bytes);
}
var array = new Uint32Array(buffer);
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
array[j] = s[i];
}
if(j % blockCount === 0)
{
f(s);
}
}
if(extraBytes)
{
array[i] = s[i];
buffer = buffer.slice(0, bytes);
}
return buffer;
};
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
Keccak.prototype.digest = Keccak.prototype.array = function ()
{
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var array = [], offset, block;
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
offset = j << 2;
block = s[i];
array[offset] = block & 0xFF;
array[offset + 1] = (block >> 8) & 0xFF;
array[offset + 2] = (block >> 16) & 0xFF;
array[offset + 3] = (block >> 24) & 0xFF;
}
if(j % blockCount === 0)
{
f(s);
}
}
if(extraBytes)
{
offset = j << 2;
block = s[i];
if(extraBytes > 0)
{
array[offset] = block & 0xFF;
}
if(extraBytes > 1)
{
array[offset + 1] = (block >> 8) & 0xFF;
}
if(extraBytes > 2)
{
array[offset + 2] = (block >> 16) & 0xFF;
}
}
return array;
};
function Kmac(bits,padding,outputBits)
{
Keccak.call(this, bits, padding, outputBits);
};
Kmac.prototype = new Keccak();
Kmac.prototype.finalize = function ()
{
this.encode(this.outputBits, true);
return Keccak.prototype.finalize.call(this);
};
var f = function (s)
{
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40,
b41, b42, b43, b44, b45, b46, b47, b48, b49;
for(n = 0; n < 48; n += 2)
{
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
s[0] ^= h;
s[1] ^= l;
s[10] ^= h;
s[11] ^= l;
s[20] ^= h;
s[21] ^= l;
s[30] ^= h;
s[31] ^= l;
s[40] ^= h;
s[41] ^= l;
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
s[2] ^= h;
s[3] ^= l;
s[12] ^= h;
s[13] ^= l;
s[22] ^= h;
s[23] ^= l;
s[32] ^= h;
s[33] ^= l;
s[42] ^= h;
s[43] ^= l;
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
s[4] ^= h;
s[5] ^= l;
s[14] ^= h;
s[15] ^= l;
s[24] ^= h;
s[25] ^= l;
s[34] ^= h;
s[35] ^= l;
s[44] ^= h;
s[45] ^= l;
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
s[6] ^= h;
s[7] ^= l;
s[16] ^= h;
s[17] ^= l;
s[26] ^= h;
s[27] ^= l;
s[36] ^= h;
s[37] ^= l;
s[46] ^= h;
s[47] ^= l;
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
s[8] ^= h;
s[9] ^= l;
s[18] ^= h;
s[19] ^= l;
s[28] ^= h;
s[29] ^= l;
s[38] ^= h;
s[39] ^= l;
s[48] ^= h;
s[49] ^= l;
b0 = s[0];
b1 = s[1];
b32 = (s[11] << 4) | (s[10] >>> 28);
b33 = (s[10] << 4) | (s[11] >>> 28);
b14 = (s[20] << 3) | (s[21] >>> 29);
b15 = (s[21] << 3) | (s[20] >>> 29);
b46 = (s[31] << 9) | (s[30] >>> 23);
b47 = (s[30] << 9) | (s[31] >>> 23);
b28 = (s[40] << 18) | (s[41] >>> 14);
b29 = (s[41] << 18) | (s[40] >>> 14);
b20 = (s[2] << 1) | (s[3] >>> 31);
b21 = (s[3] << 1) | (s[2] >>> 31);
b2 = (s[13] << 12) | (s[12] >>> 20);
b3 = (s[12] << 12) | (s[13] >>> 20);
b34 = (s[22] << 10) | (s[23] >>> 22);
b35 = (s[23] << 10) | (s[22] >>> 22);
b16 = (s[33] << 13) | (s[32] >>> 19);
b17 = (s[32] << 13) | (s[33] >>> 19);
b48 = (s[42] << 2) | (s[43] >>> 30);
b49 = (s[43] << 2) | (s[42] >>> 30);
b40 = (s[5] << 30) | (s[4] >>> 2);
b41 = (s[4] << 30) | (s[5] >>> 2);
b22 = (s[14] << 6) | (s[15] >>> 26);
b23 = (s[15] << 6) | (s[14] >>> 26);
b4 = (s[25] << 11) | (s[24] >>> 21);
b5 = (s[24] << 11) | (s[25] >>> 21);
b36 = (s[34] << 15) | (s[35] >>> 17);
b37 = (s[35] << 15) | (s[34] >>> 17);
b18 = (s[45] << 29) | (s[44] >>> 3);
b19 = (s[44] << 29) | (s[45] >>> 3);
b10 = (s[6] << 28) | (s[7] >>> 4);
b11 = (s[7] << 28) | (s[6] >>> 4);
b42 = (s[17] << 23) | (s[16] >>> 9);
b43 = (s[16] << 23) | (s[17] >>> 9);
b24 = (s[26] << 25) | (s[27] >>> 7);
b25 = (s[27] << 25) | (s[26] >>> 7);
b6 = (s[36] << 21) | (s[37] >>> 11);
b7 = (s[37] << 21) | (s[36] >>> 11);
b38 = (s[47] << 24) | (s[46] >>> 8);
b39 = (s[46] << 24) | (s[47] >>> 8);
b30 = (s[8] << 27) | (s[9] >>> 5);
b31 = (s[9] << 27) | (s[8] >>> 5);
b12 = (s[18] << 20) | (s[19] >>> 12);
b13 = (s[19] << 20) | (s[18] >>> 12);
b44 = (s[29] << 7) | (s[28] >>> 25);
b45 = (s[28] << 7) | (s[29] >>> 25);
b26 = (s[38] << 8) | (s[39] >>> 24);
b27 = (s[39] << 8) | (s[38] >>> 24);
b8 = (s[48] << 14) | (s[49] >>> 18);
b9 = (s[49] << 14) | (s[48] >>> 18);
s[0] = b0 ^ (~b2 & b4);
s[1] = b1 ^ (~b3 & b5);
s[10] = b10 ^ (~b12 & b14);
s[11] = b11 ^ (~b13 & b15);
s[20] = b20 ^ (~b22 & b24);
s[21] = b21 ^ (~b23 & b25);
s[30] = b30 ^ (~b32 & b34);
s[31] = b31 ^ (~b33 & b35);
s[40] = b40 ^ (~b42 & b44);
s[41] = b41 ^ (~b43 & b45);
s[2] = b2 ^ (~b4 & b6);
s[3] = b3 ^ (~b5 & b7);
s[12] = b12 ^ (~b14 & b16);
s[13] = b13 ^ (~b15 & b17);
s[22] = b22 ^ (~b24 & b26);
s[23] = b23 ^ (~b25 & b27);
s[32] = b32 ^ (~b34 & b36);
s[33] = b33 ^ (~b35 & b37);
s[42] = b42 ^ (~b44 & b46);
s[43] = b43 ^ (~b45 & b47);
s[4] = b4 ^ (~b6 & b8);
s[5] = b5 ^ (~b7 & b9);
s[14] = b14 ^ (~b16 & b18);
s[15] = b15 ^ (~b17 & b19);
s[24] = b24 ^ (~b26 & b28);
s[25] = b25 ^ (~b27 & b29);
s[34] = b34 ^ (~b36 & b38);
s[35] = b35 ^ (~b37 & b39);
s[44] = b44 ^ (~b46 & b48);
s[45] = b45 ^ (~b47 & b49);
s[6] = b6 ^ (~b8 & b0);
s[7] = b7 ^ (~b9 & b1);
s[16] = b16 ^ (~b18 & b10);
s[17] = b17 ^ (~b19 & b11);
s[26] = b26 ^ (~b28 & b20);
s[27] = b27 ^ (~b29 & b21);
s[36] = b36 ^ (~b38 & b30);
s[37] = b37 ^ (~b39 & b31);
s[46] = b46 ^ (~b48 & b40);
s[47] = b47 ^ (~b49 & b41);
s[8] = b8 ^ (~b0 & b2);
s[9] = b9 ^ (~b1 & b3);
s[18] = b18 ^ (~b10 & b12);
s[19] = b19 ^ (~b11 & b13);
s[28] = b28 ^ (~b20 & b22);
s[29] = b29 ^ (~b21 & b23);
s[38] = b38 ^ (~b30 & b32);
s[39] = b39 ^ (~b31 & b33);
s[48] = b48 ^ (~b40 & b42);
s[49] = b49 ^ (~b41 & b43);
s[0] ^= RC[n];
s[1] ^= RC[n + 1];
}
};
root.sha3_str = methods.sha3_256;
root.sha3_array_256 = methods.sha3_array_256;
root.sha3 = methods.sha3_array_256;
root.sha = function (data)
{
return meshhash(methods.sha3_256(data));
};
root.shaarr = function (data)
{
return meshhash(methods.sha3_array_256(data));
};
root.shabuf = function (data)
{
return Buffer.from(shaarr(data));
};
root.shabuf = function (data)
{
return Buffer.from(shaarr(data));
};
root.SHA3BUF = function (data,num)
{
return Buffer.from(SHA3ARR(data, num));
};
root.SHA3ARR = function (data,num)
{
if(!NEW_SIGN_TIME || !num || num >= NEW_SIGN_TIME)
return sha3(data);
else
return meshhash(methods.sha3_array_256(data));
};
root.shaarrblock = function (data,num)
{
return meshhash(methods.sha3_array_256(data), num);
};
})();
function meshhash(hash,num)
{
var regs = [hash[3], hash[2], hash[1], hash[0]];
var mem = [];
for(var i = 0; i < 16; i++)
{
mem[i] = hash[i * 2] + (hash[i * 2 + 1] << 8);
}
var WasGoto = 0;
var L = 0;
for(var i = 0; i < 64; i++)
{
var c = hash[L & 31];
L++;
var a = (c >> 4) & 0xF;
var b = c & 0xF;
var r = c & 0x3;
switch(a)
{
case 0:
regs[0] = regs[0] + regs[r];
break;
case 1:
regs[0] = regs[0] * regs[r];
break;
case 2:
regs[0] = regs[0] | regs[r];
break;
case 3:
regs[0] = regs[0] & regs[r];
break;
case 4:
case 5:
case 6:
case 7:
regs[0] = regs[0] + regs[1] + regs[2] + regs[3];
break;
case 8:
if((regs[0] & 0xFFFF) < 32768 && !WasGoto)
{
L = 32 + L - b;
WasGoto = 1;
}
break;
case 9:
if((regs[0] & 0xFFFF) > 32768 && !WasGoto)
{
L += b;
WasGoto = 1;
}
break;
default:
regs[a % 4] = mem[b];
}
var index1 = regs[0] & 0xF;
var index2 = (regs[0] >> 8) & 0xF;
if(index1 !== index2)
{
var temp = mem[index1];
mem[index1] = mem[index2];
mem[index2] = temp;
}
}
var ret = [];
for(var i = 0; i < 16; i++)
{
ret[i * 2] = mem[i] & 0xFF;
ret[i * 2 + 1] = mem[i] >> 8;
}
return sha3_array_256(ret);
};

4140
src/HTML/JS/sign-lib-min.js vendored Normal file

File diff suppressed because it is too large Load Diff

411
src/HTML/JS/terahashlib.js Normal file
View File

@ -0,0 +1,411 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var DELTA_LONG_MINING = 5000;
var BLOCKNUM_ALGO2 = 6560000;
var BLOCKNUM_HASH_NEW = 10195000;
var BLOCKNUM_TICKET_ALGO = 16070000;
if (typeof global === "object") {
global.GetHashFromSeqAddr = GetHashFromSeqAddr;
global.CalcHashBlockFromSeqAddr = CalcHashBlockFromSeqAddr;
global.GetHashFromNum2 = GetHashFromNum2;
global.GetHashFromNum3 = GetHashFromNum3;
global.GetHashFromArrNum2 = GetHashFromArrNum2;
global.XORArr = XORArr;
global.GetHash = GetHash;
if (global.LOCAL_RUN || global.TEST_NETWORK) {
BLOCKNUM_ALGO2 = 0;
if (global.TEST_NETWORK) {
BLOCKNUM_HASH_NEW = 100;
BLOCKNUM_TICKET_ALGO = 0;
}
else {
BLOCKNUM_HASH_NEW = 100;
BLOCKNUM_TICKET_ALGO = 0;
}
}
}
function GetHashFromSeqAddr(SeqHash, AddrHash, BlockNum, PrevHash, MiningVer) {
if (BlockNum < BLOCKNUM_ALGO2) {
var Hash = shaarrblock2(SeqHash, AddrHash, BlockNum);
return { Hash: Hash, PowHash: Hash, Hash1: Hash, Hash2: Hash };
}
var MinerID = ReadUintFromArr(AddrHash, 0);
var Nonce0 = ReadUintFromArr(AddrHash, 6);
var Nonce1 = ReadUintFromArr(AddrHash, 12);
var Nonce2 = ReadUintFromArr(AddrHash, 18);
var DeltaNum1 = ReadUint16FromArr(AddrHash, 24);
var DeltaNum2 = ReadUint16FromArr(AddrHash, 26);
var PrevHashNum;
if (PrevHash) {
PrevHashNum = ReadUint32FromArr(PrevHash, 28);
}
else {
PrevHashNum = ReadUint32FromArr(AddrHash, 28);
}
var Data = GetHash(SeqHash, PrevHashNum, BlockNum, MinerID, Nonce0, Nonce1, Nonce2, DeltaNum1, DeltaNum2);
if (MiningVer) {
if (AddrHash[17] !== MiningVer || AddrHash[23] !== MiningVer) {
Data.PowHash = [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255];
}
}
return Data;
};
function GetHash(BlockHash, PrevHashNum, BlockNum, Miner, Nonce0, Nonce1, Nonce2, DeltaNum1, DeltaNum2) {
if (DeltaNum1 > DELTA_LONG_MINING)
DeltaNum1 = 0;
if (DeltaNum2 > DELTA_LONG_MINING)
DeltaNum2 = 0;
var HashBase = GetHashFromNum2(BlockNum, PrevHashNum);
var HashCurrent = GetHashFromArrNum2(BlockHash, Miner, Nonce0);
var HashNonce1 = GetHashFromNum3(BlockNum - DeltaNum1, Miner, Nonce1);
var HashNonce2 = GetHashFromNum3(BlockNum - DeltaNum2, Miner, Nonce2);
var Hash1 = XORArr(HashBase, HashNonce1);
var Hash2 = XORArr(HashCurrent, HashNonce2);
var Ret = { Hash: Hash2, Hash1: Hash1, Hash2: Hash2 };
if (CompareArr(Hash1, Hash2) > 0) {
Ret.PowHash = Hash1;
}
else {
Ret.PowHash = Hash2;
}
if (BlockNum >= BLOCKNUM_HASH_NEW) {
if (BlockNum >= BLOCKNUM_TICKET_ALGO)
Ret.Hash = sha3arr2(Hash1, Hash2);
else
Ret.Hash = shaarr2(Hash1, Hash2);
}
return Ret;
};
function CalcHashBlockFromSeqAddr(Block, PrevHash, MiningVer) {
var Value = GetHashFromSeqAddr(Block.SeqHash, Block.AddrHash, Block.BlockNum, PrevHash, MiningVer);
Block.Hash = Value.Hash;
Block.PowHash = Value.PowHash;
};
function XORArr(Arr1, Arr2) {
var Ret = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for (var i = 0; i < 32; i++) {
Ret[i] = Arr1[i] ^ Arr2[i];
}
return Ret;
};
function GetHashFromNum2(Value1, Value2) {
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
WriteUintToArrOnPos(MeshArr, Value1, 0);
WriteUintToArrOnPos(MeshArr, Value2, 6);
return sha3(MeshArr);
};
function GetHashFromArrNum2(Arr, Value1, Value2) {
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0];
WriteArrToArrOnPos(MeshArr, Arr, 0, 32);
WriteUintToArrOnPos(MeshArr, Value1, 32);
WriteUintToArrOnPos(MeshArr, Value2, 38);
return sha3(MeshArr);
};
function GetHashFromNum3(Value1, Value2, Value3) {
var MeshArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
WriteUintToArrOnPos(MeshArr, Value1, 0);
WriteUintToArrOnPos(MeshArr, Value2, 6);
WriteUintToArrOnPos(MeshArr, Value3, 12);
return sha3(MeshArr);
};
function ReadUintFromArr(arr, len) {
if (len === undefined) {
len = arr.len;
arr.len += 6;
}
var value = (arr[len + 5] << 23) * 2 + (arr[len + 4] << 16) + (arr[len + 3] << 8) + arr[len + 2];
value = value * 256 + arr[len + 1];
value = value * 256 + arr[len];
return value;
};
function ReadUint32FromArr(arr, len) {
if (len === undefined) {
len = arr.len;
arr.len += 4;
}
var value = (arr[len + 3] << 23) * 2 + (arr[len + 2] << 16) + (arr[len + 1] << 8) + arr[len];
return value;
};
function ReadUint16FromArr(arr, len) {
if (len === undefined) {
len = arr.len;
arr.len += 2;
}
var value = (arr[len + 1] << 8) + arr[len];
return value;
};
function ReadArrFromArr(arr, length) {
var Ret = [];
var len = arr.len;
for (var i = 0; i < length; i++) {
Ret[i] = arr[len + i];
}
arr.len += length;
return Ret;
};
function WriteUintToArr(arr, Num) {
var len = arr.length;
arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF;
arr[len + 2] = (Num >>> 16) & 0xFF;
arr[len + 3] = (Num >>> 24) & 0xFF;
var NumH = Math.floor(Num / 4294967296);
arr[len + 4] = NumH & 0xFF;
arr[len + 5] = (NumH >>> 8) & 0xFF;
};
function WriteUintToArrOnPos(arr, Num, Pos) {
arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF;
arr[Pos + 2] = (Num >>> 16) & 0xFF;
arr[Pos + 3] = (Num >>> 24) & 0xFF;
var NumH = Math.floor(Num / 4294967296);
arr[Pos + 4] = NumH & 0xFF;
arr[Pos + 5] = (NumH >>> 8) & 0xFF;
};
function WriteUint32ToArr(arr, Num) {
var len = arr.length;
arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF;
arr[len + 2] = (Num >>> 16) & 0xFF;
arr[len + 3] = (Num >>> 24) & 0xFF;
};
function WriteUint32ToArrOnPos(arr, Num, Pos) {
arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF;
arr[Pos + 2] = (Num >>> 16) & 0xFF;
arr[Pos + 3] = (Num >>> 24) & 0xFF;
};
function WriteUint16ToArrOnPos(arr, Num, Pos) {
arr[Pos] = Num & 0xFF;
arr[Pos + 1] = (Num >>> 8) & 0xFF;
};
function WriteArrToArr(arr, arr2, ConstLength) {
var len = arr.length;
for (var i = 0; i < ConstLength; i++) {
arr[len + i] = arr2[i];
}
};
function WriteArrToArrOnPos(arr, arr2, Pos, ConstLength) {
for (var i = 0; i < ConstLength; i++) {
arr[Pos + i] = arr2[i];
}
};
function WriteArrToArrHOnPos(arr, arr2, Pos, ConstLength) {
for (var i = 0; i < ConstLength; i++) {
arr[Pos + i] |= (arr2[i] << 8);
}
};
function ConvertBufferToStr(Data) {
for (var key in Data) {
var item = Data[key];
if (item instanceof Buffer) {
Data[key] = GetHexFromArr(item);
}
else
if (typeof item === "object")
ConvertBufferToStr(item);
}
};
function CopyObjValue(obj, num) {
if (num && num > 5)
return obj;
var ret = {};
for (var key in obj) {
var val = obj[key];
if ((typeof val === "object") && !(val instanceof Buffer) && !(val instanceof ArrayBuffer) && !(val instanceof Array))
val = CopyObjValue(val, num + 1);
ret[key] = val;
}
return ret;
};
function CopyArr(arr1) {
var arr2 = [];
if (arr1)
for (var i = 0; i < arr1.length; i++)
arr2[i] = arr1[i];
return arr2;
};
function ParseNum(a) {
var Num = parseInt(a);
if (!Num)
Num = 0;
if (isNaN(Num))
Num = 0;
if (Num < 0)
Num = 0;
return Num;
};
function CompareArr(a, b) {
for (var i = 0; i < a.length; i++) {
if (a[i] !== b[i])
return a[i] - b[i];
}
return 0;
};
function CompareArrL(a, b) {
if (a.length !== b.length)
return a.length - b.length;
for (var i = 0; i < a.length; i++) {
if (a[i] !== b[i])
return a[i] - b[i];
}
return 0;
};
function GetSeqHash(BlockNum, PrevHash, TreeHash) {
var arr = [GetArrFromValue(BlockNum), PrevHash, TreeHash];
var SeqHash = CalcHashFromArray(arr, true);
return SeqHash;
};
function arr2(Value1, Value2) {
var Buf = [];
for (var n = 0; n < Value1.length; n++)
Buf.push(Value1[n]);
for (var n = 0; n < Value2.length; n++)
Buf.push(Value2[n]);
return Buf;
};
function shaarr2(Value1, Value2) {
return shaarr(arr2(Value1, Value2));
};
function sha3arr2(Value1, Value2) {
return sha3(arr2(Value1, Value2));
};
function GetBlockArrFromBuffer(BufRead, Info) {
if (!BufRead || BufRead.length < 10)
return [];
var BLOCK_PROCESSING_LENGTH = 8;
var BLOCK_PROCESSING_LENGTH2 = BLOCK_PROCESSING_LENGTH * 2;
BufRead.len = 0;
var StartNum = ReadUintFromArr(BufRead);
var CountLoad = ReadUint32FromArr(BufRead);
var BufSize = 6 + 4 + BLOCK_PROCESSING_LENGTH2 * 32 + 32 + 6 + CountLoad * 64;
if (CountLoad <= 0 || BufSize !== BufRead.length) {
return [];
}
var PrevBlock;
var BlockArr = [];
for (var i = 0; i < CountLoad + BLOCK_PROCESSING_LENGTH2; i++) {
var Block = {};
Block.BlockNum = StartNum + i;
if (i < BLOCK_PROCESSING_LENGTH2) {
Block.Hash = ReadArrFromArr(BufRead, 32);
}
else {
if (i === BLOCK_PROCESSING_LENGTH2) {
Block.SumHash = ReadArrFromArr(BufRead, 32);
Block.SumPow = ReadUintFromArr(BufRead);
}
Block.TreeHash = ReadArrFromArr(BufRead, 32);
Block.AddrHash = ReadArrFromArr(BufRead, 32);
var arr = [];
var start = i - BLOCK_PROCESSING_LENGTH2;
for (var n = 0; n < BLOCK_PROCESSING_LENGTH; n++) {
var Prev = BlockArr[start + n];
arr.push(Prev.Hash);
}
Block.PrevHash = CalcHashFromArray(arr, true);
Block.SeqHash = GetSeqHash(Block.BlockNum, Block.PrevHash, Block.TreeHash);
var PrevHashNum = ReadUint32FromArr(Block.PrevHash, 28);
var PrevAddrNum = ReadUint32FromArr(Block.AddrHash, 28);
if (PrevHashNum !== PrevAddrNum && Block.BlockNum > 20000000) {
if (global.WATCHDOG_DEV) {
var Str = "";
if (Info && Info.Node)
Str = " from " + NodeName(Info.Node);
ToError("Error on block load: " + Block.BlockNum + Str);
}
return [];
}
CalcHashBlockFromSeqAddr(Block, Block.PrevHash);
Block.Power = GetPowPower(Block.PowHash);
if (PrevBlock) {
Block.SumHash = shaarr2(PrevBlock.SumHash, Block.Hash);
}
PrevBlock = Block;
}
Block.TrCount = 0;
Block.TrDataPos = 0;
Block.TrDataLen = 0;
BlockArr.push(Block);
}
for (var i = BlockArr.length - 1; i >= 0; i--) {
var Block = BlockArr[i];
if (!Block.SumHash) {
BlockArr = BlockArr.slice(i + 1);
break;
}
}
return BlockArr;
};
function shaarrblock2(Value1, Value2, BlockNum) {
return shaarrblock(arr2(Value1, Value2), BlockNum);
};
if (typeof global === "object") {
global.ReadUint32FromArr = ReadUint32FromArr;
global.ReadUintFromArr = ReadUintFromArr;
global.ReadUint16FromArr = ReadUint16FromArr;
global.WriteUintToArr = WriteUintToArr;
global.WriteUint32ToArr = WriteUint32ToArr;
global.WriteUint32ToArrOnPos = WriteUint32ToArrOnPos;
global.WriteUint16ToArrOnPos = WriteUint16ToArrOnPos;
global.WriteUintToArrOnPos = WriteUintToArrOnPos;
global.WriteArrToArr = WriteArrToArr;
global.WriteArrToArrOnPos = WriteArrToArrOnPos;
global.WriteArrToArrHOnPos = WriteArrToArrHOnPos;
global.ConvertBufferToStr = ConvertBufferToStr;
global.CopyObjValue = CopyObjValue;
global.CopyArr = CopyArr;
global.ParseNum = ParseNum;
global.CompareArr = CompareArr;
global.CompareArrL = CompareArrL;
global.shaarr2 = shaarr2;
global.sha3arr2 = sha3arr2;
global.arr2 = arr2;
global.GetBlockArrFromBuffer = GetBlockArrFromBuffer;
global.shaarrblock2 = shaarrblock2;
}
else
if (typeof window === "object") {
global = window;
}

10
src/HTML/JS/tx-lib.js Normal file
View File

@ -0,0 +1,10 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/

706
src/HTML/JS/wallet-lib.js Normal file
View File

@ -0,0 +1,706 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var PayList = [];
var AttachItem;
var MapAccounts = {};
var LoadMapAfter = {};
var MapCheckTransaction = {};
var CanSendTransaction = 1;
var CurrentTR = {};
var MaxBlockNum = 0;
var DelList = {};
var WasAccountsDataStr;
function SetAccountsData(Data,AccountsDataStr)
{
if(!Data || !Data.result)
return ;
if($("idBtRun"))
$("idBtRun").style.display = (Data.arr.length ? '' : 'none');
if(AccountsDataStr === WasAccountsDataStr)
return ;
WasAccountsDataStr = AccountsDataStr;
var arr = Data.arr;
var Select = $("idAccount");
if(arr.length !== Select.options.length)
{
var options = Select.options;
options.length = arr.length;
}
MaxBlockNum = GetCurrentBlockNumByTime();
SetGridData(arr, "grid_accounts", "idMyTotalSum");
for(var i = 0; arr && i < arr.length; i++)
{
var Item = arr[i];
Item.MyAccount = true;
var Num = ParseNum(Item.Num);
if(!MapAccounts[Num])
MapAccounts[Num] = {};
CopyObjKeys(MapAccounts[Num], Item);
var option = Select.options[i];
var StrText = GetAccountText(Item, Num, 1);
if(option.text !== StrText)
CheckNameAccTo();
option.value = Num;
option.text = StrText;
}
var CurentValue = LoadMapAfter["idAccount"];
if(CurentValue)
{
Select.value = CurentValue;
delete LoadMapAfter["idAccount"];
}
SetCurCurencyName();
};
function CurTransactionToForm(bForce)
{
var Item = $("idTransaction");
if(Item && (Item.className === "" || bForce))
Item.value = GetJSONFromTransaction(CurrentTR);
};
function CheckNameAccTo()
{
MaxBlockNum = GetCurrentBlockNumByTime();
var ToID = ParseNum($("idTo").value);
if(!MapAccounts[ToID] || (MapAccounts[ToID].MustUpdate && MapAccounts[ToID].MustUpdate >= MaxBlockNum))
{
GetData("GetAccountList", {StartNum:ToID}, function (Data)
{
if(Data && Data.result === 1 && Data.arr.length)
{
var Item = Data.arr[0];
Item.UpdateData = Date.now();
MapAccounts[Item.Num] = Item;
SetNameAccTo();
}
});
}
SetNameAccTo();
};
function SetNameAccTo()
{
var Str = "";
var ToID = ParseNum($("idTo").value);
var Item = MapAccounts[ToID];
var element = $("idNameTo");
var StrTo = GetAccountText(Item, ToID, 1);
if(!element)
{
element = $("idNameTo2");
}
else
{
StrTo = "To: " + StrTo;
}
if(element.innerText !== StrTo)
{
element.innerText = StrTo;
if(Item && Item.MyAccount)
element.className = "smallbold";
else
element.className = "";
}
};
function GetAccountText(Item,Num,bGetSum)
{
if(Item)
{
var text = Item.Name;
if(!text || text.length === 0)
text = Num;
else
text = "" + Num + ". " + text;
if(bGetSum)
{
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency);
text += " (" + StrSum + ")";
}
return text;
}
else
{
return Num;
}
};
function OnEditIdTo()
{
CheckNameAccTo();
OnEditTransactionFields();
};
function OnEditTransactionFields()
{
if(IsVisibleBlock("edit_transaction"))
CreateTransaction();
SetCurCurencyName();
SaveValues();
};
function SetCurCurencyName()
{
var idCoin = $("idCoinName");
if(!idCoin)
return ;
var Num = ParseNum($("idAccount").value);
var Item = MapAccounts[Num];
if(Item)
{
idCoin.innerText = CurrencyName(Item.Currency);
}
};
function CreateTransaction(F,CheckErr,Run)
{
CheckNameAccTo();
CheckSending();
var FromID = ParseNum($("idAccount").value);
if(CheckErr && FromID === 0)
{
SetError("Select valid 'From account'");
return ;
}
var StrTo = $("idTo").value.trim();
var bFindAcc = 0;
var ToPubKey = "";
var ToID = ParseNum(StrTo);
if(StrTo !== "" + ToID)
{
if(StrTo.length === 66 && (StrTo.substr(0, 2) === "02" || StrTo.substr(0, 2) === "03") && IsHexStr(StrTo))
{
ToID = 0;
ToPubKey = StrTo;
if(ToPubKey === PubKeyStr)
bFindAcc = 1;
}
else
{
if(CheckErr)
SetError("Valid 'Pay to' - required!");
return ;
}
}
if(CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem)
{
SetError("Valid 'Pay to' - required!");
return ;
}
var Description = $("idDescription").value.substr(0, 200);
var StrSum = $("idSumSend").value;
var indDot = StrSum.indexOf(".");
if(indDot >= 0)
{
var StrTER = StrSum.substr(0, indDot);
var StrCENT = StrSum.substr(indDot + 1);
}
else
{
var StrTER = StrSum;
var StrCENT = "0";
}
StrCENT = StrCENT + "000000000";
var Coin = {SumCOIN:ParseNum(StrTER), SumCENT:ParseNum(StrCENT.substr(0, 9))};
var OperationID = 0;
var Item = MapAccounts[FromID];
if(Item)
{
OperationID = Item.Value.OperationID;
}
var AttachBody = [];
if(AttachItem)
{
AttachBody = AttachItem.Data.Body;
if(!AttachBody)
AttachBody = [];
}
var ToPubKeyArr = [];
if(ToPubKey)
ToPubKeyArr = GetArrFromHex(ToPubKey);
var TR = {Type:111, Version:3, Reserve:0, FromID:FromID, OperationID:OperationID, To:[{PubKey:ToPubKeyArr, ID:ToID, SumCOIN:Coin.SumCOIN,
SumCENT:Coin.SumCENT}], Description:Description, Body:AttachBody, Sign:CurrentTR.Sign, };
Object.defineProperties(TR, {bFindAcc:{configurable:true, writable:true, enumerable:false, value:bFindAcc}});
Object.defineProperties(TR, {Run:{configurable:true, writable:true, enumerable:false, value:Run}});
if(JSON.stringify(TR) === JSON.stringify(CurrentTR))
{
if(F)
F(CurrentTR);
return ;
}
CurrentTR = TR;
GetSignTransaction(TR, "", function (TR)
{
CurTransactionToForm(true);
if(F)
F(TR);
});
};
function SignJSON(F)
{
if($("idSignJSON").disabled)
return ;
var TR = GetTransactionFromJSON();
if(!TR)
return ;
CurrentTR = TR;
GetSignTransaction(TR, "", function (TR)
{
CurTransactionToForm(true);
if(F)
F();
});
};
function CheckSending(bToStatus)
{
MaxBlockNum = GetCurrentBlockNumByTime();
var CanSend = IsPrivateMode();
var StrButton = "Send";
var StrButtonSign = "Sign JSON";
if(!CanSend)
{
StrButton = " ";
StrButtonSign = " ";
}
if(CanSend)
{
var FromID = ParseNum($("idAccount").value);
var Item = MapAccounts[FromID];
if(Item && Item.NextSendTime && Item.NextSendTime > MaxBlockNum)
{
if(bToStatus)
SetStatus("Transaction was sending. Wait... (" + Item.LastTransactionText + ")");
CanSend = false;
StrButton = "Wait...";
}
}
$("idSendButton").disabled = (!CanSend);
$("idSendButton").value = StrButton;
$("idSignJSON").disabled = (!CanSend);
$("idSignJSON").value = StrButtonSign;
return CanSend;
};
function AddWhiteList()
{
var ToID = ParseNum($("idTo").value);
if(ToID && $("idWhiteOnSend").checked)
Storage.setItem("White:" + ToID, 1);
};
function SendMoneyBefore()
{
if($("idSendButton").disabled)
return ;
var ToID = ParseNum($("idTo").value);
var Item = MapAccounts[ToID];
if(Storage.getItem("White:" + ToID) || !$("idSumSend").value || Item && Item.MyAccount)
{
SendMoney();
}
else
{
var CoinAmount = COIN_FROM_FLOAT($("idSumSend").value);
var StrTo = " to " + GetAccountText(Item, ToID);
$("idWhiteOnSend").checked = 0;
$("idOnSendText").innerHTML = "<B style='color:#ff4534'>" + STRING_FROM_COIN(CoinAmount) + "</B> " + $("idCoinName").innerText + StrTo;
if($("idSumSend").value >= 100000)
{
$("idOnSendText").innerHTML += "<BR><DIV style='color: yellow;'>WARNING: You are about to send a very large amount!</DIV>";
}
SetVisibleBlock("idBlockOnSend", 1);
SetImg(this, 'idBlockOnSend');
}
};
function SendMoney2()
{
AddWhiteList();
SendMoney();
};
function SendMoney()
{
if(!CanSendTransaction)
{
SetError("Can't Send transaction");
return ;
}
CheckSending(true);
if($("idSendButton").disabled)
return ;
SetVisibleBlock("idBlockOnSend", 0);
CreateTransaction(SendMoneyTR, true, ClearAttach);
};
function GetJSONFromTransaction(TR)
{
var TR2 = JSON.parse(JSON.stringify(TR));
for(var i = 0; i < TR2.To.length; i++)
{
var Item = TR2.To[i];
Item.PubKey = GetHexFromArr(Item.PubKey);
}
TR2.Body = GetHexFromArr(TR2.Body);
TR2.Sign = GetHexFromArr(TR2.Sign);
var Str = JSON.stringify(TR2, "", 4);
return Str;
};
function GetTransactionFromJSON()
{
var Str = $("idTransaction").value;
try
{
var TR = JSON.parse(Str);
}
catch(e)
{
SetError(e);
return undefined;
}
for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i];
Item.PubKey = GetArrFromHex(Item.PubKey);
if(Item.SumTER && Item.SumCOIN === undefined)
{
Item.SumCOIN = Item.SumTER;
delete Item.SumTER;
}
}
TR.Body = GetArrFromHex(TR.Body);
TR.Sign = GetArrFromHex(TR.Sign);
return TR;
};
function SendMoneyJSON()
{
if(!CanSendTransaction)
{
SetError("Can't Send transaction");
return ;
}
var TR = GetTransactionFromJSON();
if(!TR)
return ;
SendMoneyTR(TR);
};
function SignAndSendFromJSON()
{
SignJSON(SendMoneyJSON);
};
function GetTransactionText(TR,key)
{
var Str;
if(TR)
{
if(TR.Type === TYPE_TRANSACTION_CREATE)
{
Str = "New account " + TR.Name.substr(0, 20);
}
else
if(TR.Type === 111)
{
var MapItem = {};
var ValueTotal = {SumCOIN:0, SumCENT:0};
Str = "" + TR.FromID + "/" + TR.OperationID + " to ";
for(var i = 0; i < TR.To.length; i++)
{
var Item = TR.To[i];
if(Item.ID === TR.FromID || MapItem[Item.ID])
continue;
MapItem[Item.ID] = 1;
ADD(ValueTotal, Item);
if(i === 0)
Str += "[";
if(Str.length < 16)
{
if(i > 0)
Str += ",";
if(Item.ID || (Item.PubKey && Item.PubKey.length !== 66))
Str += Item.ID;
else
Str += GetHexFromArr(Item.PubKey).substr(0, 8);
}
else
if(Str.substr(Str.length - 1) !== ".")
Str += "...";
}
Str += "] " + SUM_TO_STRING(ValueTotal);
Str += " " + (TR.Description.substr(0, 20)).replace(/\n/g, "");
}
}
else
{
if(key)
Str = key;
else
Str = "";
}
return Str;
};
function SendMoneyTR(TR)
{
var Body = GetArrFromTR(TR);
WriteArr(Body, TR.Sign, 64);
Body.length += 12;
SendTransaction(Body, TR, undefined, function (Err,TR,Body)
{
if(Err)
return ;
var Item = MapAccounts[TR.FromID];
if(Item)
{
var key = GetHexFromArr(sha3(Body));
var BlockNum = GetCurrentBlockNumByTime();
Item.LastTransactionText = GetTransactionText(TR);
Item.NextSendTime = BlockNum + 10;
MapCheckTransaction[key] = Item;
CheckSending();
}
});
};
function ClearTransaction()
{
PayList = [];
ClearAttach();
CheckSendList(1);
var arr = ["idAccount", "idTo", "idSumSend", "idDescription"];
for(var i = 0; i < arr.length; i++)
{
$(arr[i]).value = "";
}
SaveValues();
CreateTransaction();
};
function StartEditTransactionJSON()
{
var Item = $("idTransaction");
Item.className = "smallbold";
};
function EditJSONTransaction()
{
var name = "edit_transaction";
var Item = $("idTransaction");
if(IsVisibleBlock(name))
{
SetVisibleBlock(name, false);
Item.className = "";
}
else
{
CreateTransaction();
SetVisibleBlock(name, true);
Item.className = "";
}
};
var glNumPayCount = 0;
function GetInvoiceHTML(item,onclick,classstr)
{
if(!item.num)
{
glNumPayCount++;
item.num = glNumPayCount;
}
var idname = "idSendInvoice" + item.num;
var value = "";
if(item.Data.Amount)
value += "<B>" + item.Data.Amount + "</B> Tera";
else
value += "<B style='color:green'>No pay</B>";
value += "&#x00A;" + item.num + ". " + item.Data.name;
return "<button id='" + idname + "' onclick='" + onclick + "' class='" + classstr + "'>" + value + "</button>";
};
function AddSendList(item)
{
PayList.push({Data:item});
};
function CheckSendList(bRedraw)
{
TitleWarning = PayList.length;
if(AttachItem)
TitleWarning++;
var Str = Storage.getItem("InvoiceList");
if(!Str && !bRedraw)
return ;
if(!bRedraw)
{
SelectTab("TabSend");
}
if(Str)
{
var arr = JSON.parse(Str);
for(var i = 0; i < arr.length; i++)
{
AddSendList(arr[i]);
}
Storage.setItem("InvoiceList", "");
}
var idList = $("idSendList");
if(PayList.length)
{
idList.innerHTML = "<DIV id='PaiListInfo'>Select the item you want to sign (pay) and send to blockchain:</DIV>";
for(var i = 0; i < PayList.length; i++)
{
var item = PayList[i];
idList.innerHTML += GetInvoiceHTML(item, "UseInvoice(" + i + ")", "btinvoice");
}
if(AttachItem === undefined)
UseInvoice(0);
}
else
{
idList.innerHTML = "";
}
};
setInterval(CheckSendList, 200);
function UseInvoice(Num)
{
var item = PayList[Num];
if(item.Data.From)
$("idAccount").value = item.Data.From;
$("idTo").value = item.Data.To;
$("idSumSend").value = item.Data.Amount;
$("idDescription").value = item.Data.Description;
PayList.splice(Num, 1);
AttachItem = item;
$("idAttach").innerHTML = GetInvoiceHTML(AttachItem, "OpenAttach()", "btinvoice btinvoice_use");
CheckSendList(1);
};
function ClearAttach()
{
AttachItem = undefined;
if($("idAttach"))
$("idAttach").innerHTML = "";
};
function OpenAttach()
{
if(AttachItem)
{
var Data2 = JSON.parse(JSON.stringify(AttachItem.Data));
if(Data2.Body)
Data2.Body = GetHexFromArr(Data2.Body);
delete Data2.TransferSecret;
alert("DATA:\n" + JSON.stringify(Data2, "", 4));
}
};
var CURRENCY, PUBKEY, NAME, SMART;
function SendTrCreateAccWait(Currency,PubKey,Name,Smart)
{
CURRENCY = Currency;
PUBKEY = PubKey;
NAME = Name;
SMART = Smart;
setTimeout(function ()
{
SendTrCreateAcc(CURRENCY, PUBKEY, NAME, 0, SMART, 0, 0);
}, 50);
};
function SendTrCreateAcc(Currency,PubKey,Description,Adviser,Smart,bFindAcc,bAddToPay)
{
var TR = GetTrCreateAcc(Currency, PubKey, Description, Adviser, Smart);
var Body = GetBodyCreateAcc(TR);
TR.bFindAcc = 1;
if(bAddToPay)
{
var Item = {name:Description, To:0, Amount:CONFIG_DATA.PRICE_DAO.NewAccount, Description:"Create acc: " + Description, Body:Body,
};
AddToInvoiceList(Item);
}
else
{
SendTransaction(Body, TR);
}
$("idAccountName").value = "";
CancelCreateAccount();
};
function ChangeSmart(NumAccount,WasSmart)
{
if(!IsPrivateMode())
{
SetError("Pls, open wallet");
return 0;
}
var Result = prompt("Enter smart number:", WasSmart);
if(Result !== null && Result != WasSmart)
{
var Smart = parseInt(Result);
if(Smart)
{
GetData("GetDappList", {StartNum:Smart, CountNum:1}, function (Data)
{
if(Data && Data.result && Data.arr.length === 1)
{
SetSmartToAccount(NumAccount, Smart);
}
else
{
SetError("Error smart number");
}
});
}
else
{
SetSmartToAccount(NumAccount, Smart);
}
}
};
function SetSmartToAccount(NumAccount,Smart)
{
var OperationID = 0;
var Item = MapAccounts[NumAccount];
if(Item)
{
OperationID = Item.Value.OperationID;
}
OperationID++;
var TR = {Type:140, Account:NumAccount, Smart:Smart, FromNum:NumAccount, Reserve:[], OperationID:OperationID, Sign:"", };
var Body = [];
WriteByte(Body, TR.Type);
WriteUint(Body, TR.Account);
WriteUint32(Body, TR.Smart);
WriteArr(Body, TR.Reserve, 10);
WriteUint(Body, TR.FromNum);
WriteUint(Body, TR.OperationID);
SendTrArrayWithSign(Body, TR.Account, TR);
};
function CheckLengthAccDesription(name,Length)
{
var Str = $(name).value.substr(0, Length + 1);
var arr = toUTF8Array(Str);
var Len = Length - arr.length;
if(Len < 0)
SetError("Bad length");
else
SetStatus("Lost: " + Len + " bytes");
};

542
src/HTML/JS/wallet-node.js Normal file
View File

@ -0,0 +1,542 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
function SavePrivateKey()
{
var Select = document.getElementById("idTypeKey");
if(Select.value === "brain")
{
ConvertToPrivateKey();
return ;
}
var Str = document.getElementById("idKeyNew").value;
Str = Str.trim();
if(Select.value === "private" && (Str.length !== 64 || !IsHexStr(Str)))
{
SetError("Error: Length must 64 HEX chars. (Length=" + Str.length + ")");
return ;
}
else
if(Select.value !== "private" && (Str.length !== 66 || Str.substr(0, 1) !== "0" || !IsHexStr(Str)))
{
SetError("Error: Length must 66 HEX chars. (Length=" + Str.length + ")");
return ;
}
if(Select.value === "private" && PrivKeyStr !== Str)
SetStatus("Changed privat key");
else
if(Select.value === "public" && PubKeyStr !== Str)
SetStatus("Changed public key");
GetData("SetWalletKey", Str, function (Data)
{
if(Data && Data.result === 1)
{
if(Select.value === "private")
SelectStyle("styleContrast1");
else
if(Select.value === "public")
SelectStyle("styleContrast2");
SetVisibleEditKeys(0);
UpdatesData();
}
});
};
function CreateCheckPoint()
{
if(!ServerBlockNumDB || ServerBlockNumDB < 16)
{
SetError("Not set ServerBlockNumDB");
return ;
}
var BlockNum = ServerBlockNumDB - 10;
SetCheckPoint(BlockNum);
};
function UseAutoCheckPoint()
{
var Set = $("idUseAutoCheckPoint").checked;
var Period = ParseNum($("idPeriodAutoCheckPoint").value);
GetData("SetAutoCheckPoint", {Set:Set, Period:Period}, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result);
}
});
};
function UseAutoCorrTime()
{
GetData("SetAutoCorrTime", document.getElementById("idUseAutoCorrTime").checked, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result);
}
});
};
function SetCodeVersionJSON()
{
var Data = JSON.parse(JSON.stringify(CONFIG_DATA.CODE_VERSION));
if(!Data.BlockNum)
{
Data.LevelUpdate = 160;
}
Data.BlockNum = CONFIG_DATA.CurBlockNum;
Data.addrArr = GetHexFromArr(Data.addrArr);
Data.Hash = GetHexFromArr(Data.Hash);
Data.Sign = GetHexFromArr(Data.Sign);
Data.Hash = undefined;
Data.Sign = undefined;
Data.StartLoadVersionNum = undefined;
var Str = JSON.stringify(Data, "", 2);
document.getElementById("idDevService").value = Str;
};
function SetCorrTimeJSON()
{
var AutoDelta = parseInt(document.getElementById("idDevValue").value);
var Data = {Num:CONFIG_DATA.CurBlockNum, bUse:1, bAddTime:1};
if(AutoDelta < 0)
{
AutoDelta = - AutoDelta;
Data.bAddTime = 0;
}
Data.DeltaTime = 40;
Data.StartBlockNum = ServerCurBlockNum + 10;
Data.EndBlockNum = Data.StartBlockNum + Math.floor(AutoDelta / Data.DeltaTime);
var Str = JSON.stringify(Data, "", 2);
document.getElementById("idDevService").value = Str;
};
function SetNetConstJSON()
{
var Str = JSON.stringify(Data, "", 2);
document.getElementById("idDevService").value = Str;
var Data = {MaxTrasactionLimit:CONFIG_DATA.MAX_TRANSACTION_LIMIT};
var Str = JSON.stringify(Data, "", 2);
document.getElementById("idDevService").value = Str;
};
function SetNewCodeVersion()
{
try
{
var Data = JSON.parse(document.getElementById("idDevService").value);
}
catch(e)
{
SetError("Error format setting data");
return ;
}
Data.addrArr = GetArrFromHex(Data.addrArr);
GetData("SetNewCodeVersion", Data, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result);
}
});
};
function StartTimeCorrect()
{
try
{
var Data = JSON.parse(document.getElementById("idDevService").value);
}
catch(e)
{
SetError("Error format setting data");
return ;
}
GetData("SetCheckDeltaTime", Data, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result);
}
});
};
function StartNetConst()
{
try
{
var Data = JSON.parse(document.getElementById("idDevService").value);
}
catch(e)
{
SetError("Error format setting data");
return ;
}
GetData("SetCheckNetConstant", Data, function (Data)
{
if(Data)
{
SetStatus(Data.text, !Data.result);
}
});
};
function RestartNode()
{
GetData("RestartNode", {});
DoRestartWallet();
};
function UseAutoUpdate()
{
var Data = {USE_AUTO_UPDATE:document.getElementById("idAutoUpdate").checked, DoMining:1};
GetData("SaveConstant", Data, function (Data)
{
if(Data && Data.result)
{
SetStatus("Save AutoUpdate: " + document.getElementById("idAutoUpdate").checked);
}
});
};
function UseMining()
{
if(!MiningAccount)
{
SetError("Not set mining account");
return ;
}
var Data = {USE_MINING:document.getElementById("idUseMining").checked, DoMining:1};
GetData("SaveConstant", Data, function (Data)
{
if(Data && Data.result)
{
SetStatus("Save Mining: " + document.getElementById("idUseMining").checked);
}
});
};
function SetPercentMining()
{
var Data = {POW_MAX_PERCENT:document.getElementById("idPercentMining").value};
GetData("SaveConstant", Data, function (Data)
{
if(Data && Data.result)
{
SetStatus("Save Mining percent: " + document.getElementById("idPercentMining").value + " %");
}
});
};
function MiningSets()
{
var name = "edit_mining_set";
if(IsVisibleBlock(name))
{
SetVisibleBlock(name, false);
}
else
{
SetVisibleBlock(name, true);
document.getElementById("idMiningAccount").value = MiningAccount;
document.getElementById("idMiningAccount").focus();
}
};
function SaveMiningSet(Value)
{
SetVisibleBlock("edit_mining_set", false);
if(Value)
{
MiningAccount = Value;
}
else
{
MiningAccount = ParseNum(document.getElementById("idMiningAccount").value);
}
GetData("SetMining", MiningAccount, function (Data)
{
});
};
function CancalMiningSet()
{
var name = "edit_mining_set";
SetVisibleBlock(name, false);
};
var WasHistoryMaxNum;
var WasLastNumSound = 0;
function CheckNewMoney()
{
return ;
if(!$("idUseSoundHistory").checked)
return ;
if(WasHistoryMaxNum === HistoryMaxNum || !ServerBlockNumDB)
return ;
WasHistoryMaxNum = HistoryMaxNum;
GetData("GetHistoryAct", {StartNum:HistoryMaxNum - 40, CountNum:40}, function (Data)
{
if(Data && Data.result)
{
var arr = Data.arr;
for(var i = 0; i < arr.length; i++)
{
var Item = arr[i];
if(Item.Direct === "+" && Item.BlockNum > ServerBlockNumDB - 60 && Item.BlockNum < ServerBlockNumDB - 20 && Item.BlockNum > WasLastNumSound)
{
WasLastNumSound = Item.BlockNum;
$("sound_coin").play();
}
}
}
});
};
function DoRestartWallet()
{
SetStatus("<H1 align='center' style='color:blue'>Restarting program...</H1>");
if(!WasSetRestart)
{
WasSetRestart = 1;
setTimeout(function ()
{
window.location.reload();
}, 10 * 1000);
}
};
function SetArrLog(arr)
{
var Str = "";
var bFindAccount = 0;
for(var i = 0; i < arr.length; i++)
{
var Item = arr[i];
var tr_text = GetTransactionText(MapSendTransaction[Item.key], Item.key.substr(0, 16));
var info = Item.text;
if(tr_text)
info += " (" + tr_text + ")";
if(Item.final)
{
var TR = MapSendTransaction[Item.key];
if(TR)
{
if(Item.text.indexOf("Add to blockchain") >= 0)
{
if(TR.bFindAcc)
{
bFindAccount = 1;
TR.bFindAcc = 0;
}
if(TR.Run)
{
TR.Run(TR);
TR.Run = undefined;
}
}
}
var Account = MapCheckTransaction[Item.key];
if(Account)
{
delete MapCheckTransaction[Item.key];
Account.NextSendTime = 0;
}
}
Str = Str + info + "\n";
}
SetStatusFromServer(Str);
CheckSending();
if(bFindAccount)
{
FindMyAccounts();
}
};
function SetAutoMining()
{
setTimeout(function ()
{
var Select = $("idAccount");
if(Select.options.length)
{
SaveMiningSet(Select.options[Select.options.length - 1].value);
}
}, 100);
};
function ViewNetworkMode()
{
if(IsVisibleBlock('idNetworkView'))
{
SetVisibleBlock('idNetworkView', false);
}
else
{
SetVisibleBlock('idNetworkView', true);
var Mode = CONFIG_DATA.CONSTANTS.NET_WORK_MODE;
if(!Mode)
{
Mode = {};
Mode.UseDirectIP = true;
if(INTERNET_IP_FROM_STUN)
Mode.ip = INTERNET_IP_FROM_STUN;
else
Mode.ip = SERVER_IP;
Mode.port = SERVER_PORT;
}
document.getElementById("idUseDirectIP").checked = Mode.UseDirectIP;
document.getElementById("idIP").value = Mode.ip;
document.getElementById("idPort").value = Mode.port;
if(!Mode.NodeWhiteList)
Mode.NodeWhiteList = "";
document.getElementById("idNodeWhiteList").value = Mode.NodeWhiteList;
}
};
function SetNetworkParams(bRestart)
{
var Mode = {};
Mode.UseDirectIP = document.getElementById("idUseDirectIP").checked;
Mode.ip = document.getElementById("idIP").value;
Mode.port = ParseNum(document.getElementById("idPort").value);
Mode.NodeWhiteList = document.getElementById("idNodeWhiteList").value;
Mode.DoRestartNode = bRestart;
GetData("SetNetMode", Mode, function (Data)
{
if(Data && Data.result)
{
SetStatus("Set net work params OK");
SetVisibleBlock('idNetworkView', false);
}
});
if(bRestart)
DoRestartWallet();
};
function ViewConstant()
{
if(IsVisibleBlock('idConstantView'))
{
SetVisibleBlock('idConstantView', false);
}
else
{
SetVisibleBlock('idConstantView', true);
document.getElementById("idConstant").value = JSON.stringify(CONFIG_DATA.CONSTANTS, "", 2);
}
};
function SaveConstant(bRestart)
{
try
{
var Data = JSON.parse(document.getElementById("idConstant").value);
}
catch(e)
{
SetError("Error JSON format setting constant");
return ;
}
Data.DoRestartNode = bRestart;
GetData("SaveConstant", Data, function (Data)
{
if(Data && Data.result)
{
SetStatus("Save Constant OK");
SetVisibleBlock('idConstantView', false);
}
});
if(bRestart)
DoRestartWallet();
};
function ViewRemoteParams()
{
if(IsVisibleBlock('idRemoteView'))
{
SetVisibleBlock('idRemoteView', false);
}
else
{
SetVisibleBlock('idRemoteView', true);
if(CONFIG_DATA.HTTPPort)
document.getElementById("idHTTPPort").value = CONFIG_DATA.HTTPPort;
document.getElementById("idHTTPPassword").value = CONFIG_DATA.HTTPPassword;
}
};
function SetRemoteParams(bRestart)
{
var PrevHTTPPassword = HTTPPassword;
var HTTPPort = ParseNum(document.getElementById("idHTTPPort").value);
var HTTPPassword = document.getElementById("idHTTPPassword").value;
GetData("SetHTTPParams", {HTTPPort:HTTPPort, HTTPPassword:HTTPPassword, DoRestartNode:bRestart}, function (Data)
{
if(!PrevHTTPPassword && HTTPPassword)
window.location.reload();
else
{
SetVisibleBlock('idRemoteView', false);
SetStatus("Set HTTP params OK");
}
});
if(bRestart)
DoRestartWallet();
};
function RewriteAllTransactions()
{
DoBlockChainProcess("RewriteAllTransactions", "Rewrite all transactions", 0);
};
function RewriteTransactions()
{
DoBlockChainProcess("RewriteTransactions", "Rewrite transactions on last %1 blocks", 1);
};
function TruncateBlockChain()
{
DoBlockChainProcess("TruncateBlockChain", "Truncate last %1 blocks", 1);
};
function ClearDataBase()
{
DoBlockChainProcess("ClearDataBase", "Clear DataBase", 0);
};
function CleanChain()
{
DoBlockChainProcess("CleanChain", "Clean chain on last %1 blocks", 1);
};
function DoBlockChainProcess(FuncName,Text,LastBlock)
{
SaveValues();
var Params = {};
if(LastBlock)
{
Params.BlockCount = ParseNum(document.getElementById("idBlockCount").value);
Text = Text.replace("%1", Params.BlockCount);
}
var result = confirm(Text + "?");
if(!result)
return ;
SetVisibleBlock("idServerBlock", 1);
SetStatus("START: " + Text);
GetData(FuncName, Params, function (Data)
{
if(Data)
{
SetStatus("FINISH: " + Text, !Data.result);
}
});
};

276
src/HTML/JS/wallet-web.js Normal file
View File

@ -0,0 +1,276 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
var MIN_VERSION = 1020;
var COUNT_BLOCK_PROOF = 300;
var MIN_SUM_POWER = COUNT_BLOCK_PROOF * 35;
var MainServer = undefined;
var MaxConnectedCount = 10;
var MaxTimeConnecting = 3 * 1000;
var StartTimeConnecting = 0;
var ConnectedCount = 0;
var NETWORK = "TERA-MAIN";
var ServerMap = {};
var ServerMainMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "terafoundation.org":{"ip":"terafoundation.org",
"port":443, "Name":"TERA", "System":1}, "dappsgate.com":{"ip":"dappsgate.com", "port":80, "Name":"SUPPORT2", "System":1}, "t1.teraexplorer.com":{"ip":"t1.teraexplorer.com",
"port":80, "Name":"t1.teraexplorer.com", "System":1}, "t2.teraexplorer.com":{"ip":"t2.teraexplorer.com", "port":80, "Name":"t2.teraexplorer.com",
"System":1}, "t3.teraexplorer.com":{"ip":"t3.teraexplorer.com", "port":80, "Name":"t3.teraexplorer.com", "System":1}, "t4.teraexplorer.com":{"ip":"t4.teraexplorer.com",
"port":80, "Name":"t4.teraexplorer.com", "System":1}, "t5.teraexplorer.com":{"ip":"t5.teraexplorer.com", "port":80, "Name":"t5.teraexplorer.com",
"System":1}, };
var ServerTestMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "dappsgate.com":{"ip":"dappsgate.com", "port":88,
"Name":"SUPPORT2", "System":1}, };
function StartWebWallet()
{
if(NETWORK === "TERA-TEST2")
{
MIN_SUM_POWER = 0;
ServerMap = ServerTestMap;
}
else
{
MIN_SUM_POWER = COUNT_BLOCK_PROOF * 35;
ServerMap = ServerMainMap;
}
$("idNetwork").innerText = NETWORK;
OnInitWebWallet();
ConnectWebWallet();
};
function OnInitWebWallet()
{
var str = Storage.getItem(NETWORK + "NodesArrayList");
if(str)
{
var arr = JSON.parse(str);
for(var i = 0; i < arr.length; i++)
{
var Item = ServerMap[arr[i].ip];
if(Item && Item.System)
continue;
ServerMap[arr[i].ip] = arr[i];
}
}
};
function SaveServerMap()
{
var arr = [];
for(var key in ServerMap)
{
var Item = ServerMap[key];
if(Item.SumPower >= MIN_SUM_POWER)
{
arr.push({ip:Item.ip, port:Item.port});
}
}
Storage.setItem(NETWORK + "NodesArrayList", JSON.stringify(arr));
};
function SetStatus(Str)
{
var id = $("idStatus");
id.innerHTML = Str;
if(Str)
console.log(id.innerText);
};
function SetError(Str,bNoSound)
{
SetStatus("<DIV align='left' style='color:red'><B>" + Str + "</B></DIV>");
};
var CountConnect = 0;
var CountWallet = 0;
function ConnectWebWallet()
{
StartTimeConnecting = Date.now();
ConnectedCount = 0;
for(var key in ServerMap)
{
var Item = ServerMap[key];
Item.SendHandShake = 0;
}
if(window.BrowserIE && !IsLocalClient())
{
MainServer = undefined;
return ;
}
CountConnect = 0;
CountWallet = 0;
SetStatus("Connecting...");
LoopHandShake();
setTimeout(LoopWalletInfo, 1500);
};
var Stage = 0;
function LoopHandShake()
{
Stage++;
SetStatus("Connecting: " + Stage + "...");
for(var key in ServerMap)
{
var Item = ServerMap[key];
if(Item.SendHandShake || !Item.port)
continue;
CountConnect++;
if(window.BrowserIE && CountConnect > 4)
break;
DoNodeList(Item);
}
};
function DoNodeList(Item)
{
console.log(GetProtocolServerPath(Item) + "/GetNodeList");
if(window.location.protocol === "https:" && Item.port !== 443)
return ;
if(Item.port === 443 && IsIPAddres(Item.ip))
return ;
SetStatus("Try: " + Item.ip + ":" + Item.port);
Item.SendHandShake = 1;
GetData(GetProtocolServerPath(Item) + "/GetNodeList", {}, function (Data)
{
if(Data && Data.result && Data.NETWORK === NETWORK && Data.VersionNum >= MIN_VERSION)
{
ConnectedCount++;
Item.GetHandShake = 1;
Item.BlockChain = Data.BlockChain;
SetStatus("Get: " + Item.ip + ":" + Item.port);
var bWas = 0;
for(var i = 0; i < Data.arr.length; i++)
{
var Node = Data.arr[i];
if(!ServerMap[Node.ip] && Node.port)
{
ServerMap[Node.ip] = Node;
console.log("New: " + Node.ip + ":" + Node.port);
bWas = 1;
}
}
if(bWas && ConnectedCount < MaxConnectedCount && new Date() - StartTimeConnecting < MaxTimeConnecting)
{
setTimeout(LoopHandShake, 100);
}
}
});
};
function LoopWalletInfo()
{
SetStatus("Get wallets info...");
for(var key in ServerMap)
{
var Item = ServerMap[key];
if(Item.port)
{
CountWallet++;
if(window.BrowserIE && CountWallet > 4)
break;
DoWalletInfo(Item);
}
}
setTimeout(FindLider, 500);
};
function DoWalletInfo(Item)
{
if(window.location.protocol === "https:" && Item.port !== 443)
return ;
if(Item.port === 443 && IsIPAddres(Item.ip))
return ;
Item.StartTime = Date.now();
Item.SendWalletInfo = 1;
GetData(GetProtocolServerPath(Item) + "/GetCurrentInfo", {BlockChain:1}, function (Data)
{
if(Data && Data.result && Data.BlockChain && Data.NETWORK === NETWORK)
{
Item.Name = Data.NODES_NAME;
Item.GetWalletInfo = 1;
Item.DeltaTime = new Date() - Item.StartTime;
Item.BlockChain = Data.BlockChain;
Item.MaxNumBlockDB = Data.MaxNumBlockDB;
console.log("Get: " + Item.ip + ":" + Item.port + " delta=" + Item.DeltaTime);
}
});
};
function FindLider()
{
MainServer = undefined;
var Arr = [];
var MapSumPower = {};
for(var key in ServerMap)
{
var Item = ServerMap[key];
if(Item.GetWalletInfo && Item.BlockChain)
{
var arr = Item.BlockChain;
if(arr.data)
arr = arr.data;
Item.SumPower = CalcPowFromBlockChain(arr);
if(Item.SumPower < MIN_SUM_POWER)
{
console.log("Skip: " + Item.ip + ":" + Item.port + " SumPower(" + Item.SumPower + ") < MIN_SUM_POWER(" + MIN_SUM_POWER + ")");
continue;
}
if(!MapSumPower[Item.SumPower])
MapSumPower[Item.SumPower] = 0;
MapSumPower[Item.SumPower]++;
Arr.push(Item);
}
}
var Max = 0, MaxKey;
for(var key in MapSumPower)
{
if(MapSumPower[key] >= Max)
{
Max = MapSumPower[key];
MaxKey = parseInt(key);
}
}
Arr.sort(function (a,b)
{
return a.DeltaTime - b.DeltaTime;
});
for(var i = 0; i < Arr.length; i++)
{
var Item = Arr[i];
if(Item.SumPower === MaxKey)
{
SetStatus("Find " + Item.ip + ":" + Item.port + " with pow=" + Item.SumPower + "/" + MaxKey + " ping=" + Item.DeltaTime);
MainServer = Item;
SaveServerMap();
break;
}
}
OnFindServer();
};
function CalcPowFromBlockChain(BufRead)
{
var Sum = 0;
var Arr = GetBlockArrFromBuffer(BufRead);
if(Arr.length === COUNT_BLOCK_PROOF)
{
for(var i = 0; i < Arr.length; i++)
{
Sum += Arr[i].Power;
}
}
return Sum;
};
function SetAllSum()
{
var Item = MapAccounts[$("idAccount").value];
if(Item)
$("idSumSend").value = FLOAT_FROM_COIN(Item.Value).toStringF();
};

4
src/HTML/PIC/B.svg Normal file
View File

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="12" r="12" fill="none"/>
<path d="M16.37 11.6869C16.7553 11.143 16.9852 10.4622 16.9852 9.72248C16.9852 7.94269 15.6576 6.4998 14.0206 6.4998C13.8896 6.4998 13.7302 6.4998 13.548 6.4998V4.00765C13.548 3.86574 13.4319 3.75 13.2904 3.75H12.4304C12.2885 3.75 12.1727 3.86616 12.1727 4.00765V6.4998H10.7978V4.00765C10.7978 3.86574 10.6816 3.75 10.5402 3.75H9.68095C9.53904 3.75 9.4233 3.86616 9.4233 4.00765V6.4998H6.58724C6.4449 6.4998 6.32959 6.61511 6.32959 6.75744V7.62538C6.32959 7.75813 6.42873 7.87308 6.56106 7.8851C7.52942 7.97387 8.04837 8.62357 8.04837 9.42176V14.75C8.04837 15.4681 7.67786 16.0381 6.86807 16.1161C6.75312 16.1273 6.6577 16.209 6.63617 16.3228L6.47187 17.1989C6.4424 17.3553 6.56271 17.5002 6.72207 17.5002H9.42245V19.9924C9.42245 20.1342 9.53861 20.25 9.68009 20.25H10.5393C10.6812 20.25 10.7969 20.1338 10.7969 19.9924V17.5002H12.1719V19.9924C12.1719 20.1342 12.288 20.25 12.4295 20.25H13.2887C13.4306 20.25 13.5463 20.1338 13.5463 19.9924V17.5002C14.0334 17.5002 14.4379 17.5002 14.7064 17.5002C16.3439 17.5002 17.671 16.0768 17.671 14.3207C17.6726 13.2244 17.1562 12.2586 16.37 11.6869ZM10.7974 8.56207C10.7974 8.56207 12.1196 8.56207 12.9028 8.56207C13.6862 8.56207 14.3208 9.19682 14.3208 9.98013C14.3208 10.7634 13.6862 11.3981 12.9028 11.3981C12.1196 11.3981 10.7974 11.3981 10.7974 11.3981V8.56207ZM13.5903 15.5232C12.8071 15.5232 10.7974 15.5232 10.7974 15.5232V12.6872C10.7974 12.6872 12.8071 12.6872 13.5903 12.6872C14.3737 12.6872 15.0083 13.3219 15.0083 14.1052C15.0083 14.8884 14.3737 15.5232 13.5903 15.5232Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 1.7 KiB

3
src/HTML/PIC/T.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="11" height="14" viewBox="0 0 11 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M10.0017 5.14505H6.37967V14H3.978V5.14505H0.365723V3.12413H10.0017V5.14505ZM0.365723 1.65969V0H10.0017V1.65969H0.365723Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 251 B

13
src/HTML/PIC/TeraLogo.svg Normal file
View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<svg width="104" height="25" viewBox="0 0 105 25" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M29.9728 24.4597C29.9728 24.4587 29.9723 24.4577 29.9718 24.4566C29.9707 24.4535 29.9697 24.4504 29.9681 24.4479C29.9661 24.4427 29.9635 24.4375 29.9604 24.4323C29.9594 24.4292 29.9579 24.4261 29.9563 24.423C29.9522 24.4153 29.9481 24.408 29.9435 24.4008L15.3327 0.205778C15.3317 0.204227 15.3306 0.202158 15.3296 0.200607L15.3137 0.173722C15.2453 0.0687645 15.1275 0 14.9944 0C14.8622 0 14.746 0.0672141 14.6776 0.169586C14.6704 0.179927 14.6637 0.190783 14.6576 0.202158C13.6755 1.83184 12.6878 3.45843 11.6939 5.08191C11.5946 5.22357 11.5417 5.39264 11.5417 5.56533C11.5417 5.73854 11.5946 5.90709 11.6939 6.04875C13.0045 8.20012 14.3079 10.3567 15.6186 12.508C15.7255 12.6616 15.7826 12.8441 15.7826 13.0318C15.7826 13.219 15.7255 13.4015 15.6186 13.555C13.4652 17.1107 11.1807 20.8545 9.01708 24.4303C8.98777 24.4846 8.97131 24.5471 8.97131 24.6133C8.97131 24.8258 9.14202 24.9975 9.35334 24.9975H15.3846L15.3841 24.998H15.6746C15.7476 24.998 15.8155 24.9773 15.8736 24.9416C15.9317 24.9059 15.979 24.8553 16.0114 24.7953L16.0124 24.7948L16.2299 24.4298L19.1437 19.594C19.1443 19.5934 19.1437 19.5934 19.1437 19.5934C19.209 19.4735 19.335 19.3928 19.48 19.3928C19.6116 19.3928 19.7279 19.46 19.7968 19.5619C19.7993 19.566 19.8019 19.5702 19.8045 19.5743L19.807 19.5784L22.708 24.3424L22.9738 24.7844C23.0386 24.9039 23.1646 24.985 23.3101 24.985H23.487C23.5163 24.9866 23.5456 24.9871 23.5749 24.9856H29.618C29.8288 24.9856 30 24.8139 30 24.6014C30 24.5513 29.9908 24.5032 29.9728 24.4597Z" fill="white" />
<path d="M13.1433 13.7884C13.2133 13.6721 13.2832 13.5563 13.3536 13.4394C13.4405 13.3133 13.4873 13.1639 13.4873 13.0108C13.4873 12.8578 13.4405 12.7073 13.3536 12.5822L12.0553 10.467L10.5704 8.0468C10.503 7.93719 10.3822 7.86377 10.2449 7.86377C10.0994 7.86377 9.97242 7.94443 9.90763 8.06438L0.0457623 24.4321C0.0164543 24.4863 0 24.5489 0 24.6151C0 24.8276 0.170703 24.9992 0.382028 24.9992H3.19971V24.9987H5.77983L5.77778 24.9998H5.93872L6.17318 24.9992H6.17421C6.31869 24.9992 6.44467 24.9181 6.50894 24.7986C6.50894 24.7986 6.50945 24.7986 6.50945 24.7981L6.73106 24.429C6.74134 24.415 6.7506 24.4005 6.75883 24.3855C6.75883 24.3855 6.75934 24.3855 6.75934 24.3845L6.99998 23.9848C9.07005 20.5466 11.0429 17.2644 13.1104 13.8422C13.1223 13.8246 13.1331 13.8065 13.1433 13.7884Z" fill="white" />
<path d="M84.9771 18.1896L84.7356 17.7922L84.7372 17.7906L82.9705 14.8915C82.705 14.4544 82.7506 13.7969 83.1545 13.4891C84.4869 12.4746 85.3338 10.7451 85.3338 9.1756C85.3338 6.7668 83.1385 4.17139 80.4577 4.17139H80.0162H73.738C73.7332 4.17139 73.7292 4.1722 73.7244 4.1722H72.8967C72.5624 4.1722 72.2897 4.44845 72.2897 4.7853V6.5075C72.2897 6.84515 72.5624 7.1206 72.8967 7.1206H75.344H80.0162C80.0226 7.1206 80.029 7.1206 80.0354 7.12141C80.3049 7.12302 80.5632 7.17149 80.8032 7.25712C81.6013 7.56085 82.1692 8.33954 82.1692 9.25234C82.1692 10.2144 81.5373 11.0278 80.6688 11.292C80.4617 11.3469 80.2425 11.376 80.0162 11.376H79.901H73.7412H73.7085C73.6589 11.3768 73.6093 11.38 73.5613 11.3857H72.8967C72.8831 11.3857 72.8703 11.3865 72.8567 11.3881C72.54 11.4083 72.2897 11.6733 72.2897 11.998C72.2897 11.9988 72.2897 11.9988 72.2897 11.9996V13.6709C72.2897 13.6911 72.2905 13.7105 72.2929 13.7291V16.8544C72.2905 16.8729 72.2897 16.8923 72.2897 16.9125V19.3843C72.2897 19.7212 72.5624 19.9975 72.8967 19.9975H73.6685C73.6877 19.9983 73.7069 19.9999 73.7268 19.9999C73.746 19.9999 73.7652 19.9983 73.7844 19.9975H74.5514C74.8849 19.9975 75.1584 19.7212 75.1584 19.3843V18.6113C75.1592 18.5919 75.1616 18.5717 75.1616 18.5515C75.1616 18.537 75.16 18.5241 75.1592 18.5103L75.1608 16.6613C75.1552 16.629 75.152 16.5959 75.152 16.562V14.8907C75.152 14.553 75.4247 14.2775 75.759 14.2775H78.2063C78.2279 14.2775 78.2495 14.2792 78.2711 14.2808H78.615V14.2816C79.0181 14.2816 79.3684 14.5005 79.5611 14.826H79.5627L81.2454 17.5911C81.2478 17.5951 81.2494 17.5991 81.2518 17.6024L82.2811 19.2939L82.5147 19.6768C82.5195 19.6857 82.525 19.6945 82.5298 19.7026C82.637 19.8811 82.8306 19.9999 83.0529 19.9999H83.508C83.5104 19.9999 83.512 19.9999 83.5144 19.9999C83.5152 19.9999 83.5167 19.9999 83.5175 19.9999H84.9851C85.3226 19.9999 85.5961 19.7236 85.5961 19.3827C85.5961 19.2551 85.5578 19.1364 85.4922 19.0378L84.9771 18.1896Z" fill="white" />
<path d="M67.2056 17.1015H66.4338C66.4154 17.1007 66.397 17.0991 66.3786 17.0991H57.2429C57.2238 17.0991 57.2062 17.1007 57.1878 17.1015H56.4152C56.0817 17.1015 55.8082 17.3778 55.8082 17.7147V19.3859C55.8082 19.7236 56.0817 19.9991 56.4152 19.9991H58.8625C58.8809 19.9991 58.8993 19.9983 58.9176 19.9966H64.7031C64.7215 19.9983 64.7399 19.9991 64.7583 19.9991H67.2056C67.5399 19.9991 67.8126 19.7236 67.8126 19.3859V18.5475V17.7147C67.8126 17.3778 67.5399 17.1015 67.2056 17.1015Z" fill="white" />
<path d="M67.2056 10.6369H66.4058C66.3962 10.6369 66.3874 10.6353 66.3786 10.6353H57.2429C57.2334 10.6353 57.2246 10.6369 57.2158 10.6369H56.4152C56.0817 10.6369 55.8082 10.9123 55.8082 11.25V12.0844V12.9213C55.8082 13.2581 56.0817 13.5344 56.4152 13.5344H58.8625C58.8721 13.5344 58.8809 13.5336 58.8897 13.5328H64.7311C64.7399 13.5336 64.7495 13.5344 64.7583 13.5344H67.2056C67.5399 13.5344 67.8126 13.2581 67.8126 12.9213V12.0844V11.25C67.8126 10.9123 67.5399 10.6369 67.2056 10.6369Z" fill="white" />
<path d="M67.2056 4.17188H66.3882C66.385 4.17188 66.3818 4.17188 66.3786 4.17188H57.2429C57.2389 4.17188 57.2357 4.17188 57.2326 4.17188H56.4152C56.0817 4.17188 55.8082 4.44813 55.8082 4.78498V6.45628C55.8082 6.79394 56.0817 7.06939 56.4152 7.06939H58.8625C58.8665 7.06939 58.8697 7.06939 58.8729 7.06939H64.7479C64.7519 7.06939 64.7551 7.06939 64.7583 7.06939H67.2056C67.5399 7.06939 67.8126 6.79394 67.8126 6.45628V5.62023V4.78498C67.8126 4.44813 67.5399 4.17188 67.2056 4.17188Z" fill="white" />
<path d="M50.7665 4.17215H49.9515C49.9467 4.17215 49.9427 4.17135 49.9387 4.17135H44.9514C44.9186 4.16892 44.8866 4.1665 44.853 4.1665C44.8162 4.1665 44.7811 4.16973 44.7451 4.17215H44.0261C43.6918 4.17215 43.4191 4.44841 43.4191 4.78526V6.45656V9.32257V14.8421V16.9141V19.3867C43.4191 19.7236 43.6918 19.999 44.0261 19.999H44.8522H44.853H45.6808C46.0143 19.999 46.2878 19.7236 46.2878 19.3867V18.5515C46.2878 18.5515 46.2878 18.5515 46.2878 18.5507V14.8421V9.32338V8.51802V8.1836C46.2878 8.17795 46.2886 8.17229 46.2886 8.16663V7.68277C46.2886 7.34593 46.5613 7.06967 46.8956 7.06967H47.3915V7.06886H47.7218H48.3064C48.3104 7.06967 48.3144 7.06967 48.3192 7.06967H50.7665C51.1 7.06967 51.3735 6.79422 51.3735 6.45656V5.62132C51.3735 5.62132 51.3735 5.62132 51.3735 5.62051V4.78526C51.3735 4.44841 51.1 4.17215 50.7665 4.17215Z" fill="white" />
<path d="M41.3876 4.17188H40.5599H40.164H39.7673H38.9403C38.606 4.17188 38.3333 4.44813 38.3333 4.78498V6.45628C38.3333 6.79394 38.606 7.06939 38.9403 7.06939H39.7673H40.164H40.5599H41.3876C41.7211 7.06939 41.9946 6.79394 41.9946 6.45628V4.78498C41.9946 4.44813 41.7211 4.17188 41.3876 4.17188Z" fill="white" />
<path d="M104.124 19.1776C104.124 19.1759 104.123 19.1743 104.123 19.1727L104.105 19.1347C104.103 19.1299 104.101 19.1251 104.099 19.1202L97.9053 5.06883L97.6854 4.54539C97.6838 4.54054 97.6822 4.53569 97.6798 4.53165C97.5878 4.31921 97.3783 4.17139 97.1351 4.17139H96.0363C95.7955 4.17139 95.5876 4.31679 95.4948 4.5252C95.4916 4.53166 95.4884 4.53812 95.486 4.54458L95.2525 5.06883L91.8727 12.7387L91.1097 14.4504L90.957 14.7929C90.9546 14.7978 90.9522 14.8034 90.9498 14.8091C90.9194 14.8818 90.9034 14.9609 90.9034 15.0449C90.9034 15.3858 91.1769 15.6629 91.5152 15.6629H93.3203C93.5738 15.6629 93.7905 15.507 93.8833 15.2857L93.9233 15.1968L94.0609 14.8882C94.0696 14.8721 94.0785 14.8559 94.0865 14.839L94.108 14.7913L94.116 14.7719L94.4159 14.0918L94.7303 13.3866C94.7391 13.3672 94.747 13.347 94.7534 13.326L95.5612 11.4939L96.2658 9.89533C96.317 9.77174 96.4385 9.68531 96.5793 9.68531C96.7113 9.68531 96.8264 9.76123 96.8824 9.87271C96.8864 9.87998 96.8896 9.88725 96.8928 9.89533L97.5974 11.4939L99.3873 15.5538L99.8591 16.6242H99.8583C99.8759 16.6645 99.8855 16.7098 99.8855 16.7574C99.8855 16.9481 99.7328 17.1016 99.5448 17.1016H98.3964C98.394 17.1016 98.3916 17.1016 98.3892 17.1016H98.3468C98.3444 17.1016 98.342 17.1016 98.3396 17.1016H90.8794C90.8786 17.1016 90.8778 17.1016 90.8778 17.1016H90.7442C90.7402 17.1016 90.7354 17.1024 90.7314 17.1024H90.3244C90.0892 17.1024 89.8869 17.2397 89.7909 17.4384L89.7733 17.478L89.1895 18.7866L89.0367 19.1291C89.0343 19.1339 89.0319 19.1396 89.0295 19.1452C88.9992 19.2179 88.9832 19.2971 88.9832 19.3811C88.9832 19.722 89.2567 19.9991 89.595 19.9991H90.7434H90.7442H93.1915C93.1923 19.9991 93.1931 19.9991 93.1931 19.9991H103.572C103.9 19.9991 104.167 19.7309 104.167 19.3989C104.167 19.3205 104.152 19.2454 104.124 19.1776Z" fill="white" />
</svg>

After

Width:  |  Height:  |  Size: 8.7 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 992.13 992.13" width="150" height="150">
<title>Logo2</title>
<path d="M894.31,812.41a0.18,0.18,0,0,0,0-.08,1.11,1.11,0,0,0-.09-0.23,2.58,2.58,0,0,0-.21-0.41,1.51,1.51,0,0,0-.11-0.25c-0.11-.21-0.22-0.4-0.34-0.59l-388.62-640-0.08-.14L504.4,170a10.15,10.15,0,0,0-16.92-.11,9.33,9.33,0,0,0-.54.86q-39.18,64.66-78.83,129.08a22.21,22.21,0,0,0,0,25.57q52.29,85.36,104.39,170.85a24.15,24.15,0,0,1,0,27.69C455.24,618,394.48,717,336.93,811.63a10.18,10.18,0,0,0,8.94,15H514a10.12,10.12,0,0,0,5.29-1.49,10.25,10.25,0,0,0,3.66-3.87h0l5.79-9.66,77.5-127.91s0,0,0,0a10.18,10.18,0,0,1,17.37-.84l0.21,0.33,0.07,0.11,77.16,126L708.15,821a10.17,10.17,0,0,0,8.95,5.3h4.71a21.71,21.71,0,0,0,2.34,0H884.87A10.16,10.16,0,0,0,895,816.15,9.73,9.73,0,0,0,894.31,812.41Z" />
<path d="M446.68,530.15l5.59-9.23a19.86,19.86,0,0,0,0-22.68L417.74,442.3l-39.5-64a10.2,10.2,0,0,0-17.63.46L98.31,811.68a10.17,10.17,0,0,0,8.95,15H250.82l-0.05,0h4.28l6.23,0h0a10.12,10.12,0,0,0,8.9-5.3,0,0,0,0,0,0,0l5.89-9.77a9.82,9.82,0,0,0,.74-1.15s0,0,0,0l6.4-10.57c55.06-90.94,107.53-177.76,162.52-268.28C446.12,531.11,446.41,530.63,446.68,530.15Z" />
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 992.13 992.13" width="150" height="150">
<title>Logo2</title>
<path d="M894.31,812.41a0.18,0.18,0,0,0,0-.08,1.11,1.11,0,0,0-.09-0.23,2.58,2.58,0,0,0-.21-0.41,1.51,1.51,0,0,0-.11-0.25c-0.11-.21-0.22-0.4-0.34-0.59l-388.62-640-0.08-.14L504.4,170a10.15,10.15,0,0,0-16.92-.11,9.33,9.33,0,0,0-.54.86q-39.18,64.66-78.83,129.08a22.21,22.21,0,0,0,0,25.57q52.29,85.36,104.39,170.85a24.15,24.15,0,0,1,0,27.69C455.24,618,394.48,717,336.93,811.63a10.18,10.18,0,0,0,8.94,15H514a10.12,10.12,0,0,0,5.29-1.49,10.25,10.25,0,0,0,3.66-3.87h0l5.79-9.66,77.5-127.91s0,0,0,0a10.18,10.18,0,0,1,17.37-.84l0.21,0.33,0.07,0.11,77.16,126L708.15,821a10.17,10.17,0,0,0,8.95,5.3h4.71a21.71,21.71,0,0,0,2.34,0H884.87A10.16,10.16,0,0,0,895,816.15,9.73,9.73,0,0,0,894.31,812.41Z" fill="rgb(250,250,250)"/>
<path d="M446.68,530.15l5.59-9.23a19.86,19.86,0,0,0,0-22.68L417.74,442.3l-39.5-64a10.2,10.2,0,0,0-17.63.46L98.31,811.68a10.17,10.17,0,0,0,8.95,15H250.82l-0.05,0h4.28l6.23,0h0a10.12,10.12,0,0,0,8.9-5.3,0,0,0,0,0,0,0l5.89-9.77a9.82,9.82,0,0,0,.74-1.15s0,0,0,0l6.4-10.57c55.06-90.94,107.53-177.76,162.52-268.28C446.12,531.11,446.41,530.63,446.68,530.15Z" fill="rgb(250,250,250)"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,4 @@
<svg width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="15" cy="15" r="14.5" fill="white" fill-opacity="0.01" stroke="#F2F2F2"/>
<path d="M15.5 10H14.5V14.5H10V15.5H14.5V20H15.5V15.5H20V14.5H15.5V10Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

4
src/HTML/PIC/blank.svg Normal file
View File

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="12" cy="12" r="12" fill="none"/>
</svg>

After

Width:  |  Height:  |  Size: 149 B

BIN
src/HTML/PIC/chains.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

3
src/HTML/PIC/check.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M7.78543 13.9676L6.72477 15.0282L7.78543 16.0889L8.84609 15.0282L7.78543 13.9676ZM15.6923 3.93939L6.72477 12.9069L8.84609 15.0282L17.8136 6.06071L15.6923 3.93939ZM8.8461 12.9069L3.06067 7.12144L0.939334 9.24275L6.72477 15.0282L8.8461 12.9069Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 373 B

BIN
src/HTML/PIC/console.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 821 B

BIN
src/HTML/PIC/console0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
src/HTML/PIC/counters.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
src/HTML/PIC/dapp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -0,0 +1,3 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9 13L8.29289 13.7071L9 14.4142L9.70711 13.7071L9 13ZM16.2929 4.29289L8.29289 12.2929L9.70711 13.7071L17.7071 5.70711L16.2929 4.29289ZM9.70711 12.2929L1.70711 4.29289L0.292893 5.70711L8.29289 13.7071L9.70711 12.2929Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 347 B

BIN
src/HTML/PIC/down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

3
src/HTML/PIC/glass.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M16 8.5C16 12.6421 12.6421 16 8.5 16C4.35786 16 1 12.6421 1 8.5C1 4.35786 4.35786 1 8.5 1C12.6421 1 16 4.35786 16 8.5ZM14.1464 14.8537C12.6451 16.1889 10.6673 17 8.5 17C3.80558 17 0 13.1944 0 8.5C0 3.80558 3.80558 0 8.5 0C13.1944 0 17 3.80558 17 8.5C17 10.6673 16.1888 12.6452 14.8536 14.1466L17.8535 17.1465C18.0487 17.3417 18.0487 17.6583 17.8535 17.8536C17.6582 18.0488 17.3416 18.0488 17.1464 17.8536L14.1464 14.8537Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 593 B

3
src/HTML/PIC/info.svg Normal file
View File

@ -0,0 +1,3 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 1H15C16.1046 1 17 1.89543 17 3V15C17 16.1046 16.1046 17 15 17H3C1.89543 17 1 16.1046 1 15V3C1 1.89543 1.89543 1 3 1ZM0 3C0 1.34315 1.34315 0 3 0H15C16.6569 0 18 1.34315 18 3V15C18 16.6569 16.6569 18 15 18H3C1.34315 18 0 16.6569 0 15V3ZM8.16602 14H9.82715V6.60352H8.16602V14ZM8.30273 4.04688C8.14323 4.21549 8.06348 4.42741 8.06348 4.68262C8.06348 4.93327 8.14323 5.1429 8.30273 5.31152C8.4668 5.47559 8.69922 5.55762 9 5.55762C9.30078 5.55762 9.5332 5.47559 9.69727 5.31152C9.86133 5.1429 9.94336 4.93327 9.94336 4.68262C9.94336 4.42741 9.86133 4.21549 9.69727 4.04688C9.5332 3.87826 9.30078 3.79395 9 3.79395C8.69922 3.79395 8.4668 3.87826 8.30273 4.04688Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 831 B

BIN
src/HTML/PIC/invoice.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/HTML/PIC/invoice2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

BIN
src/HTML/PIC/key.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
src/HTML/PIC/lock_open.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
src/HTML/PIC/monitor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

BIN
src/HTML/PIC/network.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

4
src/HTML/PIC/reload.svg Normal file
View File

@ -0,0 +1,4 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M2.27602 7.97696C2.35936 8.0103 2.45603 8.0103 2.53937 7.9703L5.14285 6.7869C5.30951 6.70689 5.37952 6.50688 5.29951 6.34022C5.22285 6.18021 5.03284 6.10686 4.86949 6.18021L3.04606 7.01025C3.9161 4.40678 6.33956 2.66669 9.1297 2.66669C12.0532 2.66669 14.61 4.62013 15.3467 7.41693C15.3933 7.59359 15.5767 7.70029 15.7533 7.6536C15.93 7.60694 16.0367 7.42358 15.99 7.24692C15.1766 4.16011 12.3565 2 9.12967 2C6.05286 2 3.37604 3.9201 2.40934 6.79358L1.64264 4.87683C1.58598 4.70348 1.39597 4.60682 1.22262 4.66348C1.04927 4.72014 0.952607 4.91015 1.00927 5.0835C1.01259 5.09678 1.0192 5.11003 1.02583 5.12331L2.08932 7.79029C2.12267 7.87364 2.18933 7.94364 2.27602 7.97696Z" fill="#445368"/>
<path d="M16.9868 12.8975C16.9834 12.8908 16.9801 12.8841 16.9801 12.8775L15.9167 10.2107C15.8834 10.1274 15.8167 10.0573 15.7301 10.024C15.6467 9.99069 15.55 9.99403 15.4667 10.0307L12.8632 11.2141C12.6932 11.2841 12.6132 11.4808 12.6832 11.6508C12.7532 11.8208 12.9499 11.9008 13.1199 11.8308L13.1399 11.8208L14.9633 10.9907C14.0866 13.5942 11.6598 15.3343 8.87301 15.3343C5.94951 15.3343 3.39272 13.3809 2.65603 10.5841C2.60937 10.4074 2.42602 10.3007 2.24935 10.3474C2.07269 10.3941 1.96599 10.5774 2.01268 10.7541C2.82272 13.8442 5.64622 16.001 8.87304 16.001C11.9499 16.001 14.6233 14.0809 15.5934 11.2074L16.3601 13.1242C16.4234 13.2975 16.6134 13.3875 16.7868 13.3242C16.9601 13.2609 17.0501 13.0708 16.9868 12.8975Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,3 @@
<svg width="18" height="18" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path d="M14 9L14.7071 9.70711L15.4142 9L14.7071 8.29289L14 9ZM5.29289 1.70711L13.2929 9.70711L14.7071 8.29289L6.70711 0.292894L5.29289 1.70711ZM13.2929 8.29289L5.29289 16.2929L6.70711 17.7071L14.7071 9.70711L13.2929 8.29289Z"/>
</svg>

After

Width:  |  Height:  |  Size: 340 B

BIN
src/HTML/PIC/smart.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

BIN
src/HTML/PIC/table.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 494 B

View File

@ -0,0 +1,3 @@
<svg width="13" height="16" viewBox="0 0 13 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M9.81811 5.14505H6.19608V14H3.7944V5.14505H0.182129V3.12413H9.81811V5.14505ZM0.182129 1.65969V0H9.81811V1.65969H0.182129Z" fill="#445368"/>
</svg>

After

Width:  |  Height:  |  Size: 252 B

BIN
src/HTML/PIC/tera.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

BIN
src/HTML/PIC/up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
src/HTML/PIC/viewer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
src/HTML/PIC/wallet.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
src/HTML/PIC/wallet16.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

BIN
src/HTML/SOUND/click.mp3 Normal file

Binary file not shown.

BIN
src/HTML/SOUND/coin.mp3 Normal file

Binary file not shown.

BIN
src/HTML/SOUND/soundbt.mp3 Normal file

Binary file not shown.

131
src/HTML/blockviewer.html Normal file
View File

@ -0,0 +1,131 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Block</title>
<link rel="shortcut icon" href="./PIC/viewer.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="stylesheet" href="./CSS/blockviewer.css">-->
<link rel="stylesheet" href="./CSS/mobile-wallet.css">
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="./JS/coinlib.js"></script>
<script type="text/javascript" src="./JS/client.js"></script>
<script>
var DefTr={NumName:"idViewTrNum", TabName:"grid_transaction_all",APIName:"GetTransactionAll",Param3:undefined};
var CountViewRows=10;//global
window.onload=function()
{
InitMainServer();
document.body.className="univers "+localStorage["idSelStyle"];
var i=document.URL.indexOf("#");
if(i>0)
{
var BlockNum=ParseNum(document.URL.substr(i+1));
ViewBlock(BlockNum);
}
window.onkeydown = function (e)
{
if(e.keyCode===27)
{
window.close();
}
};
window.addEventListener("popstate", function(event)
{
var BlockNum=ParseNum(window.location.hash.substr(1));
ViewBlock(BlockNum);
}, false);
}
function ViewBlock(BlockNum)
{
if(BlockNum!==undefined)
document.getElementById("idViewBlockNum").value=BlockNum;
else
{
BlockNum=ParseNum(document.getElementById("idViewBlockNum").value);
history.pushState(null,null,"#"+BlockNum);
}
document.title="Block: "+BlockNum;
DefTr.Param3=BlockNum;
ViewCurrent(DefTr);
}
function SaveValues()
{
}
</script>
</head>
<body>
<header class="header">
<div class="header__wrapper">
<div class="header__logo header__logo--history">
<a onclick="" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="/PIC/TeraLogo.svg" alt="TERA Foundation">
<p class="header__logo-name">Blockviewer</p>
</a>
</div>
<div class="header__right">
<select size="1" id="idLang" onchange="ChangeLang()" class="bigs" >
<option value="ENG">ENG</option>
</select>
</div>
</div>
</header>
<main>
<section class="history-page" id="idTransactionBlock" style="display: block">
<div class="history__text-block">
<div class="history-page__id" >
<!--<a class="back-link back-link&#45;&#45;history" onclick="SelectTab('TabKeySet')"><span>Accounts</span></a>-->
Transactions on block: <INPUT class="history-page__id-count" type="number" id="idViewBlockNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewBlock()">
</div>
<BR>
</div>
<div class="history-page__table">
<div class="page-pagination">
<button onclick="ViewPrev(DefTr)" class="btnav btn"><</button>
<INPUT type="number" class="page-pagination__num" id="idViewTrNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewCurrent(DefTr)">
<button onclick="ViewNext(DefTr,5000)" class="btnav btn">></button>
</div>
<div class="history-page__table-wrap">
<table id="grid_transaction_all" class="grid">
<tr>
<th id="Item.Num" class="num">TrNum</th>
<th id="Item.Type" class="num">Type</th>
<th id="GetHexFromArr(Item.Body)" class="code">Body</th>
<th id="(escapeHtml(Item.Script))" class="code">JSON</th>
<th id="Item.TxID" class="hash">TxID</th>
<th id="Item.Length" class="num">Bytes</th>
<th id="Item.power" class="num">Power</th>
<th id="(Item.VerifyHTML)" class="verify">Verify</th>
</tr>
</table>
</div>
</div>
</section>
</main>
</body>
</html>

1457
src/HTML/chains.html Normal file

File diff suppressed because it is too large Load Diff

515
src/HTML/console.html Normal file
View File

@ -0,0 +1,515 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Console</title>
<link rel="shortcut icon" href="/HTML/PIC/console.png" type="image/png">
<link rel="stylesheet" type="text/css" href="/HTML/CSS/buttons.css">
<link rel="stylesheet" type="text/css" href="/HTML/CSS/style.css">
</head>
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="/HTML/JS/coinlib.js"></script>
<script type="text/javascript" src="/HTML/JS/client.js"></script>
<script type="text/javascript" src="/HTML/JS/sha3.js"></script>
<script type="text/javascript" src="/HTML/JS/crypto-client.js"></script>
<script type="text/javascript" src="/HTML/JS/terahashlib.js"></script>
<script>
function SetStatus(Str)
{
var id = $("status");
id.innerHTML=Str;
}
function SetStatus2(Str)
{
var id = $("status2");
id.innerHTML=Str;
}
function UpdateData()
{
GetData("GetWalletInfo",{}, function (Data)
{
if(Data && Data.result)
{
SetBlockChainConstant(Data);
}
});
}
///////////////////
var CodeList={};
var CurRowName;
function SetConsoleText(bRun)
{
//SaveToList();
var Name = $("idConsoleIndex").value;
$("idName").value=Name;
CurRowName=Name;
var Data=CodeList[Name];
if(Data && Data.Code)
{
$("idConsoleText").value=Data.Code;
$("idConsoleSend").value=Data.Type;
$("idProcessTX").checked=Data.ProcessTX;
}
else
{
$("idConsoleText").value=Data;
$("idProcessTX").checked=0;
$("idConsoleSend").value="ServerCode";
}
if(bRun)
SendToServer();
}
function SetAndRun()
{
SetConsoleText(1);
}
function NewRow()
{
CurRowName=undefined;
$("idName").value="";
}
function SaveToList(bUpdate)
{
var Name = $("idName").value;
if(CurRowName)
{
SetNameInSelect(Name);
delete CodeList[CurRowName];
}
if(Name)
{
var Data={Code:$("idConsoleText").value,Type:$("idConsoleSend").value,ProcessTX:$("idProcessTX").checked};
CodeList[Name]=Data;
}
if(bUpdate)
{
SaveArrToSelect(Name);
}
CurRowName=Name;
SaveValues();
}
function SetNameInSelect(Name)
{
var Select=document.getElementById("idConsoleIndex");
for(var i=0;i<Select.options.length;i++)
if(Select.options[i]===CurRowName)
{
if(Name)
{
Select.options[i].value=Name;
Select.options[i].text=Name;
}
else
{
Select.options[i] = null;
}
}
}
function SaveArrToSelect(CurrName)
{
var Select=document.getElementById("idConsoleIndex");
Select.options.length=0;
for(var Name in CodeList)
{
Select.options[Select.options.length]=new Option(Name,Name,false,(Name===CurrName));
}
}
///////////////////
function OnSelectTypeCode()
{
var Type = $("idConsoleSend").value;
if(Type==="ECode")
{
$("idBtRun").value="Send eval";
}
else
if(Type==="HEX")
{
$("idBtRun").value="Send transaction";
}
else
{
$("idBtRun").value="Run";
}
}
function SendToServer()
{
SaveValues();
var Value = $("idConsoleText").value;
var Type = $("idConsoleSend").value;
if(Type==="ECode")
{
SendECode(Value);
}
else
if(Type==="HEX")
{
SendHEXTransaction(Value);
}
else
if(Type==="ServerCode")
{
SendServerCode(Value);
}
else
{
RunClientCode(Value);
}
}
function RunClientCode(Value)
{
SetStatus("");
var Result;
try
{
Result=eval(Value);
}
catch (e)
{
Result=e;
}
ToResult(Result);
}
function SendServerCode(Value)
{
var bProcessTX = $("idProcessTX").checked;
SetStatus("");
GetData("SendDirectCode",{Code:Value,TX:bProcessTX }, function (Data)
{
if(Data)
{
ToResult(Data.text);
}
});
}
function SendHEXTransaction(Value)
{
var Body=GetArrFromHex(Value);
if(Body.length<32)
{
SetStatus("Error length HEX transaction");
return;
}
Body.length+=12;
SendTransaction(Body);
}
var AllSend=0;
var AllNoSend=0;
var MustSend=0;
var LastErr="";
var LastOK="";
function SendECode(Code)
{
var DeltaBlockNum = parseInt($("idConsoleDeltaBlockNum").value);
// if($("idSendAll").checked)
// {
// var Data={DeltaBlockNum:DeltaBlockNum,Code:Code,All:1};
// GetData("SendECode",Data, function (Data)
// {
// if(Data)
// {
// ToResult(Data.text);
// }
// });
// return;
// }
var Addr = $("idNode").value;
AllSend=0;
AllNoSend=0;
MustSend=0;
LastErr="";
LastOK="";
var arr=Addr.split("\n");
for(var i=0;i<arr.length;i++)
{
var CurAddr=arr[i].trim();
if(CurAddr.length!==64)
continue;
MustSend++;
var Data={DeltaBlockNum:DeltaBlockNum,Code:Code,Addr:CurAddr};
GetData("SendECode",Data, function (Data)
{
if(Data && Data.result===1)
{
AllSend++;
LastOK=Data.text;
}
else
{
AllNoSend++;
LastErr=Data.text;
}
ToResult("OK:"+AllSend+" ("+LastOK+") NO:"+AllNoSend+" ("+LastErr+") OF:"+MustSend);
});
}
SetStatus("Must send="+MustSend);
ToResult("Must send="+MustSend);
}
function ToResult(Str)
{
$("result").value=Str;
}
//***********************************************
var idSendServer=undefined;
function StartSendServerPeriod(Period)
{
var Period=1000*ParseNum($("idPeriodRun").value);
if(idSendServer)
clearInterval(idSendServer);
idSendServer=0;
if(Period)
{
idSendServer=setInterval(function ()
{
var Value = $("idConsoleText").value;
SendServerCode(Value);
},Period);
return "Set period="+Period;
}
return "Clear";
}
//***********************************************
var idSendRandom=undefined;
function StartSendRandom(Period)
{
if(idSendRandom)
clearInterval(idSendRandom);
idSendRandom=0;
if(Period)
{
idSendRandom=setInterval(SendRandom,Period);
return "Set period="+Period;
}
return "Clear";
}
var glNumSend=0;
function SendRandom()
{
glNumSend++;
var Body=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
Body[6]=glNumSend&0xFF;
Body[7]=(glNumSend>>>8) & 0xFF;
Body[8]=(glNumSend>>>16) & 0xFF;
Body[9]=(glNumSend>>>24) & 0xFF;
var rnd=Math.floor(Math.random()*1000000000);
Body[10]=rnd&0xFF;
Body[11]=(rnd>>>8) & 0xFF;
Body[12]=(rnd>>>16) & 0xFF;
Body[13]=(rnd>>>24) & 0xFF;
SendHEXTransaction(GetHexFromArr(Body));
}
function CheckCtrlEnter(e,F)
{
SaveValues();
if(e.ctrlKey && e.keyCode===13)
{
SendToServer();
}
if(e.keyCode===27)
{
window.close();
}
//SetStatus("keyCode="+e.keyCode)
}
function CheckDevelop()
{
GetData("GetWalletInfo",{}, function (Data)
{
if(Data && Data.result)
{
if(!Data.IsDevelopAccount)
{
var Select = $("idConsoleSend");
for(var i=0;i<Select.options.length;i++)
{
var item=Select.options[i];
if(item.value==="ECode")
{
item.disabled=1;
Select.options[i] = null;
break;
}
}
}
}
});
}
window.onload=function()
{
setInterval(UpdateData,100);
setTimeout(CheckDevelop,500);
window.onkeydown = CheckCtrlEnter;
LoadValues();
SaveArrToSelect();
document.body.className="univers "+localStorage["idSelStyle"];
SetStatus("");
OnSelectTypeCode();
}
function LoadValues()
{
if(!localStorage["WasSaveConsole"])
return;
$("idConsoleSend").value=localStorage["idConsoleSend"];
$("idConsoleDeltaBlockNum").value=localStorage["idConsoleDeltaBlockNum"];
$("idNode").value=localStorage["idConsoleNode"];
if(localStorage["ConsoleCodeList2"])
CodeList=JSON.parse(localStorage["ConsoleCodeList2"]);
if(localStorage["idConsolePow"])
$("idPow").value=localStorage["idConsolePow"];
$("idProcessTX").checked=(localStorage["idConsoleProcessTX"]==="true");
if(localStorage["idConsolePeriodRun"])
$("idPeriodRun").value=localStorage["idConsolePeriodRun"];
}
function SaveValues()
{
localStorage["WasSaveConsole"]=1;
localStorage["idConsoleSend"]=$("idConsoleSend").value;
localStorage["idConsoleDeltaBlockNum"]=$("idConsoleDeltaBlockNum").value;
localStorage["idConsoleNode"]=$("idNode").value;
localStorage["ConsoleCodeList2"]=JSON.stringify(CodeList);
localStorage["idConsolePow"]=$("idPow").value;
//localStorage["idConsoleSendAll"]=$("idSendAll").checked;
localStorage["idConsoleProcessTX"]=$("idProcessTX").checked;
localStorage["idConsolePeriodRun"]=$("idPeriodRun").value;
}
</script>
<style type="text/css">
</style>
<body>
<DIV align='center'>
<B>CONSOLE</B>
<DIV id="status2"></DIV><BR>
<DIV id="status"> ... </DIV><BR>
Mode:
<select size="1" id="idConsoleSend" onkeyup="OnSelectTypeCode();SaveValues()" onchange="OnSelectTypeCode();SaveValues()">
<option value="ServerCode">Server code</option>
<option value="ClientCode">Client code</option>
<option value="ECode" style="color:red;">Eval code !!</option>
<option value="HEX">HEX Transaction</option>
</select>
POW:<INPUT type="number" id="idPow" style="width: 50px;" onchange="SaveValues();" value="14"> Delta BlockNum:<INPUT type="number" id="idConsoleDeltaBlockNum" style="width: 50px;" value="10">
<BR>
<DIV align='left' style="border: 1px solid #39519b;width:1198px;height:800px;">
<DIV style="width: 200px;height:100%; float:left;">
<select size="45" id="idConsoleIndex" style="width:100%;height:100%;" onchange="SetConsoleText()" ondblclick="SetAndRun()">
</select>
</DIV>
<DIV style="width: 998px;height:100%; float: left;">
<DIV>
<DIV>
<INPUT type="button" onclick="NewRow()" class="bt" value="*New">
Name:<INPUT type="string" id="idName" style="width: 72%;" value="">
<INPUT type="button" onclick="SaveToList(1)" class="bt" value="Save">
</DIV>
<textarea id="idConsoleText" style="width: 99%;height: 95%;" rows="22" cols="98" autofocus>
</textarea>
</DIV>
<textarea rows="5" cols="98" name="result" id="idNode" style="width: 99%;">
</textarea>
<INPUT type="button" onclick="SendToServer()" class="bt btdoit" id="idBtRun" value="Send">
<!--All<input type="checkbox" id="idSendAll" onchange = "SaveValues()"/>-->
<INPUT type="button" onclick="StartSendServerPeriod()" class="bt btdoit" id="idBtRun2" value="Run every">
<INPUT type="number" id="idPeriodRun" style="width: 50px;" onchange="SaveValues();" value="1">sec
TX process:<INPUT type="checkbox" id="idProcessTX">
<BR>
<BR>
<textarea rows="18" cols="98" name="result" id="result" style="width: 99%;">
</textarea>
</DIV>
</DIV>
</DIV>
</body>
</html>

1048
src/HTML/dapp-edit.html Normal file

File diff suppressed because it is too large Load Diff

594
src/HTML/dapp-frame.html Normal file
View File

@ -0,0 +1,594 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-Frame-Options" value="sameorigin">
<title>DAPP Loading...</title>
<link rel="shortcut icon" href="./tera.ico" type="image/vnd.microsoft.icon">
<script type="text/javascript" src="./JS/crypto-client.js"></script>
<script type="text/javascript" src="./JS/coinlib.js"></script>
<script type="text/javascript" src="./JS/client.js"></script>
<script type="text/javascript" src="./JS/terahashlib.js"></script>
<script>
InitWalletKeyName();
window.Storage=window.localStorage;
var DapNumber="#template-number#";
var glSmart=parseInt(DapNumber);
var CONFIG_DATA={};
var NumDappGet=0;
var NumDappInfo=0;
var arr = new Uint8Array(6);
window.crypto.getRandomValues(arr);
var glSession=GetHexFromArr(arr);
//DAPP TRANSFER
function SendMessage(Data)
{
var win = window.frames.dapp;
if(!win)
{
console.log("Error window.frames.dapp");
//try latter
setTimeout(function ()
{
win.postMessage(Data, "*");
},200);
return;
}
//console.log("To dapp: "+JSON.stringify(Data))
win.postMessage(Data, "*");
}
var glProgramSetHash;
function listener(event)
{
var Data=event.data;
if(!Data || typeof Data!=="object")
return;
switch (Data.cmd)
{
case "pay":
{
AddToInvoiceList(Data);
break;
}
case "setstorage":
{
Storage.setItem("DAPP-"+DapNumber+"-"+Data.Key,JSON.stringify(Data.Value));
break;
}
case "getstorage":
{
Data.Value=Storage.getItem("DAPP-"+DapNumber+"-"+Data.Key);
if(Data.Value)
Data.Value=JSON.parse(Data.Value);
SendMessage(Data);
break;
}
case "setcommon":
{
Storage.setItem("DAPP-"+Data.Key,JSON.stringify(Data.Value));
break;
}
case "getcommon":
{
Data.Value=Storage.getItem("DAPP-"+Data.Key);
if(Data.Value)
Data.Value=JSON.parse(Data.Value);
SendMessage(Data);
break;
}
case "DappCall":
{
if(!Data.Account)
Data.Account=BASE_ACCOUNT.Num;
GetData("DappStaticCall",{Account:Data.Account,MethodName:Data.MethodName,Params:Data.Params}, function (SetData)
{
if(SetData)
{
Data.Err=!SetData.result;
Data.RetValue=SetData.RetValue;
}
else
{
Data.Err=1;
}
SendMessage(Data);
});
break;
}
case "DappSendCall":
{
if(!Data.Account)
Data.Account=BASE_ACCOUNT.Num;
if(!Data.FromNum)
Data.FromNum=0;
SendCallMethod(Data.Account,Data.MethodName,Data.Params,Data.FromNum,glSmart);
break;
}
case "DappInfo":
{
//called every 1 sec from dapp-inner.js
var AllData=0;
if(Data.AllData || !NumDappGet || NumDappGet%60===0)
AllData=1;
NumDappGet++;
var Key=GetPubKey();
GetData("DappInfo",{Smart:glSmart,Key:Key,Session:glSession,NumDappInfo:NumDappInfo,AllData:AllData,AllAccounts:Data.AllAccounts}, function (SetData)
{
if(SetData)
{
Data.Err=!SetData.result;
Data.cache=SetData.cache;
if(SetData.result)
{
CONFIG_DATA=SetData;
SMART=SetData.Smart;
BASE_ACCOUNT=SetData.Account;
SetBlockChainConstant(SetData);
NumDappInfo=SetData.NumDappInfo;
SetArrLog(SetData.ArrLog);
for(var key in SetData)
Data[key]=SetData[key];
Data.OPEN_PATH=OPEN_PATH;
if(!Data.PubKey)
{
//support web/light wallet mode:
Data.PubKey=GetPubKey();
Data.WalletIsOpen=IsPrivateMode(GetPrivKey());
Data.WalletCanSign=Data.WalletIsOpen;
}
CONFIG_DATA.WalletCanSign=Data.WalletCanSign;
CONFIG_DATA.PubKey=Data.PubKey;
}
SendMessage(Data);
}
});
break;
}
case "DappWalletList":
var Key=GetPubKey();
Data.Params={Smart:glSmart,Key:Key};
case "DappSmartHTMLFile":
case "DappBlockFile":
case "DappAccountList":
case "DappSmartList":
case "DappBlockList":
case "DappTransactionList":
{
if(Data.cmd==="DappBlockFile")
{
//check storage
var StrKeyStorage=Data.Params.BlockNum+"-"+Data.Params.TrNum;
var Storage2=sessionStorage;
var SavedTextData=Storage2[StrKeyStorage];
if(SavedTextData)
{
var SetData=JSON.parse(SavedTextData);
Data.Err=!SetData.result;
Data.arr=SetData.arr;
Data.Body=SetData.Body;
SendMessage(Data);
return;
}
}
Data.Params.Session=glSession;
GetData(Data.cmd,Data.Params, function (SetData,responseText)
{
if(SetData)
{
Data.Err=!SetData.result;
Data.arr=SetData.arr;
Data.Body=SetData.Body;
SendMessage(Data);
if(StrKeyStorage && SetData.result)
{
Storage2[StrKeyStorage]=responseText;
}
}
});
break;
}
case "SetStatus":
{
SetStatus(escapeHtml(Data.Message));
break;
}
case "SetError":
{
SetError(escapeHtml(Data.Message));
break;
}
case "CheckInstall":
{
CheckInstall();
break;
}
case "SetLocationHash":
{
glProgramSetHash=1;
window.location.hash="#"+Data.Message;
glProgramSetHash=0;
break;
}
case "OpenLink":
{
var Path=Data.Message.substr(0,200);
if(IsLocalClient() && Path.substr(0,6)==="/dapp/")
Path="?dapp="+Path.substr(6);
//console.log("OpenLink:"+Path);
window.open(Path);
break;
}
case "ComputeSecret":
{
ComputeSecret(Data.Account,Data.PubKey,function (Result)
{
Data.Result=Result;
SendMessage(Data);
});
break;
}
// case "GetLink":
// {
// GetData(Data.url,Data.Params, function (SetData)
// {
// if(SetData)
// {
// SendMessage({cmd:"GetLink",Result:SendData});
// }
// });
// break;
// }
case "SetMobileMode":
{
SetMobileMode();
break;
}
case "CreateNewAccount":
{
CreateNewAccount(Data.Currency);
break;
}
}
}
if (window.addEventListener)
{
window.addEventListener("message", listener);
} else
{
// IE8
window.attachEvent("onmessage", listener);
}
var SMART={},BASE_ACCOUNT={},OPEN_PATH="";
window.onload=function()
{
if(window.location.hash)
OPEN_PATH=window.location.hash.substr(1);
if(IsLocalClient())
{
DapNumber=window.location.search.substr(6);
if(Storage.getItem("MainServer"))
{
MainServer=JSON.parse(Storage.getItem("MainServer"));
}
}
glSmart=parseInt(DapNumber);
var Key=GetPubKey();
GetData("DappInfo",{Smart:glSmart, Key:Key, Session:glSession, AllData:1}, function (SetData)
{
if(!SetData || !SetData.result)
return;
CONFIG_DATA=SetData;
SMART=SetData.Smart;
BASE_ACCOUNT=SetData.Account;
SetBlockChainConstant(SetData);
document.title=SMART.Name;
var HTMLBlock=BASE_ACCOUNT.SmartState.HTMLBlock;
var HTMLTr=BASE_ACCOUNT.SmartState.HTMLTr;
if(!glDebugPath && HTMLBlock)
{
console.log("Load HTML from: /file/"+HTMLBlock+"/"+HTMLTr);
GetData("DappBlockFile",{BlockNum:HTMLBlock,TrNum:HTMLTr}, function (SetData)
{
if(SetData && SetData.result)
{
CreateFrame(SetData);
}
});
}
else
{
GetData("DappSmartHTMLFile",{Smart:glSmart,DebugPath:glDebugPath}, function (SetData)
{
if(SetData && SetData.result)
{
CreateFrame(SetData);
}
});
}
});
if(!window.sha3)
LoadLib("./JS/sha3.js");
LoadSignLib();
window.addEventListener("popstate", function(event)
{
OPEN_PATH=window.location.hash.substr(1);
if(!glProgramSetHash)
SendMessage({cmd:"History",OPEN_PATH:OPEN_PATH});
}, false);
}
function CreateFrame(SetData)
{
var SriptLW="";
if(MainServer)
{
var StrPath=GetProtocolServerPath(MainServer);
//console.log("StrPath:"+StrPath);
//console.log("WAS:\n"+SetData.Body);
//поддрежка старого кода dapp (после обновления dapp этот код возможно будет удален)
SetData.Body=SetData.Body.replace(/.\/CSS\/[0-9a-z_-]+.css\">/g,StrPath+"$&");
SetData.Body=SetData.Body.replace(/.\/JS\/[0-9a-z_-]+.js\">/g,StrPath+"$&");
//TODO: переделать на нормальный парсинг без регулярки
//поддержка перенаправления в блокчейн
SetData.Body=SetData.Body.replace(/\/file\/[0-9]+\/[0-9]+\"/g,StrPath+"$&");
SriptLW='<script>window.PROTOCOL_SERVER_PATH="'+StrPath+'";<\/script>';
//console.log("NEW:\n"+SetData.Body);
}
var iframe = document.createElement('iframe');
iframe.name = 'dapp';
iframe.sandbox="allow-scripts";
SetData.Body='\
<meta charset="UTF-8">\
<meta http-equiv="X-Frame-Options" value="sameorigin">\
<script type="text/javascript" src="./JS/crypto-client.js"><\/script>\
<script type="text/javascript" src="./JS/coinlib.js"><\/script>\
<script type="text/javascript" src="./JS/client.js"><\/script>\
<script type="text/javascript" src="./JS/dapp-inner.js"><\/script>\
<script type="text/javascript" src="./JS/terahashlib.js"><\/script>\
'+SriptLW+SetData.Body;
iframe.srcdoc=SetData.Body;
document.getElementsByTagName('body')[0].appendChild(iframe);
}
function SetMobileMode()
{
var newchild = document.createElement("meta")
newchild.name = "viewport"
newchild.content = "width=device-width, initial-scale=1.0";//, maximum-scale=1.0, user-scalable=0;
window.parent.document.getElementsByTagName("head")[0].appendChild(newchild);
//ToLog("SetMobileMode 2");
}
var idInstallApp=0;
function CheckInstall()
{
if(!idInstallApp)
idInstallApp=setInterval(RunCheckInstall,2000);
}
function RunCheckInstall()
{
if(CONFIG_DATA && CONFIG_DATA.ArrWallet && CONFIG_DATA.ArrWallet.length===0)
{
var StrRef;
if(MainServer)
StrRef='<A class="btcreate" href="./web-wallet.html#TabAccounts">Accounts</A>';
else
{
if(Storage.getItem("BIGWALLET"))
StrRef='<A class="btcreate" href="/wallet.html#TabAccounts">Config</A>'
else
StrRef='<A class="btcreate" href="/web-wallet.html#TabAccounts">Accounts</A>';
}
var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button> or goto '+StrRef+' tab and Set smart number <B>'+SMART.Num+'</B> to your account<DIV>';
SetStatus(Str);
}
}
//LIB
function SetArrLog(arr)
{
var Str="";
if(arr)
for(var i=0;i<arr.length;i++)
{
var Item=arr[i];
if(!Item.final)
continue;
if(Item.text.indexOf("Add to blockchain")>=0)
continue;
var TR=MapSendTransaction[Item.key];
if(TR && !TR.WasSend && Item.final)
{
var Data={};
Data.cmd="OnEvent";
Data.Description="Error: "+Item.text;
Data.Error=1;
//console.log(JSON.stringify(Item));
SendMessage(Data);
TR.WasSend=1;
}
}
}
function IsPrivateMode(PrivKeyStr)
{
if(PrivKeyStr && PrivKeyStr.length===64)
return 1;
else
return 0;
}
function SetStatus(Str)
{
var id = $("idStatus");
id.innerHTML=Str;
console.log(id.innerText);
}
function SetError(Str,bNoSound)
{
SetStatus("<DIV style='color:red'><B>"+Str+"</B></DIV>");
}
function CreateNewWebKeys()
{
var arr = new Uint8Array(32);
window.crypto.getRandomValues(arr);
var PrivKey=sha3(arr);
SetPrivKey(GetHexFromArr(PrivKey));
Storage.setItem("idPubKey",GetHexFromArr(SignLib.publicKeyCreate(PrivKey,1)));
CONFIG_DATA.PubKey=GetPubKey();
//console.log("CreateNewWebKeys: "+CONFIG_DATA.PubKey);
}
var CountCreateNewAccount=0;
function CreateNewAccount(Currency)
{
if(!CONFIG_DATA.WalletCanSign)
{
if(Storage.getItem("BIGWALLET") || IsLockedWallet())
{
SetError("Pls, open wallet");
return;
}
CreateNewWebKeys();
}
if(CountCreateNewAccount>20)
return;
CountCreateNewAccount++;
SetStatus("Calculate Tx, wait pls ...");
var TR=GetTrCreateAcc(Currency,CONFIG_DATA.PubKey,SMART.Name,0,SMART.Num);
var Body=GetBodyCreateAcc(TR);
SendTransaction(Body,TR);
}
function InstallApp()
{
CreateNewAccount(0);
if(idInstallApp)
{
clearInterval(idInstallApp);
idInstallApp=setInterval(RunCheckInstall,30000);
}
}
</script>
<style>
iframe
{
left:0;
top: 20px;
width: 100%;
height: 97vh;
border: 0;
}
#idStatus
{
text-align: center;
position:fixed;
top: 0;
left: 0;
width: 100%;
height:18px;
padding: 0;
margin: 0;
background-color:white;
}
.btcreate
{
height:18px;
background-color: #347867;
color: white;
cursor: pointer;
border-radius: 3px;
padding: 2px;
text-decoration: none;
border: 1px solid gray;
}
</style>
</head>
<body>
<DIV id="idStatus"></DIV>
</body>
</html>
<script>
var glDebugPath="";
//glDebugPath="./dapp-smart/forum.html";
//glDebugPath="./dapp-smart/DEX.html";
//glDebugPath="./dapp-smart/OnlineStore.html";
//glDebugPath="./dapp-smart/BTC-coin.html";
//glDebugPath="./dapp-smart/static/miner-list.html";
//glDebugPath="./dapp-smart/acc-control/RescueMoney2.html";
//glDebugPath="./dapp-smart/airdrop/page.html";
//{"HTMLBlock":8653023,"HTMLTr":0}
</script>

253
src/HTML/history.html Normal file
View File

@ -0,0 +1,253 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>History account</title>
<link rel="shortcut icon" href="./PIC/viewer.png" type="image/png">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!--<link rel="stylesheet" type="text/css" href="./CSS/history.css">-->
<link rel="stylesheet" href="./CSS/mobile-wallet.css">
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="./JS/coinlib.js"></script>
<script type="text/javascript" src="./JS/client.js"></script>
<script>
var AccountID;
var CountViewRows=20;
function SetStatus(Str)
{
var id = $("idStatus");
id.innerHTML=Str;
}
window.onload=function()
{
try
{
OnLoad();
}
catch (e)
{
SetStatus("Error: "+e);
}
}
function OnLoad()
{
InitMainServer();
document.body.className="univers "+localStorage["idSelStyle"];
var i=document.URL.indexOf("#");
if(i>0)
{
AccountID=ParseNum(document.URL.substr(i+1));
document.getElementById("idViewAccountID").value=AccountID;
ViewHistory(1);
}
window.onkeydown = function (e)
{
if(e.keyCode===27)
{
window.close();
}
};
window.addEventListener("popstate", function(event)
{
document.getElementById("idViewAccountID").value=ParseNum(window.location.hash.substr(1));
ViewHistory(1);
}, false);
}
function OnChangeAccount()
{
AccountID=ParseNum(document.getElementById("idViewAccountID").value);
history.pushState(null,null,"#"+AccountID);
ViewHistory(1)
}
var CurPage=0;
var ArrPos=[];
function ViewHistory(bReset,NextPos)
{
var Params={AccountID:AccountID,Count:CountViewRows,GetDescription:1}
if(bReset)
{
CurPage=0;
ArrPos=[];
AccountID=ParseNum(document.getElementById("idViewAccountID").value);
Params.AccountID=AccountID;
}
else
{
Params.NextPos=NextPos;
}
document.title="Account: "+AccountID;
GetData("GetHistoryTransactions", Params, function (Data)
{
if(!Data || !Data.History)
return;
$("idName").innerText=Data.Name;
$("idBalanceSum").innerText="Balance: "+STRING_FROM_COIN(Data.Value)+" "+CurrencyName(Data.Currency);
MaxBlockNum=Data.MaxBlockNum;
window.FIRST_TIME_BLOCK=Data.FIRST_TIME_BLOCK;
var Item;
var arr=Data.History;
for(var i=0;i<arr.length;i++)
{
Item=arr[i];
Item.Num=Item.Pos;
Item.Currency=Data.Currency;
Item.Value={SumCOIN:Item.SumCOIN,SumCENT:Item.SumCENT};
}
if(Item)
{
ArrPos[CurPage]={First:arr[0].Pos,NextPos:Item.NextPos};
}
SetGridData(Data.History,"grid_history","idTotalSumH",1);
});
}
function ViewBegin()
{
ViewHistory(1);
// CurPage=0;
// var Item=ArrPos[CurPage];
// if(Item)
// {
// ViewHistory(0,Item.First);
// }
}
function ViewPrev()
{
if(CurPage<=0)
return;
CurPage--;
var Item=ArrPos[CurPage];
if(Item)
{
ViewHistory(0,Item.First);
}
}
function ViewNext()
{
var Item=ArrPos[CurPage];
if(Item && Item.NextPos)
{
CurPage++;
ViewHistory(0,Item.NextPos);
}
}
function SaveValues()
{
}
var MaxBlockNum=0;
function ConfirmationFromBlock(BlockNum)
{
var Length=MaxBlockNum-8-BlockNum;
if(Length>0)
{
if(Length<=100)
return Length;
else
{
return ">"+Math.floor(Length/100)*100;
}
}
else
return "";
}
function GetCorrID(Item,Direct)
{
var Str;
if(Item.Direct===Direct)
Str=RetHistoryAccount(Item,"CorrID");
else
Str=AccountID;
return Str;
}
function GetStr(Str)
{
if(Str===undefined)
return "";
return Str;
}
</script>
</head>
<body>
<header class="header">
<div class="header__wrapper">
<div class="header__logo header__logo--history">
<a onclick="" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="/PIC/TeraLogo.svg" alt="TERA Foundation">
<p class="header__logo-name">History</p>
</a>
</div>
<div class="header__right">
<select size="1" id="idLang" onchange="ChangeLang()" class="bigs" >
<option value="ENG">ENG</option>
</select>
</div>
</div>
</header>
<main>
<section class="history-page" id="idTransactionBlock" style="display: block">
<div class="history__text-block">
<div class="history-page__id" >
<!--<a class="back-link back-link&#45;&#45;history" onclick="SelectTab('TabKeySet')"><span>Accounts</span></a>-->
History of <input class="history-page__id-count" type="number" id="idViewAccountID" style="text-align: center" value="0" min=0 max=1000000000 onchange="OnChangeAccount()">
</div>
<div id="idName" class="history-page__description"></div>
<div class="history-page__balance" id="idBalanceSum">Balance: 000<img class="history-page__tera-icon" src="./PIC/T.svg" width="10" height="14" alt=""></div>
</div>
<div class="history-page__table">
<div class="page-pagination">
<button onclick="ViewBegin()" class="btnav btn">|&lt;</button>
<button onclick="ViewPrev()" class="btnav btn">&lt;</button>
<input type="number" class="page-pagination__num" id="idViewAccountNum" style="text-align: center" value="0" min="0" onchange="ViewCurrent(DefAccounts)">
<button onclick="ViewNext()" class="btnav btn">&gt;</button>
</div>
<div class="history-page__table-wrap">
<table id="grid_history" class="grid">
<tr>
<th id="(RetDirect(Item.Direct))" class="direct">...</th>
<th id="(GetCorrID(Item,'+'))" class="num">From</th>
<th id="(GetCorrID(Item,'-'))" class="num">To</th>
<th id="(escapeHtml(DateFromBlock(Item.BlockNum,1)))" class="date">Date</th>
<th id="SUM_TO_STRING(Item)" class="sum smallbold">Amount</th>
<th id="CurrencyName(Item.Currency)" class="cur">Cur</th>
<th id="GetStr(Item.Description)" class="desc">Description</th>
<th id="ConfirmationFromBlock(Item.BlockNum)" class="num">Confirm</th>
<th id="(RetOpenBlock(Item.BlockNum,1))" class="num">Block</th>
<th id="Item.TrNum" class="num">Tx</th>
</tr>
</table>
</div>
<br><DIV id="idTotalSumH"></DIV>
</div>
</section>
</main>
</body>
</html>

716
src/HTML/mobile-wallet.html Normal file
View File

@ -0,0 +1,716 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TERA Mobile</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="./tera.ico" type="image/vnd.microsoft.icon">
<link rel="stylesheet" type="text/css" href="./CSS/mobile-wallet.css">
<script type="text/javascript" src="./JS/coinlib.js"></script>
<script type="text/javascript" src="./JS/client.js"></script>
<script type="text/javascript" src="./JS/sha3.js"></script>
<script type="text/javascript" src="./JS/crypto-client.js"></script>
<script type="text/javascript" src="./JS/terahashlib.js"></script>
<script type="text/javascript" src="./JS/wallet-web.js"></script>
<script type="text/javascript" src="./JS/wallet-lib.js"></script>
<script type="text/javascript" src="./JS/diagram.js"></script>
<script type="text/javascript" src="./JS/mobile-wallet.js"></script>
</head>
<body>
<header class="header">
<div class="header__wrapper">
<div class="header__logo">
<a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="/PIC/TeraLogo.svg" alt="TERA Foundation">
</a>
</div>
<div class="header__right">
<select size="1" id="idLang" onchange="ChangeLang()" class="bigs" >
<option value="ENG">ENG</option>
</select>
<div class="header__wallet-set">
<a class="header__wallet-link tab-link" id="MTabKeySet" onclick="SelectTab('TabKeySet')">
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.333 21.0024C22.8059 21.0024 24 19.8084 24 18.3354V5.66724C24 4.1943 22.8059 3.00024 21.333 3.00024H19.9995C19.9995 1.89554 19.104 1 17.9993 1H3.99756C2.52462 1 1.33057 2.19405 1.33057 3.66699V11H2.66406V3.66699C2.66406 2.93052 3.26109 2.3335 3.99756 2.3335H17.9993C18.3675 2.3335 18.666 2.63201 18.666 3.00024H5.33105C4.96282 3.00024 4.66431 3.29876 4.66431 3.66699C4.66431 4.03523 4.96282 4.33374 5.33105 4.33374H21.333C22.0695 4.33374 22.6665 4.93077 22.6665 5.66724V8.33423H17.3325C15.4913 8.33423 13.9988 9.8268 13.9988 11.668C13.9988 13.5091 15.4913 15.0017 17.3325 15.0017H22.6665V18.3354C22.6665 19.0719 22.0695 19.6689 21.333 19.6689H13V21.0024H21.333ZM15.3323 11.668C15.3323 10.5633 16.2278 9.66772 17.3325 9.66772H22.6665V13.6682H17.3325C16.2278 13.6682 15.3323 12.7727 15.3323 11.668Z"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.5414 16.4582C12.7257 16.4582 12.9388 16.5955 12.9593 16.7783C13.0144 17.2706 13.0137 17.7677 12.9564 18.2565C12.9338 18.4467 12.7624 18.5903 12.576 18.5751L12.4956 18.573C11.921 18.573 11.3868 18.927 11.1658 19.4542C10.9308 20.0142 11.0776 20.666 11.53 21.0757C11.6719 21.2041 11.6888 21.4208 11.5689 21.5697C11.2597 21.9547 10.9061 22.3045 10.5173 22.6094C10.3676 22.725 10.1552 22.7081 10.0267 22.5684C9.63998 22.1435 8.95181 21.9836 8.41688 22.2021C7.86352 22.4287 7.50573 22.9858 7.52754 23.5882C7.53388 23.7774 7.39423 23.9397 7.20573 23.9605C6.96789 23.9869 6.73001 24 6.49217 24C6.24161 24 5.99173 23.9855 5.74334 23.9566C5.55349 23.9347 5.41307 23.7682 5.42434 23.5769C5.45888 22.9678 5.10596 22.4008 4.54491 22.1661C4.00926 21.9413 3.31335 22.1004 2.92445 22.5306C2.79535 22.6728 2.57865 22.6898 2.42971 22.5698C2.05001 22.2642 1.70343 21.9141 1.4014 21.5294C1.2842 21.3809 1.30186 21.1674 1.44092 21.0396C1.88555 20.6321 2.03162 19.9864 1.80438 19.4323C1.57641 18.8776 1.03296 18.5271 0.466932 18.5416C0.280656 18.5416 0.0611022 18.4055 0.0406898 18.222C-0.0143559 17.7297 -0.0136788 17.2321 0.0434953 16.7438C0.066036 16.5564 0.212841 16.418 0.418948 16.4247C1.0541 16.4247 1.60891 16.0803 1.8333 15.546C2.06834 14.9856 1.92226 14.3339 1.46985 13.9242C1.3287 13.7958 1.31105 13.5794 1.43105 13.4302C1.73874 13.0462 2.09305 12.6962 2.48263 12.3906C2.63152 12.2745 2.84536 12.2917 2.97316 12.4318C3.35983 12.8571 4.0509 13.0152 4.58226 12.7982C5.13634 12.5712 5.49351 12.0141 5.47232 11.4113C5.46599 11.2225 5.60573 11.0602 5.79418 11.0394C6.28118 10.9854 6.77098 10.9871 7.25652 11.0433C7.44715 11.0655 7.58689 11.2317 7.57553 11.4229C7.54099 12.0317 7.8939 12.5987 8.45355 12.8342C8.99133 13.0585 9.68729 12.8991 10.0747 12.47C10.2032 12.3277 10.4206 12.3112 10.5687 12.4301C10.9471 12.7332 11.2936 13.0829 11.5985 13.47C11.7157 13.6186 11.6987 13.8324 11.559 13.9602C11.115 14.3674 10.969 15.0135 11.1955 15.5675C11.4172 16.1084 11.9458 16.4582 12.5414 16.4582ZM6.50013 21.4011C8.6546 21.4011 10.4011 19.6546 10.4011 17.5001C10.4011 15.3457 8.6546 13.5991 6.50013 13.5991C4.34566 13.5991 2.59912 15.3457 2.59912 17.5001C2.59912 19.6546 4.34566 21.4011 6.50013 21.4011Z"/>
</svg>
<span>Key settings</span>
</a>
</div>
</div>
<nav class="header__nav nav-tabs">
<ul class="nav-tabs__list">
<li class="nav-tabs__tab active"><a id="MTabAccounts" class="tab-link nav-tabs__link" onclick="SelectTab('TabAccounts')">ACCOUNTS</a></li>
<li class="nav-tabs__tab"><a id="MTabSend" class="tab-link nav-tabs__link" onclick="SelectTab('TabSend')">SEND</a></li>
<li class="nav-tabs__tab"><a id="MTabDapps" class="tab-link nav-tabs__link" onclick="SelectTab('TabDapps')">DAPPS</a></li>
<li class="nav-tabs__tab"><a id="MTabExplorer" class="tab-link nav-tabs__link" onclick="SelectTab('TabExplorer')">EXPLORER</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section id="TabWelcome" class="welcome" >
<div class="welcome__img">
<svg class="" xmlns="http://www.w3.org/2000/svg" fill="#445368" viewBox="0 0 992.13 992.13" width="150" height="150">
<path d="M894.31,812.41a0.18,0.18,0,0,0,0-.08,1.11,1.11,0,0,0-.09-0.23,2.58,2.58,0,0,0-.21-0.41,1.51,1.51,0,0,0-.11-0.25c-0.11-.21-0.22-0.4-0.34-0.59l-388.62-640-0.08-.14L504.4,170a10.15,10.15,0,0,0-16.92-.11,9.33,9.33,0,0,0-.54.86q-39.18,64.66-78.83,129.08a22.21,22.21,0,0,0,0,25.57q52.29,85.36,104.39,170.85a24.15,24.15,0,0,1,0,27.69C455.24,618,394.48,717,336.93,811.63a10.18,10.18,0,0,0,8.94,15H514a10.12,10.12,0,0,0,5.29-1.49,10.25,10.25,0,0,0,3.66-3.87h0l5.79-9.66,77.5-127.91s0,0,0,0a10.18,10.18,0,0,1,17.37-.84l0.21,0.33,0.07,0.11,77.16,126L708.15,821a10.17,10.17,0,0,0,8.95,5.3h4.71a21.71,21.71,0,0,0,2.34,0H884.87A10.16,10.16,0,0,0,895,816.15,9.73,9.73,0,0,0,894.31,812.41Z" />
<path d="M446.68,530.15l5.59-9.23a19.86,19.86,0,0,0,0-22.68L417.74,442.3l-39.5-64a10.2,10.2,0,0,0-17.63.46L98.31,811.68a10.17,10.17,0,0,0,8.95,15H250.82l-0.05,0h4.28l6.23,0h0a10.12,10.12,0,0,0,8.9-5.3,0,0,0,0,0,0,0l5.89-9.77a9.82,9.82,0,0,0,.74-1.15s0,0,0,0l6.4-10.57c55.06-90.94,107.53-177.76,162.52-268.28C446.12,531.11,446.41,530.63,446.68,530.15Z" />
</svg>
</div>
<h1 class="welcome__title title">Welcome to TERA Wallet</h1>
<p><a onclick="SelectTab('TabKeySet')" class="pointer">ATTENTION: Before using the wallet, save the private key.</a></p>
<!--<a class="welcome__link btn" onclick="SelectTab('TabAccounts')">Open wallet</a>-->
<ul id="idStableScroll" align='center' class="social-list">
<li class="social-list__item"><a href="https://terafoundation.org/">Web-site</a></li>
<li class="social-list__item"><a href="https://bitcointalk.org/index.php?topic=4573801.0">Bitcointalk</a></li>
<li class="social-list__item"><a href="https://twitter.com/terafoundation">Twitter</a></li>
<li class="social-list__item"><a href="https://t.me/terafoundation">Telegram</a></li>
<li class="social-list__item"><a href="https://discord.gg/CvwrbeG">Discord</a></li>
<li class="social-list__item"><a href="https://jq.qq.com/?_wv=1027&k=5KpN5fw">QQchat</a></li>
</ul>
</section>
<section id="TabWalletSet" class="wallet-settings" style="display: none;">
<div class="wallet-settings__title-wrap">
<a class="back-link" onclick="SelectTab('TabKeySet')"><span>Back</span></a>
<h2 class="wallet-settings__title title">Edit your wallet</h2>
</div>
<div class="wallet-settings__field key-field">
<p class="key-field__title">Private key <span>(secret)</span></p>
<!--<button class="key-field__btn btn-no-bg" onclick="pasteKey(event, 'idPrivKeyEdit')">Paste</button>-->
<textarea name="private-key" id="idPrivKeyEdit" placeholder="Insert your private key or generate a new key below..." class="key-field__textarea" oninput="OnEditPrivKey()">
</textarea>
</div>
<div class="wallet-wrapper">
<button class="btn btn--full-width wallet-settings__generate" onclick="OnGenerateKeyNew()">Generate key</button>
</div>
<div class="wallet-settings__ok-btns">
<button class="btn wallet-settings__btn-270" id="okEditBtn" style="margin-bottom: 15px;" onclick="OnPrivKeyOK()">OK</button>
<button class="btn btn--white wallet-settings__btn-270" id="cancelEditBtn" style="margin-bottom: 15px;" onclick="OnPrivKeyCancel()">Cancel</button>
</div>
<!--<button class="btn wallet-settings__go-btn" onclick="SelectTab('TabAccounts')">Go to accounts</button>-->
</section>
<section id="TabKeySet" class="wallet-settings wallet-settings--info" style="display: none;">
<div class="wallet-settings__title-wrap">
<!--<a class="back-link" onclick="SelectTab('TabWelcome')"><span>Back</span></a>-->
<h2 class="wallet-settings__title title">Key settings</h2>
<a class="modal-lock pointer" id="idPasswordEdit" onclick="openModal('password-modal-set');"><svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.5 5V10H10.5H12H13C13.5523 10 14 10.4477 14 11V17C14 17.5523 13.5523 18 13 18H1C0.447716 18 0 17.5523 0 17V11C0 10.4477 0.447715 10 1 10H2V5C2 2.23858 4.23858 0 7 0C9.76142 0 12 2.23858 12 5V7H10.5V5C10.5 3.067 8.933 1.5 7 1.5C5.067 1.5 3.5 3.067 3.5 5Z" fill="var(--fill--password)" fill-opacity="0.2"/>
</svg></a>
<a class="modal-lock2 pointer" id="idWalletExit" onclick="DoExitWallet();">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path transform="scale(0.035)" d="M0,121.05v248.2c0,34.2,27.9,62.1,62.1,62.1h200.6c34.2,0,62.1-27.9,62.1-62.1v-40.2c0-6.8-5.5-12.3-12.3-12.3
s-12.3,5.5-12.3,12.3v40.2c0,20.7-16.9,37.6-37.6,37.6H62.1c-20.7,0-37.6-16.9-37.6-37.6v-248.2c0-20.7,16.9-37.6,37.6-37.6h200.6
c20.7,0,37.6,16.9,37.6,37.6v40.2c0,6.8,5.5,12.3,12.3,12.3s12.3-5.5,12.3-12.3v-40.2c0-34.2-27.9-62.1-62.1-62.1H62.1
C27.9,58.95,0,86.75,0,121.05z" fill="blue" fill-opacity="0.2"/>
<path transform="scale(0.035)" d="M385.4,337.65c2.4,2.4,5.5,3.6,8.7,3.6s6.3-1.2,8.7-3.6l83.9-83.9c4.8-4.8,4.8-12.5,0-17.3l-83.9-83.9
c-4.8-4.8-12.5-4.8-17.3,0s-4.8,12.5,0,17.3l63,63H218.6c-6.8,0-12.3,5.5-12.3,12.3c0,6.8,5.5,12.3,12.3,12.3h229.8l-63,63
C380.6,325.15,380.6,332.95,385.4,337.65z"fill="blue" fill-opacity="0.2"/>
</svg>
</a>
</div>
<div class="wallet-settings__field key-field">
<p class="key-field__title">Private key <span>(secret)</span></p>
<label for="idShowPrivKey" class="key-field__btn btn-no-bg wallet-settings__hiding">
<input type="checkbox" class="hidden" id="idShowPrivKey" oninput="SetVisiblePrivKey()">
<span class="show-text">Show</span>
</label>
<p style="width: 100%;" class="key-field__key-place" id="idPrivKeyStatic">
••••••••••••••••••••••••••••••••••••••••••••••••••••
</p>
</div>
<div class="wallet-settings__info">
<div class="wallet-settings__field key-field">
<p class="key-field__title">Public key <span></span></p>
<p style="width: 100%;" class="key-field__key-place" id="idPubKeyStatic"></p>
</div>
</div>
<div class="wallet-wrapper" style="padding-top: 10px;">
<button class="btn btn--full-width wallet-settings__generate" id="idKeyEdit" onclick="SelectTab('TabWalletSet')">Edit</button>
<div class="wallet-settings__btns-wrapper">
<label for="load-key2" class="btn btn--white" onchange="UploadKey('load-key2')" id="idLoad2">
<input class="hidden" id="load-key2" type="file">
Load key
</label>
<button class="btn btn--white" onclick="downloadKey('idPrivKeyEdit')" id="idSave2">Save key</button>
</div>
</div>
<!--<button class="btn wallet-settings__go-btn" onclick="SelectTab('TabAccounts')">Go to accounts</button>-->
</section>
<section id="TabAccounts" class="accounts-info" style="display: none;">
<div class="accounts-info__empty hidden" >
<p class="accounts-info__counter title"><span class="accounts-info__number">0</span> accounts</p>
<p class="title text-center">You have no accounts yet</p>
<p class="text-center">Create your first account and start <br>using TERA</p>
<button class="btn btn--full-width btn--270 accounts-info__btn" onclick="OnViewAddAccount()">+ CREATE A NEW ACCOUNT</button>
</div>
<div class="accounts-info__add hidden">
<div class="wallet-settings__title-wrap">
<a class="back-link" onclick="CancelAddAccount()"><span>Back</span></a>
<h2 class="accounts-info__title title">Create an account</h2>
</div>
<div class="key-field">
<label for="idAccountName" class="key-field__title">Public name</label>
<input type="text"
id="idAccountName"
class="key-field__input"
placeholder="Input public text name of your account"
oninput="OnChangeAccName()">
</div>
<div class="key-field">
<label for="idAccountCur" class="key-field__title">Currency</label>
<select size="1" id="idAccountCur" class="bigs key-field__input key-field__input--select">
<option value="0">TERA</option>
</select>
</div>
<button onclick="OnAddAccount()"
class="btn btn--full-width accounts-info__add-btn btn--270 btn--center"
id="idBtAddAccount">
Create account
</button>
</div>
<div class="accounts-info__add2 hidden" >
<p class="title text-center">Wait 10-15 sec</p>
<p class="text-center">Creating your account</p>
</div>
<div class="accounts-info__acc-list hidden">
<div class="accounts-info__counter-wrapper">
<a href="https://terafoundation.org/tera-coin.html" target="_blank" class="accounts-info__to-send-link">Buy/sell/mine TERA</a>
<p class="title" style="font-size: 16px;"><span class="accounts-info__number" id="idListCount">4</span> ACCOUNTS</p>
<a class="btn" onclick="OnViewAddAccount()">+ CREATE NEW</a>
</div>
<ul class="accounts-info__accounts prod-list" id="idAccountsList">
<li class="prod-list__item prod-card prod-card--line prod-card--switch find--switch" id="AccCardTemplate">
<div class="prod-card__first-line">
<span class="hidden id-sign">ID:&nbsp;</span>
<a target='_blank' class="prod-card__id prod-card__id--mobile">Item.Num</a>
<a href="./history.html#Item.Num" target='_blank' class="prod-card__id prod-card__id--mobile-active">Item.Num</a>
<a href="./history.html#Item.Num" target='_blank' class="prod-card__id prod-card__id--desktop">Item.Num</a>
<div class="prod-card__heading">
<span class="prod-card__coins-count">Value.SumCOIN<sup>,Value.SumCENT</sup><br>
<span class="light-grey-text small-text mob-hidden">Value.CurrencyName</span>
</span>
<span class="prod-card__currency prod-card__currency--with-dot">
<img src="Value.CurrencyIconPath" width="18" height="18" alt="">
</span>
</div>
<span class="prod-card__descr light-grey-text">Item.Name</span>
</div>
<div class="prod-card__footer">
<div class="prod-card__footer-wrap" >
<a onclick="OpenDapps(SmartObj.Num,Item.Num)" class="prod-card__link prod-card__link--dapp">
<img src="SmartObj.IconPath" alt="." width="32" height="32">
<span class="prod-card__dapp-name mob-hidden">SmartObj.Name</span>
</a>
<a class="prod-card__link prod-card__link--connect" onclick="ConnectSmart(Item.Num)">
<svg class="prod-card__dapp-icon" width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="15" cy="15" r="14.5" fill="white" fill-opacity="0.01" stroke="#F2F2F2"/>
<path d="M15.5 10H14.5V14.5H10V15.5H14.5V20H15.5V15.5H20V14.5H15.5V10Z" fill="#445368"/>
</svg>
<span class="prod-card__dapp-text mob-hidden">Connect DApp...</span>
</a>
<button type="button" class="prod-card__drop-btn btn-no-bg mob-hidden" onclick="showMenu(Item.Num)" onblur="closeMenu(Item.Num)">
<svg width="4" height="16" viewBox="0 0 4 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.5 2C3.5 2.82843 2.82843 3.5 2 3.5C1.17157 3.5 0.5 2.82843 0.5 2C0.5 1.17157 1.17157 0.5 2 0.5C2.82843 0.5 3.5 1.17157 3.5 2ZM3.5 8C3.5 8.82843 2.82843 9.5 2 9.5C1.17157 9.5 0.5 8.82843 0.5 8C0.5 7.17157 1.17157 6.5 2 6.5C2.82843 6.5 3.5 7.17157 3.5 8ZM2 15.5C2.82843 15.5 3.5 14.8284 3.5 14C3.5 13.1716 2.82843 12.5 2 12.5C1.17157 12.5 0.5 13.1716 0.5 14C0.5 14.8284 1.17157 15.5 2 15.5Z" fill="#445368"/>
</svg>
</button>
<div class="prod-card__dropdown" style="display: none;" id="idBtItem.Num">
<a class="editdapp" onclick="SetSmart(Item.Num,SmartObj.Num)">Change dApp</a>
<a class="editdapp" onclick="DelSmart(Item.Num,-1)">Disconnect dApp</a>
<a onclick="DelAccount(Item.Num)">Hide account</a>
<a onclick="RestoreAllAccounts()">Show All accounts</a>
</div>
</div>
<a href="" class="prod-card__footer-empty" style="display: none;" onclick="ConnectSmart(Item.Num,SmartObj.Num)"><span class="mob-hidden">Connect dapp...</span></a>
</div>
</li>
</ul>
<div class="accounts-info__total">
<h3>Total</h3>
<dl class="total-info" id="idTotalList">
</dl>
</div>
</div>
</section>
<section id="TabSend" class="send-page" style="display: none;">
<div class="send-page__setting">
<h2 class="title">Sending tokens</h2>
<div class="send-page__field key-field">
<p class="key-field__title">From:</p>
<button onclick="SetAllSum()" title="Paste total amount" class="key-field__btn btn-no-bg no-mr" style="padding: 0; margin-left: 10px;">
<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 1H3C1.89543 1 1 1.89543 1 3V15C1 16.1046 1.89543 17 3 17H15C16.1046 17 17 16.1046 17 15V3C17 1.89543 16.1046 1 15 1ZM3 0C1.34315 0 0 1.34315 0 3V15C0 16.6569 1.34315 18 3 18H15C16.6569 18 18 16.6569 18 15V3C18 1.34315 16.6569 0 15 0H3ZM6.64645 10.6464C6.84171 10.4512 7.15829 10.4512 7.35355 10.6464L9.5 12.7929V6C9.5 5.17157 8.82843 4.5 8 4.5H6C5.72386 4.5 5.5 4.27614 5.5 4C5.5 3.72386 5.72386 3.5 6 3.5H8C9.38071 3.5 10.5 4.61929 10.5 6V12.7929L12.6464 10.6464C12.8417 10.4512 13.1583 10.4512 13.3536 10.6464C13.5488 10.8417 13.5488 11.1583 13.3536 11.3536L10.3536 14.3536L10 14.7071L9.64645 14.3536L6.64645 11.3536C6.45118 11.1583 6.45118 10.8417 6.64645 10.6464Z"/>
</svg>
</button>
<select size="1" id="idAccount" class="key-field__select" oninput="OnEditTransactionFields(); CheckSending();">
</select>
</div>
<div class="send-page__field key-field">
<label for="idTo" class="key-field__title key-field__title--pay">Pay to:</label>
<span id="idNameTo2" style="margin: 0 10px 0 15px"></span>
<!--<button class="key-field__btn btn-no-bg">Paste</button>-->
<!--<a onclick="openModal('addresses-modal')" class="key-field__btn btn-no-bg key-field__btn&#45;&#45;with-icon no-mr">-->
<!--Address book-->
<!--<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">-->
<!--<path fill-rule="evenodd" clip-rule="evenodd" d="M4.5585 1H16C16.5523 1 17 1.44771 17 2V16C17 16.5523 16.5523 17 16 17H4.5585C4.00622 17 3.5585 16.5523 3.5585 16V15.5H5.14688V15.7922C5.14688 16.0683 5.37074 16.2922 5.64688 16.2922C5.92303 16.2922 6.14688 16.0683 6.14688 15.7922V14.2078C6.14688 13.9317 5.92303 13.7078 5.64688 13.7078C5.37074 13.7078 5.14688 13.9317 5.14688 14.2078V14.5H3.5585V11.5H5.14688V11.7978C5.14688 12.074 5.37074 12.2978 5.64688 12.2978C5.92303 12.2978 6.14688 12.074 6.14688 11.7978V10.2134C6.14688 9.93728 5.92303 9.71342 5.64688 9.71342C5.37074 9.71342 5.14688 9.93728 5.14688 10.2134V10.5H3.5585V7.5H5.14688V7.80348C5.14688 8.07962 5.37074 8.30348 5.64688 8.30348C5.92303 8.30348 6.14688 8.07962 6.14688 7.80348V6.21907C6.14688 5.94293 5.92303 5.71907 5.64688 5.71907C5.37074 5.71907 5.14688 5.94293 5.14688 6.21907V6.5H3.5585V3.5H5.14688V3.80911C5.14688 4.08525 5.37074 4.30911 5.64688 4.30911C5.92303 4.30911 6.14688 4.08525 6.14688 3.80911V2.2247C6.14688 1.94856 5.92303 1.7247 5.64688 1.7247C5.37074 1.7247 5.14688 1.94856 5.14688 2.2247V2.5H3.5585V2C3.5585 1.44772 4.00622 1 4.5585 1ZM2.5585 16V15.5H1.5C0.671575 15.5 0 14.8284 0 14V12C0 11.1716 0.671573 10.5 1.5 10.5H2.5585V7.5H1.5C0.671575 7.5 0 6.82843 0 6V4C0 3.17157 0.671573 2.5 1.5 2.5H2.5585V2C2.5585 0.89543 3.45393 0 4.5585 0H16C17.1046 0 18 0.895431 18 2V16C18 17.1046 17.1046 18 16 18H4.5585C3.45393 18 2.5585 17.1046 2.5585 16ZM2.5585 11.5V14.5H1.5C1.22386 14.5 1 14.2761 1 14V12C1 11.7239 1.22386 11.5 1.5 11.5H2.5585ZM2.5585 3.5H1.5C1.22386 3.5 1 3.72386 1 4V6C1 6.27614 1.22386 6.5 1.5 6.5H2.5585V3.5ZM7.70564 3.5H14.9117V2.5H7.70564V3.5ZM7.70564 5.5H14.9117V4.5H7.70564V5.5ZM7.70564 7.5H14.9117V6.5H7.70564V7.5Z"/>-->
<!--</svg>-->
<!--</a>-->
<input type="text"
id="idTo"
value=""
class="key-field__input key-field__input--enter"
oninput="OnEditIdTo()"
placeholder="Enter ID..." >
</div>
<div class="send-page__field key-field">
<label for="idSumSend" class="key-field__title">Amount:</label>
<!--<b>2 000 000 000,00000000</b>-->
<input type="number" id="idSumSend" class="key-field__input" style="color:#1e21cb" value="" step=0 min=0 max=1000000000 oninput="OnEditTransactionFields()" placeholder="Input amount...">
</div>
<div class="send-page__field key-field">
<label for="idDescription" class="key-field__title">Description:</label>
<textarea name="description" id="idDescription" rows="2" placeholder="Optional..." class="key-field__textarea key-field__textarea--mobile" oninput="CheckLengthAccDesription('idDescription',200); OnEditTransactionFields()">
</textarea>
</div>
<div class="send-page__send-btn-wrp">
<button class="btn btn--full-width btn--450 send-page__send-btn" onclick="SendMobileBefore()" id="idSendButton">Send</button>
</div>
</div>
<div class="send-page__confirm hidden">
<a href="#back" class="wallet-settings__title title">Confirm Transaction</a>
<dl class="confirm-info">
<div class="confirm-info__line">
<dt class="confirm-info__title">From ID:</dt>
<dd class="confirm-info__descr">
<span id="idConfirmFromID">192333</span>
<p class="light-grey-text" id="idConfirmFromName">
Minecraft is life (2,000,000.000000 TERA)
</p>
</dd>
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Pay to ID:</dt>
<dd class="confirm-info__descr confirm-info__descr--sm">
<span id="idConfirmToID">177555</span>
<p class="light-grey-text" id="idConfirmToName">
Desitest2 (0.000 TERA)
</p>
</dd>
<!--<a href="#address-book" class="key-field__btn btn-no-bg key-field__btn&#45;&#45;with-icon">-->
<!--Save-->
<!--<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">-->
<!--<path fill-rule="evenodd" clip-rule="evenodd" d="M4.5585 1H16C16.5523 1 17 1.44771 17 2V16C17 16.5523 16.5523 17 16 17H4.5585C4.00622 17 3.5585 16.5523 3.5585 16V15.5H5.14688V15.7922C5.14688 16.0683 5.37074 16.2922 5.64688 16.2922C5.92303 16.2922 6.14688 16.0683 6.14688 15.7922V14.2078C6.14688 13.9317 5.92303 13.7078 5.64688 13.7078C5.37074 13.7078 5.14688 13.9317 5.14688 14.2078V14.5H3.5585V11.5H5.14688V11.7978C5.14688 12.074 5.37074 12.2978 5.64688 12.2978C5.92303 12.2978 6.14688 12.074 6.14688 11.7978V10.2134C6.14688 9.93728 5.92303 9.71342 5.64688 9.71342C5.37074 9.71342 5.14688 9.93728 5.14688 10.2134V10.5H3.5585V7.5H5.14688V7.80348C5.14688 8.07962 5.37074 8.30348 5.64688 8.30348C5.92303 8.30348 6.14688 8.07962 6.14688 7.80348V6.21907C6.14688 5.94293 5.92303 5.71907 5.64688 5.71907C5.37074 5.71907 5.14688 5.94293 5.14688 6.21907V6.5H3.5585V3.5H5.14688V3.80911C5.14688 4.08525 5.37074 4.30911 5.64688 4.30911C5.92303 4.30911 6.14688 4.08525 6.14688 3.80911V2.2247C6.14688 1.94856 5.92303 1.7247 5.64688 1.7247C5.37074 1.7247 5.14688 1.94856 5.14688 2.2247V2.5H3.5585V2C3.5585 1.44772 4.00622 1 4.5585 1ZM2.5585 16V15.5H1.5C0.671575 15.5 0 14.8284 0 14V12C0 11.1716 0.671573 10.5 1.5 10.5H2.5585V7.5H1.5C0.671575 7.5 0 6.82843 0 6V4C0 3.17157 0.671573 2.5 1.5 2.5H2.5585V2C2.5585 0.89543 3.45393 0 4.5585 0H16C17.1046 0 18 0.895431 18 2V16C18 17.1046 17.1046 18 16 18H4.5585C3.45393 18 2.5585 17.1046 2.5585 16ZM2.5585 11.5V14.5H1.5C1.22386 14.5 1 14.2761 1 14V12C1 11.7239 1.22386 11.5 1.5 11.5H2.5585ZM2.5585 3.5H1.5C1.22386 3.5 1 3.72386 1 4V6C1 6.27614 1.22386 6.5 1.5 6.5H2.5585V3.5ZM7.70564 3.5H14.9117V2.5H7.70564V3.5ZM7.70564 5.5H14.9117V4.5H7.70564V5.5ZM7.70564 7.5H14.9117V6.5H7.70564V7.5Z"/>-->
<!--</svg>-->
<!--</a>-->
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Amount:</dt>
<dd class="confirm-info__descr">
<span id="idConfirmAmount" style="color: #ff791a">100000</span>
<span id="idConfirmCurrency">TERA</span>
</dd>
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Description:</dt>
<dd class="confirm-info__descr light-grey-text" id="idConfirmDescription">
Test Description
</dd>
</div>
</dl>
<div class="send-page__btns-wrap">
<button class="btn" onclick="OKSend()" id="idBtOnSend">CONFIRM</button>
<button class="btn btn--white" onclick="CancelSend()" id="editKeyBtn">Cancel</button>
</div>
</div>
</section>
<section id="TabDapps" class="dapps-page" style="display: none;">
<h2 class="title">Decentralized applications (dApps)</h2>
<div align="center">
<a class="btn nomobile" style="width: 200px;" onclick="window.Open('./dapp-edit.html','smart',1240)">CREATE DAPPS</a>
</div>
<div class="dapps-page__field key-field">
<select class="key-field__select" id="idCategory" onchange="$('idViewDappNum').value=0; ViewCurrent(DefDapps)">
<option value="0">Choose the category</option>
</select>
</div>
<div id="idPaginationDapps" class="">
<div class="dapps-page__pagination page-pagination">
<button onclick="ViewBegin(DefDapps)" class="btn dapps-page__page-btns">| &lt;</button>
<button onclick="ViewPrev(DefDapps)" class="btn dapps-page__page-btns">&lt;</button>
<input type="number" id="idViewDappNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewCurrent(DefDapps)">
<button onclick="ViewNext(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt;</button>
<button onclick="ViewEnd(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt; |</button>
</div>
<div class="explorer-page__table-wrap">
<table id="dapps_list" class="grid dapps__table">
<tr>
<th id="(RetDappCard(Item))" class="dapp_card">DApps</th>
</tr>
</table>
</div>
<ul id="DappRowCardTemplate" class="grid prod-list">
<li class="prod-card dapps-page__card">
<div class="prod-card__first-line">
<span class="prod-card__id light-grey-text">ID: Item.Num</span>
<span class="prod-card__id light-grey-text">OWNER: Item.Owner</span>
<a onclick="OpenDappCard(Item.Num)" class="prod-card__link prod-card__link--info">
More info
</a>
</div>
<div class="prod-card__second-line">
<div class="prod-card__second-line-left">
<div class="prod-card__heading">
<a href="#" class="prod-card__link" onclick="OpenDapp(Item.Num)">Item.Name</a>
<!--<span class="lighter-grey-text">Without token generate</span>-->
<!--<span class="dapp-modal__ok-token">Token generate</span>-->
</div>
<p>Item.Description</p>
<!-- <ol>-->
<!--<li>Gaming & VR</li>-->
<!--<li>Gaming & VR</li>-->
<!--<li>Gaming & VR</li>-->
<!--</ol> -->
</div>
<div class="prod-card__second-line-img">
<a href="#" class="prod-card__link" onclick="OpenDapp(Item.Num)"><img src="Item.IconPath" width="32"></a>
</div>
</div>
</li>
</ul>
</div>
</section>
<section id="TabExplorer" class="explorer-page" style="display: none;">
<div id="idCurrentBlockNum" class="currentBlockNum">
<p><span>Blockchain height:</span> <b>26003136</b></p>
<p><span>Current create:</span> <b>26003140</b></p>
<p><span>Protocol ver:</span> <b>0.1057</b></p>
</div>
<button onclick="ViewCurrent(DefAccounts,1,this);" class="btview explorer-page__explore btn btn--white btn--full-width">Accounts</button>
<div class="explorer-page__table">
<div id="idPaginationAccount" style="display: none">
<div class="page-pagination">
<button onclick="ViewBegin(DefAccounts)" class="btnav btn">|&lt;</button>
<button onclick="ViewPrev(DefAccounts)" class="btnav btn">&lt;</button>
<input type="number" class="pag_num" id="idViewAccountNum" style="text-align: center" value="0" min=0 onchange="ViewCurrent(DefAccounts)">
<button onclick="ViewNext(DefAccounts,CONFIG_DATA.MaxAccID)" class="btnav btn">&gt;</button>
<button onclick="ViewEnd(DefAccounts,CONFIG_DATA.MaxAccID)" class="btnav btn">&gt;|</button>
</div>
<div class="explorer-page__table-wrap">
<table id="explorer_accounts" class="grid">
<tr>
<th id="(RetHistoryAccount(Item))" class="num">ID</th>
<th id="SUM_TO_STRING(Item.Value)" class="sum">Amount</th>
<th id="CurrencyNameItem(Item)" class="cur">Cur</th>
<th id="Item.Name" class="accname">Name</th>
<th id="Item.PubKeyStr" class="hash pubkey">PubKey</th>
<th id="Item.Value.OperationID" class="num">Operation</th>
<th id="Item.Value.Smart" class="num">Smart</th>
<th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="num">Block Num</th>
</tr>
</table>
</div>
</div>
</div>
<button onclick="ViewCurrent(DefBlock,1,this)" class="btview explorer-page__explore btn btn--white btn--full-width">Blocks & Tr</button>
<div class="explorer-page__table">
<div id="idPaginationBlock" style="display: none">
<div class="page-pagination">
<button onclick="ViewBegin(DefBlock)" class="btnav btn">|&lt;</button>
<button onclick="ViewPrev(DefBlock)" class="btnav btn">&lt;</button>
<input type="number" class="pag_num" id="idViewBlockNum" style="text-align: center" value="0" min=0 onchange="ViewCurrent(DefBlock)">
<button onclick="ViewNext(DefBlock,CONFIG_DATA.MaxNumBlockDB)" class="btnav btn">&gt;</button>
<button onclick="ViewEnd(DefBlock,CONFIG_DATA.MaxNumBlockDB)" class="btnav btn">&gt;|</button>
</div>
<div class="explorer-page__table-wrap">
<table id="explorer_blocks" class="grid">
<tr>
<th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))" class="num">Num</th>
<th id="(DateFromBlock(Item.BlockNum,1))" class="date">Date</th>
<th id="GetHexFromArr(Item.TreeHash)" class="hash">Data Hash</th>
<th id="GetHexFromArr(Item.PowHash)" class="hash">PowHash</th>
<th id="GetHexFromArr(Item.Hash)" class="hash">Block Hash</th>
<th id="Item.TrDataLen" class="num">Bytes</th>
<th id="Item.Power" class="num">Pow</th>
<th id="Item.Miner" class="num">Miner</th>
</tr>
</table>
</div>
</div>
</div>
<button onclick="ViewCounters(this)" class="btview explorer-page__explore btn btn--white btn--full-width">Counters</button>
<div class="explorer-page__diagramms">
<div id="idStatBlock" style="display: none">
<div id="diagr_content">
<div id="diargams">
</div>
</div>
</div>
</div>
</section>
</main>
<section class="dapp-modal modal" id="DappCardTemplate" style="display: none;">
<div class="modal__header">
<div class="modal__title-wrap">
<span class="light-grey-text">ID: Item.Num</span>
<h3>Item.Name</h3>
<ol class="modal__ol">
<li class="modal__category dappcategory1">Item.Category1</li>
<li class="modal__category dappcategory2">Item.Category2</li>
<li class="modal__category dappcategory3">Item.Category3</li>
</ol>
<p class="dapp-modal__token-status dapp-modal__token-status--ok">
<!--<span class="light-grey-text">Without token generate</span>-->
<span class="dapp-modal__ok-token">Token generate</span>
</p>
</div>
<div class="modal__img-wrap">
<img src="Item.IconPath" alt="dApp logo" width="32">
</div>
</div>
<p>
Item.Description
</p>
<dl class="modal__def-list def-list">
<div class="def-list__item">
<dt>Account</dt>
<dd>Item.Account</dd>
</div>
<div class="def-list__item">
<dt>Owner</dt>
<dd>Item.Owner</dd>
</div>
<div class="def-list__item">
<dt>Block num</dt>
<dd>Item.BlockNum</dd>
</div>
</dl>
<div class="modal__btns-wrap">
<button class="btn" onclick="OpenDapp(Item.Num)">Go to dapp</button>
<button class="btn btn--white" onclick="closeModal()">Back</button>
</div>
<button class="modal__close btn btn--white" title="Close modal" onclick="closeModal()"></button>
</section>
<!--TODO: адресная книга-->
<section class="addresses-modal modal" id="addresses-modal" style="display: none;">
<h2 class="title">Address book</h2>
<input type="search" class="addresses-modal__input" placeholder="Global search by ID or name">
<ul class="addresses-modal__list">
<li class="addresses-modal__item">
<div class="addresses-modal__text-wrap">
<div class="addresses-modal__item-name">
<span class="grey-blue-text">Minecraft is life</span>
<div class="light-grey-text">2 000,000000 TERA</div>
</div>
<span class="addresses-modal__id">192834</span>
</div>
<button class="addresses-modal__delete-item"></button>
<div class="addresses-modal__btns-wrapper">
<button class="btn btn--white">Cancel</button>
<button class="btn">Delete</button>
</div>
</li>
<li class="addresses-modal__item">
<div class="addresses-modal__text-wrap">
<div class="addresses-modal__item-name">
<span class="grey-blue-text">Minecraft is life</span>
<div class="light-grey-text">2 000,000000 TERA</div>
</div>
<span class="addresses-modal__id">192834</span>
</div>
<button class="addresses-modal__delete-item"></button>
<div class="addresses-modal__btns-wrapper" style="display: none;">
<button class="btn btn--white">Cancel</button>
<button class="btn">Delete</button>
</div>
</li>
</ul>
<button class="modal__close btn btn--white" title="Close modal" onclick="closeModal()"></button>
<div class="addresses-modal__choosing">
<button class="btn btn--white">Save to book</button>
<button class="btn">Choose</button>
</div>
</section>
<div id="overlay" onclick="closeModal()"></div>
<section class="modal password-modal password-modal--set" id="password-modal-set">
<h2 class="password-modal__title">Secure your wallet</h2>
<p class="password-modal__subtitle">Set a password for protect entry</p>
<form class="password-modal__form" onsubmit="">
<input type="password" class="password-modal__input" placeholder="Enter password" autocomplete="WalletPassword" id="Password1">
<input type="password" class="password-modal__input" placeholder="Repeat password" autocomplete="WalletPassword" id="Password2">
<div class="password-modal__buttons">
<a class="btn" onclick="SetNewPassword()">Set pass</a>
<a class="btn btn--white" onclick="closeModal()">Cancel</a>
</div>
</form>
</section>
<section class="modal password-modal" id="password-modal-enter">
<h2 class="password-modal__title">Wallet is secured</h2>
<p class="password-modal__subtitle">Enter password to unlock wallet</p>
<form class="password-modal__form" onsubmit="MyOpenWallet(1)">
<input type="password" class="password-modal__input" placeholder="Enter password" autocomplete="WalletPassword" id="Password">
<div class="password-modal__buttons password-modal__buttons--one">
<a class="btn" onclick="MyOpenWallet(1)">Unlock</a>
</div>
<a class="password-modal__link pointer" id="idEntrance" onclick="MyOpenWallet(0)">Entrance to sub-wallet</a>
</form>
</section>
<footer>
</footer>
<div class="fixed-status">
<div class="fixed-status__wrap">
<div id="idStatus" class="fixed-status__status">&nbsp;</div>
<select class="grey-btn" id="idCurNetwork" onchange="ChangeNetwork()">
<option value="TERA-MAIN">TERA MAIN</option>
<option value="TERA-TEST2">TERA TEST2</option>
</select>
<button class="grey-btn reconnect" onclick="ConnectWebWallet()" title="Reconnect"><span>RECONNECT</span></button>
<!--рудименты-->
<span id="idNetwork" style="display: none"></span>
<span id="idSignJSON"></span>
</div>
</div>
<DIV align='center'>
<DIV align='left' style="display: none;">
<INPUT id="idCurTabName" value="TabInfo" style="display: none">
</DIV>
</DIV>
</body>
</html>
<script type="text/javascript" src="./JS/sign-lib-min.js"></script>
<script>
$("idAccountsList").addEventListener("click", MyToggleList);
function MyToggleList(e)
{
var item=e.target;
while(true)
{
if(!item)
break;
if(!item.classList)
break;
if(item.onclick && item.onclick!==MyToggleList)
break;
if(item.classList.contains("find--switch"))
{
if(item.classList.contains("prod-card--switch"))
{
item.classList.add("prod-card--active");
item.classList.add("prod-card--toggle");
item.classList.remove("prod-card--switch");
}
else
{
item.classList.remove("prod-card--active");
item.classList.remove("prod-card--toggle");
item.classList.add("prod-card--switch");
}
break;
}
item=item.parentNode;
}
}
</script>

832
src/HTML/monitor.html Normal file
View File

@ -0,0 +1,832 @@
<!doctype html>
<html>
<head>
<title>Monitor</title>
<meta charset='utf-8' />
<link rel="shortcut icon" href="/HTML/PIC/monitor.png" type="image/png">
<link rel="stylesheet" type="text/css" href="../HTML/CSS/style.css">
</head>
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="/HTML/JS/coinlib.js"></script>
<script type="text/javascript" src="../HTML/JS/client.js"></script>
<script type="text/javascript" src="../HTML/JS/diagram.js"></script>
<script>
var bPause;
var sessionid;
var StatMode;
function SetNewSession(cursessionid)
{
sessionid=cursessionid;
}
//DIALOG
//DIALOG
//DIALOG
function SetPause(SetMode)
{
if(SetMode===undefined)
{
bPause=!bPause;
}
else
{
bPause=SetMode;
}
var item = document.getElementById("idRun");
if(bPause)
item.value="Continue view";
else
item.value="Pause view";
}
function SetStatMode()
{
if(!StatMode)
StatMode=0;
StatMode=(StatMode+1)%2;
GetData("SetStatMode",StatMode,function (Data)
{
});
}
function ClearStat()
{
GetData("ClearStat",{},function (Data)
{
});
}
function SetStatInfo(Data)
{
var item = document.getElementById("idStatInfo");
var button = document.getElementById("idStatButton");
StatMode=Data.STAT_MODE;
if(StatMode)
{
item.innerText=" =Stat ON=";
button.value="Stop stat"
}
else
{
item.innerText=" =Stat OFF=";
button.value="Start stat"
}
}
//CHARTS
//CHARTS
//CHARTS
var DiagramArr=[];
var DiagramArrR=
[
{isLine:true,text:"SYSTEM"},
{name:"TIME_IDLE",text:"HEALTH TIME, %",value:0,red:"#24aa47"},
{name:"MAX:CPU_SYS_MODE",text:"CPU USER SYS, мс",value:0,red:"#06A"},
{name:"MAX:CPU",text:"CPU ALL WORK, ms",value:0,red:"#06A"},
// {name:"MAX:CPU_USER_MODE",text:"USER MODE, мс",value:0,red:"#06A"},
// {name:"MAX:CPU_IDLE_MODE",text:"USER IDLE, мс",value:0,red:"#0A6"},
{name:"MAX:MEMORY_USAGE",text:"Mem usage, Mbyte",value:300},
{name:"MAX:MEMORY_FREE",text:"Mem free, Mbyte",value:0,red:"#a1c3b9"},
//{name:"MAX:POWER-HASH**",text:"Hash Rate, Mh/s",value:0,red:"#95d6b9"},
{name:"HASHRATE",text:"Hash Rate, Mh/s",value:0,red:"#95d6b9"},
{name:"MAX:POWER",text:"MAX:POWER",value:0,red:"#95d6b9"},
{name:"POWER_MY_WIN",text:"POWER MY WIN",value:0,red:"#088a4a"},
{name:"POWER_BLOCKCHAIN",text:"POWER Blockchain",value:0,red:"#2b6311"},
{isLine:true,text:"NETWORK"},
{name:"GETDATA(KB)",text:"Packets receive, Kbyte",value:0,red:"#3b8a7f"},
{name:"SENDDATA(KB)",text:"Packets send, Kbyte",value:0,red:"#2b1e8a"},
{name:"WRITECHAIN_TO_DB_COUNT",text:"Loaded blocks, count",value:0},
{name:"MAX:TRANSACTION_COUNT",text:"Count transactions in block",value:0,red:"#2d628a"},
{isLine:true,text:"HEALTH"},
{name:"ERRORS",text:"ERRORS",value:0,red:"#A00"},
{name:"MAX:LOADEDCHAINLIST",text:"Loaded chains, count",value:0,red:"#95d6b9"},
{isLine:true,text:"NODES"},
{name:"MAX:BUSY_LEVEL",text:"BUSY_LEVEL",value:0,red:"#ff353b"},
{name:"STOP_METHOD",text:"STOP_METHOD",value:0,red:"#8a3d74"},
{name:"AddToBan",text:"AddToBan",value:0,red:"#8a3d74"},
{name:"TRANSFER_TIME_OUT",text:"TRANSFER TIME OUT, count",value:0,red:"#ff353b"},
{name:"NETCONFIGURATION",text:"NETCONFIGURATION",value:0,red:"#8a5663"},
{name:"MAX:ALL_NODES",text:"All nodes count",value:0,red:"#83a3d6"},
{name:"MAX:CONNECTED_NODES",text:"Connected nodes count",value:0,red:"#516e80"},
{name:"MAX:HASH_OK",text:"Block chain Hash = OK",value:0,red:"#2b6311"},
{name:"MAX:HOT_NODES",text:"TRANSFER nodes, count",value:0,red:"#063c8a"},
{name:"MAX:MEDIAN_GLOB_TIME",text:"MEDIAN_GLOB_TIME",value:0,red:"#5e729b",zero:100},
{name:"MAX:DISP_MEDIAN_GLOB_TIME",text:"DISP_MEDIAN_GLOB_TIME 90%",value:0,red:"#4a809b"},
// {name:"MAX:HOT_OK",text:"TRANSFER Accounts Hash - OK",value:0,red:"#2b6311"},
// {name:"MAX:HOT_COUNT_LEVELS",text:"TRANSFER Avg Levels count",value:0,red:"#39638a"},
// {name:"MAX:DELTA_TIME_ACTUAL",text:"Avg delta time (to all)",value:0,red:"#51448a"},
// {name:"MAX:DELTA_TIME_HOT",text:"Avg delta time (TRANSFER)",value:0,red:"#313f8a"},
];
var DiagramArrD=
[
{isLine:true,text:"Блоки"},
// {name:"ROWS_WRITE-TX",text:"ROWS_WRITE-TX",value:0,red:"#06A"},
// {name:"ROWS_WRITE_MS-TX",text:"ROWS_WRITE_MS-TX",value:0,red:"#ffb417"},
{name:"MAX:DELTA_TX",text:"MAX:DELTA_TX",value:0,red:"#ff4534"},
// {name:"COUNT_BLOCK_TX-TX",text:"COUNT_BLOCK_TX-TX",value:0,red:"#69c2ff"},
// {name:"ONWRITEBLOCKFINISH_MS-TX",text:"ONWRITEBLOCKFINISH_MS-TX",value:0,red:"#7081ff"},
// {name:"BLOCKPROCESS_1-TX",text:"BLOCKPROCESS_1-TX, ms",value:0,red:"#cd72ff"},
// {name:"BLOCKPROCESS_2-TX",text:"BLOCKPROCESS_2-TX, ms",value:0,red:"#cd72ff"},
// {name:"BLOCKPROCESS_3-TX",text:"BLOCKPROCESS_3-TX, ms",value:0,red:"#cd72ff"},
// {name:"BLOCKPROCESS_4-TX",text:"BLOCKPROCESS_4-TX, ms",value:0,red:"#cd72ff"},
{name:"MAX:TRANSACTION_COUNT",text:"Число транзакций в блоке (макс)",value:0,red:"#02A"},
{name:"MAX:LOADEDCHAINLIST",text:"Load chains, count",value:0,red:"#95d6b9"},
{name:"TRANSFER_TIME_OUT",text:"TRANSFER TIME OUT, count",value:0,red:"#ff353b"},
{isLine:true,text:"SYSTEM"},
{name:"TIME_IDLE",text:"HEALTH TIME, %",value:0,red:"#24aa47"},
{name:"MAX:CPU_SYS_MODE",text:"CPU USER SYS, мс",value:0,red:"#06A"},
{name:"MAX:CPU",text:"CPU WORK, мс",value:0,red:"#06A"},
{name:"MAX:MEMORY_USAGE",text:"Используемая память, Mb",value:300},
{name:"MAX:MEMORY_FREE",text:"Mem free, Mbyte",value:0,red:"#a1c3b9"},
// {name:"MAX:CPU_USER_MODE",text:"USER MODE, мс",value:0,red:"#06A"},
// {name:"MAX:CPU_SYS_MODE",text:"USER SYS, мс",value:0,red:"#06A"},
// {name:"MAX:CPU_IDLE_MODE",text:"USER IDLE, мс",value:0,red:"#0A6"},
//{name:"MAX:POWER-HASH**",text:"Hash Rate, Mh/s",value:0,red:"#95d6b9"},
{name:"HASHRATE",text:"Hash Rate,Mh/s",value:0,red:"#95d6b9"},
// {name:"MINING-COUNT",text:"MINING-COUNT",value:0,red:"#95d6b9"},
{name:"MAX:POWER",text:"MAX:POWER",value:0,red:"#597e6e"},
//{name:"POWER_MY_WIN",text:"POWER MY WIN",value:0,red:"#088a4a"},
{name:"POWER_BLOCKCHAIN",text:"POWER Blockchain",value:0,red:"#2b6311"},
// {name:"TIME_USE_PACKET",text:"Время выполнения пакета, мс",value:100},
{name:"MAX:MEDIAN_GLOB_TIME",text:"MEDIAN_GLOB_TIME",value:0,red:"#5e729b",zero:100},
{name:"MAX:DISP_MEDIAN_GLOB_TIME",text:"DISP_MEDIAN_GLOB_TIME 90%",value:0,red:"#4a809b"},
// {name:"MAX:DELTA_GLOB_TIME",text:"DELTA_GLOB_TIME",value:0,red:"#8b7a9b",zero:100},
// {name:"MAX:DISP_DELTA_GLOB_TIME",text:"DISP_DELTA_GLOB_TIME",value:0,red:"#9b747f"},
// {name:"CORRECT_TIME_UP",text:"CORRECT_TIME_UP",value:0,red:"#449b7e"},
// {name:"CORRECT_TIME_DOWN",text:"CORRECT_TIME_DOWN",value:0,red:"#9b8a3a"},
// {name:"MAX:TIME_DELTA",text:"TIME_DELTA",value:0,red:"#4d989b",line:1},
// {name:"MAX:BUSY_LEVEL",text:"BUSY_LEVEL",value:0,red:"#ff353b"},
// {name:"STOP_METHOD",text:"STOP_METHOD",value:0,red:"#8a3c40"},
{name:"AddToBan",text:"AddToBan",value:0,red:"#8a3d74"},
// {name:"TRANSFER_TIME_OUT",text:"TRANSFER TIME OUT, count",value:0,red:"#ff353b"},
{name:"NETCONFIGURATION",text:"NETCONFIGURATION",value:0,red:"#8a5663"},
// {name:"SEND:ADDLEVELCONNECT",text:"SEND:ADDLEVELCONNECT",value:0,red:"#8a5663"},
// {name:"GET:ADDLEVELCONNECT",text:"GET:ADDLEVELCONNECT",value:0,red:"#8a5663"},
//// {name:"NETCONFIGURATION",text:"NETCONFIGURATION",value:0,red:"#8a5663"},
//// {name:"NETCONFIGURATION",text:"NETCONFIGURATION",value:0,red:"#8a5663"},
//
// {name:"AddLevelConnect",text:"AddLevelConnect",value:0,red:"#755d8a"},
// {name:"DisconnectChild",text:"DisconnectChild",value:0,red:"#755d8a"},
// {name:"DeleteLevelConnect",text:"DeleteLevelConnect",value:0,red:"#755d8a"},
//// {name:"PONG-NotHot",text:"PONG-NotHot",value:0,red:"#755d8a"},
//
//// {name:"DISCONNECTHOT",text:"DISCONNECTHOT",value:0,red:"#755d8a"},
// {name:"StartCheckConnect",text:"StartCheckConnect",value:0,red:"#755d8a"},
//
// {name:"ClientConnected",text:"ClientConnected",value:0,red:"#755d8a"},
// {name:"ClientEnd",text:"ClientEnd",value:0,red:"#755d8a"},
// {name:"ClientClose",text:"ClientClose",value:0,red:"#755d8a"},
//
{isLine:true,text:"Ноды"},
{name:"MAX:CLUSTER_NODE",text:"=RUNNING=",value:0,red:"#83a3d6"},
{name:"MAX:CLUSTER_NODE_HASH",text:"=RUNNING OK HASH=",value:0,red:"#658a61"},
// {name:"MAX:CLUSTER_NODE_ACC_HASH",text:"=RUNNING ACCOUNT HASH=",value:0,red:"#658a61"},
//{name:"MAX:COUNT_EQ_ADDR",text:"COUNT_EQ_ADDR",value:0,red:"#8a5663"},
{name:"MAX:ALL_NODES",text:"All nodes count",value:0,red:"#83a3d6"},
{name:"MAX:CONNECTED_NODES",text:"Connected nodes count",value:0,red:"#516e80"},
// {name:"MAX:AUTOCORRECT",text:"MAX:AUTOCORRECT",value:0,red:"#06A"},
{name:"MAX:MIN_VERSION",text:"MAX:MIN_VERSION",value:0,red:"#99eeff"},
{name:"MAX:HASH_OK",text:"Block chain Hash = OK",value:0,red:"#2b6311"},
{name:"MAX:CHECK_POINT_OK",text:"Check point = OK",value:0,red:"#356361"},
{name:"MAX:ACTUAL_OK",text:"Accounts Hash - OK",value:0,red:"#658a61"},
{name:"MAX:COUNTLH",text:"Nodes in Load History mode",value:0,red:"#83a3d6"},
{name:"MAX:HOT_NODES",text:"TRANSFER nodes, count",value:0,red:"#063c8a"},
//{name:"MAX:HOT_OK",text:"TRANSFER Accounts Hash - OK",value:0,red:"#2b6311"},
//{name:"MAX:HOT_COUNT_LEVELS",text:"TRANSFER Avg Levels count",value:0,red:"#39638a"},
//{name:"MAX:DELTA_TIME_ACTUAL",text:"Avg delta time (to all)",value:0,red:"#51448a"},
//{name:"MAX:DELTA_TIME_HOT",text:"Avg delta time (TRANSFER)",value:0,red:"#313f8a"},
//{name:"GET:TRANSFER",text:"GET:TRANSFER",value:0,red:"#3b5d8a"},
{isLine:true,text:"NETWORK"},
{name:"GETDATA(KB)",text:"Packets receive, Kbyte",value:0,red:"#3b8a7f"},
{name:"SENDDATA(KB)",text:"Packets send, Kbyte",value:0,red:"#2b1e8a"},
{isLine:true,text:"Пакеты полученные"},
//{name:"TEST_PACKET",text:"TEST_PACKET",value:0,red:"#2b1e8a"},
//{name:"GETDATA(KB)",text:"Получено, кбайт",value:0,red:"#2b1e8a"},
// {name:"LOADFRAGMENT",text:"Получено фрагментов",value:0,red:"#20728a"},
// {name:"LOADPACKET",text:"Получено пакетов",value:0,red:"#7f448a"},
{name:"USEPACKET",text:"Исполнено пакетов",value:0,red:"#7f448a"},
//{name:"MAX:BUFFE_LOAD_SIZE",text:"Буфер загрузки, кб",value:0,red:"#7f448a"},
// {name:"SKIPFRAGMENTUSE",text:"SKIPFRAGMENTUSE",value:0},
// {name:"TIME_USE_PACKET",text:"Время выполнения пакетов, мс",value:100},
{name:"MAX:TIMEDOGETDATA",text:"MAX:Время получения пакета, мс",value:100},
{name:"MAX:TIME_USE_PACKET",text:"MAX:Время выполнения пакета, мс",value:100},
//{name:"TRANSFER",text:"Обработка пакета TRANSFER, мс",value:90},
//{name:"MAX:TimeDoGetData",text:"Макс время обработки полученного пакета, мс",value:25},
{name:"ERRORS",text:"ERRORS",value:0,red:"#A00"},
// {name:"SEND_ERROR",text:"Ожидание статуса сокета",value:0,red:"#500"},
// {isLine:true,text:"Пакеты отправленные"},
// {name:"SENDDATA(KB)",text:"Отправлено, кбайт",value:0,red:"#2b1e8a"},
// {name:"SEND_TRAFFIC_FREE",text:"SEND_TRAFFIC_FREE",value:0,red:"#2b1e8a"},
// {name:"SEND_DATA_HARD",text:"Отправлено Hard, кбайт",value:0,red:"#2b1e8a"},
// {name:"SEND_DATA_LIGHT",text:"Отправлено Light, кбайт",value:0,red:"#2b1e8a"},
//{name:"RECALCSENDSTATICTIC",text:"RECALCSENDSTATICTIC",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30000",text:"NODE_TRAFFIC_LIMIT:30000, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30001",text:"NODE_TRAFFIC_LIMIT:30001, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_BUF_WRITE:30000",text:"MAX:NODE_BUF_WRITE:30000, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_SEND_BUF_PACKET_COUNT:30000",text:"MAX:NODE_SEND_BUF_PACKET_COUNT:30000",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30000",text:"LIMIT:30000, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30001",text:"LIMIT:30001, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30006",text:"LIMIT:30006, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_TRAFFIC_LIMIT:30007",text:"LIMIT:30007, кбайт",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_SEND_BUF_PACKET_COUNT:30006",text:"MAX:NODE_SEND_BUF_PACKET_COUNT:30006",value:0,red:"#2b1e8a"},
// {name:"MAX:NODE_BUF_WRITE:30006",text:"MAX:NODE_BUF_WRITE:30006, кбайт",value:0,red:"#2b1e8a"},
// {name:"SENDFRAGMENT_H",text:"Отправлено H-фрагментов, кбайт",value:0,red:"#20728a"},
// {name:"SENDFRAGMENT_L",text:"Отправлено L-фрагментов, кбайт",value:0,red:"#20728a"},
// {name:"FRAGMENT_LOST",text:"Потерянные фрагменты",value:0},
// {name:"FRAGMENT_OVERFLOW",text:"Переполнение массива отправленных фрагментов",value:0},
// {name:"SKIPFRAGMENTSEND",text:"SKIPFRAGMENTSEND",value:0},
//
// {isLine:true,text:"Headers"},
// {name:"SEND:GETBLOCKHEADER:30001",text:"SEND:GETBLOCKHEADER:30001",value:0,red:"#2b1e8a"},
// {name:"GET:RETBLOCKHEADER:30001",text:"GET:RETBLOCKHEADER:30001",value:0,red:"#658a61"},
// {name:"SEND:GETBLOCKHEADER:30002",text:"SEND:GETBLOCKHEADER:30002",value:0,red:"#2b1e8a"},
// {name:"GET:RETBLOCKHEADER:30002",text:"GET:RETBLOCKHEADER:30002",value:0,red:"#658a61"},
//
//
// {isLine:true,text:"Blocks"},
// {name:"SEND:GETBLOCK:30001",text:"SEND:GETBLOCK:30001",value:0,red:"#2b1e8a"},
// {name:"GET:RETGETBLOCK:30001",text:"GET:RETGETBLOCK:30001",value:0,red:"#658a61"},
// {name:"SEND:GETBLOCK:30002",text:"SEND:GETBLOCK:30002",value:0,red:"#2b1e8a"},
// {name:"GET:RETGETBLOCK:30002",text:"GET:RETGETBLOCK:30002",value:0,red:"#658a61"},
// {name:"SEND:GETBLOCK:30003",text:"SEND:GETBLOCK:30003",value:0,red:"#2b1e8a"},
// {name:"GET:RETGETBLOCK:30003",text:"GET:RETGETBLOCK:30003",value:0,red:"#658a61"},
// {name:"MAX:HIGHT",text:"MAX:HIGHT",value:0,red:"#83a3d6"},
// {name:"NODE_CAN_GET:30000",text:"NODE_CAN_GET: 30000",value:0,red:"#2b1e8a"},
// {name:"NODE_CAN_GET:30001",text:"NODE_CAN_GET: 30001",value:0,red:"#2b1e8a"},
// {name:"NODE_CAN_GET:30006",text:"NODE_CAN_GET: 30006",value:0,red:"#2b1e8a"},
//{name:"BLOCK_SEND",text:"Отдано блоков (план)",value:0,red:"#bea96d"},
// {name:"SEND:RETGETBLOCK",text:"Отдано блоков (факт)",value:0,red:"#bea96d"},
//{name:"DELETE_OLD_PACKET",text:"Удалено устаревших пакетов",value:0,red:"#bea96d"},
// {name:"BLOCK_SEND_MEM",text:"Отдано блоков из памяти",value:0,red:"#e6e349"},
// {name:"DO_GETNEXTNODE-1",text:"DO_GETNEXTNODE-1",value:0,red:"#bea96d"},
// {name:"DO_GETNEXTNODE-2",text:"DO_GETNEXTNODE-2",value:0,red:"#bea96d"},
// {name:"SEND:GETBLOCK",text:"Запрошено блоков",value:0,red:"#bea96d"},
//
// {name:"BLOCK_LOADED",text:"Получено блоков",value:0,red:"#95d6b9"},
// {name:"DOUBLE_RETGETBLOCK",text:"Получено блоков повторно",value:0,red:"#e6e349"},
// {name:"WRITECHAIN_TO_DB_COUNT",text:"Загруженные цепочки блоков",value:0},
// {name:"WRITECHAIN_TO_DB_TIME",text:"Время записи цепочек, ms",value:0},
//
//
//// {name:"WRITECHAIN_TO_DB_TIME",text:"Время обработки цепочки блоков, мс",value:90},
// {name:"WriteBlockDB",text:"Время записи блоков на диск, мс",value:50},
// {name:"MAX:WriteBlockDB",text:"Макс время записи блока на диск, мс",value:50},
// {name:"BlockToMemBuf",text:"Время BlockToMemBuf, мс",value:25},
// {name:"IsValidTransaction",text:"Время IsValidTransaction, мс",value:25},
// {name:"MAX:TimeDoGetData:RETBLOCKHEADER",text:"MAX:TimeDoGetData:RETBLOCKHEADER, мс",value:25},
// {name:"MAX:TimeDoGetData:RETGETBLOCK",text:"MAX:TimeDoGetData:RETGETBLOCK, мс",value:25},
// {name:"MAX:TimeDoGetData:TRANSFER",text:"MAX:TimeDoGetData:TRANSFER, мс",value:25},
//{name:"MAX:TimeDoGetData:GETBLOCK",text:"MAX:TimeDoGetData:GETBLOCK, мс",value:25},
// {isLine:true,text:"Ключи (индексы)"},
// {name:"MAX:CountForFlush",text:"Незаписанные на диск ключи, шт",value:1000},
// {name:"MAX:TimeFlush",text:"Макс время записи ключа на диск, мс",value:11},
// {name:"MAX:DOUBLE_FIND_KEY",text:"Коллизии хеш функции",value:32},
// {name:"SCAN_ROW_KEY",text:"Перебор строк ключей",value:30000},
// {name:"SCAN_BODY",text:"Чтение строк содержимого хешей",value:10},
// {name:"TimeKeyMove",text:"Время переноса ключей на следующий уровень, мс",value:50},
// {name:"MAX:TimeKeyMove",text:"Макс время переноса ключей на следующий уровень, мс",value:10},
// {isLine:true,text:"Операции над ключами"},
// {name:"OPERATION_KEY_DB_FIND",text:"FIND",value:0,red:"#06A"},
// {name:"OPERATION_KEY_DB_MOVEKEY",text:"MOVEKEY",value:0,red:"#06A"},
// {name:"OPERATION_KEY_DB_WRITE",text:"WRITE",value:0,red:"#06A"},
// {name:"OPERATION_KEY_DB_DELETE",text:"DELETE",value:0,red:"#06A"},
];
var IsDevelopAccount=0;
function InitDiagram()
{
var ArrSystem;
if(IsDevelopAccount)
{
ArrSystem=DiagramArrD;
}
else
{
ArrSystem=DiagramArrR;
}
var StrArr=localStorage["DiagramArr"];
if(StrArr && StrArr!=="undefined")
{
DiagramArr=JSON.parse(StrArr);
}
else
{
DiagramArr=[].concat(JSON.parse(JSON.stringify(ArrSystem)));
}
DiagramArr.push(ExternDiagramItem);
DiagramMap[ExternDiagramItem.name]=ExternDiagramItem;
DiagramMapId[ExternDiagramItem.id]=ExternDiagramItem;
InitDiagramByArr(DiagramArr,1100);
localStorage["ExternSetDiagramArr"]="";
}
function DeleteDiagram(id)
{
var Item=DiagramMapId[id];
if(Item)
{
var element2=document.getElementById("B"+id);
element2.innerHTML="";
Item.Delete=1;
localStorage["DiagramArr"]=JSON.stringify(DiagramArr);
}
}
function AddDiagram()
{
var Name=document.getElementById("idNameDiagram").value.trim();
var Item={name:Name,text:Name,value:0,red:"#5681b6"};
if(Name.substr(0,1)==="-")
{
Item.text=Name.substr(1);
Item.isLine=1;
}
AddDiagramToArr(DiagramArr,Item);
SetHTMLDiagramItem(Item,1100);
localStorage["DiagramArr"]=JSON.stringify(DiagramArr);
}
function ResetDiagrams()
{
var diargams = document.getElementById("diargams");
diargams.innerHTML="";
localStorage["DiagramArr"]="";
InitDiagram();
}
function ClearDiagrams()
{
var diargams = document.getElementById("diargams");
diargams.innerHTML="";
localStorage["DiagramArr"]="[]";
InitDiagram();
}
function GetDiagram()
{
var arrNames=[];
for(var i=0;i<DiagramArr.length;i++)
{
var Str;
var Item=DiagramArr[i];
if(!Item.isLine)
{
arrNames.push(Item.name);
}
}
GetData("GetArrStats",arrNames,function (Data)
{
if(!Data || !Data.result)
return;
SetStatInfo(Data);
var arr=Data.arr;
for(var i=0;i<arr.length;i++)
{
var ItemServer=arr[i];
var ItemClient=DiagramMap[ItemServer.name];
if(!ItemClient || ItemClient.Extern)
continue;
ItemClient.arr=ItemServer.arr;
ItemClient.AvgValue=ItemServer.AvgValue;
ItemClient.steptime=ItemServer.steptime;
//ItemClient.starttime=ItemServer.starttime;
DrawDiagram(ItemClient);
}
});
}
function ResizeArr222(arr)
{
var arr2=[];
for(var i=0;i<arr.length/2;i++)
{
arr2[i]=Math.max(arr[i*2],arr[i*2+1]);
}
return arr2;
}
//INIT
function UpdateData()
{
if(bPause)
return;
GetDiagram();
}
function LoadValues()
{
if(!localStorage["WasSaveMonitor3"])
return;
document.getElementById("idBlockNum").value=localStorage["MonitoridBlockNum"];
document.getElementById("idBlockCount").value=localStorage["MonitoridBlockCount"];
document.getElementById("idMiner").value=localStorage["MonitoridMiner"];
document.getElementById("idAdviser").value=localStorage["MonitoridAdviser"];
}
function SaveValues()
{
localStorage["WasSaveMonitor3"]=1;
localStorage["MonitoridBlockNum"]=document.getElementById("idBlockNum").value;
localStorage["MonitoridBlockCount"]=document.getElementById("idBlockCount").value;
localStorage["MonitoridMiner"]=document.getElementById("idMiner").value;
localStorage["MonitoridAdviser"]=document.getElementById("idAdviser").value;
}
window.onload=function()
{
SetPause(0);
GetData("GetWalletInfo",{}, function (Data)
{
if(Data && Data.result)
{
IsDevelopAccount=Data.IsDevelopAccount;
InitDiagram();
}
});
setInterval(function ()
{
if(localStorage["ExternSetDiagramArr"])
{
InitDiagram();
}
},300);
setInterval(UpdateData,900);
//COMMON MOUSE MOVING
window.onmousemove = function(event)
{
SetDiagramMouseX(event);
}
window.onkeydown = function (e)
{
if(e.keyCode===27)
{
window.close();
}
else
if(e.keyCode===13)
{
GetBlockchainStat();
}
};
LoadValues();
//document.body.className="univers "+localStorage["idSelStyle"];
}
var ExternDiagramItem={name:"Blockchain Hash Rate MH/s",text:"-----",value:0,red:"#078a63",Extern:1,id:"idBlockchainStat"}
function GetBlockchainPrev()
{
var BlockNum=ParseNum(document.getElementById("idBlockNum").value);
var Count=ParseNum(document.getElementById("idBlockCount").value);
BlockNum-=Count;
if(BlockNum<0)
BlockNum=0;
document.getElementById("idBlockNum").value=BlockNum;
GetBlockchainStat();
}
function GetBlockchainEnd()
{
GetData("GetWalletInfo",{}, function (Data)
{
if(Data && Data.result)
{
document.getElementById("idBlockNum").value=Data.BlockNumDB;
GetBlockchainPrev();
}
});
}
function GetBlockchainNext()
{
var BlockNum=ParseNum(document.getElementById("idBlockNum").value);
var Count=ParseNum(document.getElementById("idBlockCount").value);
BlockNum+=Count;
document.getElementById("idBlockNum").value=BlockNum;
GetBlockchainStat();
}
function GetBlockchainStat()
{
SaveValues();
var BlockNum=ParseNum(document.getElementById("idBlockNum").value);
var Count=ParseNum(document.getElementById("idBlockCount").value);
var Miner=ParseNum(document.getElementById("idMiner").value);
var Adviser=ParseNum(document.getElementById("idAdviser").value);
var bNonce=document.getElementById("idNonce").checked;
var bMinerLess=document.getElementById("idMinerLess").checked;
if(document.getElementById("idMiner").value==="")
Miner=-1;
GetData("GetBlockchainStat",{BlockNum:BlockNum,Count:Count,Miner:Miner,bMinerLess:bMinerLess,Adviser:Adviser,bNonce:bNonce}, function (Data)
{
if(Data && Data.result)
{
var BlockNum=ParseNum(document.getElementById("idBlockNum").value);
var ItemClient=ExternDiagramItem;
ItemClient.ArrList=Data.ArrList;
ItemClient.AvgValue=Data.AvgValue;
ItemClient.steptime=Data.steptime;
ItemClient.startnumber=BlockNum;
var bNonce=document.getElementById("idNonce").checked;
if(bNonce)
{
var arr=ItemClient.ArrList;
for(var i=0;i<arr.length;i++)
{
arr[i]=arr[i]/10000000;
}
}
DrawDiagram(ItemClient);
}
});
}
</script>
<style type="text/css">
#idBtEnd
{
font-family: monospace;
}
.delete
{
margin: 2px;
border: 0px;
background: #FFF;
color: #cffffa;
}
.delete:hover
{
margin: 2px;
border: 1px solid #000;
color:#000;
}
</style>
<style type="text/css">
#topframe
{
z-index:1000;
position:fixed;
top:0px;
left:0px;
text-align: center;
width:600px;
}
#idRun, #idStatButton
{
width:100px;
}
</style>
<body>
<DIV align='center'>
<DIV id="topframe">
<INPUT type="button" style="float:left" onclick="SetPause()" id="idRun">
<INPUT type="button" style="float:left" onclick="ClearStat()" id="idClearStat" value="Clear stat">
<INPUT type="button" style="float:left" onclick="SetStatMode()" id="idStatButton">
<DIV align='left'><B id="idStatInfo"></B></DIV>
</DIV>
<BR>
<BR>
<BR>
<DIV style="text-align: center;">Blockchain Power</DIV>
Adviser:<INPUT type="search" id="idAdviser" style="width:50px" >
Miner:
&lt;=<INPUT type="checkbox" id="idMinerLess" style="margin:1px" >
<INPUT type="search" id="idMiner" style="width:50px" value="">
Nonce:<INPUT type="checkbox" id="idNonce" style="margin:1px" >
Block start:<INPUT type="number" id="idBlockNum" style="width:80px" value="0"> length:<INPUT type="number" id="idBlockCount" style="width:80px" value="3600">
<INPUT type="button" onclick="GetBlockchainPrev()" value="Prev">
<INPUT type="button" onclick="GetBlockchainNext()" value="Next">
<INPUT type="button" onclick="GetBlockchainEnd()" id="idBtEnd" value="-&gt;|">
<INPUT type="button" onclick="GetBlockchainStat()" value="Update">
<!--<DIV style="text-align: center;">Blockchain Hashrate, MH/s</DIV>-->
<BR>
<canvas class="DIAGRAM" width='1100' height='200' id='idBlockchainStat'></canvas>
<DIV id="diagr_content" align='center'>
<DIV id="diargams" align='center'>
</DIV>
</DIV>
<BR>
<BR>
New diagram<INPUT type="string" id="idNameDiagram" style="width:250px" value="">
<INPUT type="button" onclick="AddDiagram()" value="Add">
<INPUT type="button" onclick="ResetDiagrams()" value="Reset">
<INPUT type="button" onclick="ClearDiagrams()" value="Clear">
<BR>
<BR>
<BR>
</DIV>
</body>
</html>

530
src/HTML/network.html Normal file
View File

@ -0,0 +1,530 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Network</title>
<link rel="shortcut icon" href="/HTML/PIC/network.png" type="image/png">
<link rel="stylesheet" type="text/css" href="../HTML/CSS/buttons.css">
<!--<link rel="stylesheet" type="text/css" href="../HTML/CSS/style.css">-->
</head>
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="/HTML/JS/coinlib.js"></script>
<script type="text/javascript" src="../HTML/JS/client.js"></script>
<script>
var MaxChildCount=7;//MAX_CONNECT_CHILD
var SaveIdArr=["idMaxNodesCount"];
var NodesArr=[];
var CurNode;
function SetStatus(Str)
{
var id = $("idStatus");
id.innerHTML=Str;
}
var WasSetName;
var WasSetProperty;
var WasSetInfo;
function SetInfo(Name,StrProperty,StrInfo)
{
var id;
if(WasSetName!==Name)
{
WasSetName=Name;
id = $("idNodeName");
id.innerHTML="<B>"+Name+"</B>";
}
if(WasSetProperty!==StrProperty)
{
WasSetProperty=StrProperty;
id = $("idNodeProperty");
id.value=StrProperty;
}
if(WasSetInfo!==StrProperty)
{
WasSetInfo=StrProperty;
id = $("idNodeLog");
id.value=StrInfo;
}
}
function UpdateData()
{
var CountBlock=ParseNum($("idCountBlock").value);
GetData("/GetHotArray",{CountBlock:CountBlock}, function (Data)
{
if(Data && Data.result)
{
SetHotTable(Data.ArrTree);
}
});
}
function SetHotTable(ArrTree)
{
var htmlTable=$("grid_hot");
if(!htmlTable.ItemsMap)
{
htmlTable.RowCounts=0;
htmlTable.ItemsMap=[];
}
var map=htmlTable.ItemsMap;
var MaxNode=ParseNum($("idMaxNodesCount").value);
//Hot
htmlTable.RowCounts=Math.max(htmlTable.RowCounts,ArrTree.length);
for(var Level=0;Level<htmlTable.RowCounts;Level++)
{
var arr=ArrTree[Level];
if(!arr)
arr=[];
var row=map[Level];
if(!row)
{
htmlTable.RowCount++;
row=htmlTable.insertRow(-1);
map[Level]=row;
for(var n=0;n<MaxChildCount+3;n++)
{
row.insertCell(n);
}
row.MaxRows=2;
}
row.cells[0].innerText=1+Level;
var StrConnect="";
var StrActive="";
var CountNodesA=0;
var CountNodesC=0;
var length=Math.max(MaxChildCount,arr.length)
length=Math.min(length,MaxNode);
for(var n=0;n<length;n++)
{
var Node=undefined;
var Str="";
var Name="";
if(n<arr.length)
{
Node=arr[n];
NodesArr[Node.id]=Node;
if(Node.Name)
Name=Node.Name;
else
Name=Node.addrStr.substr(0,6);
Str+=Name;
Str+="="+Node.BlockProcessCount+" ping:"+Node.DeltaTime+" ";
if(Node.Name)
strClass="mnode";
else
strClass="node";
Str='<INPUT type="button" id="N'+Node.id+'" class="'+strClass+'" onclick="ViewInfo('+Node.id+',1)" value="'+Str+'">';
if(Node.Hot)
Str+="<BR>";
if(!Node.Active)
Str+='<INPUT type="button" class="connect" onclick="AddConnect('+Node.id+')" value="Con...">';
else
if(Node.Active)
{
Str+="<DIV style='float: right'>"
if(!Node.Hot)
Str+='<INPUT type="button" class="edit" onclick="AddHot('+Node.id+')" value="Add"><BR>';
if(!Node.Name)
Str+='<INPUT type="button" class="edit" onclick="AddBan('+Node.id+')" value="Ban">';
Str+="</DIV>"
}
if(Node.Hot)
Str+='<INPUT type="button" class="edit" onclick="DeleteNode('+Node.id+')" value="Del">';
Str+="<BR>";
}
if(n<MaxChildCount)
{
var cell=row.cells[n+1];
if(Node && Node.Hot)
{
var id=$("S"+Node.id);
if(!id || cell.NodeID!==Node.id)
{
var Stat="<DIV id='S"+Node.id+"'></DIV>";
cell.innerHTML=Stat+Str;
cell.NodeID=Node.id;
id=$("S"+Node.id);
}
var StrTransfer,StrDelta,StrGetTiming;
if(Node.TransferCount>1000)
{
StrTransfer="<B>"+Node.TransferCount+"</B>";
}
else
{
StrTransfer=Node.TransferCount;
}
StrDelta=Node.DeltaTime;
// if(Node.DeltaTime<100)
// {
// StrDelta="<B style='color:#1727ff'>"+Node.DeltaTime+"</B>";
// }
// else
// {
// StrDelta=Node.DeltaTime;
// }
if(Node.GetTiming>2)
StrGetTiming="<B style='color:red'>"+Node.GetTiming+"</B>";
else
if(Node.GetTiming>1)
StrGetTiming="<B style='color:#df7a59'>"+Node.GetTiming+"</B>";
else
StrGetTiming="<B style='color:#1727ff'>"+Node.GetTiming+"</B>";
var Str=
"Transfer:"+StrTransfer+"<BR>"+
"Process:"+Node.BlockProcessCount+"<BR>"+
"Time:"+StrGetTiming+"<BR>"+
"Delta:"+StrDelta;
id.innerHTML=Str;
}
else
{
cell.innerHTML="";
}
}
if(Node && !Node.Active)
{
CountNodesC++;
StrConnect+=Str;
}
if(Node && !Node.Hot && Node.Active)
{
CountNodesA++;
StrActive+=Str;
}
}
row.MaxRows=Math.max(row.MaxRows,CountNodesA,CountNodesC);
for(var i=CountNodesC;i<row.MaxRows;i++)
{
StrConnect+="<DIV class='node'></DIV>"
}
if(row.StrActive!==StrActive)
{
var cell=row.cells[MaxChildCount+1];
row.StrActive=StrActive;
cell.innerHTML=StrActive;
}
if(row.StrConnect!==StrConnect)
{
var cell=row.cells[MaxChildCount+2];
row.StrConnect=StrConnect;
cell.innerHTML=StrConnect;
}
}
ViewInfo(CurNode);
}
function ViewInfo(Index,bSet)
{
if(Index!==undefined)
{
if(bSet)
CurNode=Index;
var Node=NodesArr[Index];
if(Node)
{
var Name;
if(Node.Name)
Name=Node.Name;
else
Name=Node.addrStr.substr(0,6);
var Info=Node.Info;
Node.Info=undefined;
var Str=JSON.stringify(Node,"",2);
Node.Info=Info;
SetInfo(Name,Str,Info);
//SetInfo(escapeHtml(Name+"\n"+Str+"\n"+Node.Info));
}
else
SetInfo("Not found","","");
}
}
function AddConnect(Index)
{
var Node=NodesArr[Index];
if(Node)
{
var Code='var Node=SERVER.NodesMap["'+Node.addrStr+'"]; Node.NextConnectDelta=1000; Node.CreateConnect();"OK"';
RunCode(Code);
}
}
function AddBan(Index)
{
var Node=NodesArr[Index];
if(Node)
{
var Code='var Node=SERVER.NodesMap["'+Node.addrStr+'"]; SERVER.AddToBan(Node,"=BAN=");"OK"';
RunCode(Code);
}
}
function AddHot(Index)
{
var Node=NodesArr[Index];
if(Node)
{
var Code='var Node=SERVER.NodesMap["'+Node.addrStr+'"]; SERVER.StartAddLevelConnect(Node);"OK"';
RunCode(Code);
}
}
function DeleteNode(Index)
{
var Node=NodesArr[Index];
if(Node)
{
var Code='var Node=SERVER.NodesMap["'+Node.addrStr+'"]; SERVER.StartDisconnectHot(Node,"=DEL=",1);"OK"';
RunCode(Code);
}
}
function RunCode(Code)
{
GetData("SendDirectCode",{Code:Code}, function (Data)
{
if(Data)
{
SetStatus(Data.text);
}
});
}
function CheckCtrlEnter(e,F)
{
// SaveValues();
//
// if(e.ctrlKey && e.keyCode===13)
// {
// SendToServer();
// }
//
// if(e.keyCode===27)
// {
// window.close();
// }
}
function CheckDevelop()
{
GetData("GetWalletInfo",{},function (Data)
{
if(Data && Data.result)
{
if(!Data.IsDevelopAccount)
{
}
}
});
}
window.onload=function()
{
UpdateData();
setInterval(UpdateData,1000);
//setTimeout(CheckDevelop,500);
window.onkeydown = CheckCtrlEnter;
LoadValues();
SetStatus("");
document.body.className="univers "+localStorage["idSelStyle"];
}
function LoadValues()
{
if(LoadValuesByArr(SaveIdArr))
{
if(!$("idMaxNodesCount").value)
$("idMaxNodesCount").value=10;
}
}
function SaveValues()
{
SaveValuesByArr(SaveIdArr);
}
</script>
<style type="text/css">
table
{
border-collapse: collapse;
width:100%;
font-size: small;
}
.hot_nodes th, .hot_nodes td
{
border: 1px solid #264378;
padding: 4px;
}
.hot_nodes td
{
width: 100px;
text-align: left;
padding: 1px;
}
.hot_nodes td:nth-child(1)
{
width: 20px;
text-align: center;
}
.hot_nodes td:nth-child(9)
{
width: 140px;
}
.hot_nodes td:nth-child(10)
{
width: 160px;
}
.mnode
{
width: 100px;
font-weight: 700;
font-size: 9pt;
height: 40px;
white-space: pre-line;
}
.node
{
width: 100px;
font-size: 9pt;
height: 40px;
white-space: pre-line;
}
.edit
{
width: 35px;
font-size: 9pt;
}
.connect
{
width: 60px;
font-size: 9pt;
}
#idNodeBlock
{
position: fixed;
top: 10px;
left: 1200px;
width: 650px;
height: 920px;
font-size: 11pt;
}
#idNodeName
{
height: 20px;
width: 100%;
text-align: center;
}
#idNodeProperty
{
height: 280px;
width: 100%;
}
#idNodeLog
{
height: 600px;
width: 100%;
}
</style>
<body>
<DIV align='center'>
<B>NETWORK</B><BR>
Max nodes on level: <INPUT type="number" id="idMaxNodesCount" style="width:80px" value="10" onchange="SaveValues()" onkeyup="SaveValues()">
<INPUT type="number" id="idCountBlock" style="width:80px" value="4">
<DIV id="idStatus" style="height: 20px;"></DIV><BR>
<DIV align='left' style="width: 1190px;height: 870px; float: left">
<table id="grid_hot" class="hot_nodes">
<tr>
<th>L</th>
<th class="mnode">Node1</th>
<th class="mnode">Node2</th>
<th class="mnode">Node3</th>
<th class="mnode">Node4</th>
<th class="mnode">Node5</th>
<th class="mnode">Node6</th>
<th class="mnode">Node7</th>
<th>Connected</th>
<th>Not connected</th>
</tr>
</table>
</DIV>
<DIV id="idNodeBlock" style="float: left; border: 0px solid #bfc1c0; text-align: left">
<DIV id="idNodeName"></DIV>
<textarea rows="5" cols="250" id="idNodeProperty" style="width: 99%;">
</textarea>
<textarea rows="5" cols="250" id="idNodeLog" style="width: 99%;">
</textarea>
</DIV>
</DIV>
</body>
</html>

339
src/HTML/password.html Normal file
View File

@ -0,0 +1,339 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Password</title>
<script>
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649,
0, 2147516545, 2147483648, 32777, 2147483648, 138, 0, 136, 0, 2147516425, 0,
2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771,
2147483648, 32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648,
2147516545, 2147483648, 32896, 2147483648, 2147483649, 0, 2147516424, 2147483648];
function Mesh(s,Count)
{
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9,
b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17,
b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33,
b34, b35, b36, b37, b38, b39, b40, b41, b42, b43, b44, b45, b46, b47, b48, b49;
for (n = 0; n < Count; n += 2)//48
{
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
s[0] ^= h;
s[1] ^= l;
s[10] ^= h;
s[11] ^= l;
s[20] ^= h;
s[21] ^= l;
s[30] ^= h;
s[31] ^= l;
s[40] ^= h;
s[41] ^= l;
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
s[2] ^= h;
s[3] ^= l;
s[12] ^= h;
s[13] ^= l;
s[22] ^= h;
s[23] ^= l;
s[32] ^= h;
s[33] ^= l;
s[42] ^= h;
s[43] ^= l;
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
s[4] ^= h;
s[5] ^= l;
s[14] ^= h;
s[15] ^= l;
s[24] ^= h;
s[25] ^= l;
s[34] ^= h;
s[35] ^= l;
s[44] ^= h;
s[45] ^= l;
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
s[6] ^= h;
s[7] ^= l;
s[16] ^= h;
s[17] ^= l;
s[26] ^= h;
s[27] ^= l;
s[36] ^= h;
s[37] ^= l;
s[46] ^= h;
s[47] ^= l;
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
s[8] ^= h;
s[9] ^= l;
s[18] ^= h;
s[19] ^= l;
s[28] ^= h;
s[29] ^= l;
s[38] ^= h;
s[39] ^= l;
s[48] ^= h;
s[49] ^= l;
b0 = s[0];
b1 = s[1];
b32 = (s[11] << 4) | (s[10] >>> 28);
b33 = (s[10] << 4) | (s[11] >>> 28);
b14 = (s[20] << 3) | (s[21] >>> 29);
b15 = (s[21] << 3) | (s[20] >>> 29);
b46 = (s[31] << 9) | (s[30] >>> 23);
b47 = (s[30] << 9) | (s[31] >>> 23);
b28 = (s[40] << 18) | (s[41] >>> 14);
b29 = (s[41] << 18) | (s[40] >>> 14);
b20 = (s[2] << 1) | (s[3] >>> 31);
b21 = (s[3] << 1) | (s[2] >>> 31);
b2 = (s[13] << 12) | (s[12] >>> 20);
b3 = (s[12] << 12) | (s[13] >>> 20);
b34 = (s[22] << 10) | (s[23] >>> 22);
b35 = (s[23] << 10) | (s[22] >>> 22);
b16 = (s[33] << 13) | (s[32] >>> 19);
b17 = (s[32] << 13) | (s[33] >>> 19);
b48 = (s[42] << 2) | (s[43] >>> 30);
b49 = (s[43] << 2) | (s[42] >>> 30);
b40 = (s[5] << 30) | (s[4] >>> 2);
b41 = (s[4] << 30) | (s[5] >>> 2);
b22 = (s[14] << 6) | (s[15] >>> 26);
b23 = (s[15] << 6) | (s[14] >>> 26);
b4 = (s[25] << 11) | (s[24] >>> 21);
b5 = (s[24] << 11) | (s[25] >>> 21);
b36 = (s[34] << 15) | (s[35] >>> 17);
b37 = (s[35] << 15) | (s[34] >>> 17);
b18 = (s[45] << 29) | (s[44] >>> 3);
b19 = (s[44] << 29) | (s[45] >>> 3);
b10 = (s[6] << 28) | (s[7] >>> 4);
b11 = (s[7] << 28) | (s[6] >>> 4);
b42 = (s[17] << 23) | (s[16] >>> 9);
b43 = (s[16] << 23) | (s[17] >>> 9);
b24 = (s[26] << 25) | (s[27] >>> 7);
b25 = (s[27] << 25) | (s[26] >>> 7);
b6 = (s[36] << 21) | (s[37] >>> 11);
b7 = (s[37] << 21) | (s[36] >>> 11);
b38 = (s[47] << 24) | (s[46] >>> 8);
b39 = (s[46] << 24) | (s[47] >>> 8);
b30 = (s[8] << 27) | (s[9] >>> 5);
b31 = (s[9] << 27) | (s[8] >>> 5);
b12 = (s[18] << 20) | (s[19] >>> 12);
b13 = (s[19] << 20) | (s[18] >>> 12);
b44 = (s[29] << 7) | (s[28] >>> 25);
b45 = (s[28] << 7) | (s[29] >>> 25);
b26 = (s[38] << 8) | (s[39] >>> 24);
b27 = (s[39] << 8) | (s[38] >>> 24);
b8 = (s[48] << 14) | (s[49] >>> 18);
b9 = (s[49] << 14) | (s[48] >>> 18);
s[0] = b0 ^ (~b2 & b4);
s[1] = b1 ^ (~b3 & b5);
s[10] = b10 ^ (~b12 & b14);
s[11] = b11 ^ (~b13 & b15);
s[20] = b20 ^ (~b22 & b24);
s[21] = b21 ^ (~b23 & b25);
s[30] = b30 ^ (~b32 & b34);
s[31] = b31 ^ (~b33 & b35);
s[40] = b40 ^ (~b42 & b44);
s[41] = b41 ^ (~b43 & b45);
s[2] = b2 ^ (~b4 & b6);
s[3] = b3 ^ (~b5 & b7);
s[12] = b12 ^ (~b14 & b16);
s[13] = b13 ^ (~b15 & b17);
s[22] = b22 ^ (~b24 & b26);
s[23] = b23 ^ (~b25 & b27);
s[32] = b32 ^ (~b34 & b36);
s[33] = b33 ^ (~b35 & b37);
s[42] = b42 ^ (~b44 & b46);
s[43] = b43 ^ (~b45 & b47);
s[4] = b4 ^ (~b6 & b8);
s[5] = b5 ^ (~b7 & b9);
s[14] = b14 ^ (~b16 & b18);
s[15] = b15 ^ (~b17 & b19);
s[24] = b24 ^ (~b26 & b28);
s[25] = b25 ^ (~b27 & b29);
s[34] = b34 ^ (~b36 & b38);
s[35] = b35 ^ (~b37 & b39);
s[44] = b44 ^ (~b46 & b48);
s[45] = b45 ^ (~b47 & b49);
s[6] = b6 ^ (~b8 & b0);
s[7] = b7 ^ (~b9 & b1);
s[16] = b16 ^ (~b18 & b10);
s[17] = b17 ^ (~b19 & b11);
s[26] = b26 ^ (~b28 & b20);
s[27] = b27 ^ (~b29 & b21);
s[36] = b36 ^ (~b38 & b30);
s[37] = b37 ^ (~b39 & b31);
s[46] = b46 ^ (~b48 & b40);
s[47] = b47 ^ (~b49 & b41);
s[8] = b8 ^ (~b0 & b2);
s[9] = b9 ^ (~b1 & b3);
s[18] = b18 ^ (~b10 & b12);
s[19] = b19 ^ (~b11 & b13);
s[28] = b28 ^ (~b20 & b22);
s[29] = b29 ^ (~b21 & b23);
s[38] = b38 ^ (~b30 & b32);
s[39] = b39 ^ (~b31 & b33);
s[48] = b48 ^ (~b40 & b42);
s[49] = b49 ^ (~b41 & b43);
s[0] ^= RC[n];
s[1] ^= RC[n + 1];
}
};
function GetHexFromArr(arr)
{
var Str="";
for(var i=0;arr && i<arr.length;i++)
{
if(!arr[i])
Str+="00";
else
{
var Val=arr[i]&255;
var A=Val.toString(16);
if(A.length===1)
A="0"+A;
Str=Str+A;
}
}
return Str.toUpperCase();
}
function WriteNumToArr0(body,Num)
{
body[0] ^=Num&0xFF;
body[1] ^=(Num>>>8) & 0xFF;
body[2] ^=(Num>>>16) & 0xFF;
body[3] ^=(Num>>>24) & 0xFF;
}
function ClientHex(Str)
{
var arr0=[0,0,0,0];
for(var i=0;i<Str.length;i++)
arr0[4+i]=Str.charCodeAt(i);
for(var nonce=0;nonce<1000000;nonce++)
{
var arr=[];
for(var i=0;i<arr0.length;i++)
arr[i]=arr0[i];
WriteNumToArr0(arr,nonce);
Mesh(arr,60);
if((arr[0]&255)===0 && (arr[1]&255)===0)
return GetHexFromArr(arr)+"-"+nonce;
}
return undefined;
}
function parseCookies (rc)
{
var list = {};
rc && rc.split(';').forEach(function( cookie )
{
var parts = cookie.split('=');
list[parts.shift().trim()] = decodeURI(parts.join('='));
});
return list;
}
function random(max)
{
ret=Math.floor(Math.random()*max);
return ret;
}
window.onload=function()
{
window.onkeydown = function (e)
{
if(e.keyCode===13)
{
SendPassword();
}
};
// document.getElementById("idPassword").focus();
// setTimeout(function ()
// {
// var password = document.getElementById("idPassword").value;
// if(password)
// SendPassword();
// },1000);
//
// SetStatus("Port="+window.location.port);
}
function SendPassword()
{
var port=window.location.port;
if(!port)
port="";
var list=parseCookies(document.cookie);
var id=list["token"+port];
var password = document.getElementById("idPassword").value;
var hash=ClientHex(id+"-"+password);
if(!hash)
{
console.log("Error find Hash")
return;
}
document.cookie = "hash"+port+"="+hash+";path=/";
window.location.reload();
}
</script>
<style type="text/css">
#idBlockPassword
{
z-index:1000;
position:fixed;
top:20%;
left:40%;
height:50px;
width:320px;
padding: 10px;
text-align: center;
box-shadow: 0 0 0 1px;
}
</style>
</head>
<body>
<DIV id="idBlockPassword">
ENTER PASSWORD
<BR>
<INPUT type="password" id="idPassword" autocomplete="password" autofocus > <INPUT type="button" onclick="SendPassword()" value="OK">
<DIV id="idStatus">
</DIV>
</DIV>
</body>
</html>

382
src/HTML/stat.html Normal file
View File

@ -0,0 +1,382 @@
<!doctype html>
<html>
<head>
<title>Counters</title>
<meta charset='utf-8' />
<link rel="shortcut icon" href="/HTML/PIC/counters.png" type="image/png">
<link rel="stylesheet" type="text/css" href="/HTML/CSS/style.css">
</head>
<body>
<script>
window.RUN_CLIENT=1;
window.RUN_SERVER=0;
if(typeof global === 'object')
{
global.RUN_CLIENT=1;
global.RUN_SERVER=0;
}
</script>
<script type="text/javascript" src="/HTML/JS/coinlib.js"></script>
<script type="text/javascript" src="../HTML/JS/client.js"></script>
<script type="text/javascript">
var TabbleStat,TableError;
var PrevData;
function SetResult(Data)
{
if(!Data)
Data=PrevData;
if(!Data || !Data.result)
return;
PrevData=Data;
var arrnames=["10s","10m","total, avg"];
var arrmult=[10,10*60,Data.period*10];
for(var i=0;i<arrmult.length;i++)
{
if(arrmult[i]>Data.period)
arrmult[i]=Data.period;
arrmult[i]=arrmult[i]/10;
}
var arrdata=[Data.stats.Counter10S,Data.stats.Counter10M,Data.stats.Counter];
var arrerr=[Data.errors.Counter10S,Data.errors.Counter10M,Data.errors.Counter];
//drawChart(arrdata,arrnames,arrmult);
SetStat(TabbleStat,arrdata);
SetStat(TableError,arrerr);
}
function ClearTableStat(htmlTable)
{
for(var i=htmlTable.rows.length-1;i>0;i--)
htmlTable.deleteRow(i);
htmlTable.StatItem={};
}
function SetStat(htmlTable,arr)
{
var StrFilter = document.getElementById("idFilter").value;
var rows=htmlTable.rows;
if(!htmlTable.StatItem)
{
htmlTable.StatItem={};
htmlTable.StatItem["Total"]=rows[1];
}
if(0)
for(var i=1;i<rows.length;i++)
rows[i].Do=1;
for(var m=0;m<arr.length;m++)
{
var Data=arr[m];
var Sum=0;
for(var name in Data)
{
if(name.indexOf("MAX:")!==-1)
continue;
var Count=Data[name];
if(Count)
{
Sum+=parseInt(Count);
}
}
Data["Total"]=Sum;
for(var name in Data)
{
var item=htmlTable.StatItem[name];
if(!item)
{
//index=htmlTable.rows.length;
var item=htmlTable.insertRow(1);
htmlTable.StatItem[name]=item;
item.insertCell(0);
for(var n=0;n<arr.length;n++)
{
item.insertCell(n+1);
}
item.cells[0].innerText=name;
item.insertCell(arr.length);
item.cells[arr.length+1].innerHTML='<INPUT type="button" class="add" onclick="AddDiagram(\''+name+'\')" value="Add">';
}
var Count=Math.floor(Data[name]);
item.cells[m+1].innerText=Count;
//item.visibility="visible";
if(StrFilter.length>0 && name.indexOf(StrFilter)==-1)
item.style="display:none";
else
item.style="";
item.Do=0;
}
}
if(0)
for(var i=1;i<rows.length;i++)
if(rows[i].Do===1)
for(var j=1;j<rows[i].cells.length-1;j++)
rows[i].cells[j].innerText="";
}
function AddDiagram(Name)
{
var Str=localStorage["DiagramArr"];
if(!Str|| Str==="undefined")
Str="[]";
var DiagramArr=JSON.parse(Str);
var Item={name:Name,text:Name,value:0,red:"#1c6bb6"};
AddDiagramToArr(DiagramArr,Item);
localStorage["DiagramArr"]=JSON.stringify(DiagramArr)
localStorage["ExternSetDiagramArr"]=1;
}
var bPause;
var StatMode;
function SetPause(SetMode)
{
if(SetMode===undefined)
{
bPause=!bPause;
}
else
{
bPause=SetMode;
}
var item = document.getElementById("idRun");
if(bPause)
item.value="Continue view";
else
item.value="Pause view";
}
function SetStatMode()
{
if(!StatMode)
StatMode=0;
StatMode=(StatMode+1)%3;
GetData("SetStatMode",StatMode,function (Data)
{
});
}
function ClearStat()
{
GetData("ClearStat",{},function (Data)
{
ClearTableStat(TabbleStat);
ClearTableStat(TableError);
});
}
function SetStatInfo(Data)
{
var item = document.getElementById("idStatInfo");
var button = document.getElementById("idStatButton");
StatMode=Data.STAT_MODE;
if(StatMode===1)
{
item.innerText=" =Stat ON=";
button.value="Start detail stat"
}
else
if(StatMode===2)
{
item.innerText=" =Stat detail ON=";
button.value="Stop stat"
}
else
{
item.innerText=" =Stat OFF=";
button.value="Start stat"
}
}
//LIB
function GetStat()
{
if(bPause)
return;
GetData("GetAllCounters",{},function (Data)
{
SetResult(Data);
SetStatInfo(Data);
});
}
function OnSetFilter()
{
SetResult();
}
window.onload=function()
{
TabbleStat=document.getElementById("grid_stat");
TableError=document.getElementById("grid_error");
SetPause(0);
GetStat();
setInterval(GetStat,1000);
window.onkeydown = function (e)
{
if(e.keyCode===27)
{
window.close();
}
};
//document.body.className="univers "+localStorage["idSelStyle"];
}
</script>
<style type="text/css">
table
{
border-collapse: collapse;
}
.stat th, .stat td
{
border: 1px solid #000;
padding: 5px;
}
.stat td
{
width: 122px;
text-align: right;
}
.stat td:nth-child(1)
{
width: 220px;
}
.stat td:nth-child(5)
{
width: 50px;
}
.total
{
text-align: right;
font-weight: 600;
}
#topframeFind
{
z-index:1000;
position:fixed;
top:80px;
left:10px;
text-align: left;
width:1200px;
opacity: .7;
color: blue;
}
#topframe
{
z-index:1000;
position:absolute;
top:0px;
left:0px;
text-align: center;
width:600px;
}
#idRun, #idStatButton
{
width:100px;
}
</style>
<BR>
<div id="confirm_div" style="height: 0px;"></div>
<h2 align='center' >Performance counters</h2>
<DIV id="topframeFind">
Filter: <INPUT type="search" style="width: 292px" id="idFilter" autofocus onkeyup="OnSetFilter()" value="">
</DIV>
<BR>
<table id="grid_stat" class="stat">
<tr>
<th>Counters</th>
<th>10 sec</th>
<th>10 min</th>
<th>total</th>
<th>Diagr</th>
</tr>
<tr class="total">
<td>Total</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<BR>
<table id="grid_error" class="stat">
<tr>
<th>Errors</th>
<th>10 sec</th>
<th>10 min</th>
<th>total</th>
<th>Diagr</th>
</tr>
<tr class="total">
<td>Total</td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
<DIV id="topframe">
<INPUT type="button" style="float:left" onclick="SetPause()" id="idRun">
<INPUT type="button" style="float:left" onclick="ClearStat()" id="idClearStat" value="Clear stat">
<INPUT type="button" style="float:left" onclick="SetStatMode()" id="idStatButton">
<DIV align='left'><B id="idStatInfo"></B></DIV>
</DIV>
</body>
</html>

BIN
src/HTML/tera.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

2063
src/HTML/wallet.html Normal file

File diff suppressed because it is too large Load Diff

669
src/HTML/web-wallet.html Normal file
View File

@ -0,0 +1,669 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TERA WALLET</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="./tera.ico" type="image/vnd.microsoft.icon">
<link rel="stylesheet" type="text/css" href="./CSS/mobile-wallet.css">
<script type="text/javascript" src="./JS/coinlib.js"></script>
<script type="text/javascript" src="./JS/client.js"></script>
<script type="text/javascript" src="./JS/sha3.js"></script>
<script type="text/javascript" src="./JS/crypto-client.js"></script>
<script type="text/javascript" src="./JS/terahashlib.js"></script>
<script type="text/javascript" src="./JS/wallet-web.js"></script>
<script type="text/javascript" src="./JS/wallet-lib.js"></script>
<script type="text/javascript" src="./JS/diagram.js"></script>
<script type="text/javascript" src="./JS/mobile-wallet.js"></script>
</head>
<body>
<header class="header">
<div class="header__wrapper">
<div class="header__logo">
<a onclick="SelectTab('TabWelcome')" class="header__logo-link" id="MTabWelcome">
<img class="main-logo" src="./PIC/TeraLogo.svg" alt="TERA Foundation">
</a>
</div>
<div class="header__right">
<select size="1" id="idLang" onchange="ChangeLang()" class="bigs" >
<option value="ENG">ENG</option>
</select>
<div class="header__wallet-set">
<a class="header__wallet-link tab-link" id="MTabKeySet" onclick="SelectTab('TabKeySet')">
<svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" fill="currentColor">
<path fill-rule="evenodd" clip-rule="evenodd" d="M21.333 21.0024C22.8059 21.0024 24 19.8084 24 18.3354V5.66724C24 4.1943 22.8059 3.00024 21.333 3.00024H19.9995C19.9995 1.89554 19.104 1 17.9993 1H3.99756C2.52462 1 1.33057 2.19405 1.33057 3.66699V11H2.66406V3.66699C2.66406 2.93052 3.26109 2.3335 3.99756 2.3335H17.9993C18.3675 2.3335 18.666 2.63201 18.666 3.00024H5.33105C4.96282 3.00024 4.66431 3.29876 4.66431 3.66699C4.66431 4.03523 4.96282 4.33374 5.33105 4.33374H21.333C22.0695 4.33374 22.6665 4.93077 22.6665 5.66724V8.33423H17.3325C15.4913 8.33423 13.9988 9.8268 13.9988 11.668C13.9988 13.5091 15.4913 15.0017 17.3325 15.0017H22.6665V18.3354C22.6665 19.0719 22.0695 19.6689 21.333 19.6689H13V21.0024H21.333ZM15.3323 11.668C15.3323 10.5633 16.2278 9.66772 17.3325 9.66772H22.6665V13.6682H17.3325C16.2278 13.6682 15.3323 12.7727 15.3323 11.668Z"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.5414 16.4582C12.7257 16.4582 12.9388 16.5955 12.9593 16.7783C13.0144 17.2706 13.0137 17.7677 12.9564 18.2565C12.9338 18.4467 12.7624 18.5903 12.576 18.5751L12.4956 18.573C11.921 18.573 11.3868 18.927 11.1658 19.4542C10.9308 20.0142 11.0776 20.666 11.53 21.0757C11.6719 21.2041 11.6888 21.4208 11.5689 21.5697C11.2597 21.9547 10.9061 22.3045 10.5173 22.6094C10.3676 22.725 10.1552 22.7081 10.0267 22.5684C9.63998 22.1435 8.95181 21.9836 8.41688 22.2021C7.86352 22.4287 7.50573 22.9858 7.52754 23.5882C7.53388 23.7774 7.39423 23.9397 7.20573 23.9605C6.96789 23.9869 6.73001 24 6.49217 24C6.24161 24 5.99173 23.9855 5.74334 23.9566C5.55349 23.9347 5.41307 23.7682 5.42434 23.5769C5.45888 22.9678 5.10596 22.4008 4.54491 22.1661C4.00926 21.9413 3.31335 22.1004 2.92445 22.5306C2.79535 22.6728 2.57865 22.6898 2.42971 22.5698C2.05001 22.2642 1.70343 21.9141 1.4014 21.5294C1.2842 21.3809 1.30186 21.1674 1.44092 21.0396C1.88555 20.6321 2.03162 19.9864 1.80438 19.4323C1.57641 18.8776 1.03296 18.5271 0.466932 18.5416C0.280656 18.5416 0.0611022 18.4055 0.0406898 18.222C-0.0143559 17.7297 -0.0136788 17.2321 0.0434953 16.7438C0.066036 16.5564 0.212841 16.418 0.418948 16.4247C1.0541 16.4247 1.60891 16.0803 1.8333 15.546C2.06834 14.9856 1.92226 14.3339 1.46985 13.9242C1.3287 13.7958 1.31105 13.5794 1.43105 13.4302C1.73874 13.0462 2.09305 12.6962 2.48263 12.3906C2.63152 12.2745 2.84536 12.2917 2.97316 12.4318C3.35983 12.8571 4.0509 13.0152 4.58226 12.7982C5.13634 12.5712 5.49351 12.0141 5.47232 11.4113C5.46599 11.2225 5.60573 11.0602 5.79418 11.0394C6.28118 10.9854 6.77098 10.9871 7.25652 11.0433C7.44715 11.0655 7.58689 11.2317 7.57553 11.4229C7.54099 12.0317 7.8939 12.5987 8.45355 12.8342C8.99133 13.0585 9.68729 12.8991 10.0747 12.47C10.2032 12.3277 10.4206 12.3112 10.5687 12.4301C10.9471 12.7332 11.2936 13.0829 11.5985 13.47C11.7157 13.6186 11.6987 13.8324 11.559 13.9602C11.115 14.3674 10.969 15.0135 11.1955 15.5675C11.4172 16.1084 11.9458 16.4582 12.5414 16.4582ZM6.50013 21.4011C8.6546 21.4011 10.4011 19.6546 10.4011 17.5001C10.4011 15.3457 8.6546 13.5991 6.50013 13.5991C4.34566 13.5991 2.59912 15.3457 2.59912 17.5001C2.59912 19.6546 4.34566 21.4011 6.50013 21.4011Z"/>
</svg>
<span>KEY SETTINGS</span>
</a>
</div>
</div>
<nav class="header__nav nav-tabs">
<ul class="nav-tabs__list">
<li class="nav-tabs__tab active"><a id="MTabAccounts" class="tab-link nav-tabs__link" onclick="SelectTab('TabAccounts')">ACCOUNTS</a></li>
<li class="nav-tabs__tab"><a id="MTabSend" class="tab-link nav-tabs__link" onclick="SelectTab('TabSend')">SEND</a></li>
<li class="nav-tabs__tab"><a id="MTabDapps" class="tab-link nav-tabs__link" onclick="SelectTab('TabDapps')">DAPPS</a></li>
<li class="nav-tabs__tab"><a id="MTabExplorer" class="tab-link nav-tabs__link" onclick="SelectTab('TabExplorer')">EXPLORER</a></li>
</ul>
</nav>
</div>
</header>
<main>
<section id="TabWelcome" class="welcome" >
<div class="welcome__img">
<svg class="" xmlns="http://www.w3.org/2000/svg" fill="#445368" viewBox="0 0 992.13 992.13" width="150" height="150">
<path d="M894.31,812.41a0.18,0.18,0,0,0,0-.08,1.11,1.11,0,0,0-.09-0.23,2.58,2.58,0,0,0-.21-0.41,1.51,1.51,0,0,0-.11-0.25c-0.11-.21-0.22-0.4-0.34-0.59l-388.62-640-0.08-.14L504.4,170a10.15,10.15,0,0,0-16.92-.11,9.33,9.33,0,0,0-.54.86q-39.18,64.66-78.83,129.08a22.21,22.21,0,0,0,0,25.57q52.29,85.36,104.39,170.85a24.15,24.15,0,0,1,0,27.69C455.24,618,394.48,717,336.93,811.63a10.18,10.18,0,0,0,8.94,15H514a10.12,10.12,0,0,0,5.29-1.49,10.25,10.25,0,0,0,3.66-3.87h0l5.79-9.66,77.5-127.91s0,0,0,0a10.18,10.18,0,0,1,17.37-.84l0.21,0.33,0.07,0.11,77.16,126L708.15,821a10.17,10.17,0,0,0,8.95,5.3h4.71a21.71,21.71,0,0,0,2.34,0H884.87A10.16,10.16,0,0,0,895,816.15,9.73,9.73,0,0,0,894.31,812.41Z" />
<path d="M446.68,530.15l5.59-9.23a19.86,19.86,0,0,0,0-22.68L417.74,442.3l-39.5-64a10.2,10.2,0,0,0-17.63.46L98.31,811.68a10.17,10.17,0,0,0,8.95,15H250.82l-0.05,0h4.28l6.23,0h0a10.12,10.12,0,0,0,8.9-5.3,0,0,0,0,0,0,0l5.89-9.77a9.82,9.82,0,0,0,.74-1.15s0,0,0,0l6.4-10.57c55.06-90.94,107.53-177.76,162.52-268.28C446.12,531.11,446.41,530.63,446.68,530.15Z" />
</svg>
</div>
<h1 class="welcome__title title">Welcome to TERA Wallet</h1>
<p><a onclick="SelectTab('TabKeySet')" class="pointer">ATTENTION: Before using the wallet, save the private key.</a></p>
<!--<a class="welcome__link btn" onclick="SelectTab('TabAccounts')">Open wallet</a>-->
<ul id="idStableScroll" align='center' class="social-list">
<li class="social-list__item"><a href="https://terafoundation.org/">Web-site</a></li>
<li class="social-list__item"><a href="https://bitcointalk.org/index.php?topic=4573801.0">Bitcointalk</a></li>
<li class="social-list__item"><a href="https://twitter.com/terafoundation">Twitter</a></li>
<li class="social-list__item"><a href="https://t.me/terafoundation">Telegram</a></li>
<li class="social-list__item"><a href="https://discord.gg/CvwrbeG">Discord</a></li>
<li class="social-list__item"><a href="https://jq.qq.com/?_wv=1027&k=5KpN5fw">QQchat</a></li>
</ul>
</section>
<section id="TabWalletSet" class="wallet-settings" style="display: none;">
<div class="wallet-settings__title-wrap">
<a class="back-link" onclick="SelectTab('TabKeySet')"><span>Back</span></a>
<h2 class="wallet-settings__title title">Edit your wallet</h2>
</div>
<div class="wallet-settings__field key-field">
<p class="key-field__title">Private key (secret)</p>
<!--<button class="key-field__btn btn-no-bg" onclick="pasteKey(event, 'idPrivKeyEdit')">Paste</button>-->
<textarea name="private-key" id="idPrivKeyEdit" placeholder="Insert your private key or generate a new key below..." class="key-field__textarea" oninput="OnEditPrivKey()">
</textarea>
</div>
<div class="wallet-wrapper">
<button class="btn btn--full-width wallet-settings__generate" onclick="OnGenerateKeyNew()">Generate key</button>
</div>
<div class="wallet-settings__ok-btns">
<button class="btn wallet-settings__btn-270" id="okEditBtn" style="margin-bottom: 15px;" onclick="OnPrivKeyOK()">OK</button>
<button class="btn btn--white wallet-settings__btn-270" id="cancelEditBtn" style="margin-bottom: 15px;" onclick="OnPrivKeyCancel()">Cancel</button>
</div>
<!--<button class="btn wallet-settings__go-btn" onclick="SelectTab('TabAccounts')">Go to accounts</button>-->
</section>
<section id="TabKeySet" class="wallet-settings wallet-settings--info" style="display: none;">
<div class="wallet-settings__title-wrap">
<!--<a class="back-link" onclick="SelectTab('TabWelcome')"><span>Back</span></a>-->
<h2 class="wallet-settings__title title">Key settings</h2>
<a class="modal-lock pointer" id="idPasswordEdit" onclick="openModal('password-modal-set');"><svg width="14" height="18" viewBox="0 0 14 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.5 5V10H10.5H12H13C13.5523 10 14 10.4477 14 11V17C14 17.5523 13.5523 18 13 18H1C0.447716 18 0 17.5523 0 17V11C0 10.4477 0.447715 10 1 10H2V5C2 2.23858 4.23858 0 7 0C9.76142 0 12 2.23858 12 5V7H10.5V5C10.5 3.067 8.933 1.5 7 1.5C5.067 1.5 3.5 3.067 3.5 5Z" fill="var(--fill--password)" fill-opacity="0.2"/>
</svg></a>
<a class="modal-lock2 pointer" id="idWalletExit" onclick="DoExitWallet();">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path transform="scale(0.035)" d="M0,121.05v248.2c0,34.2,27.9,62.1,62.1,62.1h200.6c34.2,0,62.1-27.9,62.1-62.1v-40.2c0-6.8-5.5-12.3-12.3-12.3
s-12.3,5.5-12.3,12.3v40.2c0,20.7-16.9,37.6-37.6,37.6H62.1c-20.7,0-37.6-16.9-37.6-37.6v-248.2c0-20.7,16.9-37.6,37.6-37.6h200.6
c20.7,0,37.6,16.9,37.6,37.6v40.2c0,6.8,5.5,12.3,12.3,12.3s12.3-5.5,12.3-12.3v-40.2c0-34.2-27.9-62.1-62.1-62.1H62.1
C27.9,58.95,0,86.75,0,121.05z" fill="blue" fill-opacity="0.2"/>
<path transform="scale(0.035)" d="M385.4,337.65c2.4,2.4,5.5,3.6,8.7,3.6s6.3-1.2,8.7-3.6l83.9-83.9c4.8-4.8,4.8-12.5,0-17.3l-83.9-83.9
c-4.8-4.8-12.5-4.8-17.3,0s-4.8,12.5,0,17.3l63,63H218.6c-6.8,0-12.3,5.5-12.3,12.3c0,6.8,5.5,12.3,12.3,12.3h229.8l-63,63
C380.6,325.15,380.6,332.95,385.4,337.65z"fill="blue" fill-opacity="0.2"/>
</svg>
</a>
</div>
<div class="wallet-settings__field key-field">
<p class="key-field__title">Private key (secret)</p>
<button class="key-field__btn btn-no-bg wallet-settings__hiding" onclick="OnVisiblePrivKey()">Show</button>
<p style="width: 100%;" class="key-field__key-place" id="idPrivKeyStatic">
••••••••••••••••••••••••••••••••••••••••••••••••••••
</p>
</div>
<div class="wallet-settings__info">
<div class="wallet-settings__field key-field">
<p class="key-field__title">Public key</p>
<p style="width: 100%;" class="key-field__key-place" id="idPubKeyStatic"></p>
</div>
</div>
<div class="wallet-wrapper" style="padding-top: 10px;">
<button class="btn btn--full-width wallet-settings__generate" id="idKeyEdit" onclick="SelectTab('TabWalletSet')">Edit</button>
<div class="wallet-settings__btns-wrapper">
<button class="btn btn--white" onclick="downloadKey('idPrivKeyEdit')" id="idSave2">Save key</button>
<label for="load-key2" class="btn btn--white" onchange="UploadKey('load-key2')" id="idLoad2">
<input class="hidden" id="load-key2" type="file">
<span>Load key</span>
</label>
</div>
</div>
<!--<button class="btn wallet-settings__go-btn" onclick="SelectTab('TabAccounts')">Go to accounts</button>-->
</section>
<section id="TabAccounts" class="accounts-info" style="display: none;">
<div class="accounts-info__empty hidden" >
<p class="accounts-info__counter title"><span class="accounts-info__number">0 Accounts</span></p>
<p class="title text-center">You have no accounts yet</p>
<p class="text-center">Create your first account and start using TERA</p>
<button class="btn btn--full-width btn--270 accounts-info__btn" onclick="OnViewAddAccount()">+ CREATE A NEW ACCOUNT</button>
</div>
<div class="accounts-info__add hidden">
<div class="wallet-settings__title-wrap">
<a class="back-link" onclick="CancelAddAccount()"><span>Back</span></a>
<h2 class="accounts-info__title title">Create an account</h2>
</div>
<div class="key-field">
<label for="idAccountName" class="key-field__title"><span>Public name</span></label>
<input type="text"
id="idAccountName"
class="key-field__input"
placeholder="Input public text name of your account"
oninput="OnChangeAccName()">
</div>
<div class="key-field">
<label for="idAccountCur" class="key-field__title"><span>Currency</span></label>
<select size="1" id="idAccountCur" class="bigs key-field__input key-field__input--select">
<option value="0">TERA</option>
</select>
</div>
<button onclick="OnAddAccount()"
class="btn btn--full-width accounts-info__add-btn btn--270 btn--center"
id="idBtAddAccount">Create account</button>
</div>
<div class="accounts-info__add2 hidden" >
<p class="title text-center">Wait 10-15 sec</p>
<p class="text-center">Creating your account</p>
</div>
<div class="accounts-info__acc-list hidden">
<div class="accounts-info__counter-wrapper">
<a href="https://terafoundation.org/tera-coin.html" target="_blank" class="accounts-info__to-send-link">Buy/sell/mine TERA</a>
<p class="title" style="font-size: 16px;"><span class="accounts-info__number" id="idListCount">4</span> <span>Account(s)</span></p>
<a class="btn" onclick="OnViewAddAccount()">+ CREATE NEW</a>
</div>
<ul class="accounts-info__accounts prod-list" id="idAccountsList">
<li class="prod-list__item prod-card prod-card--line prod-card--switch find--switch" id="AccCardTemplate">
<div class="prod-card__first-line">
<span class="hidden id-sign">ID:&nbsp;</span>
<a target='_blank' class="prod-card__id prod-card__id--mobile">{Item.Num}</a>
<a href="./history.html#{Item.Num}" target='_blank' class="prod-card__id prod-card__id--mobile-active">{Item.Num}</a>
<a href="./history.html#{Item.Num}" target='_blank' class="prod-card__id prod-card__id--desktop">{Item.Num}</a>
<div class="prod-card__heading">
<span class="prod-card__coins-count">{Value.SumCOIN}<sup>,{Value.SumCENT}</sup><br>
<span class="light-grey-text small-text mob-hidden">{Value.CurrencyName}</span>
</span>
<span class="prod-card__currency prod-card__currency--with-dot">
<img src="{Value.CurrencyIconPath}" width="18" height="18" alt="">
</span>
</div>
<span class="prod-card__descr light-grey-text">{Item.Name}</span>
</div>
<div class="prod-card__footer">
<div class="prod-card__footer-wrap" >
<a onclick="OpenDapps({SmartObj.Num},{Item.Num})" class="prod-card__link prod-card__link--dapp">
<img src="{SmartObj.IconPath}" alt="." width="32" height="32">
<span class="prod-card__dapp-name mob-hidden">{SmartObj.Name}</span>
</a>
<a class="prod-card__link prod-card__link--connect" onclick="ConnectSmart({Item.Num})">
<svg class="prod-card__dapp-icon" width="30" height="30" viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg">
<circle cx="15" cy="15" r="14.5" fill="white" fill-opacity="0.01" stroke="#F2F2F2"/>
<path d="M15.5 10H14.5V14.5H10V15.5H14.5V20H15.5V15.5H20V14.5H15.5V10Z" fill="#445368"/>
</svg>
<span class="prod-card__dapp-text mob-hidden">Connect DApp...</span>
</a>
<button type="button" class="prod-card__drop-btn btn-no-bg mob-hidden" onclick="showMenu({Item.Num})" onblur="closeMenu({Item.Num})">
<svg width="4" height="16" viewBox="0 0 4 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.5 2C3.5 2.82843 2.82843 3.5 2 3.5C1.17157 3.5 0.5 2.82843 0.5 2C0.5 1.17157 1.17157 0.5 2 0.5C2.82843 0.5 3.5 1.17157 3.5 2ZM3.5 8C3.5 8.82843 2.82843 9.5 2 9.5C1.17157 9.5 0.5 8.82843 0.5 8C0.5 7.17157 1.17157 6.5 2 6.5C2.82843 6.5 3.5 7.17157 3.5 8ZM2 15.5C2.82843 15.5 3.5 14.8284 3.5 14C3.5 13.1716 2.82843 12.5 2 12.5C1.17157 12.5 0.5 13.1716 0.5 14C0.5 14.8284 1.17157 15.5 2 15.5Z" fill="#445368"/>
</svg>
</button>
<div class="prod-card__dropdown" style="display: none;" id="idBt{Item.Num}">
<a class="editdapp" onclick="SetSmart({Item.Num},{SmartObj.Num})">Change dApp</a>
<a class="editdapp" onclick="DelSmart({Item.Num},-1)">Disconnect dApp</a>
<a onclick="DelAccount({Item.Num})">Hide account</a>
<a onclick="RestoreAllAccounts()">Show All accounts</a>
</div>
</div>
<a class="prod-card__footer-empty" style="display: none;" onclick="ConnectSmart({Item.Num},{SmartObj.Num})"><span class="mob-hidden">Connect dapp...</span></a>
</div>
</li>
</ul>
<div class="accounts-info__total">
<h3>Total</h3>
<dl class="total-info" id="idTotalList">
</dl>
</div>
</div>
</section>
<section id="TabSend" class="send-page" style="display: none;">
<div class="send-page__setting">
<h2 class="title">Sending coins</h2>
<div class="send-page__field key-field">
<p class="key-field__title">From:</p>
<button onclick="SetAllSum()" title="Paste total amount" class="key-field__btn btn-no-bg no-mr" style="padding: 0; margin-left: 10px;">
<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M15 1H3C1.89543 1 1 1.89543 1 3V15C1 16.1046 1.89543 17 3 17H15C16.1046 17 17 16.1046 17 15V3C17 1.89543 16.1046 1 15 1ZM3 0C1.34315 0 0 1.34315 0 3V15C0 16.6569 1.34315 18 3 18H15C16.6569 18 18 16.6569 18 15V3C18 1.34315 16.6569 0 15 0H3ZM6.64645 10.6464C6.84171 10.4512 7.15829 10.4512 7.35355 10.6464L9.5 12.7929V6C9.5 5.17157 8.82843 4.5 8 4.5H6C5.72386 4.5 5.5 4.27614 5.5 4C5.5 3.72386 5.72386 3.5 6 3.5H8C9.38071 3.5 10.5 4.61929 10.5 6V12.7929L12.6464 10.6464C12.8417 10.4512 13.1583 10.4512 13.3536 10.6464C13.5488 10.8417 13.5488 11.1583 13.3536 11.3536L10.3536 14.3536L10 14.7071L9.64645 14.3536L6.64645 11.3536C6.45118 11.1583 6.45118 10.8417 6.64645 10.6464Z"/>
</svg>
</button>
<select size="1" id="idAccount" class="key-field__select" oninput="OnEditTransactionFields(); CheckSending();">
</select>
</div>
<div class="send-page__field key-field">
<label for="idTo" class="key-field__title key-field__title--pay"><span>Pay to:</span></label>
<span id="idNameTo2" style="margin: 0 10px 0 15px"></span>
<!--<button class="key-field__btn btn-no-bg">Paste</button>-->
<!--<a onclick="openModal('addresses-modal')" class="key-field__btn btn-no-bg key-field__btn&#45;&#45;with-icon no-mr">-->
<!--Address book-->
<!--<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">-->
<!--<path fill-rule="evenodd" clip-rule="evenodd" d="M4.5585 1H16C16.5523 1 17 1.44771 17 2V16C17 16.5523 16.5523 17 16 17H4.5585C4.00622 17 3.5585 16.5523 3.5585 16V15.5H5.14688V15.7922C5.14688 16.0683 5.37074 16.2922 5.64688 16.2922C5.92303 16.2922 6.14688 16.0683 6.14688 15.7922V14.2078C6.14688 13.9317 5.92303 13.7078 5.64688 13.7078C5.37074 13.7078 5.14688 13.9317 5.14688 14.2078V14.5H3.5585V11.5H5.14688V11.7978C5.14688 12.074 5.37074 12.2978 5.64688 12.2978C5.92303 12.2978 6.14688 12.074 6.14688 11.7978V10.2134C6.14688 9.93728 5.92303 9.71342 5.64688 9.71342C5.37074 9.71342 5.14688 9.93728 5.14688 10.2134V10.5H3.5585V7.5H5.14688V7.80348C5.14688 8.07962 5.37074 8.30348 5.64688 8.30348C5.92303 8.30348 6.14688 8.07962 6.14688 7.80348V6.21907C6.14688 5.94293 5.92303 5.71907 5.64688 5.71907C5.37074 5.71907 5.14688 5.94293 5.14688 6.21907V6.5H3.5585V3.5H5.14688V3.80911C5.14688 4.08525 5.37074 4.30911 5.64688 4.30911C5.92303 4.30911 6.14688 4.08525 6.14688 3.80911V2.2247C6.14688 1.94856 5.92303 1.7247 5.64688 1.7247C5.37074 1.7247 5.14688 1.94856 5.14688 2.2247V2.5H3.5585V2C3.5585 1.44772 4.00622 1 4.5585 1ZM2.5585 16V15.5H1.5C0.671575 15.5 0 14.8284 0 14V12C0 11.1716 0.671573 10.5 1.5 10.5H2.5585V7.5H1.5C0.671575 7.5 0 6.82843 0 6V4C0 3.17157 0.671573 2.5 1.5 2.5H2.5585V2C2.5585 0.89543 3.45393 0 4.5585 0H16C17.1046 0 18 0.895431 18 2V16C18 17.1046 17.1046 18 16 18H4.5585C3.45393 18 2.5585 17.1046 2.5585 16ZM2.5585 11.5V14.5H1.5C1.22386 14.5 1 14.2761 1 14V12C1 11.7239 1.22386 11.5 1.5 11.5H2.5585ZM2.5585 3.5H1.5C1.22386 3.5 1 3.72386 1 4V6C1 6.27614 1.22386 6.5 1.5 6.5H2.5585V3.5ZM7.70564 3.5H14.9117V2.5H7.70564V3.5ZM7.70564 5.5H14.9117V4.5H7.70564V5.5ZM7.70564 7.5H14.9117V6.5H7.70564V7.5Z"/>-->
<!--</svg>-->
<!--</a>-->
<input type="text"
id="idTo"
value=""
class="key-field__input key-field__input--enter"
oninput="OnEditIdTo()"
placeholder="Enter ID..." >
</div>
<div class="send-page__field key-field">
<label for="idSumSend" class="key-field__title"><span>Amount:</span></label>
<!--<b>2 000 000 000,00000000</b>-->
<input type="number" id="idSumSend" class="key-field__input" style="color:#1e21cb" value="" step=0 min=0 max=1000000000 oninput="OnEditTransactionFields()" placeholder="Input amount...">
</div>
<div class="send-page__field key-field">
<label for="idDescription" class="key-field__title"><span>Description:</span></label>
<textarea name="description" id="idDescription" rows="2" placeholder="Optional..." class="key-field__textarea key-field__textarea--mobile" oninput="CheckLengthAccDesription('idDescription',200); OnEditTransactionFields()">
</textarea>
</div>
<div class="send-page__send-btn-wrp">
<button class="btn btn--full-width btn--450 send-page__send-btn" onclick="SendMobileBefore()" id="idSendButton">Send</button>
</div>
</div>
<div class="send-page__confirm hidden">
<a href="#back" class="wallet-settings__title title">Confirm Transaction</a>
<dl class="confirm-info">
<div class="confirm-info__line">
<dt class="confirm-info__title">From ID:</dt>
<dd class="confirm-info__descr">
<span id="idConfirmFromID">192333</span>
<p class="light-grey-text" id="idConfirmFromName">
</p>
</dd>
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Pay to ID:</dt>
<dd class="confirm-info__descr confirm-info__descr--sm">
<span id="idConfirmToID">177555</span>
<p class="light-grey-text" id="idConfirmToName">
</p>
</dd>
<!--<a href="#address-book" class="key-field__btn btn-no-bg key-field__btn&#45;&#45;with-icon">-->
<!--Save-->
<!--<svg width="18" height="18" viewBox="0 0 18 18" fill="currentColor" xmlns="http://www.w3.org/2000/svg">-->
<!--<path fill-rule="evenodd" clip-rule="evenodd" d="M4.5585 1H16C16.5523 1 17 1.44771 17 2V16C17 16.5523 16.5523 17 16 17H4.5585C4.00622 17 3.5585 16.5523 3.5585 16V15.5H5.14688V15.7922C5.14688 16.0683 5.37074 16.2922 5.64688 16.2922C5.92303 16.2922 6.14688 16.0683 6.14688 15.7922V14.2078C6.14688 13.9317 5.92303 13.7078 5.64688 13.7078C5.37074 13.7078 5.14688 13.9317 5.14688 14.2078V14.5H3.5585V11.5H5.14688V11.7978C5.14688 12.074 5.37074 12.2978 5.64688 12.2978C5.92303 12.2978 6.14688 12.074 6.14688 11.7978V10.2134C6.14688 9.93728 5.92303 9.71342 5.64688 9.71342C5.37074 9.71342 5.14688 9.93728 5.14688 10.2134V10.5H3.5585V7.5H5.14688V7.80348C5.14688 8.07962 5.37074 8.30348 5.64688 8.30348C5.92303 8.30348 6.14688 8.07962 6.14688 7.80348V6.21907C6.14688 5.94293 5.92303 5.71907 5.64688 5.71907C5.37074 5.71907 5.14688 5.94293 5.14688 6.21907V6.5H3.5585V3.5H5.14688V3.80911C5.14688 4.08525 5.37074 4.30911 5.64688 4.30911C5.92303 4.30911 6.14688 4.08525 6.14688 3.80911V2.2247C6.14688 1.94856 5.92303 1.7247 5.64688 1.7247C5.37074 1.7247 5.14688 1.94856 5.14688 2.2247V2.5H3.5585V2C3.5585 1.44772 4.00622 1 4.5585 1ZM2.5585 16V15.5H1.5C0.671575 15.5 0 14.8284 0 14V12C0 11.1716 0.671573 10.5 1.5 10.5H2.5585V7.5H1.5C0.671575 7.5 0 6.82843 0 6V4C0 3.17157 0.671573 2.5 1.5 2.5H2.5585V2C2.5585 0.89543 3.45393 0 4.5585 0H16C17.1046 0 18 0.895431 18 2V16C18 17.1046 17.1046 18 16 18H4.5585C3.45393 18 2.5585 17.1046 2.5585 16ZM2.5585 11.5V14.5H1.5C1.22386 14.5 1 14.2761 1 14V12C1 11.7239 1.22386 11.5 1.5 11.5H2.5585ZM2.5585 3.5H1.5C1.22386 3.5 1 3.72386 1 4V6C1 6.27614 1.22386 6.5 1.5 6.5H2.5585V3.5ZM7.70564 3.5H14.9117V2.5H7.70564V3.5ZM7.70564 5.5H14.9117V4.5H7.70564V5.5ZM7.70564 7.5H14.9117V6.5H7.70564V7.5Z"/>-->
<!--</svg>-->
<!--</a>-->
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Amount:</dt>
<dd class="confirm-info__descr">
<span id="idConfirmAmount" style="color: #ff791a">100000</span>
<span id="idConfirmCurrency">TERA</span>
</dd>
</div>
<div class="confirm-info__line">
<dt class="confirm-info__title">Description:</dt>
<dd class="confirm-info__descr light-grey-text" id="idConfirmDescription">
Test Description
</dd>
</div>
</dl>
<div class="send-page__btns-wrap">
<button class="btn" onclick="OKSend()" id="idBtOnSend">CONFIRM</button>
<button class="btn btn--white" onclick="CancelSend()" id="editKeyBtn">Cancel</button>
</div>
</div>
</section>
<section id="TabDapps" class="dapps-page" style="display: none;">
<h2 class="title">Decentralized applications (dApps)</h2>
<div align="center">
<a class="btn nomobile" style="width: 200px;" onclick="window.Open('./dapp-edit.html','smart',1240)">CREATE DAPPS</a>
</div>
<div class="dapps-page__field key-field">
<select class="key-field__select" id="idCategory" onchange="$('idViewDappNum').value=0; ViewCurrent(DefDapps)">
<option value="0">Choose the category</option>
</select>
</div>
<div id="idPaginationDapps" class="">
<div class="dapps-page__pagination page-pagination">
<button onclick="ViewBegin(DefDapps)" class="btn dapps-page__page-btns">| &lt;</button>
<button onclick="ViewPrev(DefDapps)" class="btn dapps-page__page-btns">&lt;</button>
<input type="number" id="idViewDappNum" style="text-align: center" value="0" min=0 max=1000000000 onchange="ViewCurrent(DefDapps)">
<button onclick="ViewNext(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt;</button>
<button onclick="ViewEnd(DefDapps,CONFIG_DATA.MaxDappsID)" class="btn dapps-page__page-btns">&gt; |</button>
</div>
<div class="explorer-page__table-wrap">
<table id="dapps_list" class="grid dapps__table">
<tr>
<th id="(RetDappCard(Item))" class="dapp_card">DApps</th>
</tr>
</table>
</div>
<ul id="DappRowCardTemplate" class="grid prod-list">
<li class="prod-card dapps-page__card">
<div class="prod-card__first-line">
<span class="prod-card__id light-grey-text">ID: {Item.Num}</span>
<span class="prod-card__id light-grey-text">OWNER: {Item.Owner}</span>
<a onclick="OpenDappCard({Item.Num})" class="prod-card__link prod-card__link--info">More info</a>
</div>
<div class="prod-card__second-line">
<div class="prod-card__second-line-left">
<div class="prod-card__heading">
<a class="prod-card__link" onclick="OpenDapp({Item.Num})">{Item.Name}</a>
<!--<span class="lighter-grey-text">Without token generate</span>-->
<!--<span class="dapp-modal__ok-token">Token generate</span>-->
</div>
<p>{Item.Description}</p>
<!-- <ol>-->
<!--<li>Gaming & VR</li>-->
<!--<li>Gaming & VR</li>-->
<!--<li>Gaming & VR</li>-->
<!--</ol> -->
</div>
<div class="prod-card__second-line-img">
<a class="prod-card__link" onclick="OpenDapp({Item.Num})"><img src="{Item.IconPath}" width="32"></a>
</div>
</div>
</li>
</ul>
</div>
</section>
<section id="TabExplorer" class="explorer-page" style="display: none;">
<div id="idCurrentBlockNum" class="currentBlockNum">
<p><span>Blockchain height:</span> <b id="idBHeight">26003136</b></p>
<p><span>Current create:</span> <b id="idBCurrent">26003140</b></p>
<p><span>Protocol ver:</span> <b id="idBVersion">0.1057</b></p>
</div>
<button onclick="ViewCurrent(DefAccounts,1,this);" class="btview explorer-page__explore btn btn--white btn--full-width">Accounts</button>
<div class="explorer-page__table">
<div id="idPaginationAccount" style="display: none">
<div class="page-pagination">
<button onclick="ViewBegin(DefAccounts)" class="btnav btn">|&lt;</button>
<button onclick="ViewPrev(DefAccounts)" class="btnav btn">&lt;</button>
<input type="number" class="pag_num" id="idViewAccountNum" style="text-align: center" value="0" min=0 onchange="ViewCurrent(DefAccounts)">
<button onclick="ViewNext(DefAccounts,CONFIG_DATA.MaxAccID)" class="btnav btn">&gt;</button>
<button onclick="ViewEnd(DefAccounts,CONFIG_DATA.MaxAccID)" class="btnav btn">&gt;|</button>
</div>
<div class="explorer-page__table-wrap">
<table id="explorer_accounts" class="grid">
<tr>
<th id="(RetHistoryAccount(Item))" class="num">ID</th>
<th id="SUM_TO_STRING(Item.Value)" class="sum">Amount</th>
<th id="CurrencyNameItem(Item)" class="cur">Cur</th>
<th id="Item.Name" class="accname">Name</th>
<th id="Item.PubKeyStr" class="hash">PubKey</th>
<th id="Item.Value.OperationID" class="minwidth">Operation</th>
<th id="Item.Value.Smart" class="minwidth">Smart</th>
<th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="minwidth">Block Num</th>
</tr>
</table>
</div>
</div>
</div>
<button onclick="ViewCurrent(DefBlock,1,this)" class="btview explorer-page__explore btn btn--white btn--full-width">Blocks and Tx</button>
<div class="explorer-page__table">
<div id="idPaginationBlock" style="display: none">
<div class="page-pagination">
<button onclick="ViewBegin(DefBlock)" class="btnav btn">|&lt;</button>
<button onclick="ViewPrev(DefBlock)" class="btnav btn">&lt;</button>
<input type="number" class="pag_num" id="idViewBlockNum" style="text-align: center" value="0" min=0 onchange="ViewCurrent(DefBlock)">
<button onclick="ViewNext(DefBlock,CONFIG_DATA.MaxNumBlockDB)" class="btnav btn">&gt;</button>
<button onclick="ViewEnd(DefBlock,CONFIG_DATA.MaxNumBlockDB)" class="btnav btn">&gt;|</button>
</div>
<div class="explorer-page__table-wrap">
<table id="explorer_blocks" class="grid">
<tr>
<th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))" class="num">Num</th>
<th id="(DateFromBlock(Item.BlockNum,1))" class="date">Date</th>
<th id="GetHexFromArr(Item.TreeHash)" class="hash">Data Hash</th>
<th id="GetHexFromArr(Item.PowHash)" class="hash">PowHash</th>
<th id="GetHexFromArr(Item.Hash)" class="hash">Block Hash</th>
<th id="Item.TrDataLen" class="minwidth">Bytes</th>
<th id="Item.Power" class="minwidth">Pow</th>
<th id="Item.Miner" class="minwidth">Miner</th>
</tr>
</table>
</div>
</div>
</div>
<button onclick="ViewCounters(this)" class="btview explorer-page__explore btn btn--white btn--full-width">Counters</button>
<div class="explorer-page__diagramms">
<div id="idStatBlock" style="display: none">
<div id="diagr_content">
<div id="diargams">
</div>
</div>
</div>
</div>
</section>
</main>
<section class="dapp-modal modal" id="DappCardTemplate" style="display: none;">
<div class="modal__header">
<div class="modal__title-wrap">
<span class="light-grey-text">ID: {Item.Num}</span>
<h3>{Item.Name}</h3>
<ol class="modal__ol">
<li class="modal__category dappcategory1">{Item.Category1}</li>
<li class="modal__category dappcategory2">{Item.Category2}</li>
<li class="modal__category dappcategory3">{Item.Category3}</li>
</ol>
<p class="dapp-modal__token-status dapp-modal__token-status--ok">
<!--<span class="light-grey-text">Without token generate</span>-->
<span class="dapp-modal__ok-token">Token generate</span>
</p>
</div>
<div class="modal__img-wrap">
<img src="{Item.IconPath}" alt="dApp logo" width="32">
</div>
</div>
<p>{Item.Description}</p>
<dl class="modal__def-list def-list">
<div class="def-list__item">
<dt>Account</dt>
<dd>{Item.Account}</dd>
</div>
<div class="def-list__item">
<dt>Owner</dt>
<dd>{Item.Owner}</dd>
</div>
<div class="def-list__item">
<dt>Block num</dt>
<dd>{Item.BlockNum}</dd>
</div>
</dl>
<div class="modal__btns-wrap">
<button class="btn" onclick="OpenDapp({Item.Num})">Open DApp</button>
<button class="btn btn--white" onclick="closeModal()">Back</button>
</div>
<button class="modal__close btn btn--white" title="Close modal" onclick="closeModal()"></button>
</section>
<!--TODO: адресная книга-->
<section class="addresses-modal modal" id="addresses-modal" style="display: none;">
<!--<h2 class="title">Address book</h2>-->
<!--<input type="search" class="addresses-modal__input" placeholder="Global search by ID or name">-->
<!--<ul class="addresses-modal__list">-->
<!--<li class="addresses-modal__item">-->
<!--<div class="addresses-modal__text-wrap">-->
<!--<div class="addresses-modal__item-name">-->
<!--<span class="grey-blue-text">Test name1 </span>-->
<!--<div class="light-grey-text">10 TERA</div>-->
<!--</div>-->
<!--<span class="addresses-modal__id">192834</span>-->
<!--</div>-->
<!--<button class="addresses-modal__delete-item"></button>-->
<!--<div class="addresses-modal__btns-wrapper">-->
<!--<button class="btn btn&#45;&#45;white">Cancel</button>-->
<!--<button class="btn">Delete</button>-->
<!--</div>-->
<!--</li>-->
<!--<li class="addresses-modal__item">-->
<!--<div class="addresses-modal__text-wrap">-->
<!--<div class="addresses-modal__item-name">-->
<!--<span class="grey-blue-text">Minecraft is life</span>-->
<!--<div class="light-grey-text">2 000,000000 TERA</div>-->
<!--</div>-->
<!--<span class="addresses-modal__id">192834</span>-->
<!--</div>-->
<!--<button class="addresses-modal__delete-item"></button>-->
<!--<div class="addresses-modal__btns-wrapper" style="display: none;">-->
<!--<button class="btn btn&#45;&#45;white">Cancel</button>-->
<!--<button class="btn">Delete</button>-->
<!--</div>-->
<!--</li>-->
<!--</ul>-->
<!--<button class="modal__close btn btn&#45;&#45;white" title="Close modal" onclick="closeModal()"></button>-->
<!--<div class="addresses-modal__choosing">-->
<!--<button class="btn btn&#45;&#45;white">Save to book</button>-->
<!--<button class="btn">Choose</button>-->
<!--</div>-->
</section>
<div id="overlay" onclick="closeModal()"></div>
<section class="modal password-modal password-modal--set" id="password-modal-set">
<h2 class="password-modal__title">Secure your wallet</h2>
<p class="password-modal__subtitle">Set a password for protect entry</p>
<form class="password-modal__form" onsubmit="">
<input type="password" class="password-modal__input" placeholder="Enter password" autocomplete="WalletPassword" id="Password1">
<input type="password" class="password-modal__input" placeholder="Repeat password" autocomplete="WalletPassword" id="Password2">
<div class="password-modal__buttons">
<a class="btn" onclick="SetNewPassword()">Set pass</a>
<a class="btn btn--white" onclick="closeModal()">Cancel</a>
</div>
</form>
</section>
<section class="modal password-modal" id="password-modal-enter">
<h2 class="password-modal__title">Wallet is secured</h2>
<p class="password-modal__subtitle">Enter password to unlock wallet</p>
<form class="password-modal__form" onsubmit="MyOpenWallet(1)">
<input type="password" class="password-modal__input" placeholder="Enter password" autocomplete="WalletPassword" id="Password">
<div class="password-modal__buttons password-modal__buttons--one">
<a class="btn" onclick="MyOpenWallet(1)">Unlock</a>
</div>
<a class="password-modal__link pointer" id="idEntrance" onclick="MyOpenWallet(0)">Entrance to sub-wallet</a>
</form>
</section>
<footer>
</footer>
<div class="fixed-status">
<div class="fixed-status__wrap">
<div id="idStatus" class="fixed-status__status">&nbsp;</div>
<select class="grey-btn" id="idCurNetwork" onchange="ChangeNetwork()">
<option value="TERA-MAIN">TERA MAIN</option>
<option value="TERA-TEST2">TERA TEST2</option>
</select>
<button class="grey-btn reconnect" onclick="ConnectWebWallet()" title="Reconnect"><span>RECONNECT</span></button>
<!--рудименты-->
<span id="idNetwork" style="display: none"></span>
<span id="idSignJSON"></span>
</div>
</div>
<DIV align='center'>
<DIV align='left' style="display: none;">
<INPUT id="idCurTabName" value="TabInfo" style="display: none">
</DIV>
</DIV>
</body>
</html>
<script type="text/javascript" src="./JS/sign-lib-min.js"></script>

6
src/a.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/bash
EXT=js
DIST=ts
for name in `ls *.${EXT}`; do
mv $name ${name%.${EXT}}.${DIST}
done

View File

@ -0,0 +1,40 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
import * as crypto from 'crypto'
global.HTTPCaller.CreateAccount = function(Params, response) {
if (typeof Params === "object" && Params.Name && Params.PubKey) {
var TYPE_TRANSACTION_CREATE = 100;
var TR = {
Type: global.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: global.GetArrFromHex(Params.PubKey), Description: Params.Name,
Smart: Params.Smart, Adviser: 0,
};
var Body = global.BufLib.GetBufferFromObject(TR, global.global.FORMAT_CREATE, 1000, {});
return { result: 1 };
}
return { result: 0 };
};
var MaxCountViewRows = global.HTTP_MAX_COUNT_ROWS;
global.HTTPCaller.GetBalance = function(Params) {
if (typeof Params === "object") {
var arr = global.DApps.Accounts.GetRowsAccounts(ParseNum(Params.AccountID), 1);
if (arr.length) {
arr[0].result = 1;
return arr[0];
}
}
return { result: 0 };
};
global.HTTPCaller.GenerateKeys = function(Params) {
var KeyPair = crypto.createECDH('secp256k1');
var PrivKey = global.sha3(crypto.randomBytes(32));
KeyPair.setPrivateKey(Buffer.from(PrivKey));
var PubKey = KeyPair.getPublicKey('' as any, 'compressed');
return { result: 1, PrivKey: global.GetHexFromArr(PrivKey), PubKey: global.GetHexFromArr(PubKey) };
};

View File

@ -0,0 +1,10 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/

390
src/core/base.ts Normal file
View File

@ -0,0 +1,390 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
"use strict";
require("./library.js");
require("./crypto-library");
require("./terahashmining");
import * as crypto from 'crypto';
const os = require('os');
global.glStopNode = false;
const MAX_TIME_NETWORK_TRANSPORT = 1 * 1000;
var GlSumUser;
var GlSumSys;
var GlSumIdle;
global.CountAllNode = 0;
module.exports = class CCommon importasdasd {
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
global.SERVER = this
this.VirtualMode = bVirtual
this.KeyPair = SetKeyPair
var PubKey = SetKeyPair.getPublicKey('', 'compressed');
this.PubKeyType = PubKey[0]
this.addrArr = PubKey.slice(1)
this.addrStr = global.GetHexFromArr(this.addrArr)
this.HashDBArr = shaarr2(this.KeyPair.getPrivateKey(), [0, 0, 0, 0, 0, 0, 0, 1])
this.ServerSign = []
}
AddStatOnTimer() {
var CountAll = 0;
var CurTime = global.GetCurrentTime() - 0;
for (var i = 0; i < this.NodesArr.length; i++) {
var Item = this.NodesArr[i];
if (Item.LastTime && (CurTime - Item.LastTime) < NODES_DELTA_CALC_HOUR * 3600 * 1000)
CountAll++
else
if (Item.LastTimeGetNode && (CurTime - Item.LastTimeGetNode) < NODES_DELTA_CALC_HOUR * 3600 * 1000)
CountAll++
}
global.CountAllNode = CountAll
if (!global.STAT_MODE)
return;
var StateTX = global.DApps.Accounts.DBStateTX.Read(0);
if (StateTX) {
var Delta = this.CurrentBlockNum - StateTX.BlockNum;
global.ADD_TO_STAT("MAX:DELTA_TX", Delta)
}
var bHasCP = 0;
if (CHECK_POINT.BlockNum) {
var Block = this.ReadBlockHeaderDB(CHECK_POINT.BlockNum);
if (Block && global.CompareArr(CHECK_POINT.Hash, Block.Hash) === 0)
bHasCP = 1
}
var MinVer = global.MIN_VER_STAT;
if (MinVer === 0)
MinVer = global.UPDATE_CODE_VERSION_NUM
var BufMap = {}, BufMap2 = {};
var arr = this.GetActualNodes();
var Count = 0, CountHot = 0, CountHotOK = 0, CountActualOK = 0, SumDeltaHot = 0, SumDeltaActual = 0, CountCP = 0, CountLH = 0,
CountHash = 0, CountVer = 0, CountStop = 0;
var CountAutoCorrectTime = 0;
var SumAvgDeltaTime = 0;
for (var i = 0; i < arr.length; i++) {
var Node = arr[i];
if (!Node || Node.IsAddrList)
continue;
var INFO = Node.INFO;
if (!INFO)
INFO = {}
if (bHasCP && CHECK_POINT.BlockNum && INFO.CheckPointHashDB && global.CompareArr(CHECK_POINT.Hash, INFO.CheckPointHashDB) === 0) {
CountCP++
}
if (INFO.LoadHistoryMode)
CountLH++
if (Node.StopGetBlock)
CountStop++
Count++
SumAvgDeltaTime += Node.DeltaGlobTime
if (Node.VersionNum >= MinVer)
CountVer++
if (INFO && INFO.BlockNumDB && INFO.BlockNumDB <= this.BlockNumDB) {
var HashDB = ReadHashFromBufDB(BufMap2, INFO.BlockNumDB);
if (HashDB && global.CompareArr(HashDB, INFO.HashDB) === 0)
CountHash++
}
var StrChk = GetCheckAccHash(BufMap, INFO.AccountBlockNum, INFO.AccountsHash);
var Chck = 0;
if (StrChk.indexOf("=OK=") >= 0) {
Chck = 1
}
var DeltaTime = Node.DeltaTime;
if (!DeltaTime)
DeltaTime = 0
CountActualOK += Chck
SumDeltaActual += DeltaTime
if (Node.Hot) {
CountHot++
CountHotOK += Chck
SumDeltaHot += DeltaTime
}
if (INFO.AutoCorrectTime)
CountAutoCorrectTime++
}
global.ADD_TO_STAT("MAX:ALL_NODES", CountAll)
global.ADD_TO_STAT("MAX:CONNECTED_NODES", Count)
global.ADD_TO_STAT("MAX:HOT_NODES", CountHot)
global.ADD_TO_STAT("MAX:HOT_OK", CountHotOK)
global.ADD_TO_STAT("MAX:ACTUAL_OK", CountActualOK)
global.ADD_TO_STAT("MAX:CHECK_POINT_OK", CountCP)
global.ADD_TO_STAT("MAX:COUNTLH", CountLH)
global.ADD_TO_STAT("MAX:HASH_OK", CountHash)
global.ADD_TO_STAT("MAX:MIN_VERSION", CountVer)
global.ADD_TO_STAT("MAX:STOP_GET", CountStop)
global.ADD_TO_STAT("MAX:AUTOCORRECT", CountAutoCorrectTime)
global.ADD_TO_STAT("MAX:TIME_DELTA", DELTA_CURRENT_TIME)
if (!Count)
Count = 1
if (!CountHot)
CountHot = 1
if (Count >= 20) {
var SumDeltaAvg = 0;
var AvgGlobTime = SumAvgDeltaTime / Count;
for (var i = 0; i < arr.length; i++) {
var Node = arr[i];
if (!Node || Node.IsAddrList)
continue;
var Delta = AvgGlobTime - Node.DeltaGlobTime;
SumDeltaAvg += Delta * Delta
}
SumDeltaAvg = Math.sqrt(SumDeltaAvg / Count)
global.ADD_TO_STAT("MAX:DELTA_GLOB_TIME", 100 + AvgGlobTime)
global.ADD_TO_STAT("MAX:DISP_DELTA_GLOB_TIME", SumDeltaAvg)
arr.sort(function(a, b) {
return a.DeltaGlobTime - b.DeltaGlobTime;
})
var SumDeltaAvgM = 0;
var AvgGlobTimeM = arr[Math.trunc(arr.length / 2)].DeltaGlobTime;
var Length = arr.length;
var Start = Math.trunc(Length * 0.05);
var End = Math.trunc(Length * 0.95);
var NodesCount = 0;
for (var i = Start; i < End; i++) {
var Node = arr[i];
if (!Node || Node.IsAddrList)
continue;
NodesCount++
var Delta = AvgGlobTimeM - Node.DeltaGlobTime;
SumDeltaAvgM += Delta * Delta
}
if (!NodesCount)
NodesCount = 1
SumDeltaAvgM = Math.sqrt(SumDeltaAvgM / NodesCount)
global.ADD_TO_STAT("MAX:MEDIAN_GLOB_TIME", 100 + AvgGlobTimeM)
global.ADD_TO_STAT("MAX:DISP_MEDIAN_GLOB_TIME", SumDeltaAvgM)
}
global.ADD_TO_STAT("MAX:DELTA_TIME_HOT", SumDeltaHot / CountHot)
global.ADD_TO_STAT("MAX:DELTA_TIME_ACTUAL", SumDeltaActual / Count)
global.ADD_TO_STAT("MAX:MEMORY_USAGE", process.memoryUsage().heapTotal / 1024 / 1024)
global.ADD_TO_STAT("MAX:MEMORY_FREE", os.freemem() / 1024 / 1024)
var SumUser = 0;
var SumSys = 0;
var SumIdle = 0;
var cpus = os.cpus();
for (var i = 0; i < cpus.length; i++) {
var cpu = cpus[i];
SumUser += cpu.times.user
SumSys += cpu.times.sys + cpu.times.irq
SumIdle += cpu.times.idle
}
if (GlSumUser !== undefined) {
var maxsum = cpus.length * 1000;
global.ADD_TO_STAT("MAX:CPU_USER_MODE", Math.min(maxsum, SumUser - GlSumUser))
global.ADD_TO_STAT("MAX:CPU_SYS_MODE", Math.min(maxsum, SumSys - GlSumSys))
global.ADD_TO_STAT("MAX:CPU_IDLE_MODE", Math.min(maxsum, SumIdle - GlSumIdle))
global.ADD_TO_STAT("MAX:CPU", Math.min(maxsum, SumUser + SumSys - GlSumUser - GlSumSys))
}
GlSumUser = SumUser
GlSumSys = SumSys
GlSumIdle = SumIdle
}
GetNewMeta() {
return crypto.randomBytes(32);
}
};
class SMemBuffer {
MetaMap1
MetaMap2
CheckName
constructor(MaxTime, CheckName) {
this.MetaMap1 = {}
this.MetaMap2 = {}
this.CheckName = CheckName
setInterval(this.ShiftMapDirect.bind(this), MaxTime)
}
GetStrKey(Arr) {
if (typeof Arr === "number" || typeof Arr === "string") {
return Arr;
} else {
return GetHexFromAddres(Arr);
}
throw "NOT RET!";
}
LoadValue(Arr, bStay) {
if (!Arr)
return undefined;
var Key = this.GetStrKey(Arr);
var Value = this.MetaMap1[Key];
if (Value !== undefined) {
if (!bStay)
delete this.MetaMap1[Key]
return Value;
}
Value = this.MetaMap2[Key]
if (Value !== undefined) {
if (!bStay)
delete this.MetaMap2[Key]
}
return Value;
}
SaveValue(Arr, Value) {
var Key = this.GetStrKey(Arr);
if (Value !== undefined)
this.MetaMap1[Key] = Value
}
ShiftMapDirect() {
if (glStopNode)
return;
if (this.CheckName) {
var Count = 0;
for (var key in this.MetaMap2) {
Count++
}
if (Count) {
global.ADD_TO_STAT(this.CheckName, 1, 1)
}
}
this.MetaMap2 = this.MetaMap1
this.MetaMap1 = {}
}
Clear() {
this.MetaMap2 = {}
this.MetaMap1 = {}
}
};
class STreeBuffer {
constructor(MaxTime, CompareFunction?, KeyType?, CheckName?) {
this.KeyType = KeyType
this.MetaTree1 = new RBTree(CompareFunction)
this.MetaTree2 = new RBTree(CompareFunction)
this.CheckName = CheckName
setInterval(this.ShiftMapDirect.bind(this), MaxTime)
}
LoadValue(Hash, bStay) {
if (!Hash)
return undefined;
if (typeof Hash !== this.KeyType)
throw "MUST ONLY HASH ARRAY: " + Hash;
var element = this.MetaTree1.find({ hash: Hash });
if (element) {
if (!bStay)
this.MetaTree1.remove(element)
return element.value;
}
element = this.MetaTree2.find({ hash: Hash })
if (element) {
if (!bStay)
this.MetaTree2.remove(element)
return element.value;
}
return undefined;
}
SaveValue(Hash, Value) {
if (typeof Hash !== this.KeyType)
throw "MUST ONLY TYPE=" + this.KeyType + " in " + Hash;
if (Value !== undefined) {
var element = this.MetaTree1.find({ hash: Hash });
if (element)
element.value = Value
else
this.MetaTree1.insert({ hash: Hash, value: Value })
}
}
ShiftMapDirect() {
if (this.CheckName && this.MetaTree2.size) {
global.ADD_TO_STAT(this.CheckName, this.MetaTree2.size, 1)
var it = this.MetaTree2.iterator(), Item;
while ((Item = it.next()) !== null) {
var Name = Item.value.Name;
global.ADD_TO_STAT(this.CheckName + ":" + Name, 1, 1)
}
}
this.MetaTree2.clear()
var empty_tree = this.MetaTree2;
this.MetaTree2 = this.MetaTree1
this.MetaTree1 = empty_tree
}
Clear() {
this.MetaTree1.clear()
this.MetaTree2.clear()
}
};
function ReadHashFromBufDB(Map, BlockNum) {
var MyHash = Map[BlockNum];
if (!MyHash) {
var Block = global.SERVER.ReadBlockHeaderDB(BlockNum);
if (Block)
MyHash = Block.Hash;
else
MyHash = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
Map[BlockNum] = MyHash;
}
return MyHash;
};
function GetCheckAccHash(Map, BlockNum, Hash) {
var MyHash = Map[BlockNum];
if (!MyHash) {
MyHash = global.DApps.Accounts.GetHashOrUndefined(BlockNum);
Map[BlockNum] = MyHash;
}
if (MyHash) {
if (!Hash)
return "=ERR:NO=";
if (global.CompareArr(Hash, MyHash) !== 0)
return "=ERR:BAD=";
else
return "=OK=";
}
else {
if (!Hash)
return "=OK=:NO";
else
return "=MY:NO=";
}
};
global.GetCheckAccHash = GetCheckAccHash;
global.ReadHashFromBufDB = ReadHashFromBufDB;
global.STreeBuffer = STreeBuffer;
global.TestCreateTr = TestCreateTr;
function TestCreateTr() {
const FORMAT_CREATE = "{\
Type:byte,\
Currency:uint,\
PubKey:arr33,\
Description:str40,\
Adviser:uint,\
Reserve:arr7,\
POWCreate:arr12,\
}";
var TR = {
Type: 100, Currency: 0, PubKey: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0], Description: "Description", Adviser: 10,
};
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {});
var startTime = process.hrtime();
var StartData = Date.now();
var nonce = CreateHashBodyPOWInnerMinPower(Body, 1000, 17);
var Time = process.hrtime(startTime);
var power = GetPowPower(shaarr(Body));
var deltaTime = (Time[0] * 1000 + Time[1] / 1e6) / 1000;
var DeltaData = (new Date() - StartData) / 1000;
global.ToLog("power=" + power + " nonce=" + nonce + " TIME=" + deltaTime + " sec" + " DeltaData=" + DeltaData + " sec");
return { time1: deltaTime, time2: DeltaData };
};
function CreateHashBody(body, Num, Nonce) {
body.writeUIntLE(Num, body.length - 12, 6);
body.writeUIntLE(Nonce, body.length - 6, 6);
return global.shaarr(body);
};
function CreateHashBodyPOWInnerMinPower(arr, BlockNum, MinPow) {
var nonce = 0;
while (1) {
var arrhash = CreateHashBody(arr, BlockNum, nonce);
var power = GetPowPower(arrhash);
if (power >= MinPow) {
return nonce;
}
nonce++;
}
};

1376
src/core/block-exchange.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,16 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
global.PERIOD_GET_BLOCK = 300, global.COUNT_HISTORY_BLOCKS_FOR_LOAD = 600, global.COUNT_BLOCKS_FOR_CHECK_POW = 50, global.MAX_DELTA_COUNT_SUM_FOR_LOAD = 10,
global.MAX_COUNT_CHAIN_LOAD = 120, global.PACKET_ALIVE_PERIOD = 4 * CONSENSUS_PERIOD_TIME, global.PACKET_ALIVE_PERIOD_NEXT_NODE = PACKET_ALIVE_PERIOD / 2,
global.MAX_BLOCK_SEND = 8, global.COUNT_TASK_FOR_NODE = 10, global.FORMAT_BLOCK_TRANSFER = "{ BlockNum:uint, TreeHash:hash, arrContent:[tr], }",
global.WRK_BLOCK_TRANSFER = {}, global.MAX_ACCOUNTS_TRANSFER = 1024, global.MAX_SMARTS_TRANSFER = 10, global.TEST_NETWORK && (global.MAX_ACCOUNTS_TRANSFER = 128,
global.MAX_SMARTS_TRANSFER = 10), global.FORMAT_REST_TRANSFER = "{ Result:uint, Version:uint, Arr:[arr200], ProofHash:hash, ProofArrL:<hash>, ProofArrR:<hash>, }",
global.FORMAT_SMART_TRANSFER = "{ Result:uint, Arr:[tr], }";

1284
src/core/block-loader.ts Normal file

File diff suppressed because it is too large Load Diff

364
src/core/buffer.ts Normal file
View File

@ -0,0 +1,364 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
function Write(e,r,t,n,l)
{
if(!(e.len >= e.length))
{
if("number" == typeof t)
throw ToLogTrace("ERRR StringFormat "), "ERR!!";
var a = t;
if("buffer" === a.substr(0, 6) && 6 < a.length)
n = parseInt(a.substr(6)), a = "buffer";
else
if("arr" === a.substr(0, 3) && 3 < a.length)
n = parseInt(a.substr(3)), a = "arr";
else
if("str" === a.substr(0, 3) && 3 < a.length)
{
var i = parseInt(a.substr(3));
return r && e.write(r, e.len, i), void (e.len += i);
}
switch(a)
{
case "str":
var f = toUTF8Array(r);
65535 < (i = f.length) && (i = 0), e[e.len] = 255 & i, e[e.len + 1] = i >>> 8 & 255, e.len += 2;
for(var s = 0; s < i; s++)
e[e.len + s] = f[s];
e.len += i;
break;
case "byte":
r < 0 && (r = 0), e[e.len] = r, e.len += 1;
break;
case "double":
e.writeDoubleLE(r, e.len, 8), e.len += 8;
break;
case "uint":
r < 0 && (r = 0), 0xffffffffffff <= r && (r = 0), e.writeUIntLE(r, e.len, 6), e.len += 6;
break;
case "uint16":
r < 0 && (r = 0), e[e.len] = 255 & r, e[e.len + 1] = r >>> 8 & 255, e.len += 2;
break;
case "uint32":
r < 0 && (r = 0), e.writeUInt32LE(r, e.len, 4), e.len += 4;
break;
case "time":
var u = r.valueOf();
e.writeUIntLE(u, e.len, 6), e.len += 6;
break;
case "addres":
case "hash":
i = r ? Math.min(32, r.length) : 0;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += 32;
break;
case "buffer":
i = void 0 === n ? r.length : Math.min(n, r.length);
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += n;
break;
case "arr":
i = r ? Math.min(n, r.length) : 0;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += n;
break;
case "tr":
i = r.length;
MAX_TRANSACTION_SIZE > MAX_TRANSACTION_SIZE && (i = MAX_TRANSACTION_SIZE), e[e.len] = 255 & i, e[e.len + 1] = i >>> 8 & 255,
e.len += 2;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += i;
break;
case "data":
i = r.length;
e.writeUInt32LE(i, e.len, 4), e.len += 4;
for(s = 0; s < i; s++)
e[e.len + s] = r[s];
e.len += i;
break;
case "hashSTR":
var o = GetHexFromAddres(r);
e.write(o, e.len, 64), e.len += 64;
break;
case "uintSTR":
o = r.toString();
e.write(o, e.len, 10), e.len += 10;
break;
default:
l = l || {};
var d = t.substr(0, 1);
if("[" === d)
{
r && (i = r.length);
var b = GetMiddleString(a);
Write(e, i, "uint32");
for(s = 0; s < i; s++)
Write(e, r[s], b, void 0, l);
}
else
if("<" === d)
{
r && (i = r.length);
b = GetMiddleString(a);
var h = 0, c = e.len;
e.len += 4;
for(s = 0; s < i; s++)
r[s] && (h++, Write(e, s, "uint32"), Write(e, r[s], b, void 0, l));
e.writeUInt32LE(h, c, 4);
}
else
{
if("{" !== d)
throw "Bad write type params: " + a;
var g = l[a];
g || (g = GetAttributes(GetMiddleString(a)), l[a] = g);
for(s = 0; s < g.length; s++)
{
var v = g[s];
Write(e, r[v.Key], v.Value, void 0, l);
}
}
}
}
};
function Read(e,r,t,n,l)
{
var a;
if("number" == typeof r)
throw ToLogTrace("ERR StringFormat"), "ERRR!";
var i = r;
if("buffer" === i.substr(0, 6))
6 < i.length ? (t = parseInt(i.substr(6)), i = "buffer") : t = 0;
else
if("arr" === i.substr(0, 3))
3 < i.length ? (t = parseInt(i.substr(3)), i = "arr") : t = 0;
else
if("str" === i.substr(0, 3))
{
if(3 < i.length)
{
var f = parseInt(i.substr(3));
a = e.toString("utf8", e.len, e.len + f), e.len += f;
for(var s = - 1, u = a.length - 1; 0 <= u; u--)
if(0 !== a.charCodeAt(u))
{
s = u;
break;
}
return a = 0 <= s ? a.substr(0, u + 1) : "";
}
t = 0;
}
switch(i)
{
case "str":
f = e.len + 2 <= e.length ? e[e.len] + 256 * e[e.len + 1] : 0, e.len += 2;
var o = e.slice(e.len, e.len + f);
a = Utf8ArrayToStr(o), e.len += f;
break;
case "byte":
a = e.len + 1 <= e.length ? e[e.len] : 0, e.len += 1;
break;
case "double":
a = e.len + 8 <= e.length ? e.readDoubleLE(e.len, 8) : 0, e.len += 8;
break;
case "uint":
a = e.len + 6 <= e.length ? e.readUIntLE(e.len, 6) : 0, e.len += 6;
break;
case "uint16":
a = e.len + 2 <= e.length ? e[e.len] + 256 * e[e.len + 1] : 0, e.len += 2;
break;
case "uint32":
a = e.len + 4 <= e.length ? e.readUInt32LE(e.len, 4) : 0, e.len += 4;
break;
case "time":
if(l)
throw "Bad read type params: time - DisableTime ON";
a = e.len + 6 <= e.length ? e.readUIntLE(e.len, 6) : 0, a = new Date(a), e.len += 6;
break;
case "addres":
case "hash":
a = [];
for(u = 0; u < 32; u++)
e.len + u <= e.length ? a[u] = e[e.len + u] : a[u] = 0;
e.len += 32;
break;
case "buffer":
case "arr":
a = e.len + t <= e.length ? e.slice(e.len, e.len + t) : Buffer.alloc(t), e.len += t;
break;
case "tr":
if(e.len + 1 >= e.length)
{
a = void 0;
break;
}
f = e[e.len] + 256 * e[e.len + 1];
e.len += 2, a = e.slice(e.len, e.len + f), e.len += f;
break;
case "data":
(f = e.len + 4 <= e.length ? e.readUInt32LE(e.len, 4) : 0) > e.length - e.len - 4 && (f = 0), e.len += 4, a = e.slice(e.len,
e.len + f), e.len += f;
break;
case "hashSTR":
var d = e.toString("utf8", e.len, e.len + 64);
a = GetAddresFromHex(d), e.len += 64;
break;
case "uintSTR":
d = e.toString("utf8", e.len, e.len + 10);
a = parseInt(d), e.len += 10;
break;
default:
n = n || {};
var b = i.substr(0, 1);
if("[" === b || "<" === b)
{
var h = "<" === b;
a = [];
var c = GetMiddleString(i);
for(f = Read(e, "uint32"), u = 0; u < f && e.len <= e.length; u++)
{
h ? a[Read(e, "uint32")] = Read(e, c, void 0, n, l) : a[u] = Read(e, c, void 0, n, l);
}
}
else
{
if("{" !== b)
throw "Bad read type params: " + i;
var g = n[i];
g || (g = GetAttributes(GetMiddleString(i)), n[i] = g), a = {};
for(u = 0; u < g.length; u++)
{
var v = g[u];
a[v.Key] = Read(e, v.Value, void 0, n, l);
}
}
}
return a;
};
function BufWriteByte(e)
{
this[this.len] = e, this.len += 1;
};
function BufWrite(e,r,t)
{
Write(this, e, r, t);
};
function BufRead(e,r)
{
return Read(this, e, r);
};
function GetNewBuffer(e)
{
var r = Buffer.alloc(e);
return r.Read = BufRead.bind(r), r.Write = BufWrite.bind(r), r.len = 0, r;
};
function GetReadBuffer(e)
{
var r = Buffer.from(e);
return r.Read = BufRead.bind(r), r.Write = BufWrite.bind(r), r.len = 0, r;
};
function GetObjectFromBuffer(e,r,t,n)
{
var l = Buffer.from(e);
return l.len = 0, Read(l, r, void 0, t, n);
};
function GetBufferFromObject(e,r,t,n,l)
{
var a = Buffer.alloc(t);
return a.len = 0, Write(a, e, r, void 0, n), l || (a = a.slice(0, a.len)), a;
};
function GetMiddleString(e)
{
return e.substr(1, e.length - 2);
};
function GetMiddleString2(e,r,t)
{
for(var n = 0, l = "", a = 0; a < e.length; a++)
{
var i = e.substr(a, 1);
if(" " !== i && "\n" !== i && (i !== r || 1 != ++n))
{
if(i === t && 0 === --n)
break;
n && (l += i);
}
}
return l;
};
function GetAttributeStrings(e)
{
for(var r = 0, t = [], n = "", l = 0; l < e.length; l++)
{
var a = e.substr(l, 1);
if("{" === a)
r++;
else
if("}" === a)
r--;
else
{
if("," === a && 0 === r)
{
0 < n.length && t.push(n), n = "";
continue;
}
if(" " === a || "\n" === a)
continue;
}
n += a;
}
return 0 < n.length && t.push(n), t;
};
function GetKeyValueStrings(e)
{
for(var r = "", t = 0; t < e.length; t++)
{
var n = e.substr(t, 1);
if(" " !== n && "\n" !== n)
{
if(":" === n)
return {Key:r, Value:e.substr(t + 1)};
r += n;
}
}
throw "Error format Key:Value = " + e;
};
function GetAttributes(e)
{
for(var r = [], t = GetAttributeStrings(e), n = 0; n < t.length; n++)
{
var l = GetKeyValueStrings(t[n]);
r.push(l);
}
return r;
};
module.exports.GetNewBuffer = GetNewBuffer, module.exports.GetReadBuffer = GetReadBuffer, module.exports.alloc = GetNewBuffer,
module.exports.from = GetReadBuffer, module.exports.Write = Write, module.exports.Read = Read, module.exports.GetObjectFromBuffer = GetObjectFromBuffer,
module.exports.GetBufferFromObject = GetBufferFromObject;

204
src/core/code.ts Normal file
View File

@ -0,0 +1,204 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
"use strict";
import * as fs from 'fs'
const FORMAT_EVAL_SEND = "{MaxBlockNum:uint,Code:str,Sign:arr64}";
module.exports = class CCode extends require("./base")
{
LastEvalCodeNum
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
if (!global.ADDRLIST_MODE && !this.VirtualMode) {
setInterval(this.CheckLoadCodeTime.bind(this), 10 * 1000)
}
this.LastEvalCodeNum = 0
global.CheckCreateDir(global.GetDataPath("Update"))
}
CheckLoadCodeTime() {
if (global.START_LOAD_CODE.StartLoadNode && global.START_LOAD_CODE.StartLoadVersionNum) {
var Delta = (new Date() as any) - global.START_LOAD_CODE.StartLoadVersionNumTime;
if (Delta > 20 * 1000) {
global.ToError("Cannot load code version:" + global.START_LOAD_CODE.StartLoadVersionNum + " from node: " + global.START_LOAD_CODE.StartLoadNode.ip + ":" + global.START_LOAD_CODE.StartLoadNode.port)
this.ClearLoadCode()
}
}
}
ClearLoadCode() {
global.START_LOAD_CODE.StartLoad = undefined
global.START_LOAD_CODE.StartLoadVersionNum = 0
global.START_LOAD_CODE.StartLoadVersionNumTime = 0
}
StartLoadCode(Node, CodeVersion) {
var VersionNum = CodeVersion.VersionNum;
global.START_LOAD_CODE.StartLoad = CodeVersion
global.START_LOAD_CODE.StartLoadNode = Node
global.START_LOAD_CODE.StartLoadVersionNum = VersionNum
global.START_LOAD_CODE.StartLoadVersionNumTime = new Date()
var fname = global.GetDataPath("Update/wallet-" + VersionNum + ".zip");
if (fs.existsSync(fname)) {
this.UseCode(VersionNum, false)
return;
}
var Context = { "VersionNum": VersionNum };
this.SendF(Node, { "Method": "GETCODE", "Context": Context, "Data": VersionNum })
}
static
GETCODE_F() {
return "uint";
}
RETCODE(Info) {
var VersionNum = Info.Context.VersionNum;
if (!VersionNum || !global.START_LOAD_CODE.StartLoad)
return;
var fname = global.GetDataPath("Update/wallet-" + VersionNum + ".zip");
if (!fs.existsSync(fname)) {
var Hash = global.shaarr(Info.Data);
if (global.CompareArr(Hash, global.START_LOAD_CODE.StartLoad.Hash) === 0) {
var file_handle = fs.openSync(fname, "w");
fs.writeSync(file_handle, Info.Data, 0, Info.Data.length)
fs.closeSync(file_handle)
this.UseCode(VersionNum, global.USE_AUTO_UPDATE)
}
else {
global.ToError("Error check hash of version code :" + global.START_LOAD_CODE.StartLoadVersionNum + " from node: " + Info.Node.ip + ":" + Info.Node.port)
this.ClearLoadCode()
this.AddCheckErrCount(Info.Node, 1, "Error check hash of version code")
}
}
}
UseCode(VersionNum, bUpdate) {
if (bUpdate) {
UpdateCodeFiles(VersionNum)
}
if (global.global.START_LOAD_CODE.StartLoad) {
global.CODE_VERSION = global.START_LOAD_CODE.StartLoad
this.ClearLoadCode()
}
}
SetNewCodeVersion(Data, PrivateKey) {
var fname = global.GetDataPath("ToUpdate/wallet.zip");
if (fs.existsSync(fname)) {
var fname2 = global.GetDataPath("Update/wallet-" + Data.VersionNum + ".zip");
if (fs.existsSync(fname2)) {
fs.unlinkSync(fname2)
}
var data = fs.readFileSync(fname);
var Hash = global.shaarr(data);
var file_handle = fs.openSync(fname2, "w");
fs.writeSync(file_handle, data, 0, data.length)
fs.closeSync(file_handle)
var SignArr = arr2(Hash, GetArrFromValue(Data.VersionNum));
var Sign = secp256k1.sign(SHA3BUF(SignArr), PrivateKey).signature;
global.CODE_VERSION = Data
global.CODE_VERSION.Hash = Hash
global.CODE_VERSION.Sign = Sign
return "OK Set new code version=" + Data.VersionNum;
}
else {
return "File not exist: " + fname;
}
}
};
function UpdateCodeFiles(StartNum) {
var fname = global.GetDataPath("Update");
if (!fs.existsSync(fname))
return 0;
var arr = fs.readdirSync(fname);
var arr2 = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i].substr(0, 7) === "wallet-") {
arr2.push(parseInt(arr[i].substr(7)));
}
}
arr2.sort(function(a, b) {
return a - b;
});
for (var i = 0; i < arr2.length; i++) {
var Num = arr2[i];
var Name = "wallet-" + Num + ".zip";
var Path = fname + "/" + Name;
global.ToLog("Check file:" + Name);
if (fs.existsSync(Path)) {
if (StartNum === Num) {
global.ToLog("UnpackCodeFile:" + Name);
UnpackCodeFile(Path);
if (StartNum % 2 === 0) {
global.RestartNode(1);
}
else {
}
return 1;
}
else {
global.ToLog("Delete old file update:" + Name);
fs.unlinkSync(Path);
}
}
}
return 0;
};
global.UnpackCodeFile = UnpackCodeFile;
function UnpackCodeFile(fname) {
var data = fs.readFileSync(fname);
var reader = ZIP.Reader(data);
reader.forEach(function(entry) {
var Name = entry.getName();
var Path = GetCodePath(Name);
if (entry.isFile()) {
var buf = entry.getData();
global.CheckCreateDir(Path, true, true);
var file_handle = fs.openSync(Path, "w");
fs.writeSync(file_handle, buf, 0, buf.length);
fs.closeSync(file_handle);
}
else {
}
});
reader.close();
};
global.RestartNode = function RestartNode(bForce) {
global.NeedRestart = 1;
setTimeout(DoExit, 5000);
if (global.nw || global.NWMODE) {
} else {
StopChildProcess();
global.ToLog("********************************** FORCE RESTART!!!");
return;
}
if (this.ActualNodes) {
var it = this.ActualNodes.iterator(), Node;
while ((Node = it.next()) !== null) {
if (Node.Socket)
CloseSocket(Node.Socket, "Restart");
}
}
this.StopServer();
this.StopNode();
StopChildProcess();
global.ToLog("****************************************** RESTART!!!");
global.ToLog("EXIT 1");
};
function DoExit() {
global.ToLog("EXIT 2");
if (global.nw || global.NWMODE) {
global.ToLog("RESTART NW");
var StrRun = '"' + process.argv[0] + '" .\n';
StrRun += '"' + process.argv[0] + '" .\n';
SaveToFile("run-next.bat", StrRun);
const child_process = require('child_process');
child_process.exec("run-next.bat", { shell: true });
}
global.ToLog("EXIT 3");
process.exit(0);
};

1372
src/core/connect.ts Normal file

File diff suppressed because it is too large Load Diff

352
src/core/constant.ts Normal file
View File

@ -0,0 +1,352 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
global.UPDATE_CODE_VERSION_NUM = 1102;
global.MIN_CODE_VERSION_NUM = 1094;
global.MINING_VERSION_NUM = 0;
global.InitParamsArg = InitParamsArg;
global.CONST_NAME_ARR = [
"AUTO_CORRECT_TIME",
"DELTA_CURRENT_TIME",
"COMMON_KEY",
"NODES_NAME",
"SERVER_PRIVATE_KEY_HEX",
"USE_NET_FOR_SERVER_ADDRES",
"NET_WORK_MODE",
"STAT_MODE",
"MAX_STAT_PERIOD",
"LISTEN_IP",
"HTTP_PORT_NUMBER",
"HTTP_PORT_PASSWORD",
"HTTP_IP_CONNECT",
"WALLET_NAME",
"WALLET_DESCRIPTION",
"USE_HARD_API_V2",
"COUNT_VIEW_ROWS",
"USE_HINT",
"ALL_VIEW_ROWS",
"ALL_LOG_TO_CLIENT",
"LOG_LEVEL",
"USE_MINING",
"MINING_START_TIME",
"MINING_PERIOD_TIME",
"POW_MAX_PERCENT",
"COUNT_MINING_CPU",
"SIZE_MINING_MEMORY",
"POW_RUN_COUNT",
"USE_AUTO_UPDATE",
"RESTART_PERIOD_SEC",
"MAX_GRAY_CONNECTIONS_TO_SERVER",
"TRANSACTION_PROOF_COUNT",
"UPDATE_NUM_COMPLETE",
"LIMIT_SEND_TRAFIC",
"WATCHDOG_DEV",
"ADDRLIST_MODE",
"CheckPointDelta",
"MIN_VER_STAT",
"DEBUG_WALLET",
"HTTP_HOSTING_PORT",
"HTTPS_HOSTING_DOMAIN",
"HTTP_MAX_COUNT_ROWS",
"HTTP_ADMIN_PASSORD",
"WATCHDOG_BADACCOUNT",
"RESYNC_CONDITION",
"MAX_CONNECTIONS_COUNT",
"TRUST_PROCESS_COUNT",
"REST_START_COUNT",
"LOAD_TO_BEGIN"
];
global.NODES_DELTA_CALC_HOUR = 4;
global.USE_HARD_API_V2 = 0;
global.USE_TICKET = 0;
global.USE_CHECK_SENDING = 1;
global.USE_LEVEL_WAY = 0;
global.TR_TICKET_HASH_LENGTH = 10;
global.BLOCKNUM_TICKET_ALGO = 16070000;
global.WATCHDOG_BADACCOUNT = 1;
global.WATCHDOG_DEV = 0;
global.RESYNC_CONDITION = { "OWN_BLOCKS": 20, "K_POW": 5 };
global.REST_BLOCK_SCALE = 1000;
global.REST_START_COUNT = 10000;
global.LOAD_TO_BEGIN = 2;
global.DEBUG_WALLET = 0;
global.CHECK_GLOBAL_TIME = 1;
global.AUTO_CORRECT_TIME = 1;
global.DELTA_CURRENT_TIME = 0;
global.NODES_NAME = "";
global.COMMON_KEY = "";
global.SERVER_PRIVATE_KEY_HEX = undefined;
global.USE_NET_FOR_SERVER_ADDRES = 1;
global.NET_WORK_MODE = undefined;
global.STAT_MODE = 0;
global.MAX_STAT_PERIOD = 1 * 3600;
global.UPDATE_NUM_COMPLETE = 0;
global.WALLET_NAME = "TERA";
global.WALLET_DESCRIPTION = "";
global.USE_MINING = 0;
global.POW_MAX_PERCENT = 50;
global.POW_RUN_COUNT = 5000;
global.POWRunPeriod = 1;
global.CheckPointDelta = 20;
global.ALL_LOG_TO_CLIENT = 1;
global.LOG_LEVEL = 1;
global.LIMIT_SEND_TRAFIC = 0;
global.COUNT_VIEW_ROWS = 20;
global.MIN_VER_STAT = 0;
global.STOPGETBLOCK = 0;
global.RESTART_PERIOD_SEC = 0;
global.HARD_PACKET_PERIOD120 = 160;
global.MINING_START_TIME = "";
global.MINING_PERIOD_TIME = "";
global.CHECK_RUN_MINING = 21 * 1000;
global.CHECK_STOP_CHILD_PROCESS = 10 * 1000;
global.COUNT_MINING_CPU = 0;
global.SIZE_MINING_MEMORY = 0;
global.HTTP_HOSTING_PORT = 0;
global.HTTPS_HOSTING_DOMAIN = "";
global.HTTP_MAX_COUNT_ROWS = 20;
global.HTTP_ADMIN_PASSORD = "";
require("./startlib.js");
global.MIN_POWER_POW_HANDSHAKE = 12;
global.USE_HINT = 0;
global.ALL_VIEW_ROWS = 0;
global.COUNT_BLOCK_PROOF = 300;
global.COUNT_NODE_PROOF = 10;
global.MIN_POWER_POW_MSG = 2;
global.MEM_POOL_MSG_COUNT = 1000;
global.MAX_LEVEL_SPECIALIZATION = 24;
global.MIN_CONNECT_CHILD = 2;
global.MAX_CONNECT_CHILD = 7;
global.MAX_CONNECTIONS_COUNT = 1000;
global.TRUST_PROCESS_COUNT = 80000;
global.MAX_NODES_RETURN = 100;
global.MAX_WAIT_PERIOD_FOR_STATUS = 10 * 1000;
global.MAX_GRAY_CONNECTIONS_TO_SERVER = 10;
global.MAX_PACKET_LENGTH = 450 * 1024;
global.COUNT_BLOCKS_FOR_LOAD = 600;
global.TR_LEN = 100;
global.BLOCK_PROCESSING_LENGTH = 8;
global.BLOCK_PROCESSING_LENGTH2 = global.BLOCK_PROCESSING_LENGTH * 2;
global.CONSENSUS_PERIOD_TIME = 1000;
global.MAX_BLOCK_SIZE = 130 * 1024;
global.MAX_TRANSACTION_SIZE = 65535;
global.MIN_TRANSACTION_SIZE = 32;
global.MAX_TRANSACTION_COUNT = 2000;
global.MAX_TRANSACTION_LIMIT = 250;
global.MIN_POWER_POW_TR = 10;
if (global.MIN_POWER_POW_BL === undefined)
global.MIN_POWER_POW_BL = 5;
global.GENERATE_BLOCK_ACCOUNT = 0;
global.TOTAL_SUPPLY_TERA = 1e9;
global.TRANSACTION_PROOF_COUNT = 1000 * 1000;
global.MIN_POWER_POW_ACC_CREATE = 16;
global.START_MINING = 2 * 1000 * 1000;
global.REF_PERIOD_MINING = 1 * 1000 * 1000;
global.DELTA_BLOCK_ACCOUNT_HASH = 1000;
global.PERIOD_ACCOUNT_HASH = 50;
global.START_BLOCK_ACCOUNT_HASH = 14500000;
global.START_BLOCK_ACCOUNT_HASH3 = 24015000;
global.NEW_ACCOUNT_INCREMENT = 22305000;
global.NEW_BLOCK_REWARD1 = 22500000;
global.NEW_FORMULA_START = 32000000;
global.NEW_FORMULA_KTERA = 3;
global.NEW_FORMULA_TARGET1 = 43000000;
global.NEW_FORMULA_TARGET2 = 45000000;
global.BLOCK_COUNT_IN_MEMORY = 40;
global.HISTORY_BLOCK_COUNT = 40;
global.MAX_SIZE_LOG = 200 * 1024 * 1024;
global.READ_ONLY_DB = 0;
global.USE_CHECK_SAVE_DB = 1;
global.START_NETWORK_DATE = 1530446400000;
global.NETWORK = "TERA-MAIN";
global.DEF_MAJOR_VERSION = "0001";
global.SMART_BLOCKNUM_START = 10000000;
global.PRICE_DAO = function(BlockNum) {
return { NewAccount: 10, NewSmart: 100, NewTokenSmart: 10000 };
};
if (global.LOCAL_RUN) {
var Num = Date.now() - 300 * 1000;
global.START_NETWORK_DATE = Math.trunc(Num / 1000) * 1000;
}
global.NEW_SIGN_TIME = 25500000;
InitParamsArg();
if (global.LOCAL_RUN) {
global.REST_BLOCK_SCALE = 100;
global.DELTA_BLOCK_ACCOUNT_HASH = 30;
global.PERIOD_ACCOUNT_HASH = 10;
global.START_BLOCK_ACCOUNT_HASH = 1;
global.START_BLOCK_ACCOUNT_HASH3 = 1;
global.BLOCKNUM_TICKET_ALGO = 1;
global.SMART_BLOCKNUM_START = 0;
global.START_MINING = 60;
global.REF_PERIOD_MINING = 10;
global.TEST_TRANSACTION_GENERATE = 0;
global.MIN_POWER_POW_TR = 8;
global.MIN_POWER_POW_ACC_CREATE = 8;
global.NEW_ACCOUNT_INCREMENT = 1;
global.NEW_BLOCK_REWARD1 = 1;
global.NEW_FORMULA_START = 1;
global.NEW_FORMULA_KTERA = 3;
global.NEW_FORMULA_TARGET1 = 0;
global.NEW_FORMULA_TARGET2 = 1;
NETWORK = "LOCAL";
global.ALL_VIEW_ROWS = 1;
global.COUNT_NODE_PROOF = 1;
global.NEW_SIGN_TIME = 0;
}
else
if (global.TEST_NETWORK) {
global.REST_BLOCK_SCALE = 100;
var Num = Date.now() - 50 * 1000;
console.log("CURRENT NUM: " + (Math.trunc(Num / 1000) * 1000));
global.SMART_BLOCKNUM_START = 0;
global.START_NETWORK_DATE = 1550843168000 + 1000 * 1000;
global.START_MINING = 1000;
global.REF_PERIOD_MINING = 1000;
global.MIN_POWER_POW_ACC_CREATE = 8;
global.TRANSACTION_PROOF_COUNT = 200 * 1000;
global.MAX_SIZE_LOG = 20 * 1024 * 1024;
global.START_BLOCK_ACCOUNT_HASH = 1000;
global.START_BLOCK_ACCOUNT_HASH3 = 2356000;
global.BLOCKNUM_TICKET_ALGO = 1;
global.WALLET_NAME = "TEST";
NETWORK = "TERA-TEST2";
if (global.START_PORT_NUMBER === undefined)
global.START_PORT_NUMBER = 40000;
global.ALL_VIEW_ROWS = 1;
global.NEW_ACCOUNT_INCREMENT = 1903000;
global.NEW_BLOCK_REWARD1 = 1905000;
global.NEW_FORMULA_START = 11402000;
global.NEW_FORMULA_KTERA = 3;
global.NEW_FORMULA_TARGET1 = 11403000;
global.NEW_FORMULA_TARGET2 = 11405000;
global.COUNT_NODE_PROOF = 8;
global.REST_START_COUNT = 10000;
global.NEW_SIGN_TIME = 4859000;
}
if (global.LOCAL_RUN) {
global.BLOCKNUM_TICKET_ALGO = 0;
global.MIN_POWER_POW_TR = 0;
global.AUTO_CORRECT_TIME = 0;
global.CHECK_GLOBAL_TIME = 0;
}
global.GetNetworkName = function() {
return NETWORK + "-" + global.DEF_MAJOR_VERSION;
};
global.DEF_VERSION = global.DEF_MAJOR_VERSION + "." + global.UPDATE_CODE_VERSION_NUM;
global.DEF_CLIENT = "TERA-CORE";
global.FIRST_TIME_BLOCK = global.START_NETWORK_DATE;
global.START_BLOCK_RUN = 0;
if (global.START_IP === undefined)
global.START_IP = "";
if (global.LISTEN_IP === undefined)
global.LISTEN_IP = "0.0.0.0";
if (global.START_PORT_NUMBER === undefined)
global.START_PORT_NUMBER = 30000;
if (global.HTTP_PORT_PASSWORD === undefined)
global.HTTP_PORT_PASSWORD = "";
if (global.HTTP_IP_CONNECT === undefined)
global.HTTP_IP_CONNECT = "";
if (global.USE_AUTO_UPDATE === undefined)
global.USE_AUTO_UPDATE = 1;
if (global.USE_PARAM_JS === undefined)
global.USE_PARAM_JS = 1;
if (global.DATA_PATH === undefined)
global.DATA_PATH = "";
if (global.CREATE_ON_START === undefined)
global.CREATE_ON_START = false;
if (global.LOCAL_RUN === undefined)
global.LOCAL_RUN = 0;
if (global.CODE_PATH === undefined)
global.CODE_PATH = process.cwd();
if (global.DEBUG_MODE === undefined)
global.DEBUG_MODE = 0;
global.DEBUG_MODE = 0;
if (typeof window === 'object') {
window.RUN_CLIENT = 0;
window.RUN_SERVER = 1;
}
global.RUN_CLIENT = 0;
global.RUN_SERVER = 1;
function InitParamsArg() {
for (var i = 1; i < process.argv.length; i++) {
var str0 = process.argv[i];
var str = str0.toUpperCase();
if (str.substr(0, 9) == "HTTPPORT:") {
global.HTTP_PORT_NUMBER = parseInt(str.substr(9));
}
else
if (str.substr(0, 9) == "PASSWORD:") {
global.HTTP_PORT_PASSWORD = str0.substr(9);
}
else
if (str.substr(0, 5) == "PATH:")
global.DATA_PATH = str0.substr(5);
else
if (str.substr(0, 5) == "PORT:")
global.START_PORT_NUMBER = parseInt(str.substr(5));
else
if (str.substr(0, 3) == "IP:")
global.START_IP = str.substr(3);
else
if (str.substr(0, 7) == "LISTEN:")
global.LISTEN_IP = str.substr(7);
else
if (str.substr(0, 8) == "HOSTING:") {
global.HTTP_HOSTING_PORT = parseInt(str.substr(8));
}
else
if (str.substr(0, 13) == "STARTNETWORK:") {
global.START_NETWORK_DATE = parseInt(str.substr(13));
console.log("START_NETWORK_DATE: " + global.START_NETWORK_DATE);
}
else {
switch (str) {
case "CHILDPOW":
global.CHILD_POW = true;
break;
case "ADDRLIST":
global.ADDRLIST_MODE = true;
break;
case "CREATEONSTART":
global.CREATE_ON_START = true;
break;
case "LOCALRUN":
global.LOCAL_RUN = 1;
break;
case "TESTRUN":
global.TEST_NETWORK = 1;
break;
case "NOLOCALRUN":
global.LOCAL_RUN = 0;
break;
case "NOAUTOUPDATE":
global.USE_AUTO_UPDATE = 0;
break;
case "NOPARAMJS":
global.USE_PARAM_JS = 0;
break;
case "READONLYDB":
global.READ_ONLY_DB = 1;
break;
case "NWMODE":
global.NWMODE = 1;
break;
case "NOALIVE":
global.NOALIVE = 1;
break;
case "DEV_MODE":
global.DEV_MODE = 1;
break;
}
}
}
};

993
src/core/crypto-library.ts Normal file
View File

@ -0,0 +1,993 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
require("./library.js");
import * as crypto from 'crypto'
let {
sha3,
secp256k1,
SHA3BUF,
GetSignHash,
shaarr,
ToLog
} = global
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
var BuferForStr = Buffer.alloc(32);
global.GetHexFromAddres = function(arr) {
if (!arr)
return "";
if (arr.data !== undefined)
arr = arr.data;
for (var i = 0; i < 32; i++)
BuferForStr[i] = arr[i];
return BuferForStr.toString('hex').toUpperCase();
};
global.GetArr32FromHex = function(Str) {
var array = new Uint8Array(32);
for (var i = 0; i < array.length; i++) {
array[i] = parseInt(Str.substr(i * 2, 2), 16);
}
return array;
};
global.GetAddresFromHex = global.GetArr32FromHex;
global.GetHexAddresFromPublicKey = function(arr) {
return Buffer.from(arr.slice(1)).toString('hex').toUpperCase();
};
global.GetHexFromArr = function(arr) {
if (!arr)
return "";
else
return Buffer.from(arr).toString('hex').toUpperCase();
};
function GetArrFromHex(Str) {
var array = [];
for (var i = 0; i < Str.length / 2; i++) {
array[i] = parseInt(Str.substr(i * 2, 2), 16);
}
return array;
};
global.GetArrFromHex = GetArrFromHex;
global.GetHexFromArrBlock = function(Arr, LenBlock) {
var Str = "";
var Arr2 = [];
for (var i = 0; i < Arr.length; i++) {
Arr2[i % LenBlock] = Arr[i];
if (Arr2.length >= LenBlock) {
Str += global.GetHexFromArr(Arr2) + "\n";
Arr2 = [];
}
}
if (Arr2.length) {
Str += global.GetHexFromArr(Arr2);
}
return Str;
};
global.GetPublicKeyFromAddres = function(Arr) {
var RetArr = new Uint8Array(33);
RetArr[0] = 2;
for (var i = 1; i < 33; i++)
RetArr[i] = Arr[i - 1];
return RetArr;
};
global.CheckDevelopSign = function(SignArr, Sign) {
var hash = SHA3BUF(SignArr);
for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++) {
var Result = secp256k1.verify(hash, Buffer.from(Sign), DEVELOP_PUB_KEY_ARR[i]);
if (Result)
return 1;
}
return 0;
};
let GetPublicKeyFromAddres = global.GetPublicKeyFromAddres;
global.CheckContextSecret = function(Context, ContextAddrTo) {
if (ContextAddrTo.Secret === undefined) {
if (ContextAddrTo.publickey === undefined) {
ContextAddrTo.publickey = GetPublicKeyFromAddres(ContextAddrTo.addrArr);
}
ContextAddrTo.Secret = Context.KeyPair.computeSecret(ContextAddrTo.publickey, null);
}
};
let CheckContextSecret = global.CheckContextSecret;
global.GetSignHash = function(Context, ContextAddrTo, Msg) {
CheckContextSecret(Context, ContextAddrTo);
if (typeof Msg === "string")
Msg = Buffer.from(Msg);
var Buf = Buffer.concat([Msg, ContextAddrTo.Secret], Msg.length + ContextAddrTo.Secret.length);
var Arr = global.shaarr(Buf);
return Arr;
};
global.GetVerifyHash = function(Context, ContextAddr, Msg, Sign1) {
try {
var Sign2 = GetSignHash(Context, ContextAddr, Msg);
for (var i = 0; i < Sign1.length; i++)
if (Sign1[i] !== Sign2[i])
return false;
return true;
}
catch (e) {
return false;
}
};
global.GetKeyPair = function(password, secret, startnonce1, startnonce2) {
secret = secret || "low";
startnonce1 = startnonce1 || 0;
startnonce2 = startnonce2 || 0;
var KeyPair: any = crypto.createECDH('secp256k1');
var private1 = global.shaarr(password);
var private2 = private1;
var nonce1 = 0;
if (secret === "high")
for (nonce1 = startnonce1; nonce1 < 2000000000; nonce1++) {
private1[31] = nonce1 & 0xFF;
private1[30] = (nonce1 >>> 8) & 0xFF;
private1[29] = (nonce1 >>> 16) & 0xFF;
private1[28] = (nonce1 >>> 24) & 0xFF;
private2 = global.shaarr(private1);
if (private2[0] === 0 && private2[1] === 0 && private2[2] === 0) {
break;
}
nonce1++;
}
var nonce2;
for (nonce2 = startnonce2; nonce2 < 2000000000; nonce2++) {
private2[31] = nonce2 & 0xFF;
private2[30] = (nonce2 >>> 8) & 0xFF;
private2[29] = (nonce2 >>> 16) & 0xFF;
private2[28] = (nonce2 >>> 24) & 0xFF;
KeyPair.setPrivateKey(Buffer.from(private2));
var Data = KeyPair.getPublicKey('', 'compressed');
if (Data[0] === 2 && Data[31] === 0 && Data[32] === 0) {
KeyPair.nonce1 = nonce1;
KeyPair.nonce2 = nonce2;
KeyPair.PubKeyArr = KeyPair.getPublicKey('', 'compressed');
KeyPair.addrArr = KeyPair.PubKeyArr.slice(1);
KeyPair.addrStr = global.GetHexFromArr(KeyPair.addrArr);
KeyPair.addr = KeyPair.addrArr;
return KeyPair;
}
nonce2++;
}
throw "ERROR. Key pair not found. Try another password!";
};
global.GetKeyPairTest = function(password, Power) {
var KeyPair: any = crypto.createECDH('secp256k1');
var private2 = global.shaarr(password);
for (var nonce2 = 0; nonce2 < 1000000000; nonce2++) {
private2[31] = nonce2 & 0xFF;
private2[30] = (nonce2 >> 8) & 0xFF;
private2[29] = (nonce2 >> 16) & 0xFF;
private2[28] = (nonce2 >> 24) & 0xFF;
KeyPair.setPrivateKey(Buffer.from(private2));
var Data = KeyPair.getPublicKey('', 'compressed');
if (Data[0] === 2) {
if (Power) {
var nBits = GetPowPower(Data.slice(1));
if (nBits < Power)
continue;
}
KeyPair.PubKeyArr = Data;
KeyPair.addrArr = KeyPair.PubKeyArr.slice(1);
KeyPair.addrStr = global.GetHexFromArr(KeyPair.addrArr);
KeyPair.addr = KeyPair.addrArr;
return KeyPair;
}
}
throw "ERROR. Key pair not found. Try another password!";
};
function GetArrFromValue(Num) {
var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
arr[0] = Num & 0xFF;
arr[1] = (Num >>> 8) & 0xFF;
arr[2] = (Num >>> 16) & 0xFF;
arr[3] = (Num >>> 24) & 0xFF;
var NumH = Math.floor(Num / 4294967296);
arr[4] = NumH & 0xFF;
arr[5] = (NumH >>> 8) & 0xFF;
return arr;
};
function GetHashWithNonce(hash0, nonce) {
return shaarr2(hash0, GetArrFromValue(nonce));
};
global.GetHashWithValues = GetHashWithValues;
function GetHashWithValues(hash0, value1, value2, bNotCopy) {
var hash;
if (bNotCopy)
hash = hash0;
else
hash = hash0.slice();
hash[0] = value1 & 0xFF;
hash[1] = (value1 >>> 8) & 0xFF;
hash[2] = (value1 >>> 16) & 0xFF;
hash[3] = (value1 >>> 24) & 0xFF;
hash[4] = value2 & 0xFF;
hash[5] = (value2 >>> 8) & 0xFF;
hash[6] = (value2 >>> 16) & 0xFF;
hash[7] = (value2 >>> 24) & 0xFF;
var arrhash = global.shaarr(hash);
return arrhash;
};
function GetPowPower(arrhash) {
var SumBit = 0;
if (arrhash)
for (var i = 0; i < arrhash.length; i++) {
var CurSum = Math.clz32(arrhash[i]) - 24;
SumBit += CurSum;
if (CurSum !== 8)
break;
}
return SumBit;
};
function GetPowValue(arrhash) {
var value = (arrhash[0] << 23) * 2 + (arrhash[1] << 16) + (arrhash[2] << 8) + arrhash[3];
value = value * 256 + arrhash[4];
value = value * 256 + arrhash[5];
return value;
};
global.CreateNoncePOWExtern = CreateNoncePOWExtern;
function CreateNoncePOWExtern(arr0, BlockNum, count, startnone) {
var arr = [];
for (var i = 0; i < arr0.length; i++)
arr[i] = arr0[i];
if (!startnone)
startnone = 0;
var maxnonce = 0;
var supervalue = MAX_SUPER_VALUE_POW;
for (var nonce = startnone; nonce <= startnone + count; nonce++) {
var arrhash = GetHashWithValues(arr, nonce, BlockNum, true);
var value = GetPowValue(arrhash);
if (value < supervalue) {
maxnonce = nonce;
supervalue = value;
}
}
return maxnonce;
};
global.CreateNoncePOWExternMinPower = CreateNoncePOWExternMinPower;
function CreateNoncePOWExternMinPower(arr0, BlockNum, MinPow) {
var arr = [];
for (var i = 0; i < arr0.length; i++)
arr[i] = arr0[i];
var nonce = 0;
while (1) {
var arrhash = GetHashWithValues(arr, nonce, BlockNum, true);
var power = GetPowPower(arrhash);
if (power >= MinPow) {
return nonce;
}
nonce++;
}
};
global.CreateNoncePOWInner = function(arr0, count) {
var Hash;
var arr = arr0.slice();
var maxnonce = 0;
var supervalue = MAX_SUPER_VALUE_POW;
for (var nonce = 0; nonce < count; nonce++) {
var hashTest = GetHashWithNonce(arr, nonce);
var value = GetPowValue(hashTest);
if (value < supervalue) {
maxnonce = nonce;
supervalue = value;
Hash = hashTest;
}
}
return { nonce: maxnonce, Hash: Hash };
};
global.CreateAddrPOW = function(SeqHash, AddrArr, MaxHash, Start, CountNonce, BlockNum) {
var MaxNonce = 0;
var bFind = 0;
for (var nonce = Start; nonce < Start + CountNonce; nonce++) {
AddrArr[6] = nonce & 0xFF;
AddrArr[7] = (nonce >>> 8) & 0xFF;
AddrArr[8] = (nonce >>> 16) & 0xFF;
AddrArr[9] = (nonce >>> 24) & 0xFF;
var HashTest = shaarrblock2(SeqHash, AddrArr, BlockNum);
if (global.CompareArr(MaxHash, HashTest) >= 0) {
MaxHash = HashTest;
MaxNonce = nonce;
bFind = 1;
}
}
if (bFind) {
AddrArr[6] = MaxNonce & 0xFF;
AddrArr[7] = (MaxNonce >>> 8) & 0xFF;
AddrArr[8] = (MaxNonce >>> 16) & 0xFF;
AddrArr[9] = (MaxNonce >>> 24) & 0xFF;
}
return { MaxHash: MaxHash, LastNonce: nonce, MaxNonce: MaxNonce, bFind: bFind };
};
function IsZeroArr(arr) {
if (arr)
for (var i = 0; i < arr.length; i++) {
if (arr[i])
return false;
}
return true;
};
function CalcHashFromArray(ArrHashes, bOriginalSeq) {
if (bOriginalSeq === undefined)
ArrHashes.sort(CompareArr);
var Buf = [];
for (var i = 0; i < ArrHashes.length; i++) {
var Value = ArrHashes[i];
for (var n = 0; n < Value.length; n++)
Buf.push(Value[n]);
}
if (Buf.length === 0)
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else
if (Buf.length === 32)
return Buf;
var Hash = global.shaarr(Buf);
return Hash;
};
function CalcHash3FromArray(ArrHashes, bOriginalSeq) {
if (bOriginalSeq === undefined)
ArrHashes.sort(CompareArr);
var Buf = [];
for (var i = 0; i < ArrHashes.length; i++) {
var Value = ArrHashes[i];
for (var n = 0; n < Value.length; n++)
Buf.push(Value[n]);
}
if (Buf.length === 0)
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else
if (Buf.length === 32)
return Buf;
var Hash = global.sha3(Buf);
return Hash;
};
function CalcMerkl3FromArray(Arr, Tree0?) {
var Tree, bSort;
if (Tree0) {
bSort = 0;
Tree = Tree0;
}
else {
bSort = 1;
Tree = { Levels: [], Full: true };
}
Tree.Levels.push(Arr);
if (Arr.length < 2) {
if (Arr.length === 0)
Tree.Root = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else {
if (Arr[0].length === 32)
Tree.Root = Arr[0];
else
Tree.Root = global.sha3(Arr[0]);
}
return Tree;
}
if (bSort) {
Arr.sort(CompareArr);
}
var Arr2 = [];
var len = Math.floor(Arr.length / 2);
for (var i = 0; i < len; i++) {
var Hash = sha3arr2(Arr[i * 2], Arr[i * 2 + 1]);
Arr2.push(Hash);
}
if (len * 2 !== Arr.length) {
Arr2.push(Arr[Arr.length - 1]);
}
return CalcMerkl3FromArray(Arr2, Tree);
};
function CalcMerkl0FromArray(Arr, Tree0?) {
var Tree, bSort;
if (Tree0) {
bSort = 0;
Tree = Tree0;
}
else {
bSort = 1;
Tree = { Levels: [], Full: true };
}
Tree.Levels.push(Arr);
if (Arr.length < 2) {
if (Arr.length === 0)
Tree.Root = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else {
if (Arr[0].length === 32)
Tree.Root = Arr[0];
else
Tree.Root = global.shaarr(Arr[0]);
}
return Tree;
}
if (bSort) {
Arr.sort(CompareArr);
}
var Arr2 = [];
var len = Math.floor(Arr.length / 2);
for (var i = 0; i < len; i++) {
var Hash = shaarr2(Arr[i * 2], Arr[i * 2 + 1]);
Arr2.push(Hash);
}
if (len * 2 !== Arr.length) {
Arr2.push(Arr[Arr.length - 1]);
}
return CalcMerkl0FromArray(Arr2, Tree);
};
function CalcMerklFromArray(BlockNum, Arr) {
if (BlockNum >= global.BLOCKNUM_TICKET_ALGO) {
return CalcMerkl3FromArray(Arr);
}
else {
return CalcMerkl0FromArray(Arr);
}
};
function CalcTreeHashFromArrBody(BlockNum, arrContent) {
if (arrContent) {
var arrHASH = [];
for (var i = 0; i < arrContent.length; i++) {
var HASH;
if (BlockNum >= global.BLOCKNUM_TICKET_ALGO)
HASH = global.sha3(arrContent[i]);
else
HASH = global.shaarr(arrContent[i]);
arrHASH.push(HASH);
}
var Tree = CalcMerklFromArray(BlockNum, arrHASH);
return Tree.Root;
}
else {
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
};
function TestMerklTree() {
var h1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var h2 = global.sha3("2");
var h3 = global.sha3("3");
var h4 = global.sha3("4");
var h5 = global.sha3("5");
var Tree: any = { RecalcCount: 0 };
var CalcMap = {};
Tree.LevelsHash = [[h1, h2]];
Tree.RecalcCount = 0;
CalcMap[0] = 1;
CalcMap[1] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
CalcMap = {};
Tree.LevelsHash[0] = [h1, h2, h3, h4];
Tree.RecalcCount = 0;
CalcMap[2] = 1;
CalcMap[3] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
CalcMap = {};
Tree.LevelsHash[0] = [h1, h2, h3];
Tree.RecalcCount = 0;
CalcMap[Tree.LevelsHash[0].length - 1] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
global.ToLog("Root=" + global.GetHexFromArr(Tree.Root));
global.ToLog("RecalcCount=" + Tree.RecalcCount);
return Tree;
};
if (0)
setTimeout(function() {
TestMerkleProof(100);
global.ToLog("=========END=========");
process.exit(0);
});
function TestMerkleProof(CountTest) {
for (var R = 0; R < CountTest; R++) {
var CountItems = Math.floor(Math.random() * CountTest);
var Tree: any = { RecalcCount: 0 };
var CalcMap = {};
Tree.LevelsHash = [];
Tree.LevelsHash[0] = [];
for (var i = 0; i < CountItems; i++) {
CalcMap[i] = 1;
Tree.LevelsHash[0][i] = global.sha3("" + i + "-" + R);
}
UpdateMerklTree(Tree, CalcMap, 0);
global.ToLog("Hash1=" + global.GetHexFromArr(Tree.Root) + " CountItems:" + CountItems);
var FirstNum = Math.floor(Math.random() * CountItems / 2);
var LastNum = Math.floor(CountItems / 2 + Math.random() * CountItems / 2);
var Ret = GetMerkleProof(Tree.LevelsHash, FirstNum, LastNum);
var ArrM = Tree.LevelsHash[0].slice(FirstNum, LastNum + 1);
var Hash2 = CheckMerkleProof(Ret.ArrL, ArrM, Ret.ArrR);
global.ToLog("Hash2=" + global.GetHexFromArr(Hash2) + " FirstNum=" + FirstNum + "/" + LastNum);
if (global.CompareArr(Tree.Root, Hash2) !== 0)
throw ("=========ERROR HASHTEST==============");
else
global.ToLog("=========OK==============");
}
};
function GetMerkleProof(LevelsHash, FirstNum, LastNum) {
var ArrL = [];
var ArrR = [];
var CurL = FirstNum;
var CurR = LastNum;
for (var L = 0; L < LevelsHash.length; L++) {
var LevelArr = LevelsHash[L];
if (CurL % 2 === 1)
ArrL[L] = LevelArr[CurL - 1];
if (CurR % 2 === 0 && CurR + 1 < LevelArr.length)
ArrR[L] = LevelArr[CurR + 1];
CurL = Math.floor(CurL / 2);
CurR = Math.floor(CurR / 2);
}
return { ArrL: ArrL, ArrR: ArrR };
};
function CheckMerkleProof(ArrL, ArrM, ArrR) {
var L = 0;
var Arr2 = ArrM;
while (true) {
var Arr = [].concat(Arr2);
if (ArrL[L])
Arr.unshift(ArrL[L]);
if (ArrR[L])
Arr.push(ArrR[L]);
if (Arr.length <= 1 && L >= ArrL.length && L >= ArrR.length) {
if (!Arr.length)
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
return Arr[0];
}
var length2 = Math.floor(Arr.length / 2);
Arr2 = [];
for (i = 0; i < length2; i++) {
var Hash = global.sha3(arr2(Arr[i * 2], Arr[i * 2 + 1]));
Arr2.push(Hash);
}
if (Arr.length / 2 > length2)
Arr2.push(Arr[Arr.length - 1]);
L++;
}
};
function UpdateMerklTree(Tree, CalcMap: any, NumLevel) {
var HashArr = Tree.LevelsHash[NumLevel];
if (!HashArr || !HashArr.length) {
Tree.LevelsHash.length = NumLevel + 1;
Tree.MaxLevel = NumLevel;
Tree.Root = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
else
if (HashArr.length === 1) {
Tree.LevelsHash.length = NumLevel + 1;
Tree.MaxLevel = NumLevel;
Tree.Root = HashArr[0];
}
else {
var CalcMap2 = {};
var HashArr2 = Tree.LevelsHash[NumLevel + 1];
if (!HashArr2) {
HashArr2 = [];
Tree.LevelsHash[NumLevel + 1] = HashArr2;
}
var len2 = Math.floor(HashArr.length / 2);
HashArr2.length = Math.floor(0.5 + HashArr.length / 2);
var Count = 0;
var LastIndex = HashArr.length - 1;
for (var key in CalcMap) {
var i2 = Math.floor(key as any / 2);
if (i2 < len2) {
Count++;
CalcMap2[i2] = 1;
HashArr2[i2] = global.sha3(arr2(HashArr[i2 * 2], HashArr[i2 * 2 + 1]));
}
else {
if (key as any > LastIndex) {
CalcMap2[i2] = 1;
}
else
if (i2 === len2) {
Count++;
CalcMap2[i2] = 1;
HashArr2[i2] = HashArr[key];
}
}
}
if (Count) {
Tree.RecalcCount += Count;
UpdateMerklTree(Tree, CalcMap2, NumLevel + 1);
}
}
};
var RC = [1, 0, 32898, 0, 32906, 2147483648, 2147516416, 2147483648, 32907, 0, 2147483649, 0, 2147516545, 2147483648, 32777,
2147483648, 138, 0, 136, 0, 2147516425, 0, 2147483658, 0, 2147516555, 0, 139, 2147483648, 32905, 2147483648, 32771, 2147483648,
32770, 2147483648, 128, 2147483648, 32778, 0, 2147483658, 2147483648, 2147516545, 2147483648, 32896, 2147483648, 2147483649,
0, 2147516424, 2147483648];
function Mesh(s, Count) {
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40,
b41, b42, b43, b44, b45, b46, b47, b48, b49;
for (n = 0; n < Count; n += 2) {
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
c3 = s[3] ^ s[13] ^ s[23] ^ s[33] ^ s[43];
c4 = s[4] ^ s[14] ^ s[24] ^ s[34] ^ s[44];
c5 = s[5] ^ s[15] ^ s[25] ^ s[35] ^ s[45];
c6 = s[6] ^ s[16] ^ s[26] ^ s[36] ^ s[46];
c7 = s[7] ^ s[17] ^ s[27] ^ s[37] ^ s[47];
c8 = s[8] ^ s[18] ^ s[28] ^ s[38] ^ s[48];
c9 = s[9] ^ s[19] ^ s[29] ^ s[39] ^ s[49];
h = c8 ^ ((c2 << 1) | (c3 >>> 31));
l = c9 ^ ((c3 << 1) | (c2 >>> 31));
s[0] ^= h;
s[1] ^= l;
s[10] ^= h;
s[11] ^= l;
s[20] ^= h;
s[21] ^= l;
s[30] ^= h;
s[31] ^= l;
s[40] ^= h;
s[41] ^= l;
h = c0 ^ ((c4 << 1) | (c5 >>> 31));
l = c1 ^ ((c5 << 1) | (c4 >>> 31));
s[2] ^= h;
s[3] ^= l;
s[12] ^= h;
s[13] ^= l;
s[22] ^= h;
s[23] ^= l;
s[32] ^= h;
s[33] ^= l;
s[42] ^= h;
s[43] ^= l;
h = c2 ^ ((c6 << 1) | (c7 >>> 31));
l = c3 ^ ((c7 << 1) | (c6 >>> 31));
s[4] ^= h;
s[5] ^= l;
s[14] ^= h;
s[15] ^= l;
s[24] ^= h;
s[25] ^= l;
s[34] ^= h;
s[35] ^= l;
s[44] ^= h;
s[45] ^= l;
h = c4 ^ ((c8 << 1) | (c9 >>> 31));
l = c5 ^ ((c9 << 1) | (c8 >>> 31));
s[6] ^= h;
s[7] ^= l;
s[16] ^= h;
s[17] ^= l;
s[26] ^= h;
s[27] ^= l;
s[36] ^= h;
s[37] ^= l;
s[46] ^= h;
s[47] ^= l;
h = c6 ^ ((c0 << 1) | (c1 >>> 31));
l = c7 ^ ((c1 << 1) | (c0 >>> 31));
s[8] ^= h;
s[9] ^= l;
s[18] ^= h;
s[19] ^= l;
s[28] ^= h;
s[29] ^= l;
s[38] ^= h;
s[39] ^= l;
s[48] ^= h;
s[49] ^= l;
b0 = s[0];
b1 = s[1];
b32 = (s[11] << 4) | (s[10] >>> 28);
b33 = (s[10] << 4) | (s[11] >>> 28);
b14 = (s[20] << 3) | (s[21] >>> 29);
b15 = (s[21] << 3) | (s[20] >>> 29);
b46 = (s[31] << 9) | (s[30] >>> 23);
b47 = (s[30] << 9) | (s[31] >>> 23);
b28 = (s[40] << 18) | (s[41] >>> 14);
b29 = (s[41] << 18) | (s[40] >>> 14);
b20 = (s[2] << 1) | (s[3] >>> 31);
b21 = (s[3] << 1) | (s[2] >>> 31);
b2 = (s[13] << 12) | (s[12] >>> 20);
b3 = (s[12] << 12) | (s[13] >>> 20);
b34 = (s[22] << 10) | (s[23] >>> 22);
b35 = (s[23] << 10) | (s[22] >>> 22);
b16 = (s[33] << 13) | (s[32] >>> 19);
b17 = (s[32] << 13) | (s[33] >>> 19);
b48 = (s[42] << 2) | (s[43] >>> 30);
b49 = (s[43] << 2) | (s[42] >>> 30);
b40 = (s[5] << 30) | (s[4] >>> 2);
b41 = (s[4] << 30) | (s[5] >>> 2);
b22 = (s[14] << 6) | (s[15] >>> 26);
b23 = (s[15] << 6) | (s[14] >>> 26);
b4 = (s[25] << 11) | (s[24] >>> 21);
b5 = (s[24] << 11) | (s[25] >>> 21);
b36 = (s[34] << 15) | (s[35] >>> 17);
b37 = (s[35] << 15) | (s[34] >>> 17);
b18 = (s[45] << 29) | (s[44] >>> 3);
b19 = (s[44] << 29) | (s[45] >>> 3);
b10 = (s[6] << 28) | (s[7] >>> 4);
b11 = (s[7] << 28) | (s[6] >>> 4);
b42 = (s[17] << 23) | (s[16] >>> 9);
b43 = (s[16] << 23) | (s[17] >>> 9);
b24 = (s[26] << 25) | (s[27] >>> 7);
b25 = (s[27] << 25) | (s[26] >>> 7);
b6 = (s[36] << 21) | (s[37] >>> 11);
b7 = (s[37] << 21) | (s[36] >>> 11);
b38 = (s[47] << 24) | (s[46] >>> 8);
b39 = (s[46] << 24) | (s[47] >>> 8);
b30 = (s[8] << 27) | (s[9] >>> 5);
b31 = (s[9] << 27) | (s[8] >>> 5);
b12 = (s[18] << 20) | (s[19] >>> 12);
b13 = (s[19] << 20) | (s[18] >>> 12);
b44 = (s[29] << 7) | (s[28] >>> 25);
b45 = (s[28] << 7) | (s[29] >>> 25);
b26 = (s[38] << 8) | (s[39] >>> 24);
b27 = (s[39] << 8) | (s[38] >>> 24);
b8 = (s[48] << 14) | (s[49] >>> 18);
b9 = (s[49] << 14) | (s[48] >>> 18);
s[0] = b0 ^ (~b2 & b4);
s[1] = b1 ^ (~b3 & b5);
s[10] = b10 ^ (~b12 & b14);
s[11] = b11 ^ (~b13 & b15);
s[20] = b20 ^ (~b22 & b24);
s[21] = b21 ^ (~b23 & b25);
s[30] = b30 ^ (~b32 & b34);
s[31] = b31 ^ (~b33 & b35);
s[40] = b40 ^ (~b42 & b44);
s[41] = b41 ^ (~b43 & b45);
s[2] = b2 ^ (~b4 & b6);
s[3] = b3 ^ (~b5 & b7);
s[12] = b12 ^ (~b14 & b16);
s[13] = b13 ^ (~b15 & b17);
s[22] = b22 ^ (~b24 & b26);
s[23] = b23 ^ (~b25 & b27);
s[32] = b32 ^ (~b34 & b36);
s[33] = b33 ^ (~b35 & b37);
s[42] = b42 ^ (~b44 & b46);
s[43] = b43 ^ (~b45 & b47);
s[4] = b4 ^ (~b6 & b8);
s[5] = b5 ^ (~b7 & b9);
s[14] = b14 ^ (~b16 & b18);
s[15] = b15 ^ (~b17 & b19);
s[24] = b24 ^ (~b26 & b28);
s[25] = b25 ^ (~b27 & b29);
s[34] = b34 ^ (~b36 & b38);
s[35] = b35 ^ (~b37 & b39);
s[44] = b44 ^ (~b46 & b48);
s[45] = b45 ^ (~b47 & b49);
s[6] = b6 ^ (~b8 & b0);
s[7] = b7 ^ (~b9 & b1);
s[16] = b16 ^ (~b18 & b10);
s[17] = b17 ^ (~b19 & b11);
s[26] = b26 ^ (~b28 & b20);
s[27] = b27 ^ (~b29 & b21);
s[36] = b36 ^ (~b38 & b30);
s[37] = b37 ^ (~b39 & b31);
s[46] = b46 ^ (~b48 & b40);
s[47] = b47 ^ (~b49 & b41);
s[8] = b8 ^ (~b0 & b2);
s[9] = b9 ^ (~b1 & b3);
s[18] = b18 ^ (~b10 & b12);
s[19] = b19 ^ (~b11 & b13);
s[28] = b28 ^ (~b20 & b22);
s[29] = b29 ^ (~b21 & b23);
s[38] = b38 ^ (~b30 & b32);
s[39] = b39 ^ (~b31 & b33);
s[48] = b48 ^ (~b40 & b42);
s[49] = b49 ^ (~b41 & b43);
s[0] ^= RC[n];
s[1] ^= RC[n + 1];
}
};
function WriteNumToArr0(body, Num) {
body[0] ^= Num & 0xFF;
body[1] ^= (Num >>> 8) & 0xFF;
body[2] ^= (Num >>> 16) & 0xFF;
body[3] ^= (Num >>> 24) & 0xFF;
};
function ClientHex(Str, nonce) {
var arr = [0, 0, 0, 0];
for (var i = 0; i < Str.length; i++)
arr[4 + i] = Str.charCodeAt(i);
WriteNumToArr0(arr, nonce);
Mesh(arr, 60);
return global.GetHexFromArr(arr) + "-" + nonce;
};
global.ClientHex = ClientHex;
var GlobalCryptID = 0;
var DeltaTimeCryptID = new Date(2018, 1, 1) as any - 0;
function Encrypt(Arr, Arr2, ArrSecret) {
const StartLen = 9;
var arrRnd: any = Buffer.alloc(StartLen);
GlobalCryptID++;
arrRnd.writeUInt32LE(GlobalCryptID, 1, 4);
var Time = Math.floor((Date.now() - DeltaTimeCryptID) / 1000);
arrRnd.writeUInt32LE(Time, 5, 4);
Arr2[0] = Arr[0];
for (var i = 1; i < StartLen; i++)
Arr2[i] = arrRnd[i];
var SecretBuf = Buffer.concat([Arr2.slice(0, StartLen), ArrSecret]);
DoSecret(Arr, Arr2, SecretBuf, 9);
};
function Decrypt(Arr, Arr2, ArrSecret) {
const StartLen = 9;
var SecretBuf = Buffer.concat([Arr.slice(0, StartLen), ArrSecret]);
DoSecret(Arr, Arr2, SecretBuf, StartLen);
};
function DoSecret(Arr, Arr2, SecretBuf, StartLen) {
var CryptID = SecretBuf.readUInt32LE(1, 4);
var Pos = StartLen;
while (Pos < Arr.length) {
var CurBuf = global.shaarr(SecretBuf);
for (var i = 0; i < 32 && Pos < Arr.length; i++ , Pos++) {
Arr2[Pos] = Arr[Pos] ^ CurBuf[i];
}
CryptID++;
SecretBuf.writeUInt32LE(CryptID, 5, 4);
}
};
function TestEncryptDecrypt() {
var ArrSecret = Buffer.from([1, 1, 1, 1, 1, 1]);
var Arr = GetArrFromStr(" Secret message", 64);
var Arr2 = Buffer.from(new Uint8Array(Arr.length));
var Arr3 = Buffer.from(new Uint8Array(Arr.length));
console.log("Message:");
console.log(Arr);
console.log("-------------------");
Encrypt(Arr, Arr2, ArrSecret);
console.log("Encrypt:");
console.log(Arr2);
console.log("-------------------");
Decrypt(Arr2, Arr3, ArrSecret);
console.log("Decrypt:");
console.log(Utf8ArrayToStr(Arr3.slice(9)));
};
function toUTF8Array(str) {
var utf8 = [];
for (var i = 0; str && i < str.length; i++) {
var charcode = str.charCodeAt(i);
if (charcode < 0x80)
utf8.push(charcode);
else
if (charcode < 0x800) {
utf8.push(0xc0 | (charcode >> 6), 0x80 | (charcode & 0x3f));
}
else
if (charcode < 0xd800 || charcode >= 0xe000) {
utf8.push(0xe0 | (charcode >> 12), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
}
else {
i++;
charcode = 0x10000 + (((charcode & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
utf8.push(0xf0 | (charcode >> 18), 0x80 | ((charcode >> 12) & 0x3f), 0x80 | ((charcode >> 6) & 0x3f), 0x80 | (charcode & 0x3f));
}
}
return utf8;
};
function Utf8ArrayToStr(array) {
var out, i, len, c;
var char2, char3;
out = "";
len = array.length;
i = 0;
while (i < len) {
c = array[i++];
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
out += String.fromCharCode(c);
break;
case 12:
case 13:
char2 = array[i++];
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
char2 = array[i++];
char3 = array[i++];
out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
break;
}
}
for (var i: any = 0; i < out.length; i++) {
if (out.charCodeAt(i) === 0) {
out = out.substr(0, i);
break;
}
}
return out;
};
function GetArr32FromStr(Str) {
return GetArrFromStr(Str, 32);
};
function GetArrFromStr(Str, Len) {
var arr = toUTF8Array(Str);
for (var i = arr.length; i < Len; i++) {
arr[i] = 0;
}
return arr.slice(0, Len);
};
global.CalcHash3FromArray = CalcHash3FromArray;
global.CalcHashFromArray = CalcHashFromArray;
global.CalcMerklFromArray = CalcMerklFromArray;
global.CalcTreeHashFromArrBody = CalcTreeHashFromArrBody;
global.UpdateMerklTree = UpdateMerklTree;
global.GetMerkleProof = GetMerkleProof;
global.CheckMerkleProof = CheckMerkleProof;
global.IsZeroArr = IsZeroArr;
global.GetHashWithNonce = GetHashWithNonce;
global.GetPowPower = GetPowPower;
global.GetArrFromValue = GetArrFromValue;
global.GetPowValue = GetPowValue;
global.Mesh = Mesh;
global.Encrypt = Encrypt;
global.Decrypt = Decrypt;
global.toUTF8Array = toUTF8Array;
global.Utf8ArrayToStr = Utf8ArrayToStr;
global.GetArrFromStr = GetArrFromStr;
global.IsDeveloperAccount = function(Key) {
for (var i = 0; i < global.DEVELOP_PUB_KEY_ARR.length; i++)
if (global.CompareArr(Key, global.DEVELOP_PUB_KEY_ARR[i]) === 0) {
return 1;
}
return 0;
};
global.DEVELOP_PUB_KEY_ARR = ["0222263942b11f7a78e11c43903094f870a2bf728bc8be085023b4eaf4e6228cd9", "02250c8c8f7f7e1468cdc5e9b9203841ba14250e2f480f77ebcd502f3e691506d8",
"027c0caec4e6f8f08d220f6dab24bb6f53d3f1d7b95231216805d9fac85d34a95f", "025defd5b884cc02f6948cd0d62b03d7b7445bf942206ab935158b6be8f0f7a2ce",
"024a97d69cd81c965f162b4b8b7b506263bc8aec8dbcea9eec59f73b5b470a0be1",];
let DEVELOP_PUB_KEY_ARR: any = global.DEVELOP_PUB_KEY_ARR;
for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++)
DEVELOP_PUB_KEY_ARR[i] = Buffer.from(global.GetArrFromHex(DEVELOP_PUB_KEY_ARR[i]));
global.DEVELOP_PUB_KEY = DEVELOP_PUB_KEY_ARR[0];
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("022e80aa78bc07c72781fac12488096f0bfa7b4f48fbab0f2a92e208d1ee3654df"));
let LOCAL_RUN = global.LOCAL_RUN;
if (LOCAL_RUN) {
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("026A04AB98D9E4774AD806E302DDDEB63BEA16B5CB5F223EE77478E861BB583EB3"));
global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY0;
}
global.ARR_PUB_KEY = ["027ae0dce92d8be1f893525b226695ddf0fe6ad756349a76777ff51f3b59067d70", "02769165a6f9950d023a415ee668b80bb96b5c9ae2035d97bdfb44f356175a44ff",
"021566c6feb5495594fc4bbea27795e1db5a663b3fe81ea9846268d5c394e24c23", "0215accbc993e67216c9b7f3912b29b91671864e861e61ab73589913c946839efa",
"0270e0c5acb8eefe7faddac45503da4885e02fb554975d12907f6c33ac6c6bdba5", "0202f2aad628f46d433faf70ba6bf12ab9ed96a46923b592a72508dc43af36cb80",
"0254f373fc44ac4a3e80ec8cb8cc3693a856caa82e0493067bdead78ce8ec354b8", "027617f9511b0b0cdbda8f3e17907732731296321846f3fd6fd19460f7227d9482",
];
let GetHexFromArr = global.GetHexFromArr;
if (global.TEST_NETWORK || LOCAL_RUN) {
for (var i = 0; i < 100; i++)
global.ARR_PUB_KEY[i] = global.GetHexFromArr(global.DEVELOP_PUB_KEY0);
global.DEVELOP_PUB_KEY_ARR = [global.DEVELOP_PUB_KEY0];
global.DEVELOP_PUB_KEY = DEVELOP_PUB_KEY_ARR[0];
}

1026
src/core/db/block-db.ts Normal file

File diff suppressed because it is too large Load Diff

229
src/core/db/db-row.ts Normal file
View File

@ -0,0 +1,229 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
"use strict";
import * as fs from 'fs'
module.exports = class CDBState extends require("./db")
{
private FileName;
private DataSize;
private Format;
private WorkStruct;
private FileNameFull;
private LastHash;
private WasUpdate;
private BufMap;
private BufMapCount;
constructor(FileName, DataSize, Format, bReadOnly) {
super()
this.FileName = FileName
this.DataSize = DataSize
this.Format = Format
this.WorkStruct = {}
var FI = this.OpenDBFile(this.FileName, !bReadOnly);
this.FileNameFull = FI.fname
this.LastHash = undefined
this.WasUpdate = 1
this.BufMap = {}
this.BufMapCount = 0
setInterval(this.CheckBufMap.bind(this), 1000)
}
GetMaxNum() {
var FI = this.OpenDBFile(this.FileName);
var Num = Math.floor(FI.size / this.DataSize) - 1;
return Num;
}
CheckNewNum(Data) {
if (Data.Num === undefined)
Data.Num = this.GetMaxNum() + 1
}
Write(Data, RetBuf) {
var startTime = process.hrtime();
this.LastHash = undefined
this.WasUpdate = 1
this.CheckNewNum(Data)
Data.Num = Math.trunc(Data.Num)
this.DeleteMap(Data.Num)
var BufWrite = global.BufLib.GetBufferFromObject(Data, this.Format, this.DataSize, this.WorkStruct, 1);
var Position = Data.Num * this.DataSize;
var FI = this.OpenDBFile(this.FileName, 1);
var written = fs.writeSync(FI.fd, BufWrite, 0, BufWrite.length, Position);
if (written !== BufWrite.length) {
global.TO_ERROR_LOG("DB-ROW", 10, "Error write to file:" + written + " <> " + BufWrite.length)
return false;
}
if (RetBuf) {
RetBuf.Buf = BufWrite
}
if (Position >= FI.size) {
FI.size = Position + this.DataSize
}
global.ADD_TO_STAT_TIME("ROWS_WRITE_MS", startTime)
global.ADD_TO_STAT("ROWS_WRITE")
return true;
}
Read(Num, GetBufOnly?) {
Num = Math.trunc(Num)
var Data;
if (isNaN(Num) || Num < 0 || Num > this.GetMaxNum()) {
return undefined;
}
var BufRead = this.GetMap(Num);
if (!BufRead) {
BufRead = global.BufLib.GetNewBuffer(this.DataSize)
var Position = Num * this.DataSize;
var FI = this.OpenDBFile(this.FileName);
var bytesRead = fs.readSync(FI.fd, BufRead, 0, BufRead.length, Position);
if (bytesRead !== BufRead.length)
return undefined;
this.SetMap(Num, BufRead)
}
if (GetBufOnly) {
return BufRead;
}
try {
Data = global.BufLib.GetObjectFromBuffer(BufRead, this.Format, this.WorkStruct)
}
catch (e) {
global.ToLog("DBROW:" + e)
return undefined;
}
Data.Num = Num
return Data;
}
GetRows(start, count) {
var arr = [];
for (var num = start; num < start + count; num++) {
var Data = this.Read(num);
if (!Data)
break;
arr.push(Data)
}
return arr;
}
Truncate(LastNum) {
var startTime = process.hrtime();
LastNum = Math.trunc(LastNum)
var Position = (LastNum + 1) * this.DataSize;
if (Position < 0)
Position = 0
var FI = this.OpenDBFile(this.FileName, 1);
if (Position < FI.size) {
this.LastHash = undefined
this.WasUpdate = 1
if (LastNum < 0)
global.ToLog("Truncate " + this.FileName + " from 0", 2)
FI.size = Position
fs.ftruncateSync(FI.fd, FI.size)
this.BufMap = {}
this.BufMapCount = 0
}
global.ADD_TO_STAT_TIME("ROWS_WRITE_MS", startTime)
}
DeleteHistory(BlockNumFrom) {
var MaxNum = this.GetMaxNum();
if (MaxNum === - 1)
return;
for (var num = MaxNum; num >= 0; num--) {
var ItemCheck = this.Read(num);
if (!ItemCheck)
break;
if (ItemCheck.BlockNum < BlockNumFrom) {
if (num < MaxNum) {
this.Truncate(num)
}
return;
}
}
this.Truncate(- 1)
}
FastFindBlockNum(BlockNum) {
var MaxNum = this.GetMaxNum();
if (MaxNum === - 1)
return;
var StartNum = 0;
var EndNum = MaxNum;
var CurNum = Math.trunc(MaxNum / 2);
while (true) {
var Item = this.Read(CurNum);
if (Item) {
if (Item.BlockNum > BlockNum) {
EndNum = CurNum - 1
var Delta = CurNum - StartNum;
if (Delta === 0)
return "NoHistory";
Delta = Math.trunc((1 + Delta) / 2)
CurNum = CurNum - Delta
}
else
if (Item.BlockNum < BlockNum) {
StartNum = CurNum + 1
var Delta = EndNum - CurNum;
if (Delta === 0)
return "NoPresent";
Delta = Math.trunc((1 + Delta) / 2)
CurNum = CurNum + Delta
}
else
if (Item.BlockNum === BlockNum)
break;
}
else {
throw "Error read num";
return;
}
}
var num = CurNum;
while (true) {
num--
if (num < 0)
return CurNum;
var Item = this.Read(num);
if (Item) {
if (Item.BlockNum === BlockNum)
CurNum = num
else
return CurNum;
}
else {
throw "Error read num";
return;
}
}
}
SetMap(Num, Value) {
this.BufMap[Num] = Value
this.BufMapCount++
}
GetMap(Num) {
return this.BufMap[Num];
}
DeleteMap(Num) {
if (this.BufMap[Num]) {
delete this.BufMap[Num]
this.BufMapCount--
}
}
CheckBufMap() {
if (this.BufMapCount > 1000) {
this.ClearBufMap()
}
}
ClearBufMap() {
this.BufMap = {}
this.BufMapCount = 0
}
Close() {
this.ClearBufMap()
this.CloseDBFile(this.FileName)
}
};

106
src/core/db/db.ts Normal file
View File

@ -0,0 +1,106 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
"use strict";
import * as fs from 'fs'
module.exports = class {
private DBMap;
private LastHash;
private WasUpdate;
private WasCheckPathDB;
constructor() {
this.DBMap = {}
}
CheckPathDB() {
var Path = global.global.GetDataPath("DB");
global.global.CheckCreateDir(Path)
}
CloseDBFile(name, bdelete) {
this.LastHash = undefined
this.WasUpdate = 1
var Item = this.DBMap[name];
if (Item) {
let bDelete = bdelete;
let Name = name;
fs.close(Item.fd, function(err) {
if (!err) {
if (bDelete) {
var fname = global.global.GetDataPath("DB/" + Name);
fs.unlink(fname, function(err) {
if (err)
global.ToLog(err)
})
}
}
else {
global.ToLog(err)
}
})
delete this.DBMap[name]
}
}
OpenDBFile(name, bWrite, bExist) {
if (bWrite && global.READ_ONLY_DB) {
global.ToLogTrace("CANNOT WRITE - DB IN READ_ONLY MODE!!!")
process.exit()
}
if (bWrite)
CheckStartOneProcess(name + "-run")
this.LastHash = undefined
this.WasUpdate = 1
var Item = this.DBMap[name];
if (Item === undefined) {
if (!this.WasCheckPathDB) {
this.CheckPathDB()
this.WasCheckPathDB = true
}
var fname = global.global.GetDataPath("DB/" + name);
if (!fs.existsSync(fname)) {
if (bExist) {
this.DBMap[name] = null
return null;
}
var fd = fs.openSync(fname, "w+");
fs.closeSync(fd)
}
var fd = fs.openSync(fname, "r+");
var stat = fs.statSync(fname);
var size = stat.size;
Item = { name: name, fname: fname, fd: fd, size: size, FillRows: 0, CountRows: 0, }
this.DBMap[name] = Item
}
return Item;
}
};
var MapCheckProcess = {};
var BlockDB = new module.exports();
function CheckStartOneProcess(Name) {
if (global.UpdateMode)
return;
if (global.READ_ONLY_DB || MapCheckProcess[Name])
return;
MapCheckProcess[Name] = 1;
var path = global.global.GetDataPath("DB/" + Name);
if (fs.existsSync(path)) {
fs.unlinkSync(path);
}
try {
BlockDB.OpenDBFile(Name);
}
catch (e) {
global.ToLog("****** DETECT START ANOTHER PROCESS for: " + Name);
global.ToLogTrace("EXIT");
process.exit();
}
};
global.CheckStartOneProcess = CheckStartOneProcess;

77
src/core/geo.ts Normal file
View File

@ -0,0 +1,77 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
import * as fs from 'fs'
import './library'
var BufIP;
var MapNames = {}, FileIp = "./SITE/DB/iplocation.db", FileNames = "./SITE/DB/locationnames.csv", Format = "{Value:uint32,Length:uint32, id:uint32, latitude:uint32, longitude:uint32}",
FormatStruct = {};
function SetGeoLocation(e) {
if (!e.ip || !BufIP || !BufIP.length)
return !1;
var t = IPToUint(e.ip), i = FindItem(BufIP, 20, t);
return i && (e.latitude = i.latitude, e.longitude = i.longitude, e.name = MapNames[i.id]), e.Geo = 1, !0;
};
function ReadItem(e, t) {
return BufIP.len = e * t, global.BufLib.Read(BufIP, Format, void 0, FormatStruct);
};
function FindItem(e, t, i) {
var n, r = Math.trunc(e.length / t), a = (ReadItem(0, t), ReadItem(r, t), 0), u = r, o = Math.trunc(i * r / 4294967296);
r <= o && (o = r - 1), o < a && (o = a);
for (var f = 40; 0 < f;) {
if (f-- , !(n = ReadItem(o, t)))
return void global.ToLog("GEO FindItem - Error read num: " + o);
if (n.Value > i) {
if (u = o - 1, 0 === (l = o - a))
return;
o -= l = Math.trunc((1 + l) / 2);
}
else
if (n.Value < i) {
if (n.Value + n.Length >= i)
return n;
var l;
if (a = o + 1, 0 === (l = u - o))
return;
o += l = Math.trunc((1 + l) / 2);
}
else
if (n.Value === i)
return n;
}
};
function Init() {
if (fs.existsSync(FileIp) && fs.existsSync(FileNames)) {
BufIP = fs.readFileSync(FileIp);
for (var e = fs.readFileSync(FileNames), t = 0; ;) {
var i = e.indexOf("\n", t);
if (i < 0)
break;
var n = e.toString("utf-8", t, i - 1);
t = i + 1;
var r = n.split(","), a = parseInt(r[0]);
if (a) {
0;
var u = r[10];
u || (u = r[7]), u || (u = r[5]), MapNames[a] = u;
}
}
}
};
function IPToUint(e) {
var t = e.split(".");
return 256 * (256 * (256 * + t[0] + + t[1]) + + t[2]) + + t[3];
};
global.SetGeoLocation = SetGeoLocation, Init();

1710
src/core/html-server.ts Normal file

File diff suppressed because it is too large Load Diff

424
src/core/library.ts Normal file
View File

@ -0,0 +1,424 @@
/*
* @project: TERA
* @version: Development (beta)
* @license: MIT (not for evil)
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
* Web: https://terafoundation.org
* Twitter: https://twitter.com/terafoundation
* Telegram: https://t.me/terafoundation
*/
import * as fs from 'fs'
import * as os from 'os'
import './constant'
import './log'
let {
CONSENSUS_PERIOD_TIME,
ToLog,
TO_ERROR_LOG,
SaveToFile,
TimeStart,
LOAD_CONST,
LoadParams,
GetDataPath,
CONST_NAME_ARR,
SaveParams,
SAVE_CONST,
GetDeltaCurrentTime,
} = global
Number.prototype.toStringZ = function(count) {
var strnum = this.toString();
if (strnum.length > count)
count = strnum.length;
else
strnum = "0000000000" + strnum;
return strnum.substring(strnum.length - count, strnum.length);
};
String.prototype.right = function(count) {
if (this.length > count)
return this.substr(this.length - count, count);
else
return this.substr(0, this.length);
};
if (fs.existsSync("./lib/bintrees"))
global.RBTree = require("../lib/bintrees").RBTree;
else
global.RBTree = require('bintrees').RBTree;
if (fs.existsSync("./lib/ntp-client"))
global.ntpClient = require('../lib/ntp-client');
else
global.ntpClient = require('ntp-client');
global.Stun = require('stun');
global.ZIP = require("zip");
var strOS = os.platform() + "_" + os.arch();
if (global.NWMODE)
strOS = strOS + "-nw" + global.NWVERSION;
if (fs.existsSync("./lib/secp256k1/" + strOS + "/secp256k1.node")) {
try {
global.secp256k1 = require('../lib/secp256k1/' + strOS + '/secp256k1.node');
}
catch (e) {
}
}
if (!global.secp256k1) {
global.secp256k1 = require('secp256k1');
}
require('../HTML/JS/terahashlib.js');
require("./crypto-library");
if (global.USE_PARAM_JS) {
var PathParams = global.GetCodePath("../extern-run.js");
if (fs.existsSync(PathParams))
try {
require(PathParams);
}
catch (e) {
console.log(e);
}
}
global.BufLib = require("../core/buffer");
require('../HTML/JS/sha3.js');
require('../HTML/JS/coinlib.js');
global.GetCurrentBlockNumByTime = function GetCurrentBlockNumByTime() {
var CurTimeNum = global.GetCurrentTime() - global.FIRST_TIME_BLOCK;
var StartBlockNum = Math.trunc((CurTimeNum + CONSENSUS_PERIOD_TIME) / CONSENSUS_PERIOD_TIME);
return StartBlockNum;
};
global.DelDir = function(Path) {
if (Path.substr(Path.length - 1, 1) === "/")
Path = Path.substr(0, Path.length - 1);
if (fs.existsSync(Path)) {
var arr = fs.readdirSync(Path);
for (var i = 0; i < arr.length; i++) {
var name = Path + "/" + arr[i];
if (fs.statSync(name).isDirectory()) {
global.DelDir(name);
}
else {
if (name.right(9) == "const.lst")
continue;
if (name.right(7) == "log.log")
continue;
fs.unlinkSync(name);
}
}
}
};
global.SliceArr = function(arr, start, end) {
var ret = [];
for (var i = start; i < end; i++) {
ret[i - start] = arr[i];
}
return ret;
};
var nRand = Math.floor(123 + Math.random() * 1000);
function random(max) {
return Math.floor(Math.random() * max);
};
global.random = random;
global.AddrLevelArrFromBegin = function(arr1, arr2) {
var Level = 0;
for (var i = 0; i < arr1.length; i++) {
var a1 = arr1[i];
var a2 = arr2[i];
for (var b = 0; b < 8; b++) {
if ((a1 & 128) !== (a2 & 128))
return Level;
a1 = a1 << 1;
a2 = a2 << 1;
Level++;
}
}
return Level;
};
global.AddrLevelArr = function(arr1, arr2) {
var Level = 0;
for (var i = arr1.length - 1; i >= 0; i--) {
var a1 = arr1[i];
var a2 = arr2[i];
for (var b = 0; b < 8; b++) {
if ((a1 & 1) !== (a2 & 1))
return Level;
a1 = a1 >> 1;
a2 = a2 >> 1;
Level++;
}
}
return Level;
};
global.SaveToFile = function(name, buf) {
var fs = require('fs');
var file_handle = fs.openSync(name, "w");
fs.writeSync(file_handle, buf, 0, buf.length);
fs.closeSync(file_handle);
};
global.LoadParams = function(filename, DefaultValue) {
try {
if (fs.existsSync(filename)) {
var Str = fs.readFileSync(filename);
if (Str.length > 0)
return JSON.parse(Str as any);
}
}
catch (err) {
TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
}
return DefaultValue;
};
global.SaveParams = function(filename, data) {
SaveToFile(filename, Buffer.from(JSON.stringify(data, undefined, 4)));
};
global.StartTime = function() {
global.TimeStart = global.GetCurrentTime();
};
global.FinishTime = function(Str) {
Str = Str || "";
var TimeFinish = global.GetCurrentTime();
var delta = TimeFinish - TimeStart;
console.log(Str + " time: " + delta + " ms");
};
global.CompareItemBufFD = function(a, b) {
if (a.FD !== b.FD)
return a.FD - b.FD;
else
return a.Position - b.Position;
};
global.CompareArr33 = function(a, b) {
for (var i = 0; i < 33; i++) {
if (a[i] !== b[i])
return a[i] - b[i];
}
return 0;
};
global.CompareItemHashSimple = function(a, b) {
if (a.hash < b.hash)
return - 1;
else
if (a.hash > b.hash)
return 1;
else
return 0;
};
global.CompareItemHash = function(a, b) {
var hasha = a.hash;
var hashb = b.hash;
for (var i = 0; i < hasha.length; i++) {
if (hasha[i] !== hashb[i])
return hasha[i] - hashb[i];
}
return 0;
};
global.CompareItemHash32 = function(a, b) {
var hasha = a.hash;
var hashb = b.hash;
for (var i = 0; i < 32; i++) {
if (hasha[i] !== hashb[i])
return hasha[i] - hashb[i];
}
return 0;
};
global.CompareItemHASH32 = function(a, b) {
var hasha = a.HASH;
var hashb = b.HASH;
for (var i = 0; i < 32; i++) {
if (hasha[i] !== hashb[i])
return hasha[i] - hashb[i];
}
return 0;
};
global.CompareItemHash33 = function(a, b) {
var hasha = a.hash;
var hashb = b.hash;
for (var i = 0; i < 33; i++) {
if (hasha[i] !== hashb[i])
return hasha[i] - hashb[i];
}
return 0;
};
global.CompareItemHashPow = function(a, b) {
return global.CompareArr(a.HashPow, b.HashPow);
};
global.CompareItemTimePow = function(a, b) {
if (b.TimePow !== a.TimePow)
return b.TimePow - a.TimePow;
else
return global.CompareArr(a.HashPow, b.HashPow);
};
global.LOAD_CONST = function() {
var Count = 0;
var constants = LoadParams(global.GetDataPath("const.lst"), {});
if (constants) {
for (var i = 0; i < CONST_NAME_ARR.length; i++) {
var key = CONST_NAME_ARR[i];
if (constants[key] !== undefined) {
Count++;
global[key] = constants[key];
}
}
}
return Count;
};
var WasStartSaveConst = false;
function SaveConst() {
var constants = {};
for (var i = 0; i < CONST_NAME_ARR.length; i++) {
var key = CONST_NAME_ARR[i];
if (global[key] !== undefined)
constants[key] = global[key];
}
SaveParams(global.GetDataPath("const.lst"), constants);
WasStartSaveConst = false;
};
global.SAVE_CONST = function(bForce) {
if (bForce) {
SaveConst();
}
else {
if (!WasStartSaveConst)
setTimeout(SaveConst, 10 * 1000);
WasStartSaveConst = true;
}
};
function CheckGlobalTime() {
global.ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, NetTime) {
if (err) {
TO_ERROR_LOG("MAINLIB", 110, err);
return;
}
var curTime = new Date;
global.DELTA_CURRENT_TIME = NetTime - (curTime as any);
if (isNaN(global.DELTA_CURRENT_TIME) || typeof global.DELTA_CURRENT_TIME !== "number")
global.DELTA_CURRENT_TIME = 0;
else
if (Math.abs(global.DELTA_CURRENT_TIME) > 24 * 3600 * 1000)
global.DELTA_CURRENT_TIME = 0;
global.ToLog("Get global time: " + NetTime);
SAVE_CONST();
});
SAVE_CONST();
};
global.CheckGlobalTime = CheckGlobalTime;
global.GetDeltaCurrentTime = function() {
if (isNaN(global.DELTA_CURRENT_TIME) || typeof global.DELTA_CURRENT_TIME !== "number")
global.DELTA_CURRENT_TIME = 0;
return global.DELTA_CURRENT_TIME;
};
global.GetStrTimeUTC = function(now) {
if (!global.GetCurrentTime)
return ":::";
if (!now)
now = global.GetCurrentTime();
var Str = "" + now.getUTCDate();
Str = Str + "." + (1 + now.getUTCMonth());
Str = Str + "." + now.getUTCFullYear();
Str = Str + " " + now.getUTCHours();
Str = Str + ":" + now.getUTCMinutes();
Str = Str + ":" + now.getUTCSeconds();
return Str;
};
global.GetStrOnlyTimeUTC = function(now) {
if (!global.GetCurrentTime)
return ":::";
if (!now)
now = global.GetCurrentTime();
var Str;
Str = "" + now.getUTCHours().toStringZ(2);
Str = Str + ":" + now.getUTCMinutes().toStringZ(2);
Str = Str + ":" + now.getUTCSeconds().toStringZ(2);
return Str;
};
function GetSecFromStrTime(Str) {
var arr = Str.split(":");
var Mult = 3600;
var Sum = 0;
for (var i = 0; i < arr.length; i++) {
Sum += Mult * parseInt(arr[i]);
Mult = Mult / 60;
}
return Sum;
};
global.GetSecFromStrTime = GetSecFromStrTime;
global.GetCurrentTime = function(Delta_Time) {
if (Delta_Time === undefined)
Delta_Time = GetDeltaCurrentTime();
var curTime: any = new Date;
var Time = new Date(curTime - (- Delta_Time));
return Time;
};
function DateFromBlock(BlockNum) {
var Str;
var now = new Date(global.FIRST_TIME_BLOCK + BlockNum * 1000);
Str = now.toISOString();
Str = Str.substr(0, Str.indexOf("."));
Str = Str.replace("T", " ");
return Str;
};
global.DateFromBlock = DateFromBlock;
var code_base = ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\u0402\u0403\u201a\u0453\u201e\u2026\u2020\u2021\u20ac\u2030\u0409\u2039\u040a\u040c\u040b\u040f\u0452\u2018\u2019\u201c\u201d\u2022\u2013\u2014\ufffd\u2122\u0459\u203a\u045a\u045c\u045b\u045f\xa0\u040e\u045e\u0408\xa4\u0490\xa6\xa7\u0401\xa9\u0404\xab\xac\xad\xae\u0407\xb0\xb1\u0406\u0456\u0491\xb5\xb6\xb7\u0451\u2116\u0454\xbb\u0458\u0405\u0455\u0457\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f';
global.NormalizeName = function(Name) {
var Str = "";
for (var i = 0; i < Name.length; i++) {
var code = Name.charCodeAt(i);
if (code >= 32)
Str += code_base.charAt(code - 32);
}
return Str;
};
var glEvalMap = {};
function CreateEval(formula, StrParams) {
var Ret = glEvalMap[formula];
if (!Ret) {
eval("function M(" + StrParams + "){return " + formula + "}; Ret=M;");
glEvalMap[formula] = Ret;
}
return Ret;
};
global.CreateEval = CreateEval;
var CPU_Count = os.cpus().length;
function GetCountMiningCPU() {
if (global.COUNT_MINING_CPU)
return global.COUNT_MINING_CPU;
else {
return CPU_Count - 1;
}
};
global.GetCountMiningCPU = GetCountMiningCPU;
var AddTrMap = [];
AddTrMap[- 6] = "Inner node error";
AddTrMap[- 5] = "Bad block num";
AddTrMap[- 4] = "Bad type transaction";
AddTrMap[- 3] = "Bad time";
AddTrMap[- 2] = "Bad PoW";
AddTrMap[- 1] = "Bad length";
AddTrMap[0] = "Not add";
AddTrMap[1] = "OK";
AddTrMap[2] = "Update OK";
AddTrMap[3] = "Was send";
AddTrMap[4] = "Added to timer";
global.AddTrMap = AddTrMap;
function GrayConnect() {
if (global.NET_WORK_MODE && !global.NET_WORK_MODE.UseDirectIP)
return 1;
else
return 0;
};
global.GrayConnect = GrayConnect;
var ResConst = LOAD_CONST();
if (global.START_SERVER) {
if (!ResConst) {
CheckGlobalTime();
}
else
if (global.CHECK_GLOBAL_TIME) {
CheckGlobalTime();
}
}

Some files were not shown because too many files have changed in this diff Show More