sync: sync upstream code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
68310f1a3b
commit
8dafeb2cf0
@ -11,6 +11,15 @@
|
||||
var MAX_SUM_TER = 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)
|
||||
{
|
||||
Coin.SumCOIN += Value2.SumCOIN;
|
||||
@ -102,6 +111,7 @@ function COIN_FROM_STRING(Str)
|
||||
};
|
||||
if(typeof global === "object")
|
||||
{
|
||||
global.CHECKSUM = CHECKSUM;
|
||||
global.ADD = ADD;
|
||||
global.SUB = SUB;
|
||||
global.DIV = DIV;
|
||||
|
@ -135,6 +135,15 @@ window.GetCurrentBlockNumByTime = function ()
|
||||
return 0;
|
||||
};
|
||||
|
||||
function SetMinPow()
|
||||
{
|
||||
var item = $("idDeltaPow");
|
||||
if(item)
|
||||
{
|
||||
window.DELTA_POWER_POW_TR = ParseNum(item.value);
|
||||
}
|
||||
};
|
||||
|
||||
function GetBlockNumTr(arr)
|
||||
{
|
||||
var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
|
||||
@ -153,6 +162,7 @@ var LastCreatePOWHash = [255, 255, 255, 255];
|
||||
|
||||
function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
|
||||
{
|
||||
SetMinPow();
|
||||
var TrType = arr[0];
|
||||
var BlockNum = GetBlockNumTr(arr);
|
||||
if(MinPow === undefined)
|
||||
|
@ -63,7 +63,7 @@
|
||||
var SaveIdArr=["idAccount","idTo","idSumSend","idDescription","idSelStyle",
|
||||
"idViewAccountNum","idViewBlockNum","idViewActNum","idViewHashNum","idViewDappNum",
|
||||
"idRunText","idViewAccountFilter",
|
||||
"idBlockCount","idPeriodAutoCheckPoint"];
|
||||
"idBlockCount","idPeriodAutoCheckPoint","idDeltaPow"];
|
||||
|
||||
|
||||
var MaxAccID=0;
|
||||
@ -1730,6 +1730,7 @@
|
||||
<BR>
|
||||
<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">
|
||||
Pow:<INPUT type="number" id="idDeltaPow" style="width: 60px" value="" onchange="SetMinPow()">
|
||||
</DIV>
|
||||
|
||||
<script>
|
||||
|
@ -1352,10 +1352,19 @@ export default class CConsensus extends CBlock {
|
||||
MiningProcess(msg) {
|
||||
var BlockMining = this.GetBlock(msg.BlockNum);
|
||||
if (!BlockMining) {
|
||||
SendToWebClient({
|
||||
msg: msg,
|
||||
errror: '!BlockMining'
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (!BlockMining.StartMining || BlockMining.bSave)
|
||||
if (!BlockMining.StartMining || BlockMining.bSave) {
|
||||
SendToWebClient({
|
||||
msg: msg,
|
||||
errror: `!BlockMining.StartMining ${BlockMining.StartMining} || BlockMining.bSave ${BlockMining.bSave}`
|
||||
})
|
||||
return;
|
||||
}
|
||||
if (BlockMining && BlockMining.Hash && BlockMining.SeqHash && global.CompareArr(BlockMining.SeqHash, msg.SeqHash) === 0) {
|
||||
var ValueOld = global.GetHashFromSeqAddr(BlockMining.SeqHash, BlockMining.AddrHash, BlockMining.BlockNum);
|
||||
var ValueMsg = global.GetHashFromSeqAddr(msg.SeqHash, msg.AddrHash, BlockMining.BlockNum);
|
||||
@ -1395,12 +1404,12 @@ export default class CConsensus extends CBlock {
|
||||
setTimeout(() => {
|
||||
let webmsg: any = { BlockNum: msg.BlockNum }
|
||||
webmsg.Mining = {
|
||||
Hash: BlockMining.Hash.toString(),
|
||||
SeqHash: BlockMining.Hash.toString()
|
||||
Hash: global.GetHexFromArr(BlockMining.Hash),
|
||||
SeqHash: global.GetHexFromArr(BlockMining.Hash)
|
||||
}
|
||||
webmsg.New = {
|
||||
Hash: ValueNew.Hash.toString(),
|
||||
PowHash: ValueNew.PowHash.toString()
|
||||
Hash: global.GetHexFromArr(ValueNew.Hash),
|
||||
PowHash: global.GetHexFromArr(ValueNew.PowHash)
|
||||
}
|
||||
Object.assign(webmsg, {
|
||||
HashCount,
|
||||
|
@ -110,7 +110,7 @@ global.HARD_PACKET_PERIOD120 = 160;
|
||||
global.MINING_START_TIME = "";
|
||||
global.MINING_PERIOD_TIME = "";
|
||||
global.CHECK_RUN_MINING = 21 * 1000;
|
||||
global.CHECK_STOP_CHILD_PROCESS = 10 * 1000;
|
||||
global.CHECK_STOP_CHILD_PROCESS = 100 * 1000;
|
||||
global.COUNT_MINING_CPU = 0;
|
||||
global.SIZE_MINING_MEMORY = 0;
|
||||
global.HTTP_HOSTING_PORT = 0;
|
||||
@ -123,7 +123,6 @@ global.MIN_POWER_POW_HANDSHAKE = 12;
|
||||
global.USE_HINT = 0;
|
||||
global.ALL_VIEW_ROWS = 0;
|
||||
global.COUNT_BLOCK_PROOF = 300;
|
||||
global.COUNT_NODE_PROOF = 10;
|
||||
global.MIN_POWER_POW_MSG = 2;
|
||||
global.MEM_POOL_MSG_COUNT = 1000;
|
||||
global.MAX_LEVEL_SPECIALIZATION = 24;
|
||||
@ -204,7 +203,6 @@ if (global.LOCAL_RUN) {
|
||||
global.NEW_FORMULA_TARGET2 = 1;
|
||||
global.NETWORK = "LOCAL";
|
||||
global.ALL_VIEW_ROWS = 1;
|
||||
global.COUNT_NODE_PROOF = 1;
|
||||
global.NEW_SIGN_TIME = 0;
|
||||
}
|
||||
else
|
||||
@ -234,7 +232,6 @@ else
|
||||
global.NEW_FORMULA_KTERA = 3;
|
||||
global.NEW_FORMULA_TARGET1 = 0;
|
||||
global.NEW_FORMULA_TARGET2 = 1;
|
||||
global.COUNT_NODE_PROOF = 8;
|
||||
global.NEW_SIGN_TIME = 4859000;
|
||||
global.MAX_LENGTH_SENDER_MAP = 100;
|
||||
global.DELTA_START_SENDER_MAP = 12;
|
||||
|
@ -21,8 +21,7 @@ if (global.USE_PARAM_JS) {
|
||||
if (fs.existsSync(PathParams))
|
||||
try {
|
||||
require(PathParams);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
@ -63,8 +62,7 @@ if (global.USE_PARAM_JS) {
|
||||
if (fs.existsSync(PathParams))
|
||||
try {
|
||||
require(PathParams);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
@ -291,6 +289,12 @@ function CheckGlobalTime() {
|
||||
global.ToLog("Get global time: " + NetTime);
|
||||
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.CheckGlobalTime = CheckGlobalTime;
|
||||
|
@ -13,8 +13,10 @@ import CDB from './db/block-db'
|
||||
import { TYPE_TRANSACTION } from '../constant/account';
|
||||
import { DB_FORMAT } from '../constant/db-format';
|
||||
var MIN_POW_CHAINS = 2;
|
||||
global.COUNT_NODE_PROOF = 6;
|
||||
if (global.TEST_NETWORK) {
|
||||
MIN_POW_CHAINS = 1;
|
||||
global.COUNT_NODE_PROOF = 1;
|
||||
}
|
||||
export default class CRest extends CDB {
|
||||
LoadRestContext
|
||||
@ -67,6 +69,9 @@ export default class CRest extends CDB {
|
||||
let Context = this.LoadRestContext;
|
||||
switch (Context.Mode) {
|
||||
case 0:
|
||||
if (!global.TX_PROCESS) {
|
||||
return;
|
||||
}
|
||||
var ArrNodes = this.GetActualNodes();
|
||||
for (var i = 0; i < ArrNodes.length; i++) {
|
||||
var Node = ArrNodes[i];
|
||||
@ -74,7 +79,7 @@ export default class CRest extends CDB {
|
||||
continue;
|
||||
}
|
||||
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, {
|
||||
"Method": "GETBLOCKHEADER", "Data": { Foward: 1, BlockNum: Context.BlockNumProof, Hash: [] }, "Context": { F: this.RETBLOCKHEADER_REST.bind(this) },
|
||||
})
|
||||
|
@ -17,8 +17,9 @@ import "../system/smart"
|
||||
import "../system/file"
|
||||
import "../system/messager"
|
||||
import "../system/names"
|
||||
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX")
|
||||
if (global.PROCESS_NAME === "MAIN") {
|
||||
require("./wallet");
|
||||
}
|
||||
import CConsensus from './block-exchange'
|
||||
export default class CSmartContract extends CConsensus {
|
||||
BufHashTree
|
||||
|
@ -24,6 +24,12 @@ function RunOnUpdate() {
|
||||
if (CurNum < 1137) {
|
||||
global.SERVER.ClearDataBase();
|
||||
}
|
||||
if (CurNum < 1142) {
|
||||
setTimeout(function() {
|
||||
global.ToLog("UPD: START RewriteAllTransactions");
|
||||
global.SERVER.RewriteAllTransactions();
|
||||
}, 3000);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
global.ToLog("UPDATER Finish");
|
||||
|
@ -45,7 +45,7 @@ class CApp {
|
||||
this.AccountMap = Params.AccountMap
|
||||
this.KeyPair = crypto.createECDH('secp256k1')
|
||||
if (Params.Protect) {
|
||||
global.ToLogClient("Wallet protect by password")
|
||||
global.ToLog("Wallet protect by password")
|
||||
this.KeyXOR = global.GetArrFromHex(Params.KeyXOR)
|
||||
this.WalletOpen = false
|
||||
this.SetPrivateKey(Params.PubKey)
|
||||
|
1
src/global.d.ts
vendored
1
src/global.d.ts
vendored
@ -664,6 +664,7 @@ declare global {
|
||||
shaarr: any;
|
||||
ELECTRON: any;
|
||||
TestTestWaletMode: any;
|
||||
OnExit: any;
|
||||
}
|
||||
interface Process {
|
||||
RunRPC: Function;
|
||||
|
120
src/process/child-process.ts
Normal file
120
src/process/child-process.ts
Normal 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);
|
||||
});
|
@ -390,9 +390,9 @@ if (global.ADDRLIST_MODE) {
|
||||
}
|
||||
function AllAlive() {
|
||||
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() {
|
||||
|
@ -19,35 +19,11 @@ import '../system/smart'
|
||||
global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
|
||||
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
|
||||
import "../core/library"
|
||||
import "./child-process"
|
||||
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) {
|
||||
LastAlive = Date.now();
|
||||
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":
|
||||
GETBLOCKHEADER(msg);
|
||||
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 { DB_FORMAT } from '../constant/db-format';
|
||||
var KeyPair = crypto.createECDH('secp256k1');
|
||||
|
@ -15,59 +15,16 @@ global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
|
||||
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
|
||||
import "../core/library"
|
||||
global.READ_ONLY_DB = 0;
|
||||
var LastAlive = Date.now();
|
||||
setTimeout(function() {
|
||||
setInterval(CheckAlive, 1000);
|
||||
}, 20000);
|
||||
require("./child-process");
|
||||
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) {
|
||||
LastAlive = Date.now();
|
||||
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":
|
||||
global.TreeFindTX.SaveValue(msg.TX, msg);
|
||||
break;
|
||||
case "SetSmartEvent":
|
||||
global.TreeFindTX.SaveValue("Smart:" + msg.Smart, 1);
|
||||
break;
|
||||
case "Eval":
|
||||
global.EvalCode(msg.Code);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -77,27 +34,6 @@ global.SetStatMode = function(Val) {
|
||||
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;
|
||||
import CServerDB from '../core/transaction-validator'
|
||||
import { STreeBuffer } from '../core/base';
|
||||
@ -356,13 +292,3 @@ function TXWriteAccHash() {
|
||||
return DataHash;
|
||||
};
|
||||
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;
|
||||
};
|
||||
|
@ -21,39 +21,15 @@ global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
|
||||
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
|
||||
import "../core/library"
|
||||
import "../core/geo"
|
||||
import "./child-process"
|
||||
global.READ_ONLY_DB = 1;
|
||||
global.MAX_STAT_PERIOD = 600;
|
||||
var HostNodeList = [];
|
||||
var AllNodeList = [];
|
||||
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) {
|
||||
LastAlive = Date.now();
|
||||
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 = global.GlobalRunMap[msg.id];
|
||||
if (F) {
|
||||
@ -99,38 +75,16 @@ process.on('message', function(msg) {
|
||||
var RedirectServer;
|
||||
var HostingServer;
|
||||
|
||||
function Exit() {
|
||||
global.ToLogWeb("=Exit1=");
|
||||
global.OnExit = function() {
|
||||
if (RedirectServer)
|
||||
RedirectServer.close();
|
||||
if (HostingServer)
|
||||
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) {
|
||||
global.ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT);
|
||||
global.OnExit();
|
||||
process.exit();
|
||||
}
|
||||
var CServerDB = require("../core/db/block-db");
|
||||
@ -239,17 +193,18 @@ function RunListenServer() {
|
||||
HostingServer.Server.close();
|
||||
if (!bWasRun)
|
||||
setTimeout(function() {
|
||||
RunListenServer();
|
||||
if (!bWasRun)
|
||||
RunListenServer();
|
||||
}, TimeToRerun);
|
||||
return;
|
||||
}
|
||||
global.ToError("H##6");
|
||||
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() {
|
||||
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;
|
||||
});
|
||||
};
|
||||
@ -776,20 +731,6 @@ HostingCaller.GetSupply = function(Params) {
|
||||
HostingCaller.GetTotalSupply = function(Params) {
|
||||
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() {
|
||||
if (global.SERVER)
|
||||
global.SERVER.Close();
|
||||
|
@ -551,9 +551,6 @@ export default class AccountApp extends DApp {
|
||||
Account.Adviser = TR.Adviser
|
||||
Account.Value.Smart = TR.Smart
|
||||
this.WriteStateTR(Account, TrNum)
|
||||
if (global.CompareArr(Account.PubKey, global.WALLET.PubKeyArr) === 0) {
|
||||
global.WALLET.OnCreateAccount(Account)
|
||||
}
|
||||
this.ResultTx = Account.Num
|
||||
return true;
|
||||
}
|
||||
|
@ -860,6 +860,7 @@ function $SetValue(ID, CoinSum) {
|
||||
if (typeof CoinSum === "number") {
|
||||
CoinSum = global.COIN_FROM_FLOAT(CoinSum);
|
||||
}
|
||||
CHECKSUM(CoinSum);
|
||||
if (CoinSum.SumCENT >= 1e9) {
|
||||
throw "ERROR SumCENT>=1e9";
|
||||
}
|
||||
@ -906,6 +907,7 @@ function $Move(FromID, ToID, CoinSum, Description) {
|
||||
if (typeof CoinSum === "number") {
|
||||
CoinSum = global.COIN_FROM_FLOAT(CoinSum);
|
||||
}
|
||||
CHECKSUM(CoinSum);
|
||||
if (CoinSum.SumCENT >= 1e9) {
|
||||
throw "ERROR SumCENT>=1e9";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user