Tue Sep 3 09:01:40 CST 2019 Source Update...

This commit is contained in:
MiaoWoo 2019-09-03 09:01:40 +08:00
parent 48fe258e2e
commit 228076945f
16 changed files with 1262 additions and 697 deletions

View File

@ -198,13 +198,35 @@ function GetProtocolServerPath(Item)
return "http://" + Item.ip + ":" + Item.port; return "http://" + Item.ip + ":" + Item.port;
}; };
function ToFixed(Sum,Currency)
{
var Fixed = GetCurrencyFixed(Currency);
var Str = Sum.toFixed(Fixed);
var Index = Str.indexOf(".");
if(Index > 0)
{
for(var i = Str.length - 1; i >= Index; i--)
{
var c = Str.substr(i, 1);
if(c !== "0")
{
if(c === ".")
Str = Str.substr(0, i);
break;
}
Str = Str.substr(0, i);
}
}
return Str;
};
function SUM_TO_STRING(Value,Currency,bFloat,bLocal) function SUM_TO_STRING(Value,Currency,bFloat,bLocal)
{ {
var Str; var Str;
if(Value.SumCOIN || Value.SumCENT) if(Value.SumCOIN || Value.SumCENT)
if(bFloat) if(bFloat)
{ {
Str = "" + FLOAT_FROM_COIN(Value).toStringF(); Str = ToFixed(FLOAT_FROM_COIN(Value), Currency);
} }
else else
{ {
@ -1284,8 +1306,7 @@ function GetTokenName(Num,Name)
{ {
if(!Name) if(!Name)
Name = "Token"; Name = "Token";
return "(" + Num + "." + Name + ")"; return String(Name).toLowerCase();
return "{" + Num + "." + Name + "}";
}; };
function CurrencyNameItem(Item) function CurrencyNameItem(Item)
@ -1294,11 +1315,15 @@ function CurrencyNameItem(Item)
if(!Name) if(!Name)
{ {
if(Item.CurrencyObj) if(Item.CurrencyObj)
{
Name = GetTokenName(Item.Currency, Item.CurrencyObj.ShortName); Name = GetTokenName(Item.Currency, Item.CurrencyObj.ShortName);
}
else else
Name = GetTokenName(Item.Currency, ""); Name = GetTokenName(Item.Currency, "");
MapCurrency[Item.Currency] = Name; MapCurrency[Item.Currency] = Name;
} }
if(Item.CurrencyObj && Item.CurrencyObj.TokenDescription)
Name += " : " + Item.CurrencyObj.TokenDescription;
return Name; return Name;
}; };

View File

@ -108,6 +108,15 @@ function COIN_FROM_STRING(Str)
{ {
throw "TODO: COIN_FROM_STRING"; throw "TODO: COIN_FROM_STRING";
}; };
function GetCurrencyFixed(Currency)
{
var Fixed = 9;
var Name = CurrencyName(Currency);
if(Name === "BTC")
Fixed = 8;
return Fixed;
};
if(typeof global === "object") if(typeof global === "object")
{ {
global.CHECKSUM = CHECKSUM; global.CHECKSUM = CHECKSUM;

View File

@ -175,6 +175,11 @@ function SendTransaction(Body,TR,SumPow,F)
SetError("Cannt SEND TR: " + JSON.stringify(TR)); SetError("Cannt SEND TR: " + JSON.stringify(TR));
}; };
function ReloadDapp()
{
SendData({cmd:"ReloadDapp"});
};
function CurrencyName(Num) function CurrencyName(Num)
{ {
var Name = MapCurrency[Num]; var Name = MapCurrency[Num];
@ -232,6 +237,8 @@ function FindAllCurrencyNext(StartNum)
function GetFilePath(Path) function GetFilePath(Path)
{ {
if(Path.substr(0, 5) === "http:" || Path.substr(0, 6) === "https:")
return Path;
if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/")) if(window.PROTOCOL_SERVER_PATH && Path.indexOf("file/"))
{ {
if(Path.substr(0, 1) !== "/") if(Path.substr(0, 1) !== "/")
@ -277,26 +284,71 @@ function GetState(AccNum,F,FErr)
} }
}); });
}; };
var glWasModal = 0;
function UpdateListArr(Block,Tr,Arr,StopBlock,IgnoreTailBlock,MaxDepth,F) function openModal(id)
{ {
Arr.sort(function (a,b) glWasModal = 1;
{ var modal = document.querySelector("#" + id);
return a.Num - b.Num; var overlay = document.querySelector("#idOverlay");
}); modal.style.display = "block";
if(Arr.length) overlay.style.display = "block";
StopBlock = Math.max(StopBlock, Arr[Arr.length - 1].BlockNum);
UpdateListArrNext(Block, Tr, Arr, StopBlock, IgnoreTailBlock, MaxDepth, F);
}; };
function UpdateListArrNext(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F) function closeModal()
{
glWasModal = 0;
var modals = document.querySelectorAll(".ModalDlg");
var overlay = document.querySelector("#idOverlay");
modals.forEach(function (item)
{
item.style.display = "none";
});
overlay.style.display = "none";
};
var TEMP_DISABLED_MAP = {};
function SetTempDisabled(Id,TimeSec)
{
if(!TimeSec)
TimeSec = 8;
$(Id).disabled = 1;
TEMP_DISABLED_MAP[Id] = 1;
setTimeout(function ()
{
$(Id).disabled = 0;
delete TEMP_DISABLED_MAP[Id];
}, TimeSec * 1000);
};
var glConfirmF;
function DoConfirm(StrTitle,StrText,F,bDirect)
{
if(!bDirect && window.openModal && $("idConfirm"))
{
$("idConfirmTitle").innerHTML = StrTitle;
$("idConfirmText").innerHTML = StrText;
glConfirmF = F;
openModal("idConfirm");
}
else
{
F();
}
};
function OnConfirmOK()
{
closeModal();
if(glConfirmF)
glConfirmF();
glConfirmF = undefined;
};
function GetDappBlock(Block,Tr,F)
{ {
if(Block <= StopMinBlock || !MaxDepth)
return ;
SendCountUpdate++;
DappBlockFile(Block, Tr, function (Err,Data) DappBlockFile(Block, Tr, function (Err,Data)
{ {
SendCountUpdate--;
if(!Err && Data.Type === 135) if(!Err && Data.Type === 135)
{ {
try try
@ -307,6 +359,35 @@ function UpdateListArrNext(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F)
{ {
} }
if(Params) if(Params)
{
F(0, Params, Data.MethodName, Data.FromNum);
return ;
}
}
F(1);
});
};
function UpdateListArr(Block,Tr,Arr,StopBlock,IgnoreTailBlock,MaxDepth,F)
{
Arr.sort(function (a,b)
{
return a.Num - b.Num;
});
if(Arr.length)
StopBlock = Math.max(StopBlock, Arr[Arr.length - 1].BlockNum);
UpdateRowArr(Block, Tr, Arr, StopBlock, IgnoreTailBlock, MaxDepth, F);
};
function UpdateRowArr(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F)
{
if(Block <= StopMinBlock || !MaxDepth)
return ;
SendCountUpdate++;
GetDappBlock(Block, Tr, function (Err,Params)
{
SendCountUpdate--;
if(!Err)
{ {
if(Block <= INFO.CurBlockNum - IgnoreTailBlock) if(Block <= INFO.CurBlockNum - IgnoreTailBlock)
{ {
@ -315,24 +396,231 @@ function UpdateListArrNext(Block,Tr,Arr,StopMinBlock,IgnoreTailBlock,MaxDepth,F)
Params.Num = Params.BlockNum * 100000 + Params.TrNum; Params.Num = Params.BlockNum * 100000 + Params.TrNum;
Params.Time = Date.now(); Params.Time = Date.now();
if(!Arr.length || Arr[Arr.length - 1].Num !== Params.Num) if(!Arr.length || Arr[Arr.length - 1].Num !== Params.Num)
{
if(F)
{
if(F(Params))
{
return ;
}
}
else
{
Arr.push(Params); Arr.push(Params);
} }
}
}
if(Params.PrevBlock) if(Params.PrevBlock)
{ {
UpdateListArrNext(Params.PrevBlock, Params.PrevTr, Arr, StopMinBlock, IgnoreTailBlock, MaxDepth - 1, F); UpdateRowArr(Params.PrevBlock, Params.PrevTr, Arr, StopMinBlock, IgnoreTailBlock, MaxDepth - 1, F);
} }
} }
}
if(F && SendCountUpdate === 0)
{
Arr.sort(function (a,b)
{
return a.Num - b.Num;
});
F(Arr);
}
}); });
}; };
function GetKeyNum(Key)
{
var Arr;
if(typeof Key === "number")
{
Arr = sha3("" + Key);
}
else
{
Arr = sha3(Key);
}
var KeyNum = ReadUintFromArr(Arr, 0);
return KeyNum;
};
function GetKeyInner(Key,DBBlock,DBTr,F)
{
FindItem(DBBlock, DBTr, Key, function (Result,PathArr)
{
for(var i = 0; i < PathArr.length; i++)
{
var Elem = PathArr[i];
if(Elem.Key === Key)
{
if(Elem.VB)
{
LoadElement(Elem, i, PathArr, F);
}
else
{
F(1, Elem, PathArr);
}
return ;
}
}
F(0, undefined, PathArr);
});
};
function SetKeyInner(Key,Value,DBBlock,DBTr,F)
{
FindItem(DBBlock, DBTr, Key, function (Result,PathArr)
{
var Elem;
var bCreate = 1;
var ElemEdit = undefined;
for(var i = 0; i < PathArr.length; i++)
{
Elem = PathArr[i];
if(Elem.Key === Key)
{
Elem.Key = undefined;
Elem.VB = undefined;
Elem.VT = undefined;
Elem.Level = undefined;
if(i === PathArr.length - 1)
bCreate = 0;
if(typeof Value === "number")
ElemEdit = Elem;
}
if(Elem.VB)
{
Elem.Value = undefined;
}
}
var L = PathArr.length - 1;
if(ElemEdit)
{
Elem = ElemEdit;
}
else
{
if(L === - 1 || bCreate)
{
L++;
PathArr[L] = {};
}
Elem = PathArr[L];
}
Elem.Key = Key;
Elem.Value = Value;
F(PathArr);
});
};
var GetBlockKeyCount = 0;
function FindItem(Block,Tr,Key,F)
{
GetBlockKeyCount = 0;
var KeyNum = GetKeyNum(Key);
FindItemNext(Block, Tr, Key, KeyNum, [], 0, F);
};
function FindItemNext(Block,Tr,Key,KeyNum,PathArr,Level,F)
{
GetBlockKeyCount++;
GetDappBlock(Block, Tr, function (Err,Params)
{
GetBlockKeyCount--;
if(!Err)
{
var KeyNumStr = KeyNum.toString(2);
var Arr = Params.Arr;
for(var L = Level; Arr && L < Arr.length; L++)
{
var Elem = Arr[L];
PathArr[L] = Elem;
if(Elem.Key !== undefined)
{
if(Elem.Key !== Key && !Elem.VB && typeof Elem.Value !== "number")
{
Elem.VB = Block;
Elem.VT = Tr;
}
}
var Bit = + KeyNumStr.substr(L, 1);
if(Bit !== Elem.t)
{
var IB = Elem.IB;
var IT = Elem.IT;
Elem.t = Bit;
Elem.IB = Block;
Elem.IT = Tr;
if(IB)
{
FindItemNext(IB, IT, Key, KeyNum, PathArr, L + 1, F);
}
else
{
break;
}
return ;
}
}
F(1, PathArr);
return ;
}
if(GetBlockKeyCount === 0)
F(0, []);
});
};
function LoadElement(Element,Level,PathArr,F)
{
GetBlockKeyCount++;
GetDappBlock(Element.VB, Element.VT, function (Err,Params)
{
GetBlockKeyCount--;
if(!Err)
{
F(1, Params.Arr[Level], PathArr);
return ;
}
if(GetBlockKeyCount === 0)
F(0);
});
};
function GetXORArr(Arr1,Arr2)
{
var Arr3 = [];
for(var i = 0; i < 32; i++)
{
Arr3[i] = Arr1[i] ^ Arr2[i];
}
return Arr3;
};
function EncryptUint32(ArrSecret,RandomNum,Value)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var ValueArr = [];
WriteUint32ToArr(ValueArr, Value);
return GetHexFromArr(DoSecret(ValueArr, ArrSecret));
};
function DecryptUint32(ArrSecret,RandomNum,StrValue)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var Arr0 = GetArrFromHex(StrValue);
var ValueArr = DoSecret(Arr0, ArrSecret);
ValueArr.len = 0;
var Value = ReadUint32FromArr(ValueArr);
return Value;
};
function EncryptArr32(ArrSecret,RandomNum,ValueArr)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
return GetHexFromArr(DoSecret(ValueArr, ArrSecret));
};
function DecryptArr32(ArrSecret,RandomNum,StrValue)
{
WriteUintToArrOnPos(ArrSecret, 0, 0);
WriteUintToArrOnPos(ArrSecret, RandomNum, 6);
var Arr0 = GetArrFromHex(StrValue);
var ValueArr = DoSecret(Arr0, ArrSecret);
return ValueArr;
};
var glMapF = {}; var glMapF = {};
var glKeyF = 0; var glKeyF = 0;
@ -492,24 +780,14 @@ function GetDappParams(BNum,TrNum,F,bAll)
return ; return ;
} }
SendCountDappParams++; SendCountDappParams++;
DappBlockFile(BNum, TrNum, function (Err,Data) GetDappBlock(BNum, TrNum, function (Err,Params,MethodName,FromNum)
{ {
SendCountDappParams--; SendCountDappParams--;
if(!Err && Data.Type === 135) if(!Err)
{ {
try F(Params, MethodName, FromNum);
{
var Params = JSON.parse(Data.Params);
}
catch(e)
{
}
if(Params)
{
F(Params, Data.MethodName, Data.FromNum);
return ; return ;
} }
}
if(bAll) if(bAll)
F(); F();
}); });
@ -595,3 +873,23 @@ window.addEventListener('load', function ()
UpdateDappInfo(); UpdateDappInfo();
setInterval(UpdateDappInfo, 1000); setInterval(UpdateDappInfo, 1000);
}); });
window.onkeydown = function (e)
{
if(e.keyCode === 116)
{
e.preventDefault();
ReloadDapp();
}
else
if(e.keyCode === 27)
{
if(window.closeModal)
closeModal();
}
else
if(e.keyCode === 13)
{
if(glConfirmF)
OnConfirmOK();
}
};

View File

@ -468,7 +468,7 @@ function SetAccountsCard(Data,AccountsDataStr)
Str1 = ""; Str1 = "";
Str2 = ""; Str2 = "";
} }
var StrCurrencyName = CurrencyName(Item.Currency); var StrCurrencyName = CurrencyNameItem(Item);
Str = Str.replace("$Value.SumCOIN", Str1); Str = Str.replace("$Value.SumCOIN", Str1);
Str = Str.replace("$Value.SumCENT", Str2); Str = Str.replace("$Value.SumCENT", Str2);
Str = Str.replace("$Value.CurrencyName", StrCurrencyName); Str = Str.replace("$Value.CurrencyName", StrCurrencyName);
@ -1295,8 +1295,7 @@ LangMap["RUS"] = {"TERA WALLET":"TERA КОШЕЛЕК", "Generate key":"Сген
"Load key":"Загруз.", "Create your first account and start using TERA":"Создайте свой первый счет и начните использовать TERA", "Load key":"Загруз.", "Create your first account and start using TERA":"Создайте свой первый счет и начните использовать TERA",
"0 Accounts":"0 Счетов", "OWNER: {Item.Owner}":"Владелец: {Item.Owner}", "More info":"Инфо", "Public key":"Публичный ключ", "0 Accounts":"0 Счетов", "OWNER: {Item.Owner}":"Владелец: {Item.Owner}", "More info":"Инфо", "Public key":"Публичный ключ",
"Enter number of dapp":"Введите номер Dapp", "Enter the dapps number that will be added to your account. Attention make sure that you trust this dapp, otherwise you may lose all funds in this account.":"Введите номер Dapp, который будет добавлен в ваш аккаунт. Внимание убедитесь, что Вы доверяете ему, в противном случае вы можете потерять все средства на этом счете.", "Enter number of dapp":"Введите номер Dapp", "Enter the dapps number that will be added to your account. Attention make sure that you trust this dapp, otherwise you may lose all funds in this account.":"Введите номер Dapp, который будет добавлен в ваш аккаунт. Внимание убедитесь, что Вы доверяете ему, в противном случае вы можете потерять все средства на этом счете.",
"Sending Tx":"Отправка транзакции", "Wallet ver:":"Версия:", "HELP: Tera Wallet creation Guide...":"Руководство по созданию Tera Wallet...", "Sending Tx":"Отправка транзакции", "Wallet ver:":"Версия:", "Tera Wallet Guide...":"Руководство по Tera Wallet...", "==HELP-LINK==":"https://medium.com/@evkara777/tera-%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D0%B0%D0%BB%D1%8E%D1%82%D0%BD%D1%8B%D0%B9-%D0%BA%D0%BE%D1%88%D0%B5%D0%BB%D0%B5%D0%BA-%D0%B2%D0%B8%D0%B4%D1%8B-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5-%D1%81%D1%87%D0%B5%D1%82%D0%B0-6402531ecc11",
"==HELP-LINK==":"https://medium.com/@evkara777/tera-%D0%BA%D1%80%D0%B8%D0%BF%D1%82%D0%BE%D0%B2%D0%B0%D0%BB%D1%8E%D1%82%D0%BD%D1%8B%D0%B9-%D0%BA%D0%BE%D1%88%D0%B5%D0%BB%D0%B5%D0%BA-%D0%B2%D0%B8%D0%B4%D1%8B-%D1%81%D0%BE%D0%B7%D0%B4%D0%B0%D0%BD%D0%B8%D0%B5-%D1%81%D1%87%D0%B5%D1%82%D0%B0-6402531ecc11",
}; };
LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成私钥", "OK":"OK", "Cancel":"取消", "Edit":"编辑", "Save key":"保存私钥", LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成私钥", "OK":"OK", "Cancel":"取消", "Edit":"编辑", "Save key":"保存私钥",
"+ CREATE A NEW ACCOUNT":"+ 新建账号", "Create account":"创建账号", "Send":"发送", "SEND":"转账", "CONFIRM":"确认", "Accounts":"账号", "Account(s)":"账号", "+ CREATE A NEW ACCOUNT":"+ 新建账号", "Create account":"创建账号", "Send":"发送", "SEND":"转账", "CONFIRM":"确认", "Accounts":"账号", "Account(s)":"账号",
@ -1314,7 +1313,7 @@ LangMap["简体中文"] = {"TERA WALLET":"TERA 钱包", "Generate key":"生成
"From:":"付款:", "Set a password for protect entry":"设置密码保护钱包", "Enter password to unlock wallet":"输入密码解锁钱包", "From ID:":"付款ID:", "From:":"付款:", "Set a password for protect entry":"设置密码保护钱包", "Enter password to unlock wallet":"输入密码解锁钱包", "From ID:":"付款ID:",
"Pay to ID:":"收款ID:", "Account":"账号", "Owner":"拥有者", "Block num":"区块编号", "Private key (secret)":"私钥 (机密)", "Load key":"载入私钥", "Pay to ID:":"收款ID:", "Account":"账号", "Owner":"拥有者", "Block num":"区块编号", "Private key (secret)":"私钥 (机密)", "Load key":"载入私钥",
"Create your first account and start using TERA":"创建你的第一个账号开启TERA之旅", "0 Accounts":"0 账号", "OWNER: {Item.Owner}":"拥有者: {Item.Owner}", "Create your first account and start using TERA":"创建你的第一个账号开启TERA之旅", "0 Accounts":"0 账号", "OWNER: {Item.Owner}":"拥有者: {Item.Owner}",
"More info":"详情", "Public key":"公钥", "HELP: Tera Wallet creation Guide...":"TERA钱包创作指南", "==HELP-LINK==":"https://terafoundation.org/files/Tera-Wallet-cn.pdf", "More info":"详情", "Public key":"公钥", "Tera Wallet Guide...":"TERA钱包创建指南", "==HELP-LINK==":"https://terafoundation.org/files/Tera-Wallet-cn.pdf",
}; };
LangMap["한글"] = {"TERA WALLET":"TERA 지갑", "Generate key":"개인 키 생성", "OK":"OK", "Cancel":"취소", "Edit":"편집", "Save key":"개인 키 저장", LangMap["한글"] = {"TERA WALLET":"TERA 지갑", "Generate key":"개인 키 생성", "OK":"OK", "Cancel":"취소", "Edit":"편집", "Save key":"개인 키 저장",
"+ CREATE A NEW ACCOUNT":"+ 새 계정 만들기", "Create account":"계정 만들기", "Send":"발송", "CONFIRM":"확인", "Accounts":"계정", "Account(s)":"계정", "+ CREATE A NEW ACCOUNT":"+ 새 계정 만들기", "Create account":"계정 만들기", "Send":"발송", "CONFIRM":"확인", "Accounts":"계정", "Account(s)":"계정",

View File

@ -216,6 +216,13 @@ function WriteUintToArrOnPos(arr,Num,Pos)
arr[Pos + 5] = (NumH >>> 8) & 0xFF; arr[Pos + 5] = (NumH >>> 8) & 0xFF;
}; };
function WriteUint16ToArr(arr,Num)
{
var len = arr.length;
arr[len] = Num & 0xFF;
arr[len + 1] = (Num >>> 8) & 0xFF;
};
function WriteUint32ToArr(arr,Num) function WriteUint32ToArr(arr,Num)
{ {
var len = arr.length; var len = arr.length;

View File

@ -129,8 +129,8 @@ function GetAccountText(Item,Num,bGetSum)
text = "" + Num + ". " + text; text = "" + Num + ". " + text;
if(bGetSum) if(bGetSum)
{ {
var StrSum = SUM_TO_STRING(Item.Value, Item.Currency); var StrSum = SUM_TO_STRING(Item.Value, Item.Currency, 1);
text += " (" + StrSum + ")"; text += " : " + StrSum;
} }
return text; return text;
} }

View File

@ -933,7 +933,7 @@
<DIV> <DIV>
<DIV> <DIV>
Name:<INPUT type="string" id="idName" style="width: 20%;" value=""> Name:<INPUT type="string" id="idName" style="width: 20%;" value="">
Accounts:<INPUT type="number" id="idAccountLength" min=1 max=50 style="width: 5%;" value="1"> Acc count:<INPUT type="number" id="idAccountLength" min=1 max=50 style="width: 5%;" value="1">
<INPUT type="button" onclick="SendToBlockchain()" class="bt btdoit" style="width: 150px; " id="idBtSendSmart" value="Send to blockchain"> <INPUT type="button" onclick="SendToBlockchain()" class="bt btdoit" style="width: 150px; " id="idBtSendSmart" value="Send to blockchain">
<select size="1" id="idUser" class="" style="width: 300px" onchange="SaveValues()"> <select size="1" id="idUser" class="" style="width: 300px" onchange="SaveValues()">
<option value="">loading</option> <option value="">loading</option>

View File

@ -26,6 +26,7 @@
var NumDappGet=0; var NumDappGet=0;
var NumDappInfo=0; var NumDappInfo=0;
var DAPPPREFIX="DAPP-"; var DAPPPREFIX="DAPP-";
var MAX_DELTA_IGNORE_BUFFER=10;
//DAPP TRANSFER //DAPP TRANSFER
@ -70,8 +71,8 @@
case "getstorage": case "getstorage":
{ {
Data.Value=Storage.getItem(DAPPPREFIX+DapNumber+"-"+Data.Key); Data.Value=Storage.getItem(DAPPPREFIX+DapNumber+"-"+Data.Key);
if(Data.Value) if(Data.Value && Data.Value!=="undefined")
Data.Value=JSON.parse(Data.Value); try {Data.Value=JSON.parse(Data.Value);}catch (e){};
SendMessage(Data); SendMessage(Data);
break; break;
} }
@ -83,8 +84,8 @@
case "getcommon": case "getcommon":
{ {
Data.Value=Storage.getItem(DAPPPREFIX+Data.Key); Data.Value=Storage.getItem(DAPPPREFIX+Data.Key);
if(Data.Value) if(Data.Value && Data.Value!=="undefined")
Data.Value=JSON.parse(Data.Value); try {Data.Value=JSON.parse(Data.Value);}catch (e){};
SendMessage(Data); SendMessage(Data);
break; break;
} }
@ -136,16 +137,27 @@
{ {
if(SetData) if(SetData)
{ {
//ToLog("glSession="+glSession+" RES:"+SetData.result+" SetData.cache="+SetData.cache+" CurBlockNum="+SetData.CurBlockNum);
Data.Err=!SetData.result; Data.Err=!SetData.result;
Data.cache=SetData.cache;
if(SetData.result) if(SetData.result)
{
if(SetData.cache)
{
for(var key in SetData)
CONFIG_DATA[key]=SetData[key];
SetData=CONFIG_DATA;
}
else
{ {
CONFIG_DATA=SetData; CONFIG_DATA=SetData;
SMART=SetData.Smart; SMART=SetData.Smart;
BASE_ACCOUNT=SetData.Account; BASE_ACCOUNT=SetData.Account;
SetBlockChainConstant(SetData);
NumDappInfo=SetData.NumDappInfo;
SetArrLog(SetData.ArrLog); SetArrLog(SetData.ArrLog);
}
NumDappInfo=SetData.NumDappInfo;
SetBlockChainConstant(SetData);
for(var key in SetData) for(var key in SetData)
@ -179,11 +191,13 @@
case "DappTransactionList": case "DappTransactionList":
{ {
if(Data.cmd==="DappBlockFile") if(Data.cmd==="DappBlockFile"
&& Data.Params.BlockNum<=CONFIG_DATA.CurBlockNum-MAX_DELTA_IGNORE_BUFFER)
{ {
//check storage //check storage
var StrKeyStorage=Data.Params.BlockNum+"-"+Data.Params.TrNum; var StrKeyStorage=Data.Params.BlockNum+"-"+Data.Params.TrNum;
//ToLog("StrKeyStorage: "+StrKeyStorage);
var Storage2=sessionStorage; var Storage2=sessionStorage;
var SavedTextData=Storage2[StrKeyStorage]; var SavedTextData=Storage2[StrKeyStorage];
if(SavedTextData) if(SavedTextData)
@ -277,6 +291,12 @@
CreateNewAccount(Data.Currency); CreateNewAccount(Data.Currency);
break; break;
} }
case "ReloadDapp":
{
ReloadDapp();
break;
}
} }
} }
@ -378,6 +398,7 @@
{ {
var StrPath=GetProtocolServerPath(MainServer); var StrPath=GetProtocolServerPath(MainServer);
//поддрежка старого кода dapp (после обновления dapp этот код возможно будет удален) //поддрежка старого кода dapp (после обновления dapp этот код возможно будет удален)
SetData.Body=SetData.Body.replace(/.\/CSS\/[0-9a-z_-]+.css\">/g,StrPath+"$&"); SetData.Body=SetData.Body.replace(/.\/CSS\/[0-9a-z_-]+.css\">/g,StrPath+"$&");
SetData.Body=SetData.Body.replace(/.\/JS\/[0-9a-z_-]+.js\">/g,StrPath+"$&"); SetData.Body=SetData.Body.replace(/.\/JS\/[0-9a-z_-]+.js\">/g,StrPath+"$&");
@ -407,6 +428,14 @@
<script type="text/javascript" src="./JS/terahashlib.js"><\/script>\ <script type="text/javascript" src="./JS/terahashlib.js"><\/script>\
'+SriptLW+SetData.Body; '+SriptLW+SetData.Body;
SetData.Body+=$("idModalCSS").outerHTML;
SetData.Body+=$("idOverlay").outerHTML;
SetData.Body+=$("idConfirm").outerHTML;
iframe.srcdoc=SetData.Body; iframe.srcdoc=SetData.Body;
document.getElementsByTagName('body')[0].appendChild(iframe); document.getElementsByTagName('body')[0].appendChild(iframe);
@ -455,7 +484,6 @@
StrRef='<A class="btcreate" href="'+GetWalletLink()+'">Accounts</A>'; StrRef='<A class="btcreate" href="'+GetWalletLink()+'">Accounts</A>';
} }
//var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button> or goto '+StrRef+' tab and Set smart number <B>'+SMART.Num+'</B> to your account<DIV>';
var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button><DIV>'; var Str='<DIV style="background-color: #c8ecff;">For install this app press: <button class="btcreate" onclick="InstallApp()">Create account</button><DIV>';
SetStatus(Str); SetStatus(Str);
} }
@ -662,7 +690,7 @@
CloseMenu(); CloseMenu();
} }
break; break;
case 115: case 116:
e.preventDefault(); e.preventDefault();
ReloadDapp(); ReloadDapp();
break; break;
@ -814,6 +842,7 @@
</style> </style>
</head> </head>
<body> <body>
<DIV id="idStatus" class="top"></DIV> <DIV id="idStatus" class="top"></DIV>
@ -821,16 +850,77 @@
<div id="idMenuList" class="top open"> <div id="idMenuList" class="top open">
<div class="item" onclick="OpenWalletPage();">Open wallet page</div> <div class="item" onclick="OpenWalletPage();">Open wallet page</div>
<div class="item" onclick="RunDappFromFile();" id="idRunItem">Load from file...</div> <div class="item" onclick="RunDappFromFile();" id="idRunItem">Load from file...</div>
<div class="item" onclick="ReloadDapp();">F4: Rerun</div> <div class="item" onclick="ReloadDapp();">F5: ReRun</div>
<div class="item" onclick="window.location.reload();">Reset</div>
<div class="item" onclick="InstallApp();" id="idCreateItem">Create account with DApp NNN</div> <div class="item" onclick="InstallApp();" id="idCreateItem">Create account with DApp NNN</div>
</div> </div>
</DIV> </DIV>
<input type="file" id="idFile" style="display: none"> <input type="file" id="idFile" style="display: none">
<!--modal support dor dapp-->
<style id="idModalCSS">
/*modal support*/
#idOverlay
{
background: rgba(68, 83, 104, 0.65);
position: fixed;
width: 100%;
height: 100vh;
top: 0;
display: none;
}
.ModalDlg
{
z-index: 1000;
padding: 30px;
background: #fff;
border-radius: 5px;
border: 1px solid #727473;
box-shadow: 0px 8px 10px rgba(68, 83, 104, 0.15);
color: #000;
position: fixed;
margin: 0 auto;
top: 30%;
left: 50%;
transform: translate(-50%, -50%);
max-width: 250px;
width: 87%;
}
.bt-confirm
{
border-radius: 4px;
min-height: 14px;
margin: 5px;
width: 100px;
height: 36px;
color:white;
background-color: #53687e;
border-color: #445368;
}
.bt-confirm:hover
{
color: #cb763a;
cursor: pointer;
}
</style>
<div id="idOverlay" onclick="closeModal()" style="display: none;"></div>
<section id="idConfirm" class="ModalDlg" style="display: none;">
<DIV align='center'>
<h2 id="idConfirmTitle">Confirm</h2>
<p id="idConfirmText">A you sure?</p>
<button class="bt-confirm" onclick="OnConfirmOK()">OK</button>
<button class="bt-confirm" onclick="closeModal()">Cancel</button>
</DIV>
</section>
</body> </body>
</html> </html>
<script> <script>
var glDebugPath=""; var glDebugPath="";
//glDebugPath="./dapp-smart/mixer/mixer.html";
//{"HTMLBlock":2303846,"HTMLTr":0} //{"HTMLBlock":2303846,"HTMLTr":0}
</script> </script>

View File

@ -1419,6 +1419,7 @@
<body> <body>
<DIV align='center'> <DIV align='center'>
<DIV align='left' style="width: 800px;border2: 1px solid #727473;"> <DIV align='left' style="width: 800px;border2: 1px solid #727473;">
@ -1454,8 +1455,7 @@
</DIV> </DIV>
<DIV id="idDevelopService" style="display: none"> <DIV id="idDevelopService" style="display: none">
<BR> <BR>
<INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')" <INPUT type="button" id="idDown" onclick="SetVisibleBlock('idDevelopServiceView',!IsVisibleBlock('idDevelopServiceView'));SetImg(this,'idDevelopServiceView')" class="btdoit bt" value="DEV SERVICE">
class="btdoit bt" value="DEV SERVICE">
<DIV id="idDevelopServiceView" style="display: none"> <DIV id="idDevelopServiceView" style="display: none">
<table> <table>
<tr> <tr>
@ -1598,6 +1598,7 @@
<th id="(RetHistoryAccount(Item))" class="num">ID</th> <th id="(RetHistoryAccount(Item))" class="num">ID</th>
<th id="SUM_TO_STRING(Item.Value)" class="sum bold">Amount</th> <th id="SUM_TO_STRING(Item.Value)" class="sum bold">Amount</th>
<th id="CurrencyNameItem(Item)" data-name="Currency" class="cur hint">Cur</th> <th id="CurrencyNameItem(Item)" data-name="Currency" class="cur hint">Cur</th>
<!--<th id="(CurrencyNameItemHTML(Item))" data-name="Currency" class="cur hint">Cur</th>-->
<th id="Item.Name" data-name="Account name" class="accname hint">Name</th> <th id="Item.Name" data-name="Account name" class="accname hint">Name</th>
<th id="Item.Value.OperationID" data-name="Operation ID" class="snum hint">OP</th> <th id="Item.Value.OperationID" data-name="Operation ID" class="snum hint">OP</th>
<th id="(RetHistoryAccount(Item,'Adviser'))" data-name="Adviser" class="snum hint">Adv</th> <th id="(RetHistoryAccount(Item,'Adviser'))" data-name="Adviser" class="snum hint">Adv</th>
@ -1736,7 +1737,9 @@
{ {
var Item=MapAccounts[$("idAccount").value]; var Item=MapAccounts[$("idAccount").value];
if(Item) if(Item)
$("idSumSend").value=FLOAT_FROM_COIN(Item.Value).toStringF(); {
$("idSumSend").value=ToFixed(FLOAT_FROM_COIN(Item.Value),Item.Currency);
}
} }
</script> </script>
@ -2060,8 +2063,10 @@
</audio> </audio>
</DIV>
</DIV> </DIV>
</DIV>
</body> </body>
</html> </html>

View File

@ -63,7 +63,7 @@
</svg> </svg>
</div> </div>
<h1 class="welcome__title title">Welcome to TERA Wallet</h1> <h1 class="welcome__title title">Welcome to TERA Wallet</h1>
<p><a onclick="OpenHelp()" class="pointer">HELP: Tera Wallet creation Guide...</a></p> <p><a onclick="OpenHelp()" class="pointer">Tera Wallet Guide...</a></p>
<p><a onclick="SelectTab('TabKeySet')" class="pointer">ATTENTION: Before using the wallet, save the private key.</a></p> <p><a onclick="SelectTab('TabKeySet')" class="pointer">ATTENTION: Before using the wallet, save the private key.</a></p>
<ul id="idStableScroll" align='center' class="social-list"> <ul id="idStableScroll" align='center' class="social-list">

View File

@ -8,7 +8,7 @@
* Telegram: https://t.me/terafoundation * Telegram: https://t.me/terafoundation
*/ */
global.UPDATE_CODE_VERSION_NUM = 1194; global.UPDATE_CODE_VERSION_NUM = 1213;
global.MIN_CODE_VERSION_NUM = 1114; global.MIN_CODE_VERSION_NUM = 1114;
global.MINING_VERSION_NUM = 0; global.MINING_VERSION_NUM = 0;
global.InitParamsArg = InitParamsArg; global.InitParamsArg = InitParamsArg;
@ -21,6 +21,7 @@ global.CONST_NAME_ARR = ["AUTO_CORRECT_TIME", "DELTA_CURRENT_TIME", "COMMON_KEY"
"HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "HTTP_ADMIN_PASSWORD", "HTTP_START_PAGE", "WATCHDOG_BADACCOUNT", "RESYNC_CONDITION", "HTTPS_HOSTING_DOMAIN", "HTTP_MAX_COUNT_ROWS", "HTTP_ADMIN_PASSWORD", "HTTP_START_PAGE", "WATCHDOG_BADACCOUNT", "RESYNC_CONDITION",
"MAX_CONNECTIONS_COUNT", "TRUST_PROCESS_COUNT", "REST_START_COUNT", "LOAD_TO_BEGIN", ]; "MAX_CONNECTIONS_COUNT", "TRUST_PROCESS_COUNT", "REST_START_COUNT", "LOAD_TO_BEGIN", ];
global.UPDATE_CODE_1 = 36000000; global.UPDATE_CODE_1 = 36000000;
global.UPDATE_CODE_2 = 40000000;
global.MAX_LENGTH_SENDER_MAP = 3000; global.MAX_LENGTH_SENDER_MAP = 3000;
global.DELTA_START_SENDER_MAP = 24; global.DELTA_START_SENDER_MAP = 24;
global.NODES_DELTA_CALC_HOUR = 4; global.NODES_DELTA_CALC_HOUR = 4;
@ -171,6 +172,7 @@ if(global.LOCAL_RUN)
global.AUTO_CORRECT_TIME = 0; global.AUTO_CORRECT_TIME = 0;
global.CHECK_GLOBAL_TIME = 0; global.CHECK_GLOBAL_TIME = 0;
global.UPDATE_CODE_1 = 0; global.UPDATE_CODE_1 = 0;
global.UPDATE_CODE_2 = 0;
} }
else else
if(global.TEST_NETWORK) if(global.TEST_NETWORK)
@ -207,6 +209,7 @@ else
global.LOAD_TO_BEGIN = 2; global.LOAD_TO_BEGIN = 2;
global.START_BAD_ACCOUNT_CONTROL = 3105000; global.START_BAD_ACCOUNT_CONTROL = 3105000;
global.UPDATE_CODE_1 = 3180000; global.UPDATE_CODE_1 = 3180000;
global.UPDATE_CODE_2 = 4000000;
} }
global.GetNetworkName = function () global.GetNetworkName = function ()
{ {

View File

@ -332,6 +332,14 @@ function SendToResponceResult0(response)
var glBlock0; var glBlock0;
HTTPCaller.DappStaticCall = function (Params,response) HTTPCaller.DappStaticCall = function (Params,response)
{ {
var Result = RunStaticSmartMethod(ParseNum(Params.Account), Params.MethodName, Params.Params);
var Str = JSON.stringify(Result);
if(Str.length > 16000)
{
return {result:0, RetValue:"Error result length (more 16000)"};
}
response.end(Str);
return null;
DApps.Accounts.BeginBlock(); DApps.Accounts.BeginBlock();
DApps.Accounts.BeginTransaction(); DApps.Accounts.BeginTransaction();
global.TickCounter = 100000; global.TickCounter = 100000;
@ -345,7 +353,9 @@ HTTPCaller.DappStaticCall = function (Params,response)
var RetValue; var RetValue;
try try
{ {
RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, 0, 0, undefined, Params.MethodName, Params.Params, 1); var BlockNum = GetCurrentBlockNumByTime();
RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, BlockNum, 0, undefined, Params.MethodName, Params.Params,
1);
} }
catch(e) catch(e)
{ {
@ -409,7 +419,6 @@ HTTPCaller.DappInfo = function (Params,responce,ObjectOnly)
{ {
Ret.CurTime = Date.now(); Ret.CurTime = Date.now();
Ret.CurBlockNum = GetCurrentBlockNumByTime(); Ret.CurBlockNum = GetCurrentBlockNumByTime();
Ret.BlockNumDB = SERVER.BlockNumDB;
Ret.MaxAccID = DApps.Accounts.GetMaxAccount(); Ret.MaxAccID = DApps.Accounts.GetMaxAccount();
Ret.MaxDappsID = DApps.Smart.GetMaxNum(); Ret.MaxDappsID = DApps.Smart.GetMaxNum();
} }
@ -1895,6 +1904,8 @@ function GetUserContext(Params)
if(!Context) if(!Context)
{ {
Context = {NumDappInfo:0, PrevDappInfo:"", NumAccountList:0, PrevAccountList:"", LastTime:0, FromEventNum:0}; Context = {NumDappInfo:0, PrevDappInfo:"", NumAccountList:0, PrevAccountList:"", LastTime:0, FromEventNum:0};
Context.Session = Params.Session;
Context.Key = StrKey;
WebWalletUser[StrKey] = Context; WebWalletUser[StrKey] = Context;
} }
return Context; return Context;

View File

@ -42,7 +42,7 @@ module.exports = class CRest extends require("./db/block-db")
return ; return ;
} }
this.LoadRestContext = {Mode:0, BlockNum:BlockNumRest, BlockNumRest:BlockNumRest, WasDelta:Delta, BlockNumProof:BlockNumRest + DELTA_BLOCK_ACCOUNT_HASH, this.LoadRestContext = {Mode:0, BlockNum:BlockNumRest, BlockNumRest:BlockNumRest, WasDelta:Delta, BlockNumProof:BlockNumRest + DELTA_BLOCK_ACCOUNT_HASH,
CountProof:COUNT_BLOCKS_FOR_LOAD, StartTimeHistory:Date.now(), MaxTimeOut:600 * 1000, LoopSyncRest:1, SendGetHeaderCount:0, CountProof:COUNT_BLOCKS_FOR_LOAD, StartTimeHistory:Date.now(), MaxTimeOut:3600 * 1000, LoopSyncRest:1, SendGetHeaderCount:0,
ReceiveHeaderCount:0, ArrProof:[], MapSend:{}} ReceiveHeaderCount:0, ArrProof:[], MapSend:{}}
for(var i = 0; i < this.NodesArr.length; i++) for(var i = 0; i < this.NodesArr.length; i++)
{ {

View File

@ -632,7 +632,7 @@ HostingCaller.GetAccountListByKey = function (Params,aaa,bbb,bRet)
if(!Data.PubKeyStr) if(!Data.PubKeyStr)
Data.PubKeyStr = GetHexFromArr(Data.PubKey); Data.PubKeyStr = GetHexFromArr(Data.PubKey);
if(Data.Currency) if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency); Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1);
if(Data.Value.Smart) if(Data.Value.Smart)
{ {
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart); Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart);
@ -742,15 +742,17 @@ HostingCaller.DappInfo = function (Params)
var StrInfo = JSON.stringify(Ret); var StrInfo = JSON.stringify(Ret);
if(!Params.AllData && Context.PrevDappInfo === StrInfo) if(!Params.AllData && Context.PrevDappInfo === StrInfo)
{ {
return {result:0, cache:1}; Ret = {result:2, cache:1, Session:Context.Session};
} }
else
{
Context.PrevDappInfo = StrInfo; Context.PrevDappInfo = StrInfo;
Context.NumDappInfo++; Context.NumDappInfo++;
Context.LastTime = Date.now(); Context.LastTime = Date.now();
}
Ret.NumDappInfo = Context.NumDappInfo; Ret.NumDappInfo = Context.NumDappInfo;
Ret.CurTime = Date.now(); Ret.CurTime = Date.now();
Ret.CurBlockNum = GetCurrentBlockNumByTime(); Ret.CurBlockNum = GetCurrentBlockNumByTime();
Ret.BlockNumDB = SERVER.BlockNumDB;
Ret.MaxAccID = DApps.Accounts.GetMaxAccount(); Ret.MaxAccID = DApps.Accounts.GetMaxAccount();
Ret.MaxDappsID = DApps.Smart.GetMaxNum(); Ret.MaxDappsID = DApps.Smart.GetMaxNum();
return Ret; return Ret;

View File

@ -973,7 +973,7 @@ class AccountApp extends require("./dapp")
var Count = 0; var Count = 0;
for(var num = 0; true; num++) for(var num = 0; true; num++)
{ {
if(this.IsHole(num) || HiddenMap[num] !== undefined) if(this.IsHole(num) || (HiddenMap && HiddenMap[num] !== undefined))
continue; continue;
var Data = this.ReadState(num); var Data = this.ReadState(num);
if(!Data) if(!Data)
@ -1002,7 +1002,9 @@ class AccountApp extends require("./dapp")
Data.WN = map[key] Data.WN = map[key]
Data.Name = NormalizeName(Data.Name) Data.Name = NormalizeName(Data.Name)
if(Data.Currency) if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency) {
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1)
}
if(Data.Value.Smart) if(Data.Value.Smart)
{ {
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart) Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart)
@ -1093,7 +1095,7 @@ class AccountApp extends require("./dapp")
if(bGetState) if(bGetState)
{ {
if(Data.Currency) if(Data.Currency)
Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency) Data.CurrencyObj = DApps.Smart.ReadSimple(Data.Currency, 1)
if(Data.Value.Smart) if(Data.Value.Smart)
{ {
Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart) Data.SmartObj = DApps.Smart.ReadSimple(Data.Value.Smart)

View File

@ -28,7 +28,9 @@ global.FORMAT_SMART_CREATE = "{\
Category1:byte,\ Category1:byte,\
Category2:byte,\ Category2:byte,\
Category3:byte,\ Category3:byte,\
Reserve:arr20,\ Fixed:byte,\
CentName:str5,\
Reserve:arr14,\
IconBlockNum:uint,\ IconBlockNum:uint,\
IconTrNum:uint16,\ IconTrNum:uint16,\
ShortName:str5,\ ShortName:str5,\
@ -82,7 +84,9 @@ class SmartApp extends require("./dapp")
Category2:byte,\ Category2:byte,\
Category3:byte,\ Category3:byte,\
Owner:uint,\ Owner:uint,\
Reserve:arr20,\ Fixed:byte,\
CentName:str5,\
Reserve:arr14,\
StateFormat:str,\ StateFormat:str,\
Description:str,\ Description:str,\
Code:str,\ Code:str,\
@ -238,7 +242,6 @@ class SmartApp extends require("./dapp")
Smart.Zip = 0 Smart.Zip = 0
Smart.BlockNum = BlockNum Smart.BlockNum = BlockNum
Smart.TrNum = TrNum Smart.TrNum = TrNum
Smart.Reserve = []
Smart.Num = undefined Smart.Num = undefined
Smart.Owner = ContextFrom.FromID Smart.Owner = ContextFrom.FromID
this.DBSmart.CheckNewNum(Smart) this.DBSmart.CheckNewNum(Smart)
@ -275,6 +278,10 @@ class SmartApp extends require("./dapp")
this.DBSmart.DeleteMap("EVAL" + Smart.Num) this.DBSmart.DeleteMap("EVAL" + Smart.Num)
return e; return e;
} }
if(BlockNum < global.UPDATE_CODE_2)
{
Smart.Reserve = []
}
this.DBSmartWrite(Smart) this.DBSmartWrite(Smart)
return true; return true;
} }
@ -502,7 +509,7 @@ class SmartApp extends require("./dapp")
} }
return Smart; return Smart;
} }
ReadSimple(Num) ReadSimple(Num, bTokenDescription)
{ {
var Smart = this.DBSmart.GetMap("SIMPLE" + Num); var Smart = this.DBSmart.GetMap("SIMPLE" + Num);
if(!Smart) if(!Smart)
@ -512,14 +519,70 @@ class SmartApp extends require("./dapp")
{ {
Smart.CodeLength = Smart.Code.length Smart.CodeLength = Smart.Code.length
Smart.HTMLLength = Smart.HTML.length Smart.HTMLLength = Smart.HTML.length
Smart.Code = undefined Object.defineProperties(Smart, {Reserve:{configurable:true, enumerable:false}})
Smart.HTML = undefined Object.defineProperties(Smart, {Code:{configurable:true, enumerable:false}})
Smart.Description = undefined Object.defineProperties(Smart, {HTML:{configurable:true, enumerable:false}})
Object.defineProperties(Smart, {Description:{configurable:true, enumerable:false}})
this.DBSmart.SetMap("SIMPLE" + Num, Smart) this.DBSmart.SetMap("SIMPLE" + Num, Smart)
} }
} }
if(bTokenDescription)
this.AddCurrencyTokenDescription(Smart)
return Smart; return Smart;
} }
AddCurrencyTokenDescription(Smart)
{
if(!Smart.Num)
return ;
if(!this.MapTokenDescription)
this.MapTokenDescription = {}
var Item = this.MapTokenDescription[Smart.Num];
var Time = Date.now();
if(!Item)
{
Item = {Time:Time, Description:""}
this.MapTokenDescription[Smart.Num] = Item
}
if(Time - Item.Time > 5 * 1000)
{
Item.Time = Time
var Params = undefined;
var BlockNum = GetCurrentBlockNumByTime();
if(BlockNum < UPDATE_CODE_2)
{
try
{
var Account = DApps.Accounts.ReadState(Smart.Account);
if(Smart.StateFormat)
{
var State = BufLib.GetObjectFromBuffer(Account.Value.Data, Smart.StateFormat, {}, 1);
Params = {State:State, PayCur:GET_SMART(DApps.Smart.ReadSmart(State.PayCurrency)), OpnCur:GET_SMART(DApps.Smart.ReadSmart(State.Currency)),
}
}
}
catch(e)
{
}
}
else
{
Params = {}
}
var Result;
if(Params)
Result = RunStaticSmartMethod(Smart.Account, "GetTokenDescription", Params)
if(Result && Result.result)
{
Item.TokenDescription = Result.RetValue
}
else
{
Item.TokenDescription = ""
Item.Time = Time + 1000 * 1000
}
}
Smart.TokenDescription = Item.TokenDescription
}
InitHole() InitHole()
{ {
if(global.LOCAL_RUN || global.TEST_NETWORK) if(global.LOCAL_RUN || global.TEST_NETWORK)
@ -628,7 +691,7 @@ function RunSmartMethod(Block,SmartOrSmartID,Account,BlockNum,TrNum,PayContext,M
if(PayContext.Value) if(PayContext.Value)
context.Value = {SumCOIN:PayContext.Value.SumCOIN, SumCENT:PayContext.Value.SumCENT}; context.Value = {SumCOIN:PayContext.Value.SumCOIN, SumCENT:PayContext.Value.SumCENT};
} }
if(BlockNum === 0) if(Block.BlockNum === 0)
{ {
context.GetBlockHeader = StaticGetBlockHeader; context.GetBlockHeader = StaticGetBlockHeader;
context.GetBlockNumDB = StaticGetBlockNumDB; context.GetBlockNumDB = StaticGetBlockNumDB;
@ -653,6 +716,32 @@ function RunSmartMethod(Block,SmartOrSmartID,Account,BlockNum,TrNum,PayContext,M
} }
return RetValue; return RetValue;
}; };
var glBlock0;
global.RunStaticSmartMethod = RunStaticSmartMethod;
function RunStaticSmartMethod(AccountNum,MethodName,Params)
{
DApps.Accounts.BeginBlock();
DApps.Accounts.BeginTransaction();
global.TickCounter = 100000;
var Account = DApps.Accounts.ReadStateTR(AccountNum);
if(!Account)
{
return {result:0, RetValue:"Error account Num: " + AccountNum};
}
if(!glBlock0)
glBlock0 = SERVER.ReadBlockHeaderDB(0);
try
{
var BlockNum = GetCurrentBlockNumByTime();
var RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, BlockNum, 0, undefined, MethodName, Params, 1);
return {result:1, RetValue:RetValue};
}
catch(e)
{
return {result:0, RetValue:"" + e};
}
};
function GET_ACCOUNT(Obj) function GET_ACCOUNT(Obj)
{ {
@ -739,6 +828,15 @@ function GET_SMART(Obj)
}, get HTML() }, get HTML()
{ {
return Data.HTML; return Data.HTML;
}, get Fixed()
{
return Data.Fixed;
}, get CoinName()
{
return Data.ShortName;
}, get CentName()
{
return Data.CentName;
}, }; }, };
return GET_PROP; return GET_PROP;
}; };
@ -937,6 +1035,7 @@ function InitEval()
Object.freeze($GetHexFromArr); Object.freeze($GetHexFromArr);
Object.freeze($GetArrFromHex); Object.freeze($GetArrFromHex);
Object.freeze($sha); Object.freeze($sha);
Object.freeze($ReadSmart);
Object.freeze($isFinite); Object.freeze($isFinite);
Object.freeze($isNaN); Object.freeze($isNaN);
Object.freeze($parseFloat); Object.freeze($parseFloat);
@ -1083,6 +1182,7 @@ function $SetValue(ID,CoinSum)
{ {
CoinSum = COIN_FROM_FLOAT(CoinSum); CoinSum = COIN_FROM_FLOAT(CoinSum);
} }
CHECKSUM(CoinSum);
if(CoinSum.SumCENT >= 1e9) if(CoinSum.SumCENT >= 1e9)
{ {
throw "ERROR SumCENT>=1e9"; throw "ERROR SumCENT>=1e9";
@ -1119,7 +1219,7 @@ function $Send(ToID,CoinSum,Description)
} }
if(RunContext.Account.Currency !== ToData.Currency) if(RunContext.Account.Currency !== ToData.Currency)
{ {
throw "Different currencies"; throw "Different currencies. Accounts: " + RunContext.Account.Num + " and " + ToID;
} }
DApps.Accounts.SendMoneyTR(RunContext.Block, RunContext.Account.Num, ToID, CoinSum, RunContext.BlockNum, RunContext.TrNum, DApps.Accounts.SendMoneyTR(RunContext.Block, RunContext.Account.Num, ToID, CoinSum, RunContext.BlockNum, RunContext.TrNum,
Description, Description, 1); Description, Description, 1);
@ -1142,7 +1242,7 @@ function $Move(FromID,ToID,CoinSum,Description)
} }
if(FromData.Currency !== ToData.Currency) if(FromData.Currency !== ToData.Currency)
{ {
throw "Different currencies"; throw "Different currencies. Accounts: " + FromID + " and " + ToID;
} }
if(FromData.Value.Smart !== RunContext.Smart.Num) if(FromData.Value.Smart !== RunContext.Smart.Num)
{ {
@ -1190,6 +1290,20 @@ function $ReadAccount(ID)
return GET_ACCOUNT(Account); return GET_ACCOUNT(Account);
}; };
function $ReadSmart(ID)
{
if(RunContext.BlockNum < global.UPDATE_CODE_2)
{
throw "Method call not available";
}
DO(900);
ID = ParseNum(ID);
var Smart = DApps.Smart.ReadSmart(ID);
if(!Smart)
throw "Error smart ID: " + ID;
return GET_SMART(Smart);
};
function $ReadState(ID) function $ReadState(ID)
{ {
DO(900); DO(900);