Skip to content

Commit 3fba6b9

Browse files
authored
Merge pull request jimmysong#202 from joelklabo/fix-tx-fetcher
Use Blockstream API for Fetching Transactions
2 parents 2a65582 + a429299 commit 3fba6b9

File tree

9 files changed

+26
-26
lines changed

9 files changed

+26
-26
lines changed

code-ch05/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ class TxFetcher:
2121
@classmethod
2222
def get_url(cls, testnet=False):
2323
if testnet:
24-
return 'http://testnet.programmingbitcoin.com'
24+
return 'https://blockstream.info/testnet/api/'
2525
else:
26-
return 'http://mainnet.programmingbitcoin.com'
26+
return 'https://blockstream.info/api/'
2727

2828
@classmethod
2929
def fetch(cls, tx_id, testnet=False, fresh=False):
3030
if fresh or (tx_id not in cls.cache):
31-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
31+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3232
response = requests.get(url)
3333
try:
3434
raw = bytes.fromhex(response.text.strip())

code-ch06/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ class TxFetcher:
2020
@classmethod
2121
def get_url(cls, testnet=False):
2222
if testnet:
23-
return 'http://testnet.programmingbitcoin.com'
23+
return 'https://blockstream.info/testnet/api'
2424
else:
25-
return 'http://mainnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/api'
2626

2727
@classmethod
2828
def fetch(cls, tx_id, testnet=False, fresh=False):
2929
if fresh or (tx_id not in cls.cache):
30-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
30+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3131
response = requests.get(url)
3232
try:
3333
raw = bytes.fromhex(response.text.strip())

code-ch07/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):
3131
if fresh or (tx_id not in cls.cache):
32-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
32+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3333
response = requests.get(url)
3434
try:
3535
raw = bytes.fromhex(response.text.strip())

code-ch08/tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):

code-ch09/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):
3131
if fresh or (tx_id not in cls.cache):
32-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
32+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3333
response = requests.get(url)
3434
try:
3535
raw = bytes.fromhex(response.text.strip())

code-ch10/tx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):

code-ch11/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api/'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api/'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):
3131
if fresh or (tx_id not in cls.cache):
32-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
32+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3333
response = requests.get(url)
3434
try:
3535
raw = bytes.fromhex(response.text.strip())

code-ch12/tx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class TxFetcher:
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):
3131
if fresh or (tx_id not in cls.cache):
32-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
32+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3333
response = requests.get(url)
3434
try:
3535
raw = bytes.fromhex(response.text.strip())

code-ch13/tx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818

1919
class TxFetcher:
2020
cache = {}
21-
21+
2222
@classmethod
2323
def get_url(cls, testnet=False):
2424
if testnet:
25-
return 'http://testnet.programmingbitcoin.com'
25+
return 'https://blockstream.info/testnet/api'
2626
else:
27-
return 'http://mainnet.programmingbitcoin.com'
27+
return 'https://blockstream.info/api'
2828

2929
@classmethod
3030
def fetch(cls, tx_id, testnet=False, fresh=False):
3131
if fresh or (tx_id not in cls.cache):
32-
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
32+
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
3333
response = requests.get(url)
3434
try:
3535
raw = bytes.fromhex(response.text.strip())

0 commit comments

Comments
 (0)