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
modifier onlyBy(address _account) | |
{ | |
require(msg.sender == _account); | |
_; | |
} | |
function changeOwner(address _newOwner) | |
onlyBy(owner) | |
{ | |
owner = _newOwner; |
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
// Un unico costruttore, niente overloading ricorda! | |
function AtomicSwap() {} |
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
event Refunded(uint _refundTime); | |
event Redeemed(uint _redeemTime); | |
event Participated( | |
address _initiator, | |
address _participator, | |
bytes20 _hashedSecret, | |
uint256 _value | |
); |
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
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); | |
_; |
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
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; |
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
contract AtomicSwap { | |
enum State { Empty, Initiator, Participant } | |
struct Swap { | |
uint initTimestamp; | |
uint refundTime; | |
bytes20 hashedSecret; | |
bytes32 secret; | |
address initiator; |
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
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; |
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
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 |
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.4.17; | |
contract Hello { | |
function hello() public pure returns(string) { | |
return "Hello World!"; | |
} | |
} |
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
web3.eth.sendTransaction({ | |
from: '0x123...', | |
data: '0x432...' | |
}) | |
.once('transactionHash', function(hash){ | |
console.log('Hash: ' + hash) | |
}) | |
.once('receipt', function(receipt){ | |
console.log('Receipt: ' + receipt) | |
}) |
OlderNewer