refactor: extracting global constants
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
1509b956a9
commit
207db65a07
@ -1,7 +1,11 @@
|
|||||||
export enum TYPE_TRANSACTION {
|
export enum TYPE_TRANSACTION {
|
||||||
|
TYPE_TRANSACTION_FILE = 5,
|
||||||
TYPE_TRANSACTION_CREATE = 100,
|
TYPE_TRANSACTION_CREATE = 100,
|
||||||
TYPE_DEPRECATED_TRANSFER1 = 105,
|
TYPE_DEPRECATED_TRANSFER1 = 105,
|
||||||
TYPE_DEPRECATED_TRANSFER2 = 110,
|
TYPE_DEPRECATED_TRANSFER2 = 110,
|
||||||
TYPE_TRANSACTION_TRANSFER = 111,
|
TYPE_TRANSACTION_TRANSFER = 111,
|
||||||
TYPE_TRANSACTION_ACC_HASH = 119
|
TYPE_TRANSACTION_ACC_HASH = 119,
|
||||||
|
TYPE_TRANSACTION_SMART_CREATE = 130,
|
||||||
|
TYPE_TRANSACTION_SMART_RUN = 135,
|
||||||
|
TYPE_TRANSACTION_SMART_CHANGE = 140
|
||||||
}
|
}
|
181
src/constant/db-format.ts
Normal file
181
src/constant/db-format.ts
Normal file
@ -0,0 +1,181 @@
|
|||||||
|
export enum DB_FORMAT {
|
||||||
|
//#region account.ts
|
||||||
|
FORMAT_CREATE = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Currency:uint,\
|
||||||
|
PubKey:arr33,\
|
||||||
|
Name:str40,\
|
||||||
|
Adviser:uint,\
|
||||||
|
Smart:uint32,\
|
||||||
|
Reserve:arr3,\
|
||||||
|
}",
|
||||||
|
FORMAT_MONEY_TRANSFER = '{\
|
||||||
|
Type:byte,\
|
||||||
|
Currency:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Sign:arr64,\
|
||||||
|
}',
|
||||||
|
FORMAT_MONEY_TRANSFER_BODY = '{\
|
||||||
|
Type:byte,\
|
||||||
|
Currency:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
}',
|
||||||
|
FORMAT_MONEY_TRANSFER2 = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Version:byte,\
|
||||||
|
Currency:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Sign:arr64,\
|
||||||
|
}",
|
||||||
|
FORMAT_MONEY_TRANSFER_BODY2 = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Version:byte,\
|
||||||
|
Currency:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
}",
|
||||||
|
FORMAT_MONEY_TRANSFER3 = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Version:byte,\
|
||||||
|
Reserve:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{PubKey:tr,ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Body:tr,\
|
||||||
|
Sign:arr64,\
|
||||||
|
}",
|
||||||
|
FORMAT_MONEY_TRANSFER_BODY3 = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Version:byte,\
|
||||||
|
Reserve:uint,\
|
||||||
|
FromID:uint,\
|
||||||
|
To:[{PubKey:tr,ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
||||||
|
Description:str,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Body:tr,\
|
||||||
|
}",
|
||||||
|
FORMAT_ACCOUNT_HASH = "{\
|
||||||
|
Type:byte,\
|
||||||
|
BlockNum:uint,\
|
||||||
|
AccHash:buffer32,\
|
||||||
|
}",
|
||||||
|
FORMAT_ACCOUNT_HASH3 = "{\
|
||||||
|
Type:byte,\
|
||||||
|
BlockNum:uint,\
|
||||||
|
AccHash:buffer32,\
|
||||||
|
AccountMax:uint,\
|
||||||
|
SmartHash:buffer32,\
|
||||||
|
SmartCount:uint,\
|
||||||
|
}",
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region file.ts
|
||||||
|
FORMAT_FILE_CREATE = "{\
|
||||||
|
type:byte,\
|
||||||
|
Name:str,\
|
||||||
|
ContentType:str,\
|
||||||
|
Reserve:arr10,\
|
||||||
|
Data:tr\
|
||||||
|
}",
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region smart.ts
|
||||||
|
FORMAT_SMART_CREATE = "{\
|
||||||
|
Type:byte,\
|
||||||
|
TokenGenerate:byte,\
|
||||||
|
StartValue:uint,\
|
||||||
|
OwnerPubKey:byte,\
|
||||||
|
ISIN:str,\
|
||||||
|
Zip:byte,\
|
||||||
|
AccountLength:byte,\
|
||||||
|
StateFormat:str,\
|
||||||
|
Category1:byte,\
|
||||||
|
Category2:byte,\
|
||||||
|
Category3:byte,\
|
||||||
|
Reserve:arr20,\
|
||||||
|
IconBlockNum:uint,\
|
||||||
|
IconTrNum:uint16,\
|
||||||
|
ShortName:str5,\
|
||||||
|
Name:str,\
|
||||||
|
Description:str,\
|
||||||
|
Code:str,\
|
||||||
|
HTML:str,\
|
||||||
|
}",
|
||||||
|
FORMAT_SMART_RUN = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Account:uint,\
|
||||||
|
MethodName:str,\
|
||||||
|
Params:str,\
|
||||||
|
FromNum:uint,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Reserve:arr10,\
|
||||||
|
Sign:arr64,\
|
||||||
|
}",
|
||||||
|
FORMAT_SMART_CHANGE = "{\
|
||||||
|
Type:byte,\
|
||||||
|
Account:uint,\
|
||||||
|
Smart:uint32,\
|
||||||
|
Reserve:arr10,\
|
||||||
|
FromNum:uint,\
|
||||||
|
OperationID:uint,\
|
||||||
|
Sign:arr64,\
|
||||||
|
}",
|
||||||
|
// global.DApps.Smart.FORMAT_ROW
|
||||||
|
FORMAT_SMART_ROW = "{\
|
||||||
|
Version:byte,\
|
||||||
|
TokenGenerate:byte,\
|
||||||
|
ISIN:str12,\
|
||||||
|
Zip:byte,\
|
||||||
|
BlockNum:uint,\
|
||||||
|
TrNum:uint16,\
|
||||||
|
IconBlockNum:uint,\
|
||||||
|
IconTrNum:uint16,\
|
||||||
|
ShortName:str5,\
|
||||||
|
Name:str40,\
|
||||||
|
Account:uint,\
|
||||||
|
AccountLength:byte,\
|
||||||
|
Category1:byte,\
|
||||||
|
Category2:byte,\
|
||||||
|
Category3:byte,\
|
||||||
|
Owner:uint,\
|
||||||
|
Reserve:arr20,\
|
||||||
|
StateFormat:str,\
|
||||||
|
Description:str,\
|
||||||
|
Code:str,\
|
||||||
|
HTML:str,\
|
||||||
|
SumHash:hash,\
|
||||||
|
}",
|
||||||
|
//#endregion
|
||||||
|
|
||||||
|
//#region block-loader-const.ts
|
||||||
|
FORMAT_BLOCK_TRANSFER = "{\
|
||||||
|
BlockNum:uint,\
|
||||||
|
TreeHash:hash,\
|
||||||
|
arrContent:[tr],\
|
||||||
|
}",
|
||||||
|
FORMAT_REST_TRANSFER = "{\
|
||||||
|
Result:uint,\
|
||||||
|
Version:uint,\
|
||||||
|
Arr:[arr200],\
|
||||||
|
ProofHash:hash,\
|
||||||
|
ProofArrL:<hash>,\
|
||||||
|
ProofArrR:<hash>,\
|
||||||
|
}",
|
||||||
|
FORMAT_SMART_TRANSFER = "{\
|
||||||
|
Result:uint,\
|
||||||
|
Arr:[tr],\
|
||||||
|
}"
|
||||||
|
//#endregion
|
||||||
|
}
|
@ -394,7 +394,7 @@ function TestCreateTr() {
|
|||||||
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,
|
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,
|
0, 0, 0, 0, 0], Description: "Description", Adviser: 10,
|
||||||
};
|
};
|
||||||
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {});
|
var Body = global.BufLib.GetBufferFromObject(TR, FORMAT_CREATE, 1000, {});
|
||||||
var startTime = process.hrtime();
|
var startTime = process.hrtime();
|
||||||
var StartData = Date.now();
|
var StartData = Date.now();
|
||||||
var nonce = CreateHashBodyPOWInnerMinPower(Body, 1000, 17);
|
var nonce = CreateHashBodyPOWInnerMinPower(Body, 1000, 17);
|
||||||
|
@ -17,11 +17,6 @@ global.PACKET_ALIVE_PERIOD = 4 * global.CONSENSUS_PERIOD_TIME;
|
|||||||
global.PACKET_ALIVE_PERIOD_NEXT_NODE = global.PACKET_ALIVE_PERIOD / 2;
|
global.PACKET_ALIVE_PERIOD_NEXT_NODE = global.PACKET_ALIVE_PERIOD / 2;
|
||||||
global.MAX_BLOCK_SEND = 8;
|
global.MAX_BLOCK_SEND = 8;
|
||||||
global.COUNT_TASK_FOR_NODE = 10;
|
global.COUNT_TASK_FOR_NODE = 10;
|
||||||
global.FORMAT_BLOCK_TRANSFER = "{\
|
|
||||||
BlockNum:uint,\
|
|
||||||
TreeHash:hash,\
|
|
||||||
arrContent:[tr],\
|
|
||||||
}";
|
|
||||||
global.WRK_BLOCK_TRANSFER = {};
|
global.WRK_BLOCK_TRANSFER = {};
|
||||||
global.MAX_ACCOUNTS_TRANSFER = 1024;
|
global.MAX_ACCOUNTS_TRANSFER = 1024;
|
||||||
global.MAX_SMARTS_TRANSFER = 10;
|
global.MAX_SMARTS_TRANSFER = 10;
|
||||||
@ -29,15 +24,3 @@ if (global.TEST_NETWORK) {
|
|||||||
global.MAX_ACCOUNTS_TRANSFER = 128;
|
global.MAX_ACCOUNTS_TRANSFER = 128;
|
||||||
global.MAX_SMARTS_TRANSFER = 10;
|
global.MAX_SMARTS_TRANSFER = 10;
|
||||||
}
|
}
|
||||||
global.FORMAT_REST_TRANSFER = "{\
|
|
||||||
Result:uint,\
|
|
||||||
Version:uint,\
|
|
||||||
Arr:[arr200],\
|
|
||||||
ProofHash:hash,\
|
|
||||||
ProofArrL:<hash>,\
|
|
||||||
ProofArrR:<hash>,\
|
|
||||||
}";
|
|
||||||
global.FORMAT_SMART_TRANSFER = "{\
|
|
||||||
Result:uint,\
|
|
||||||
Arr:[tr],\
|
|
||||||
}";
|
|
||||||
|
@ -14,6 +14,7 @@ import CRest from './rest-loader'
|
|||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
import { STreeBuffer } from './base';
|
import { STreeBuffer } from './base';
|
||||||
import { RBTree } from './library';
|
import { RBTree } from './library';
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
//import * as crypto from 'crypto';
|
//import * as crypto from 'crypto';
|
||||||
require('./block-loader-const');
|
require('./block-loader-const');
|
||||||
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
||||||
@ -1009,7 +1010,7 @@ export default class CBlock extends CRest {
|
|||||||
Info.Node.NextPing = global.MIN_PERIOD_PING
|
Info.Node.NextPing = global.MIN_PERIOD_PING
|
||||||
var Block = Info.Context.Block;
|
var Block = Info.Context.Block;
|
||||||
if (Block && !Block.TreeEq) {
|
if (Block && !Block.TreeEq) {
|
||||||
var Data = global.BufLib.GetObjectFromBuffer(Info.Data, global.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
var Data = global.BufLib.GetObjectFromBuffer(Info.Data, DB_FORMAT.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
||||||
Info.Data = undefined
|
Info.Data = undefined
|
||||||
if (Data.BlockNum !== Block.BlockNum || global.CompareArr(Data.TreeHash, Block.TreeHash) !== 0) {
|
if (Data.BlockNum !== Block.BlockNum || global.CompareArr(Data.TreeHash, Block.TreeHash) !== 0) {
|
||||||
this.SetBlockNOSendToNode(Block, Info.Node, "NO")
|
this.SetBlockNOSendToNode(Block, Info.Node, "NO")
|
||||||
@ -1325,7 +1326,7 @@ global.LoadBlockFromNetwork = function(Params, F) {
|
|||||||
global.SERVER.SendF(Node, {
|
global.SERVER.SendF(Node, {
|
||||||
"Method": "GETBLOCK", "Data": { BlockNum: BlockNum, TreeHash: [] }, "Context": {
|
"Method": "GETBLOCK", "Data": { BlockNum: BlockNum, TreeHash: [] }, "Context": {
|
||||||
F: function(Info) {
|
F: function(Info) {
|
||||||
var Block = global.BufLib.GetObjectFromBuffer(Info.Data, global.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
var Block = global.BufLib.GetObjectFromBuffer(Info.Data, DB_FORMAT.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
||||||
Info.Data = undefined;
|
Info.Data = undefined;
|
||||||
if (!Block.BlockNum || Block.BlockNum !== Params.BlockNum) {
|
if (!Block.BlockNum || Block.BlockNum !== Params.BlockNum) {
|
||||||
global.ToLog("Error get BlockNum:" + Params.BlockNum + " from " + global.NodeName(Info.Node), 2);
|
global.ToLog("Error get BlockNum:" + Params.BlockNum + " from " + global.NodeName(Info.Node), 2);
|
||||||
|
@ -1039,7 +1039,7 @@ declare global {
|
|||||||
namespace NodeJS {
|
namespace NodeJS {
|
||||||
interface Global {
|
interface Global {
|
||||||
//#region block-db.ts
|
//#region block-db.ts
|
||||||
BlockDB: any;
|
BlockDB: DBLib;
|
||||||
BLOCK_HEADER_SIZE: number;
|
BLOCK_HEADER_SIZE: number;
|
||||||
BLOCK_HEADER_SIZE2: number;
|
BLOCK_HEADER_SIZE2: number;
|
||||||
DB_VERSION: number;
|
DB_VERSION: number;
|
||||||
|
@ -18,6 +18,7 @@ import * as fs from 'fs'
|
|||||||
import * as querystring from 'querystring'
|
import * as querystring from 'querystring'
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { STreeBuffer } from './base';
|
import { STreeBuffer } from './base';
|
||||||
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
|
|
||||||
var BlockTree = new STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
var BlockTree = new STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
||||||
var ContenTypeMap = {};
|
var ContenTypeMap = {};
|
||||||
@ -222,7 +223,7 @@ function SendToResponceFile(response, Block, TrNum) {
|
|||||||
var Body = Block.arrContent[TrNum];
|
var Body = Block.arrContent[TrNum];
|
||||||
if (Body && Body.data)
|
if (Body && Body.data)
|
||||||
Body = Body.data;
|
Body = Body.data;
|
||||||
if (Body && Body[0] === global.TYPE_TRANSACTION_FILE) {
|
if (Body && Body[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_FILE) {
|
||||||
var TR = global.DApps.File.GetObjectTransaction(Body);
|
var TR = global.DApps.File.GetObjectTransaction(Body);
|
||||||
if (TR.ContentType.toLowerCase().indexOf("html") >= 0)
|
if (TR.ContentType.toLowerCase().indexOf("html") >= 0)
|
||||||
response.writeHead(200, { 'Content-Type': "text/plain" });
|
response.writeHead(200, { 'Content-Type': "text/plain" });
|
||||||
@ -269,7 +270,7 @@ function SendToResponceDappFile(response, Block, TrNum) {
|
|||||||
var Body = Block.arrContent[TrNum];
|
var Body = Block.arrContent[TrNum];
|
||||||
if (Body) {
|
if (Body) {
|
||||||
var Type = Body[0];
|
var Type = Body[0];
|
||||||
if (Type === global.TYPE_TRANSACTION_FILE) {
|
if (Type === TYPE_TRANSACTION.TYPE_TRANSACTION_FILE) {
|
||||||
var TR = global.DApps.File.GetObjectTransaction(Body);
|
var TR = global.DApps.File.GetObjectTransaction(Body);
|
||||||
Result = { result: 1, Type: Type, ContentType: TR.ContentType, Name: TR.Name, Body: TR.Data.toString('utf8') };
|
Result = { result: 1, Type: Type, ContentType: TR.ContentType, Name: TR.Name, Body: TR.Data.toString('utf8') };
|
||||||
} else {
|
} else {
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import CDB from './db/block-db'
|
import CDB from './db/block-db'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
export default class CRest extends CDB {
|
export default class CRest extends CDB {
|
||||||
LoadRestContext
|
LoadRestContext
|
||||||
BlockNumDB
|
BlockNumDB
|
||||||
@ -150,7 +151,7 @@ export default class CRest extends CDB {
|
|||||||
F: function(Info) {
|
F: function(Info) {
|
||||||
if (Context.TxProof)
|
if (Context.TxProof)
|
||||||
return;
|
return;
|
||||||
var Data = global.BufLib.GetObjectFromBuffer(Info.Data, global.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
var Data = global.BufLib.GetObjectFromBuffer(Info.Data, DB_FORMAT.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
||||||
Info.Data = undefined
|
Info.Data = undefined
|
||||||
if (Data.BlockNum !== BlockProof.BlockNum || global.CompareArr(Data.TreeHash, BlockProof.TreeHash) !== 0) {
|
if (Data.BlockNum !== BlockProof.BlockNum || global.CompareArr(Data.TreeHash, BlockProof.TreeHash) !== 0) {
|
||||||
global.ToLog("Error get proof block from " + global.NodeName(Item.Node), 2)
|
global.ToLog("Error get proof block from " + global.NodeName(Item.Node), 2)
|
||||||
@ -167,7 +168,7 @@ export default class CRest extends CDB {
|
|||||||
var Body = Data.arrContent[n];
|
var Body = Data.arrContent[n];
|
||||||
if (Body[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH) {
|
if (Body[0] === TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH) {
|
||||||
try {
|
try {
|
||||||
FindTx = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_ACCOUNT_HASH3, {})
|
FindTx = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_ACCOUNT_HASH3, {})
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
global.ToLog("Error parsing Body[" + n + "] block proof: " + e, 2)
|
global.ToLog("Error parsing Body[" + n + "] block proof: " + e, 2)
|
||||||
@ -393,19 +394,16 @@ export default class CRest extends CDB {
|
|||||||
SumPower = 0
|
SumPower = 0
|
||||||
Context.ArrProof.push({ Node: Info.Node, SumPower: SumPower, arr: arr, BufRead: BufRead })
|
Context.ArrProof.push({ Node: Info.Node, SumPower: SumPower, arr: arr, BufRead: BufRead })
|
||||||
}
|
}
|
||||||
static
|
static GETSMART_F() {
|
||||||
GETSMART_F() {
|
|
||||||
return "{\
|
return "{\
|
||||||
SmartNum:uint,\
|
SmartNum:uint,\
|
||||||
Count:uint,\
|
Count:uint,\
|
||||||
}";
|
}";
|
||||||
}
|
}
|
||||||
static
|
static RETSMART_F() {
|
||||||
RETSMART_F() {
|
return DB_FORMAT.FORMAT_SMART_TRANSFER;
|
||||||
return global.FORMAT_SMART_TRANSFER;
|
|
||||||
}
|
}
|
||||||
static
|
static GETREST_F() {
|
||||||
GETREST_F() {
|
|
||||||
return "{\
|
return "{\
|
||||||
BlockNum:uint,\
|
BlockNum:uint,\
|
||||||
AccNum:uint,\
|
AccNum:uint,\
|
||||||
@ -413,9 +411,8 @@ export default class CRest extends CDB {
|
|||||||
AccHash:hash,\
|
AccHash:hash,\
|
||||||
}";
|
}";
|
||||||
}
|
}
|
||||||
static
|
static RETREST_F() {
|
||||||
RETREST_F() {
|
return DB_FORMAT.FORMAT_REST_TRANSFER;
|
||||||
return global.FORMAT_REST_TRANSFER;
|
|
||||||
}
|
}
|
||||||
SendLoadToBegin() {
|
SendLoadToBegin() {
|
||||||
return;
|
return;
|
||||||
@ -462,7 +459,7 @@ function CheckHashSmarts(LastSumHash) {
|
|||||||
return Num;
|
return Num;
|
||||||
var WasSumHash = Item.SumHash;
|
var WasSumHash = Item.SumHash;
|
||||||
Item.SumHash = [];
|
Item.SumHash = [];
|
||||||
var Buf = global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, WorkStruct);
|
var Buf = global.BufLib.GetBufferFromObject(Item, DB_FORMAT.FORMAT_SMART_ROW, 20000, WorkStruct);
|
||||||
var Hash = global.sha3(Buf);
|
var Hash = global.sha3(Buf);
|
||||||
var SumHash = global.sha3arr2(PrevItem.SumHash, Hash);
|
var SumHash = global.sha3arr2(PrevItem.SumHash, Hash);
|
||||||
if (global.CompareArr(SumHash, WasSumHash) !== 0)
|
if (global.CompareArr(SumHash, WasSumHash) !== 0)
|
||||||
|
@ -131,7 +131,7 @@ export default class CSmartContract extends CConsensus {
|
|||||||
var ResultStr = Result;
|
var ResultStr = Result;
|
||||||
if (Result === true || typeof Result === "number") {
|
if (Result === true || typeof Result === "number") {
|
||||||
ResultStr = "Add to blockchain"
|
ResultStr = "Add to blockchain"
|
||||||
if (type === global.TYPE_TRANSACTION_FILE)
|
if (type === TYPE_TRANSACTION.TYPE_TRANSACTION_FILE)
|
||||||
ResultStr += ": file/" + BlockNum + "/" + i
|
ResultStr += ": file/" + BlockNum + "/" + i
|
||||||
}
|
}
|
||||||
item.cmd = "RetFindTX"
|
item.cmd = "RetFindTX"
|
||||||
|
@ -147,6 +147,7 @@ function RecreateAccountHashDB3() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
import '../core/db/db-row'
|
import '../core/db/db-row'
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
function ReWriteDBSmartWrite() {
|
function ReWriteDBSmartWrite() {
|
||||||
global.UpdateMode = 1;
|
global.UpdateMode = 1;
|
||||||
global.ToLog("Start ReWriteDBSmartWrite");
|
global.ToLog("Start ReWriteDBSmartWrite");
|
||||||
@ -154,7 +155,7 @@ function ReWriteDBSmartWrite() {
|
|||||||
var Item = global.DApps.Smart.DBSmart.Read(num);
|
var Item = global.DApps.Smart.DBSmart.Read(num);
|
||||||
if (!Item)
|
if (!Item)
|
||||||
break;
|
break;
|
||||||
var Body = global.GetArrFromHex(GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {}));
|
var Body = global.GetArrFromHex(GetBufferFromObject(Item, DB_FORMAT.FORMAT_SMART_ROW, 20000, {}));
|
||||||
if (Body.length > 15000)
|
if (Body.length > 15000)
|
||||||
global.ToLog("Smart " + Item.Num + ". " + Item.Name + " length=" + Body.length);
|
global.ToLog("Smart " + Item.Num + ". " + Item.Name + " length=" + Body.length);
|
||||||
global.DApps.Smart.DBSmartWrite(Item);
|
global.DApps.Smart.DBSmartWrite(Item);
|
||||||
|
38
src/global.d.ts
vendored
38
src/global.d.ts
vendored
@ -413,17 +413,15 @@ declare global {
|
|||||||
|
|
||||||
//#region accounts.ts
|
//#region accounts.ts
|
||||||
HistoryDB: any;
|
HistoryDB: any;
|
||||||
TYPE_TRANSACTION_CREATE: number;
|
// FORMAT_CREATE: string;
|
||||||
TYPE_TRANSACTION_ACC_HASH: number;
|
// FORMAT_MONEY_TRANSFER: string;
|
||||||
FORMAT_CREATE: string;
|
// FORMAT_MONEY_TRANSFER_BODY: string;
|
||||||
FORMAT_MONEY_TRANSFER: string;
|
// FORMAT_MONEY_TRANSFER2: string;
|
||||||
FORMAT_MONEY_TRANSFER_BODY: string;
|
// FORMAT_MONEY_TRANSFER_BODY2: string;
|
||||||
FORMAT_MONEY_TRANSFER2: string;
|
// FORMAT_MONEY_TRANSFER3: string;
|
||||||
FORMAT_MONEY_TRANSFER_BODY2: string;
|
// FORMAT_MONEY_TRANSFER_BODY3: string;
|
||||||
FORMAT_MONEY_TRANSFER3: string;
|
// FORMAT_ACCOUNT_HASH: string;
|
||||||
FORMAT_MONEY_TRANSFER_BODY3: string;
|
// FORMAT_ACCOUNT_HASH3: string;
|
||||||
FORMAT_ACCOUNT_HASH: string;
|
|
||||||
FORMAT_ACCOUNT_HASH3: string;
|
|
||||||
|
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
@ -447,8 +445,8 @@ declare global {
|
|||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region file.ts
|
//#region file.ts
|
||||||
TYPE_TRANSACTION_FILE: number;
|
// TYPE_TRANSACTION_FILE: number;
|
||||||
FORMAT_FILE_CREATE: string;
|
// FORMAT_FILE_CREATE: string;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
// //#region dapp.ts
|
// //#region dapp.ts
|
||||||
@ -468,10 +466,10 @@ declare global {
|
|||||||
|
|
||||||
//#region smart.ts
|
//#region smart.ts
|
||||||
TickCounter: number;
|
TickCounter: number;
|
||||||
TYPE_TRANSACTION_SMART_RUN: number;
|
// TYPE_TRANSACTION_SMART_RUN: number;
|
||||||
FORMAT_SMART_CREATE: string;
|
// FORMAT_SMART_CREATE: string;
|
||||||
FORMAT_SMART_RUN
|
// FORMAT_SMART_RUN
|
||||||
FORMAT_SMART_CHANGE
|
// FORMAT_SMART_CHANGE
|
||||||
RunSmartMethod: Function;
|
RunSmartMethod: Function;
|
||||||
DebugEvent: Function;
|
DebugEvent: Function;
|
||||||
//#endregion
|
//#endregion
|
||||||
@ -594,12 +592,12 @@ declare global {
|
|||||||
PACKET_ALIVE_PERIOD_NEXT_NODE: number;
|
PACKET_ALIVE_PERIOD_NEXT_NODE: number;
|
||||||
MAX_BLOCK_SEND: number;
|
MAX_BLOCK_SEND: number;
|
||||||
COUNT_TASK_FOR_NODE: number;
|
COUNT_TASK_FOR_NODE: number;
|
||||||
FORMAT_BLOCK_TRANSFER: string;
|
// FORMAT_BLOCK_TRANSFER: string;
|
||||||
WRK_BLOCK_TRANSFER: any;
|
WRK_BLOCK_TRANSFER: any;
|
||||||
MAX_ACCOUNTS_TRANSFER: number;
|
MAX_ACCOUNTS_TRANSFER: number;
|
||||||
MAX_SMARTS_TRANSFER: number;
|
MAX_SMARTS_TRANSFER: number;
|
||||||
FORMAT_REST_TRANSFER: string;
|
// FORMAT_REST_TRANSFER: string;
|
||||||
FORMAT_SMART_TRANSFER: string;
|
// FORMAT_SMART_TRANSFER: string;
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region server.ts
|
//#region server.ts
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
let WebApi2: any = {};
|
let WebApi2: any = {};
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
WebApi2.GenerateKeys = function(Params) {
|
WebApi2.GenerateKeys = function(Params) {
|
||||||
var KeyPair = crypto.createECDH('secp256k1');
|
var KeyPair = crypto.createECDH('secp256k1');
|
||||||
var PrivKey = global.sha3(crypto.randomBytes(32));
|
var PrivKey = global.sha3(crypto.randomBytes(32));
|
||||||
@ -23,7 +24,7 @@ WebApi2.CreateAccount = function(Params, response) {
|
|||||||
KeyPair.setPrivateKey(Buffer.from(global.GetArrFromHex(Params.PrivKey)));
|
KeyPair.setPrivateKey(Buffer.from(global.GetArrFromHex(Params.PrivKey)));
|
||||||
var PubKey = KeyPair.getPublicKey('' as any, 'compressed');
|
var PubKey = KeyPair.getPublicKey('' as any, 'compressed');
|
||||||
var TR: any = { Type: TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: PubKey, Name: Params.Name, Smart: Params.Smart, };
|
var TR: any = { Type: TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE, Currency: Params.Currency, PubKey: PubKey, Name: Params.Name, Smart: Params.Smart, };
|
||||||
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_CREATE, 1000, {}, 1);
|
var Body = global.BufLib.GetBufferFromObject(TR, DB_FORMAT.FORMAT_CREATE, 1000, {}, 1);
|
||||||
Body = Body.slice(0, Body.len + 12);
|
Body = Body.slice(0, Body.len + 12);
|
||||||
SendTransaction(Body, TR as any, Params.Wait, function(result, text) {
|
SendTransaction(Body, TR as any, Params.Wait, function(result, text) {
|
||||||
var Result = {
|
var Result = {
|
||||||
@ -87,7 +88,7 @@ WebApi2.Send = function(Params, response, A, bJsonRet) {
|
|||||||
if (!Params.FromPrivKey)
|
if (!Params.FromPrivKey)
|
||||||
return { result: 0, Meta: Params.Meta, text: "Params.FromPrivKey required" };
|
return { result: 0, Meta: Params.Meta, text: "Params.FromPrivKey required" };
|
||||||
TR.Sign = global.DApps.Accounts.GetSignTransferTx(TR, global.GetArrFromHex(Params.FromPrivKey));
|
TR.Sign = global.DApps.Accounts.GetSignTransferTx(TR, global.GetArrFromHex(Params.FromPrivKey));
|
||||||
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_MONEY_TRANSFER3, global.MAX_TRANSACTION_SIZE, {}, 1);
|
var Body = global.BufLib.GetBufferFromObject(TR, DB_FORMAT.FORMAT_MONEY_TRANSFER3, global.MAX_TRANSACTION_SIZE, {}, 1);
|
||||||
Body = Body.slice(0, Body.len + 12);
|
Body = Body.slice(0, Body.len + 12);
|
||||||
SendTransaction(Body, TR, Params.Wait, function(result, text) {
|
SendTransaction(Body, TR, Params.Wait, function(result, text) {
|
||||||
var Result = {
|
var Result = {
|
||||||
@ -209,7 +210,7 @@ WebApi2.SendRawTransaction = function(Params, response) {
|
|||||||
return { result: 0, Meta: Params.Meta, text: "Params.Tx.Sign required" };
|
return { result: 0, Meta: Params.Meta, text: "Params.Tx.Sign required" };
|
||||||
var TR = Params.Tx;
|
var TR = Params.Tx;
|
||||||
TxHexToArr(TR);
|
TxHexToArr(TR);
|
||||||
var Body = global.BufLib.GetBufferFromObject(TR, global.FORMAT_MONEY_TRANSFER3, global.MAX_TRANSACTION_SIZE, {}, 1);
|
var Body = global.BufLib.GetBufferFromObject(TR, DB_FORMAT.FORMAT_MONEY_TRANSFER3, global.MAX_TRANSACTION_SIZE, {}, 1);
|
||||||
Body = Body.slice(0, Body.len + 12);
|
Body = Body.slice(0, Body.len + 12);
|
||||||
SendTransaction(Body, TR, Params.Wait, function(result, text) {
|
SendTransaction(Body, TR, Params.Wait, function(result, text) {
|
||||||
var Result = {
|
var Result = {
|
||||||
|
@ -91,6 +91,7 @@ process.on('error' as any, function(err: TeraError) {
|
|||||||
global.ToLog(err.stack);
|
global.ToLog(err.stack);
|
||||||
});
|
});
|
||||||
import CServerDB from '../core/db/block-db'
|
import CServerDB from '../core/db/block-db'
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
var KeyPair = crypto.createECDH('secp256k1');
|
var KeyPair = crypto.createECDH('secp256k1');
|
||||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
||||||
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
||||||
@ -182,7 +183,7 @@ function GETBLOCK(msg) {
|
|||||||
var BlockDB = global.SERVER.ReadBlockDB(BlockNum);
|
var BlockDB = global.SERVER.ReadBlockDB(BlockNum);
|
||||||
var StrSend;
|
var StrSend;
|
||||||
if (BlockDB && (global.CompareArr(BlockDB.TreeHash, TreeHash) === 0 || global.IsZeroArr(TreeHash))) {
|
if (BlockDB && (global.CompareArr(BlockDB.TreeHash, TreeHash) === 0 || global.IsZeroArr(TreeHash))) {
|
||||||
var BufWrite = global.BufLib.GetBufferFromObject(BlockDB, global.FORMAT_BLOCK_TRANSFER, global.MAX_PACKET_LENGTH, global.WRK_BLOCK_TRANSFER);
|
var BufWrite = global.BufLib.GetBufferFromObject(BlockDB, DB_FORMAT.FORMAT_BLOCK_TRANSFER, global.MAX_PACKET_LENGTH, global.WRK_BLOCK_TRANSFER);
|
||||||
StrSend = "OK";
|
StrSend = "OK";
|
||||||
}
|
}
|
||||||
if (StrSend === "OK") {
|
if (StrSend === "OK") {
|
||||||
@ -260,7 +261,7 @@ function GETREST(msg) {
|
|||||||
ProofArrL: ProofArrL,
|
ProofArrL: ProofArrL,
|
||||||
ProofArrR: ProofArrR
|
ProofArrR: ProofArrR
|
||||||
};
|
};
|
||||||
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_REST_TRANSFER, BufLength, {});
|
var BufWrite = global.BufLib.GetBufferFromObject(Data2, DB_FORMAT.FORMAT_REST_TRANSFER, BufLength, {});
|
||||||
process.send({
|
process.send({
|
||||||
cmd: "Send",
|
cmd: "Send",
|
||||||
addrStr: msg.addrStr,
|
addrStr: msg.addrStr,
|
||||||
@ -288,7 +289,7 @@ function GETSMART(msg) {
|
|||||||
Arr.push(BufSmart);
|
Arr.push(BufSmart);
|
||||||
}
|
}
|
||||||
var Data2 = { Result: Arr.length ? 1 : 0, Arr: Arr };
|
var Data2 = { Result: Arr.length ? 1 : 0, Arr: Arr };
|
||||||
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_SMART_TRANSFER, BufLength, {});
|
var BufWrite = global.BufLib.GetBufferFromObject(Data2, DB_FORMAT.FORMAT_SMART_TRANSFER, BufLength, {});
|
||||||
process.send({
|
process.send({
|
||||||
cmd: "Send",
|
cmd: "Send",
|
||||||
addrStr: msg.addrStr,
|
addrStr: msg.addrStr,
|
||||||
|
@ -101,6 +101,7 @@ process.on('error' as any, function(err: TeraError) {
|
|||||||
global.HTTP_PORT_NUMBER = 0;
|
global.HTTP_PORT_NUMBER = 0;
|
||||||
import CServerDB from '../core/transaction-validator'
|
import CServerDB from '../core/transaction-validator'
|
||||||
import { STreeBuffer } from '../core/base';
|
import { STreeBuffer } from '../core/base';
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
var KeyPair = crypto.createECDH('secp256k1');
|
var KeyPair = crypto.createECDH('secp256k1');
|
||||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
||||||
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
||||||
@ -328,7 +329,7 @@ global.TXWriteAccArr = TXWriteAccArr;
|
|||||||
|
|
||||||
function TXWriteSmartArr(Params) {
|
function TXWriteSmartArr(Params) {
|
||||||
var WorkStruct = {};
|
var WorkStruct = {};
|
||||||
var WorkFormat = global.DApps.Smart.FORMAT_ROW;
|
var WorkFormat = DB_FORMAT.FORMAT_SMART_ROW;
|
||||||
global.ToLog("Write smarts: " + Params.StartNum + "-" + Params.Arr.length, 2);
|
global.ToLog("Write smarts: " + Params.StartNum + "-" + Params.Arr.length, 2);
|
||||||
for (var i = 0; i < Params.Arr.length; i++) {
|
for (var i = 0; i < Params.Arr.length; i++) {
|
||||||
var Data = global.BufLib.GetObjectFromBuffer(Params.Arr[i], WorkFormat, WorkStruct);
|
var Data = global.BufLib.GetObjectFromBuffer(Params.Arr[i], WorkFormat, WorkStruct);
|
||||||
@ -345,7 +346,7 @@ function TXWriteAccHash() {
|
|||||||
var Item = global.DApps.Smart.DBSmart.Read(num);
|
var Item = global.DApps.Smart.DBSmart.Read(num);
|
||||||
if (!Item)
|
if (!Item)
|
||||||
break;
|
break;
|
||||||
var Body = global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {});
|
var Body = global.BufLib.GetBufferFromObject(Item, DB_FORMAT.FORMAT_SMART_ROW, 20000, {});
|
||||||
global.DApps.Smart.DBSmartWrite(Item);
|
global.DApps.Smart.DBSmartWrite(Item);
|
||||||
}
|
}
|
||||||
global.DApps.Accounts.CalcMerkleTree(1);
|
global.DApps.Accounts.CalcMerkleTree(1);
|
||||||
|
@ -14,6 +14,7 @@ import DBRow from '../core/db/db-row'
|
|||||||
import '../core/rest_tables'
|
import '../core/rest_tables'
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1 } from '../core/library'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account'
|
import { TYPE_TRANSACTION } from '../constant/account'
|
||||||
|
import { DB_FORMAT } from '../constant/db-format'
|
||||||
const MAX_SUM_TER = 1e9;
|
const MAX_SUM_TER = 1e9;
|
||||||
const MAX_SUM_CENT = 1e9;
|
const MAX_SUM_CENT = 1e9;
|
||||||
import DBLib from "../core/db/db"
|
import DBLib from "../core/db/db"
|
||||||
@ -21,69 +22,9 @@ global.HistoryDB = new DBLib();
|
|||||||
const FILE_NAME_HISTORY = "history-body";
|
const FILE_NAME_HISTORY = "history-body";
|
||||||
var WorkStructHistory = {};
|
var WorkStructHistory = {};
|
||||||
const BLOCK_CREATE_INTERVAL = 10;
|
const BLOCK_CREATE_INTERVAL = 10;
|
||||||
global.TYPE_TRANSACTION_CREATE = 100;
|
|
||||||
const TYPE_DEPRECATED_TRANSFER1 = 105;
|
|
||||||
const TYPE_DEPRECATED_TRANSFER2 = 110;
|
|
||||||
const TYPE_TRANSACTION_TRANSFER = 111;
|
|
||||||
global.TYPE_TRANSACTION_ACC_HASH = 119;
|
|
||||||
global.FORMAT_CREATE = "{\
|
|
||||||
Type:byte,\
|
|
||||||
Currency:uint,\
|
|
||||||
PubKey:arr33,\
|
|
||||||
Name:str40,\
|
|
||||||
Adviser:uint,\
|
|
||||||
Smart:uint32,\
|
|
||||||
Reserve:arr3,\
|
|
||||||
}";
|
|
||||||
global.FORMAT_MONEY_TRANSFER = '{\
|
|
||||||
Type:byte,\
|
|
||||||
Currency:uint,\
|
|
||||||
FromID:uint,\
|
|
||||||
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
|
||||||
Description:str,\
|
|
||||||
OperationID:uint,\
|
|
||||||
Sign:arr64,\
|
|
||||||
}';
|
|
||||||
const WorkStructTransfer = {};
|
const WorkStructTransfer = {};
|
||||||
global.FORMAT_MONEY_TRANSFER_BODY = global.FORMAT_MONEY_TRANSFER.replace("Sign:arr64,", "");
|
|
||||||
global.FORMAT_MONEY_TRANSFER2 = "{\
|
|
||||||
Type:byte,\
|
|
||||||
Version:byte,\
|
|
||||||
Currency:uint,\
|
|
||||||
FromID:uint,\
|
|
||||||
To:[{ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
|
||||||
Description:str,\
|
|
||||||
OperationID:uint,\
|
|
||||||
Sign:arr64,\
|
|
||||||
}";
|
|
||||||
const WorkStructTransfer2 = {};
|
const WorkStructTransfer2 = {};
|
||||||
global.FORMAT_MONEY_TRANSFER_BODY2 = global.FORMAT_MONEY_TRANSFER2.replace("Sign:arr64,", "");
|
|
||||||
global.FORMAT_MONEY_TRANSFER3 = "{\
|
|
||||||
Type:byte,\
|
|
||||||
Version:byte,\
|
|
||||||
Reserve:uint,\
|
|
||||||
FromID:uint,\
|
|
||||||
To:[{PubKey:tr,ID:uint,SumCOIN:uint,SumCENT:uint32}],\
|
|
||||||
Description:str,\
|
|
||||||
OperationID:uint,\
|
|
||||||
Body:tr,\
|
|
||||||
Sign:arr64,\
|
|
||||||
}";
|
|
||||||
const WorkStructTransfer3 = {};
|
const WorkStructTransfer3 = {};
|
||||||
global.FORMAT_MONEY_TRANSFER_BODY3 = global.FORMAT_MONEY_TRANSFER3.replace("Sign:arr64,", "");
|
|
||||||
global.FORMAT_ACCOUNT_HASH = "{\
|
|
||||||
Type:byte,\
|
|
||||||
BlockNum:uint,\
|
|
||||||
AccHash:buffer32,\
|
|
||||||
}";
|
|
||||||
global.FORMAT_ACCOUNT_HASH3 = "{\
|
|
||||||
Type:byte,\
|
|
||||||
BlockNum:uint,\
|
|
||||||
AccHash:buffer32,\
|
|
||||||
AccountMax:uint,\
|
|
||||||
SmartHash:buffer32,\
|
|
||||||
SmartCount:uint,\
|
|
||||||
}";
|
|
||||||
import DApp from './dapp'
|
import DApp from './dapp'
|
||||||
class MerkleDBRow extends DBRow {
|
class MerkleDBRow extends DBRow {
|
||||||
private MerkleTree
|
private MerkleTree
|
||||||
@ -321,7 +262,7 @@ export default class AccountApp extends DApp {
|
|||||||
var Num = BlockNum;
|
var Num = BlockNum;
|
||||||
return Num;
|
return Num;
|
||||||
}
|
}
|
||||||
case TYPE_TRANSACTION_TRANSFER:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_TRANSFER:
|
||||||
var Num = global.ReadUintFromArr(Body, 1 + 1 + 6);
|
var Num = global.ReadUintFromArr(Body, 1 + 1 + 6);
|
||||||
return Num;
|
return Num;
|
||||||
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
||||||
@ -376,19 +317,19 @@ export default class AccountApp extends DApp {
|
|||||||
Result = this.TRCreateAccount(Body, BlockNum, TrNum, ContextFrom)
|
Result = this.TRCreateAccount(Body, BlockNum, TrNum, ContextFrom)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_DEPRECATED_TRANSFER1:
|
case TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER1:
|
||||||
{
|
{
|
||||||
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, global.FORMAT_MONEY_TRANSFER, WorkStructTransfer)
|
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, DB_FORMAT.FORMAT_MONEY_TRANSFER, WorkStructTransfer)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_DEPRECATED_TRANSFER2:
|
case TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER2:
|
||||||
{
|
{
|
||||||
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, global.FORMAT_MONEY_TRANSFER2, WorkStructTransfer2)
|
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, DB_FORMAT.FORMAT_MONEY_TRANSFER2, WorkStructTransfer2)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_TRANSACTION_TRANSFER:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_TRANSFER:
|
||||||
{
|
{
|
||||||
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, global.FORMAT_MONEY_TRANSFER3, WorkStructTransfer3)
|
Result = this.TRTransferMoney(Block, Body, BlockNum, TrNum, DB_FORMAT.FORMAT_MONEY_TRANSFER3, WorkStructTransfer3)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
||||||
@ -479,27 +420,27 @@ export default class AccountApp extends DApp {
|
|||||||
switch (Type) {
|
switch (Type) {
|
||||||
case TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE:
|
||||||
{
|
{
|
||||||
format = global.FORMAT_CREATE
|
format = DB_FORMAT.FORMAT_CREATE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_DEPRECATED_TRANSFER1:
|
case TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER1:
|
||||||
{
|
{
|
||||||
format = global.FORMAT_MONEY_TRANSFER
|
format = DB_FORMAT.FORMAT_MONEY_TRANSFER
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_DEPRECATED_TRANSFER2:
|
case TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER2:
|
||||||
{
|
{
|
||||||
format = global.FORMAT_MONEY_TRANSFER2
|
format = DB_FORMAT.FORMAT_MONEY_TRANSFER2
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_TRANSACTION_TRANSFER:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_TRANSFER:
|
||||||
{
|
{
|
||||||
format = global.FORMAT_MONEY_TRANSFER3
|
format = DB_FORMAT.FORMAT_MONEY_TRANSFER3
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH:
|
||||||
{
|
{
|
||||||
format = global.FORMAT_ACCOUNT_HASH3
|
format = DB_FORMAT.FORMAT_ACCOUNT_HASH3
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@ -530,7 +471,7 @@ export default class AccountApp extends DApp {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_ACCOUNT_HASH3, {});
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_ACCOUNT_HASH3, {});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -595,7 +536,7 @@ export default class AccountApp extends DApp {
|
|||||||
return "Error min power POW for create account (update client)";
|
return "Error min power POW for create account (update client)";
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_CREATE, {});
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_CREATE, {});
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
return "Error transaction format";
|
return "Error transaction format";
|
||||||
@ -1286,9 +1227,9 @@ export default class AccountApp extends DApp {
|
|||||||
if (TR.Version === 2 || TR.Version === 3) {
|
if (TR.Version === 2 || TR.Version === 3) {
|
||||||
var format;
|
var format;
|
||||||
if (TR.Version === 2)
|
if (TR.Version === 2)
|
||||||
format = global.FORMAT_MONEY_TRANSFER_BODY2
|
format = DB_FORMAT.FORMAT_MONEY_TRANSFER_BODY2
|
||||||
else
|
else
|
||||||
format = global.FORMAT_MONEY_TRANSFER_BODY3
|
format = DB_FORMAT.FORMAT_MONEY_TRANSFER_BODY3
|
||||||
Arr = []
|
Arr = []
|
||||||
for (var i = 0; i < TR.To.length; i++) {
|
for (var i = 0; i < TR.To.length; i++) {
|
||||||
var Item = TR.To[i];
|
var Item = TR.To[i];
|
||||||
@ -1304,7 +1245,7 @@ export default class AccountApp extends DApp {
|
|||||||
Arr[Arr.length] = Body[j]
|
Arr[Arr.length] = Body[j]
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Arr = global.BufLib.GetBufferFromObject(TR, global.FORMAT_MONEY_TRANSFER_BODY, global.MAX_TRANSACTION_SIZE, {})
|
Arr = global.BufLib.GetBufferFromObject(TR, DB_FORMAT.FORMAT_MONEY_TRANSFER_BODY, global.MAX_TRANSACTION_SIZE, {})
|
||||||
}
|
}
|
||||||
var sigObj = secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey));
|
var sigObj = secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey));
|
||||||
return sigObj.signature;
|
return sigObj.signature;
|
||||||
@ -1384,28 +1325,7 @@ export default class AccountApp extends DApp {
|
|||||||
var App = new AccountApp;
|
var App = new AccountApp;
|
||||||
global.DApps["Accounts"] = App;
|
global.DApps["Accounts"] = App;
|
||||||
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_CREATE] = App;
|
||||||
global.DAppByType[TYPE_DEPRECATED_TRANSFER1] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER1] = App;
|
||||||
global.DAppByType[TYPE_DEPRECATED_TRANSFER2] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_DEPRECATED_TRANSFER2] = App;
|
||||||
global.DAppByType[TYPE_TRANSACTION_TRANSFER] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_TRANSFER] = App;
|
||||||
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_ACC_HASH] = App;
|
global.DAppByType[TYPE_TRANSACTION.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);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
@ -9,11 +9,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
global.TYPE_TRANSACTION_FILE = 5;
|
|
||||||
global.FORMAT_FILE_CREATE = "{type:byte,Name:str,ContentType:str,Reserve:arr10,Data:tr}";
|
|
||||||
//@ts-ignore
|
|
||||||
let WorkStructRun = {};
|
let WorkStructRun = {};
|
||||||
import DApp from './dapp'
|
import DApp from './dapp'
|
||||||
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
export default class FileApp extends DApp {
|
export default class FileApp extends DApp {
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
@ -22,7 +21,7 @@ export default class FileApp extends DApp {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
GetObjectTransaction(Body) {
|
GetObjectTransaction(Body) {
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_FILE_CREATE, WorkStructRun);
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_FILE_CREATE, WorkStructRun);
|
||||||
return TR;
|
return TR;
|
||||||
}
|
}
|
||||||
GetScriptTransaction(Body) {
|
GetScriptTransaction(Body) {
|
||||||
@ -36,4 +35,4 @@ export default class FileApp extends DApp {
|
|||||||
};
|
};
|
||||||
var App = new FileApp;
|
var App = new FileApp;
|
||||||
global.DApps.File = App;
|
global.DApps.File = App;
|
||||||
global.DAppByType[global.TYPE_TRANSACTION_FILE] = App;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_FILE] = App;
|
||||||
|
@ -15,87 +15,21 @@ global.TickCounter = 0;
|
|||||||
import DBRow from '../core/db/db-row'
|
import DBRow from '../core/db/db-row'
|
||||||
import DApp from './dapp'
|
import DApp from './dapp'
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1 } from '../core/library'
|
||||||
const TYPE_TRANSACTION_SMART_CREATE = 130;
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
global.TYPE_TRANSACTION_SMART_RUN = 135;
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
const TYPE_TRANSACTION_SMART_CHANGE = 140;
|
|
||||||
global.FORMAT_SMART_CREATE = "{\
|
|
||||||
Type:byte,\
|
|
||||||
TokenGenerate:byte,\
|
|
||||||
StartValue:uint,\
|
|
||||||
OwnerPubKey:byte,\
|
|
||||||
ISIN:str,\
|
|
||||||
Zip:byte,\
|
|
||||||
AccountLength:byte,\
|
|
||||||
StateFormat:str,\
|
|
||||||
Category1:byte,\
|
|
||||||
Category2:byte,\
|
|
||||||
Category3:byte,\
|
|
||||||
Reserve:arr20,\
|
|
||||||
IconBlockNum:uint,\
|
|
||||||
IconTrNum:uint16,\
|
|
||||||
ShortName:str5,\
|
|
||||||
Name:str,\
|
|
||||||
Description:str,\
|
|
||||||
Code:str,\
|
|
||||||
HTML:str,\
|
|
||||||
}";
|
|
||||||
const WorkStructCreate = {};
|
const WorkStructCreate = {};
|
||||||
global.FORMAT_SMART_RUN = "{\
|
|
||||||
Type:byte,\
|
|
||||||
Account:uint,\
|
|
||||||
MethodName:str,\
|
|
||||||
Params:str,\
|
|
||||||
FromNum:uint,\
|
|
||||||
OperationID:uint,\
|
|
||||||
Reserve:arr10,\
|
|
||||||
Sign:arr64,\
|
|
||||||
}";
|
|
||||||
//@ts-ignore
|
|
||||||
const WorkStructRun = {};
|
const WorkStructRun = {};
|
||||||
global.FORMAT_SMART_CHANGE = "{\
|
|
||||||
Type:byte,\
|
|
||||||
Account:uint,\
|
|
||||||
Smart:uint32,\
|
|
||||||
Reserve:arr10,\
|
|
||||||
FromNum:uint,\
|
|
||||||
OperationID:uint,\
|
|
||||||
Sign:arr64,\
|
|
||||||
}";
|
|
||||||
const WorkStructChange = {};
|
const WorkStructChange = {};
|
||||||
export default class SmartApp extends DApp {
|
export default class SmartApp extends DApp {
|
||||||
FORMAT_ROW
|
|
||||||
ROW_SIZE
|
ROW_SIZE
|
||||||
DBSmart
|
DBSmart
|
||||||
RowHole
|
RowHole
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
var bReadOnly = (global.PROCESS_NAME !== "TX");
|
var bReadOnly = (global.PROCESS_NAME !== "TX");
|
||||||
this.FORMAT_ROW = "{\
|
|
||||||
Version:byte,\
|
|
||||||
TokenGenerate:byte,\
|
|
||||||
ISIN:str12,\
|
|
||||||
Zip:byte,\
|
|
||||||
BlockNum:uint,\
|
|
||||||
TrNum:uint16,\
|
|
||||||
IconBlockNum:uint,\
|
|
||||||
IconTrNum:uint16,\
|
|
||||||
ShortName:str5,\
|
|
||||||
Name:str40,\
|
|
||||||
Account:uint,\
|
|
||||||
AccountLength:byte,\
|
|
||||||
Category1:byte,\
|
|
||||||
Category2:byte,\
|
|
||||||
Category3:byte,\
|
|
||||||
Owner:uint,\
|
|
||||||
Reserve:arr20,\
|
|
||||||
StateFormat:str,\
|
|
||||||
Description:str,\
|
|
||||||
Code:str,\
|
|
||||||
HTML:str,\
|
|
||||||
SumHash:hash,\
|
|
||||||
}"
|
|
||||||
this.ROW_SIZE = 2 * (1 << 13)
|
this.ROW_SIZE = 2 * (1 << 13)
|
||||||
this.DBSmart = new DBRow("smart", this.ROW_SIZE, this.FORMAT_ROW, bReadOnly)
|
this.DBSmart = new DBRow("smart", this.ROW_SIZE, DB_FORMAT.FORMAT_SMART_ROW, bReadOnly)
|
||||||
this.InitHole()
|
this.InitHole()
|
||||||
if (!bReadOnly)
|
if (!bReadOnly)
|
||||||
this.Start()
|
this.Start()
|
||||||
@ -118,7 +52,7 @@ export default class SmartApp extends DApp {
|
|||||||
var Type = Body[0];
|
var Type = Body[0];
|
||||||
if (Type && Body.length > 90) {
|
if (Type && Body.length > 90) {
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case global.TYPE_TRANSACTION_SMART_RUN:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_RUN:
|
||||||
var len = 1 + 6;
|
var len = 1 + 6;
|
||||||
len += 2 + Body[len] + Body[len + 1] * 256
|
len += 2 + Body[len] + Body[len + 1] * 256
|
||||||
if (len + 64 > Body.length)
|
if (len + 64 > Body.length)
|
||||||
@ -128,7 +62,7 @@ export default class SmartApp extends DApp {
|
|||||||
return 0;
|
return 0;
|
||||||
var Num = global.ReadUintFromArr(Body, len);
|
var Num = global.ReadUintFromArr(Body, len);
|
||||||
return Num;
|
return Num;
|
||||||
case TYPE_TRANSACTION_SMART_CHANGE:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CHANGE:
|
||||||
var Num = global.ReadUintFromArr(Body, 1);
|
var Num = global.ReadUintFromArr(Body, 1);
|
||||||
return Num;
|
return Num;
|
||||||
}
|
}
|
||||||
@ -155,13 +89,13 @@ export default class SmartApp extends DApp {
|
|||||||
var Result;
|
var Result;
|
||||||
try {
|
try {
|
||||||
switch (Type) {
|
switch (Type) {
|
||||||
case TYPE_TRANSACTION_SMART_CREATE:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CREATE:
|
||||||
Result = this.TRCreateSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
Result = this.TRCreateSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
||||||
break;
|
break;
|
||||||
case global.TYPE_TRANSACTION_SMART_RUN:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_RUN:
|
||||||
Result = this.TRRunSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
Result = this.TRRunSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
||||||
break;
|
break;
|
||||||
case TYPE_TRANSACTION_SMART_CHANGE:
|
case TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CHANGE:
|
||||||
Result = this.TRChangeSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
Result = this.TRChangeSmart(Block, Body, BlockNum, TrNum, ContextFrom)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -174,14 +108,14 @@ export default class SmartApp extends DApp {
|
|||||||
GetScriptTransaction(Body) {
|
GetScriptTransaction(Body) {
|
||||||
var Type = Body[0];
|
var Type = Body[0];
|
||||||
var format;
|
var format;
|
||||||
if (Type === TYPE_TRANSACTION_SMART_CREATE)
|
if (Type === TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CREATE)
|
||||||
format = global.FORMAT_SMART_CREATE
|
format = DB_FORMAT.FORMAT_SMART_CREATE
|
||||||
else
|
else
|
||||||
if (Type === global.TYPE_TRANSACTION_SMART_RUN)
|
if (Type === TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_RUN)
|
||||||
format = global.FORMAT_SMART_RUN
|
format = DB_FORMAT.FORMAT_SMART_RUN
|
||||||
else
|
else
|
||||||
if (Type === TYPE_TRANSACTION_SMART_CHANGE)
|
if (Type === TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CHANGE)
|
||||||
format = global.FORMAT_SMART_CHANGE
|
format = DB_FORMAT.FORMAT_SMART_CHANGE
|
||||||
if (!format)
|
if (!format)
|
||||||
return "";
|
return "";
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, format, {});
|
var TR = global.BufLib.GetObjectFromBuffer(Body, format, {});
|
||||||
@ -200,7 +134,7 @@ export default class SmartApp extends DApp {
|
|||||||
return "Error length transaction (max size)";
|
return "Error length transaction (max size)";
|
||||||
if (BlockNum < global.SMART_BLOCKNUM_START)
|
if (BlockNum < global.SMART_BLOCKNUM_START)
|
||||||
return "Error block num";
|
return "Error block num";
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_SMART_CREATE, WorkStructCreate);
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_SMART_CREATE, WorkStructCreate);
|
||||||
if (!TR.Name.trim())
|
if (!TR.Name.trim())
|
||||||
return "Name required";
|
return "Name required";
|
||||||
if (TR.AccountLength > 50)
|
if (TR.AccountLength > 50)
|
||||||
@ -297,7 +231,7 @@ export default class SmartApp extends DApp {
|
|||||||
return "Error length transaction (min size)";
|
return "Error length transaction (min size)";
|
||||||
if (BlockNum < global.SMART_BLOCKNUM_START)
|
if (BlockNum < global.SMART_BLOCKNUM_START)
|
||||||
return "Error block num";
|
return "Error block num";
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_SMART_RUN, WorkStructRun);
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_SMART_RUN, WorkStructRun);
|
||||||
var Account = global.DApps.Accounts.ReadStateTR(TR.Account);
|
var Account = global.DApps.Accounts.ReadStateTR(TR.Account);
|
||||||
if (!Account)
|
if (!Account)
|
||||||
return "RunSmart: Error account Num: " + TR.Account;
|
return "RunSmart: Error account Num: " + TR.Account;
|
||||||
@ -321,7 +255,7 @@ export default class SmartApp extends DApp {
|
|||||||
return "Error length transaction (min size)";
|
return "Error length transaction (min size)";
|
||||||
if (BlockNum < global.SMART_BLOCKNUM_START)
|
if (BlockNum < global.SMART_BLOCKNUM_START)
|
||||||
return "Error block num";
|
return "Error block num";
|
||||||
var TR = global.BufLib.GetObjectFromBuffer(Body, global.FORMAT_SMART_CHANGE, WorkStructChange);
|
var TR = global.BufLib.GetObjectFromBuffer(Body, DB_FORMAT.FORMAT_SMART_CHANGE, WorkStructChange);
|
||||||
if (!ContextFrom) {
|
if (!ContextFrom) {
|
||||||
var ResultCheck = this.CheckSignFrom(Body, TR, BlockNum, TrNum);
|
var ResultCheck = this.CheckSignFrom(Body, TR, BlockNum, TrNum);
|
||||||
if (typeof ResultCheck === "string")
|
if (typeof ResultCheck === "string")
|
||||||
@ -421,7 +355,7 @@ export default class SmartApp extends DApp {
|
|||||||
else
|
else
|
||||||
PrevNum = Item.Num - 1
|
PrevNum = Item.Num - 1
|
||||||
Item.SumHash = []
|
Item.SumHash = []
|
||||||
var Buf = global.BufLib.GetBufferFromObject(Item, this.FORMAT_ROW, 20000, {});
|
var Buf = global.BufLib.GetBufferFromObject(Item, DB_FORMAT.FORMAT_SMART_ROW, 20000, {});
|
||||||
var Hash = global.sha3(Buf);
|
var Hash = global.sha3(Buf);
|
||||||
if (PrevNum < 0)
|
if (PrevNum < 0)
|
||||||
Item.SumHash = Hash
|
Item.SumHash = Hash
|
||||||
@ -1215,6 +1149,6 @@ InitEval();
|
|||||||
|
|
||||||
var smartApp = new SmartApp;
|
var smartApp = new SmartApp;
|
||||||
global.DApps.Smart = smartApp;
|
global.DApps.Smart = smartApp;
|
||||||
global.DAppByType[TYPE_TRANSACTION_SMART_CREATE] = smartApp;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CREATE] = smartApp;
|
||||||
global.DAppByType[global.TYPE_TRANSACTION_SMART_RUN] = smartApp;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_RUN] = smartApp;
|
||||||
global.DAppByType[TYPE_TRANSACTION_SMART_CHANGE] = smartApp;
|
global.DAppByType[TYPE_TRANSACTION.TYPE_TRANSACTION_SMART_CHANGE] = smartApp;
|
||||||
|
Loading…
Reference in New Issue
Block a user