From 931bfb07895febfd135b1f60374f34b50c27a2c0 Mon Sep 17 00:00:00 2001 From: Mentor Palokaj Date: Tue, 19 Oct 2021 14:30:36 +0200 Subject: [PATCH] Fix missing erms and add some comments --- .github/workflows/deploy-functions.yml | 2 ++ functions/index.js | 3 +++ functions/modules/contract.js | 3 +++ functions/modules/express.js | 12 +++--------- functions/modules/firebase.js | 2 +- functions/modules/rocketeer.js | 2 +- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.github/workflows/deploy-functions.yml b/.github/workflows/deploy-functions.yml index b71e20c..7d8b22b 100644 --- a/.github/workflows/deploy-functions.yml +++ b/.github/workflows/deploy-functions.yml @@ -42,6 +42,8 @@ jobs: service_account_key: "${{ secrets.GCP_SERVICE_ACCOUT_JSON_PRODUCTION }}" export_default_credentials: true + # Note to self: needs IAM permissions + # see https://firebase.google.com/docs/firestore/manage-data/export-import - name: Backup firestore run: | gcloud config set project ${{ secrets.FIREBASE_PROJECT_ID_PRODUCTION }} diff --git a/functions/index.js b/functions/index.js index 620411d..7aa13c2 100644 --- a/functions/index.js +++ b/functions/index.js @@ -2,5 +2,8 @@ const functions = require( 'firebase-functions' ) const testnetAPI = require( './modules/testnet' ) const mainnetAPI = require( './modules/mainnet' ) +// Testnet endpoint exports.testnetMetadata = functions.https.onRequest( testnetAPI ) + +// Mainnet endpoint exports.mainnetMetadata = functions.https.onRequest( mainnetAPI ) \ No newline at end of file diff --git a/functions/modules/contract.js b/functions/modules/contract.js index 5fba569..e249e89 100644 --- a/functions/modules/contract.js +++ b/functions/modules/contract.js @@ -8,6 +8,8 @@ const contractAddress = { mainnet: '', rinkeby: '0x2829ba9d76e675b8867E1707A9aB49B280D916c6' } + +// ABI with only the supply definitions const ABI = [ { "inputs": [], @@ -25,6 +27,7 @@ const ABI = [ } ] +// Total current supply, in accordance with ERC721 spec async function getTotalSupply( network='mainnet' ) { // Initialise contract connection diff --git a/functions/modules/express.js b/functions/modules/express.js index ee20919..39bc73c 100644 --- a/functions/modules/express.js +++ b/functions/modules/express.js @@ -1,20 +1,14 @@ const express = require( 'express' ) const cors = require( 'cors' ) - - // CORS enabled express generator module.exports = f => { + // Create express server const app = express() + + // Enable CORS app.use( cors( { origin: true } ) ) - // Logger for debugging - // app.use( ( req, res, next ) => { - - // console.log( 'base:', req.baseUrl, 'params:', req.params, 'body:', req.body, 'originalurl:', req.originalUrl, 'path:', req.path ) - - // next() - // } ) return app diff --git a/functions/modules/firebase.js b/functions/modules/firebase.js index 6efa07e..169d7bd 100644 --- a/functions/modules/firebase.js +++ b/functions/modules/firebase.js @@ -1,5 +1,5 @@ // Dependencies -const admin = require('firebase-admin') +const admin = require( 'firebase-admin' ) // Admin api const app = admin.initializeApp() diff --git a/functions/modules/rocketeer.js b/functions/modules/rocketeer.js index 4ea197d..45f56ee 100644 --- a/functions/modules/rocketeer.js +++ b/functions/modules/rocketeer.js @@ -3,7 +3,7 @@ const { db } = require( './firebase' ) const { getTotalSupply } = require( './contract' ) // /////////////////////////////// -// Data sources +// Attribute sources // /////////////////////////////// const globalAttributes = [ { trait_type: "Age", display_type: "number", values: [