-
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.
-
@Validator(yup.string(), yup.string(), yup.string())
public async getAccountStatus(orgId: string, userId: string, tokenId ?: string) {
const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.get", "TOKEN", { accountId: tokenAccount.accountId });
try {
return await this.Ctx.ERC1155AccountStatus.getAccountStatus(tokenAccount.accountId);
} catch (err) {
return await this.Ctx.ERC1155AccountStatus.getDefaultAccountStatus(tokenAccount.accountId);
}
}
- 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 ?: string
– 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.
-
public async getAccountStatusHistory(orgId: string, userId: string, tokenId ?: string) {
const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.history", "TOKEN", { accountId: tokenAccount.accountId });
const status_id = await this.Ctx.ERC1155AccountStatus.generateAccountStatusId(tokenAccount.accountId);
let accountStatusHistory: any;
try {
accountStatusHistory = await this.Ctx.ERC1155AccountStatus.history(status_id);
} catch (err) {
return [];
}
return accountStatusHistory;
}
- 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 ?: string
– 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:
[
{
"trxId": "d5c6d6f601257ba9b6edaf5b7660f00adc13c37d5321b8f7d3a35afab2e93e63",
"timeStamp": "2022-12-02T10:39:14.000Z",
"value": {
"assetType": "oaccountStatus",
"statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
"accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
"status": "suspended"
}
},
{
"trxId": "e6c850cfa084dc20ad95fb2bb8165eef3a3bd62a0ac867cccee57c2003125183",
"timeStamp": "2022-12-02T10:37:50.000Z",
"value": {
"assetType": "oaccountStatus",
"statusId": "oaccountStatus~5a0b0d8b1c6433af9fedfe0d9e6580e7cf6b6bb62a0de6267aaf79f79d5e96d7",
"accountId": "oaccount~1c568151c4acbcd1bd265c766c677145760a61c47fc8a3ba681a4cfbe287f9c1",
"status": "active"
}
}
]
-
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
.
-
@Validator(yup.string(), yup.string(), yup.string())
public async activateAccount(orgId: string, userId: string, tokenId ?: string) {
await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.activateAccount", "TOKEN");
const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
return await this.Ctx.ERC1155Account.activateAccount(tokenAccount.accountId);
}
- 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 ?: string
– 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.
-
@Validator(yup.string(), yup.string(), yup.string())
public async suspendAccount(orgId: string, userId: string, tokenId ?: string) {
await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.suspendAccount", "TOKEN");
const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
return await this.Ctx.ERC1155Account.suspendAccount(tokenAccount.accountId);
}
- 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 ?: string
– 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.
-
@Validator(yup.string(), yup.string(), yup.string())
public async deleteAccount(orgId: string, userId: string, tokenId ?: string) {
await this.Ctx.ERC1155Auth.checkAuthorization("ERC1155ACCOUNT_STATUS.deleteAccount", "TOKEN");
const userAccountId = this.Ctx.ERC1155Account.generateAccountId(orgId, userId, ACCOUNT_TYPE.USER_ACCOUNT);
let tokenAccount = await this.Ctx.ERC1155Account.getAccount(userAccountId, tokenId);
return await this.Ctx.ERC1155Account.deleteAccount(tokenAccount.accountId);
}
- 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 ?: string
– 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"
}