11import json
2+
23import requests
34
45from bitsv .network .meta import Unspent
56from bitsv .network .transaction import Transaction , TxInput , TxOutput
67
8+ MATTERCLOUD_API_KEY_VARNAME = 'MATTERCLOUD_API_KEY'
9+
710
811def woc_tx_to_transaction (response ):
912 tx_inputs = []
@@ -20,9 +23,9 @@ def woc_tx_to_transaction(response):
2023 return tx
2124
2225
23- class BitIndex3 :
26+ class MatterCloud :
2427 """
25- Implements version 3 of the BitIndex API
28+ Implements version 3 of the MatterCloud API
2629
2730 :param network: select 'main', 'test', or 'stn'
2831 :type network: ``str``
@@ -68,12 +71,13 @@ def get_unspents(self, address, sort=False, sort_direction='asc'):
6871 headers = self .headers ,
6972 )
7073 r .raise_for_status ()
71- return [Unspent (
74+ utxos = [Unspent (
7275 amount = tx ['satoshis' ],
7376 confirmations = tx ['confirmations' ],
7477 txid = tx ['txid' ],
7578 txindex = tx ['vout' ],
7679 ) for tx in r .json ()]
80+ return sorted (utxos , key = lambda utxo : (- utxo .confirmations , utxo .amount ))
7781
7882 def get_balance (self , address ):
7983 """
@@ -283,7 +287,7 @@ def get_xpub_addresses(
283287 :param address: Filter by a specific address in the xpub
284288 """
285289 r = requests .get (
286- 'https://api.mattercloud.net/api/v3/{self.network }/xpub/{xpub }/addrs' .format (self .network , xpub ),
290+ 'https://api.mattercloud.net/api/v3/{}/xpub/{}/addrs' .format (self .network , xpub ),
287291 params = {
288292 'offset' : offset ,
289293 'limit' : limit ,
@@ -393,7 +397,7 @@ def update_webhook_monitored_addresses(self, address):
393397 return r .json ()
394398
395399
396- class BitIndex3MainNet ( BitIndex3 ):
400+ class MatterCloudMainNet ( MatterCloud ):
397401 """
398402 Implements version 3 of the BitIndex API using the mainnet network
399403 """
@@ -402,7 +406,7 @@ def __init__(self, *args, **kwargs):
402406 return super ().__init__ (* args , ** kwargs , network = 'main' )
403407
404408
405- class BitIndex3TestNet ( BitIndex3 ):
409+ class MatterCloudTestNet ( MatterCloud ):
406410 """
407411 Implements version 3 of the BitIndex API using the testnet network
408412 """
@@ -411,7 +415,7 @@ def __init__(self, *args, **kwargs):
411415 return super ().__init__ (* args , ** kwargs , network = 'test' )
412416
413417
414- class BitIndex3STN ( BitIndex3 ):
418+ class MatterCloudSTN ( MatterCloud ):
415419 """
416420 Implements version 3 of the BitIndex API using the STN network
417421 """
0 commit comments