토큰 분류 프레임워크에 대한 비계획 Go 프로젝트

Blockchain App Builder는 토큰 사양 파일에서 입력을 가져와 완전한 기능을 갖춘 비계 체인 코드 프로젝트를 생성합니다.

프로젝트는 CRUD 및 비CRUD 메서드를 포함한 토큰 수명 주기 클래스 및 함수를 자동으로 생성합니다. 인수 검증, 마셜링/마셜링 해제 및 투명한 지속성 기능은 모두 자동으로 지원됩니다.

비계 프로젝트 및 토큰과 직접 관련되지 않은 방법에 대한 자세한 내용은 비계 Go Chaincode Project를 참조하십시오.

모델

Transparent Persistence Capability 또는 단순화된 ORM은 OchainModel 클래스에서 캡처됩니다.

package src
type Digicur struct {
    AssetType               string                 `json:"AssetType" final:"otoken"`
    Token_id                string                 `json:"Token_id" id:"true" mandatory:"true" validate:"regexp=^[A-Za-z0-9][A-Za-z0-9_-]*$,max=16"`
    Token_name              string                 `json:"Token_name" final:"digicur"`
    Token_desc              string                 `json:"Token_desc" validate:"max=256"`
    Token_type              string                 `json:"Token_type" final:"fungible" validate:"regexp=^fungible$"`
    Behavior                []string               `json:"Behavior" final:"[\"divisible\",\"mintable\",\"transferable\",\"burnable\",\"holdable\",\"roles\"]"`
    Roles                   map[string]interface{} `json:"Roles" final:"{\"minter_role_name\":\"minter\",\"burner_role_name\":\"burner\",\"notary_role_name\":\"notary\"}"`
    Mintable                map[string]interface{} `json:"Mintable" final:"{\"Max_mint_quantity\":20000}"`
    Divisible               map[string]interface{} `json:"Divisible" final:"{\"Decimal\":1}"`
    Token_to_currency_ratio int                    `json:"Token_to_currency_ratio" validate:"int"`
    Currency_representation string                 `json:"Currency_representation" validate:"string"`
    Metadata                interface{}            `json:"Metadata,omitempty"`
}

제어 장치

하나의 주 컨트롤러만 있습니다.

type Controller struct {
    Ctx trxcontext.TrxContext
}

클래스, 함수 또는 파일을 원하는 만큼 만들 수 있지만 주 컨트롤러 클래스 내에 정의된 메소드만 호출할 수 있습니다. 다른 방법은 숨겨져 있습니다.

토큰 SDK 메소드를 사용하여 비즈니스 애플리케이션에 대한 사용자정의 메소드를 작성할 수 있습니다.

사용자 정의 메소드에 둘 이상의 토큰 SDK 메소드를 사용하는 경우 상태 데이터베이스의 동일한 키-값 쌍에 영향을 주는 메소드를 사용하지 마십시오.

대신 다음 코드 조각에 표시된 것처럼 BulkTransferTokens 메소드를 사용하여 호출자의 계정에서 여러 계정으로 이전하십시오.

BulkTransferTokens(token_id string, flow: []map[string]interface{})

주:

상태 데이터베이스의 동일한 키-값 쌍에 영향을 줄 수 있는 사용자정의 메소드에 둘 이상의 토큰 SDK 메소드를 사용하는 경우 토큰 체인코드에 대해 MVCC 최적화를 사용으로 설정합니다. 자세한 내용은 MVCC Optimization을 참조하십시오.

자동으로 생성된 토큰 메소드

Blockchain App Builder는 토큰 및 토큰 수명 주기를 지원하는 방법을 자동으로 생성합니다. 이러한 방법을 사용하면 추가 코딩 없이 토큰을 초기화하고, 역할 및 계정을 관리하고, 기타 토큰 수명 주기 작업을 완료할 수 있습니다. 컨트롤러 메소드를 호출하려면 공용이어야 합니다. 공용 메소드 이름은 대문자로 시작합니다. 소문자로 시작하는 메소드 이름은 전용입니다.

액세스 제어 관리 방법

AddTokenAdmin
이 메소드는 사용자를 체인 코드의 Token Admin로 추가합니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
func (t *Controller) AddTokenAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.AddAdmin", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.AddTokenAdmin(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 체인 코드의 Token Admin로 추가된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{
    "msg": "Successfully added Token Admin (Org_Id: Org1MSP, User_Id: user1)"
}
RemoveTokenAdmin
이 메소드는 사용자를 체인 코드의 Token Admin로 제거합니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
func (t *Controller) RemoveTokenAdmin(org_id string, user_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Admin.RemoveAdmin", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Admin.RemoveAdmin(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 체인 코드의 Token Admin로 제거된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{"msg":"Successfuly removed Admin (Org_Id Org1MSP User_Id user1)"}
IsTokenAdmin
이 메소드는 함수 호출자가 Token Admin인 경우 부울 값 true를 반환하고, 그렇지 않은 경우 false를 반환합니다. Token Admin 또는 Org Admin는 블록체인 네트워크의 다른 사용자에 대해 이 기능을 호출할 수 있습니다. 다른 사용자는 자신의 계정에서만 이 메소드를 호출할 수 있습니다.
func (t *Controller) IsTokenAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.IsTokenAdmin", "TOKEN", map[string]string{"org_id": org_id, "user_id": user_id})
      if err != nil || !auth {
            return false, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Auth.IsUserTokenAdmin(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 호출자가 Token Admin인 경우 이 메소드는 true를 반환하고, 그렇지 않은 경우 false를 반환합니다.
반환 값 예제:
{"result":false}
GetAllTokenAdmins
이 메소드는 체인 코드의 Token Admin인 모든 사용자 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetAllTokenAdmins() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Admin.GetAllAdmins", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Admin.GetAllAdmins()
}
매개변수:
  • 없음
반환값:
  • 성공 시 OrgIdUserId 객체를 포함하는 JSON 관리자 목록입니다.
반환 값 예제:
{"admins":[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user2"}]}
AddOrgAdmin
이 방법은 사용자를 조직의 Org Admin로 추가합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) AddOrgAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.AddOrgAdmin", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.AddOrgAdmin(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 조직의 Org Admin로 추가된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
RemoveOrgAdmin
이 방법은 조직의 Org Admin인 사용자를 제거합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) RemoveOrgAdmin(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.RemoveOrgAdmin", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.RemoveOrgAdmin(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 조직의 Org Admin로 제거된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{
    "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
GetOrgAdmins
이 메소드는 조직의 Org Admin인 모든 사용자 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetOrgAdmins() (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Admin.GetOrgAdmins", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Admin.GetAllOrgAdmins()
}
매개변수:
  • 없음
반환값:
  • 성공 시 OrgIdUserId 객체를 포함하는 JSON 목록입니다.
반환 값 예제:
{
    "admins": [
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin1"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin2"
        }
    ]
}

토큰 구성 관리 방법

Init
이 메소드는 체인 코드가 배치될 때 호출됩니다. 모든 Token Admin는 필수 adminList 매개변수에 있는 user_idorg_id 정보로 식별됩니다. user_id는 인스턴스 소유자 또는 인스턴스에 로그인한 사용자의 사용자 이름 또는 전자메일 ID입니다. org_id는 현재 네트워크 조직에 있는 사용자의 MSP(멤버쉽 서비스 제공자) ID입니다.
Token Admin 사용자는 AddTokenAdminRemoveTokenAdmin 메소드를 호출하여 다른 Token Admin 사용자를 추가 및 제거할 수 있습니다.
func (t *Controller) Init(adminList []admin.TokenAdminAsset) (interface{}, error) {
    list, err := t.Ctx.Admin.InitAdmin(adminList)
    if err != nil {
        return nil, fmt.Errorf("initializing admin list failed %s", err.Error())
    }
    return list, nil
}
매개변수:
  • adminList array - 토큰 관리자 목록을 지정하는 {user_id, org_id} 정보의 배열입니다. adminList 배열은 필수 매개변수입니다.
매개변수 예(Mac OSX 및 Linux CLI):
'[{"user_id":"userid", "org_id":"OrgMSPId"}]'
매개변수 예(Microsoft Windows CLI):
"[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"
매개변수 예, Oracle Blockchain Platform 콘솔:
["[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"]
Initialize<Token Name>Token
이 메소드는 토큰을 생성하고 토큰 속성을 초기화합니다. 자산 및 해당 속성은 상태 데이터베이스에 저장됩니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
func (t *Controller) InitializeDigicurToken(asset Digicur) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Save", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.Save(&asset)
}
매개변수:
  • asset <Token Class> - 토큰 자산이 이 메소드에 매개변수로 전달됩니다. 토큰 자산의 속성은 모델 파일에 설명되어 있습니다.
반환값:
  • 성공 시 생성된 토큰 자산의 JSON 표현입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
Update<Token Name>Token
이 메소드는 토큰 속성을 업데이트합니다. 토큰 자산이 생성된 후에는 token_desc 속성 및 사용자정의 속성만 업데이트할 수 있습니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
func (t *Controller) UpdateDigicurToken(asset Digicur) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Update", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.Update(&asset)
}
매개변수:
  • asset <Token Class> - 토큰 자산이 이 메소드에 매개변수로 전달됩니다. 토큰 자산의 속성은 모델 파일에 설명되어 있습니다.
반환값:
  • 성공 시 토큰 자산의 업데이트된 JSON 표현입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetTokenDecimals
이 메소드는 소수 토큰에 대해 구성된 소수 자릿수를 반환합니다. 토큰에 대해 divisible 동작이 지정되지 않은 경우 기본값은 0입니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetTokenDecimals(token_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokenDecimals", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    tokenDecimal, err := t.Ctx.Token.GetTokenDecimals(token_id)
    if err != nil {
        return nil, fmt.Errorf("Error in GetTokenDecimals %s", err.Error())
    }
    response := make(map[string]interface{})
    response["msg"] = fmt.Sprintf("Token Id: %s has %d decimal places.", token_id, tokenDecimal)
    return response, nil
}
매개변수:
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 토큰 소수점 자릿수를 보여주는 JSON 문자열입니다.
반환 값 예제:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
GetTokenById
이 메소드는 상태 데이터베이스에 토큰 객체가 있는 경우 해당 객체를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetTokenById(token_id string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.Get", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    tokenAsset, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return tokenAsset.Interface(), err
}
매개변수:
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 토큰 자산을 나타내는 JSON 객체입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetTokenHistory
이 메소드는 지정된 토큰 ID에 대한 토큰 내역을 반환합니다. 모든 사용자가 이 메소드를 호출할 수 있습니다.
func (t *Controller) GetTokenHistory(token_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokenHistory", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.History(token_id)
}
매개변수:
  • tokenId: string - 토큰의 ID입니다.
반환값:
  • 성공 시 토큰 내역을 나타내는 JSON 객체입니다.
반환 값 예제:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:46:33Z",
        "TxId": "12333b8a4f63aa9b3a34072efcbd7df546c6d1e7d82a7a9596e899383656d6f7",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "updated description",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:04:25Z",
        "TxId": "99702e2dad7554a5ee4716a0d01d3e394cbce39bea8bade265d8911f30ebad0b",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetAllTokens
이 메소드는 상태 데이터베이스에 저장된 모든 토큰을 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetAllTokens() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetAllTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Token.GetAllTokens()
}
매개변수:
  • 없음
반환값:
  • 성공 시 모든 토큰 자산을 나타내는 JSON 객체입니다.
반환 값 예제:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 2,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetTokensByName
이 메소드는 지정된 이름을 가진 모든 토큰 객체를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다. 이 방법은 Berkeley DB SQL 서식 있는 쿼리를 사용하며 원격 Oracle Blockchain Platform 네트워크에 연결된 경우에만 호출할 수 있습니다.
func (t *Controller) GetTokensByName(token_name string) (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTokensByName", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Token.GetTokensByName(token_name)
}
매개변수:
  • token_name string - 검색할 토큰의 이름입니다. 이름은 사양 파일의 Token_name 속성에 해당합니다. 값은 토큰의 클래스 이름입니다.
반환값:
  • 성공 시 이름과 일치하는 모든 토큰 자산의 JSON 객체입니다.
반환 값 예제:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "key": "obp2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "",
            "Token_id": "obp2",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]

계정 관리 방법

CreateAccount
이 메소드는 지정된 사용자 및 토큰에 대한 계정을 생성합니다. 언제든지 토큰을 보유할 모든 사용자에 대해 계정을 만들어야 합니다. 계정은 잔액, 보류 잔액 및 거래 내역을 추적합니다. 계정 ID는 영숫자 문자 집합으로, 앞에 oaccount~<token asset name>~이 붙고 그 뒤에 인스턴스 소유자의 사용자 이름 또는 전자 메일 ID(user_id) 해시 또는 인스턴스에 로그인한 사용자, 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자 ID(org_id)가 붙습니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
unc (t *Controller) CreateAccount(org_id string, user_id string, token_type string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.CreateAccount", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.CreateAccount(org_id, user_id, token_type)
}
매개변수:
  • org_id: string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id: string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • token_type: string - 토큰의 유형으로, fungible여야 합니다.
반환값:
  • 성공 시 생성된 계정의 JSON 객체입니다. BapAccountVersion 매개변수는 계정 객체에서 내부용으로 정의됩니다.
반환 값 예제:
{ 
   "AssetType":"oaccount",
   "AccountId":"oaccount~a73085a385bc96c4a45aa2dff032e7dede82c0664dee5f396b7c5854eeafd4bd",
   "BapAccountVersion": 0,
   "UserId":"user1",
   "OrgId":"Org1MSP",
   "AccountType":"fungible",
   "TokenId":"",
   "TokenName":"",
   "Balance":0,
   "BalanceOnHold":0
}
AssociateTokenToAccount
이 방법은 대체 가능한 토큰을 계정과 연관시킵니다. 이 메소드는 체인 코드의 Token Admin 또는 관련 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) AssociateTokenToAccount(account_id string, token_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.AssociateToken", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.AssociateToken(account_id, token_id)
}
매개변수:
  • account_id string - 계정의 ID입니다.
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 업데이트된 계정의 JSON 객체입니다. BapAccountVersion 매개변수는 계정 객체에서 내부용으로 정의됩니다.
반환 값 예제:
{ 
"AssetType":"oaccount", 
"AccountId":"oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb", 
"BapAccountVersion": 0,
"UserId":"admin", 
"OrgId":"Org1MSP", 
"AccountType":"fungible", 
"TokenId":"token1", 
"TokenName":"loyaltok", 
"Balance":0, 
"BalanceOnHold":0 
}
GetAccount
이 메소드는 지정된 사용자 및 토큰에 대한 계정 세부정보를 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) GetAccount(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccount", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAccountWithStatus(account_id)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 다음 속성을 포함하는 JSON 계정 객체:
  • AccountId - 사용자 계정의 ID입니다.
  • UserId - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • OrgId - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • TokenId - 토큰의 ID입니다.
  • Balance - 계정의 현재 잔액입니다.
  • BalanceOnHold - 계정의 현재 보류 중인 잔액입니다.
  • BapAccountVersion - 내부용 계정 객체 매개변수입니다.
  • Status - 사용자 계정의 현재 상태입니다.
반환 값 예제:
{
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 95,
  "BalanceOnHold": 0,
  "BapAccountVersion": 8,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "obp1",
  "TokenName": "obptok",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAccountHistory
이 메소드는 지정된 사용자 및 토큰에 대한 계정 내역 세부정보를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) GetAccountHistory(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.History", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.History(account_id)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 다음 속성을 포함하는 JSON 계정 객체 배열입니다.
  • TxId - 원장에서 반환된 트랜잭션의 트랜잭션 ID입니다.
  • Timestamp - 트랜잭션의 시간입니다.
  • IsDelete - 레코드가 삭제되었는지 여부를 나타내는 부울 값입니다.
  • Value - 계정 객체의 JSON 문자열입니다. BapAccountVersion 매개변수는 계정 객체에서 내부용으로 정의됩니다.
반환 값 예제:
[
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:31:15Z",
      "TxId": "adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 100,
          "BalanceOnHold": 0,
          "BapAccountVersion": 1,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:30:23Z",
      "TxId": "8fbeda2ba60ba175091faae5ae369247775f2cba45c4d6d1ead6f0b05be84743",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:29:54Z",
      "TxId": "19bb296ae71709e91b097ba5d9ebd7f7522095880382fbf5913334a46a6026aa",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "",
          "TokenName": "",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  }
]
GetAccountOnHoldBalance
이 메소드는 지정된 계정 및 토큰에 대한 현재 보류 중 잔액을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) GetAccountOnHoldBalance(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountOnHoldBalance", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      response, err := t.Ctx.Account.GetAccountOnHoldBalance(account_id)
      return response, err
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 현재 보류 중인 잔액에 대한 JSON 표현입니다.
반환 값 예제:
{
    "holding_balance": 0,
    "msg": "Total Holding Balance of Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id: Org1MSP, user_id: user1) is 0"
}
GetAllAccounts
이 메소드는 모든 계정 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다. 이 방법은 Berkeley DB SQL 서식 있는 쿼리를 사용하며 원격 Oracle Blockchain Platform 네트워크에 연결된 경우에만 호출할 수 있습니다.
func (t *Controller) GetAllAccounts() (interface{}, error) {
    auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAllAccounts", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    return t.Ctx.Account.GetAllAccounts()
}
매개변수:
  • 없음
반환값:
  • 성공 시 모든 계정의 JSON 배열입니다.
반환 값 예제:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 100,
            "BalanceOnHold": 0,
            "BapAccountVersion": 1,
            "OrgId": "appdev",
            "TokenId": "t1",
            "TokenName": "obptok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetUserByAccountId
이 메소드는 지정된 계정에 대한 사용자 세부정보(org_iduser_id)를 반환합니다. 이 메소드는 체인 코드의 모든 사용자가 호출할 수 있습니다.
func (t *Controller) GetUserByAccountId(account_id string) (interface{}, error) {
    return t.Ctx.Account.GetUserByAccountById(account_id)
}
매개변수:
  • account_id string - 계정의 ID입니다.
반환값:
  • 성공 시 사용자 세부정보의 JSON 객체(org_id, token_iduser_id)입니다.
반환 값 예제:
{"org_id":"Org1MSP","token_id":"digiCurr101","user_id":"user1"}
GetAccountBalance
이 메소드는 지정된 계정 및 토큰에 대한 현재 잔액을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) GetAccountBalance(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountBalance", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      response, err := t.Ctx.Account.GetAccountBalance(account_id)
      return response, err
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 현재 계정 잔액에 대한 JSON 표현입니다.
반환 값 예제:
{"msg":"Current Balance of oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f is 0","user_balance":0}
GetAllOrgAccounts
이 메소드는 지정된 조직에 속하는 모든 토큰 계정 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) GetAllOrgAccounts(org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAllOrgAccounts", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAllOrgAccounts(org_id)
}
매개변수:
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에 대한 모든 고객사 리스트입니다.
반환 값 예제:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "key": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
        "valueJson": {
            "AccountId": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "example_minter"
        }
    }
]

역할 관리 방법

AddRole
이 메소드는 지정된 사용자 및 토큰에 롤을 추가합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 롤을 가진 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) AddRole(token_id string, user_role string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.AddRoleMember", "TOKEN", map[string]string{"org_id": org_id, "token_id": token_id, "role": user_role})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.AddRoleMember(user_role, account_id, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • user_role string - 지정된 사용자에 추가할 역할의 이름입니다. mintableburnable 동작은 사양 파일의 minter_role_nameburner_role_name 속성에 해당합니다. 마찬가지로 notary 역할은 사양 파일의 notary_role_name 등록 정보에 해당합니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 계정 세부정보가 포함된 메시지입니다.
반환 값 예제:
 {"msg":"Successfully added role minter to oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
RemoveRole
이 메소드는 지정된 사용자 및 토큰에서 롤을 제거합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 롤을 가진 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) RemoveRole(token_id string, user_role string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.RemoveRoleMember", "TOKEN", map[string]string{"org_id": org_id, "token_id": token_id, "role": user_role})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Token.RemoveRoleMember(user_role, account_id, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • user_role string - 지정된 사용자로부터 제거할 롤의 이름입니다. mintableburnable 동작은 사양 파일의 minter_role_nameburner_role_name 속성에 해당합니다. 마찬가지로 notary 역할은 사양 파일의 notary_role_name 등록 정보에 해당합니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 계정 세부정보가 포함된 메시지입니다.
반환 값 예제:
{"msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"}
GetAccountsByRole
이 메소드는 지정된 롤 및 토큰에 대한 모든 계정 ID 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
func (t *Controller) GetAccountsByRole(token_id string, user_role string) (interface{}, error) {
    auth, err:= t.Ctx.Auth.CheckAuthorization("Role.GetAccountsByRole", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Role.GetAccountsByRole(token_id, user_role)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • user_role string - 검색할 롤의 이름입니다.
반환값:
  • 성공 시 JSON 계정 ID 배열입니다.
반환 값 예제:
{
    "accounts": [
        "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4"
    ]
}
GetAccountsByUser
이 메소드는 지정된 조직 ID 및 사용자 ID에 대한 모든 계정 ID 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 매개변수에 지정된 Account Owner로만 호출할 수 있습니다.
func (t *Controller) GetAccountsByUser(org_id string, user_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountsByUser", "TOKEN", map[string]string{"org_id": org_id, "user_id": user_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetAccountsByUser(org_id, user_id)
}
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 JSON 계정 ID 배열입니다.
반환 값 예제:
{
    "accounts": [
        "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4"
    ]
}
GetUsersByRole
이 메소드는 지정된 롤 및 토큰에 대한 모든 사용자 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 매개변수에 지정된 Account Owner로만 호출할 수 있습니다.
func (t *Controller) GetUsersByRole(token_id string, user_role string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetUsersByRole", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetUsersByRole(token_id, user_role)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • user_role string - 검색할 롤의 이름입니다.
반환값:
  • 성공 시 사용자 객체의 JSON 배열(org_iduser_id)입니다.
반환 값 예제:
{"Users":[{"org_id":"Org1MSP","token_id":"digiCurr101","user_id":"user1"}]}
IsInRole
이 메소드는 사용자 및 토큰에 지정된 롤이 있는지 여부를 나타내는 부울 값을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) IsInRole(token_id string, org_id string, user_id string, user_role string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Token.IsInRole", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      result, err := t.Ctx.Token.IsInRole(user_role, account_id, tokenAssetValue.Interface())
      if err != nil {
            return nil, fmt.Errorf("error in IsInRole %s", err.Error())
      }
      response := make(map[string]interface{})
      response["result"] = result
      return response, nil
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • user_role string - 검색할 롤의 이름입니다.
반환값:
  • 성공 시 부울 결과의 JSON 문자열입니다.
반환 값 예제:
{"result":false}
GetOrgUsersByRole
이 메소드는 지정된 조직에서 지정된 롤을 가진 모든 사용자에 대한 정보를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) GetOrgUsersByRole(token_id string, user_role string, org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetOrgUsersByRole", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetOrgUsersByRole(token_id, user_role, org_id)
}
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 확인할 롤 이름입니다.
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에서 지정된 역할을 가진 모든 사용자 목록입니다.
반환 값 예제:
{
    "Users": [
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "admin"
        },
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "orgAdmin"
        }
    ]
}
GetOrgAccountsByRole
이 방법은 지정된 조직에서 지정된 역할을 가진 모든 계정에 대한 정보를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 지정된 조직의 Org Admin에 의해서만 호출될 수 있습니다.
func (t *Controller) GetOrgAccountsByRole(token_id string, user_role string, org_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Role.GetOrgAccountsByRole", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Role.GetOrgAccountsByRole(token_id, user_role, org_id)
}
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 확인할 롤 이름입니다.
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에서 지정된 역할을 가진 모든 고객사 리스트입니다.
반환 값 예제:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
         "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}

트랜잭션 내역 관리 방법

GetAccountTransactionHistory
이 메소드는 지정된 사용자 및 토큰에 대한 계정 트랜잭션 내역 세부정보 배열을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다.
func (t *Controller) GetAccountTransactionHistory(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountTransactionHistory", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      transactionArray, err := t.Ctx.Account.GetAccountTransactionHistory(account_id, org_id, user_id)
      return transactionArray, err
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 다음 속성을 포함하는 JSON 계정 트랜잭션 객체의 배열입니다.
  • balance - 계정 잔액입니다.
  • holding_id - 보류 계정의 ID입니다.
  • onhold_balance - 보류 중인 잔액입니다.
  • timestamp - 트랜잭션의 시간입니다.
  • token_id - 토큰의 ID입니다.
  • transacted_account - 트랜잭션이 발생한 계정입니다.
  • transacted_amount - 트랜잭션 금액입니다.
  • transaction_id - 트랜잭션의 ID입니다.
  • transaction_type - 트랜잭션의 유형입니다.
반환 값 예제:
[{
    "balance": 199,
    "onhold_balance": 0,
    "timestamp": "2021-08-16T17:42:32.905+05:30",
    "token_id": "digiCurr101",
    "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "transacted_amount": 1,
    "transaction_id": "otransaction~c8a9fa001aba6e0d8391b034655889df47eb5103713840b999a4ab41f5e57b38",
    "transaction_type": "DEBIT"
}, {
    "balance": 200,
    "onhold_balance": 0,
    "timestamp": "2021-08-16T17:41:59.262+05:30",
    "token_id": "digiCurr101",
    "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "transacted_amount": 100,
    "transaction_id": "otransaction~65a0bf8ae8108baa7495fbab91c205651c055e9f480f6808753287173026aa69",
    "transaction_type": "MINT"
}]
GetAccountTransactionHistoryWithFilters
이 메소드는 지정된 사용자 및 토큰에 대한 계정 트랜잭션 내역 세부정보 배열을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 AccountOwner로만 호출할 수 있습니다. 이 메소드는 원격 Oracle Blockchain Platform 네트워크에 접속된 경우에만 호출할 수 있습니다.
func (t *Controller) GetAccountTransactionHistoryWithFilters(token_id string, org_id string, user_id string, filters ...account.AccountHistoryFilters) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetAccountTransactionHistoryWithFilters", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }

      // sample format of filter: []string{"3", "", "2022-01-16T15:16:36+00:00", "2022-01-17T15:16:36+00:00"}
      transactionArray, err := t.Ctx.Account.GetAccountTransactionHistoryWithFilters(account_id, org_id, user_id, filters...)
      return transactionArray, err
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • filters: string - 선택적 매개변수입니다. 비어 있으면 모든 레코드가 반환됩니다. PageSize 속성은 반환할 레코드 수를 결정합니다. PageSize가 0이면 기본 페이지 크기는 20입니다. Bookmark 속성은 반환할 레코드의 시작 인덱스를 결정합니다. 자세한 내용은 Hyperledger Fabric 설명서를 참조하십시오. StartTimeEndTime 속성은 RFC-3339 형식으로 지정해야 합니다.
예제:

ochain invoke GetAccountTransactionHistoryWithFilters 'token1' 'appbuilder12' 'user_minter' '{"PageSize":10,"Bookmark":"1","StartTime":"2022-01-25T17:41:42Z","EndTime":"2022-01-25T17:59:10Z"}'

[
  {
    "transaction_id": "otransaction~3f9c306b0ef6994885939c1a6eb5f063b06617ecb932d4a043f323ba53d55f9f",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:27:13.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa324
1abd3598e05d05",
    "transaction_type": "DEBIT",
    "balance": 9200,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~f1d37c3abd5c85c0a399f246d8eb68257c49ab4fe4cdfd3501908583c51c421e",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:27:02.000Z",
    "token_id": "token1",
    "transaction_type": "BULKTRANSFER",
    "number_of_sub_transactions": 2,
    "balance": 9600,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b",
    "transacted_amount": 200,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transaction_type": "BULKTRANSFER",
    "number_of_sub_transactions": 2,
    "balance": 9800,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~07331a1f7be99d6750973674a783da9ec9ca17df23747cdf52d388865d93f9a",
    "transacted_amount": 10000,
    "timestamp": "2022-02-15T18:26:30.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~88b62f329f20fffc6fc9231cb51019a5e9550c78b657123d140897
62397d2b55",
    "transaction_type": "MINT",
    "balance": 10000,
    "onhold_balance": 0
  }
]
GetSubTransactionsById
이 메소드는 지정된 트랜잭션에 대한 하위 트랜잭션 내역 세부 정보의 배열을 반환합니다.
func (t *Controller) GetSubTransactionsById(transaction_id string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetSubTransactionsById", "TOKEN", map[string]string{"transaction_id": transaction_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetSubTransactionsById(transaction_id)
}
매개변수:
  • transaction_id string - 트랜잭션의 ID입니다.
예제:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 100,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~6600eb38d365552b76f41d4186acece104f31eae331a440f963e6fa75b62ff21",
    "transaction_type": "DEBIT",
    "balance": 9900,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 100,
    "timestamp": "2022-02-15T18:26:57.000Z",
    "token_id": "token1",
    "transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa3241abd3598e05d05",
    "transaction_type": "DEBIT",
    "balance": 9800,
    "onhold_balance": 0
  }
]
GetSubTransactionsByIdWithFilters
이 메소드는 지정된 트랜잭션에 대한 하위 트랜잭션 내역 세부 정보의 배열을 반환합니다.
func (t *Controller) GetSubTransactionsByIdWithFilters(transaction_id string, filters ...account.SubTransactionFilters) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetSubTransactionsByIdWithFilters", "TOKEN", map[string]string{"transaction_id": transaction_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetSubTransactionsByIdWithFilters(transaction_id, filters...)
}
매개변수:
  • transaction_id string - 트랜잭션의 ID입니다.
  • filters: string - 선택적 매개변수입니다. 비어 있으면 모든 레코드가 반환됩니다. PageSize 속성은 반환할 레코드 수를 결정합니다. PageSize가 0이면 기본 페이지 크기는 20입니다. Bookmark 속성은 반환할 레코드의 시작 인덱스를 결정합니다. 자세한 내용은 Hyperledger Fabric 설명서를 참조하십시오. StartTimeEndTime 속성은 RFC-3339 형식으로 지정해야 합니다.
예제:

ochain invoke GetAccountSubTransactionHistoryWithFilters 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b' '{"PageSize":10,"Bookmark":"1"}'

[
{
"transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c4ca4238a0b923820dcc509a6f75849b",
"transacted_amount": 100,
"timestamp": "2022-02-15T18:26:57.000Z",
"token_id": "token1",
"transacted_account": "oaccount~obptok~6600eb38d365552b76f41d4186acece104f31eae331a440f963e6fa75b62ff21",
"transaction_type": "DEBIT",
"balance": 9900,
"onhold_balance": 0
},
{
"transaction_id": "otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b~c81e728d9d4c2f636f067f89cc14862c",
"transacted_amount": 100,
"timestamp": "2022-02-15T18:26:57.000Z",
"token_id": "token1",
"transacted_account": "oaccount~obptok~26e046c8ba8b98da2cdabb78113d67200581ea3d4eea5aa3241abd3598e05d05",
"transaction_type": "DEBIT",
"balance": 9800,
"onhold_balance": 0
}
]
GetTransactionById
이 메소드는 Transaction 자산의 내역을 반환합니다.
func (t *Controller) GetTransactionById(transaction_id string) (interface{}, error) {
    return t.Ctx.Transaction.GetTransactionById(transaction_id)
}
매개변수:
  • transaction_id string - 트랜잭션 자산의 ID입니다.
반환값:
  • 성공 시 트랜잭션에 대한 내역의 JSON 배열입니다.
반환 값 예제:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2021-08-16 20:19:05.028 +0530 IST",
            "TxId": "67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
            "Value": {
                "Amount": 3,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "HoldingId": "ohold~digicur~digiCurr101~op2",
                "NumberOfSubTransactions": 0,
                "Timestamp": "2021-08-16T20:19:05+05:30",
                "ToAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "TokenId": "digiCurr101",
                "TransactionId": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
                "TransactionType": "RELEASEHOLD"
            }
        }
    ],
    "transaction_id": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220"
}
DeleteHistoricalTransactions
이 방법은 상태 데이터베이스에서 오래된 트랜잭션을 삭제합니다.
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error) {
      auth, err := t.Ctx.Auth.CheckAuthorization("Transaction.DeleteHistoricalTransactions", "TOKEN")
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Transaction.DeleteHistoricalTransactions(timestamp)
}
매개변수:
  • timestamp string - 트랜잭션을 삭제할 시기를 나타내는 시간 기록입니다. 지정된 시간보다 오래된 트랜잭션 자산이 삭제됩니다.

토큰 동작 관리 방법 - 민트 가능한 동작

IssueTokens
이 메소드는 토큰을 최소화합니다. 토큰은 메소드 호출자가 소유합니다. 호출자에게 계정 및 채굴자 역할이 있어야 합니다. 민트할 수 있는 토큰 수는 사양 파일에서 mintable 동작의 max_mint_quantity 등록 정보로 제한됩니다. max_mint_quantity 등록 정보가 지정되지 않은 경우 토큰을 무제한으로 만들 수 있습니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 이 메소드는 minter 롤이 있는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
func (t *Controller) IssueTokens(token_id string, quantity float64) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Mint(quantity, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • quantity float64 - 민트할 토큰 수입니다.
반환값:
  • 성공 시 계정 세부정보가 포함된 메시지입니다.
반환 값 예제:
{"msg":"Successfully minted 100 tokens to account oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetTotalMintedTokens
이 메소드는 지정된 토큰에 대한 총 연동 토큰 수를 반환합니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetTotalMintedTokens(token_id string) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetTotalMintedTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.GetTotalMintedTokens(tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 총 토큰 수를 나타내는 JSON 문자열입니다.
반환 값 예제:
{"msg":"total minted amount for token with id digiCurr101 is 1000","quantity":1000}
GetNetTokens
이 메소드는 지정된 토큰에 대해 시스템에서 사용 가능한 총 순 토큰 수를 반환합니다. 순 토큰 합계는 토큰이 소모된 후 남은 토큰의 양입니다. 방정식 형식에서 net 토큰 = 총 minted 토큰 - 총 burned 토큰. 토큰이 소모되지 않는 경우 순 토큰 수는 총 소모 토큰과 같습니다. 이 메소드는 체인 코드의 Token Admin 또는 Org Admin로만 호출할 수 있습니다.
func (t *Controller) GetNetTokens(token_id string) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    auth, err := t.Ctx.Auth.CheckAuthorization("Token.GetNetTokens", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
    }
    return t.Ctx.Token.GetNetTokens(tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 토큰의 순 번호를 나타내는 JSON 문자열입니다.
반환 값 예제:
{"msg":"net minted amount for token with id digiCurr101 is 1000","quantity":1000}

토큰 동작 관리 방법 - 전송 가능한 동작

TransferTokens
이 메소드는 호출자의 토큰을 지정된 계정으로 이전합니다. 메소드 호출자에 계정이 있어야 합니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 이 메소드는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
func (t *Controller) TransferTokens(token_id string, to_org_id string, to_user_id string, quantity float64) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    to_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, to_org_id, to_user_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Transfer(to_account_id, quantity, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • to_org_id string - 현재 조직에 있는 수신자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • to_user_id string - 수신자의 사용자 이름 또는 전자메일 ID입니다.
  • quantity float64 - 전송할 토큰 수입니다.
반환값:
  • 성공 시 두 계정에 대한 세부정보가 포함된 메시지입니다.
반환 값 예제:
{"msg":"successfully transferred 1 tokens from account oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) to account oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : admin)"}
BulkTransferTokens
이 메소드는 호출자 계정의 토큰을 flow 객체에 지정된 계정으로 대량 이전하는 데 사용됩니다. 수량은 이 메소드의 사양 file.The 호출자에 있는 divisible 동작의 decimal 매개변수로 지정된 소수 값 내에 있어야 합니다. 이미 생성된 계정이 있어야 합니다. 이 메소드는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
func (t *Controller) BulkTransferTokens(token_id string, flow[]map[string]interface{}) (interface{}, error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.BulkTransfer(flow, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • flow[]map[string]interface{} - 수신기 세부정보 및 수량을 지정하는 JSON 객체의 배열입니다.
    • to_org_id string - 현재 조직에 있는 수신자의 멤버쉽 서비스 제공자(MSP) ID입니다.
    • to_user_id string - 수신자의 사용자 이름 또는 전자메일 ID입니다.
    • quantity float64 - 전송할 토큰 수입니다.
    예:
    [{
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user1",
    	"quantity": 10
    }, {
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user2",
    	"quantity": 10
    }]
반환값:
  • 성공을 나타내는 메시지입니다.
반환 값 예제:
{
    "from_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "msg": "Successfully transferred 2 tokens from Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)",
    "sub_transactions": [
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e"
        },
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df"
        }
    ]
}

토큰 동작 관리 방법 - 보류 가능한 동작

HoldTokens
이 방법은 토큰 소유자를 대신하여 to_account_id 계정으로 보류를 생성합니다. 공증 계정이 지정되어 보류를 완료하거나 해제합니다. 보류가 생성되면 지급인의 지정된 토큰 잔액이 보류됩니다. 보류가 완료되거나 해제될 때까지 보류 잔액을 이전할 수 없습니다. 이 메소드의 호출자에는 이미 생성된 계정이 있어야 합니다. 이 메소드는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
func (t *Controller) HoldTokens(token_id string, operation_id string, to_org_id string, to_user_id string, notary_org_id string, notary_user_id string, quantity float64, TimeToExpiration string) (interface{}, error) {
      tokenAssetValue, err := t.getTokenObject(token_id)
      if err != nil {
            return nil, err
      }
      notary_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, notary_org_id, notary_user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting notary account id from org_id: %s and user_id: %s with token_id: %s, error %s ", notary_org_id, notary_user_id, token_id, err.Error())
      }
      to_account_id, err := t.Ctx.Account.GenerateAccountId(token_id, to_org_id, to_user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting to_account id from org_id: %s and user_id: %s with token_id: %s, error %s ", to_org_id, to_user_id, token_id, err.Error())
      }
      return t.Ctx.Token.Hold(operation_id, to_account_id, notary_account_id, quantity, TimeToExpiration, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • operation_id string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • to_org_id string - 현재 조직에 있는 수신자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • to_user_id string - 수신자의 사용자 이름 또는 전자메일 ID입니다.
  • notary_org_id string - 현재 조직에 있는 공증인의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • notary_user_id string - 공증인의 사용자 이름 또는 전자메일 ID입니다.
  • quantity float64 - 보류할 토큰 수입니다.
  • time_to_expiration - 보류가 만료되는 시간입니다. 영구 보류에 대해 0을 지정합니다. 그렇지 않은 경우 RFC-3339 형식을 사용합니다. 2021-06-02T12:46:06Z를 입력합니다.
반환값:
  • 성공 시 호출자의 계정과 보류 세부정보가 포함된 메시지입니다.
반환 값 예제:
{"msg":"AccountId oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) is successfully holding 2 tokens"}
ExecuteHoldTokens
이 메소드는 토큰에 대한 보류를 완료합니다. 토큰 소유자가 이전에 보유한 토큰 수량이 수신자에게 전송됩니다. quantity 값이 실제 보류 값보다 작으면 토큰의 원래 소유자가 나머지 금액을 다시 사용할 수 있습니다. 이 메소드는 notary 롤이 있는 AccountOwner ID로만 호출할 수 있습니다. 공증인만 보류를 완료할 수 있습니다.
func (t *Controller) ExecuteHoldTokens(token_id string, operation_id string, quantity float64) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.ExecuteHold(operation_id, quantity, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • operation_id string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • quantity float64 - 전송할 보류 중인 토큰 수입니다.
반환값:
  • 성공 시 발신자의 계정 ID 및 트랜잭션 수량이 포함된 메시지입니다.
반환 값 예제:
{"msg":"Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) has successfully executed '1' tokens(digiCurr101) from the hold with Operation Id 'op1'"}
ReleaseHoldTokens
이 방법은 토큰 보류를 해제합니다. 전송이 완료되지 않았으며 모든 보류 토큰을 원래 소유자에게 다시 사용할 수 있습니다. 이 메소드는 지정된 시간 제한 내에 notary 롤이 있는 Account Owner ID 또는 지정된 시간 제한 이후의 지불인, 수취인 또는 공증인에 의해 호출될 수 있습니다.
func (t *Controller) ReleaseHoldTokens(token_id string, operation_id string) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.ReleaseHold(operation_id, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • operation_id string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
반환값:
  • 성공 시 보류가 해제되었음을 나타내는 메시지입니다.
반환 값 예제:
{"msg":"Successfully released '3' tokens from Operation Id 'op2' to Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetOnHoldIds
이 메소드는 지정된 계정에 대한 모든 보유 ID 목록을 반환합니다. 이 메소드는 체인 코드의 Token Admin, 지정된 조직의 Org Admin 또는 계정의 Account Owner에 의해 호출될 수 있습니다.
func (t *Controller) GetOnHoldIds(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, err
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("Account.GetOnHoldIds", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.GetOnHoldIDs(account_id)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 보유 ID의 JSON 목록입니다. 보유 ID는 ohold 자산 유형, 토큰 이름, 토큰 ID 및 작업 ID의 연결입니다.
반환 값 예제:
{"holding_ids":["ohold~loyaltok123~t1~op1"],"msg":"Holding Ids are: [ohold~loyaltok123~t1~op1]"}
GetOnHoldDetailsWithOperationId
이 메소드는 지정된 작업 ID 및 토큰에 대해 보류 중인 트랜잭션 세부정보를 반환합니다. 이 방법은 누구나 호출할 수 있습니다.
func (t *Controller) GetOnHoldDetailsWithOperationId(token_id string, operation_id string) (interface{} error) {
    return t.Ctx.Hold.GetOnHoldDetailsWithOperationId(token_id, operation_id)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • operation_id string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
반환값:
  • 성공 시 JSON은 다음 속성을 포함하는 객체를 보유합니다.
  • HoldingId - 트랜잭션의 보류 ID입니다.
  • OperationId - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • FromAccountId - 보류 중인 토큰의 현재 소유자의 계정 ID입니다.
  • ToAccountId - 수신자의 계정 ID입니다.
  • NotaryAccountId - 공증인의 계정 ID입니다.
  • TokenId - 저장된 토큰의 ID입니다.
  • Quantity - 보류 ID에 대해 보류 중인 토큰의 양입니다.
  • TimeToExpiration - 보류가 만료될 때까지의 기간입니다.
반환 값 예제:
{
    "AssetType": "ohold",
    "HoldingId": "ohold~digicur~digiCurr101~op1",
    "OperationId": "op1",
    "TokenName": "digicur",
    "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "ToAccountId": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "NotaryAccountId": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "TokenId": "digiCurr101",
    "Quantity": 2,
    "TimeToExpiration": "0"
}
GetOnHoldBalanceWithOperationId
이 메소드는 지정된 작업 ID 및 토큰에 대해 보류 중인 잔액을 반환합니다. 이 방법은 누구나 호출할 수 있습니다.
func (t *Controller) GetOnHoldBalanceWithOperationId(token_id string, operation_id string) (interface{} error) {
    return t.Ctx.Hold.GetOnHoldBalanceWithOperationId(token_id, operation_id)
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • operation_id string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
반환값:
  • 성공 시 보류 잔액을 나타내는 JSON 문자열입니다.
반환 값 예제:
{
	"holding_balance": 10,
	"msg": "Current Holding Balance of OperationId opr_121 for token digiCurr101 is : 10"
}

토큰 동작 관리 방법 - 굽기 가능한 동작

BurnTokens
이 메소드는 트랜잭션 호출자의 계정에서 토큰을 비활성화하거나 레코딩합니다. 이 메소드의 호출자는 계정과 버너 롤을 가져야 합니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 이 메소드는 버너 롤이 있는 계정의 Account Owner에 의해 호출될 수 있습니다.
func (t *Controller) BurnTokens(token_id string, quantity float64) (interface{} error) {
    tokenAssetValue, err := t.getTokenObject(token_id)
    if err != nil {
        return nil, err
    }
    return t.Ctx.Token.Burn(quantity, tokenAssetValue.Interface())
}
매개변수:
  • token_id string - 토큰의 ID입니다.
  • quantity float64 - 레코딩할 토큰 수입니다.
반환값:
  • 성공 시 레코딩된 토큰 수와 계정 ID가 포함된 성공 메시지입니다.
반환 값 예제:
{"msg":"Successfully burned 1 tokens from account id: oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e (org_id : Org1MSP, user_id : user2)"}

사용자정의 방법

토큰 SDK 메소드를 사용하여 비즈니스 애플리케이션에 대한 사용자정의 메소드를 작성할 수 있습니다.

토큰 SDK 메소드를 사용할 때는 반환 값을 추적해야 합니다. 또한 이중 지출을 피하려면 상태 데이터베이스의 동일한 키-값 쌍에서 작동하는 여러 비동기 함수를 결합하지 마십시오. 대신 BulkTransferTokens 메소드를 사용하여 한 가지 방법으로 다중 전송을 수행합니다.

다음 예에서는 사용자정의 메소드에서 토큰 SDK 메소드를 사용하는 방법을 보여줍니다. BuyTicket 메소드가 호출되면 호출자 계정에서 판매자 계정으로 20개의 토큰을 전송하고 전송의 트랜잭션 메시지를 반환합니다.

func (t *Controller) BuyTicket(TokenId string, SellerOrgId string, SellerUserId string) (interface{}, error){
	token, err := t.Ctx.Token.Get(TokenId)
	if err != nil {
		return nil, err
	}
	
	/**
	* The following method t.Ctx.Account.GenerateAccountId(TokenId, SellerOrgId, SellerUserId) generates account id of the seller
	*/
	sellerAccountId, err := t.Ctx.Account.GenerateAccountId(TokenId, SellerOrgId, SellerUserId)
    if err != nil {
		return nil, err
	}   

	/**
	* The following method t.Ctx.Token.Transfer(sellerAccountId, 20, token) transfers the quantity 20 from caller's
	* account & to seller's account.
	*/
    transaction, err := t.Ctx.Token.Transfer(sellerAccountId, 20, token)
    if err != nil {
		return nil, err
	}
    return transaction, nil
}

토큰 SDK 메소드

액세스 제어 관리 방법

토큰 SDK는 액세스 제어 기능을 제공합니다. 일부 메소드는 토큰의 Token Admin, Org Admin 또는 AccountOwner에 의해서만 호출될 수 있습니다. 이 기능을 사용하면 의도한 사용자만 작업을 수행할 수 있습니다. 무단 액세스로 인해 오류가 발생합니다. 액세스 제어 기능을 사용하려면 ../lib/auth 모듈에서 Authorization 클래스를 임포트합니다.
import { Authorization } from '../lib/auth';
AddAdmin
이 메소드는 사용자를 토큰 체인 코드의 Token Admin로 추가합니다.
Ctx.AddAdmin(org_id string, user_id string) (interface{}, error)
매개변수:
  • user_id - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • org_id - 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 추가된 Token Admin 사용자에 대한 성공 메시지 및 세부정보입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: user2)"}
RemoveAdmin
이 메소드는 토큰 체인 코드의 Token Admin인 사용자를 제거합니다.
Ctx.RemoveAdmin(org_id string, user_id string) (interface{}, error)
매개변수:
  • user_id - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • org_id - 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 제거된 Token Admin 사용자에 대한 성공 메시지 및 세부정보입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"msg":"Successfuly removed Admin (Org_Id Org1MSP User_Id user1)"}
GetAllAdmins
이 메소드는 토큰 체인 코드의 Token Admin인 모든 사용자 목록을 반환합니다.
Ctx.GetAllAdmins() (interface{}, error)
매개변수:
  • 없음
반환값:
  • 성공 시 토큰 체인 코드의 Token Admin인 모든 사용자 목록입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user1"}]
GetAllAdminUsers
이 메소드는 토큰 체인 코드의 Token Admin인 모든 사용자 목록을 반환합니다.
Ctx.Admin.GetAllAdminUsers() (interface{}, error) 
매개변수:
  • 없음
반환값:
  • 성공 시 map[string]interface{} 폼에서 토큰 체인 코드의 Token Admin인 모든 사용자 목록입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"admins":[{"OrgId":"Org1MSP","UserId":"admin"},{"OrgId":"Org1MSP","UserId":"user1"}]}
CheckAuthorization
이 방법을 사용하여 체인 코드에 액세스 제어를 추가합니다. 자동으로 생성된 많은 토큰 메소드는 액세스 제어를 사용합니다. SDK 수신기와 액세스 제어가 있는 메소드 간의 매핑은 oChainUtil.go 파일에 설명되어 있습니다. 고유의 액세스 제어를 사용하거나 액세스 제어를 사용 안함으로 설정하려면 자동으로 생성된 제어기 메소드 및 사용자 정의 메소드에서 액세스 제어 코드를 제거합니다.
var t TokenAccess
      var r RoleAccess
      var a AccountAccess
      var as AccountStatusAccess
      var h HoldAccess
      var ad AdminAccess
      var trx TransactionAccess
      var tc TokenConversionAccess
      var auth AuthAccess

      auth.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner"}

      trx.DeleteHistoricalTransactions = []string{"Admin"}
      ad.AddAdmin = []string{"Admin"}
      ad.RemoveAdmin = []string{"Admin"}
      ad.GetAllAdmins = []string{"Admin", "OrgAdmin"}
      ad.AddOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.RemoveOrgAdmin = []string{"Admin", "OrgAdminOrgIdCheck"}
      ad.GetOrgAdmins = []string{"Admin", "OrgAdmin"}
      ad.IsTokenAdmin = []string{"Admin", "MultipleAccountOwner", "OrgAdmin"}
      t.Save = []string{"Admin"}
      t.GetAllTokens = []string{"Admin", "OrgAdmin"}
      t.Update = []string{"Admin"}
      t.GetTokenDecimals = []string{"Admin", "OrgAdmin"}
      t.GetTokensByName = []string{"Admin", "OrgAdmin"}
      t.AddRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.RemoveRoleMember = []string{"Admin", "OrgAdminRoleCheck"}
      t.IsInRole = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      t.GetTotalMintedTokens = []string{"Admin", "OrgAdmin"}
      t.GetNetTokens = []string{"Admin", "OrgAdmin"}
      t.Get = []string{"Admin", "OrgAdmin"}
      t.GetTokenHistory = []string{"Admin", "OrgAdmin"}
      a.CreateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.AssociateToken = []string{"Admin", "OrgAdminAccountIdCheck"}
      a.GetAllAccounts = []string{"Admin"}
      a.GetAllOrgAccounts = []string{"Admin", "OrgAdminOrgIdCheck"}
      a.GetAccount = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.History = []string{"Admin", "AccountOwner"}
      a.GetAccountTransactionHistory = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountTransactionHistoryWithFilters = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetSubTransactionsById = []string{"Admin", "TransactionInvoker"}
      a.GetSubTransactionsByIdWithFilters = []string{"Admin", "TransactionInvoker"}
      a.GetAccountBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountOnHoldBalance = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetOnHoldIds = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      a.GetAccountsByUser = []string{"Admin", "OrgAdminOrgIdCheck", "MultipleAccountOwner"}

      as.Get = []string{"Admin", "OrgAdminAccountIdCheck", "AccountOwner"}
      as.ActivateAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.SuspendAccount = []string{"Admin", "OrgAdminOrgIdCheck"}
      as.DeleteAccount = []string{"Admin", "OrgAdminOrgIdCheck"}

      r.GetAccountsByRole = []string{"Admin"}
      r.GetUsersByRole = []string{"Admin"}
      r.GetOrgAccountsByRole = []string{"Admin", "OrgAdminOrgIdCheck"}
      r.GetOrgUsersByRole = []string{"Admin", "OrgAdminOrgIdCheck"}

      tc.InitializeExchangePoolUser = []string{"Admin"}
      tc.AddConversionRate = []string{"Admin"}
      tc.UpdateConversionRate = []string{"Admin"}
      tc.GetConversionRate = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.GetConversionRateHistory = []string{"Admin", "OrgAdmin", "AnyAccountOwner"}
      tc.TokenConversion = []string{"Admin", "AnyAccountOwner"}
      tc.GetExchangePoolUser = []string{"Admin"}
Ctx.Auth.CheckAuthorization(classFuncName string, args ...string) (bool, error)
매개변수:
  • classFuncName string - oChainUtil.go 파일에 설명된 대로 수신기와 메소드 사이의 맵 값입니다.
  • args - 변수 인수입니다. 여기서 args[0]는 상수 TOKEN이고 args[1]는 필요한 경우 account_id 인수입니다.
반환값:
  • 부울 응답 및 오류 메시지(오류가 발생한 경우)
IsUserTokenAdmin
이 메소드는 함수 호출자가 Token Admin인 경우 부울 값 true를 반환합니다. 그렇지 않으면 메소드가 false를 반환합니다.
Ctx.Auth.IsUserTokenAdmin()  (bool, error)
매개변수:
  • user_id - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • org_id - 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 부울 응답 및 오류 메시지(오류가 발생한 경우)
반환 값 예제:
{"result":false}
AddOrgAdmin
이 방법은 사용자를 조직의 Org Admin로 추가합니다.
Ctx.Admin.AddOrgAdmin(org_id, user_id) (interface{}, error)
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 조직의 Org Admin로 추가된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
RemoveOrgAdmin
이 방법은 조직의 Org Admin인 사용자를 제거합니다.
Ctx.Admin.RemoveOrgAdmin(org_id, user_id) (interface{}, error)
매개변수:
  • org_id string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 조직의 Org Admin로 제거된 사용자의 세부정보를 포함하는 메시지입니다.
반환 값 예제:
{
    "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
GetOrgAdmins
이 메소드는 조직의 Org Admin인 모든 사용자 목록을 반환합니다.
Ctx.Admin.GetAllOrgAdmins() (interface{}, error)
매개변수:
  • 없음
반환값:
  • 성공 시 OrgIdUserId 객체를 포함하는 JSON 목록입니다.
반환 값 예제:
{
    "admins": [
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin1"
        },
        {
            "OrgId": "Org1MSP",
            "UserId": "orgadmin2"
        }
    ]
}

토큰 구성 관리 방법

GetTokenDecimals
이 메소드는 소수 토큰에 사용할 수 있는 소수 자릿수를 반환합니다. divisible 동작이 지정되지 않은 경우 기본값은 0입니다.
Ctx.Token.GetTokenDecimals(token_id string) (int, error)
매개변수:
  • 없음
반환값:
  • 성공 시 토큰의 소수 자릿수(숫자 데이터 유형)입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
1
GetAllTokens
이 메소드는 상태 데이터베이스에 저장된 모든 토큰 자산을 반환합니다. 이 방법은 Berkeley DB SQL 서식 있는 쿼리를 사용하며 원격 Oracle Blockchain Platform 네트워크에 연결된 경우에만 호출할 수 있습니다.
Ctx.Token.GetAllTokens()  (interface{}, error)
매개변수:
  • 없음
반환값:
  • 성공 시 모든 토큰 자산의 맵 배열입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
GetTokensByName
이 메소드는 지정된 이름을 가진 토큰 자산을 모두 반환합니다. 이 방법은 Berkeley DB SQL 서식 있는 쿼리를 사용하며 원격 Oracle Blockchain Platform 네트워크에 연결된 경우에만 호출할 수 있습니다.
Ctx.Token.GetTokensByName(token_name string) (interface{}, error)
매개변수:
  • token_name string - 모델의 Token_name 속성에 해당하는 토큰의 이름입니다. 값은 토큰의 클래스 이름입니다.
반환값:
  • 지정된 이름의 모든 토큰 자산에 대한 맵 배열을 반환합니다.
반환 값 예제:
"payload": [
    {
        "key": "t1",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "Currency_name value",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "Token_desc value",
            "Token_id": "t1",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 999,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "key": "obp2",
        "valueJson": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "holdable",
                "burnable",
                "roles"
            ],
            "Currency_name": "",
            "Divisible": {
                "Decimal": 8
            },
            "Mintable": {
                "Max_mint_quantity": 10000
            },
            "Roles": {
                "burner_role_name": "burner",
                "minter_role_name": "minter",
                "notary_role_name": "notary"
            },
            "Token_desc": "",
            "Token_id": "obp2",
            "Token_name": "obptok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]
Get
이 메소드는 상태 데이터베이스에 토큰 객체가 있는 경우 해당 객체를 반환합니다. 이 메소드는 토큰 체인 코드의 Token Admin에 의해서만 호출될 수 있습니다.
Ctx.Get(Id string, result ...interface{}) (interface{}, error)
매개변수:
  • token_id: string - 반환할 토큰의 ID입니다.
  • result - 변수 인수입니다. 여기서 첫번째 인수 result[0]는 필수 유형의 빈 Token 객체에 대한 참조입니다.
반환값:
  • 성공 시 토큰 자산 데이터가 있는 맵입니다. 변수 인수 result[0]에 토큰 데이터가 포함되어 있습니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "holdable", "roles"],
    "Roles": {
        "burner_role_name": "burner",
        "minter_role_name": "minter",
        "notary_role_name": "notary"
    },
    "Mintable": {
        "Max_mint_quantity": 20000
    },
    "Divisible": {
        "Decimal": 1
    },
    "Token_to_currency_ratio": 1,
    "Currency_representation": "DOLLAR"
}
IsTokenType
이 메소드는 지정된 토큰 ID에 대한 토큰 자산이 존재하는지 여부를 테스트합니다.
Ctx.Model.IsTokenType(token_id: string) error
매개변수:
  • token_id: string - 확인할 토큰의 ID입니다.
반환값:
  • 지정된 ID의 토큰 자산이 존재하는 경우 nil 오류가 발생합니다. 그렇지 않으면 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
nil
Save
이 메소드는 토큰을 생성하고 해당 속성을 상태 데이터베이스에 저장합니다.
Ctx.Token.Save(args ...interface{}) (interface{}, error)
매개변수:
  • token_id: string - 반환할 토큰의 ID입니다.
  • args - 변수 인수입니다. 여기서 첫번째 인수 args[0]는 원장에 추가하는 데 필요한 유형의 토큰 struct 데이터에 대한 참조입니다.
반환값:
  • 성공 시 상태 데이터베이스에 저장된 토큰에 대한 세부정보가 포함된 interface{} 객체입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
Update
이 메소드는 토큰 속성을 업데이트합니다. 토큰 자산이 생성된 후에는 token_desc 값 및 해당 사용자정의 속성만 업데이트할 수 있습니다.
Ctx.Token.Update(args ...interface{}) (interface{}, error)
매개변수:
  • 원장에서 업데이트하는 데 필요한 유형의 토큰 struct 데이터에 대한 참조를 포함하는 자산입니다.
반환값:
  • 성공 시 토큰 세부정보가 포함된 약속 메시지입니다. 오류 발생 시 오류 메시지가 있는 거부입니다.
반환 값 예제:
{
    "AssetType": "otoken",
    "Token_id": "digiCurr101",
    "Token_name": "digicur",
    "Token_desc": "Digital Currency equiv of dollar",
    "Token_type": "fungible",
    "Behavior": ["divisible", "mintable", "transferable", "burnable", "roles"],
    "Roles": {
        "minter_role_name": "minter"
    },
    "Mintable": {
        "Max_mint_quantity": 1000
    },
    "Divisible": {
        "Decimal": 2
    },
    "Currency_name": "",
    "Token_to_currency_ratio": 1
}
GetByRange
이 메소드는 내부적으로 패브릭 getStateByRange 메소드를 호출합니다. 지정된 ID를 가진 자산이 원장에서 반환되더라도 이 메소드는 자산을 호출자 자산 유형으로 변환합니다.
Ctx.Token.GetByRange(startId string, endId string, asset ...interface{}) ([]map[string]interface{}, error)
매개변수:
  • startId: string - 범위의 시작 키입니다. 이 키는 범위에 포함됩니다.
  • endId: string - 범위의 끝 키입니다. 이 키는 범위에서 제외됩니다.
  • asset[0] - 필수 유형의 토큰 조각이 비어 있습니다. 메소드가 성공적으로 실행되면 요청된 결과가 포함됩니다.
반환값:
  • 성공 시 token_id 값이 지정된 범위에 있는 토큰에 대한 토큰 자산 세부정보를 포함하는 맵 조각입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
[{
    "Key": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
    "Record": {
        "AccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "AssetType": "oaccount",
        "Balance": 99,
        "BalanceOnHold": 1,
        "BapAccountVersion": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "u1"
    }
}, {
    "Key": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
    "Record": {
        "AccountId": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
        "AssetType": "oaccount",
        "Balance": 0,
        "BalanceOnHold": 0,
        "BapAccountVersion": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "u2"
    }
}, {
    "Key": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
    "Record": {
        "AccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "AssetType": "oaccount",
        "Balance": 0,
        "BapAccountVersion": 0,
        "BalanceOnHold": 0,
        "OrgId": "Org1MSP",
        "TokenId": "t1",
        "TokenName": "loyaltok123",
        "UserId": "admin"
    }
}, {
    "Key": "oadmin~Org1MSP~admin",
    "Record": {
        "AssetType": "oadmin",
        "Key": "oadmin~Org1MSP~admin",
        "OrgId": "Org1MSP",
        "UserId": "admin"
    }
}, {
    "Key": "ohold~loyaltok123~t1~op1",
    "Record": {
        "AssetType": "ohold",
        "FromAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "HoldingId": "ohold~loyaltok123~t1~op1",
        "NotaryAccountId": "oaccount~loyaltok123~ac30c5ca924a2c7def61acf596d91e0cca70bc8cd233179df4efb2791b56336b",
        "OperationId": "op1",
        "Quantity": 1,
        "TimeToExpiration": "0",
        "ToAccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "TokenId": "t1",
        "TokenName": "loyaltok123"
    }
}, {
    "Key": "ometadata~loyaltok123~t1",
    "Record": {
        "AssetType": "ometadata",
        "Metadata_id": "ometadata~loyaltok123~t1",
        "Token_id": "t1",
        "Token_name": "loyaltok123",
        "Total_minted_amount": 100,
        "Total_supply": 100
    }
}, {
    "Key": "orole~t1~minter~oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
    "Record": {
        "AccountID": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "AssetType": "orole",
        "Key": "orole~t1~minter~oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "RoleName": "minter",
        "TokenId": "t1"
    }
}, {
    "Key": "otransaction~4a774f6493f6521cab9eda96822cb3bb4103c0738ee2dbb9a193b868ace36fa5",
    "Record": {
        "Amount": 100,
        "AssetType": "otransaction",
        "FromAccountId": "",
        "HoldingId": "",
        "NumberOfSubTransactions": 0,
        "Timestamp": "2021-08-25T23:04:42+05:30",
        "ToAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "TokenId": "t1",
        "TransactionId": "otransaction~4a774f6493f6521cab9eda96822cb3bb4103c0738ee2dbb9a193b868ace36fa5",
        "TransactionType": "MINT"
    }
}, {
    "Key": "otransaction~69f3cefbcb64b73f01a0eadff87169f456873ccebe61ca8da3eef3f465f0c129",
    "Record": {
        "Amount": 1,
        "AssetType": "otransaction",
        "FromAccountId": "oaccount~loyaltok123~a4bd3d8abfb1708198971311df77bb527233bcf9121ff95b0526bc056c4b8974",
        "HoldingId": "ohold~loyaltok123~t1~op1",
        "NumberOfSubTransactions": 0,
        "Timestamp": "2021-08-25T23:06:13+05:30",
        "ToAccountId": "oaccount~loyaltok123~aef96c40d99e09ef17f9bdda7038e8fbe829a327bae2b4d8d9fcf752190f3ff0",
        "TokenId": "t1",
        "TransactionId": "otransaction~69f3cefbcb64b73f01a0eadff87169f456873ccebe61ca8da3eef3f465f0c129",
        "TransactionType": "ONHOLD"
    }
}, {
    "Key": "t1",
    "Record": {
        "AssetType": "otoken",
        "Behavior": ["divisible", "mintable", "transferable", "burnable", "holdable", "roles"],
        "Currency_Name": "a",
        "Divisible": {
            "Decimal": 2
        },
        "Effective_From_Date": "2020-09-09T00:00:00Z",
        "Mintable": {
            "Max_mint_quantity": 10000
        },
        "Roles": {
            "minter_role_name": "minter"
        },
        "Token_To_Currency_Ratio": 1,
        "Token_desc": "",
        "Token_id": "t1",
        "Token_name": "loyaltok123",
        "Token_type": "fungible"
    }
}]
History
이 메소드는 지정된 토큰 ID에 대한 토큰 내역을 반환합니다.
Ctx.Token.History(tokenId string) (interface{}, error)
매개변수:
  • tokenId: string - 토큰의 ID입니다.
반환값:
  • 성공 시 토큰 내역을 나타내는 JSON 배열입니다.
반환 값 예제:
[
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:46:33Z",
        "TxId": "12333b8a4f63aa9b3a34072efcbd7df546c6d1e7d82a7a9596e899383656d6f7",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "updated description",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    },
    {
        "IsDelete": "false",
        "Timestamp": "2023-09-01T16:04:25Z",
        "TxId": "99702e2dad7554a5ee4716a0d01d3e394cbce39bea8bade265d8911f30ebad0b",
        "Value": {
            "AssetType": "otoken",
            "Behavior": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "Currency_name1": "",
            "Divisible": {
                "Decimal": 2
            },
            "Mintable": {
                "Max_mint_quantity": 1000
            },
            "Roles": {
                "minter_role_name": "minter"
            },
            "Token_desc": "",
            "Token_id": "token",
            "Token_name": "fiatmoneytok",
            "Token_to_currency_ratio": 0,
            "Token_type": "fungible",
            "Token_unit": "fractional"
        }
    }
]

계정 관리 방법

GenerateAccountId
이 메소드는 oaccount~<token asset name>~ 접두어가 붙은 영숫자 문자 집합인 계정 ID와 인스턴스 소유자의 사용자 이름 또는 전자 메일 ID(user_id) 해시 또는 인스턴스에 로그인한 사용자, 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자 ID(org_id) 및 고유한 토큰 ID(token_id)를 반환합니다.
Ctx.Account.GenerateAccountId(token_id string, org_id string, user_id string) (string, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • org_id: string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id: string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 생성된 계정 ID입니다. 오류 발생 시 오류 메시지가 있는 거부입니다.
반환 값 예제:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
CreateAccount
이 메소드는 지정된 사용자 및 토큰에 대한 계정을 생성합니다. 토큰이 있는 모든 사용자에게는 계정이 있어야 합니다. 계정은 사용자의 잔액, 보류 중인 잔액 및 거래 내역을 추적합니다. 계정 ID는 영숫자 문자 집합으로, 앞에 oaccount~<token asset name>~이 붙고 그 뒤에 인스턴스 소유자의 사용자 이름 또는 전자 메일 ID(user_id) 해시 또는 인스턴스에 로그인한 사용자, 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자 ID(org_id)가 붙습니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
t.Ctx.Account.CreateAccount(org_id string, user_id string, token_type string)
매개변수:
  • org_id: string - 현재 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id: string - 사용자의 사용자 이름 또는 전자메일 ID입니다.
  • token_type: string - 토큰의 유형으로, fungible여야 합니다.
반환값:
  • 성공 시 생성된 계정 객체입니다. 오류 발생 시 오류 메시지가 있는 거부입니다.
반환 값 예제:
{
 "AssetType":"oaccount",
"AccountId":"oaccount~a73085a385bc96c4a45aa2dff032e7dede82c0664dee5f396b7c5854eeafd4bd",
   "UserId":"user1",
   "OrgId":"Org1MSP",
   "BapAccountVersion": 0,
   "AccountType":"fungible",
   "TokenId":"",
   "TokenName":"",
   "Balance":0,
   "BalanceOnHold":0
}
AssociateToken
이 방법은 대체 가능한 토큰을 계정과 연관시킵니다. 이 메소드는 체인 코드의 Token Admin로만 호출할 수 있습니다.
t.Ctx.Account.AssociateToken(account_id, token_id)
매개변수:
  • account_id string - 계정의 ID입니다.
  • token_id string - 토큰의 ID입니다.
반환값:
  • 성공 시 업데이트된 계정의 JSON 객체입니다.
반환 값 예제:
{ 
"AssetType":"oaccount", 
"AccountId":"oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb", 
"BapAccountVersion": 0,
"UserId":"admin", 
"OrgId":"Org1MSP", 
"AccountType":"fungible", 
"TokenId":"token1", 
"TokenName":"loyaltok", 
"Balance":0, 
"BalanceOnHold":0 
}
GetAccountWithStatus
이 방법은 계정 상태를 포함하여 지정된 계정의 계정 세부정보를 반환합니다.
Ctx.Account.GetAccountWithStatus(account_id string) (interface{}, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 요청된 계정 세부정보입니다. 오류 발생 시 오류 메시지가 있는 거부입니다.
반환 값 예제:
{
  "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "AssetType": "oaccount",
  "Balance": 95,
  "BalanceOnHold": 0,
  "BapAccountVersion": 8,
  "OrgId": "appdev",
  "Status": "active",
  "TokenId": "obp1",
  "TokenName": "obptok",
  "TokenType": "fungible",
  "UserId": "idcqa"
}
GetAccount
이 메소드는 지정된 계정의 계정 세부 정보를 반환합니다.
Ctx.Account.GetAccount(account_id string) (Account, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 요청된 계정 세부정보입니다. 오류 발생 시 오류 메시지가 있는 거부입니다.
반환 값 예제:
{
    "AssetType": "oaccount",
    "BapAccountVersion": 0,
    "AccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "UserId": "user1",
    "OrgId": "Org1MSP",
    "TokenId": "digiCurr101",
    "TokenName": "digicur",
    "Balance": 0,
    "BalanceOnHold": 0
}
GetAccountHistory
이 메소드는 지정된 계정에 대한 계정 내역 세부정보의 배열을 반환합니다.
Ctx.Account.History(account_id string) ([]interface{}, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 계정 내역 세부정보를 포함하는 map[string]interface{} 배열입니다. 계정 데이터는 맵의 Value 키 아래에 표시됩니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다. 반환 값은 "GetAccountHistory" 메소드와 동일합니다.
반환 값 예제:
[
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:31:15Z",
      "TxId": "adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 100,
          "BalanceOnHold": 0,
          "BapAccountVersion": 1,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:30:23Z",
      "TxId": "8fbeda2ba60ba175091faae5ae369247775f2cba45c4d6d1ead6f0b05be84743",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "t1",
          "TokenName": "obptok",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  },
  {
      "IsDelete": "false",
      "Timestamp": "2023-08-28T19:29:54Z",
      "TxId": "19bb296ae71709e91b097ba5d9ebd7f7522095880382fbf5913334a46a6026aa",
      "Value": {
          "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
          "AssetType": "oaccount",
          "Balance": 0,
          "BalanceOnHold": 0,
          "BapAccountVersion": 0,
          "OrgId": "Org1MSP",
          "TokenId": "",
          "TokenName": "",
          "TokenType": "fungible",
          "UserId": "idcqa"
      }
  }
]
GetAccountOnHoldBalance
이 방법은 지정된 계정에 대한 보류 중인 잔액을 반환합니다.
Ctx.Account.getAccountOnHoldBalance(account_id: string)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 현재 보류 중인 잔액 및 성공 메시지가 있는 약속 객체입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
   "holding_balance":0,
   "msg":"Total Holding Balance of Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id: Org1MSP, user_id: user1) is 0"
}
GetAllAccounts
이 메소드는 모든 계정 목록을 반환합니다. 이 방법은 Berkeley DB SQL 서식 있는 쿼리를 사용하며 원격 Oracle Blockchain Platform 네트워크에 연결된 경우에만 호출할 수 있습니다.
Ctx.func (t *Controller) GetAllAccounts() (interface{}, error)
매개변수:
  • 없음
반환값:
  • 성공 시 모든 계정을 나열하는 JSON 배열입니다.
반환 값 예제:
"payload": [
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 100,
            "BalanceOnHold": 0,
            "BapAccountVersion": 1,
            "OrgId": "appdev",
            "TokenId": "t1",
            "TokenName": "obptok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    }
]
GetUserByAccountId
이 메소드는 지정된 계정에 대한 사용자 세부정보를 반환합니다.
Ctx.Account.GetUserByAccountById(account_id string) (interface{}, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 세 가지 등록 정보가 포함된 JSON 객체가 포함된 약속:
    • user_id - 사용자의 사용자 이름 또는 전자메일 ID입니다.
    • org_id - 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
    • token_id - 토큰의 ID입니다.
  • 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
   "org_id":"Org1MSP",
   "token_id":"digiCurr101",
   "user_id":"user1"
}
GetAccountBalance
이 방법은 지정된 계정의 계정 잔액을 반환합니다.
Ctx.GetAccountBalance(token_id string, org_id string, user_id string) (interface{}, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 성공 시 메시지 문자열과 현재 잔액이 있는 인터페이스입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "msg": "Current Balance of +p2uaMTsU9D74l9XpHQ2c55ic/2gbO4NZITC4Zq4P8E= is: 200",
    "user_balance": 200
}
GetAllOrgAccounts
이 메소드는 지정된 조직에 속하는 모든 토큰 계정 목록을 반환합니다.
Ctx.Account.GetAllOrgAccounts(org_id string) (interface{}, error)
매개변수:
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에 대한 모든 고객사 리스트입니다.
반환 값 예제:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "AccountId": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "idcqa"
        }
    },
    {
        "key": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
        "valueJson": {
            "AccountId": "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850",
            "AssetType": "oaccount",
            "Balance": 0,
            "BalanceOnHold": 0,
            "BapAccountVersion": 0,
            "OrgId": "appdev",
            "TokenId": "token",
            "TokenName": "fiatmoneytok",
            "TokenType": "fungible",
            "UserId": "example_minter"
        }
    }
]

역할 관리 방법

AddRoleMember
이 메소드는 지정된 사용자 및 토큰에 롤을 추가합니다.
Ctx.Token.AddRoleMember(role string, account_id string, tokenAsset interface{}) (interface{}, error)
매개변수:
  • role: string - 지정된 사용자에 추가할 롤의 이름입니다. mintableburnable 동작은 사양 파일의 minter_role_nameburner_role_name 속성에 해당합니다. 마찬가지로 notary 역할은 사양 파일의 notary_role_name 등록 정보에 해당합니다.
  • account_id: number - 역할을 추가할 계정 ID입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 계정에 역할이 추가되었음을 나타내는 성공 메시지가 포함된 맵을 반환합니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
   "msg":"Successfully added role minter to oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"
}
RemoveRoleMember
이 메소드는 지정된 사용자 및 토큰에서 롤을 제거합니다.
Ctx.Token.RemoveRoleMember(role string, account_id string, tokenAsset interface{}) (interface{}, error)
매개변수:
  • role: string - 지정된 사용자에게 제거할 롤의 이름입니다. mintableburnable 동작은 사양 파일의 minter_role_nameburner_role_name 속성에 해당합니다. 마찬가지로 notary 역할은 사양 파일의 notary_role_name 등록 정보에 해당합니다.
  • account_id: number - 역할을 제거할 계정 ID입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 계정에서 역할 제거를 나타내는 성공 메시지가 포함된 맵을 반환합니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
  "msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"
}
GetAccountsByRole
이 메소드는 지정된 롤 및 토큰에 대한 모든 계정 목록을 반환합니다.
Ctx.Role.GetAccountsByRole(token_id string, user_role string) (interface{}, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 검색할 역할의 이름입니다.
반환값:
  • 성공 시 JSON 계정 ID 배열입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"accounts":["oaccount~obptok~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
GetUsersByRole
이 메소드는 지정된 롤 및 토큰에 대한 모든 사용자 목록을 반환합니다.
Ctx.Role.GetUsersByRole(token_id string, user_role string) (interface{}, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 검색할 역할의 이름입니다.
반환값:
  • 성공 시 사용자 객체의 JSON 배열입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "Users": [
        {
            "token_id":"digiCurr101",
            "user_id": "user1",
            "org_id": "Org1MSP"
        }
    ]
}
IsInRole
이 메소드는 사용자 및 토큰에 지정된 롤이 있는지 여부를 나타냅니다.
Ctx.Token.IsInRole(role string, account_id string, tokenAsset interface{}) (bool, error)
매개변수:
  • role: string - 확인할 롤 이름입니다.
  • account_id: number - 확인할 계정 ID입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 계정에서 역할 제거를 나타내는 성공 메시지가 포함된 맵을 반환합니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "result": false
}
RoleCheck
이 방법은 제공된 계정 ID가 역할의 구성원인지 여부를 확인합니다.
Ctx.Token.RoleCheck(account_id string, tokenAsset interface{}) (bool, error)
매개변수:
  • account_id: string - 확인할 계정 ID입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 지정된 계정에 롤이 있으면 성공 메시지와 부울 값이 true입니다. 그렇지 않은 경우 부울 값은 false입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{ result: true }
GetOrgUsersByRole
이 메소드는 지정된 조직에서 지정된 롤을 가진 모든 사용자에 대한 정보를 반환합니다.
Ctx.Role.GetOrgUsersByRole(token_id string, user_role string, org_id string) (interface{}, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 확인할 롤 이름입니다.
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에서 지정된 역할을 가진 모든 사용자 목록입니다.
반환 값 예제:
{
    "Users": [
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "admin"
        },
        {
            "org_id": "Org1MSP",
            "token_id": "token",
            "user_id": "orgAdmin"
        }
    ]
}
GetOrgAccountsByRole
이 방법은 지정된 조직에서 지정된 역할을 가진 모든 계정에 대한 정보를 반환합니다.
Ctx.Role.GetOrgAccountsByRole(token_id string, user_role string, org_id string) (interface{}, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • role: string - 확인할 롤 이름입니다.
  • org_id: string - 조직의 멤버쉽 서비스 제공자(MSP) ID입니다.
반환값:
  • 성공 시 지정된 조직에서 지정된 역할을 가진 모든 고객사 리스트입니다.
반환 값 예제:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
         "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}

트랜잭션 내역 관리 방법

GetAccountTransactionHistory
이 메소드는 지정된 계정에 대한 트랜잭션 내역 세부정보의 배열을 반환합니다.
Ctx.Account.GetAccountTransactionHistory(account_id string) (interface{}, error)
매개변수:
  • account_id: string - 계정의 ID입니다.
반환값:
  • 반환 값은 "GetAccountTransactionHistory" 메소드와 동일합니다.
  • 성공 시 JSON 계정 트랜잭션 객체의 배열입니다.
  • 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
[
  {
      "NumberOfSubTransactions": 2,
      "balance": 160,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:51:48Z",
      "token_id": "t1",
      "transacted_amount": 20,
      "transaction_id": "otransaction~bd3e8d7d0bcdbed0469a2fccfe95f7ebbeb1987d8385bccf5c84bf80251e748c",
      "transaction_type": "BULKTRANSFER"
  },
  {
      "balance": 180,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:47:14Z",
      "token_id": "t1",
      "transacted_account": "oaccount~692a7465c01e36b694cb8ae86e6c6584240aa1f865fde54f95f32429eadd4097",
      "transacted_amount": 10,
      "transaction_id": "otransaction~250996f1df6a36a1b647f522efcaaf48fd70452d711c247fc4cd475b8e752b08",
      "transaction_type": "DEBIT"
  },
  {
      "balance": 190,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:47:08Z",
      "token_id": "t1",
      "transacted_account": "oaccount~bb5a0b57d895327c8a8cd1f267310cbf3ae542bc854fab8188b5083a969d72fb",
      "transacted_amount": 10,
      "transaction_id": "otransaction~664325a25ae6b19b23693c66f83811184e0a78fabb49122359a2dbf209f32976",
      "transaction_type": "DEBIT"
  },
  {
      "balance": 200,
      "onhold_balance": 0,
      "timestamp": "2023-09-06T06:46:46Z",
      "token_id": "t1",
      "transacted_account": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
      "transacted_amount": 100,
      "transaction_id": "otransaction~7f49564b1eb61d4c8be0ef61cd5e635b533ca533907944e4ec500f390237fd6b",
      "transaction_type": "MINT"
  },
  {
      "balance": 100,
      "onhold_balance": 0,
      "timestamp": "2023-08-28T19:31:15Z",
      "token_id": "t1",
      "transacted_account": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
      "transacted_amount": 100,
      "transaction_id": "otransaction~adde470a63860ec1013bd5c5987e8a506a48942a91b0f39fc8e561374042bd27",
      "transaction_type": "MINT"
  }
]
GetAccountTransactionHistoryWithFilters
이 메소드는 지정된 트랜잭션에 대한 트랜잭션 내역 세부 정보의 배열을 반환합니다. 이 메소드는 원격 Oracle Blockchain Platform 네트워크에 접속된 경우에만 호출할 수 있습니다.
t.Ctx.Account.GetAccountTransactionHistoryWithFilters (transaction_id: string, filters?: SubTransactionFilters)
매개변수:
  • Transaction_id: string - 트랜잭션의 ID입니다.
  • filters: string - 선택적 매개변수입니다. 비어 있으면 모든 레코드가 반환됩니다. PageSize 속성은 반환할 레코드 수를 결정합니다. PageSize가 0이면 기본 페이지 크기는 20입니다. Bookmark 속성은 반환할 레코드의 시작 인덱스를 결정합니다. 자세한 내용은 Hyperledger Fabric 설명서를 참조하십시오. StartTimeEndTime 속성은 RFC-3339 형식으로 지정해야 합니다.
예제:

ochain invoke GetAccountTransactionHistoryWithFilters 'token1' 'appbuilder12' 'user_minter' '{"PageSize":10,"Bookmark":"1","StartTime":"2022-01-25T17:41:42Z","EndTime":"2022-01-25T17:59:10Z"}'

[
    {
        "balance": 90,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:43:36Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~dd9986d3686e52264935558e42026fbf8a9af48b06a3256a58b453f5ada4e636",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 95,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:43:22Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~5e53424de3d691cf6b2a55ea3dc478c555d8784111c11847e594194d6c2e7755",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 100,
        "onhold_balance": 0,
        "timestamp": "2022-04-20T19:42:54Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~b63935592a702d30bedb87ae97b9b1ba7d0f346716adc4f5a4192220bf410d4e",
        "transacted_amount": 100,
        "transaction_id": "otransaction~94c467825ce9f66cc69958d38b169022a69eebc66b75b7d6e0b0585af2c3c228",
        "transaction_type": "MINT"
    }
]
GetSubTransactionsById
이 메소드는 지정된 트랜잭션에 대한 트랜잭션 내역 세부 정보의 배열을 반환합니다.
t.Ctx.Account.GetSubTransactionsById(transaction_id string)
매개변수:
  • transaction_id: string - 트랜잭션의 ID입니다.
예제:

ochain invoke GetSubTransactionsById 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "balance": 80,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c81e728d9d4c2f636f067f89cc14862c",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 85,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c4ca4238a0b923820dcc509a6f75849b",
        "transaction_type": "DEBIT"
    }
]
GetSubTransactionsByIdWithFilters
이 메소드는 지정된 트랜잭션에 대한 트랜잭션 내역 세부 정보의 배열을 반환합니다.
t.Ctx.Account.GetSubTransactionsByIdWithFilters(transaction_id string, filters ...SubTransactionFilters)
매개변수:
  • transaction_id: string - 트랜잭션의 ID입니다.
  • filters: string - 선택적 매개변수입니다. 비어 있으면 모든 레코드가 반환됩니다. PageSize 속성은 반환할 레코드 수를 결정합니다. PageSize가 0이면 기본 페이지 크기는 20입니다. Bookmark 속성은 반환할 레코드의 시작 인덱스를 결정합니다. 자세한 내용은 Hyperledger Fabric 설명서를 참조하십시오. StartTimeEndTime 속성은 RFC-3339 형식으로 지정해야 합니다.
예제:

ochain invoke GetSubTransactionsByIdWithFilters 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b' '{"PageSize":10,"Bookmark":"1"}'

[
    {
        "balance": 80,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~7a4d67118e623a876b77c67e76b819269a8d4a509aece5d2263fb274a9beb3b8",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c81e728d9d4c2f636f067f89cc14862c",
        "transaction_type": "DEBIT"
    },
    {
        "balance": 85,
        "onhold_balance": 0,
        "timestamp": "2022-04-21T05:02:33Z",
        "token_id": "tokenId",
        "transacted_account": "oaccount~0642308fc4c514c257ebf04326c63f990e2531bfd59d0b952056094da61e04ab",
        "transacted_amount": 5,
        "transaction_id": "otransaction~33de5d63058d5e9abc011bc850878dfb7ac3080495729aed345c45b2f21735fa~c4ca4238a0b923820dcc509a6f75849b",
        "transaction_type": "DEBIT"
    }
]
GetTransactionById
이 메소드는 Transaction 자산의 내역을 반환합니다.
t.Ctx.Transaction.GetTransactionById(transaction_id string)
매개변수:
  • transaction_id string - 트랜잭션 자산의 ID입니다.
반환 값 예제:
{
    "history": [
        {
            "IsDelete": "false",
            "Timestamp": "2021-08-16 20:19:05.028 +0530 IST",
            "TxId": "67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
            "Value": {
                "Amount": 3,
                "AssetType": "otransaction",
                "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "HoldingId": "ohold~digicur~digiCurr101~op2",
                "NumberOfSubTransactions": 0,
                "Timestamp": "2021-08-16T20:19:05+05:30",
                "ToAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "TokenId": "digiCurr101",
                "TransactionId": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220",
                "TransactionType": "RELEASEHOLD"
            }
        }
    ],
    "transaction_id": "otransaction~67042154a6853011d111b13f73943f06d2a6ae3cfb9a84cb104482c359eb2220"
}
DeleteHistoricalTransactions
이 방법은 상태 데이터베이스에서 오래된 트랜잭션을 삭제합니다.
func (t *Controller) DeleteHistoricalTransactions(timestamp string) (interface{}, error)
매개변수:
  • time_to_expiration: Date - 트랜잭션을 삭제할 시기를 나타내는 시간 기록입니다. 지정된 시간보다 오래된 트랜잭션 자산이 삭제됩니다.
반환 값 예제:
"payload": {
    "msg": "Successfuly deleted transaction older than date:2021-08-18T05:43:30Z",
    "transactions": [
        "otransaction~57d81f681aa215bb73d6c017d16be8b283d3fcb50051c85891a97d1d407fc342"
    ]
}

토큰 동작 관리 방법 - 민트 가능한 동작

Mint
이 메소드는 토큰을 최소화합니다. 토큰은 메소드 호출자가 소유합니다. 호출자에게 계정 및 채굴자 역할이 있어야 합니다. 민트할 수 있는 토큰 수는 사양 파일에서 mintable 동작의 max_mint_quantity 등록 정보로 제한됩니다. max_mint_quantity 등록 정보가 지정되지 않은 경우 토큰을 무제한으로 만들 수 있습니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 이 메소드는 minter 롤이 있는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
Ctx.Token.Mint(quantity float64, tokenAsset interface{}) (interface{}, error)
매개변수:
  • quantity: number - 민트할 토큰 수입니다.
  • tokenAsset - 민트할 토큰 자산에 대한 참조입니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
  "msg":"Successfully minted 1000 tokens to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
GetTotalMintedTokens
이 메소드는 연동된 총 토큰 수를 반환합니다.
Ctx.Token.GetTotalMintedTokens(tokenAsset interface{}) (map[string]interface{}, error)
매개변수:
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 성공 메시지 및 숫자 데이터 유형의 총 주석 토큰 맵입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"msg":"total minted amount for token with id digiCurr101 is 0","quantity":0}
GetNetTokens
이 메소드는 지정된 토큰에 대해 시스템에서 사용 가능한 토큰의 순 수량을 반환합니다. 그물 토큰은 토큰이 소모된 후 남은 토큰의 양입니다. 방정식 형식: net 토큰 = 총 minted 토큰 - 총 burned 토큰. 토큰이 소모되지 않는 경우 순 토큰 수는 총 소모 토큰과 같습니다.
Ctx.Token.GetNetTokens(tokenAsset interface{}) (map[string]interface{}, error)
매개변수:
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 숫자 데이터 유형의 토큰 순 수량에 대한 성공 메시지 및 맵입니다. 오류가 발생하면 오류 메시지가 표시됩니다.
반환 값 예제:
{"msg":"net minted amount for token with id digiCurr101 is 0","quantity":0}
GetMaxMintQuantity
이 메소드는 토큰에 대한 최대 민트 가능 수량을 반환합니다. max_mint_quantity 동작이 지정되지 않은 경우 기본값은 0이며, 이를 통해 원하는 수의 토큰을 연동할 수 있습니다.
Ctx.Token.GetMaxMintQuantity(token_id string) (float64, error)
매개변수:
  • token_id: string - 확인할 토큰 ID입니다.
반환값:
  • 성공 시 숫자 데이터 유형의 최대 연동 가능 토큰 수량입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
20000

토큰 동작 관리 방법 - 전송 가능한 동작

Transfer
이 메소드는 호출자의 토큰을 지정된 계정으로 이전합니다. 메소드 호출자에 계정이 있어야 합니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 이 메소드는 계정의 AccountOwner에 의해서만 호출될 수 있습니다.
Ctx.Token.Transfer(to_account_id string, quantity float64, tokenAsset interface{}) (interface{}, error)
매개변수:
  • to_account_id: string - 토큰을 수신할 계정 ID입니다.
  • quantity: number - 전송할 총 토큰 수입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다. 반환 값은 "TransferTokens" 메소드와 동일합니다.
반환 값 예제:
{     "msg":"Successfully transferred 50 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP,  User-Id: admin) to account id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"
}
BulkTransfer
이 메소드는 호출자 계정의 토큰을 flow 객체에 지정된 계정으로 대량 이전하는 데 사용됩니다. 이 메소드의 호출자에는 이미 생성된 계정이 있어야 합니다.
Ctx.Token.BulkTransfer(flow []map[string]interface{}, tokenAsset interface{}) (interface{}, error)
매개변수:
  • flow: object[] - 수신기 세부정보 및 수량을 지정하는 JSON 객체의 배열입니다. 전송 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다. 예:
    [{
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user1",
    	"quantity": 10
    }, {
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user2",
    	"quantity": 10
    }]
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공 시 전송된 토큰 수를 포함하는 성공 메시지입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "from_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "msg": "Successfully transferred 2 tokens from Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)",
    "sub_transactions": [
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e"
        },
        {
            "amount": 1,
            "to_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df"
        }
    ]
}

토큰 동작 관리 방법 - 보류 가능한 동작

Hold
이 방법은 토큰 소유자를 대신하여 to_account_id 계정으로 보류를 생성합니다. 공증 계정이 지정되어 보류를 완료하거나 해제합니다. 보류가 생성되면 지급인의 지정된 토큰 잔액이 보류됩니다. 보류가 완료되거나 해제될 때까지 보류 잔액을 이전할 수 없습니다. 이 메소드의 호출자에는 이미 생성된 계정이 있어야 합니다.
Ctx.Token.Hold(operation_id string, to_account_id string, notary_account_id string, quantity float64, TimeToExpiration string, tokenAsset)) (interface{}, error)
매개변수:
  • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • to_account_id: string - 토큰을 수신할 계정의 ID입니다.
  • notary__account_id: string - 공증 계정의 ID입니다.
  • quantity: number - 보류할 총 토큰 수입니다.
  • time_to_expiration: date - 보류가 만료될 때까지의 기간입니다. 영구 보류에 대해 0을 지정합니다. 그렇지 않은 경우 RFC-3339 형식을 사용합니다. 예를 들면 다음과 같습니다. 2021-06-02T12.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
 "msg": "account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) is successfully holding 10 tokens",
}
ExecuteHold
이 방법은 토큰에 대한 보류를 완료하여 이전에 보류 중인 토큰의 지정된 수량을 수신자에게 이전합니다. quantity 값이 실제 보류 값보다 작으면 토큰의 원래 소유자가 나머지 금액을 다시 사용할 수 있습니다. 이 메소드는 notary 롤이 있는 AccountOwner ID로만 호출할 수 있습니다.
Ctx.Token.ExecuteHold(operation_id string, quantity float64, tokenAsset interface{}) (interface{}, error)
매개변수:
  • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • quantity: number - 보류할 총 토큰 수입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"msg":"Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) has successfully executed '1' tokens(digiCurr101) from the hold with Operation Id 'op1'"}
ReleaseHold
이 방법은 토큰 보류를 해제합니다. 전송이 완료되지 않았으며 모든 보류 토큰을 원래 소유자에게 다시 사용할 수 있습니다. 이 메소드는 지정된 시간 제한 내에 notary 롤이 있는 Account Owner ID 또는 지정된 시간 제한 이후의 지불인, 수취인 또는 공증인에 의해 호출될 수 있습니다.
Ctx.Token.ReleaseHold(operation_id string, tokenAsset interface{}) (interface{}, error)
매개변수:
  • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{"msg":"Successfully released '3' tokens from Operation Id 'op2' to Account Id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1)"}
GetOnHoldIds
이 메소드는 지정된 사용자 및 토큰에 대한 모든 보유 ID 목록을 반환합니다.
Ctx.Account.GetOnHoldIDs(account_id string) (map[string]interface{}, error)
매개변수:
  • token_id - 토큰의 ID입니다.
  • org_id - 현재 네트워크 조직에 있는 사용자의 멤버쉽 서비스 제공자(MSP) ID입니다.
  • user_id - 사용자의 사용자 이름 또는 전자메일 ID입니다.
반환값:
  • 성공 시 ID 보유 목록이 있는 JSON 객체입니다. 보유 ID는 자산 유형(ohold), 토큰 이름, 토큰 ID 및 작업 ID를 연결하여 구성됩니다.
반환 값 예제:
{"holding_ids":["ohold~loyaltok123~t1~op1"],"msg":"Holding Ids are: [ohold~loyaltok123~t1~op1]"}
GetOnHoldDetailsWithOperationID
이 메소드는 지정된 작업 ID 및 토큰에 대한 보류 중인 트랜잭션 세부정보를 반환합니다.
Ctx.Hold.GetOnHoldDetailsWithOperationID(token_id string, operation_id string) (Hold, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
반환값:
  • 반환 값은 "GetOnHoldDetailsWithOperationId" 메소드와 동일합니다.
  • 성공 시 지정된 작업 ID 및 토큰에 대한 보류 중인 트랜잭션 세부정보를 포함하는 promise 객체입니다. 보류 객체에는 다음 등록 정보가 포함됩니다.
    • holding_id - 트랜잭션의 보류 ID입니다.
    • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
    • from_account_id - 보류 중인 토큰의 현재 소유자의 계정 ID입니다.
    • to_account_id - 수신자의 계정 ID입니다.
    • notary_account_id - 공증인의 계정 ID입니다.
    • token_id: string - 저장된 토큰의 ID입니다.
    • quantity - 보류 ID에 대해 보류 중인 토큰의 양입니다.
    • time_to_expiration - 보류가 만료될 때까지의 기간입니다.
  • 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "AssetType": "ohold",
    "HoldingId": "ohold~digicur~digiCurr101~op1",
    "OperationId": "op1",
    "TokenName": "digicur",
    "FromAccountId": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "ToAccountId": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "NotaryAccountId": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "TokenId": "digiCurr101",
    "Quantity": 2,
    "TimeToExpiration": "0"
}
GetOnHoldBalanceWithOperationID
이 메소드는 지정된 작업 ID 및 토큰에 대해 보류 중인 잔액을 반환합니다.
Ctx.Hold.GetOnHoldBalanceWithOperationID(token_id string, operation_id string) (map[string]interface{}, error)
매개변수:
  • token_id: string - 토큰의 ID입니다.
  • operation_id: string - 보류 작업을 식별하는 고유 ID입니다. 일반적으로 이 ID는 클라이언트 응용 프로그램에서 전달합니다.
반환값:
  • 성공 시 지정된 작업 ID 및 토큰의 보류 중 잔액입니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
    "holding_balance": 10,
    "msg": "Current Holding Balance of OperationId opr_121 for token digiCurr101 is : 10"
}

토큰 동작 관리 방법 - 굽기 가능한 동작

Burn
이 메소드는 트랜잭션 호출자의 계정에서 토큰을 비활성화하거나 레코딩합니다. 이 메소드의 호출자는 계정과 버너 롤을 가져야 합니다. 수량은 사양 파일에서 divisible 동작의 decimal 매개변수로 지정된 십진수 값 내에 있어야 합니다.
Ctx.Token.Burn(quantity float64 , tokenAsset interface{}) (interface{}, error)
매개변수:
  • quantity: number - 레코딩할 총 토큰 수입니다.
  • tokenAsset - tokenAsset 인수는 작업할 토큰 데이터의 참조를 포함합니다.
반환값:
  • 성공하면 성공 메시지가 나타납니다. 오류 시 오류 메시지가 포함된 nil이 아닌 오류 객체입니다.
반환 값 예제:
{
 "msg":"Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}