Skip to content

Instantly share code, notes, and snippets.

View spalladino's full-sized avatar
🔷

Santiago Palladino spalladino

🔷
View GitHub Profile
@spalladino
spalladino / test-deployment.js
Created September 18, 2018 22:24
Tests contract deployment via web3 using manually signed transactions
const Tx = require('ethereumjs-tx');
const Web3 = require('web3')
const web3 = new Web3(new Web3.providers.HttpProvider(url));
function getCodeFromTxHash(hash, source) {
web3.eth.getTransactionReceipt(hash, function (err, receipt) {
if (err) {
console.error(source, "ERROR on getting tx receipt from hash", err);
}
@spalladino
spalladino / zos-initializers.md
Last active July 25, 2018 19:02
Summary of experiments on initializer contracts

Proxy contract initialization

This gist contains a summary of the experiments around initialization of proxy contracts, comparing the current approach with new ones we have been working on. We used a sample ERC20 and an ERC721 contracts for testing. Most of these tests can be found in the labs repo. Credit for most approaches listed here goes to @frangio.

Initializer functions

Initializer functions is the current approach used for zOS. All contracts must be modified to have an initializer function, which is invoked right after creating the proxy. It must also be decorated with an isInitializer modifier to ensure it can be called only once.

Note that this modification, while is currently done manually, could be automated by using a tool.

[
{
"inputs": [
{
"name": "_implementation",
"type": "address"
}
],
"payable": false,
"stateMutability": "nonpayable",
@spalladino
spalladino / count-repos.py
Last active February 21, 2020 06:40
Estimate number of repositories that match a code search
from http.client import HTTPSConnection
from base64 import b64encode
from json import loads
from sys import exit, argv, stderr
from time import sleep
import urllib3
# Settings
PRINT_REPOS = True
@spalladino
spalladino / hash.py
Created October 21, 2017 23:50
Solution for Coursera Cryptography 1 course Week 3 programming assignment
from hashlib import sha256
from sys import argv
with open(argv[1], "rb") as f:
blocks = []
block = f.read(1024)
while block:
blocks.append(block)
block = f.read(1024)
@spalladino
spalladino / web3.js
Created October 16, 2017 16:00
Detect whether a web3 connection is available
// Adapted from https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#partly_sunny-web3---ethereum-browser-environment-check
window.addEventListener('load', function() {
// Checking if Web3 has been injected by the browser (Mist/MetaMask)
if (typeof web3 !== 'undefined') {
// Use Mist/MetaMask's provider
window.web3 = new Web3(web3.currentProvider);
} else {
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
window.web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
@spalladino
spalladino / monitor.js
Created October 15, 2017 23:15
Configure ngrok with nodemon for local development
#!/usr/bin/env node
if (process.env.NODE_ENV === 'production') {
throw new Error("Do not use nodemon in production, run bin/www.js directly instead");
}
const nodemon = require('nodemon');
const ngrok = require('ngrok');
// We start an ngrok tunnel to ensure it stays the same for the entire process
@spalladino
spalladino / rinkeby.txt
Created September 8, 2017 14:56
Rinkeby test address
0x9D49a5aBBD1AD73aA7D0547e3Ec5B14ce640718E
@spalladino
spalladino / main.cr
Last active November 29, 2016 23:31
Alternative code for "Crystal in real life" post
# Adapted from http://pfertyk.me/2016/11/crystal-in-real-life/
require "stumpy_png"
canvas = StumpyPNG.read("image.png")
canvas.width.times do |x|
canvas.height.times do |y|
color = canvas[x, y]
@spalladino
spalladino / Makefile
Created November 23, 2016 15:40
Proof of concept of Ruby extension written in Crystal
testruby.bundle: testruby.cr
crystal testruby.cr --link-flags "-dynamic -bundle -Wl,-undefined,dynamic_lookup" -o testruby.bundle
irb: testruby.bundle
irb -rtestruby -I.
clean:
rm -rf .crystal testruby.bundle