Skip to content

Instantly share code, notes, and snippets.

@ethers
ethers / itmap.sol
Last active May 19, 2022 02:29 — forked from Arachnid/itmap.sol
Solidity iterable map
library itmap {
struct entry {
// Equal to the index of the key of this item in keys, plus 1.
uint keyIndex;
uint value;
}
struct itmap {
mapping(uint => entry) data;
uint[] keys;
@ethers
ethers / call-then-sendtx-pattern.js
Last active July 24, 2020 05:51
call-then-sendtx pattern for Ethereum Dapps
/*
In Ethereum, a contract can be written so that it returns a value for eth_call.
A Dapp can then check for success or error value of eth_call, before calling eth_sendTransaction,
to take advantage of eth_call effectively being a "preview" of the code flow that the transaction
will take. In traditional client-server, clients can't ask servers beforehand what's going to
happen when the client makes a call; with Dapps contracts can be written so that clients can ask
for a "preview" of what is going to happen, before any funds/ethers are actually utilized
(eth_call does not cost any ethers).
Note: it is possible that in between eth_call and when eth_sendTransaction is actually mined,
pyepm -a 29d33c02a200937995e632c4597b4dca8e503978 testBulkDeploy.yaml
PyEPM 0.9.6
=====
Deploying testBulkDeploy.yaml...
Loading testBulkDeploy.yaml...
Parsing testBulkDeploy.yaml...
deploy:
Deploying btcBulkStoreHeaders.py...
Contract will be available at 0xb8e116ddf8b8d451e04c5733a96a853b9036e883
Waiting for transaction... took 3s
@ethers
ethers / gist:7fd8363880a675edeb2c
Created March 19, 2015 22:07
pyepm deploy to Alethzero
pyepm -a 29d33c02a200937995e632c4597b4dca8e503978 testBulkDeploy.yaml
PyEPM 0.9.5-2-g13e13e7-dirty
=====
Deploying testBulkDeploy.yaml...
Loading testBulkDeploy.yaml...
Parsing testBulkDeploy.yaml...
deploy:
Deploying btcBulkStoreHeaders.py...
Contract will be available at 0xcf2d91e4a42568344d6222f08003db3104f3cddd
Waiting for transaction.. took 2s
@ethers
ethers / gist:4e348c99347008e207d9
Last active August 29, 2015 14:17
pyepm deploy to C++ cli
pyepm -a f52a423ecad0b6c70b5adf69edbe51b9db11c7c9 testBulkDeploy.yaml
PyEPM 0.9.6
=====
Deploying testBulkDeploy.yaml...
Loading testBulkDeploy.yaml...
Parsing testBulkDeploy.yaml...
deploy:
Deploying btcBulkStoreHeaders.py...
Contract will be available at 0x6da764a088e1d16610f38b305eb4f320f1cb227c
Waiting for transaction.
@ethers
ethers / gist:16cd74b0a1e90d112b59
Last active August 29, 2015 14:17
pyepm deploy to Go cli
pyepm -a 9409fe90e19bc99a9316e9f80bb3ede98cffac75 testBulkDeploy.yaml
PyEPM 0.9.6-2-ga67094c
=====
Deploying testBulkDeploy.yaml...
Loading testBulkDeploy.yaml...
Parsing testBulkDeploy.yaml...
deploy:
Deploying btcBulkStoreHeaders.py...
Contract will be available at 0xdc6b46483528c59c7354f3f84e27e79f41ad1e55
Waiting for transaction............................................. took 45s
@ethers
ethers / gist:4f2cab393d13b8000c55
Last active August 29, 2015 14:16
move untracked files outside a git repository
# Found from https://snipt.net/akaihola/move-untracked-files-outside-a-git-repository/
git ls-files --others --exclude-standard -z | cpio -pmd0 ../untracked/
# git clean -d -f
# git ls-files: print a
# * null-delimited (-z) list of
# * untracked (--others)
# * non-ignored (--exclude-standard) files.
# cpio:
@ethers
ethers / gist:8d771d0eb727439e59bb
Created December 11, 2014 04:17
python flipBytes
byte = range(32)
def flipBytes(n):
numByte = 32
mask = 0xff
i = 0
while i < numByte:
b = n & mask
b /= 2 ** (i*8)
b *= 2 ** ((numByte-i-1)*8)
@ethers
ethers / gist:5a225b566393c1823524
Created December 11, 2014 04:15
flipBytes Serpent
data byte[32]
def flipBytes(n):
numByte = 5
mask = 0xff
i = 0
while i < numByte:
b = n & mask
b /= 2^(i*8)
b *= 2^((numByte-i-1)*8)
@ethers
ethers / gist:10f27a44c3ab5e2997a0
Created November 12, 2014 20:19
SSTORE logic
storageTrie.get(key, function(err, found) {
if (found || (!found && val.toString('hex') === '00')) {
gasLeft = gasLeft.add(100);
} else if (!found && val.toString('hex') !== '00') {
gasLeft = gasLeft.sub(100);
} else if (found && val.toString('hex') === '00') {
gasLeft = gasLeft.add(200);
}
if (val.toString('hex') === '00') {