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

Commit 61ce31e

Browse files
committed
Merge branch 'develop'
2 parents bc70b84 + 0ac6084 commit 61ce31e

Some content is hidden

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

68 files changed

+5920
-7984
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ First pull request? Read our [guide to contributing](http://docs.originprotocol.
99

1010
### Description:
1111

12-
Please explain the changes you made here:
12+
Please explain the changes in this PR:
1313

14-
- A description of the problem you're trying to solve
15-
- An overview of the suggested solution
16-
- If the feature changes current behavior, reasons why your solution is better
14+
- Description of the problem being solved
15+
- Overview of the suggested solution
16+
- If the feature changes current behavior, reasons why this solution is better

.gitignore

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1-
.idea
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# Truffle build artifacts
4+
# https://ethereum.stackexchange.com/questions/19486/storing-a-truffle-contract-interface-in-version-control
5+
/build
6+
7+
# compiled output
8+
/dist
9+
10+
# dependencies
11+
/node_modules
12+
13+
# IDEs and editors
14+
.idea/
15+
/.idea
16+
/.idea
17+
.project
18+
.classpath
19+
.c9/
20+
*.launch
21+
.settings/
22+
*.sublime-workspace
23+
24+
# IDE - VSCode
25+
.vscode/*
26+
!.vscode/settings.json
27+
!.vscode/tasks.json
28+
!.vscode/launch.json
29+
!.vscode/extensions.json
30+
31+
# misc
32+
/.sass-cache
33+
/connect.lock
34+
/coverage
35+
/libpeerconnection.log
36+
npm-debug.log
37+
testem.log
38+
/typings
239
.DS_Store
File renamed without changes.

CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Contributing to Origin.js
2+
3+
Thanks for helping out! 👍
4+
5+
Before you summit a PR, you'll want to make sure that:
6+
7+
1. Any changes are tested.
8+
2. All tests pass. (See each package's readme for instructions on testing that package.)
9+
3. The formatting is correct. Just run `npm run format` in a package folder.
10+
11+
If this is a new feature, make sure you've discussed it with [our #engineering channel on Discord](https://www.originprotocol.com/discord).
12+
13+
14+
### Coding style: Javascript
15+
16+
We use [NPM style](https://docs.npmjs.com/misc/coding-style), as automated by the [prettier](https://prettier.io) tool. 2 space indents, no semi-semicolons.
17+
18+
### Coding style: Solidity
19+
20+
We use two space indents. Just copy the surrounding style and use your good judgement.

README.md

Lines changed: 137 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,173 @@
11
![origin_github_banner](https://user-images.githubusercontent.com/673455/37314301-f8db9a90-2618-11e8-8fee-b44f38febf38.png)
22

3+
![origin_npm_version](https://img.shields.io/npm/v/@originprotocol/origin.svg) ![origin_license](https://img.shields.io/npm/l/@originprotocol/origin.svg)
4+
35
# Origin Platform
46

5-
Origin Protocol is a library of javascript code and Ethereum smart contracts which allow anyone to create decentralized marketplaces, including for fractional usage.
7+
Origin Protocol is a library of javascript code and Ethereum smart contracts which allow anyone to create decentralized marketplaces, including for fractional usage.
68

79
Please refer to our [product brief](https://www.originprotocol.com/product-brief) and [technical whitepaper](https://www.originprotocol.com/whitepaper) for more detail.
810

9-
- [README for Javascript code](https://github.com/OriginProtocol/platform/tree/master/packages/origin.js)
10-
- [README for Ethereum contracts](https://github.com/OriginProtocol/platform/tree/master/packages/contracts)
11+
- [README for Javascript code](#originjs-documentation)
1112

1213
## Follow our progress and get involved
1314

1415
This repo is under active development. We welcome your participation!
1516

1617
1. [Join our #engineering channel on Discord](http://www.originprotocol.com/discord).
1718

18-
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) at the following times:
19+
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)):
1920

2021
> | Pacific | Mountain | Central | Eastern | GMT |
2122
> |---------|----------|---------|---------|-----|
2223
> | Wed 1pm | Wed 2pm | Wed 3pm | Wed 4pm | Wed 9pm |
23-
24+
2425
3. Catch up on our meeting notes & weekly sprint planning docs (feel free to add comments):
2526
- [Engineering meeting notes](https://docs.google.com/document/d/1aRcAk_rEjRgd1BppzxZJK9RXfDkbuwKKH8nPQk7FfaU/)
2627
- [Weekly sprint doc](https://docs.google.com/document/d/1qJ3sem38ED8oRI72JkeilcvIs82oDq5IT3fHKBrhZIM)
2728

28-
# What we're building
29-
30-
The main components of this repo are:
29+
4. Read our simple [contributing and style guide](CONTRIBUTING.md).
3130

32-
- [Origin.js](/packages/origin.js/)
33-
- [Ethereum smart contracts](/packages/contracts/)
34-
- Origin DApp that's built on top of origin.js (basically our current demo-dapp reworked to use origin.js)
31+
# What we're building
3532

36-
This library is an abstraction layer for developers who want to build DApps on Origin Protocol.
33+
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).
3734

3835
The library will make it easy for sellers to do things like:
3936

4037
- Create listings
4138
- Update listings
4239
- Delete listings
4340
- Validate listings
44-
41+
4542
And buyers to:
46-
43+
4744
- Browse listing
4845
- Create bookings
4946
- Update bookings
5047
- Cancel bookings
48+
49+
# origin.js Documentation
50+
51+
## Introduction
52+
53+
Welcome to the origin.js documentation! origin.js is a Javascript library for interacting with the Origin protocol.
54+
55+
Using the library you can create new listings from your applications, purchase them, or update them from your own off-chain applications.
56+
57+
### Warning
58+
This is still an alpha version which will evolve significantly before the main net release.
59+
60+
## Using origin.js in your project
61+
62+
### Plain javascript
63+
64+
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`.
65+
66+
## Install
67+
68+
### NPM
69+
```
70+
npm install @originprotocol/origin --save
71+
```
72+
73+
### Yarn
74+
```
75+
yarn add @originprotocol/origin
76+
```
77+
78+
### Local
79+
80+
1. Clone
81+
```
82+
git clone https://github.com/OriginProtocol/platform origin-platform && cd origin-platform
83+
```
84+
85+
2. Setup (shortcut for `npm install && npm link`). Linking makes this available as a local npm package for local dapp development.
86+
```
87+
npm run setup
88+
```
89+
90+
3. Start the localblockchain and create the build. Code changes will trigger a live rebuild.
91+
```
92+
npm start
93+
```
94+
95+
4. 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).
96+
97+
## Import
98+
99+
```
100+
import Origin from '@originprotocol/origin'
101+
102+
let configOptions = {}
103+
104+
let { contractService, ipfsService, originService } = new Origin(configOptions)
105+
```
106+
107+
## Configuration Options
108+
109+
Config options are passed into the Origin constructor at instantiation.
110+
111+
```
112+
let configOptions = {
113+
option: 'value'
114+
}
115+
let origin = new Origin(configOptions)
116+
```
117+
118+
Valid options:
119+
- `ipfsDomain`
120+
- `ipfsApiPort`
121+
- `ipfsGatewayPort`
122+
- `ipfsGatewayProtocol`
123+
124+
## IPFS
125+
126+
If you are running a local IPFS daemon then set the following config options ([see config options](#configuration-options)):
127+
128+
```
129+
{
130+
ipfsDomain: '127.0.0.1',
131+
ipfsApiPort: '5001',
132+
ipfsGatewayPort: '8080',
133+
ipfsGatewayProtocol: 'http'
134+
}
135+
```
136+
137+
Configure your local IPFS daemon with the following settings to avoid CORS errors:
138+
139+
```
140+
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["localhost:*"]'
141+
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST", "PUT"]'
142+
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'
143+
```
144+
145+
## Troubleshooting
146+
147+
### Python 3
148+
149+
If you have Python 3 installed, you may see this error when installing dependencies:
150+
151+
```
152+
gyp ERR! stack Error: Python executable "/Users/aiham/.pyenv/shims/python" is v3.6.4, which is not supported by gyp.
153+
```
154+
155+
Resolve this by configuring npm to use Python 2 (where python2.7 is a binary accessible from your $PATH):
156+
157+
```
158+
npm config set python python2.7
159+
```
160+
161+
## Tests
162+
163+
Browser tests are automatically served at `http://localhost:8081` when you run `npm start`.
164+
165+
Tests are automatically rerun when source or test code is changed.
166+
167+
Run a subset of tests using the `grep` query string parameter, for example: http://localhost:8081/?grep=IpfsService
168+
169+
We also have contract unit tests that are not run in the browser. These can be run with `npm run test:contracts` (you should *not* have the server running at this time, as these tests start their own local blockchain instance).
170+
171+
## Documentation
172+
173+
Needed
File renamed without changes.
File renamed without changes.

packages/contracts/contracts/Listing.sol renamed to contracts/contracts/Listing.sol

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
pragma solidity ^0.4.11;
1+
pragma solidity 0.4.21;
22

33
/// @title Listing
44
/// @dev An indiviual Origin Listing representing an offer for booking/purchase
55

66
import "./Purchase.sol";
7+
import "./PurchaseLibrary.sol";
8+
79

810
contract Listing {
911

@@ -12,6 +14,7 @@ contract Listing {
1214
*/
1315

1416
event ListingPurchased(Purchase _purchaseContract);
17+
event ListingChange();
1518

1619
/*
1720
* Storage
@@ -25,6 +28,7 @@ contract Listing {
2528
bytes32 public ipfsHash;
2629
uint public price;
2730
uint public unitsAvailable;
31+
uint public expiration;
2832
Purchase[] public purchases;
2933

3034

@@ -41,14 +45,15 @@ contract Listing {
4145
ipfsHash = _ipfsHash;
4246
price = _price;
4347
unitsAvailable = _unitsAvailable;
48+
expiration = now + 60 days;
4449
}
4550

4651
/*
4752
* Modifiers
4853
*/
4954

5055
modifier isSeller() {
51-
require (msg.sender == owner);
56+
require(msg.sender == owner);
5257
_;
5358
}
5459

@@ -64,10 +69,13 @@ contract Listing {
6469
payable
6570
{
6671
// Ensure that this is not trying to purchase more than is available.
67-
require (_unitsToBuy <= unitsAvailable);
72+
require(_unitsToBuy <= unitsAvailable);
73+
74+
// Ensure that we are not past the expiration
75+
require(now < expiration);
6876

6977
// Create purchase contract
70-
Purchase purchaseContract = new Purchase(this, msg.sender);
78+
Purchase purchaseContract = PurchaseLibrary.newPurchase(this, msg.sender);
7179

7280
// Count units as sold
7381
unitsAvailable -= _unitsToBuy;
@@ -77,7 +85,8 @@ contract Listing {
7785
// TODO STAN: How to call function *AND* transfer value??
7886
purchaseContract.pay.value(msg.value)();
7987

80-
ListingPurchased(purchaseContract);
88+
emit ListingPurchased(purchaseContract);
89+
emit ListingChange();
8190
}
8291

8392
/// @dev close(): Allows a seller to close the listing from further purchases
@@ -86,6 +95,7 @@ contract Listing {
8695
isSeller
8796
{
8897
unitsAvailable = 0;
98+
emit ListingChange();
8999
}
90100

91101
/// @dev purchasesLength(): Return number of listings

0 commit comments

Comments
 (0)