forked from XinFinOrg/XDCScan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
138 lines (125 loc) · 3.78 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var mongoose = require( 'mongoose' );
var Schema = mongoose.Schema;
var Block = new Schema(
{
"number": {type: Number, index: {unique: true}},
"hash": String,
"parentHash": String,
"nonce": String,
"sha3Uncles": String,
"logsBloom": String,
"transactionsRoot": String,
"stateRoot": String,
"receiptRoot": String,
"miner": String,
"difficulty": String,
"totalDifficulty": String,
"size": Number,
"extraData": String,
"gasLimit": Number,
"gasUsed": Number,
"timestamp": {type: Number, index: true},
"uncles": [String],
"txs": [String],//same with transactions
"witness": {type: String, index: true}
});
//master node Info
var Witness = new Schema(
{
"blocksNum": Number,//mine block count
"lastCountTo": Number,//block height
"witness": {type: String, index: {unique: true}},
"status":Boolean,
"hash":String,
"reward":Number,
"miner":String,
"timestamp": Number
});
var Contract = new Schema(
{
"address": {type: String, index: {unique: true}},
"blockNumber": Number,
"ERC":{type: Number, index: true},//0:normal contract 2:ERC20, 3:ERC223
"creationTransaction": String,
"contractName": String,
"tokenName": String,
"symbol": String,
"owner": String,
"decimals": Number,
"totalSupply": Number,
"balance": Number,
"compilerVersion": String,
"optimization": Boolean,
"sourceCode": String,
"abi": String,
"byteCode": String
}, {collection: "Contract"});
var Transaction = new Schema(
{
"hash": {type: String, index: {unique: true}},
"nonce": Number,
"blockHash": String,
"blockNumber": {type: Number, index: true},
"transactionIndex": Number,
"status":Number,
"from": String,
"to": String,
"value": String,
"gas": Number,
"contractAddress":String,
"gasUsed":Number,
"gasPrice": String,
"timestamp": Number,
"input": String,
"witness": String
});
var TokenTransfer = new Schema(
{
"transactionHash": {type: String, index: {unique: true}},
"blockNumber": Number,
"methodName": String,
"amount": Number,
"contractAdd": String,
"to": String,
"from": String,
"timestamp": Number
});
mongoose.model('TokenTransfer', TokenTransfer);
var TokenTransferClass = mongoose.model('TokenTransfer');
var LogEvent = new Schema(
{
"address": String,
"txHash": {type: String, index: true},
"blockNumber": Number,
"contractAdd": String,//same with address
"timestamp": Number,
"methodName": String,
"eventName": String,
"from": String,
"to": String,
"logIndex": Number,
"topics": Array,
"data": String
});
mongoose.model('LogEvent', LogEvent);
//all address
var Address = new Schema(
{
"addr": {type: String, index: {unique: true}},
"type": {type: Number, index: true},//0:normal 1:contract 2:masternode
"balance": Number
});
mongoose.model('Address', Address);
mongoose.model('Block', Block);
mongoose.model('Contract', Contract);
mongoose.model('Transaction', Transaction);
mongoose.model('Witness', Witness);
module.exports.Block = mongoose.model('Block');
module.exports.Contract = mongoose.model('Contract');
module.exports.Transaction = mongoose.model('Transaction');
module.exports.TokenTransfer = TokenTransferClass;
module.exports.Witness = Witness;
module.exports.LogEvent = mongoose.model('LogEvent');
module.exports.Address = mongoose.model('Address');
mongoose.connect( 'mongodb://localhost/BlockScanDB' );
mongoose.set('debug', false);