Skip to content

Commit

Permalink
Revert "Remove unnecesary files"
Browse files Browse the repository at this point in the history
This reverts commit c080c95.
  • Loading branch information
biscuitdey authored and ognjenkurtic committed Jun 30, 2024
1 parent c3d3633 commit 2827151
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Contract } from 'ethers';
export interface IBlockchainService {
deployContract(contractName: string): Promise<void>;
connectToContract(contractName: string): Promise<Contract>;
storeAnchorHash(contractName: string, anchorHash: string): Promise<void>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

contract Ccsm {
mapping(string => bool) public anchorHashStore;

function setAnchorHash(string calldata _anchorHash) external {
anchorHashStore[_anchorHash] = true;
}

function getAnchorHash(
string calldata _anchorHash
) external view returns (bool) {
return anchorHashStore[_anchorHash];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { EthereumService } from './ethereum.service';

describe('Ethereum services', () => {
let ccsm: EthereumService;

//REMOVE THIS
it('empty test', async () => {
expect('empty').toBe('empty');
});

//NOTE: Commenting out the test as it requires compiled artifacts to run. RUN THIS.
// beforeAll(async () => {
// ccsm = new EthereumService();
// await ccsm.deployContract('Ccsm');
// });

// describe('storeAnchorHash', () => {
// it('should set anchor hash in the mapping and return true', async () => {
// //Arrange
// const anchorHash = 'anchorHash';

// //Act
// await ccsm.storeAnchorHash('Ccsm', anchorHash);
// const ccsmContract = await ccsm.connectToContract('Ccsm');

// //Assert
// expect(await ccsmContract.anchorHashStore('anchorHash')).toEqual(true);
// });
// });
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { readFile, writeFile } from 'fs/promises';
import { Injectable, NotImplementedException } from '@nestjs/common';
import { IBlockchainService } from '../blockchain.interface';
import { Contract } from 'ethers';

@Injectable()
export class EthereumService implements IBlockchainService {
public async deployContract(contractName: string): Promise<void> {
throw new NotImplementedException();
// TODO: We need to use ethers js here for connection, not hardhat ethers
// const ccsmContract = await ethers.getContractFactory(contractName);
// const deployedCcsmContract = await ccsmContract.deploy();
// await this.storeDeployedContractAddress(deployedCcsmContract.address);
}

async connectToContract(contractName: string): Promise<Contract> {
throw new NotImplementedException();
// TODO: We need to use ethers js here for connection, not hardhat ethers
// const ccsmContractAddress = await this.getDeployedContractAddress();
// return await ethers.getContractAt(contractName, ccsmContractAddress);
}

public async storeAnchorHash(
contractName: string,
anchorHash: string,
): Promise<void> {
const ccsmContract = await this.connectToContract(contractName);
await ccsmContract.setAnchorHash(anchorHash);
}

private async getDeployedContractAddress(): Promise<string> {
return JSON.parse(
(
await readFile(
'./zeroKnowledgeArtifacts/blockchain/ethereum/artifacts/ccsmContractAddress.json',
)
).toString(),
).contractAddress;
}

private async storeDeployedContractAddress(contractAddress: string) {
const ccsmAddress = JSON.stringify({
contractAddress: contractAddress,
});

await writeFile(
'./zeroKnowledgeArtifacts/blockchain/ethereum/artifacts/ccsmContractAddress.json',
ccsmAddress,
);
}
}

0 comments on commit 2827151

Please sign in to comment.