Commit 82494571 authored by Is Nikolova's avatar Is Nikolova

Fixed speed

parent a1da92a0
This diff is collapsed.
import Tx from 'ethereumjs-tx'
import Web3 from 'web3'
import { pirlRpc,
import { // pirlRpc,
wsPirlRpc,
positiveVoteAddress,
negativeVoteAddress,
......@@ -12,8 +12,8 @@ import { pirlRpc,
contentNodeAddress,
contentNodeAbi } from './config'
const web3 = new Web3(new Web3.providers.HttpProvider(pirlRpc))
const web3Ws = new Web3(new Web3.providers.WebsocketProvider(wsPirlRpc))
// const web3 = new Web3(new Web3.providers.HttpProvider(pirlRpc))
const web3 = new Web3(new Web3.providers.WebsocketProvider(wsPirlRpc))
let lowerCaseBlackList = blackList.map(a => a.toLowerCase())
const getPrivatekey = ({ keystore, password }) => {
let decryptedAccount = web3.eth.accounts.decrypt(keystore, password)
......@@ -74,6 +74,7 @@ const takeResults = async () => {
let positiveAddresses = positiveResultsDistinct.map(x => x.address)
let negativeAddresses = negativeResultsDistinct.map(x => x.address)
let controversial = []
for (let i = 0; i < positiveAddresses.length; i++) {
......@@ -86,29 +87,23 @@ const takeResults = async () => {
controversial.push(arr)
} else {
if (checkWithBlackList(positiveAddresses[i]) < 0) {
let amount = await checkAddressIsMasternode(positiveAddresses[i])
if (amount > 0) {
positiveBalance += Number(amount)
} else {
let balance = await web3.eth.getBalance(positiveAddresses[i])
let pirl = web3.utils.fromWei(balance, 'ether')
positiveBalance += Number(pirl)
}
web3.eth.getBalance(positiveAddresses[i])
.then(async (balance) => {
let pirl = web3.utils.fromWei(balance, 'ether')
let amount = await checkAddressIsMasternode(positiveAddresses[i])
positiveBalance += (amount + Number(pirl))
})
}
}
}
for (let i = 0; i < negativeAddresses.length; i++) {
let indexOfPositive = positiveAddresses.indexOf(negativeAddresses[i])
if (indexOfPositive < 0 && checkWithBlackList(positiveAddresses[i]) < 0) {
if (indexOfPositive < 0 && checkWithBlackList(negativeAddresses[i]) < 0) {
let balance = await web3.eth.getBalance(negativeAddresses[i])
let pirl = web3.utils.fromWei(balance, 'ether')
let amount = await checkAddressIsMasternode(negativeAddresses[i])
if (amount > 0) {
negativeBalance += Number(amount)
} else {
let balance = await web3.eth.getBalance(negativeAddresses[i])
let pirl = web3.utils.fromWei(balance, 'ether')
negativeBalance += Number(pirl)
}
negativeBalance += (amount + Number(pirl))
}
}
......@@ -116,24 +111,16 @@ const takeResults = async () => {
if (checkWithBlackList(controversial[i][0].address) < 0) {
let positiveBlockNumber = controversial[i][0].blockNumber
let negativeBlockNumber = controversial[i][1].blockNumber
let balance = await web3.eth.getBalance(controversial[i][0].address)
let pirl = web3.utils.fromWei(balance, 'ether')
let amount = await checkAddressIsMasternode(controversial[i][0].address)
let sum = Number(pirl) + amount
if (positiveBlockNumber >= negativeBlockNumber) {
let amount = await checkAddressIsMasternode(controversial[i][0].address)
if (amount > 0) {
positiveBalance += Number(amount)
} else {
let balance = await web3.eth.getBalance(controversial[i][0].address)
let pirl = web3.utils.fromWei(balance, 'ether')
positiveBalance += Number(pirl)
}
positiveBalance += sum
} else {
let amount = await checkAddressIsMasternode(controversial[i][0].address)
if (amount > 0) {
negativeBalance += Number(amount)
} else {
let balance = await web3.eth.getBalance(controversial[i][0].address)
let pirl = web3.utils.fromWei(balance, 'ether')
negativeBalance += Number(pirl)
}
negativeBalance += sum
}
}
}
......@@ -144,18 +131,10 @@ const takeResults = async () => {
const checkAddressIsMasternode = async (address) => {
let res = await contentNodeContract.methods.getNodeAddress(address).call()
let balance1 = await web3.eth.getBalance(address)
let pirl1 = web3.utils.fromWei(balance1, 'ether')
if (!res.startsWith('0x0000')) return 10000 + Number(pirl1)
if (!res.startsWith('0x0000')) return 10000
let res2 = await premiumMasternodeContract.methods.getNodeAddress(address).call()
let balance = await web3.eth.getBalance(address)
let pirl = web3.utils.fromWei(balance, 'ether')
if (!res2.startsWith('0x0000')) return 20000 + Number(pirl)
else {
let balance3 = await web3.eth.getBalance(address)
let pirl3 = web3.utils.fromWei(balance3, 'ether')
return Number(pirl3)
}
if (!res2.startsWith('0x0000')) return 20000
return 0
}
const checkWithBlackList = (address) => {
......@@ -225,7 +204,7 @@ const negativeVoteContract = new web3.eth.Contract(voteAbi, negativeVoteAddress)
const network = {
web3,
web3Ws,
// web3Ws,
sendTransaction,
contentNodeContract,
premiumMasternodeContract,
......
......@@ -190,12 +190,8 @@ Due to this, we think the decision on what would happen to the PIRL from a liqui
this.negativeAddr = negativeVoteAddress
this.init()
setInterval(() => {
network.takeResults()
.then((result) => {
this.yesResult = result.positiveBalance
this.noResult = result.negativeBalance
})
}, 2000)
this.init()
}, 12000)
},
methods: {
init () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment