-
Notifications
You must be signed in to change notification settings - Fork 235
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
examples/bri-3/src/bri/zeroKnowledgeProof/services/blockchain/blockchain.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
} |
16 changes: 16 additions & 0 deletions
16
examples/bri-3/src/bri/zeroKnowledgeProof/services/blockchain/ethereum/contracts/Ccsm.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...es/bri-3/src/bri/zeroKnowledgeProof/services/blockchain/ethereum/ethereum.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// }); | ||
// }); | ||
}); |
51 changes: 51 additions & 0 deletions
51
examples/bri-3/src/bri/zeroKnowledgeProof/services/blockchain/ethereum/ethereum.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} | ||
} |