check.js 1.69 KB
const file = require('fs')
const request = require('request')

async function getBlance(address) {
  return new Promise((resolve, reject) => {
    request({
      url: `http://localhost:8001/api/accounts?address=${address}`,
      method: 'GET',
    }, (err, response, body) => {
      if (err) {
        reject(err)
      } else {
        body = JSON.parse(body)
        resolve(body)
      }
    })
  })
  //  const respose=await nodeFetch('http://localhost:8001/api/transaction', {
  // 	method: 'post',
  // 	body: JSON.stringify(data),
  // 	headers: {'Content-Type': 'application/json'}
  // })
  // return await respose.json()
}
async function main() {
  let result = await file.readFileSync('./log/success.text','utf-8')
  const array = JSON.parse(result).list
  let unSuccessAccount = [], total = 0, unSuccesstotal = 0;
  for (let index = 0; index < array.length; index++) {
    const item = array[index];
    const result = await getBlance(item.address)
    if (result.success && Number(result.account.balance) !== Number(item.balance)) {
      console.log(result.account.balance, item.balance, Number(result.account.balance) !== Number(item.balance))
      unSuccesstotal += Number(item.balance)
      unSuccessAccount.push({ address: item.address, balance: item.balance, index: index })
    } else {
      total += Number(result.account.balance)
    }

  }
  console.log(`成功转账:${total},失败转账:${unSuccesstotal}`)
  file.writeFile('./log/unSuccess.text', `{"success":${total},"unSucccess":${unSuccesstotal},"list":${JSON.stringify(unSuccessAccount)}}`, { flag: 'a' }, err => { })

  // file.writeFile('./log/unSuccess.text', `${JSON.stringify(unSuccessAccount)}`, { flag: 'a' }, err => { })
}

main()