Skip to content

Instantly share code, notes, and snippets.

@dodikk
dodikk / watchTokenTransfers.js
Created October 2, 2018 14:42 — forked from dsemenovsky/watchTokenTransfers.js
Token transfers watcher
function watchTokenTransfers() {
// Instantiate web3 with WebSocketProvider
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws'))
// Instantiate token contract object with JSON ABI and address
const tokenContract = new web3.eth.Contract(
TOKEN_ABI, process.env.TOKEN_CONTRACT_ADDRESS,
(error, result) => { if (error) console.log(error) }
)
@dodikk
dodikk / getConfirmations.js
Created October 2, 2018 14:41 — forked from dsemenovsky/getConfirmations.js
Get Ethereum transaction confirmations count
async function getConfirmations(txHash) {
try {
// Instantiate web3 with HttpProvider
const web3 = new Web3('https://rinkeby.infura.io/')
// Get transaction details
const trx = await web3.eth.getTransaction(txHash)
// Get current block number
const currentBlock = await web3.eth.getBlockNumber()
@dodikk
dodikk / watchEtherTransfers.js
Created October 2, 2018 14:37 — forked from dsemenovsky/watchEtherTransfers.js
Ether transfers watcher
function watchEtherTransfers() {
// Instantiate web3 with WebSocket provider
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://rinkeby.infura.io/ws'))
// Instantiate subscription object
const subscription = web3.eth.subscribe('pendingTransactions')
// Subscribe to pending transactions
subscription.subscribe((error, result) => {
if (error) console.log(error)
@dodikk
dodikk / 0 README.md
Created September 27, 2018 13:46 — forked from chriseth/0 README.md
Formal verification for re-entrant Solidity contracts

This gist shows how formal conditions of Solidity smart contracts can be automatically verified even in the presence of potential re-entrant calls from other contracts.

Solidity already supports formal verification of some contracts that do not make calls to other contracts. This of course excludes any contract that transfers Ether or tokens.

The Solidity contract below models a crude crowdfunding contract that can hold Ether and some person can withdraw Ether according to their shares. It is missing the actual access control, but the point that wants to be made

/**
* Base contract that all upgradeable contracts should use.
*
* Contracts implementing this interface are all called using delegatecall from
* a dispatcher. As a result, the _sizes and _dest variables are shared with the
* dispatcher contract, which allows the called contract to update these at will.
*
* _sizes is a map of function signatures to return value sizes. Due to EVM
* limitations, these need to be populated by the target contract, so the
* dispatcher knows how many bytes of data to return from called functions.
@dodikk
dodikk / cli-logs.txt
Last active September 26, 2018 09:31
adk@adk-VirtualBox:~/Applications$ ./jre1.8.0_181/bin/java -jar cakeshop-0.10.0-x86_64-linux.war
Defaulting to spring profile: local
Extracting geth to /home/adk/Applications/data/geth
[INFO ] 2018-09-26 12:25:09.795 [main] SpringBootApplication - Starting SpringBootApplication v0.10.0 on adk-VirtualBox with PID 11187 (/home/adk/Applications/cakeshop-0.10.0-x86_64-linux.war started by adk in /home/adk/Applications)
[INFO ] 2018-09-26 12:25:09.804 [main] SpringBootApplication - The following profiles are active: container,spring-boot,local
[INFO ] 2018-09-26 12:25:13.995 [main] AppConfig - eth.config.dir=/home/adk/Applications/data/local
[WARN ] 2018-09-26 12:25:13.996 [main] AppConfig - Authentication disabled.
[INFO ] 2018-09-26 12:25:14.022 [main] AppConfig - Loading config from /home/adk/Applications/data/local/application.properties
@dodikk
dodikk / gist:6e4b5fdc141025d609756f8aa5a20d63
Created September 20, 2018 10:35 — forked from jdmaresco/gist:3d7bfbc922a44e641f33
Custom Ethereum Genesis File
{
"nonce": "0x0000000000000042",
"difficulty": "0x40000",
"alloc": {
"YOUR_COINBASE_ADDRESS": {
"balance": "10015200000000000000000"
}
},
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",
@dodikk
dodikk / FixVideoLinksToHttps.js
Created July 31, 2018 12:33
Javascript injection in WKWebView
var videoTags = document.getElementsByTagName('video');
var result = [];
result.push('====\n')
for (var i = 0; i < videoTags.length; i++)
{
// result.push("====singleVideoTag \n");
var singleVideoTag = videoTags[i];
@dodikk
dodikk / shared.rs
Created June 25, 2018 14:51 — forked from stevedonovan/shared.rs
An ergonomic way of saying Rc<RefCell>
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
#[derive(Clone)]
struct Shared<T> {
v: Rc<RefCell<T>>
}
@dodikk
dodikk / EmailValidationRegex.swift
Created March 6, 2018 15:06
Email validation regex from bootstrap
private static func validateEmailByBootstrapRegex(_ userInput: String) -> Bool
{
var emailRegex = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}"
let emailTest = NSPredicate(format:"SELF MATCHES %@", emailRegex)
return emailTest.evaluate(with: userInput)
}
// TODO: is NSPredicate any better