This commit is contained in:
progr76@gmail.com
2019-02-16 20:08:41 +03:00
parent 4087d50a65
commit 5affe69fe0
19 changed files with 304 additions and 77 deletions

View File

@@ -313,7 +313,7 @@ class STreeBuffer
SaveValue(Hash, Value)
{
if(typeof Hash !== this.KeyType)
throw "MUST ONLY HASH ARRAY: " + Hash;
throw "MUST ONLY TYPE=" + this.KeyType + " in " + Hash;
if(Value !== undefined)
{
var element = this.MetaTree1.find({hash:Hash});

View File

@@ -753,7 +753,7 @@ module.exports = class CBlock extends require("./db/block-db")
if(CompareArr(BlockDB.TreeHash, Block.TreeHash) == 0)
{
Block.TreeEq = true
Block.BodyFileNum = BlockDB.BodyFileNum
Block.Reserv500 = BlockDB.Reserv500
Block.TrDataPos = BlockDB.TrDataPos
Block.TrDataLen = BlockDB.TrDataLen
continue;
@@ -856,7 +856,6 @@ module.exports = class CBlock extends require("./db/block-db")
{
if(IsZeroArr(Block.TreeHash))
{
Block.BodyFileNum = 0
Res = this.WriteBlockDB(Block)
}
else
@@ -1124,7 +1123,6 @@ module.exports = class CBlock extends require("./db/block-db")
}
}
}
Block.BodyFileNum = this.GetChainFileNum(Block.chain)
Block.arrContent = arrContent
var Ret = this.WriteBodyDB(Block);
Block.TrCount = 0

View File

@@ -8,7 +8,7 @@
* Telegram: https://web.telegram.org/#/im?p=@terafoundation
*/
global.UPDATE_CODE_VERSION_NUM = 891;
global.UPDATE_CODE_VERSION_NUM = 893;
global.MIN_CODE_VERSION_NUM = 884;
global.MINING_VERSION_NUM = 3;
global.InitParamsArg = InitParamsArg;

View File

@@ -164,10 +164,6 @@ module.exports = class CDB extends require("../code")
}
return num > 0 ? num - 1 : 0;
}
GetChainFileNum(chain)
{
return 0;
}
WriteBlockDB(Block)
{
var startTime = process.hrtime();
@@ -212,6 +208,34 @@ module.exports = class CDB extends require("../code")
}
return Ret;
}
WriteBodyResultDB(Block)
{
var arrTr = Block.arrContentResult;
if(Block.TrDataPos && Block.TrDataLen && Block.VersionBody && arrTr && arrTr.length)
{
var FileItem = BlockDB.OpenDBFile(FILE_NAME_BODY, 1);
var FD = FileItem.fd;
var Size = arrTr.length * 6;
var Position = Block.TrDataPos + Block.TrDataLen - Size;
if(FileItem.size < Position + Size)
{
TO_ERROR_LOG("DB", 241, "Error Position in WriteBodyResultDB on block: " + Block.BlockNum)
return false;
}
var BufWrite = BufLib.GetNewBuffer(Size);
for(var i = 0; i < arrTr.length; i++)
{
BufWrite.Write(arrTr[i], "uint")
}
var written = fs.writeSync(FD, BufWrite, 0, BufWrite.length, Position);
if(written !== BufWrite.length)
{
TO_ERROR_LOG("DB", 242, "Error write to file block-chain : " + written + " <> " + BufWrite.length)
return false;
}
}
return true;
}
WriteBodyDB(Block)
{
var FileItem = BlockDB.OpenDBFile(FILE_NAME_BODY, 1);
@@ -233,9 +257,11 @@ module.exports = class CDB extends require("../code")
arrSize[i] = 2 + body.length
TrDataLen += arrSize[i]
}
Block.VersionBody = 1
TrDataLen += arrTr.length * 6
var BufWrite = BufLib.GetNewBuffer(TrDataLen);
BufWrite.Write(arrTr.length, "uint16")
BufWrite.Write(0, "uint16")
BufWrite.Write(Block.VersionBody, "uint16")
for(var i = 0; i < arrTr.length; i++)
{
var body = arrTr[i];
@@ -337,8 +363,9 @@ module.exports = class CDB extends require("../code")
return false;
}
Block.arrContent = []
Block.arrContentResult = []
var TrCount = BufRead.Read("uint16");
var TrCountDapp = BufRead.Read("uint16");
Block.VersionBody = BufRead.Read("uint16")
if(TrCount <= MAX_TRANSACTION_COUNT)
{
for(var i = 0; i < TrCount; i++)
@@ -348,6 +375,15 @@ module.exports = class CDB extends require("../code")
break;
Block.arrContent[i] = body
}
if(Block.VersionBody === 1)
{
var Size = TrCount * 6;
BufRead.len = Block.TrDataLen - Size
for(var i = 0; i < TrCount; i++)
{
Block.arrContentResult[i] = BufRead.Read("uint")
}
}
}
Block.TrCount = Block.arrContent.length
return true;
@@ -475,14 +511,14 @@ module.exports = class CDB extends require("../code")
}
BlockHeaderToBuf(BufWrite, Block)
{
Block.BodyFileNum = 0
Block.Reserv500 = 0
var len = BufWrite.len;
BufWrite.Write(Block.TreeHash, "hash")
BufWrite.Write(Block.AddrHash, "hash")
BufWrite.Write(Block.PrevHash, "hash")
BufWrite.Write(Block.SumHash, "hash")
BufWrite.Write(Block.SumPow, "uint")
BufWrite.Write(Block.BodyFileNum, "uint")
BufWrite.Write(Block.Reserv500, "uint")
BufWrite.Write(Block.TrDataPos, "uint")
BufWrite.Write(Block.TrDataLen, "uint32")
BufWrite.len = len + BLOCK_HEADER_SIZE
@@ -498,7 +534,7 @@ module.exports = class CDB extends require("../code")
Block.PrevHash = BufRead.Read("hash")
Block.SumHash = BufRead.Read("hash")
Block.SumPow = BufRead.Read("uint")
Block.BodyFileNum = BufRead.Read("uint")
Block.Reserv500 = BufRead.Read("uint")
Block.TrDataPos = BufRead.Read("uint")
Block.TrDataLen = BufRead.Read("uint32")
Block.TrCount = 0
@@ -593,9 +629,15 @@ module.exports = class CDB extends require("../code")
if(App)
{
Tr.Script = App.GetScriptTransaction(Tr.body)
Tr.Verify = App.GetVerifyTransaction(BlockNum, Tr.Num, Tr.body)
if(Tr.Verify == 1)
Tr.Verify = App.GetVerifyTransaction(Block, BlockNum, Tr.Num, Tr.body)
if(Tr.Verify >= 1)
{
Tr.VerifyHTML = "<B style='color:green'>✔</B>"
if(Tr.Verify > 1)
{
Tr.VerifyHTML += "(" + Tr.Verify + ")"
}
}
else
if(Tr.Verify == - 1)
Tr.VerifyHTML = "<B style='color:red'>✘</B>"

View File

@@ -367,7 +367,7 @@ HTTPCaller.ToLogServer = function (Str)
};
HTTPCaller.FindMyAccounts = function (Params)
{
WALLET.FindMyAccounts();
WALLET.FindMyAccounts(1);
return {result:1};
};
HTTPCaller.GetAccount = function (id)

View File

@@ -92,6 +92,7 @@ module.exports = class CSmartContract extends require("./block-exchange")
{
DApps[key].OnWriteBlockStart(Block)
}
var arrContentResult = [];
var BlockNum = Block.BlockNum;
var arr = Block.arrContent;
if(arr)
@@ -106,26 +107,46 @@ module.exports = class CSmartContract extends require("./block-exchange")
var App = DAppByType[type];
if(App)
{
App.ResultTx = 0
DApps.Accounts.BeginTransaction()
var StrHex = GetHexFromArr(sha3(arr[i]));
var item = global.TreeFindTX.LoadValue(StrHex);
global.CurTrItem = item
if(item)
global.CurTrItem = item.TX
else
global.CurTrItem = undefined
var Result = App.OnWriteTransaction(Block, arr[i], BlockNum, i);
var SetResult = Result;
if(Result === true)
{
if(App.ResultTx)
SetResult = App.ResultTx
if(!DApps.Accounts.CommitTransaction(BlockNum, i))
SetResult = 0
}
else
{
DApps.Accounts.RollBackTransaction()
SetResult = 0
}
if(SetResult === true)
SetResult = 1
arrContentResult[i] = SetResult
if(item)
{
var ResultStr = Result;
if(Result === true)
if(Result === true || typeof Result === "number")
{
ResultStr = "Add to blockchain"
if(type === global.TYPE_TRANSACTION_FILE)
ResultStr += ": file/" + BlockNum + "/" + i
}
ToLogClient(ResultStr, item, true)
item.cmd = "RetFindTX"
item.ResultStr = "" + ResultStr
item.bFinal = 1
item.Result = SetResult
process.send(item)
}
if(Result === true)
DApps.Accounts.CommitTransaction(BlockNum, i)
else
DApps.Accounts.RollBackTransaction()
global.CurTrItem = undefined
}
}
@@ -136,6 +157,8 @@ module.exports = class CSmartContract extends require("./block-exchange")
this.DeleteBlockFromHashTree(Block2)
this.AddBlockToHashTree(Block)
}
if(arrContentResult.length)
process.send({cmd:"WriteBodyResult", BlockNum:Block.BlockNum, arrContentResult:arrContentResult})
for(var key in DApps)
{
DApps[key].OnWriteBlockFinish(Block)

View File

@@ -108,7 +108,7 @@ class CApp
{
this.AccountMap = {}
}
this.FindMyAccounts()
this.FindMyAccounts(0)
if(bGo)
this.SaveWallet()
}
@@ -230,11 +230,12 @@ class CApp
{
this.AccountMap[Data.Num] = 0
}
FindMyAccounts()
FindMyAccounts(bClean)
{
if(IsZeroArr(this.PubKeyArr))
return ;
this.AccountMap = {}
if(bClean)
this.AccountMap = {}
DApps.Accounts.FindAccounts([this.PubKeyArr], this.AccountMap, 0)
}
GetAccountKey(Num)