1
0
forked from circlecloud/tera

fix: error global replace

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-07-12 22:46:26 +08:00
parent 92a1edb789
commit 1225f4b2f5
27 changed files with 504 additions and 723 deletions

View File

@ -18,13 +18,11 @@
"clean": "npx rimraf dist", "clean": "npx rimraf dist",
"prebuild": "yarn clean", "prebuild": "yarn clean",
"watch": "npx tsc --watch", "watch": "npx tsc --watch",
"postbuild": "cp src/HTML/* dist/HTML/ -rf", "postbuild": "cp src/HTML/* dist/HTML/ -rf && cp package.json dist/",
"build": "npx tsc", "build": "npx tsc",
"start": "node dist/run-node.js" "start": "node dist/run-node.js"
}, },
"dependencies": { "dependencies": {
"@types/bintrees": "^1.0.2",
"@types/secp256k1": "^3.5.0",
"bintrees": "^1.0.2", "bintrees": "^1.0.2",
"greenlock": "^2.6.7", "greenlock": "^2.6.7",
"ntp-client": "^0.5.3", "ntp-client": "^0.5.3",
@ -34,6 +32,8 @@
"zip": "^1.2.0" "zip": "^1.2.0"
}, },
"devDependencies": { "devDependencies": {
"@types/bintrees": "^1.0.2",
"@types/secp256k1": "^3.5.0",
"@types/node": "^12.6.1", "@types/node": "^12.6.1",
"rimraf": "^2.6.3", "rimraf": "^2.6.3",
"ts-node-dev": "^1.0.0-pre.40", "ts-node-dev": "^1.0.0-pre.40",

View File

@ -1,162 +0,0 @@
‘à ¢­¥­¨¥ ä ©«®¢ 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

@ -36,8 +36,7 @@ function GetPowPower(arrhash) {
for (var b = 7; b >= 0; b--) { for (var b = 7; b >= 0; b--) {
if ((byte >> b) & 1) { if ((byte >> b) & 1) {
return SumBit; return SumBit;
} } else {
else {
SumBit++; SumBit++;
} }
} }

View File

@ -1409,26 +1409,21 @@
<DIV id="idNodeUpdateMiningStatus" style="display: block"> <DIV id="idNodeUpdateMiningStatus" style="display: block">
<DIV style="float: left"> <DIV style="float: left">
<input type="checkbox" class="checkbox" id="idAutoUpdate" onchange = "UseAutoUpdate()"/> <input type="checkbox" class="checkbox" id="idAutoUpdate" onchange = "UseAutoUpdate()"/>
<label for="idAutoUpdate">自动更新</label> <label for="idAutoUpdate">AutoUpdate</label>
</DIV> </DIV>
<DIV style="float: left"> <DIV style="float: left">
<input type="checkbox" class="checkbox" id="idUseMining" onchange = "UseMining()"/> <input type="checkbox" class="checkbox" id="idUseMining" onchange = "UseMining()"/>
<label for="idUseMining">挖矿</label> <label for="idUseMining">UseMining</label>
</DIV>
<DIV style="float: left">
<label>此版本由 MiaoWoo 使用 TypeScript 重构</label>
</DIV> </DIV>
<DIV style="float: left;display: none" id="idMiningParams"> <DIV style="float: left;display: none" id="idMiningParams">
<DIV style="float: left; color: blue;">CPU <DIV style="float: left; color: blue;">CPU
use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV> use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV>
<DIV style="float: left; margin: 2px 0 0 8px;" id="idStatusMining"></DIV>
</DIV> </DIV>
</DIV> </DIV>
<DIV id="idDevelopService" style="display: none"> <DIV id="idDevelopService" style="display: none">
<BR> <BR>
<INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')" <INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')" class="btdoit bt" value="DEV SERVICE">
class="btdoit bt" value="DEV SERVICE"> <DIV id="idDevelopServiceView">
<DIV id="idDevelopServiceView" style="display: none">
<table> <table>
<tr> <tr>
<td style="width: 100px"> <td style="width: 100px">
@ -1461,6 +1456,7 @@
</DIV> </DIV>
<canvas width='800' height='30' id='idBlockInfo'></canvas> <canvas width='800' height='30' id='idBlockInfo'></canvas>
<BR><BR> <BR><BR>
<DIV style="float: left;" id="idStatusMining"></DIV>
<DIV style="float: left; font-family: monospace"> <DIV style="float: left; font-family: monospace">
Block:<B id="idCurBlockNum"></B> Block:<B id="idCurBlockNum"></B>
DB delta:<B id="idDeltaDB" style="min-width: 30px"></B> DB delta:<B id="idDeltaDB" style="min-width: 30px"></B>
@ -1476,23 +1472,16 @@
</DIV> </DIV>
<BR> <BR>
</DIV> </DIV>
<DIV id="wallet_config_tab" style="display: none;float: left"> <DIV id="wallet_config_tab" style="display: none;float: left">
钱包数据目录: <B id="idDataPath"></B><BR> DataPath: <B id="idDataPath"></B><BR>
账户公钥: <B id="idPubKey"></B><BR> PubKey: <B id="idPubKey"></B><BR>
<!--Node addr: <B id="idNodeAddr"></B><BR>--> <!--Node addr: <B id="idNodeAddr"></B><BR>-->
<INPUT type="button" onclick="MoveUp($('edit_keys'));NewPrivateKey();" class="btdoit bt" value="NewWallet" id="idDown2">
<INPUT type="button" onclick="MoveUp($('edit_keys'));EditPrivateKey();SetImg(this,'edit_keys');" class="btdoit bt" value="EditWallet" id="idDown">
<INPUT type="button" onclick="MoveUp($('edit_keys'));NewPrivateKey();" class="btdoit bt" value="新建钱包" id="idDown2"> <INPUT type="button" onclick="MoveUp($('idAccountEdit'));ViewNewAccount();SetImg(this,'idAccountEdit');" class="btdoit bt" value="NewAccount" id="idDown">
<INPUT type="button" onclick="MoveUp($('edit_keys'));EditPrivateKey();SetImg(this,'edit_keys');" class="btdoit bt" value="编辑钱包" id="idDown"> <INPUT type="button" onclick="MoveUp($('edit_mining_set'));MiningSets();SetImg(this,'edit_mining_set');" class="btdoit bt" value="MiningSet" id="idDown">
<INPUT type="button" onclick="MoveUp($('idAccountEdit'));ViewNewAccount();SetImg(this,'idAccountEdit');" class="btdoit bt" value="新建账户" id="idDown"> <INPUT type="button" onclick="ViewSetPassword();itemBtPassword=this; SetImg(itemBtPassword,'idBlockPasswordSet');" class="bt btdoit" value="SetPassword" id="idDown">
<INPUT type="button" onclick="MoveUp($('edit_mining_set'));MiningSets();SetImg(this,'edit_mining_set');" class="btdoit bt" value="设置挖矿账号" id="idDown">
<INPUT type="button" onclick="ViewSetPassword();itemBtPassword=this; SetImg(itemBtPassword,'idBlockPasswordSet');" class="bt btdoit" value="设置密码" id="idDown">
</DIV> </DIV>
<DIV> <DIV>
<DIV id="edit_mining_set" style="display: none"> <DIV id="edit_mining_set" style="display: none">
<table class="form_input keys" id="grid_mining_set"> <table class="form_input keys" id="grid_mining_set">
@ -1665,8 +1654,6 @@
<HR> <HR>
</DIV> </DIV>
</DIV> </DIV>
Style: Style:
<select size="1" id="idSelStyle" onkeyup="SelectStyle();SaveValues()" onchange="SelectStyle();SaveValues()"> <select size="1" id="idSelStyle" onkeyup="SelectStyle();SaveValues()" onchange="SelectStyle();SaveValues()">
<option value="styleBrown">Brown</option> <option value="styleBrown">Brown</option>
@ -1678,24 +1665,16 @@
<option value="styleContrast2">Contrast 2</option> <option value="styleContrast2">Contrast 2</option>
<option value="styleContrast3">Contrast 3</option> <option value="styleContrast3">Contrast 3</option>
</select> </select>
此版本由 MiaoWoo 使用 TypeScript 重构<BR>
</DIV> </DIV>
<DIV id="TabSend" style="display: none"> <DIV id="TabSend" style="display: none">
<DIV id="idSendList"> </DIV> <DIV id="idSendList"> </DIV>
<table class="form_input"> <table class="form_input">
<tr> <tr>
<td style="min-width: 115px">From account</td> <td style="min-width: 115px">From account</td>
<td> <td>
<select size="1" id="idAccount" onkeyup="OnEditTransactionFields()" onchange="OnEditTransactionFields()"> <select size="1" id="idAccount" onkeyup="OnEditTransactionFields()" onchange="OnEditTransactionFields()">
</select> </select>
</td> </td>
</tr> </tr>
<tr> <tr>
@ -1849,7 +1828,8 @@
<table id="grid_accounts_all" class="grid"> <table id="grid_accounts_all" class="grid">
<tr> <tr>
<th id="(RetHistoryAccount(Item))" class="num">ID</th> <th id="(RetHistoryAccount(Item))" class="num">ID</th>
<th id="SUM_TO_STRING(Item.Value)" class="sum smallbold">Amount</th> <th id="SUM_TO_STRING(Item.Value)" class="sum smallbold">Amount
</th>
<th id="CurrencyNameItem(Item)" class="cur">Cur</th> <th id="CurrencyNameItem(Item)" class="cur">Cur</th>
<th id="Item.Name" class="accname">Name</th> <th id="Item.Name" class="accname">Name</th>
<th id="Item.PubKeyStr" class="pubkey">PubKey</th> <th id="Item.PubKeyStr" class="pubkey">PubKey</th>
@ -1857,7 +1837,8 @@
<th id="(RetHistoryAccount(Item,'Adviser'))" class="num">Adviser <th id="(RetHistoryAccount(Item,'Adviser'))" class="num">Adviser
</th> </th>
<th id="Item.Value.Smart" class="num">Smart</th> <th id="Item.Value.Smart" class="num">Smart</th>
<th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="num">Block Num <th id="(RetOpenBlock(Item.BlockNumCreate,1))" class="num">Block
Num
</th> </th>
<!--<th id="Item.Arr[0].BlockNum" class="num">0</th>--> <!--<th id="Item.Arr[0].BlockNum" class="num">0</th>-->
<!--<th id="Item.Arr[1].BlockNum" class="num">1</th>--> <!--<th id="Item.Arr[1].BlockNum" class="num">1</th>-->
@ -1890,13 +1871,17 @@
<th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))" <th id="(RetOpenBlock(Item.BlockNum,Item.TrDataLen))"
class="num">Num</th> class="num">Num</th>
<th id="(DateFromBlock(Item.BlockNum,1))" class="date">Date <th id="(DateFromBlock(Item.BlockNum,1))" class="date">
Date
</th> </th>
<th id="GetHexFromArr(Item.TreeHash)" class="hash">Data Hash <th id="GetHexFromArr(Item.TreeHash)" class="hash">Data
Hash
</th> </th>
<th id="GetHexFromArr(Item.PowHash)" class="hash">PowHash <th id="GetHexFromArr(Item.PowHash)" class="hash">
PowHash
</th> </th>
<th id="GetHexFromArr(Item.Hash)" class="hash">Block Hash <th id="GetHexFromArr(Item.Hash)" class="hash">Block
Hash
</th> </th>
<!--<th id="GetHexFromArr(Item.SumHash)" class="hash">SumHash</th>--> <!--<th id="GetHexFromArr(Item.SumHash)" class="hash">SumHash</th>-->
<th id="Item.TrDataLen" class="num">Bytes</th> <th id="Item.TrDataLen" class="num">Bytes</th>
@ -1948,9 +1933,11 @@
<th id="Item.PrevValue.OperationID" class="num"> <th id="Item.PrevValue.OperationID" class="num">
Prev. Operation</th> Prev. Operation</th>
<th id="SUM_TO_STRING(Item.PrevValue)" class="sum"> <th id="SUM_TO_STRING(Item.PrevValue)"
class="sum">
Prev. amount</th> Prev. amount</th>
<th id="Item.PrevValue.NextPos" class="num">Prev. <th id="Item.PrevValue.NextPos" class="num">
Prev.
History</th> History</th>
</tr> </tr>
</table> </table>
@ -2025,7 +2012,8 @@
<BR> <BR>
<DIV id="idServerBlock" style="width: 99.5%"> <DIV id="idServerBlock"
style="width: 99.5%">
<HR> <HR>
Log from node: Log from node:
<DIV id="idServerLog"></DIV><BR> <DIV id="idServerLog"></DIV><BR>
@ -2034,7 +2022,8 @@
<FORM id="idBlockPasswordSet" <FORM id="idBlockPasswordSet"
style="display: none"> style="display: none">
<H3 align="center">Enter new password: <H3 align="center">Enter new
password:
</H3> </H3>
<table class="password" <table class="password"
id="idTablePassword1"> id="idTablePassword1">
@ -2067,7 +2056,8 @@
</FORM> </FORM>
<FORM id="idBlockPasswordGet" <FORM id="idBlockPasswordGet"
style="display: none"> style="display: none">
<H3 align="center">Enter your password: <H3 align="center">Enter your
password:
</H3> </H3>
<table class="password" <table class="password"
id="idTablePassword2"> id="idTablePassword2">
@ -2096,7 +2086,8 @@
<DIV id="idBlockOnSend" <DIV id="idBlockOnSend"
style="display: none"> style="display: none">
<DIV align="center"> <DIV align="center">
Send <B id="idOnSendText"></B><BR> Send
<B id="idOnSendText"></B><BR>
<button onclick="SendMoney2()" id="idBtOnSend" class="radius">Send</button> <button onclick="SendMoney2()" id="idBtOnSend" class="radius">Send</button>
<button onclick='SetVisibleBlock("idBlockOnSend",0);' class="radius">Cancel</button> <button onclick='SetVisibleBlock("idBlockOnSend",0);' class="radius">Cancel</button>
@ -2109,12 +2100,14 @@
<audio style="visibility: hidden;" <audio style="visibility: hidden;"
controls="controls" id="sound_coin"> controls="controls"
id="sound_coin">
<source src="coin.mp3" <source src="coin.mp3"
type="audio/mpeg" /> type="audio/mpeg" />
</audio> </audio>
<audio style="visibility: hidden;" <audio style="visibility: hidden;"
controls="controls" id="sound_err"> controls="controls"
id="sound_err">
<source src="click.mp3" <source src="click.mp3"
type="audio/mpeg" /> type="audio/mpeg" />
</audio> </audio>

7
src/constant/account.ts Normal file
View File

@ -0,0 +1,7 @@
export enum TYPE_TRANSACTION {
TYPE_TRANSACTION_CREATE = 100,
TYPE_DEPRECATED_TRANSFER1 = 105,
TYPE_DEPRECATED_TRANSFER2 = 110,
TYPE_TRANSACTION_TRANSFER = 111,
TYPE_TRANSACTION_ACC_HASH = 119
}

View File

@ -1,42 +0,0 @@
/*
* @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,
};
global.BufLib.GetBufferFromObject(TR, 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(global.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

@ -1,10 +0,0 @@
/*
* @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
*/

View File

@ -279,7 +279,7 @@ class SMemBuffer {
this.MetaMap1 = {} this.MetaMap1 = {}
} }
}; };
class STreeBuffer { export class STreeBuffer {
KeyType KeyType
MetaTree1 MetaTree1
MetaTree2 MetaTree2

View File

@ -10,6 +10,8 @@
"use strict"; "use strict";
import CBlock from './block-loader' import CBlock from './block-loader'
import { RBTree } from './library'
import { STreeBuffer } from './base';
require('./library'); require('./library');
require('./crypto-library'); require('./crypto-library');
const TX_PROCESS_TIME = 100; const TX_PROCESS_TIME = 100;
@ -52,7 +54,7 @@ export default class CConsensus extends CBlock {
this.CurrentBlockNum = 0 this.CurrentBlockNum = 0
this.SendBlockID = 0 this.SendBlockID = 0
this.RelayMode = false this.RelayMode = false
this.TreeSendPacket = new global.RBTree(global.CompareItemHash) this.TreeSendPacket = new RBTree(global.CompareItemHash)
if (!global.ADDRLIST_MODE && !this.VirtualMode) { if (!global.ADDRLIST_MODE && !this.VirtualMode) {
this.idBlockChainTimer = setInterval(this.StartBlockChain.bind(this), global.CONSENSUS_PERIOD_TIME - 5) this.idBlockChainTimer = setInterval(this.StartBlockChain.bind(this), global.CONSENSUS_PERIOD_TIME - 5)
setInterval(this.DoTransfer.bind(this), global.CONSENSUS_CHECK_TIME) setInterval(this.DoTransfer.bind(this), global.CONSENSUS_CHECK_TIME)
@ -86,8 +88,8 @@ export default class CConsensus extends CBlock {
Context.TransferFromAddr = {} Context.TransferFromAddr = {}
Context.LevelsTransfer = [] Context.LevelsTransfer = []
Context.ErrRun = "" Context.ErrRun = ""
Context.PowTxTree = new global.RBTree(global.CompareItemTimePow) Context.PowTxTree = new RBTree(global.CompareItemTimePow)
Context.PowTicketTree = new global.RBTree(global.CompareItemTimePow) Context.PowTicketTree = new RBTree(global.CompareItemTimePow)
Context.bSave = false Context.bSave = false
Context.PrevHash = undefined Context.PrevHash = undefined
Context.TreeHash = undefined Context.TreeHash = undefined
@ -127,7 +129,7 @@ export default class CConsensus extends CBlock {
return Context; return Context;
} }
StartConsensus() { StartConsensus() {
if (!global.global.CAN_START) if (!global.CAN_START)
return; return;
var StartBlockNum = global.GetCurrentBlockNumByTime(); var StartBlockNum = global.GetCurrentBlockNumByTime();
if (StartBlockNum < global.BLOCK_PROCESSING_LENGTH2) if (StartBlockNum < global.BLOCK_PROCESSING_LENGTH2)
@ -137,8 +139,7 @@ export default class CConsensus extends CBlock {
if (!Block0.Active) { if (!Block0.Active) {
global.AddInfoBlock(Block0, "Activate") global.AddInfoBlock(Block0, "Activate")
this.StartBlock(Block0) this.StartBlock(Block0)
} } else {
else {
global.AddInfoBlock(Block0, "Was Active") global.AddInfoBlock(Block0, "Was Active")
} }
} }
@ -368,12 +369,10 @@ export default class CConsensus extends CBlock {
this.AddTrToBlockQuote(Block, Data.Array[i], 1) this.AddTrToBlockQuote(Block, Data.Array[i], 1)
} }
} }
static static TRANSFERTX_F() {
TRANSFERTX_F() {
return "{BlockNum:uint, Array:[{body:tr}]}"; return "{BlockNum:uint, Array:[{body:tr}]}";
} }
static static GETTRANSFERTX_F() {
GETTRANSFERTX_F() {
return "{BlockNum:uint, TicketArray:[{HashTicket:arr10}]}"; return "{BlockNum:uint, TicketArray:[{HashTicket:arr10}]}";
} }
GETTRANSFERTX(Info, CurTime) { GETTRANSFERTX(Info, CurTime) {
@ -696,7 +695,7 @@ export default class CConsensus extends CBlock {
} }
AddPOWToMaxTree(POW, item) { AddPOWToMaxTree(POW, item) {
if (!POW.MaxTree) { if (!POW.MaxTree) {
POW.MaxTree = new global.RBTree(function(a, b) { POW.MaxTree = new RBTree(function(a: any, b: any) {
return global.CompareArr(a.PowHash, b.PowHash); return global.CompareArr(a.PowHash, b.PowHash);
}) })
} }
@ -1396,7 +1395,7 @@ export default class CConsensus extends CBlock {
} }
} }
}; };
global.TreeBlockBuf = new global.STreeBuffer(50 * 1000, global.CompareItemHashSimple, "string"); global.TreeBlockBuf = new STreeBuffer(50 * 1000, global.CompareItemHashSimple, "string");
var PrevTimeIdle = 0; var PrevTimeIdle = 0;
OnTimeIdle(); OnTimeIdle();

View File

@ -11,6 +11,8 @@
"use strict"; "use strict";
import * as fs from 'fs' import * as fs from 'fs'
import CRest from './rest-loader' import CRest from './rest-loader'
import { TYPE_TRANSACTION } from '../constant/account';
import { STreeBuffer } from './base';
//import * as crypto from 'crypto'; //import * as crypto from 'crypto';
require('./block-loader-const'); require('./block-loader-const');
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5; const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
@ -356,7 +358,7 @@ export default class CBlock extends CRest {
Node = arr[this.TaskNodeIndex % arr.length] Node = arr[this.TaskNodeIndex % arr.length]
} }
if (Node.Active) { if (Node.Active) {
if (!Node.INFO || !Node.INFO.WasPing || Node.StopGetBlock || (Node.INFO.CheckPointHashDB && global.global.CHECK_POINT.BlockNum && global.CompareArr(global.global.CHECK_POINT.Hash, if (!Node.INFO || !Node.INFO.WasPing || Node.StopGetBlock || (Node.INFO.CheckPointHashDB && global.CHECK_POINT.BlockNum && global.CompareArr(global.CHECK_POINT.Hash,
Node.INFO.CheckPointHashDB) !== 0)) { Node.INFO.CheckPointHashDB) !== 0)) {
timewait = true timewait = true
continue; continue;
@ -415,8 +417,7 @@ export default class CBlock extends CRest {
} }
return false; return false;
} }
static static GETBLOCKHEADER_F() {
GETBLOCKHEADER_F() {
return "{\ return "{\
Foward:byte,\ Foward:byte,\
BlockNum:uint,\ BlockNum:uint,\
@ -425,8 +426,7 @@ export default class CBlock extends CRest {
IsSum:byte\ IsSum:byte\
}"; }";
} }
static static GETBLOCKHEADER100_F() {
GETBLOCKHEADER100_F() {
return "{\ return "{\
BlockNum:uint,\ BlockNum:uint,\
Hash:hash,\ Hash:hash,\
@ -773,8 +773,7 @@ export default class CBlock extends CRest {
else { else {
if (global.IsZeroArr(Block.TreeHash)) { if (global.IsZeroArr(Block.TreeHash)) {
Res = this.WriteBlockDB(Block) Res = this.WriteBlockDB(Block)
} } else {
else {
global.ToLogTrace("global.IsZeroArr(Block.TreeHash)") global.ToLogTrace("global.IsZeroArr(Block.TreeHash)")
throw "global.IsZeroArr(Block.TreeHash)"; throw "global.IsZeroArr(Block.TreeHash)";
} }
@ -987,7 +986,7 @@ export default class CBlock extends CRest {
} }
if (arrContent.length > 0 && Data.BlockNum % global.PERIOD_ACCOUNT_HASH === 0) { if (arrContent.length > 0 && Data.BlockNum % global.PERIOD_ACCOUNT_HASH === 0) {
var TR = arrContent[0]; var TR = arrContent[0];
if (TR[0] === global.TYPE_TRANSACTION_ACC_HASH) { if (TR[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH) {
if (!global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum)) { if (!global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum)) {
global.ToLog(`global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum) ${JSON.stringify(TR)}, ${Data.BlockNum}`) global.ToLog(`global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum) ${JSON.stringify(TR)}, ${Data.BlockNum}`)
if (!this.BADHashCount) if (!this.BADHashCount)
@ -1295,8 +1294,7 @@ global.LoadBlockFromNetwork = function(Params, F) {
var ResError; var ResError;
if (!Block.arrContent || Block.arrContent.length === 0) { if (!Block.arrContent || Block.arrContent.length === 0) {
ResError = 1; ResError = 1;
} } else {
else {
ResError = 0; ResError = 0;
global.SERVER.WriteBlockDB(Block); global.SERVER.WriteBlockDB(Block);
} }
@ -1310,4 +1308,4 @@ global.LoadBlockFromNetwork = function(Params, F) {
F(1); F(1);
} }
}; };
global.HistoryBlockBuf = new global.STreeBuffer(global.HISTORY_BLOCK_COUNT * 1000, global.CompareItemHashSimple, "string"); global.HistoryBlockBuf = new STreeBuffer(global.HISTORY_BLOCK_COUNT * 1000, global.CompareItemHashSimple, "string");

View File

@ -28,6 +28,7 @@ const MAX_PERIOD_GETNODES = 120 * 1000;
global.MIN_PERIOD_PING = 4 * 1000; global.MIN_PERIOD_PING = 4 * 1000;
const MAX_PERIOD_PING = 120 * 1000; const MAX_PERIOD_PING = 120 * 1000;
global.MAX_PING_FOR_CONNECT = 400; global.MAX_PING_FOR_CONNECT = 400;
const CAN_START_TIME_AVG = 200;
var MAX_TIME_CORRECT = 3 * 3600 * 1000; var MAX_TIME_CORRECT = 3 * 3600 * 1000;
global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME; global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME;
const PERIOD_FOR_START_CHECK_TIME = 300; const PERIOD_FOR_START_CHECK_TIME = 300;
@ -347,7 +348,7 @@ export default class CConnect extends CMessages {
} }
global.ADD_TO_STAT("MAX:PING_TIME", DeltaTime) global.ADD_TO_STAT("MAX:PING_TIME", DeltaTime)
if (!global.CAN_START) if (!global.CAN_START)
if (Times && Times.Count >= 1 && Times.AvgDelta <= 200) { if (Times && Times.Count >= 1 && Times.AvgDelta <= CAN_START_TIME_AVG) {
global.ToLog("****************************************** CAN_START") global.ToLog("****************************************** CAN_START")
global.CAN_START = true global.CAN_START = true
} }
@ -369,8 +370,7 @@ export default class CConnect extends CMessages {
this.TruncateBlockDB(this.BlockNumDB) this.TruncateBlockDB(this.BlockNumDB)
this.StartSyncBlockchain(Node, 0, 1) this.StartSyncBlockchain(Node, 0, 1)
} }
} } else {
else {
Node.NextConnectDelta = 60 * 1000 Node.NextConnectDelta = 60 * 1000
global.ToLog("Error Sign CheckPoint=" + Data.CheckPoint.BlockNum + " from " + global.NodeInfo(Node)) global.ToLog("Error Sign CheckPoint=" + Data.CheckPoint.BlockNum + " from " + global.NodeInfo(Node))
this.AddCheckErrCount(Node, 10, "Error Sign CheckPoint") this.AddCheckErrCount(Node, 10, "Error Sign CheckPoint")
@ -1280,8 +1280,7 @@ export default class CConnect extends CMessages {
global.AddNodeInfo(Node, "DeleteFromActive") global.AddNodeInfo(Node, "DeleteFromActive")
this.DeleteNodeFromActive(Node) this.DeleteNodeFromActive(Node)
} }
} } else {
else {
this.DetectGrayMode() this.DetectGrayMode()
for (var Level = 0; Level < ArrTree.length; Level++) { for (var Level = 0; Level < ArrTree.length; Level++) {
var arr = ArrTree[Level]; var arr = ArrTree[Level];

View File

@ -72,8 +72,8 @@ global.GetPublicKeyFromAddres = function(Arr) {
}; };
global.CheckDevelopSign = function(SignArr, Sign) { global.CheckDevelopSign = function(SignArr, Sign) {
var hash = global.SHA3BUF(SignArr); var hash = global.SHA3BUF(SignArr);
for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++) { for (var i = 0; i < global.DEVELOP_PUB_KEY_ARR.length; i++) {
var Result = secp256k1.verify(hash, Buffer.from(Sign), DEVELOP_PUB_KEY_ARR[i]); var Result = secp256k1.verify(hash, Buffer.from(Sign), global.DEVELOP_PUB_KEY_ARR[i]);
if (Result) if (Result)
return 1; return 1;
} }
@ -963,13 +963,12 @@ global.IsDeveloperAccount = function(Key) {
global.DEVELOP_PUB_KEY_ARR = ["0222263942b11f7a78e11c43903094f870a2bf728bc8be085023b4eaf4e6228cd9", "02250c8c8f7f7e1468cdc5e9b9203841ba14250e2f480f77ebcd502f3e691506d8", global.DEVELOP_PUB_KEY_ARR = ["0222263942b11f7a78e11c43903094f870a2bf728bc8be085023b4eaf4e6228cd9", "02250c8c8f7f7e1468cdc5e9b9203841ba14250e2f480f77ebcd502f3e691506d8",
"027c0caec4e6f8f08d220f6dab24bb6f53d3f1d7b95231216805d9fac85d34a95f", "025defd5b884cc02f6948cd0d62b03d7b7445bf942206ab935158b6be8f0f7a2ce", "027c0caec4e6f8f08d220f6dab24bb6f53d3f1d7b95231216805d9fac85d34a95f", "025defd5b884cc02f6948cd0d62b03d7b7445bf942206ab935158b6be8f0f7a2ce",
"024a97d69cd81c965f162b4b8b7b506263bc8aec8dbcea9eec59f73b5b470a0be1",]; "024a97d69cd81c965f162b4b8b7b506263bc8aec8dbcea9eec59f73b5b470a0be1",];
let DEVELOP_PUB_KEY_ARR: any = global.DEVELOP_PUB_KEY_ARR; for (var i = 0; i < global.DEVELOP_PUB_KEY_ARR.length; i++)
for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++) global.DEVELOP_PUB_KEY_ARR[i] = Buffer.from(global.GetArrFromHex(global.DEVELOP_PUB_KEY_ARR[i]));
DEVELOP_PUB_KEY_ARR[i] = Buffer.from(global.GetArrFromHex(DEVELOP_PUB_KEY_ARR[i])); global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY_ARR[0];
global.DEVELOP_PUB_KEY = DEVELOP_PUB_KEY_ARR[0];
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("022e80aa78bc07c72781fac12488096f0bfa7b4f48fbab0f2a92e208d1ee3654df")); global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("022e80aa78bc07c72781fac12488096f0bfa7b4f48fbab0f2a92e208d1ee3654df"));
if (global.LOCAL_RUN) { if (global.LOCAL_RUN) {
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("026A04AB98D9E4774AD806E302DDDEB63BEA16B5CB5F223EE77478E861BB583EB3")); global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("03047E3BB0F0C1C46F478BDFA7DDAF908F5AEA0B303F33EB53ACC4F0FD14475A90"));
global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY0; global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY0;
} }
global.ARR_PUB_KEY = ["027ae0dce92d8be1f893525b226695ddf0fe6ad756349a76777ff51f3b59067d70", "02769165a6f9950d023a415ee668b80bb96b5c9ae2035d97bdfb44f356175a44ff", global.ARR_PUB_KEY = ["027ae0dce92d8be1f893525b226695ddf0fe6ad756349a76777ff51f3b59067d70", "02769165a6f9950d023a415ee668b80bb96b5c9ae2035d97bdfb44f356175a44ff",
@ -977,12 +976,11 @@ global.ARR_PUB_KEY = ["027ae0dce92d8be1f893525b226695ddf0fe6ad756349a76777ff51f3
"0270e0c5acb8eefe7faddac45503da4885e02fb554975d12907f6c33ac6c6bdba5", "0202f2aad628f46d433faf70ba6bf12ab9ed96a46923b592a72508dc43af36cb80", "0270e0c5acb8eefe7faddac45503da4885e02fb554975d12907f6c33ac6c6bdba5", "0202f2aad628f46d433faf70ba6bf12ab9ed96a46923b592a72508dc43af36cb80",
"0254f373fc44ac4a3e80ec8cb8cc3693a856caa82e0493067bdead78ce8ec354b8", "027617f9511b0b0cdbda8f3e17907732731296321846f3fd6fd19460f7227d9482", "0254f373fc44ac4a3e80ec8cb8cc3693a856caa82e0493067bdead78ce8ec354b8", "027617f9511b0b0cdbda8f3e17907732731296321846f3fd6fd19460f7227d9482",
]; ];
// let GetHexFromArr = global.GetHexFromArr;
if (global.TEST_NETWORK || global.LOCAL_RUN) { if (global.TEST_NETWORK || global.LOCAL_RUN) {
for (var i = 0; i < 100; i++) for (var i = 0; i < 100; i++)
global.ARR_PUB_KEY[i] = global.GetHexFromArr(global.DEVELOP_PUB_KEY0); global.ARR_PUB_KEY[i] = global.GetHexFromArr(global.DEVELOP_PUB_KEY0);
global.DEVELOP_PUB_KEY_ARR = [global.DEVELOP_PUB_KEY0]; global.DEVELOP_PUB_KEY_ARR = [global.DEVELOP_PUB_KEY0];
global.DEVELOP_PUB_KEY = DEVELOP_PUB_KEY_ARR[0]; global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY_ARR[0];
} }
declare global { declare global {
namespace NodeJS { namespace NodeJS {
@ -1030,7 +1028,7 @@ declare global {
Utf8ArrayToStr: Function; Utf8ArrayToStr: Function;
GetArrFromStr: Function; GetArrFromStr: Function;
IsDeveloperAccount: Function; IsDeveloperAccount: Function;
DEVELOP_PUB_KEY_ARR: Buffer[] | string[]; DEVELOP_PUB_KEY_ARR: any[];
DEVELOP_PUB_KEY: any; DEVELOP_PUB_KEY: any;
DEVELOP_PUB_KEY0: Buffer; DEVELOP_PUB_KEY0: Buffer;
ARR_PUB_KEY: any; ARR_PUB_KEY: any;

View File

@ -668,11 +668,12 @@ export default class CDB extends CCode {
if (Block.BlockNum < 16 || Block.Miner > MaxAccount) if (Block.BlockNum < 16 || Block.Miner > MaxAccount)
Block.Miner = 0 Block.Miner = 0
if (bMinerName && Block.Miner) { if (bMinerName && Block.Miner) {
Block.MinerName = ""
if (Block.Miner) {
var Item = global.DApps.Accounts.ReadState(Block.Miner); var Item = global.DApps.Accounts.ReadState(Block.Miner);
if (Item && Item.Name) if (Item && Item.Name)
Block.MinerName = Item.Name.substr(0, 8) Block.MinerName = Item.Name.substr(0, 8)
else }
Block.MinerName = ""
} }
var Value = global.GetHashFromSeqAddr(Block.SeqHash, Block.AddrHash, Block.BlockNum, Block.PrevHash); var Value = global.GetHashFromSeqAddr(Block.SeqHash, Block.AddrHash, Block.BlockNum, Block.PrevHash);
Block.Hash1 = Value.Hash1 Block.Hash1 = Value.Hash1
@ -687,8 +688,7 @@ export default class CDB extends CCode {
try { try {
if (!eval(Filter)) if (!eval(Filter))
continue; continue;
} } catch (e) {
catch (e) {
if (!WasError) if (!WasError)
global.ToLog(e) global.ToLog(e)
WasError = 1 WasError = 1
@ -844,7 +844,7 @@ export default class CDB extends CCode {
var StartNumStat = this.StatMap.StartBlockNum; var StartNumStat = this.StatMap.StartBlockNum;
var FinishNumStat = this.StatMap.StartBlockNum + this.StatMap.Length - 1; var FinishNumStat = this.StatMap.StartBlockNum + this.StatMap.Length - 1;
var CountReadDB = 0; var CountReadDB = 0;
var arr = new Array(MinLength); let arr = new Array(MinLength);
var arrmy = new Array(MinLength); var arrmy = new Array(MinLength);
for (var num = start; num < finish; num++) { for (var num = start; num < finish; num++) {
var i = num - start; var i = num - start;
@ -884,7 +884,7 @@ export default class CDB extends CCode {
this.StatMap["POWER_BLOCKCHAIN"] = arr this.StatMap["POWER_BLOCKCHAIN"] = arr
this.StatMap["POWER_MY_WIN"] = arrmy this.StatMap["POWER_MY_WIN"] = arrmy
} }
arr = this.StatMap[name]; var arr = this.StatMap[name];
if (!arr) if (!arr)
arr = [] arr = []
var arrT = this.StatMap["POWER_BLOCKCHAIN"]; var arrT = this.StatMap["POWER_BLOCKCHAIN"];
@ -940,11 +940,9 @@ export default class CDB extends CCode {
var Block = arr0[arr0.length - 1]; var Block = arr0[arr0.length - 1];
if (Block.BlockNum >= StartNum && Block.BlockNum <= EndBlockNum) { if (Block.BlockNum >= StartNum && Block.BlockNum <= EndBlockNum) {
var BlockDB = this.ReadBlockHeaderDB(Block.BlockNum); var BlockDB = this.ReadBlockHeaderDB(Block.BlockNum);
if (!BlockDB || global.CompareArr(Block.SumHash, global.BlockDB.SumHash) !== 0) { if (!BlockDB || global.CompareArr(Block.SumHash, BlockDB.SumHash) !== 0) {
arr0 = undefined arr0 = undefined
} }
else {
}
} }
} }
var i0 = 0; var i0 = 0;

View File

@ -12,7 +12,7 @@
import * as fs from 'fs' import * as fs from 'fs'
import Db from './db' import Db from './db'
class DBRow extends Db { export default class DBRow extends Db {
FileName; FileName;
DataSize; DataSize;
Format; Format;
@ -227,5 +227,3 @@ class DBRow extends Db {
this.CloseDBFile(this.FileName) this.CloseDBFile(this.FileName)
} }
}; };
export default DBRow

View File

@ -11,7 +11,7 @@
"use strict"; "use strict";
import * as fs from 'fs' import * as fs from 'fs'
class Db { export default class Db {
DBMap; DBMap;
LastHash; LastHash;
WasUpdate; WasUpdate;
@ -112,5 +112,3 @@ declare global {
} }
} }
} }
export default Db;

View File

@ -12,10 +12,10 @@
import './crypto-library' import './crypto-library'
import './log' import './log'
import { secp256k1 } from '../core/library' import { secp256k1 } from '../core/library'
import http = require('http'); import * as http from 'http'
import url = require('url'); import * as url from 'url'
import fs = require('fs'); import * as fs from 'fs'
import querystring = require('querystring'); import * as querystring from 'querystring'
import * as crypto from 'crypto'; import * as crypto from 'crypto';
var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number"); var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
@ -529,7 +529,7 @@ HTTPCaller.GetWalletInfo = function(Params) {
CurTime: Date.now(), CurTime: Date.now(),
IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr), IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr),
AccountMap: global.WALLET.AccountMap, AccountMap: global.WALLET.AccountMap,
ArrLog: global.global.ArrLogClient, ArrLog: global.ArrLogClient,
MaxAccID: global.DApps.Accounts.GetMaxAccount(), MaxAccID: global.DApps.Accounts.GetMaxAccount(),
MaxActNum: global.DApps.Accounts.GetActsMaxNum(), MaxActNum: global.DApps.Accounts.GetActsMaxNum(),
MaxDappsID: global.DApps.Smart.GetMaxNum(), MaxDappsID: global.DApps.Smart.GetMaxNum(),

View File

@ -10,6 +10,7 @@
"use strict"; "use strict";
import CDB from './db/block-db' import CDB from './db/block-db'
import { TYPE_TRANSACTION } from '../constant/account';
export default class CRest extends CDB { export default class CRest extends CDB {
LoadRestContext LoadRestContext
BlockNumDB BlockNumDB
@ -164,7 +165,7 @@ export default class CRest extends CDB {
var FindTx = undefined; var FindTx = undefined;
for (var n = 0; n < Data.arrContent.length; n++) { for (var n = 0; n < Data.arrContent.length; n++) {
var Body = Data.arrContent[n]; var Body = Data.arrContent[n];
if (Body[0] === global.TYPE_TRANSACTION_ACC_HASH) { if (Body[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH) {
try { try {
FindTx = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_ACCOUNT_HASH3, {}) FindTx = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_ACCOUNT_HASH3, {})
} }
@ -371,7 +372,7 @@ export default class CRest extends CDB {
} }
} }
GetBlockArrFromBuffer_Load(BufRead, Info?): any { GetBlockArrFromBuffer_Load(BufRead, Info?): any {
//defiend in block-loader.ts(CBlock)
} }
RETBLOCKHEADER_REST(Info, CurTime) { RETBLOCKHEADER_REST(Info, CurTime) {
if (Info.Node.SendRestGetHeader === 2) if (Info.Node.SendRestGetHeader === 2)

View File

@ -9,7 +9,7 @@
*/ */
"use strict"; "use strict";
import net = require("net"); import * as net from 'net'
// import dgram = require("dgram"); // import dgram = require("dgram");
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import "./library" import "./library"

View File

@ -10,6 +10,7 @@
"use strict"; "use strict";
import CConsensus from './block-exchange' import CConsensus from './block-exchange'
import { TYPE_TRANSACTION } from '../constant/account';
require("../system/dapp"); require("../system/dapp");
require("../system/accounts"); require("../system/accounts");
require("../system/smart"); require("../system/smart");
@ -175,7 +176,7 @@ export default class CSmartContract extends CConsensus {
return - 2; return - 2;
if (Tr.num !== BlockNum) if (Tr.num !== BlockNum)
return - 3; return - 3;
if (Tr.body[0] === global.TYPE_TRANSACTION_ACC_HASH) if (Tr.body[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH)
return - 4; return - 4;
return 1; return 1;
} }
@ -205,7 +206,7 @@ export default class CSmartContract extends CConsensus {
return; return;
var Item = global.DApps.Accounts.GetAccountHashItem(BlockNumHash); var Item = global.DApps.Accounts.GetAccountHashItem(BlockNumHash);
if (Item) { if (Item) {
var Body = [global.TYPE_TRANSACTION_ACC_HASH]; var Body = [TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH];
global.WriteUintToArr(Body, BlockNumHash) global.WriteUintToArr(Body, BlockNumHash)
global.WriteArrToArr(Body, Item.AccHash, 32) global.WriteArrToArr(Body, Item.AccHash, 32)
if (BlockNumHash >= global.START_BLOCK_ACCOUNT_HASH3) { if (BlockNumHash >= global.START_BLOCK_ACCOUNT_HASH3) {

View File

@ -132,7 +132,7 @@ export default class CMessages extends CSmartContract {
} }
this.SendF(Info.Node, { "Method": "MESSAGE", "Context": Info.Context, "Data": { Arr: arr } }, BufLength) this.SendF(Info.Node, { "Method": "MESSAGE", "Context": Info.Context, "Data": { Arr: arr } }, BufLength)
} }
AddTransaction(Tr, ToAll) { AddTransaction(Tr, ToAll?) {
Tr.ToAll = ToAll Tr.ToAll = ToAll
var Res = this.IsValidTransaction(Tr, this.CurrentBlockNum); var Res = this.IsValidTransaction(Tr, this.CurrentBlockNum);
if (Res <= 0 && Res !== - 3) if (Res <= 0 && Res !== - 3)

19
src/global.d.ts vendored
View File

@ -1,5 +1,9 @@
export { }; export { };
import CSmartContract from './core/transaction-validator'
import CConsensus from './core/block-exchange'
import CTransport from './core/server'
declare global { declare global {
var nw: any; var nw: any;
interface TeraError { interface TeraError {
@ -46,7 +50,10 @@ declare global {
BLOCKNUM_TICKET_ALGO: number; BLOCKNUM_TICKET_ALGO: number;
WATCHDOG_BADACCOUNT: number; WATCHDOG_BADACCOUNT: number;
WATCHDOG_DEV: number; WATCHDOG_DEV: number;
RESYNC_CONDITION: any; RESYNC_CONDITION: {
OWN_BLOCKS: number;
K_POW: number;
};
REST_BLOCK_SCALE: number; REST_BLOCK_SCALE: number;
REST_START_COUNT: number; REST_START_COUNT: number;
LOAD_TO_BEGIN: number; LOAD_TO_BEGIN: number;
@ -190,7 +197,7 @@ declare global {
ArrConnect: any[]; ArrConnect: any[];
//#region main-process.ts:51 //#region main-process.ts:51
SERVER: any; SERVER: CSmartContract | CConsensus | CTransport | any;
NeedRestart: number; NeedRestart: number;
WEB_PROCESS: TeraProcess; WEB_PROCESS: TeraProcess;
CountAllNode: number; CountAllNode: number;
@ -241,12 +248,12 @@ declare global {
CompareItemBufFD: Function; CompareItemBufFD: Function;
CompareArr33: Function; CompareArr33: Function;
CompareItemHashSimple: Function; CompareItemHashSimple: Function;
CompareItemHash: Function; CompareItemHash: any;
CompareItemHash32: Function; CompareItemHash32: Function;
CompareItemHASH32: Function; CompareItemHASH32: Function;
CompareItemHash33: Function; CompareItemHash33: Function;
CompareItemHashPow: Function; CompareItemHashPow: Function;
CompareItemTimePow: Function; CompareItemTimePow: any;
LOAD_CONST: Function; LOAD_CONST: Function;
SAVE_CONST: Function; SAVE_CONST: Function;
CheckGlobalTime: Function; CheckGlobalTime: Function;
@ -368,7 +375,7 @@ declare global {
//#endregion //#endregion
//#region web-process.ts //#region web-process.ts
LoadBlockFromNetwork: Function; LoadBlockFromNetwork: (Params, F?) => any;
GlobalRunID: number; GlobalRunID: number;
//#endregion //#endregion
@ -525,7 +532,7 @@ declare global {
CopyObjValue: Function; CopyObjValue: Function;
CopyArr: Function; CopyArr: Function;
ParseNum: Function; ParseNum: Function;
CompareArr: Function; CompareArr: (a: any[], b: any[]) => number;
CompareArrL: Function; CompareArrL: Function;
shaarr2: Function; shaarr2: Function;
sha3arr2: Function; sha3arr2: Function;

View File

@ -9,6 +9,7 @@
*/ */
let WebApi2: any = {}; let WebApi2: any = {};
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import { TYPE_TRANSACTION } from '../constant/account';
WebApi2.GenerateKeys = function(Params) { WebApi2.GenerateKeys = function(Params) {
var KeyPair = crypto.createECDH('secp256k1'); var KeyPair = crypto.createECDH('secp256k1');
var PrivKey = global.sha3(crypto.randomBytes(32)); var PrivKey = global.sha3(crypto.randomBytes(32));
@ -21,7 +22,7 @@ WebApi2.CreateAccount = function(Params, response) {
var KeyPair = crypto.createECDH('secp256k1'); var KeyPair = crypto.createECDH('secp256k1');
KeyPair.setPrivateKey(Buffer.from(global.GetArrFromHex(Params.PrivKey))); KeyPair.setPrivateKey(Buffer.from(global.GetArrFromHex(Params.PrivKey)));
var PubKey = KeyPair.getPublicKey('' as any, 'compressed'); var PubKey = KeyPair.getPublicKey('' as any, 'compressed');
var TR: any = { Type: global.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: PubKey, Name: Params.Name, Smart: Params.Smart, }; var TR: any = { Type: TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: PubKey, Name: Params.Name, Smart: Params.Smart, };
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {}, 1); var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {}, 1);
Body = Body.slice(0, Body.len + 12); Body = Body.slice(0, Body.len + 12);
SendTransaction(Body, TR as any, Params.Wait, function(result, text) { SendTransaction(Body, TR as any, Params.Wait, function(result, text) {
@ -270,7 +271,7 @@ function CreateTxID(body, BlockNum, Nonce) {
function GetBlockNumTr(arr) { function GetBlockNumTr(arr) {
var BlockNum = DELTA_FOR_TIME_TX + global.GetCurrentBlockNumByTime(); var BlockNum = DELTA_FOR_TIME_TX + global.GetCurrentBlockNumByTime();
if (arr[0] === global.TYPE_TRANSACTION_CREATE) { if (arr[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE) {
var BlockNum2 = Math.floor(BlockNum / 10) * 10; var BlockNum2 = Math.floor(BlockNum / 10) * 10;
if (BlockNum2 < BlockNum) if (BlockNum2 < BlockNum)
BlockNum2 = BlockNum2 + 10; BlockNum2 = BlockNum2 + 10;

View File

@ -10,8 +10,8 @@
import '../core/constant' import '../core/constant'
global.PROCESS_NAME = "MAIN"; global.PROCESS_NAME = "MAIN";
import fs = require('fs'); import * as fs from 'fs'
import os = require('os'); import * as os from 'os'
// import path = require('path') // import path = require('path')
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import { secp256k1 } from '../core/library' import { secp256k1 } from '../core/library'
@ -236,9 +236,8 @@ function StartChildProcess(Item) {
global.ToLog("KILL PROCESS " + ITEM.Name + ": " + ITEM.Worker.pid); global.ToLog("KILL PROCESS " + ITEM.Name + ": " + ITEM.Worker.pid);
try { try {
process.kill(ITEM.Worker.pid, 'SIGKILL'); process.kill(ITEM.Worker.pid, 'SIGKILL');
} } catch (e) {
catch (e) { global.ToLog("ERR KILL" + e);
global.ToLog("ERR KILL");
} }
ITEM.Worker = undefined; ITEM.Worker = undefined;
} }

View File

@ -71,8 +71,7 @@ function StartHashPump(e) {
(!global.BlockPump || global.BlockPump.BlockNum < e.BlockNum || global.BlockPump.MinerID !== e.MinerID || global.BlockPump.Percent !== e.Percent) && (global.BlockPump = { (!global.BlockPump || global.BlockPump.BlockNum < e.BlockNum || global.BlockPump.MinerID !== e.MinerID || global.BlockPump.Percent !== e.Percent) && (global.BlockPump = {
BlockNum: e.BlockNum, BlockNum: e.BlockNum,
RunCount: e.RunCount, MinerID: e.MinerID, Percent: e.Percent, LastNonce: 0 RunCount: e.RunCount, MinerID: e.MinerID, Percent: e.Percent, LastNonce: 0
}), idIntervalPump = idIntervalPump || setInterval(PumpHash, }), idIntervalPump = idIntervalPump || setInterval(PumpHash, global.POWRunPeriod);
global.POWRunPeriod);
}; };
var StartTime = 1, EndTime = 0; var StartTime = 1, EndTime = 0;

View File

@ -14,6 +14,7 @@ import DApp from './dapp'
import DBRow from '../core/db/db-row' import DBRow from '../core/db/db-row'
import DBLib from "../core/db/db" import DBLib from "../core/db/db"
import { secp256k1 } from '../core/library' import { secp256k1 } from '../core/library'
import { TYPE_TRANSACTION } from '../constant/account'
require('../core/rest_tables'); require('../core/rest_tables');
const MAX_SUM_TER = 1e9; const MAX_SUM_TER = 1e9;
const MAX_SUM_CENT = 1e9; const MAX_SUM_CENT = 1e9;
@ -76,7 +77,7 @@ global.FORMAT_ACCOUNT_HASH = "{\
BlockNum:uint,\ BlockNum:uint,\
AccHash:buffer32,\ AccHash:buffer32,\
}"; }";
global.global.FORMAT_ACCOUNT_HASH3 = "{\ global.FORMAT_ACCOUNT_HASH3 = "{\
Type:byte,\ Type:byte,\
BlockNum:uint,\ BlockNum:uint,\
AccHash:buffer32,\ AccHash:buffer32,\
@ -317,7 +318,7 @@ class AccountApp extends DApp {
var Type = Body[0]; var Type = Body[0];
if (Type && Body.length > 90) { if (Type && Body.length > 90) {
switch (Type) { switch (Type) {
case global.TYPE_TRANSACTION_CREATE: case TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE:
{ {
if (BlockNum % BLOCK_CREATE_INTERVAL !== 0) if (BlockNum % BLOCK_CREATE_INTERVAL !== 0)
return 0; return 0;
@ -371,7 +372,7 @@ class AccountApp extends DApp {
var Type = Body[0]; var Type = Body[0];
var Result; var Result;
switch (Type) { switch (Type) {
case global.TYPE_TRANSACTION_CREATE: case TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE:
{ {
Result = this.TRCreateAccount(Body, BlockNum, TrNum, ContextFrom) Result = this.TRCreateAccount(Body, BlockNum, TrNum, ContextFrom)
break; break;
@ -391,13 +392,13 @@ class AccountApp extends DApp {
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, global.FORMAT_MONEY_TRANSFER3, WorkStructTransfer3) Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, global.FORMAT_MONEY_TRANSFER3, WorkStructTransfer3)
break; break;
} }
case global.TYPE_TRANSACTION_ACC_HASH: case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
{ {
Result = 1 Result = 1
if (global.LOCAL_RUN || global.TEST_NETWORK) { if (global.LOCAL_RUN || global.TEST_NETWORK) {
} else { } else {
if (BlockNum < global.global.START_BLOCK_ACCOUNT_HASH + 200000) if (BlockNum < global.START_BLOCK_ACCOUNT_HASH + 200000)
break; break;
} }
var BlockNumHash = BlockNum - global.DELTA_BLOCK_ACCOUNT_HASH; var BlockNumHash = BlockNum - global.DELTA_BLOCK_ACCOUNT_HASH;
@ -481,7 +482,7 @@ class AccountApp extends DApp {
var Type = Body[0]; var Type = Body[0];
var format; var format;
switch (Type) { switch (Type) {
case global.TYPE_TRANSACTION_CREATE: case TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE:
{ {
format = global.FORMAT_CREATE format = global.FORMAT_CREATE
break; break;
@ -501,9 +502,9 @@ class AccountApp extends DApp {
format = global.FORMAT_MONEY_TRANSFER3 format = global.FORMAT_MONEY_TRANSFER3
break; break;
} }
case global.TYPE_TRANSACTION_ACC_HASH: case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
{ {
format = global.global.FORMAT_ACCOUNT_HASH3 format = global.FORMAT_ACCOUNT_HASH3
break; break;
} }
default: default:
@ -1393,11 +1394,11 @@ class AccountApp extends DApp {
}; };
var App = new AccountApp; var App = new AccountApp;
global.DApps["Accounts"] = App; global.DApps["Accounts"] = App;
global.DAppByType[global.TYPE_TRANSACTION_CREATE] = App; global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE] = App;
global.DAppByType[TYPE_DEPRECATED_TRANSFER1] = App; global.DAppByType[TYPE_DEPRECATED_TRANSFER1] = App;
global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App; global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App;
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App; global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
global.DAppByType[global.TYPE_TRANSACTION_ACC_HASH] = App; global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH] = App;
export default AccountApp; export default AccountApp;
// function TestStateFiles(Size, Format) { // function TestStateFiles(Size, Format) {

View File

@ -370,7 +370,7 @@ class SmartApp extends DApp {
Filter = Filter.toUpperCase() Filter = Filter.toUpperCase()
} }
if (Category) if (Category)
Category = global.global.ParseNum(Category) Category = global.ParseNum(Category)
var WasError = 0; var WasError = 0;
var arr = []; var arr = [];
var Data; var Data;
@ -436,7 +436,7 @@ class SmartApp extends DApp {
this.DBSmart.Write(Item) this.DBSmart.Write(Item)
} }
ReadSmart(Num) { ReadSmart(Num) {
Num = global.global.ParseNum(Num) Num = global.ParseNum(Num)
var Smart = this.DBSmart.GetMap("ITEM" + Num); var Smart = this.DBSmart.GetMap("ITEM" + Num);
if (!Smart) { if (!Smart) {
Smart = this.DBSmart.Read(Num) Smart = this.DBSmart.Read(Num)

View File

@ -2,7 +2,6 @@
"compilerOptions": { "compilerOptions": {
"outDir": "dist", "outDir": "dist",
"allowJs": true, "allowJs": true,
"sourceMap": true,
"target": "es5" "target": "es5"
}, },
"include": [ "include": [