循环遍历出用户所有历史,包括所有的发贴、评论、转帐、更改密码等信息,也就是说用户的所有操作都在这个历史里面。
getAll() {
let account = "starnote"
let from = 10
let limit = 9
let i = 1
let _this = this
async function getAllHistory(all=[]){
//标记最后一次的操作,作为循环的终止条件
let latestHistory = await _this.steem.api.getAccountHistoryAsync(account, -1, 0)
console.log(111, latestHistory)
while(true) {
let history = await _this.steem.api.getAccountHistoryAsync(account, from, limit)
console.log(222, history)
all = all.concat(history)
from = from + 10
i++
if (history[limit][1].block === latestHistory[0][1].block) {
break
}
console.log(355, i)
}
return all
}
getAllHistory()
.then(res => {
console.log(123, res)
let newJson = [] //盛放去重后数据的新数组
for(let item1 of res){ //循环json数组对象的内容
let flag = true //建立标记,判断数据是否重复,true为不重复
for(let item2 of newJson){ //循环新数组的内容
if(item1[1].block==item2[1].block){
//让json数组对象的内容与新数组的内容作比较,相同的话,改变标记为false
flag = false
}
}
if(flag){ //判断是否重复
newJson.push(item1)//不重复的放入新数组.新数组的内容会继续进行上边的循环。
}
}
console.log("newJson",newJson)
})
}
RE: SteemJS中文手册