1
0
forked from circlecloud/tera

style: comment unused code and format

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-07-10 17:53:52 +08:00
parent 812813da8d
commit f0d4952b27
32 changed files with 3958 additions and 5739 deletions

View File

@ -10,23 +10,19 @@
const ipcRenderer = require('electron').ipcRenderer;
function GetDataElectron(Method,ObjPost,Func)
{
if(Func === undefined)
{
function GetDataElectron(Method, ObjPost, Func) {
if (Func === undefined) {
Func = ObjPost;
ObjPost = null;
}
var reply;
try
{
reply = ipcRenderer.sendSync('GetData', {path:Method, obj:ObjPost});
try {
reply = ipcRenderer.sendSync('GetData', { path: Method, obj: ObjPost });
}
catch(e)
{
catch (e) {
reply = undefined;
}
if(Func)
if (Func)
Func(reply);
};
window.GetData = GetDataElectron;

File diff suppressed because it is too large Load Diff

View File

@ -11,10 +11,9 @@
var MAX_SUPER_VALUE_POW = (1 << 30) * 2;
window.TYPE_TRANSACTION_CREATE = 100;
function GetHashWithValues(hash0,value1,value2,bNotCopy)
{
function GetHashWithValues(hash0, value1, value2, bNotCopy) {
var hash;
if(bNotCopy)
if (bNotCopy)
hash = hash0;
else
hash = hash0.slice();
@ -30,20 +29,15 @@ function GetHashWithValues(hash0,value1,value2,bNotCopy)
return arrhash;
};
function GetPowPower(arrhash)
{
function GetPowPower(arrhash) {
var SumBit = 0;
for(var i = 0; i < arrhash.length; i++)
{
for (var i = 0; i < arrhash.length; i++) {
var byte = arrhash[i];
for(var b = 7; b >= 0; b--)
{
if((byte >> b) & 1)
{
for (var b = 7; b >= 0; b--) {
if ((byte >> b) & 1) {
return SumBit;
}
else
{
else {
SumBit++;
}
}
@ -51,29 +45,25 @@ function GetPowPower(arrhash)
return SumBit;
};
function GetPowValue(arrhash)
{
function GetPowValue(arrhash) {
var value = (arrhash[0] << 23) * 2 + (arrhash[1] << 16) + (arrhash[2] << 8) + arrhash[3];
value = value * 256 + arrhash[4];
value = value * 256 + arrhash[5];
return value;
};
function CreateNoncePOWExtern(arr0,BlockNum,count,startnone)
{
function CreateNoncePOWExtern(arr0, BlockNum, count, startnone) {
var arr = [];
for(var i = 0; i < arr0.length; i++)
for (var i = 0; i < arr0.length; i++)
arr[i] = arr0[i];
if(!startnone)
if (!startnone)
startnone = 0;
var maxnonce = 0;
var supervalue = MAX_SUPER_VALUE_POW;
for(var nonce = startnone; nonce <= startnone + count; nonce++)
{
for (var nonce = startnone; nonce <= startnone + count; nonce++) {
var arrhash = GetHashWithValues(arr, nonce, BlockNum, true);
var value = GetPowValue(arrhash);
if(value < supervalue)
{
if (value < supervalue) {
maxnonce = nonce;
supervalue = value;
}
@ -82,8 +72,7 @@ function CreateNoncePOWExtern(arr0,BlockNum,count,startnone)
};
window.TR_TICKET_HASH_LENGTH = 10;
function CreateHashBody(body,Num,Nonce)
{
function CreateHashBody(body, Num, Nonce) {
var length = body.length - 12;
body[length + 0] = Num & 0xFF;
body[length + 1] = (Num >>> 8) & 0xFF;
@ -100,7 +89,7 @@ function CreateHashBody(body,Num,Nonce)
body[length + 5] = 0;
var HASH = sha3(body);
var FullHashTicket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
for(var i = 0; i < TR_TICKET_HASH_LENGTH; i++)
for (var i = 0; i < TR_TICKET_HASH_LENGTH; i++)
FullHashTicket[i] = HASH[i];
WriteUintToArrOnPos(FullHashTicket, Num, TR_TICKET_HASH_LENGTH);
return sha3(FullHashTicket);
@ -111,18 +100,16 @@ window.MIN_POWER_POW_TR = 0;
window.CONSENSUS_PERIOD_TIME = 1000;
window.FIRST_TIME_BLOCK = 1530446400000;
window.NEW_SIGN_TIME = 25500000;
window.SetBlockChainConstant = function (Data)
{
window.SetBlockChainConstant = function(Data) {
var DeltaServerClient = new Date() - Data.CurTime;
if(!Data.DELTA_CURRENT_TIME)
if (!Data.DELTA_CURRENT_TIME)
Data.DELTA_CURRENT_TIME = 0;
window.DELTA_CURRENT_TIME2 = Data.DELTA_CURRENT_TIME - DeltaServerClient;
window.MIN_POWER_POW_TR = DELTA_POWER_POW_TR + Data.MIN_POWER_POW_TR;
window.FIRST_TIME_BLOCK = Data.FIRST_TIME_BLOCK;
window.NEW_SIGN_TIME = Data.NEW_SIGN_TIME;
window.CONSENSUS_PERIOD_TIME = Data.CONSENSUS_PERIOD_TIME;
window.GetCurrentBlockNumByTime = function ()
{
window.GetCurrentBlockNumByTime = function() {
var CurrentTime = Date.now() + DELTA_CURRENT_TIME2;
var CurTimeNum = CurrentTime - FIRST_TIME_BLOCK;
var StartBlockNum = Math.floor((CurTimeNum + CONSENSUS_PERIOD_TIME) / CONSENSUS_PERIOD_TIME);
@ -130,18 +117,15 @@ window.SetBlockChainConstant = function (Data)
};
window.NWMODE = Data.NWMODE;
};
window.GetCurrentBlockNumByTime = function ()
{
window.GetCurrentBlockNumByTime = function() {
return 0;
};
function GetBlockNumTr(arr)
{
function GetBlockNumTr(arr) {
var BlockNum = window.DELTA_FOR_TIME_TX + GetCurrentBlockNumByTime();
if(arr[0] === TYPE_TRANSACTION_CREATE)
{
if (arr[0] === TYPE_TRANSACTION_CREATE) {
var BlockNum2 = Math.floor(BlockNum / 10) * 10;
if(BlockNum2 < BlockNum)
if (BlockNum2 < BlockNum)
BlockNum2 = BlockNum2 + 10;
BlockNum = BlockNum2;
}
@ -151,26 +135,20 @@ var LastCreatePOWTrType = 0;
var LastCreatePOWBlockNum = 0;
var LastCreatePOWHash = [255, 255, 255, 255];
function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
{
function CreateHashBodyPOWInnerMinPower(arr, MinPow, startnonce) {
var TrType = arr[0];
var BlockNum = GetBlockNumTr(arr);
if(MinPow === undefined)
{
if (MinPow === undefined) {
MinPow = MIN_POWER_POW_TR + Math.log2(arr.length / 128);
}
var nonce = startnonce;
while(1)
{
while (1) {
var arrhash = CreateHashBody(arr, BlockNum, nonce);
var power = GetPowPower(arrhash);
if(power >= MinPow)
{
if(LastCreatePOWBlockNum === BlockNum && LastCreatePOWTrType === TrType && CompareArr(LastCreatePOWHash, arrhash) > 0)
{
if (power >= MinPow) {
if (LastCreatePOWBlockNum === BlockNum && LastCreatePOWTrType === TrType && CompareArr(LastCreatePOWHash, arrhash) > 0) {
}
else
{
else {
LastCreatePOWBlockNum = BlockNum;
LastCreatePOWTrType = TrType;
LastCreatePOWHash = arrhash;
@ -178,35 +156,31 @@ function CreateHashBodyPOWInnerMinPower(arr,MinPow,startnonce)
}
}
nonce++;
if(nonce % 2000 === 0)
{
if (nonce % 2000 === 0) {
BlockNum = GetBlockNumTr(arr);
}
}
};
function CalcHashFromArray(ArrHashes,bOriginalSeq)
{
if(bOriginalSeq === undefined)
function CalcHashFromArray(ArrHashes, bOriginalSeq) {
if (bOriginalSeq === undefined)
ArrHashes.sort(CompareArr);
var Buf = [];
for(var i = 0; i < ArrHashes.length; i++)
{
for (var i = 0; i < ArrHashes.length; i++) {
var Value = ArrHashes[i];
for(var n = 0; n < Value.length; n++)
for (var n = 0; n < Value.length; n++)
Buf.push(Value[n]);
}
if(Buf.length === 0)
if (Buf.length === 0)
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
else
if(Buf.length === 32)
if (Buf.length === 32)
return Buf;
var Hash = shaarr(Buf);
return Hash;
};
function GetArrFromValue(Num)
{
function GetArrFromValue(Num) {
var arr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
arr[0] = Num & 0xFF;
arr[1] = (Num >>> 8) & 0xFF;
@ -218,54 +192,44 @@ function GetArrFromValue(Num)
return arr;
};
function LoadLib(Path)
{
function LoadLib(Path) {
var item = document.createElement('script');
item.type = "text/javascript";
item.src = Path;
document.getElementsByTagName('head')[0].appendChild(item);
};
function IsMS()
{
function IsMS() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if(msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) {
return 1;
}
else
{
else {
return 0;
}
};
function LoadSignLib()
{
if(window.SignLib)
return ;
function LoadSignLib() {
if (window.SignLib)
return;
LoadLib("./JS/sign-lib-min.js");
};
function ComputeSecretWithCheck(PubKey,StrPrivKey,F)
{
if(!window.SignLib)
{
function ComputeSecretWithCheck(PubKey, StrPrivKey, F) {
if (!window.SignLib) {
SetError("Error - SignLib not installed");
return ;
return;
}
if(!IsHexStr(StrPrivKey) || StrPrivKey.length !== 64)
{
if (!IsHexStr(StrPrivKey) || StrPrivKey.length !== 64) {
SetError("Error set PrivKey");
return ;
return;
}
var PrivKey = Buffer.from(GetArrFromHex(StrPrivKey));
if(typeof PubKey === "string")
{
if(!IsHexStr(PubKey) || PubKey.length !== 66)
{
if (typeof PubKey === "string") {
if (!IsHexStr(PubKey) || PubKey.length !== 66) {
SetError("Error PubKey");
return ;
return;
}
PubKey = Buffer.from(GetArrFromHex(PubKey));
}
@ -273,35 +237,29 @@ function ComputeSecretWithCheck(PubKey,StrPrivKey,F)
F(sha3(Result));
};
function ComputeSecret(Account,PubKey,F)
{
if(GetPrivKey())
{
function ComputeSecret(Account, PubKey, F) {
if (GetPrivKey()) {
ComputeSecretWithCheck(PubKey, GetPrivKey(), F);
}
else
{
GetData("GetWalletInfo", {Account:Account}, function (Data)
{
if(!Data || !Data.result)
return ;
else {
GetData("GetWalletInfo", { Account: Account }, function(Data) {
if (!Data || !Data.result)
return;
ComputeSecretWithCheck(PubKey, Data.PrivateKey, F);
});
}
};
function Encrypt(ArrSecret,StartEncrypt,StrName,StrValue)
{
function Encrypt(ArrSecret, StartEncrypt, StrName, StrValue) {
var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt));
var Arr = toUTF8Array(StrValue);
return DoSecret(Arr, arrRnd);
};
function Decrypt(ArrSecret,StartEncrypt,StrName,Arr)
{
if(!ArrSecret)
function Decrypt(ArrSecret, StartEncrypt, StrName, Arr) {
if (!ArrSecret)
return "".padEnd(Arr.length / 2, ".");
if(typeof Arr === "string")
if (typeof Arr === "string")
Arr = GetArrFromHex(Arr);
var arrRnd = sha3arr2(ArrSecret, sha3(StrName + StartEncrypt));
var Arr2 = DoSecret(Arr, arrRnd);
@ -309,18 +267,15 @@ function Decrypt(ArrSecret,StartEncrypt,StrName,Arr)
return Str;
};
function DoSecret(Arr,arrRnd)
{
function DoSecret(Arr, arrRnd) {
var Arr2 = [];
var CryptID = 0;
var Pos = 0;
while(Pos < Arr.length)
{
while (Pos < Arr.length) {
CryptID++;
WriteUintToArrOnPos(arrRnd, CryptID, 0);
var CurBuf = sha3(arrRnd);
for(var i = 0; i < 32 && Pos < Arr.length; i++, Pos++)
{
for (var i = 0; i < 32 && Pos < Arr.length; i++ , Pos++) {
Arr2[Pos] = Arr[Pos] ^ CurBuf[i];
}
}
@ -328,26 +283,22 @@ function DoSecret(Arr,arrRnd)
};
var glEncryptInit = 0;
function EncryptInit()
{
function EncryptInit() {
glEncryptInit++;
var Time = Date.now() - new Date(2019, 0, 1);
return Math.floor(Time * 100 + Math.random() * 100) * 100 + glEncryptInit;
};
function EncryptID(ArrSecret,StartEncrypt,id)
{
function EncryptID(ArrSecret, StartEncrypt, id) {
var Value = $(id).value;
Value = Value.padEnd(Value.length + random(5), " ");
return GetHexFromArr(Encrypt(ArrSecret, StartEncrypt, id, Value));
};
function EncryptFields(ArrSecret,Params,ArrName)
{
if(!Params.Crypto)
function EncryptFields(ArrSecret, Params, ArrName) {
if (!Params.Crypto)
Params.Crypto = EncryptInit();
for(var i = 0; i < ArrName.length; i++)
{
for (var i = 0; i < ArrName.length; i++) {
var Name = ArrName[i];
var Value = Params[Name];
Value = Value.padEnd(Value.length + random(5), " ");
@ -355,17 +306,13 @@ function EncryptFields(ArrSecret,Params,ArrName)
}
};
function DecryptFields(ArrSecret,Params,ArrName)
{
for(var i = 0; i < ArrName.length; i++)
{
function DecryptFields(ArrSecret, Params, ArrName) {
for (var i = 0; i < ArrName.length; i++) {
var Name = ArrName[i];
if(Params[Name])
{
if (Params[Name]) {
Params[Name] = Decrypt(ArrSecret, Params.Crypto, Name, GetArrFromHex(Params[Name]));
}
else
{
else {
Params[Name] = "";
}
}

View File

@ -9,181 +9,147 @@
*/
function SendPay(Data)
{
function SendPay(Data) {
Data.cmd = "pay";
SendData(Data);
};
function SetStorage(Key,Value)
{
var Data = {cmd:"setstorage", Key:Key, Value:Value};
function SetStorage(Key, Value) {
var Data = { cmd: "setstorage", Key: Key, Value: Value };
SendData(Data);
};
function GetStorage(Key,F)
{
var Data = {cmd:"getstorage", Key:Key};
function GetStorage(Key, F) {
var Data = { cmd: "getstorage", Key: Key };
SendData(Data, F);
};
function SetCommon(Key,Value)
{
var Data = {cmd:"setcommon", Key:Key, Value:Value};
function SetCommon(Key, Value) {
var Data = { cmd: "setcommon", Key: Key, Value: Value };
SendData(Data);
};
function GetCommon(Key,F)
{
var Data = {cmd:"getcommon", Key:Key};
function GetCommon(Key, F) {
var Data = { cmd: "getcommon", Key: Key };
SendData(Data, F);
};
function GetInfo(F,bUseCache)
{
var Data = {cmd:"DappInfo", AllAccounts:ALL_ACCOUNTS, AllData:!bUseCache};
function GetInfo(F, bUseCache) {
var Data = { cmd: "DappInfo", AllAccounts: ALL_ACCOUNTS, AllData: !bUseCache };
SendData(Data, F);
};
function Call(Account,MethodName,Params,F)
{
var Data = {cmd:"DappCall", MethodName:MethodName, Params:Params, Account:Account};
function Call(Account, MethodName, Params, F) {
var Data = { cmd: "DappCall", MethodName: MethodName, Params: Params, Account: Account };
SendData(Data, F);
};
function SendCall(Account,MethodName,Params,FromNum)
{
if(!INFO.WalletCanSign)
{
function SendCall(Account, MethodName, Params, FromNum) {
if (!INFO.WalletCanSign) {
SetError("Pls, open wallet");
return 0;
}
var Data = {cmd:"DappSendCall", MethodName:MethodName, Params:Params, Account:Account, FromNum:FromNum};
var Data = { cmd: "DappSendCall", MethodName: MethodName, Params: Params, Account: Account, FromNum: FromNum };
SendData(Data);
return 1;
};
function GetWalletAccounts(F)
{
var Data = {cmd:"DappWalletList"};
function GetWalletAccounts(F) {
var Data = { cmd: "DappWalletList" };
SendData(Data, F);
};
function GetAccountList(Params,F)
{
var Data = {cmd:"DappAccountList", Params:Params};
function GetAccountList(Params, F) {
var Data = { cmd: "DappAccountList", Params: Params };
SendData(Data, F);
};
function GetSmartList(Params,F)
{
var Data = {cmd:"DappSmartList", Params:Params};
function GetSmartList(Params, F) {
var Data = { cmd: "DappSmartList", Params: Params };
SendData(Data, F);
};
function GetBlockList(Params,F)
{
var Data = {cmd:"DappBlockList", Params:Params};
function GetBlockList(Params, F) {
var Data = { cmd: "DappBlockList", Params: Params };
SendData(Data, F);
};
function GetTransactionList(Params,F)
{
var Data = {cmd:"DappTransactionList", Params:Params};
function GetTransactionList(Params, F) {
var Data = { cmd: "DappTransactionList", Params: Params };
SendData(Data, F);
};
function DappSmartHTMLFile(Smart,F)
{
var Data = {cmd:"DappSmartHTMLFile", Params:{Smart:Smart}};
function DappSmartHTMLFile(Smart, F) {
var Data = { cmd: "DappSmartHTMLFile", Params: { Smart: Smart } };
SendData(Data, F);
};
function DappBlockFile(BlockNum,TrNum,F)
{
var Data = {cmd:"DappBlockFile", Params:{BlockNum:BlockNum, TrNum:TrNum}};
function DappBlockFile(BlockNum, TrNum, F) {
var Data = { cmd: "DappBlockFile", Params: { BlockNum: BlockNum, TrNum: TrNum } };
SendData(Data, F);
};
function SetStatus(Str)
{
SendData({cmd:"SetStatus", Message:Str});
function SetStatus(Str) {
SendData({ cmd: "SetStatus", Message: Str });
};
function SetError(Str)
{
SendData({cmd:"SetError", Message:Str});
function SetError(Str) {
SendData({ cmd: "SetError", Message: Str });
};
function SetLocationPath(Str)
{
SendData({cmd:"SetLocationHash", Message:Str});
function SetLocationPath(Str) {
SendData({ cmd: "SetLocationHash", Message: Str });
};
function CreateNewAccount(Currency)
{
SendData({cmd:"CreateNewAccount", Currency:Currency});
function CreateNewAccount(Currency) {
SendData({ cmd: "CreateNewAccount", Currency: Currency });
};
function OpenLink(Str)
{
SendData({cmd:"OpenLink", Message:Str});
function OpenLink(Str) {
SendData({ cmd: "OpenLink", Message: Str });
};
function SetMobileMode()
{
SendData({cmd:"SetMobileMode"});
function SetMobileMode() {
SendData({ cmd: "SetMobileMode" });
};
function ComputeSecret(PubKey,F,Account)
{
if(!INFO.WalletCanSign)
{
function ComputeSecret(PubKey, F, Account) {
if (!INFO.WalletCanSign) {
SetError("Pls, open wallet");
return 0;
}
if(!Account && USER_ACCOUNT.length)
if (!Account && USER_ACCOUNT.length)
Account = USER_ACCOUNT[0].Num;
if(typeof PubKey === "number")
{
if (typeof PubKey === "number") {
var AccNum = PubKey;
GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
{
if(Err)
{
GetAccountList({ StartNum: AccNum, CountNum: 1 }, function(Err, Arr) {
if (Err) {
SetError(Err);
}
else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:Arr[0].PubKey.data}, F);
else {
SendData({ cmd: "ComputeSecret", Account: Account, PubKey: Arr[0].PubKey.data }, F);
}
});
}
else
{
SendData({cmd:"ComputeSecret", Account:Account, PubKey:PubKey}, F);
else {
SendData({ cmd: "ComputeSecret", Account: Account, PubKey: PubKey }, F);
}
};
function CheckInstall()
{
SendData({cmd:"CheckInstall"});
function CheckInstall() {
SendData({ cmd: "CheckInstall" });
};
function SendTransaction(Body,TR,SumPow,F)
{
function SendTransaction(Body, TR, SumPow, F) {
SetError("Cannt SEND TR: " + JSON.stringify(TR));
};
function CurrencyName(Num)
{
function CurrencyName(Num) {
var Name = MapCurrency[Num];
if(!Name)
{
GetSmartList({StartNum:Num, CountNum:1, TokenGenerate:1}, function (Err,Arr)
{
if(Err || Arr.length === 0)
return ;
if (!Name) {
GetSmartList({ StartNum: Num, CountNum: 1, TokenGenerate: 1 }, function(Err, Arr) {
if (Err || Arr.length === 0)
return;
var Smart = Arr[0];
Name = GetTokenName(Smart.Num, Smart.ShortName);
MapCurrency[Smart.Num] = Name;
@ -194,19 +160,15 @@ function CurrencyName(Num)
};
var SendCountUpdate = 0;
function FindAllCurrency()
{
function FindAllCurrency() {
SendCountUpdate++;
GetSmartList({StartNum:8, CountNum:100, TokenGenerate:1}, function (Err,Arr)
{
GetSmartList({ StartNum: 8, CountNum: 100, TokenGenerate: 1 }, function(Err, Arr) {
SendCountUpdate--;
if(Err)
return ;
for(var i = 0; i < Arr.length; i++)
{
if (Err)
return;
for (var i = 0; i < Arr.length; i++) {
var Smart = Arr[i];
if(!MapCurrency[Smart.Num])
{
if (!MapCurrency[Smart.Num]) {
var Name = GetTokenName(Smart.Num, Smart.ShortName);
MapCurrency[Smart.Num] = Name;
}
@ -214,62 +176,50 @@ function FindAllCurrency()
});
};
function GetFilePath(Path)
{
if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/"))
{
if(Path.substr(0, 1) !== "/")
function GetFilePath(Path) {
if (window.PROTOCOL_SERVER_PATH && Path.indexOf("file/")) {
if (Path.substr(0, 1) !== "/")
Path = "/" + Path;
Path = window.PROTOCOL_SERVER_PATH + Path;
}
return Path;
};
function GetParamsFromPath(Name)
{
if(!OPEN_PATH)
function GetParamsFromPath(Name) {
if (!OPEN_PATH)
return undefined;
var arr = OPEN_PATH.split("&");
for(var i = 0; i < arr.length; i++)
{
if(arr[i].indexOf(Name + "=") === 0)
{
for (var i = 0; i < arr.length; i++) {
if (arr[i].indexOf(Name + "=") === 0) {
return arr[i].split("=")[1];
}
}
};
function GetState(AccNum,F,FErr)
{
function GetState(AccNum, F, FErr) {
SendCountUpdate++;
GetAccountList({StartNum:AccNum, CountNum:1}, function (Err,Arr)
{
GetAccountList({ StartNum: AccNum, CountNum: 1 }, function(Err, Arr) {
SendCountUpdate--;
if(!Err && Arr.length)
{
if (!Err && Arr.length) {
var Item = Arr[0].SmartState;
if(Item)
{
if (Item) {
F(Item);
return ;
return;
}
}
if(FErr)
{
if (FErr) {
FErr();
return ;
return;
}
});
};
var glMapF = {};
var glKeyF = 0;
function SendData(Data,F)
{
if(!window.parent)
return ;
if(F)
{
function SendData(Data, F) {
if (!window.parent)
return;
if (F) {
glKeyF++;
Data.CallID = glKeyF;
glMapF[glKeyF] = F;
@ -277,22 +227,18 @@ function SendData(Data,F)
window.parent.postMessage(Data, "*");
};
function OnMessage(event)
{
function OnMessage(event) {
var Data = event.data;
if(!Data || typeof Data !== "object")
return ;
if (!Data || typeof Data !== "object")
return;
var CallID = Data.CallID;
var cmd = Data.cmd;
if(CallID)
{
if (CallID) {
var F = glMapF[CallID];
if(F)
{
if (F) {
delete Data.CallID;
delete Data.cmd;
switch(cmd)
{
switch (cmd) {
case "getstorage":
case "getcommon":
F(Data.Key, Data.Value);
@ -323,49 +269,40 @@ function OnMessage(event)
delete glMapF[CallID];
}
}
else
{
switch(cmd)
{
else {
switch (cmd) {
case "History":
var eventEvent = new CustomEvent("History", {detail:Data});
var eventEvent = new CustomEvent("History", { detail: Data });
window.dispatchEvent(eventEvent);
break;
case "OnEvent":
if(window.OnEvent)
{
if (window.OnEvent) {
window.OnEvent(Data);
}
var eventEvent = new CustomEvent("Event", {detail:Data});
var eventEvent = new CustomEvent("Event", { detail: Data });
window.dispatchEvent(eventEvent);
}
}
};
function OpenRefFile(Str)
{
function OpenRefFile(Str) {
var Param = ParseFileName(Str);
if(Param.BlockNum)
DappBlockFile(Param.BlockNum, Param.TrNum, function (Err,Body)
{
if (Param.BlockNum)
DappBlockFile(Param.BlockNum, Param.TrNum, function(Err, Body) {
document.write(Body);
});
else
{
else {
OpenLink(Str);
}
};
function SaveToStorageByArr(Arr)
{
function SaveToStorageByArr(Arr) {
SetStorage("VerSave", "1");
for(var i = 0; i < Arr.length; i++)
{
for (var i = 0; i < Arr.length; i++) {
var name = Arr[i];
var Item = $(name);
if(Item)
{
if(Item.type === "checkbox")
if (Item) {
if (Item.type === "checkbox")
SetStorage(name, 0 + Item.checked);
else
SetStorage(name, Item.value);
@ -373,94 +310,74 @@ function SaveToStorageByArr(Arr)
}
};
function LoadFromStorageByArr(Arr,F,bAll)
{
GetStorage("VerSave", function (Key,Value)
{
if(Value === "1")
{
for(var i = 0; i < Arr.length; i++)
{
if(i === Arr.length - 1)
function LoadFromStorageByArr(Arr, F, bAll) {
GetStorage("VerSave", function(Key, Value) {
if (Value === "1") {
for (var i = 0; i < Arr.length; i++) {
if (i === Arr.length - 1)
LoadFromStorageById(Arr[i], F);
else
LoadFromStorageById(Arr[i]);
}
}
if(bAll && F)
if (bAll && F)
F(0);
});
};
function LoadFromStorageById(Name,F)
{
GetStorage(Name, function (Key,Value)
{
function LoadFromStorageById(Name, F) {
GetStorage(Name, function(Key, Value) {
var Item = document.getElementById(Name);
if(Item)
{
if(Item.type === "checkbox")
if (Item) {
if (Item.type === "checkbox")
Item.checked = parseInt(Value);
else
Item.value = Value;
}
if(F)
if (F)
F(Key, Value);
});
};
var SendCountDappParams = 0;
function GetDappParams(BNum,TrNum,F,bAll)
{
if(!BNum)
{
if(bAll)
function GetDappParams(BNum, TrNum, F, bAll) {
if (!BNum) {
if (bAll)
F();
return ;
return;
}
SendCountDappParams++;
DappBlockFile(BNum, TrNum, function (Err,Data)
{
DappBlockFile(BNum, TrNum, function(Err, Data) {
SendCountDappParams--;
if(!Err && Data.Type === 135)
{
try
{
if (!Err && Data.Type === 135) {
try {
var Params = JSON.parse(Data.Params);
}
catch(e)
{
catch (e) {
}
if(Params)
{
if (Params) {
F(Params, Data.MethodName, Data.FromNum);
return ;
return;
}
}
if(bAll)
if (bAll)
F();
});
};
document.addEventListener("DOMContentLoaded", function ()
{
document.addEventListener("DOMContentLoaded", function() {
var refs = document.getElementsByTagName("A");
for(var i = 0, L = refs.length; i < L; i++)
{
if(refs[i].href.indexOf("/file/") >= 0)
{
refs[i].onclick = function ()
{
for (var i = 0, L = refs.length; i < L; i++) {
if (refs[i].href.indexOf("/file/") >= 0) {
refs[i].onclick = function() {
OpenRefFile(this.href);
};
}
}
});
if(window.addEventListener)
{
if (window.addEventListener) {
window.addEventListener("message", OnMessage);
}
else
{
else {
window.attachEvent("onmessage", OnMessage);
}
var SMART = {}, BASE_ACCOUNT = {}, INFO = {}, USER_ACCOUNT = [], USER_ACCOUNT_MAP = {}, OPEN_PATH = "", ACCOUNT_OPEN_NUM = 0;
@ -468,13 +385,10 @@ var ALL_ACCOUNTS = 0;
var WasStartInit = 0, WasStartInit2 = 0;
var eventInfo = new Event("UpdateInfo");
function UpdateDappInfo()
{
GetInfo(function (Err,Data)
{
if(Err)
{
return ;
function UpdateDappInfo() {
GetInfo(function(Err, Data) {
if (Err) {
return;
}
INFO = Data;
SMART = Data.Smart;
@ -484,37 +398,32 @@ function UpdateDappInfo()
SetBlockChainConstant(Data);
USER_ACCOUNT = Data.ArrWallet;
USER_ACCOUNT_MAP = {};
for(var i = 0; i < USER_ACCOUNT.length; i++)
for (var i = 0; i < USER_ACCOUNT.length; i++)
USER_ACCOUNT_MAP[USER_ACCOUNT[i].Num] = USER_ACCOUNT[i];
if(window.OnInit && !WasStartInit)
{
if (window.OnInit && !WasStartInit) {
WasStartInit = 1;
window.OnInit(1);
}
else
if(window.OnUpdateInfo)
{
if (window.OnUpdateInfo) {
window.OnUpdateInfo();
}
if(!WasStartInit2)
{
if (!WasStartInit2) {
WasStartInit2 = 1;
var eventInit = new Event("Init");
window.dispatchEvent(eventInit);
}
window.dispatchEvent(eventInfo);
if(Data.ArrEvent)
for(var i = 0; i < Data.ArrEvent.length; i++)
{
if (Data.ArrEvent)
for (var i = 0; i < Data.ArrEvent.length; i++) {
var Item = Data.ArrEvent[i];
Item.cmd = "OnEvent";
OnMessage({data:Item});
OnMessage({ data: Item });
}
}, 1);
};
window.addEventListener('load', function ()
{
if(!window.sha3)
window.addEventListener('load', function() {
if (!window.sha3)
LoadLib("./JS/sha3.js");
UpdateDappInfo();
setInterval(UpdateDappInfo, 1000);

View File

@ -11,80 +11,67 @@
var DiagramMap = {};
var DiagramMapId = {};
var LMouseOn = false;
if(!window.toStaticHTML)
toStaticHTML = function (Str)
{
if (!window.toStaticHTML)
toStaticHTML = function(Str) {
return Str;
};
function Rigth(Str,Count)
{
if(Str.length < Count)
function Rigth(Str, Count) {
if (Str.length < Count)
return Str;
else
return Str.substr(Str.length - Count);
};
function SetHTMLDiagramItem(Item,width)
{
function SetHTMLDiagramItem(Item, width) {
Item.mouseX = width - 50;
if(Item.Extern || Item.Delete)
return ;
if (Item.Extern || Item.Delete)
return;
var MinHeight = 80;
if(!Item.id)
if (!Item.id)
Item.id = "DgrmId" + Item.num;
DiagramMap[Item.name] = Item;
DiagramMapId[Item.id] = Item;
if(Item.isLine)
{
if(Item.text)
if (Item.isLine) {
if (Item.text)
Str = "<BR><B>" + Item.text + '</B><INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X">';
else
Str = "<HR>";
}
else
{
else {
Str = '<BR><DIV>' + Item.text + '<INPUT type="button" class="delete" onclick="DeleteDiagram(\'' + Item.id + '\')" value="X"></DIV>\
<BR><canvas class="DIAGRAM" width="' + width + '" height="' + MinHeight + '" id="' + Item.id + '"></canvas>';
}
var ElBlock = document.getElementById("B" + Item.id);
if(ElBlock)
if (ElBlock)
ElBlock.innerHTML = toStaticHTML(Str);
else
{
else {
var diargams = document.getElementById("diargams");
diargams.innerHTML = toStaticHTML(diargams.innerHTML + "<DIV id='B" + Item.id + "'>" + Str + "</DIV>");
}
};
function SetDiagramMouseX(event,mode)
{
if(event.srcElement && event.srcElement.className && event.srcElement.className.indexOf && event.srcElement.className.indexOf("DIAGRAM") >= 0)
{
if(mode === "down")
function SetDiagramMouseX(event, mode) {
if (event.srcElement && event.srcElement.className && event.srcElement.className.indexOf && event.srcElement.className.indexOf("DIAGRAM") >= 0) {
if (mode === "down")
LMouseOn = true;
else
if(mode === "up")
if (mode === "up")
LMouseOn = false;
event.preventDefault();
if(LMouseOn === true)
{
if (LMouseOn === true) {
var obj = event.srcElement;
var mouse = getMouse(obj, event);
if(event.ctrlKey === true)
{
for(var key in DiagramMapId)
{
if (event.ctrlKey === true) {
for (var key in DiagramMapId) {
var Item = DiagramMapId[key];
Item.mouseX = mouse.x;
DrawDiagram(Item);
}
}
else
{
else {
var Item = DiagramMapId[obj.id];
if(Item)
{
if (Item) {
Item.mouseX = mouse.x;
DrawDiagram(Item);
}
@ -93,12 +80,11 @@ function SetDiagramMouseX(event,mode)
}
};
function DrawDiagram(Item)
{
if(Item.Delete)
return ;
function DrawDiagram(Item) {
if (Item.Delete)
return;
var arr = Item.arr;
if(!arr)
if (!arr)
arr = Item.ArrList;
var arrX = Item.arrX;
var GreenValue = Item.value;
@ -107,71 +93,69 @@ function DrawDiagram(Item)
var StartServer = Item.starttime;
var mouseX = Item.mouseX;
var KPrecision = Item.KPrecision;
if(!KPrecision)
if (!KPrecision)
KPrecision = 1;
if(!arr)
return ;
if (!arr)
return;
var obj = document.getElementById(Item.id);
var ctx = obj.getContext('2d');
var Left = 50;
var Top = 11;
var Button = 15;
var Right = 50;
if(Item.fillStyle)
if (Item.fillStyle)
ctx.fillStyle = Item.fillStyle;
else
ctx.fillStyle = "#FFF";
ctx.fillRect(0, 0, obj.width, obj.height);
if(arr.length <= 0)
return ;
if (arr.length <= 0)
return;
var Pow2 = 0;
if(Item.name.substr(Item.name.length - 2) === "**")
if (Item.name.substr(Item.name.length - 2) === "**")
Pow2 = 1;
var MaxValue = arr[0];
var MinValue = arr[0];
var AvgValue = 0;
for(var i = 0; i < arr.length; i++)
{
if(arr[i] > MaxValue)
for (var i = 0; i < arr.length; i++) {
if (arr[i] > MaxValue)
MaxValue = arr[i];
if(arr[i] < MinValue)
if (arr[i] < MinValue)
MinValue = arr[i];
if(arr[i])
if (arr[i])
AvgValue += arr[i];
}
if(Item.name.substr(0, 4) !== "MAX:" || !Item.AvgValue)
if (Item.name.substr(0, 4) !== "MAX:" || !Item.AvgValue)
AvgValue = AvgValue / arr.length;
else
AvgValue = Item.AvgValue;
if(Pow2 && AvgValue)
if (Pow2 && AvgValue)
AvgValue = Math.pow(2, AvgValue) / 1000000;
if(AvgValue < 50)
if (AvgValue < 50)
AvgValue = AvgValue.toFixed(2);
else
AvgValue = Math.floor(AvgValue);
if(Item.MaxValue !== undefined)
if (Item.MaxValue !== undefined)
MaxValue = Item.MaxValue;
if(Pow2 && MaxValue)
if (Pow2 && MaxValue)
MaxValue = Math.pow(2, MaxValue) / 1000000;
var HValue = MaxValue;
if(HValue <= 0)
if (HValue <= 0)
HValue = 1;
var KX = (obj.width - Left - Right) / arr.length;
var KY = (obj.height - Top - Button) / HValue;
var DeltaY = 0;
var bLine = Item.line;
if(Item.zero)
{
if (Item.zero) {
bLine = 1;
DeltaY -= Item.zero * KY;
MaxValue -= Item.zero;
AvgValue -= Item.zero;
}
MaxValue = Math.floor(MaxValue + 0.5);
if(bLine)
if (bLine)
ctx.lineWidth = 3;
else
if(KX > 1)
if (KX > 1)
ctx.lineWidth = KX;
else
ctx.lineWidth = 1;
@ -181,68 +165,57 @@ function DrawDiagram(Item)
var mouseValue = undefined;
var mouseColor = undefined;
function DrawLines(arr,mode,color)
{
function DrawLines(arr, mode, color) {
var WasMove0 = 0;
ctx.beginPath();
ctx.moveTo(Left, obj.height - Button);
ctx.strokeStyle = color;
var PrevX = undefined;
for(var i = 0; i < arr.length; i++)
{
for (var i = 0; i < arr.length; i++) {
var Value = arr[i];
if(!Value)
if (!Value)
Value = 0;
if(Value)
{
if(Pow2)
if (Value) {
if (Pow2)
Value = Math.pow(2, Value) / 1000000;
}
if(mode === "green")
{
if(Value > GreenValue)
if (mode === "green") {
if (Value > GreenValue)
continue;
}
else
if(mode === "red")
{
if(Value <= GreenValue)
if (mode === "red") {
if (Value <= GreenValue)
continue;
}
var Value1 = Value;
if(Value1 > GreenValue)
if (Value1 > GreenValue)
Value1 = GreenValue;
var VX1 = Math.floor(Value1 * KY);
var VX2 = Math.floor(Value * KY);
if(VX1 === VX2)
if (VX1 === VX2)
VX1 -= 2;
var x = StartX + ctx.lineWidth / 2 + (i) * KX;
if(bLine)
{
if(!WasMove0)
{
if (bLine) {
if (!WasMove0) {
WasMove0 = 1;
ctx.moveTo(x, StartY - VX2);
}
else
{
else {
ctx.lineTo(x, StartY - VX2);
}
}
else
{
else {
ctx.moveTo(x, StartY - VX1);
ctx.lineTo(x, StartY - VX2);
}
if(mouseX)
{
if (mouseX) {
var deltaCur = Math.abs(x - mouseX);
var deltaWas = Math.abs(mouseValueX - mouseX);
if(deltaCur < deltaWas)
{
if (deltaCur < deltaWas) {
mouseValueX = x;
mouseValue = Value;
if(Item.zero)
if (Item.zero)
mouseValue -= Item.zero;
mouseColor = color;
}
@ -250,16 +223,14 @@ function DrawLines(arr,mode,color)
}
ctx.stroke();
};
if(!Item.red)
if (!Item.red)
Item.red = "#A00";
if(bLine)
{
if (bLine) {
DrawLines(arr, "line", Item.red);
}
else
{
else {
DrawLines(arr, "red", Item.red);
if(GreenValue > 0)
if (GreenValue > 0)
DrawLines(arr, "green", "#0A0");
}
var MaxValueText = GetValueByItemProperty(MaxValue, Item);
@ -275,20 +246,18 @@ function DrawLines(arr,mode,color)
ctx.moveTo(StartX, StartY + DeltaY);
ctx.lineTo(obj.width - 10, StartY + DeltaY);
ctx.stroke();
if(mouseX !== undefined)
{
if (mouseX !== undefined) {
ctx.beginPath();
ctx.lineWidth = 0.5;
ctx.strokeStyle = "#00F";
ctx.moveTo(mouseX, Top);
ctx.lineTo(mouseX, StartY);
ctx.stroke();
if(mouseValue !== undefined)
{
if (mouseValue !== undefined) {
ctx.fillStyle = mouseColor;
var Val = GetValueByItemProperty(mouseValue, Item);
var mouseTextX = mouseX;
if(Item.MouseText)
if (Item.MouseText)
mouseTextX -= 3 * Item.MouseText.length;
else
Item.MouseText = "";
@ -296,16 +265,14 @@ function DrawLines(arr,mode,color)
}
}
ctx.fillStyle = "#000";
if(!Item.NoTextMax)
if (!Item.NoTextMax)
ctx.fillText(Rigth("" + MaxValueText, 8), 0, Top - 3);
if(MaxValue > 0 && AvgValue > 0)
{
if (MaxValue > 0 && AvgValue > 0) {
var heigh = StartY - Top;
var KKY = AvgValue / MaxValue;
var y = (heigh - Math.floor(KKY * heigh));
var yT = y;
if(yT < 10)
{
if (yT < 10) {
yT = 10;
}
ctx.beginPath();
@ -316,67 +283,58 @@ function DrawLines(arr,mode,color)
ctx.fillText(Rigth("" + AvgValueText, 8), 0, yT + Top);
}
var CountNameX = 10;
if(arr.length < CountNameX)
if (arr.length < CountNameX)
CountNameX = arr.length;
var KX3 = (obj.width - Left - Right) / CountNameX;
var KDelitel = 1;
var Step = arr.length / CountNameX;
var StartTime, bNumber;
if(arrX)
{
if (arrX) {
}
else
if(StartNumber !== undefined)
{
if (StartNumber !== undefined) {
bNumber = 1;
StartTime = StartNumber;
}
else
if(StartServer)
{
if (StartServer) {
bNumber = 1;
StartTime = Math.floor(((Date.now() - StartServer) - StepTime * arr.length * 1000) / 1000);
if(StartTime < 0)
if (StartTime < 0)
StartTime = 0;
var KDelitel = Math.floor(Step / 10) * 10;
if(KDelitel == 0)
if (KDelitel == 0)
KDelitel = 1;
}
else
{
else {
bNumber = 0;
StartTime = Date.now() - StepTime * arr.length * 1000;
StartX = StartX - 16;
}
for(i = 0; i <= CountNameX; i++)
{
for (i = 0; i <= CountNameX; i++) {
var Val;
if(i === CountNameX)
{
if (i === CountNameX) {
Val = arr.length * StepTime;
KDelitel = 1;
}
else
if(i === 0)
if (i === 0)
Val = 0;
else
Val = i * Step * StepTime;
var Str;
if(arrX)
{
if (arrX) {
Val = Math.floor(Val);
Str = arrX[Val];
if(Str === undefined)
if (Str === undefined)
Str = "";
}
else
if(bNumber)
{
if (bNumber) {
Val = Math.floor((StartTime + Val) / KDelitel) * KDelitel;
Str = Val;
}
else
{
else {
var Time = new Date(StartTime + Val * 1000);
Str = "" + Time.getHours();
Str += ":" + Rigth("0" + Time.getMinutes(), 2);
@ -386,68 +344,56 @@ function DrawLines(arr,mode,color)
}
};
function GetValueByItemProperty(Value,Item)
{
if(Item.MathPow && Item.MathDiv)
{
function GetValueByItemProperty(Value, Item) {
if (Item.MathPow && Item.MathDiv) {
Value = Math.pow(Item.MathPow, Value) / Item.MathDiv;
}
var KPrecision = Item.KPrecision;
if(!Item.KPrecision)
if (!Item.KPrecision)
KPrecision = 1;
Value = Math.floor(Value * KPrecision + 0.5) / KPrecision;
return Value;
};
function InitDiagramByArr(Arr,width)
{
for(var i = 0; i < Arr.length; i++)
{
function InitDiagramByArr(Arr, width) {
for (var i = 0; i < Arr.length; i++) {
Arr[i].num = i + 1;
SetHTMLDiagramItem(Arr[i], width);
}
window.addEventListener('mousedown', function (event)
{
window.addEventListener('mousedown', function(event) {
SetDiagramMouseX(event, "down");
}, false);
window.addEventListener('mouseup', function (event)
{
window.addEventListener('mouseup', function(event) {
SetDiagramMouseX(event, "up");
}, false);
window.addEventListener('onmousemove', function (event)
{
window.addEventListener('onmousemove', function(event) {
SetDiagramMouseX(event, "move");
}, false);
};
function getMouse(canvas,e)
{
function getMouse(canvas, e) {
var x = e.clientX - getTrueOffsetLeft(canvas);
if(window.pageXOffset)
if (window.pageXOffset)
x = x + window.pageXOffset;
var y = e.clientY - getTrueOffsetTop(canvas);
if(window.pageYOffset)
if (window.pageYOffset)
y = y + window.pageYOffset;
var coord = {x:x, y:y};
var coord = { x: x, y: y };
return coord;
};
function getTrueOffsetLeft(ele)
{
function getTrueOffsetLeft(ele) {
var n = 0;
while(ele)
{
while (ele) {
n += ele.offsetLeft || 0;
ele = ele.offsetParent;
}
return n;
};
function getTrueOffsetTop(ele)
{
function getTrueOffsetTop(ele) {
var n = 0;
while(ele)
{
while (ele) {
n += ele.offsetTop || 0;
ele = ele.offsetParent;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -11,180 +11,150 @@
"use strict";
var der = require("./der"), toString = Object.prototype.toString, exports = {}, assert = exports;
exports.isArray = function (e,s)
{
if(!Array.isArray(e))
exports.isArray = function(e, s) {
if (!Array.isArray(e))
throw TypeError(s);
}, exports.isBoolean = function (e,s)
{
if("[object Boolean]" !== toString.call(e))
}, exports.isBoolean = function(e, s) {
if ("[object Boolean]" !== toString.call(e))
throw TypeError(s);
}, exports.isBuffer = function (e,s)
{
if(!Buffer.isBuffer(e))
}, exports.isBuffer = function(e, s) {
if (!Buffer.isBuffer(e))
throw TypeError(s);
}, exports.isFunction = function (e,s)
{
if("[object Function]" !== toString.call(e))
}, exports.isFunction = function(e, s) {
if ("[object Function]" !== toString.call(e))
throw TypeError(s);
}, exports.isNumber = function (e,s)
{
if("[object Number]" !== toString.call(e))
}, exports.isNumber = function(e, s) {
if ("[object Number]" !== toString.call(e))
throw TypeError(s);
}, exports.isObject = function (e,s)
{
if("[object Object]" !== toString.call(e))
}, exports.isObject = function(e, s) {
if ("[object Object]" !== toString.call(e))
throw TypeError(s);
}, exports.isBufferLength = function (e,s,r)
{
if(e.length !== s)
}, exports.isBufferLength = function(e, s, r) {
if (e.length !== s)
throw RangeError(r);
}, exports.isBufferLength2 = function (e,s,r,_)
{
if(e.length !== s && e.length !== r)
}, exports.isBufferLength2 = function(e, s, r, _) {
if (e.length !== s && e.length !== r)
throw RangeError(_);
}, exports.isLengthGTZero = function (e,s)
{
if(0 === e.length)
}, exports.isLengthGTZero = function(e, s) {
if (0 === e.length)
throw RangeError(s);
}, exports.isNumberInInterval = function (e,s,r,_)
{
if(e <= s || r <= e)
}, exports.isNumberInInterval = function(e, s, r, _) {
if (e <= s || r <= e)
throw RangeError(_);
};
var messages = {COMPRESSED_TYPE_INVALID:"compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID:"private key should be a Buffer",
EC_PRIVATE_KEY_LENGTH_INVALID:"private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID:"private key range is invalid",
EC_PRIVATE_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL:"tweak out of range",
EC_PRIVATE_KEY_EXPORT_DER_FAIL:"couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL:"couldn't import from DER format",
EC_PUBLIC_KEYS_TYPE_INVALID:"public keys should be an Array", EC_PUBLIC_KEYS_LENGTH_INVALID:"public keys Array should have at least 1 element",
EC_PUBLIC_KEY_TYPE_INVALID:"public key should be a Buffer", EC_PUBLIC_KEY_LENGTH_INVALID:"public key length is invalid", EC_PUBLIC_KEY_PARSE_FAIL:"the public key could not be parsed or is invalid",
EC_PUBLIC_KEY_CREATE_FAIL:"private was invalid, try again", EC_PUBLIC_KEY_TWEAK_ADD_FAIL:"tweak out of range or resulting public key is invalid",
EC_PUBLIC_KEY_TWEAK_MUL_FAIL:"tweak out of range", EC_PUBLIC_KEY_COMBINE_FAIL:"the sum of the public keys is not valid", ECDH_FAIL:"scalar was invalid (zero or overflow)",
ECDSA_SIGNATURE_TYPE_INVALID:"signature should be a Buffer", ECDSA_SIGNATURE_LENGTH_INVALID:"signature length is invalid",
ECDSA_SIGNATURE_PARSE_FAIL:"couldn't parse signature", ECDSA_SIGNATURE_PARSE_DER_FAIL:"couldn't parse DER signature", ECDSA_SIGNATURE_SERIALIZE_DER_FAIL:"couldn't serialize signature to DER format",
ECDSA_SIGN_FAIL:"nonce generation function failed or private key is invalid", ECDSA_RECOVER_FAIL:"couldn't recover public key from signature",
MSG32_TYPE_INVALID:"message should be a Buffer", MSG32_LENGTH_INVALID:"message length is invalid", OPTIONS_TYPE_INVALID:"options should be an Object",
OPTIONS_DATA_TYPE_INVALID:"options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID:"options.data length is invalid",
OPTIONS_NONCEFN_TYPE_INVALID:"options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID:"recovery should be a Number",
RECOVERY_ID_VALUE_INVALID:"recovery should have value between -1 and 4", TWEAK_TYPE_INVALID:"tweak should be a Buffer", TWEAK_LENGTH_INVALID:"tweak length is invalid"};
var messages = {
COMPRESSED_TYPE_INVALID: "compressed should be a boolean", EC_PRIVATE_KEY_TYPE_INVALID: "private key should be a Buffer",
EC_PRIVATE_KEY_LENGTH_INVALID: "private key length is invalid", EC_PRIVATE_KEY_RANGE_INVALID: "private key range is invalid",
EC_PRIVATE_KEY_TWEAK_ADD_FAIL: "tweak out of range or resulting private key is invalid", EC_PRIVATE_KEY_TWEAK_MUL_FAIL: "tweak out of range",
EC_PRIVATE_KEY_EXPORT_DER_FAIL: "couldn't export to DER format", EC_PRIVATE_KEY_IMPORT_DER_FAIL: "couldn't import from DER format",
EC_PUBLIC_KEYS_TYPE_INVALID: "public keys should be an Array", EC_PUBLIC_KEYS_LENGTH_INVALID: "public keys Array should have at least 1 element",
EC_PUBLIC_KEY_TYPE_INVALID: "public key should be a Buffer", EC_PUBLIC_KEY_LENGTH_INVALID: "public key length is invalid", EC_PUBLIC_KEY_PARSE_FAIL: "the public key could not be parsed or is invalid",
EC_PUBLIC_KEY_CREATE_FAIL: "private was invalid, try again", EC_PUBLIC_KEY_TWEAK_ADD_FAIL: "tweak out of range or resulting public key is invalid",
EC_PUBLIC_KEY_TWEAK_MUL_FAIL: "tweak out of range", EC_PUBLIC_KEY_COMBINE_FAIL: "the sum of the public keys is not valid", ECDH_FAIL: "scalar was invalid (zero or overflow)",
ECDSA_SIGNATURE_TYPE_INVALID: "signature should be a Buffer", ECDSA_SIGNATURE_LENGTH_INVALID: "signature length is invalid",
ECDSA_SIGNATURE_PARSE_FAIL: "couldn't parse signature", ECDSA_SIGNATURE_PARSE_DER_FAIL: "couldn't parse DER signature", ECDSA_SIGNATURE_SERIALIZE_DER_FAIL: "couldn't serialize signature to DER format",
ECDSA_SIGN_FAIL: "nonce generation function failed or private key is invalid", ECDSA_RECOVER_FAIL: "couldn't recover public key from signature",
MSG32_TYPE_INVALID: "message should be a Buffer", MSG32_LENGTH_INVALID: "message length is invalid", OPTIONS_TYPE_INVALID: "options should be an Object",
OPTIONS_DATA_TYPE_INVALID: "options.data should be a Buffer", OPTIONS_DATA_LENGTH_INVALID: "options.data length is invalid",
OPTIONS_NONCEFN_TYPE_INVALID: "options.noncefn should be a Function", RECOVERY_ID_TYPE_INVALID: "recovery should be a Number",
RECOVERY_ID_VALUE_INVALID: "recovery should have value between -1 and 4", TWEAK_TYPE_INVALID: "tweak should be a Buffer", TWEAK_LENGTH_INVALID: "tweak length is invalid"
};
function initCompressedValue(e,s)
{
function initCompressedValue(e, s) {
return void 0 === e ? s : (assert.isBoolean(e, messages.COMPRESSED_TYPE_INVALID), e);
};
module.exports = function (E)
{
return {privateKeyVerify:function (e)
{
module.exports = function(E) {
return {
privateKeyVerify: function(e) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), 32 === e.length && E.privateKeyVerify(e);
}, privateKeyExport:function (e,s)
{
}, privateKeyExport: function(e, s) {
assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0);
var r = E.privateKeyExport(e, s);
return der.privateKeyExport(e, r, s);
}, privateKeyImport:function (e)
{
if(assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), (e = der.privateKeyImport(e)) && 32 === e.length && E.privateKeyVerify(e))
}, privateKeyImport: function(e) {
if (assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), (e = der.privateKeyImport(e)) && 32 === e.length && E.privateKeyVerify(e))
return e;
throw new Error(messages.EC_PRIVATE_KEY_IMPORT_DER_FAIL);
}, privateKeyNegate:function (e)
{
}, privateKeyNegate: function(e) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyNegate(e);
}, privateKeyModInverse:function (e)
{
}, privateKeyModInverse: function(e) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.privateKeyModInverse(e);
}, privateKeyTweakAdd:function (e,s)
{
}, privateKeyTweakAdd: function(e, s) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakAdd(e,
s);
}, privateKeyTweakMul:function (e,s)
{
}, privateKeyTweakMul: function(e, s) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), E.privateKeyTweakMul(e,
s);
}, publicKeyCreate:function (e,s)
{
}, publicKeyCreate: function(e, s) {
return assert.isBuffer(e, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(e, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyCreate(e, s);
}, publicKeyConvert:function (e,s)
{
}, publicKeyConvert: function(e, s) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
s = initCompressedValue(s, !0), E.publicKeyConvert(e, s);
}, publicKeyVerify:function (e)
{
}, publicKeyVerify: function(e) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), E.publicKeyVerify(e);
}, publicKeyTweakAdd:function (e,s,r)
{
}, publicKeyTweakAdd: function(e, s, r) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakAdd(e, s, r);
}, publicKeyTweakMul:function (e,s,r)
{
}, publicKeyTweakMul: function(e, s, r) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.TWEAK_TYPE_INVALID), assert.isBufferLength(s, 32, messages.TWEAK_LENGTH_INVALID), r = initCompressedValue(r,
!0), E.publicKeyTweakMul(e, s, r);
}, publicKeyCombine:function (e,s)
{
}, publicKeyCombine: function(e, s) {
assert.isArray(e, messages.EC_PUBLIC_KEYS_TYPE_INVALID), assert.isLengthGTZero(e, messages.EC_PUBLIC_KEYS_LENGTH_INVALID);
for(var r = 0; r < e.length; ++r)
for (var r = 0; r < e.length; ++r)
assert.isBuffer(e[r], messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e[r], 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID);
return s = initCompressedValue(s, !0), E.publicKeyCombine(e, s);
}, signatureNormalize:function (e)
{
}, signatureNormalize: function(e) {
return assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID),
E.signatureNormalize(e);
}, signatureExport:function (e)
{
}, signatureExport: function(e) {
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(e, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = E.signatureExport(e);
return der.signatureExport(s);
}, signatureImport:function (e)
{
}, signatureImport: function(e) {
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImport(e);
if(s)
if (s)
return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, signatureImportLax:function (e)
{
}, signatureImportLax: function(e) {
assert.isBuffer(e, messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isLengthGTZero(e, messages.ECDSA_SIGNATURE_LENGTH_INVALID);
var s = der.signatureImportLax(e);
if(s)
if (s)
return E.signatureImport(s);
throw new Error(messages.ECDSA_SIGNATURE_PARSE_DER_FAIL);
}, sign:function (e,s,r)
{
}, sign: function(e, s, r) {
assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID);
var _ = null, t = null;
return void 0 !== r && (assert.isObject(r, messages.OPTIONS_TYPE_INVALID), void 0 !== r.data && (assert.isBuffer(r.data, messages.OPTIONS_DATA_TYPE_INVALID),
assert.isBufferLength(r.data, 32, messages.OPTIONS_DATA_LENGTH_INVALID), _ = r.data), void 0 !== r.noncefn && (assert.isFunction(r.noncefn,
messages.OPTIONS_NONCEFN_TYPE_INVALID), t = r.noncefn)), E.sign(e, s, t, _);
}, verify:function (e,s,r)
{
}, verify: function(e, s, r) {
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isBuffer(r,
messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(r, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID), E.verify(e,
s, r);
}, recover:function (e,s,r,_)
{
}, recover: function(e, s, r, _) {
return assert.isBuffer(e, messages.MSG32_TYPE_INVALID), assert.isBufferLength(e, 32, messages.MSG32_LENGTH_INVALID), assert.isBuffer(s,
messages.ECDSA_SIGNATURE_TYPE_INVALID), assert.isBufferLength(s, 64, messages.ECDSA_SIGNATURE_LENGTH_INVALID), assert.isNumber(r,
messages.RECOVERY_ID_TYPE_INVALID), assert.isNumberInInterval(r, - 1, 4, messages.RECOVERY_ID_VALUE_INVALID), _ = initCompressedValue(_,
!0), E.recover(e, s, r, _);
}, ecdh:function (e,s)
{
}, ecdh: function(e, s) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
E.ecdh(e, s);
}, ecdhUnsafe:function (e,s,r)
{
}, ecdhUnsafe: function(e, s, r) {
return assert.isBuffer(e, messages.EC_PUBLIC_KEY_TYPE_INVALID), assert.isBufferLength2(e, 33, 65, messages.EC_PUBLIC_KEY_LENGTH_INVALID),
assert.isBuffer(s, messages.EC_PRIVATE_KEY_TYPE_INVALID), assert.isBufferLength(s, 32, messages.EC_PRIVATE_KEY_LENGTH_INVALID),
r = initCompressedValue(r, !0), E.ecdhUnsafe(e, s, r);
}};
}
};
}, global.SIGN_LIB = module.exports;

View File

@ -8,17 +8,14 @@
* Telegram: https://t.me/terafoundation
*/
(function ()
{
(function() {
'use strict';
var root = typeof window === 'object' ? window : {};
var NODE_JS = !root.JS_SHA3_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if(NODE_JS && !root.RUN_NW_CLIENT)
{
if (NODE_JS && !root.RUN_NW_CLIENT) {
root = global;
}
if(root.RUN_CLIENT)
{
if (root.RUN_CLIENT) {
root = window;
}
var COMMON_JS = !root.JS_SHA3_NO_COMMON_JS && typeof module === 'object' && module.exports;
@ -36,142 +33,118 @@
var BITS = [224, 256, 384, 512];
var SHAKE_BITS = [128, 256];
var OUTPUT_TYPES = ['hex', 'buffer', 'arrayBuffer', 'array'];
var CSHAKE_BYTEPAD = {'128':168, '256':136};
if(root.JS_SHA3_NO_NODE_JS || !Array.isArray)
{
Array.isArray = function (obj)
{
var CSHAKE_BYTEPAD = { '128': 168, '256': 136 };
if (root.JS_SHA3_NO_NODE_JS || !Array.isArray) {
Array.isArray = function(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
var createOutputMethod = function (bits,padding,outputType)
{
return function (message)
{
var createOutputMethod = function(bits, padding, outputType) {
return function(message) {
return new Keccak(bits, padding, bits).update(message)[outputType]();
};
};
var createShakeOutputMethod = function (bits,padding,outputType)
{
return function (message,outputBits)
{
var createShakeOutputMethod = function(bits, padding, outputType) {
return function(message, outputBits) {
return new Keccak(bits, padding, outputBits).update(message)[outputType]();
};
};
var createCshakeOutputMethod = function (bits,padding,outputType)
{
return function (message,outputBits,n,s)
{
var createCshakeOutputMethod = function(bits, padding, outputType) {
return function(message, outputBits, n, s) {
return methods['cshake' + bits].update(message, outputBits, n, s)[outputType]();
};
};
var createKmacOutputMethod = function (bits,padding,outputType)
{
return function (key,message,outputBits,s)
{
var createKmacOutputMethod = function(bits, padding, outputType) {
return function(key, message, outputBits, s) {
return methods['kmac' + bits].update(key, message, outputBits, s)[outputType]();
};
};
var createOutputMethods = function (method,createMethod,bits,padding)
{
for(var i = 0; i < OUTPUT_TYPES.length; ++i)
{
var createOutputMethods = function(method, createMethod, bits, padding) {
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createMethod(bits, padding, type);
}
return method;
};
var createMethod = function (bits,padding,outputs)
{
var createMethod = function(bits, padding, outputs) {
var method = createOutputMethod(bits, padding, outputs);
method.create = function ()
{
method.create = function() {
return new Keccak(bits, padding, bits);
};
method.update = function (message)
{
method.update = function(message) {
return method.create().update(message);
};
return createOutputMethods(method, createOutputMethod, bits, padding);
};
var createMethodArray = function (bits,padding)
{
var createMethodArray = function(bits, padding) {
var method = createOutputMethod(bits, padding, 'array');
method.create = function ()
{
method.create = function() {
return new Keccak(bits, padding, bits);
};
method.update = function (message)
{
method.update = function(message) {
return method.create().update(message);
};
return createOutputMethods(method, createOutputMethod, bits, padding);
};
var createShakeMethod = function (bits,padding)
{
var createShakeMethod = function(bits, padding) {
var method = createShakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits)
{
method.create = function(outputBits) {
return new Keccak(bits, padding, outputBits);
};
method.update = function (message,outputBits)
{
method.update = function(message, outputBits) {
return method.create(outputBits).update(message);
};
return createOutputMethods(method, createShakeOutputMethod, bits, padding);
};
var createCshakeMethod = function (bits,padding)
{
var createCshakeMethod = function(bits, padding) {
var w = CSHAKE_BYTEPAD[bits];
var method = createCshakeOutputMethod(bits, padding, 'hex');
method.create = function (outputBits,n,s)
{
if(!n && !s)
{
method.create = function(outputBits, n, s) {
if (!n && !s) {
return methods['shake' + bits].create(outputBits);
}
else
{
else {
return new Keccak(bits, padding, outputBits).bytepad([n, s], w);
}
};
method.update = function (message,outputBits,n,s)
{
method.update = function(message, outputBits, n, s) {
return method.create(outputBits, n, s).update(message);
};
return createOutputMethods(method, createCshakeOutputMethod, bits, padding);
};
var createKmacMethod = function (bits,padding)
{
var createKmacMethod = function(bits, padding) {
var w = CSHAKE_BYTEPAD[bits];
var method = createKmacOutputMethod(bits, padding, 'hex');
method.create = function (key,outputBits,s)
{
method.create = function(key, outputBits, s) {
return new Kmac(bits, padding, outputBits).bytepad(['KMAC', s], w).bytepad([key], w);
};
method.update = function (key,message,outputBits,s)
{
method.update = function(key, message, outputBits, s) {
return method.create(key, outputBits, s).update(message);
};
return createOutputMethods(method, createKmacOutputMethod, bits, padding);
};
var algorithms = [{name:'keccak', padding:KECCAK_PADDING, bits:BITS, createMethod:createMethod}, {name:'sha3', padding:PADDING,
bits:BITS, createMethod:createMethod, outputs:'hex'}, {name:'sha3_array', padding:PADDING, bits:BITS, createMethod:createMethod,
outputs:'array'}, {name:'sha3_buf', padding:PADDING, bits:BITS, createMethod:createMethod, outputs:'buffer'}, {name:'shake',
padding:SHAKE_PADDING, bits:SHAKE_BITS, createMethod:createShakeMethod}, {name:'cshake', padding:CSHAKE_PADDING, bits:SHAKE_BITS,
createMethod:createCshakeMethod}, {name:'kmac', padding:CSHAKE_PADDING, bits:SHAKE_BITS, createMethod:createKmacMethod}];
var algorithms = [{ name: 'keccak', padding: KECCAK_PADDING, bits: BITS, createMethod: createMethod }, {
name: 'sha3', padding: PADDING,
bits: BITS, createMethod: createMethod, outputs: 'hex'
}, {
name: 'sha3_array', padding: PADDING, bits: BITS, createMethod: createMethod,
outputs: 'array'
}, { name: 'sha3_buf', padding: PADDING, bits: BITS, createMethod: createMethod, outputs: 'buffer' }, {
name: 'shake',
padding: SHAKE_PADDING, bits: SHAKE_BITS, createMethod: createShakeMethod
}, {
name: 'cshake', padding: CSHAKE_PADDING, bits: SHAKE_BITS,
createMethod: createCshakeMethod
}, { name: 'kmac', padding: CSHAKE_PADDING, bits: SHAKE_BITS, createMethod: createKmacMethod }];
var methods = {}, methodNames = [];
for(var i = 0; i < algorithms.length; ++i)
{
for (var i = 0; i < algorithms.length; ++i) {
var algorithm = algorithms[i];
var bits = algorithm.bits;
for(var j = 0; j < bits.length; ++j)
{
for (var j = 0; j < bits.length; ++j) {
var methodName = algorithm.name + '_' + bits[j];
methodNames.push(methodName);
methods[methodName] = algorithm.createMethod(bits[j], algorithm.padding, algorithm.outputs);
if(algorithm.name !== 'sha3')
{
if (algorithm.name !== 'sha3') {
var newMethodName = algorithm.name + bits[j];
methodNames.push(newMethodName);
methods[newMethodName] = methods[methodName];
@ -179,8 +152,7 @@
}
}
function Keccak(bits,padding,outputBits)
{
function Keccak(bits, padding, outputBits) {
this.blocks = [];
this.s = [];
this.padding = padding;
@ -192,71 +164,55 @@ function Keccak(bits,padding,outputBits)
this.byteCount = this.blockCount << 2;
this.outputBlocks = outputBits >> 5;
this.extraBytes = (outputBits & 31) >> 3;
for(var i = 0; i < 50; ++i)
{
for (var i = 0; i < 50; ++i) {
this.s[i] = 0;
}
};
Keccak.prototype.update = function (message)
{
Keccak.prototype.update = function(message) {
var notString = typeof message !== 'string';
if(notString && message.constructor === root.ArrayBuffer)
{
if (notString && message.constructor === root.ArrayBuffer) {
TO_ERROR_LOG("SHA3", 10, 'ERROR: Error type ArrayBuffer, use Uint8Array instead!');
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
var length = message.length;
if(notString)
{
if(typeof length !== 'number' || !Array.isArray(message) && !(ARRAY_BUFFER && ArrayBuffer.isView(message)))
{
if (notString) {
if (typeof length !== 'number' || !Array.isArray(message) && !(ARRAY_BUFFER && ArrayBuffer.isView(message))) {
TO_ERROR_LOG("SHA3", 20, 'ERROR: Input is invalid type, message=' + JSON.stringify(message));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
var blocks = this.blocks, byteCount = this.byteCount, blockCount = this.blockCount, index = 0, s = this.s, i, code;
while(index < length)
{
if(this.reset)
{
while (index < length) {
if (this.reset) {
this.reset = false;
blocks[0] = this.block;
for(i = 1; i < blockCount + 1; ++i)
{
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;
}
}
if(notString)
{
for(i = this.start; index < length && i < byteCount; ++index)
{
if (notString) {
for (i = this.start; index < length && i < byteCount; ++index) {
blocks[i >> 2] |= message[index] << SHIFT[i++ & 3];
}
}
else
{
for(i = this.start; index < length && i < byteCount; ++index)
{
else {
for (i = this.start; index < length && i < byteCount; ++index) {
code = message.charCodeAt(index);
if(code < 0x80)
{
if (code < 0x80) {
blocks[i >> 2] |= code << SHIFT[i++ & 3];
}
else
if(code < 0x800)
{
if (code < 0x800) {
blocks[i >> 2] |= (0xc0 | (code >> 6)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else
if(code < 0xd800 || code >= 0xe000)
{
if (code < 0xd800 || code >= 0xe000) {
blocks[i >> 2] |= (0xe0 | (code >> 12)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
else
{
else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >> 2] |= (0xf0 | (code >> 18)) << SHIFT[i++ & 3];
blocks[i >> 2] |= (0x80 | ((code >> 12) & 0x3f)) << SHIFT[i++ & 3];
@ -266,91 +222,73 @@ function Keccak(bits,padding,outputBits)
}
}
this.lastByteIndex = i;
if(i >= byteCount)
{
if (i >= byteCount) {
this.start = i - byteCount;
this.block = blocks[blockCount];
for(i = 0; i < blockCount; ++i)
{
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];
}
f(s);
this.reset = true;
}
else
{
else {
this.start = i;
}
}
return this;
};
Keccak.prototype.encode = function (x,right)
{
Keccak.prototype.encode = function(x, right) {
var o = x & 255, n = 1;
var bytes = [o];
x = x >> 8;
o = x & 255;
while(o > 0)
{
while (o > 0) {
bytes.unshift(o);
x = x >> 8;
o = x & 255;
++n;
}
if(right)
{
if (right) {
bytes.push(n);
}
else
{
else {
bytes.unshift(n);
}
this.update(bytes);
return bytes.length;
};
Keccak.prototype.encodeString = function (str)
{
Keccak.prototype.encodeString = function(str) {
str = str || '';
var notString = typeof str !== 'string';
if(notString && str.constructor === root.ArrayBuffer)
{
if (notString && str.constructor === root.ArrayBuffer) {
str = new Uint8Array(str);
}
var length = str.length;
if(notString)
{
if(typeof length !== 'number' || !Array.isArray(str) && !(ARRAY_BUFFER && ArrayBuffer.isView(str)))
{
if (notString) {
if (typeof length !== 'number' || !Array.isArray(str) && !(ARRAY_BUFFER && ArrayBuffer.isView(str))) {
TO_ERROR_LOG("SHA3", 30, 'ERROR: Input is invalid type, str=' + JSON.stringify(str));
return [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
var bytes = 0;
if(notString)
{
if (notString) {
bytes = length;
}
else
{
for(var i = 0; i < str.length; ++i)
{
else {
for (var i = 0; i < str.length; ++i) {
var code = str.charCodeAt(i);
if(code < 0x80)
{
if (code < 0x80) {
bytes += 1;
}
else
if(code < 0x800)
{
if (code < 0x800) {
bytes += 2;
}
else
if(code < 0xd800 || code >= 0xe000)
{
if (code < 0xd800 || code >= 0xe000) {
bytes += 3;
}
else
{
else {
code = 0x10000 + (((code & 0x3ff) << 10) | (str.charCodeAt(++i) & 0x3ff));
bytes += 4;
}
@ -360,11 +298,9 @@ function Keccak(bits,padding,outputBits)
this.update(str);
return bytes;
};
Keccak.prototype.bytepad = function (strs,w)
{
Keccak.prototype.bytepad = function(strs, w) {
var bytes = this.encode(w);
for(var i = 0; i < strs.length; ++i)
{
for (var i = 0; i < strs.length; ++i) {
bytes += this.encodeString(strs[i]);
}
var paddingBytes = w - bytes % w;
@ -373,104 +309,82 @@ function Keccak(bits,padding,outputBits)
this.update(zeros);
return this;
};
Keccak.prototype.finalize = function ()
{
Keccak.prototype.finalize = function() {
var blocks = this.blocks, i = this.lastByteIndex, blockCount = this.blockCount, s = this.s;
blocks[i >> 2] |= this.padding[i & 3];
if(this.lastByteIndex === this.byteCount)
{
if (this.lastByteIndex === this.byteCount) {
blocks[0] = blocks[blockCount];
for(i = 1; i < blockCount + 1; ++i)
{
for (i = 1; i < blockCount + 1; ++i) {
blocks[i] = 0;
}
}
blocks[blockCount - 1] |= 0x80000000;
for(i = 0; i < blockCount; ++i)
{
for (i = 0; i < blockCount; ++i) {
s[i] ^= blocks[i];
}
f(s);
};
Keccak.prototype.toString = Keccak.prototype.hex = function ()
{
Keccak.prototype.toString = Keccak.prototype.hex = function() {
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var hex = '', block;
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
while (j < outputBlocks) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
block = s[i];
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F] + HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F] + HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F] + HEX_CHARS[(block >> 28) & 0x0F] + HEX_CHARS[(block >> 24) & 0x0F];
}
if(j % blockCount === 0)
{
if (j % blockCount === 0) {
f(s);
i = 0;
}
}
if(extraBytes)
{
if (extraBytes) {
block = s[i];
if(extraBytes > 0)
{
if (extraBytes > 0) {
hex += HEX_CHARS[(block >> 4) & 0x0F] + HEX_CHARS[block & 0x0F];
}
if(extraBytes > 1)
{
if (extraBytes > 1) {
hex += HEX_CHARS[(block >> 12) & 0x0F] + HEX_CHARS[(block >> 8) & 0x0F];
}
if(extraBytes > 2)
{
if (extraBytes > 2) {
hex += HEX_CHARS[(block >> 20) & 0x0F] + HEX_CHARS[(block >> 16) & 0x0F];
}
}
return hex;
};
Keccak.prototype.arrayBuffer = function ()
{
Keccak.prototype.arrayBuffer = function() {
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var bytes = this.outputBits >> 3;
var buffer;
if(extraBytes)
{
if (extraBytes) {
buffer = new ArrayBuffer((outputBlocks + 1) << 2);
}
else
{
else {
buffer = new ArrayBuffer(bytes);
}
var array = new Uint32Array(buffer);
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
while (j < outputBlocks) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
array[j] = s[i];
}
if(j % blockCount === 0)
{
if (j % blockCount === 0) {
f(s);
}
}
if(extraBytes)
{
if (extraBytes) {
array[i] = s[i];
buffer = buffer.slice(0, bytes);
}
return buffer;
};
Keccak.prototype.buffer = Keccak.prototype.arrayBuffer;
Keccak.prototype.digest = Keccak.prototype.array = function ()
{
Keccak.prototype.digest = Keccak.prototype.array = function() {
this.finalize();
var blockCount = this.blockCount, s = this.s, outputBlocks = this.outputBlocks, extraBytes = this.extraBytes, i = 0, j = 0;
var array = [], offset, block;
while(j < outputBlocks)
{
for(i = 0; i < blockCount && j < outputBlocks; ++i, ++j)
{
while (j < outputBlocks) {
for (i = 0; i < blockCount && j < outputBlocks; ++i, ++j) {
offset = j << 2;
block = s[i];
array[offset] = block & 0xFF;
@ -478,48 +392,39 @@ function Keccak(bits,padding,outputBits)
array[offset + 2] = (block >> 16) & 0xFF;
array[offset + 3] = (block >> 24) & 0xFF;
}
if(j % blockCount === 0)
{
if (j % blockCount === 0) {
f(s);
}
}
if(extraBytes)
{
if (extraBytes) {
offset = j << 2;
block = s[i];
if(extraBytes > 0)
{
if (extraBytes > 0) {
array[offset] = block & 0xFF;
}
if(extraBytes > 1)
{
if (extraBytes > 1) {
array[offset + 1] = (block >> 8) & 0xFF;
}
if(extraBytes > 2)
{
if (extraBytes > 2) {
array[offset + 2] = (block >> 16) & 0xFF;
}
}
return array;
};
function Kmac(bits,padding,outputBits)
{
function Kmac(bits, padding, outputBits) {
Keccak.call(this, bits, padding, outputBits);
};
Kmac.prototype = new Keccak();
Kmac.prototype.finalize = function ()
{
Kmac.prototype.finalize = function() {
this.encode(this.outputBits, true);
return Keccak.prototype.finalize.call(this);
};
var f = function (s)
{
var f = function(s) {
var h, l, n, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15,
b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40,
b41, b42, b43, b44, b45, b46, b47, b48, b49;
for(n = 0; n < 48; n += 2)
{
for (n = 0; n < 48; n += 2) {
c0 = s[0] ^ s[10] ^ s[20] ^ s[30] ^ s[40];
c1 = s[1] ^ s[11] ^ s[21] ^ s[31] ^ s[41];
c2 = s[2] ^ s[12] ^ s[22] ^ s[32] ^ s[42];
@ -697,58 +602,47 @@ function Kmac(bits,padding,outputBits)
root.sha3_str = methods.sha3_256;
root.sha3_array_256 = methods.sha3_array_256;
root.sha3 = methods.sha3_array_256;
root.sha = function (data)
{
root.sha = function(data) {
return meshhash(methods.sha3_256(data));
};
root.shaarr = function (data)
{
root.shaarr = function(data) {
return meshhash(methods.sha3_array_256(data));
};
root.shabuf = function (data)
{
root.shabuf = function(data) {
return Buffer.from(shaarr(data));
};
root.shabuf = function (data)
{
root.shabuf = function(data) {
return Buffer.from(shaarr(data));
};
root.SHA3BUF = function (data,num)
{
root.SHA3BUF = function(data, num) {
return Buffer.from(SHA3ARR(data, num));
};
root.SHA3ARR = function (data,num)
{
if(!NEW_SIGN_TIME || !num || num >= NEW_SIGN_TIME)
root.SHA3ARR = function(data, num) {
if (!NEW_SIGN_TIME || !num || num >= NEW_SIGN_TIME)
return sha3(data);
else
return meshhash(methods.sha3_array_256(data));
};
root.shaarrblock = function (data,num)
{
root.shaarrblock = function(data, num) {
return meshhash(methods.sha3_array_256(data), num);
};
})();
function meshhash(hash,num)
{
function meshhash(hash, num) {
var regs = [hash[3], hash[2], hash[1], hash[0]];
var mem = [];
for(var i = 0; i < 16; i++)
{
for (var i = 0; i < 16; i++) {
mem[i] = hash[i * 2] + (hash[i * 2 + 1] << 8);
}
var WasGoto = 0;
var L = 0;
for(var i = 0; i < 64; i++)
{
for (var i = 0; i < 64; i++) {
var c = hash[L & 31];
L++;
var a = (c >> 4) & 0xF;
var b = c & 0xF;
var r = c & 0x3;
switch(a)
{
switch (a) {
case 0:
regs[0] = regs[0] + regs[r];
break;
@ -768,15 +662,13 @@ function meshhash(hash,num)
regs[0] = regs[0] + regs[1] + regs[2] + regs[3];
break;
case 8:
if((regs[0] & 0xFFFF) < 32768 && !WasGoto)
{
if ((regs[0] & 0xFFFF) < 32768 && !WasGoto) {
L = 32 + L - b;
WasGoto = 1;
}
break;
case 9:
if((regs[0] & 0xFFFF) > 32768 && !WasGoto)
{
if ((regs[0] & 0xFFFF) > 32768 && !WasGoto) {
L += b;
WasGoto = 1;
}
@ -786,16 +678,14 @@ function meshhash(hash,num)
}
var index1 = regs[0] & 0xF;
var index2 = (regs[0] >> 8) & 0xF;
if(index1 !== index2)
{
if (index1 !== index2) {
var temp = mem[index1];
mem[index1] = mem[index2];
mem[index2] = temp;
}
}
var ret = [];
for(var i = 0; i < 16; i++)
{
for (var i = 0; i < 16; i++) {
ret[i * 2] = mem[i] & 0xFF;
ret[i * 2 + 1] = mem[i] >> 8;
}

File diff suppressed because it is too large Load Diff

View File

@ -19,65 +19,56 @@ var MaxBlockNum = 0;
var DelList = {};
var WasAccountsDataStr;
function SetAccountsData(Data,AccountsDataStr)
{
if(!Data || !Data.result)
return ;
if($("idBtRun"))
function SetAccountsData(Data, AccountsDataStr) {
if (!Data || !Data.result)
return;
if ($("idBtRun"))
$("idBtRun").style.display = (Data.arr.length ? '' : 'none');
if(AccountsDataStr === WasAccountsDataStr)
return ;
if (AccountsDataStr === WasAccountsDataStr)
return;
WasAccountsDataStr = AccountsDataStr;
var arr = Data.arr;
var Select = $("idAccount");
if(arr.length !== Select.options.length)
{
if (arr.length !== Select.options.length) {
var options = Select.options;
options.length = arr.length;
}
MaxBlockNum = GetCurrentBlockNumByTime();
SetGridData(arr, "grid_accounts", "idMyTotalSum");
for(var i = 0; arr && i < arr.length; i++)
{
for (var i = 0; arr && i < arr.length; i++) {
var Item = arr[i];
Item.MyAccount = true;
var Num = ParseNum(Item.Num);
if(!MapAccounts[Num])
if (!MapAccounts[Num])
MapAccounts[Num] = {};
CopyObjKeys(MapAccounts[Num], Item);
var option = Select.options[i];
var StrText = GetAccountText(Item, Num, 1);
if(option.text !== StrText)
if (option.text !== StrText)
CheckNameAccTo();
option.value = Num;
option.text = StrText;
}
var CurentValue = LoadMapAfter["idAccount"];
if(CurentValue)
{
if (CurentValue) {
Select.value = CurentValue;
delete LoadMapAfter["idAccount"];
}
SetCurCurencyName();
};
function CurTransactionToForm(bForce)
{
function CurTransactionToForm(bForce) {
var Item = $("idTransaction");
if(Item && (Item.className === "" || bForce))
if (Item && (Item.className === "" || bForce))
Item.value = GetJSONFromTransaction(CurrentTR);
};
function CheckNameAccTo()
{
function CheckNameAccTo() {
MaxBlockNum = GetCurrentBlockNumByTime();
var ToID = ParseNum($("idTo").value);
if(!MapAccounts[ToID] || (MapAccounts[ToID].MustUpdate && MapAccounts[ToID].MustUpdate >= MaxBlockNum))
{
GetData("GetAccountList", {StartNum:ToID}, function (Data)
{
if(Data && Data.result === 1 && Data.arr.length)
{
if (!MapAccounts[ToID] || (MapAccounts[ToID].MustUpdate && MapAccounts[ToID].MustUpdate >= MaxBlockNum)) {
GetData("GetAccountList", { StartNum: ToID }, function(Data) {
if (Data && Data.result === 1 && Data.arr.length) {
var Item = Data.arr[0];
Item.UpdateData = Date.now();
MapAccounts[Item.Num] = Item;
@ -88,199 +79,173 @@ function CheckNameAccTo()
SetNameAccTo();
};
function SetNameAccTo()
{
function SetNameAccTo() {
var Str = "";
var ToID = ParseNum($("idTo").value);
var Item = MapAccounts[ToID];
var element = $("idNameTo");
var StrTo = GetAccountText(Item, ToID, 1);
if(!element)
{
if (!element) {
element = $("idNameTo2");
}
else
{
else {
StrTo = "To: " + StrTo;
}
if(element.innerText !== StrTo)
{
if (element.innerText !== StrTo) {
element.innerText = StrTo;
if(Item && Item.MyAccount)
if (Item && Item.MyAccount)
element.className = "smallbold";
else
element.className = "";
}
};
function GetAccountText(Item,Num,bGetSum)
{
if(Item)
{
function GetAccountText(Item, Num, bGetSum) {
if (Item) {
var text = Item.Name;
if(!text || text.length === 0)
if (!text || text.length === 0)
text = Num;
else
text = "" + Num + ". " + text;
if(bGetSum)
{
if (bGetSum) {
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency);
text += " (" + StrSum + ")";
}
return text;
}
else
{
else {
return Num;
}
};
function OnEditIdTo()
{
function OnEditIdTo() {
CheckNameAccTo();
OnEditTransactionFields();
};
function OnEditTransactionFields()
{
if(IsVisibleBlock("edit_transaction"))
function OnEditTransactionFields() {
if (IsVisibleBlock("edit_transaction"))
CreateTransaction();
SetCurCurencyName();
SaveValues();
};
function SetCurCurencyName()
{
function SetCurCurencyName() {
var idCoin = $("idCoinName");
if(!idCoin)
return ;
if (!idCoin)
return;
var Num = ParseNum($("idAccount").value);
var Item = MapAccounts[Num];
if(Item)
{
if (Item) {
idCoin.innerText = CurrencyName(Item.Currency);
}
};
function CreateTransaction(F,CheckErr,Run)
{
function CreateTransaction(F, CheckErr, Run) {
CheckNameAccTo();
CheckSending();
var FromID = ParseNum($("idAccount").value);
if(CheckErr && FromID === 0)
{
if (CheckErr && FromID === 0) {
SetError("Select valid 'From account'");
return ;
return;
}
var StrTo = $("idTo").value.trim();
var bFindAcc = 0;
var ToPubKey = "";
var ToID = ParseNum(StrTo);
if(StrTo !== "" + ToID)
{
if(StrTo.length === 66 && (StrTo.substr(0, 2) === "02" || StrTo.substr(0, 2) === "03") && IsHexStr(StrTo))
{
if (StrTo !== "" + ToID) {
if (StrTo.length === 66 && (StrTo.substr(0, 2) === "02" || StrTo.substr(0, 2) === "03") && IsHexStr(StrTo)) {
ToID = 0;
ToPubKey = StrTo;
if(ToPubKey === PubKeyStr)
if (ToPubKey === PubKeyStr)
bFindAcc = 1;
}
else
{
if(CheckErr)
else {
if (CheckErr)
SetError("Valid 'Pay to' - required!");
return ;
return;
}
}
if(CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem)
{
if (CheckErr && ToID <= 0 && ToPubKey === "" && !AttachItem) {
SetError("Valid 'Pay to' - required!");
return ;
return;
}
var Description = $("idDescription").value.substr(0, 200);
var StrSum = $("idSumSend").value;
var indDot = StrSum.indexOf(".");
if(indDot >= 0)
{
if (indDot >= 0) {
var StrTER = StrSum.substr(0, indDot);
var StrCENT = StrSum.substr(indDot + 1);
}
else
{
else {
var StrTER = StrSum;
var StrCENT = "0";
}
StrCENT = StrCENT + "000000000";
var Coin = {SumCOIN:ParseNum(StrTER), SumCENT:ParseNum(StrCENT.substr(0, 9))};
var Coin = { SumCOIN: ParseNum(StrTER), SumCENT: ParseNum(StrCENT.substr(0, 9)) };
var OperationID = 0;
var Item = MapAccounts[FromID];
if(Item)
{
if (Item) {
OperationID = Item.Value.OperationID;
}
var AttachBody = [];
if(AttachItem)
{
if (AttachItem) {
AttachBody = AttachItem.Data.Body;
if(!AttachBody)
if (!AttachBody)
AttachBody = [];
}
var ToPubKeyArr = [];
if(ToPubKey)
if (ToPubKey)
ToPubKeyArr = GetArrFromHex(ToPubKey);
var TR = {Type:111, Version:3, Reserve:0, FromID:FromID, OperationID:OperationID, To:[{PubKey:ToPubKeyArr, ID:ToID, SumCOIN:Coin.SumCOIN,
SumCENT:Coin.SumCENT}], Description:Description, Body:AttachBody, Sign:CurrentTR.Sign, };
Object.defineProperties(TR, {bFindAcc:{configurable:true, writable:true, enumerable:false, value:bFindAcc}});
Object.defineProperties(TR, {Run:{configurable:true, writable:true, enumerable:false, value:Run}});
if(JSON.stringify(TR) === JSON.stringify(CurrentTR))
{
if(F)
var TR = {
Type: 111, Version: 3, Reserve: 0, FromID: FromID, OperationID: OperationID, To: [{
PubKey: ToPubKeyArr, ID: ToID, SumCOIN: Coin.SumCOIN,
SumCENT: Coin.SumCENT
}], Description: Description, Body: AttachBody, Sign: CurrentTR.Sign,
};
Object.defineProperties(TR, { bFindAcc: { configurable: true, writable: true, enumerable: false, value: bFindAcc } });
Object.defineProperties(TR, { Run: { configurable: true, writable: true, enumerable: false, value: Run } });
if (JSON.stringify(TR) === JSON.stringify(CurrentTR)) {
if (F)
F(CurrentTR);
return ;
return;
}
CurrentTR = TR;
GetSignTransaction(TR, "", function (TR)
{
GetSignTransaction(TR, "", function(TR) {
CurTransactionToForm(true);
if(F)
if (F)
F(TR);
});
};
function SignJSON(F)
{
if($("idSignJSON").disabled)
return ;
function SignJSON(F) {
if ($("idSignJSON").disabled)
return;
var TR = GetTransactionFromJSON();
if(!TR)
return ;
if (!TR)
return;
CurrentTR = TR;
GetSignTransaction(TR, "", function (TR)
{
GetSignTransaction(TR, "", function(TR) {
CurTransactionToForm(true);
if(F)
if (F)
F();
});
};
function CheckSending(bToStatus)
{
function CheckSending(bToStatus) {
MaxBlockNum = GetCurrentBlockNumByTime();
var CanSend = IsPrivateMode();
var StrButton = "Send";
var StrButtonSign = "Sign JSON";
if(!CanSend)
{
if (!CanSend) {
StrButton = " ";
StrButtonSign = " ";
}
if(CanSend)
{
if (CanSend) {
var FromID = ParseNum($("idAccount").value);
var Item = MapAccounts[FromID];
if(Item && Item.NextSendTime && Item.NextSendTime > MaxBlockNum)
{
if(bToStatus)
if (Item && Item.NextSendTime && Item.NextSendTime > MaxBlockNum) {
if (bToStatus)
SetStatus("Transaction was sending. Wait... (" + Item.LastTransactionText + ")");
CanSend = false;
StrButton = "Wait...";
@ -293,31 +258,26 @@ function CheckSending(bToStatus)
return CanSend;
};
function AddWhiteList()
{
function AddWhiteList() {
var ToID = ParseNum($("idTo").value);
if(ToID && $("idWhiteOnSend").checked)
if (ToID && $("idWhiteOnSend").checked)
Storage.setItem("White:" + ToID, 1);
};
function SendMoneyBefore()
{
if($("idSendButton").disabled)
return ;
function SendMoneyBefore() {
if ($("idSendButton").disabled)
return;
var ToID = ParseNum($("idTo").value);
var Item = MapAccounts[ToID];
if(Storage.getItem("White:" + ToID) || !$("idSumSend").value || Item && Item.MyAccount)
{
if (Storage.getItem("White:" + ToID) || !$("idSumSend").value || Item && Item.MyAccount) {
SendMoney();
}
else
{
else {
var CoinAmount = COIN_FROM_FLOAT($("idSumSend").value);
var StrTo = " to " + GetAccountText(Item, ToID);
$("idWhiteOnSend").checked = 0;
$("idOnSendText").innerHTML = "<B style='color:#ff4534'>" + STRING_FROM_COIN(CoinAmount) + "</B> " + $("idCoinName").innerText + StrTo;
if($("idSumSend").value >= 100000)
{
if ($("idSumSend").value >= 100000) {
$("idOnSendText").innerHTML += "<BR><DIV style='color: yellow;'>WARNING: You are about to send a very large amount!</DIV>";
}
SetVisibleBlock("idBlockOnSend", 1);
@ -325,31 +285,26 @@ function SendMoneyBefore()
}
};
function SendMoney2()
{
function SendMoney2() {
AddWhiteList();
SendMoney();
};
function SendMoney()
{
if(!CanSendTransaction)
{
function SendMoney() {
if (!CanSendTransaction) {
SetError("Can't Send transaction");
return ;
return;
}
CheckSending(true);
if($("idSendButton").disabled)
return ;
if ($("idSendButton").disabled)
return;
SetVisibleBlock("idBlockOnSend", 0);
CreateTransaction(SendMoneyTR, true, ClearAttach);
};
function GetJSONFromTransaction(TR)
{
function GetJSONFromTransaction(TR) {
var TR2 = JSON.parse(JSON.stringify(TR));
for(var i = 0; i < TR2.To.length; i++)
{
for (var i = 0; i < TR2.To.length; i++) {
var Item = TR2.To[i];
Item.PubKey = GetHexFromArr(Item.PubKey);
}
@ -359,24 +314,19 @@ function GetJSONFromTransaction(TR)
return Str;
};
function GetTransactionFromJSON()
{
function GetTransactionFromJSON() {
var Str = $("idTransaction").value;
try
{
try {
var TR = JSON.parse(Str);
}
catch(e)
{
catch (e) {
SetError(e);
return undefined;
}
for(var i = 0; i < TR.To.length; i++)
{
for (var i = 0; i < TR.To.length; i++) {
var Item = TR.To[i];
Item.PubKey = GetArrFromHex(Item.PubKey);
if(Item.SumTER && Item.SumCOIN === undefined)
{
if (Item.SumTER && Item.SumCOIN === undefined) {
Item.SumCOIN = Item.SumTER;
delete Item.SumTER;
}
@ -386,68 +336,58 @@ function GetTransactionFromJSON()
return TR;
};
function SendMoneyJSON()
{
if(!CanSendTransaction)
{
function SendMoneyJSON() {
if (!CanSendTransaction) {
SetError("Can't Send transaction");
return ;
return;
}
var TR = GetTransactionFromJSON();
if(!TR)
return ;
if (!TR)
return;
SendMoneyTR(TR);
};
function SignAndSendFromJSON()
{
function SignAndSendFromJSON() {
SignJSON(SendMoneyJSON);
};
function GetTransactionText(TR,key)
{
function GetTransactionText(TR, key) {
var Str;
if(TR)
{
if(TR.Type === TYPE_TRANSACTION_CREATE)
{
if (TR) {
if (TR.Type === TYPE_TRANSACTION_CREATE) {
Str = "New account " + TR.Name.substr(0, 20);
}
else
if(TR.Type === 111)
{
if (TR.Type === 111) {
var MapItem = {};
var ValueTotal = {SumCOIN:0, SumCENT:0};
var ValueTotal = { SumCOIN: 0, SumCENT: 0 };
Str = "" + TR.FromID + "/" + TR.OperationID + " to ";
for(var i = 0; i < TR.To.length; i++)
{
for (var i = 0; i < TR.To.length; i++) {
var Item = TR.To[i];
if(Item.ID === TR.FromID || MapItem[Item.ID])
if (Item.ID === TR.FromID || MapItem[Item.ID])
continue;
MapItem[Item.ID] = 1;
ADD(ValueTotal, Item);
if(i === 0)
if (i === 0)
Str += "[";
if(Str.length < 16)
{
if(i > 0)
if (Str.length < 16) {
if (i > 0)
Str += ",";
if(Item.ID || (Item.PubKey && Item.PubKey.length !== 66))
if (Item.ID || (Item.PubKey && Item.PubKey.length !== 66))
Str += Item.ID;
else
Str += GetHexFromArr(Item.PubKey).substr(0, 8);
}
else
if(Str.substr(Str.length - 1) !== ".")
if (Str.substr(Str.length - 1) !== ".")
Str += "...";
}
Str += "] " + SUM_TO_STRING(ValueTotal);
Str += " " + (TR.Description.substr(0, 20)).replace(/\n/g, "");
}
}
else
{
if(key)
else {
if (key)
Str = key;
else
Str = "";
@ -455,18 +395,15 @@ function GetTransactionText(TR,key)
return Str;
};
function SendMoneyTR(TR)
{
function SendMoneyTR(TR) {
var Body = GetArrFromTR(TR);
WriteArr(Body, TR.Sign, 64);
Body.length += 12;
SendTransaction(Body, TR, undefined, function (Err,TR,Body)
{
if(Err)
return ;
SendTransaction(Body, TR, undefined, function(Err, TR, Body) {
if (Err)
return;
var Item = MapAccounts[TR.FromID];
if(Item)
{
if (Item) {
var key = GetHexFromArr(sha3(Body));
var BlockNum = GetCurrentBlockNumByTime();
Item.LastTransactionText = GetTransactionText(TR);
@ -477,37 +414,31 @@ function SendMoneyTR(TR)
});
};
function ClearTransaction()
{
function ClearTransaction() {
PayList = [];
ClearAttach();
CheckSendList(1);
var arr = ["idAccount", "idTo", "idSumSend", "idDescription"];
for(var i = 0; i < arr.length; i++)
{
for (var i = 0; i < arr.length; i++) {
$(arr[i]).value = "";
}
SaveValues();
CreateTransaction();
};
function StartEditTransactionJSON()
{
function StartEditTransactionJSON() {
var Item = $("idTransaction");
Item.className = "smallbold";
};
function EditJSONTransaction()
{
function EditJSONTransaction() {
var name = "edit_transaction";
var Item = $("idTransaction");
if(IsVisibleBlock(name))
{
if (IsVisibleBlock(name)) {
SetVisibleBlock(name, false);
Item.className = "";
}
else
{
else {
CreateTransaction();
SetVisibleBlock(name, true);
Item.className = "";
@ -515,16 +446,14 @@ function EditJSONTransaction()
};
var glNumPayCount = 0;
function GetInvoiceHTML(item,onclick,classstr)
{
if(!item.num)
{
function GetInvoiceHTML(item, onclick, classstr) {
if (!item.num) {
glNumPayCount++;
item.num = glNumPayCount;
}
var idname = "idSendInvoice" + item.num;
var value = "";
if(item.Data.Amount)
if (item.Data.Amount)
value += "<B>" + item.Data.Amount + "</B> Tera";
else
value += "<B style='color:green'>No pay</B>";
@ -532,55 +461,46 @@ function GetInvoiceHTML(item,onclick,classstr)
return "<button id='" + idname + "' onclick='" + onclick + "' class='" + classstr + "'>" + value + "</button>";
};
function AddSendList(item)
{
PayList.push({Data:item});
function AddSendList(item) {
PayList.push({ Data: item });
};
function CheckSendList(bRedraw)
{
function CheckSendList(bRedraw) {
TitleWarning = PayList.length;
if(AttachItem)
if (AttachItem)
TitleWarning++;
var Str = Storage.getItem("InvoiceList");
if(!Str && !bRedraw)
return ;
if(!bRedraw)
{
if (!Str && !bRedraw)
return;
if (!bRedraw) {
SelectTab("TabSend");
}
if(Str)
{
if (Str) {
var arr = JSON.parse(Str);
for(var i = 0; i < arr.length; i++)
{
for (var i = 0; i < arr.length; i++) {
AddSendList(arr[i]);
}
Storage.setItem("InvoiceList", "");
}
var idList = $("idSendList");
if(PayList.length)
{
if (PayList.length) {
idList.innerHTML = "<DIV id='PaiListInfo'>Select the item you want to sign (pay) and send to blockchain:</DIV>";
for(var i = 0; i < PayList.length; i++)
{
for (var i = 0; i < PayList.length; i++) {
var item = PayList[i];
idList.innerHTML += GetInvoiceHTML(item, "UseInvoice(" + i + ")", "btinvoice");
}
if(AttachItem === undefined)
if (AttachItem === undefined)
UseInvoice(0);
}
else
{
else {
idList.innerHTML = "";
}
};
setInterval(CheckSendList, 200);
function UseInvoice(Num)
{
function UseInvoice(Num) {
var item = PayList[Num];
if(item.Data.From)
if (item.Data.From)
$("idAccount").value = item.Data.From;
$("idTo").value = item.Data.To;
$("idSumSend").value = item.Data.Amount;
@ -591,19 +511,16 @@ function UseInvoice(Num)
CheckSendList(1);
};
function ClearAttach()
{
function ClearAttach() {
AttachItem = undefined;
if($("idAttach"))
if ($("idAttach"))
$("idAttach").innerHTML = "";
};
function OpenAttach()
{
if(AttachItem)
{
function OpenAttach() {
if (AttachItem) {
var Data2 = JSON.parse(JSON.stringify(AttachItem.Data));
if(Data2.Body)
if (Data2.Body)
Data2.Body = GetHexFromArr(Data2.Body);
delete Data2.TransferSecret;
alert("DATA:\n" + JSON.stringify(Data2, "", 4));
@ -611,79 +528,65 @@ function OpenAttach()
};
var CURRENCY, PUBKEY, NAME, SMART;
function SendTrCreateAccWait(Currency,PubKey,Name,Smart)
{
function SendTrCreateAccWait(Currency, PubKey, Name, Smart) {
CURRENCY = Currency;
PUBKEY = PubKey;
NAME = Name;
SMART = Smart;
setTimeout(function ()
{
setTimeout(function() {
SendTrCreateAcc(CURRENCY, PUBKEY, NAME, 0, SMART, 0, 0);
}, 50);
};
function SendTrCreateAcc(Currency,PubKey,Description,Adviser,Smart,bFindAcc,bAddToPay)
{
function SendTrCreateAcc(Currency, PubKey, Description, Adviser, Smart, bFindAcc, bAddToPay) {
var TR = GetTrCreateAcc(Currency, PubKey, Description, Adviser, Smart);
var Body = GetBodyCreateAcc(TR);
TR.bFindAcc = 1;
if(bAddToPay)
{
var Item = {name:Description, To:0, Amount:CONFIG_DATA.PRICE_DAO.NewAccount, Description:"Create acc: " + Description, Body:Body,
if (bAddToPay) {
var Item = {
name: Description, To: 0, Amount: CONFIG_DATA.PRICE_DAO.NewAccount, Description: "Create acc: " + Description, Body: Body,
};
AddToInvoiceList(Item);
}
else
{
else {
SendTransaction(Body, TR);
}
$("idAccountName").value = "";
CancelCreateAccount();
};
function ChangeSmart(NumAccount,WasSmart)
{
if(!IsPrivateMode())
{
function ChangeSmart(NumAccount, WasSmart) {
if (!IsPrivateMode()) {
SetError("Pls, open wallet");
return 0;
}
var Result = prompt("Enter smart number:", WasSmart);
if(Result !== null && Result != WasSmart)
{
if (Result !== null && Result != WasSmart) {
var Smart = parseInt(Result);
if(Smart)
{
GetData("GetDappList", {StartNum:Smart, CountNum:1}, function (Data)
{
if(Data && Data.result && Data.arr.length === 1)
{
if (Smart) {
GetData("GetDappList", { StartNum: Smart, CountNum: 1 }, function(Data) {
if (Data && Data.result && Data.arr.length === 1) {
SetSmartToAccount(NumAccount, Smart);
}
else
{
else {
SetError("Error smart number");
}
});
}
else
{
else {
SetSmartToAccount(NumAccount, Smart);
}
}
};
function SetSmartToAccount(NumAccount,Smart)
{
function SetSmartToAccount(NumAccount, Smart) {
var OperationID = 0;
var Item = MapAccounts[NumAccount];
if(Item)
{
if (Item) {
OperationID = Item.Value.OperationID;
}
OperationID++;
var TR = {Type:140, Account:NumAccount, Smart:Smart, FromNum:NumAccount, Reserve:[], OperationID:OperationID, Sign:"", };
var TR = { Type: 140, Account: NumAccount, Smart: Smart, FromNum: NumAccount, Reserve: [], OperationID: OperationID, Sign: "", };
var Body = [];
WriteByte(Body, TR.Type);
WriteUint(Body, TR.Account);
@ -694,12 +597,11 @@ function SetSmartToAccount(NumAccount,Smart)
SendTrArrayWithSign(Body, TR.Account, TR);
};
function CheckLengthAccDesription(name,Length)
{
function CheckLengthAccDesription(name, Length) {
var Str = $(name).value.substr(0, Length + 1);
var arr = toUTF8Array(Str);
var Len = Length - arr.length;
if(Len < 0)
if (Len < 0)
SetError("Bad length");
else
SetStatus("Lost: " + Len + " bytes");

View File

@ -18,24 +18,37 @@ var StartTimeConnecting = 0;
var ConnectedCount = 0;
var NETWORK = "TERA-MAIN";
var ServerMap = {};
var ServerMainMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "terafoundation.org":{"ip":"terafoundation.org",
"port":443, "Name":"TERA", "System":1}, "dappsgate.com":{"ip":"dappsgate.com", "port":80, "Name":"SUPPORT2", "System":1}, "t1.teraexplorer.com":{"ip":"t1.teraexplorer.com",
"port":80, "Name":"t1.teraexplorer.com", "System":1}, "t2.teraexplorer.com":{"ip":"t2.teraexplorer.com", "port":80, "Name":"t2.teraexplorer.com",
"System":1}, "t3.teraexplorer.com":{"ip":"t3.teraexplorer.com", "port":80, "Name":"t3.teraexplorer.com", "System":1}, "t4.teraexplorer.com":{"ip":"t4.teraexplorer.com",
"port":80, "Name":"t4.teraexplorer.com", "System":1}, "t5.teraexplorer.com":{"ip":"t5.teraexplorer.com", "port":80, "Name":"t5.teraexplorer.com",
"System":1}, };
var ServerTestMap = {"127.0.0.1":{"ip":"127.0.0.1", "port":80, "Name":"LOCAL"}, "dappsgate.com":{"ip":"dappsgate.com", "port":88,
"Name":"SUPPORT2", "System":1}, };
var ServerMainMap = {
"127.0.0.1": { "ip": "127.0.0.1", "port": 80, "Name": "LOCAL" }, "terafoundation.org": {
"ip": "terafoundation.org",
"port": 443, "Name": "TERA", "System": 1
}, "dappsgate.com": { "ip": "dappsgate.com", "port": 80, "Name": "SUPPORT2", "System": 1 }, "t1.teraexplorer.com": {
"ip": "t1.teraexplorer.com",
"port": 80, "Name": "t1.teraexplorer.com", "System": 1
}, "t2.teraexplorer.com": {
"ip": "t2.teraexplorer.com", "port": 80, "Name": "t2.teraexplorer.com",
"System": 1
}, "t3.teraexplorer.com": { "ip": "t3.teraexplorer.com", "port": 80, "Name": "t3.teraexplorer.com", "System": 1 }, "t4.teraexplorer.com": {
"ip": "t4.teraexplorer.com",
"port": 80, "Name": "t4.teraexplorer.com", "System": 1
}, "t5.teraexplorer.com": {
"ip": "t5.teraexplorer.com", "port": 80, "Name": "t5.teraexplorer.com",
"System": 1
},
};
var ServerTestMap = {
"127.0.0.1": { "ip": "127.0.0.1", "port": 80, "Name": "LOCAL" }, "dappsgate.com": {
"ip": "dappsgate.com", "port": 88,
"Name": "SUPPORT2", "System": 1
},
};
function StartWebWallet()
{
if(NETWORK === "TERA-TEST2")
{
function StartWebWallet() {
if (NETWORK === "TERA-TEST2") {
MIN_SUM_POWER = 0;
ServerMap = ServerTestMap;
}
else
{
else {
MIN_SUM_POWER = COUNT_BLOCK_PROOF * 35;
ServerMap = ServerMainMap;
}
@ -44,64 +57,53 @@ function StartWebWallet()
ConnectWebWallet();
};
function OnInitWebWallet()
{
function OnInitWebWallet() {
var str = Storage.getItem(NETWORK + "NodesArrayList");
if(str)
{
if (str) {
var arr = JSON.parse(str);
for(var i = 0; i < arr.length; i++)
{
for (var i = 0; i < arr.length; i++) {
var Item = ServerMap[arr[i].ip];
if(Item && Item.System)
if (Item && Item.System)
continue;
ServerMap[arr[i].ip] = arr[i];
}
}
};
function SaveServerMap()
{
function SaveServerMap() {
var arr = [];
for(var key in ServerMap)
{
for (var key in ServerMap) {
var Item = ServerMap[key];
if(Item.SumPower >= MIN_SUM_POWER)
{
arr.push({ip:Item.ip, port:Item.port});
if (Item.SumPower >= MIN_SUM_POWER) {
arr.push({ ip: Item.ip, port: Item.port });
}
}
Storage.setItem(NETWORK + "NodesArrayList", JSON.stringify(arr));
};
function SetStatus(Str)
{
function SetStatus(Str) {
var id = $("idStatus");
id.innerHTML = Str;
if(Str)
if (Str)
console.log(id.innerText);
};
function SetError(Str,bNoSound)
{
function SetError(Str, bNoSound) {
SetStatus("<DIV align='left' style='color:red'><B>" + Str + "</B></DIV>");
};
var CountConnect = 0;
var CountWallet = 0;
function ConnectWebWallet()
{
function ConnectWebWallet() {
StartTimeConnecting = Date.now();
ConnectedCount = 0;
for(var key in ServerMap)
{
for (var key in ServerMap) {
var Item = ServerMap[key];
Item.SendHandShake = 0;
}
if(window.BrowserIE && !IsLocalClient())
{
if (window.BrowserIE && !IsLocalClient()) {
MainServer = undefined;
return ;
return;
}
CountConnect = 0;
CountWallet = 0;
@ -111,68 +113,57 @@ function ConnectWebWallet()
};
var Stage = 0;
function LoopHandShake()
{
function LoopHandShake() {
Stage++;
SetStatus("Connecting: " + Stage + "...");
for(var key in ServerMap)
{
for (var key in ServerMap) {
var Item = ServerMap[key];
if(Item.SendHandShake || !Item.port)
if (Item.SendHandShake || !Item.port)
continue;
CountConnect++;
if(window.BrowserIE && CountConnect > 4)
if (window.BrowserIE && CountConnect > 4)
break;
DoNodeList(Item);
}
};
function DoNodeList(Item)
{
function DoNodeList(Item) {
console.log(GetProtocolServerPath(Item) + "/GetNodeList");
if(window.location.protocol === "https:" && Item.port !== 443)
return ;
if(Item.port === 443 && IsIPAddres(Item.ip))
return ;
if (window.location.protocol === "https:" && Item.port !== 443)
return;
if (Item.port === 443 && IsIPAddres(Item.ip))
return;
SetStatus("Try: " + Item.ip + ":" + Item.port);
Item.SendHandShake = 1;
GetData(GetProtocolServerPath(Item) + "/GetNodeList", {}, function (Data)
{
if(Data && Data.result && Data.NETWORK === NETWORK && Data.VersionNum >= MIN_VERSION)
{
GetData(GetProtocolServerPath(Item) + "/GetNodeList", {}, function(Data) {
if (Data && Data.result && Data.NETWORK === NETWORK && Data.VersionNum >= MIN_VERSION) {
ConnectedCount++;
Item.GetHandShake = 1;
Item.BlockChain = Data.BlockChain;
SetStatus("Get: " + Item.ip + ":" + Item.port);
var bWas = 0;
for(var i = 0; i < Data.arr.length; i++)
{
for (var i = 0; i < Data.arr.length; i++) {
var Node = Data.arr[i];
if(!ServerMap[Node.ip] && Node.port)
{
if (!ServerMap[Node.ip] && Node.port) {
ServerMap[Node.ip] = Node;
console.log("New: " + Node.ip + ":" + Node.port);
bWas = 1;
}
}
if(bWas && ConnectedCount < MaxConnectedCount && new Date() - StartTimeConnecting < MaxTimeConnecting)
{
if (bWas && ConnectedCount < MaxConnectedCount && new Date() - StartTimeConnecting < MaxTimeConnecting) {
setTimeout(LoopHandShake, 100);
}
}
});
};
function LoopWalletInfo()
{
function LoopWalletInfo() {
SetStatus("Get wallets info...");
for(var key in ServerMap)
{
for (var key in ServerMap) {
var Item = ServerMap[key];
if(Item.port)
{
if (Item.port) {
CountWallet++;
if(window.BrowserIE && CountWallet > 4)
if (window.BrowserIE && CountWallet > 4)
break;
DoWalletInfo(Item);
}
@ -180,18 +171,15 @@ function LoopWalletInfo()
setTimeout(FindLider, 500);
};
function DoWalletInfo(Item)
{
if(window.location.protocol === "https:" && Item.port !== 443)
return ;
if(Item.port === 443 && IsIPAddres(Item.ip))
return ;
function DoWalletInfo(Item) {
if (window.location.protocol === "https:" && Item.port !== 443)
return;
if (Item.port === 443 && IsIPAddres(Item.ip))
return;
Item.StartTime = Date.now();
Item.SendWalletInfo = 1;
GetData(GetProtocolServerPath(Item) + "/GetCurrentInfo", {BlockChain:1}, function (Data)
{
if(Data && Data.result && Data.BlockChain && Data.NETWORK === NETWORK)
{
GetData(GetProtocolServerPath(Item) + "/GetCurrentInfo", { BlockChain: 1 }, function(Data) {
if (Data && Data.result && Data.BlockChain && Data.NETWORK === NETWORK) {
Item.Name = Data.NODES_NAME;
Item.GetWalletInfo = 1;
Item.DeltaTime = new Date() - Item.StartTime;
@ -202,49 +190,40 @@ function DoWalletInfo(Item)
});
};
function FindLider()
{
function FindLider() {
MainServer = undefined;
var Arr = [];
var MapSumPower = {};
for(var key in ServerMap)
{
for (var key in ServerMap) {
var Item = ServerMap[key];
if(Item.GetWalletInfo && Item.BlockChain)
{
if (Item.GetWalletInfo && Item.BlockChain) {
var arr = Item.BlockChain;
if(arr.data)
if (arr.data)
arr = arr.data;
Item.SumPower = CalcPowFromBlockChain(arr);
if(Item.SumPower < MIN_SUM_POWER)
{
if (Item.SumPower < MIN_SUM_POWER) {
console.log("Skip: " + Item.ip + ":" + Item.port + " SumPower(" + Item.SumPower + ") < MIN_SUM_POWER(" + MIN_SUM_POWER + ")");
continue;
}
if(!MapSumPower[Item.SumPower])
if (!MapSumPower[Item.SumPower])
MapSumPower[Item.SumPower] = 0;
MapSumPower[Item.SumPower]++;
Arr.push(Item);
}
}
var Max = 0, MaxKey;
for(var key in MapSumPower)
{
if(MapSumPower[key] >= Max)
{
for (var key in MapSumPower) {
if (MapSumPower[key] >= Max) {
Max = MapSumPower[key];
MaxKey = parseInt(key);
}
}
Arr.sort(function (a,b)
{
Arr.sort(function(a, b) {
return a.DeltaTime - b.DeltaTime;
});
for(var i = 0; i < Arr.length; i++)
{
for (var i = 0; i < Arr.length; i++) {
var Item = Arr[i];
if(Item.SumPower === MaxKey)
{
if (Item.SumPower === MaxKey) {
SetStatus("Find " + Item.ip + ":" + Item.port + " with pow=" + Item.SumPower + "/" + MaxKey + " ping=" + Item.DeltaTime);
MainServer = Item;
SaveServerMap();
@ -254,23 +233,19 @@ function FindLider()
OnFindServer();
};
function CalcPowFromBlockChain(BufRead)
{
function CalcPowFromBlockChain(BufRead) {
var Sum = 0;
var Arr = GetBlockArrFromBuffer(BufRead);
if(Arr.length === COUNT_BLOCK_PROOF)
{
for(var i = 0; i < Arr.length; i++)
{
if (Arr.length === COUNT_BLOCK_PROOF) {
for (var i = 0; i < Arr.length; i++) {
Sum += Arr[i].Power;
}
}
return Sum;
};
function SetAllSum()
{
function SetAllSum() {
var Item = MapAccounts[$("idAccount").value];
if(Item)
if (Item)
$("idSumSend").value = FLOAT_FROM_COIN(Item.Value).toStringF();
};

View File

@ -12,7 +12,9 @@ global.HTTPCaller.CreateAccount = function(Params, response) {
if (typeof Params === "object" && Params.Name && Params.PubKey) {
var TYPE_TRANSACTION_CREATE = 100;
var TR = {
Type: global.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: global.GetArrFromHex(Params.PubKey), Description: Params.Name,
Type: global.TYPE_TRANSACTION_CREATE,
Currency: Params.Currency,
PubKey: global.GetArrFromHex(Params.PubKey), Description: Params.Name,
Smart: Params.Smart, Adviser: 0,
};
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {});

View File

@ -16,7 +16,7 @@ import * as crypto from 'crypto';
import * as os from 'os'
global.glStopNode = false;
const MAX_TIME_NETWORK_TRANSPORT = 1 * 1000;
//const MAX_TIME_NETWORK_TRANSPORT = 1 * 1000;
var GlSumUser;
var GlSumSys;
var GlSumIdle;
@ -204,7 +204,7 @@ module.exports = class CCommon {
return crypto.randomBytes(32);
}
};
class SMemBuffer {
export class SMemBuffer {
MetaMap1
MetaMap2
CheckName
@ -249,7 +249,7 @@ class SMemBuffer {
return;
if (this.CheckName) {
var Count = 0;
for (var key in this.MetaMap2) {
for (var _ in this.MetaMap2) {
Count++
}
if (Count) {
@ -366,15 +366,15 @@ global.STreeBuffer = STreeBuffer;
global.TestCreateTr = TestCreateTr;
function TestCreateTr() {
const FORMAT_CREATE = "{\
Type:byte,\
Currency:uint,\
PubKey:arr33,\
Description:str40,\
Adviser:uint,\
Reserve:arr7,\
POWCreate:arr12,\
}";
// const FORMAT_CREATE = "{\
// Type:byte,\
// Currency:uint,\
// PubKey:arr33,\
// Description:str40,\
// Adviser:uint,\
// Reserve:arr7,\
// POWCreate:arr12,\
// }";
var TR = {
Type: 100, Currency: 0, PubKey: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0], Description: "Description", Adviser: 10,

View File

@ -99,7 +99,7 @@ module.exports = class CConsensus extends require("./block-loader")
Context.TrDataLen = 0
Context.Info = "Create at:" + global.GetStrOnlyTimeUTC()
var Transfer;
var TransferM2;
//var TransferM2;
var LocalLevel = 0;
var Levels = this.LevelNodes;
for (let L = 0; L < Levels.length; L++) {
@ -180,13 +180,14 @@ module.exports = class CConsensus extends require("./block-loader")
global.ToLog("TRANSFER BlockNum:" + Block.BlockNum + " TxArray=" + Data.TxArray.length + " from " + NodeName(Node))
this.ToMaxPOWList(Data.MaxPOW)
this.ToMaxSumList(this.GetMaxSumListFromID(Node, Data.MaxSumID, Data.BlockList))
var WasNewAdd = 0;
//var WasNewAdd = 0;
if (Data.TxArray.length) {
for (var i = 0; i < Data.TxArray.length; i++) {
var Tr = Data.TxArray[i];
var Res = this.AddTrToBlockQuote(Block, Tr);
if (Res === 1)
WasNewAdd = 1
if (Res === 1) {
//WasNewAdd = 1
}
if (global.USE_CHECK_SENDING && Res > 0) {
var Tt = Block.PowTxTree.find(Tr);
if (Tt) {
@ -511,9 +512,8 @@ module.exports = class CConsensus extends require("./block-loader")
bSend = 1
CanEnd = 0
break;
}
else {
var Stop = 1;
} else {
//var Stop = 1;
}
}
}
@ -825,7 +825,7 @@ module.exports = class CConsensus extends require("./block-loader")
var SumPow = 0;
if (arr.length !== global.SUM_LIST_LENGTH)
return SumPow;
var CountLoad = 0;
//var CountLoad = 0;
var BlockNumStart = CurBlockNum - arr.length + 1;
for (var i = 0; i < arr.length; i++) {
var Item = arr[i];
@ -1105,8 +1105,8 @@ module.exports = class CConsensus extends require("./block-loader")
if (this.LoadHistoryMode)
return;
var bWasSave = false;
var LoadBlockNum;
var LoadHash;
// var LoadBlockNum;
// var LoadHash;
var start_save = CURRENTBLOCKNUM + global.TIME_START_SAVE;
for (var BlockNum = CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2; BlockNum > global.BLOCK_PROCESSING_LENGTH2 && BlockNum < CURRENTBLOCKNUM; BlockNum++) {
var Block = this.GetBlock(BlockNum);

View File

@ -9,8 +9,8 @@
*/
"use strict";
const fs = require("fs");
import * as crypto from 'crypto';
//const fs = require("fs");
//import * as crypto from 'crypto';
require('./block-loader-const');
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
module.exports = class CBlock extends require("./rest-loader")
@ -264,7 +264,7 @@ module.exports = class CBlock extends require("./rest-loader")
if (global.LOAD_TO_BEGIN && this.BlockNumDBMin) {
this.SendLoadToBegin()
}
var CountStopSend = 0;
//var CountStopSend = 0;
var min_num = this.CurrentBlockNum - global.MAX_COUNT_CHAIN_LOAD;
var min_num_load = this.CurrentBlockNum;
for (var i = 0; i < this.LoadedChainList.length; i++) {
@ -309,8 +309,9 @@ module.exports = class CBlock extends require("./rest-loader")
chain.StopSend = true
}
}
if (chain && chain.StopSend)
CountStopSend++
if (chain && chain.StopSend) {
//CountStopSend++
}
chain = this.LoadedChainList[i]
if (chain && !chain.GetFindDB() && !chain.StopSend) {
this.SendChainNext(chain, true)
@ -532,7 +533,7 @@ module.exports = class CBlock extends require("./rest-loader")
chain.BlockHead = Block
if (!chain.BlockNumMax)
chain.BlockNumMax = Block.BlockNum
var PrevBlock0 = PrevBlock;
//var PrevBlock0 = PrevBlock;
if (BlockFind) {
if (PrevBlock) {
PrevBlock.BlockDown = BlockFind
@ -671,9 +672,9 @@ module.exports = class CBlock extends require("./rest-loader")
for (var num = 0; num < this.LoadedChainList.length; num++) {
var chain = this.LoadedChainList[num];
if (chain && chain.arr && chain.arr.length && chain.StopSend) {
var Count = 0;
//var Count = 0;
for (var i = chain.CurNumArrLoad; i < chain.arr.length; i++) {
Count++
//Count++
var Block = chain.arr[i];
if (!global.IsZeroArr(Block.TreeHash) && !Block.TreeEq && !Block.LoadDBFinaly) {
if (!Block.MapSend) {
@ -696,12 +697,12 @@ module.exports = class CBlock extends require("./rest-loader")
if (CountSend >= global.MAX_BLOCK_SEND)
return;
}
}
else
} else {
if (i === chain.CurNumArrLoad) {
chain.CurNumArrLoad++
Block.LoadDBFinaly = true
Count = 0
//Count = 0
}
}
}
this.CheckAndWriteLoadedChain(chain)
@ -1029,16 +1030,14 @@ module.exports = class CBlock extends require("./rest-loader")
this.SendF(Node, { "Method": "CANBLOCK", "Data": { BlockNum: Block.BlockNum } })
}
}
static
CANBLOCK_F() {
static CANBLOCK_F() {
return "{BlockNum:uint}";
}
CANBLOCK(Info, CurTime) {
var Data = this.DataFromF(Info);
// var Data = this.DataFromF(Info);
this.SendF(Info.Node, { "Method": "RETCANBLOCK", "Data": { Result: 1 } })
}
static
RETCANBLOCK_F() {
static RETCANBLOCK_F() {
return "{Result:byte}";
}
RETCANBLOCK(Info, CurTime) {
@ -1149,10 +1148,10 @@ module.exports = class CBlock extends require("./rest-loader")
this.FREE_MEM_BLOCKS(NumMax - global.BLOCK_COUNT_IN_MEMORY)
var maxArrMap = Math.floor(NumMax / global.BLOCK_COUNT_IN_MEMORY) - 1;
if (maxArrMap >= 0) {
var nWasCount = 0;
// var nWasCount = 0;
for (var key in this.MapMapLoaded)
if (key as any < maxArrMap) {
nWasCount++
// nWasCount++
delete this.MapMapLoaded[key]
}
}

View File

@ -9,7 +9,7 @@
*/
"use strict";
import * as crypto from 'crypto';
// import * as crypto from 'crypto';
const CNode = require("./node");
global.PERIOD_FOR_RECONNECT = 3600 * 1000;
global.CHECK_DELTA_TIME = { Num: 0, bUse: 0, StartBlockNum: 0, EndBlockNum: 0, bAddTime: 0, DeltaTime: 0, Sign: [] };
@ -205,8 +205,8 @@ module.exports = class CConnect extends require("./transfer-msg")
if (Node.BlockProcessCount <= this.BusyLevel)
StopGetBlock = 1
}
var СтатДанные = [];
var DirectMAccount = 0;
// var СтатДанные = [];
// var DirectMAccount = 0;
var Ret = {
VERSIONMAX: global.DEF_VERSION,
FIRST_TIME_BLOCK: 0,

View File

@ -451,40 +451,42 @@ function CalcTreeHashFromArrBody(BlockNum, arrContent) {
}
};
function TestMerklTree() {
var h1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var h2 = global.sha3("2");
var h3 = global.sha3("3");
var h4 = global.sha3("4");
var h5 = global.sha3("5");
var Tree: any = { RecalcCount: 0 };
var CalcMap = {};
Tree.LevelsHash = [[h1, h2]];
Tree.RecalcCount = 0;
CalcMap[0] = 1;
CalcMap[1] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
CalcMap = {};
Tree.LevelsHash[0] = [h1, h2, h3, h4];
Tree.RecalcCount = 0;
CalcMap[2] = 1;
CalcMap[3] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
CalcMap = {};
Tree.LevelsHash[0] = [h1, h2, h3];
Tree.RecalcCount = 0;
CalcMap[Tree.LevelsHash[0].length - 1] = 1;
UpdateMerklTree(Tree, CalcMap, 0);
global.ToLog("Root=" + global.GetHexFromArr(Tree.Root));
global.ToLog("RecalcCount=" + Tree.RecalcCount);
return Tree;
};
if (0)
// function TestMerklTree() {
// var h1 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
// var h2 = global.sha3("2");
// var h3 = global.sha3("3");
// var h4 = global.sha3("4");
// // var h5 = global.sha3("5");
// var Tree: any = { RecalcCount: 0 };
// var CalcMap = {};
// Tree.LevelsHash = [[h1, h2]];
// Tree.RecalcCount = 0;
// CalcMap[0] = 1;
// CalcMap[1] = 1;
// UpdateMerklTree(Tree, CalcMap, 0);
// CalcMap = {};
// Tree.LevelsHash[0] = [h1, h2, h3, h4];
// Tree.RecalcCount = 0;
// CalcMap[2] = 1;
// CalcMap[3] = 1;
// UpdateMerklTree(Tree, CalcMap, 0);
// CalcMap = {};
// Tree.LevelsHash[0] = [h1, h2, h3];
// Tree.RecalcCount = 0;
// CalcMap[Tree.LevelsHash[0].length - 1] = 1;
// UpdateMerklTree(Tree, CalcMap, 0);
// global.ToLog("Root=" + global.GetHexFromArr(Tree.Root));
// global.ToLog("RecalcCount=" + Tree.RecalcCount);
// return Tree;
// };
if (0) {
setTimeout(function() {
TestMerkleProof(100);
global.ToLog("=========END=========");
process.exit(0);
});
}
function TestMerkleProof(CountTest) {
for (var R = 0; R < CountTest; R++) {
@ -841,22 +843,22 @@ function DoSecret(Arr, Arr2, SecretBuf, StartLen) {
}
};
function TestEncryptDecrypt() {
var ArrSecret = Buffer.from([1, 1, 1, 1, 1, 1]);
var Arr = GetArrFromStr(" Secret message", 64);
var Arr2 = Buffer.from(new Uint8Array(Arr.length));
var Arr3 = Buffer.from(new Uint8Array(Arr.length));
console.log("Message:");
console.log(Arr);
console.log("-------------------");
Encrypt(Arr, Arr2, ArrSecret);
console.log("Encrypt:");
console.log(Arr2);
console.log("-------------------");
Decrypt(Arr2, Arr3, ArrSecret);
console.log("Decrypt:");
console.log(Utf8ArrayToStr(Arr3.slice(9)));
};
// function TestEncryptDecrypt() {
// var ArrSecret = Buffer.from([1, 1, 1, 1, 1, 1]);
// var Arr = GetArrFromStr(" Secret message", 64);
// var Arr2 = Buffer.from(new Uint8Array(Arr.length));
// var Arr3 = Buffer.from(new Uint8Array(Arr.length));
// console.log("Message:");
// console.log(Arr);
// console.log("-------------------");
// Encrypt(Arr, Arr2, ArrSecret);
// console.log("Encrypt:");
// console.log(Arr2);
// console.log("-------------------");
// Decrypt(Arr2, Arr3, ArrSecret);
// console.log("Decrypt:");
// console.log(Utf8ArrayToStr(Arr3.slice(9)));
// };
function toUTF8Array(str) {
var utf8 = [];
@ -921,9 +923,9 @@ function Utf8ArrayToStr(array) {
return out;
};
function GetArr32FromStr(Str) {
return GetArrFromStr(Str, 32);
};
// function GetArr32FromStr(Str) {
// return GetArrFromStr(Str, 32);
// };
function GetArrFromStr(Str, Len) {
var arr = toUTF8Array(Str);
@ -965,8 +967,7 @@ for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++)
DEVELOP_PUB_KEY_ARR[i] = Buffer.from(global.GetArrFromHex(DEVELOP_PUB_KEY_ARR[i]));
global.DEVELOP_PUB_KEY = DEVELOP_PUB_KEY_ARR[0];
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("022e80aa78bc07c72781fac12488096f0bfa7b4f48fbab0f2a92e208d1ee3654df"));
let LOCAL_RUN = global.LOCAL_RUN;
if (LOCAL_RUN) {
if (global.LOCAL_RUN) {
global.DEVELOP_PUB_KEY0 = Buffer.from(global.GetArrFromHex("026A04AB98D9E4774AD806E302DDDEB63BEA16B5CB5F223EE77478E861BB583EB3"));
global.DEVELOP_PUB_KEY = global.DEVELOP_PUB_KEY0;
}
@ -975,8 +976,8 @@ global.ARR_PUB_KEY = ["027ae0dce92d8be1f893525b226695ddf0fe6ad756349a76777ff51f3
"0270e0c5acb8eefe7faddac45503da4885e02fb554975d12907f6c33ac6c6bdba5", "0202f2aad628f46d433faf70ba6bf12ab9ed96a46923b592a72508dc43af36cb80",
"0254f373fc44ac4a3e80ec8cb8cc3693a856caa82e0493067bdead78ce8ec354b8", "027617f9511b0b0cdbda8f3e17907732731296321846f3fd6fd19460f7227d9482",
];
let GetHexFromArr = global.GetHexFromArr;
if (global.TEST_NETWORK || LOCAL_RUN) {
// let GetHexFromArr = global.GetHexFromArr;
if (global.TEST_NETWORK || global.LOCAL_RUN) {
for (var i = 0; i < 100; i++)
global.ARR_PUB_KEY[i] = global.GetHexFromArr(global.DEVELOP_PUB_KEY0);
global.DEVELOP_PUB_KEY_ARR = [global.DEVELOP_PUB_KEY0];

View File

@ -13,10 +13,12 @@ import './crypto-library'
import './log'
import * as crypto from 'crypto';
const os = require('os');
var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
const http = require('http'), net = require('net'), url = require('url'), fs = require('fs'), querystring = require('querystring');
import http = require('http');
const url = require('url')
const fs = require('fs')
const querystring = require('querystring');
var ContenTypeMap = {};
ContenTypeMap["js"] = "application/javascript";
ContenTypeMap["css"] = "text/css";
@ -1117,27 +1119,27 @@ HTTPCaller.GetHistoryTransactions = function(Params) {
return { result: 0 };
};
function GetCopyBlock(Block) {
var Result: any = {
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,
TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
TrCount: Block.TrCount, arrContent: Block.arrContent,
};
return Result;
};
// function GetCopyBlock(Block) {
// var Result: any = {
// 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,
// TrDataLen: Block.TrDataLen, SeqHash: global.GetHexFromAddres(Block.SeqHash), Hash: global.GetHexFromAddres(Block.Hash), Power: global.GetPowPower(Block.PowHash),
// TrCount: Block.TrCount, arrContent: Block.arrContent,
// };
// return Result;
// };
var AddrLength = 16;
function GetHexFromAddresShort(Hash) {
return global.GetHexFromAddres(Hash).substr(0, AddrLength);
};
function GetHexFromStrShort(Str) {
if (Str === undefined)
return Str;
else
return Str.substr(0, AddrLength);
};
// function GetHexFromStrShort(Str) {
// if (Str === undefined)
// return Str;
// else
// return Str.substr(0, AddrLength);
// };
var glid = 0;
function GetGUID(Block) {
@ -1247,7 +1249,7 @@ function AddMapList(arrLoadedBlocks, type, MapMapLoaded, MainChains?) {
}
}
};
var MapFileHTML5 = {};
// var MapFileHTML5 = {};
function SendWebFile(response, name?, StrCookie?, bParsing?) {
var type = name.substr(name.length - 4, 4);
@ -1385,21 +1387,21 @@ global.GetFileHTMLFromMarkdown = GetFileHTMLFromMarkdown;
global.GetFileSimple = GetFileSimple;
global.SaveFileSimple = SaveFileSimple;
function GetStrTime(now) {
if (!now)
now = global.GetCurrentTime(0);
var Str = "" + now.getHours().toStringZ(2);
Str = Str + ":" + now.getMinutes().toStringZ(2);
Str = Str + ":" + now.getSeconds().toStringZ(2);
return Str;
};
// function GetStrTime(now) {
// if (!now)
// now = global.GetCurrentTime(0);
// var Str = "" + now.getHours().toStringZ(2);
// Str = Str + ":" + now.getMinutes().toStringZ(2);
// Str = Str + ":" + now.getSeconds().toStringZ(2);
// return Str;
// };
function OnGetData(arg) {
var response = {
end: function() {
}, writeHead: function() {
},
};
// var response = {
// end: function() {
// }, writeHead: function() {
// },
// };
var Path = arg.path;
var obj = arg.obj;
if (Path.substr(0, 1) === "/")
@ -1573,18 +1575,18 @@ if (global.ELECTRON) {
}
exports.SendData = OnGetData;
function RunConsole(StrRun) {
var Str = fs.readFileSync("./EXPERIMENTAL/!run-console.js", { encoding: "utf8" });
if (StrRun)
Str += "\n" + StrRun;
try {
var ret = eval(Str);
}
catch (e) {
ret = e.message + "\n" + e.stack;
}
return ret;
};
// function RunConsole(StrRun) {
// var Str = fs.readFileSync("./EXPERIMENTAL/!run-console.js", { encoding: "utf8" });
// if (StrRun)
// Str += "\n" + StrRun;
// try {
// var ret = eval(Str);
// }
// catch (e) {
// ret = e.message + "\n" + e.stack;
// }
// return ret;
// };
var WebWalletUser = {};
function GetUserContext(Params) {

View File

@ -31,7 +31,7 @@ global.RBTree = require('bintrees').RBTree;
global.ntpClient = require('ntp-client');
global.Stun = require('stun');
global.ZIP = require("zip");
var strOS = os.platform() + "_" + os.arch();
// var strOS = os.platform() + "_" + os.arch();
if (!global.secp256k1) {
global.secp256k1 = require('secp256k1');
}
@ -56,16 +56,16 @@ global.GetCurrentBlockNumByTime = function GetCurrentBlockNumByTime() {
return StartBlockNum;
};
global.DelDir = function(Path) {
if (Path.substr(Path.length - 1, 1) === "/")
if (Path.substr(Path.length - 1, 1) === "/") {
Path = Path.substr(0, Path.length - 1);
}
if (fs.existsSync(Path)) {
var arr = fs.readdirSync(Path);
for (var i = 0; i < arr.length; i++) {
var name = Path + "/" + arr[i];
if (fs.statSync(name).isDirectory()) {
global.DelDir(name);
}
else {
} else {
if (name.right(9) == "const.lst")
continue;
if (name.right(7) == "log.log")
@ -82,7 +82,7 @@ global.SliceArr = function(arr, start, end) {
}
return ret;
};
var nRand = Math.floor(123 + Math.random() * 1000);
// var nRand = Math.floor(123 + Math.random() * 1000);
function random(max) {
return Math.floor(Math.random() * max);

View File

@ -12,31 +12,30 @@ import * as fs from 'fs'
import './constant'
import './log-strict'
let {
START_PORT_NUMBER,
CheckSizeLogFile,
} = global
var file_name_info = global.GetDataPath("info.log"), file_name_infoPrev = global.GetDataPath("info-prev.log");
CheckSizeLogFile(file_name_info, file_name_infoPrev);
var file_name_log = global.GetDataPath("log.log"), file_name_logPrev = global.GetDataPath("log-prev.log");
CheckSizeLogFile(file_name_log, file_name_logPrev);
var file_name_log_web = global.GetDataPath("web.log"), file_name_log_webPrev = global.GetDataPath("web-prev.log");
CheckSizeLogFile(file_name_log_web, file_name_log_webPrev);
var StartStatTime, file_name_error = global.GetDataPath("err.log"), file_name_errorPrev = global.GetDataPath("err-prev.log");
var file_name_info = global.GetDataPath("info.log")
var file_name_infoPrev = global.GetDataPath("info-prev.log");
global.CheckSizeLogFile(file_name_info, file_name_infoPrev);
var file_name_log = global.GetDataPath("log.log")
var file_name_logPrev = global.GetDataPath("log-prev.log");
global.CheckSizeLogFile(file_name_log, file_name_logPrev);
var file_name_log_web = global.GetDataPath("web.log")
var file_name_log_webPrev = global.GetDataPath("web-prev.log");
global.CheckSizeLogFile(file_name_log_web, file_name_log_webPrev);
var StartStatTime, file_name_error = global.GetDataPath("err.log")
var file_name_errorPrev = global.GetDataPath("err-prev.log");
function ToLogFile(e, t, r?) {
t instanceof Error && (t = t.message + "\n" + t.stack), global.START_SERVER || (t = global.PROCESS_NAME + ": " + t), "MAIN" !== global.PROCESS_NAME && process.send ? process.send({
cmd: "log",
message: t
}) : (console.log(START_PORT_NUMBER + ": " + global.GetStrOnlyTime() + ": " + t), r || SaveToLogFileSync(e, t));
}) : (console.log(global.START_PORT_NUMBER + ": " + global.GetStrOnlyTime() + ": " + t), r || SaveToLogFileSync(e, t));
};
function ToLogClient(e, t, r) {
let ArrLogClient = global.ArrLogClient;
e && (ToLogFile(file_name_log, e), t || (t = ""), ArrLogClient.push({ text: global.GetStrOnlyTime() + " " + e, key: t, final: r }), 13 < ArrLogClient.length && ArrLogClient.shift());
};
CheckSizeLogFile(file_name_error, file_name_errorPrev), global.ToLog = function(e, t) {
global.CheckSizeLogFile(file_name_error, file_name_errorPrev), global.ToLog = function(e, t) {
void 0 === t && (t = 1), t && t > global.LOG_LEVEL || (global.ALL_LOG_TO_CLIENT ? ToLogClient(e, void 0, void 0) : ToLogFile(file_name_log,
e));
}, global.ToLogWeb = function(e) {
@ -70,11 +69,11 @@ function ResizeArrAvg(e) {
return t;
};
function ResizeArr(e) {
for (var t = [], r = Math.trunc(e.length / 2), o = 0; o < r; o++)
t[o] = e[2 * o];
return t;
};
// function ResizeArr(e) {
// for (var t = [], r = Math.trunc(e.length / 2), o = 0; o < r; o++)
// t[o] = e[2 * o];
// return t;
// };
function GetDiagramData(e, t) {
var r, o = 2 * MAX_STAT_PERIOD + 2;
@ -115,20 +114,20 @@ function CopyStatInterval(e, t) {
r[n] = o[n], "MAX:" === n.substr(0, 4) && (o[n] = 0);
};
function SaveToLogFileAsync(e, o) {
fs.open(e, "a", void 0, function(e, r) {
if (e)
console.log("Ошибка открытия лог-файла ошибок");
else {
var t = global.GetStrTime() + " : " + o + "\r\n";
fs.write(r, t, null, "utf8", function(e, t) {
e ? console.log("Ошибка записи в лог-файл ошибок!") : fs.close(r, function(e) {
e && console.log(e);
});
});
}
});
};
// function SaveToLogFileAsync(e, o) {
// fs.open(e, "a", void 0, function(e, r) {
// if (e)
// console.log("Ошибка открытия лог-файла ошибок");
// else {
// var t = global.GetStrTime() + " : " + o + "\r\n";
// fs.write(r, t, null, "utf8", function(e, t) {
// e ? console.log("Ошибка записи в лог-файл ошибок!") : fs.close(r, function(e) {
// e && console.log(e);
// });
// });
// }
// });
// };
function SaveToLogFileSync(e, t) {
try {
@ -143,29 +142,35 @@ global.PrepareStatEverySecond = function() {
CurStatIndex++;
var e = GetCurrentStatIndex();
CopyStatInterval(CONTEXT_STATS, e), CopyStatInterval(CONTEXT_ERRORS, e);
}, global.TO_ERROR_LOG = function(e, t, r, o, n, a) {
}
global.TO_ERROR_LOG = function(e, t, r, o, n, a) {
r instanceof Error && (r = r.message + "\n"), "rinfo" === o ? r += " from: " + n.address + ":" + n.port : "node" === o && (r += " from: " + n.ip + ":" + n.port);
var l = e + ":" + t;
global.ToError(" ==ERROR== " + l + " " + r), AddToStatContext(CONTEXT_ERRORS, l), global.ADD_TO_STAT("ERRORS");
}, global.HASH_RATE = 0, global.ADD_HASH_RATE = function(e) {
}
global.HASH_RATE = 0, global.ADD_HASH_RATE = function(e) {
e /= 1e6, global.HASH_RATE += e, global.ADD_TO_STAT("HASHRATE", e);
}, global.GET_STAT = function(e) {
}
global.GET_STAT = function(e) {
var t = CONTEXT_STATS.Total[e];
return t || (t = 0), t;
}, global.ADD_TO_STAT_TIME = function(e, t, r) {
}
global.ADD_TO_STAT_TIME = function(e, t, r) {
if (global.STAT_MODE) {
if (r && 2 !== global.STAT_MODE)
return;
var o = process.hrtime(t), n = 1e3 * o[0] + o[1] / 1e6;
global.ADD_TO_STAT(e, n);
}
}, global.ADD_TO_STAT = function(e, t, r) {
}
global.ADD_TO_STAT = function(e, t, r) {
if (global.STAT_MODE) {
if (r && 2 !== global.STAT_MODE)
return;
AddToStatContext(CONTEXT_STATS, e, t);
}
}, global.GET_STATDIAGRAMS = function(e) {
}
global.GET_STATDIAGRAMS = function(e) {
global.GetCurrentTime();
var t = GetCurrentStatIndex();
if (!e || !e.length)
@ -195,7 +200,8 @@ global.PrepareStatEverySecond = function() {
i.AvgValue = g, i.steptime = _, i.arr = T.slice(1);
}
return r;
}, global.GET_STATS = function(e) {
}
global.GET_STATS = function(e) {
var t = global.GetCurrentTime(), r = GetCurrentStatIndex();
return {
stats: {
@ -206,23 +212,28 @@ global.PrepareStatEverySecond = function() {
r, 600)
}, period: (t - StartStatTime) / 1e3, Confirmation: []
};
}, global.StartCommonStat = function() {
for (var e in CONTEXT_STATS.Total)
}
global.StartCommonStat = function() {
for (var _ in CONTEXT_STATS.Total)
return;
global.ClearCommonStat();
}, global.ClearCommonStat = function() {
}
global.ClearCommonStat = function() {
StartStatTime = void (CurStatIndex = 0), CONTEXT_STATS = { Total: {}, Interval: [] }, CONTEXT_ERRORS = { Total: {}, Interval: [] },
global.HASH_RATE = 0, global.SERVER.ClearStat();
}, global.ResizeArrAvg = ResizeArrAvg, global.ResizeArrMax = ResizeArrMax, global.DEBUG_MODE ? global.TO_DEBUG_LOG = function(e, t, r, o) {
}
global.ResizeArrAvg = ResizeArrAvg, global.ResizeArrMax = ResizeArrMax, global.DEBUG_MODE ? global.TO_DEBUG_LOG = function(e, t, r, o) {
global.DEBUG_MODE && ("rinfo" === t && (e += " from: " + r.address + ":" + r.port + " - " + o.length), global.ToLog(e));
} : global.TO_DEBUG_LOG = function(e, t, r, o) {
}, global.GetStrOnlyTime = function(e) {
}
global.GetStrOnlyTime = function(e) {
if (!global.GetCurrentTime)
return ":::";
e || (e = global.GetCurrentTime());
var t = "" + e.getHours().toStringZ(2);
return t = (t = (t = t + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
}, global.GetStrTime = function(e) {
}
global.GetStrTime = function(e) {
if (!global.GetCurrentTime)
return ":::";
e || (e = global.GetCurrentTime());

View File

@ -10,7 +10,7 @@
"use strict";
import net = require("net");
import dgram = require("dgram");
// import dgram = require("dgram");
import * as crypto from 'crypto';
import "./library"
import "./crypto-library"
@ -19,7 +19,7 @@ global.BUF_TYPE = 1;
global.STR_TYPE = 2;
global.MAX_STR_BUF_DATA = 200;
global.MAX_CONNECTION_ACTIVE = 40;
var MAX_CONNECTION_ANOTHER = 40;
// var MAX_CONNECTION_ANOTHER = 40;
const TRAFIC_LIMIT_NODE_1S = global.MAX_BLOCK_SIZE * 1.25;
const TRAFIC_LIMIT_1S = 8 * TRAFIC_LIMIT_NODE_1S;
global.STAT_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
@ -715,13 +715,13 @@ export default class CTransport extends require("./connect")
}
DoSendBuf() {
this.RecalcSendStatictic()
var CountNodeSend = 0;
// var CountNodeSend = 0;
var it = this.ActualNodes.iterator(), Node;
NEXT_NODE:
while ((Node = it.next()) !== null)
if (Node.Socket && Node.ConnectStatus() === 100)
if (Node.BufWrite.length > 0) {
CountNodeSend++
// CountNodeSend++
var CountSend = Math.min(BUF_PACKET_SIZE, Node.BufWrite.length);
var Value = CountSend / 1024;
if (global.LIMIT_SEND_TRAFIC) {

View File

@ -30,7 +30,7 @@ function RunOnUpdate() {
function CreateHeadersHash100() {
global.ToLog("CreateHeadersHash100");
const DBRow = require("./db/db-row");
// const DBRow = require("./db/db-row");
global.UpdateMode = 1;
var DB = global.SERVER.DBHeader100;
var Num = 0;

View File

@ -9,12 +9,12 @@
*/
"use strict";
const fs = require('fs');
// const fs = require('fs');
import * as crypto from 'crypto';
require("./library");
require("./crypto-library");
const WalletPath = "WALLET";
const DBRow = require("./db/db-row");
// const DBRow = require("./db/db-row");
const CONFIG_NAME = global.GetDataPath(WalletPath + "/config.lst");
class CApp {
Password
@ -25,7 +25,7 @@ class CApp {
PubKeyArr
constructor() {
global.CheckCreateDir(global.GetDataPath(WalletPath))
var bReadOnly = (global.PROCESS_NAME !== "TX");
// var bReadOnly = (global.PROCESS_NAME !== "TX");
this.Password = ""
this.WalletOpen = undefined
var Params = global.LoadParams(CONFIG_NAME, undefined);

View File

@ -12,7 +12,7 @@ import '../core/constant'
global.PROCESS_NAME = "MAIN";
import fs = require('fs');
import os = require('os');
import path = require('path')
// import path = require('path')
import * as crypto from 'crypto';
global.START_SERVER = 1;
@ -366,7 +366,7 @@ var StartCheckMining = 0;
global.MiningPaused = 0;
var ProcessMemorySize = 0;
global.ArrMiningWrk = [];
var BlockMining;
// var BlockMining;
if (global.ADDRLIST_MODE) {
// @ts-ignore
return;
@ -503,7 +503,7 @@ function SetCalcPOW(Block, cmd) {
return;
if (ArrMiningWrk.length !== global.GetCountMiningCPU())
return;
BlockMining = Block;
// BlockMining = Block;
for (var i = 0; i < ArrMiningWrk.length; i++) {
var CurWorker = ArrMiningWrk[i];
if (!CurWorker.bOnline)
@ -654,7 +654,7 @@ function RunOnce() {
}, 10000);
}
};
var glPortDebug = 49800;
// var glPortDebug = 49800;
function Fork(Path, ArrArgs?) {
const child_process = require('child_process');
@ -674,7 +674,7 @@ function Fork(Path, ArrArgs?) {
ArrArgs.push("NOALIVE");
if (global.DEV_MODE)
ArrArgs.push("DEV_MODE");
glPortDebug++;
// glPortDebug++;
var execArgv = [];
var Worker = child_process.fork(Path, ArrArgs, { execArgv: execArgv });
return Worker;

View File

@ -111,7 +111,7 @@ function GETBLOCKHEADER100(msg) {
return;
var EndNum100 = BlockNum / 100;
var LoadHash100 = Data.Hash;
var Hash100;
// var Hash100;
var Count = Data.Count;
if (!Count || Count < 0 || !EndNum100)
return;
@ -228,8 +228,8 @@ function GETREST(msg) {
var ProofArrR = [];
var ArrRest = [];
if (nResult) {
var WorkStruct = {};
var WorkFormat = global.DApps.Accounts.FORMAT_ACCOUNT_ROW;
// var WorkStruct = {};
// var WorkFormat = global.DApps.Accounts.FORMAT_ACCOUNT_ROW;
var WorkFormatLength = global.DApps.Accounts.SIZE_ACCOUNT_ROW;
var Max = global.DApps.Accounts.DBState.GetMaxNum();
var LengthAccount = Data.Count;

View File

@ -122,7 +122,7 @@ function DoTXProcess() {
var StartTime = Date.now();
if (global.bShowDetail)
global.ToLog("BlockMin: " + BlockMin.BlockNum + " LastBlockNum=" + LastBlockNum);
var CountTX = 0;
// var CountTX = 0;
for (var Num = BlockMin.BlockNum; Num < BlockMin.BlockNum + 200; Num++) {
var EndTime = Date.now();
var Delta = EndTime - StartTime;
@ -155,7 +155,7 @@ function DoTXProcess() {
global.SERVER.BlockProcessTX(Block);
if (Num % 100000 === 0)
global.ToLog("CALC: " + Num);
CountTX++;
// CountTX++;
if (global.bShowDetail)
global.ToLog(" CALC: " + Num + " SumHash: " + global.GetHexFromArr(Block.SumHash).substr(0, 12));
BlockTree.SaveValue(Block.BlockNum, { BlockNum: Block.BlockNum, SumHash: Block.SumHash });
@ -330,7 +330,8 @@ function TXWriteAccHash() {
var Item = global.DApps.Smart.DBSmart.Read(num);
if (!Item)
break;
var Body = global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {});
// var Body =
global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {});
global.DApps.Smart.DBSmartWrite(Item);
}
global.DApps.Accounts.CalcMerkleTree(1);

View File

@ -9,7 +9,7 @@
*/
import * as crypto from 'crypto'
import * as http from 'http'
import * as net from 'net'
// import * as net from 'net'
import * as url from 'url'
import * as fs from 'fs'
import * as querystring from 'querystring'
@ -106,23 +106,13 @@ process.on('message', function(msg) {
var RedirectServer;
var HostingServer;
let {
ToLogWeb,
CHECK_STOP_CHILD_PROCESS,
ToError,
ToLog,
TO_ERROR_LOG,
PrepareStatEverySecond,
ToLogTrace
} = global
function Exit() {
ToLogWeb("=Exit1=");
global.ToLogWeb("=Exit1=");
if (RedirectServer)
RedirectServer.close();
if (HostingServer)
HostingServer.close();
ToLogWeb("=Exit2=");
global.ToLogWeb("=Exit2=");
process.exit(0);
};
@ -130,7 +120,7 @@ function CheckAlive() {
if (global.NOALIVE)
return;
var Delta = Date.now() - LastAlive;
if (Delta > CHECK_STOP_CHILD_PROCESS) {
if (Delta > global.CHECK_STOP_CHILD_PROCESS) {
Exit();
return;
}
@ -138,7 +128,7 @@ function CheckAlive() {
process.on('uncaughtException', function(err) {
global.ToError(err.stack);
global.ToLog(err.stack);
TO_ERROR_LOG("HOSTING", 777, err);
global.TO_ERROR_LOG("HOSTING", 777, err);
global.ToLog("-----------------HOSTING EXIT------------------", 0);
process.exit();
});
@ -147,7 +137,7 @@ process.on('error' as any, function(err: TeraError) {
global.ToLog(err.stack);
});
if (!global.HTTP_HOSTING_PORT) {
ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT);
global.ToLogTrace("global.HTTP_HOSTING_PORT=" + global.HTTP_HOSTING_PORT);
process.exit();
}
var CServerDB = require("../core/db/block-db");
@ -159,18 +149,12 @@ global.HTTP_PORT_NUMBER = 0;
require("../core/html-server");
require("../core/transaction-validator");
global.STAT_MODE = 1;
setInterval(PrepareStatEverySecond, 1000);
setInterval(global.PrepareStatEverySecond, 1000);
var IndexName = "index.html";
let {
GetDataPath,
CheckCreateDir,
LoadParams,
SaveParams,
ADD_TO_STAT
} = global
if (global.HTTPS_HOSTING_DOMAIN) {
var file_sert = global.GetDataPath("sertif.lst");
CheckCreateDir(global.GetDataPath("tmp"));
global.CheckCreateDir(global.GetDataPath("tmp"));
var greenlock = require('greenlock').create({
version: 'draft-12', server: 'https://acme-v02.api.letsencrypt.org/directory', configDir: global.GetDataPath('tmp'),
});
@ -182,7 +166,7 @@ if (global.HTTPS_HOSTING_DOMAIN) {
RedirectServer.listen(80);
var GetNewSert = 1;
if (fs.existsSync(file_sert)) {
var certs = LoadParams(file_sert, {});
var certs = global.LoadParams(file_sert, {});
var Delta = certs.expiresAt - Date.now();
if (Delta >= 10 * 24 * 3600 * 1000) {
global.ToLog("USE EXIST SERT. ExpiresAt: " + new Date(certs.expiresAt));
@ -196,7 +180,7 @@ if (global.HTTPS_HOSTING_DOMAIN) {
global.ToLog("Start get new SERT", 0);
var opts = { domains: [global.HTTPS_HOSTING_DOMAIN], email: 'progr76@gmail.com', agreeTos: true, communityMember: true, };
greenlock.register(opts).then(function(certs) {
SaveParams(file_sert, certs);
global.SaveParams(file_sert, certs);
var tlsOptions = { key: certs.privkey, cert: certs.cert + '\r\n' + certs.chain };
HostingServer = require('https').createServer(tlsOptions, MainHTTPFunction);
RunListenServer();
@ -219,7 +203,7 @@ function MainHTTPFunction(request, response) {
var DataURL = url.parse(request.url);
var Params = querystring.parse(DataURL.query);
var Path = querystring.unescape(DataURL.pathname);
ADD_TO_STAT("HTTP_ALL");
global.ADD_TO_STAT("HTTP_ALL");
var Type = request.method;
if (Type === "POST") {
let Response = response;
@ -354,7 +338,7 @@ function DoCommandNew(response, Type, Path, Params) {
}
Method = ArrPath[2];
}
ADD_TO_STAT("HTTP:" + Method);
global.ADD_TO_STAT("HTTP:" + Method);
var F = Caller[Method];
if (F) {
response.writeHead(200, { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': "*" });
@ -841,7 +825,7 @@ setInterval(function() {
if (!Count)
Count = 1;
var AvgPow = SumPow / Count;
ADD_TO_STAT("MAX:HASH_RATE_B", AvgPow);
global.ADD_TO_STAT("MAX:HASH_RATE_B", AvgPow);
}
var Count = global.COUNT_BLOCK_PROOF + 16 - 1;
if (MaxNumBlockDB > Count) {
@ -852,8 +836,7 @@ setInterval(function() {
require("./api-exchange.js");
try {
require("../SITE/JS/web-addon.js");
}
catch (e) {
} catch (e) {
}
global.LoadBlockFromNetwork = function(Params, F) {
global.ToLog("RUN: LoadBlockFromNetwork:" + Params.BlockNum, 2);

View File

@ -82,13 +82,6 @@ global.global.FORMAT_ACCOUNT_HASH3 = "{\
SmartHash:buffer32,\
SmartCount:uint,\
}";
let {
ToLog,
shaarr,
UpdateMerklTree,
ToError,
SERVER
} = global
class MerkleDBRow extends DBRow {
private MerkleTree
@ -120,7 +113,7 @@ class MerkleDBRow extends DBRow {
}
}
this.MerkleTree.RecalcCount = 0
UpdateMerklTree(this.MerkleTree, this.MerkleCalc, 0)
global.UpdateMerklTree(this.MerkleTree, this.MerkleCalc, 0)
this.MerkleCalc = {}
return this.MerkleTree.Root;
}
@ -590,7 +583,7 @@ class AccountApp extends require("./dapp")
power = Tr.power
}
else {
power = global.GetPowPower(shaarr(Body))
power = global.GetPowPower(global.shaarr(Body))
}
if (global.TEST_NETWORK && BlockNum >= 3290000) {
CheckMinPower = 0
@ -1408,23 +1401,23 @@ global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App;
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
global.DAppByType[global.TYPE_TRANSACTION_ACC_HASH] = App;
function TestStateFiles(Size, Format) {
return;
if (global.PROCESS_NAME !== "MAIN")
return;
var DBState1 = new DBRow("state-ok", Size, Format, 0);
var DBState2 = new DBRow("state-no", Size, Format, 0);
for (var Num = 0; 1; Num++) {
var Item1 = DBState1.Read(Num);
var Item2 = DBState2.Read(Num);
if (!Item1 && !Item2)
break;
var Str1 = JSON.stringify(Item1);
var Str2 = JSON.stringify(Item2);
if (Str1 !== Str2) {
global.ToLog("Err item: " + Num);
global.ToLog("1: " + Str1);
global.ToLog("2: " + Str2);
}
}
};
// function TestStateFiles(Size, Format) {
// return;
// if (global.PROCESS_NAME !== "MAIN")
// return;
// var DBState1 = new DBRow("state-ok", Size, Format, 0);
// var DBState2 = new DBRow("state-no", Size, Format, 0);
// for (var Num = 0; 1; Num++) {
// var Item1 = DBState1.Read(Num);
// var Item2 = DBState2.Read(Num);
// if (!Item1 && !Item2)
// break;
// var Str1 = JSON.stringify(Item1);
// var Str2 = JSON.stringify(Item2);
// if (Str1 !== Str2) {
// global.ToLog("Err item: " + Num);
// global.ToLog("1: " + Str1);
// global.ToLog("2: " + Str2);
// }
// }
// };

View File

@ -9,7 +9,7 @@
*/
"use strict";
import * as fs from 'fs'
// import * as fs from 'fs'
class DApp {
constructor() {
}
@ -46,16 +46,16 @@ class DApp {
};
module.exports = DApp;
function ReqDir(Path) {
if (fs.existsSync(Path)) {
var arr = fs.readdirSync(Path);
for (var i = 0; i < arr.length; i++) {
var name = arr[i];
global.ToLog("Reg: " + name);
var name2 = Path + "/" + arr[i];
require(name2);
}
}
};
// function ReqDir(Path) {
// if (fs.existsSync(Path)) {
// var arr = fs.readdirSync(Path);
// for (var i = 0; i < arr.length; i++) {
// var name = arr[i];
// global.ToLog("Reg: " + name);
// var name2 = Path + "/" + arr[i];
// require(name2);
// }
// }
// };
global.DApps = {};
global.DAppByType = {};

View File

@ -371,7 +371,7 @@ class SmartApp extends require("./dapp")
}
if (Category)
Category = global.global.ParseNum(Category)
var WasError = 0;
// var WasError = 0;
var arr = [];
var Data;
for (var num = start; true; num++) {
@ -1178,10 +1178,10 @@ var mask = 0xffffffff;
function MathRandom() {
DO(5);
function seed(i) {
m_w = i;
m_z = 987654321;
};
// function seed(i) {
// m_w = i;
// m_z = 987654321;
// };
function random() {
m_z = (36969 * (m_z & 65535) + (m_z >> 16)) & mask;

View File

@ -3,6 +3,7 @@
"outDir": "dist",
"allowJs": true,
"sourceMap": true,
"noUnusedLocals": true,
"target": "es5"
},
"include": [