Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfschoen committed Oct 14, 2024
1 parent 1283459 commit 57a0dba
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 225 deletions.
11 changes: 7 additions & 4 deletions packages/hardhat/contracts/DummyGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@ contract SecretContract {
function linkPaymentRef(uint256 secret, string calldata ref) external returns (uint256) {
return 5;
}
function pay(string calldata ref, uint256 amount) external returns (uint256) {
// TODO: `string calldata secret` or `uint256 secret`
function pay(string calldata secret, string calldata ref, uint256 amount, uint256 denomination) external returns (uint256) {
return 4;
}
function payWithReceipt(string calldata ref, uint256 amount, uint256 userPubkey) external returns (uint256) {
// TODO: `string calldata secret` or `uint256 secret`
function payWithReceipt(string calldata secret, string calldata ref, uint256 amount, uint256 denomination, uint256 userPubkey) external returns (uint256) {
return 3;
}
function withdraw(string calldata secret, address withdrawalAddress) external returns (uint256){
// TODO: `string calldata secret` or `uint256 secret`
function withdrawTo(string calldata secret, uint256 amount, uint256 denomination, address withdrawalAddress) external returns (uint256){
return 2;
}

function retrievePubkey() external returns (uint256){
return 1;
}

}
}
25 changes: 15 additions & 10 deletions packages/hardhat/contracts/NunyaBusiness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import "hardhat/console.sol";
interface SecretContract {
function newSecretUser(uint256 secret) external returns (uint256);
function linkPaymentRef(uint256 secret, string calldata ref) external returns (uint256);
function pay(string calldata ref, uint256 amount) external returns (uint256);
function payWithReceipt(string calldata ref, uint256 amount, uint256 userPubkey) external returns (uint256);
function withdraw(string calldata secret, address withdrawalAddress) external returns (uint256);
function pay(string calldata ref, uint256 amount, uint256 denomination) external returns (uint256);
function payWithReceipt(string calldata ref, uint256 amount, uint256 denomination, uint256 userPubkey) external returns (uint256);
function withdrawTo(string calldata secret, uint256 amount, uint256 _denomination, address withdrawalAddress) external returns (uint256);
function retrievePubkey() external returns (uint256);
}

Expand All @@ -27,6 +27,7 @@ contract NunyaBusiness {
struct Receipt {
uint256 paymentRef;
uint256 amount;
uint256 denomination;
bytes32 sig;
}

Expand Down Expand Up @@ -97,21 +98,23 @@ contract NunyaBusiness {
}

// TODO: use ref encrypted with (user pubkey+salt)
function pay(string calldata _ref, uint256 _amount) public payable returns (uint256) {
// TODO: `string calldata secret` or `uint256 secret`
function pay(string calldata _secret, string calldata _ref, uint256 _amount, uint256 _denomination) public payable returns (uint256) {
// >= because we need gas for
require (_amount >= msg.value, "Naughty!");
uint256 gasPaid = fundGateway();
uint256 requestId = secretContract.pay(_ref, msg.value-gasPaid);
uint256 requestId = secretContract.pay(_secret, _ref, msg.value-gasPaid, _denomination);
expectedResult[requestId]=FunctionCallType.PAY;
return(requestId);
}

// TODO: use ref encrypted with (user pubkey+salt)
function pay(string calldata _ref, uint256 _amount, uint256 _userPubkey) public payable returns (uint256) {
// TODO: `string calldata secret` or `uint256 secret`
function pay(string calldata _secret, string calldata _ref, uint256 _amount, uint256 _denomination, uint256 _userPubkey) public payable returns (uint256) {
// >= because we need gas for
require (_amount >= msg.value, "Naughty!");
uint256 gasPaid = fundGateway();
uint256 requestId = secretContract.payWithReceipt(_ref, msg.value-gasPaid, _userPubkey);
uint256 requestId = secretContract.payWithReceipt(_secret, _ref, msg.value-gasPaid, _denomination, _userPubkey);
expectedResult[requestId]=FunctionCallType.PAY;
return(requestId);
}
Expand Down Expand Up @@ -155,20 +158,22 @@ contract NunyaBusiness {
}

// Function wrapped in secret network payload encryption
function withdrawTo(string calldata _secret, uint256 _amount, address _withdrawalAddress) public payable returns (uint256) {
// TODO: `string calldata secret` or `uint256 secret`
function withdrawTo(string calldata _secret, uint256 _amount, uint256 _denomination, address _withdrawalAddress) public payable returns (uint256) {
require((_amount > 0), "Account not found or empty.");
fundGateway(msg.value);
uint256 requestId = secretContract.withdraw(_secret, _withdrawalAddress);
uint256 requestId = secretContract.withdrawTo(_secret, _amount, _denomination, _withdrawalAddress);
// TODO: error check
expectedResult[requestId]=FunctionCallType.WITHDRAW;
return(requestId);
}

function withdrawToCallback(uint256 _requestId, bool _success, uint256 _amount, address payable _withdrawalAddress) onlyGateway public {
function withdrawToCallback(uint256 _requestId, bool _success, uint256 _amount, uint256 _denomination, address payable _withdrawalAddress) onlyGateway public {
require (expectedResult[_requestId]==FunctionCallType.WITHDRAW);
if (!_success)
emit SecretNetworkError(_requestId, "Error withdrawing - out of funds?");
require(_amount > 0, "Account not found or empty.");
// TODO: only if the `_denomination` is "ETH"?
_withdrawalAddress.transfer(_amount);
emit RequestSuccess(_requestId);
}
Expand Down
Loading

0 comments on commit 57a0dba

Please sign in to comment.