Go Methods for Token Account Status

Blockchain App Builder automatically generates methods that you can use to manage account status for fungible tokens that use the Token Taxonomy Framework standard.

You can use the following methods to put token user accounts in the active, suspended, or deleted states.

When an account is suspended, the account user cannot complete any write operations, which include minting, burning, transferring, and holding tokens. Additionally, other users cannot transfer tokens to or hold tokens in a suspended account. A suspended account can still complete read operations.

An account with a non-zero token balance cannot be deleted. You must transfer or burn all tokens in an account before you can delete the account. After an account is in the deleted state, the account state cannot be changed back to active or suspended.

Automatically Generated Account Status Methods

Blockchain App Builder automatically generates methods to manage token account status. Controller methods must be public to be invokable. Public method names begin with an upper case character. Method names that begin with a lower case character are private.

GetAccountStatus
This method gets the current status of the token account. This method can be called by the Token Admin of the chaincode, an Org Admin of the specified organization, or by the token account owner. This method also supports data migration for existing chaincode that is upgraded to a newer version.
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
}
Parameters:
  • token_id: string – The ID of the token.
  • org_id: string – The membership service provider (MSP) ID of the user in the current organization.
  • user_id: string – The user name or email ID of the user.
Returns:
  • On success, a message that includes details of the token account status.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatusHistory
This method gets the history of the account status. This method can be called by the Token Admin of the chaincode, an Org Admin of the specified organization, or by the token account owner.
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
}
Parameters:
  • token_id: string – The ID of the token.
  • org_id: string – The membership service provider (MSP) ID of the user in the current organization.
  • user_id: string – The user name or email ID of the user.
Returns:
  • On success, a message that includes details of the account status history.
Return Value Example:
[
  {
    "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
This method activates a token account. This method can be called only by a Token Admin of the chaincode or by an Org Admin of the specified organization. Deleted accounts cannot be activated.
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)
}
Parameters:
  • token_id: string – The ID of the token.
  • org_id: string – The membership service provider (MSP) ID of the user in the current organization.
  • user_id: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
This method suspends a token account. Suspended accounts can still complete read operations. Users with suspended accounts cannot send, receive, mint, or burn tokens. This method can be called only by a Token Admin of the chaincode or by an Org Admin of the specified organization. After an account is suspended, you cannot complete any operations that update the account. A deleted account cannot be suspended.
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)
}
Parameters:
  • token_id: string – The ID of the token.
  • org_id: string – The membership service provider (MSP) ID of the user in the current organization.
  • user_id: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
This method deletes a token account. This method can be called only by a Token Admin of the chaincode or by an Org Admin of the specified organization. After an account is deleted, you cannot complete any operations that update the account. The deleted account is in a final state and cannot be changed to any other state. To delete an account, the account balance and the on-hold balance must be zero.
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)
}
Parameters:
  • token_id: string – The ID of the token.
  • org_id: string – The membership service provider (MSP) ID of the user in the current organization.
  • user_id: string – The user name or email ID of the user.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}

Account Status SDK Methods

GetDefaultAccountStatus
This method gets the current status of a token account, with the status as active for any account that does not have account status stored in the ledger (because the account was created prior to the account status functionality).
Ctx.AccountStatus.GetDefaultAccountStatus(account_id string) (FungibleAccountStatus, error)
Parameters:
  • account_id: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatus
This method gets the current status of the token account.
Ctx.AccountStatus.GetAccountStatus(account_id string) (FungibleAccountStatus, error)
Parameters:
  • account_id: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SaveAccountStatus
This method saves the status object (if a status object is not present) for the token account, and sets the status to the specified value.
Ctx.AccountStatus.SaveAccountStatus(account_id string, status string)
Parameters:
  • account_id: string – The ID of the token account.
  • status: string – The status to set for the specified account. Only three values are supported: active, suspended, or deleted.
Returns:
  • On success, a JSON representation of the account status object.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
GetAccountStatusHistory
This method gets the history of the account status.
Ctx.AccountStatus.History(status_id string) (interface{}, error)
Parameters:
  • status_id: string – The ID of the account status object.
Returns:
  • On success, a JSON representation of the account status history.
Return Value Example:
[
  {
    "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
This method activates a token account.
Ctx.Account.ActivateAccount(account_id: string) (interface{}, error)
Parameters:
  • account_id: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "active"
}
SuspendAccount
This method suspends a token account.
Ctx.Account.SuspendAccount(account_id string) (interface{}, error)
Parameters:
  • account_id: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "suspended"
}
DeleteAccount
This method deletes a token account.
Ctx.Account.DeleteAccount(account_id string) (interface{}, error)
Parameters:
  • account_id: string – The ID of the token account.
Returns:
  • On success, a JSON representation of the account status object for the specified token account.
Return Value Example:
{
    "AssetType": "oaccountStatus",
    "StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
    "AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
    "Status": "deleted"
}