-
GetAccountStatus
- This method gets the current status of the token account. This method can be called by the
Token Admin of the chaincode or by the token account owner.
func (t *Controller) GetAccountStatus(orgId string, userId string, tokenId ...float64) (interface{}, error) {
// Convert tokenIds first
tokenIdStr, err := util.ConvertFloat64SliceToStrings(tokenId)
if err != nil {
return nil, err
}
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, tokenIdStr...)
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
}
- Parameters:
orgId: string – The membership service provider (MSP) ID of the user in the current organization.
userId: string – The user name or email ID of the user.
tokenId ...float64 – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
- Returns:
- On success, a JSON representation of the token account status. If no status is found in the ledger for the account because the account was created before the account status functionality was available, the status is listed as
active in the response.
- 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 or by the token account owner.
func (t *Controller) GetAccountStatusHistory(orgId string, userId string, tokenId ...float64) (interface{}, error) {
// Convert tokenIds first
tokenIdStr, err := util.ConvertFloat64SliceToStrings(tokenId)
if err != nil {
return nil, err
}
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, tokenIdStr...)
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
}
- Parameters:
orgId: string – The membership service provider (MSP) ID of the user in the current organization.
userId: string – The user name or email ID of the user.
tokenId ...float64 – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
- Returns:
- On success, the account status history in JSON format.
- 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. Deleted accounts cannot be activated. For any accounts created prior to the account status functionality being available, you must call this method to set the account status as active.
func (t *Controller) ActivateAccount(orgId string, userId string, tokenId ...float64) (interface{}, error) {
// Convert tokenIds first
tokenIdStr, err := util.ConvertFloat64SliceToStrings(tokenId)
if err != nil {
return nil, err
}
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, tokenIdStr...)
if err != nil {
return nil, fmt.Errorf("error in ActivateAccount. Error: %s", err)
}
tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
return t.Ctx.ERC1155Account.ActivateAccount(tokenAccountId)
}
- Parameters:
orgId: string – The membership service provider (MSP) ID of the user in the current organization.
userId: string – The user name or email ID of the user.
tokenId ...float64 – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
- Returns:
- On success, a JSON representation of the token account status.
- Return Value Example:
{
"AssetType": "oaccountStatus",
"StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
"AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
"Status": "active"
}
-
SuspendAccount
- This method suspends a token account. This method can be called only by a
Token Admin of the chaincode. After an account is suspended, you cannot complete any operations that update the account. A deleted account cannot be suspended.
func (t *Controller) SuspendAccount(orgId string, userId string, tokenId ...float64) (interface{}, error) {
// Convert tokenIds first
tokenIdStr, err := util.ConvertFloat64SliceToStrings(tokenId)
if err != nil {
return nil, err
}
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, tokenIdStr...)
if err != nil {
return nil, fmt.Errorf("error in SuspendAccount. Error: %s", err)
}
tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
return t.Ctx.ERC1155Account.SuspendAccount(tokenAccountId)
}
- Parameters:
orgId: string – The membership service provider (MSP) ID of the user in the current organization.
userId: string – The user name or email ID of the user.
tokenId ...float64 – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
- Returns:
- On success, a JSON representation of the token account status.
- 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. 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 must be zero.
func (t *Controller) DeleteAccount(orgId string, userId string, tokenId ...float64) (interface{}, error) {
// Convert tokenIds first
tokenIdStr, err := util.ConvertFloat64SliceToStrings(tokenId)
if err != nil {
return nil, err
}
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, tokenIdStr...)
if err != nil {
return nil, fmt.Errorf("error in DeleteAccount. Error: %s", err)
}
tokenAccountId, err := util.GetAccountProperty(tokenAccount, constants.AccountId)
return t.Ctx.ERC1155Account.DeleteAccount(tokenAccountId)
}
- Parameters:
orgId: string – The membership service provider (MSP) ID of the user in the current organization.
userId: string – The user name or email ID of the user.
tokenId ...float64 – For a non-fungible token account, an empty string. For a fungible token account, the token ID.
- Returns:
- On success, a JSON representation of the token account status.
- Return Value Example:
{
"AssetType": "oaccountStatus",
"StatusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
"AccountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
"Status": "deleted"
}