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"
}