Skip to content

Instantly share code, notes, and snippets.

@laalaguer
laalaguer / Crowd.sol
Last active January 12, 2022 10:29
Crowd contract allows users to participate in a crowd funding in a limited time frame.
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.
@laalaguer
laalaguer / VeChainRandom.sol
Last active February 26, 2022 11:35
Random Number Generation on VeChain
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);
@laalaguer
laalaguer / count.py
Last active July 15, 2020 06:36
count the code, comments, empty lines in the project
# 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.
@laalaguer
laalaguer / possibility.py
Last active March 31, 2020 04:11
# In 100 numbers, # Have x numbers, that are <= y, # The possibly.
# 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
@laalaguer
laalaguer / block_random.py
Created March 30, 2020 10:33
The random possibilites
import random
foo = random.SystemRandom()
threshold = 8
at_least = 5
bingo = 0
experiment_times = 100000
@laalaguer
laalaguer / user.js
Created January 13, 2020 07:22
User's side Snippet
/**
* 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
@laalaguer
laalaguer / signature.js
Created January 13, 2020 07:10
Compound signature from user and sponsor
// 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')
@laalaguer
laalaguer / sponsor.js
Last active January 13, 2020 08:48
sponsor using Express framework
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) {
@laalaguer
laalaguer / getSponsorSignature.js
Last active January 13, 2020 06:28
get sponsor signature function
// 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({
@laalaguer
laalaguer / UserSignature.js
Created January 13, 2020 06:15
How to generate a user signature
// 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