-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.mjs
114 lines (94 loc) · 2.64 KB
/
index.mjs
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
import express from 'express'
import assert from 'assert'
import _log from 'debug'
import dotenv from 'dotenv'
import { ticketService } from './modules/tickets.mjs'
import { transactService } from './modules/transact.mjs'
/**
* DANGER! THERE IS NO ENDPOINT AUTH OR PROTECTION
* WHATSOEVER! PLEASE ADD YOUR OWN AUTH MIDDLEWARE
* AND IP WHITELISTING, ETC.
*/
const log = _log('accacser')
log('Starting app...')
const app = express()
const config = {
node: 'wss://testnet.xrpl-labs.com',
account: 'rhZ3E8LLdwQt8WuFgmPvu9j3npjDb7Xu4z', // TESTNET (No bug bounty ;))
familyseed: 'sEd7ZyacaRt9gh9DENZkSEKP4je31qy', // TESTNET (No bug bounty ;))
maxledgers: 10,
feedrops: 10,
minTickets: 5,
createTickets: 20,
port: 3000,
}
const envConfig = (dotenv.config().parsed || {})
log({envConfig})
Object.keys(envConfig).forEach(k => {
const lowerCaseKey = k.toLowerCase()
const baseConfigKeys = Object.keys(config)
const lowerBaseConfigKeys = Object.keys(config).map(bk => bk.toLowerCase())
const keyMatch = lowerBaseConfigKeys.indexOf(lowerCaseKey)
if (keyMatch > -1) {
Object.assign(config, {
[baseConfigKeys[keyMatch]]: envConfig[k]
})
}
})
log('Config', Object.assign({}, {
...config,
familyseed: '<<<<<<<<<<<<<<< SECRET >>>>>>>>>>>>>>>'
}))
assert(config?.account, 'Config (account) missing')
assert(config?.familyseed, 'Config (familyseed) missing')
const {
get: getTicket,
ready: ticketServiceReady,
count: ticketCount,
refreshCount: ticketRefreshCount,
balance: faucetBalance,
} = ticketService(config)
await ticketServiceReady()
const {
submit,
count: txCount,
} = transactService(getTicket, config)
log(`Distributing from\n > ${config.account}`)
/**
* Start Webserver
*/
const port = Number(config.port)
app.listen(port)
log('Listening at port', port)
/**
* Add routes
*/
app.get('/state', async (req, res) => {
return res.json({
account: config.account,
ticketCount: ticketCount(),
ticketRefreshCount: ticketRefreshCount(),
txCount: txCount(),
balance: faucetBalance(),
})
})
//
// ADD YOUR OWN TX PROCESSORS OVER HERE
//
// A GOOD PRACTICE WOULD BE TO SEND NO INFORMATION
// IN THE ROUTE OR PARAMS, BUT SIMPLY TRIGGER THIS
// CODE TO FETCH A JOB FROM YOUR OWN SECURED INFRA
// AND PROCESS BASED ON THAT FETCHED INFO INSTEAD OF
// CALLED INFO.
//
app.get('/pay/:account(r[a-zA-Z0-9]{16,})/:amount([0-9]{1,})', async (req, res) => {
/**
* This is where you change the tx logic.
* WARNING! ADD PROPER CHECKS, MAX AMOUNT, ETC!
*/
res.json(await submit({
TransactionType: 'Payment',
Destination: req.params.account,
Amount: String(req.params.amount || 1),
}))
})