This repository has been archived by the owner on Jan 28, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
CarlosFaria94
committed
Aug 18, 2018
0 parents
commit 15c0403
Showing
44 changed files
with
1,339 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json", | ||
"project": { | ||
"name": "angular-truffle-box" | ||
}, | ||
"apps": [ | ||
{ | ||
"root": "src", | ||
"outDir": "dist", | ||
"assets": ["assets", "favicon.ico"], | ||
"index": "index.html", | ||
"main": "main.ts", | ||
"polyfills": "polyfills.ts", | ||
"test": "test.ts", | ||
"tsconfig": "tsconfig.app.json", | ||
"testTsconfig": "tsconfig.spec.json", | ||
"prefix": "app", | ||
"styles": ["styles.css"], | ||
"scripts": [], | ||
"environmentSource": "environments/environment.ts", | ||
"environments": { | ||
"dev": "environments/environment.ts", | ||
"prod": "environments/environment.prod.ts" | ||
} | ||
} | ||
], | ||
"e2e": { | ||
"protractor": { | ||
"config": "./protractor.conf.js" | ||
} | ||
}, | ||
"lint": [ | ||
{ | ||
"project": "src/tsconfig.app.json" | ||
}, | ||
{ | ||
"project": "src/tsconfig.spec.json" | ||
}, | ||
{ | ||
"project": "e2e/tsconfig.e2e.json" | ||
} | ||
], | ||
"test": { | ||
"karma": { | ||
"config": "./karma.conf.js" | ||
} | ||
}, | ||
"defaults": { | ||
"styleExt": "css", | ||
"component": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# dependencies | ||
node_modules | ||
|
||
# Solidity | ||
config/development/contracts.json | ||
config/development/*.sol.js | ||
config/test/contracts.json | ||
build | ||
|
||
## compiled output | ||
/dist | ||
/tmp | ||
/out-tsc | ||
|
||
## e2e | ||
/e2e/*.js | ||
/e2e/*.map | ||
|
||
# testing | ||
coverage | ||
|
||
# production | ||
build_webpack | ||
|
||
# misc | ||
/.sass-cache | ||
/connect.lock | ||
/libpeerconnection.log | ||
testem.log | ||
/typings | ||
/shippable | ||
.DS_Store | ||
.env | ||
npm-debug.log | ||
.truffle-solidity-loader | ||
|
||
# Logs | ||
logs | ||
*.log | ||
|
||
# VS Code | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Truffle Box for Angular | ||
|
||
This Truffle Box provides a base for working with the Truffle Framework and Angular. | ||
It provides a basic working example of the MetaCoin contracts with Angular components. | ||
This project is generated with [Angular CLI](https://cli.angular.io/). | ||
|
||
## Prerequisites | ||
|
||
In order to run the Truffle box, you will need [Node.js](https://nodejs.org) (tested with version 8.9.x). This will include `npm`, needed | ||
to install dependencies. In order install these dependencies, you will also need [Python](https://www.python.org) (version 2.7.x) and | ||
[git](https://git-scm.com/downloads). You will also need the [MetaMask](https://metamask.io/) plugin for Chrome. | ||
|
||
## Building | ||
|
||
1. Install truffle, Angular CLI and an Ethereum client. If you don't have a test environment, we recommend ganache-cli | ||
```bash | ||
npm install -g truffle | ||
npm install -g @angular/cli | ||
npm install -g ganache-cli | ||
``` | ||
|
||
2. Download the box. | ||
```bash | ||
truffle unbox Quintor/angular-truffle-box | ||
``` | ||
|
||
3. Run your Ethereum client. For Ganache CLI: | ||
```bash | ||
ganache-cli | ||
``` | ||
Note the mnemonic 12-word phrase printed on startup, you will need it later. | ||
|
||
4. Compile and migrate your contracts. | ||
```bash | ||
truffle compile && truffle migrate | ||
``` | ||
|
||
## Configuration | ||
1. In order to connect with the Ethereum network, you will need to configure MetaMask | ||
2. Log into the `ganache-cli` test accounts in MetaMask, using the 12-word phrase printed earlier. | ||
1. A detailed explaination of how to do this can be found [here](http://truffleframework.com/docs/advanced/truffle-with-metamask#using-the-browser-extension) | ||
1. Normally, the available test accounts will change whenever you restart `ganache-cli`. | ||
2. In order to receive the same test accounts every time you start `ganache-cli`, start it with a seed like this: `ganache-cli --seed 0` or `ganache-cli -m "put your mnemonic phrase here needs twelve words to work with MetaMask"` | ||
3. Point MetaMask to `ganache-cli` by connecting to the network `localhost:8545` | ||
|
||
|
||
## Running | ||
|
||
1. Run the app using Angular CLI: | ||
```bash | ||
npm start | ||
``` | ||
The app is now served on localhost:4200 | ||
|
||
2. Making sure you have configured MetaMask, visit http://localhost:4200 in your browser. | ||
|
||
3. Send MetaCoins! | ||
|
||
## Testing | ||
|
||
1. Running the Angular component tests: | ||
```bash | ||
ng test | ||
``` | ||
|
||
2. Running the Truffle tests: | ||
```bash | ||
truffle test | ||
``` | ||
|
||
3. Running Protactor end-to-end tests | ||
|
||
```bash | ||
ng e2e | ||
``` | ||
## Releasing | ||
Using the Angular CLI you can build a distributable of your app. Will be placed in `dist/` | ||
|
||
```bash | ||
ng build | ||
``` | ||
|
||
## FAQ | ||
|
||
* __Where can I find more documentation?__ | ||
|
||
This Truffle box is a union of [Truffle](http://truffleframework.com/) and an Angular setup created with [Angular CLI](https://cli.angular.io/). | ||
For solidity compilation and Ethereum related issues, try the [Truffle documentation](http://truffleframework.com/docs/). | ||
For Angular CLI and typescript issues, refer to the [Angular CLI documentation](https://github.com/angular/angular-cli/wiki) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env sh | ||
set -x | ||
set -e | ||
ganache-cli -m "candy maple cake sugar pudding cream honey rich smooth crumble sweet treat" > /dev/null & | ||
GANACHE_PID=$! | ||
trap "kill $GANACHE_PID" EXIT INT TERM | ||
|
||
truffle compile | ||
truffle migrate | ||
truffle test | ||
|
||
npm test | ||
ng e2e | ||
ng lint | ||
|
||
|
||
#(0) 0x627306090abab3a6e1400e9345bc60c78a8bef57 | ||
#(1) 0xf17f52151ebef6c7334fad080c5704d77216b732 | ||
#(2) 0xc5fdf4076b8f3a5357c5e395ab970b5b54098fef |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ganache-cli | ||
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
contract EntryStorage { | ||
mapping (uint => Entry) public entries; | ||
uint public entryCount; | ||
|
||
struct Entry { | ||
uint id; | ||
address owner; | ||
uint bounty; | ||
// Multihash directoryHash; | ||
uint unsafeCreatedTimestamp; | ||
uint submissionCount; | ||
mapping (uint => Submission) submissions; | ||
Submission acceptedSubmission; | ||
uint state; | ||
} | ||
|
||
enum State { Open, Submitted, Done, Canceled } | ||
|
||
struct Submission { | ||
uint id; | ||
address owner; | ||
// Multihash directoryHash; | ||
uint created; | ||
} | ||
|
||
struct Multihash { | ||
bytes32 digest; | ||
uint8 hashFunction; | ||
uint8 size; | ||
} | ||
|
||
constructor() public { | ||
entryCount = 0; | ||
} | ||
|
||
function addEntry( | ||
// bytes32 _directoryDigest, | ||
// uint8 _directoryHashFunction, | ||
// uint8 _directorySize | ||
) public payable { | ||
entryCount = entryCount + 1; | ||
|
||
// Multihash memory _directoryHash = Multihash( | ||
// _directoryDigest, _directoryHashFunction, _directorySize); | ||
|
||
entries[entryCount].id = entryCount; | ||
entries[entryCount].owner = msg.sender; | ||
entries[entryCount].bounty = msg.value; | ||
// entries[entryCount].directoryHash = _directoryHash; | ||
// This timestamp will not be used for critical contract logic, only as reference | ||
entries[entryCount].unsafeCreatedTimestamp = block.timestamp; | ||
entries[entryCount].submissionCount = 0; | ||
entries[entryCount].state = uint(State.Open); | ||
} | ||
|
||
function cancelEntry(uint _entryId) public { | ||
entries[_entryId].state = uint(State.Canceled); | ||
entries[_entryId].owner.transfer(entries[_entryId].bounty); | ||
} | ||
|
||
function submit( | ||
uint _entryId | ||
// bytes32 _directoryDigest, | ||
// uint8 _directoryHashFunction, | ||
// uint8 _directorySize | ||
) public { | ||
Entry storage e = entries[_entryId]; | ||
e.submissionCount = e.submissionCount + 1; | ||
|
||
// Multihash memory _directoryHash = Multihash( | ||
// _directoryDigest, _directoryHashFunction, _directorySize); | ||
|
||
Submission memory newSubmission = Submission( | ||
e.submissionCount, | ||
msg.sender, | ||
// _directoryHash, | ||
block.timestamp | ||
); | ||
|
||
e.state = uint(State.Submitted); | ||
e.submissions[e.submissionCount] = newSubmission; | ||
} | ||
|
||
function acceptSubmission(uint _entryId, uint _submissionId) public { | ||
Entry storage e = entries[_entryId]; | ||
e.state = uint(State.Done); | ||
e.acceptedSubmission = e.submissions[_submissionId]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
pragma solidity ^0.4.23; | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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('mat-toolbar')).getText(); | ||
} | ||
|
||
getButton() { | ||
return element(by.id('send')); | ||
} | ||
|
||
getBalance() { | ||
return element(by.id('balance')).getText(); | ||
} | ||
|
||
clickSelect() { | ||
return element(by.id('address-selector')).click(); | ||
} | ||
|
||
setAddress(index: number) { | ||
return element.all(by.tagName('mat-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(); | ||
} | ||
} |
Oops, something went wrong.