Skip to content

Instantly share code, notes, and snippets.

View devonwesley's full-sized avatar
Probably at coffee shop in Oakland, CA.

Devon Wesley devonwesley

Probably at coffee shop in Oakland, CA.
  • Oakland, CA
View GitHub Profile
pragma solidity ^0.4.8;
contract Victim {
bool locked;
/**
@dev Modifier to insure that functions cannot be reentered
during execution. Note there is only one global "locked" var, so
there is a potential to be locked out of all functions that use
the modifier at the same time.
function withdrawShares() insureShareholder {
uint shareCount = shares[msg.sender].shareCount;
shares[msg.sender].shareCount = 0;
if (msg.sender.send(shareCount)){
SharesWithdrawn(msg.sender, shareCount);
} else {
shares[msg.sender].shareCount = shareCount;
FailedSend(msg.sender, shareCount);
}
@devonwesley
devonwesley / HelloWorld.sol
Last active November 20, 2017 23:08
Simple hello world contract for a blog being written.
pragma solidity ^0.4.18;
contract HelloWorld {
function displayMessage() constant returns (string) {
return "Whale hello there!";
}
}
@devonwesley
devonwesley / compile.html
Last active November 14, 2017 19:27
Code snippet for Web3JS blog
<div class="mui-container-fluid">
<div class="mui-row">
<div class="mui-col-md-6">
<div class="mui-panel">
<p style="font-size:25px; font-weight:bold">
Compile Contract
</p>
<textarea id="source" onclick="this.select()" style="height:360px; width: 600px; display:block; margin-left:20px"></textarea>
<button class="mui-btn mui-btn--primary">
Compile
@devonwesley
devonwesley / compiler_select.html
Last active December 22, 2017 01:17
A way to select solidity compiler versions in a ui.
<section class="mui-container-fluid">
<div class="mui-row">
<div class="mui-col-md-6">
<div class="mui-select">
<select id="versions"></select>
</div>
</div>
</div>
</section>
@devonwesley
devonwesley / status.html
Created November 8, 2017 19:55
A status bar that helps us keep track of were we're at, in the compiling process.
<div class="mui-container" style="float: left;">
<p id="status" style="float: right; margin-top:20px"></p>
</div>
@devonwesley
devonwesley / DisplayCompilerVersions.js
Last active November 19, 2017 21:51
Code snippet for Solcjs and Web3JS blog
let compiler
window.onload = function () {
document.getElementById('versions').onchange = loadSolcVersion
if (!BrowserSolc) {
console.log('You have to load browser-solc.js in the page. We recommend using a <script> tag.')
throw new Error()
}
@devonwesley
devonwesley / ContractInput.html
Last active November 21, 2017 08:02
Code snipper for blog
<div class="mui-row">
<div class="mui-col-md-6">
<div class="mui-panel">
<p style="font-size:25px; font-weight:bold">
Compile Contract
</p>
<textarea id="source" onclick="this.select()" style="height: 360px; width: 530px; display: block; margin-left: 20px;"></textarea>
<button id="contract-compile" class="mui-btn mui-btn--primary">
Compile
</button>
@devonwesley
devonwesley / ContractCompile.js
Last active November 21, 2017 07:58
Code snippet for Medium blog.
function addCompileEvent() {
const compileBtn = document.getElementById('contract-compile')
compileBtn.addEventListener('click', solcCompile)
}
function solcCompile() {
if (!compiler) return alert('Please select a compiler version.')
setCompileButtonState(true)
status("Compiling contract...")
@devonwesley
devonwesley / RenderContract.js
Last active November 21, 2017 07:34
Code that is being used for a blog
function renderContractList() {
const contractListContainer = document.getElementById('contract-list')
const { contracts } = compiledContract
Object.keys(contracts).forEach((contract, index) => {
const label = `contract-id-${index}`
const gas = contracts[contract].gasEstimates.creation
createContractInfo(gas, contract, label, function(el){
contractListContainer.appendChild(el)