Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions content-service/.gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,3 +9,4 @@ npm-debug.log
local-test/
local-storage/
contract-config.json
eth-contract-config.json
8 changes: 4 additions & 4 deletions content-service/docker-compose/development.env
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,10 @@ port=8000
ethProviderUrl=http://docker.for.mac.localhost:8546

# Address information required on all environments
ethNetworkId=
ethTokenAddress=
ethRegistryAddress=
ethOwnerWallet=
# ethNetworkId=
# ethTokenAddress=
# ethRegistryAddress=
# ethOwnerWallet=

# wallet information required on all environments
delegateOwnerWallet=
Expand Down
13 changes: 13 additions & 0 deletions content-service/src/config.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,6 +102,19 @@ if (defaultConfigExists) config.loadFile('default-config.json')
const contractConfigExists = fs.existsSync('contract-config.json')
if (contractConfigExists) config.loadFile('contract-config.json')

// the eth-contract-config.json file is used to load registry address locally
// during development
const ethContractConfigExists = fs.existsSync('eth-contract-config.json')
if (ethContractConfigExists) {
let ethContractConfig = require('../eth-contract-config.json')

config.load({
'ethTokenAddress': ethContractConfig.audiusTokenAddress,
'ethRegistryAddress': ethContractConfig.registryAddress,
'ethOwnerWallet': ethContractConfig.ownerWallet
})
}

// Perform validation and error any properties are not present on schema
config.validate()

Expand Down
19 changes: 19 additions & 0 deletions eth-contracts/scripts/migrate-contracts.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,9 @@ const os = require('os');
const AudiusToken = artifacts.require('AudiusToken')
const Registry = artifacts.require('Registry')

const AudiusIdentityService = 'identity-service'
const AudiusContentService = 'content-service'

const Libs = 'libs'

const getDefaultAccount = async () => {
Expand DownExpand Up@@ -78,6 +81,22 @@ module.exports = async callback => {

copyBuildDirectory(libsDirRoot + '/ABIs')
outputJsonConfigFile(libsDirRoot + '/config.json')

// output to Identity Service
try {
outputJsonConfigFile(getDirectoryRoot(AudiusIdentityService) + '/eth-contract-config.json')
}
catch(e){
console.log("Identity service doesn't exist, probably running via E2E setup scripts")
}

// special case for content service which isn't run locally for E2E test or during front end dev
try {
outputJsonConfigFile(getDirectoryRoot(AudiusContentService) + '/eth-contract-config.json')
}
catch(e){
console.log("Content service folder doesn't exist, probably running via E2E setup scripts")
}

const dappOutput = os.homedir() + '/.audius'
if (!fs.existsSync(dappOutput)) {
Expand Down
3 changes: 2 additions & 1 deletion identity-service/.gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,4 +9,5 @@ npm-debug.log
file_storage/
local-storage/
local-test/
contract-config.json
contract-config.json
eth-contract-config.json
6 changes: 3 additions & 3 deletions identity-service/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,15 +3,15 @@
"version": "0.1.0",
"description": "",
"main": "src/index.js",
"keywords": [],
"author": "",
"license": "Apache-2.0",
"scripts": {
"start": "nodemon src/index.js | ./node_modules/.bin/bunyan || exit 0",
"test": "./scripts/run-tests.sh",
"lint": "./node_modules/.bin/standard",
"lint-fix": "./node_modules/.bin/standard --fix"
},
"keywords": [],
"author": "",
"license": "Apache-2.0",
"dependencies": {
"@audius/libs": "^0.10.0",
"aws-sdk": "^2.313.0",
Expand Down
28 changes: 20 additions & 8 deletions identity-service/src/audiusLibsInstance.js
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
const AudiusLibs = require('@audius/libs')
const Web3 = require('web3')
const config = require('./config.js')

const registryAddress = config.get('registryAddress')
const web3ProviderUrl = config.get('web3Provider')

let audiusInstance = {}

async function setupAndRun () {
const registryAddress = config.get('registryAddress')
const web3ProviderUrl = config.get('web3Provider')
const dataWeb3 = new Web3(new Web3.providers.HttpProvider(web3ProviderUrl))
const dataWeb3 = await AudiusLibs.Utils.configureWeb3(web3ProviderUrl, null, false)
if (!dataWeb3) throw new Error('Web3 incorrectly configured')

const audiusInstance = new AudiusLibs({
web3Config: AudiusLibs.configExternalWeb3(registryAddress, dataWeb3),
audiusInstance.libs = new AudiusLibs({
web3Config: {
registryAddress,
useExternalWeb3: true,
externalWeb3Config: {
web3: dataWeb3,
// this is a stopgap since libs external web3 init requires an ownerWallet
// this is never actually used in the service's libs calls
ownerWallet: config.get('relayerPublicKey')
}
},
isServer: true
})

await audiusInstance.init()
return audiusInstance
return audiusInstance.libs.init()
}

module.exports = setupAndRun
module.exports.audiusLibsInstance = audiusInstance
6 changes: 6 additions & 0 deletions identity-service/src/index.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,9 @@ const txRelay = require('./txRelay')
const { sequelize } = require('./models')
const { runMigrations } = require('./migrationManager')
const { logger } = require('./logging')

const initAudiusLibs = require('./audiusLibsInstance')

let appInfo

// run all migrations
Expand All@@ -18,6 +21,9 @@ setTimeout(async () => {
logger.info('Executing database migrations...')
runMigrations().then(async () => {
logger.info('Migrations completed successfully')

await initAudiusLibs()

appInfo = initializeApp(config.get('port'))
}).error((err) => {
logger.error('Error in migrations: ', err)
Expand Down
4 changes: 2 additions & 2 deletions identity-service/src/routes/twitter.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ const config = require('../config.js')
const models = require('../models')
const uuidv4 = require('uuid/v4')
const txRelay = require('../txRelay')
const getAudiusLibsInstance = require('../audiusLibsInstance')
let { audiusLibsInstance } = require('../audiusLibsInstance')

const { handleResponse, successResponse, errorResponseBadRequest } = require('../apiHelpers')

Expand DownExpand Up@@ -112,8 +112,8 @@ module.exports = function (app) {
* the blockchainUserId with the twitter profile so we can write the verified flag on chain
*/
app.post('/twitter/associate', handleResponse(async (req, res, next) => {
audiusLibsInstance = audiusLibsInstance.libs
let { uuid, userId, handle } = req.body
let audiusLibsInstance = await getAudiusLibsInstance()
try {
let twitterObj = await models.TwitterUser.findOne({ where: { uuid: uuid } })
// only set blockchainUserId if not already set
Expand Down
12 changes: 6 additions & 6 deletions libs/examples/local_initStakingOperations.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,10 +5,9 @@ const initAudiusLibs = require('./initAudiusLibs')
const serviceTypeList = ['discovery-provider', 'creator-node', 'content-service']
const spDiscProvType = serviceTypeList[0]
const spCreatorNodeType = serviceTypeList[1]
const discProvEndpoint1 = 'http://localhost:5000'
const creatorNodeEndpoint1 = 'http://localhost:4000'
const creatorNodeEndpoint2 = 'http://localhost:4010'
const spEndpoint2 = 'http://localhost:5001'
const discProvEndpoint1 = 'http://docker.for.mac.localhost:5000'
const creatorNodeEndpoint1 = 'http://docker.for.mac.localhost:4000'
const creatorNodeEndpoint2 = 'http://docker.for.mac.localhost:4010'

function throwArgError () {
throw new Error('missing argument - format: node examples/initiateStakingOperations.js [distribute, fundclaim, getclaim, stakeinfo, initversions, register-sps, query-sps, init-all]')
Expand DownExpand Up@@ -183,11 +182,12 @@ async function registerLocalServices () {
console.log(`\n${discProvEndpoint1} already registered`)
}
}

// Initialize w/different acct
const audius2 = await initAudiusLibs(true, null, ethAccts[1])
try {
// Register creator node
console.log('\nregistering creator node 2')
console.log('\nregistering creator node 1')
let tx = await audius2.ethContracts.ServiceProviderFactoryClient.register(
spCreatorNodeType,
creatorNodeEndpoint1,
Expand All@@ -197,7 +197,7 @@ async function registerLocalServices () {
if (!e.toString().includes('already registered')) {
console.log(e)
} else {
console.log(`\n${creatorNodeEndpoint2} already registered`)
console.log(`\n${creatorNodeEndpoint1} already registered`)
}
}
}
Expand Down