-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.js
62 lines (52 loc) · 1.59 KB
/
deploy.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
const { redis, web3 } = require("../connections");
const { User, Bank } = require("../models");
const config = require("../config");
const deployed = require("./deployed");
function listener(job, done) {
(async function () {
try {
const [user] = await User.find({ where: { id: job.data.user.id } });
const [bank] = await Bank.find({ where: { id: config.BANK_ID } });
const bankContract = web3.getBankContract(bank.address);
const createReceiver = bankContract.methods.createReceiver(user.id);
const nonce = await web3.client.eth.getTransactionCount(
config.TRANSACTION_SIGNER_PUBLIC_KEY
);
const createReceiverSigned =
await web3.client.eth.accounts.signTransaction(
{
to: bank.address,
data: createReceiver.encodeABI(),
gas: config.RECEIVER_DEPLOY_GAS,
nonce,
},
config.TRANSACTION_SIGNER_PRIVATE_KEY
);
const gasPrice = await web3.client.eth.getGasPrice();
const receipt = await web3.client.eth.sendSignedTransaction(
createReceiverSigned.rawTransaction
);
await deployed.addToQueue({
transactionHash: receipt.transactionHash,
user,
gasPrice,
});
done();
} catch (error) {
console.error(error);
done(error);
}
})();
}
function listen() {
redis.queues.Deploy.process(listener);
}
async function addToQueue({ user }) {
await redis.queues.Deploy.add(
{
user: { id: user.id },
},
{ attempts: 100, backoff: 5000 }
);
}
module.exports = { listen, addToQueue };