Skip to content

Commit

Permalink
initial draft of EVM gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
svub committed Oct 5, 2024
1 parent 4fef2e7 commit ffed8a2
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions packages/hardhat/contracts/payWithEth.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// TODO in production
import "hardhat/console.sol";
// import "@openzeppelin/contracts/";
// import "@openzeppelin/contracts/access/Ownable.sol";

interface SecretContract {
function makeRef(string calldata encrypteSecret) external returns (string memory);
function pay(string calldata ref, uint256 amout) external returns (uint256);
function withdraw(string calldata encrypteSecret, address withdrawalAddress) external returns (uint256);
}

/**
* @author
*/
contract PayWithEth {

SecretContract secretContact;

function makeRef(string calldata encryptedSecret) public returns (string memory){
string memory ref = secretContact.makeRef(encryptedSecret);
return ref;
}

function pay(string calldata ref) public payable returns (uint256) {
// TODO replace with proper type for proofs
uint256 paymentProof = secretContact.pay(ref, msg.value);
require(paymentProof > 0, "Payment reference not found");
return paymentProof;
}
// useful?
// function payEncrypted(string EncryptedRef) payable {
// secretContact.pay()
// }

receive() external payable {}

function withdraw(string calldata encryptedSecret, address payable withdrawalAddress) public {
uint256 amount = secretContact.withdraw(encryptedSecret, withdrawalAddress);
require(amount > 0, "Account not found or empty.");
withdrawalAddress.transfer(amount);
}
}

0 comments on commit ffed8a2

Please sign in to comment.