Skip to content
This repository has been archived by the owner on Oct 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from 1Hive/worker-improvements
Browse files Browse the repository at this point in the history
Various improvements to worker
  • Loading branch information
onbjerg authored Aug 16, 2019
2 parents 8fa081e + d6667c8 commit e7256b1
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 16 deletions.
7 changes: 5 additions & 2 deletions worker/src/classifiers/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import topics from '../data/topics'

export default function * () {
yield takeEvery('daolist/eth/LOG', function * ({ payload: event }) {
const timestamp = event.timestamp
switch (event.topics[0]) {
case topics.NEW_APP_PROXY:
const { proxy, appId } = abi.decodeLog(
Expand All @@ -27,7 +28,8 @@ export default function * () {

const appInstall = {
proxy,
appId
appId,
timestamp
}

yield put({
Expand Down Expand Up @@ -55,7 +57,8 @@ export default function * () {
const newVersion = {
id: versionId,
semantic: semanticVersion,
repository: event.address
repository: event.address,
timestamp
}

yield put({
Expand Down
3 changes: 2 additions & 1 deletion worker/src/classifiers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export default function * () {
kit: transaction.to,
creator: transaction.from,
transaction: transaction.hash,
name: `${name}.aragonid.eth`
name: `${name}.aragonid.eth`,
timestamp: transaction.timestamp
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions worker/src/fetchers/block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { delay } from 'redux-saga'
import { getContext, put, all } from 'redux-saga/effects'
import { getContext, put, all, delay } from 'redux-saga/effects'
import _ from 'lodash'
import { promisify } from 'util'

Expand Down
1 change: 1 addition & 0 deletions worker/src/fetchers/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default function * () {
const { logs } = yield web3.eth.getTransactionReceipt(transaction.hash)

for (const log of logs) {
log.timestamp = transaction.timestamp
yield put({
type: 'daolist/eth/LOG',
payload: log
Expand Down
5 changes: 3 additions & 2 deletions worker/src/fetchers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { take, put } from 'redux-saga/effects'
export default function * transactionFetcher () {
while (true) {
const {
payload: { transactions }
payload: block
} = yield take('daolist/eth/BLOCK')

for (const transaction of transactions) {
for (const transaction of block.transactions) {
transaction.timestamp = block.timestamp
yield put({
type: 'daolist/eth/TRANSACTION',
payload: transaction
Expand Down
3 changes: 3 additions & 0 deletions worker/src/persisters/app/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export default function * () {
id: appInstall.appId,
address: appInstall.proxy
}
},
$min: {
created_at: appInstall.timestamp
}
}
)
Expand Down
27 changes: 21 additions & 6 deletions worker/src/persisters/app/metadata.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getContext, takeEvery } from 'redux-saga/effects'
import { getContext, takeEvery, retry } from 'redux-saga/effects'
import abi from 'web3-eth-abi'
import got from 'got'
import path from 'path'
Expand Down Expand Up @@ -35,6 +35,8 @@ const KNOWN_APPS_BY_URI = {
}
}

const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'

export async function fetchVersion (web3, repository, versionId) {
const call = abi.encodeFunctionCall(
{
Expand Down Expand Up @@ -73,8 +75,15 @@ export async function fetchVersion (web3, repository, versionId) {
result
)

const [type, uri] = web3.utils.hexToAscii(contentURI).split(':')
const content = web3.utils.hexToAscii(contentURI)
if (!content.includes(':') && contractAddress === NULL_ADDRESS) {
// If the content URI is malformed and there is no implementation address,
// then we skip this app as it is possibly another type of content published
// over APM.
return null
}

const [type, uri] = content.split(':')
const isKnownApp = !!KNOWN_APPS_BY_URI[uri]

let manifest = {}
Expand Down Expand Up @@ -131,20 +140,26 @@ export default function * () {
payload: newVersion
}) {
log.info('New version for app', newVersion)

const { app, version } = yield fetchVersion(
const versionMeta = yield retry(
3,
3000,
fetchVersion,
web3,
newVersion.repository,
newVersion.id
)

if (versionMeta === null) {
return
}

// Add app to org
yield apps.updateOne(
{ address: newVersion.repository },
{
$set: app,
$set: versionMeta.app,
$addToSet: {
versions: version
versions: versionMeta.version
}
},
{ upsert: true }
Expand Down
15 changes: 12 additions & 3 deletions worker/src/persisters/dao/name.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getContext, take } from 'redux-saga/effects'
import { getContext, take, retry } from 'redux-saga/effects'
import { safeUpsert } from '../../utils/index'

export default function * () {
Expand All @@ -12,9 +12,18 @@ export default function * () {

log.info('DAO name set', { dao })

const address = yield web3.eth.ens.getAddress(dao.name)
const address = yield retry(3, 3000, () => web3.eth.ens.getAddress(dao.name))
dao.address = address

yield safeUpsert(orgs, { address }, { $set: dao })
yield safeUpsert(
orgs,
{ address },
{
$set: dao,
$min: {
created_at: dao.timestamp
}
}
)
}
}

0 comments on commit e7256b1

Please sign in to comment.