입력 사양 파일

Blockchain App Builder 초기화 명령은 입력 사양 파일을 읽고 체인 코드 개발 프로세스를 지원하는 여러 가지 도구를 사용하여 스캐폴드 프로젝트를 생성합니다.

사양 파일을 사용하여 여러 자산 정의 및 동작, CRUD 및 비CRUD 메소드 선언, 사용자 정의 메소드, 인수 검증, 자동 마셜링/마셜링 해제, 투명한 지속성 기능 및 SQL SELECT 또는 CouchDB Query Language를 사용하여 다양한 데이터 질의를 호출할 수 있습니다. 이러한 기능은 자동으로 생성됩니다.

사양 파일은 yaml 또는 json에 기록할 수 있습니다. Blockchain App Builder 패키지 다운로드에서 두 가지 형식으로 샘플 사양 파일을 볼 수 있습니다.
  • Fabcar-Typescript.yml
  • Marbles-Go.yml

주:

Go 규칙에 따라 내보낸 이름은 대문자로 시작합니다. 따라서 모든 자산 속성 및 메소드의 이름은 사양 파일에서 대문자로 시작해야 합니다.

사양 파일 구조

일반적으로 다음과 같은 방법으로 사양 파일을 구성합니다.

assets: 
    name:
    type:
    properties:
        name:
        type:
        id:
        derived:
           strategy:
           algorithm:
           format:
        mandatory:
        default:
        validate:
    methods:
        crud:
        others:
customMethods:

Blockchain App Builder는 지정된 유형이 없는 일반 자산 외에도 포함된 자산과 토큰 자산의 두 가지 특수 자산 유형을 지원합니다. 특수 자산은 사양 파일의 assets: 섹션 아래에 type: embedded 또는 type: token로 정의됩니다.

표 7-2 사양 파일 매개변수 설명 및 예

항목 설명
assets:

이 속성은 자산의 정의 및 동작을 가져옵니다. 여기에서 여러 자산 정의를 지정할 수 있습니다.

 
name:

자산 이름입니다.

예약된 이름은 다음과 같습니다. 자산에는 이러한 이름을 사용하지 마십시오.
  • account
  • role
  • hold
  • token
  • authorization
  • tokenAdmin
  • Account
  • Role
  • Hold
  • Token
  • Authorization
  • TokenAdmin
name: owner # Information about the owner
type:

자산 유형

다음 특수 자산 유형이 지원됩니다.
  • embedded
  • token

assets 섹션에서 type 매개변수를 지정하지 않으면 자산이 일반 유형입니다.

 
type:

유형: 임베디드

이 속성을 embedded로 설정하면 자산이 포함된 자산으로 정의됩니다. 포함된 자산에는 CRUD 방법이 없으며 원장에 저장하기 위해 다른 자산의 일부여야 합니다.

예제에서는 address 속성이 포함되고 다른 자산에 정의됩니다.

포함된 자산은 순환 참조를 지원하지 않습니다. 예를 들어, 이전 예에서 address 자산은 employee 자산에 대한 참조를 포함할 수 없습니다.

자산: employee
name: employee
  properties:
     name: employeeId
     type: string
     mandatory: true
     id: true

     name: firstName
     type: string
     validate: max(30)
     mandatory: true

     name: lastName
     type: string
     validate: max(30)
     mandatory: true

     name: age
     type: number
     validate: positive(),min(18)

     name: address
     type: address
자산: address
name: address

type: embedded

properties:
   name: street
   type: string

   name: city
   type: string

   name: state
   type: string

   name: country
   type: string
properties:

자산의 모든 속성을 기술합니다.

 
name:

속성의 이름입니다.

name: ownerId # Unique ID for each owner
id:
  • true

이 자산의 식별자를 지정합니다. 필수 등록 정보입니다.

name: owner            # Information about the owner
properties:
     name: ownerId    # Unique ID for each owner
     type: string
     mandatory: true
     id: true
     name: name        # Name of the owner
     type: string
     mandatory: true
type:

속성 유형

다음 기본 등록 정보 유형이 지원됩니다.
  • number
  • float
  • string
  • boolean
  • date
  • array
Go 체인 코드의 경우 numberint에 매핑되고 floatfloat64에 매핑됩니다. 다음 유형을 비롯한 기타 유형은 현재 지원되지 않습니다.
  • complex
  • unsigned/signed int
  • 8/16/32/64 bits
name: year        # Model year
                    type: number
                    mandatory: true
                    validate: min(1910),max(2020)
                    name: color       # Color - no validation as color names are innumerable
                    type: string
                    mandatory: true
derived:

이 등록 정보는 id 등록 정보가 다른 키에서 파생되도록 지정합니다. 종속 속성은 포함된 자산이 아닌 string 데이터 유형이어야 합니다.

이 등록 정보에는 두 가지 필수 매개변수가 있습니다.
  • strategy: concat 또는 hash 값을 사용합니다.
  • format: 전략에서 사용할 사양 문자열 및 값 배열을 사용합니다.
예 1:
  • employeeID 속성은 firstNamelastName 속성에 종속됩니다.
  • 이 등록 정보는 format 배열에 나열된 값의 연결입니다.
  • IND%1#%2%tIND는 배열의 0번째 인덱스이며 최종 형식을 설명합니다.
  • %n는 배열의 다른 인덱스에서 해당 값을 가져오는 위치 지정자입니다.
  • %t는 채널 헤더에서 값이 stub.timestamp여야 함을 나타냅니다.
  • format 문자열에서 % 문자를 사용해야 하는 경우 다른 %로 이스케이프 처리해야 합니다.
  • 이 예제의 마지막 형식은 INDfirstName#lastName1606885454916IND입니다.
예 2:
  • hash를 사용할 때는 algorithm 매개변수도 사용해야 합니다. 기본값은 sha256이고 md5도 지원됩니다.
  • IND%1#%2%t는 배열의 0번째 인덱스이며 최종 형식을 설명합니다.
  • %n는 배열의 다른 인덱스에서 해당 값을 가져오는 위치 지정자입니다.
  • %t는 채널 헤더에서 값이 stub.timestamp여야 함을 나타냅니다.
  • format 문자열에서 % 문자를 사용해야 하는 경우 다른 %로 이스케이프 처리해야 합니다.
예제 1
name: employee
  properties:
     name: employeeId
     type: string
     mandatory: true
     id: true
     derived:
         strategy: concat
         format: ["IND%1#%2%tIND","firstName","lastName"]

     name: firstName
     type: string
     validate: max(30)
     mandatory: true

     name: lastName
     type: string
     validate: max(30)
     mandatory: true

     name: age
     type: number
     validate: positive(),min(18)
예제 2
name: account
  properties:
     name: accountId
     type: string
     mandatory: true
     id: true
     derived:
         strategy: hash
         algorithm: 'sha256'
         format: ["IND%1#%2%t","bankName","ifsccode"]

     name: bankName
     type: string
     validate: max(30)
     mandatory: true

     name: ifsccode
     type: string
     mandatory: true
mandatory:
  • true
  • false

해당 속성은 필수이며 자산을 생성하는 동안 건너뛸 수 없습니다.

name: phone       # Phone number - validate as (ddd)-ddd-dddd where dashes could also be periods or spaces
type: string
mandatory: true
validate: /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
name: cars        # The list of car VINs owned by this owner
type: string[]
mandatory: false
default:

그러면 이 등록 정보의 기본값이 제공됩니다.

 
validate:

제공된 속성은 Blockchain App Builder에서 제공하는 몇 가지 미리 정의된 검증에 대해 검증됩니다. 체인이 유효한지 확인하는 경우 검증을 체인화할 수 있습니다.

validate 등록 정보가 제공되지 않은 경우 type 등록 정보에 대해서만 검증이 수행됩니다.

 
validate:

유형: 숫자

  • 긍정적()
  • 부정적()
  • min()
  • max()

이러한 검증은 콤마로 구분하여 함께 체인화할 수 있습니다.

name: offerApplied
type: number
validate: negative(),min(-4)
name: year  # Model year
type: number
mandatory: true
validate: min(1910),max(2020)
validate:

유형: 문자열

  • min()
  • max()
  • email()
  • url()
  • /regex/ - PHP 정규 표현식 지원

Go 체인코드의 경우 예약된 특정 문자 또는 공백 문자를 포함하는 정규 표현식이 제대로 이스케이프되어야 합니다.

name: website 
type: string
mandatory: false
validate: url()
name: phone  # Phone number - validate as (ddd)-ddd-dddd where dashes could also be periods or spaces
type: string
mandatory: true
validate: /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/
name: Color #Color can be red, blue, or green
type: string
mandatory: true
validate: /^\\s*(red|blue|green)\\s*$/
validate:

유형: 부울

  • true
  • false

예제에서 active 등록 정보의 검증은 유형 자체(boolean)를 기준으로 합니다.

name: active
type: boolean
validate:

유형: 배열

유형 자체에 따라 type: number[] 형식으로 배열이 숫자 유형임을 나타냅니다.

배열에 대한 제한을 number[1:5] 형식으로 입력할 수 있습니다. 이는 최소 길이가 1이고 최대 길이가 5임을 의미합니다. 둘 중 하나를 사용하지 않으면 최소/최대만 고려됩니다.

name: items
type: number[:5]
validate:

유형: 날짜

  • min()
  • max()
날짜는 다음 형식 중 하나여야 합니다.
  • YYYY-MM-DD
  • YYYY-MM-DDTHH:MM:SSZ - 여기서 T는 날짜와 시간을 구분하고 Z는 UTC를 나타냅니다. 시간대 오프셋은 Central Daylight Savings Time에 대해 -05:00과 같이 Z를 대체할 수 있습니다.
name: expiryDate
type: date
validate: max('2020-06-26')
name: completionDate
type: date
validate: min('2020-06-26T02:30:55Z')
methods:

생성할 CRUD(생성/읽기/업데이트/삭제) 또는 추가 메소드를 나타내는 데 사용합니다.

기본적으로 아무것도 입력하지 않으면 모든 CRUD 및 기타 메소드가 생성됩니다.

methods:
    crud: [create, getById, update, delete]
    others: [getHistoryById, getByRange]
crud:
  • create
  • getByID(읽기)
  • update
  • delete

이 배열을 비워 두면 CRUD 메소드가 생성되지 않습니다.

crud 매개변수를 전혀 사용하지 않으면 네 개의 메소드가 모두 기본적으로 생성됩니다.

crud 매개변수는 tokenembedded 자산에 적용할 수 없습니다.

methods:
    crud: [create, getById, delete]
    others: [] # no other methods will be created
others:
  • getHistoryById
  • getByRange

getHistoryById는 목록에 있는 자산의 내역을 반환합니다.

getByRange는 지정된 범위의 모든 자산을 반환합니다. 자세한 내용은 "getByRange"(TypeScript) 및 "GetByRange"(실행)을 참조하십시오.

이 배열을 비워 두면 다른 메소드가 생성되지 않습니다.

others 매개변수를 전혀 사용하지 않으면 두 메소드가 기본적으로 생성됩니다.

others 매개변수는 tokenembedded 자산에 적용할 수 없습니다.

methods:
    crud: [create, delete]
    others: [] # no other methods will be created
      methods:
        crud: [create, getById, update, delete]
        others: [getHistoryById, getByRange]
customMethods:

이 등록 정보는 기본 컨트롤러 파일에 호출 가능한 사용자 정의 메소드 템플리트를 만듭니다. 이 메소드는 메소드 서명을 가져와서 컨트롤러 파일에 함수 선언을 생성합니다.

여기서 언어별 함수 선언을 제공할 수 있습니다.

executeQuery라는 사용자 정의 메소드를 제공합니다. 사양 파일에 추가된 경우 Berkeley DB SQL 및 CouchDB 서식 있는 쿼리를 실행하는 방법에 대해 자세히 설명합니다. 이 메소드는 Oracle Blockchain Platform Cloud 또는 Enterprise Edition에 접속된 경우에만 호출할 수 있습니다.

TypeScript

customMethods:
    - executeQuery
    - "buyCar(vin: string, buyerId: string, sellerId: string, price: number, date: Date)"
    - "addCar(vin: string, dealerId: string, price: number, date: Date)"

실행

customMethods:
    - executeQuery
    - "BuyCar(vin string, buyerId string, sellerId string, price int)"
    - "AddCar(vin string, dealerId string, price int)"