스팀 앱 개발기 #23 - condenser_api.get_accounts API 연동에 필요한 데이터 클래스 정의

image.png

지금은 앱과 condenser_api.get_accounts API를 연동을 구현 중입니다. 이번 포스트에서는 이 API 연동에 필요한 데이터 클래스들을 정의해보겠습니다.


서버에 보낼 파라메터 클래스

condenser_api.get_accounts API를 실행할 때, 서버에 보낼 JSON 데이터는 아래와 같습니다.

{"jsonrpc":"2.0", "method":"condenser_api.get_accounts", "params":[["스팀잇_계정"]], "id":1}

위 JSON 자료를 데이터 클래스 포맷으로 나타내면 다음과 같습니다.

data class GetAccountsParams(
    val jsonrpc: String = "2.0",
    val method: String = "condenser_api.get_accounts",
    val params: Array<Array<String>>,
    val id: Int
)

서버로부터 받을 응답 클래스

아... 이게 무지 깁니다. 어제 포스트를 길게 쓰지 못 했던 이유이기도 하죠. 서버 응답 자료를 아래와 같이 데이터 클래스로 변환할 것입니다. 최상위 클래스는 GetAccountsResponseEntity이구요. 하위 JSON 자료들도 하위 데이터 클래스로 변환합니다. 이들이 여러개라서 여러 개의 클래스들이 추가로 만들어졌습니다. API 테스트 결과, 응답 자료에 빈 배열이 여러 개 있습니다. 이들의 원소들이 어떤 데이터 포맷을 갖는지 지금은 알 수 없네요. 일단 포맷을 알 수 없는 원소들의 데이터 타입은 Any로 정했습니다.

data class GetAccountsResponseEntity(
    val jsonrpc: String = "2.0",
    val result: Array<SteemitAccountEntity>,
    val id: Int
)

data class SteemitAccountEntity(
    val id: String,
    val name: String,
    val owner: SteemitKeyEntity,
    val active: SteemitKeyEntity,
    val posting: SteemitKeyEntity,
    val memo_key: String,
    val json_metadata: String,
    val posting_json_metadata: String,
    val proxy: String,
    val last_owner_update: String,
    val last_account_update: String,
    val created: String,
    val mined: Boolean,
    val recovery_account: String,
    val last_account_recovery: String,
    val reset_account: String,
    val comment_count: Int,
    val lifetime_vote_count: Int,
    val post_count: Int,
    val can_vote: Boolean,
    val voting_manabar: ManabarEntity,
    val downvote_manabar: ManabarEntity,
    val voting_power: Int,
    val balance: String,
    val savings_balance: String,
    val sbd_balance: String,
    val sbd_seconds: String,
    val sbd_seconds_last_update: String,
    val sbd_last_interest_payment: String,
    val savings_sbd_balance: String,
    val savings_sbd_seconds: String,
    val savings_sbd_seconds_last_update: String,
    val savings_sbd_last_interest_payment: String,
    val savings_withdraw_requests: Int,
    val reward_sbd_balance: String,
    val reward_steem_balance: String,
    val reward_vesting_balance: String,
    val reward_vesting_steem: String,
    val vesting_shares: String,
    val delegated_vesting_shares: String,
    val received_vesting_shares: String,
    val vesting_withdraw_rate: String,
    val next_vesting_withdrawal: String,
    val withdrawn: String,
    val to_withdraw: String,
    val withdraw_routes: Int,
    val curation_rewards: Long,
    val posting_rewards: Long,
    val proxied_vsf_votes: Array<Any>,
    val witnesses_voted_for: Int,
    val last_post: String,
    val last_root_post: String,
    val last_vote_time: String,
    val post_bandwidth: Int,
    val pending_claimed_accounts: Int,
    val vesting_balance: String,
    val reputation: String,
    val transfer_history: Array<Any>,
    val market_history: Array<Any>,
    val post_history: Array<Any>,
    val vote_history: Array<Any>,
    val other_history: Array<Any>,
    val witness_votes: Array<Any>,
    val tags_usage: Array<Any>,
    val guest_bloggers: Array<Any>
)

data class SteemitKeyEntity(
    val weight_threshold: Int,
    val account_auths: Array<Any>,
    val key_auths: Array<Array<Any>>
)

data class ManabarEntity(
    val current_mana: String,
    val last_update_time: Long
)

길이를 보면 아시겠지만, 포맷이 길다 보니 클래스 작성하는 시간도 적지 않게 들더군요.


GitHub Commits


마치며...

다음 포스트에서는 서버 연동을 담당할 클래스를 정의할 예정입니다. 틈내서 조금씩 작업하는 것이다 보니 진도가 빠르지는 않네요. 차근차근 그러나 꾸준히 진행해 보고자 합니다.


지난 스팀 앱 개발기

Coin Marketplace

STEEM 0.18
TRX 0.14
JST 0.029
BTC 57849.42
ETH 3122.29
USDT 1.00
SBD 2.43