Skip to content

Instantly share code, notes, and snippets.

View Siimone's full-sized avatar
🎯
Focusing

Simone Da Re Siimone

🎯
Focusing
View GitHub Profile
@Siimone
Siimone / modifierExample.sol
Last active October 13, 2017 10:26
Solidity example by Solidity documentation
modifier onlyBy(address _account)
{
require(msg.sender == _account);
_;
}
function changeOwner(address _newOwner)
onlyBy(owner)
{
owner = _newOwner;
// Un unico costruttore, niente overloading ricorda!
function AtomicSwap() {}
event Refunded(uint _refundTime);
event Redeemed(uint _redeemTime);
event Participated(
address _initiator,
address _participator,
bytes20 _hashedSecret,
uint256 _value
);
@Siimone
Siimone / AtomicSwapModifiers.sol
Created October 18, 2017 12:37
AtomicSwap Modifiers from AltcoinExchange
modifier isRefundable(bytes20 _hashedSecret) {
require(block.timestamp < swaps[_hashedSecret].initTimestamp + swaps[_hashedSecret].refundTime);
require(swaps[_hashedSecret].emptied == false);
_;
}
modifier isRedeemable(bytes20 _hashedSecret, bytes32 _secret) {
require(ripemd160(_secret) == _hashedSecret);
require(swaps[_hashedSecret].emptied == false);
_;
@Siimone
Siimone / AtomicSwapFunctions.sol
Created October 18, 2017 19:58
Functions from AtomicSwap by AltcoinExchange
function initiate (uint _refundTime,bytes20 _hashedSecret,address _participant)
payable
isNotInitiated(_hashedSecret)
{
swaps[_hashedSecret].refundTime = _refundTime;
swaps[_hashedSecret].initTimestamp = block.timestamp;
swaps[_hashedSecret].hashedSecret = _hashedSecret;
swaps[_hashedSecret].participant = _participant;
swaps[_hashedSecret].initiator = msg.sender;
swaps[_hashedSecret].state = State.Initiator;
@Siimone
Siimone / AtomicSwapHead.sol
Created October 18, 2017 23:19
First part of Atomic Swap by AltcoinExchange
contract AtomicSwap {
enum State { Empty, Initiator, Participant }
struct Swap {
uint initTimestamp;
uint refundTime;
bytes20 hashedSecret;
bytes32 secret;
address initiator;
contract Coiners {
enum EmozioniPersona { felice, triste, normale }
EmozioniPersona persona;
function getEmozione() public view returns (uint) {
return uint(persona);
}
function setFelice() returns(uint){
persona = EmozioniPersona.felice;
@Siimone
Siimone / ContractDeployment.js
Created March 29, 2018 12:18
Solidity Smart Contract deployment
var Web3 = require("web3")
let web3 = new Web3()
web3.setProvider(new Web3.providers.HttpProvider('http://localhost:8545'))
var helloContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"hello","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"pure","type":"function"}]);
var hello = helloContract.new(
{
from: web3.eth.accounts[0],
data: '0x6060604052341561000f57600080fd5b6101578061001e6000396000f300606060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806319ff1d2114610046575b600080fd5b341561005157600080fd5b6100596100d4565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561009957808201518184015260208101905061007e565b50505050905090810190601f1680156100c65780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6100dc610117565b6040805190810160405280600c81526020017f48656c6c6f20576f726c64210000000000000000000000000000000000000000815250905090565b602
@Siimone
Siimone / HelloWorld.sol
Created March 29, 2018 12:23
Decentralized Hello World
pragma solidity ^0.4.17;
contract Hello {
function hello() public pure returns(string) {
return "Hello World!";
}
}
@Siimone
Siimone / PromiEvents.sol
Created March 29, 2018 13:35
Example of PromiEvents
web3.eth.sendTransaction({
from: '0x123...',
data: '0x432...'
})
.once('transactionHash', function(hash){
console.log('Hash: ' + hash)
})
.once('receipt', function(receipt){
console.log('Receipt: ' + receipt)
})