-
Notifications
You must be signed in to change notification settings - Fork 0
/
btcrpc.py
44 lines (32 loc) · 1 KB
/
btcrpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!coding: utf8
import os
import sys
import math
import string
from datetime import datetime, timedelta
import settings
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
# import logging
# logging.basicConfig()
# logging.getLogger("BitcoinRPC").setLevel(logging.DEBUG)
access = AuthServiceProxy(settings.BITCOIN_RPC)
def getnewaddress(account):
return access.getnewaddress(account)
def getbalance(account=False):
return access.getbalance(account) if account else access.getbalance()
def getaccount(address):
return access.getaccount(address)
def getreceivedbyaddress(address):
return access.getreceivedbyaddress(address)
def listreceivedbyaddress(address):
return access.listreceivedbyaddress(address, True)
def listtransactions(account, count, skip):
return access.listtransactions(account, count, skip)
def send_to_address(address, amount):
try:
access.sendtoaddress(address, amount)
except Exception as e:
return 'error'
return True
if __name__ == '__main__':
print (getbalance())