Skip to content

Commit

Permalink
Merge branch 'release/0.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
oimou committed Jun 28, 2018
2 parents b308873 + 4dbe295 commit 46ff58a
Show file tree
Hide file tree
Showing 39 changed files with 12,871 additions and 56 deletions.
73 changes: 18 additions & 55 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,22 @@
# Logs
logs
*.log
.DS_Store
node_modules
/dist
/dist_electron

# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# 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

# nyc test coverage
.nyc_output

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

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

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw*
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright [2018] [Soramitsu Co., Ltd.]

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
89 changes: 89 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Iroha Wallet

[![Iroha 1.0 beta-3](https://img.shields.io/badge/iroha-1.0.0--beta3-e2232d.svg?style=flat-square)](https://github.com/hyperledger/iroha/releases/tag/v1.0.0_beta-3)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://opensource.org/licenses/Apache-2.0)

Iroha Wallet is an example wallet application for [Iroha](http://iroha.readthedocs.io/).
This version is compatible with [Iroha 1.0 beta-3](https://github.com/hyperledger/iroha/releases/tag/v1.0.0_beta-3).

Iroha Wallet has following features:

1. Login with your Iroha account.
2. See your assets and transactions.
3. Transfer your assets to another Iroha account.

![iroha-wallet](https://user-images.githubusercontent.com/1365915/42019575-72e1d60c-7af0-11e8-9a49-8c019548efdc.png)

## Getting Started

### Prerequisites

First, you need to have an Iroha instance working. You can read how to launch it on [Iroha's docs](http://iroha.readthedocs.io/en/latest/getting_started/index.html). In this guide we assume the local Iroha instance working at `localhost:50051`.

Then, populate the database by our example script. The script will create new account `alice@test` and new assets `coolcoin#test` and `hotcoin#test`. Note that there already exist `admin@test`. Their keys are in `example/`.

```
% node example/setup-accounts-and-assets.js
alice@test has successfully been created
coolcoin#test (precision: 2) has successfully been created
hotcoin#test (precision: 5) has successfully been created
```

### Installation

Install npm packages.

```bash
# install dependencies
yarn install

# rebuild native modules for Electron environment
yarn rebuild
```

### Development

Launch an Electron app in development mode.

```bash
yarn serve:electron
```

### Package and build an Electron app

Since Iroha Wallet is built with Electron, you can package an Electron app for distribution. The following command generates installers in `dist_electron/`.

```bash
yarn build:electron
```

See [electron-builder's docs](https://www.electron.build/multi-platform-build) for build options.

## Running the tests

Run unit tests and lint js files.

```bash
# run unit test
yarn test:unit

# lint all JS/Vue component files in `src/`
yarn lint
```

## Technologies

* [Iroha v1.0.0-beta3](http://iroha.readthedocs.io/)
* [Electron 2](https://electronjs.org/)
* [vue-cli 3](https://github.com/vuejs/vue-cli)
* [webpack 4](https://github.com/webpack/webpack)
* [vue-cli-plugin-electron-builder](https://github.com/nklayman/vue-cli-plugin-electron-builder)
* [JavaScript Standard Style](https://github.com/standard/standard)
* [Font Awesome](https://fontawesome.com/)

## License

Iroha Wallet codebase is licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
1 change: 1 addition & 0 deletions example/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0f0ce16d2afbb8eca23c7d8c2724f0c257a800ee2bbd54688cec6b898e3f7e33
1 change: 1 addition & 0 deletions example/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
889f6b881e331be21487db77dcf32c5f8d3d5e8066e78d2feac4239fe91d416f
1 change: 1 addition & 0 deletions example/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9c430dfe8c54b0a447e25f75121119ac3b649c1253bce8420f245e4c104dccd1
1 change: 1 addition & 0 deletions example/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bcc4ab167ae7db371672170ed31e382f7c612fbfe918f99c276cd9dc199446a4
66 changes: 66 additions & 0 deletions example/setup-accounts-and-assets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/* eslint-disable no-unused-vars */
/*
* NODE_IP=localhost:50051 DEBUG=iroha-util node example/setup-accounts-and-assets.js
*/
const fs = require('fs')
const path = require('path')
const iroha = require('iroha-lib')
const irohaUtil = require('../src/util/iroha-util')

const crypto = new iroha.ModelCrypto()
const adminPrivKeyHex = fs.readFileSync(path.join(__dirname, '[email protected]')).toString().trim()
const adminPubKey = crypto.fromPrivateKey(adminPrivKeyHex).publicKey()
const alicePrivKeyHex = fs.readFileSync(path.join(__dirname, '[email protected]')).toString().trim()
const alicePubKey = crypto.fromPrivateKey(alicePrivKeyHex).publicKey()

const nodeIp = process.env.NODE_IP || 'localhost:50051'

irohaUtil.login('admin@test', adminPrivKeyHex, nodeIp)
.then(() => tryToCreateAccount('alice', 'test', alicePubKey))
.then(() => tryToCreateAsset('coolcoin', 'test', 2))
.then(() => tryToCreateAsset('hotcoin', 'test', 5))
.then(() => irohaUtil.addAssetQuantity('admin@test', 'coolcoin#test', '1000.00'))
.then(() => irohaUtil.addAssetQuantity('admin@test', 'hotcoin#test', '1000.00000'))
.then(() => irohaUtil.transferAsset('admin@test', 'alice@test', 'coolcoin#test', 'hi', '0.50'))
.then(() => irohaUtil.transferAsset('admin@test', 'alice@test', 'hotcoin#test', 'hi', '0.50000'))
.catch(err => console.error(err))

function tryToCreateAccount (accountName, domainId, publicKey) {
return new Promise((resolve, reject) => {
irohaUtil.createAccount(accountName, domainId, publicKey)
.then(() => {
console.log(`${accountName}@${domainId} has successfully been created`)
resolve()
})
.catch(err => {
irohaUtil.getAccount(accountName + '@' + domainId)
.then(account => {
console.log(`${account.accountId} already exist`)
resolve()
})
.catch(() => reject(err))
})
})
}

function tryToCreateAsset (assetName, domainId, precision) {
return new Promise((resolve, reject) => {
irohaUtil.createAsset(assetName, domainId, precision)
.then(() => {
console.log(`${assetName}#${domainId} (precision: ${precision}) has successfully been created`)
resolve()
})
.catch(err => {
irohaUtil.getAssetInfo(assetName + '#' + domainId)
.then(info => {
if (info.asset.precision === precision) {
console.log(`${assetName}#${domainId} (precision: ${precision}) already exist`)
resolve()
} else {
reject(new Error(`${assetName}#${domainId} is already used with different precision.`))
}
})
.catch(() => reject(err))
})
})
}
140 changes: 140 additions & 0 deletions example/test-iroha-lib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
/* eslint-disable no-new */
/*
* test iroha-lib directly (without iroha-util)
*/
const fs = require('fs')
const path = require('path')
const iroha = require('iroha-lib')
const grpc = require('grpc')

const endpointGrpc = require('iroha-lib/pb/endpoint_grpc_pb.js')
const queryBuilder = new iroha.ModelQueryBuilder()
const crypto = new iroha.ModelCrypto()

const accountId = 'admin@test'
const assetId = 'coolcoin#test'
const nodeIp = process.env.NODE_IP || 'localhost:50051'

const adminPrivKeyHex = fs.readFileSync(path.join(__dirname, '[email protected]')).toString().trim()
const adminPubKey = crypto.fromPrivateKey(adminPrivKeyHex).publicKey()

const adminKeys = crypto.convertFromExisting(
adminPubKey.hex(),
adminPrivKeyHex
)

/*
* send queries
*/
Promise.resolve()
.then(function () {
console.log('accountId:', accountId)
console.log('assetId:', assetId)
console.log('nodeIp:', nodeIp)
})
.then(
/*
* getAccount
*/
function getAccount () {
return new Promise((resolve, reject) => {
const queryClient = new endpointGrpc.QueryServiceClient(
nodeIp,
grpc.credentials.createInsecure()
)
const query = queryBuilder
.creatorAccountId(accountId)
.createdTime(Date.now())
.queryCounter(1)
.getAccount(accountId)
.build()
const protoQuery = makeProtoQueryWithKeys(query, adminKeys)

queryClient.find(protoQuery, (err, response) => {
if (err) return reject(err)

console.log('\ngetAccount:', JSON.stringify(response.toObject(), null, ' '))

resolve()
})
})
}
)
.then(
/*
* getAccountAssetTransactions
*/
function getAccountAssetTransactions () {
return new Promise((resolve, reject) => {
const queryClient = new endpointGrpc.QueryServiceClient(
nodeIp,
grpc.credentials.createInsecure()
)
const query = queryBuilder
.creatorAccountId(accountId)
.createdTime(Date.now())
.queryCounter(1)
.getAccountAssetTransactions(accountId, assetId)
.build()
const protoQuery = makeProtoQueryWithKeys(query, adminKeys)

queryClient.find(protoQuery, (err, response) => {
if (err) return reject(err)

console.log('\ngetAccountAssetTransactions:', JSON.stringify(response.toObject(), null, ' '))

resolve()
})
})
}
)
.then(
/*
* getAccountTransactions
*/
function getAccountTransactions () {
return new Promise((resolve, reject) => {
const queryClient = new endpointGrpc.QueryServiceClient(
nodeIp,
grpc.credentials.createInsecure()
)
const query = queryBuilder
.creatorAccountId(accountId)
.createdTime(Date.now())
.queryCounter(1)
.getAccountTransactions(accountId)
.build()
const protoQuery = makeProtoQueryWithKeys(query, adminKeys)

queryClient.find(protoQuery, (err, response) => {
if (err) return reject(err)

console.log('\ngetAccountTransactions:', JSON.stringify(response.toObject(), null, ' '))

resolve()
})
})
}
)
.catch(err => console.error(err))

/*
* utilities
*/
function blob2array (blob) {
const bytearray = new Uint8Array(blob.size())
for (let i = 0; i < blob.size(); ++i) {
bytearray[i] = blob.get(i)
}
return bytearray
}

function makeProtoQueryWithKeys (builtQuery, keys) {
const pbQuery = require('iroha-lib/pb/queries_pb.js').Query

const blob = new iroha.ModelProtoQuery(builtQuery).signAndAddSignature(keys).finish().blob()
const arr = blob2array(blob)
const protoQuery = pbQuery.deserializeBinary(arr)

return protoQuery
}
Loading

0 comments on commit 46ff58a

Please sign in to comment.