-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtriggerInteractionsUpdate.js
More file actions
97 lines (78 loc) · 2.63 KB
/
Copy pathtriggerInteractionsUpdate.js
File metadata and controls
97 lines (78 loc) · 2.63 KB
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
const partnersRegistryAddress = '0x67A28F057C431c901f62f3F162e045589C442e46';
var ethers = require('ethers');
var partnersRegistryAbi = require('./abis/PartnersRegistry.json')
.abi
var partnersAgreementAbi = require('./abis/PartnersAgreement.json')
.abi
var communityAbi = require('./abis/ICommunity.json')
.abi
const fs = require("fs");
const provider = new ethers.providers.JsonRpcProvider(
'https://rpc-mumbai.maticvigil.com/'
);
function mnemonic() {
try {
return fs.readFileSync("./mnemonic.txt").toString().trim();
} catch (e) {
throw new Error("Error: no mnemonic!")
}
}
// Wallet connected to a provider
const senderWalletMnemonic = ethers.Wallet.fromMnemonic(
mnemonic(),
"m/44'/60'/0'/0/0"
);
let signer = senderWalletMnemonic.connect(provider)
const partnersRegistryContract = new ethers.Contract(
partnersRegistryAddress,
partnersRegistryAbi,
signer,
)
// returns all partners agreements
async function getPartnerAgreementsAddresses() {
const partnerAgreements = await partnersRegistryContract.getPartnerAgreementAddresses();
return partnerAgreements;
}
async function getCommunityAddress(partnersAgreement) {
const partnersAgreementContract = new ethers.Contract(
partnersAgreement,
partnersAgreementAbi,
signer,
);
return await partnersAgreementContract.communityAddress();
}
async function getCommunityMembers(communityAddress) {
const community = new ethers.Contract(
communityAddress,
communityAbi,
signer,
);
return await community.getMemberAddresses();
}
async function queryForNewInteractions(agreement, memberAddress) {
const partnersAgreementContract = new ethers.Contract(
agreement,
partnersAgreementAbi,
signer,
);
var options = { gasPrice: 1000000000000, gasLimit: 1000000 };
partnersAgreementContract.queryForNewInteractions(memberAddress, options);
}
async function interactionsJob() {
const agreementsAddresses = await getPartnerAgreementsAddresses();
console.log(agreementsAddresses);
// agreementsAddresses.forEach(async agreement => {
// const agreement = agreementsAddresses[0];
// console.log(agreement)
const agreement = '0xcEf46F78182DF2a21bEFDA522A5F65fE4d0faA3E';
const community = await getCommunityAddress(agreement);
console.log('community', community)
const members = await getCommunityMembers(community);
console.log('members', members)
console.log(agreement, community, members);
members.forEach(member => queryForNewInteractions(agreement, member));
// });
}
// This allows the function to be exported for testing
// or for running in express
module.exports.interactionsJob = interactionsJob