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
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
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
}
category
equals send
or receive
, then output your data as you like.
Commented
Dec 8, 2018 at 6:30
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))