令牌分类框架的基架 TypeScript 项目

Blockchain App Builder 从您的令牌规范文件中获取输入,并生成一个功能完备的链码项目。

该项目自动生成令牌生命周期类和函数,包括 CRUD 和非 CRUD 方法。自动支持参数验证、编集/解编集以及透明的持久性功能。

有关与令牌不直接相关的基架项目和方法的信息,请参见 Scaffolded TypeScript Chaincode Project

型号

每个标记化的模型类都扩展 Token 类,这反过来又扩展了 OchainModel 类。Token 类是从 ../lib/token 导入的。透明持久性功能(或简化的 ORM)在 OchainModel 类中捕获。

import * as yup from 'yup';
import { Id, Mandatory, Validate, ReadOnly } from '../lib/decorators';
import { Token } from '../lib/token';
 
@Id('token_id')
export class Digicur extends Token<Digicur> {
 
    public readonly assetType = 'otoken';
 
    @Mandatory()
    @Validate(yup.string().required().matches(/^[A-Za-z0-9][A-Za-z0-9_-]*$/).max(16))
    public token_id: string;
 
    @ReadOnly('digicur')
    public token_name: string;
 
    @Validate(yup.string().trim().max(256))
    public token_desc: string;
 
    @ReadOnly('fungible')
    public token_type: string;
 
    @ReadOnly(["divisible","mintable","transferable","burnable","holdable","roles"])
    public behaviors: string[];
 
    @ReadOnly({minter_role_name: "minter", burner_role_name: "burner", notary_role_name: "notary"})
    public roles: object;
 
    @ReadOnly({max_mint_quantity: 20000})
    public mintable: object;
 
    @ReadOnly({decimal: 1})
    public divisible: object;
 
    @Validate(yup.number())
    public token_to_currency_ratio: number;
 
    @Validate(yup.string())
    public currency_representation: string;
 
}

控制器

主控制器类扩展了 OchainController 类。只有一个主控制器。

export class DigiCurrCCController extends OchainController{

您可以创建任意数量的类、函数或文件,但只能调用在主控制器类中定义的那些方法。其他方法被隐藏。

您可以使用令牌 SDK 方法为业务应用程序编写定制方法。

自动生成的令牌方法

Blockchain App Builder 自动生成支持令牌和令牌生命周期的方法。您可以使用这些方法来初始化令牌、管理角色和账户,以及完成其他令牌生命周期任务,而无需额外编码。控制器方法必须具有可调用的 @Validator(...params) 装饰器。

访问控制管理的方法

addTokenAdmin
此方法将用户添加为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async addTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.addAdmin', 'TOKEN');
    return await this.Ctx.Admin.addAdmin(org_id, user_id);
}
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Token Admin 添加的用户详细信息的消息。
返回值示例:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: User1)"}
removeTokenAdmin
此方法将用户删除为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async removeTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.removeAdmin', 'TOKEN');
    return await this.Ctx.Admin.removeAdmin(org_id, user_id);
}
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Token Admin 的用户的详细信息的消息。
返回值示例:
{"msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: User1)"}
isTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true,否则返回 falseToken AdminOrg Admin 可以在区块链网络中的任何其他用户上调用此功能。其他用户只能在自己的账户上调用此方法。
@Validator(yup.string(), yup.string())
  public async isTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.isUserTokenAdmin", "TOKEN");
    return await this.Ctx.Auth.isUserTokenAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 如果调用方为 Token Admin,则该方法返回 true,否则返回 false
getAllTokenAdmins
此方法返回链代码为 Token Admin 的所有用户的列表。此方法只能由链代码的 Token Admin 或任何 Org Admin 调用。
@Validator()
public async getAllTokenAdmins() {
    await this.Ctx.Auth.checkAuthorization('ADMIN.getAllAdmins', 'TOKEN');
    return await this.Ctx.Admin.getAllAdmins();
}
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式的 admins 数组。
返回值示例:
{"admins":[{"org_id":"Org1MSP","user_id":"admin"}]}
addOrgAdmin
此方法将用户添加为组织的 Org Admin。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
@Validator(yup.string(), yup.string())
  public async addOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.addOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.addOrgAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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 调用。
@Validator(yup.string(), yup.string())
  public async removeOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.removeOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.removeOrgAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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 调用。
  @Validator()
  public async getOrgAdmins() {
    await this.Ctx.Auth.checkAuthorization("ADMIN.getOrgAdmins", "TOKEN");
    return await this.Ctx.Admin.getAllOrgAdmins();
  }
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式数组。
返回值示例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAdmin
此方法将用户添加为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async addTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.addAdmin', 'TOKEN');
    return await this.Ctx.Admin.addAdmin(org_id, user_id);
}
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Token Admin 添加的用户详细信息的消息。
返回值示例:
{"msg":"Successfully added Admin (Org_Id: Org1MSP, User_Id: User1)"}
removeTokenAdmin
此方法将用户删除为链代码的 Token Admin。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async removeTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization('ADMIN.removeAdmin', 'TOKEN');
    return await this.Ctx.Admin.removeAdmin(org_id, user_id);
}
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Token Admin 的用户的详细信息的消息。
返回值示例:
{"msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: User1)"}
isTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true,否则返回 falseToken AdminToken Auditor、任何 Org Admin 或任何 Org Auditor 可以在区块链网络中的任何其他用户上调用此功能。其他用户只能在自己的账户上调用此方法。
@Validator(yup.string(), yup.string())
  public async isTokenAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.isUserTokenAdmin", "TOKEN");
    return await this.Ctx.Auth.isUserTokenAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 如果调用方为 Token Admin,则该方法返回 true,否则返回 false
getAllTokenAdmins
此方法返回链代码为 Token Admin 的所有用户的列表。此方法只能由链代码的 Token AdminToken Auditor 调用。
@Validator()
public async getAllTokenAdmins() {
    await this.Ctx.Auth.checkAuthorization('ADMIN.getAllAdmins', 'TOKEN');
    return await this.Ctx.Admin.getAllAdmins();
}
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式的 admins 数组。
返回值示例:
{"admins":[{"org_id":"Org1MSP","user_id":"admin"}]}
addOrgAdmin
此方法将用户添加为组织的 Org Admin。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
@Validator(yup.string(), yup.string())
  public async addOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.addOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.addOrgAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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 调用。
@Validator(yup.string(), yup.string())
  public async removeOrgAdmin(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ADMIN.removeOrgAdmin", "TOKEN", { org_id });
    return await this.Ctx.Admin.removeOrgAdmin(org_id, user_id);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含被删除为组织的 Org Admin 的用户的详细信息的消息。
返回值示例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法返回属于组织 Org Admin 的所有用户的列表。此方法只能由 Token AdminToken Auditor、任何 Org Admin 或任何 Org Auditor 调用。
  @Validator()
  public async getOrgAdmins() {
    await this.Ctx.Auth.checkAuthorization("ADMIN.getOrgAdmins", "TOKEN");
    return await this.Ctx.Admin.getAllOrgAdmins();
  }
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式数组。
返回值示例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAuditor
此方法将用户添加为链代码的 Token Auditor。此方法只能由链代码的 Token Admin 调用。
public async addTokenAuditor(org_id: string, user_id: string)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Token Auditor 添加的用户详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "cd81f6c4c9e7c18ece357dbf5c139ef66ef2d6566be3b14de5f6d0a3fd4bb2f0",
        "payload": {
            "msg": "Successfully added Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 196
    }
}
removeTokenAuditor
此方法将用户删除为链代码的 Token Auditor。此方法只能由链代码的 Token Admin 调用。
public async removeTokenAuditor(org_id: string, user_id: string)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Token Auditor 的用户的详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "a886a6040fbc76374a3c78c89ab0ffc9f7b8391cc5239b169bf3b878cf40c67b",
        "payload": {
            "msg": "Successfully removed Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 219
    }
}
getTokenAuditors
此方法返回链代码的所有 Token Auditors。此方法只能由链代码的 Token AdminToken Auditor 调用。
public async getTokenAuditors()
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "CB",
                    "user_id": "auditor_user_cb"
                }
            ]
        },
        "encode": "JSON"
    }
}
addOrgAuditor
此方法将用户添加为链代码的 Org Auditor。此方法只能由链代码的 Token AdminOrg Admin 调用。
public async addOrgAuditor(org_id: string, user_id: string)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Org Auditor 添加的用户详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "44bbad35a1478cb714e32f7cfd551897868a203520aab9cea5771d3aadc1cf03",
        "payload": {
            "msg": "Successfully added Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 198
    }
}
removeOrgAuditor
此方法将用户删除为链代码的 Org Auditor。此方法只能由链代码的 Token AdminOrg Admin 调用。
public async removeOrgAuditor(org_id: string, user_id: string)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Org Auditor 的用户的详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "c3bc720461004a53b37c68d4bb264858b88d980bc093a0a3ebb62a32974fb306",
        "payload": {
            "msg": "Successfully removed Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 221
    }
}
getOrgAuditors
此方法返回链代码的所有 Org Auditors。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
public async getOrgAuditors()
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "FI1",
                    "user_id": "auditor_user_fi1"
                },
                {
                    "org_id": "FI2",
                    "user_id": "auditor_user_fi2"
                }
            ]
        },
        "encode": "JSON"
    }
}

标记配置管理的方法

init
部署或升级链代码时会调用此方法。每个 Token Admin 都由必需的 adminList 参数中的 user_idorg_id 信息标识。user_id 是实例所有者或登录到实例的用户的用户名或电子邮件 ID。org_id 是当前网络组织中用户的成员服务提供商 (Membership Service Provider,MSP) ID。
任何 Token Admin 用户都可以通过调用 addAdminremoveAdmin 方法来添加和删除其他 Token Admin 用户。
public async init(adminList: TokenAdminAsset[]) {
    await this.Ctx.Admin.initAdmin(adminList);
    return;
}
参数:
  • adminList array-{user_id, org_id} 信息数组,用于指定令牌管理员的列表。adminList 数组是必需参数。
参数示例:macOS 和 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 调用。
@Validator(Digicur)
    public async initializeDigicurToken(token_asset: Digicur) {
        await this.Ctx.Auth.checkAuthorization('TOKEN.save', 'TOKEN');
        return await this.Ctx.Token.save(token_asset)
    }
参数:
  • asset <Token Class>- 标记资产作为参数传递到此方法。标记资产的属性可能会有所不同,并在标记规范文件中进行说明。请勿在规范文件中包括标记为只读的参数。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 asset 参数。

    Visual Studio Code:使用 GUI 传递与令牌类字段对应的单个参数。

    CLI / Postman:传递包含令牌规范字段的序列化 JSON 字符串,如以下示例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

返回:
  • 成功时,所创建的令牌资产的 JSON 表示形式。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
update<Token Name>Token
此方法更新令牌属性。创建标记资产后,只能更新 token_desc 属性和定制属性。此方法只能由链代码的 Token Admin 调用。
@Validator(Digicur)
public async updateDigicurToken(token_asset: Digicur) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.update', 'TOKEN');
    return await this.Ctx.Token.update(token_asset);
}
参数:
  • asset <Token Class>- 标记资产作为参数传递到此方法。标记资产的属性可能会有所不同,并在标记规范文件中进行说明。请勿在规范文件中包括标记为只读的参数。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 asset 参数。

    Visual Studio Code:使用 GUI 传递与令牌类字段对应的单个参数。

    CLI / Postman:传递包含令牌规范字段的序列化 JSON 字符串,如以下示例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

返回:
  • 成功后,将更新标记资产的 JSON 表示形式。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenDecimals
此方法返回为小数标记配置的小数位数。如果未为标记指定 divisible 行为,则默认值为 0。此方法只能由链代码的 Token AdminOrg Admin 调用。
@Validator(yup.string())
public async getTokenDecimals(token_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    await this.Ctx.Auth.checkAuthorization('TOKEN.getDecimals', 'TOKEN');
    return {
        msg: `Token Id: ${token_id} has ${this.Ctx.Token.getDecimals(token_asset)} decimal places.`
    };
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,将显示标记小数位数的 JSON 字符串。
返回值示例:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
getTokenById
如果某个令牌对象存在于状态数据库中,则此方法返回该对象。此方法只能由链代码的 Token AdminOrg Admin 调用。
@Validator(yup.string())
public async getTokenById(token_id: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.get', 'TOKEN');
    const token = await this.getTokenObject(token_id);
    return token;
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,表示令牌资产的 JSON 对象。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 2000
    },
    "divisible": {
        "decimal": 1
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenHistory
此方法返回指定标记 ID 的标记历史记录。任何用户都可以调用此方法。
  @Validator(yup.string())
  public async getTokenHistory(tokenId: string) {
    await this.Ctx.Auth.checkAuthorization("TOKEN.getTokenHistory", "TOKEN");
    return await this.Ctx.Token.history(tokenId);
  }
参数:
  • tokenId: string- 令牌的 ID。
返回:
  • 成功时,表示令牌历史记录的 JSON 对象。
返回值示例:

[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
此方法返回存储在状态数据库中的所有令牌。此方法只能由链代码的 Token AdminOrg Admin 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator()
public async getAllTokens() {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getAllTokens', 'TOKEN');
    return await this.Ctx.Token.getAllTokens();
}
参数:
返回:
  • 成功时,表示所有令牌资产的 JSON 对象。
getTokensByName
此方法返回具有指定名称的所有令牌对象。此方法只能由链代码的 Token AdminOrg Admin 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator(yup.string())
public async getTokensByName(token_name: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getTokensByName', 'TOKEN');
    return await this.Ctx.Token.getTokensByName(token_name);
}
参数:
  • token_name: string- 要检索的令牌的名称。该名称对应于规范文件中的 token_name 属性。该值是令牌的类名。
返回:
  • 成功后,所有与名称匹配的令牌资产的 JSON 对象。
init
部署或升级链代码时会调用此方法。每个 Token Admin 都由必需的 adminList 参数中的 user_idorg_id 信息标识。user_id 是实例所有者或登录到实例的用户的用户名或电子邮件 ID。org_id 是当前网络组织中用户的成员服务提供商 (Membership Service Provider,MSP) ID。
任何 Token Admin 用户都可以通过调用 addAdminremoveAdmin 方法来添加和删除其他 Token Admin 用户。
public async init(adminList: TokenAdminAsset[]) {
    await this.Ctx.Admin.initAdmin(adminList);
    return;
}
参数:
  • adminList array-{user_id, org_id} 信息数组,用于指定令牌管理员的列表。adminList 数组是必需参数。
参数示例:macOS 和 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 调用。
@Validator(Digicur)
    public async initializeDigicurToken(token_asset: Digicur) {
        await this.Ctx.Auth.checkAuthorization('TOKEN.save', 'TOKEN');
        return await this.Ctx.Token.save(token_asset)
    }
参数:
  • asset <Token Class>- 标记资产作为参数传递到此方法。标记资产的属性可能会有所不同,并在标记规范文件中进行说明。请勿在规范文件中包括标记为只读的参数。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 asset 参数。

    Visual Studio Code:使用 GUI 传递与令牌类字段对应的单个参数。

    CLI / Postman:传递包含令牌规范字段的序列化 JSON 字符串,如以下示例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

返回:
  • 成功时,所创建的令牌资产的 JSON 表示形式。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
update<Token Name>Token
此方法更新令牌属性。创建标记资产后,只能更新 token_desc 属性和定制属性。此方法只能由链代码的 Token Admin 调用。
@Validator(Digicur)
public async updateDigicurToken(token_asset: Digicur) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.update', 'TOKEN');
    return await this.Ctx.Token.update(token_asset);
}
参数:
  • asset <Token Class>- 标记资产作为参数传递到此方法。标记资产的属性可能会有所不同,并在标记规范文件中进行说明。请勿在规范文件中包括标记为只读的参数。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 asset 参数。

    Visual Studio Code:使用 GUI 传递与令牌类字段对应的单个参数。

    CLI / Postman:传递包含令牌规范字段的序列化 JSON 字符串,如以下示例所示。

    "{\"token_id\":\"USD\",\"token_desc\":\"token_desc value\",\"Currency_Name\":\"Currency_Name value\"}"

返回:
  • 成功后,将更新标记资产的 JSON 表示形式。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
    },
    "mintable": {
        "max_mint_quantity": 1000
    },
    "divisible": {
        "decimal": 2
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenDecimals
此方法返回为小数标记配置的小数位数。如果未为标记指定 divisible 行为,则默认值为 0。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
@Validator(yup.string())
public async getTokenDecimals(token_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    await this.Ctx.Auth.checkAuthorization('TOKEN.getDecimals', 'TOKEN');
    return {
        msg: `Token Id: ${token_id} has ${this.Ctx.Token.getDecimals(token_asset)} decimal places.`
    };
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,将显示标记小数位数的 JSON 字符串。
返回值示例:
{"msg":"Token Id: digiCurr101 has 1 decimal places."}
getTokenById
如果某个令牌对象存在于状态数据库中,则此方法返回该对象。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
@Validator(yup.string())
public async getTokenById(token_id: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.get', 'TOKEN');
    const token = await this.getTokenObject(token_id);
    return token;
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,表示令牌资产的 JSON 对象。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "digiCurr101",
    "token_name": "digicur",
    "token_desc": "Digital Currency equiv of dollar",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter"
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 2000
    },
    "divisible": {
        "decimal": 1
    },
    "currency_name": "DOLLAR",
    "token_to_currency_ratio": 1
}
getTokenHistory
此方法返回指定标记 ID 的标记历史记录。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
  @Validator(yup.string())
  public async getTokenHistory(tokenId: string) {
    await this.Ctx.Auth.checkAuthorization("TOKEN.getTokenHistory", "TOKEN");
    return await this.Ctx.Token.history(tokenId);
  }
参数:
  • tokenId: string- 令牌的 ID。
返回:
  • 成功时,表示令牌历史记录的 JSON 对象。
返回值示例:

[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
此方法返回存储在状态数据库中的所有令牌。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator()
public async getAllTokens() {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getAllTokens', 'TOKEN');
    return await this.Ctx.Token.getAllTokens();
}
参数:
返回:
  • 成功时,表示所有令牌资产的 JSON 对象。
getTokensByName
此方法返回具有指定名称的所有令牌对象。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator(yup.string())
public async getTokensByName(token_name: string) {
    await this.Ctx.Auth.checkAuthorization('TOKEN.getTokensByName', 'TOKEN');
    return await this.Ctx.Token.getTokensByName(token_name);
}
参数:
  • token_name: string- 要检索的令牌的名称。该名称对应于规范文件中的 token_name 属性。该值是令牌的类名。
返回:
  • 成功后,所有与名称匹配的令牌资产的 JSON 对象。

账户管理方法

createAccount
此方法为指定的用户和令牌创建帐户。必须为在任何时候将具有令牌的任何用户创建账户。账户跟踪余额、暂挂余额和事务处理历史记录。账户 ID 是一组字母数字字符,以 oaccount~<token asset name>~ 为前缀,后跟实例所有者或登录到实例的用户的用户的用户名或电子邮件 ID (user_id) 的散列,即当前网络组织中用户的成员资格服务提供商 ID (org_id)。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async createAccount(org_id: string, user_id: string, token_type: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.createAccount", "TOKEN", { org_id });
    return await this.Ctx.Account.createAccount(org_id, user_id, token_type);
  }
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • token_type: string- 令牌的类型,必须是 fungible
返回:
  • 成功时,已创建的账户的 JSON 对象。bapAccountVersion 参数在帐户对象中定义供内部使用。
返回值示例:
{
  "assetType": "oaccount",
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "bapAccountVersion": 0,
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0
}
associateTokenToAccount
此方法将可变令牌与账户关联。此方法只能由链代码的 Token Admin 或相关组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string())
  public async associateTokenToAccount(account_id: string, token_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.associateToken", "TOKEN", { account_id });
    return await this.Ctx.Account.associateToken(account_id, token_id);
  }
参数:
  • account_id: string- 帐户的 ID。
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,更新账户的 JSON 对象。bapAccountVersion 参数在帐户对象中定义供内部使用。
返回值示例:
{
    "assetType": "oaccount",
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "bapAccountVersion": 0,
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccount
此方法返回指定用户和令牌的帐户详细信息。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.string(), yup.string())
public async getAccount(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.getAccount", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountWithStatus(account_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含以下属性的 JSON 帐户对象:
  • account_id- 用户帐户的 ID。
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • token_id- 令牌的 ID。
  • token_name- 令牌的名称。
  • balance –账户的当前余额。
  • onhold_balance —账户的当前暂挂余额。
  • bapAccountVersion- 用于内部使用的帐户对象参数。
  • status- 用户帐户的当前状态。
返回值示例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccountHistory
此方法返回指定用户和令牌的帐户历史记录详细信息。此方法只能由链代码的 Token Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountHistory(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.history", "TOKEN", { account_id });
    return await this.Ctx.Account.history(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含以下属性的 JSON 帐户对象数组:
  • trxId —分类账返回的事务处理的事务处理 ID。
  • timeStamp –交易时间。
  • value- 帐户对象的 JSON 字符串。
返回值示例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法返回指定账户和令牌的当前暂挂余额。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountOnHoldBalance(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.getAccountOnHoldBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountOnHoldBalance(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,当前暂挂余额的 JSON 表示形式。
返回值示例:
{"msg":"Total Holding Balance is: 0","holding_balance":0}
getAllAccounts
此方法返回所有帐户的列表。此方法只能由链代码的 Token Admin 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator()
public async getAllAccounts() {
    await this.Ctx.Auth.checkAuthorization('ACCOUNT.getAllAccounts', 'TOKEN');
    return await this.Ctx.Account.getAllAccounts();
}
参数:
返回:
  • 成功后,所有帐户的 JSON 数组。
getUserByAccountId
此方法返回指定帐户的用户详细信息(org_iduser_id)。链代码的任何用户都可以调用此方法。
@Validator(yup.string())
public async getUserByAccountId(account_id: string) {
    return await this.Ctx.Account.getUserByAccountId(account_id);
}
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,用户详细信息的 JSON 对象(org_idtoken_iduser_id)。
返回值示例:
{
    "token_id": "digiCurr101",
    "user_id": "user1",
    "org_id": "Org1MSP"
}
getAccountBalance
此方法返回指定帐户和令牌的当前余额。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountBalance(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.getAccountBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountBalance(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,当前帐户余额的 JSON 表示形式。
返回值示例:
{"msg":"Current Balance is: 0","user_balance":0}
getAllOrgAccounts
此方法返回属于指定组织的所有令牌帐户的列表。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
  @Validator(yup.string())
  public async getAllOrgAccounts(org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAllOrgAccounts", "TOKEN", { org_id });
    return await this.Ctx.Account.getAllOrgAccounts(org_id);
  }
参数:
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出指定组织的所有客户。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]
createAccount
此方法为指定的用户和令牌创建帐户。必须为在任何时候将具有令牌的任何用户创建账户。账户跟踪余额、暂挂余额和事务处理历史记录。账户 ID 是一组字母数字字符,以 oaccount~<token asset name>~ 为前缀,后跟实例所有者或登录到实例的用户的用户的用户名或电子邮件 ID (user_id) 的散列,即当前网络组织中用户的成员资格服务提供商 ID (org_id)。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
@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);
}
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • token_type: string- 令牌的类型,必须是 fungible
  • daily_limits: JSON- 指定每日事务中可用的最大标记量 (max_daily_amount) 以及每日可完成的最大事务数 (max_daily_transactions) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 daily_limits 参数。

    Visual Studio Code:{ "max_daily_amount": 1000, "max_daily_transactions": 100 }

    CLI / Postman: "{\"max_daily_amount\":1000,\"max_daily_transactions\":100}"

返回:
  • 成功时,已创建的账户的 JSON 对象。bapAccountVersion 参数在帐户对象中定义供内部使用。
返回值示例:
{
  "assetType": "oaccount",
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "bapAccountVersion": 0,
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0,
  "onhold_burn_balance": 0,
  "max_daily_amount": 1000,
  "max_daily_transactions": 100
}
associateTokenToAccount
此方法将可变令牌与账户关联。此方法只能由链代码的 Token Admin 或相关组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string())
  public async associateTokenToAccount(account_id: string, token_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.associateToken", "TOKEN", { account_id });
    return await this.Ctx.Account.associateToken(account_id, token_id);
  }
参数:
  • account_id: string- 帐户的 ID。
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,更新账户的 JSON 对象。bapAccountVersion 参数在帐户对象中定义供内部使用。
返回值示例:
{
    "assetType": "oaccount",
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "bapAccountVersion": 0,
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccount
此方法返回指定用户和令牌的帐户详细信息。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.string(), yup.string())
public async getAccount(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.getAccount", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountWithStatus(account_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含以下属性的 JSON 帐户对象:
  • account_id- 用户帐户的 ID。
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • token_id- 令牌的 ID。
  • token_name- 令牌的名称。
  • balance –账户的当前余额。
  • onhold_balance —账户的当前暂挂余额。
  • bapAccountVersion- 用于内部使用的帐户对象参数。
  • status- 用户帐户的当前状态。
返回值示例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccountHistory
此方法返回指定用户和令牌的帐户历史记录详细信息。此方法只能由链代码的 Token Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountHistory(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.history", "TOKEN", { account_id });
    return await this.Ctx.Account.history(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含以下属性的 JSON 帐户对象数组:
  • trxId —分类账返回的事务处理的事务处理 ID。
  • timeStamp –交易时间。
  • value- 帐户对象的 JSON 字符串。
返回值示例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法返回指定账户和令牌的当前暂挂余额。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountOnHoldBalance(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.getAccountOnHoldBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountOnHoldBalance(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,当前暂挂余额的 JSON 表示形式。
返回值示例:
{"msg":"Total Holding Balance is: 0","holding_balance":0}
getAllAccounts
此方法返回所有帐户的列表。此方法只能由 Token AdminToken Auditor 调用。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
@Validator()
public async getAllAccounts() {
    await this.Ctx.Auth.checkAuthorization('ACCOUNT.getAllAccounts', 'TOKEN');
    return await this.Ctx.Account.getAllAccounts();
}
参数:
返回:
  • 成功后,所有帐户的 JSON 数组。
getUserByAccountId
此方法返回指定帐户的用户详细信息(org_iduser_id)。此方法可由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
@Validator(yup.string())
public async getUserByAccountId(account_id: string) {
    return await this.Ctx.Account.getUserByAccountId(account_id);
}
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,用户详细信息的 JSON 对象(org_idtoken_iduser_id)。
返回值示例:
{
    "token_id": "digiCurr101",
    "user_id": "user1",
    "org_id": "Org1MSP"
}
getAccountBalance
此方法返回指定帐户和令牌的当前余额。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountBalance(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.getAccountBalance", "TOKEN", { account_id });
    return await this.Ctx.Account.getAccountBalance(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,当前帐户余额的 JSON 表示形式。
返回值示例:
{"msg":"Current Balance is: 0","user_balance":0}
getAllOrgAccounts
此方法返回属于指定组织的所有令牌帐户的列表。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
  @Validator(yup.string())
  public async getAllOrgAccounts(org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAllOrgAccounts", "TOKEN", { org_id });
    return await this.Ctx.Account.getAllOrgAccounts(org_id);
  }
参数:
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出指定组织的所有客户。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]

角色管理的方法

addRole
此方法将角色添加到指定的用户和令牌。此方法只能由链代码的 Token Admin 或同时具有指定角色的指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async addRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.addRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.addRoleMember(role, account_id, token_asset);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要添加到指定用户的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示包含客户详细信息的消息。
返回值示例:
{"msg":"Successfully added role 'minter' to Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
removeRole
此方法从指定用户和令牌中删除角色。此方法只能由链代码的 Token Admin 或同时具有指定角色的指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async removeRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.removeRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.removeRoleMember(role, account_id, token_asset);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要从指定用户中删除的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示包含客户详细信息的消息。
返回值示例:
{"msg":"Successfully removed role 'minter' from Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
getAccountsByRole
此方法返回指定角色和令牌的所有账户 ID 的列表。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async getAccountsByRole(token_id: string, role: string) {
   await this.Ctx.Auth.checkAuthorization('ROLE.getAccountsByRole', 'TOKEN');
   return await this.Ctx.Role.getAccountsByRole(token_id, role);
}
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功后,会出现帐户 ID 的 JSON 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getAccountsByUser
此方法返回指定组织 ID 和用户 ID 的所有帐户 ID 的列表。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或参数中指定的 Account Owner 调用。
  @Validator(yup.string(), yup.string())
  public async getAccountsByUser(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountsByUser", "TOKEN", { org_id, user_id });
    return await this.Ctx.Account.getAccountsByUser(org_id, user_id);
  }
参数:
  • org_id string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,会出现帐户 ID 的 JSON 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法返回指定角色和令牌的所有用户的列表。此方法只能由链代码的 Token Admin 调用。
@Validator(yup.string(), yup.string())
public async getUsersByRole(token_id: string, role: string) {
    await this.Ctx.Auth.checkAuthorization('ROLE.getUsersByRole', 'TOKEN');
    return await this.Ctx.Role.getUsersByRole(token_id, role);
}
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功后,用户对象的 JSON 数组(org_idtoken_iduser_id)。
返回值示例:
{"users":[{"token_id":"digiCurr101","user_id":"user1","org_id":"Org1MSP"}]}
isInRole
此方法返回布尔值以指示用户和令牌是否具有指定的角色。此方法只能由链代码的 Token Admin、帐户的 AccountOwner 或指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async isInRole(token_id: string, org_id: string, user_id: string, role: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.isInRole", "TOKEN", { account_id });
    return { result: await this.Ctx.Token.isInRole(role, account_id, token_asset) };
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功时,布尔结果的 JSON 字符串。
返回值示例:
{"result":"false"}
getOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
   @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgAccountsByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgAccountsByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgAccountsByRole(token_id, role, org_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgUsersByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgUsersByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgUsersByRole(token_id, role, org_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,在指定组织中具有指定角色的所有用户的列表。
返回值示例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}
addRole
此方法将角色添加到指定的用户和令牌。此方法只能由链代码的 Token Admin 或同时具有指定角色的指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async addRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.addRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.addRoleMember(role, account_id, token_asset);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要添加到指定用户的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示包含客户详细信息的消息。
返回值示例:
{"msg":"Successfully added role 'minter' to Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
removeRole
此方法从指定用户和令牌中删除角色。此方法只能由链代码的 Token Admin 或同时具有指定角色的指定组织的 Org Admin 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async removeRole(token_id: string, role: string, org_id: string, user_id: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.removeRoleMember", "TOKEN", { token_id, org_id, role });
    return await this.Ctx.Token.removeRoleMember(role, account_id, token_asset);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要从指定用户中删除的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示包含客户详细信息的消息。
返回值示例:
{"msg":"Successfully removed role 'minter' from Account Id: oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (Org-Id: Org1MSP, User-Id: user1)"}
getAccountsByRole
此方法返回指定角色和令牌的所有账户 ID 的列表。此方法只能由 Token AdminToken Auditor 调用。
@Validator(yup.string(), yup.string())
public async getAccountsByRole(token_id: string, role: string) {
   await this.Ctx.Auth.checkAuthorization('ROLE.getAccountsByRole', 'TOKEN');
   return await this.Ctx.Role.getAccountsByRole(token_id, role);
}
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功后,会出现帐户 ID 的 JSON 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getAccountsByUser
此方法返回指定组织 ID 和用户 ID 的所有帐户 ID 的列表。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或参数中指定的 Account Owner 调用。
  @Validator(yup.string(), yup.string())
  public async getAccountsByUser(org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getAccountsByUser", "TOKEN", { org_id, user_id });
    return await this.Ctx.Account.getAccountsByUser(org_id, user_id);
  }
参数:
  • org_id string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,会出现帐户 ID 的 JSON 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法返回指定角色和令牌的所有用户的列表。此方法只能由 Token AdminToken Auditor 调用。
@Validator(yup.string(), yup.string())
public async getUsersByRole(token_id: string, role: string) {
    await this.Ctx.Auth.checkAuthorization('ROLE.getUsersByRole', 'TOKEN');
    return await this.Ctx.Role.getUsersByRole(token_id, role);
}
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功后,用户对象的 JSON 数组(org_idtoken_iduser_id)。
返回值示例:
{"users":[{"token_id":"digiCurr101","user_id":"user1","org_id":"Org1MSP"}]}
isInRole
此方法返回布尔值以指示用户和令牌是否具有指定的角色。此方法只能由指定的组织的 Token AdminToken Auditor、帐户的 AccountOwnerOrg AdminOrg Auditor 调用。
  @Validator(yup.string(), yup.string(), yup.string(), yup.string())
  public async isInRole(token_id: string, org_id: string, user_id: string, role: string) {
    const token_asset = await this.getTokenObject(token_id);
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    await this.Ctx.Auth.checkAuthorization("TOKEN.isInRole", "TOKEN", { account_id });
    return { result: await this.Ctx.Token.isInRole(role, account_id, token_asset) };
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功时,布尔结果的 JSON 字符串。
返回值示例:
{"result":"false"}
getOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
   @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgAccountsByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgAccountsByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgAccountsByRole(token_id, role, org_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。此方法只能由指定组织的 Org AdminOrg Auditor 通过 Token AdminToken Auditor 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOrgUsersByRole(token_id: string, role: string, org_id: string) {
    await this.Ctx.Auth.checkAuthorization("ROLE.getOrgUsersByRole", "TOKEN", { org_id });
    return await this.Ctx.Role.getOrgUsersByRole(token_id, role, org_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,在指定组织中具有指定角色的所有用户的列表。
返回值示例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}

事务处理历史记录管理的方法

getAccountTransactionHistory
此方法返回指定用户和令牌的账户事务处理历史记录详细信息数组。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
 @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- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,包含以下属性的 JSON 账户事务处理对象数组:
  • transaction_id- 事务处理的 ID。
  • transacted_account –发生交易的帐户。
  • transaction_type- 事务处理类型。
  • transacted_amount –事务处理的金额。
  • timestamp –交易时间。
  • balance –交易时的账户余额。
  • onhold_balance —事务处理时的暂挂余额。
  • token_id- 令牌的 ID。
  • holding_id-holdTokens 方法返回的唯一标识符。
返回值示例:
[
    {
        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
        "transacted_amount": 20,
        "timestamp": "2021-08-17T06:04:24.000Z",
        "balance": 930,
        "onhold_balance": 0,
        "token_id": "digiCurr101",
        "transaction_type": "BULKTRANSFER",
        "sub_transactions": [
            {
                "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                "transaction_type": "DEBIT",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                "transacted_amount": 10
            },
            {
                "transacted_account": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                "transaction_type": "DEBIT",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                "transacted_amount": 10
            }
        ]
    },
    {
        "transaction_id": "otransaction~757864d5369bd0539d044caeb3bb4898db310fd7aa740f45a9938771903d43da",
        "transacted_amount": 50,
        "timestamp": "2021-08-17T06:02:44.000Z",
        "balance": 950,
        "onhold_balance": 0,
        "token_id": "digiCurr101",
        "transacted_account": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
        "transaction_type": "DEBIT"
    }
]
getAccountTransactionHistoryWithFilters
此方法返回指定用户和令牌的账户事务处理历史记录详细信息数组。此方法只能由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。仅当连接到远程 Oracle Blockchain Platform 网络时,才能调用此方法。
  @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- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
示例:

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~672897b5a4fa78b421c000e4d6d4f71f3d46529bfbb5b4be10bf5471dc35ce89",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:46:04.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 90,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~467bb67a33aaffca4487f33dcd46c9844efdb5421a2e7b6aa2d53152eb2c6d85",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:45:47.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 95,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~c6d56ce54a9bbe24597d1d10448e39316dc6f16328bf3c5b0c8ef10e1dfeb397",
    "transacted_amount": 100,
    "timestamp": "2022-04-20T15:44:26.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~deb5fb0906c40506f6c2d00c573b774e01a53dd91499e651d92ac4778b6add6a",
    "transaction_type": "MINT",
    "balance": 100,
    "onhold_balance": 0
  }
]
getSubTransactionsById
此方法返回指定用户和令牌的账户事务处理历史记录详细信息数组。此方法只能由链代码的 Token Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string())
  public async getSubTransactionsById(transaction_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsById", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsById(transaction_id);
  }
参数:
  • transaction_id: string —批量传输事务处理的 ID。
返回:
  • 指定批量传输事务处理 ID 的 JSON 格式的账户子事务处理对象数组。
示例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionsByIdWithFilters
此方法返回指定事务处理的账户子事务处理历史记录详细信息数组。
  @Validator(yup.string(), yup.object().nullable())
  public async getSubTransactionsByIdWithFilters(transaction_id: string, filters?: SubTransactionFilters) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsByIdWithFilters", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsByIdWithFilters(transaction_id, filters);
  } 
参数:
  • transaction_id: string- 事务处理的 ID。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
返回:
  • 指定批量传输事务处理 ID 的 JSON 格式的账户子事务处理对象数组。
示例:

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

[
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 80,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 85,
    "onhold_balance": 0
  }
]
getTransactionById
此方法返回 Transaction 资产的历史记录。
@Validator(yup.string())
    public async getTransactionById(transaction_id: string) {
        return await this.Ctx.Transaction.getTransactionById(transaction_id);
    }
参数:
  • transaction_id string —事务处理资产的 ID。
返回:
  • 成功后,该事务处理的历史记录的 JSON 数组。
返回值示例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法从状态数据库中删除较早的事务处理。
@Validator(yup.date())
    public async deleteHistoricalTransactions(time_to_expiration: Date) {
        await this.Ctx.Auth.checkAuthorization('TRANSACTION.deleteTransactions', 'TOKEN');
        return await this.Ctx.Transaction.deleteTransactions(time_to_expiration);
    }
参数:
  • time_to_expiration Date- 指示何时删除事务的时间戳。将删除早于指定时间的事务处理资产。
返回值示例:
"payload": {
    "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
    "transactions": [
        "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
    ]
}
getAccountTransactionHistoryWithFiltersFromRichHistDB
您可以将数据同步到富历史记录数据库,然后使用链代码 API 调用提取数据。此方法从富历史记录数据库中获取事务处理历史记录。使用此方法之前,必须先启用 Oracle REST Data Services (ORDS) 和 OAuth 来运行 Oracle Autonomous Database,如 Oracle Blockchain Platform Digital Assets Edition 中的 Oracle Database View Definitions for Wholesale CBDC 中所述。
@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- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • custom_endpoint- 富历史记录数据库的 RESTful 服务端点。
  • bearer_token-RESTful 服务端点的访问授权令牌。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
getAccountTransactionHistory
此方法返回指定用户和令牌的账户事务处理历史记录详细信息数组。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户的 AccountOwner 调用。
@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- 当前组织中用户的成员服务提供商 (membership service provider,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
此方法返回指定用户和令牌的账户事务处理历史记录详细信息的筛选数组。此方法只能由指定组织的 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户的 AccountOwner 调用。
@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- 当前组织中用户的成员服务提供商 (membership service provider,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"
            }
 ]
getSubTransactionsById
此方法返回指定用户和令牌的账户事务处理历史记录详细信息数组。此方法只能由调用该事务处理的 Token AdminToken AuditorAccountOwner 调用。
  @Validator(yup.string())
  public async getSubTransactionsById(transaction_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsById", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsById(transaction_id);
  }
参数:
  • transaction_id: string —批量传输事务处理的 ID。
返回:
  • 指定批量传输事务处理 ID 的 JSON 格式的账户子事务处理对象数组。
示例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionsByIdWithFilters
此方法返回指定事务处理的账户子事务处理历史记录详细信息数组。
  @Validator(yup.string(), yup.object().nullable())
  public async getSubTransactionsByIdWithFilters(transaction_id: string, filters?: SubTransactionFilters) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT.getSubTransactionsByIdWithFilters", "TOKEN", { transaction_id });
    return await this.Ctx.Account.getSubTransactionsByIdWithFilters(transaction_id, filters);
  } 
参数:
  • transaction_id: string- 事务处理的 ID。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
返回:
  • 指定批量传输事务处理 ID 的 JSON 格式的账户子事务处理对象数组。
示例:

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

[
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
    "transaction_type": "DEBIT",
    "balance": 80,
    "onhold_balance": 0
  },
  {
    "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
    "transacted_amount": 5,
    "timestamp": "2022-04-20T15:52:21.000Z",
    "token_id": "tokenId",
    "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
    "transaction_type": "DEBIT",
    "balance": 85,
    "onhold_balance": 0
  }
]
getTransactionById
此方法返回 Transaction 资产的历史记录。此方法只能由 Token AdminToken Auditor、指定组织的 Org AdminOrg Auditor 或事务处理参与者(发件人、收件人或公证人)调用。
@Validator(yup.string())
    public async getTransactionById(transaction_id: string) {
        return await this.Ctx.Transaction.getTransactionById(transaction_id);
    }
参数:
  • transaction_id string —事务处理资产的 ID。
返回:
  • 成功后,该事务处理的历史记录的 JSON 数组。
返回值示例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法从状态数据库中删除较早的事务处理。
@Validator(yup.date())
    public async deleteHistoricalTransactions(time_to_expiration: Date) {
        await this.Ctx.Auth.checkAuthorization('TRANSACTION.deleteTransactions', 'TOKEN');
        return await this.Ctx.Transaction.deleteTransactions(time_to_expiration);
    }
参数:
  • time_to_expiration Date- 指示何时删除事务的时间戳。将删除早于指定时间的事务处理资产。
返回值示例:
"payload": {
    "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
    "transactions": [
        "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
    ]
}

令牌行为管理方法 - 可铸造行为

issueTokens
此方法用于生成标记,然后这些标记由该方法的调用方拥有。调用方必须具有帐户和 minter 角色。可铸造的令牌数量受规范文件中 mintable 行为的 max_mint_quantity 属性的限制。如果未指定 max_mint_quantity 属性,则可以铸造无限数量的标记。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由具有 minter 角色的帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.number().positive())
public async issueTokens(token_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.mint(quantity, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • quantity- 要铸造的标记数。
返回:
  • 成功后,将显示包含客户详细信息的消息。
返回值示例:
{
    "msg": "Successfully minted 1000 tokens to Account Id: \
oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)  ",
}
getTotalMintedTokens
此方法返回指定标记的铸造标记总数。此方法只能由链代码的 Token Admin 或任何 Org Admin 调用。
@Validator(yup.string())
 public async getTotalMintedTokens(token_id: string) {
     const token_asset = await this.getTokenObject(token_id);
     await this.Ctx.Auth.checkAuthorization('TOKEN.getTotalMintedTokens', 'TOKEN');
     const totalMintedTokens = await this.Ctx.Token.getTotalMintedTokens(token_asset);
     return {
         msg: `Total minted token for Token Id: ${token_id} is ${totalMintedTokens} tokens.`,
         quantity: totalMintedTokens
     };
 }
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,JSON 字符串指示令牌总数。
返回值示例:
{"msg":"Total minted token for Token Id: digiCurr101 is 100 tokens.","quantity":100}
getNetTokens
此方法返回系统中指定令牌的可用令牌净总数。净令牌总数是令牌被烧毁后剩余的令牌数量。在方程式中:净代币 = 总铸币代币 - 总烧毁代币。如果未刻录任何令牌,则净令牌数等于铸造的令牌总数。此方法只能由链代码的 Token Admin 或任何 Org Admin 调用。
@Validator(yup.string())
public async getNetTokens(token_id: string) {
	const token_asset = await this.getTokenObject(token_id);
	await this.Ctx.Auth.checkAuthorization('TOKEN.getNetTokens', 'TOKEN');
	const netTokens = await this.Ctx.Token.getNetTokens(token_asset);
	return {
		msg: `Net supply of token for Token Id: ${token_id} is ${netTokens} tokens.`,
		quantity: netTokens
	};
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,指示令牌净数的 JSON 字符串。
返回值示例:
{"msg":"Net supply of token for Token Id: digiCurr101 is 0 tokens.","quantity":0}
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) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
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"
}
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) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
msg:
"Successfully minted 100 tokens to Account Id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}
getTotalMintedTokens
此方法返回指定标记的铸造标记总数。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
@Validator(yup.string())
 public async getTotalMintedTokens(token_id: string) {
     const token_asset = await this.getTokenObject(token_id);
     await this.Ctx.Auth.checkAuthorization('TOKEN.getTotalMintedTokens', 'TOKEN');
     const totalMintedTokens = await this.Ctx.Token.getTotalMintedTokens(token_asset);
     return {
         msg: `Total minted token for Token Id: ${token_id} is ${totalMintedTokens} tokens.`,
         quantity: totalMintedTokens
     };
 }
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,JSON 字符串指示令牌总数。
返回值示例:
{"msg":"Total minted token for Token Id: digiCurr101 is 100 tokens.","quantity":100}
getNetTokens
此方法返回系统中指定令牌的可用令牌净总数。净令牌总数是令牌被烧毁后剩余的令牌数量。在方程式中:净代币 = 总铸币代币 - 总烧毁代币。如果未刻录任何令牌,则净令牌数等于铸造的令牌总数。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 调用。
@Validator(yup.string())
public async getNetTokens(token_id: string) {
	const token_asset = await this.getTokenObject(token_id);
	await this.Ctx.Auth.checkAuthorization('TOKEN.getNetTokens', 'TOKEN');
	const netTokens = await this.Ctx.Token.getNetTokens(token_asset);
	return {
		msg: `Net supply of token for Token Id: ${token_id} is ${netTokens} tokens.`,
		quantity: netTokens
	};
}
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功时,指示令牌净数的 JSON 字符串。
返回值示例:
{"msg":"Net supply of token for Token Id: digiCurr101 is 0 tokens.","quantity":0}

令牌行为管理的方法 - 可转移行为

transferTokens
此方法将令牌从调用方转移到指定的帐户。该方法的调用方必须具有帐户。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法只能由帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.string(), yup.string(), yup.number().positive())
public async transferTokens(token_id: string, to_org_id: string, to_user_id: string, quantity: number) {
   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);
}
参数:
  • token_id: string- 令牌的 ID。
  • to_org_id: string- 当前组织中接收方(收款人)的成员服务提供商 (MSP) ID。
  • to_user_id: string- 接收者的用户名或电子邮件 ID。
  • quantity: number- 要传输的标记数。
返回:
  • 成功后,将显示一条消息,其中包含付款人和收款人帐户的详细信息。
返回值示例:
{
    "msg": "Successfully transferred 400 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1) to account id: oaccount~digicur~682bb71de419602af74e3f226345ef308445ca51010737900c112435f676152df (Org-Id: Org1MSP, User-Id: user2) ",
}
bulkTransferTokens
此方法将令牌从调用方帐户批量传输到 flow 对象中指定的帐户。数量必须位于此方法的规范 file.The 调用程序中 divisible 行为的 decimal 参数指定的十进制值内,必须已创建帐户。此方法只能由帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.array().of(yup.object()))
public async bulkTransferTokens(token_id: string, flow: object[]) {
     const token_asset = await this.getTokenObject(token_id);
     return await this.Ctx.Token.bulkTransfer(flow, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • flow : object[] - 指定接收器和数量的 JSON 对象数组。
    • to_orgId: string- 当前组织中接收者的成员服务提供商 (MSP) ID。
    • userId: string- 接收者的用户名或电子邮件 ID。
    • quantity: number- 要传输的标记数。
    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 flow 参数。
    Visual Studio Code:
    [
      { "to_org_id": "Org1MSP", "to_user_id": "user1", "quantity": 10 },
      { "to_org_id": "Org1MSP", "to_user_id": "user2", "quantity": 10 }
    ]
    
    CLI / Postman:
    "[{ \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user1\", \"quantity\": 10 }, { \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user2\", \"quantity\": 10 }]"
返回:
  • 指示成功的消息。
返回值示例:
{
    "msg": "Successfully transferred 20 tokens from Account Id           'oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df' (Org-Id: Org1MSP, User-Id: admin).",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "sub_transactions": [
        {
            "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
            "amount": 10
        },
        {
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
            "amount": 10
        }
    ]
}
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) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
 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)",
}
bulkTransferTokens
此方法将令牌从调用方帐户批量传输到 flow 对象中指定的帐户。数量必须位于此方法的规范 file.The 调用程序中 divisible 行为的 decimal 参数指定的十进制值内,必须已创建帐户。此方法只能由帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.array().of(yup.object()))
public async bulkTransferTokens(token_id: string, flow: object[]) {
     const token_asset = await this.getTokenObject(token_id);
     return await this.Ctx.Token.bulkTransfer(flow, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • flow : object[] - 指定接收器和数量的 JSON 对象数组。
    • to_orgId: string- 当前组织中接收者的成员服务提供商 (MSP) ID。
    • userId: string- 接收者的用户名或电子邮件 ID。
    • quantity: number- 要传输的标记数。
    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 flow 参数。
    Visual Studio Code:
    [
      { "to_org_id": "Org1MSP", "to_user_id": "user1", "quantity": 10 },
      { "to_org_id": "Org1MSP", "to_user_id": "user2", "quantity": 10 }
    ]
    
    CLI / Postman:
    "[{ \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user1\", \"quantity\": 10 }, { \"to_org_id\": \"Org1MSP\", \"to_user_id\": \"user2\", \"quantity\": 10 }]"
返回:
  • 指示成功的消息。
返回值示例:
{
    "msg": "Successfully transferred 20 tokens from Account Id           'oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df' (Org-Id: Org1MSP, User-Id: admin).",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "sub_transactions": [
        {
            "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
            "amount": 10
        },
        {
            "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
            "amount": 10
        }
    ]
}

令牌行为管理的方法 - 可暂挂行为

holdTokens
此方法代表具有 to_account_id 帐户的令牌的所有者创建暂挂。指定公证账户,该账户负责完成或释放暂挂。创建暂挂时,付款人的指定标记余额将被暂挂。在暂挂完成或释放之前,无法转移暂挂余额。此方法的调用方必须已创建帐户。此方法只能由帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.string(), yup.number().positive(), yup.date())
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
) {
    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);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
  • to_org_id: string- 当前组织中接收者的成员服务提供商 (MSP) ID。
  • to_user_id: string- 接收者的用户名或电子邮件 ID。
  • notary_org_id: string- 当前组织中公证人的成员服务提供商 (membership service provider,MSP) ID。
  • notary_user_id: string- 公证人的用户名或电子邮件 ID。
  • quantity: number –要暂挂的令牌数。
  • time_to_expiration- 暂挂到期的时间。为永久暂挂指定 0 。否则,请使用 RFC-3339 格式。例如 2021-06-02T12:46:06Z
返回:
  • 成功后,将显示一条消息,其中包含呼叫者的帐户和暂挂详细信息。
返回值示例:
{
  "msg":"AccountId oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP , User-Id: admin) is   successfully holding 10 tokens"
}
executeHoldTokens
此方法完成对令牌的暂挂。令牌所有者以前持有的令牌数量将转移给接收者。如果 quantity 值小于实际暂挂值,则剩余金额将再次可供令牌的原始所有者使用。此方法只能由具有指定操作 ID 的 notary 角色的 AccountOwner ID 调用。暂停只能由公证人完成。
@Validator(yup.string(), yup.string(), yup.number().positive())
public async executeHoldTokens(token_id: string, operation_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.executeHold(operation_id, quantity, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
  • quantity: number –要传输的暂挂令牌数。
返回:
  • 成功后,将收到一条消息,其中包含呼叫者的帐户 ID 和交易数量。
返回值示例:
{
 "msg":"Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin) is successfully executed '10' tokens from Operation Id 'opr_121'."
}
releaseHoldTokens
此方法释放暂挂令牌。传输未完成,所有保留的令牌将再次提供给原始所有者。此方法可以由具有 notary 角色的 AccountOwner ID 在指定时间限制内调用,也可以由付款人、收款人或公证人在指定时间限制之后调用。
@Validator(yup.string(), yup.string())
public async releaseHoldTokens(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。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,将发出一条消息,指示释放暂挂。
返回值示例:
{
 "msg":"Successfully released '10' tokens from Operation Id 'opr_121' to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)."
}
getOnHoldIds
此方法返回指定帐户的所有持有 ID 的列表。此方法可以由链代码的 Token Admin、指定组织的 Org Admin 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOnHoldIds(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.getOnHoldIds", "TOKEN", { account_id });
    return await this.Ctx.Account.getOnHoldIds(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含 ID 的 JSON 列表。
返回值示例:
{"msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121","holding_ids":["ohold~digicur~digiCurr101~opr_121"]}
getOnHoldDetailsWithOperationId
此方法返回指定操作 ID 和令牌的暂挂事务处理详细信息。任何人都可以调用此方法。
@Validator(yup.string(), yup.string())
public async getOnHoldDetailsWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldDetailsWithOperationId(token_id, operation_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,包含以下属性的 JSON 暂挂对象:
  • 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- 暂挂到期之前的持续时间。
返回值示例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法返回指定操作 ID 和令牌的暂挂余额。任何人都可以调用此方法。
@Validator(yup.string(), yup.string())
public async getOnHoldBalanceWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldBalanceWithOperationId(token_id, operation_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功时,JSON 字符串指示暂挂余额。
返回值示例:
{
	"msg": "Current Holding Balance of Operation 'opr_121' for token 'digiCurr101' is: 10",
	"holding_balance": 10
}
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- 当前组织中公证人的成员服务提供商 (membership service provider,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) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
msg:
"AccountId oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin) is successfully holding 100 tokens",
}
executeHoldTokens
此方法完成对令牌的暂挂。令牌所有者以前持有的令牌数量将转移给接收者。如果 quantity 值小于实际暂挂值,则剩余金额将再次可供令牌的原始所有者使用。此方法只能由具有指定操作 ID 的 notary 角色的 AccountOwner ID 调用。暂停只能由公证人完成。
@Validator(yup.string(), yup.string(), yup.number().positive())
public async executeHoldTokens(token_id: string, operation_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.executeHold(operation_id, quantity, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
  • quantity: number –要传输的暂挂令牌数。
返回:
  • 成功后,将收到一条消息,其中包含呼叫者的帐户 ID 和交易数量。
返回值示例:
{
 "msg":"Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin) is successfully executed '10' tokens from Operation Id 'opr_121'."
}
releaseHoldTokens
此方法释放暂挂令牌。传输未完成,所有保留的令牌将再次提供给原始所有者。此方法可以由具有 notary 角色的 AccountOwner ID 在指定时间限制内调用,也可以由付款人、收款人或公证人在指定时间限制之后调用。
@Validator(yup.string(), yup.string())
public async releaseHoldTokens(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。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,将发出一条消息,指示释放暂挂。
返回值示例:
{
 "msg":"Successfully released '10' tokens from Operation Id 'opr_121' to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: user1)."
}
getOnHoldIds
此方法返回指定帐户的所有持有 ID 的列表。此方法可由链代码的 Token AdminToken Auditor、指定组织的 Org AdminOrg Auditor 或帐户的 AccountOwner 调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getOnHoldIds(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.getOnHoldIds", "TOKEN", { account_id });
    return await this.Ctx.Account.getOnHoldIds(account_id);
  }
参数:
  • token_id: string- 令牌的 ID。
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含 ID 的 JSON 列表。
返回值示例:
{"msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121","holding_ids":["ohold~digicur~digiCurr101~opr_121"]}
getOnHoldDetailsWithOperationId
此方法返回指定操作 ID 和令牌的暂挂事务处理详细信息。此方法可以由链代码的 Token AdminToken Auditor 调用,也可以由事务处理参与者(发件人、收件人、公证人)调用。
@Validator(yup.string(), yup.string())
public async getOnHoldDetailsWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldDetailsWithOperationId(token_id, operation_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,包含以下属性的 JSON 暂挂对象:
  • 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- 暂挂到期之前的持续时间。
返回值示例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法返回指定操作 ID 和令牌的暂挂余额。此方法可以由链代码的 Token AdminToken Auditor 调用,也可以由事务处理参与者(发件人、收件人、公证人)调用。
@Validator(yup.string(), yup.string())
public async getOnHoldBalanceWithOperationId(token_id: string, operation_id: string) {
    return await this.Ctx.Hold.getOnHoldBalanceWithOperationId(token_id, operation_id);
}
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功时,JSON 字符串指示暂挂余额。
返回值示例:
{
	"msg": "Current Holding Balance of Operation 'opr_121' for token 'digiCurr101' is: 10",
	"holding_balance": 10
}

令牌行为管理的方法 - 可燃行为

burnTokens
此方法从交易调用者的账户中停用或刻录令牌。此方法的调用者必须具有帐户和刻录角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。此方法可由具有刻录器角色的帐户的 AccountOwner 调用。
@Validator(yup.string(), yup.number().positive())
public async burnTokens(token_id: string, quantity: number) {
    const token_asset = await this.getTokenObject(token_id);
    return await this.Ctx.Token.burn(quantity, token_asset);
}
参数:
  • token_id: string- 令牌的 ID。
  • quantity- 要刻录的标记数。
返回:
  • 成功后,将显示一则成功消息,其中包含消耗的令牌数量和账户 ID。
返回值示例:
{
    "msg": "Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
requestBurn
刻录器可以调用此方法,向刻录器公证器发送请求以销毁指定数量的标记,这些标记必须小于或等于其可用余额。刻录请求开始时,会立即从可用余额中扣除指定的金额,并将其添加到 onhold_burn_balance 字段。如果请求获得批准,则会刻录令牌。如果请求被拒绝,令牌将从 onhold_burn_balance 字段返回到可用余额。
@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- 将处理请求的刻录公证人的成员服务提供商 (membership service provider,MSP) ID。
  • notary_user_id: string- 将处理请求的刻录公证人的用户名或电子邮件 ID。
  • quantity: number –要燃烧的令牌数量。
  • time_to_expiration- 燃烧请求过期且不再有效的时间。
  • info_details: JSON- 指定请求类别 (category) 和说明 (description) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
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",
}
getAccountOnHoldBurnBalance
此方法返回指定用户的暂挂消耗余额。此方法只能由 Token AdminToken AuditorOrg AdminOrg Auditor 或帐户所有者调用。
@GetMethod()
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountOnHoldBurnBalance(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.getAccountOnHoldBurnBalance", "TOKEN", { account_id });
  return await this.Ctx.Account.getAccountOnHoldBurnBalance(account_id);
}
参数:
  • token_id: string- 要燃烧的令牌的 ID。
  • org_id string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id string- 用户的用户名或电子邮件 ID。
返回值示例:
{
  "msg": "Total On Hold Burning Balance is: 10",
  "onhold_burn_balance": 10
}
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) 的对象。

    如果使用的是 Visual Studio Code 与 CLI 或 Postman 集合,则可以采用不同的格式指定 info_details 参数。

    Visual Studio Code:{ "category": "category value", "description": "description value" }

    CLI / Postman: "{\"category\":\"category value\",\"description\":\"description value\"}"

返回值示例:
{
msg:
"Successfully burned 100 tokens from account id: oaccount~95be539b4e1e4136dd86a806020c97a930909325340481b8fd88d339874fa699 (Org-Id: Org1MSP, User-Id: admin)"
}

自定义方法

您可以使用令牌 SDK 方法为业务应用程序编写定制方法。

为了避免双重支出,请不要组合对状态数据库中的相同键 - 值对进行操作的多个异步函数。而是使用 bulkTransferTokens 方法在一个方法中进行多个传输。

以下示例说明如何在定制方法中使用令牌 SDK 方法。当调用 buyTicket 方法时,它将 20 个令牌从调用者的帐户传输到卖方的帐户,并返回传输的事务消息。

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async buyTicket(token_id: string, seller_org_id: string, seller_user_id: string) {
	const token = await this.getTokenObject(token_id);

	/**
	* The following method this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id) generates account id of the seller.
	*/
	const seller_account_id = await this.Ctx.Account.generateAccountId(token_id, seller_org_id, seller_user_id);

	/**
	* The following method this.Ctx.Token.transfer(seller_account_id, 20, token) transfers the quantity 20 from caller's
	* account & to seller's account.
	*/
	const transaction = await this.Ctx.Token.transfer(seller_account_id, 20, token);

	return transaction;
}

如果在定制方法中使用多个令牌 SDK 方法,请勿使用会影响状态数据库中相同键 - 值对的方法。以下示例显示了创建多个传输的错误方式:

@Validator(yup.string(), yup.string(), yup.string(), yup.string(), yup.string())
public async sendTokens(token_id: string, user1_org_id: string, user1_user_id: string, user2_org_id: string, user2_user_id: string) {
    const token = await this.getTokenObject(token_id);
    const user1_account_id = await Account.generateAccountId(token_id, user1_org_id, user1_user_id);
    const user2_account_id = await Account.generateAccountId(token_id, user2_org_id, user2_user_id);
    await token.transfer(user1_account_id, 20);
    await token.transfer(user2_account_id, 30);
}

而是使用 bulkTransferTokens 方法从调用者的帐户转移到多个帐户,如以下代码片段中所示。

bulkTransferTokens(token_id: string, flow: object[])

注意:

如果您在定制方法中使用多个令牌 SDK 方法,这些方法可能会影响状态数据库中的相同键 - 值对,请为令牌链代码启用 MVCC 优化。有关更多信息,请参见 MVCC Optimization

标记 SDK 方法

访问控制管理的方法

令牌 SDK 提供了访问控制功能。某些方法只能由令牌的 Token AdminOrg AdminAccountOwner 调用。您可以使用此功能来确保操作仅由预期用户执行。任何未经授权的访问都会导致错误。要使用访问控制功能,请从 ../lib/auth 模块导入 Authorization 类。
import { Authorization } from '../lib/auth';
addAdmin
此方法将用户添加为令牌链代码的 Token Admin
Ctx.Admin.addAdmin(org_id: string, user_id: string)
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,包含 JSON 对象的 promise 消息将列出作为令牌链代码的 Token Admin 添加的用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg": "Successfully added Admin (Org_Id: Org1MSP, User_Id: user1)"
}
removeAdmin
此方法将用户删除为令牌链代码的 Token Admin
Ctx.Admin.removeAdmin(org_id: string, user_id: string)
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,包含 JSON 对象的 promise 消息将列出不再是令牌链代码的 Token Admin 的用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: user1)"
}
isUserTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true。否则,该方法将返回 false
Ctx.Auth.isUserTokenAdmin()
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 布尔值响应和错误消息(如果遇到错误)。
getAllAdmins
此方法返回作为令牌链代码的 Token Admin 的所有用户的列表。
Ctx.Admin.getAllAdmins()
参数:
返回:
  • 成功后,具有 JSON 对象的承诺将列出作为令牌链代码 Token Admin 的所有用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "admins": [
        {
            "orgId": "Org1MSP",
            "userId": "admin"
        }
    ]
}
checkAuthorization
使用此方法可将访问控制检查添加到操作。某些令牌方法只能由令牌的 Token AdminAccountOwner 运行,也可以由具有多个帐户的用户使用 MultipleAccountOwner 运行。访问控制映射在 ../lib/constant.ts 文件中进行了介绍。您可以通过编辑 ../lib/constant.ts 文件来修改访问控制。要使用您自己的访问控制或禁用访问控制,请从自动生成的控制器方法和定制方法中删除访问控制代码。
export const TOKENACCESS = {
  ADMIN: {
    isUserTokenAdmin: ["Admin", "OrgAdmin"],
    addTokenAdmin: ["Admin"],
    removeTokenAdmin: ["Admin"],
    getAllAdmins: ["Admin", "OrgAdmin"],
    addOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    removeOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    getOrgAdmins: ["Admin", "OrgAdmin"],
  },
  TOKEN: {
    save: ["Admin"],
    getAllTokens: ["Admin", "OrgAdmin"],
    get: ["Admin", "OrgAdmin"],
    update: ["Admin"],
    getDecimals: ["Admin", "OrgAdmin"],
    getTokensByName: ["Admin", "OrgAdmin"],
    addRoleMember: ["Admin", "OrgAdminRoleCheck"],
    removeRoleMember: ["Admin", "OrgAdminRoleCheck"],
    isInRole: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getTotalMintedTokens: ["Admin", "OrgAdmin"],
    getNetTokens: ["Admin", "OrgAdmin"],
    getTokenHistory: ["Admin", "OrgAdmin"],
  },
  ROLE: {
    getAccountsByRole: ["Admin"],
    getOrgAccountsByRole: ["Admin", "OrgAdminForOrgId"],
    getUsersByRole: ["Admin"],
    getOrgUsersByRole: ["Admin", "OrgAdminForOrgId"],
  },
  TRANSACTION: {
    deleteTransactions: ["Admin"],
  },ACCOUNT: {
    createAccount: ["Admin", "OrgAdminForOrgId"],
    associateToken: ["Admin", "OrgAdminForAccountId"],
    getAllAccounts: ["Admin"],
    getAllOrgAccounts: ["Admin", "OrgAdminForOrgId"],
    getAccountsByUser: ["Admin", "OrgAdminForOrgId", "MultipleAccountOwner"],
    getAccount: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "AccountOwner"],
    getAccountTransactionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountTransactionHistoryWithFilters: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getSubTransactionsById: ["Admin", "TransactionInvoker"],
    getSubTransactionsByIdWithFilters: ["Admin", "TransactionInvoker"],
    getAccountBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountOnHoldBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getOnHoldIds: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getConversionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
  },
  ACCOUNT_STATUS: {
    get: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    activateAccount: ["Admin", "OrgAdminForOrgId"],
    suspendAccount: ["Admin", "OrgAdminForOrgId"],
    deleteAccount: ["Admin", "OrgAdminForOrgId"],
  },
  TOKEN_CONVERSION: {
    initializeExchangePoolUser: ["Admin"],
    addConversionRate: ["Admin"],
    updateConversionRate: ["Admin"],
    getConversionRate: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    getConversionRateHistory: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    tokenConversion: ["Admin", "AnyAccountOwner"],
    getExchangePoolUser: ["Admin"],
  },
}
await this.Ctx.Auth.checkAuthorization(<parameters>);
参数:
  • classFuncName: string- 类与方法之间的映射值,如 ../lib/constant.ts 文件中所述。
  • ...args- 变量参数,其中 args[0] 接受常量 'TOKEN'args[1] 接受 account_idAccountOwner 添加访问控制检查。要为 MultipleAccountOwner 添加访问控制检查,args[1] 将获取 org_idargs[2] 将获取 user_id
返回:
  • 成功时,承诺。出错时,将拒绝并显示错误消息。
addOrgAdmin
此方法将用户添加为组织的 Org Admin
Ctx.Admin.addOrgAdmin(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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()
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式数组。
返回值示例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addAdmin
此方法将用户添加为令牌链代码的 Token Admin
Ctx.Admin.addAdmin(org_id: string, user_id: string)
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,包含 JSON 对象的 promise 消息将列出作为令牌链代码的 Token Admin 添加的用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg": "Successfully added Admin (Org_Id: Org1MSP, User_Id: user1)"
}
removeAdmin
此方法将用户删除为令牌链代码的 Token Admin
Ctx.Admin.removeAdmin(org_id: string, user_id: string)
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,包含 JSON 对象的 promise 消息将列出不再是令牌链代码的 Token Admin 的用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg": "Successfully removed Admin (Org_Id: Org1MSP, User_Id: user1)"
}
isUserTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true。否则,该方法将返回 false
Ctx.Auth.isUserTokenAdmin()
参数:
  • user_id- 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 布尔值响应和错误消息(如果遇到错误)。
getAllAdmins
此方法返回作为令牌链代码的 Token Admin 的所有用户的列表。
Ctx.Admin.getAllAdmins()
参数:
返回:
  • 成功后,具有 JSON 对象的承诺将列出作为令牌链代码 Token Admin 的所有用户的详细信息。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "admins": [
        {
            "orgId": "Org1MSP",
            "userId": "admin"
        }
    ]
}
checkAuthorization
使用此方法可将访问控制检查添加到操作。某些令牌方法只能由令牌的 Token AdminAccountOwner 运行,也可以由具有多个帐户的用户使用 MultipleAccountOwner 运行。访问控制映射在 ../lib/constant.ts 文件中进行了介绍。您可以通过编辑 ../lib/constant.ts 文件来修改访问控制。要使用您自己的访问控制或禁用访问控制,请从自动生成的控制器方法和定制方法中删除访问控制代码。
export const TOKENACCESS = {
  ADMIN: {
    isUserTokenAdmin: ["Admin", "OrgAdmin"],
    addTokenAdmin: ["Admin"],
    removeTokenAdmin: ["Admin"],
    getAllAdmins: ["Admin", "OrgAdmin"],
    addOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    removeOrgAdmin: ["Admin", "OrgAdminForOrgId"],
    getOrgAdmins: ["Admin", "OrgAdmin"],
  },
  TOKEN: {
    save: ["Admin"],
    getAllTokens: ["Admin", "OrgAdmin"],
    get: ["Admin", "OrgAdmin"],
    update: ["Admin"],
    getDecimals: ["Admin", "OrgAdmin"],
    getTokensByName: ["Admin", "OrgAdmin"],
    addRoleMember: ["Admin", "OrgAdminRoleCheck"],
    removeRoleMember: ["Admin", "OrgAdminRoleCheck"],
    isInRole: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getTotalMintedTokens: ["Admin", "OrgAdmin"],
    getNetTokens: ["Admin", "OrgAdmin"],
    getTokenHistory: ["Admin", "OrgAdmin"],
  },
  ROLE: {
    getAccountsByRole: ["Admin"],
    getOrgAccountsByRole: ["Admin", "OrgAdminForOrgId"],
    getUsersByRole: ["Admin"],
    getOrgUsersByRole: ["Admin", "OrgAdminForOrgId"],
  },
  TRANSACTION: {
    deleteTransactions: ["Admin"],
  },ACCOUNT: {
    createAccount: ["Admin", "OrgAdminForOrgId"],
    associateToken: ["Admin", "OrgAdminForAccountId"],
    getAllAccounts: ["Admin"],
    getAllOrgAccounts: ["Admin", "OrgAdminForOrgId"],
    getAccountsByUser: ["Admin", "OrgAdminForOrgId", "MultipleAccountOwner"],
    getAccount: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "AccountOwner"],
    getAccountTransactionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountTransactionHistoryWithFilters: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getSubTransactionsById: ["Admin", "TransactionInvoker"],
    getSubTransactionsByIdWithFilters: ["Admin", "TransactionInvoker"],
    getAccountBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getAccountOnHoldBalance: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getOnHoldIds: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    getConversionHistory: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
  },
  ACCOUNT_STATUS: {
    get: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    history: ["Admin", "OrgAdminForAccountId", "AccountOwner"],
    activateAccount: ["Admin", "OrgAdminForOrgId"],
    suspendAccount: ["Admin", "OrgAdminForOrgId"],
    deleteAccount: ["Admin", "OrgAdminForOrgId"],
  },
  TOKEN_CONVERSION: {
    initializeExchangePoolUser: ["Admin"],
    addConversionRate: ["Admin"],
    updateConversionRate: ["Admin"],
    getConversionRate: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    getConversionRateHistory: ["Admin", "OrgAdmin", "AnyAccountOwner"],
    tokenConversion: ["Admin", "AnyAccountOwner"],
    getExchangePoolUser: ["Admin"],
  },
}
await this.Ctx.Auth.checkAuthorization(<parameters>);
参数:
  • classFuncName: string- 类与方法之间的映射值,如 ../lib/constant.ts 文件中所述。
  • ...args- 变量参数,其中 args[0] 接受常量 'TOKEN'args[1] 接受 account_idAccountOwner 添加访问控制检查。要为 MultipleAccountOwner 添加访问控制检查,args[1] 将获取 org_idargs[2] 将获取 user_id
返回:
  • 成功时,承诺。出错时,将拒绝并显示错误消息。
addOrgAdmin
此方法将用户添加为组织的 Org Admin
Ctx.Admin.addOrgAdmin(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,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()
参数:
返回:
  • 成功后,包含 orgIduserId 对象的 JSON 格式数组。
返回值示例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}
addTokenAuditor
此方法将用户添加为链代码的 Token Auditor
this.Ctx.Admin.addTokenAuditor(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Token Auditor 添加的用户详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "cd81f6c4c9e7c18ece357dbf5c139ef66ef2d6566be3b14de5f6d0a3fd4bb2f0",
        "payload": {
            "msg": "Successfully added Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 196
    }
}
removeTokenAuditor
此方法将用户删除为链代码的 Token Auditor
this.Ctx.Admin.removeTokenAuditor(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Token Auditor 的用户的详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "a886a6040fbc76374a3c78c89ab0ffc9f7b8391cc5239b169bf3b878cf40c67b",
        "payload": {
            "msg": "Successfully removed Token Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 219
    }
}
getTokenAuditors
此方法返回链代码的所有 Token Auditors
this.Ctx.Admin.getAllTokenAuditors()
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "CB",
                    "user_id": "auditor_user_cb"
                }
            ]
        },
        "encode": "JSON"
    }
}
addOrgAuditor
此方法将用户添加为链代码的 Org Auditor
this.Ctx.Admin.addOrgAuditor(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含作为链代码的 Org Auditor 添加的用户详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "44bbad35a1478cb714e32f7cfd551897868a203520aab9cea5771d3aadc1cf03",
        "payload": {
            "msg": "Successfully added Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20009",
        "blockNumber": 198
    }
}
removeOrgAuditor
此方法将用户删除为链代码的 Org Auditor
this.Ctx.Admin.removeOrgAuditor(org_id, user_id)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将包含被删除为链代码 Org Auditor 的用户的详细信息的消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "c3bc720461004a53b37c68d4bb264858b88d980bc093a0a3ebb62a32974fb306",
        "payload": {
            "msg": "Successfully removed Org Auditor (Org_Id: CB, User_Id: cb)"
        },
        "encode": "JSON",
        "sourceURL": "cb-oabcs1-bom.blockchain.ocp.example.com:20010",
        "blockNumber": 221
    }
}
getOrgAuditors
此方法返回链代码的所有 Org Auditors
this.Ctx.Admin.getAllOrgAuditors()
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "payload": {
            "auditors": [
                {
                    "org_id": "FI1",
                    "user_id": "auditor_user_fi1"
                },
                {
                    "org_id": "FI2",
                    "user_id": "auditor_user_fi2"
                }
            ]
        },
        "encode": "JSON"
    }
}

标记配置管理的方法

save
此方法创建令牌并将其属性保存在状态数据库中。
Ctx.Token.save(token: <Instance of Token Class>,extraMetadata?:any)
参数:
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,将显示包含令牌详细信息的 promise 消息。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "assetType":"otoken",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "token_type":"fungible",
   "behaviors":[
      "divisible",
      "mintable",
      "transferable",
      "burnable",
      "roles"
   ],
   "roles":{
      "minter_role_name":"minter"
   },
   "mintable":{
      "max_mint_quantity":1000
   },
   "divisible":{
      "decimal":2
   },
   "currency_name":"DOLLAR",
   "token_to_currency_ratio":1
}
update
此方法更新令牌属性。创建令牌资产后,仅更新 token_desc 值及其定制属性。
Ctx.Token.update(token: <Instance of Token Class>)
参数:
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,将显示包含令牌详细信息的 promise 消息。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "assetType":"otoken",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "token_desc":"Digital Currency equiv of dollar",
   "token_type":"fungible",
   "behaviors":[
      "divisible",
      "mintable",
      "transferable",
      "burnable",
      "roles"
   ],
   "roles":{
      "minter_role_name":"minter"
   },
   "mintable":{
      "max_mint_quantity":1000
   },
   "divisible":{
      "decimal":2
   },
   "currency_name":"DOLLAR",
   "token_to_currency_ratio":1
}
getTokenDecimals
此方法返回小数标记的可用小数位数。如果未指定 divisible 行为,则默认值为 0。
Ctx.Token.getTokenDecimals(token_id: string)
参数:
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,令牌的小数位(在数字数据类型中)。出错时,将返回错误消息。
返回值示例:
1
get
如果某个令牌对象存在于状态数据库中,则此方法返回该对象。
Ctx.Token.get(token_id: string)
参数:
  • token_id: string- 要返回的令牌的 ID。
返回:
  • 成功后,使用令牌的 JSON 表示形式发出 promise。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "assetType": "otoken",
    "token_id": "token1",
    "token_name": "account",
    "token_desc": "Token 1",
    "token_type": "fungible",
    "behaviors": [
        "divisible",
        "mintable",
        "transferable",
        "burnable",
        "holdable",
        "roles"
    ],
    "roles": {
        "minter_role_name": "minter",
        "burner_role_name": "burner",
        "notary_role_name": "notary"
    },
    "mintable": {
        "max_mint_quantity": 20000
    },
    "divisible": {
        "decimal": 1
    },
    "token_to_currency_ratio": 2,
    "currency_representation": "EURO"
}
history
此方法返回指定标记的历史记录。
Ctx.Token.history(tokenId)
参数:
  • tokenId: string- 令牌的 ID。
返回:
  • 成功后,具有指定标记的帐户历史记录详细信息数组的 promise。出错时,将拒绝并显示错误消息。
返回值示例:
[
    {
        "trxId": "0d75f09446a60088afb948c6aca046e261fddcd43df416076201cdc5565f1a35",
        "timeStamp": "2023-09-01T16:48:41.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_desc": "updatedDesc",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    },
    {
        "trxId": "3666344878b043b65d5b821cc79c042ba52aec467618800df5cf14eac69f72fa",
        "timeStamp": "2023-08-31T20:24:55.000Z",
        "value": {
            "assetType": "otoken",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "token_standard": "ttf+",
            "token_type": "fungible",
            "token_unit": "fractional",
            "behaviors": [
                "divisible",
                "mintable",
                "transferable",
                "burnable",
                "roles"
            ],
            "roles": {
                "minter_role_name": "minter"
            },
            "mintable": {
                "max_mint_quantity": 1000
            },
            "divisible": {
                "decimal": 2
            }
        }
    }
]
getAllTokens
此方法返回保存在状态数据库中的所有令牌资产。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
Ctx.Token.getAllTokens()
参数:
返回:
  • 成功后,它将返回具有所有令牌资产的承诺。出错时,将返回错误消息。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "98e0a0a115803d25b843d630e6b23c435a192a03eb0a301fc9375f05da49a8b2",
        "payload": [
            {
                "key": "token1",
                "valueJson": {
                    "assetType": "otoken",
                    "token_id": "token1",
                    "token_name": "vtok",
                    "token_type": "fungible",
                    "behaviours": [
                        "divisible",
                        "mintable",
                        "transferable",
                        "burnable",
                        "holdable",
                        "roles"
                    ],
                    "roles": {
                        "burner_role_name": "burner",
                        "notary_role_name": "notary"
                    },
                    "mintable": {
                        "max_mint_quantity": 0
                    },
                    "divisible": {
                        "decimal": 1
                    }
                }
            }
        ],
        "encode": "JSON"
    }
}
getTokensByName
此方法返回具有指定名称的所有标记资产。此方法使用 Berkeley DB SQL 丰富的查询,并且只能在连接到远程 Oracle Blockchain Platform 网络时调用。
Ctx.Token.getTokensByName(token_name: string)
参数:
  • token_name: string- 标记的名称,对应于模型的 Token_name 属性。该值是令牌的类名。
返回:
  • 它以 JSON 格式返回指定名称的所有标记资产的数组。
返回值示例:
{
    "returnCode": "Success",
    "error": "",
    "result": {
        "txid": "98e0a0a115803d25b843d630e6b23c435a192a03eb0a301fc9375f05da49a8b2",
        "payload": [
            {
                "key": "token1",
                "valueJson": {
                    "assetType": "otoken",
                    "token_id": "token1",
                    "token_name": "vtok",
                    "token_type": "fungible",
                    "behaviours": [
                        "divisible",
                        "mintable",
                        "transferable",
                        "burnable",
                        "holdable",
                        "roles"
                    ],
                    "roles": {
                        "burner_role_name": "burner",
                        "notary_role_name": "notary"
                    },
                    "mintable": {
                        "max_mint_quantity": 0
                    },
                    "divisible": {
                        "decimal": 1
                    }
                }
            }
        ],
        "encode": "JSON"
    }
}
isTokenType
此方法指示是否存在具有指定 ID 的标记资产。
Ctx.Token.isTokenType(token_id: string)
参数:
  • token_id: string- 要检查的令牌的 ID。
返回:
  • 成功后,如果存在具有指定 ID 的令牌资产,则承诺为 true 。出错时,将拒绝并显示错误消息。
返回值示例:
true
getByRange
此方法在内部调用网状结构网络 getStateByRange 方法。即使从分类账中返回具有给定 ID 的任何资产,此方法也会将资产强制转换为调用方资产类型。
<Token ClassCtx.Token.getByRange(start_token_id: string, end_token_id: string, token_class_reference?: <Instance of Token Class> )
参数:
  • startId: string- 范围的起始键。此密钥包含在范围内。
  • endId: string- 范围的结束键。此键已从范围中排除。
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,使用数组 <Token Class> 的 promise。出错时,将拒绝并显示错误消息。
示例:
@validator(yup.string(), yup.string())
public async getDigiCurrGetByRange(start_token_id: string, end_token_id: string) {
   return await this.Ctx.Token.getByRange(start_token_id, end_token_id, DigiCurr);
}
返回值示例:
[
    {
        "assetType": "otoken",
        "token_id": "token1",
        "token_name": "digicur",
        "token_desc": "Token 1",
        "token_type": "fungible",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "holdable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner",
            "notary_role_name": "notary"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "divisible": {
            "decimal": 0
        },
        "token_to_currency_ratio": 1.5,
        "currency_representation": "USD"
    },
    {
        "assetType": "otoken",
        "token_id": "token2",
        "token_name": "digicur",
        "token_desc": "Token2",
        "token_type": "fungible",
        "behaviors": [
            "divisible",
            "mintable",
            "transferable",
            "burnable",
            "holdable",
            "roles"
        ],
        "roles": {
            "minter_role_name": "minter",
            "burner_role_name": "burner",
            "notary_role_name": "notary"
        },
        "mintable": {
            "max_mint_quantity": 20000
        },
        "divisible": {
            "decimal": 0
        },
        "token_to_currency_ratio": 1,
        "currency_representation": "EURO"
    }
]

账户管理方法

getCallerAccountId
此方法返回调用者的帐户 ID。
Ctx.Account.getCallerAccountId(token_id: string)
参数:
  • tokenId: string- 令牌的 ID。
返回:
  • 成功时,使用调用方帐户 ID 的 promise。出错时,将拒绝并显示错误消息。
返回值示例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
generateAccountId
此方法返回帐户 ID,该 ID 是一组字母数字字符,前缀为 oaccount~<token asset name>~,后跟实例所有者或登录到实例的用户的用户的用户名或电子邮件 ID (user_id) 的散列、当前网络组织中用户的成员资格服务提供商 ID (org_id) 以及唯一令牌 ID (token_id)。
Ctx.Account.generateAccountId(token_id: string, org_id: string, user_id: string)
参数:
  • tokenId: string- 令牌的 ID。
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,生成账户 ID 为 promise。出错时,将拒绝并显示错误消息。
返回值示例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
createAccount
此方法为指定的用户和令牌创建帐户。每个在任何时候都有令牌的用户都必须有一个帐户。账户跟踪用户的余额、暂挂余额和事务处理历史记录。账户 ID 是一组字母数字字符,以 oaccount~<token asset name>~ 为前缀,后跟实例所有者或登录到实例的用户的用户的用户名或电子邮件 ID (user_id) 的散列,即当前网络组织中用户的成员资格服务提供商 ID (org_id)。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。
this.Ctx.Account.createAccount(org_id: string, user_id: string, token_type: string)
参数:
  • org_id: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id: string- 用户的用户名或电子邮件 ID。
  • token_type: string- 令牌的类型,必须是 fungible
返回:
  • 成功后,新帐户对象将采用 JSON 格式。
返回值示例:
{
  "assetType": "oaccount",
  "bapAccountVersion": 0,
  "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
  "user_id": "admin",
  "org_id": "Org1MSP",
  "token_type": "fungible",
  "token_id": "",
  "token_name": "",
  "balance": 0,
  "onhold_balance": 0
}
associateTokenToAccount
此方法将可变令牌与账户关联。此方法只能由链代码的 Token Admin 或相关组织的 Org Admin 调用。
async associateTokenToAccount(account_id: string, token_id: string)
参数:
  • account_id: string- 帐户的 ID。
  • token_id: string- 令牌的 ID。
返回:
  • 成功后,更新账户的 JSON 对象。
返回值示例:
{
    "assetType": "oaccount",
    "bapAccountVersion": 0,
    "account_id": "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
    "user_id": "admin",
    "org_id": "Org1MSP",
    "token_type": "fungible",
    "token_id": "fungible",
    "token_name": "fiatmoneytok",
    "balance": 0,
    "onhold_balance": 0
}
getAccountWithStatus
此方法返回指定帐户的帐户详细信息,包括帐户状态。
Ctx.Account.getAccountWithStatus(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,对客户详细信息做出承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
  "bapAccountVersion": 0,
  "assetType": "oaccount",
  "status": "active",
  "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
  "user_id": "idcqa",
  "org_id": "appdev",
  "token_type": "fungible",
  "token_id": "t1",
  "token_name": "obptok",
  "balance": 0,
  "onhold_balance": 0
}
getAccount
此方法返回指定帐户的帐户详细信息。
Ctx.Account.getAccount(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,对客户详细信息做出承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "assetType":"oaccount",
   "bapAccountVersion": 0,
   "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
   "user_id":"user1",
   "org_id":"Org1MSP",
   "token_id":"digiCurr101",
   "token_name":"digicur",
   "balance":0,
   "onhold_balance":0
}
history
此方法返回指定帐户的帐户历史记录详细信息数组。
Ctx.Account.history(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,使用账户历史记录详细信息数组提供承诺。出错时,将拒绝并显示错误消息。返回值与 getAccountHistory 方法相同。
返回值示例:
[
    {
      "trxId":"2gsdh17fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":100,
         "onhold_balance":0,
         "bapAccountVersion": 1
   },
   {
      "trxId":"9fd07fff222467e5667be042e33ce18e804b3e065cca15de306f837e416d7c3e",
      "timeStamp":1629718288,
      "value":{
         "assetType":"oaccount",
         "account_id":"oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
         "user_id":"user1",
         "org_id":"Org1MSP",
         "token_id":"digiCurr101",
         "token_name":"digicur",
         "balance":0,
         "onhold_balance":0,
         "bapAccountVersion": 0
      }
   }
]
getAccountOnHoldBalance
此方法返回指定账户的暂挂余额。
Ctx.Account.getAccountOnHoldBalance(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,带有 JSON 对象的 promise 将显示指定账户的暂挂余额。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "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.Account.getAllAccounts()
参数:
返回:
  • 成功后,一个包含列出所有帐户的 JSON 对象的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
[
           {
               "key": "oaccount~digicur~2e2ef3375ae347cbd7b4d3d7be5cece803f9c36a184aaf2b8d332c5d2dcead52",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~2e2ef3375ae347cbd7b4d3d7be5cece803f9c36a184aaf2b8d332c5d2dcead52",
                   "user_id": "admin",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "bapAccountVersion": 0,
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~30080c7e5ba94035af57fbbccbbb495e92515e4b2b3dbcd476eb1c0343e4da65",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~30080c7e5ba94035af57fbbccbbb495e92515e4b2b3dbcd476eb1c0343e4da65",
                   "bapAccountVersion": 0,
                   "user_id": "user1",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~cbde438258cb01a82f71a9a9f8029243c40c6d836a505432120529c2b3c2ff0c",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~cbde438258cb01a82f71a9a9f8029243c40c6d836a505432120529c2b3c2ff0c",
                   "bapAccountVersion": 0,
                   "user_id": "user2",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 0,
                   "onhold_balance": 0
               }
           },
           {
               "key": "oaccount~digicur~ecbc3aefcc562d3049c988717940195b30297e95012b7824bbd33a57ca50a626",
               "valueJson": {
                   "assetType": "oaccount",
                   "account_id": "oaccount~digicur~ecbc3aefcc562d3049c988717940195b30297e95012b7824bbd33a57ca50a626",
                   "bapAccountVersion": 0,
                   "user_id": "user3",
                   "org_id": "Org1MSP",
                   "token_id": "digiCurr101",
                   "token_name": "digicur",
                   "balance": 500,
                   "onhold_balance": 0
               }
           }
       ]
getUserByAccountId
此方法返回指定帐户的用户详细信息。
Ctx.Account.getUserByAccountId(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,具有包含三个属性的 JSON 对象的 promise:
    • user_id- 用户的用户名或电子邮件 ID。
    • org_id- 当前网络组织中用户的成员服务提供商 (membership service provider,MSP) ID。
    • token_id- 令牌的 ID。
  • 出错时,将拒绝并显示错误消息。
返回值示例:
{
   "token_id": "digiCurr101",
   "user_id": "user1",
   "org_id": "Org1MSP"
}
getAccountBalance
此方法返回指定帐户的帐户余额。
Ctx.Account.getAccountBalance(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功后,包含两个属性的 JSON 对象的 promise 消息:
    • msg- 显示当前余额的消息。
    • user_balance –当前余额的数值。
  • 出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg": "Current Balance is: 200",
    "user_balance": 200
}
getAllOrgAccounts
此方法返回属于指定组织的所有令牌帐户的列表。
Ctx.Account.getAllOrgAccounts(org_id: string) 
参数:
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出指定组织的所有客户。
返回值示例:
[
    {
        "key": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~2de8db6b91964f8c9009136831126d3cfa94e1d00c4285c1ea3e6d1f36479ed4",
            "user_id": "idcqa",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    },
    {
        "key": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
        "valueJson": {
            "bapAccountVersion": 0,
            "assetType": "oaccount",
            "account_id": "oaccount~620fcf5deb5fd5a65c0b5b10fda129de0f629ccd232c5891c130e24a574df50a",
            "user_id": "example_minter",
            "org_id": "appdev",
            "token_type": "fungible",
            "token_id": "token",
            "token_name": "fiatmoneytok",
            "balance": 0,
            "onhold_balance": 0
        }
    }
]

角色管理的方法

addRoleMember
此方法将角色添加到指定的用户和令牌。
Ctx.Token.addRoleMember(role: string, account_id: string, token: <Instance of Token Class>)
参数:
  • role: string- 要添加到指定用户的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • account_id: number- 要将角色添加到的帐户 ID。
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "msg":"Successfully added role minter to oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id :          Org1MSP, user_id : user1)"
}
removeRoleMember
此方法从指定用户和令牌中删除角色。
Ctx.Token.removeRoleMember(role: string, account_id: string, token: <Instance of Token Class>)
参数:
  • role: string- 要从指定用户中删除的角色的名称。mintableburnable 行为对应于规范文件的 minter_role_nameburner_role_name 属性。同样,notary 角色对应于规范文件的 notary_role_name 属性。
  • account_id: number- 用于从中删除角色的帐户 ID。
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
  "msg":"successfully removed member_id oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f (org_id : Org1MSP, user_id : user1) from role minter"
}
getAccountsByRole
此方法返回指定角色和令牌的所有帐户的列表。
Ctx.Role.getAccountsByRole(token_id: string, role: string)
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功时,带有 JSON 对象的 promise 会列出指定角色和令牌的所有帐户。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "accounts": [
        "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
        "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"
    ]
}
getAccountsByUser
此方法返回指定用户的所有帐户 ID 的列表。
async getAccountsByUser(org_id: string, user_id: string)
参数:
  • org_id string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • user_id string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,会出现帐户 ID 的 JSON 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法返回指定角色和令牌的所有用户的列表。
Ctx.Role.getUsersByRole(token_id: string, role: string)
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要搜索的角色的名称。
返回:
  • 成功时,带有 JSON 对象的承诺会列出指定角色和令牌的所有用户。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "users":[
      {
         "token_id":"digiCurr101",
         "user_id":"user1",
         "org_id":"Org1MSP"
      }
   ]
}
isInRole
此方法指示用户和令牌是否具有指定的角色。
Ctx.Token.isInRole(role: string, account_id: string, token: <Instance of Token Class>)
参数:
  • role: string- 要检查的角色的名称。
  • account_id: number- 要检查的帐户 ID。
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,如果用户具有角色,则承诺为 true ;如果用户没有角色,则承诺为 false 。出错时,将拒绝并显示错误消息。
返回值示例:
{"result":"true"}
getOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。
Ctx.Role.getOrgAccountsByRole(token_id: string, role: string, org_id: string)
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}
getOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。
Ctx.Role.getOrgUsersByRole(token_id: string, role: string, org_id: string)
参数:
  • token_id: string- 令牌的 ID。
  • role: string- 要检查的角色的名称。
  • org_id: string- 组织的成员服务提供商 (membership service provider,MSP) ID。
返回:
  • 成功后,在指定组织中具有指定角色的所有用户的列表。
返回值示例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}
roleCheck
此方法检查提供的帐户 ID 是否是任何角色的成员。
Ctx.Token.roleCheck(account_id: string, token: <Instance of Token Class>)
参数:
  • account_id: string- 要检查的帐户 ID。
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 如果帐户 ID 是任何角色的一部分,则返回 true。否则,将返回 false
返回值示例:
{ result: true }

事务处理历史记录管理的方法

getAccountTransactionHistory
此方法返回指定账户的事务处理历史记录详细信息数组。
Ctx.Account.getAccountTransactionHistory(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 返回值与 getAccountTransactionHistory 方法相同。
  • 成功后,使用账户事务处理对象数组的 promise:
    • transaction_id- 事务处理的 ID。
    • transacted_account –发生交易的帐户。
    • transaction_type- 事务处理类型。
    • transacted_amount –事务处理的金额。
    • timestamp –交易时间。
    • balance –交易时的账户余额。
    • onhold_balance —事务处理时的暂挂余额。
    • sub_transactions- 仅对于批量传输,列出属于批量传输一部分的事务。
    • holding_id-holdTokens 方法返回的唯一标识符。
    • token_id- 令牌的 ID。
  • 出错时,将拒绝并显示错误消息。
返回值示例:
[
   {
      "transaction_id":"otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
      "transacted_amount":20,
      "timestamp":"2021-08-17T06:04:24.000Z",
      "balance":60,
      "onhold_balance":0,
      "token_id":"digiCurr101",
      "transaction_type":"BULKTRANSFER",
      "sub_transactions":[
         {
            "transacted_account":"oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
            "transaction_type":"CREDIT",
            "transaction_id":"otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "transacted_amount":10
         }
      ]
   },
   {
      "transaction_id":"otransaction~757864d5369bd0539d044caeb3bb4898db310fd7aa740f45a9938771903d43da",
      "transacted_amount":50,
      "timestamp":"2021-08-17T06:02:44.000Z",
      "balance":50,
      "onhold_balance":0,
      "token_id":"digiCurr101",
      "transacted_account":"oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
      "transaction_type":"CREDIT"
   }
]
getAccountTransactionHistoryWithFilters
此方法返回指定账户的事务处理历史记录详细信息数组。仅当连接到远程 Oracle Blockchain Platform 网络时,才能调用此方法。
await this.Ctx.Account.getAccountTransactionHistoryWithFilters(account_id: string, filters?: Filters)
参数:
  • account_id: string- 帐户的 ID。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
示例:

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~672897b5a4fa78b421c000e4d6d4f71f3d46529bfbb5b4be10bf5471dc35ce89",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:46:04.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "balance": 90,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~467bb67a33aaffca4487f33dcd46c9844efdb5421a2e7b6aa2d53152eb2c6d85",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:45:47.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "balance": 95,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~c6d56ce54a9bbe24597d1d10448e39316dc6f16328bf3c5b0c8ef10e1dfeb397",
        "transacted_amount": 100,
        "timestamp": "2022-04-20T15:44:26.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~deb5fb0906c40506f6c2d00c573b774e01a53dd91499e651d92ac4778b6add6a",
        "transaction_type": "MINT",
        "balance": 100,
        "onhold_balance": 0
    }
]
getSubTransactionHistory
此方法返回指定事务处理的事务处理历史记录详细信息数组。
await this.Ctx.Account.getSubTransactionHistory(transaction_id)
参数:
  • transaction_id: string —批量传输事务处理的 ID。
示例:

ochain invoke GetAccountSubTransactionHistory 'otransaction~21972b4d206bd52ea77924efb259c67217edb23b4386580d1bee696f6f864b9b'

[
    {
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "balance": 85,
        "onhold_balance": 0
    }
]
getSubTransactionHistoryWithFilters
此方法返回指定事务处理的子事务处理历史记录详细信息数组。
await this.Ctx.Account.getSubTransactionHistoryWithFilters(transaction_id: string, filters?: SubTransactionFilters)
参数:
  • transaction_id: string —批量传输事务处理的 ID。
  • filters: string- 可选参数。如果为空,则返回所有记录。PageSize 属性确定要返回的记录数。如果 PageSize 为 0,则默认页面大小为 20。Bookmark 属性确定要返回的记录的起始索引。有关更多信息,请参见 Hyperledger Fabric 文档。必须以 RFC-3339 格式指定 StartTimeEndTime 属性。
示例:

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

[
    {
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c81e728d9d4c2f636f067f89cc14862c",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~16c38d804413ebabf416360d374f76c973d4e71c74adfde73cc40c7c274883b8",
        "transaction_type": "DEBIT",
        "balance": 80,
        "onhold_balance": 0
    },
    {
        "transaction_id": "otransaction~6e0f8fe4a6430322170b9c619b04b6c9f1c8d257923f611b866bdf69d7fe6cb8~c4ca4238a0b923820dcc509a6f75849b",
        "transacted_amount": 5,
        "timestamp": "2022-04-20T15:52:21.000Z",
        "token_id": "token1",
        "transacted_account": "oaccount~fbf95683b21bbc91a22205819ac1e2e9c90355d536821ed3fe22b7d23915c248",
        "transaction_type": "DEBIT",
        "balance": 85,
        "onhold_balance": 0
    }
]
getTransactionById
此方法返回 Transaction 资产的历史记录。
async getTransactionById(transaction_id: string)
参数:
  • transaction_id: string —事务处理资产的 ID。
返回:
  • 成功时,事务处理资产历史记录。
返回值示例:
{
    "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
    "history": [
        {
            "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
            "timeStamp": 1629180264,
            "value": {
                "assetType": "otransaction",
                "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                "token_id": "digiCurr101",
                "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                "to_account_id": "",
                "transaction_type": "BULKTRANSFER",
                "amount": 20,
                "timestamp": "2021-08-17T06:04:24.000Z",
                "number_of_sub_transactions": 2,
                "holding_id": ""
            }
        }
    ],
    "sub_transactions": [
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c4ca4238a0b923820dcc509a6f75849b",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        },
        {
            "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
            "history": [
                {
                    "trxId": "68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775",
                    "timeStamp": 1629180264,
                    "value": {
                        "assetType": "otransaction",
                        "transaction_id": "otransaction~68f46c90d0d8d6b93d827e6b9e0152b4845e6e42a61965e63a9bbf1d8e0fc775~c81e728d9d4c2f636f067f89cc14862c",
                        "token_id": "digiCurr101",
                        "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
                        "to_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
                        "transaction_type": "TRANSFER",
                        "amount": 10,
                        "timestamp": "2021-08-17T06:04:24.000Z",
                        "number_of_sub_transactions": 0,
                        "holding_id": ""
                    }
                }
            ]
        }
    ]
}
deleteHistoricalTransactions
此方法返回指定账户的事务处理历史记录详细信息数组。
async deleteHistoricalTransactions(time_to_expiration: Date)
参数:
  • time_to_expiration: Date- 指示何时删除事务的时间戳。早于指定时间的事务处理资产将被删除。
返回:
  • 返回值与 getAccountTransactionHistory 方法相同。
  • 成功后,使用账户事务处理对象数组的 promise:
    • transaction_id- 事务处理的 ID。
    • transacted_account –发生交易的帐户。
    • transaction_type- 事务处理类型。
    • transacted_amount –事务处理的金额。
    • timestamp –交易时间。
    • balance –交易时的账户余额。
    • onhold_balance —事务处理时的暂挂余额。
    • sub_transactions- 仅对于批量传输,列出属于批量传输一部分的事务。
    • holding_id-holdTokens 方法返回的唯一标识符。
    • token_id- 令牌的 ID。
  • 出错时,将拒绝并显示错误消息。
返回值示例:
"payload": {
            "msg": "Successfuly deleted transaction older than date: Thu Aug 19 2021 11:19:36 GMT+0000 (Coordinated Universal Time).",
            "transactions": [
                "otransaction~ec3366dd48b4ce2838f820f2f138648e6e55a07226713e59b411ff31b0d21058"
            ]
        }

令牌行为管理

令牌生命周期管理方法基于令牌分类框架的标准。要使用令牌生命周期方法,请从 ../lib/token 模块导入 Token 类。
import { Token } from '../lib/token';

令牌行为管理方法 - 可铸造行为

mint
此方法会生成一定数量的令牌,然后这些令牌归方法的调用者所有。调用方必须具有帐户和 minter 角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。
Ctx.Token.mint(quantity: number, token: <Instance of Token Class>)
参数:
  • quantity: number - 要铸造的标记总数。
  • token: <Instance of Token Class>- 要铸造的令牌资产。
返回:
  • 成功后,将收到包含成功消息和 toAccount 详细信息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
  "msg":"Successfully minted 1000 tokens to Account Id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}
getTotalMintedTokens
此方法返回铸造的令牌总数。
Ctx.Token.getTotalMintedTokens(token: <Instance of Token Class>)
参数:
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,铸币代币的数量,即数字数据类型。出错时,将返回错误消息。
返回值示例:
4000
getNetTokens
此方法返回系统中可用的令牌的净数量。净令牌是指令牌被烧毁后剩余的令牌数量。在方程式中:净代币 = 总铸币代币 - 总烧毁代币。如果未刻录任何令牌,则净令牌数等于铸造的令牌总数。
Ctx.Token.getNetTokens(token: <Instance of Token Class>)
参数:
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功时,数字数据类型中的净令牌数量。出错时,将返回错误消息。
返回值示例:
2000
getMaxMintQuantity
此方法返回令牌的最大可铸件数量。如果未指定 max_mint_quantity 行为,则默认值为 0,这允许铸造任意数量的令牌。
Ctx.Token.getMaxMintQuantity(token: <Instance of Token Class>)
参数:
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,标记的最大可铸件数量(以数字数据类型表示)。出错时,将返回错误消息。
返回值示例:
20000

令牌行为管理的方法 - 可转移行为

transfer
此方法将令牌从事务处理调用方传输到 to_account_id 账户。此方法的调用方必须具有帐户,且数量必须在规范文件中 divisible 行为的 decimal 参数指定的十进制值内。
Ctx.Token.transfer(to_account_id: string, quantity: number, token: <Instance of Token Class>)
参数:
  • to_account_id: string- 用于接收令牌的帐户 ID。
  • quantity: number –要传输的令牌总数。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
 "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: object[], token: <Instance of Token Class>)
参数:
  • 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
    }]
  • token: <Instance of Token Class>- 要操作的令牌资产。
返回:
  • 成功后,提交具有成功消息和客户信息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
    "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: number, time_to_expiration: Date, token: <Instance of Token Class>)
参数:
  • 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
  • token: <Instance of Token Class>- 要暂挂的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
 "msg": "account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) is successfully holding 10 tokens",
}
executeHold
此方法完成对令牌的暂挂,将以前暂挂的指定数量的令牌转移给接收者。如果 quantity 值小于实际暂挂值,则剩余金额将再次可供令牌的原始所有者使用。此方法只能由具有指定操作 ID 的 notary 角色的 AccountOwner ID 调用。暂停只能由公证人完成。
Ctx.Token.executeHold(operation_id: string, quantity: number, token: <Instance of Token Class>)
参数:
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
  • quantity: number —要完成暂挂的令牌总数。
  • token: <Instance of Token Class> –要完成暂挂的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
 "msg": "user with accountId: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1) has successfully executed 5  tokens(digiCurr101) from the hold with Operation Id opr_121",
}
releaseHold
此方法释放暂挂令牌。传输未完成,所有保留的令牌将再次提供给原始所有者。此方法可以由具有 notary 角色的 AccountOwner ID 在指定时间限制内调用,也可以由付款人、收款人或公证人在指定时间限制之后调用。
Ctx.Token.releaseHold(operation_id: string, token: <Instance of Token Class>)
参数:
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
  • token: <Instance of Token Class>- 释放暂挂的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
  "msg": "Successfully released 5 tokens from Operation Id opr_121 to Account Id: oaccount~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (org_id : Org1MSP, user_id : user1)",
}
getOnHoldIds
此方法返回指定帐户的所有持有 ID 的列表。
Ctx.Account.getOnHoldIds(account_id: string)
参数:
  • account_id: string- 帐户的 ID。
返回:
  • 成功时,带有 JSON 对象的 promise 会列出指定帐户的所有持有 ID。出错时,将拒绝并显示错误消息。
返回值示例:
{
   "msg":"Holding Ids are: ohold~digicur~digiCurr101~opr_121",
   "holding_ids":[
      "ohold~digicur~digiCurr101~opr_121"
   ]
}
getOnHoldDetailsWithOperationId
此方法返回指定操作 ID 和令牌的暂挂事务处理详细信息。
Ctx.Hold.getOnHoldDetailsWithOperationId(token_id: string, operation_id: string)
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,包含以下属性的暂挂对象:
    • 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- 暂挂到期之前的持续时间。
  • 出错时,将拒绝并显示错误消息。
返回值示例:
{
    "assetType": "ohold",
    "holding_id": "ohold~digicur~digiCurr101~opr_121",
    "operation_id": "opr_121",
    "token_name": "digicur",
    "from_account_id": "oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df",
    "to_account_id": "oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f",
    "notary_account_id": "oaccount~digicur~38848e87296d67c8a90918f78cf55f9c9baab2cdc8c928535471aaa1210c706e",
    "token_id": "digiCurr101",
    "quantity": 10,
    "time_to_expiration": "2022-08-01T18:30:00.000Z"
}
getOnHoldBalanceWithOperationId
此方法返回指定操作 ID 和令牌的暂挂余额。任何人都可以调用此方法。
Ctx.Hold.getOnHoldBalanceWithOperationId(token_id: string, operation_id: string)
参数:
  • token_id: string- 令牌的 ID。
  • operation_id: string- 用于标识暂挂操作的唯一 ID。通常,此 ID 由客户端应用程序传递。
返回:
  • 成功后,具有指定操作 ID 和令牌的暂挂余额的 promise 对象。出错时,拒绝并显示错误消息
返回值示例:
{
    "msg": "Current Holding Balance of Operation 'op1' for token 'token1' is: 10",
    "holding_balance": 10
}

令牌行为管理的方法 - 可燃行为

burn
此方法从交易调用者的账户中停用或刻录令牌。此方法的调用者必须具有帐户和刻录角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。
Ctx.Token.burn(quantity: number, token: <Instance of Token Class>)
参数:
  • quantity: number –要燃烧的令牌总数。
  • token: <Instance of Token Class>- 要消耗的令牌资产。
返回:
  • 成功后,将发出具有成功消息的承诺。出错时,将拒绝并显示错误消息。
返回值示例:
{
 "msg":"Successfully burned 10 tokens from account id: oaccount~digicur~682bb71de419602af74e3f226345ae308445ca51010737900c1d85f0376152df (Org-Id: Org1MSP, User-Id: admin)"
}