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
5 changes: 5 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Truffle Box for Angular
Copyright 2017 Quintor

This product includes software developed at Quintor (http://www.quintor.nl/).
Angular Logo provided by the Angular team (https://angular.io/presskit), licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/).
Binary file added ThembaR Option2.mp4
Binary file not shown.
Binary file added UnblocktheBlock Presentation.pptx
Binary file not shown.
Binary file added box-img-lg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added box-img-sm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env sh
set -x
set -e
testrpc -l 100000000 -m "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat" > /dev/null &
TESTRPC_PID=$!
trap "kill $TESTRPC_PID" EXIT INT TERM

truffle compile
truffle migrate
truffle test

npm test
ng e2e
ng lint


#(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57
#(1) 0xf17f52151ebef6c7334fad080c5704d77216b732
#(2) 0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef
6 changes: 6 additions & 0 deletions ci/install-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env sh
set -x
npm install -g @angular/cli
npm install -g truffle
npm install -g ethereumjs-testrpc
npm install
50 changes: 50 additions & 0 deletions contracts/AccessRestriction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pragma solidity ^0.4.16;

contract AccessRestriction {
// These will be assigned at the construction
// phase, where `msg.sender` is the account
// creating this contract.
address public owner = msg.sender;
uint public creationTime = now;

// Modifiers can be used to change
// the body of a function.
// If this modifier is used, it will
// prepend a check that only passes
// if the function is called from
// a certain address.
modifier onlyBy(address _account)
{
require(msg.sender == _account);
_;
}
modifier onlyByOwner()
{
require(msg.sender == owner);
_;
}
/// Make `_newOwner` the new owner of this
/// contract.
function changeOwner(address _newOwner)
public
onlyBy(owner)
{
owner = _newOwner;
}

modifier onlyAfter(uint _time) {
require(now >= _time);
_;
}

/// Erase ownership information.
/// May only be called 6 weeks after
/// the contract has been created.
function disown()
public
onlyBy(owner)
onlyAfter(creationTime + 6 weeks)
{
delete owner;
}
}
97 changes: 97 additions & 0 deletions contracts/Agreement.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
pragma solidity ^0.4.16;

import "./ThembaR.sol";
import "./AccessRestriction.sol";

contract Agreement is AccessRestriction {
address private owner;
address private ownerToken;
address private signer;
address private signerToken;
uint private direction;
uint private left;
uint private right;
bool private signed;
bool private canPort;

//The agreement can be signed by any organisation,
// a customer of one organisation may also be the owner of another business,
//the business adding the agreement should then request the sign it.
//the party that is to sign the agreement should be sent through as the _signer
function Agreement(address _owner, address _signer, address _ownerToken, uint _direction, uint _left, uint _right, bool _canPort) public {
owner = _owner;
signer = _signer;
ownerToken = _ownerToken;
direction = _direction;
left = _left;
right = _right;
signed = false;
canPort = _canPort;
}
//The _signer is the only party that can sign the agreement
function signAgreement(address _signerToken) onlyBy(signer) public returns(bool) {
signerToken = _signerToken;
signed = true;
return true;
}
//This function returns the signer if the signer has signed
//Can be used to demonstrate partnerships to customers of either the owner or the _signer
function getSignedSigner() public view returns(address) {
if (signed)
return signerToken;
return 0x0;
}
//This functions checks if the _signer is the intended signer and has not signed the agreement
function amIUnsignedSigner(address _signer) public view returns(bool) {
if (!signed) {
if (signer == _signer)
return true;
}
return false;
}
//This function is used by the port function to check whether it is a valid port
function checkCredential(address _from) private view returns (bool) {
return (direction == 2 || (direction == 0 && _from == owner) || (direction == 1 && _from == signer));
}
//This function prints out the state of the agreement
function getInfo() public view returns (address,address,address,address,uint,uint,uint,bool,bool) {

return (owner,ownerToken,signer,signerToken,left,right,direction,signed,canPort);
}
//This function ports tokens between owner and _signer tokens for the customer account i.e. msg.sender
function port(address _fromToken, uint amount, address me) external returns (bool) {
require(canPort);
require((_fromToken == ownerToken) || (_fromToken == signerToken));
ThembaR tr = ThembaR(_fromToken);
require(tr.balanceOf(msg.sender) >= amount);
uint otherAmount;
ThembaR otherAddress;
bool blockUno = false;
bool blockTwo = false;
if (_fromToken == ownerToken && checkCredential(_fromToken)) {
blockUno = true;
otherAmount = amount*(right/left);
otherAddress = ThembaR(signerToken);
tr.specialTransfer(signer, amount, msg.sender, me);
otherAddress.specialTransfer(msg.sender, otherAmount,signer,me);
} else if (checkCredential(_fromToken)) {
blockTwo = true;
otherAmount = amount*(left/right);
otherAddress = ThembaR(ownerToken);
tr.specialTransfer(owner, amount, msg.sender, me);
otherAddress.specialTransfer(msg.sender, otherAmount,owner, me);
}
return true;
}
//This function ports the tokens between owner and _signer and pays the _to party ie the party in the agreement who is not _fromToken
function portAndPay(address _fromToken, uint amount) external returns (bool) {
require((_fromToken == ownerToken) || (_fromToken == signerToken));
ThembaR tr = ThembaR(_fromToken);
require(tr.balanceOf(msg.sender) >= amount);
if (_fromToken == ownerToken && checkCredential(_fromToken)) {
tr.specialTransfer(signer, amount, msg.sender, this);
} else if (checkCredential(_fromToken)) {
tr.specialTransfer(owner, amount, msg.sender, this);
}
}
}
23 changes: 23 additions & 0 deletions contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pragma solidity ^0.4.16;

contract Migrations {
address public owner;
uint public last_completed_migration;

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

function Migrations() public {
owner = msg.sender;
}

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);
}
}
89 changes: 89 additions & 0 deletions contracts/ThembaR.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
pragma solidity ^0.4.16;
import ".././node_modules/zeppelin-solidity/contracts/token/ERC20/BasicToken.sol";
import "./Agreement.sol";
import "./AccessRestriction.sol";
//THis is the ERC20 basic token that is used to facilitate loyality program transactions.
//It is owned by the msg.sender that called the create token function in the factory ie ThebaRController contract

//Themba is a south african word for trust.

contract ThembaR is BasicToken, AccessRestriction {
address public owner;
address[] public agreements;
string public name;
string public symbol;
uint public INITIAL_SUPPLY = 5000000000000;

//Constructor
function ThembaR(address _owner, string _name, string _symbol) {
owner = _owner;
name = _name;
symbol = _symbol;
totalSupply_ = INITIAL_SUPPLY;
balances[_owner] = INITIAL_SUPPLY;
}
//Returns the business that owns the token
function getOwner() external view returns (address) {
return owner;
}

//This returns the balance of the customer at the specified address.
//The restrictions were removed from the ERC20 token and therefore it is the reloaded function.
function getBalanceReloaded(address accountHolder) public view returns (uint) {
return balances[accountHolder];
}
//This creates an agreement for the owner of the token
//This agreement will be added to the agreement list and signed will be false and the _arrangee signs the agreement
function addAgreement(address _arrangee, uint _direction, uint _left, uint _right, bool _canPort) onlyBy(owner) public {
address a = new Agreement(owner, _arrangee,this, _direction, _left, _right, _canPort);
agreements.push(a);
}
//Returns all the agreements associated with the token
function getAgreementList() public view returns (address[]) {
return agreements;
}
//get all the agreements associated with this token that are signed and return an array of addresses
function getSignedPartners() public returns (address[]) {
address[] toReturn;
for (uint i = 0;i < agreements.length;i++) {
Agreement tempAgreement = Agreement(agreements[i]);
address signedSigner = tempAgreement.getSignedSigner();
if (signedSigner != 0x0) {
toReturn.push(signedSigner);
}
}
return toReturn;
}
//get the agreements of the _signer that are not signed, this can be requested by the signer to verify if they have signed
function getSignerUnSignedAgreements(address _signer) public returns(address[]) {
address[] toReturn;
for (uint i = 0;i < agreements.length;i++) {
Agreement tempAgreement = Agreement(agreements[i]);
if (tempAgreement.amIUnsignedSigner(_signer)) {
toReturn.push(tempAgreement);
}
}
return toReturn;
}
function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
require(_to != address(0));
balances[_from] = balances[_from].sub(_value);
balances[_to] = balances[_to].add(_value);
Transfer(_from, _to, _value);
return true;
}
//Used by this token to participate in the agreement that was sent as the parameter
function signAgreement(address _agreementAddress) public {
Agreement toSign = Agreement(_agreementAddress);
toSign.signAgreement(this);
agreements.push(toSign);
}
//Used by an agreement to transfer funds
function specialTransfer(address _to, uint amount, address _from, address agreement) public {
for (uint i = 0; i < agreements.length; i++) {
if (agreements[i] == agreement) {
transferFrom(_from, _to, amount);
}
}
}
}
44 changes: 44 additions & 0 deletions contracts/ThembaRController.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
pragma solidity ^0.4.16;
import "./ThembaR.sol";

contract ThembaRController {
struct program {
address company;
address token;
}
mapping(uint=>program) private tokens;
uint numTokens=0;
address _owner;
function ThembaRController() public {
_owner = msg.sender;
}
function createNewToken(string _name, string _symbol) public { //business should call this
ThembaR newToken = new ThembaR(msg.sender, _name, _symbol);
numTokens++;
tokens[numTokens] = program(msg.sender,newToken);
}
function createBizToken(address ownerAdd, string _name, string _symbol) public { //business should call this
ThembaR newToken = new ThembaR(ownerAdd, _name, _symbol);
numTokens++;
tokens[numTokens] = program(ownerAdd,newToken);
}
function getAllTokens() public returns (address[]) {
address[] allTokens;
for (uint i = 1;i <= numTokens;i++) {
ThembaR temp = ThembaR(tokens[i].token);
allTokens.push(temp);
}
return allTokens;
}
function getCustomerTokens() public returns (address[]) {
address[] customerTokens;
for (uint i = 1;i <= numTokens;i++) {
ThembaR temp = ThembaR(tokens[i].token);
if (temp.balanceOf(msg.sender) >= 0) {
customerTokens.push(temp);
}
}
return customerTokens;
}
}

14 changes: 14 additions & 0 deletions e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { AppPage } from './app.po';

describe('angular-truffle-box App', () => {
let page: AppPage;

beforeEach(() => {
page = new AppPage();
});

it('should display welcome message', () => {
page.navigateTo();
expect(page.getHeader()).toContain('Angular Truffle Box');
});
});
41 changes: 41 additions & 0 deletions e2e/app.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { browser, by, element } from 'protractor';

export class AppPage {
navigateTo() {
browser.waitForAngularEnabled(false);
browser.get('/');
return browser.driver.sleep(1000);
}

getHeader() {
return element(by.css('h1')).getText();
}

getButton() {
return element(by.id('send'));
}

getBalance() {
return element(by.id('balance')).getText();
}

setAddress(index: number) {
return element.all(by.tagName('option')).filter((
(el, i) => {
return index === i;
}
)).click();
}

setToAddress(address: string) {
return element(by.id('receiver')).sendKeys(address);
}

setAmount(amount: string) {
return element(by.id('amount')).sendKeys(amount);
}

clickSend() {
return this.getButton().click();
}
}
Loading