Git Product home page Git Product logo

estate-sample's Issues

queryByChaincode が offlineでも使えるか調べる

#11 (comment)
でも書いたが、ledgerからデータだけ取得したい場合のofflineの方法がわからない。

  const response = await channel.sendSignedTransaction({
    signedProposal: signedCommitProposal,
    request: commitReq
  })

を使った際のresponseが

{ status: 'SUCCESS', info: '' }

とだけで、データが取得できない。

queryByChaincode は channelからtransaction発行するわけではなさそうなので、こちらを調べてみる

Estate売買実装

Estate購入時のフロー

以下のフローを実現する

  1. buyerが買い申請をsellerに通知
  2. sellerが金額を確認してOKをbuyerに通知
  3. コントラクトが所有権を移転

上記は申請したtransactionのオーナーが、所有者と一致していればOKか?

fabric-ca-client の中身を探る

offlineのtestコードがfabric-ca-client を使っていて、enroll をしているが、adminのpasswordを渡してチャンネルを作成している。
これってoffline署名ということになるのかどうかよくわからず、、、

/**
 * Enroll a registered user in order to receive a signed X509 certificate
 * @param {string} enrollmentID The registered ID to use for enrollment
 * @param {string} enrollmentSecret The secret associated with the enrollment ID
 * @param {string} csr PEM-encoded PKCS#10 certificate signing request
 * @param {string} profile The profile name.  Specify the 'tls' profile for a TLS certificate; otherwise, an enrollment certificate is issued.
 * @param {AttributeRequest[]} attr_reqs An array of {@link AttributeRequest}
 * @returns {Promise} {@link EnrollmentResponse}
 * @throws Will throw an error if all parameters are not provided
 * @throws Will throw an error if calling the enroll API fails for any reason
 */
enroll(enrollmentID, enrollmentSecret, csr, profile, attr_reqs) {

  const self = this;

  // check for required args
  if (arguments.length < 3) {
    return Promise.reject('Missing required parameters.  \'enrollmentID\', \'enrollmentSecret\' and \'csr\' are all required.');
  }

  const requestOptions = {
    hostname: self._hostname,
    port: self._port,
    path: self._baseAPI + 'enroll',
    method: 'POST',
    auth: enrollmentID + ':' + enrollmentSecret,
    ca: self._tlsOptions.trustedRoots,
    rejectUnauthorized: self._tlsOptions.verify
  };

  const enrollRequest = {
    caname: self._caName,
    certificate_request: csr
  };

  if (profile) {
    enrollRequest.profile = profile;
  }

  if (attr_reqs) {
    enrollRequest.attr_reqs = attr_reqs;
  }

  return new Promise(((resolve, reject) => {

    const request = self._httpClient.request(requestOptions, (response) => {

      const responseBody = [];
      response.on('data', (chunk) => {
        responseBody.push(chunk);
      });

      response.on('end', (data) => {

        const payload = responseBody.join('');

        if (!payload) {
          return reject(new Error(
            util.format('Enrollment failed with HTTP status code', response.statusCode)));
        }
        // response should be JSON
        try {
          const res = JSON.parse(payload);
          if (res.success) {
            // we want the result field which is Base64-encoded PEM
            const enrollResponse = new Object();
            // Cert field is Base64-encoded PEM
            enrollResponse.enrollmentCert = Buffer.from(res.result.Cert, 'base64').toString();
            enrollResponse.caCertChain = Buffer.from(res.result.ServerInfo.CAChain, 'base64').toString();
            return resolve(enrollResponse);
          } else {
            return reject(new Error(
              util.format('Enrollment failed with errors [%s]', JSON.stringify(res.errors))));
          }

        } catch (err) {
          return reject(new Error(
            util.format('Could not parse enrollment response [%s] as JSON due to error [%s]', payload, err)));
        }
      });

      response.on('error', (error) => {
        reject(new Error(
          util.format('Enrollment failed with error [%s]', error)));
      });
    });

    request.on('error', (err) => {
      reject(new Error(util.format('Calling enrollment endpoint failed with error [%s]', err)));
    });

    const body = JSON.stringify(enrollRequest);
    request.end(body);

  }));

}

起動用script作成

reset_hyper.sh

docker stop $(docker ps -q)
docker rm $(docker ps -aq)
CONTRACT_IMAGE=$(docker images | grep 'dev-peer0.org1.example.com-estatecontract' | awk '{print $3}')
echo $CONTRACT_IMAGE
docker rmi $CONTRACT_IMAGE

start_monitor_fabric.sh

#!/bin/bash

cd /Users/shohu33/sc/estate-sample/basic-network
./start.sh

cd ../estate/configuration/cli/
./monitordocker.sh net_basic

update_fabric_code.sh

#!/bin/bash

docker exec cliMagnetoCorp peer chaincode install -n estatecontract -v $1 -p /opt/gopath/src/github.com/contract -l node

docker exec cliMagnetoCorp peer chaincode upgrade -n estatecontract -v $1 -l node -c '{"Args":["org.estatenet.estate:instantiate"]}' -C mychannel -P "AND ('Org1MSP.member')"

要件定義

所有権の移転関係のブロックチェーンシステムのプロトタイプをhyperlegderで作る。
sampleを改造して、1つ追加する。

プロトタイプ要件定義

  • 証券が作れて
  • 証券が買えて
  • 証券の分配
  • 証券の所有ログがみれて(あとで登記関係に使えそうなため
  • 所有権移転ができること
  • depositができること

開発方針の決定

server レンダリングタイプでサイト構築する。

スクリーンショット 2019-06-05 9 58 32

nodeのフレームワークは AdonisJs を使用

nodeのフレームワーク選定

今回、hyperledger fabric側のsampleがjsファイルを参考にしているうため、連携しやすいようにnodeで簡単なサイトを作ることにした。

差し当たって以下のようなイメージなので、node の フレームワークを選定する

スクリーンショット 2019-06-05 9 58 32

Node.js が使えるクライアントアプリを見つけてfabric libを使う

デスクトップアプリ編

5 Best JavaScript Frameworks for Desktop Apps

  1. Electron
  2. NW.js
     JavaScriptを用いてWindows上で動作するアプリケーションを実装できるフレームワーク
     NW.jsでデスクトップアプリの夢を見る!
  3. AppJS
  4. Meteor
  5. Proton Native
     react に似せて作られているとのこと。これがよさそうか?

Mobile アプリ編

TOP JAVASCRIPT FRAMEWORKS FOR NATIVE MOBILE APPS 2019

  1. ReactNative
     node の core 使えない

fabricのロールバック処理対応

Estateを作成してから、Historyを作成する場合にどちらか1つでも失敗した場合にロールバックしたい。
ただ、couchdbだとロールバックできないようだ。

ロールバックにあたる処理を実装するか?
それとも設計がそもそもおかしいのか?

を検討する

chainnodeを動かす

chainnodeの雛形ができたので、実際にestateを登録するところまでやってみる

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.