Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function contribute(BountyInterface.Bounty storage _bounty, uint _amount) external {
- //For now accept only contributions in the token that the bounty is in
- require(_bounty.status == BountyInterface.statusOptions.ACTIVE);
- BountyInterface.Contribution memory newContribution;
- newContribution.contributer = msg.sender;
- newContribution.token = _bounty.token;
- newContribution.amount = _amount;
- newContribution.timestamp = now;
- _bounty.contributions.push(newContribution);
- _bounty.totalContributions += _amount; //SAFEMATH THIS
- if (!ERC20(_bounty.token).transferFrom(msg.sender, _bounty.self, _amount)) revert();
- emit logContribute(msg.sender, _bounty.self, _amount, now);
- }
- export async function bountyActivityFeed(address) {
- try {
- //We can get created from the timestamp
- //startWork
- let event = (new Interface(BountyLib.abi)).events.logStartWork
- console.log(event.topics)
- let topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
- let startWorkLogs = await this.provider.getLogs({
- fromBlock: 1,
- toBlock: 'latest',
- topics: topics
- })
- startWorkLogs = startWorkLogs.map(log => {
- let ev = event.parse(log.topics, log.data)
- return {
- by: ev._by,
- timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
- type: 'startWork',
- extraData: null
- }
- })
- //Commits
- event = (new Interface(BountyLib.abi)).events.logSubmission
- topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
- let submissionLogs = await this.provider.getLogs({
- fromBlock: 1,
- toBlock: 'latest',
- topics: topics
- })
- submissionLogs = submissionLogs.map(log => {
- let ev = event.parse(log.topics, log.data)
- return {
- by: ev._by,
- timestamp:moment((ev._timestamp.toString(10) * 1000), "x"),
- type: 'commit',
- extraData: ev._id
- }
- })
- //contributions
- event = (new Interface(BountyLib.abi)).events.logContribute
- topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
- let contributionLogs = await this.provider.getLogs({
- fromblock: 1,
- toBlock: 'latest',
- topics: topics
- })
- contributionLogs = contributionLogs.map(log => {
- console.log(log)
- let ev = event.parse(log.topics, log.data)
- return {
- by: ev._by,
- timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
- type: 'contribute',
- extraData: parseFloat(formatEther(ev._amount)).toFixed(2)
- }
- })
- //Acceptance
- event = (new Interface(BountyLib.abi)).events.logAccepted
- topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
- let acceptedLog = await this.provider.getLogs({
- fromBlock: 1,
- toBlock: 'latest',
- topics: topics
- })
- acceptedLog = acceptedLog.map(log => {
- let ev = event.parse(log.topics, log.data)
- return {
- by: ev._winner,
- timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
- type: 'accepted'
- }
- })
- let activityLog = [...startWorkLogs, ...submissionLogs, ...contributionLogs, ...acceptedLog]
- activityLog = activityLog.sort((a, b) => {
- if (a.timestamp.isBefore(b.timestamp)) {
- return -1
- } else {
- return 1
- }
- })
- return activityLog
- } catch (err) {
- console.log(err)
- }
- }
- *getContribution()*
- Array(3) [ {…}, {…}, {…} ]
- *logContribute*
- ContributionLogs
- [],
- length: 0
Add Comment
Please, Sign In to add comment