Skip to content
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
104 changes: 104 additions & 0 deletions smart-contracts/status/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
70 changes: 70 additions & 0 deletions smart-contracts/status/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
![Jur](/logo.png)
# Jur Status
Smart contracts implementing the Jur Status for authenticating the licence of a member in the Jur ecosystem. A licenced Jur Status will get access to Jur's exclusive features and activities and get rewarded for maintaining an active community.
The term Jur Status and the license is used interchangeably.
## Running and Testing the project
```
git clone https://github.com/jurteam/jur-status-smart-contract.git
cd jur-status-smart-contract
npm install
truffle compile
truffle test
```
> **Prerequisite :** Please install truffle by running,
```
npm install -g truffle
```

## Deployment
```
constructor()
```
The address used to deploy the contract **JurStatus.sol** automatically becomes the owner/admin of the contract.

## Functions
### 1. Adding a new status type
```
addStatusType(string _statusType)
```
Currently, Jur offers two types of licenses (enabling different sets of features), "Solomon" and "Justinian". The admin of the smart contract is required to officially add these types in the system.
Unless added, they cannot be associated with any of the statuses.

### 2. Granting a new license
```
addJurStatus(address _statusHolder, uint _statusType)
```
To grant a new license, the admin should use this function.
1. **_statusHolder** is the address which will be given the license.
2. **_statusType** is the index of the type to be used from the "statusTypes" array.

### 3. Invalidating a license
```
changeState(address _statusHolder, bool _newState)
```
A license can be invalidated by the Jur admin at any point as they see fit. Admin should call this function to invalidate it. By invalidating, only the "isActive" state of the license will change.
But it's record on the blockchain will always remain unchanged. Admin can also reinstate by license by using the same function.
1. **_statusHolder** is the address of the Jur Status holder.
2. **_newState** is the boolean state the admin wishes to impose on the Jur Status


### 4. Upgrading/Downgrading a licence
```
changeStatusType(address _statusHolder, uint _newStatusType)
```
A license can be upgraded or downgraded by the Jur admin at any point as they see fit. Admin should call this function to do so. By invalidating, only the "statusType" of the license will change.
But it's record on the blockchain will always remain unchanged.
1. **_statusHolder** is the address of the Jur Status holder.
2. **_newStatusType** is the index of the type to be used from the "statusTypes" array.



# Jur Status on the test network

#### Address - [0x7d6a130ace2271e23ce6d5527647ecb81fa72aea](https://explore-testnet.vechain.org/accounts/0x7d6a130ace2271e23ce6d5527647ecb81fa72aea)

NOTE: The bool field for `changeState` is read incorrectly by the inspector app as of June 20'. Please use other mediums to interact with the contract for this specific function only.





57 changes: 57 additions & 0 deletions smart-contracts/status/contracts/IStatus.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
pragma solidity ^0.5.0;

interface IStatus {
event StateChanged(address statusHolder, bool newState, uint timestamp);
event StatusTypeChanged(address statusHolder,string statusType, uint timestamp);
event StatusAdded(address statusHolder, uint activationTime, string statusType);

/**
@dev addJurStatus - Function to let the Jur admin add a new address as a Jur Status, thus
validating it's license which can be verified on the blockchain.
@param _statusHolder - The address which will hold the Jur Status.
@param _statusType - The position of the value from the statusTypes array signifying the
status type.
*/
function addJurStatus(address _statusHolder, uint _statusType) external;

/**
@dev changeState - Function to let the Jur admin change the state of a Jur Status.
@param _statusHolder - The address holding the Jur Status.
@param _newState - Boolean status to update.
*/
function changeState(address _statusHolder, bool _newState) external;

/**
@dev addStatusType - Function to let an admin add status types to support the bussiness
logic.
@param _statusType - The new status type.
*/
function addStatusType(string calldata _statusType) external;

/**
@dev isStatus - Returns if a status is still active.
@param _statusHolder - The address holding the Jur Status.
*/
function isStatus(address _statusHolder) external view returns (bool);

/**
@dev getStatus - Returns the details of a Status
@param _statusHolder - The address holding the Jur Status.
*/
function getStatus(address _statusHolder) external view returns (uint, bool, string memory);

/**
@dev getStatusCount - Returns the total number of statuses
*/
function getStatusCount() external view returns (uint256);

/**
@dev getStatusTypeCount - Returns the total number of status types
*/
function getStatusTypeCount() external view returns (uint256);

/**
@dev getStatusType - Returns the string value stored for each status type
*/
function getStatusType(uint256 _index) external view returns (string memory);
}
114 changes: 114 additions & 0 deletions smart-contracts/status/contracts/JurStatus.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
pragma solidity >=0.5.0 <0.7.0;

import "@openzeppelin/contracts/ownership/Ownable.sol";
import "./IStatus.sol";

contract JurStatus is IStatus, Ownable {

/**
Struct defining the values of a Jur Status.
activationTime - The timestamp from which the status will be valid.
isActive - Boolean state depicting if a Jur Status is currently valid.
statusType - The type of the Jur Status complementing the bussiness logic.
*/
struct Status {
address statusHolder;
uint activationTime;
uint statusCount;
bool isActive;
string statusType;
}

/** Dynamic array holding the status types */
string[] private statusTypes;

/** Mapping between the address of the Jur Status holders and their properties. */
mapping(address => Status) public status;
mapping(uint => Status) public statusList;

/** Total count of Jur Statuses. */
uint private statusCount;

/**
@dev addJurStatus - Function to let the Jur admin add a new address as a Jur Status, thus
validating it's license which can be verified on the blockchain.
@param _statusHolder - The address which will hold the Jur Status.
@param _statusType - The position of the value from the statusTypes array signifying the
status type.
*/
function addJurStatus(address _statusHolder, uint _statusType) public onlyOwner {
require(_statusHolder != address(0), "Please provide a valid address.");
assert(_statusType <= statusTypes.length);
status[_statusHolder] = Status(_statusHolder, now, statusCount, true, statusTypes[_statusType]);
statusList[statusCount] = Status(_statusHolder, now, statusCount, true, statusTypes[_statusType]);
statusCount++;

emit StatusAdded(_statusHolder, now, statusTypes[_statusType]);
}

/**
@dev changeState - Function to let the Jur admin change the state of a Jur Status.
@param _statusHolder - The address holding the Jur Status.
@param _newState - Boolean status to update.
*/
function changeState(address _statusHolder, bool _newState) public onlyOwner {
require(_statusHolder != address(0), "Please provide a valid address.");
Status storage _status = status[_statusHolder];
Status storage _statusList = statusList[_status.statusCount];
require(_status.activationTime != 0, "Address is not a Jur Status holder.");
// require(_status.isActive != _newState, "Already in the similar state.");
_status.isActive = _newState;
_statusList.isActive = _newState;

emit StateChanged(_statusHolder, _newState, now);
}

/**
@dev changeState - Function to let the Jur admin change the state of a Jur Status.
@param _statusHolder - The address holding the Jur Status.
@param _statusType - Status type to update to update.
*/
function changeStatusType(address _statusHolder, uint _statusType) public onlyOwner {
require(_statusHolder != address(0), "Please provide a valid address.");
assert(_statusType <= statusTypes.length);
Status storage _status = status[_statusHolder];
Status storage _statusList = statusList[_status.statusCount];
require(_status.activationTime != 0, "Address is not a Jur Status holder.");
_status.statusType = statusTypes[_statusType];
_statusList.statusType = statusTypes[_statusType];

emit StatusTypeChanged(_statusHolder, statusTypes[_statusType], now);
}

/**
@dev addStatusType - Function to let an admin add status types to support the bussiness
logic.
@param _statusType - The new status type.
*/
function addStatusType(string memory _statusType) public onlyOwner {
require(bytes(_statusType).length != 0, "Status type cannot be an empty string.");
statusTypes.push(_statusType);
}

function isStatus(address _statusHolder) public view returns(bool) {
Status storage _status = status[_statusHolder];
return(_status.isActive);
}

function getStatus(address _statusHolder) public view returns(uint, bool, string memory) {
Status storage _status = status[_statusHolder];
return(_status.activationTime, _status.isActive, _status.statusType);
}

function getStatusCount() public view returns (uint256) {
return(statusCount);
}

function getStatusTypeCount() public view returns (uint256) {
return (statusTypes.length);
}

function getStatusType(uint256 _index) public view returns (string memory) {
return(statusTypes[_index]);
}
}
23 changes: 23 additions & 0 deletions smart-contracts/status/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity >=0.4.21 <0.7.0;

contract Migrations {
address public owner;
uint public last_completed_migration;

constructor() public {
owner = msg.sender;
}

modifier restricted() {
if (msg.sender == owner) _;
}

function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}

function upgrade(address new_address) public restricted {
Migrations upgraded = Migrations(new_address);
upgraded.setCompleted(last_completed_migration);
}
}
Binary file added smart-contracts/status/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions smart-contracts/status/migrations/1_initial_migrations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Migrations = artifacts.require("./Migrations.sol");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};
5 changes: 5 additions & 0 deletions smart-contracts/status/migrations/2_deploy_contract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const JurStatus = artifacts.require("JurStatus.sol");

module.exports = function(deployer) {
deployer.deploy(JurStatus);
};
Loading