Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local dev init script #17

Merged
merged 1 commit into from
Aug 16, 2019
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
5 changes: 3 additions & 2 deletions libs/examples/initAudiusLibs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const dataWeb3ProviderEndpoint = 'http://localhost:8545'
const ethWeb3ProviderEndpoint = 'http://localhost:8546'
const isServer = true

async function initAudiusLibs (useExternalWeb3, ownerWalletOverride = null) {
async function initAudiusLibs (useExternalWeb3, ownerWalletOverride = null, ethOwnerWalletOverride = null) {
let audiusLibsConfig
const ethWeb3 = new Web3(new Web3.providers.HttpProvider(ethWeb3ProviderEndpoint))
let ethWallet = ethOwnerWalletOverride === null ? ethContractsConfig.ownerWallet : ethOwnerWalletOverride
if (useExternalWeb3) {
const dataWeb3 = new Web3(new Web3.providers.HttpProvider(dataWeb3ProviderEndpoint))
audiusLibsConfig = {
Expand All @@ -27,7 +28,7 @@ async function initAudiusLibs (useExternalWeb3, ownerWalletOverride = null) {
ethContractsConfig.audiusTokenAddress,
ethContractsConfig.registryAddress,
ethWeb3,
ethContractsConfig.ownerWallet
ethWallet
),
discoveryProviderConfig: AudiusLibs.configDiscoveryProvider(true),
creatorNodeConfig: AudiusLibs.configCreatorNode(creatorNodeEndpoint),
Expand Down
124 changes: 123 additions & 1 deletion libs/examples/local_initStakingOperations.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const spEndpoint2 = 'http://localhost:5001'
function throwArgError () {
throw new Error('missing argument - format: node examples/initiateStakingOperations.js [distribute, fundclaim, getclaim, stakeinfo]')
}
let testVersionStr = '0.0.1'
let testVersionStr = '0.1.0'

let args = process.argv
if (args.length < 3) {
Expand All @@ -37,6 +37,18 @@ switch (args[2]) {
console.log('stakeinfo')
getStakingParameters()
break
case 'initversions':
initializeVersions()
break
case 'register-sps':
registerLocalServices()
break
case 'query-sps':
queryLocalServices()
break
case 'init-all':
initializeLocalEnvironment()
break
default:
throwArgError()
}
Expand Down Expand Up @@ -105,3 +117,113 @@ async function distributeTokens () {
console.log(tx)
}
}

async function initializeVersions () {
const audius1 = await initAudiusLibs(true)
let testTx = null
for (const serviceType of serviceTypeList) {
console.log(`\nregistering ${serviceType}`)
try {
testTx = await audius1.ethContracts.VersioningFactoryClient.setServiceVersion(
serviceType,
testVersionStr)
console.log(testTx)
} catch (e) {
if (!e.toString().includes('Already registered')) {
console.log(e)
} else {
console.log('Already registered')
}
}
}

for (const serviceType of serviceTypeList) {
let versionTx = await audius1.ethContracts.VersioningFactoryClient.getCurrentVersion(serviceType)
let numVersionsTx = await audius1.ethContracts.VersioningFactoryClient.getNumberOfVersions(serviceType)
console.log(`${serviceType} | current version: ${versionTx} | number of versions : ${numVersionsTx}`)
}

console.log('----version init---/')
}

async function registerLocalServices () {
await distributeTokens()
const testWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8546/'))
const audius1 = await initAudiusLibs(true)
let ethweb3 = audius1.ethWeb3Manager.getWeb3()
let ethAccts = await ethweb3.eth.getAccounts()
console.log('\nregistering service providers/---')
const amountOfAUDS = 100000
let initialTokenInAudWei = testWeb3.utils.toWei(amountOfAUDS.toString(), 'ether')
let initialTokenInAudWeiBN = testWeb3.utils.toBN(initialTokenInAudWei)
try {
// Register discovery provider
console.log('\nregistering disc prov')
let tx = await audius1.ethContracts.ServiceProviderFactoryClient.register(
spDiscProvType,
discProvEndpoint1,
initialTokenInAudWeiBN)
console.dir(tx, { depth: 5 })
} catch (e) {
if (!e.toString().includes('already registered')) {
console.log(e)
} else {
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')
let tx = await audius2.ethContracts.ServiceProviderFactoryClient.register(
spCreatorNodeType,
creatorNodeEndpoint1,
initialTokenInAudWeiBN)
console.dir(tx, { depth: 5 })
} catch (e) {
if (!e.toString().includes('already registered')) {
console.log(e)
} else {
console.log(`\n${creatorNodeEndpoint2} already registered`)
}
}
}

async function queryLocalServices () {
const ethWeb3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8546/'))
const ethAccounts = await ethWeb3.eth.getAccounts()
const audius1 = await initAudiusLibs(true)
for (const spType of serviceTypeList) {
console.log(`\n${spType}`)
let spList = await audius1.ethContracts.ServiceProviderFactoryClient.getServiceProviderList(spType)
for (const sp of spList) {
console.log(sp)
let endpt = sp.endpoint
let spID = sp.spID
let type = sp.type
let idFromEndpoint =
await audius1.ethContracts.ServiceProviderFactoryClient.getServiceProviderIdFromEndpoint(endpt)
console.log(`ID from endpoint: ${idFromEndpoint}`)
let infoFromId =
await audius1.ethContracts.ServiceProviderFactoryClient.getServiceProviderInfo(type, spID)
let jsonInfoFromId = JSON.stringify(infoFromId)
console.log(`Info from ID: ${jsonInfoFromId}`)
let idsFromAddress =
await audius1.ethContracts.ServiceProviderFactoryClient.getServiceProviderIdFromAddress(
ethAccounts[0],
type)
console.log(`SP IDs from owner wallet ${ethAccounts[0]}: ${idsFromAddress}`)
}
let numProvs = await audius1.ethContracts.ServiceProviderFactoryClient.getTotalServiceTypeProviders(spType)
console.log(`num ${spType}: ${numProvs}`)
}
console.log('----querying service providers done')
}

async function initializeLocalEnvironment () {
await distributeTokens()
await initializeVersions()
await registerLocalServices()
await queryLocalServices()
}
144 changes: 0 additions & 144 deletions libs/examples/local_versionAndServiceProviderInit.js

This file was deleted.