how to split transactions based on send and receive Json rpc bitcoin

0

I am creating new wallet for bitcoin and want to know how we can get the separate list of send and receive transactions using JSON rpc.

I cant see any method for json rpc that give list of send and receive category

Pankaj Kumar

Posted 2018-12-03T07:09:07.913

Reputation: 145

are you searching for sendtoaddress rpc?cryptoKTM 2018-12-03T11:27:11.803

no , i am looking for the way to get list of sent and receive transactions ,listtransactions returning send and receive list , i want to get separate list of sent and recievePankaj Kumar 2018-12-03T11:40:59.827

you need to find it out through VOUT and VIN listcryptoKTM 2018-12-03T12:26:50.290

is that means there is no separate rpc call for getting the sent and receive for particular account label ?Pankaj Kumar 2018-12-03T12:41:48.267

listunspent : version 0.7 Returns array of unspent transaction inputs in the wallet. source : https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list

cryptoKTM 2018-12-03T12:55:38.303

sorry but its not have any parameters that differentiate the accounts. i need a way so that on the basis of accounts label i have the sent and receive transactions listPankaj Kumar 2018-12-03T13:01:11.980

Let us continue this discussion in chat.

Pankaj Kumar 2018-12-04T09:11:46.297

Answers

0

Sounds like you are looking for the listtransactions API call in combination with the category field.

First argument is for a specific account, use * to return all accounts.
2nd is how many you want to return.
3rd is if you want to skip transaction from the start.
4th argument is if you want to include watch-only addresses.

$bitcoin->listtransactions("*", 100, 0, false);

Example output (note the category field):

{
"result": [
    {
        "account": "",
        "address": "32NFcoB96ANoPnqycLH9WUd94o7bwRyq66",
        "category": "receive",
        "amount": 0.00385000,
        "label": "",
        "vout": 1,
        "confirmations": 24827,
        "blockhash": "000000000000000000250cffa73c2a08e64e53dab398ede3f38b1c30ae5c66ca",
        "blockindex": 317,
        "blocktime": 1529098309,
        "txid": "07b1d3fbc4d78d480d510264bb01bd390e81cda34dcb01e882e94adfa9355d10",
        "walletconflicts": [

        ],
        "time": 1529098115,
        "timereceived": 1529098115,
        "bip125-replaceable": "no"
    }
],
"error": null,
"id": null
}

m1xolyd1an

Posted 2018-12-03T07:09:07.913

Reputation: 3 356

sorry but how can i categorise all transactions ? With above results its mixed transactions of send and receive .Also i cant get the total count of all transactionsPankaj Kumar 2018-12-04T09:16:01.343

1You need to filter the result yourself by looking at the category.Andrew Chow 2018-12-04T16:49:10.900

Andrew but i can understand that i have to filter result , but one thing i cant understand that how can i count the total transactions , as there is no count attribute return by the listransactions rpc callPankaj Kumar 2018-12-05T04:27:53.987

Andrew can you please check if the above logic is correct or notPankaj Kumar 2018-12-05T06:21:56.277

As achow mentions you need to add that yourself. Create a simple loop and then check to see if category equals send or receive, then output your data as you like.m1xolyd1an 2018-12-08T06:30:40.207

0

    from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
import logging
RPC_USER, RPC_PWD,URL,PORT="RPC_USER","RPC_PWD","URL","PORT"


CONN="http://%s:%s@%s:%s"%(RPC_USER, RPC_PWD,URL,PORT)
try:
    rpc_connection = AuthServiceProxy(CONN) 
    start=10
    end=0
    count=0 
    receive=[]
    send=[]
    while True:
        trans=rpc_connection.listtransactions("prologic",10,end)
        for tran in trans:                  
            if(tran['category'] == "receive"):
                receive.insert(0,tran)              
            else:
                send.insert(0,tran)
        if(len(trans) is 0):
            break
        else:
            end=end+10
            count=count+len(trans)


    all_trans={"total":count,"receive":{"count":len(receive),"trans":receive},"send":{"count":len(send),"trans":send}}
    print(all_trans)

except Exception as e:
    print (str(e))

Pankaj Kumar

Posted 2018-12-03T07:09:07.913

Reputation: 145