From 33a03132f7781034ae8f8177f10cb62f54fe0db9 Mon Sep 17 00:00:00 2001 From: shawticus Date: Sun, 9 May 2021 14:10:03 -0700 Subject: [PATCH] Add dockerfile and remove unnecessary files --- Dockerfile | 17 + account-manager.js | 91 - api.js | 103 - aws.js | 65 - bip32.js | 17908 ------------------------------- bip39.js | 24445 ------------------------------------------ blockchain.js | 275 - browser-manager.js | 18 - encoder.js | 52 - ethereumjs-util.js | 18764 -------------------------------- events-manager.js | 78 - flow-constants.js | 15 - flow.js | 308 - index.js | 46 - namegen.js | 37 - package-lock.json | 1 - package.json | 8 +- routes/accounts.js | 84 - routes/analytics.js | 90 - routes/preview.js | 202 - routes/sign.js | 250 - routes/storage.js | 107 - routes/worlds.js | 311 - utils.js | 25 - 24 files changed, 21 insertions(+), 63279 deletions(-) create mode 100644 Dockerfile delete mode 100644 account-manager.js delete mode 100644 api.js delete mode 100644 aws.js delete mode 100644 bip32.js delete mode 100644 bip39.js delete mode 100644 blockchain.js delete mode 100644 browser-manager.js delete mode 100644 encoder.js delete mode 100644 ethereumjs-util.js delete mode 100644 events-manager.js delete mode 100644 flow-constants.js delete mode 100644 flow.js delete mode 100644 namegen.js delete mode 100644 routes/accounts.js delete mode 100644 routes/analytics.js delete mode 100644 routes/preview.js delete mode 100644 routes/sign.js delete mode 100644 routes/storage.js delete mode 100644 routes/worlds.js delete mode 100644 utils.js diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..954c46f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM node:14 +WORKDIR /usr/src/app +RUN wget https://dist.ipfs.io/go-ipfs/v0.8.0/go-ipfs_v0.8.0_linux-amd64.tar.gz +RUN tar -xvzf go-ipfs_v0.8.0_linux-amd64.tar.gz +WORKDIR /usr/src/app/go-ipfs +RUN bash install.sh +RUN ipfs init +WORKDIR /usr/src/app +COPY package*.json ./ + +RUN npm install +# IPFS host is exposed on 8080 +EXPOSE 8080 +EXPOSE 80 +EXPOSE 443 +COPY . . +CMD [ "node", "index.js" ] diff --git a/account-manager.js b/account-manager.js deleted file mode 100644 index 3f11575..0000000 --- a/account-manager.js +++ /dev/null @@ -1,91 +0,0 @@ -const AWS = require('aws-sdk'); -const blockchain = require('./blockchain.js'); -const config = require('./config.json'); -const {accessKeyId, secretAccessKey, /*githubUsername, githubApiKey,*/ githubPagesDomain, githubClientId, githubClientSecret, stripeClientId, stripeClientSecret} = config; -const awsConfig = new AWS.Config({ - credentials: new AWS.Credentials({ - accessKeyId, - secretAccessKey, - }), - region: 'us-west-1', -}); -const ddb = new AWS.DynamoDB(awsConfig); -const tableName = 'users'; -const keyName = 'test-users.cache'; - -const _makePromise = () => { - let accept, reject; - const p = new Promise((a, r) => { - accept = a; - reject = r; - }); - p.accept = accept; - p.reject = reject; - return p; -}; - -const MAX_CACHED_USERS = 5; -class AccountManager { - constructor() { - this.users = []; - this.queue = []; - - this.load(); - } - async load() { - const tokenItem = await ddb.getItem({ - TableName: tableName, - Key: { - email: {S: keyName}, - } - }).promise(); - this.users = tokenItem.Item ? JSON.parse(tokenItem.Item.users.S) : []; - // console.log('got old', this.users); - - const _save = async () => { - await ddb.putItem({ - TableName: tableName, - Item: { - email: {S: keyName}, - users: {S: JSON.stringify(this.users)}, - } - }).promise(); - }; - const _flush = async () => { - while (this.queue.length > 0 && this.users.length > 0) { - this.queue.shift()(this.users.shift()); - } - await _save(); - }; - await _flush(); - - const _recurse = async () => { - while (this.users.length < MAX_CACHED_USERS) { - const mnemonic = blockchain.makeMnemonic(); - const userKeys = await blockchain.genKeys(mnemonic); - const address = await blockchain.createAccount(userKeys, { - bake: true, - }); - userKeys.mnemonic = mnemonic; - userKeys.address = address; - - this.users.push(userKeys); - await _flush(); - } - setTimeout(_recurse, 1000); - }; - setTimeout(_recurse, 1000); - } - async getAccount() { - if (this.users.length > 0) { - return this.users.shift(); - } else { - const p = _makePromise(); - this.queue.push(p.accept); - return await p; - } - } -} -const accountManager = new AccountManager(); - -module.exports = accountManager; \ No newline at end of file diff --git a/api.js b/api.js deleted file mode 100644 index 8c64beb..0000000 --- a/api.js +++ /dev/null @@ -1,103 +0,0 @@ -const Web3 = require('web3'); -const bip32 = require('./bip32.js'); -const bip39 = require('./bip39.js'); - -const {infuraApiKey, network, mnemonic} = require('./config.json'); -const webaverseAbi = require('./webaverse-abi.json'); -const webaverseAddress = require('./webaverse-address.json'); - -const _makeContracts = web3 => { - return { - webaverse: new web3.eth.Contract(webaverseAbi, webaverseAddress), - }; -}; -async function _execute(spec) { - const _waitTransaction = txId => new Promise((accept, reject) => { - const _recurse = () => { - this.eth.getTransactionReceipt(txId, (err, result) => { - if (!err) { - if (result !== null) { - accept(result); - } else { - _recurse(); - } - } else { - reject(err); - } - }); - }; - _recurse(); - }); - - const {method, data, wait} = spec; - switch (method) { - case 'mintToken': { - const {tokenId, addr, name} = data; - - const nonce = (await this.eth.getTransactionCount(this.eth.defaultAccount)) + 1; - const gas = await this.contracts.webaverse.methods.mintToken(tokenId, addr, name).estimateGas({from: this.eth.defaultAccount, nonce}); - console.log('estimate gas', gas); - // const {transactionHash} = await this.contracts.webaverse.methods.mintToken(tokenId, addr, name).send({from: this.eth.defaultAccount, gas, nonce}); - const transactionHash = await new Promise((accept, reject) => { - const p = this.contracts.webaverse.methods.mintToken(tokenId, addr, name).send({from: this.eth.defaultAccount, gas, nonce}); - p.once('transactionHash', accept); - p.once('error', reject); - }); - console.log('got txid', transactionHash); - if (wait) { - const rx = await _waitTransaction(transactionHash); - console.log('got rx', rx); - return rx; - /* const result = await this.contracts.webaverse.methods.getTokenByName(name).call(); - console.log('got result 1', result); - const tokenId = parseInt(result[1], 10); - console.log('got result 2', tokenId); - return tokenId; */ - } else { - return null; - } - } - case 'transferTo': { - const {addr, tokenId} = data; - - const nonce = (await this.eth.getTransactionCount(this.eth.defaultAccount)) + 1; - const gas = await this.contracts.webaverse.methods.transferTo(addr, tokenId).estimateGas({from: this.eth.defaultAccount, nonce}); - console.log('estimate gas', gas); - // const {transactionHash} = await this.contracts.webaverse.methods.mintToken(tokenId, addr, name).send({from: this.eth.defaultAccount, gas, nonce}); - const transactionHash = await new Promise((accept, reject) => { - const p = this.contracts.webaverse.methods.transferTo(addr, tokenId).send({from: this.eth.defaultAccount, gas, nonce}); - p.once('transactionHash', accept); - p.once('error', reject); - }); - console.log('got txid', transactionHash); - if (wait) { - const rx = await _waitTransaction(transactionHash); - console.log('got rx', rx); - return rx; - /* const result = await this.contracts.webaverse.methods.getTokenByName(name).call(); - console.log('got result 1', result); - const tokenId = parseInt(result[1], 10); - console.log('got result 2', tokenId); - return tokenId; */ - } else { - return null; - } - } - default: throw new Error(`unknown execute method ${method}`); - } -} -const makeWeb3 = () => { - const rpcUrl = `https://${network}.infura.io/v3/${infuraApiKey}`; - - const web3 = new Web3(new Web3.providers.HttpProvider(rpcUrl)); - const seed = bip39.mnemonicToSeedSync(mnemonic, ''); - const privateKey = '0x' + bip32.fromSeed(seed).derivePath("m/44'/60'/0'/0").derive(0).privateKey.toString('hex'); - const account = web3.eth.accounts.privateKeyToAccount(privateKey); - web3.eth.accounts.wallet.add(account); - web3.eth.defaultAccount = account.address; - web3.contracts = _makeContracts(web3); - web3.execute = _execute; - return web3; -}; - -module.exports = makeWeb3(); diff --git a/aws.js b/aws.js deleted file mode 100644 index d5463c2..0000000 --- a/aws.js +++ /dev/null @@ -1,65 +0,0 @@ -const stream = require('stream'); -const AWS = require('aws-sdk'); -const {accessKeyId, secretAccessKey} = require('./config.json'); -const awsConfig = new AWS.Config({ - credentials: new AWS.Credentials({ - accessKeyId, - secretAccessKey, - }), - region: 'us-west-1', -}); -const s3 = new AWS.S3(awsConfig); - -const getObject = (bucket, key) => { - return new Promise(async (resolve, reject) => { - const params = { Bucket: bucket, Key: key }; - s3.getObject(params, (error, data) => { - if (error) { - reject(error) - } - else { - resolve(data) - } - }); - }) -} - -const putObject = (bucket, key, data, type) => { - return new Promise(async (resolve, reject) => { - const params = { Body: data, Bucket: bucket, Key: key, ACL: 'public-read' }; - if (type) { - params['ContentType'] = type; - } - s3.putObject(params, (error, data) => { - if (error) { - reject(error) - } - else { - resolve(data) - } - }); - }) -} - -function uploadFromStream(bucket, key, type) { - const pass = new stream.PassThrough(); - const params = {Bucket: bucket, Key: key, Body: pass, ACL: 'public-read'}; - if (type) { - params['ContentType'] = type; - } - s3.upload(params, function(err, data) { - console.log('emit done', !!err, !!data); - if (err) { - pass.emit('error', err); - } else { - pass.emit('done', data); - } - }); - return pass; -} - -module.exports = { - getObject, - putObject, - uploadFromStream, -} diff --git a/bip32.js b/bip32.js deleted file mode 100644 index 3fd5111..0000000 --- a/bip32.js +++ /dev/null @@ -1,17908 +0,0 @@ -// modules are defined as an array -// [ module function, map of requires ] -// -// map of requires is short require name -> numeric require -// -// anything defined in a previous bundle is accessed via the -// orig method which is the require for previous bundles -parcelRequire = (function (modules, cache, entry, globalName) { - // Save the require from previous bundle to this closure if any - var previousRequire = typeof parcelRequire === 'function' && parcelRequire; - var nodeRequire = typeof require === 'function' && require; - - function newRequire(name, jumped) { - if (!cache[name]) { - if (!modules[name]) { - // if we cannot find the module within our internal map or - // cache jump to the current global require ie. the last bundle - // that was added to the page. - var currentRequire = typeof parcelRequire === 'function' && parcelRequire; - if (!jumped && currentRequire) { - return currentRequire(name, true); - } - - // If there are other bundles on this page the require from the - // previous one is saved to 'previousRequire'. Repeat this as - // many times as there are bundles until the module is found or - // we exhaust the require chain. - if (previousRequire) { - return previousRequire(name, true); - } - - // Try the node require function if it exists. - if (nodeRequire && typeof name === 'string') { - return nodeRequire(name); - } - - var err = new Error('Cannot find module \'' + name + '\''); - err.code = 'MODULE_NOT_FOUND'; - throw err; - } - - localRequire.resolve = resolve; - localRequire.cache = {}; - - var module = cache[name] = new newRequire.Module(name); - - modules[name][0].call(module.exports, localRequire, module, module.exports, this); - } - - return cache[name].exports; - - function localRequire(x){ - return newRequire(localRequire.resolve(x)); - } - - function resolve(x){ - return modules[name][1][x] || x; - } - } - - function Module(moduleName) { - this.id = moduleName; - this.bundle = newRequire; - this.exports = {}; - } - - newRequire.isParcelRequire = true; - newRequire.Module = Module; - newRequire.modules = modules; - newRequire.cache = cache; - newRequire.parent = previousRequire; - newRequire.register = function (id, exports) { - modules[id] = [function (require, module) { - module.exports = exports; - }, {}]; - }; - - var error; - for (var i = 0; i < entry.length; i++) { - try { - newRequire(entry[i]); - } catch (e) { - // Save first error but execute all entries - if (!error) { - error = e; - } - } - } - - if (entry.length) { - // Expose entry point to Node, AMD or browser globals - // Based on https://github.com/ForbesLindesay/umd/blob/master/template.js - var mainExports = newRequire(entry[entry.length - 1]); - - // CommonJS - if (typeof exports === "object" && typeof module !== "undefined") { - module.exports = mainExports; - - // RequireJS - } else if (typeof define === "function" && define.amd) { - define(function () { - return mainExports; - }); - - //