TypeScript ERC-721 标记帐户状态的方法

Blockchain App Builder 自动生成可用于管理使用扩展 ERC-721 标准的令牌的账户状态的方法。

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

暂停帐户时,帐户用户无法完成任何写入操作,包括铸造、刻录和转移令牌。此外,其他用户无法将令牌转移到已挂起的帐户。挂起的帐户仍可以完成读取操作。

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

自动生成的账户状态方法

getAccountStatus
此方法获取令牌帐户的当前状态。链代码的 Token Admin 或令牌帐户所有者可以调用此方法。
@Validator(yup.string(), yup.string())
     public async getAccountStatus(orgId: string, userId: string) {
       const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
       await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.get", "TOKEN", { accountId });
       try {
         return await this.Ctx.ERC721AccountStatus.getAccountStatus(accountId);
       } catch (err) {
        return await this.Ctx.ERC721AccountStatus.getDefaultAccountStatus(accountId);
       }
     }
参数:
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,标记帐户状态的 JSON 表示形式。如果在账户的分类账中未找到状态,因为账户是在账户状态功能可用之前创建的,则状态在回应中将列为 active
返回值示例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法获取帐户状态的历史记录。链代码的 Token Admin 或令牌帐户所有者可以调用此方法。
public async getAccountStatusHistory(orgId: string, userId: string) {
       const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
       await this.Ctx.ERC721Account.getAccount(accountId);
       await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.history", "TOKEN", { accountId });
       const status_id = await this.Ctx.ERC721AccountStatus.generateAccountStatusId(accountId);
       let accountStatusHistory: any;
       try {
         accountStatusHistory = await this.Ctx.ERC721AccountStatus.history(status_id);
       } catch (err) {
         return [];
       }
       return accountStatusHistory;
     }
参数:
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功后,账户状态历史记录采用 JSON 格式。
返回值示例:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
此方法激活令牌帐户。此方法只能由链代码的 Token Admin 调用。无法激活已删除的账户。对于在帐户状态功能可用之前创建的任何帐户,必须调用此方法以将帐户状态设置为 active
@Validator(yup.string(), yup.string())
 public async activateAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.activateAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.activateAccount(accountId);
 }
参数:
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,标记帐户状态的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法暂停令牌帐户。此方法只能由链代码的 Token Admin 调用。账户挂起后,您无法完成任何更新账户的操作。已删除的账户无法暂停。
@Validator(yup.string(), yup.string())
 public async suspendAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.suspendAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.suspendAccount(accountId);
 }
参数:
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,标记帐户状态的 JSON 表示形式。
返回值示例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法将删除令牌帐户。此方法只能由链代码的 Token Admin 调用。在删除帐户后,您无法完成更新帐户的任何操作。已删除的帐户处于最终状态,无法更改为任何其他状态。要删除帐户,帐户余额必须为零。
@Validator(yup.string(), yup.string())
 public async deleteAccount(orgId: string, userId: string) {
   await this.Ctx.ERC721Auth.checkAuthorization("ERC721ACCOUNT_STATUS.deleteAccount", "TOKEN");
   const accountId = await this.Ctx.ERC721Account.generateAccountId(orgId, userId);
   return await this.Ctx.ERC721Account.deleteAccount(accountId);
 }
参数:
  • orgId: string- 当前组织中用户的成员服务提供商 (membership service provider,MSP) ID。
  • userId: string- 用户的用户名或电子邮件 ID。
返回:
  • 成功时,标记帐户状态的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}

账户状态 SDK 方法

getAccountStatus
此方法获取令牌帐户的当前状态。
Ctx.ERC721AccountStatus.getAccountStatus(accountId: string)
参数:
  • accountId: string- 令牌帐户的 ID。
返回:
  • 成功时,标记帐户状态的 JSON 表示形式。如果在账户的分类账中未找到状态,因为账户是在账户状态功能可用之前创建的,则状态在回应中将列为 active
返回值示例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法获取帐户状态的历史记录。
Ctx.ERC721AccountStatus.history(statusId: string)
参数:
  • statusId: string- 帐户状态对象的 ID。
返回:
  • 成功时,表示帐户状态历史记录的 JSON。
返回值示例:
[
  {
    "trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
    "timeStamp": "2022-12-02T10:39:14.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "suspended"
    }
  },
  {
    "trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
    "timeStamp": "2022-12-02T10:37:50.000Z",
    "value": {
      "assetType": "oaccountStatus",
      "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "status": "active"
    }
  }
]
activateAccount
此方法激活令牌帐户。对于在帐户状态功能可用之前创建的任何帐户,必须调用此方法以将帐户状态设置为 active
Ctx.ERC721Account.activateAccount(accountId: string)
参数:
  • accountId: string- 令牌帐户的 ID。
返回:
  • 成功时,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法暂停令牌帐户。
Ctx.ERC721AccountStatus.suspendAccount(accountId: string)
参数:
  • accountId: string- 令牌帐户的 ID。
返回:
  • 成功时,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法将删除令牌帐户。
Ctx.ERC721Account.deleteAccount(accountId: string)
参数:
  • accountId: string- 令牌帐户的 ID。
返回:
  • 成功时,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}