Last active
May 31, 2018 06:33
-
-
Save objectcraftworks/7966eca75f86148f744927331ec19e10 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.24; | |
contract Sample { | |
uint[] values; | |
function justGasSpendingTx(uint gasToSpend) public { | |
uint gasLeftAtStart = gasleft(); | |
require(gasToSpend > 21000); | |
uint gasLeftToSpend = gasToSpend - 21000; | |
if(gasLeftToSpend > 20000){ | |
uint length = uint(gasLeftToSpend)/uint(20000); | |
values.length = length; | |
for (uint index=0;index< values.length;index++) | |
{ | |
values[index] = index; //Gas 20000 to set a value; BIG TICKET ITEM | |
} | |
} | |
int remaining = int(gasLeftToSpend - (gasLeftAtStart - gasleft())); | |
if(remaining < 700) { | |
return; | |
} | |
uint codeSizeBlockRunCount = (uint(remaining)/uint(700)); | |
for(index=0; index < codeSizeBlockRunCount ;index ++){ | |
// Gas for extcodesize is 700. BIG TICKET ITEM | |
uint32 size; | |
address thisAddress =this ; | |
assembly { | |
size := extcodesize(thisAddress) | |
} | |
} | |
// and other big ticket items LogX, Call, Contract creation etc can be used | |
} | |
function getGasLimitAndGasLeft() public view returns (uint, uint) { | |
return (block.gaslimit, gasleft()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment