docs: def btc_address_reencode( address, **blockchain_opts ):
      """
      Depending on whether or not we're in testnet 
      or mainnet, re-encode an address accordingly.
      """
      # re-encode bitcoin address
      network = blockchain_opts.get('network', None)
      opt_version_byte = blockchain_opts.get('version_byte', None)
  
      if btc_is_segwit_address(address):
          # bech32 address
          hrp = None
          if network == 'mainnet':
              hrp = 'bc'
  
          elif network == 'testnet':
              hrp = 'tb'
  
          else:
              if os.environ.get('BLOCKSTACK_TESTNET') == '1' or os.environ.get('BLOCKSTACK_TESTNET3') == '1':
                  hrp = 'tb'
  
              else:
                  hrp = 'bc'
  
          wver, whash = segwit_addr_decode(address)
          return segwit_addr_encode(whash, hrp=hrp, witver=wver)
  
      else:
          # base58 address
          vb = keylib.b58check.b58check_version_byte( address )
  
          if network == 'mainnet':
              if vb == 0 or vb == 111:
                  vb = 0
  
              elif vb == 5 or vb == 196:
                  vb = 5
  
              else:
                  raise ValueError("Unrecognized address %s" % address)
          
          elif network == 'testnet':
              if vb == 0 or vb == 111:
                  vb = 111
              
              elif vb == 5 or vb == 196:
                  vb = 196
  
              else:
                  raise ValueError("Unrecognized address %s" % address)
  
          else:
              if opt_version_byte is not None:
                  vb = opt_version_byte
  
              elif os.environ.get("BLOCKSTACK_TESTNET") == "1" or os.environ.get("BLOCKSTACK_TESTNET3") == "1":
                  if vb == 0 or vb == 111:
                      # convert to testnet p2pkh
                      vb = 111
  
                  elif vb == 5 or vb == 196:
                      # convert to testnet p2sh
                      vb = 196
  
                  else:
                      raise ValueError("unrecognized address %s" % address)
  
              else:
                  if vb == 0 or vb == 111:
                      # convert to mainnet p2pkh
                      vb = 0
  
                  elif vb == 5 or vb == 196:
                      # convert to mainnet p2sh
                      vb = 5
  
                  else:
                      raise ValueError("unrecognized address %s" % address)
  
          return keylib.b58check.b58check_encode( keylib.b58check.b58check_decode(address), vb )