标记分类框架增强功能

区块链应用程序构建器的增强版本包括与扩展的令牌分类框架标准相关的新功能。

每日交易限额

您可以限制账户每天可以完成的事务处理数,以及可以执行的标记数。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- 要 mint 的令牌的 ID。
  • operation_id: string- 表示 mint 请求的唯一操作 ID。
  • notary_org_id: string —将处理请求的矿工公证人的成员服务提供商 (MSP) ID。
  • notary_user_id: string —将处理请求的 minter 公证人的用户名或电子邮件 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- 要 mint 的令牌的 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- 要 mint 的令牌的 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- 要 mint 的令牌的 ID。
  • operation_id: string- 表示 mint 请求的唯一操作 ID。
  • notary_org_id: string —将处理请求的矿工公证人的成员服务提供商 (MSP) ID。
  • notary_user_id: string —将处理请求的 minter 公证人的用户名或电子邮件 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- 要 mint 的令牌的 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- 要 mint 的令牌的 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",
}

从富历史记录数据库提取事务处理历史记录

您可以将数据同步到富历史记录数据库,然后使用链代码 API 调用提取数据。以下方法(显示在 TypeScript 和 Go 中)从富历史记录数据库中提取事务处理历史记录。在使用这些方法之前,必须运行启用了 Oracle REST Data Services (ORDS) 和 OAuth 的 Oracle Autonomous Database,如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- 要 mint 的令牌的 ID。
  • org_id: string —当前组织中用户的成员服务提供商 (MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • custom_endpoint —富历史记录数据库的 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- 要 mint 的令牌的 ID。
  • org_id: string —当前组织中用户的成员服务提供商 (MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • custom_endpoint —富历史记录数据库的 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 具有已修改输入的方法

使用区块链应用程序构建器的增强版本时,以下方法支持可选类别和说明属性。

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)"
}

使用修改的输入执行方法

使用区块链应用程序构建器的增强版本时,以下方法支持可选类别和说明属性。

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 具有已修改输出的方法

使用增强版区块链应用程序构建器时,以下方法将返回相关的组织和用户 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"
            }
 ]

使用修改后的输出执行方法

使用增强版区块链应用程序构建器时,以下方法将返回相关的组织和用户 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"
            }
 ]