Skip to content

Commit

Permalink
Merge pull request #202 from joelklabo/fix-tx-fetcher
Browse files Browse the repository at this point in the history
Use Blockstream API for Fetching Transactions
  • Loading branch information
jimmysong authored Dec 4, 2020
2 parents 2a65582 + a429299 commit 3fba6b9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions code-ch05/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api/'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api/'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
6 changes: 3 additions & 3 deletions code-ch06/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
6 changes: 3 additions & 3 deletions code-ch07/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
4 changes: 2 additions & 2 deletions code-ch08/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
Expand Down
6 changes: 3 additions & 3 deletions code-ch09/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
4 changes: 2 additions & 2 deletions code-ch10/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
Expand Down
6 changes: 3 additions & 3 deletions code-ch11/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api/'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api/'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
6 changes: 3 additions & 3 deletions code-ch12/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ class TxFetcher:
@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down
8 changes: 4 additions & 4 deletions code-ch13/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

class TxFetcher:
cache = {}

@classmethod
def get_url(cls, testnet=False):
if testnet:
return 'http://testnet.programmingbitcoin.com'
return 'https://blockstream.info/testnet/api'
else:
return 'http://mainnet.programmingbitcoin.com'
return 'https://blockstream.info/api'

@classmethod
def fetch(cls, tx_id, testnet=False, fresh=False):
if fresh or (tx_id not in cls.cache):
url = '{}/tx/{}.hex'.format(cls.get_url(testnet), tx_id)
url = '{}/tx/{}/hex'.format(cls.get_url(testnet), tx_id)
response = requests.get(url)
try:
raw = bytes.fromhex(response.text.strip())
Expand Down

0 comments on commit 3fba6b9

Please sign in to comment.