BitShares Forum

Main => Technical Support => Topic started by: runestone on March 23, 2018, 12:39:26 am

Title: Convert account history (transactions) object to JSON
Post by: runestone on March 23, 2018, 12:39:26 am
Hi, can someone help me convert the generator object returned by history() to JSON?

Code: [Select]
>>from bitshares.account import Account
>>account = Account("test")
>>history = account.history()
>>print(history)
<bound method Account.history of <Account 1.2.1516>>

Reference: http://docs.pybitshares.com/en/latest/bitshares.account.html
Title: Re: Convert account history (transactions) object to JSON
Post by: xeroc on March 23, 2018, 09:18:54 am
that call returns a *generator*:

Code: [Select]
for h in accout.history(limit=10):
   print(h)
Title: Re: Convert account history (transactions) object to JSON
Post by: runestone on March 25, 2018, 03:43:39 pm
Thanks, I got it working now. One more question.

When running this:
Code: [Select]
from bitshares.account import Account
account = Account("xeroc")
history = account.history(exclude_ops=[6])
data = [trans for trans in history]
return data

The following is returned:
Code: [Select]
[
    {
        "id": "1.11.158994520",
        "op": [
            6,
            {
                "fee": {
                    "amount": 1666,
                    "asset_id": "1.3.0"
                },
                "account": "1.2.282",
                "new_options": {
                    "memo_key": "BTS5TPTziKkLexhVKsQKtSpo4bAv5RnB8oXcG4sMHEwCcTf3r7dqE",
                    "voting_account": "1.2.5",
                    "num_witness": 21,
...SNIPPET...

It seems like the exclude_ops dosen't work. The same thing applies to only_ops, or what am I doing wrong?
Title: Re: Convert account history (transactions) object to JSON
Post by: xeroc on March 25, 2018, 04:00:04 pm
exclude_ops=['transfer']
Title: Re: Convert account history (transactions) object to JSON
Post by: runestone on March 28, 2018, 12:11:56 am
Thanks! :)