Skip to content

Commit

Permalink
adding allowances
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 13, 2024
1 parent 75b6f96 commit 105120f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func handleLog(vLog *types.Log, w *wallet.Wallet, q *uploader.Queue, jackalContr
}

cost := q.GetCost(fileSize*maxProofs, hours)
cost = int64(float64(cost) * 1.1)
cost = int64(float64(cost) * 1.2)
c := sdk.NewInt64Coin("ujkl", cost)

msg := &wasm.MsgExecuteContract{
Expand Down
26 changes: 24 additions & 2 deletions forge/src/Jackal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ abstract contract Jackal {

function getPrice() public view virtual returns(int);

mapping(address => mapping(address => bool)) public allowances;

function getAllowance(address from, address to) public view returns(bool) {
if (from == to) {
return true;
}
return allowances[to][from];
}

function addAllowance(address allow) public {
allowances[msg.sender][allow] = true;
}

function removeAllowance(address allow) public {
allowances[msg.sender][allow] = false;
}

function getStoragePrice(uint64 filesize) public view returns (uint256) {
uint256 price = uint256(getPrice());

Expand All @@ -32,13 +49,18 @@ abstract contract Jackal {
return p;
}

function postFile(string memory merkle, uint64 filesize) public payable{
function postFileFrom(address from, string memory merkle, uint64 filesize) public payable{
require(msg.sender != address(0), "Invalid sender address");
require(getAllowance(msg.sender, from), "No allowance for this contract set");

uint256 pE = getStoragePrice(filesize);

require(msg.value >= pE, string.concat("Incorrect payment amount, need ", Strings.toString(pE), " wei"));

emit PostedFile(msg.sender, merkle, filesize);
emit PostedFile(from, merkle, filesize);
}

function postFile(string memory merkle, uint64 filesize) public payable{
postFileFrom(msg.sender, merkle, filesize);
}
}
1 change: 1 addition & 0 deletions forge/src/JackalInterface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ pragma solidity ^0.8.26;

interface JackalInterface {
function postFile(string memory merkle, uint64 filesize) external payable;
function postFileFrom(address from, string memory merkle, uint64 filesize) external payable;
}
2 changes: 1 addition & 1 deletion forge/src/StorageDrawer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract StorageDrawer {
}

function upload(string memory merkle, uint64 filesize) public payable {
jackalBridge.postFile{value: msg.value}(merkle, filesize);
jackalBridge.postFileFrom{value: msg.value}(msg.sender, merkle, filesize);
cabinet[msg.sender].push(merkle);
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rm -rf ~/.foundry/anvil
sleep 5

# Run the forge create command
forge create JackalBridge --root forge --rpc-url https://ethereum-sepolia-rpc.publicnode.com --private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
forge create JackalBridge --root forge --rpc-url https://ethereum-sepolia-rpc.publicnode.com --private-key "2547c566531d275b86985d18dc90812009d396b6004436a35b689dccc2e86a83"

# send myself some tokens >:)
#cast send 0x9443A8C2aa7788EEE05f9734Ad4174a6C5CA0A25 --value 10ether --private-key "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
Expand Down

0 comments on commit 105120f

Please sign in to comment.