执行 ERC-1155 令牌账户状态的方法

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

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

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

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

自动生成的账户状态方法

GetAccountStatus
此方法获取令牌帐户的当前状态。此方法可由链代码的 Token Admin 或令牌帐户所有者调用。
func (t *Controller) GetAccountStatus(orgId string, userId string, tokenId ...string) (interface{}, error) {
      userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating accountId of (Org-Id: %s, User-Id: %s)", orgId, userId)
      }
      auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155AccountStatus.Get", "TOKEN", map[string]string{"accountId": userAccountId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
      if err != nil {
            return nil, fmt.Errorf("error in GetAccountStatus. Error: %s", err)
      }
      tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
      accountStatus, err := t.Ctx.ERC1155AccountStatus.GetAccountStatus(tokenAccountId)
      if err != nil {
            return t.Ctx.ERC1155AccountStatus.GetDefaultAccountStatus(tokenAccountId)
      }
      return accountStatus, nil
}
参数:
  • 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 或令牌帐户所有者调用。
func (t *Controller) GetAccountStatusHistory(orgId string, userId string, tokenId ...string) (interface{}, error) {
      userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating accountId of (Org-Id: %s, User-Id: %s)", orgId, userId)
      }
      auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155AccountStatus.Get", "TOKEN", map[string]string{"accountId": userAccountId})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
      if err != nil {
            return nil, fmt.Errorf("error in GetAccountStatusHistory. Error: %s", err)
      }
      tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
      statusId, err := t.Ctx.ERC1155AccountStatus.GenerateAccountStatusId(tokenAccountId)
      if err != nil {
            return nil, err
      }
      accountStatusHistory, err := t.Ctx.ERC1155AccountStatus.History(statusId)
      if err != nil {
            return []map[string]interface{}{}, nil
      }
      return accountStatusHistory, nil
}
参数:
  • orgId: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • userId: string - 用户的用户名或电子邮件 ID。
  • tokenId ...string - 对于不可替代的令牌帐户,为空字符串。对于可替换标记帐户,标记 ID。
返回:
  • 成功后,将以 JSON 格式显示账户状态历史记录。
返回值示例:
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-02T16:20:34+05:30",
    "TxId": "af1601c7a14b4becf4bb3b285d85553b39bf234caaf1cd488a284a31a2d9df78",
    "Value": {
      "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "AssetType": "oaccountStatus",
      "Status": "suspended",
      "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7"
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-02T16:19:15+05:30",
    "TxId": "4b307b989063e43add5357ab110e19174d586b9746cc8a30c9aa3a2b0b48a34e",
    "Value": {
      "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "AssetType": "oaccountStatus",
      "Status": "active",
      "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7"
    }
  }
]
ActivateAccount
此方法激活令牌帐户。此方法只能由链代码的 Token Admin 调用。无法激活删除的账户。对于在帐户状态功能可用之前创建的任何帐户,必须调用此方法以将帐户状态设置为 active
func (t *Controller) ActivateAccount(orgId string, userId string, tokenId ...string) (interface{}, error) {
    userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
    if err != nil {
        return nil, fmt.Errorf("error in getting the generating accountId of (Org-Id: %s, User-Id: %s)", orgId, userId)
    }
    auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155AccountStatus.ActivateAccount", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
    if err != nil {
        return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
    }
    tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
    return t.Ctx.ERC1155Account.ActivateAccount(tokenAccountId)
}
参数:
  • orgId: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • userId: string - 用户的用户名或电子邮件 ID。
  • tokenId ...string - 对于不可替代的令牌帐户,为空字符串。对于可替换标记帐户,标记 ID。
返回:
  • 成功后,将以 JSON 表示标记账户状态。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
此方法暂停令牌帐户。此方法只能由链代码的 Token Admin 调用。账户暂停后,您将无法完成任何更新账户的操作。已删除的账户无法挂起。
func (t *Controller) SuspendAccount(orgId string, userId string, tokenId ...string) (interface{}, error) {
    userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
    if err != nil {
        return nil, fmt.Errorf("error in getting the generating accountId of (Org-Id: %s, User-Id: %s)", orgId, userId)
    }
    auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155AccountStatus.SuspendAccount", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
    if err != nil {
        return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
    }
    tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
    return t.Ctx.ERC1155Account.SuspendAccount(tokenAccountId)
}
参数:
  • orgId: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • userId: string - 用户的用户名或电子邮件 ID。
  • tokenId ...string - 对于不可替代的令牌帐户,为空字符串。对于可替换标记帐户,标记 ID。
返回:
  • 成功后,将以 JSON 表示标记账户状态。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
此方法删除令牌帐户。此方法只能由链代码的 Token Admin 调用。在删除帐户后,您无法完成任何更新帐户的操作。已删除的账户处于最终状态,无法更改为任何其他状态。要删除帐户,帐户余额必须为零。
func (t *Controller) DeleteAccount(orgId string, userId string, tokenId ...string) (interface{}, error) {
    userAccountId, err := t.Ctx.ERC1155Account.GenerateAccountId(orgId, userId, constants.UserAccount)
    if err != nil {
        return nil, fmt.Errorf("error in getting the generating accountId of (Org-Id: %s, User-Id: %s)", orgId, userId)
    }
    auth, err := t.Ctx.ERC1155Auth.CheckAuthorization("ERC1155AccountStatus.DeleteAccount", "TOKEN")
    if err != nil && !auth {
        return nil, fmt.Errorf("error in authorizing the caller  %s", err.Error())
    }
    tokenAccount, err := t.Ctx.ERC1155Account.Get(userAccountId, tokenId...)
    if err != nil {
        return nil, fmt.Errorf("error in GetAccountTransactionHistory. Error: %s", err)
    }
    tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
    return t.Ctx.ERC1155Account.DeleteAccount(tokenAccountId)
}
参数:
  • orgId: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • userId: string - 用户的用户名或电子邮件 ID。
  • tokenId ...string - 对于不可替代的令牌帐户,为空字符串。对于可替换标记帐户,标记 ID。
返回:
  • 成功后,将以 JSON 表示标记账户状态。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}

账户状态 SDK 方法

GetDefaultAccountStatus
此方法获取令牌账户的当前状态,对于未在分类账中存储账户状态的任何账户,其状态为 active(因为该账户是在账户状态功能之前创建的)。
Ctx.GetDefaultAccountStatus(accountId string) (ERC1155AccountStatus, error)
参数:
  • accountId: string - 令牌帐户的 ID。
返回:
  • 成功后,将以 JSON 表示标记账户状态。
返回值示例:
{
      "AssetType": "oaccountStatus",
      "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
      "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "Status": "active"
}
GetAccountStatus
此方法获取令牌帐户的当前状态。
Ctx.ERC1155AccountStatus.GetAccountStatus(accountId string) (NFTAccountStatus, error)
参数:
  • accountId: string - 令牌帐户的 ID。
返回:
  • 成功后,将以 JSON 表示标记账户状态。如果在分类账中找不到账户的状态,因为该账户是在账户状态功能可用之前创建的,则该状态在响应中将列为 active
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatusHistory
此方法获取帐户状态的历史记录。
Ctx.ERC1155AccountStatus.History(statusId string) (interface{}, error)
参数:
  • statusId: string - 账户状态对象的 ID。
返回:
  • 成功后,将以 JSON 表示形式显示账户状态历史记录。
返回值示例:
[
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-02T16:20:34+05:30",
    "TxId": "af1601c7a14b4becf4bb3b285d85553b39bf234caaf1cd488a284a31a2d9df78",
    "Value": {
      "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "AssetType": "oaccountStatus",
      "Status": "suspended",
      "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7"
    }
  },
  {
    "IsDelete": "false",
    "Timestamp": "2022-12-02T16:19:15+05:30",
    "TxId": "4b307b989063e43add5357ab110e19174d586b9746cc8a30c9aa3a2b0b48a34e",
    "Value": {
      "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
      "AssetType": "oaccountStatus",
      "Status": "active",
      "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7"
    }
  }
]
ActivateAccount
此方法激活令牌帐户。对于在帐户状态功能可用之前创建的任何帐户,必须调用此方法以将帐户状态设置为 active
Ctx.ERC1155Account.ActivateAccount(tokenAccountId string) (interface{}, error)
参数:
  • tokenAccountId: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
此方法暂停令牌帐户。
Ctx.ERC1155Account.SuspendAccount(tokenAccountId string) (interface{}, error)
参数:
  • tokenAccountId: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
此方法删除令牌帐户。
Ctx.ERC1155Account.DeleteAccount(tokenAccountId string) (interface{}, error)
参数:
  • tokenAccountId: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}