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

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

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

有关脚手架项目和与标记不直接相关的方法的信息,请参阅脚手架 TypeScript Chaincode Project

型号

每个标记化的模型类都扩展了 Token 类,而该类又扩展了 OchainModel 类。Token 类是从 ../lib/token 导入的。透明持久性功能(Transparent Persistence Capability,简称 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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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();
}
参数:
返回:
  • 成功时,使用 JSON 格式的 admins 数组包含 orgIduserId 对象。
返回值示例:
{"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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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"
        }
    ]
}

标记配置管理的方法

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 数组是必需的参数。
参数示例,Mac OSX 和 Linux CLI:
'[{"user_id":"userid", "org_id":"OrgMSPId"}]'
参数示例 Microsoft Windows CLI:
"[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"
参数示例,Oracle Blockchain Platform 控制台:
["[{\"user_id\":\"userid\", \"org_id\":\"OrgMSPId\"}]"]
initialize<Token Name>Token
此方法创建令牌并初始化令牌属性。资产及其属性保存在状态数据库中。此方法只能由链代码的 Token Admin 调用。
@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> - 标记资产作为参数传递到此方法。模型文件中介绍了标记资产的属性。
返回:
  • 成功后,将以 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> - 标记资产作为参数传递到此方法。模型文件中介绍了标记资产的属性。
返回:
  • 成功后,将更新令牌资产的 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 对象。

账户管理方法

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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,包含以下属性的 JSON 帐户对象:
  • account_id - 用户帐户的 ID。
  • user_id - 用户的用户名或电子邮件 ID。
  • org_id - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 组织的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 要搜索的角色的名称。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。
返回值示例:
{"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 - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。
返回值示例:
{"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 - 当前组织中用户的成员服务提供者 (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 - 组织的成员服务提供者 (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 - 组织的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (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
  }
]
getSubTransactionById
此方法返回指定用户和令牌的帐户事务处理历史记录详细信息数组。此方法只能由链代码的 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"
    ]
}

标记行为管理的方法 - 可最小化行为

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 - 到 mint 的标记数。
返回:
  • 成功时,会显示包含账户详细信息的消息。
返回值示例:
{
    "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}

标记行为管理的方法 - 可传输行为

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_org_id": "Org1MSP",
    	"to_user_id": "user1",
    	"quantity": 10
    }, {
    	"to_org_id": "Org1MSP",
    	"to_user_id": "user2",
    	"quantity": 10
    }]
    • to_orgId: string - 当前组织中接收者的成员服务提供者 (MSP) ID。
    • userId: string - 接收者的用户名或电子邮件 ID。
    • quantity: number - 要传输的令牌数。
返回:
  • 表示成功的消息。
返回值示例:
{
    "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 - 当前组织中公证员的成员资格服务提供商 (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 的 AccountOwner ID 和 notary 角色来调用。暂挂只能由公证人完成。
@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
此方法释放对标记的暂挂。转移未完成,所有保留的令牌都再次可供原始所有者使用。此方法可由 AccountOwner ID 在指定时间限制内具有 notary 角色或者在指定时间限制后由付款人、受款人或公证人调用。
@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 - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将列出 JSON 存储 ID。
返回值示例:
{"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 hold 对象:
  • 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
}

标记行为管理的方法 - 可刻录行为

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

定制方法

您可以使用令牌 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)"
}
getAllAdmins
此方法返回作为标记链代码 Token Admin 的所有用户的列表。
Ctx.Admin.getAllAdmins()
参数:
返回:
  • 成功后,使用 JSON 对象的 promise 将列出作为令牌链代码 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
返回:
  • 成功的时候,一个承诺。出错时,拒绝并显示错误消息。
isUserTokenAdmin
如果函数的调用方为 Token Admin,则此方法返回布尔值 true。否则,方法返回 false
Ctx.Auth.isUserTokenAdmin()
参数:
  • user_id - 用户的用户名或电子邮件 ID。
  • org_id- 当前网络组织中用户的成员服务提供者 (Membership Service Provider,MSP) ID。
返回:
  • 布尔值响应和错误消息(如果遇到错误)。
addOrgAdmin
此方法将用户添加为组织的 Org Admin
Ctx.Admin.addOrgAdmin(org_id, user_id)
参数:
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示一条消息,其中包含作为组织的 Org Admin 添加的用户的详细信息。
返回值示例:
{
    "msg": "Successfully added Org Admin (Org_Id: Org1MSP, User_Id: orgAdmin)"
}
removeOrgAdmin
此方法将删除用户作为组织的 Org Admin
Ctx.Admin.removeOrgAdmin(org_id, user_id)
参数:
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将显示一条消息,其中包含作为组织的 Org Admin 删除的用户的详细信息。
返回值示例:
{
  "msg": "Successfully removed Org Admin (Org_Id Org1MSP User_Id orgAdmin)"
}
getOrgAdmins
此方法返回组织 Org Admin 的所有用户的列表。
Ctx.Admin.getAllOrgAdmins()
参数:
返回:
  • 成功时,包含 orgIduserId 对象的 JSON 格式数组。
返回值示例:
{
    "admins": [
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin1"
        },
        {
            "org_id": "Org1MSP",
            "user_id": "orgadmin2"
        }
    ]
}

标记配置管理的方法

getTokenDecimals
此方法返回可用于小数标记的小数位数。如果未指定 divisible 行为,则默认值为 0。
Ctx.Token.getTokenDecimals(token_id: string)
参数:
  • token_id: string - 标记的 ID。
返回:
  • 成功时,标记的小数位数,在数字数据类型中。出错时,它将返回错误消息。
返回值示例:
1
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"
    }
}
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"
}
isTokenType
此方法指示是否存在具有指定 ID 的标记资产。
Ctx.Token.isTokenType(token_id: string)
参数:
  • token_id: string - 要检查的令牌的 ID。
返回:
  • 成功时,如果存在具有指定 ID 的令牌资产,则承诺使用 true 。出错时,拒绝并显示错误消息。
返回值示例:
true
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
}
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"
    }
]
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
            }
        }
    }
]

账户管理方法

getCallerAccountId
此方法返回调用者的帐户 ID。
Ctx.Account.getCallerAccountId(token_id: string)
参数:
  • tokenId: string - 标记的 ID。
返回:
  • 成功时,使用呼叫者帐户 ID 的承诺。出错时,拒绝并显示错误消息。
返回值示例:
oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f
generateAccountId
此方法返回帐户 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 - 当前组织中用户的成员服务提供者 (MSP) ID。
  • userId: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,使用生成的账户 ID 的承诺。出错时,拒绝并显示错误消息。
返回值示例:
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 - 当前组织中用户的成员服务提供者 (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 对象的承诺会显示指定账户的暂挂余额。出错时,拒绝并显示错误消息。
返回值示例:
{
   "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 对象进行 promise。出错时,拒绝并显示错误消息。
返回值示例:
[
           {
               "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 - 组织的成员服务提供者 (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 - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,将生成 JSON 帐户 ID 数组。
返回值示例:
{"accounts":["oaccount~digicur~b4f45440aa2a7942db64443d047027e9d714d62cba5c3d546d64f368642f622f"]}
getUsersByRole
此方法返回指定角色和令牌的所有用户的列表。
Ctx.Role.getUsersByRole(token_id: string, role: string)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要搜索的角色的名称。
返回:
  • 成功后,使用 JSON 对象的 promise 将列出指定角色和令牌的所有用户。出错时,拒绝并显示错误消息。
返回值示例:
{
   "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"}
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 }
getOrgUsersByRole
此方法返回有关在指定组织中具有指定角色的所有用户的信息。
Ctx.Role.getOrgUsersByRole(token_id: string, role: string, org_id: string)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出指定组织中具有指定角色的所有用户。
返回值示例:
{
    "users": [
        {
            "token_id": "token",
            "user_id": "admin",
            "org_id": "Org1MSP"
        },
        {
            "token_id": "token",
            "user_id": "orgAdmin",
            "org_id": "Org1MSP"
        }
    ]
}
getOrgAccountsByRole
此方法返回有关在指定组织中具有指定角色的所有帐户的信息。
Ctx.Role.getOrgAccountsByRole(token_id: string, role: string, org_id: string)
参数:
  • token_id: string - 标记的 ID。
  • role: string - 要检查的角色的名称。
  • org_id: string - 组织的成员服务提供者 (MSP) ID。
返回:
  • 成功后,将列出在指定组织中具有指定角色的所有客户。
返回值示例:
{
    "accounts": [
        "oaccount~abc74791148b761352b98df58035601b6f5480448ac2b4a3a7eb54bdbebf48eb",
        "oaccount~9c650574af9025a6106c8d12a801b079eda9ae2e3399fc2fbd5bd683d738a850"
    ]
}

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

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" 方法相同。
  • 成功后,使用帐户事务处理对象数组承诺:
    • 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"
            ]
        }
getAccountTransactionHistory
此方法返回指定账户的事务处理历史记录详细信息数组。
Ctx.Account.getAccountTransactionHistory(account_id: string)
参数:
  • account_id: string - 帐户的 ID。
返回:
  • 返回值与 "getAccountTransactionHistory" 方法相同。
  • 成功后,使用帐户事务处理对象数组承诺:
    • 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
    }
]

标记行为管理

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

标记行为管理的方法 - 可最小化行为

mint
此方法铸造一定数量的标记,然后这些标记由方法的调用方拥有。调用方必须具有帐户和 minter 角色。数量必须在规范文件中 divisible 行为的 decimal 参数指定的小数值内。
Ctx.Token.mint(quantity: number, token: <Instance of Token Class>)
参数:
  • quantity: number - 到 mint 的令牌总数。
  • token: <Instance of Token Class> - mint 的标记资产。
返回:
  • 成功时,将发出包含成功消息和 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 的 AccountOwner ID 和 notary 角色来调用。暂挂只能由公证人完成。
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
此方法释放对标记的暂挂。转移未完成,所有保留的令牌都再次可供原始所有者使用。此方法可由 AccountOwner ID 在指定时间限制内具有 notary 角色或者在指定时间限制后由付款人、受款人或公证人调用。
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)"
}