TypeScript 令牌帐户状态的方法

Blockchain App Builder 自动生成可用于管理使用令牌分类框架标准的可替换令牌的账户状态的方法。

可以使用以下方法将令牌用户帐户置于活动、已挂起或已删除状态。

当帐户暂停时,帐户用户无法完成任何写入操作,包括铸造、燃烧、转移和持有令牌。此外,其他用户无法将令牌传输到已挂起账户或持有令牌。暂停的帐户仍可以完成读取操作。

无法删除具有非零标记余额的账户。您必须先转移或刻录账户中的所有令牌,然后才能删除账户。账户处于已删除状态后,无法将账户状态更改回活动或暂停状态。

自动生成的账户状态方法

Blockchain App Builder 自动生成用于管理令牌账户状态的方法。控制器方法必须具有可调用的 @Validator(...params) 修饰器。

getAccountStatus
此方法获取令牌帐户的当前状态。此方法可由链代码的 Token Admin、指定组织的 Org Admin 或令牌帐户所有者调用。此方法还支持对升级到较新版本的现有链代码进行数据迁移。
@Validator(yup.string(), yup.string(), yup.string())
  public async getAccountStatus(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_STATUS.get", "TOKEN", { account_id });
    try {
      return await this.Ctx.AccountStatus.getAccountStatus(account_id);
    } catch (err) {
      return await this.Ctx.AccountStatus.getDefaultAccountStatus(account_id);
    }
  }
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,显示一条消息,其中包含令牌帐户状态的详细信息。
返回值示例:
{
    "assetType": "oaccountStatus",
    "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法获取帐户状态的历史记录。此方法可由链代码的 Token Admin、指定组织的 Org Admin 或令牌帐户所有者调用。
  @Validator(yup.string(), yup.string(), yup.string())
  public async getAccountStatusHistory(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.Account.getAccount(account_id);
    await this.Ctx.Auth.checkAuthorization("ACCOUNT_STATUS.history", "TOKEN", { account_id });
    const status_id = await this.Ctx.AccountStatus.generateAccountStatusId(account_id);
    let account_status_history: any;
    try {
      account_status_history = await this.Ctx.AccountStatus.history(status_id);
    } catch (err) {
      return [];
    }
    return account_status_history;
  }
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,显示一条消息,其中包含账户状态历史记录的详细信息。
返回值示例:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
此方法激活令牌帐户。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。无法激活删除的账户。
@Validator(yup.string(), yup.string(), yup.string())
  public async activateAccount(token_id: string, org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT_STATUS.activateAccount", "TOKEN", { org_id });
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    return await this.Ctx.Account.activateAccount(account_id);
  }
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法暂停令牌帐户。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。账户暂停后,您将无法完成任何更新账户的操作。已删除的账户无法挂起。
@Validator(yup.string(), yup.string(), yup.string())
  public async suspendAccount(token_id: string, org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT_STATUS.suspendAccount", "TOKEN", { org_id });
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    return await this.Ctx.Account.suspendAccount(account_id);
  }
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "assetType": "oaccountStatus",
    "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法删除令牌帐户。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。在删除帐户后,您无法完成任何更新帐户的操作。已删除的账户处于最终状态,无法更改为任何其他状态。要删除帐户,帐户余额和暂挂余额必须为零。
@Validator(yup.string(), yup.string(), yup.string())
  public async deleteAccount(token_id: string, org_id: string, user_id: string) {
    await this.Ctx.Auth.checkAuthorization("ACCOUNT_STATUS.deleteAccount", "TOKEN", { org_id });
    const account_id = await this.Ctx.Account.generateAccountId(token_id, org_id, user_id);
    return await this.Ctx.Account.deleteAccount(account_id);
  }
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}

账户状态 SDK 方法

getAccountStatus
此方法获取令牌帐户的当前状态。
Ctx.AccountStatus.getAccountStatus(account_id: string)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,将以 JSON 表示帐户状态对象。
返回值示例:
{
    "assetType": "oaccountStatus",
    "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
saveAccountStatus
此方法保存令牌帐户的状态对象(如果不存在状态对象),并将状态设置为指定值。
Ctx.AccountStatus.saveAccountStatus(account_id: string, status: AccountStatus)
参数:
  • account_id: string - 令牌帐户的 ID。
  • status: AccountStatus- 为指定帐户设置的状态。

    AccountStatusenum 类型,必须为 activesuspendeddeleted

返回:
  • 成功后,将以 JSON 表示帐户状态对象。
返回值示例:
{
    "assetType": "oaccountStatus",
    "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法获取帐户状态的历史记录。
Ctx.AccountStatus.history(status_id: string)
参数:
  • status_id: string - 账户状态对象的 ID。
返回:
  • 成功后,将以 JSON 表示形式显示账户状态历史记录。
返回值示例:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
此方法激活令牌帐户。
Ctx.Account.activateAccount(account_id: string)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法暂停令牌帐户。
Ctx.Account.suspendAccount(account_id: string)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "assetType": "oaccountStatus",
    "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法删除令牌帐户。
Ctx.Account.deleteAccount(account_id: string)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "status_id": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "account_id": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}