This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.5.3 <=0.6.4; | |
// Crowd contract allows users | |
// to participate in a crowd funding in a limited time frame. | |
// Owner of the contract can decide: | |
// 1. Stop time of this round of crowd funding (using block.number). | |
// 2. If allow a user to deposit multiple times. | |
// 3. To which address withdraw the funds collected. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity >=0.5.3 <=0.6.4; | |
contract Extension { | |
function blake2b256(bytes memory data) public view returns(bytes32); | |
function blockID(uint num) public view returns(bytes32); | |
function blockTotalScore(uint num) public view returns(uint64); | |
function blockTime(uint num) public view returns(uint); | |
function blockSigner(uint num) public view returns(address); | |
function totalSupply() public view returns(uint256); | |
function txProvedWork() public view returns(uint256); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 3 Script | |
# Count the "real" code lines (exclude empty lines, and comments) in a project. | |
# Languages supported: Python, JavaScript, C, C++, Java, C#, etc.... | |
# Analyse: | |
# A source code file contains code, and comments. | |
# Single line comments are easy. Just // or # | |
# Multi-line comments are begin usually with /*, and ends with */, this is | |
# accomplished with a stack, maybe. /* // */ counts as a single block of comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python3 | |
# In 100 numbers, | |
# Exactly has (n) numbers, that are <= value | |
# The possibility. | |
def f(n, value): | |
a = 1 - value/100 | |
b = value/100 | |
# Numbers that are > 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
foo = random.SystemRandom() | |
threshold = 8 | |
at_least = 5 | |
bingo = 0 | |
experiment_times = 100000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Attempt to commit a transaction to a contract. | |
* | |
* With a hefty wallet as "sponsor" + an empty wallet as "sender". | |
* | |
*/ | |
const fetch = require("node-fetch"); | |
const cry = require('thor-devkit/dist/cry') | |
const Transaction = require('thor-devkit/dist/transaction').Transaction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fetch the sponsor signature. | |
const sponsorSignature = await getSponosrSignature( | |
'0x'+originAddress.toString('hex'), | |
txBody | |
) | |
// Compose a combined signature of user + sponsor. | |
const sig = Buffer.concat([ | |
originSignature, | |
Buffer.from(sponsorSignature, 'hex') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express') | |
const cry = require('thor-devkit/dist/cry') | |
const Transaction = require('thor-devkit/dist/transaction').Transaction | |
const app = express() | |
app.use(express.json()) | |
const port = 3000 | |
app.post('/', function(req, res) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// HTTP function definition | |
async function getSponosrSignature(sender, txBody) { | |
const url = 'http://localhost:3000/' | |
const response = await fetch(url, { | |
method: 'POST', | |
headers: { | |
'Accept': 'application/json', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import library | |
const cry = require('thor-devkit/dist/cry') | |
const Transaction = require('thor-devkit/dist/transaction').Transaction | |
// User private key. | |
const originPriv = Buffer.from( | |
'2a0cbfe49ea7c18e89b87be4237e1717823fc16b52dc02e91fb30af122fba9b3', | |
'hex' | |
) | |
// User public address: 0x881Ab2380017870C49a9A114806C05F3CFE406e2 |