Skip to content

Instantly share code, notes, and snippets.

View daragao's full-sized avatar

Duarte Aragão daragao

View GitHub Profile
@daragao
daragao / readDatadirLeveDB.js
Last active June 7, 2017 22:30
playing around to check how to read a levelDB
const level = require('level');
const levelup = require('levelup');
const RLP = require('rlp');
const Trie = require('merkle-patricia-tree')
const DATADIR_PATH = '../../simple_geth_launcher/data_node1';
/*
const nodeDb = level('/home/da/.ethereum/geth/nodes');
const nodeDataArr = [];
@daragao
daragao / test.js
Last active October 11, 2018 22:39
Chat that we had today :)
const printMatrix = (matrix) => matrix.forEach((line,j) => console.log('('+j+')',line));
// USES ALGORITHM THAT I DESCRIBED WHICH WAS WRONG!!!!
const countIslandsMyAlgorithm = (matrix) => {
const checkCounterMatrix = (counterMatrix,i,j) => {
if((i-1 >= 0) && (counterMatrix[i-1][j] !== 0)) return counterMatrix[i-1][j];
if((j-1 >= 0) && (counterMatrix[i][j-1] !== 0)) return counterMatrix[i][j-1];
// this 2 cases are never considered in any of the matrices, this causes issues
if((i+1 < matrix.length) && (matrix[i+1][j] !== 0)) return counterMatrix[i+1][j] = 0;
#!/bin/bash
UP_SYMBOL=▲
DOWN_SYMBOL=▼
# BTC_SYMBOL="<fc=#FFFF00>฿</fc>"
BTC_SYMBOL="<fc=#FF9900><fn=1></fn></fc>"
#ETH_SYMBOL="<fc=#7777FF>Ξ</fc>"
ETH_SYMBOL="<fc=#7777FF><fn=1></fn></fc>"
@daragao
daragao / txRootExample.go
Last active July 3, 2018 15:55
Example of how a transaction root is created using the Ethereum Golang libraries
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethdb"
@daragao
daragao / nested_nodes_trie_example.go
Last active April 20, 2020 16:12
Example of a Patricia Trie with some value smaller than 32bytes wich results in nodes being nested inside each other
package main
import (
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb/memorydb"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
@daragao
daragao / flow_test.go
Last active October 11, 2018 22:38
Simple flow test without using the abigen generated file (only using common transactions and the simulated blockchain)
package ionflow
import (
"bytes"
"context"
"math/big"
"regexp"
"strings"
"testing"
@daragao
daragao / printStateAccounts.js
Last active October 11, 2018 22:37
Simple example on how to get accounts from state trie
const level = require('level')
const rlp = require('rlp')
const chaindatadirectory = './data_node_0/geth/chaindata'
const TX_ROOT_HASH = '146d436eb3af4eeaf1f421d86a8994ef9f6e3670393837e9141f7f44b00e01cf'
const STATE_ROOT_HASH = '0c773fdbbe314cbeb0908d1b4949b39d1edca0653efee339882679538fce3318'
level(chaindatadirectory, { keyEncoding: 'utf8', valueEncoding: 'binary'}, async (err, db) => {
if(err) {
console.log('ERROR: ',err)
@daragao
daragao / run_geth.sh
Created October 25, 2018 17:29
Bash script to start geth
#!/bin/bash
#-x
NODE_NUMBER=$1
REMAINING_ARGS=${@:2}
re_number=^-?[0-9]+$
if ! [[ $NODE_NUMBER =~ $re_number ]]; then
echo "First argument needs to be a number!"
exit 1
@daragao
daragao / goldmine.py
Created November 8, 2018 18:35
Gold mine proble hackerrank
def mining(k, mines):
n = len(mines)
#create matrix
matrix = []
for i in range(n):
row = []
distance_i = mines[i][0]
weight_i = mines[i][1]
for j in range(n):
distance_j = mines[j][0]
@daragao
daragao / generateEthereumKey.sh
Created August 9, 2019 11:02
script to generate Ethereum private key, public key, and address
#!/bin/bash
#Libs used for keccak-256sum
#https://github.com/maandree/libkeccak.git
#https://github.com/maandree/argparser.git
#https://github.com/maandree/sha3sum.git
# Generate the private and public keys
KEY="$(openssl ecparam -name secp256k1 -genkey -noout | openssl ec -text -noout 2> /dev/null)"
echo "$KEY"