トークン・アカウント・ステータスのGoメソッド

ブロックチェーン・アプリケーション・ビルダーは、トークン・タクソノミ・フレームワーク標準を使用する実行可能なトークンのアカウント・ステータスを管理するために使用できるメソッドを自動的に生成します。

次の方法を使用して、トークン・ユーザー・アカウントをアクティブ、一時停止または削除された状態に設定できます。

アカウントが一時停止されると、アカウント・ユーザーは、トークンをマイニング、書き込み、転送および保持する書き込み操作を完了できません。また、他のユーザーは、中断されたアカウントにトークンを転送したり、トークンを保持することはできません。中断されたアカウントは、引き続き読取り操作を完了できます。

トークン残高がゼロ以外のアカウントは削除できません。アカウントを削除する前に、アカウント内のすべてのトークンを転送または書き込む必要があります。アカウントが削除済状態になると、アカウントの状態をアクティブまたは一時停止に戻すことはできません。

自動生成された勘定科目ステータス方法

ブロックチェーン・アプリケーション・ビルダーは、トークン・アカウント・ステータスを管理するメソッドを自動的に生成します。コントローラメソッドを呼び出すには、publicである必要があります。パブリック・メソッド名は大文字で始まります。小文字で始まるメソッド名はprivateです。

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 - 指定したアカウントに設定するステータス。activesuspendedまたはdeletedの3つの値のみがサポートされています。
戻り値:
  • 成功すると、アカウント・ステータス・オブジェクトの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"
}