Skip to content

Instantly share code, notes, and snippets.

@wjmelements
Last active March 10, 2018 08:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wjmelements/fab8c6961cff3dbd8715c7c55d29d660 to your computer and use it in GitHub Desktop.
Save wjmelements/fab8c6961cff3dbd8715c7c55d29d660 to your computer and use it in GitHub Desktop.
Sponsored gas plugin
pragma solidity^0.4.19;
// like a less-liquid GasToken
contract Sponsored {
uint256[] wastedSpace;
function sponsor() external {
uint256 len = wastedSpace.length;
wastedSpace.length = len + 5;
wastedSpace[len] = 1;
wastedSpace[len+1] = 1;
wastedSpace[len+2] = 1;
wastedSpace[len+3] = 1;
wastedSpace[len+4] = 1;
}
modifier sponsored {
_;
uint256 len = wastedSpace.length;
if (len != 0) {
wastedSpace[--len] = 0;
wastedSpace[--len] = 0;
wastedSpace[--len] = 0;
wastedSpace[--len] = 0;
wastedSpace[--len] = 0;
wastedSpace.length = len;
}
}
}
@wjmelements
Copy link
Author

How to use:

contract Dapp is Sponsored {
    function action(/* */) external sponsored {
        /* */
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment