pragma solidity ^0.4.10; contract DebianRules { /* Consideraciones: -Cada software tiene un encargado del que se requiere saber su apellido e email -Cada software cuenta ademas con su nombre, descripcion, año de creacion y unidad academica donde se desarrolla. -Para identificar cada software se utiliza una address, esto puede representar un inconveniente para el testing, pero hace mas real la simulación ya que si se considera llevar un blockchain de software probablemente existan contratos de produccion de los mismos y se podria utilizar esa address. -Para el funcionamiento del smart contract se utilizo un struct que genera la representacion de cada software. Para almacenar se utiliza un mapeo de direcciones a structs de software y un array que almacena las direcciones de cada software para poder llevar los punteros y las cantidades actualizadas (principalmente para eliminar entradas de forma lógica). */ struct systemStruct { bytes16 unidadAcademica; bytes16 nombreSistema; bytes16 apellidoEncargado; bytes16 emailEncargado; bytes32 descripcion; uint anoCreacion; uint index; } mapping(address => systemStruct) private systemStructs; address[] private systemIndex; event LogNewSystem (address indexed systemAddress, uint index, bytes16 unidadAcademica, bytes16 nombreSistema, bytes16 apellidoEncargado, bytes16 emailEncargado, bytes32 descripcion, uint anoCreacion); event LogUpdateSystem(address indexed systemAddress, uint index, bytes16 unidadAcademica, bytes16 nombreSistema, bytes16 apellidoEncargado, bytes16 emailEncargado, bytes32 descripcion, uint anoCreacion); event LogDeleteSystem(address indexed systemAddress, uint index); function isLoad(address systemAddress) external constant returns(bool isIndeed) { if(systemIndex.length == 0) return false; return (systemIndex[systemStructs[systemAddress].index] == systemAddress); } //unidadA: Unidad Academica, nombreS: nombre Software, apellidoE: Apellido del encargado, // emailE: Email del encargado, descrip: Descripcion del software (por ejemplo, licencia). // anoC: Año de creacion del software y client: wallet del encargado del contract function insertSystem ( address systemAddress, bytes16 unidadA, bytes16 nombreS, bytes16 apellidoE, bytes16 emailE, bytes32 descrip, uint anoC, address client) public payable returns(uint index) { // Exigimos un pago de al menos 50 Wei require(msg.value > 50); // Verificamos que no exista la direccion en el arreglo if(this.isLoad(systemAddress)) throw; // Generamos el alta systemStructs[systemAddress].emailEncargado = emailE; systemStructs[systemAddress].anoCreacion = anoC; systemStructs[systemAddress].unidadAcademica = unidadA; systemStructs[systemAddress].nombreSistema = nombreS; systemStructs[systemAddress].apellidoEncargado = apellidoE; systemStructs[systemAddress].descripcion = descrip; systemStructs[systemAddress].index = systemIndex.push(systemAddress) - 1; // Con el evento de nuevo sistema, cargamos el log LogNewSystem( systemAddress, systemStructs[systemAddress].index, unidadA, nombreS, apellidoE, emailE, descrip, anoC); // La billetera destino debe tener valor if (client != address(0)) { // Generamos una transaccion segura de transferencia client.transfer(msg.value); } return systemIndex.length-1; } function deleteSystem(address systemAddress,address client) public payable returns(uint index) { // Exigimos un pago de al menos 25 Wei require(msg.value > 25); if(!this.isLoad(systemAddress)) throw; uint rowToDelete = systemStructs[systemAddress].index; address keyToMove = systemIndex[systemIndex.length-1]; systemIndex[rowToDelete] = keyToMove; systemStructs[keyToMove].index = rowToDelete; systemIndex.length--; LogDeleteSystem( systemAddress, rowToDelete); LogUpdateSystem( keyToMove, rowToDelete, systemStructs[keyToMove].unidadAcademica, systemStructs[keyToMove].nombreSistema, systemStructs[keyToMove].apellidoEncargado, systemStructs[keyToMove].emailEncargado, systemStructs[keyToMove].descripcion, systemStructs[keyToMove].anoCreacion ); // La billetera destino debe tener valor if (client != address(0)) { // Generamos una transaccion segura de transferencia client.transfer(msg.value); } return rowToDelete; } function getSystem(address systemAddress) public constant returns(bytes16 userEmail, uint userAge, uint index) { if(!this.isLoad(systemAddress)) throw; return( systemStructs[systemAddress].emailEncargado, systemStructs[systemAddress].anoCreacion, systemStructs[systemAddress].index); } function updateSystemEmail(address systemAddress, bytes16 userEmail, address client) public payable returns(bool success) { // Exigimos un pago de al menos 20 Wei para pagar el Gas require(msg.value > 20); if(!this.isLoad(systemAddress)) throw; systemStructs[systemAddress].emailEncargado = userEmail; LogUpdateSystem( systemAddress, systemStructs[systemAddress].index, systemStructs[systemAddress].unidadAcademica, systemStructs[systemAddress].nombreSistema, systemStructs[systemAddress].apellidoEncargado, userEmail, systemStructs[systemAddress].descripcion, systemStructs[systemAddress].anoCreacion); // La billetera destino debe tener valor if (client != address(0)) { // Generamos una transaccion segura de transferencia client.transfer(msg.value); } return true; } function updateSystemEncargado(address systemAddress, bytes16 userApellido, address client) public payable returns(bool success) { // Exigimos un pago de al menos 20 Wei require(msg.value > 20); if(!this.isLoad(systemAddress)) throw; systemStructs[systemAddress].apellidoEncargado = userApellido; LogUpdateSystem( systemAddress, systemStructs[systemAddress].index, systemStructs[systemAddress].unidadAcademica, systemStructs[systemAddress].nombreSistema, userApellido, systemStructs[systemAddress].emailEncargado, systemStructs[systemAddress].descripcion, systemStructs[systemAddress].anoCreacion); // La billetera destino debe tener valor if (client != address(0)) { // Generamos una transaccion segura de transferencia client.transfer(msg.value); } return true; } function updateSystemDescripcion(address systemAddress, bytes32 descrip, address client) public payable returns(bool success) { // Exigimos un pago de al menos 20 Wei require(msg.value > 20); if(!this.isLoad(systemAddress)) throw; systemStructs[systemAddress].descripcion = descrip; LogUpdateSystem( systemAddress, systemStructs[systemAddress].index, systemStructs[systemAddress].unidadAcademica, systemStructs[systemAddress].nombreSistema, systemStructs[systemAddress].apellidoEncargado, systemStructs[systemAddress].emailEncargado, descrip, systemStructs[systemAddress].anoCreacion); // La billetera destino debe tener valor if (client != address(0)) { // Generamos una transaccion segura de transferencia client.transfer(msg.value); } return true; } function getSystemCount() public constant returns(uint count) { return systemIndex.length; } function getSystemAtIndex(uint index) public constant returns(address systemAddress) { return systemIndex[index]; } }
0.4.10