def map_candidate(candidate): return { 'address': to_none_if_empty(candidate.address), 'votes': string_utils.base64_string(candidate.votes), 'pub_key': string_utils.base64_string(candidate.pubKey), 'reward_address': to_none_if_empty(candidate.rewardAddress) }
def map_log(block, log): return { 'type': 'log', 'height': log.blkHeight, 'action_hash': log.actHash.hex(), 'contract_address': log.contractAddress, 'topics': [string_utils.base64_string(topic) for topic in log.topics], 'data': string_utils.base64_string(log.data), 'index': log.index, 'timestamp': block.header.core.timestamp.ToJsonString() }
def map_plum_challenge_exit(action): plum_challenge_exit = action.core.plumChallengeExit return { 'action_type': 'plum_challenge_exit', 'plum_challenge_exit': { 'sub_chain_address': to_none_if_empty(plum_challenge_exit.subChainAddress), 'coin_id': plum_challenge_exit.coinID, 'challenge_transfer': string_utils.base64_string(plum_challenge_exit.challengeTransfer), 'challenge_transfer_block_proof': string_utils.base64_string( plum_challenge_exit.challengeTransferBlockProof), 'challenge_transfer_block_height': plum_challenge_exit.challengeTransferBlockHeight, } }
def map_plum_start_exit(action): plum_start_exit = action.core.plumStartExit return { 'action_type': 'plum_start_exit', 'plum_start_exit': { 'sub_chain_address': to_none_if_empty(plum_start_exit.subChainAddress), 'previous_transfer': string_utils.base64_string(plum_start_exit.previousTransfer), 'previous_transfer_block_proof': string_utils.base64_string(plum_start_exit.previousTransferBlockProof), 'previous_transfer_block_height': plum_start_exit.previousTransferBlockHeight, 'exit_transfer': string_utils.base64_string(plum_start_exit.exitTransfer), 'exit_transfer_block_proof': string_utils.base64_string(plum_start_exit.exitTransferBlockProof), 'exit_transfer_block_height': plum_start_exit.exitTransferBlockHeight, } }
def map_stake_withdraw(action): stake_withdraw = action.core.stakeWithdraw return { 'action_type': 'stake_withdraw', 'stake_withdraw': { 'bucket_index': stake_withdraw.bucketIndex, 'payload': string_utils.base64_string(stake_withdraw.payload), } }
def map_claim_from_rewarding_fund(action): claim_from_rewarding_fund = action.core.claimFromRewardingFund return { 'action_type': 'claim_from_rewarding_fund', 'claim_from_rewarding_fund': { 'amount': to_int(claim_from_rewarding_fund.amount), 'data': string_utils.base64_string(claim_from_rewarding_fund.data), } }
def map_deposit_to_rewarding_fund(action): deposit_to_rewarding_fund = action.core.depositToRewardingFund return { 'action_type': 'deposit_to_rewarding_fund', 'deposit_to_rewarding_fund': { 'amount': to_int(deposit_to_rewarding_fund.amount), 'data': string_utils.base64_string(deposit_to_rewarding_fund.data), } }
def map_block(raw_block, raw_block_meta): header = raw_block.block.header block = { 'type': 'block', 'version': header.core.version, 'height': header.core.height, 'hash': raw_block_meta.hash, 'timestamp': header.core.timestamp.ToJsonString(), 'prev_block_hash': header.core.prevBlockHash.hex(), 'tx_root': base64_string(header.core.txRoot), 'receipt_root': base64_string(header.core.receiptRoot), 'delta_state_digest': base64_string(header.core.deltaStateDigest), 'producer': iotex_utils.pubkey_to_address(header.producerPubkey), 'signature': base64_string(header.signature), 'number_of_actions': len(raw_block.block.body.actions) } return block
def map_stake_unstake(action): stake_unstake = action.core.stakeUnstake return { 'action_type': 'stake_unstake', 'stake_unstake': { 'bucket_index': stake_unstake.bucketIndex, 'payload': string_utils.base64_string(stake_unstake.payload), } }
def map_execution(action): execution = action.core.execution return { 'action_type': 'execution', 'execution': { 'amount': to_int(execution.amount), 'contract': execution.contract, 'data': string_utils.base64_string(execution.data), } }
def map_put_block(action): put_block = action.core.putBlock return { 'action_type': 'put_block', 'put_block': { 'sub_chain_address': to_none_if_empty(put_block.subChainAddress), 'height': put_block.height, 'roots': [{'name': root.name, 'value': string_utils.base64_string(root.value)} for root in put_block.roots] } }
def map_stake_add_deposit(action): stake_add_deposit = action.core.stakeAddDeposit return { 'action_type': 'stake_add_deposit', 'stake_add_deposit': { 'bucket_index': stake_add_deposit.bucketIndex, 'amount': to_int(stake_add_deposit.amount), 'payload': string_utils.base64_string(stake_add_deposit.payload), } }
def map_transfer(action): transfer = action.core.transfer return { 'action_type': 'transfer', 'transfer': { 'amount': to_int(transfer.amount), 'recipient': to_none_if_empty(transfer.recipient), 'payload': string_utils.base64_string(transfer.payload), } }
def map_stake_transfer_ownership(action): stake_transfer_ownership = action.core.stakeTransferOwnership return { 'action_type': 'stake_transfer_ownership', 'stake_transfer_ownership': { 'bucket_index': stake_transfer_ownership.bucketIndex, 'voter_address': to_none_if_empty(stake_transfer_ownership.voterAddress), 'payload': string_utils.base64_string(stake_transfer_ownership.payload), } }
def map_stake_change_candidate(action): stake_change_candidate = action.core.stakeChangeCandidate return { 'action_type': 'stake_change_candidate', 'stake_change_candidate': { 'bucket_index': stake_change_candidate.bucketIndex, 'candidate_name': stake_change_candidate.candidateName, 'payload': string_utils.base64_string(stake_change_candidate.payload), } }
def map_plum_put_block(action): plum_put_block = action.core.plumPutBlock return { 'action_type': 'plum_put_block', 'plum_put_block': { 'sub_chain_address': to_none_if_empty(plum_put_block.subChainAddress), 'height': plum_put_block.height, 'roots': [{'name': name, 'value': string_utils.base64_string(value)} for name, value in plum_put_block.roots.items()], } }
def map_plum_transfer(action): plum_transfer = action.core.plumTransfer return { 'action_type': 'plum_transfer', 'plum_transfer': { 'coin_id': plum_transfer.coinID, 'denomination': string_utils.base64_string(plum_transfer.denomination), 'owner': plum_transfer.owner, 'recipient': plum_transfer.recipient, } }
def map_stake_restake(action): stake_restake = action.core.stakeRestake return { 'action_type': 'stake_restake', 'stake_restake': { 'bucket_index': stake_restake.bucketIndex, 'staked_duration': stake_restake.stakedDuration, 'auto_stake': stake_restake.autoStake, 'payload': string_utils.base64_string(stake_restake.payload), } }
def map_stake_create(action): stake_create = action.core.stakeCreate return { 'action_type': 'stake_create', 'stake_create': { 'candidate_name': stake_create.candidateName, 'staked_amount': to_int(stake_create.stakedAmount), 'staked_duration': stake_create.stakedDuration, 'auto_stake': stake_create.autoStake, 'payload': string_utils.base64_string(stake_create.payload), } }
def map_candidate_register(action): candidate_register = action.core.candidateRegister return { 'action_type': 'candidate_register', 'candidate_register': { 'name': candidate_register.candidate.name, 'operator_address': to_none_if_empty(candidate_register.candidate.operatorAddress), 'reward_address': to_none_if_empty(candidate_register.candidate.rewardAddress), 'staked_amount': to_int(candidate_register.stakedAmount), 'staked_duration': candidate_register.stakedDuration, 'auto_stake': candidate_register.autoStake, 'owner_address': to_none_if_empty(candidate_register.ownerAddress), 'payload': string_utils.base64_string(candidate_register.payload), } }
def map_transaction_logs(raw_block, block_transaction_log): for log in block_transaction_log.transactionLogs.logs: for index, transaction in enumerate(log.transactions): yield { 'type': 'transaction_log', 'transaction_log_type': transaction.type, 'height': block_transaction_log.blockIdentifier.height, 'action_hash': log.actionHash.hex(), 'index': index, 'topic': string_utils.base64_string(transaction.topic), 'amount': string_utils.to_int(transaction.amount), 'sender': to_none_if_empty(transaction.sender), 'recipient': to_none_if_empty(transaction.recipient), 'timestamp': raw_block.block.header.core.timestamp.ToJsonString(), }