權杖分類架構增強功能

區塊鏈 App 產生器的增強版本包含與擴充權杖分類標準架構標準相關的新功能。

每日交易限額

您可以限制帳戶每天可完成的交易數,以及可執行的記號數。createAccount 方法的 max_daily_amountmax_daily_transactions 輸入參數會控制此行為。這些參數是選擇性的。

如果您未設定帳戶的每日交易限額,則可以提高處理量。

createAccount (TypeScript)
@Validator(yup.string(), yup.string(), yup.string(), yup.object().nullable())

public async createAccount(org_id: string, user_id: string, token_type: string, daily_limits: DailyLimits) {
await this.Ctx.Auth.checkAuthorization("ACCOUNT.createAccount", "TOKEN", { org_id });
return await this.Ctx.Account.createAccount(org_id, user_id, token_type, daily_limits);
}
其他參數:
  • daily_limits: JSON – 指定每日交易 (max_daily_amount) 中可使用的記號數目上限,以及每日可完成的交易數目上限 (max_daily_transactions) 的物件,如下列範例所示。
    {
         "max_daily_amount": 100000
         "max_daily_transactions": 10000
     }
CreateAccount (Go)
func (t *Controller) CreateAccount(org_id string, user_id string, token_type string, daily_limits ...account.AccountDailyLimits) (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, daily_limits...)
}
其他參數:
  • daily_limits: JSON – 包含 MaxDailyAmount 參數 (每日交易中可使用的記號數目上限) 和 MaxDailyTransactions 參數 (每日可完成的交易數目上限) 的 JSON 物件,如下列範例所示。
    {
         "MaxDailyAmount": 100000
         "MaxDailyTransactions": 10000
     }
傳回值:
  • 成功時,所建立帳戶的 JSON 物件。BapAccountVersion 參數是在帳戶物件中定義供內部使用。
傳回值範例:
{ 
   "AssetType":"oaccount",
   "AccountId":"oaccount~a73085a385bc96c4a45aa2dff032e7dede82c0664dee5f396b7c5854eeafd4bd",
   "BapAccountVersion": 0,
   "UserId":"user1",
   "OrgId":"Org1MSP",
   "AccountType":"fungible",
   "TokenId":"",
   "TokenName":"",
   "Balance":0,
   "BalanceOnHold":0
}

採礦與燒錄的核准需求

您可以設定用於採礦和燒錄記號的核准,這樣具有礦工或燒錄機角色的使用者必須將要求提交給核准者,而不是直接採礦或燒錄記號。核准者可以接受或拒絕提示或燒錄記號的要求。若要啟用採礦和燒錄的核准,請使用 mint_approval_requiredburn_approval_required 參數。然後還必須指定 mint_approver_role_nameburn_approval_role_name 的值,如下列範例所示。

behavior: # Token behaviors
          - divisible: 
                decimal: 2  
          - mintable: 
                max_mint_quantity: 1000 
                mint_approval_required: true
          - transferable
          - burnable 
                burn_approval_required: true
          - holdable 
          - roles: 
                minter_role_name: minter
                notary_role_name: notary
                mint_approver_role_name: minter_notary
                burn_approver_role_name: burner_notary
下列方法支援要求、接受及拒絕核准薄荷和燒錄記號。

TypeScript 採礦與燒錄核准的方法

requestMint
礦工可以呼叫此方法,將請求傳送給礦工公證人,以建立指定數量的記號。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())
public async requestMint( token_id: string, operation_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails) {

const token_asset = await this.getTokenObject(token_id);
const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
return await this.Ctx.Token.hold(operation_id, null, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.MINT, info_details);

}
參數:
  • token_id: string – 要提示之記號的 ID。
  • operation_id: string – 代表 mint 要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求之礦工公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之礦工公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要提示的記號數量。
  • time_to_expiration – 採礦要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) has successfully submitted request to mint 100 tokens",
}
approveMint
礦工公證人可以呼叫此方法來核准採礦請求。
@Validator(yup.string(), yup.string())
public async approveMint(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.executeHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • operation_id: string – 代表 mint 要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
rejectMint
礦工公證人可以呼叫此方法,以拒絕採礦請求。
@Validator(yup.string(), yup.string())
public async rejectMint(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • operation_id: string – 代表 mint 要求的唯一作業 ID。
傳回值範例:
{
 msg: "Successfully rejected mint request with Operation Id 'operation1' to mint 100 tokens of token id token"
}
requestBurn
燃燒器可以呼叫此方法,以傳送要求給燃燒器公證人,以銷毀指定數量的記號。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())

public async requestBurn( token_id: string, operation_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails ) {

const token_asset = await this.getTokenObject(token_id);
const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
return await this.Ctx.Token.hold(operation_id, null, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.BURN, null, description);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求之燃燒器公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之燒錄公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要燒錄的記號量。
  • time_to_expiration – 燒錄要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) has successfully submitted request to mint 100 tokens",
}
approveBurn
燃燒器公證人可以呼叫這個方法來核准燃燒請求。
@Validator(yup.string(), yup.string())
public async approveBurn(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.executeHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
rejectBurn
燃燒器公證人可以呼叫這個方法來拒絕燃燒請求。
@Validator(yup.string(), yup.string())
public async rejectBurn(token_id: string, operation_id: string) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.releaseHold(operation_id, token_asset);
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
傳回值範例:
{
 msg: "Successfully rejected burn request with Operation Id 'operation1' to burn 100 tokens of token id token",
}

採礦與燒錄核准的執行方式

RequestMint
礦工可以呼叫此方法,將請求傳送給礦工公證人,以建立指定數量的記號。
func (t *Controller) RequestMint(token_id string, operation_id string, notary_org_id string, notary_user_id string, quantity float64, timeToExpiration string, info_details ...token.InfoDetails) (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())
 }
return t.Ctx.Token.Hold(operation_id, "", notary_account_id, quantity, timeToExpiration, tokenAssetValue.Interface(), constants.HoldMint, info_details...)
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • operation_id: string – 代表 mint 要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求之礦工公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之礦工公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要提示的記號數量。
  • TimeToExpiration – 採礦要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "Category" : "category input",
         "Description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (org_id: Org1MSP, user_id: admin) has successfully submitted request to mint 100 tokens",
}
ApproveMint
礦工公證人可以呼叫此方法來核准採礦請求。
func (t *Controller) ApproveMint(token_id string, operation_id string) (interface{}, error) {
tokenAssetValue, err := t.getTokenObject(token_id)
if err != nil {
return nil, err
}
return t.Ctx.Token.ExecuteHold(operation_id, tokenAssetValue.Interface())
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • operation_id: string – 代表 mint 要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (org_id: Org1MSP, user_id: admin)"
}
RejectMint
礦工公證人可以呼叫此方法,以拒絕採礦請求。
func (t *Controller) RejectMint(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 – 代表 mint 要求的唯一作業 ID。
傳回值範例:
{
 msg: "Successfully rejected mint request with Operation Id 'operation1' to mint 100 tokens of token id token"
}
RequestBurn
燃燒器可以呼叫此方法,以傳送要求給燃燒器公證人,以銷毀指定數量的記號。
func (t *Controller) RequestBurn(token_id string, operation_id string, notary_org_id string, notary_user_id string, quantity float64, timeToExpiration string, info_details ...token.InfoDetails) (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())
 }
return t.Ctx.Token.Hold(operation_id, "", notary_account_id, quantity, timeToExpiration, tokenAssetValue.Interface(), constants.HoldBurn, info_details...)
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
  • notary_org_id: string – 將處理要求之燃燒器公證人的會員服務提供者 (MSP) ID。
  • notary_user_id: string – 將處理要求之燒錄公證人的使用者名稱或電子郵件 ID。
  • quantity: number – 要燒錄的記號量。
  • time_to_expiration – 燒錄要求到期且不再有效的時間。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (org_id: Org1MSP, user_id: admin) has successfully submitted request to mint 100 tokens",
}
ApproveBurn
燃燒器公證人可以呼叫這個方法來核准燃燒請求。
func (t *Controller) ApproveBurn(token_id string, operation_id string) (interface{}, error) {
tokenAssetValue, err := t.getTokenObject(token_id)
if err != nil {
return nil, err
}
return t.Ctx.Token.ExecuteHold(operation_id, tokenAssetValue.Interface())
}
參數:
  • token_id: string – 要燒錄的記號 ID。
  • operation_id: string – 代表燒錄要求的唯一作業 ID。
傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (org_id: Org1MSP, user_id: admin)"
}
RejectBurn
燃燒器公證人可以呼叫這個方法來拒絕燃燒請求。
func (t *Controller) RejectBurn(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。
傳回值範例:
{
 msg: "Successfully rejected burn request with Operation Id 'operation1' to burn 100 tokens of token id token",
}

從 Rich History 資料庫擷取交易歷史記錄

您可以將資料同步至豐富的歷史記錄資料庫,然後使用鏈碼 API 呼叫來擷取資料。下列方法 (如 TypeScript 和 Go 中所示) 會從 Rich History 資料庫擷取交易歷史記錄。您必須先執行 Oracle Autonomous Database 並啟用 Oracle REST Data Services (ORDS) 和 OAuth (如 Oracle Database View Definitions for Wholesale CBDC 中所述)。
getAccountTransactionHistoryWithFiltersFromRichHistDB (TypeScript)
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.object().nullable())
public async getAccountTransactionHistoryWithFiltersFromRichHistDB(token_id: string, org_id: string, user_id: string, custom_endpoint: string, bearer_token: string, filters?: Filters) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistoryWithFilters", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTrxHistoryWithFiltersFromRichHistDB(account_id, org_id, user_id.toLowerCase(), custom_endpoint, bearer_token, filters);
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • org_id: string – 目前組織中使用者的成員身分服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • custom_endpoint – Rich History 資料庫的 RESTful 服務端點。
  • bearer_token – RESTful 服務端點的存取授權記號。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
GetAccountTransactionHistoryWithFiltersFromRichHistDB (Go)
func (t *Controller) GetAccountTransactionHistoryWithFiltersFromRichHistDB(token_id string, org_id string, user_id string, custom_endPoint string, bearer_token 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.GetAccountTransactionHistoryWithFiltersFromRichHistDB(account_id, org_id, user_id, custom_endPoint, bearer_token, filters...)
return transactionArray, err
}
參數:
  • token_id: string – 要提示之記號的 ID。
  • org_id: string – 目前組織中使用者的成員身分服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • custom_endpoint – Rich History 資料庫的 RESTful 服務端點。
  • bearer_token – RESTful 服務端點的存取授權記號。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。

交易物件中的類目與描述屬性

  • 類別和描述屬性必須包含在控制器檔案中的 transferTokensholdTokensissueTokensrequestMintrequestBurnburnTokensrejectBurn 方法中。對應的 SDK 方法也必須包含類別和描述屬性。
  • 類別和描述屬性輸入的格式為 info_details 的 JSON 物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
  • info_details 欄位為選擇性欄位。您只能視需要傳送類目或僅傳送描述。
  • transferTokensholdTokensexecuteHoldreleaseHoldrequestMintapproveMintrejectMintrequestBurnapproveBurnrejectBurn 之任何交易相關的 GET 方法,如果它們存在,必須在有效負載回應中包含類別和描述屬性。
  • 種類欄位限制為 20 個字元,且描述欄位限制為 250 個字元。

TypeScript 含有已修改輸入值的方法

當您使用增強版的區塊鏈 App 產生器時,下列方法支援選擇性的類別和描述屬性。

transferTokens
此方法會將記號從呼叫程式轉移至指定的帳戶。
@Validator(yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.object().nullable())
public async transferTokens(token_id: string, to_org_id: string, to_user_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
return await this.Ctx.Token.transfer(to_account_id, quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • to_org_id: string – 目前組織中接收者 (受款人) 的會員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • quantity: number – 要傳輸的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
 msg: "Successfully transferred 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) to account id: oaccount~7yuijg39b4e1e4136dd86a806020c97a930909325340481b8fdhjklliugbv699 (Org-Id: Org1MSP, User-Id: user)",
}
holdTokens
此方法會代表具有 to_account_id 帳戶之記號的擁有者建立保留。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date(), yup.object().nullable())
  public async holdTokens( token_id: string, operation_id: string, to_org_id: string, to_user_id: string, notary_org_id: string, notary_user_id: string, quantity: number, time_to_expiration: Date, info_details?: InfoDetails) {
    const token_asset = await this.getTokenObject(token_id);
    const to_account_id = await this.Ctx.Account.generateAccountId(token_id, to_org_id, to_user_id);
    const notary_account_id = await this.Ctx.Account.generateAccountId(token_id, notary_org_id, notary_user_id);
    return await this.Ctx.Token.hold(operation_id, to_account_id, notary_account_id, quantity, time_to_expiration, token_asset, HoldOperationType.TRANSFER, info_details);
  }
參數:
  • 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: number – 要保留的記號數目。
  • time_to_expiration – 保留到期的時間。指定 0 表示永久保留。否則,請使用 RFC-3339 格式。例如,2021-06-02T12:46:06Z
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) is successfully holding 100 tokens",
}
issueTokens
這個方法會提示記號,然後由方法的呼叫程式所擁有。
@Validator(yup.string(), yup.number().positive(), yup.object().nullable())
public async issueTokens(token_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.mint(quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要提示的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
burnTokens
此方法會停用或燒錄交易呼叫程式帳戶中的記號。
@Validator(yup.string(), yup.number().positive(), yup.object().nullable())

public async burnTokens(token_id: string, quantity: number, info_details?: InfoDetails) {
const token_asset = await this.getTokenObject(token_id);
return await this.Ctx.Token.burn(quantity, token_asset, info_details);
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要燒錄的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}

具有已修改輸入的執行方法

當您使用增強版的區塊鏈 App 產生器時,下列方法支援選擇性的類別和描述屬性。

TransferTokens
此方法會將記號從呼叫程式轉移至指定的帳戶。
func (t *Controller) TransferTokens(token_id string, to_org_id string, to_user_id string, quantity float64, info_details ...token.InfoDetails) (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(), info_details...)
}
參數:
  • token_id: string – 記號的 ID。
  • to_org_id: string – 目前組織中接收者 (受款人) 的會員服務提供者 (MSP) ID。
  • to_user_id: string – 接收者的使用者名稱或電子郵件 ID。
  • quantity: number – 要傳輸的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
 msg: "Successfully transferred 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) to account id: oaccount~7yuijg39b4e1e4136dd86a806020c97a930909325340481b8fdhjklliugbv699 (Org-Id: Org1MSP, User-Id: user)",
}
HoldTokens
此方法會代表具有 to_account_id 帳戶之記號的擁有者建立保留。
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, info_details ...token.InfoDetails) (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(), constants.HoldTransfer, info_details...)
}
參數:
  • 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: number – 要保留的記號數目。
  • time_to_expiration – 保留到期的時間。指定 0 表示永久保留。否則,請使用 RFC-3339 格式。例如,2021-06-02T12:46:06Z
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) is successfully holding 100 tokens",
}
IssueTokens
這個方法會提示記號,然後由方法的呼叫程式所擁有。
func (t *Controller) IssueTokens(token_id string, quantity float64, info_details ...token.InfoDetails) (interface{}, error) {
tokenAssetValue, err := t.getTokenObject(token_id)
if err != nil {
return nil, err
 }
return t.Ctx.Token.Mint(quantity, tokenAssetValue.Interface(), info_details...)
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要提示的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
BurnTokens
此方法會停用或燒錄交易呼叫程式帳戶中的記號。
func (t *Controller) BurnTokens(token_id string, quantity float64, info_details ...token.InfoDetails) (interface{}, error) {
tokenAssetValue, err := t.getTokenObject(token_id)
if err != nil {
return nil, err
 }
return t.Ctx.Token.Burn(quantity, tokenAssetValue.Interface(), info_details...)
}
參數:
  • token_id: string – 記號的 ID。
  • quantity – 要燒錄的記號數目。
  • info_details: JSON – 指定要求之類別 (category) 和描述 (description) 的物件,如下列範例所示。
    {
         "category" : "category input",
         "description" : "description input"
    }
傳回值範例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}

TypeScript 含有已修改輸出的方法

當您使用增強版的區塊鏈 App 產生器時,下列方法會傳回相關的組織和使用者 ID。

getAccountTransactionHistory
此方法會傳回指定使用者和記號的帳戶交易歷史記錄明細陣列。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountTransactionHistory(token_id: string, org_id: string, user_id: string) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistory", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTransactionHistory(account_id, org_id, user_id.toLowerCase());
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的成員身分服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]
getAccountTransactionHistoryWithFilters
此方法會傳回指定使用者和記號之帳戶交易歷史記錄明細的篩選陣列。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string(), yup.object().nullable())
public async getAccountTransactionHistoryWithFilters(token_id: string, org_id: string, user_id: string, filters?: Filters) {
const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountTransactionHistoryWithFilters", "TOKEN", { account_id });
return await this.Ctx.Account.getAccountTransactionHistoryWithFilters(account_id, org_id, user_id.toLowerCase(), filters);
}
參數:
  • token_id: string – 記號的 ID。
  • org_id: string – 目前組織中使用者的成員身分服務提供者 (MSP) ID。
  • user_id: string – 使用者的使用者名稱或電子郵件 ID。
  • filters: string – 選擇性參數。如果空白,則會傳回所有記錄。PageSize 特性決定要傳回的記錄數目。如果 PageSize 為 0,則預設頁面大小為 20。Bookmark 特性決定要傳回之記錄的開始索引。如需詳細資訊,請參閱 Hyperledger Fabric 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]

含有已修改輸出的執行方法

當您使用增強版的區塊鏈 App 產生器時,下列方法會傳回相關的組織和使用者 ID。

GetAccountTransactionHistory
此方法會傳回指定使用者和記號的帳戶交易歷史記錄明細陣列。
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。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]
GetAccountTransactionHistoryWithFilters
此方法會傳回指定使用者和記號之帳戶交易歷史記錄明細的篩選陣列。
func (t *Controller) GetAccountTransactionHistoryWithFilters(token_id string, filters ...account.AccountHistoryFilters) (interface{}, error) {
org_id, err := t.Ctx.Model.GetTransientMapKeyAsString(constants.OrgIdCC)
if err != nil {
return nil, err
}
user_id, err := t.Ctx.Model.GetTransientMapKeyAsString(constants.UserIdCC)
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("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.GetReconciledTransactionHistory(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 文件。必須以 RFC-3339 格式指定 StartTimeEndTime 特性。
傳回值範例:
[
            {
                "transaction_id": "otransaction~64c5a4830949eae1424600f3d4a438c6f603a7c3ea31a68e374b899803999e22",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:37:28.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REJECT_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~a4537ef34a955b023b7c205b9abf06a6c79e4fdd761fb24f41b8eb34126b66c0",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:32.000Z",
                "balance": 550,
                "onhold_balance": 10,
                "token_id": "USD",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "APPROVE_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~6237a759422bd9fb112742e8cd7e6450df5a74a32236d9b1005571afed8904a4",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:36:18.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            },
            {
                "transaction_id": "otransaction~06b35071415d74aa1a7c18449149c937d886cae76a832c44cf8d98e84586e76e",
                "transacted_amount": 10,
                "timestamp": "2024-12-11T13:35:46.000Z",
                "balance": 540,
                "onhold_balance": 10,
                "token_id": "USD",
                "category": "category value",
                "description": "description value",
                "transacted_account": "oaccount~9d9806fa92aa0c4fdb34eaffac6e830181b5d47e64fbce752195e83024125ca0",
                "transaction_type": "REQUEST_MINT",
                "transacted_org_id": "CB",
                "transacted_user_id'": "creator_user_cb"
            }
 ]