You are here

Ethereum - Anyone?

3 posts / 0 new
Last post
Baaleos
Ethereum - Anyone?

Has anyone looked into Ethereum for programming / scripting.
I have started and im interested in the concept of using it for decentralized data storage and its ability to easilly run private blockchains.

As a database engine - it would be decentralized, secure (transactions that modify the blockchain are logged in the public ledger) and highly flexible with the creation of smart contracts.


This is a theoretical ethereum smart contract that could be used to facilitate a decentralized database on a blockchain.
It would allow the owner to mark databases as private or public and it would protect the data from change from outside sources.

 

pragma solidity ^0.4.11;
 
contract dataStorage {
    /* Constructor */
    mapping (string => Gameworlds) Gameworlds;
    
 
struct StoredData{
string type;
string val;
}
 
struct Database {
mapping (string => StoredData) data;
bool isPrivate;
    }
 
    struct Gameworld {
address owner;
        mapping (string => Database) databases;
    }
 
function setDatabasePrivate(string gameWorldName, string databaseName) returns (bool b){
//msg.sender is the person sending the ethereum contract call
if(msg.sender != Gameworlds[gameWorldName].owner){
return false;
}
 
 
}
    
    function storePersistentData(string gameWorldName, string databaseName, string varname, string varValue, string varType) returns (bool b){
      example[index] = data;
 //Does a gameworld exist by that name
 
 //Does the caller have ownership over the gameworld
 
 //Does the gameworld have a db by that name
 
 //Add or update the StoredData associated with that key
 
 
      return true;
    }
    
    function readPersistentData(string gameWorldName, string databaseName, string varname, string varValue,) returns (string retVal) {
if(Gameworlds[gameWorldName].databases[databaseName].isPrivate && (msg.sender != Gameworlds[gameWorldName].owner))
{
//This db is marked as private - only the owner can read from it
return;
}
        return Gameworlds[gameWorldName].databases[databaseName].data[varname].val;
    }
}





Pros of block chain datastorage:
Security through concensus: More people who host the block chain, makes it harder for any one person to maliciously change the data.
Security through contract: Direct modification of the hosted data can only be done through the contracts public functions.
Decentralized : Data is stored in multiple places and resistant to data corruption or loss.
Async : Calls to contract functions that modify the blockchain data are fire and forget, no need to block execution of calling application (remember how nwn would freeze for half a second if you stored data in a database?)


Cons:
Writing to the block chain is not immediate - it can take a minute or two for any reads from the blockchain to pick up the changes.
Data only gets stored once a block is mined - people need to mine to keep the databases working (Reading from the block chain requires no mining)
It Costs Ether: In order to store data, it costs a certain amount of ethereum to read and write to the blockchain.


On the 'ether cost' - because the proposal is to make a private blockchain instance, when generating a genesis block - it is possible to mint as many coins as you want on the outset and assign them to one or more people. (Its basically like cheating - giving you some free money)
Even without the cheating aspect of it - everytime you mine a block, you get +5 ether.
Storage costs of simple strings on the block chain cost amounts like 0.03 ether.
And to put things in context - on a new blockchain - you are likely to get blocks every 5-10 seconds for the first few hours, and then every 10 minutes or so afterwards.
After mining on my own private blockchain solo using a CPU, I ended up with 8000 ether after maybe 5-6 hours.


Risks : After the block chain has been running for a long time - it might be impractical for smaller users of the system to gain ether.
The community could always award free ether to people, in order to keep the system alive.
Eg: 
One ethereum account is credited with 1000000000000000000000000 ether
And  once per day, users of the system all receive +1 from that fund.

Still has an element of finality - but it also encourages people to mine for new ethereum - in order to retain the ability to store data.


 

 

  • up
    50%
  • down
    50%
niv

This sounds like a hammer in search of a nail, but the hammer is made out of rubber.

  • up
    50%
  • down
    50%
Baaleos

Its not to necessarilly say that it has to be used for nwn.
Its no secret that I am interested in cryptocurrencies and block chain technologies.

It offers the capabilitiy of creating entirely decentralized systems.


Got my smart contract finished - which would in theory allow anyone to create a database and store data.
Also there is currently a bug in solidity / ethereum which prevents the use of strings within structs.
So having to use bytes32




 

pragma solidity ^0.4.11;
 
contract dataStorage {
    /* Constructor */
    mapping (string => Gameworld) Gameworlds;
    
 
struct StoredData{
bytes32 dataType;
bytes32 val;
uint updateTime;
}
 
struct Database {
mapping (string => StoredData) data;
bool isPrivate;
uint createdTime;
    }
 
    struct Gameworld {
address owner;
        mapping (string => Database) databases;
    }
 
function setDatabasePrivate(string gameWorldName, string databaseName, bool b) returns (bool b2){
//msg.sender is the person sending the ethereum contract call
if(msg.sender != Gameworlds[gameWorldName].owner){
return false;
}
if(Gameworlds[gameWorldName].databases[databaseName].createdTime <= 0){
return false;
}
Gameworlds[gameWorldName].databases[databaseName].isPrivate = b;
return true;
}
    
    function storePersistentData(string gameWorldName, string databaseName, string varname, bytes32 varValue, bytes32 varType) returns (bool b){
      
 //Does a gameworld exist by that name
 //If not - create it first
 if(Gameworlds[gameWorldName].owner <= 0x0){
    Gameworld memory gw;
    gw.owner = msg.sender;
    Gameworlds[gameWorldName] = gw;
 }
 //Does the caller have ownership over the gameworld
 if(Gameworlds[gameWorldName].owner != msg.sender){
     return;
 }
 
 
 //Does the gameworld have a db by that name
 if(Gameworlds[gameWorldName].databases[databaseName].createdTime == 0){
     //Create the db
     Database memory db;
     db.isPrivate = false;
     db.createdTime = block.timestamp;
     Gameworlds[gameWorldName].databases[databaseName] = db;
 }
 
 
 
 //Add or update the StoredData associated with that key
 if(Gameworlds[gameWorldName].databases[databaseName].data[varname].updateTime == 0){
     //Create the variable
     StoredData memory data;
     Gameworlds[gameWorldName].databases[databaseName].data[varname] = data;
 }
 Gameworlds[gameWorldName].databases[databaseName].data[varname].updateTime = block.timestamp;
 Gameworlds[gameWorldName].databases[databaseName].data[varname].dataType = varType;
 Gameworlds[gameWorldName].databases[databaseName].data[varname].val = varValue;
      return true;
    }
    
    function readPersistentData(string gameWorldName, string databaseName, string varName) returns (bytes32 retVal) {
if(Gameworlds[gameWorldName].databases[databaseName].isPrivate && (msg.sender != Gameworlds[gameWorldName].owner))
{
//This db is marked as private - only the owner can read from it
return;
}
        return Gameworlds[gameWorldName].databases[databaseName].data[varName].val;
    }
}
  • up
    50%
  • down
    50%