Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 49fe587

Browse files
committed
Merge branch 'develop'
2 parents 72408cb + 8be85f2 commit 49fe587

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2078
-807
lines changed

README.md

Lines changed: 72 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -4,197 +4,120 @@
44
![origin_license](https://img.shields.io/badge/license-MIT-6e3bea.svg?style=flat-square&colorA=111d28)
55
![origin_travis_banner](https://img.shields.io/travis/OriginProtocol/origin-js/master.svg?style=flat-square&colorA=111d28)
66

7-
# Origin Protocol
7+
# origin-js
88

9-
Origin Protocol is a library of javascript code and Ethereum smart contracts which allow anyone to create decentralized marketplaces, including for fractional usage.
9+
origin-js is a library of javascript code and Ethereum smart contracts which allow anyone to create decentralized marketplaces, including for fractional usage. It is an open source project created by [Origin Protocol](https://www.originprotocol.com/).
1010

11-
Please refer to our [product brief](https://www.originprotocol.com/product-brief) and [technical whitepaper](https://www.originprotocol.com/whitepaper) for more detail.
11+
To learn more about Origin Protocol, please read our [product brief](https://www.originprotocol.com/product-brief) and [whitepaper](https://www.originprotocol.com/whitepaper) for a high-level description of what we're building and why it matters. Our official website is [https://www.originprotocol.com](https://www.originprotocol.com).
1212

13-
- [README for Javascript code](#originjs-documentation)
13+
⚠️ This is an alpha version which is not suitable for production environments.
1414

15-
## Follow our progress and get involved
15+
## Documentation
16+
[origin-js documentation](http://docs.originprotocol.com/)
1617

17-
This repo is under active development. We welcome your participation!
18+
## Demo
1819

19-
1. [Join our #engineering channel on Discord](http://www.originprotocol.com/discord).
20+
origin-js is showcased in our Demo DApp currently running on the Rinkeby testnet.
21+
- [Overview and step-by-step instructions](https://medium.com/originprotocol/origin-demo-dapp-is-now-live-on-testnet-835ae201c58)
22+
- [Live Demo](http://demo.originprotocol.com)
23+
- [Github Repo](https://github.com/OriginProtocol/demo-dapp)
2024

21-
2. Listen in on our weekly engineering call on Google Hangouts. It happens every week and everyone is welcome to listen in and participate. [Join us on Google Hangouts](https://meet.google.com/pws-cgyd-tqp) on Wednesdays at 9pm GMT ([Add to Calendar](https://calendar.google.com/event?action=TEMPLATE&tmeid=MHAyNHI3N2hzMjk5b3V2bjhoM2Q1ZWVzY2pfMjAxODA0MTFUMjAwMDAwWiBqb3NoQG9yaWdpbnByb3RvY29sLmNvbQ&tmsrc=josh%40originprotocol.com&scp=ALL)):
25+
## Using origin-js in your project
2226

23-
| Pacific | Mountain | Central | Eastern | GMT |
24-
|---------|----------|---------|---------|-----|
25-
| Wed 1pm | Wed 2pm | Wed 3pm | Wed 4pm | Wed 9pm |
27+
### As a node package
2628

27-
3. Catch up on our meeting notes & weekly sprint planning docs (feel free to add comments):
28-
- [Engineering meeting notes](https://docs.google.com/document/d/1aRcAk_rEjRgd1BppzxZJK9RXfDkbuwKKH8nPQk7FfaU/)
29-
- [Weekly sprint doc](https://docs.google.com/document/d/1qJ3sem38ED8oRI72JkeilcvIs82oDq5IT3fHKBrhZIM)
29+
```
30+
npm install origin --save
31+
```
32+
or
33+
```
34+
yarn add origin
35+
```
3036

31-
4. Read our simple [contributing and style guide](CONTRIBUTING.md).
37+
### Plain javascript
3238

33-
# What we're building
39+
A browser-compatible plain javascript file `origin.js` is available in the [Releases section](https://github.com/OriginProtocol/origin-js/releases). A hosted version can be directly included in your html as:
40+
```html
41+
<script src="https://code.originprotocol.com/origin-js/origin-v0.5.10.js"></script>
42+
```
3443

35-
This library is an abstraction layer for developers who want to build DApps on Origin Protocol, and is also used to build the [Origin Demo DApp](https://github.com/OriginProtocol/demo-dapp).
44+
`npm build` will generate this file and save it to `dist/origin.js`.
3645

37-
The library will make it easy for sellers to do things like:
46+
## Local development
3847

39-
- Create listings
40-
- Update listings
41-
- Delete listings
42-
- Validate listings
48+
### 1. Clone this repo.
49+
```
50+
git clone https://github.com/OriginProtocol/origin-js.git && cd origin-js
51+
```
4352

44-
And buyers to:
53+
If you would like to submit pull requests, you should instead fork this repo and then clone your fork. Note pull requests should always be made to the `develop` branch, which always has the latest commits.
4554

46-
- Browse listing
47-
- Create bookings
48-
- Update bookings
49-
- Cancel bookings
55+
### 2. Install dependencies and link
56+
```
57+
npm run install:dev
58+
```
5059

51-
# origin.js Documentation
60+
`install:dev` is shortcut for `npm install && npm link`. Linking means that changes to `origin-js` code are immediately available to local DApps without an `npm install`.
5261

53-
## Introduction
62+
### 3. Start the local blockchain and build origin-js
5463

55-
Welcome to the origin.js documentation! origin.js is a Javascript library for interacting with the Origin protocol.
64+
```
65+
npm start
66+
```
5667

57-
Using the library you can create new listings from your applications, purchase them, or update them from your own off-chain applications.
58-
59-
### Warning
60-
This is still an alpha version which will evolve significantly before the main net release.
61-
62-
## Using origin.js in your project
63-
64-
### Plain javascript
65-
66-
A browser-compatible plain javascript file `origin.js` is available in the "Releases" tab, and will soon be hosted on originprotocol.com. It can be generated locally via `npm build` and will be placed in `dist/origin.js`.
67-
68-
## Install
69-
70-
### NPM
71-
```
72-
npm install @originprotocol/origin --save
73-
```
74-
75-
### Yarn
76-
```
77-
yarn add @originprotocol/origin
78-
```
79-
80-
### Local
81-
82-
1. `git clone` your fork. Note that the latest commits will be on the `develop`
83-
branch. So switch to that branch if you want to submit a PR or check out
84-
recently merged code.
85-
86-
1. Install:dev (shortcut for `npm install && npm link`). Linking makes this available as a local npm package for local dapp development.
87-
```
88-
npm run install:dev
89-
```
90-
91-
1. Start the localblockchain and create the build. Code changes will trigger a live rebuild.
92-
```
93-
npm start
94-
```
95-
96-
In order to conduct test transactions, you can create a new wallet using the following seed phrase (Mnemonic):
68+
Code changes will trigger a live rebuild.
9769

98-
_**Be careful to back up the seed phrases and private keys for any existing wallets before creating a new one.**_
99-
```
100-
candy maple cake sugar pudding cream honey rich smooth crumble sweet treat
101-
```
102-
103-
1. To develop against a working dapp and UI, see [the instructions in our demo dapp](https://github.com/OriginProtocol/demo-dapp#developing-with-a-local-chain).
104-
105-
## Import
106-
107-
```
108-
import Origin from '@originprotocol/origin'
109-
110-
let configOptions = {}
70+
### 4. Use with local Demo DApp
11171

112-
let { contractService, ipfsService, originService } = new Origin(configOptions)
113-
```
114-
115-
## Configuration Options
116-
117-
Config options are passed into the Origin constructor at instantiation.
118-
119-
```
120-
let configOptions = {
121-
option: 'value'
122-
}
123-
let origin = new Origin(configOptions)
124-
```
72+
To interact with your local origin-js and local blockahin, see [the instructions in our Demo DApp](https://github.com/OriginProtocol/demo-dapp#developing-with-a-local-chain).
12573

126-
Valid options:
127-
- `ipfsDomain`
128-
- `ipfsApiPort`
129-
- `ipfsGatewayPort`
130-
- `ipfsGatewayProtocol`
131-
- `attestationServerUrl`
13274

133-
## IPFS
75+
## Tests
13476

135-
If you are running a local IPFS daemon then set the following config options ([see config options](#configuration-options)):
77+
### Command Line (All Tests)
13678

137-
```
138-
{
139-
ipfsDomain: '127.0.0.1',
140-
ipfsApiPort: '5001',
141-
ipfsGatewayPort: '8080',
142-
ipfsGatewayProtocol: 'http'
143-
}
144-
```
145-
146-
Configure your local IPFS daemon with the following settings to avoid CORS errors:
147-
148-
```
149-
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["localhost:*"]'
150-
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]'
151-
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'
152-
```
153-
154-
## Troubleshooting
79+
Our full test suite can be run with:
15580

156-
### Python 3
81+
```
82+
npm run test
83+
```
15784

158-
If you have Python 3 installed, you may see this error when installing dependencies:
85+
Note: you should *not* have the server running at this time, as these tests start their own local blockchain instance.
15986

160-
```
161-
gyp ERR! stack Error: Python executable "/Users/aiham/.pyenv/shims/python" is v3.6.4, which is not supported by gyp.
162-
```
87+
### Command Line (Only Solidity Tests)
16388

164-
Resolve this by configuring npm to use Python 2 (where python2.7 is a binary accessible from your $PATH):
89+
Our Solidity tests (which use [Truffle](http://truffleframework.com/docs/getting_started/javascript-tests)) are located at `contracts/test`.
16590

16691
```
167-
npm config set python python2.7
92+
npm run test:contracts
16893
```
16994

170-
## Tests
95+
Note: you should *not* have the server running at this time, as these tests start their own local blockchain instance.
17196

172-
### Command Line (All Tests)
97+
### Browser Tests
17398

174-
Our full test suite can be run with:
99+
A subset of our tests can be run from the browser. These tests are automatically served at `http://localhost:8081` when you run `npm start`. These tests are automatically rerun when source or test code is changed.
175100

176-
```
177-
npm run test
178-
```
101+
Run a subset of these tests using the `grep` query string parameter, for example: http://localhost:8081/?grep=IpfsService
179102

180-
Note: you should *not* have the server running at this time, as these tests start their own local blockchain instance.
103+
## Troubleshooting
181104

182-
### Command Line (Only Solidity Tests)
105+
### Python 3
183106

184-
Our Solidity tests (which use [Truffle](http://truffleframework.com/docs/getting_started/javascript-tests)) are located at `contracts/test`.
185-
186-
```
187-
npm run test:contracts
188-
```
189-
190-
Note: you should *not* have the server running at this time, as these tests start their own local blockchain instance.
107+
If you have Python 3 installed, you may see this error when installing dependencies:
191108

192-
### Browser Tests
109+
```
110+
gyp ERR! stack Error: Python executable "/Users/aiham/.pyenv/shims/python" is v3.6.4, which is not supported by gyp.
111+
```
193112

194-
A subset of our tests can be run from the browser. These tests are automatically served at `http://localhost:8081` when you run `npm start`. These tests are automatically rerun when source or test code is changed.
113+
Resolve this by configuring npm to use Python 2 (where python2.7 is a binary accessible from your $PATH):
195114

196-
Run a subset of these tests using the `grep` query string parameter, for example: http://localhost:8081/?grep=IpfsService
115+
```
116+
npm config set python python2.7
117+
```
118+
119+
## Contributing
197120

198-
## Documentation
121+
Origin is an 100% open-source and community-driven project and we welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing code, and helping us improve our community.
199122

200-
Needed
123+
To get involved, please join our [Discord channel](https://discord.gg/jyxpUSe) and review our [guide to contributing](https://docs.originprotocol.com/#contributing).

contracts/contracts/ListingsRegistry.sol

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ contract ListingsRegistry {
2424
// Array of all listings
2525
Listing[] public listings;
2626

27-
28-
/*
29-
* Modifiers
30-
*/
31-
modifier isValidListingIndex(uint _index) {
32-
require (_index < listings.length);
33-
_;
34-
}
35-
36-
37-
modifier isOwner() {
38-
require (msg.sender == owner);
39-
_;
40-
}
41-
42-
4327
/*
4428
* Public functions
4529
*/
@@ -101,5 +85,24 @@ contract ListingsRegistry {
10185
return listings.length;
10286
}
10387

104-
88+
/// @dev createOnBehalf(): Create a new listing with specified creator
89+
/// Used for migrating from old contracts (admin only)
90+
/// @param _ipfsHash Hash of data on ipfsHash
91+
/// @param _price Price of unit in wei
92+
/// @param _unitsAvailable Number of units availabe for sale at start
93+
/// @param _creatorAddress Address of account to be the creator
94+
function createOnBehalf(
95+
bytes32 _ipfsHash,
96+
uint _price,
97+
uint _unitsAvailable,
98+
address _creatorAddress
99+
)
100+
public
101+
returns (uint)
102+
{
103+
require (msg.sender == owner, "Only callable by registry owner");
104+
listings.push(new Listing(_creatorAddress, _ipfsHash, _price, _unitsAvailable));
105+
emit NewListing(listings.length-1);
106+
return listings.length;
107+
}
105108
}

contracts/contracts/Purchase.sol

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ contract Purchase {
1212
*/
1313

1414
event PurchaseChange(Stages stage);
15+
event PurchaseReview(address reviewer, address reviewee, Roles revieweeRole, uint8 rating, bytes32 ipfsHash);
1516

1617
/*
1718
* Enum
@@ -27,6 +28,11 @@ contract Purchase {
2728
COMPLETE // It's all over
2829
}
2930

31+
enum Roles {
32+
BUYER,
33+
SELLER
34+
}
35+
3036
/*
3137
* Storage
3238
*/
@@ -119,23 +125,40 @@ contract Purchase {
119125
emit PurchaseChange(internalStage);
120126
}
121127

122-
function buyerConfirmReceipt()
128+
function buyerConfirmReceipt(uint8 _rating, bytes32 _ipfsHash)
123129
public
124130
isBuyer
125131
atStage(Stages.BUYER_PENDING)
126132
{
127-
internalStage = Stages.SELLER_PENDING;
128-
emit PurchaseChange(internalStage);
133+
// Checks
134+
require(_rating >= 1);
135+
require(_rating <= 5);
136+
137+
// State changes
138+
internalStage = Stages.SELLER_PENDING;
139+
140+
// Events
141+
emit PurchaseChange(internalStage);
142+
emit PurchaseReview(buyer, listingContract.owner(), Roles.SELLER, _rating, _ipfsHash);
129143
}
130144

131-
function sellerCollectPayout()
145+
function sellerCollectPayout(uint8 _rating, bytes32 _ipfsHash)
132146
public
133147
isSeller
134148
atStage(Stages.SELLER_PENDING)
135149
{
150+
// Checks
151+
require(_rating >= 1);
152+
require(_rating <= 5);
153+
154+
// State changes
136155
internalStage = Stages.COMPLETE;
156+
157+
// Events
137158
emit PurchaseChange(internalStage);
159+
emit PurchaseReview(listingContract.owner(), buyer, Roles.BUYER, _rating, _ipfsHash);
138160

161+
// Transfers
139162
// Send contract funds to seller (ie owner of Listing)
140163
// Transfering money always needs to be the last thing we do, do avoid
141164
// rentrancy bugs. (Though here the seller would just be getting their own money)

0 commit comments

Comments
 (0)