Skip to content

Instantly share code, notes, and snippets.

View RomanFro's full-sized avatar

Roman Frolov RomanFro

View GitHub Profile
@RomanFro
RomanFro / state_switcher.js
Last active October 18, 2018 10:36
state_switcher
// Forecasting -> Forecasting finished
if (state === forecasting && forecastingEndTimestamp < block.timestamp) {
switch state -> forecasting_finished;
}
// Forecasting completed -> Crowdfunding deadline missed
if (state === forecasting_completed && forecastingEndTimestamp < (block.timestamp - secondsInDay * crowdsaleStartTimeout)) {
switch state -> crowdfunding_deadline_missed;
}
@RomanFro
RomanFro / eth_call.js
Last active October 14, 2021 13:04
eth_call
'use strict';
const WEB3_URL = process.env.WEB3_URL;
const prom = require('util').promisify;
const ethABI = require('ethereumjs-abi');
const Web3 = require('web3');
const provider = new Web3.providers.HttpProvider(WEB3_URL);
const web3 = module.exports = new Web3(provider);
const sendAsync = prom(web3.currentProvider.sendAsync).bind(web3.currentProvider);
@RomanFro
RomanFro / executeCall.sol
Created October 11, 2018 06:57
Execute function using solidity assembly.
// Execute the encoded function in the specified contract
function executeCall(address to, uint256 value, bytes data)
internal
returns (bool success)
{
assembly {
success := call(gas, to, value, add(data, 0x20), mload(data), 0, 0)
}
}
@RomanFro
RomanFro / voting.cpp
Last active August 20, 2018 11:16
Simple voting contract
#include <eosiolib/eosio.hpp>
namespace eosio {
class voting : public eosio::contract {
/// @abi table candidates i64
struct candidate {
uint64_t id;
account_name name;
auto primary_key() const { return id; }