Skip to content

Commit 69a1844

Browse files
committed
add transaction & wallet model
1 parent 807d260 commit 69a1844

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

models/mongodb/index.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const mongoose = require('mongoose')
6+
const config = require('config')
7+
const db = {}
8+
9+
mongoose.Promise = global.Promise
10+
mongoose.connect(config.get('db.uri'), { useNewUrlParser: true })
11+
12+
// import all file in this dir, except index.js
13+
fs.readdirSync(__dirname)
14+
.filter(function (file) {
15+
return (file.indexOf('.') !== 0) && (file !== 'index.js')
16+
})
17+
.forEach(function (file) {
18+
var model = require(path.join(__dirname, file))
19+
db[model.modelName] = model
20+
})
21+
22+
db.mongoose = mongoose
23+
module.exports = db

models/mongodb/transaction.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
const mongoose = require('mongoose')
4+
const Schema = mongoose.Schema
5+
6+
const Transaction = new Schema({
7+
hash: {
8+
type: String,
9+
index: true,
10+
unique: true
11+
},
12+
block: {
13+
type: Number,
14+
index: true
15+
},
16+
fromAccount: {
17+
type: String,
18+
index: true
19+
},
20+
toAccount: {
21+
type: String,
22+
index: true
23+
},
24+
tokenAmount: {
25+
type: Number
26+
},
27+
isProcess: {
28+
type: Boolean
29+
}
30+
}, { timestamps: true })
31+
32+
module.exports = mongoose.model('Transaction', Transaction)

models/mongodb/wallet.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const mongoose = require('mongoose')
4+
const Schema = mongoose.Schema
5+
6+
const Wallet = new Schema({
7+
address: {
8+
type: String,
9+
index: true,
10+
unique: true
11+
},
12+
balance: {
13+
type: Number,
14+
index: true
15+
},
16+
transactionCount: {
17+
type: Number,
18+
index: true
19+
}
20+
}, { timestamps: true })
21+
22+
module.exports = mongoose.model('Wallet', Wallet)

0 commit comments

Comments
 (0)