Skip to content

Storage #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
build
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}
Binary file added contracts/.DS_Store
Binary file not shown.
108 changes: 108 additions & 0 deletions contracts/AttestStorage.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
pragma solidity ^0.4.19;
contract Ownable {
address public owner;


event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);


/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
function Ownable() {
owner = msg.sender;
}


/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}


/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}

}
contract AttestStorage is Ownable {
/**
The struct for attestations,claim etc...
*/
uint256 counter=0;
struct claimStructure {
string claim;
uint256 attest_level;
bool active;
}
struct attestationStructure {
string data;
string opposite_party_id;
uint256 attest_level;
bool active;
}
//mapping for user_id to ref id to struct detail
mapping(string=>mapping(string=>claimStructure)) claims;
//mapping for attestor id to user id to detail
mapping(string=>mapping(uint256=>attestationStructure)) attestations;
mapping(string=>uint256) attest_counter;
//mapping to allow access to only some addresses
mapping(address => bool) Access_allowed;
//to check that the request is actually coming from the vanity contract
modifier checkOwner(address _add) {
require(Access_allowed[_add]==true);
_;
}
//to set the contract address
function allowAccess(address newAddr) onlyOwner public {
Access_allowed[newAddr]=true;
}

//function update claim by the user
function setClaimMapping(string uid,string ref_id,string _claim) checkOwner(msg.sender) public {
claims[uid][ref_id]=claimStructure(_claim,0,true);
}
//function to get current count for a refernce
function getCounter(string ref_id) public view returns(uint256) {
return attest_counter[ref_id];
}
//function to set attesting mapping
function setAttestingsMapping(string uid1,string uid2,string ref_id,uint256 _level,uint256 count) checkOwner(msg.sender) public {
attestations[ref_id][count]=attestationStructure(claims[uid1][ref_id].claim,uid2,_level,true);
}
//function to set attest_counter mapping
function setAttestCounterMapping(string ref_id,uint256 count) checkOwner(msg.sender) public {
attest_counter[ref_id]=count;
}
//get the details through the pagination function
function getPaginationResults(uint256 index,string ref_id) public view returns(string,string,uint256,bool) {
require(keccak256(attestations[ref_id][index].opposite_party_id)!=keccak256(""));
return (attestations[ref_id][index].data,attestations[ref_id][index].opposite_party_id,attestations[ref_id][index].attest_level,attestations[ref_id][index].active);
}
//function to get claim attest_level
function getClaimLevel(string uid1,string ref_id) public view returns(uint256) {
return claims[uid1][ref_id].attest_level;
}
//function to claim done by user
function getClaimDoneByUser(string uid1,string ref_id) public view returns(string) {
return claims[uid1][ref_id].claim;
}
function setClaimLevel(string uid1,string ref_id,uint256 level) checkOwner(msg.sender) public {
claims[uid1][ref_id].attest_level=level;
}
//function to delete old claim
function deleteOldClaim(string uid1,string ref_id) checkOwner(msg.sender) public {
delete claims[uid1][ref_id];
}

}
45 changes: 36 additions & 9 deletions contracts/Attestation.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
pragma solidity ^0.4.19;

import "./AttestStorage.sol";
contract Attestation {

event Attest(address _address,string _type,string _data);

function write(string _type,string _data) public returns (bool) {
Attest(msg.sender,_type,_data);
return true;
}
}
AttestStorage storageAddress;
event claimAdded(string _by,string ref_id,string claim);
event attestDone(string _for,string _by,string ref_id,uint256 level);
//constructor to set storage address
function Attestation (address _addr) {
storageAddress=AttestStorage(_addr);
}
//function to claim | can be called by anyone
function setClaim(string uid,string ref_id,string _claim) public {
storageAddress.setClaimMapping(uid,ref_id,_claim);
claimAdded(uid,ref_id,_claim);
}
//function to attest or verify a claim
function attesting(string uid1,string uid2,string ref_id,uint256 _level) public {
uint256 count = storageAddress.getCounter(ref_id);
require(keccak256(uid1)!=keccak256(uid2)&&keccak256(storageAddress.getClaimDoneByUser(uid1,ref_id))!=keccak256(""));
count++;
storageAddress.setAttestingsMapping(uid1,uid2,ref_id,_level,count);
storageAddress.setAttestCounterMapping(ref_id,count);
if(storageAddress.getClaimLevel(uid1,ref_id)<_level){
storageAddress.setClaimLevel(uid1,ref_id,_level);
}
attestDone(uid1,uid2,ref_id,_level);
}
//function to get pagination results
function getAttestResults(uint256 index,string ref_id) public view returns(string,string,uint256,bool) {
return storageAddress.getPaginationResults(index,ref_id);
}
//function to update any current attribute like work ex,education etc
function updateAttribute(string uid,string ref_id,string _newclaim) public {
storageAddress.deleteOldClaim(uid,ref_id);
setClaim(uid,ref_id,_newclaim);
}

}
11 changes: 11 additions & 0 deletions contracts/Attestation_stateless.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.19;

contract Attestation_stateless {

event Attest(address _address,string _type,string _data);

function write(string _type,string _data) public returns (bool) {
Attest(msg.sender,_type,_data);
return true;
}
}
19 changes: 8 additions & 11 deletions contracts/SPRINGToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract Ownable {
*/
function transferOwnership(address newOwner) onlyOwner public {
require(newOwner != address(0));
OwnershipTransferred(owner, newOwner);
OwnershipTransferred(owner, newOwner);
owner = newOwner;
}

Expand Down Expand Up @@ -89,24 +89,22 @@ contract Pausable is Ownable {
*/
function pause() onlyOwner whenNotPaused public {
paused = true;
Pause();
Pause();
}

/**
* @dev called by the owner to unpause, returns to normal state
*/
function unpause() onlyOwner whenPaused public {
paused = false;
Unpause();
Unpause();
}
}

contract StandardToken is ERC20,Pausable {
using SafeMath for uint256;

mapping (address => uint256) public balances;
mapping (address => mapping (address => uint256)) public allowed;

/**
* @dev transfer token for a specified address
* @param _to The address to transfer to.
Expand All @@ -119,7 +117,6 @@ contract StandardToken is ERC20,Pausable {
Transfer(msg.sender, _to, _value);
return true;
}

/**
* @dev Transfer tokens from one address to another
* @param _from address The address which you want to send tokens from
Expand All @@ -131,7 +128,7 @@ contract StandardToken is ERC20,Pausable {
balances[_to] = balances[_to].add(_value);
balances[_from] = balances[_from].sub(_value);
allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
Transfer(_from, _to, _value);
Transfer(_from, _to, _value);
return true;
}

Expand All @@ -154,7 +151,7 @@ contract StandardToken is ERC20,Pausable {
function approve(address _spender, uint256 _value) whenNotPaused returns (bool success) {
require(allowed[msg.sender][_spender] == 0);
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
Approval(msg.sender, _spender, _value);
return true;
}

Expand All @@ -174,7 +171,7 @@ contract StandardToken is ERC20,Pausable {
*/
function increaseApproval(address _spender, uint _addedValue) whenNotPaused public returns (bool) {
allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}

Expand All @@ -185,7 +182,7 @@ contract StandardToken is ERC20,Pausable {
} else {
allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
}
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
return true;
}
}
Expand Down Expand Up @@ -228,7 +225,7 @@ contract SPRINGToken is StandardToken {
uint256 public maxSupply;

/* Contructor function to set maxSupply*/
function SPRINGToken(uint256 _maxSupply){
function SPRINGToken(uint256 _maxSupply) {
maxSupply = _maxSupply.mul(10**decimals);
}

Expand Down
Loading