-
Notifications
You must be signed in to change notification settings - Fork 1
/
examples.js
57 lines (43 loc) · 1.51 KB
/
examples.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
async function getSongScore(cid) {
const chart = await Chart.deployed()
const score = await chart.methods.getSongScore(cid).call()
// the score will already be decay-weighted based on the formula in the smart contract
}
async function getSongsToday() {
const chart = await Chart.deployed()
const latestBlockNumber = await web3.eth.getBlockNumber()
const blocksInADay = (24 * 60 * 60) / 15
let events = await chart.contract.getPastEvents('SongProposed', {
fromBlock: latestBlockNumber - blocksInADay,
toBlock: 'latest',
})
// do ABI decoding
events = Chart.decodeLogs(events)
// ... do stuff with events ...
}
async function getSongsProposedByUser(userAddr) {
const chart = await Chart.deployed()
const latestBlockNumber = await web3.eth.getBlockNumber()
const blocksInADay = (24 * 60 * 60) / 15
let events = await chart.contract.getPastEvents('SongProposed', {
filter: {
proposer: userAddr,
},
})
// do ABI decoding
events = Chart.decodeLogs(events)
// ... do stuff with events ...
}
async function getSongsUpvotedByUser(userAddr) {
const chart = await Chart.deployed()
const latestBlockNumber = await web3.eth.getBlockNumber()
const blocksInADay = (24 * 60 * 60) / 15
let events = await chart.contract.getPastEvents('SongUpvoted', {
filter: {
upvoter: userAddr,
},
})
// do ABI decoding
events = Chart.decodeLogs(events)
// ... do stuff with events ...
}