Skip to content

Instantly share code, notes, and snippets.

@lucashenning
Created March 31, 2023 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucashenning/f162871f7ef112922db82f270f1b75a5 to your computer and use it in GitHub Desktop.
Save lucashenning/f162871f7ef112922db82f270f1b75a5 to your computer and use it in GitHub Desktop.
withdraw function in socialLock.sol
function withdraw(string memory headerJson, string memory payloadJson, bytes memory signature, uint amount) public {
// validate JWT
string memory email = validateJwt(headerJson, payloadJson, signature);
bytes32 emailHash = keccak256(abi.encodePacked(email));
// balance check
// this uses the email address from the Google JWT to check if there is a balance for this email
require(balances[emailHash] > 0, "No balance for this email");
require(balances[emailHash] >= amount, "Not enough balance for this email");
// transfer
balances[emailHash] -= amount;
msg.sender.transfer(amount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment