refactor: sync code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
8576359edc
commit
12e835d5f5
@ -9,9 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
// import * as crypto from 'crypto';
|
|
||||||
import CNode from './node'
|
import CNode from './node'
|
||||||
import CMessages from './transfer-msg'
|
import { secp256k1 } from './library'
|
||||||
global.PERIOD_FOR_RECONNECT = 3600 * 1000;
|
global.PERIOD_FOR_RECONNECT = 3600 * 1000;
|
||||||
global.CHECK_DELTA_TIME = { Num: 0, bUse: 0, StartBlockNum: 0, EndBlockNum: 0, bAddTime: 0, DeltaTime: 0, Sign: [] };
|
global.CHECK_DELTA_TIME = { Num: 0, bUse: 0, StartBlockNum: 0, EndBlockNum: 0, bAddTime: 0, DeltaTime: 0, Sign: [] };
|
||||||
global.CHECK_POINT = { BlockNum: 0, Hash: [], Sign: [] };
|
global.CHECK_POINT = { BlockNum: 0, Hash: [], Sign: [] };
|
||||||
@ -28,10 +27,11 @@ const MAX_PERIOD_GETNODES = 120 * 1000;
|
|||||||
global.MIN_PERIOD_PING = 4 * 1000;
|
global.MIN_PERIOD_PING = 4 * 1000;
|
||||||
const MAX_PERIOD_PING = 120 * 1000;
|
const MAX_PERIOD_PING = 120 * 1000;
|
||||||
global.MAX_PING_FOR_CONNECT = 400;
|
global.MAX_PING_FOR_CONNECT = 400;
|
||||||
const CAN_START_TIME_AVG = 200;
|
|
||||||
var MAX_TIME_CORRECT = 3 * 3600 * 1000;
|
var MAX_TIME_CORRECT = 3 * 3600 * 1000;
|
||||||
global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME;
|
global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME;
|
||||||
const PERIOD_FOR_START_CHECK_TIME = 300;
|
const PERIOD_FOR_START_CHECK_TIME = 300;
|
||||||
|
const CAN_START_TIME_AVG = 200;
|
||||||
|
import CMessages from './transfer-msg'
|
||||||
export default class CConnect extends CMessages {
|
export default class CConnect extends CMessages {
|
||||||
ip
|
ip
|
||||||
port
|
port
|
||||||
@ -217,17 +217,34 @@ export default class CConnect extends CMessages {
|
|||||||
VERSIONMAX: global.DEF_VERSION,
|
VERSIONMAX: global.DEF_VERSION,
|
||||||
FIRST_TIME_BLOCK: 0,
|
FIRST_TIME_BLOCK: 0,
|
||||||
PingVersion: 3,
|
PingVersion: 3,
|
||||||
GrayConnect: GrayAddres, Reserve2: 0, AutoCorrectTime: global.AUTO_CORRECT_TIME,
|
GrayConnect: GrayAddres,
|
||||||
LevelCount: LevelCount, Time: (global.GetCurrentTime() - 0), BlockNumDB: this.BlockNumDB, LoadHistoryMode: this.LoadHistoryMode, CanStart: global.CAN_START,
|
Reserve2: 0,
|
||||||
CheckPoint: global.CHECK_POINT, Reserv3: [], Key: this.KeyToNode, Name: this.NameToNode, TrafficFree: this.SendTrafficFree, AccountBlockNum: BlockNumHash,
|
AutoCorrectTime: global.AUTO_CORRECT_TIME,
|
||||||
AccountsHash: AccountsHash, MemoryUsage: Math.trunc(process.memoryUsage().heapTotal / 1024 / 1024), CheckDeltaTime: global.CHECK_DELTA_TIME,
|
LevelCount: LevelCount,
|
||||||
CodeVersion: global.CODE_VERSION, IsAddrList: global.ADDRLIST_MODE, CheckPointHashDB: CheckPointHashDB, PortWeb: global.HTTP_HOSTING_PORT, HashDB: HashDB,
|
Time: (global.GetCurrentTime() - 0),
|
||||||
StopGetBlock: StopGetBlock, NetConstant: global.NET_CONSTANT,
|
BlockNumDB: this.BlockNumDB,
|
||||||
|
LoadHistoryMode: this.LoadHistoryMode,
|
||||||
|
CanStart: global.CAN_START,
|
||||||
|
CheckPoint: global.CHECK_POINT,
|
||||||
|
Reserv3: [],
|
||||||
|
Key: this.KeyToNode,
|
||||||
|
Name: this.NameToNode,
|
||||||
|
TrafficFree: this.SendTrafficFree,
|
||||||
|
AccountBlockNum: BlockNumHash,
|
||||||
|
AccountsHash: AccountsHash,
|
||||||
|
MemoryUsage: Math.trunc(process.memoryUsage().heapTotal / 1024 / 1024),
|
||||||
|
CheckDeltaTime: global.CHECK_DELTA_TIME,
|
||||||
|
CodeVersion: global.CODE_VERSION,
|
||||||
|
IsAddrList: global.ADDRLIST_MODE,
|
||||||
|
CheckPointHashDB: CheckPointHashDB,
|
||||||
|
PortWeb: global.HTTP_HOSTING_PORT,
|
||||||
|
HashDB: HashDB,
|
||||||
|
StopGetBlock: StopGetBlock,
|
||||||
|
NetConstant: global.NET_CONSTANT,
|
||||||
};
|
};
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
static
|
static PING_F(bSend) {
|
||||||
PING_F(bSend) {
|
|
||||||
return "{\
|
return "{\
|
||||||
VERSIONMAX:str15,\
|
VERSIONMAX:str15,\
|
||||||
PingVersion:byte,\
|
PingVersion:byte,\
|
||||||
@ -886,7 +903,7 @@ export default class CConnect extends CMessages {
|
|||||||
}
|
}
|
||||||
if (!this.SignCurrentTimeDev) {
|
if (!this.SignCurrentTimeDev) {
|
||||||
var SignArr = global.GetArrFromHex(global.SERVER.addrStr);
|
var SignArr = global.GetArrFromHex(global.SERVER.addrStr);
|
||||||
this.SignCurrentTimeDev = global.GetArrFromValue(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
this.SignCurrentTimeDev = secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||||
}
|
}
|
||||||
var Time = global.GetCurrentTime() - 0;
|
var Time = global.GetCurrentTime() - 0;
|
||||||
global.ToLog("Send time: " + Time + " to " + global.NodeInfo(Node))
|
global.ToLog("Send time: " + Time + " to " + global.NodeInfo(Node))
|
||||||
|
@ -66,6 +66,8 @@ global.CONST_NAME_ARR = [
|
|||||||
global.MAX_LENGTH_SENDER_MAP = 3000;
|
global.MAX_LENGTH_SENDER_MAP = 3000;
|
||||||
global.DELTA_START_SENDER_MAP = 24;
|
global.DELTA_START_SENDER_MAP = 24;
|
||||||
global.NODES_DELTA_CALC_HOUR = 4;
|
global.NODES_DELTA_CALC_HOUR = 4;
|
||||||
|
global.USE_API_WALLET = 1;
|
||||||
|
global.USE_API_V1 = 1;
|
||||||
global.USE_HARD_API_V2 = 0;
|
global.USE_HARD_API_V2 = 0;
|
||||||
global.USE_TICKET = 0;
|
global.USE_TICKET = 0;
|
||||||
global.USE_CHECK_SENDING = 1;
|
global.USE_CHECK_SENDING = 1;
|
||||||
@ -76,7 +78,7 @@ global.WATCHDOG_BADACCOUNT = 1;
|
|||||||
global.WATCHDOG_DEV = 0;
|
global.WATCHDOG_DEV = 0;
|
||||||
global.RESYNC_CONDITION = { "OWN_BLOCKS": 20, "K_POW": 5 };
|
global.RESYNC_CONDITION = { "OWN_BLOCKS": 20, "K_POW": 5 };
|
||||||
global.REST_BLOCK_SCALE = 1000;
|
global.REST_BLOCK_SCALE = 1000;
|
||||||
global.REST_START_COUNT = 10000;
|
global.REST_START_COUNT = 1000;
|
||||||
global.LOAD_TO_BEGIN = 2;
|
global.LOAD_TO_BEGIN = 2;
|
||||||
global.DEBUG_WALLET = 0;
|
global.DEBUG_WALLET = 0;
|
||||||
global.CHECK_GLOBAL_TIME = 1;
|
global.CHECK_GLOBAL_TIME = 1;
|
||||||
@ -114,7 +116,8 @@ global.SIZE_MINING_MEMORY = 0;
|
|||||||
global.HTTP_HOSTING_PORT = 0;
|
global.HTTP_HOSTING_PORT = 0;
|
||||||
global.HTTPS_HOSTING_DOMAIN = "";
|
global.HTTPS_HOSTING_DOMAIN = "";
|
||||||
global.HTTP_MAX_COUNT_ROWS = 20;
|
global.HTTP_MAX_COUNT_ROWS = 20;
|
||||||
global.HTTP_ADMIN_PASSORD = "";
|
global.HTTP_ADMIN_PASSWORD = "";
|
||||||
|
global.HTTP_START_PAGE = "";
|
||||||
require("./startlib");
|
require("./startlib");
|
||||||
global.MIN_POWER_POW_HANDSHAKE = 12;
|
global.MIN_POWER_POW_HANDSHAKE = 12;
|
||||||
global.USE_HINT = 0;
|
global.USE_HINT = 0;
|
||||||
@ -232,6 +235,8 @@ else
|
|||||||
global.COUNT_NODE_PROOF = 8;
|
global.COUNT_NODE_PROOF = 8;
|
||||||
global.REST_START_COUNT = 10000;
|
global.REST_START_COUNT = 10000;
|
||||||
global.NEW_SIGN_TIME = 4859000;
|
global.NEW_SIGN_TIME = 4859000;
|
||||||
|
global.MAX_LENGTH_SENDER_MAP = 100;
|
||||||
|
global.DELTA_START_SENDER_MAP = 12;
|
||||||
}
|
}
|
||||||
if (global.LOCAL_RUN) {
|
if (global.LOCAL_RUN) {
|
||||||
global.BLOCKNUM_TICKET_ALGO = 0;
|
global.BLOCKNUM_TICKET_ALGO = 0;
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
require("./library");
|
require("./library");
|
||||||
import { secp256k1 } from './library'
|
|
||||||
import * as crypto from 'crypto'
|
import * as crypto from 'crypto'
|
||||||
|
import { secp256k1 } from './library'
|
||||||
|
|
||||||
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
|
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
|
||||||
var BuferForStr = Buffer.alloc(32);
|
var BuferForStr = Buffer.alloc(32);
|
||||||
@ -79,18 +79,16 @@ global.CheckDevelopSign = function(SignArr, Sign) {
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
let GetPublicKeyFromAddres = global.GetPublicKeyFromAddres;
|
|
||||||
global.CheckContextSecret = function(Context, ContextAddrTo) {
|
global.CheckContextSecret = function(Context, ContextAddrTo) {
|
||||||
if (ContextAddrTo.Secret === undefined) {
|
if (ContextAddrTo.Secret === undefined) {
|
||||||
if (ContextAddrTo.publickey === undefined) {
|
if (ContextAddrTo.publickey === undefined) {
|
||||||
ContextAddrTo.publickey = GetPublicKeyFromAddres(ContextAddrTo.addrArr);
|
ContextAddrTo.publickey = global.GetPublicKeyFromAddres(ContextAddrTo.addrArr);
|
||||||
}
|
}
|
||||||
ContextAddrTo.Secret = Context.KeyPair.computeSecret(ContextAddrTo.publickey, null);
|
ContextAddrTo.Secret = Context.KeyPair.computeSecret(ContextAddrTo.publickey, null);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let CheckContextSecret = global.CheckContextSecret;
|
|
||||||
global.GetSignHash = function(Context, ContextAddrTo, Msg) {
|
global.GetSignHash = function(Context, ContextAddrTo, Msg) {
|
||||||
CheckContextSecret(Context, ContextAddrTo);
|
global.CheckContextSecret(Context, ContextAddrTo);
|
||||||
if (typeof Msg === "string")
|
if (typeof Msg === "string")
|
||||||
Msg = Buffer.from(Msg);
|
Msg = Buffer.from(Msg);
|
||||||
var Buf = Buffer.concat([Msg, ContextAddrTo.Secret], Msg.length + ContextAddrTo.Secret.length);
|
var Buf = Buffer.concat([Msg, ContextAddrTo.Secret], Msg.length + ContextAddrTo.Secret.length);
|
||||||
@ -924,9 +922,9 @@ function Utf8ArrayToStr(array) {
|
|||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
// function GetArr32FromStr(Str) {
|
function GetArr32FromStr(Str) {
|
||||||
// return GetArrFromStr(Str, 32);
|
return GetArrFromStr(Str, 32);
|
||||||
// };
|
};
|
||||||
|
|
||||||
function GetArrFromStr(Str, Len) {
|
function GetArrFromStr(Str, Len) {
|
||||||
var arr = toUTF8Array(Str);
|
var arr = toUTF8Array(Str);
|
||||||
@ -1035,4 +1033,4 @@ declare global {
|
|||||||
//#endregion
|
//#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
147
src/core/geo.ts
147
src/core/geo.ts
@ -7,71 +7,116 @@
|
|||||||
* Twitter: https://twitter.com/terafoundation
|
* Twitter: https://twitter.com/terafoundation
|
||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import './library'
|
import "./library.js"
|
||||||
|
|
||||||
var BufIP;
|
var BufIP;
|
||||||
var MapNames = {}, FileIp = "./SITE/DB/iplocation.db", FileNames = "./SITE/DB/locationnames.csv", Format = "{Value:uint32,Length:uint32, id:uint32, latitude:uint32, longitude:uint32}",
|
var MapNames = {};
|
||||||
FormatStruct = {};
|
var FileIp = "./SITE/DB/iplocation.db";
|
||||||
|
var FileNames = "./SITE/DB/locationnames.csv";
|
||||||
|
var Format = "{Value:uint32,Length:uint32, id:uint32, latitude:uint32, longitude:uint32}";
|
||||||
|
var FormatStruct = {};
|
||||||
|
|
||||||
function SetGeoLocation(e) {
|
function SetGeoLocation(Item) {
|
||||||
if (!e.ip || !BufIP || !BufIP.length)
|
if (!Item.ip || !BufIP || !BufIP.length)
|
||||||
return !1;
|
return false;
|
||||||
var t = IPToUint(e.ip), i = FindItem(BufIP, 20, t);
|
var Num = IPToUint(Item.ip);
|
||||||
return i && (e.latitude = i.latitude, e.longitude = i.longitude, e.name = MapNames[i.id]), e.Geo = 1, !0;
|
var Location = FindItem(BufIP, 20, Num);
|
||||||
|
if (Location) {
|
||||||
|
Item.latitude = Location.latitude;
|
||||||
|
Item.longitude = Location.longitude;
|
||||||
|
Item.name = MapNames[Location.id];
|
||||||
|
}
|
||||||
|
Item.Geo = 1;
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
function ReadItem(e, t) {
|
function ReadItem(Num, Size) {
|
||||||
return BufIP.len = e * t, global.BufLib.Read(BufIP, Format, void 0, FormatStruct);
|
BufIP.len = Num * Size;
|
||||||
|
var Data = global.BufLib.Read(BufIP, Format, undefined, FormatStruct);
|
||||||
|
return Data;
|
||||||
};
|
};
|
||||||
|
|
||||||
function FindItem(e, t, i) {
|
function FindItem(Buf, Size, FindValue) {
|
||||||
var n, r = Math.trunc(e.length / t), a = (ReadItem(0, t), ReadItem(r, t), 0), u = r, o = Math.trunc(i * r / 4294967296);
|
var Item;
|
||||||
r <= o && (o = r - 1), o < a && (o = a);
|
var MaxNum = Math.trunc(Buf.length / Size);
|
||||||
for (var f = 40; 0 < f;) {
|
var MinItem = ReadItem(0, Size);
|
||||||
if (f-- , !(n = ReadItem(o, t)))
|
var MaxItem = ReadItem(MaxNum, Size);
|
||||||
return void global.ToLog("GEO FindItem - Error read num: " + o);
|
var StartNum = 0;
|
||||||
if (n.Value > i) {
|
var EndNum = MaxNum;
|
||||||
if (u = o - 1, 0 === (l = o - a))
|
var CurNum = Math.trunc(FindValue * MaxNum / 0x100000000);
|
||||||
return;
|
if (CurNum >= MaxNum)
|
||||||
o -= l = Math.trunc((1 + l) / 2);
|
CurNum = MaxNum - 1;
|
||||||
}
|
if (CurNum < StartNum)
|
||||||
else
|
CurNum = StartNum;
|
||||||
if (n.Value < i) {
|
var CountIt = 40;
|
||||||
if (n.Value + n.Length >= i)
|
while (CountIt > 0) {
|
||||||
return n;
|
CountIt--;
|
||||||
var l;
|
Item = ReadItem(CurNum, Size);
|
||||||
if (a = o + 1, 0 === (l = u - o))
|
if (Item) {
|
||||||
return;
|
if (Item.Value > FindValue) {
|
||||||
o += l = Math.trunc((1 + l) / 2);
|
EndNum = CurNum - 1;
|
||||||
|
var Delta = CurNum - StartNum;
|
||||||
|
if (Delta === 0)
|
||||||
|
return undefined;
|
||||||
|
Delta = Math.trunc((1 + Delta) / 2);
|
||||||
|
CurNum = CurNum - Delta;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (n.Value === i)
|
if (Item.Value < FindValue) {
|
||||||
return n;
|
if (Item.Value + Item.Length >= FindValue)
|
||||||
|
return Item;
|
||||||
|
StartNum = CurNum + 1;
|
||||||
|
var Delta = EndNum - CurNum;
|
||||||
|
if (Delta === 0)
|
||||||
|
return undefined;
|
||||||
|
Delta = Math.trunc((1 + Delta) / 2);
|
||||||
|
CurNum = CurNum + Delta;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (Item.Value === FindValue)
|
||||||
|
return Item;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
global.ToLog("GEO FindItem - Error read num: " + CurNum);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
function Init() {
|
function Init() {
|
||||||
if (fs.existsSync(FileIp) && fs.existsSync(FileNames)) {
|
if (!fs.existsSync(FileIp))
|
||||||
BufIP = fs.readFileSync(FileIp);
|
return;
|
||||||
for (var e = fs.readFileSync(FileNames), t = 0; ;) {
|
if (!fs.existsSync(FileNames))
|
||||||
var i = e.indexOf("\n", t);
|
return;
|
||||||
if (i < 0)
|
BufIP = fs.readFileSync(FileIp);
|
||||||
break;
|
var Buf = fs.readFileSync(FileNames);
|
||||||
var n = e.toString("utf-8", t, i - 1);
|
var index2 = 0;
|
||||||
t = i + 1;
|
var Count = 0;
|
||||||
var r = n.split(","), a = parseInt(r[0]);
|
while (true) {
|
||||||
if (a) {
|
var index = Buf.indexOf("\n", index2);
|
||||||
0;
|
if (index < 0)
|
||||||
var u = r[10];
|
break;
|
||||||
u = (u = u || r[7]) || r[5], MapNames[a] = u;
|
var Str = Buf.toString('utf-8', index2, index - 1);
|
||||||
}
|
index2 = index + 1;
|
||||||
}
|
var Arr = Str.split(',');
|
||||||
|
var Num = parseInt(Arr[0]);
|
||||||
|
if (!Num)
|
||||||
|
continue;
|
||||||
|
Count++;
|
||||||
|
var Name = Arr[10];
|
||||||
|
if (!Name)
|
||||||
|
Name = Arr[7];
|
||||||
|
if (!Name)
|
||||||
|
Name = Arr[5];
|
||||||
|
MapNames[Num] = Name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function IPToUint(e) {
|
function IPToUint(IPv4) {
|
||||||
var t = e.split(".");
|
var d = IPv4.split('.');
|
||||||
return 256 * (256 * (256 * + t[0] + + t[1]) + + t[2]) + + t[3];
|
return ((((((+ d[0]) * 256) + (+ d[1])) * 256) + (+ d[2])) * 256) + (+ d[3]);
|
||||||
};
|
};
|
||||||
global.SetGeoLocation = SetGeoLocation, Init();
|
global.SetGeoLocation = SetGeoLocation;
|
||||||
|
Init();
|
||||||
|
@ -44,7 +44,7 @@ ContenTypeMap[".js"] = "application/javascript";
|
|||||||
ContenTypeMap["html"] = "text/html";
|
ContenTypeMap["html"] = "text/html";
|
||||||
ContenTypeMap["psd"] = "application/octet-stream";
|
ContenTypeMap["psd"] = "application/octet-stream";
|
||||||
global.HTTPCaller = {};
|
global.HTTPCaller = {};
|
||||||
let HTTPCaller = global.HTTPCaller
|
|
||||||
function DoCommand(response, Type, Path, params, remoteAddress) {
|
function DoCommand(response, Type, Path, params, remoteAddress) {
|
||||||
var F = global.HTTPCaller[params[0]];
|
var F = global.HTTPCaller[params[0]];
|
||||||
if (F) {
|
if (F) {
|
||||||
@ -238,7 +238,7 @@ function SendToResponce404(response) {
|
|||||||
response.writeHead(404, { 'Content-Type': 'text/html' });
|
response.writeHead(404, { 'Content-Type': 'text/html' });
|
||||||
response.end();
|
response.end();
|
||||||
};
|
};
|
||||||
HTTPCaller.DappBlockFile = function(Params, response) {
|
global.HTTPCaller.DappBlockFile = function(Params, response) {
|
||||||
Params.BlockNum = global.ParseNum(Params.BlockNum);
|
Params.BlockNum = global.ParseNum(Params.BlockNum);
|
||||||
Params.TrNum = global.ParseNum(Params.TrNum);
|
Params.TrNum = global.ParseNum(Params.TrNum);
|
||||||
if (!Params.TrNum)
|
if (!Params.TrNum)
|
||||||
@ -289,7 +289,7 @@ function SendToResponceResult0(response) {
|
|||||||
response.end("{\"result\":0}");
|
response.end("{\"result\":0}");
|
||||||
};
|
};
|
||||||
var glBlock0;
|
var glBlock0;
|
||||||
HTTPCaller.DappStaticCall = function(Params, response) {
|
global.HTTPCaller.DappStaticCall = function(Params, response) {
|
||||||
global.DApps.Accounts.BeginBlock();
|
global.DApps.Accounts.BeginBlock();
|
||||||
global.DApps.Accounts.BeginTransaction();
|
global.DApps.Accounts.BeginTransaction();
|
||||||
global.TickCounter = 100000;
|
global.TickCounter = 100000;
|
||||||
@ -312,7 +312,7 @@ HTTPCaller.DappStaticCall = function(Params, response) {
|
|||||||
response.end(Str);
|
response.end(Str);
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
global.HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
||||||
var SmartNum = global.ParseNum(Params.Smart);
|
var SmartNum = global.ParseNum(Params.Smart);
|
||||||
if (global.TX_PROCESS && global.TX_PROCESS.Worker)
|
if (global.TX_PROCESS && global.TX_PROCESS.Worker)
|
||||||
global.TX_PROCESS.Worker.send({ cmd: "SetSmartEvent", Smart: SmartNum });
|
global.TX_PROCESS.Worker.send({ cmd: "SetSmartEvent", Smart: SmartNum });
|
||||||
@ -336,7 +336,7 @@ HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
|||||||
DeleteOldEvents(SmartNum);
|
DeleteOldEvents(SmartNum);
|
||||||
var Context = GetUserContext(Params);
|
var Context = GetUserContext(Params);
|
||||||
var EArr = GetEventArray(SmartNum, Context);
|
var EArr = GetEventArray(SmartNum, Context);
|
||||||
var WLData = HTTPCaller.DappWalletList(Params);
|
var WLData = global.HTTPCaller.DappWalletList(Params);
|
||||||
var ArrLog = [];
|
var ArrLog = [];
|
||||||
for (var i = 0; i < global.ArrLogClient.length; i++) {
|
for (var i = 0; i < global.ArrLogClient.length; i++) {
|
||||||
var Item = global.ArrLogClient[i];
|
var Item = global.ArrLogClient[i];
|
||||||
@ -363,7 +363,7 @@ HTTPCaller.DappInfo = function(Params, responce, ObjectOnly) {
|
|||||||
}
|
}
|
||||||
return Ret;
|
return Ret;
|
||||||
};
|
};
|
||||||
HTTPCaller.DappWalletList = function(Params) {
|
global.HTTPCaller.DappWalletList = function(Params) {
|
||||||
var arr0 = global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap);
|
var arr0 = global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap);
|
||||||
var arr = [];
|
var arr = [];
|
||||||
for (var i = 0; i < arr0.length; i++) {
|
for (var i = 0; i < arr0.length; i++) {
|
||||||
@ -374,54 +374,54 @@ HTTPCaller.DappWalletList = function(Params) {
|
|||||||
var Ret: any = { result: 1, arr: arr, };
|
var Ret: any = { result: 1, arr: arr, };
|
||||||
return Ret;
|
return Ret;
|
||||||
};
|
};
|
||||||
HTTPCaller.DappAccountList = function(Params) {
|
global.HTTPCaller.DappAccountList = function(Params) {
|
||||||
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, undefined, 1);
|
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, undefined, 1);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.DappSmartList = function(Params) {
|
global.HTTPCaller.DappSmartList = function(Params) {
|
||||||
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, undefined, undefined, Params.GetAllData, Params.TokenGenerate);
|
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, undefined, undefined, Params.GetAllData, Params.TokenGenerate);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.DappBlockList = function(Params, response) {
|
global.HTTPCaller.DappBlockList = function(Params, response) {
|
||||||
Params.Filter = undefined;
|
Params.Filter = undefined;
|
||||||
return HTTPCaller.GetBlockList(Params, response, 1);
|
return global.HTTPCaller.GetBlockList(Params, response, 1);
|
||||||
};
|
};
|
||||||
HTTPCaller.DappTransactionList = function(Params, response) {
|
global.HTTPCaller.DappTransactionList = function(Params, response) {
|
||||||
Params.Filter = undefined;
|
Params.Filter = undefined;
|
||||||
Params.Param3 = Params.BlockNum;
|
Params.Param3 = Params.BlockNum;
|
||||||
return HTTPCaller.GetTransactionAll(Params, response);
|
return global.HTTPCaller.GetTransactionAll(Params, response);
|
||||||
};
|
};
|
||||||
var sessionid = global.GetHexFromAddres(crypto.randomBytes(20));
|
var sessionid = global.GetHexFromAddres(crypto.randomBytes(20));
|
||||||
HTTPCaller.RestartNode = function(Params) {
|
global.HTTPCaller.RestartNode = function(Params) {
|
||||||
global.RestartNode();
|
global.RestartNode();
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.ToLogServer = function(Str) {
|
global.HTTPCaller.ToLogServer = function(Str) {
|
||||||
global.ToLogClient(Str);
|
global.ToLogClient(Str);
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.FindMyAccounts = function(Params) {
|
global.HTTPCaller.FindMyAccounts = function(Params) {
|
||||||
global.WALLET.FindMyAccounts(1);
|
global.WALLET.FindMyAccounts(1);
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetAccount = function(id) {
|
global.HTTPCaller.GetAccount = function(id) {
|
||||||
id = parseInt(id);
|
id = parseInt(id);
|
||||||
var arr = global.DApps.Accounts.GetRowsAccounts(id, 1);
|
var arr = global.DApps.Accounts.GetRowsAccounts(id, 1);
|
||||||
return { Item: arr[0], result: 1 };
|
return { Item: arr[0], result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetAccountList = function(Params) {
|
global.HTTPCaller.GetAccountList = function(Params) {
|
||||||
if (!Params.CountNum)
|
if (!Params.CountNum)
|
||||||
Params.CountNum = 1;
|
Params.CountNum = 1;
|
||||||
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.DApps.Accounts.GetRowsAccounts(Params.StartNum, Params.CountNum, Params.Filter);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetDappList = function(Params) {
|
global.HTTPCaller.GetDappList = function(Params) {
|
||||||
if (!Params.CountNum)
|
if (!Params.CountNum)
|
||||||
Params.CountNum = 1;
|
Params.CountNum = 1;
|
||||||
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, Params.Filter, Params.Filter2, 1);
|
var arr = global.DApps.Smart.GetRows(Params.StartNum, Params.CountNum, Params.Filter, Params.Filter2, 1);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
global.HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
||||||
if (!Params.CountNum)
|
if (!Params.CountNum)
|
||||||
Params.CountNum = 1;
|
Params.CountNum = 1;
|
||||||
if (Params.StartNum < global.SERVER.BlockNumDBMin) {
|
if (Params.StartNum < global.SERVER.BlockNumDBMin) {
|
||||||
@ -448,7 +448,7 @@ HTTPCaller.GetBlockList = function(Params, response, bOnlyNum) {
|
|||||||
var arr = global.SERVER.GetRows(Params.StartNum, Params.CountNum, Params.Filter, !bOnlyNum);
|
var arr = global.SERVER.GetRows(Params.StartNum, Params.CountNum, Params.Filter, !bOnlyNum);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetTransactionAll = function(Params, response) {
|
global.HTTPCaller.GetTransactionAll = function(Params, response) {
|
||||||
if (!Params.CountNum)
|
if (!Params.CountNum)
|
||||||
Params.CountNum = 1;
|
Params.CountNum = 1;
|
||||||
var BlockNum = Params.Param3;
|
var BlockNum = Params.Param3;
|
||||||
@ -473,11 +473,11 @@ HTTPCaller.GetTransactionAll = function(Params, response) {
|
|||||||
var arr = global.SERVER.GetTrRows(BlockNum, Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.SERVER.GetTrRows(BlockNum, Params.StartNum, Params.CountNum, Params.Filter);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetActList = function(Params) {
|
global.HTTPCaller.GetActList = function(Params) {
|
||||||
var arr = global.DApps.Accounts.GetActList(Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.DApps.Accounts.GetActList(Params.StartNum, Params.CountNum, Params.Filter);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetHashList = function(Params) {
|
global.HTTPCaller.GetHashList = function(Params) {
|
||||||
var arr = global.DApps.Accounts.DBAccountsHash.GetRows(Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.DApps.Accounts.DBAccountsHash.GetRows(Params.StartNum, Params.CountNum, Params.Filter);
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
var item = arr[i];
|
var item = arr[i];
|
||||||
@ -491,14 +491,14 @@ HTTPCaller.GetHashList = function(Params) {
|
|||||||
}
|
}
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetHistoryAct = function(Params) {
|
global.HTTPCaller.GetHistoryAct = function(Params) {
|
||||||
var arr = global.WALLET.GetHistory(Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.WALLET.GetHistory(Params.StartNum, Params.CountNum, Params.Filter);
|
||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
var LastTimeGetHashRate = 0;
|
var LastTimeGetHashRate = 0;
|
||||||
var LastHashRate = 0;
|
var LastHashRate = 0;
|
||||||
var HashRateOneSec = 0;
|
var HashRateOneSec = 0;
|
||||||
HTTPCaller.GetWalletInfo = function(Params) {
|
global.HTTPCaller.GetWalletInfo = function(Params) {
|
||||||
var Constants = {};
|
var Constants = {};
|
||||||
for (var i = 0; i < global.CONST_NAME_ARR.length; i++) {
|
for (var i = 0; i < global.CONST_NAME_ARR.length; i++) {
|
||||||
var key = global.CONST_NAME_ARR[i];
|
var key = global.CONST_NAME_ARR[i];
|
||||||
@ -571,37 +571,37 @@ HTTPCaller.GetWalletInfo = function(Params) {
|
|||||||
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
||||||
return Ret;
|
return Ret;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetCurrentInfo = HTTPCaller.GetWalletInfo;
|
global.HTTPCaller.GetCurrentInfo = global.HTTPCaller.GetWalletInfo;
|
||||||
HTTPCaller.TestSignLib = function() {
|
global.HTTPCaller.TestSignLib = function() {
|
||||||
global.TestSignLib();
|
global.TestSignLib();
|
||||||
};
|
};
|
||||||
HTTPCaller.GetWalletAccounts = function() {
|
global.HTTPCaller.GetWalletAccounts = function() {
|
||||||
var Ret: any = { result: 1, arr: global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap), };
|
var Ret: any = { result: 1, arr: global.DApps.Accounts.GetWalletAccountsByMap(global.WALLET.AccountMap), };
|
||||||
Ret.PrivateKey = global.WALLET.KeyPair.PrivKeyStr;
|
Ret.PrivateKey = global.WALLET.KeyPair.PrivKeyStr;
|
||||||
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
Ret.PublicKey = global.WALLET.KeyPair.PubKeyStr;
|
||||||
return Ret;
|
return Ret;
|
||||||
};
|
};
|
||||||
HTTPCaller.SetWalletKey = function(PrivateKeyStr) {
|
global.HTTPCaller.SetWalletKey = function(PrivateKeyStr) {
|
||||||
global.WALLET.SetPrivateKey(PrivateKeyStr, true);
|
global.WALLET.SetPrivateKey(PrivateKeyStr, true);
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetWalletPasswordNew = function(Password) {
|
global.HTTPCaller.SetWalletPasswordNew = function(Password) {
|
||||||
global.WALLET.SetPasswordNew(Password);
|
global.WALLET.SetPasswordNew(Password);
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.OpenWallet = function(Password) {
|
global.HTTPCaller.OpenWallet = function(Password) {
|
||||||
var res = global.WALLET.OpenWallet(Password);
|
var res = global.WALLET.OpenWallet(Password);
|
||||||
return { result: res };
|
return { result: res };
|
||||||
};
|
};
|
||||||
HTTPCaller.CloseWallet = function() {
|
global.HTTPCaller.CloseWallet = function() {
|
||||||
var res = global.WALLET.CloseWallet();
|
var res = global.WALLET.CloseWallet();
|
||||||
return { result: res };
|
return { result: res };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetSignTransaction = function(TR) {
|
global.HTTPCaller.GetSignTransaction = function(TR) {
|
||||||
var Sign = global.WALLET.GetSignTransaction(TR);
|
var Sign = global.WALLET.GetSignTransaction(TR);
|
||||||
return { Sign: Sign, result: 1 };
|
return { Sign: Sign, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetSignFromHEX = function(Params) {
|
global.HTTPCaller.GetSignFromHEX = function(Params) {
|
||||||
var Arr = global.GetArrFromHex(Params.Hex);
|
var Arr = global.GetArrFromHex(Params.Hex);
|
||||||
var Sign;
|
var Sign;
|
||||||
if (Params.Account)
|
if (Params.Account)
|
||||||
@ -610,7 +610,7 @@ HTTPCaller.GetSignFromHEX = function(Params) {
|
|||||||
Sign = global.WALLET.GetSignFromArr(Arr);
|
Sign = global.WALLET.GetSignFromArr(Arr);
|
||||||
return { Sign: Sign, result: 1 };
|
return { Sign: Sign, result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.SendTransactionHex = function(Params) {
|
global.HTTPCaller.SendTransactionHex = function(Params) {
|
||||||
var body = global.GetArrFromHex(Params.Hex);
|
var body = global.GetArrFromHex(Params.Hex);
|
||||||
var Result: any = { result: 1 };
|
var Result: any = { result: 1 };
|
||||||
var Res = global.SERVER.AddTransactionOwn({ body: body, ToAll: 1 });
|
var Res = global.SERVER.AddTransactionOwn({ body: body, ToAll: 1 });
|
||||||
@ -622,11 +622,16 @@ HTTPCaller.SendTransactionHex = function(Params) {
|
|||||||
global.ToLogClient("Send: " + Result.text, global.GetHexFromArr(global.sha3(body)), final);
|
global.ToLogClient("Send: " + Result.text, global.GetHexFromArr(global.sha3(body)), final);
|
||||||
return Result;
|
return Result;
|
||||||
};
|
};
|
||||||
HTTPCaller.SendDirectCode = function(Params, response) {
|
global.HTTPCaller.SendDirectCode = function(Params, response) {
|
||||||
var Result;
|
var Result;
|
||||||
if (Params.TX) {
|
if (Params.TX || Params.WEB) {
|
||||||
if (global.TX_PROCESS && global.TX_PROCESS.RunRPC) {
|
var RunProcess;
|
||||||
global.TX_PROCESS.RunRPC("EvalCode", Params.Code, function(Err, Ret) {
|
if (Params.TX)
|
||||||
|
RunProcess = global.TX_PROCESS;
|
||||||
|
if (Params.WEB)
|
||||||
|
RunProcess = global.WEB_PROCESS;
|
||||||
|
if (RunProcess && RunProcess.RunRPC) {
|
||||||
|
RunProcess.RunRPC("EvalCode", Params.Code, function(Err, Ret) {
|
||||||
Result = { result: !Err, sessionid: sessionid, text: Ret, };
|
Result = { result: !Err, sessionid: sessionid, text: Ret, };
|
||||||
var Str = JSON.stringify(Result);
|
var Str = JSON.stringify(Result);
|
||||||
response.end(Str);
|
response.end(Str);
|
||||||
@ -634,7 +639,7 @@ HTTPCaller.SendDirectCode = function(Params, response) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Result = "No send to TX";
|
Result = "No process for send call";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -649,7 +654,7 @@ HTTPCaller.SendDirectCode = function(Params, response) {
|
|||||||
var Struct = { result: 1, sessionid: sessionid, text: Result };
|
var Struct = { result: 1, sessionid: sessionid, text: Result };
|
||||||
return Struct;
|
return Struct;
|
||||||
};
|
};
|
||||||
HTTPCaller.SetMining = function(MiningAccount) {
|
global.HTTPCaller.SetMining = function(MiningAccount) {
|
||||||
global.WALLET.SetMiningAccount(parseInt(MiningAccount));
|
global.WALLET.SetMiningAccount(parseInt(MiningAccount));
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
@ -667,7 +672,7 @@ function CheckCorrectDevKey() {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
HTTPCaller.SendECode = function(Param) {
|
global.HTTPCaller.SendECode = function(Param) {
|
||||||
var Ret = CheckCorrectDevKey();
|
var Ret = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -688,7 +693,7 @@ HTTPCaller.SendECode = function(Param) {
|
|||||||
global.SERVER.SendECode(Param, Node);
|
global.SERVER.SendECode(Param, Node);
|
||||||
return { result: 1, text: "Send" };
|
return { result: 1, text: "Send" };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetCheckPoint = function(BlockNum) {
|
global.HTTPCaller.SetCheckPoint = function(BlockNum) {
|
||||||
var Ret = CheckCorrectDevKey();
|
var Ret = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -716,7 +721,7 @@ function SetCheckPointOnBlock(BlockNum) {
|
|||||||
};
|
};
|
||||||
global.SetCheckPointOnBlock = SetCheckPointOnBlock;
|
global.SetCheckPointOnBlock = SetCheckPointOnBlock;
|
||||||
var idSetTimeSetCheckPoint;
|
var idSetTimeSetCheckPoint;
|
||||||
HTTPCaller.SetAutoCheckPoint = function(Param) {
|
global.HTTPCaller.SetAutoCheckPoint = function(Param) {
|
||||||
var Ret = CheckCorrectDevKey();
|
var Ret = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -759,7 +764,7 @@ function RunSetCheckPoint() {
|
|||||||
global.ToLog("SET CHECK POINT Power=" + Power + "/" + AvgPow + " BlockNum=" + BlockNum);
|
global.ToLog("SET CHECK POINT Power=" + Power + "/" + AvgPow + " BlockNum=" + BlockNum);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
HTTPCaller.SetNewCodeVersion = function(Data) {
|
global.HTTPCaller.SetNewCodeVersion = function(Data) {
|
||||||
var Ret: any = CheckCorrectDevKey();
|
var Ret: any = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -767,7 +772,7 @@ HTTPCaller.SetNewCodeVersion = function(Data) {
|
|||||||
global.SERVER.ResetNextPingAllNode();
|
global.SERVER.ResetNextPingAllNode();
|
||||||
return { result: 1, text: Ret };
|
return { result: 1, text: Ret };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetCheckNetConstant = function(Data) {
|
global.HTTPCaller.SetCheckNetConstant = function(Data) {
|
||||||
var Ret: any = CheckCorrectDevKey();
|
var Ret: any = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -783,7 +788,7 @@ HTTPCaller.SetCheckNetConstant = function(Data) {
|
|||||||
global.SERVER.ResetNextPingAllNode();
|
global.SERVER.ResetNextPingAllNode();
|
||||||
return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum };
|
return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetCheckDeltaTime = function(Data) {
|
global.HTTPCaller.SetCheckDeltaTime = function(Data) {
|
||||||
var Ret = CheckCorrectDevKey();
|
var Ret = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -798,7 +803,7 @@ HTTPCaller.SetCheckDeltaTime = function(Data) {
|
|||||||
return { result: 1, text: "Set check time Num=" + Data.Num };
|
return { result: 1, text: "Set check time Num=" + Data.Num };
|
||||||
};
|
};
|
||||||
var idAutoCorrTime;
|
var idAutoCorrTime;
|
||||||
HTTPCaller.SetAutoCorrTime = function(bSet) {
|
global.HTTPCaller.SetAutoCorrTime = function(bSet) {
|
||||||
var Ret = CheckCorrectDevKey();
|
var Ret = CheckCorrectDevKey();
|
||||||
if (Ret !== true)
|
if (Ret !== true)
|
||||||
return Ret;
|
return Ret;
|
||||||
@ -832,7 +837,7 @@ function RunAutoCorrTime() {
|
|||||||
global.ToLog("Auto corr time Num:" + Data.Num + " AutoDelta=" + AutoDelta);
|
global.ToLog("Auto corr time Num:" + Data.Num + " AutoDelta=" + AutoDelta);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
HTTPCaller.SaveConstant = function(SetObj) {
|
global.HTTPCaller.SaveConstant = function(SetObj) {
|
||||||
var WasUpdate = global.USE_AUTO_UPDATE;
|
var WasUpdate = global.USE_AUTO_UPDATE;
|
||||||
for (var key in SetObj) {
|
for (var key in SetObj) {
|
||||||
global[key] = SetObj[key];
|
global[key] = SetObj[key];
|
||||||
@ -850,7 +855,7 @@ HTTPCaller.SaveConstant = function(SetObj) {
|
|||||||
}
|
}
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetHTTPParams = function(SetObj) {
|
global.HTTPCaller.SetHTTPParams = function(SetObj) {
|
||||||
global.HTTP_PORT_NUMBER = SetObj.HTTPPort;
|
global.HTTP_PORT_NUMBER = SetObj.HTTPPort;
|
||||||
global.HTTP_PORT_PASSWORD = SetObj.HTTPPassword;
|
global.HTTP_PORT_PASSWORD = SetObj.HTTPPassword;
|
||||||
global.SAVE_CONST(true);
|
global.SAVE_CONST(true);
|
||||||
@ -858,7 +863,7 @@ HTTPCaller.SetHTTPParams = function(SetObj) {
|
|||||||
global.RestartNode();
|
global.RestartNode();
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.SetNetMode = function(SetObj) {
|
global.HTTPCaller.SetNetMode = function(SetObj) {
|
||||||
if (!global.NET_WORK_MODE)
|
if (!global.NET_WORK_MODE)
|
||||||
global.NET_WORK_MODE = {};
|
global.NET_WORK_MODE = {};
|
||||||
for (var key in SetObj) {
|
for (var key in SetObj) {
|
||||||
@ -873,7 +878,7 @@ HTTPCaller.SetNetMode = function(SetObj) {
|
|||||||
global.RestartNode();
|
global.RestartNode();
|
||||||
return { result: 1 };
|
return { result: 1 };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetAccountKey = function(Num) {
|
global.HTTPCaller.GetAccountKey = function(Num) {
|
||||||
var Result: any = {};
|
var Result: any = {};
|
||||||
Result.result = 0;
|
Result.result = 0;
|
||||||
var KeyPair = global.WALLET.GetAccountKey(Num);
|
var KeyPair = global.WALLET.GetAccountKey(Num);
|
||||||
@ -883,7 +888,7 @@ HTTPCaller.GetAccountKey = function(Num) {
|
|||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetHotArray = function(Param) {
|
global.HTTPCaller.GetHotArray = function(Param) {
|
||||||
var ArrTree = global.SERVER.GetTransferTree();
|
var ArrTree = global.SERVER.GetTransferTree();
|
||||||
if (!ArrTree)
|
if (!ArrTree)
|
||||||
return { result: 0 };
|
return { result: 0 };
|
||||||
@ -945,23 +950,50 @@ function GetCopyNode(Node, BlockCounts) {
|
|||||||
if (BlockCounts !== 0)
|
if (BlockCounts !== 0)
|
||||||
GetTiming = Math.trunc(Node.GetTiming / BlockCounts) / 1000;
|
GetTiming = Math.trunc(Node.GetTiming / BlockCounts) / 1000;
|
||||||
var Item = {
|
var Item = {
|
||||||
VersionNum: Node.VersionNum, NoSendTx: Node.NoSendTx, GetNoSendTx: Node.GetNoSendTx, DirectMAccount: Node.DirectMAccount,
|
VersionNum: Node.VersionNum,
|
||||||
id: Node.id, ip: Node.ip, portweb: Node.portweb, port: Node.port, TransferCount: Node.TransferCount, GetTiming: GetTiming, ErrCountAll: Node.ErrCountAll,
|
NoSendTx: Node.NoSendTx,
|
||||||
LevelCount: Node.LevelCount, LevelEnum: Node.LevelEnum, TimeTransfer: global.GetStrOnlyTimeUTC(new Date(Node.LastTimeTransfer)), BlockProcessCount: Node.BlockProcessCount,
|
GetNoSendTx: Node.GetNoSendTx,
|
||||||
DeltaTime: Node.DeltaTime, DeltaTimeM: Node.DeltaTimeM, DeltaGlobTime: Node.DeltaGlobTime, PingNumber: Node.PingNumber, NextConnectDelta: Node.NextConnectDelta,
|
DirectMAccount: Node.DirectMAccount,
|
||||||
NextGetNodesDelta: Node.NextGetNodesDelta, NextHotDelta: Node.NextHotDelta, Name: Node.Name, addrStr: Node.addrStr, CanHot: Node.CanHot,
|
id: Node.id,
|
||||||
Active: Node.Active, Hot: Node.Hot, Info: Node.PrevInfo + Node.Info, InConnectArr: Node.WasAddToConnect, Level: Node.Level, TransferBlockNum: Node.TransferBlockNum,
|
ip: Node.ip,
|
||||||
TransferSize: Node.TransferSize, TransferBlockNumFix: Node.TransferBlockNumFix, CurBlockNum: Node.CurBlockNum,
|
portweb: Node.portweb,
|
||||||
|
port: Node.port,
|
||||||
|
TransferCount: Node.TransferCount,
|
||||||
|
GetTiming: GetTiming,
|
||||||
|
ErrCountAll: Node.ErrCountAll,
|
||||||
|
LevelCount: Node.LevelCount,
|
||||||
|
LevelEnum: Node.LevelEnum,
|
||||||
|
TimeTransfer: global.GetStrOnlyTimeUTC(new Date(Node.LastTimeTransfer)),
|
||||||
|
BlockProcessCount: Node.BlockProcessCount,
|
||||||
|
DeltaTime: Node.DeltaTime,
|
||||||
|
DeltaTimeM: Node.DeltaTimeM,
|
||||||
|
DeltaGlobTime: Node.DeltaGlobTime,
|
||||||
|
PingNumber: Node.PingNumber,
|
||||||
|
NextConnectDelta: Node.NextConnectDelta,
|
||||||
|
NextGetNodesDelta: Node.NextGetNodesDelta,
|
||||||
|
NextHotDelta: Node.NextHotDelta,
|
||||||
|
Name: Node.Name,
|
||||||
|
addrStr: Node.addrStr,
|
||||||
|
CanHot: Node.CanHot,
|
||||||
|
Active: Node.Active,
|
||||||
|
Hot: Node.Hot,
|
||||||
|
Info: Node.PrevInfo + Node.Info,
|
||||||
|
InConnectArr: Node.WasAddToConnect,
|
||||||
|
Level: Node.Level,
|
||||||
|
TransferBlockNum: Node.TransferBlockNum,
|
||||||
|
TransferSize: Node.TransferSize,
|
||||||
|
TransferBlockNumFix: Node.TransferBlockNumFix,
|
||||||
|
CurBlockNum: Node.CurBlockNum,
|
||||||
};
|
};
|
||||||
return Item;
|
return Item;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetBlockchainStat = function(Param) {
|
global.HTTPCaller.GetBlockchainStat = function(Param) {
|
||||||
var Result = global.SERVER.GetStatBlockchainPeriod(Param);
|
var Result = global.SERVER.GetStatBlockchainPeriod(Param);
|
||||||
Result.result = 1;
|
Result.result = 1;
|
||||||
Result.sessionid = sessionid;
|
Result.sessionid = sessionid;
|
||||||
return Result;
|
return Result;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetAllCounters = function(Params, response) {
|
global.HTTPCaller.GetAllCounters = function(Params, response) {
|
||||||
let Result = global.GET_STATS();
|
let Result = global.GET_STATS();
|
||||||
Result.result = 1;
|
Result.result = 1;
|
||||||
Result.sessionid = sessionid;
|
Result.sessionid = sessionid;
|
||||||
@ -997,7 +1029,7 @@ function AddStatData(Params, Result, Prefix) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
HTTPCaller.SetStatMode = function(flag) {
|
global.HTTPCaller.SetStatMode = function(flag) {
|
||||||
if (flag)
|
if (flag)
|
||||||
global.StartCommonStat();
|
global.StartCommonStat();
|
||||||
global.STAT_MODE = flag;
|
global.STAT_MODE = flag;
|
||||||
@ -1005,7 +1037,7 @@ HTTPCaller.SetStatMode = function(flag) {
|
|||||||
global.TX_PROCESS.RunRPC("LOAD_CONST");
|
global.TX_PROCESS.RunRPC("LOAD_CONST");
|
||||||
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
||||||
};
|
};
|
||||||
HTTPCaller.ClearStat = function() {
|
global.HTTPCaller.ClearStat = function() {
|
||||||
global.ClearCommonStat();
|
global.ClearCommonStat();
|
||||||
if (global.TX_PROCESS && global.TX_PROCESS.RunRPC) {
|
if (global.TX_PROCESS && global.TX_PROCESS.RunRPC) {
|
||||||
global.TX_PROCESS.RunRPC("ClearCommonStat", "", function(Err, Params) {
|
global.TX_PROCESS.RunRPC("ClearCommonStat", "", function(Err, Params) {
|
||||||
@ -1017,15 +1049,15 @@ HTTPCaller.ClearStat = function() {
|
|||||||
}
|
}
|
||||||
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
return { result: 1, sessionid: sessionid, STAT_MODE: global.STAT_MODE };
|
||||||
};
|
};
|
||||||
HTTPCaller.RewriteAllTransactions = function(Param) {
|
global.HTTPCaller.RewriteAllTransactions = function(Param) {
|
||||||
global.RewriteAllTransactions();
|
global.RewriteAllTransactions();
|
||||||
return { result: 1, sessionid: sessionid };
|
return { result: 1, sessionid: sessionid };
|
||||||
};
|
};
|
||||||
HTTPCaller.RewriteTransactions = function(Param) {
|
global.HTTPCaller.RewriteTransactions = function(Param) {
|
||||||
var Ret = global.SERVER.ReWriteDAppTransactions(Param.BlockCount);
|
var Ret = global.SERVER.ReWriteDAppTransactions(Param.BlockCount);
|
||||||
return { result: Ret, sessionid: sessionid };
|
return { result: Ret, sessionid: sessionid };
|
||||||
};
|
};
|
||||||
HTTPCaller.TruncateBlockChain = function(Param) {
|
global.HTTPCaller.TruncateBlockChain = function(Param) {
|
||||||
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
||||||
var MinBlock = global.DApps.Accounts.GetMinBlockAct();
|
var MinBlock = global.DApps.Accounts.GetMinBlockAct();
|
||||||
if (MinBlock > StartNum) {
|
if (MinBlock > StartNum) {
|
||||||
@ -1035,12 +1067,12 @@ HTTPCaller.TruncateBlockChain = function(Param) {
|
|||||||
global.SERVER.TruncateBlockDB(StartNum);
|
global.SERVER.TruncateBlockDB(StartNum);
|
||||||
return { result: 1, sessionid: sessionid };
|
return { result: 1, sessionid: sessionid };
|
||||||
};
|
};
|
||||||
HTTPCaller.ClearDataBase = function(Param) {
|
global.HTTPCaller.ClearDataBase = function(Param) {
|
||||||
BlockTree.Clear();
|
BlockTree.Clear();
|
||||||
global.SERVER.ClearDataBase();
|
global.SERVER.ClearDataBase();
|
||||||
return { result: 1, sessionid: sessionid };
|
return { result: 1, sessionid: sessionid };
|
||||||
};
|
};
|
||||||
HTTPCaller.CleanChain = function(Param) {
|
global.HTTPCaller.CleanChain = function(Param) {
|
||||||
if (global.CleanChain) {
|
if (global.CleanChain) {
|
||||||
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
var StartNum = global.SERVER.BlockNumDB - Param.BlockCount;
|
||||||
global.CleanChain(StartNum);
|
global.CleanChain(StartNum);
|
||||||
@ -1048,7 +1080,7 @@ HTTPCaller.CleanChain = function(Param) {
|
|||||||
}
|
}
|
||||||
return { result: 0, sessionid: sessionid };
|
return { result: 0, sessionid: sessionid };
|
||||||
};
|
};
|
||||||
HTTPCaller.GetArrStats = function(Keys, response) {
|
global.HTTPCaller.GetArrStats = function(Keys, response) {
|
||||||
var arr = global.GET_STATDIAGRAMS(Keys);
|
var arr = global.GET_STATDIAGRAMS(Keys);
|
||||||
let Result: any = { result: 1, sessionid: sessionid, arr: arr, STAT_MODE: global.STAT_MODE };
|
let Result: any = { result: 1, sessionid: sessionid, arr: arr, STAT_MODE: global.STAT_MODE };
|
||||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
||||||
@ -1073,7 +1105,7 @@ HTTPCaller.GetArrStats = function(Keys, response) {
|
|||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetBlockChain = function(type) {
|
global.HTTPCaller.GetBlockChain = function(type) {
|
||||||
if (!global.SERVER || !global.SERVER.LoadedChainList) {
|
if (!global.SERVER || !global.SERVER.LoadedChainList) {
|
||||||
return { result: 0 };
|
return { result: 0 };
|
||||||
}
|
}
|
||||||
@ -1110,14 +1142,14 @@ HTTPCaller.GetBlockChain = function(type) {
|
|||||||
IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr), LoadedChainCount: global.SERVER.LoadedChainList.length, StartLoadBlockTime: global.SERVER.StartLoadBlockTime,
|
IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr), LoadedChainCount: global.SERVER.LoadedChainList.length, StartLoadBlockTime: global.SERVER.StartLoadBlockTime,
|
||||||
sessionid: sessionid, result: 1
|
sessionid: sessionid, result: 1
|
||||||
};
|
};
|
||||||
var obj2: any = HTTPCaller.GetHotArray();
|
var obj2: any = global.HTTPCaller.GetHotArray();
|
||||||
obj.ArrTree = obj2.ArrTree;
|
obj.ArrTree = obj2.ArrTree;
|
||||||
arrBlocks = [];
|
arrBlocks = [];
|
||||||
arrLoadedChainList = [];
|
arrLoadedChainList = [];
|
||||||
arrLoadedBlocks = [];
|
arrLoadedBlocks = [];
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetHistoryTransactions = function(Params) {
|
global.HTTPCaller.GetHistoryTransactions = function(Params) {
|
||||||
if (typeof Params === "object" && Params.AccountID) {
|
if (typeof Params === "object" && Params.AccountID) {
|
||||||
var Account = global.DApps.Accounts.ReadState(Params.AccountID);
|
var Account = global.DApps.Accounts.ReadState(Params.AccountID);
|
||||||
if (!Account)
|
if (!Account)
|
||||||
@ -1140,35 +1172,43 @@ HTTPCaller.GetHistoryTransactions = function(Params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var Result: any = {
|
var Result: any = {
|
||||||
Value: { SumCOIN: Account.Value.SumCOIN, SumCENT: Account.Value.SumCENT }, Name: Account.Name, Currency: Account.Currency,
|
Value: {
|
||||||
MaxBlockNum: global.GetCurrentBlockNumByTime(), FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK, result: arr.length > 0 ? 1 : 0, History: arr
|
SumCOIN: Account.Value.SumCOIN,
|
||||||
|
SumCENT: Account.Value.SumCENT
|
||||||
|
},
|
||||||
|
Name: Account.Name,
|
||||||
|
Currency: Account.Currency,
|
||||||
|
MaxBlockNum: global.GetCurrentBlockNumByTime(),
|
||||||
|
FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK,
|
||||||
|
result: arr.length > 0 ? 1 : 0,
|
||||||
|
History: arr
|
||||||
};
|
};
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
return { result: 0 };
|
return { result: 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
// function GetCopyBlock(Block) {
|
function GetCopyBlock(Block) {
|
||||||
// var Result: any = {
|
var Result: any = {
|
||||||
// BlockNum: Block.BlockNum, bSave: Block.bSave, TreeHash: global.GetHexFromAddres(Block.TreeHash), AddrHash: global.GetHexFromAddres(Block.AddrHash),
|
BlockNum: Block.BlockNum, bSave: Block.bSave, TreeHash: global.GetHexFromAddres(Block.TreeHash), AddrHash: global.GetHexFromAddres(Block.AddrHash),
|
||||||
// PrevHash: global.GetHexFromAddres(Block.PrevHash), SumHash: global.GetHexFromAddres(Block.SumHash), SumPow: Block.SumPow, TrDataPos: Block.TrDataPos,
|
PrevHash: global.GetHexFromAddres(Block.PrevHash), SumHash: global.GetHexFromAddres(Block.SumHash), SumPow: Block.SumPow, TrDataPos: Block.TrDataPos,
|
||||||
// TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
|
TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
|
||||||
// TrCount: Block.TrCount, arrContent: Block.arrContent,
|
TrCount: Block.TrCount, arrContent: Block.arrContent,
|
||||||
// };
|
};
|
||||||
// return Result;
|
return Result;
|
||||||
// };
|
};
|
||||||
var AddrLength = 16;
|
var AddrLength = 16;
|
||||||
|
|
||||||
function GetHexFromAddresShort(Hash) {
|
function GetHexFromAddresShort(Hash) {
|
||||||
return global.GetHexFromAddres(Hash).substr(0, AddrLength);
|
return global.GetHexFromAddres(Hash).substr(0, AddrLength);
|
||||||
};
|
};
|
||||||
|
|
||||||
// function GetHexFromStrShort(Str) {
|
function GetHexFromStrShort(Str) {
|
||||||
// if (Str === undefined)
|
if (Str === undefined)
|
||||||
// return Str;
|
return Str;
|
||||||
// else
|
else
|
||||||
// return Str.substr(0, AddrLength);
|
return Str.substr(0, AddrLength);
|
||||||
// };
|
};
|
||||||
var glid = 0;
|
var glid = 0;
|
||||||
|
|
||||||
function GetGUID(Block) {
|
function GetGUID(Block) {
|
||||||
@ -1201,12 +1241,34 @@ function CopyBlockDraw(Block, MainChains) {
|
|||||||
Mining = 0;
|
Mining = 0;
|
||||||
GetGUID(Block);
|
GetGUID(Block);
|
||||||
Item = {
|
Item = {
|
||||||
guid: Block.guid, Active: Block.Active, bSave: Block.bSave, Prepared: Block.Prepared, BlockNum: Block.BlockNum, Hash: GetHexFromAddresShort(Block.Hash),
|
guid: Block.guid,
|
||||||
SumHash: GetHexFromAddresShort(Block.SumHash), SeqHash: GetHexFromAddresShort(Block.SeqHash), TreeHash: GetHexFromAddresShort(Block.TreeHash),
|
Active: Block.Active,
|
||||||
AddrHash: GetHexFromAddresShort(Block.AddrHash), MinerID: MinerID, MinerName: MinerName, Comment1: Block.Comment1, Comment2: Block.Comment2,
|
bSave: Block.bSave,
|
||||||
SumPow: Block.SumPow, Info: Block.Info, TreeLoaded: Block.TreeEq, AddToLoad: Block.AddToLoad, LoadDB: Block.LoadDB, FindBlockDB: Block.FindBlockDB,
|
Prepared: Block.Prepared,
|
||||||
TrCount: Block.TrCount, ArrLength: 0, TrDataLen: Block.TrDataLen, Power: global.GetPowPower(Block.PowHash), CheckPoint: CheckPoint, Mining: Mining,
|
BlockNum: Block.BlockNum,
|
||||||
TransferSize: Block.TransferSize, HasErr: Block.HasErr,
|
Hash: GetHexFromAddresShort(Block.Hash),
|
||||||
|
SumHash: GetHexFromAddresShort(Block.SumHash),
|
||||||
|
SeqHash: GetHexFromAddresShort(Block.SeqHash),
|
||||||
|
TreeHash: GetHexFromAddresShort(Block.TreeHash),
|
||||||
|
AddrHash: GetHexFromAddresShort(Block.AddrHash),
|
||||||
|
MinerID: MinerID,
|
||||||
|
MinerName: MinerName,
|
||||||
|
Comment1: Block.Comment1,
|
||||||
|
Comment2: Block.Comment2,
|
||||||
|
SumPow: Block.SumPow,
|
||||||
|
Info: Block.Info,
|
||||||
|
TreeLoaded: Block.TreeEq,
|
||||||
|
AddToLoad: Block.AddToLoad,
|
||||||
|
LoadDB: Block.LoadDB,
|
||||||
|
FindBlockDB: Block.FindBlockDB,
|
||||||
|
TrCount: Block.TrCount,
|
||||||
|
ArrLength: 0,
|
||||||
|
TrDataLen: Block.TrDataLen,
|
||||||
|
Power: global.GetPowPower(Block.PowHash),
|
||||||
|
CheckPoint: CheckPoint,
|
||||||
|
Mining: Mining,
|
||||||
|
TransferSize: Block.TransferSize,
|
||||||
|
HasErr: Block.HasErr,
|
||||||
};
|
};
|
||||||
if (Block.chain)
|
if (Block.chain)
|
||||||
Item.chainid = Block.chain.id;
|
Item.chainid = Block.chain.id;
|
||||||
@ -1278,7 +1340,7 @@ function AddMapList(arrLoadedBlocks, type, MapMapLoaded, MainChains?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// var MapFileHTML5 = {};
|
var MapFileHTML5 = {};
|
||||||
|
|
||||||
function SendWebFile(response, name?, StrCookie?, bParsing?) {
|
function SendWebFile(response, name?, StrCookie?, bParsing?) {
|
||||||
var type = name.substr(name.length - 4, 4);
|
var type = name.substr(name.length - 4, 4);
|
||||||
@ -1416,28 +1478,28 @@ global.GetFileHTMLFromMarkdown = GetFileHTMLFromMarkdown;
|
|||||||
global.GetFileSimple = GetFileSimple;
|
global.GetFileSimple = GetFileSimple;
|
||||||
global.SaveFileSimple = SaveFileSimple;
|
global.SaveFileSimple = SaveFileSimple;
|
||||||
|
|
||||||
// function GetStrTime(now) {
|
function GetStrTime(now) {
|
||||||
// if (!now)
|
if (!now)
|
||||||
// now = global.GetCurrentTime(0);
|
now = global.GetCurrentTime(0);
|
||||||
// var Str = "" + now.getHours().toStringZ(2);
|
var Str = "" + now.getHours().toStringZ(2);
|
||||||
// Str = Str + ":" + now.getMinutes().toStringZ(2);
|
Str = Str + ":" + now.getMinutes().toStringZ(2);
|
||||||
// Str = Str + ":" + now.getSeconds().toStringZ(2);
|
Str = Str + ":" + now.getSeconds().toStringZ(2);
|
||||||
// return Str;
|
return Str;
|
||||||
// };
|
};
|
||||||
|
|
||||||
function OnGetData(arg) {
|
function OnGetData(arg) {
|
||||||
// var response = {
|
var response = {
|
||||||
// end: function() {
|
end: function() {
|
||||||
// }, writeHead: function() {
|
}, writeHead: function() {
|
||||||
// },
|
},
|
||||||
// };
|
};
|
||||||
var Path = arg.path;
|
var Path = arg.path;
|
||||||
var obj = arg.obj;
|
var obj = arg.obj;
|
||||||
if (Path.substr(0, 1) === "/")
|
if (Path.substr(0, 1) === "/")
|
||||||
Path = Path.substr(1);
|
Path = Path.substr(1);
|
||||||
var params = Path.split('/', 5);
|
var params = Path.split('/', 5);
|
||||||
var Ret;
|
var Ret;
|
||||||
var F = HTTPCaller[params[0]];
|
var F = global.HTTPCaller[params[0]];
|
||||||
if (F) {
|
if (F) {
|
||||||
if (obj)
|
if (obj)
|
||||||
Ret = F(obj);
|
Ret = F(obj);
|
||||||
@ -1677,7 +1739,7 @@ function GetEventArray(SmartNum, Context) {
|
|||||||
}
|
}
|
||||||
return ArrRet;
|
return ArrRet;
|
||||||
};
|
};
|
||||||
HTTPCaller.GetHashRate = function(ArrParams) {
|
global.HTTPCaller.GetHashRate = function(ArrParams) {
|
||||||
var CurBlockNum = global.GetCurrentBlockNumByTime();
|
var CurBlockNum = global.GetCurrentBlockNumByTime();
|
||||||
var ResArr = [];
|
var ResArr = [];
|
||||||
for (var i = 0; i < ArrParams.length; i++) {
|
for (var i = 0; i < ArrParams.length; i++) {
|
||||||
@ -1703,6 +1765,9 @@ HTTPCaller.GetHashRate = function(ArrParams) {
|
|||||||
var CountAvg = 10;
|
var CountAvg = 10;
|
||||||
if (i === ArrParams.length - 1)
|
if (i === ArrParams.length - 1)
|
||||||
CountAvg = 3;
|
CountAvg = 3;
|
||||||
|
var StepDeltaAvg = Math.floor(StepDelta / CountAvg);
|
||||||
|
if (StepDeltaAvg < 1)
|
||||||
|
StepDeltaAvg = 1;
|
||||||
var ItervalArr = [];
|
var ItervalArr = [];
|
||||||
for (var Num = Item.BlockNum1; Num < Item.BlockNum2; Num += StepDelta) {
|
for (var Num = Item.BlockNum1; Num < Item.BlockNum2; Num += StepDelta) {
|
||||||
var Power;
|
var Power;
|
||||||
|
@ -16,6 +16,16 @@ import * as stun from 'stun'
|
|||||||
import * as zip from 'zip'
|
import * as zip from 'zip'
|
||||||
|
|
||||||
import './constant'
|
import './constant'
|
||||||
|
if (global.USE_PARAM_JS) {
|
||||||
|
var PathParams = global.GetCodePath("../extern-run.js");
|
||||||
|
if (fs.existsSync(PathParams))
|
||||||
|
try {
|
||||||
|
require(PathParams);
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
import './log'
|
import './log'
|
||||||
|
|
||||||
Number.prototype.toStringZ = function(count) {
|
Number.prototype.toStringZ = function(count) {
|
||||||
@ -58,6 +68,8 @@ if (global.USE_PARAM_JS) {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
require('../HTML/JS/terahashlib.js');
|
||||||
|
require("./crypto-library");
|
||||||
global.BufLib = require("../core/buffer");
|
global.BufLib = require("../core/buffer");
|
||||||
require('../HTML/JS/sha3.js');
|
require('../HTML/JS/sha3.js');
|
||||||
require('../HTML/JS/coinlib.js');
|
require('../HTML/JS/coinlib.js');
|
||||||
@ -93,7 +105,7 @@ global.SliceArr = function(arr, start, end) {
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
// var nRand = Math.floor(123 + Math.random() * 1000);
|
var nRand = Math.floor(123 + Math.random() * 1000);
|
||||||
|
|
||||||
function random(max) {
|
function random(max) {
|
||||||
return Math.floor(Math.random() * max);
|
return Math.floor(Math.random() * max);
|
||||||
@ -142,8 +154,7 @@ global.LoadParams = function(filename, DefaultValue) {
|
|||||||
if (Str.length > 0)
|
if (Str.length > 0)
|
||||||
return JSON.parse(Str as any);
|
return JSON.parse(Str as any);
|
||||||
}
|
}
|
||||||
}
|
} catch (err) {
|
||||||
catch (err) {
|
|
||||||
global.TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
|
global.TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
|
||||||
}
|
}
|
||||||
return DefaultValue;
|
return DefaultValue;
|
||||||
@ -265,7 +276,7 @@ global.SAVE_CONST = function(bForce) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function CheckGlobalTime() {
|
function CheckGlobalTime() {
|
||||||
global.ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, NetTime) {
|
global.ntpClient.getNetworkTime("ntp1.aliyun.com", 123, function(err, NetTime) {
|
||||||
if (err) {
|
if (err) {
|
||||||
global.TO_ERROR_LOG("MAINLIB", 110, err);
|
global.TO_ERROR_LOG("MAINLIB", 110, err);
|
||||||
return;
|
return;
|
||||||
@ -372,7 +383,7 @@ function GetCountMiningCPU() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
global.GetCountMiningCPU = GetCountMiningCPU;
|
global.GetCountMiningCPU = GetCountMiningCPU;
|
||||||
var AddTrMap = [];
|
var AddTrMap: any = {};
|
||||||
AddTrMap[- 6] = "Inner node error";
|
AddTrMap[- 6] = "Inner node error";
|
||||||
AddTrMap[- 5] = "Bad block num";
|
AddTrMap[- 5] = "Bad block num";
|
||||||
AddTrMap[- 4] = "Bad type transaction";
|
AddTrMap[- 4] = "Bad type transaction";
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
* Twitter: https://twitter.com/terafoundation
|
* Twitter: https://twitter.com/terafoundation
|
||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
|
||||||
function CheckSizeLogFile(file_name, file_name_prev) {
|
function CheckSizeLogFile(file_name, file_name_prev) {
|
||||||
|
@ -341,8 +341,7 @@ export default class CNode {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var Buf = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_CLIENT, {});
|
var Buf = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_CLIENT, {});
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
global.SERVER.SendCloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
global.SERVER.SendCloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ export default class CRest extends CDB {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (MaxCount < 2 || MaxPow === 0) {
|
if (MaxCount < 2 || MaxPow === 0) {
|
||||||
global.ToLog("****************************************************************** Error MaxPow - reload.")
|
global.ToLog("****************************************************************** Error MaxPow=" + MaxPow + " - reload.")
|
||||||
this.CheckSyncRest()
|
this.CheckSyncRest()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9,59 +9,91 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
function DoRest(r, t, e) {
|
function DoRest(RestData, Data, BlockNum) {
|
||||||
var u = r.Arr[0], o = Math.floor(e / global.REST_BLOCK_SCALE);
|
var Prev = RestData.Arr[0];
|
||||||
if (o !== Math.floor((u.BlockNum - 1) / global.REST_BLOCK_SCALE)) {
|
var BlockNum0 = Math.floor(BlockNum / global.REST_BLOCK_SCALE);
|
||||||
for (var n = GetRestArr(o), l = [], a = n.length - 2; 0 <= a; a--)
|
if (BlockNum0 !== Math.floor((Prev.BlockNum - 1) / global.REST_BLOCK_SCALE)) {
|
||||||
l.push(n[a] * global.REST_BLOCK_SCALE);
|
var arr = GetRestArr(BlockNum0);
|
||||||
RestPush(r, l, e, 1);
|
var arr2 = [];
|
||||||
|
for (var i = arr.length - 2; i >= 0; i--) {
|
||||||
|
arr2.push(arr[i] * global.REST_BLOCK_SCALE);
|
||||||
|
}
|
||||||
|
RestPush(RestData, arr2, BlockNum, 1);
|
||||||
}
|
}
|
||||||
r.Arr[0] = { BlockNum: e, Value: t.Value };
|
RestData.Arr[0] = { BlockNum: BlockNum, Value: Data.Value };
|
||||||
};
|
};
|
||||||
|
|
||||||
function RestPush(r, t, e, u) {
|
function RestPush(RestData, ArrRest, BlockNum, Index) {
|
||||||
var o = r.Arr[u - 1], n = r.Arr[u];
|
var Prev = RestData.Arr[Index - 1];
|
||||||
if (1 < u) {
|
var Cur = RestData.Arr[Index];
|
||||||
var l = t[u - 2];
|
if (Index > 1) {
|
||||||
if (o.BlockNum > l)
|
var RestNum = ArrRest[Index - 2];
|
||||||
|
if (Prev.BlockNum > RestNum)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (n.BlockNum && n.BlockNum >= e || o.BlockNum >= e)
|
if ((Cur.BlockNum && Cur.BlockNum >= BlockNum) || Prev.BlockNum >= BlockNum) {
|
||||||
return n.BlockNum = 0, void (n.Value = {});
|
Cur.BlockNum = 0;
|
||||||
n.BlockNum && u < r.Arr.length - 1 && RestPush(r, t, e, u + 1), r.Arr[u] = o;
|
Cur.Value = {};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Cur.BlockNum) {
|
||||||
|
if (Index < RestData.Arr.length - 1) {
|
||||||
|
RestPush(RestData, ArrRest, BlockNum, Index + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
RestData.Arr[Index] = Prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
function GetRestArr(r) {
|
function GetRestArr(CurBlockNum) {
|
||||||
for (var t = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], e = t.length, u = 0; u <= r; u++)
|
var Arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||||
for (var o = 0, n = u, l = e - 1; 0 <= l; l--) {
|
var ArrLength = Arr.length;
|
||||||
var a = t[l];
|
var StartNum = 0;
|
||||||
if (t[l] = n, n = a, 0 == ((o = o << 4 | 15) & u))
|
for (var num = StartNum; num <= CurBlockNum; num++) {
|
||||||
|
var maska = 0;
|
||||||
|
var CurNum = num;
|
||||||
|
for (var i = ArrLength - 1; i >= 0; i--) {
|
||||||
|
var PosNum = Arr[i];
|
||||||
|
Arr[i] = CurNum;
|
||||||
|
CurNum = PosNum;
|
||||||
|
maska = (maska << 4) | 15;
|
||||||
|
if ((maska & num) === 0)
|
||||||
break;
|
break;
|
||||||
if (0 != (o & n))
|
if ((maska & CurNum) !== 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return t;
|
}
|
||||||
|
return Arr;
|
||||||
};
|
};
|
||||||
var RestArrMap = {};
|
var RestArrMap = {};
|
||||||
|
|
||||||
function GetCurrentRestArr() {
|
function GetCurrentRestArr() {
|
||||||
var r = global.GetCurrentBlockNumByTime(), t = Math.floor(r / global.REST_BLOCK_SCALE), e = RestArrMap[t];
|
var BlockNum = global.GetCurrentBlockNumByTime();
|
||||||
if (void 0 === e) {
|
var BlockNum0 = Math.floor(BlockNum / global.REST_BLOCK_SCALE);
|
||||||
RestArrMap = {}, (e = GetRestArr(t)).length = e.length - 1;
|
var arr = RestArrMap[BlockNum0];
|
||||||
for (var u = 0; u < e.length; u++)
|
if (arr === undefined) {
|
||||||
e[u] = e[u] * global.REST_BLOCK_SCALE;
|
RestArrMap = {};
|
||||||
RestArrMap[t] = e;
|
arr = GetRestArr(BlockNum0);
|
||||||
|
arr.length = arr.length - 1;
|
||||||
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
arr[i] = arr[i] * global.REST_BLOCK_SCALE;
|
||||||
|
}
|
||||||
|
RestArrMap[BlockNum0] = arr;
|
||||||
}
|
}
|
||||||
return e;
|
return arr;
|
||||||
};
|
};
|
||||||
|
|
||||||
function GetCurrentRestNum(r) {
|
function GetCurrentRestNum(NumDelta) {
|
||||||
for (var t = global.GetCurrentBlockNumByTime() - r, e = GetCurrentRestArr(), u = e.length - 1; 0 <= u; u--)
|
var BlockNum = global.GetCurrentBlockNumByTime();
|
||||||
if (e[u] <= t)
|
var BlockNumMin = BlockNum - NumDelta;
|
||||||
return e[u];
|
var arr = GetCurrentRestArr();
|
||||||
|
for (var i = arr.length - 1; i >= 0; i--) {
|
||||||
|
if (arr[i] <= BlockNumMin) {
|
||||||
|
return arr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
global.DoRest = DoRest
|
global.DoRest = DoRest;
|
||||||
global.GetRestArr = GetRestArr
|
global.GetRestArr = GetRestArr;
|
||||||
global.GetCurrentRestArr = GetCurrentRestArr
|
global.GetCurrentRestArr = GetCurrentRestArr;
|
||||||
global.GetCurrentRestNum = GetCurrentRestNum;
|
global.GetCurrentRestNum = GetCurrentRestNum;
|
||||||
|
@ -32,7 +32,7 @@ const BUF_PACKET_SIZE = 32 * 1024;
|
|||||||
global.FORMAT_POW_TO_CLIENT = "{addrArr:hash,HashRND:hash,MIN_POWER_POW_HANDSHAKE:uint,PubKeyType:byte,Sign:arr64,Reserve:arr33}";
|
global.FORMAT_POW_TO_CLIENT = "{addrArr:hash,HashRND:hash,MIN_POWER_POW_HANDSHAKE:uint,PubKeyType:byte,Sign:arr64,Reserve:arr33}";
|
||||||
global.FORMAT_POW_TO_SERVER = "{\
|
global.FORMAT_POW_TO_SERVER = "{\
|
||||||
DEF_NETWORK:str15,\
|
DEF_NETWORK:str15,\
|
||||||
global.DEF_VERSION:str9,\
|
DEF_VERSION:str9,\
|
||||||
DEF_CLIENT:str16, \
|
DEF_CLIENT:str16, \
|
||||||
addrArr:addres, \
|
addrArr:addres, \
|
||||||
ToIP:str26,\
|
ToIP:str26,\
|
||||||
@ -366,13 +366,11 @@ export default class CTransport extends CConnect {
|
|||||||
else
|
else
|
||||||
if (TypeData === global.STR_TYPE) {
|
if (TypeData === global.STR_TYPE) {
|
||||||
BufData = Buffer.from(Data.substr(0, global.MAX_STR_BUF_DATA))
|
BufData = Buffer.from(Data.substr(0, global.MAX_STR_BUF_DATA))
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (Data === undefined) {
|
if (Data === undefined) {
|
||||||
TypeData = global.BUF_TYPE
|
TypeData = global.BUF_TYPE
|
||||||
BufData = Buffer.alloc(0)
|
BufData = Buffer.alloc(0)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw "ERROR TYPE DATA";
|
throw "ERROR TYPE DATA";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -394,8 +392,7 @@ export default class CTransport extends CConnect {
|
|||||||
GetDataFromBuf(buf) {
|
GetDataFromBuf(buf) {
|
||||||
try {
|
try {
|
||||||
var Meta = global.BufLib.GetObjectFromBuffer(buf, FORMAT_PACKET_SEND_TCP, WorkStructPacketSend);
|
var Meta = global.BufLib.GetObjectFromBuffer(buf, FORMAT_PACKET_SEND_TCP, WorkStructPacketSend);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
global.TO_ERROR_LOG("TRANSPORT", 640, "Error parsing Buffer")
|
global.TO_ERROR_LOG("TRANSPORT", 640, "Error parsing Buffer")
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
@ -420,8 +417,7 @@ export default class CTransport extends CConnect {
|
|||||||
Node.Socket = Socket
|
Node.Socket = Socket
|
||||||
if (!Socket.Buf || Socket.Buf.length === 0) {
|
if (!Socket.Buf || Socket.Buf.length === 0) {
|
||||||
Socket.Buf = Buf
|
Socket.Buf = Buf
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Socket.Buf = Buffer.concat([Socket.Buf, Buf])
|
Socket.Buf = Buffer.concat([Socket.Buf, Buf])
|
||||||
}
|
}
|
||||||
if (!Socket.SocketNum) {
|
if (!Socket.SocketNum) {
|
||||||
|
@ -8,39 +8,63 @@
|
|||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as fs from 'fs'
|
var fs = require("fs");
|
||||||
|
global.GetDataPath = function GetDataPath(name) {
|
||||||
function CopyFiles(l, o, t) {
|
if (global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) !== "/")
|
||||||
if (fs.existsSync(l))
|
global.DATA_PATH = global.DATA_PATH + "/";
|
||||||
for (var e = fs.readdirSync(l), n = 0; n < e.length; n++) {
|
return global.GetNormalPathString(global.DATA_PATH + name);
|
||||||
var a = l + "/" + e[n], s = o + "/" + e[n];
|
};
|
||||||
if (fs.statSync(a).isDirectory())
|
global.GetCodePath = function GetCodePath(name) {
|
||||||
t && (fs.existsSync(s) || fs.mkdirSync(s), CopyFiles(a, s, t));
|
if (global.CODE_PATH.substr(global.CODE_PATH.length - 1, 1) !== "/")
|
||||||
else {
|
global.CODE_PATH = global.CODE_PATH + "/";
|
||||||
var r = fs.readFileSync(a), i = fs.openSync(s, "w");
|
return global.GetNormalPathString(global.CODE_PATH + name);
|
||||||
fs.writeSync(i, r, 0, r.length), fs.closeSync(i);
|
};
|
||||||
|
global.GetNormalPathString = function(Str) {
|
||||||
|
return Str.split("\\").join('/');
|
||||||
|
};
|
||||||
|
global.CheckCreateDir = function(Path, bHidden, IsFile) {
|
||||||
|
Path = global.GetNormalPathString(Path);
|
||||||
|
if (!fs.existsSync(Path)) {
|
||||||
|
if (!bHidden)
|
||||||
|
console.log("Create: " + Path);
|
||||||
|
var arr = Path.split('/');
|
||||||
|
var CurPath = arr[0];
|
||||||
|
if (IsFile) {
|
||||||
|
arr.length--;
|
||||||
|
}
|
||||||
|
for (var i = 1; i < arr.length; i++) {
|
||||||
|
CurPath += "/" + arr[i];
|
||||||
|
if (!fs.existsSync(CurPath)) {
|
||||||
|
fs.mkdirSync(CurPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
global.GetDataPath = function(l) {
|
|
||||||
return "/" !== global.DATA_PATH.substr(global.DATA_PATH.length - 1, 1) && (global.DATA_PATH = global.DATA_PATH + "/"), global.GetNormalPathString(global.DATA_PATH + l);
|
|
||||||
}
|
|
||||||
global.GetCodePath = function(l) {
|
|
||||||
return "/" !== global.CODE_PATH.substr(global.CODE_PATH.length - 1, 1) && (global.CODE_PATH = global.CODE_PATH + "/"), global.GetNormalPathString(global.CODE_PATH + l);
|
|
||||||
}
|
|
||||||
global.GetNormalPathString = function(l: string) {
|
|
||||||
return l.split("\\").join("/");
|
|
||||||
}
|
|
||||||
global.CheckCreateDir = function(l, o, t) {
|
|
||||||
if (l = global.GetNormalPathString(l), !fs.existsSync(l)) {
|
|
||||||
o || console.log("Create: " + l);
|
|
||||||
var e = l.split("/"), n = e[0];
|
|
||||||
t && e.length--;
|
|
||||||
for (var a = 1; a < e.length; a++)
|
|
||||||
n += "/" + e[a], fs.existsSync(n) || fs.mkdirSync(n);
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
global.CopyFiles = CopyFiles
|
global.CopyFiles = CopyFiles;
|
||||||
global.ToLog || (global.ToLog = function(l) {
|
|
||||||
console.log(l);
|
function CopyFiles(FromPath, ToPath, bRecursive) {
|
||||||
});
|
if (fs.existsSync(FromPath)) {
|
||||||
|
var arr = fs.readdirSync(FromPath);
|
||||||
|
for (var i = 0; i < arr.length; i++) {
|
||||||
|
var name1 = FromPath + "/" + arr[i];
|
||||||
|
var name2 = ToPath + "/" + arr[i];
|
||||||
|
if (fs.statSync(name1).isDirectory()) {
|
||||||
|
if (bRecursive) {
|
||||||
|
if (!fs.existsSync(name2))
|
||||||
|
fs.mkdirSync(name2);
|
||||||
|
CopyFiles(name1, name2, bRecursive);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var data = fs.readFileSync(name1);
|
||||||
|
var file_handle = fs.openSync(name2, "w");
|
||||||
|
fs.writeSync(file_handle, data, 0, data.length);
|
||||||
|
fs.closeSync(file_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (!global.ToLog)
|
||||||
|
global.ToLog = function(Str) {
|
||||||
|
console.log(Str);
|
||||||
|
};
|
||||||
|
@ -157,8 +157,7 @@ function CreatePOWVersion3(Block, bHashPump) {
|
|||||||
Block.Hash = MaxLider.Hash2;
|
Block.Hash = MaxLider.Hash2;
|
||||||
if (global.CompareArr(MaxLider.Hash1, MaxLider.Hash2) > 0) {
|
if (global.CompareArr(MaxLider.Hash1, MaxLider.Hash2) > 0) {
|
||||||
Block.PowHash = MaxLider.Hash1;
|
Block.PowHash = MaxLider.Hash1;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Block.PowHash = MaxLider.Hash2;
|
Block.PowHash = MaxLider.Hash2;
|
||||||
}
|
}
|
||||||
if (BlockNum >= global.BLOCKNUM_TICKET_ALGO)
|
if (BlockNum >= global.BLOCKNUM_TICKET_ALGO)
|
||||||
|
@ -9,17 +9,17 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import CConsensus from './block-exchange'
|
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
import { RBTree } from './library';
|
import { RBTree } from './library';
|
||||||
require("../system/dapp");
|
import "../system/dapp"
|
||||||
require("../system/accounts");
|
import "../system/accounts"
|
||||||
require("../system/smart");
|
import "../system/smart"
|
||||||
require("../system/file");
|
import "../system/file"
|
||||||
require("../system/messager");
|
import "../system/messager"
|
||||||
require("../system/names");
|
import "../system/names"
|
||||||
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX")
|
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX")
|
||||||
require("./wallet");
|
require("./wallet");
|
||||||
|
import CConsensus from './block-exchange'
|
||||||
export default class CSmartContract extends CConsensus {
|
export default class CSmartContract extends CConsensus {
|
||||||
BufHashTree
|
BufHashTree
|
||||||
SenderBlockHashMap
|
SenderBlockHashMap
|
||||||
@ -29,8 +29,8 @@ export default class CSmartContract extends CConsensus {
|
|||||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||||
this.BufHashTree = new RBTree(global.CompareArr)
|
this.BufHashTree = new RBTree(global.CompareArr)
|
||||||
this.BufHashTree.LastAddNum = 0
|
this.BufHashTree.LastAddNum = 0
|
||||||
this.SenderBlockHashMap = {}
|
|
||||||
this.SenderMap = {}
|
this.SenderMap = {}
|
||||||
|
this.SenderBlockHashMap = {}
|
||||||
if (!global.ADDRLIST_MODE && !this.VirtualMode && global.START_SERVER) {
|
if (!global.ADDRLIST_MODE && !this.VirtualMode && global.START_SERVER) {
|
||||||
setInterval(this.ClearOldSenderMapItem.bind(this), 10000)
|
setInterval(this.ClearOldSenderMapItem.bind(this), 10000)
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ export default class CSmartContract extends CConsensus {
|
|||||||
var arr = Block.arrContent;
|
var arr = Block.arrContent;
|
||||||
if (arr) {
|
if (arr) {
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
var HASH = global.shaarr(arr[i]);
|
var HASH = global.sha3(arr[i]);
|
||||||
this.BufHashTree.insert(HASH)
|
this.BufHashTree.insert(HASH)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ export default class CSmartContract extends CConsensus {
|
|||||||
var arr = Block.arrContent;
|
var arr = Block.arrContent;
|
||||||
if (arr) {
|
if (arr) {
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
var HASH = global.shaarr(arr[i]);
|
var HASH = global.sha3(arr[i]);
|
||||||
this.BufHashTree.remove(HASH)
|
this.BufHashTree.remove(HASH)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,6 +233,8 @@ export default class CSmartContract extends CConsensus {
|
|||||||
// transfer-msg.ts(CMessages)
|
// transfer-msg.ts(CMessages)
|
||||||
}
|
}
|
||||||
AddToSenderMap(Block) {
|
AddToSenderMap(Block) {
|
||||||
|
if (!global.START_SERVER)
|
||||||
|
return;
|
||||||
var BlockNum = Block.BlockNum;
|
var BlockNum = Block.BlockNum;
|
||||||
var StrBlockHash = global.GetHexFromArr(Block.Hash);
|
var StrBlockHash = global.GetHexFromArr(Block.Hash);
|
||||||
this.SenderBlockHashMap[BlockNum] = StrBlockHash
|
this.SenderBlockHashMap[BlockNum] = StrBlockHash
|
||||||
@ -295,7 +297,9 @@ export default class CSmartContract extends CConsensus {
|
|||||||
this.WasReloadSenderMapFromDB = 1
|
this.WasReloadSenderMapFromDB = 1
|
||||||
}
|
}
|
||||||
ClearOldSenderMapItem() {
|
ClearOldSenderMapItem() {
|
||||||
var MinBlockNum = global.GetCurrentBlockNumByTime() - global.MAX_LENGTH_SENDER_MAP * 2;
|
if (!global.START_SERVER)
|
||||||
|
return;
|
||||||
|
var MinBlockNum = global.GetCurrentBlockNumByTime() - (global.MAX_LENGTH_SENDER_MAP + global.COUNT_BLOCKS_FOR_LOAD);
|
||||||
var ArrForDel = [];
|
var ArrForDel = [];
|
||||||
for (var key in this.SenderMap) {
|
for (var key in this.SenderMap) {
|
||||||
var ItemArr = this.SenderMap[key];
|
var ItemArr = this.SenderMap[key];
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import CSmartContract from './transaction-validator'
|
|
||||||
import { RBTree } from './library';
|
import { RBTree } from './library';
|
||||||
const MAX_MESSAGE_COUNT = 1000;
|
const MAX_MESSAGE_COUNT = 1000;
|
||||||
|
import CSmartContract from './transaction-validator'
|
||||||
export default class CMessages extends CSmartContract {
|
export default class CMessages extends CSmartContract {
|
||||||
MemPoolMsg
|
MemPoolMsg
|
||||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||||
|
@ -147,7 +147,6 @@ function RecreateAccountHashDB3() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
import '../core/db/db-row'
|
import '../core/db/db-row'
|
||||||
|
|
||||||
function ReWriteDBSmartWrite() {
|
function ReWriteDBSmartWrite() {
|
||||||
global.UpdateMode = 1;
|
global.UpdateMode = 1;
|
||||||
global.ToLog("Start ReWriteDBSmartWrite");
|
global.ToLog("Start ReWriteDBSmartWrite");
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import { secp256k1 } from './library'
|
import { secp256k1 } from './library'
|
||||||
// const fs = require('fs');
|
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
require("./library");
|
require("./library");
|
||||||
require("./crypto-library");
|
require("./crypto-library");
|
||||||
|
5
src/global.d.ts
vendored
5
src/global.d.ts
vendored
@ -42,6 +42,8 @@ declare global {
|
|||||||
MAX_LENGTH_SENDER_MAP: number;
|
MAX_LENGTH_SENDER_MAP: number;
|
||||||
DELTA_START_SENDER_MAP: number;
|
DELTA_START_SENDER_MAP: number;
|
||||||
NODES_DELTA_CALC_HOUR: number;
|
NODES_DELTA_CALC_HOUR: number;
|
||||||
|
USE_API_WALLET: number;
|
||||||
|
USE_API_V1: number;
|
||||||
USE_HARD_API_V2: number;
|
USE_HARD_API_V2: number;
|
||||||
USE_TICKET: number;
|
USE_TICKET: number;
|
||||||
USE_CHECK_SENDING: number;
|
USE_CHECK_SENDING: number;
|
||||||
@ -99,7 +101,8 @@ declare global {
|
|||||||
HTTP_HOSTING_PORT: number;
|
HTTP_HOSTING_PORT: number;
|
||||||
HTTPS_HOSTING_DOMAIN: string;
|
HTTPS_HOSTING_DOMAIN: string;
|
||||||
HTTP_MAX_COUNT_ROWS: number;
|
HTTP_MAX_COUNT_ROWS: number;
|
||||||
HTTP_ADMIN_PASSORD: string;
|
HTTP_ADMIN_PASSWORD: string;
|
||||||
|
HTTP_START_PAGE: string;
|
||||||
MIN_POWER_POW_HANDSHAKE: number;
|
MIN_POWER_POW_HANDSHAKE: number;
|
||||||
USE_HINT: number;
|
USE_HINT: number;
|
||||||
ALL_VIEW_ROWS: number;
|
ALL_VIEW_ROWS: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user