-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_notes.py
62 lines (46 loc) · 1.82 KB
/
1_notes.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Prints the hexadecimal representation of the value.
print(int('b',16), int('62ba1cd8a',16))
#testnet : A small replica of bitcoin for developers to test their app without real money.
#We use bitcoin-cli command to communicate with a node. It is a command line utility.
#In this course we use >testnet rather than >bitcoin-cli.
#Prints all the commands to use in testnet or mainnet
testnet help
mainnet help
#Gets the help for the related command
testnet help getblockchaininfo
#Makes the query with the method for the testnet. mainnet for the actual chain
testnet getblockchaininfo
#Gives the mining info
mainnet getmininginfo
#Check how the nodes talk with each other from https://bitcoin.org/en/developer-reference#protocol-versions
#This changes from version to version. ipv4 / ipv6 / onion
#Gives the wallet info
testnet getwalletinfo
#The transactions related to wallet
testnet listtransactions
#Code to connect to node
#If you don't have bitcoinrpc install it with pip:
#pip install python-bitcoinrpc
"""
Code:
from bitcoinrpc.authproxy import AuthServiceProxy
N = 115792089237316195423570985008687907852837564279074904382605163141518161494337
big_number = 105936749493397165751943248390023977685888340619776708311600296471039819517671
class RPC:
def __init__(self, uri):
self.rpc = AuthServiceProxy(uri)
def __getattr__(self, name):
"""Hack to establish a new AuthServiceProxy every time this is called"""
return getattr(self.rpc, name)
rpc_template = "http://%s:%s@%s:%s"
mainnet = RPC(rpc_template %
('bitcoin', 'python', '68.183.110.103', 8332))
testnet = RPC(rpc_template %
('bitcoin', 'python', 'localhost', 18332))
"""
"""
pprint : A package to print objects pretty.Especially JSON objects.
from helpers import testnet
from pprint import pprint
pprint(testnet.getblockchaininfo())
"""