From 72540cb937389144301eeeaf60aa4ae65d45d506 Mon Sep 17 00:00:00 2001 From: Joel Klabo Date: Wed, 2 Dec 2020 13:39:43 -0800 Subject: [PATCH 1/2] Use Blockstream API for Fetching Transactions --- code-ch05/tx.py | 6 +++--- code-ch07/tx.py | 6 +++--- code-ch09/tx.py | 6 +++--- code-ch11/tx.py | 6 +++--- code-ch13/tx.py | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/code-ch05/tx.py b/code-ch05/tx.py index 5d7a7eb3..276e866c 100644 --- a/code-ch05/tx.py +++ b/code-ch05/tx.py @@ -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()) diff --git a/code-ch07/tx.py b/code-ch07/tx.py index 7a5dc69e..fc4f5995 100644 --- a/code-ch07/tx.py +++ b/code-ch07/tx.py @@ -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()) diff --git a/code-ch09/tx.py b/code-ch09/tx.py index 7b3b4080..16c4b96e 100644 --- a/code-ch09/tx.py +++ b/code-ch09/tx.py @@ -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()) diff --git a/code-ch11/tx.py b/code-ch11/tx.py index f2e8008f..674d69ea 100644 --- a/code-ch11/tx.py +++ b/code-ch11/tx.py @@ -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()) diff --git a/code-ch13/tx.py b/code-ch13/tx.py index f6ab094b..79161b2f 100644 --- a/code-ch13/tx.py +++ b/code-ch13/tx.py @@ -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()) From a42929940ae07378a6a0e38eb9986879f04222f5 Mon Sep 17 00:00:00 2001 From: Joel Klabo Date: Wed, 2 Dec 2020 13:54:20 -0800 Subject: [PATCH 2/2] Remove Trailing Slashes --- code-ch06/tx.py | 6 +++--- code-ch07/tx.py | 4 ++-- code-ch08/tx.py | 4 ++-- code-ch09/tx.py | 4 ++-- code-ch10/tx.py | 4 ++-- code-ch12/tx.py | 6 +++--- code-ch13/tx.py | 6 +++--- 7 files changed, 17 insertions(+), 17 deletions(-) diff --git a/code-ch06/tx.py b/code-ch06/tx.py index f96054ad..6ad8bf63 100644 --- a/code-ch06/tx.py +++ b/code-ch06/tx.py @@ -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()) diff --git a/code-ch07/tx.py b/code-ch07/tx.py index fc4f5995..d3beba9c 100644 --- a/code-ch07/tx.py +++ b/code-ch07/tx.py @@ -22,9 +22,9 @@ class TxFetcher: @classmethod def get_url(cls, testnet=False): if testnet: - return 'https://blockstream.info/testnet/api/' + return 'https://blockstream.info/testnet/api' else: - return 'https://blockstream.info/api/' + return 'https://blockstream.info/api' @classmethod def fetch(cls, tx_id, testnet=False, fresh=False): diff --git a/code-ch08/tx.py b/code-ch08/tx.py index 412b63ed..500bea16 100644 --- a/code-ch08/tx.py +++ b/code-ch08/tx.py @@ -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): diff --git a/code-ch09/tx.py b/code-ch09/tx.py index 16c4b96e..99ba94a2 100644 --- a/code-ch09/tx.py +++ b/code-ch09/tx.py @@ -22,9 +22,9 @@ class TxFetcher: @classmethod def get_url(cls, testnet=False): if testnet: - return 'https://blockstream.info/testnet/api/' + return 'https://blockstream.info/testnet/api' else: - return 'https://blockstream.info/api/' + return 'https://blockstream.info/api' @classmethod def fetch(cls, tx_id, testnet=False, fresh=False): diff --git a/code-ch10/tx.py b/code-ch10/tx.py index f2e8008f..a5e658ef 100644 --- a/code-ch10/tx.py +++ b/code-ch10/tx.py @@ -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): diff --git a/code-ch12/tx.py b/code-ch12/tx.py index 168e1cb7..396be463 100644 --- a/code-ch12/tx.py +++ b/code-ch12/tx.py @@ -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()) diff --git a/code-ch13/tx.py b/code-ch13/tx.py index 79161b2f..6c1b6312 100644 --- a/code-ch13/tx.py +++ b/code-ch13/tx.py @@ -18,13 +18,13 @@ class TxFetcher: cache = {} - + @classmethod def get_url(cls, testnet=False): if testnet: - return 'https://blockstream.info/testnet/api/' + return 'https://blockstream.info/testnet/api' else: - return 'https://blockstream.info/api/' + return 'https://blockstream.info/api' @classmethod def fetch(cls, tx_id, testnet=False, fresh=False):