mirror of
https://github.com/status-im/contract-notifier.git
synced 2025-02-23 00:18:15 +00:00
Support querying smart contracts for template data
This commit is contained in:
parent
78201af25a
commit
13a0dfe98f
@ -78,7 +78,6 @@ class Controller {
|
||||
|
||||
static unsubscribe(dappConfig) {
|
||||
return async (req, res) => {
|
||||
// TODO:
|
||||
const {
|
||||
params: { dappId },
|
||||
body: { address, signature }
|
||||
|
@ -1,3 +1,32 @@
|
||||
|
||||
const ERC20_ABI = [
|
||||
{
|
||||
constant: true,
|
||||
inputs: [],
|
||||
name: "name",
|
||||
outputs: [
|
||||
{
|
||||
name: "",
|
||||
type: "string"
|
||||
}
|
||||
],
|
||||
payable: false,
|
||||
stateMutability: "view",
|
||||
type: "function"
|
||||
},
|
||||
{
|
||||
constant: true,
|
||||
type: "function",
|
||||
name: "balanceOf",
|
||||
inputs: [
|
||||
{ name: "owner", type: "address" }
|
||||
],
|
||||
outputs: [{ name: "balance", type: "uint256" }],
|
||||
stateMutability: "view"
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
module.exports = {
|
||||
from: {
|
||||
email: "noreply@teller.exchange",
|
||||
@ -27,7 +56,15 @@ module.exports = {
|
||||
template: {
|
||||
subject: "New trade!",
|
||||
html: "escrow-creation.html",
|
||||
text: "escrow-creation.txt"
|
||||
text: "escrow-creation.txt",
|
||||
data: async (web3, returnValues) => {
|
||||
// Example obtaining contract data
|
||||
const SNT = new web3.eth.Contract(ERC20_ABI, "0x3C36db79598e7902b5D726af7C7d406d5Da8aF14");
|
||||
return {
|
||||
'tokenName': await SNT.methods.name().call(),
|
||||
'balance': await SNT.methods.balanceOf(returnValues.seller).call()
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
"escrow-funded": {
|
||||
|
@ -18,8 +18,7 @@ eth.init();
|
||||
|
||||
events.on("db:connected", () => {
|
||||
events.on("web3:connected", () => {
|
||||
const blockNum =
|
||||
process.argv.length >= 3 ? parseInt(process.argv[2], 10) : 0;
|
||||
const blockNum = process.argv.length >= 3 ? parseInt(process.argv[2], 10) : 0;
|
||||
|
||||
dappConfig.getDapps().forEach(dappId => {
|
||||
const contracts = dappConfig.contracts(dappId);
|
||||
@ -33,17 +32,24 @@ events.on("db:connected", () => {
|
||||
events.on("web3:event", ({ dappId, address, event, returnValues }) => {
|
||||
dappConfig.eventConfig(dappId, address, event).forEach(async eventConfig => {
|
||||
const users = await Subscribers.findVerifiedUsersByDapp(dappId);
|
||||
users.forEach(user => {
|
||||
users.forEach(async user => {
|
||||
if (addressCompare(returnValues[eventConfig.index], user.address)) {
|
||||
console.log("Sending email...");
|
||||
mailer.send(
|
||||
dappConfig.getEmailTemplate(dappId, eventConfig.template),
|
||||
dappConfig.config(dappId).from,
|
||||
{
|
||||
email: user.email,
|
||||
...returnValues
|
||||
|
||||
let data = {
|
||||
email: user.email,
|
||||
...returnValues
|
||||
};
|
||||
|
||||
if (eventConfig.template.data) {
|
||||
try {
|
||||
data = Object.assign(data, await eventConfig.template.data(eth.web3, returnValues));
|
||||
} catch (err) {
|
||||
console.err("Error using data function", err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
mailer.send(dappConfig.getEmailTemplate(dappId, eventConfig.template), dappConfig.config(dappId).from, data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user