This repository has been archived by the owner on Jan 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.ts
142 lines (116 loc) · 3.18 KB
/
index.ts
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
139
140
141
142
import dotenv = require('dotenv')
dotenv.config()
import makeDebug = require('debug')
const debug = makeDebug('gnarly')
/**
* @TODO - handle lazy-require, config-based bootstrapping
*/
import Sequelize = require('sequelize')
import Gnarly, {
SequelizePersistInterface,
Web3Api,
} from '@xlnt/gnarly-core'
import makeERC20Reducer, {
makeSequelizeTypeStore as makeERC20TypeStore,
} from '@xlnt/gnarly-reducer-erc20'
import makeERC721Reducer, {
makeSequelizeTypeStore as makeERC721TypeStore,
} from '@xlnt/gnarly-reducer-erc721'
import makeBlockReducer, {
makeSequelizeTypeStore as makeBlockTypeStore,
} from '@xlnt/gnarly-reducer-block-meta'
import makeEventsReducer, {
makeSequelizeTypeStore as makeEventsTypeStore,
} from '@xlnt/gnarly-reducer-events'
const ZRX_ADDRESS = '0xe41d2489571d322189246dafa5ebde1f4699f498'
const CRYPTO_KITTIES_ADDRESS = '0x06012c8cf97BEaD5deAe237070F9587f8E7A266d'
const ETHER_GOO_ADDRESS = '0x57b116da40f21f91aec57329ecb763d29c1b2355'
import etherGooAbi from './abis/EtherGoo'
enum Keys {
ZRX = 'ZRX',
CryptoKitties = 'cryptoKitties',
Blocks = 'blocks',
Events = 'events',
}
const main = async () => {
const nodeEndpoint = process.env.NODE_ENDPOINT
const connectionString = process.env.DB_CONNECTION_STRING
const sequelize = new Sequelize(connectionString, {
logging: false,
pool: {
max: 5,
min: 0,
idle: 20000,
acquire: 20000,
},
retry: {
max: 1,
// @TODO(shrugs) ^ make this configurable with a default of ~3
},
})
const erc20Reducer = makeERC20Reducer(Keys.ZRX, makeERC20TypeStore(
Sequelize,
sequelize,
))(
ZRX_ADDRESS,
)
// ^ using ZRX simply because it has most transfers per block right now
const erc721Reducer = makeERC721Reducer(Keys.CryptoKitties, makeERC721TypeStore(
Sequelize,
sequelize,
))(
CRYPTO_KITTIES_ADDRESS,
)
const blockReducer = makeBlockReducer(Keys.Blocks, makeBlockTypeStore(
Sequelize,
sequelize,
))(
)
const eventsReducer = makeEventsReducer(Keys.Events, makeEventsTypeStore(
Sequelize,
sequelize,
))({
[ETHER_GOO_ADDRESS]: etherGooAbi,
})
const reducers = [
erc20Reducer,
erc721Reducer,
blockReducer,
eventsReducer,
]
const store = new SequelizePersistInterface(
Sequelize,
sequelize,
)
const ingestApi = new Web3Api(nodeEndpoint)
const gnarly = new Gnarly(
ingestApi,
store,
reducers,
)
let didRequestExit = false
const gracefulExit = async () => {
if (didRequestExit) {
process.exit(1)
}
didRequestExit = true
debug('Gracefully exiting. Send the signal again to force exit.')
await gnarly.bailOut()
process.exit(0)
}
process.on('SIGINT', gracefulExit)
process.on('SIGTERM', gracefulExit)
const GNARLY_RESET = (process.env.GNARLY_RESET || 'false') === 'true'
const LATEST_BLOCK_HASH = process.env.LATEST_BLOCK_HASH || null
await gnarly.reset(GNARLY_RESET)
await gnarly.shaka(LATEST_BLOCK_HASH)
}
process.on('unhandledRejection', (error) => {
console.error('unhandledRejection:', error, error.stack)
process.exit(1)
})
main()
.catch((error) => {
console.error(error, error.stack)
process.exit(1)
})