Blockchain (Hyperledger Fabric)/작업 중인 Solution

Hyperledger Composer Logic(Transaction 수행) Ver. 0.0.1

김야키 2019. 2. 22. 18:58

Logic(Transaction 수행 작업) 설정


작성일자 2019.02.22

Ver 0.0.1

/* * 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. */ 'use strict'; /** * @param {org.example.mynetwork.SendMoney} sendMoney * @transaction */ async function sendMoney(tx) { // 트랜잭션에 정의되는 학과 정보 const duesMajor = tx.dues.inmajor;             // 학과 명 const duesMoney = tx.dues.duesMoney;      // 학회비 // 트랜잭션에 정의되는 학생들 (일반 학생, 회계) const normalStd = tx.normal;            // 일반 학생 const accoutantStd = tx.accoutant;     // 회계 // 일반 학생과 회계의 소지 금액 정보 const fromStdMoney = normalStd.money     // 보내는 학생 (일반 학생) const toStdMoney = accoutantStd.money     // 받는 학생 (회계) // 일반 학생과 회계의 학과 정보 const fromStdMajor = normalStd.major;     // 보내는 학생의 학과 const toStdMajor = accoutantStd.major;     // 받는 학생의 학과 /** * 1번째 조건 * 1-1 학회비를 내는 학생의 학과와 회계의 학과 일치 여부 * 1-2 회계의 학과와 위에서 정의한 학회비가 포함된 정보의 학과 일치 여부 */ if (fromStdMajor == toStdMajor && toStdMajor == duesMajor) { // 2번째 조건 학회비를 보내는 학행의 소지 금액이 학과별로 정의된 학회비 보다 더 많은지 검사 /** * 해당 조건이 필요 없어지는 경우 * 1) 회원가입 시에 소지금액을 입력하는 것이 필요 없을 경우가 있음 * 2) 돈을 주고 받는 정보만 기록하면 되기 때문에 초기 금액이 얼마인지 알 필요가 없을 경우 */ if (fromStdMoney >= duesMoney) { // 3번째 조건 2중 납부 방지를 위해서 학회비를 납부하는 학생의 납부 여부를 검사 if (normalStd.state) { // 납부 학생의 상태 변경 tx.normal.state = false; // 납부 학생의 소지금액을 학회비 만큼 감소 tx.normal.money = fromStdMoney - duesMoney; // 회계의 소지 금액에 학회비 만큼 증가 tx.accoutant.money = toStdMoney + duesMoney; // 해당 네임 스페이스에서 Participant에 저장되어 있는 정보를 가져옴 const participantRegistry = await getParticipantRegistry('org.example.mynetwork.Student'); // Transaction에서 선언된 normal의 정보 업데이트 await participantRegistry.update(tx.normal); // Transaction에서 선언된 accoutant의 정보 업데이트 await participantRegistry.update(tx.accoutant); // 거래 정보 업데이트 완료 return 'Success'; } else { // 2중 납부가 발생하는 경우 return 'Fail'; } } else { // 학과별로 정의된 학회비보다 소지금액이 적은 경우 return 'Fail'; } } else { // 학과 정보가 일치하지 않음 return 'Fail'; } }


ISSUES

  1. 해당 학과의 정보가 일치하는지 확인 X
  2. 현제 Transaction에서 Event설정이 없음
  3. 모델링과 마찬가지로 한 학교의 학과들을 기준으로 두는것이 아닌 일반 사용자들을 기준으로 두면 다시 수정해야 함