Skip to content
Snippets Groups Projects
Commit 56c523af authored by Patricio Kumagae's avatar Patricio Kumagae
Browse files

Subida inicial

parents
No related branches found
No related tags found
No related merge requests found
pragma solidity ^0.4.11;
/// @dev Models a address -> uint mapping where it is possible to iterate over all keys.
library IterableMapping{
struct itmap{
mapping(address => IndexValue) data;
KeyFlag[] keys;
uint size;
}
struct IndexValue { uint keyIndex; uint value; }
struct KeyFlag { address key; bool deleted; }
function insert(itmap storage self, address key, uint value) public returns (bool replaced){
uint keyIndex = self.data[key].keyIndex;
self.data[key].value = value;
if (keyIndex > 0){
return true;
}else{
keyIndex = self.keys.length++;
self.data[key].keyIndex = keyIndex + 1;
self.keys[keyIndex].key = key;
self.size++;
return false;
}
}
function size(itmap storage self) public view returns(uint){
return self.size;
}
function remove(itmap storage self, address key) public returns (bool success){
uint keyIndex = self.data[key].keyIndex;
if (keyIndex == 0)
return false;
delete self.data[key];
self.keys[keyIndex - 1].deleted = true;
self.size --;
}
function modify(itmap storage self, address key, uint value) public returns (bool success){
uint keyIndex = self.data[key].keyIndex;
if (keyIndex == 0)
return false;
self.data[key].value = value;
return true;
}
function get(itmap storage self, address key) public view returns(uint){
return self.data[key].value;
}
function contains(itmap storage self, address key) public view returns (bool){
return self.data[key].keyIndex > 0;
}
function iterate_start(itmap storage self) public view returns (uint keyIndex){
return iterate_next(self, uint(-1));
}
function iterate_valid(itmap storage self, uint keyIndex) public view returns (bool){
return keyIndex < self.keys.length;
}
function iterate_next(itmap storage self, uint keyIndex) public view returns (uint r_keyIndex){
keyIndex++;
while (keyIndex < self.keys.length && self.keys[keyIndex].deleted)
keyIndex++;
return keyIndex;
}
function iterate_get(itmap storage self, uint keyIndex) public view returns (address key, uint value){
key = self.keys[keyIndex].key;
value = self.data[key].value;
}
}
pragma solidity ^0.4.24;
contract ProofOfExistence {
struct Dato {
uint blockNumber;
uint256 hash;
}
mapping (uint256 => Dato) private hashstore;
function stamp(uint256 ots, uint256 file_hash) public {
hashstore[ots] = Dato({blockNumber: block.number, hash: file_hash});
}
function verify(uint256 ots, uint256 file_hash) public view returns(bool){
Dato memory dato = hashstore[ots];
return dato.hash == file_hash;
}
function getHash(uint256 ots) public view returns(uint256){
Dato memory dato = hashstore[ots];
return dato.hash;
}
function getBlockNumber(uint256 ots) public view returns(uint){
Dato memory dato = hashstore[ots];
return dato.blockNumber;
}
}
\ No newline at end of file
Contracts de verify y stamp
pragma solidity ^0.4.11;
import "iterableMapping.sol";
contract PeronEther {
// Just a struct holding our data.
IterableMapping.itmap data;
// Insert something
function addReceiver(address k) public payable returns (uint size){
// Actually calls itmap_impl.insert, auto-supplying the first parameter for us.
IterableMapping.insert(data, k, 0);
// We can still access members of the struct - but we should take care not to mess with them.
return data.size;
}
/*
msg.sender and msg.value are implicitly available, contain information
about the adress of a caller and amount of ether they sent with the call (in wei)
*/
function deposit() public payable returns(bool success) {
uint eth = msg.value / IterableMapping.size(data);
uint i = IterableMapping.iterate_start(data);
for (; IterableMapping.iterate_valid(data, i); i = IterableMapping.iterate_next(data, i)){
var (cuenta, balance) = IterableMapping.iterate_get(data, i);
balance += eth;
IterableMapping.modify(data,cuenta,balance);
}
return true;
}
function getBalance(address cuenta) public view returns(uint) {
return IterableMapping.get(data,cuenta);
}
function distribute() public{
uint i = IterableMapping.iterate_start(data);
for (; IterableMapping.iterate_valid(data, i); i = IterableMapping.iterate_next(data, i)){
var (cuenta, balance) = IterableMapping.iterate_get(data, i);
cuenta.transfer(balance);
IterableMapping.modify(data,cuenta,0);
}
}
}
import web3
from web3 import Web3
from web3.middleware import geth_poa_middleware
w3 = Web3(Web3.HTTPProvider('http://10.23.10.71:8501'))
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
result = w3.miner.start(1)
if w3.eth.mining:
print ("Minero arrancado")
else:
print ("Minero no arrancado")
import web3
from web3 import Web3
from web3.middleware import geth_poa_middleware
w3 = Web3(Web3.HTTPProvider('http://10.23.10.71:8501'))
w3.middleware_stack.inject(geth_poa_middleware, layer=0)
result = w3.miner.stop()
if result:
print ("Minero detenido")
else:
print ("Minero no detenido")
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment