sync: sync upstream code

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-07-18 19:22:32 +08:00
parent 68310f1a3b
commit 8dafeb2cf0
18 changed files with 196 additions and 211 deletions

View File

@ -11,6 +11,15 @@
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 +111,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

@ -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;
@ -1730,6 +1730,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

@ -1352,10 +1352,19 @@ export default class CConsensus extends CBlock {
MiningProcess(msg) { MiningProcess(msg) {
var BlockMining = this.GetBlock(msg.BlockNum); var BlockMining = this.GetBlock(msg.BlockNum);
if (!BlockMining) { if (!BlockMining) {
SendToWebClient({
msg: msg,
errror: '!BlockMining'
})
return; return;
} }
if (!BlockMining.StartMining || BlockMining.bSave) if (!BlockMining.StartMining || BlockMining.bSave) {
SendToWebClient({
msg: msg,
errror: `!BlockMining.StartMining ${BlockMining.StartMining} || BlockMining.bSave ${BlockMining.bSave}`
})
return; return;
}
if (BlockMining && BlockMining.Hash && BlockMining.SeqHash && global.CompareArr(BlockMining.SeqHash, msg.SeqHash) === 0) { if (BlockMining && BlockMining.Hash && BlockMining.SeqHash && global.CompareArr(BlockMining.SeqHash, msg.SeqHash) === 0) {
var ValueOld = global.GetHashFromSeqAddr(BlockMining.SeqHash, BlockMining.AddrHash, BlockMining.BlockNum); var ValueOld = global.GetHashFromSeqAddr(BlockMining.SeqHash, BlockMining.AddrHash, BlockMining.BlockNum);
var ValueMsg = global.GetHashFromSeqAddr(msg.SeqHash, msg.AddrHash, BlockMining.BlockNum); var ValueMsg = global.GetHashFromSeqAddr(msg.SeqHash, msg.AddrHash, BlockMining.BlockNum);
@ -1395,12 +1404,12 @@ export default class CConsensus extends CBlock {
setTimeout(() => { setTimeout(() => {
let webmsg: any = { BlockNum: msg.BlockNum } let webmsg: any = { BlockNum: msg.BlockNum }
webmsg.Mining = { webmsg.Mining = {
Hash: BlockMining.Hash.toString(), Hash: global.GetHexFromArr(BlockMining.Hash),
SeqHash: BlockMining.Hash.toString() SeqHash: global.GetHexFromArr(BlockMining.Hash)
} }
webmsg.New = { webmsg.New = {
Hash: ValueNew.Hash.toString(), Hash: global.GetHexFromArr(ValueNew.Hash),
PowHash: ValueNew.PowHash.toString() PowHash: global.GetHexFromArr(ValueNew.PowHash)
} }
Object.assign(webmsg, { Object.assign(webmsg, {
HashCount, HashCount,

View File

@ -110,7 +110,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;
@ -123,7 +123,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;
@ -204,7 +203,6 @@ if (global.LOCAL_RUN) {
global.NEW_FORMULA_TARGET2 = 1; global.NEW_FORMULA_TARGET2 = 1;
global.NETWORK = "LOCAL"; global.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
@ -234,7 +232,6 @@ 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.NEW_SIGN_TIME = 4859000; global.NEW_SIGN_TIME = 4859000;
global.MAX_LENGTH_SENDER_MAP = 100; global.MAX_LENGTH_SENDER_MAP = 100;
global.DELTA_START_SENDER_MAP = 12; global.DELTA_START_SENDER_MAP = 12;

View File

@ -21,8 +21,7 @@ if (global.USE_PARAM_JS) {
if (fs.existsSync(PathParams)) if (fs.existsSync(PathParams))
try { try {
require(PathParams); require(PathParams);
} } catch (e) {
catch (e) {
console.log(e); console.log(e);
} }
} }
@ -63,8 +62,7 @@ if (global.USE_PARAM_JS) {
if (fs.existsSync(PathParams)) if (fs.existsSync(PathParams))
try { try {
require(PathParams); require(PathParams);
} } catch (e) {
catch (e) {
console.log(e); console.log(e);
} }
} }
@ -291,6 +289,12 @@ function CheckGlobalTime() {
global.ToLog("Get global time: " + NetTime); global.ToLog("Get global time: " + NetTime);
global.SAVE_CONST(); global.SAVE_CONST();
}); });
setTimeout(() => {
global.DELTA_CURRENT_TIME = global.DELTA_CURRENT_TIME * -1;
setTimeout(() => {
global.DELTA_CURRENT_TIME = global.DELTA_CURRENT_TIME * -1
}, 3000)
}, 5000)
global.SAVE_CONST(); global.SAVE_CONST();
}; };
global.CheckGlobalTime = CheckGlobalTime; global.CheckGlobalTime = CheckGlobalTime;

View File

@ -13,8 +13,10 @@ import CDB from './db/block-db'
import { TYPE_TRANSACTION } from '../constant/account'; import { TYPE_TRANSACTION } from '../constant/account';
import { DB_FORMAT } from '../constant/db-format'; import { DB_FORMAT } from '../constant/db-format';
var MIN_POW_CHAINS = 2; var MIN_POW_CHAINS = 2;
global.COUNT_NODE_PROOF = 6;
if (global.TEST_NETWORK) { if (global.TEST_NETWORK) {
MIN_POW_CHAINS = 1; MIN_POW_CHAINS = 1;
global.COUNT_NODE_PROOF = 1;
} }
export default class CRest extends CDB { export default class CRest extends CDB {
LoadRestContext LoadRestContext
@ -67,6 +69,9 @@ export default class CRest extends CDB {
let Context = this.LoadRestContext; let Context = this.LoadRestContext;
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++) {
var Node = ArrNodes[i]; var Node = ArrNodes[i];
@ -74,7 +79,7 @@ export default class CRest extends CDB {
continue; continue;
} }
Node.SendRestGetHeader = 1 Node.SendRestGetHeader = 1
global.ToLog("Send rest get headers from " + Context.BlockNumProof + " to " + global.NodeName(Node), 2) global.ToLog("Send rest get header " + Context.BlockNumProof + " to " + global.NodeName(Node), 2)
this.SendF(Node, { this.SendF(Node, {
"Method": "GETBLOCKHEADER", "Data": { Foward: 1, BlockNum: Context.BlockNumProof, Hash: [] }, "Context": { F: this.RETBLOCKHEADER_REST.bind(this) }, "Method": "GETBLOCKHEADER", "Data": { Foward: 1, BlockNum: Context.BlockNumProof, Hash: [] }, "Context": { F: this.RETBLOCKHEADER_REST.bind(this) },
}) })

View File

@ -17,8 +17,9 @@ import "../system/smart"
import "../system/file" import "../system/file"
import "../system/messager" import "../system/messager"
import "../system/names" import "../system/names"
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX") if (global.PROCESS_NAME === "MAIN") {
require("./wallet"); require("./wallet");
}
import CConsensus from './block-exchange' import CConsensus from './block-exchange'
export default class CSmartContract extends CConsensus { export default class CSmartContract extends CConsensus {
BufHashTree BufHashTree

View File

@ -24,6 +24,12 @@ function RunOnUpdate() {
if (CurNum < 1137) { if (CurNum < 1137) {
global.SERVER.ClearDataBase(); global.SERVER.ClearDataBase();
} }
if (CurNum < 1142) {
setTimeout(function() {
global.ToLog("UPD: START RewriteAllTransactions");
global.SERVER.RewriteAllTransactions();
}, 3000);
}
} else { } else {
} }
global.ToLog("UPDATER Finish"); global.ToLog("UPDATER Finish");

View File

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

1
src/global.d.ts vendored
View File

@ -664,6 +664,7 @@ declare global {
shaarr: any; shaarr: any;
ELECTRON: any; ELECTRON: any;
TestTestWaletMode: any; TestTestWaletMode: any;
OnExit: any;
} }
interface Process { interface Process {
RunRPC: Function; RunRPC: Function;

View File

@ -0,0 +1,120 @@
/*
* @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 > global.CHECK_STOP_CHILD_PROCESS) {
global.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":
global.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 = global.GlobalRunMap[msg.id];
if (F) {
delete global.GlobalRunMap[msg.id];
F(msg.Err, msg.Params);
}
break;
case "ToLogClient":
{
global.ToLogClient0(msg.Str, msg.StrKey, msg.bFinal);
break;
}
case "Eval":
global.EvalCode(msg.Code);
break;
}
});
function Exit() {
if (global.OnExit)
global.OnExit();
process.exit(0);
};
process.RunRPC = function(Name, Params, F) {
if (F) {
global.GlobalRunID++;
try {
process.send({ cmd: "call", id: global.GlobalRunID, Name: Name, Params: Params });
global.GlobalRunMap[global.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, undefined, 4);
}
catch (e) {
Result = "" + e;
}
return Result;
};
process.on('uncaughtException', function(err) {
global.ToError(err.stack);
global.ToLog(err.stack);
global.TO_ERROR_LOG(global.PROCESS_NAME, 777, err);
global.ToLog("-----------------" + global.PROCESS_NAME + " EXIT------------------");
process.exit();
});
process.on('error' as any, function(err: TeraError) {
global.ToError(global.PROCESS_NAME + ":\n" + err.stack);
global.ToLog(err.stack);
});

View File

@ -390,9 +390,9 @@ if (global.ADDRLIST_MODE) {
} }
function AllAlive() { function AllAlive() {
for (var i = 0; i < global.ArrMiningWrk.length; i++) { for (var i = 0; i < global.ArrMiningWrk.length; i++) {
global.ArrMiningWrk[i].send({ cmd: "Alive" }); global.ArrMiningWrk[i].send({ cmd: "Alive", DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME });
} }
SendToClient({ cmd: "Alive" }) SendToClient({ cmd: "Alive", DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME })
}; };
function ClearArrMining() { function ClearArrMining() {

View File

@ -19,35 +19,11 @@ import '../system/smart'
global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH); global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH); global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
import "../core/library" import "../core/library"
import "./child-process"
global.READ_ONLY_DB = 1; global.READ_ONLY_DB = 1;
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":
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;
@ -69,27 +45,6 @@ process.on('message', function(msg) {
} }
}); });
function CheckAlive() {
if (global.NOALIVE)
return;
var Delta = Date.now() - LastAlive;
if (Delta > global.CHECK_STOP_CHILD_PROCESS) {
global.ToLog("STATIC-DB: ALIVE TIMEOUT Stop and exit: " + Delta + "/" + global.CHECK_STOP_CHILD_PROCESS);
process.exit(0);
return;
}
};
process.on('uncaughtException', function(err) {
global.ToError(err.stack);
global.ToLog(err.stack);
global.TO_ERROR_LOG("STATIC-DB", 777, err);
global.ToLog("-----------------STATIC-DB EXIT------------------");
process.exit();
});
process.on('error' as any, function(err: TeraError) {
global.ToError("STATIC-DB:\n" + err.stack);
global.ToLog(err.stack);
});
import CServerDB from '../core/db/block-db' import CServerDB from '../core/db/block-db'
import { DB_FORMAT } from '../constant/db-format'; import { DB_FORMAT } from '../constant/db-format';
var KeyPair = crypto.createECDH('secp256k1'); var KeyPair = crypto.createECDH('secp256k1');

View File

@ -15,59 +15,16 @@ global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH); global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
import "../core/library" import "../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(global.PrepareStatEverySecond, 1000); setInterval(global.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":
global.EvalCode(msg.Code);
break;
default: default:
break; break;
} }
@ -77,27 +34,6 @@ global.SetStatMode = function(Val) {
return global.STAT_MODE; return global.STAT_MODE;
}; };
function CheckAlive() {
if (global.NOALIVE)
return;
var Delta = Date.now() - LastAlive;
if (Delta > 100 * 1000) {
global.ToLog("TX-PROCESS: ALIVE TIMEOUT Stop and exit: " + Delta);
process.exit(0);
return;
}
};
process.on('uncaughtException', function(err) {
global.ToError(err.stack);
global.ToLog(err.stack);
global.TO_ERROR_LOG("TX-PROCESS", 777, err);
global.ToLog("-----------------TX-PROCESS EXIT------------------");
process.exit();
});
process.on('error' as any, function(err: TeraError) {
global.ToError("TX-PROCESS:\n" + err.stack);
global.ToLog(err.stack);
});
global.HTTP_PORT_NUMBER = 0; global.HTTP_PORT_NUMBER = 0;
import CServerDB from '../core/transaction-validator' import CServerDB from '../core/transaction-validator'
import { STreeBuffer } from '../core/base'; import { STreeBuffer } from '../core/base';
@ -356,13 +292,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, undefined, 4);
} catch (e) {
Result = "" + e;
}
return Result;
};

View File

@ -21,39 +21,15 @@ global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH); global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
import "../core/library" import "../core/library"
import "../core/geo" import "../core/geo"
import "./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": case "retcall":
var F = global.GlobalRunMap[msg.id]; var F = global.GlobalRunMap[msg.id];
if (F) { if (F) {
@ -99,38 +75,16 @@ process.on('message', function(msg) {
var RedirectServer; var RedirectServer;
var HostingServer; var HostingServer;
function Exit() { global.OnExit = function() {
global.ToLogWeb("=Exit1=");
if (RedirectServer) if (RedirectServer)
RedirectServer.close(); RedirectServer.close();
if (HostingServer) if (HostingServer)
HostingServer.close(); HostingServer.close();
global.ToLogWeb("=Exit2=");
process.exit(0);
}; };
function CheckAlive() {
if (global.NOALIVE)
return;
var Delta = Date.now() - LastAlive;
if (Delta > global.CHECK_STOP_CHILD_PROCESS) {
Exit();
return;
}
};
process.on('uncaughtException', function(err) {
global.ToError(err.stack);
global.ToLog(err.stack);
global.TO_ERROR_LOG("HOSTING", 777, err);
global.ToLog("-----------------HOSTING EXIT------------------", 0);
process.exit();
});
process.on('error' as any, function(err: TeraError) {
global.ToError("HOSTING:\n" + err.stack);
global.ToLog(err.stack);
});
if (!global.HTTP_HOSTING_PORT) { if (!global.HTTP_HOSTING_PORT) {
global.ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT); global.ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT);
global.OnExit();
process.exit(); process.exit();
} }
var CServerDB = require("../core/db/block-db"); var CServerDB = require("../core/db/block-db");
@ -239,17 +193,18 @@ function RunListenServer() {
HostingServer.Server.close(); HostingServer.Server.close();
if (!bWasRun) if (!bWasRun)
setTimeout(function() { setTimeout(function() {
RunListenServer(); if (!bWasRun)
RunListenServer();
}, TimeToRerun); }, TimeToRerun);
return; return;
} }
global.ToError("H##6"); global.ToError("H##6");
global.ToError(err); global.ToError(err);
}); });
global.ToLogClient("Prepare to run WEB-server on port: " + global.HTTP_HOSTING_PORT); global.ToLog("Prepare to run WEB-server on port: " + global.HTTP_HOSTING_PORT);
HostingServer.listen(global.HTTP_HOSTING_PORT, global.LISTEN_IP, function() { HostingServer.listen(global.HTTP_HOSTING_PORT, global.LISTEN_IP, function() {
if (!bWasRun) if (!bWasRun)
global.ToLogClient("Run WEB-server on " + global.LISTEN_IP + ":" + global.HTTP_HOSTING_PORT); global.ToLog("Run WEB-server on " + global.LISTEN_IP + ":" + global.HTTP_HOSTING_PORT);
bWasRun = 1; bWasRun = 1;
}); });
}; };
@ -776,20 +731,6 @@ HostingCaller.GetSupply = function(Params) {
HostingCaller.GetTotalSupply = function(Params) { 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) {
global.GlobalRunID++;
try {
process.send({ cmd: "call", id: global.GlobalRunID, Name: Name, Params: Params });
global.GlobalRunMap[global.GlobalRunID] = F;
} catch (e) {
}
} else {
process.send({ cmd: "call", id: 0, Name: Name, Params: Params });
}
};
setInterval(function() { setInterval(function() {
if (global.SERVER) if (global.SERVER)
global.SERVER.Close(); global.SERVER.Close();

View File

@ -551,9 +551,6 @@ export default class AccountApp extends 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 (global.CompareArr(Account.PubKey, global.WALLET.PubKeyArr) === 0) {
global.WALLET.OnCreateAccount(Account)
}
this.ResultTx = Account.Num this.ResultTx = Account.Num
return true; return true;
} }

View File

@ -860,6 +860,7 @@ function $SetValue(ID, CoinSum) {
if (typeof CoinSum === "number") { if (typeof CoinSum === "number") {
CoinSum = global.COIN_FROM_FLOAT(CoinSum); CoinSum = global.COIN_FROM_FLOAT(CoinSum);
} }
CHECKSUM(CoinSum);
if (CoinSum.SumCENT >= 1e9) { if (CoinSum.SumCENT >= 1e9) {
throw "ERROR SumCENT>=1e9"; throw "ERROR SumCENT>=1e9";
} }
@ -906,6 +907,7 @@ function $Move(FromID, ToID, CoinSum, Description) {
if (typeof CoinSum === "number") { if (typeof CoinSum === "number") {
CoinSum = global.COIN_FROM_FLOAT(CoinSum); CoinSum = global.COIN_FROM_FLOAT(CoinSum);
} }
CHECKSUM(CoinSum);
if (CoinSum.SumCENT >= 1e9) { if (CoinSum.SumCENT >= 1e9) {
throw "ERROR SumCENT>=1e9"; throw "ERROR SumCENT>=1e9";
} }