Fri Jul 19 12:26:00 CST 2019 Source Update...

This commit is contained in:
MiaoWoo 2019-07-19 12:26:00 +08:00
parent 9e5466dfdd
commit 6d7e4474f7
26 changed files with 400 additions and 368 deletions

View File

@ -2753,3 +2753,12 @@ iframe
cursor: pointer; cursor: pointer;
} }
.btn--float
{
float: left;
width: 230px;
margin: 10px;
}

View File

@ -13,6 +13,17 @@ function $(id)
{ {
return document.getElementById(id); return document.getElementById(id);
}; };
window.Storage = {};
window.Storage.setItem = function (Key,Value)
{
if(window.localStorage)
localStorage.setItem(Key, Value);
};
window.Storage.getItem = function (Key)
{
if(window.localStorage)
return localStorage.getItem(Key);
};
var WALLET_KEY_NAME = "WALLET_KEY"; var WALLET_KEY_NAME = "WALLET_KEY";
var WALLET_PUB_KEY_NAME = "WALLET_PUB_KEY"; var WALLET_PUB_KEY_NAME = "WALLET_PUB_KEY";
if(!Math.log2) if(!Math.log2)
@ -49,17 +60,6 @@ if(!String.prototype.padStart)
} }
}; };
} }
window.Storage = {};
window.Storage.setItem = function (Key,Value)
{
if(window.localStorage)
localStorage.setItem(Key, Value);
};
window.Storage.getItem = function (Key)
{
if(window.localStorage)
return localStorage.getItem(Key);
};
window.IsLocalClient = function () window.IsLocalClient = function ()
{ {
return (window.location.protocol.substr(0, 4) !== "http"); return (window.location.protocol.substr(0, 4) !== "http");
@ -937,7 +937,7 @@ function RetIconPath(Item,bCurrency)
return StrPath + '/file/' + Item.IconBlockNum + '/' + Item.IconTrNum; return StrPath + '/file/' + Item.IconBlockNum + '/' + Item.IconTrNum;
} }
else else
return StrPath + "./PIC/blank.svg"; return StrPath + "/PIC/blank.svg";
}; };
function RetIconDapp(Item) function RetIconDapp(Item)
@ -1437,9 +1437,9 @@ function AddToInvoiceList(Item)
Storage.setItem("InvoiceList", JSON.stringify(arr)); Storage.setItem("InvoiceList", JSON.stringify(arr));
}; };
function OpenDapps(Num,AccountNum) function OpenDapps(Num,AccountNum,HTMLLength)
{ {
if(!Num) if(!Num || !HTMLLength)
return ; return ;
var StrPath = '/dapp/' + Num; var StrPath = '/dapp/' + Num;
if(IsLocalClient()) if(IsLocalClient())
@ -1801,8 +1801,8 @@ function ToLog(Str)
function InitMainServer() function InitMainServer()
{ {
var Str = localStorage["MainServer"]; var Str = Storage.getItem("MainServer");
if(Str && !localStorage["BIGWALLET"] && Str.substr(0, 1) === "{") if(Str && !Storage.getItem("BIGWALLET") && Str.substr(0, 1) === "{")
{ {
MainServer = JSON.parse(Str); MainServer = JSON.parse(Str);
} }
@ -1823,13 +1823,13 @@ var KeyPasswordMap = {};
function InitWalletKeyName() function InitWalletKeyName()
{ {
if(!localStorage["WALLET_KEY"]) if(!Storage.getItem("WALLET_KEY"))
{ {
localStorage["WALLET_KEY"] = localStorage["idPrivKey"]; Storage.setItem("WALLET_KEY", Storage.getItem("idPrivKey"));
} }
if(!localStorage["WALLET_PUB_KEY"]) if(!Storage.getItem("WALLET_PUB_KEY"))
{ {
localStorage["WALLET_PUB_KEY"] = localStorage["idPubKey"]; Storage.setItem("WALLET_PUB_KEY", Storage.getItem("idPubKey"));
} }
}; };
@ -1862,8 +1862,11 @@ function OpenWalletKey()
{ {
PubKeyStr = ""; PubKeyStr = "";
} }
if(window.sessionStorage)
{
sessionStorage[WALLET_KEY_NAME] = RetKey; sessionStorage[WALLET_KEY_NAME] = RetKey;
sessionStorage[WALLET_PUB_KEY_NAME] = PubKeyStr; sessionStorage[WALLET_PUB_KEY_NAME] = PubKeyStr;
}
if(!WALLET_PASSWORD) if(!WALLET_PASSWORD)
Storage.setItem(WALLET_PUB_KEY_NAME, PubKeyStr); Storage.setItem(WALLET_PUB_KEY_NAME, PubKeyStr);
return RetKey; return RetKey;
@ -1880,18 +1883,28 @@ function IsLockedWallet()
function GetPrivKey() function GetPrivKey()
{ {
var Key = sessionStorage[WALLET_KEY_NAME]; var Key;
if(window.sessionStorage)
Key = sessionStorage[WALLET_KEY_NAME];
if(!Key) if(!Key)
Key = Storage.getItem(WALLET_KEY_NAME); Key = Storage.getItem(WALLET_KEY_NAME);
if(Key && typeof Key === "string" && Key.length >= 64)
return Key; return Key;
else
return "";
}; };
function GetPubKey() function GetPubKey()
{ {
var Key = sessionStorage[WALLET_PUB_KEY_NAME]; var Key;
if(window.sessionStorage)
Key = sessionStorage[WALLET_PUB_KEY_NAME];
if(!Key) if(!Key)
Key = Storage.getItem(WALLET_PUB_KEY_NAME); Key = Storage.getItem(WALLET_PUB_KEY_NAME);
if(Key && typeof Key === "string" && Key.length >= 66)
return Key; return Key;
else
return "";
}; };
function SetPrivKey(StrPrivKey) function SetPrivKey(StrPrivKey)
@ -1912,15 +1925,18 @@ function SetPrivKey(StrPrivKey)
Storage.setItem(WALLET_KEY_NAME, Key); Storage.setItem(WALLET_KEY_NAME, Key);
Storage.setItem(WALLET_PUB_KEY_NAME, StrPubKey); Storage.setItem(WALLET_PUB_KEY_NAME, StrPubKey);
Storage.setItem("WALLET_PUB_KEY_MAIN", StrPubKey); Storage.setItem("WALLET_PUB_KEY_MAIN", StrPubKey);
if(window.sessionStorage)
{
sessionStorage[WALLET_KEY_NAME] = StrPrivKey; sessionStorage[WALLET_KEY_NAME] = StrPrivKey;
sessionStorage[WALLET_PUB_KEY_NAME] = StrPubKey; sessionStorage[WALLET_PUB_KEY_NAME] = StrPubKey;
}
}; };
function SetWalletPassword(Str) function SetWalletPassword(Str)
{ {
WALLET_PASSWORD = Str; WALLET_PASSWORD = Str;
if(localStorage["idPrivKey"]) if(Storage.getItem("idPrivKey"))
delete localStorage["idPrivKey"]; Storage.setItem("idPrivKey", "");
}; };
function HashProtect(Str) function HashProtect(Str)
@ -1942,3 +1958,11 @@ function XORHash(arr1,arr2,length)
} }
return arr3; return arr3;
}; };
function Right(Str,count)
{
if(Str.length > count)
return Str.substr(Str.length - count, count);
else
return Str.substr(0, Str.length);
};

View File

@ -11,6 +11,14 @@
var MAX_SUM_TER = 1e9; var MAX_SUM_TER = 1e9;
var MAX_SUM_CENT = 1e9; var MAX_SUM_CENT = 1e9;
function CHECKSUM(Coin)
{
if(typeof Coin.SumCOIN !== "number")
Coin.SumCOIN = 0;
if(typeof Coin.SumCENT !== "number")
Coin.SumCENT = 0;
};
function ADD(Coin,Value2) function ADD(Coin,Value2)
{ {
Coin.SumCOIN += Value2.SumCOIN; Coin.SumCOIN += Value2.SumCOIN;
@ -102,6 +110,7 @@ function COIN_FROM_STRING(Str)
}; };
if(typeof global === "object") if(typeof global === "object")
{ {
global.CHECKSUM = CHECKSUM;
global.ADD = ADD; global.ADD = ADD;
global.SUB = SUB; global.SUB = SUB;
global.DIV = DIV; global.DIV = DIV;

View File

@ -135,6 +135,15 @@ window.GetCurrentBlockNumByTime = function ()
return 0; return 0;
}; };
function SetMinPow()
{
var item = $("idDeltaPow");
if(item)
{
window.DELTA_POWER_POW_TR = ParseNum(item.value);
}
};
function GetBlockNumTr(arr) function GetBlockNumTr(arr)
{ {
var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime(); var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
@ -153,6 +162,7 @@ var LastCreatePOWHash = [255, 255, 255, 255];
function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce) function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
{ {
SetMinPow();
var TrType = arr[0]; var TrType = arr[0];
var BlockNum = GetBlockNumTr(arr); var BlockNum = GetBlockNumTr(arr);
if(MinPow === undefined) if(MinPow === undefined)

View File

@ -74,17 +74,25 @@ window.onload = function ()
}; };
function OnLoad() function OnLoad()
{
if(window.location.protocol === "https:")
{
NETWORK = "TERA-MAIN";
FillSelect("idCurNetwork", [{value:NETWORK, text:"TERA MAIN"}]);
$("idCurNetwork").value = NETWORK;
Storage.setItem("NETWORK", NETWORK);
}
else
{ {
if(Storage.getItem("NETWORK")) if(Storage.getItem("NETWORK"))
{ {
NETWORK = Storage.getItem("NETWORK"); NETWORK = Storage.getItem("NETWORK");
} }
$("idCurNetwork").value = NETWORK; $("idCurNetwork").value = NETWORK;
}
LoadValues(); LoadValues();
InitDappsCard(); InitDappsCard();
StartWebWallet(); StartWebWallet();
UpdatesExplorerData();
UpdatesAccountsData();
setInterval(UpdatesExplorerData, 1000); setInterval(UpdatesExplorerData, 1000);
setInterval(UpdatesAccountsData, 1000); setInterval(UpdatesAccountsData, 1000);
DoStableScroll(); DoStableScroll();
@ -107,9 +115,14 @@ function ChangeNetwork()
CONNECT_STATUS = 0; CONNECT_STATUS = 0;
NETWORK = $("idCurNetwork").value; NETWORK = $("idCurNetwork").value;
Storage.setItem("NETWORK", NETWORK); Storage.setItem("NETWORK", NETWORK);
StartWebWallet(); ConnectWebWallet();
};
function UpdateTabs()
{
UpdatesExplorerData(); UpdatesExplorerData();
UpdatesAccountsData(); UpdatesAccountsData();
ViewDapps();
}; };
function OnFindServer() function OnFindServer()
@ -124,13 +137,16 @@ function OnFindServer()
CONNECT_STATUS = 2; CONNECT_STATUS = 2;
Storage.setItem("MainServer", JSON.stringify({ip:MainServer.ip, port:MainServer.port})); Storage.setItem("MainServer", JSON.stringify({ip:MainServer.ip, port:MainServer.port}));
FillCurrencyAsync("idAccountCur"); FillCurrencyAsync("idAccountCur");
UpdateTabs();
}; };
function LoadValues() function LoadValues()
{ {
var StrDelList = localStorage["DelList"]; var StrDelList = Storage.getItem("DelList");
if(StrDelList) if(StrDelList)
DelList = JSON.parse(StrDelList); DelList = JSON.parse(StrDelList);
if(typeof DelList !== "object")
DelList = {};
if(LoadValuesByArr(SaveIdArr)) if(LoadValuesByArr(SaveIdArr))
{ {
ChangeLang(); ChangeLang();
@ -141,7 +157,7 @@ function LoadValues()
function SaveValues() function SaveValues()
{ {
SaveValuesByArr(SaveIdArr); SaveValuesByArr(SaveIdArr);
localStorage["DelList"] = JSON.stringify(DelList); Storage.setItem("DelList", JSON.stringify(DelList));
}; };
var TabArr = [{name:"TabWelcome"}, {name:"TabWalletSet"}, {name:"TabKeySet"}, {name:"TabAccounts"}, {name:"TabSend"}, {name:"TabDapps"}, var TabArr = [{name:"TabWelcome"}, {name:"TabWalletSet"}, {name:"TabKeySet"}, {name:"TabAccounts"}, {name:"TabSend"}, {name:"TabDapps"},
{name:"TabExplorer"}, {name:"TabLogo"}]; {name:"TabExplorer"}, {name:"TabLogo"}];
@ -300,10 +316,6 @@ function UpdatesAccountsData()
} }
else else
{ {
if(FirstAccountsData && !Data.arr.length)
{
SelectTab('TabAccounts');
}
} }
FirstAccountsData = 0; FirstAccountsData = 0;
}); });
@ -409,9 +421,21 @@ function SetAccountsCard(Data,AccountsDataStr)
var Str = StrAccCardTemplate; var Str = StrAccCardTemplate;
Str = Str.replace("AccCardTemplate", "idCard" + Item.Num); Str = Str.replace("AccCardTemplate", "idCard" + Item.Num);
Str = Str.replace(/{Item.Num}/g, Item.Num); Str = Str.replace(/{Item.Num}/g, Item.Num);
Str = Str.replace("{Value.SumCOIN}", Item.Value.SumCOIN); var Str1, Str2;
Str = Str.replace("{Value.SumCENT}", Item.Value.SumCENT); if(Item.Value.SumCOIN || Item.Value.SumCENT)
Str = Str.replace("{Value.CurrencyName}", CurrencyName(Item.Currency)); {
Str1 = Item.Value.SumCOIN;
Str2 = "," + Right("000000000" + Item.Value.SumCENT, 9);
}
else
{
Str1 = "";
Str2 = "";
}
var StrCurrencyName = CurrencyName(Item.Currency);
Str = Str.replace("{Value.SumCOIN}", Str1);
Str = Str.replace("{Value.SumCENT}", Str2);
Str = Str.replace("{Value.CurrencyName}", StrCurrencyName);
var CurrencyObj = Item.CurrencyObj; var CurrencyObj = Item.CurrencyObj;
if(!CurrencyObj) if(!CurrencyObj)
CurrencyObj = {IconBlockNum:0, Num:0}; CurrencyObj = {IconBlockNum:0, Num:0};
@ -422,11 +446,12 @@ function SetAccountsCard(Data,AccountsDataStr)
Str = Str.replace("{Item.Name}", escapeHtml(Item.Name)); Str = Str.replace("{Item.Name}", escapeHtml(Item.Name));
var SmartObj = Item.SmartObj; var SmartObj = Item.SmartObj;
if(!SmartObj) if(!SmartObj)
SmartObj = {Name:"", Num:0}; SmartObj = {Name:"", Num:0, HTMLLength:0};
SmartObj.IconPath = RetIconPath(SmartObj, 0); SmartObj.IconPath = RetIconPath(SmartObj, 0);
Str = Str.replace("{SmartObj.IconPath}", SmartObj.IconPath); Str = Str.replace("{SmartObj.IconPath}", SmartObj.IconPath);
Str = Str.replace("{SmartObj.Name}", escapeHtml(SmartObj.Name)); Str = Str.replace("{SmartObj.Name}", escapeHtml(SmartObj.Name));
Str = Str.replace(/{SmartObj.Num}/g, SmartObj.Num); Str = Str.replace(/{SmartObj.Num}/g, SmartObj.Num);
Str = Str.replace(/{SmartObj.HTMLLength}/g, SmartObj.HTMLLength);
if(SmartObj.Num) if(SmartObj.Num)
{ {
Str = Str.replace("prod-card__link--connect", "myhidden"); Str = Str.replace("prod-card__link--connect", "myhidden");
@ -462,15 +487,40 @@ function SetAccountsCard(Data,AccountsDataStr)
delete LoadMapAfter["idAccount"]; delete LoadMapAfter["idAccount"];
} }
}; };
var glWasSmart;
var glWasNumAccount;
function ChangeSmartLocal(NumAccount,WasSmart)
{
if(!IsPrivateMode())
{
SetError("Pls, open wallet");
return 0;
}
openModal('idSmartEnter');
if(WasSmart)
$("idSmartNum").value = WasSmart;
else
$("idSmartNum").value = "";
$("idSmartNum").focus();
glWasNumAccount = NumAccount;
glWasSmart = WasSmart;
};
function DoSetSmartLocal()
{
DoChangeSmart(glWasNumAccount, glWasSmart, $("idSmartNum").value);
closeModal();
};
function ConnectSmart(NumAccount) function ConnectSmart(NumAccount)
{ {
ChangeSmart(NumAccount, 0); ChangeSmartLocal(NumAccount, 0);
}; };
function SetSmart(NumAccount,WasSmart) function SetSmart(NumAccount,WasSmart)
{ {
ChangeSmart(NumAccount, WasSmart); ChangeSmartLocal(NumAccount, WasSmart);
}; };
function DelSmart(NumAccount,WasSmart) function DelSmart(NumAccount,WasSmart)
@ -914,6 +964,7 @@ function FillDappCard(Str,Item)
Str = Str.replace("{Item.Owner}", Item.Owner); Str = Str.replace("{Item.Owner}", Item.Owner);
if(!Item.TokenGenerate) if(!Item.TokenGenerate)
Str = Str.replace("dapp-modal__ok-token", "myhidden"); Str = Str.replace("dapp-modal__ok-token", "myhidden");
Str = Str.replace(/{Item.HTMLLength}/g, Item.HTMLLength);
Str = Str.replace("{Item.IconPath}", RetIconPath(Item, 0)); Str = Str.replace("{Item.IconPath}", RetIconPath(Item, 0));
return Str; return Str;
}; };
@ -940,10 +991,13 @@ function OpenDappCard(Num)
openModal('DappCardTemplate'); openModal('DappCardTemplate');
}; };
function OpenDapp(Num) function OpenOnlyDapp(Num,HTMLLength)
{ {
OpenDapps(Num); if(HTMLLength)
{
OpenDapps(Num, 0, HTMLLength);
closeModal(); closeModal();
}
}; };
function FillDappCategory(Str,Item,Num) function FillDappCategory(Str,Item,Num)

View File

@ -658,17 +658,11 @@ function SendTrCreateAcc(Currency,PubKey,Description,Adviser,Smart,bFindAcc,bAdd
CancelCreateAccount(); CancelCreateAccount();
}; };
function ChangeSmart(NumAccount,WasSmart) function DoChangeSmart(NumAccount,WasSmart,SmartNum)
{ {
if(!IsPrivateMode()) if(SmartNum !== null && SmartNum != WasSmart)
{ {
SetError("Pls, open wallet"); var Smart = parseInt(SmartNum);
return 0;
}
var Result = prompt("Enter smart number:", WasSmart);
if(Result !== null && Result != WasSmart)
{
var Smart = parseInt(Result);
if(Smart) if(Smart)
{ {
GetData("GetDappList", {StartNum:Smart, CountNum:1}, function (Data) GetData("GetDappList", {StartNum:Smart, CountNum:1}, function (Data)
@ -690,6 +684,17 @@ function ChangeSmart(NumAccount,WasSmart)
} }
}; };
function ChangeSmart(NumAccount,WasSmart)
{
if(!IsPrivateMode())
{
SetError("Pls, open wallet");
return 0;
}
var SmartNum = prompt("Enter smart number:", WasSmart);
DoChangeSmart(NumAccount, WasSmart, SmartNum);
};
function SetSmartToAccount(NumAccount,Smart) function SetSmartToAccount(NumAccount,Smart)
{ {
var OperationID = 0; var OperationID = 0;

View File

@ -30,7 +30,7 @@
{ {
InitMainServer(); InitMainServer();
document.body.className="univers "+localStorage["idSelStyle"]; document.body.className="univers "+Storage.getItem("idSelStyle");
var i=document.URL.indexOf("#"); var i=document.URL.indexOf("#");
if(i>0) if(i>0)
{ {

View File

@ -69,12 +69,14 @@
$("idConsoleSend").value=Data.Type; $("idConsoleSend").value=Data.Type;
$("idProcessTX").checked=Data.ProcessTX; $("idProcessTX").checked=Data.ProcessTX;
$("idProcessWEB").checked=Data.ProcessWEB; $("idProcessWEB").checked=Data.ProcessWEB;
$("idProcessST").checked=Data.ProcessST;
} }
else else
{ {
$("idConsoleText").value=Data; $("idConsoleText").value=Data;
$("idProcessTX").checked=0; $("idProcessTX").checked=0;
$("idProcessWEB").checked=0; $("idProcessWEB").checked=0;
$("idProcessST").checked=0;
$("idConsoleSend").value="ServerCode"; $("idConsoleSend").value="ServerCode";
} }
if(bRun) if(bRun)
@ -101,7 +103,7 @@
if(Name) if(Name)
{ {
var Data={Code:$("idConsoleText").value,Type:$("idConsoleSend").value,ProcessTX:$("idProcessTX").checked,ProcessWEB:$("idProcessWEB").checked}; var Data={Code:$("idConsoleText").value,Type:$("idConsoleSend").value,ProcessTX:$("idProcessTX").checked,ProcessWEB:$("idProcessWEB").checked,ProcessST:$("idProcessST").checked};
CodeList[Name]=Data; CodeList[Name]=Data;
} }
@ -209,9 +211,11 @@
{ {
var bProcessTX = $("idProcessTX").checked; var bProcessTX = $("idProcessTX").checked;
var bProcessWEB = $("idProcessWEB").checked; var bProcessWEB = $("idProcessWEB").checked;
var bProcessST = $("idProcessST").checked;
SetStatus(""); SetStatus("");
GetData("SendDirectCode",{Code:Value,TX:bProcessTX,WEB:bProcessWEB }, function (Data) GetData("SendDirectCode",{Code:Value,TX:bProcessTX,WEB:bProcessWEB,ST:bProcessST }, function (Data)
{ {
if(Data) if(Data)
{ {
@ -403,7 +407,7 @@
LoadValues(); LoadValues();
SaveArrToSelect(); SaveArrToSelect();
document.body.className="univers "+localStorage["idSelStyle"]; document.body.className="univers "+Storage.getItem("idSelStyle");
SetStatus(""); SetStatus("");
@ -427,6 +431,7 @@
$("idProcessTX").checked=(localStorage["idConsoleProcessTX"]==="true"); $("idProcessTX").checked=(localStorage["idConsoleProcessTX"]==="true");
$("idProcessWEB").checked=(localStorage["idConsoleProcessWEB"]==="true"); $("idProcessWEB").checked=(localStorage["idConsoleProcessWEB"]==="true");
$("idProcessST").checked=(localStorage["idConsoleProcessST"]==="true");
if(localStorage["idConsolePeriodRun"]) if(localStorage["idConsolePeriodRun"])
$("idPeriodRun").value=localStorage["idConsolePeriodRun"]; $("idPeriodRun").value=localStorage["idConsolePeriodRun"];
} }
@ -443,6 +448,8 @@
localStorage["idConsoleProcessTX"]=$("idProcessTX").checked; localStorage["idConsoleProcessTX"]=$("idProcessTX").checked;
localStorage["idConsoleProcessWEB"]=$("idProcessWEB").checked; localStorage["idConsoleProcessWEB"]=$("idProcessWEB").checked;
localStorage["idConsoleProcessST"]=$("idProcessST").checked;
localStorage["idConsolePeriodRun"]=$("idPeriodRun").value; localStorage["idConsolePeriodRun"]=$("idPeriodRun").value;
} }
@ -506,6 +513,7 @@
<INPUT type="number" id="idPeriodRun" style="width: 50px;" onchange="SaveValues();" value="1">sec <INPUT type="number" id="idPeriodRun" style="width: 50px;" onchange="SaveValues();" value="1">sec
TX process:<INPUT type="checkbox" id="idProcessTX"> TX process:<INPUT type="checkbox" id="idProcessTX">
WEB process:<INPUT type="checkbox" id="idProcessWEB"> WEB process:<INPUT type="checkbox" id="idProcessWEB">
Static process:<INPUT type="checkbox" id="idProcessST">
<BR> <BR>

View File

@ -28,8 +28,9 @@
function SetStatus(Str) function SetStatus(Str)
{ {
var id = $("idStatus"); console.log(Str);
id.innerHTML=Str; // var id = $("idStatus");
// id.innerHTML=Str;
} }
window.onload=function() window.onload=function()
@ -48,7 +49,7 @@
{ {
InitMainServer(); InitMainServer();
document.body.className="univers "+localStorage["idSelStyle"]; document.body.className="univers "+Storage.getItem("idSelStyle");
var i=document.URL.indexOf("#"); var i=document.URL.indexOf("#");
if(i>0) if(i>0)
{ {

View File

@ -444,7 +444,7 @@
ArrSystem=DiagramArrR; ArrSystem=DiagramArrR;
} }
var StrArr=localStorage["DiagramArr"]; var StrArr=Storage.getItem("DiagramArr");
if(StrArr && StrArr!=="undefined") if(StrArr && StrArr!=="undefined")
{ {
DiagramArr=JSON.parse(StrArr); DiagramArr=JSON.parse(StrArr);

View File

@ -63,7 +63,7 @@
var SaveIdArr=["idAccount","idTo","idSumSend","idDescription","idSelStyle", var SaveIdArr=["idAccount","idTo","idSumSend","idDescription","idSelStyle",
"idViewAccountNum","idViewBlockNum","idViewActNum","idViewHashNum","idViewDappNum", "idViewAccountNum","idViewBlockNum","idViewActNum","idViewHashNum","idViewDappNum",
"idRunText","idViewAccountFilter", "idRunText","idViewAccountFilter",
"idBlockCount","idPeriodAutoCheckPoint"]; "idBlockCount","idPeriodAutoCheckPoint","idDeltaPow"];
var MaxAccID=0; var MaxAccID=0;
@ -1731,6 +1731,7 @@
<BR> <BR>
<INPUT type="button" onclick="SignJSON()" class="btdoit bt" value="Sign JSON" id="idSignJSON"> <INPUT type="button" onclick="SignJSON()" class="btdoit bt" value="Sign JSON" id="idSignJSON">
<INPUT type="button" onclick="SendMoneyJSON()" class="btdoit bt" value="Send from JSON"> <INPUT type="button" onclick="SendMoneyJSON()" class="btdoit bt" value="Send from JSON">
Pow:<INPUT type="number" id="idDeltaPow" style="width: 60px" value="" onchange="SetMinPow()">&nbsp;
</DIV> </DIV>
<script> <script>

View File

@ -143,7 +143,7 @@
<div class="wallet-wrapper" style="padding-top: 10px;"> <div class="wallet-wrapper" style="padding-top: 10px;">
<button class="btn btn--full-width wallet-settings__generate" id="idKeyEdit" onclick="SelectTab('TabWalletSet')">Edit</button> <button class="btn btn--full-width wallet-settings__generate" id="idKeyEdit" onclick="SelectTab('TabWalletSet')">Edit</button>
<div class="wallet-settings__btns-wrapper"> <div class="wallet-settings__btns-wrapper nomobile">
<button class="btn btn--white" onclick="downloadKey('idPrivKeyEdit')" id="idSave2">Save key</button> <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"> <label for="load-key2" class="btn btn--white" onchange="UploadKey('load-key2')" id="idLoad2">
<input class="hidden" id="load-key2" type="file"> <input class="hidden" id="load-key2" type="file">
@ -214,7 +214,7 @@
<a onclick="OpenHistoryPage({Item.Num})" class="prod-card__id prod-card__id--mobile-active pointer">{Item.Num}</a> <a onclick="OpenHistoryPage({Item.Num})" class="prod-card__id prod-card__id--mobile-active pointer">{Item.Num}</a>
<a onclick="OpenHistoryPage({Item.Num})" target='_blank' class="prod-card__id prod-card__id--desktop pointer">{Item.Num}</a> <a onclick="OpenHistoryPage({Item.Num})" target='_blank' class="prod-card__id prod-card__id--desktop pointer">{Item.Num}</a>
<div class="prod-card__heading"> <div class="prod-card__heading">
<span class="prod-card__coins-count">{Value.SumCOIN}<sup>,{Value.SumCENT}</sup><br> <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 class="light-grey-text small-text mob-hidden">{Value.CurrencyName}</span>
</span> </span>
<span class="prod-card__currency prod-card__currency--with-dot"> <span class="prod-card__currency prod-card__currency--with-dot">
@ -227,7 +227,7 @@
<div class="prod-card__footer"> <div class="prod-card__footer">
<div class="prod-card__footer-wrap" > <div class="prod-card__footer-wrap" >
<a onclick="OpenDapps({SmartObj.Num},{Item.Num})" class="prod-card__link prod-card__link--dapp"> <a onclick="OpenDapps({SmartObj.Num},{Item.Num},{SmartObj.HTMLLength})" class="prod-card__link prod-card__link--dapp">
<img src="{SmartObj.IconPath}" alt="." width="32" height="32"> <img src="{SmartObj.IconPath}" alt="." width="32" height="32">
<span class="prod-card__dapp-name mob-hidden">{SmartObj.Name}</span> <span class="prod-card__dapp-name mob-hidden">{SmartObj.Name}</span>
</a> </a>
@ -414,7 +414,7 @@
<div class="prod-card__second-line"> <div class="prod-card__second-line">
<div class="prod-card__second-line-left"> <div class="prod-card__second-line-left">
<div class="prod-card__heading"> <div class="prod-card__heading">
<a class="prod-card__link" onclick="OpenDapp({Item.Num})">{Item.Name}</a> <a class="prod-card__link" onclick="OpenOnlyDapp({Item.Num},{Item.HTMLLength})">{Item.Name}</a>
<!--<span class="lighter-grey-text">Without token generate</span>--> <!--<span class="lighter-grey-text">Without token generate</span>-->
<!--<span class="dapp-modal__ok-token">Token generate</span>--> <!--<span class="dapp-modal__ok-token">Token generate</span>-->
</div> </div>
@ -426,7 +426,7 @@
<!--</ol> --> <!--</ol> -->
</div> </div>
<div class="prod-card__second-line-img"> <div class="prod-card__second-line-img">
<a class="prod-card__link" onclick="OpenDapp({Item.Num})"><img src="{Item.IconPath}" width="32"></a> <a class="prod-card__link" onclick="OpenOnlyDapp({Item.Num},{Item.HTMLLength})"><img src="{Item.IconPath}" width="32"></a>
</div> </div>
</div> </div>
</li> </li>
@ -551,7 +551,7 @@
</dl> </dl>
<div class="modal__btns-wrap"> <div class="modal__btns-wrap">
<button class="btn" onclick="OpenDapp({Item.Num})">Open DApp</button> <button class="btn" onclick="OpenOnlyDapp({Item.Num},{Item.HTMLLength})">Open DApp</button>
<button class="btn btn--white" onclick="closeModal()">Back</button> <button class="btn btn--white" onclick="closeModal()">Back</button>
</div> </div>
@ -633,6 +633,17 @@
</section> </section>
<section class="modal password-modal" id="idSmartEnter">
<h2 class="password-modal__title">Enter number of dapp</h2>
<p class="password-modal__subtitle">Enter the dapps number that will be added to your account. Attention make sure that you trust this dapp, otherwise you may lose all funds in this account.</p>
<input type="number" class="password-modal__input" placeholder="Dapp number" id="idSmartNum">
<a class="btn btn--270 btn--float" onclick="DoSetSmartLocal()">OK</a>
<a class="btn btn--270 btn--float btn--white" onclick="closeModal()">Cancel</a>
</section>
<div class="fixed-status"> <div class="fixed-status">
<div class="fixed-status__wrap"> <div class="fixed-status__wrap">
<div id="idStatus" class="fixed-status__status">&nbsp;</div> <div id="idStatus" class="fixed-status__status">&nbsp;</div>
@ -640,7 +651,7 @@
<option value="TERA-MAIN">TERA MAIN</option> <option value="TERA-MAIN">TERA MAIN</option>
<option value="TERA-TEST3">TERA TEST3</option> <option value="TERA-TEST3">TERA TEST3</option>
</select> </select>
<button class="grey-btn reconnect" onclick="ConnectWebWallet()" title="Reconnect"><span>RECONNECT</span></button> <button class="grey-btn reconnect" onclick="ChangeNetwork()" title="Reconnect"><span>RECONNECT</span></button>
<!--рудименты--> <!--рудименты-->
<span id="idNetwork" style="display: none"></span> <span id="idNetwork" style="display: none"></span>
<span id="idSignJSON"></span> <span id="idSignJSON"></span>

View File

@ -8,7 +8,7 @@
* Telegram: https://t.me/terafoundation * Telegram: https://t.me/terafoundation
*/ */
global.UPDATE_CODE_VERSION_NUM = 1137; global.UPDATE_CODE_VERSION_NUM = 1151;
global.MIN_CODE_VERSION_NUM = 1114; global.MIN_CODE_VERSION_NUM = 1114;
global.MINING_VERSION_NUM = 0; global.MINING_VERSION_NUM = 0;
global.InitParamsArg = InitParamsArg; global.InitParamsArg = InitParamsArg;
@ -67,7 +67,7 @@ global.HARD_PACKET_PERIOD120 = 160;
global.MINING_START_TIME = ""; global.MINING_START_TIME = "";
global.MINING_PERIOD_TIME = ""; global.MINING_PERIOD_TIME = "";
global.CHECK_RUN_MINING = 21 * 1000; global.CHECK_RUN_MINING = 21 * 1000;
global.CHECK_STOP_CHILD_PROCESS = 10 * 1000; global.CHECK_STOP_CHILD_PROCESS = 100 * 1000;
global.COUNT_MINING_CPU = 0; global.COUNT_MINING_CPU = 0;
global.SIZE_MINING_MEMORY = 0; global.SIZE_MINING_MEMORY = 0;
global.HTTP_HOSTING_PORT = 0; global.HTTP_HOSTING_PORT = 0;
@ -80,7 +80,6 @@ global.MIN_POWER_POW_HANDSHAKE = 12;
global.USE_HINT = 0; global.USE_HINT = 0;
global.ALL_VIEW_ROWS = 0; global.ALL_VIEW_ROWS = 0;
global.COUNT_BLOCK_PROOF = 300; global.COUNT_BLOCK_PROOF = 300;
global.COUNT_NODE_PROOF = 10;
global.MIN_POWER_POW_MSG = 2; global.MIN_POWER_POW_MSG = 2;
global.MEM_POOL_MSG_COUNT = 1000; global.MEM_POOL_MSG_COUNT = 1000;
global.MAX_LEVEL_SPECIALIZATION = 24; global.MAX_LEVEL_SPECIALIZATION = 24;
@ -91,7 +90,7 @@ global.TRUST_PROCESS_COUNT = 80000;
global.MAX_NODES_RETURN = 100; global.MAX_NODES_RETURN = 100;
global.MAX_WAIT_PERIOD_FOR_STATUS = 10 * 1000; global.MAX_WAIT_PERIOD_FOR_STATUS = 10 * 1000;
global.MAX_GRAY_CONNECTIONS_TO_SERVER = 10; global.MAX_GRAY_CONNECTIONS_TO_SERVER = 10;
global.MAX_PACKET_LENGTH = 450 * 1024; global.MAX_PACKET_LENGTH = 550 * 1024;
global.COUNT_BLOCKS_FOR_LOAD = 600; global.COUNT_BLOCKS_FOR_LOAD = 600;
global.TR_LEN = 100; global.TR_LEN = 100;
global.BLOCK_PROCESSING_LENGTH = 8; global.BLOCK_PROCESSING_LENGTH = 8;
@ -165,7 +164,6 @@ if(global.LOCAL_RUN)
global.NEW_FORMULA_TARGET2 = 1; global.NEW_FORMULA_TARGET2 = 1;
NETWORK = "LOCAL"; NETWORK = "LOCAL";
global.ALL_VIEW_ROWS = 1; global.ALL_VIEW_ROWS = 1;
global.COUNT_NODE_PROOF = 1;
global.NEW_SIGN_TIME = 0; global.NEW_SIGN_TIME = 0;
} }
else else
@ -196,11 +194,11 @@ else
global.NEW_FORMULA_KTERA = 3; global.NEW_FORMULA_KTERA = 3;
global.NEW_FORMULA_TARGET1 = 0; global.NEW_FORMULA_TARGET1 = 0;
global.NEW_FORMULA_TARGET2 = 1; global.NEW_FORMULA_TARGET2 = 1;
global.COUNT_NODE_PROOF = 8;
global.REST_START_COUNT = 1000;
global.NEW_SIGN_TIME = 1; global.NEW_SIGN_TIME = 1;
global.MAX_LENGTH_SENDER_MAP = 100; global.MAX_LENGTH_SENDER_MAP = 100;
global.DELTA_START_SENDER_MAP = 12; global.DELTA_START_SENDER_MAP = 12;
global.REST_START_COUNT = 0;
global.LOAD_TO_BEGIN = 0;
} }
if(global.LOCAL_RUN) if(global.LOCAL_RUN)
{ {

View File

@ -685,13 +685,15 @@ HTTPCaller.SendTransactionHex = function (Params)
HTTPCaller.SendDirectCode = function (Params,response) HTTPCaller.SendDirectCode = function (Params,response)
{ {
var Result; var Result;
if(Params.TX || Params.WEB) if(Params.TX || Params.WEB || Params.ST)
{ {
var RunProcess; var RunProcess;
if(Params.TX) if(Params.TX)
RunProcess = global.TX_PROCESS; RunProcess = global.TX_PROCESS;
if(Params.WEB) if(Params.WEB)
RunProcess = global.WEB_PROCESS; RunProcess = global.WEB_PROCESS;
if(Params.ST)
RunProcess = global.STATIC_PROCESS;
if(RunProcess && RunProcess.RunRPC) if(RunProcess && RunProcess.RunRPC)
{ {
RunProcess.RunRPC("EvalCode", Params.Code, function (Err,Ret) RunProcess.RunRPC("EvalCode", Params.Code, function (Err,Ret)

View File

@ -9,6 +9,13 @@
*/ */
"use strict"; "use strict";
var MIN_POW_CHAINS = 2;
global.COUNT_NODE_PROOF = 6;
if(global.TEST_NETWORK)
{
MIN_POW_CHAINS = 1;
global.COUNT_NODE_PROOF = 1;
}
module.exports = class CRest extends require("./db/block-db") module.exports = class CRest extends require("./db/block-db")
{ {
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
@ -54,6 +61,10 @@ module.exports = class CRest extends require("./db/block-db")
switch(Context.Mode) switch(Context.Mode)
{ {
case 0: case 0:
if(!global.TX_PROCESS)
{
return ;
}
var ArrNodes = this.GetActualNodes(); var ArrNodes = this.GetActualNodes();
for(var i = 0; i < ArrNodes.length; i++) for(var i = 0; i < ArrNodes.length; i++)
{ {
@ -63,7 +74,7 @@ module.exports = class CRest extends require("./db/block-db")
continue; continue;
} }
Node.SendRestGetHeader = 1 Node.SendRestGetHeader = 1
ToLog("Send rest get headers from " + Context.BlockNumProof + " to " + NodeName(Node), 2) ToLog("Send rest get header " + Context.BlockNumProof + " to " + NodeName(Node), 2)
this.SendF(Node, {"Method":"GETBLOCKHEADER", "Data":{Foward:1, BlockNum:Context.BlockNumProof, Hash:[]}, "Context":{F:this.RETBLOCKHEADER_REST.bind(this)}, this.SendF(Node, {"Method":"GETBLOCKHEADER", "Data":{Foward:1, BlockNum:Context.BlockNumProof, Hash:[]}, "Context":{F:this.RETBLOCKHEADER_REST.bind(this)},
}) })
Context.SendGetHeaderCount++ Context.SendGetHeaderCount++
@ -95,7 +106,7 @@ module.exports = class CRest extends require("./db/block-db")
MaxPow = parseInt(key) MaxPow = parseInt(key)
} }
} }
if(MaxCount < 2 || MaxPow === 0) if(MaxCount < MIN_POW_CHAINS || MaxPow === 0)
{ {
ToLog("****************************************************************** Error MaxPow=" + MaxPow + " - reload.") ToLog("****************************************************************** Error MaxPow=" + MaxPow + " - reload.")
this.CheckSyncRest() this.CheckSyncRest()

View File

@ -15,8 +15,10 @@ require("../system/smart");
require("../system/file"); require("../system/file");
require("../system/messager"); require("../system/messager");
require("../system/names"); require("../system/names");
if(global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX") if(global.PROCESS_NAME === "MAIN")
{
require("./wallet"); require("./wallet");
}
module.exports = class CSmartContract extends require("./block-exchange") module.exports = class CSmartContract extends require("./block-exchange")
{ {
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)

View File

@ -28,6 +28,14 @@ function RunOnUpdate()
{ {
SERVER.ClearDataBase(); SERVER.ClearDataBase();
} }
if(CurNum < 1142)
{
setTimeout(function ()
{
ToLog("UPD: START RewriteAllTransactions");
SERVER.RewriteAllTransactions();
}, 3000);
}
} }
else else
{ {

View File

@ -45,7 +45,7 @@ class CApp
this.KeyPair = crypto.createECDH('secp256k1') this.KeyPair = crypto.createECDH('secp256k1')
if(Params.Protect) if(Params.Protect)
{ {
ToLogClient("Wallet protect by password") ToLog("Wallet protect by password")
this.KeyXOR = GetArrFromHex(Params.KeyXOR) this.KeyXOR = GetArrFromHex(Params.KeyXOR)
this.WalletOpen = false this.WalletOpen = false
this.SetPrivateKey(Params.PubKey) this.SetPrivateKey(Params.PubKey)

View File

@ -0,0 +1,143 @@
/*
* @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.GlobalRunID = 0;
global.GlobalRunMap = {};
var LastAlive = Date.now();
setTimeout(function ()
{
setInterval(CheckAlive, 1000);
}, 20000);
if(process.send)
{
setInterval(function ()
{
process.send({cmd:"Alive"});
}, 1000);
process.send({cmd:"online", message:"OK"});
setInterval(function ()
{
process.send({cmd:"Alive"});
}, 1000);
global.ToLogClient = function (Str,StrKey,bFinal)
{
process.send({cmd:"ToLogClient", Str:"" + Str, StrKey:StrKey, bFinal:bFinal});
};
}
function CheckAlive()
{
if(global.NOALIVE)
return ;
var Delta = Date.now() - LastAlive;
if(Delta > CHECK_STOP_CHILD_PROCESS)
{
ToLog("ALIVE TIMEOUT. Stop and exit: " + Delta + "/" + global.CHECK_STOP_CHILD_PROCESS);
Exit();
return ;
}
};
process.on('message', function (msg)
{
LastAlive = Date.now();
switch(msg.cmd)
{
case "Alive":
DELTA_CURRENT_TIME = msg.DELTA_CURRENT_TIME;
break;
case "Exit":
Exit();
break;
case "call":
var Err = 0;
var Ret;
try
{
Ret = global[msg.Name](msg.Params);
}
catch(e)
{
Err = 1;
Ret = "" + e;
}
if(msg.id)
process.send({cmd:"retcall", id:msg.id, Err:Err, Params:Ret});
break;
case "retcall":
var F = GlobalRunMap[msg.id];
if(F)
{
delete GlobalRunMap[msg.id];
F(msg.Err, msg.Params);
}
break;
case "ToLogClient":
{
ToLogClient0(msg.Str, msg.StrKey, msg.bFinal);
break;
}
case "Eval":
EvalCode(msg.Code);
break;
}
});
function Exit()
{
if(global.OnExit)
global.OnExit();
process.exit(0);
};
process.RunRPC = function (Name,Params,F)
{
if(F)
{
GlobalRunID++;
try
{
process.send({cmd:"call", id:GlobalRunID, Name:Name, Params:Params});
GlobalRunMap[GlobalRunID] = F;
}
catch(e)
{
}
}
else
{
process.send({cmd:"call", id:0, Name:Name, Params:Params});
}
};
global.EvalCode = function (Code)
{
var Result;
try
{
var ret = eval(Code);
Result = JSON.stringify(ret, "", 4);
}
catch(e)
{
Result = "" + e;
}
return Result;
};
process.on('uncaughtException', function (err)
{
ToError(err.stack);
ToLog(err.stack);
TO_ERROR_LOG(global.PROCESS_NAME, 777, err);
ToLog("-----------------" + global.PROCESS_NAME + " EXIT------------------");
process.exit();
});
process.on('error', function (err)
{
ToError(global.PROCESS_NAME + ":\n" + err.stack);
ToLog(err.stack);
});

View File

@ -404,7 +404,7 @@ function AllAlive()
{ {
for(var i = 0; i < ArrMiningWrk.length; i++) for(var i = 0; i < ArrMiningWrk.length; i++)
{ {
ArrMiningWrk[i].send({cmd:"Alive"}); ArrMiningWrk[i].send({cmd:"Alive", DELTA_CURRENT_TIME:DELTA_CURRENT_TIME});
} }
}; };

View File

@ -45,29 +45,6 @@ PROCESS.on('message', function (msg)
ToError(e); ToError(e);
} }
} }
else
if(msg.cmd === "SetBlock")
{
var StartNonce = 1000000 * (1 + msg.Num);
if(Block.HashCount)
{
process.send({cmd:"HASHRATE", CountNonce:Block.HashCount, Hash:Block.Hash});
}
Block.HashCount = 0;
Block = msg;
Block.Time = Date.now();
Block.LastNonce = StartNonce;
Block.Period = CONSENSUS_PERIOD_TIME * Block.Percent / 100;
if(Block.Period > 0 && Block.RunPeriod > 0)
{
CalcPOWHash();
if(idInterval !== undefined)
{
clearInterval(idInterval);
}
idInterval = setInterval(CalcPOWHash, Block.RunPeriod);
}
}
else else
if(msg.cmd === "Alive") if(msg.cmd === "Alive")
{ {

View File

@ -20,41 +20,11 @@ global.DATA_PATH = GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = GetNormalPathString(global.CODE_PATH); global.CODE_PATH = GetNormalPathString(global.CODE_PATH);
require("../core/library"); require("../core/library");
global.READ_ONLY_DB = 1; global.READ_ONLY_DB = 1;
var LastAlive = Date.now(); require("./child-process");
setTimeout(function ()
{
setInterval(CheckAlive, 1000);
}, 20000);
setInterval(function ()
{
process.send({cmd:"Alive"});
}, 1000);
process.send({cmd:"online", message:"OK"});
process.on('message', function (msg) process.on('message', function (msg)
{ {
LastAlive = Date.now();
switch(msg.cmd) switch(msg.cmd)
{ {
case "ALive":
break;
case "Exit":
process.exit(0);
break;
case "call":
var Err = 0;
var Ret;
try
{
Ret = global[msg.Name](msg.Params);
}
catch(e)
{
Err = 1;
Ret = "" + e;
}
if(msg.id)
process.send({cmd:"retcall", id:msg.id, Err:Err, Params:Ret});
break;
case "GETBLOCKHEADER": case "GETBLOCKHEADER":
GETBLOCKHEADER(msg); GETBLOCKHEADER(msg);
break; break;
@ -75,32 +45,6 @@ process.on('message', function (msg)
break; break;
} }
}); });
function CheckAlive()
{
if(global.NOALIVE)
return ;
var Delta = Date.now() - LastAlive;
if(Delta > CHECK_STOP_CHILD_PROCESS)
{
ToLog("STATIC-DB: ALIVE TIMEOUT Stop and exit: " + Delta + "/" + global.CHECK_STOP_CHILD_PROCESS);
process.exit(0);
return ;
}
};
process.on('uncaughtException', function (err)
{
ToError(err.stack);
ToLog(err.stack);
TO_ERROR_LOG("STATIC-DB", 777, err);
ToLog("-----------------STATIC-DB EXIT------------------");
process.exit();
});
process.on('error', function (err)
{
ToError("STATIC-DB:\n" + err.stack);
ToLog(err.stack);
});
var CServerDB = require("../core/db/block-db"); var CServerDB = require("../core/db/block-db");
var KeyPair = crypto.createECDH('secp256k1'); var KeyPair = crypto.createECDH('secp256k1');
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,

View File

@ -16,58 +16,18 @@ global.DATA_PATH = GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = GetNormalPathString(global.CODE_PATH); global.CODE_PATH = GetNormalPathString(global.CODE_PATH);
require("../core/library"); require("../core/library");
global.READ_ONLY_DB = 0; global.READ_ONLY_DB = 0;
var LastAlive = Date.now(); require("./child-process");
setTimeout(function ()
{
setInterval(CheckAlive, 1000);
}, 20000);
setInterval(PrepareStatEverySecond, 1000); setInterval(PrepareStatEverySecond, 1000);
if(process.send)
{
setInterval(function ()
{
process.send({cmd:"Alive"});
}, 1000);
process.send({cmd:"online", message:"OK"});
global.ToLogClient = function (Str,StrKey,bFinal)
{
process.send({cmd:"ToLogClient", Str:"" + Str, StrKey:StrKey, bFinal:bFinal});
};
}
process.on('message', function (msg) process.on('message', function (msg)
{ {
LastAlive = Date.now();
switch(msg.cmd) switch(msg.cmd)
{ {
case "ALive":
break;
case "Exit":
process.exit(0);
break;
case "call":
var Err = 0;
var Ret;
try
{
Ret = global[msg.Name](msg.Params);
}
catch(e)
{
Err = 1;
Ret = "" + e;
}
if(msg.id)
process.send({cmd:"retcall", id:msg.id, Err:Err, Params:Ret});
break;
case "FindTX": case "FindTX":
global.TreeFindTX.SaveValue(msg.TX, msg); global.TreeFindTX.SaveValue(msg.TX, msg);
break; break;
case "SetSmartEvent": case "SetSmartEvent":
global.TreeFindTX.SaveValue("Smart:" + msg.Smart, 1); global.TreeFindTX.SaveValue("Smart:" + msg.Smart, 1);
break; break;
case "Eval":
EvalCode(msg.Code);
break;
default: default:
break; break;
} }
@ -77,32 +37,6 @@ global.SetStatMode = function (Val)
global.STAT_MODE = Val; global.STAT_MODE = Val;
return global.STAT_MODE; return global.STAT_MODE;
}; };
function CheckAlive()
{
if(global.NOALIVE)
return ;
var Delta = Date.now() - LastAlive;
if(Delta > 100 * 1000)
{
ToLog("TX-PROCESS: ALIVE TIMEOUT Stop and exit: " + Delta);
process.exit(0);
return ;
}
};
process.on('uncaughtException', function (err)
{
ToError(err.stack);
ToLog(err.stack);
TO_ERROR_LOG("TX-PROCESS", 777, err);
ToLog("-----------------TX-PROCESS EXIT------------------");
process.exit();
});
process.on('error', function (err)
{
ToError("TX-PROCESS:\n" + err.stack);
ToLog(err.stack);
});
global.HTTP_PORT_NUMBER = 0; global.HTTP_PORT_NUMBER = 0;
var CServerDB = require("../core/transaction-validator"); var CServerDB = require("../core/transaction-validator");
var KeyPair = crypto.createECDH('secp256k1'); var KeyPair = crypto.createECDH('secp256k1');
@ -395,17 +329,3 @@ function TXWriteAccHash()
return DataHash; return DataHash;
}; };
global.TXWriteAccHash = TXWriteAccHash; global.TXWriteAccHash = TXWriteAccHash;
global.EvalCode = function (Code)
{
var Result;
try
{
var ret = eval(Code);
Result = JSON.stringify(ret, "", 4);
}
catch(e)
{
Result = "" + e;
}
return Result;
};

View File

@ -18,54 +18,16 @@ global.DATA_PATH = GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = GetNormalPathString(global.CODE_PATH); global.CODE_PATH = GetNormalPathString(global.CODE_PATH);
require("../core/library"); require("../core/library");
require("../core/geo"); require("../core/geo");
require("./child-process");
global.READ_ONLY_DB = 1; global.READ_ONLY_DB = 1;
global.MAX_STAT_PERIOD = 600; global.MAX_STAT_PERIOD = 600;
var HostNodeList = []; var HostNodeList = [];
var AllNodeList = []; var AllNodeList = [];
var NodeBlockChain = []; var NodeBlockChain = [];
var LastAlive = Date.now();
setTimeout(function ()
{
setInterval(CheckAlive, 1000);
}, 20000);
setInterval(function ()
{
process.send({cmd:"Alive"});
}, 1000);
process.send({cmd:"online", message:"OK"});
process.on('message', function (msg) process.on('message', function (msg)
{ {
LastAlive = Date.now();
switch(msg.cmd) switch(msg.cmd)
{ {
case "ALive":
break;
case "Exit":
Exit();
break;
case "call":
var Err = 0;
var Ret;
try
{
Ret = global[msg.Name](msg.Params);
}
catch(e)
{
Err = 1;
Ret = "" + e;
}
if(msg.id)
process.send({cmd:"retcall", id:msg.id, Err:Err, Params:Ret});
break;
case "retcall":
var F = GlobalRunMap[msg.id];
if(F)
{
delete GlobalRunMap[msg.id];
F(msg.Err, msg.Params);
}
break;
case "Stat": case "Stat":
ADD_TO_STAT(msg.Name, msg.Value); ADD_TO_STAT(msg.Name, msg.Value);
break; break;
@ -101,52 +63,21 @@ process.on('message', function (msg)
ArrLogClient.push({text:msg.ResultStr, key:msg.TX, final:msg.bFinal, }); ArrLogClient.push({text:msg.ResultStr, key:msg.TX, final:msg.bFinal, });
break; break;
} }
case "Eval":
EvalCode(msg.Code);
break;
} }
}); });
var RedirectServer; var RedirectServer;
var HostingServer; var HostingServer;
global.OnExit = function ()
function Exit()
{ {
ToLogWeb("=Exit1=");
if(RedirectServer) if(RedirectServer)
RedirectServer.close(); RedirectServer.close();
if(HostingServer) if(HostingServer)
HostingServer.close(); HostingServer.close();
ToLogWeb("=Exit2=");
process.exit(0);
}; };
function CheckAlive()
{
if(global.NOALIVE)
return ;
var Delta = Date.now() - LastAlive;
if(Delta > CHECK_STOP_CHILD_PROCESS)
{
Exit();
return ;
}
};
process.on('uncaughtException', function (err)
{
ToError(err.stack);
ToLog(err.stack);
TO_ERROR_LOG("HOSTING", 777, err);
ToLog("-----------------HOSTING EXIT------------------", 0);
process.exit();
});
process.on('error', function (err)
{
ToError("HOSTING:\n" + err.stack);
ToLog(err.stack);
});
if(!global.HTTP_HOSTING_PORT) if(!global.HTTP_HOSTING_PORT)
{ {
ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT); ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT);
OnExit();
process.exit(); process.exit();
} }
var CServerDB = require("../core/db/block-db"); var CServerDB = require("../core/db/block-db");
@ -275,12 +206,13 @@ function RunListenServer()
TimeToRerun = Math.floor(TimeToRerun * 1.1); TimeToRerun = Math.floor(TimeToRerun * 1.1);
if(TimeToRerun > 1000000 * 1000) if(TimeToRerun > 1000000 * 1000)
return ; return ;
ToLogClient('Port ' + global.HTTP_HOSTING_PORT + ' in use, retrying...'); ToLog('Port ' + global.HTTP_HOSTING_PORT + ' in use, retrying...');
if(HostingServer.Server) if(HostingServer.Server)
HostingServer.Server.close(); HostingServer.Server.close();
if(!bWasRun) if(!bWasRun)
setTimeout(function () setTimeout(function ()
{ {
if(!bWasRun)
RunListenServer(); RunListenServer();
}, TimeToRerun); }, TimeToRerun);
return ; return ;
@ -288,11 +220,11 @@ function RunListenServer()
ToError("H##6"); ToError("H##6");
ToError(err); ToError(err);
}); });
ToLogClient("Prepare to run WEB-server on port: " + global.HTTP_HOSTING_PORT); ToLog("Prepare to run WEB-server on port: " + global.HTTP_HOSTING_PORT);
HostingServer.listen(global.HTTP_HOSTING_PORT, LISTEN_IP, function () HostingServer.listen(global.HTTP_HOSTING_PORT, LISTEN_IP, function ()
{ {
if(!bWasRun) if(!bWasRun)
ToLogClient("Run WEB-server on " + LISTEN_IP + ":" + global.HTTP_HOSTING_PORT); ToLog("Run WEB-server on " + LISTEN_IP + ":" + global.HTTP_HOSTING_PORT);
bWasRun = 1; bWasRun = 1;
}); });
}; };
@ -899,41 +831,6 @@ HostingCaller.GetTotalSupply = function (Params)
{ {
return "" + global.TOTAL_SUPPLY_TERA; return "" + global.TOTAL_SUPPLY_TERA;
}; };
global.GlobalRunID = 0;
global.GlobalRunMap = {};
process.RunRPC = function (Name,Params,F)
{
if(F)
{
GlobalRunID++;
try
{
process.send({cmd:"call", id:GlobalRunID, Name:Name, Params:Params});
GlobalRunMap[GlobalRunID] = F;
}
catch(e)
{
}
}
else
{
process.send({cmd:"call", id:0, Name:Name, Params:Params});
}
};
global.EvalCode = function (Code)
{
var Result;
try
{
var ret = eval(Code);
Result = JSON.stringify(ret, "", 4);
}
catch(e)
{
Result = "" + e;
}
return Result;
};
setInterval(function () setInterval(function ()
{ {
if(SERVER) if(SERVER)

View File

@ -674,10 +674,6 @@ class AccountApp extends require("./dapp")
Account.Adviser = TR.Adviser Account.Adviser = TR.Adviser
Account.Value.Smart = TR.Smart Account.Value.Smart = TR.Smart
this.WriteStateTR(Account, TrNum) this.WriteStateTR(Account, TrNum)
if(CompareArr(Account.PubKey, WALLET.PubKeyArr) === 0)
{
WALLET.OnCreateAccount(Account)
}
this.ResultTx = Account.Num this.ResultTx = Account.Num
return true; return true;
} }

View File

@ -1099,6 +1099,7 @@ function $Send(ToID,CoinSum,Description)
ToID = ParseNum(ToID); ToID = ParseNum(ToID);
if(typeof CoinSum === "number") if(typeof CoinSum === "number")
CoinSum = COIN_FROM_FLOAT(CoinSum); CoinSum = COIN_FROM_FLOAT(CoinSum);
CHECKSUM(CoinSum);
if(CoinSum.SumCENT >= 1e9) if(CoinSum.SumCENT >= 1e9)
{ {
throw "ERROR SumCENT>=1e9"; throw "ERROR SumCENT>=1e9";
@ -1147,6 +1148,7 @@ function $Move(FromID,ToID,CoinSum,Description)
{ {
CoinSum = COIN_FROM_FLOAT(CoinSum); CoinSum = COIN_FROM_FLOAT(CoinSum);
} }
CHECKSUM(CoinSum);
if(CoinSum.SumCENT >= 1e9) if(CoinSum.SumCENT >= 1e9)
{ {
throw "ERROR SumCENT>=1e9"; throw "ERROR SumCENT>=1e9";