LoginSignup
3
2

More than 5 years have passed since last update.

BitZeny のマイニングの集計を行う

Last updated at Posted at 2018-01-28

漢なら BitZeny のマイニングの集計を行い, 税計算に活用したいですね!

やりましょう!

前提条件

  • ブロックチェーンに記録されたトランザクションで集計を行います.
  • プールマイニングの場合, 報酬はプールマイニングから自動で払い出され, ブロックチェーンに刻まれた情報を元に集計を行います(プールに報酬が溜まったままで払い出されていない状態の残高は考慮しない).
  • マイニング用にひとつのアドレスを使っていて, 交換所で変えたトランザクションは無いものとします.

集計する.

BitZeny 用の Insight(ブロックチェーン解析ソフト) サービスが立ち上がっています. ありがとうございます.

https://zenyinsight.tomotomo9696.xyz/

以下の REST API を GET で叩くと, アドレスのすべての取引履歴を JSON で取得することができます.

https://zenyinsight.tomotomo9696.xyz/api/txs/?address=XXXXX

JSON のレイアウトは ZChain とだいたい同じです(ZChain のほうが Bitcoin Insight を拡張したようですね).

を参考に, python スクリプトを書きます.

#!/usr/bin/env python
# 
import json
import os
import sys
import datetime

# Set your BitZeny address.
MY_ADDR = 'XXXXXXXXX'

def findReceivedAmount(b, addr):
    amount = 0.0

    for vout in b['vout']:
        if MY_ADDR in vout['scriptPubKey']['addresses']:
            amount += float(vout['value'])

    return amount

def main():
    j = json.loads(open("data.json").read())

    print("timestamp, date, amount")

    # for each block
    for b in j['txs']:
        timestamp = b['time']
        # print(b['timestamp'])

        # find received amount for my account
        amount = findReceivedAmount(b, MY_ADDR)
        textualdate = datetime.datetime.fromtimestamp(timestamp)
        print("{0}, {1}, {2}".format(timestamp, textualdate, amount))      

main()
timestamp, date, amount
1517149933, 2018-01-28 23:32:13, 0.14967285
1517143276, 2018-01-28 21:41:16, 0.14737623
1517138526, 2018-01-28 20:22:06, 0.13828271
1517125319, 2018-01-28 16:41:59, 0.13137248
...

Voila! 無事集計できました.

ZNY/JPY の日毎の価格を取得する

取得価額を得るため, ZNY/JPY の日毎の価格を CryptoCompare API で取得します.

date, open, high, low, close, ave
2017-02-15, 0.007055, 0.007055, 0.007055, 0.007055, 0.007055
2017-02-16, 0.007181, 0.007181, 0.007181, 0.007181, 0.007181
2017-02-17, 0.007286, 0.008501, 0.007286, 0.008501, 0.0078935
2017-02-18, 0.008509, 0.008509, 0.007293, 0.008509, 0.007901
2017-02-19, 0.008481, 0.01212, 0.007269, 0.01212, 0.0096945
2017-02-20, 0.01232, 0.01232, 0.008627, 0.008627, 0.0104735
2017-02-21, 0.009158, 0.009158, 0.007849, 0.007849, 0.0085035
2017-02-22, 0.007809, 0.009111, 0.007809, 0.007809, 0.008459999999999999
2017-02-23, 0.008128, 0.009482, 0.008128, 0.008128, 0.008805
2017-02-24, 0.008171, 0.06128, 0.008171, 0.01089, 0.0347255
2017-02-25, 0.01049, 0.01311, 0.00918, 0.01049, 0.011145
2017-02-26, 0.01078, 0.01078, 0.01078, 0.01078, 0.01078
2017-02-27, 0.01091, 0.01227, 0.01091, 0.01091, 0.01159
2017-02-28, 0.01122, 0.01262, 0.009817, 0.01122, 0.0112185
2017-03-01, 0.01165, 0.01165, 0.01019, 0.01019, 0.01092
2017-03-02, 0.01052, 0.01352, 0.01052, 0.01352, 0.01202
2017-03-03, 0.01392, 0.01392, 0.01237, 0.01237, 0.013145
...

Voila! 無事 ZNY/JPY の日毎の価格を取得できました!

TODO

  • 日毎の価格とマイニングの履歴とのマッチングを取り, 移動平均法で取得価額の計算を行う.
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2