@ -175,6 +175,11 @@ function SendTransaction(Body,TR,SumPow,F)
SetError ( "Cannt SEND TR: " + JSON . stringify ( TR ) ) ;
} ;
function ReloadDapp ( )
{
SendData ( { cmd : "ReloadDapp" } ) ;
} ;
function CurrencyName ( Num )
{
var Name = MapCurrency [ Num ] ;
@ -232,6 +237,8 @@ function FindAllCurrencyNext(StartNum)
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 ( Path . substr ( 0 , 1 ) !== "/" )
@ -277,6 +284,89 @@ function GetState(AccNum,F,FErr)
}
} ) ;
} ;
var glWasModal = 0 ;
function openModal ( id )
{
glWasModal = 1 ;
var modal = document . querySelector ( "#" + id ) ;
var overlay = document . querySelector ( "#idOverlay" ) ;
modal . style . display = "block" ;
overlay . style . display = "block" ;
} ;
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 )
{
DappBlockFile ( Block , Tr , function ( Err , Data )
{
if ( ! Err && Data . Type === 135 )
{
try
{
var Params = JSON . parse ( Data . Params ) ;
}
catch ( e )
{
}
if ( Params )
{
F ( 0 , Params , Data . MethodName , Data . FromNum ) ;
return ;
}
}
F ( 1 ) ;
} ) ;
} ;
function UpdateListArr ( Block , Tr , Arr , StopBlock , IgnoreTailBlock , MaxDepth , F )
{
@ -286,53 +376,251 @@ function UpdateListArr(Block,Tr,Arr,StopBlock,IgnoreTailBlock,MaxDepth,F)
} ) ;
if ( Arr . length )
StopBlock = Math . max ( StopBlock , Arr [ Arr . length - 1 ] . BlockNum ) ;
Update ListArrNext ( Block , Tr , Arr , StopBlock , IgnoreTailBlock , MaxDepth , F ) ;
Update RowArr ( Block , Tr , Arr , StopBlock , IgnoreTailBlock , MaxDepth , F ) ;
} ;
function Update ListArrNext ( Block , Tr , Arr , StopMinBlock , IgnoreTailBlock , MaxDepth , F )
function Update RowArr ( Block , Tr , Arr , StopMinBlock , IgnoreTailBlock , MaxDepth , F )
{
if ( Block <= StopMinBlock || ! MaxDepth )
return ;
SendCountUpdate ++ ;
DappBlockFile ( Block , Tr , function ( Err , Data )
Get DappBlock( Block , Tr , function ( Err , Params )
{
SendCountUpdate -- ;
if ( ! Err && Data . Type === 135 )
if ( ! Err )
{
try
if( Block <= INFO . CurBlockNum - IgnoreTailBlock )
{
var Params = JSON . parse ( Data . Params ) ;
Params . BlockNum = Block ;
Params . TrNum = Tr ;
Params . Num = Params . BlockNum * 100000 + Params . TrNum ;
Params . Time = Date . now ( ) ;
if ( ! Arr . length || Arr [ Arr . length - 1 ] . Num !== Params . Num )
{
if ( F )
{
if ( F ( Params ) )
{
return ;
}
}
else
{
Arr . push ( Params ) ;
}
}
}
catch ( e )
if( Params . PrevBlock )
{
UpdateRowArr ( Params . PrevBlock , Params . PrevTr , Arr , StopMinBlock , IgnoreTailBlock , MaxDepth - 1 , F ) ;
}
if ( Params )
}
} ) ;
} ;
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 ( Block <= INFO . CurBlockNum - IgnoreTailBlock )
if ( Elem. VB )
{
Params . BlockNum = Block ;
Params . TrNum = Tr ;
Params . Num = Params . BlockNum * 100000 + Params . TrNum ;
Params . Time = Date . now ( ) ;
if ( ! Arr . length || Arr [ Arr . length - 1 ] . Num !== Params . Num )
Arr . push ( Params ) ;
LoadElement ( Elem , i , PathArr , F ) ;
}
if ( Params . PrevBlock )
else
{
UpdateListArrNext ( Params . PrevBlock , Params . PrevTr , Arr , StopMinBlock , IgnoreTailBlock , MaxDepth - 1 , F ) ;
F ( 1 , Elem , PathArr ) ;
}
return ;
}
}
if ( F && SendCountUpdate === 0 )
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 )
{
Arr . sort ( function ( a , b )
var KeyNumStr = KeyNum . toString ( 2 ) ;
var Arr = Params . Arr ;
for ( var L = Level ; Arr && L < Arr . length ; L ++ )
{
return a . Num - b . Num ;
} ) ;
F ( Arr ) ;
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 glKeyF = 0 ;
@ -492,23 +780,13 @@ function GetDappParams(BNum,TrNum,F,bAll)
return ;
}
SendCountDappParams ++ ;
DappBlockFile ( BNum , TrNum , function ( Err , Data )
Get DappBlock( BNum , TrNum , function ( Err , Params, MethodName , FromNum )
{
SendCountDappParams -- ;
if ( ! Err && Data . Type === 135 )
if ( ! Err )
{
try
{
var Params = JSON . parse ( Data . Params ) ;
}
catch ( e )
{
}
if ( Params )
{
F ( Params , Data . MethodName , Data . FromNum ) ;
return ;
}
F ( Params , MethodName , FromNum ) ;
return ;
}
if ( bAll )
F ( ) ;
@ -595,3 +873,23 @@ window.addEventListener('load', function ()
UpdateDappInfo ( ) ;
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 ( ) ;
}
} ;