Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Created using soleditor: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://chriseth.github.io/browser-solidity/?gist=
import "SuperdaoActions";
contract SuperdaoActionDb is SuperdaoActionManagerEnabled {
// This is where we keep all the actions.
mapping (bytes32 => address) public Superdaoactions;
//ensure call is from action manager
modifier verifyAm(){
if(!isActionManager()){
throw;
}
}
modifier checkNull(bytes32 name){
if(Superdaoactions[name] == 0x0){
throw;
}
}
// To make sure we have an add action action, we need to auto generate
// it as soon as we got the DOUG address.
function setDougAddress(address dAddr) returns (bool result) {
super.setSuperdaoDougAddress(dAddr);
var addaction = new ActionAddAction();
// If this fails, then something is wrong with the add action contract.
// Will be events logging these things in later parts.
if(!SuperdaoDougEnabled(addaction).setSuperdaoDougAddress(dAddr)){
return false;
}
Superdaoactions["addaction"] = address(addaction);
}
function addAction(bytes32 name, address addr)verifyAm() returns (bool){
bool sdda = SuperdaoDougEnabled(addr).setSuperdaoDougAddress(sDOUG);
if(!sdda)return false;
Superdaoactions[name] = addr;
return true;
}
function removeAction(bytes32 name)verifyAm()checkNull(name) returns (bool){
Superdaoactions[name] = 0x0;
return true;
}
}
import "SuperdaoActionDb";
import "SuperdaoLogs";
contract SuperdaoActionManager is SuperdaoDougEnabled {
address activeAction;
address actn;
address actionDb = 0x0;
modifier check_actionDb(bytes32 actionName){
actionDb = SuperdaoContractProvider(sDOUG).contracts("sdaoactiondb");
if(actionDb == 0x0){
SuperdaoLogs(sDOUG).save_log(actionName,false);
throw;
}else if(actn == 0x0){
SuperdaoLogs(sDOUG).save_log(actionName,false);
throw;
}
}
modifier checkAction(bytes32 actionName){
actn = SuperdaoActionDb(actionDb).Superdaoactions(actionName);
if(actn ==0x0){
SuperdaoLogs(sDOUG).save_log(actionName,false);
throw;
}
}
//Consensus permission to be added later
function execute(bytes32 actionName, bytes data)check_actionDb(actionName) checkAction(actionName) returns (bool){
activeAction = actn;
actn.call(data);
activeAction = 0x0;
SuperdaoLogs(sDOUG).save_log(actionName,true);
return true;
}
function validate(address addr) constant returns (bool){
return addr == activeAction;
}
}
import "SuperdaoDougEnabled";
import "SuperdaoContractProvider";
contract SuperdaoActionManagerEnabled is SuperdaoDougEnabled {
// Makes it easier to check that action manager is the caller.
function isActionManager() internal constant returns (bool) {
if(sDOUG != 0x0){
address am = SuperdaoContractProvider(sDOUG).contracts("actions");
if (msg.sender == am){
return true;
}
}
return false;
}
}
import "SuperdaoActionManagerEnabled";
import "SuperdaoActionDb";
contract Action is SuperdaoActionManagerEnabled{
/*// Note auto accessor.
uint8 public permission;
function setPermission(uint8 permVal) returns (bool) {
if(!validate()){
return false;
}
permission = permVal;
}
*/
}
// Add action. NOTE: Overwrites currently added actions with the same name.
contract ActionAddAction is Action {
function execute(bytes32 name, address addr) returns (bool) {
if(!isActionManager()){
return false;
}
SuperdaoContractProvider dg = SuperdaoContractProvider(sDOUG);
address adb = dg.contracts("actiondb");
if(adb == 0x0){
return false;
}
return SuperdaoActionDb(adb).addAction(name, addr);
}
}
// Remove action. Does not allow 'addaction' to be removed, though that it can still
// be done by overwriting this action with one that allows it.
contract ActionRemoveAction is Action {
function execute(bytes32 name) returns (bool) {
if(!isActionManager()){
return false;
}
SuperdaoContractProvider dg = SuperdaoContractProvider(sDOUG);
address adb = dg.contracts("sdaoactiondb");
if(adb == 0x0){
return false;
}
if(name == "addaction"){
return false;
}
return SuperdaoActionDb(adb).removeAction(name);
}
}
/* Lock actions. Makes it impossible to run actions for everyone but the owner.
// It is good to unlock the actions manager while replacing parts of the system
// for example.
contract ActionLockActions is Action {
function execute() returns (bool) {
if(!isActionManager()){
return false;
}
SuperContractProvider dg = SuperdaoContractProvider(DOUG);
address am = dg.contracts("actions");
if(am == 0x0){
return false;
}
return SuperdaoActionManager(am).lock();
}
}
// Unlock actions. Makes it possible for everyone to run actions.
contract ActionUnlockActions is Action {
function execute() returns (bool) {
if(!isActionManager()){
return false;
}
SuperdaoContractProvider dg = SuperdaoContractProvider(DOUG);
address am = dg.contracts("actions");
if(am == 0x0){
return false;
}
return SuperdaoActionManager(am).unlock();
}
}*/
/* Add contract.
contract ActionAddContract is Action {
function execute(bytes32 name, address addr) returns (bool) {
if(!isActionManager()){
return false;
}
SuperdaoDoug d = SuperdaoDoug(sDOUG);
return d.addContract(name,addr);
}
}
// Remove contract.
contract ActionRemoveContract is Action {
function execute(bytes32 name) returns (bool) {
if(!isActionManager()){
return false;
}
SuperdaoDoug d = SuperdaoDoug(sDOUG);
return d.removeContract(name);
}
}*/
import "github.com/adibas03/ethereum-grove/contracts/Grove.sol";
library GroveAPI {
struct Index {
bytes32 id;
bytes32 name;
bytes root;
mapping(bytes32 => Node) nodes;
}
struct Node {
bytes32 nodeId;
bytes32 indexId;
bytes32 id;
int value;
bytes32 parent;
bytes32 left;
bytes32 right;
uint height;
}
function insert(Index storage index, bytes32 id, int value) public;
function remove(Index storage name, bytes32 id) public;
}
import "SuperdaoActionManager";
contract SuperdaoContractDb is SuperdaoDougEnabled{
address addr;
mapping(bytes32 => address) contracts;
//Integration with Grove to be follow
//Grove sGrove;
// GroveAPI.Index contract_s;
modifier onlyDoug(){
if(msg.sender != sDOUG){
throw;
}
}
function addContract(bytes32 name,address addr) onlyDoug() returns (bool){
if(contracts[name] == 0x0 && contracts['sdaoactiondb'] != 0x0){
contracts[name] = addr;
return true;
}
else return false;
}
function removeContract(bytes32 name) onlyDoug returns (bool){
if(contracts[name] == 0x0){
return false;
}
contracts[name] = 0x0;
return true;
}
function getContract(bytes32 name) constant returns (address addr){
if(contracts[name] == 0x0){
throw;
}
return contracts[name];
}
}
contract SuperdaoContractProvider {
function contracts(bytes32 name) returns (address){
}
}
import "SuperdaoContractDb";
contract SuperdaoDoug{
address contractOwner;
address activecontract;
modifier onlyCreator(){
if(msg.sender != contractOwner ){
throw;
}
}
function SuperdaoDoug(){
contractOwner = msg.sender;
}
function addContract(bytes32 name, address addr)onlyCreator() returns (bool result){
SuperdaoDougEnabled sde = SuperdaoDougEnabled(addr);
if(!sde.setSuperdaoDougAddress(address(this))){
return false;
}else{
SuperdaoContractDb(this).addContract(name, addr);
return true;
}
}
function removeContract(bytes32 name)onlyCreator() returns (bool result){
address cName = SuperdaoContractDb(this).getContract(name);
if(cName == 0x0){
return false;
}else{
SuperdaoContractDb(this).removeContract(name);
return true;
}
}
function remove()onlyCreator(){
selfdestruct(contractOwner);
}
}
contract SuperdaoDougEnabled {
address sDOUG;
modifier onlyCreator(){
if(msg.sender != sDOUG){
throw;
}
}
function setSuperdaoDougAddress(address addr) returns (bool result){
if(sDOUG != 0x0 && addr != sDOUG){
return false;
}
sDOUG = addr;
return true;
}
function remove()onlyCreator(){
selfdestruct(sDOUG);
}
function(){
throw;
}
}
contract SuperdaoLogs{
struct Log{
address caller;
bytes32 action;
uint blockIndex;
bool success;
}
bool LOGGING = true;
uint public nextEntry = 0;
mapping(uint => Log) public logEntries;
modifier onlyinternal(){
if(msg.sender != address(this)){
throw;
}
}
function save_log(bytes32 name,bool state){
_log(name,state);
}
function _log(bytes32 actionName, bool success) internal {
// TODO check if this is really necessary in an internal function.
Log le = logEntries[nextEntry++];
le.caller = msg.sender;
le.action = actionName;
le.success = success;
le.blockIndex = block.number;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.