转到令牌账户状态的方法

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

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

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

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

自动生成的账户状态方法

Blockchain App Builder 自动生成用于管理令牌账户状态的方法。控制器方法必须是公共的才能调用。公共方法名称以大写字符开头。以小写字符开头的方法名称是专用的。

GetAccountStatus
此方法获取令牌帐户的当前状态。此方法可由链代码的 Token Admin、指定组织的 Org Admin 或令牌帐户所有者调用。此方法还支持对升级到较新版本的现有链代码进行数据迁移。
func (t *Controller) GetAccountStatus(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating account_id of (Org-Id: %s, User-Id: %s)", org_id, user_id)
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("AccountStatus.Get", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      accountStatus, err := t.Ctx.AccountStatus.GetAccountStatus(account_id)
      if err != nil {
            return t.Ctx.AccountStatus.GetDefaultAccountStatus(account_id)
      }
      return accountStatus, nil
}
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,显示一条消息,其中包含令牌帐户状态的详细信息。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatusHistory
此方法获取帐户状态的历史记录。此方法可由链代码的 Token Admin、指定组织的 Org Admin 或令牌帐户所有者调用。
func (t *Controller) GetAccountStatusHistory(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating account_id of (Org-Id: %s, User-Id: %s)", org_id, user_id)
      }
      _, err = t.Ctx.Account.GetAccount(account_id)
      if err != nil {
            return nil, fmt.Errorf("error in GetAccountStatusHistory: %s", err)
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("AccountStatus.Get", "TOKEN", map[string]string{"account_id": account_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      status_id, err := t.Ctx.AccountStatus.GenerateAccountStatusId(account_id)
      if err != nil {
            return nil, err
      }
      account_status_history, err := t.Ctx.AccountStatus.History(status_id)
      if err != nil {
            return []map[string]interface{}{}, nil
      }
      return account_status_history, nil
}
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功时,显示一条消息,其中包含账户状态历史记录的详细信息。
返回值示例:
[
  {
    "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 或指定组织的 Org Admin 调用。无法激活删除的账户。
func (t *Controller) ActivateAccount(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating account_id of (Org-Id: %s, User-Id: %s)", org_id, user_id)
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("AccountStatus.ActivateAccount", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.ActivateAccount(account_id)
}
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
此方法暂停令牌帐户。暂停的帐户仍可以完成读取操作。具有已挂起帐户的用户无法发送、接收、铸币或刻录令牌。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。账户暂停后,您将无法完成任何更新账户的操作。已删除的账户无法挂起。
func (t *Controller) SuspendAccount(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating account_id of (Org-Id: %s, User-Id: %s)", org_id, user_id)
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("AccountStatus.SuspendAccount", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.SuspendAccount(account_id)
}
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
此方法删除令牌帐户。此方法只能由链代码的 Token Admin 或指定组织的 Org Admin 调用。在删除帐户后,您无法完成任何更新帐户的操作。已删除的账户处于最终状态,无法更改为任何其他状态。要删除帐户,帐户余额和暂挂余额必须为零。
func (t *Controller) DeleteAccount(token_id string, org_id string, user_id string) (interface{}, error) {
      account_id, err := t.Ctx.Account.GenerateAccountId(token_id, org_id, user_id)
      if err != nil {
            return nil, fmt.Errorf("error in getting the generating account_id of (Org-Id: %s, User-Id: %s)", org_id, user_id)
      }
      auth, err := t.Ctx.Auth.CheckAuthorization("AccountStatus.DeleteAccount", "TOKEN", map[string]string{"org_id": org_id})
      if err != nil && !auth {
            return nil, fmt.Errorf("error in authorizing the caller %s", err.Error())
      }
      return t.Ctx.Account.DeleteAccount(account_id)
}
参数:
  • token_id: string - 标记的 ID。
  • org_id: string - 当前组织中用户的成员服务提供者 (MSP) ID。
  • user_id: string - 用户的用户名或电子邮件 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}

账户状态 SDK 方法

GetDefaultAccountStatus
此方法获取令牌账户的当前状态,对于未在分类账中存储账户状态的任何账户,其状态为 active(因为该账户是在账户状态功能之前创建的)。
Ctx.AccountStatus.GetDefaultAccountStatus(account_id string) (FungibleAccountStatus, error)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,将以 JSON 表示帐户状态对象。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatus
此方法获取令牌帐户的当前状态。
Ctx.AccountStatus.GetAccountStatus(account_id string) (FungibleAccountStatus, error)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,将以 JSON 表示帐户状态对象。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SaveAccountStatus
此方法保存令牌帐户的状态对象(如果不存在状态对象),并将状态设置为指定值。
Ctx.AccountStatus.SaveAccountStatus(account_id string, status string)
参数:
  • account_id: string - 令牌帐户的 ID。
  • status: string- 为指定帐户设置的状态。仅支持三个值:activesuspendeddeleted
返回:
  • 成功后,将以 JSON 表示帐户状态对象。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatusHistory
此方法获取帐户状态的历史记录。
Ctx.AccountStatus.History(status_id string) (interface{}, error)
参数:
  • status_id: 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
此方法激活令牌帐户。
Ctx.Account.ActivateAccount(account_id: string) (interface{}, error)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
此方法暂停令牌帐户。
Ctx.Account.SuspendAccount(account_id string) (interface{}, error)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
此方法删除令牌帐户。
Ctx.Account.DeleteAccount(account_id string) (interface{}, error)
参数:
  • account_id: string - 令牌帐户的 ID。
返回:
  • 成功后,指定令牌账户的账户状态对象的 JSON 表示形式。
返回值示例:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}