-
Notifications
You must be signed in to change notification settings - Fork 0
/
revenueSharing.js
40 lines (33 loc) · 1.14 KB
/
revenueSharing.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
var path = require('path');
const { ABI, address } = require(path.join(global.appRoot, global.config.smartContract.smartContractInfoFilePath))
const { ethers } = require('ethers')
const itx = new ethers.providers.InfuraProvider(
global.config.smartContract.provider,
global.config.smartContract.key,
)
const revShareContract = new ethers.Contract(address, ABI, itx);
const _pickPointer = async () => {
try {
var totalPercentage = await revShareContract.getTotalPercentage()
var bigInt = totalPercentage._hex
var totalPercentage = ethers.BigNumber.from(bigInt).toNumber()
} catch (error) {
console.log('Total percentage error')
console.log(error)
}
// Generate a number from 1 to totalPercentage
var randomNum = Math.floor(1 + Math.random() * totalPercentage)
try {
var pointer = await revShareContract.pickPointer(randomNum)
} catch (error) {
console.log('Pick pointer error')
console.log(error)
}
if (global.config.useReceiptVerification == 'true') {
pointer = global.config.receiptVerification.service + encodeURIComponent(pointer)
}
return pointer
}
module.exports = {
pickPointer: _pickPointer
};