diff --git a/functions/src/scripts/correct-bet-probability.ts b/functions/src/scripts/correct-bet-probability.ts index d61157ff..47ffdb58 100644 --- a/functions/src/scripts/correct-bet-probability.ts +++ b/functions/src/scripts/correct-bet-probability.ts @@ -1,20 +1,14 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('stephen') + import { Bet } from '../../../common/bet' import { getProbability } from '../../../common/calculate' import { Contract } from '../../../common/contract' type DocRef = admin.firestore.DocumentReference - -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// const serviceAccount = require('../../../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') -const serviceAccount = require('../../../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-351a65eca3.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) const firestore = admin.firestore() async function migrateContract(contractRef: DocRef, contract: Contract) { diff --git a/functions/src/scripts/create-private-users.ts b/functions/src/scripts/create-private-users.ts index f9d84ba3..34a51a90 100644 --- a/functions/src/scripts/create-private-users.ts +++ b/functions/src/scripts/create-private-users.ts @@ -1,17 +1,11 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('stephen') + import { PrivateUser, STARTING_BALANCE, User } from '../../../common/user' -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk - -const serviceAccount = require('../../../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) - const firestore = admin.firestore() async function main() { diff --git a/functions/src/scripts/make-contracts-public.ts b/functions/src/scripts/make-contracts-public.ts index 2ebc5d61..a801f387 100644 --- a/functions/src/scripts/make-contracts-public.ts +++ b/functions/src/scripts/make-contracts-public.ts @@ -1,16 +1,11 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('james') + import { Contract } from '../../../common/contract' -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// const serviceAccount = require('../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') -const serviceAccount = require('../../../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) const firestore = admin.firestore() async function makeContractsPublic() { diff --git a/functions/src/scripts/migrate-contract.ts b/functions/src/scripts/migrate-contract.ts index 118c9159..c64981b1 100644 --- a/functions/src/scripts/migrate-contract.ts +++ b/functions/src/scripts/migrate-contract.ts @@ -1,18 +1,14 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('james') + import { Bet } from '../../../common/bet' import { Contract } from '../../../common/contract' type DocRef = admin.firestore.DocumentReference -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -const serviceAccount = require('../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) const firestore = admin.firestore() async function migrateBet(contractRef: DocRef, bet: Bet) { diff --git a/functions/src/scripts/migrate-to-dpm-2.ts b/functions/src/scripts/migrate-to-dpm-2.ts index a9787950..8ceef137 100644 --- a/functions/src/scripts/migrate-to-dpm-2.ts +++ b/functions/src/scripts/migrate-to-dpm-2.ts @@ -1,6 +1,9 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('stephenDev') + import { Contract } from '../../../common/contract' import { Bet } from '../../../common/bet' import { calculateShares, getProbability } from '../../../common/calculate' @@ -9,15 +12,6 @@ import { User } from '../../../common/user' type DocRef = admin.firestore.DocumentReference -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// const serviceAccount = require('../../../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') -const serviceAccount = require('../../../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-351a65eca3.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) - const firestore = admin.firestore() async function recalculateContract( diff --git a/functions/src/scripts/recalculate-contract-totals.ts b/functions/src/scripts/recalculate-contract-totals.ts index 3a368fbb..6521425b 100644 --- a/functions/src/scripts/recalculate-contract-totals.ts +++ b/functions/src/scripts/recalculate-contract-totals.ts @@ -1,19 +1,14 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('james') + import { Bet } from '../../../common/bet' import { Contract } from '../../../common/contract' type DocRef = admin.firestore.DocumentReference -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// const serviceAccount = require('../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') -const serviceAccount = require('../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) const firestore = admin.firestore() async function recalculateContract(contractRef: DocRef, contract: Contract) { diff --git a/functions/src/scripts/rename-user-contracts.ts b/functions/src/scripts/rename-user-contracts.ts index 8639a590..fabb5acd 100644 --- a/functions/src/scripts/rename-user-contracts.ts +++ b/functions/src/scripts/rename-user-contracts.ts @@ -1,19 +1,12 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' +import { initAdmin } from './script-init' +initAdmin('stephenDev') + import { Contract } from '../../../common/contract' import { getValues } from '../utils' -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// James: -const serviceAccount = require('../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json') -// Stephen: -// const serviceAccount = require('../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') - -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) const firestore = admin.firestore() async function renameUserContracts( diff --git a/functions/src/scripts/script-init.ts b/functions/src/scripts/script-init.ts new file mode 100644 index 00000000..5924ad1d --- /dev/null +++ b/functions/src/scripts/script-init.ts @@ -0,0 +1,32 @@ +import * as admin from 'firebase-admin' + +// Generate your own private key, and set the path below: +// Prod: +// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk +// Dev: +// https://console.firebase.google.com/u/0/project/dev-mantic-markets/settings/serviceaccounts/adminsdk + +const pathsToPrivateKey = { + james: + '/Users/jahooma/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json', + jamesDev: + '/Users/jahooma/dev-mantic-markets-firebase-adminsdk-sir5m-f38cdbee37.json', + stephen: + '../../../../../../Downloads/mantic-markets-firebase-adminsdk-1ep46-351a65eca3.json', + stephenDev: + '../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json', +} + +export const initAdmin = (who: keyof typeof pathsToPrivateKey) => { + const serviceAccount = require(pathsToPrivateKey[who]) + + admin.initializeApp({ + credential: admin.credential.cert(serviceAccount), + }) +} + +// Then: +// yarn watch (or yarn build) +// firebase use dev (or firebase use prod) +// Run script: +// node lib/functions/src/scripts/update-contract-tags.js diff --git a/functions/src/scripts/update-contract-tags.ts b/functions/src/scripts/update-contract-tags.ts index 72f6b87a..29b68685 100644 --- a/functions/src/scripts/update-contract-tags.ts +++ b/functions/src/scripts/update-contract-tags.ts @@ -1,22 +1,15 @@ import * as admin from 'firebase-admin' import * as _ from 'lodash' -// Generate your own private key, and set the path below: -// https://console.firebase.google.com/u/0/project/mantic-markets/settings/serviceaccounts/adminsdk -// James: -const serviceAccount = require('/Users/jahooma/mantic-markets-firebase-adminsdk-1ep46-820891bb87.json') -// Stephen: -// const serviceAccount = require('../../../../Downloads/dev-mantic-markets-firebase-adminsdk-sir5m-b2d27f8970.json') -admin.initializeApp({ - credential: admin.credential.cert(serviceAccount), -}) -const firestore = admin.firestore() +import { initAdmin } from './script-init' +initAdmin('jamesDev') import { Contract } from '../../../common/contract' import { parseTags } from '../../../common/util/parse' import { getValues } from '../utils' async function updateContractTags() { + const firestore = admin.firestore() console.log('Updating contracts tags') const contracts = await getValues(firestore.collection('contracts')) @@ -48,4 +41,6 @@ async function updateContractTags() { } } -if (require.main === module) updateContractTags().then(() => process.exit()) +if (require.main === module) { + updateContractTags().then(() => process.exit()) +}