TypeScript ERC-1155 記號帳戶狀態的方法

Blockchain App Builder 會自動產生方法,供您用來管理使用延伸 ERC-1155 標準的權杖帳戶狀態。

您可以使用下列方法將記號使用者帳戶置於作用中、已暫停或已刪除的狀態。

帳戶暫停時,帳戶使用者無法完成任何寫入作業,包括微調、燒錄及傳輸記號。此外,其他使用者無法將記號轉移到暫停的帳戶。暫停的帳號仍然可以完成讀取作業。

無法刪除具有非零權杖餘額的帳戶。您必須先轉移或燒錄帳戶中的所有權杖,才能刪除帳戶。帳戶處於已刪除狀態之後,便無法將帳戶狀態變更回作用中或已暫停。

自動產生的科目狀態方法

getAccountStatus
此方法會取得權杖帳戶的目前狀態。鏈碼的 Token Admin 或記號帳戶擁有者可以呼叫此方法。
@Validator(yup.string(), yup.string(), yup.string())
  public async getAccountStatus(orgId: string, userId: string, tokenId ?: string) {
    const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
    let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.get", "TOKEN", { accountId: tokenAccount.accountId });
    try {
      return await this.Ctx.ERC1155AccountStatus.getAccountStatus(tokenAccount.accountId);
    } catch (err) {
      return await this.Ctx.ERC1155AccountStatus.getDefaultAccountStatus(tokenAccount.accountId);
    }
  }
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ?: string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,代表權杖帳戶狀態的 JSON。如果在帳戶的分類帳中找不到狀態,因為帳戶在帳戶狀態功能可用之前已建立,則狀態會在回應中列為 active
傳回值範例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法會取得帳戶狀態的歷史記錄。鏈碼的 Token Admin 或記號帳戶擁有者可以呼叫此方法。
public async getAccountStatusHistory(orgId: string, userId: string, tokenId ?: string) {
    const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
    let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
    await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.history", "TOKEN", { accountId: tokenAccount.accountId });
    const status_id = await this.Ctx.ERC1155AccountStatus.generateAccountStatusId(tokenAccount.accountId);
    let accountStatusHistory: any;
    try {
      accountStatusHistory = await this.Ctx.ERC1155AccountStatus.history(status_id);
    } catch (err) {
      return [];
    }
    return accountStatusHistory;
  }
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ?: 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(), yup.string())
public async activateAccount(orgId: string, userId: string, tokenId ?: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.activateAccount", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
  return await this.Ctx.ERC1155Account.activateAccount(tokenAccount.accountId);
}
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ?: string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,代表權杖帳戶狀態的 JSON。
傳回值範例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法會暫停權杖帳戶。鏈碼的 Token Admin 只能呼叫此方法。帳戶暫停後,您便無法完成任何更新帳戶的作業。無法暫停已刪除的帳戶。
@Validator(yup.string(), yup.string(), yup.string())
public async suspendAccount(orgId: string, userId: string, tokenId ?: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.suspendAccount", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
  return await this.Ctx.ERC1155Account.suspendAccount(tokenAccount.accountId);
}
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ?: string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,代表權杖帳戶狀態的 JSON。
傳回值範例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法會刪除記號帳戶。鏈碼的 Token Admin 只能呼叫此方法。刪除帳戶後,您便無法完成任何更新帳戶的作業。刪除的帳戶處於最終狀態,無法變更為任何其他狀態。若要刪除帳戶,帳戶餘額必須為零。
@Validator(yup.string(), yup.string(), yup.string())
public async deleteAccount(orgId: string, userId: string, tokenId ?: string) {
  await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.deleteAccount", "TOKEN");
  const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
  let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
  return await this.Ctx.ERC1155Account.deleteAccount(tokenAccount.accountId);
}
參數:
  • orgId: string - 目前組織中使用者的成員服務提供者 (MSP) ID。
  • userId: string - 使用者的使用者名稱或電子郵件 ID。
  • tokenId ?: string - 若為非工具權杖帳戶,則為空白字串。如果是有趣的權杖帳戶,則是權杖 ID。
傳回值:
  • 成功時,代表權杖帳戶狀態的 JSON。
傳回值範例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}

帳戶狀態 SDK 方法

getAccountStatus
此方法會取得權杖帳戶的目前狀態。
Ctx.ERC1155AccountStatus.getAccountStatus(accountId: string)
參數:
  • accountId: string - 權杖帳戶的 ID。
傳回值:
  • 成功時,代表權杖帳戶狀態的 JSON。如果在帳戶的分類帳中找不到狀態,因為帳戶在帳戶狀態功能可用之前已建立,則狀態會在回應中列為 active
傳回值範例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "active"
}
getAccountStatusHistory
此方法會取得帳戶狀態的歷史記錄。
Ctx.ERC1155AccountStatus.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.ERC1155Account.activateAccount(tokenAccountId: string)
參數:
  • tokenAccountId: string - 權杖帳戶的 ID。
傳回值:
  • 成功時,指定記號帳戶之帳戶狀態物件的 JSON 表示法。
傳回值範例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "active"
}
suspendAccount
此方法會暫停權杖帳戶。
Ctx.ERC1155Account.suspendAccount(tokenAccountId: string)
參數:
  • tokenAccountId: string - 權杖帳戶的 ID。
傳回值:
  • 成功時,指定記號帳戶之帳戶狀態物件的 JSON 表示法。
傳回值範例:
{
    "assetType": "oaccountStatus",
    "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "status": "suspended"
}
deleteAccount
此方法會刪除記號帳戶。
Ctx.ERC1155Account.deleteAccount(tokenAccountId: string)
參數:
  • tokenAccountId: string - 權杖帳戶的 ID。
傳回值:
  • 成功時,指定記號帳戶之帳戶狀態物件的 JSON 表示法。
傳回值範例:
{
  "assetType": "oaccountStatus",
  "statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
  "accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
  "status": "deleted"
}