From 202af63b3ebb1874ebd7ad13ab02bcf42fa6654d Mon Sep 17 00:00:00 2001 From: ramkri123 Date: Sun, 23 Apr 2023 10:27:23 -0700 Subject: [PATCH] Revert "Features: 1) Blockchain URL and contract re-deploy are configurable through config.json 2) Web3 wallet (Metamask etc.) is not mandatory for blockchain reads. All blockchain reads use json rpc provider with the specified blockchain url." --- .../source/artemis/scripts/deploy.js | 21 ++++++--------- .../src/app/main/digital-arts.service.ts | 18 ++++--------- .../artemis/src/app/main/ethereum.service.ts | 27 +++++-------------- .../source/artemis/src/assets/config.json | 2 +- 4 files changed, 20 insertions(+), 48 deletions(-) diff --git a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/scripts/deploy.js b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/scripts/deploy.js index 188061d34..26dbcce67 100644 --- a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/scripts/deploy.js +++ b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/scripts/deploy.js @@ -8,21 +8,16 @@ const fs = require("fs"); const hre = require("hardhat"); async function main() { - let config = await fs.readFileSync('./src/assets/config.json'); - config = JSON.parse(config); - - if (config['DEFAULT_NFT_CONTRACT_ADDRESS'] == '' || config['REDEPLOY_CONTRACT'] == 'true') { - const DigitalArt = await hre.ethers.getContractFactory("DigitalArt"); - const digitalArt = await DigitalArt.deploy(); + const DigitalArt = await hre.ethers.getContractFactory("DigitalArt"); + const digitalArt = await DigitalArt.deploy(); - await digitalArt.deployed(); - console.log(`DigitalArt Smart Contract deployed to ${digitalArt.address}`); + await digitalArt.deployed(); + console.log(`DigitalArt Smart Contract deployed to ${digitalArt.address}`); - config['DEFAULT_NFT_CONTRACT_ADDRESS'] = digitalArt.address; - await fs.writeFileSync('./src/assets/config.json', JSON.stringify(config)); - } else { - console.log("DigitalArt Smart Contract already deployed at " + config['DEFAULT_NFT_CONTRACT_ADDRESS']); - } + let config = await fs.readFileSync('./src/assets/config.json'); + config = JSON.parse(config); + config['DEFAULT_NFT_CONTRACT_ADDRESS'] = digitalArt.address; + await fs.writeFileSync('./src/assets/config.json', JSON.stringify(config)); } // We recommend this pattern to be able to use async/await everywhere diff --git a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/digital-arts.service.ts b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/digital-arts.service.ts index fa038fb55..1e6765da5 100644 --- a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/digital-arts.service.ts +++ b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/digital-arts.service.ts @@ -12,7 +12,6 @@ const baseData = { contract: null, contractAddressOverride: Config.DEFAULT_NFT_CONTRACT_ADDRESS, totalArtsSupply: null, - jsonrpcContract: null, }; @Injectable({ providedIn: 'root' }) @@ -62,12 +61,10 @@ export class DigitalArtsService { if (baseData.contract) { return baseData.contract; } baseData.contract = new ethers.Contract(this.mainContractAddress, DigitalArtAbi.abi, this.ethService.web3Provider); - baseData.jsonrpcContract = new ethers.Contract(this.mainContractAddress, DigitalArtAbi.abi, this.ethService.jsonrpcProvider); try{ - baseData.totalArtsSupply = await baseData.jsonrpcContract.totalSupply(); + baseData.totalArtsSupply = await baseData.contract.totalSupply(); console.log("Contract deployed successfully at " + baseData.contract.address); - console.log("totalArtsSupply " + baseData.totalArtsSupply); this.mainContractStatus = 'CONNECTED'; this.mainContract = new ethers.Contract(baseData.contract.address, DigitalArtAbi.abi, this.ethService.web3Provider) as DigitalArtContract; @@ -92,7 +89,7 @@ export class DigitalArtsService { } baseData.contract = new ethers.Contract(newAddress, DigitalArtAbi.abi, this.ethService.web3Provider); try { - await baseData.jsonrpcContract.totalSupply(); + await baseData.contract.totalSupply(); console.log(`NFT Contract Address Changed: ${newAddress}`); window.location.reload(); } catch (e) { @@ -113,9 +110,7 @@ export class DigitalArtsService { //sets up inits async waitForIt() { if (this.initPromise) { return this.initPromise; } - if (this.ethService.jsonrpcOnly == false) { - await this.ethService.waitForEthWindow(); - } + await this.ethService.waitForEthWindow(); await this.initializeDigitalArtsContract(); const prom = new Promise(async resolve => { if (this.ready) { return resolve(true); } @@ -154,14 +149,14 @@ export class DigitalArtsService { //getter async fetchArtByTokenId(index: string) { await this.waitForIt(); - const artObjData = await baseData.jsonrpcContract.DigitalArtArr(index) as any as DigitalArt; + const artObjData = await this.mainContract.DigitalArtArr(index) as any as DigitalArt; const artObj: DigitalArt = { title: artObjData.title, artistName: artObjData.artistName, image: artObjData.image, tokId: artObjData.tokId, }; - artObj.ownerHistory = await baseData.jsonrpcContract.getOwnerToken(index); + artObj.ownerHistory = await this.contract.getOwnerToken(index); artObj.effectiveImageUrl = artObj.image.startsWith('http://localhost') ? artObj.image.replace(/http\:\/\/localhost\.com/g, '') : artObj.image; @@ -186,7 +181,6 @@ export class DigitalArtsService { //standard mint function async mint(title: string, artist: string, imageUrl: string) { - if (this.ethService.jsonrpcOnly) { return; } await this.waitForIt(); const signer = await this.ethService.web3Provider.getSigner(this.ethService.currentAccount); const newContract = await this.contract.connect(signer); @@ -207,7 +201,6 @@ export class DigitalArtsService { //for mock art minting async testMint(title: string, artist: string, imageUrl: string){ - if (this.ethService.jsonrpcOnly) { return; } const newContract = await this.contract.connect(this.ethService.testAccount); let transaction; try { @@ -221,7 +214,6 @@ export class DigitalArtsService { //standard transfer function async transfer(tokenId: string, to: string) { - if (this.ethService.jsonrpcOnly) { return; } await this.waitForIt(); const signer = await this.ethService.web3Provider.getSigner(this.ethService.currentAccount); const newContract = await this.contract.connect(signer); diff --git a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/ethereum.service.ts b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/ethereum.service.ts index 25b92142f..b2961c676 100644 --- a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/ethereum.service.ts +++ b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/app/main/ethereum.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; import { ethers } from 'ethers'; -import Config from 'src/assets/config.json'; declare var window: any; let web3Provider: any; @@ -18,8 +17,6 @@ export class EthereumService { currentSigner: any; accounts: string[] = []; testAccount; - jsonrpcProvider: any; - jsonrpcOnly: boolean = false; constructor() { this.initialize(); @@ -46,26 +43,15 @@ export class EthereumService { } else if(window.web3) { // if deprecated window.web3 provided instead this.setWeb3Provider(new ethers.providers.Web3Provider(window.web3)); } else { - //throw new Error('Non-valid/Ethereum browser extension detected. Use MetaMask!'); - this.jsonrpcOnly = true; + throw new Error('Non-valid/Ethereum browser extension detected. Use MetaMask!'); } - this.jsonrpcProvider = new ethers.providers.JsonRpcProvider(Config.BLOCKCHAIN_URL); - this.jsonrpcProvider.getBlockNumber().then((result) => { - console.log("Current block number: " + result); - }); - // account handling - if (this.jsonrpcOnly) { - this.currentAccount = '0x5a51Ed9DD3bAC1cdf3Ae4e01593e95d81337dfDD'; - console.log("jsonrpc current account: " + this.currentAccount); - } else { - try { - await window.ethereum.request({ method: 'eth_requestAccounts' }); - await this.getAccounts(); - } catch (e) { - console.log(e); - } + try { + await window.ethereum.request({ method: 'eth_requestAccounts' }); + await this.getAccounts(); + } catch (e) { + console.log(e); } } @@ -81,7 +67,6 @@ export class EthereumService { async getAccounts() { this.accounts = await web3Provider.listAccounts(); this.currentAccount = this.accounts[0]; - console.log("web3 current account: " + this.currentAccount); // await this.getAccountBalance(this.currentAccount); this.currentSigner = await this.web3Provider.getSigner(this.currentAccount); } diff --git a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/assets/config.json b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/assets/config.json index fab3a35cb..2bf3a2c30 100644 --- a/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/assets/config.json +++ b/vmbc-ethereum/sample-dapps/nft-platform/source/artemis/src/assets/config.json @@ -1 +1 @@ -{"DEFAULT_NFT_CONTRACT_ADDRESS":"0x0B6Ab24A032D5eACA954C2f4457618bDD12e9969","REDEPLOY_CONTRACT":"false","BLOCKCHAIN_URL":"http://54.213.130.0:8545"} +{"DEFAULT_NFT_CONTRACT_ADDRESS":""} \ No newline at end of file