bytes -> str
    Convert output script (the on-chain format) to an address
    There's probably a better way to do this
975258
def from_output_script(output_script, cashaddr=True):
    '''
    
    '''
    try:
        if (len(output_script) == len(riemann.network.P2WSH_PREFIX) + 32
                and output_script.find(riemann.network.P2WSH_PREFIX) == 0):
            # Script hash is the last 32 bytes
            return _hash_to_sh_address(
                output_script[-32:], witness=True, cashaddr=cashaddr)
    except TypeError:
        pass
    try:
        if (len(output_script) == len(riemann.network.P2WPKH_PREFIX) + 20
                and output_script.find(riemann.network.P2WPKH_PREFIX) == 0):
            # PKH is the last 20 bytes
            return _make_pkh_address(
                output_script[-20:], witness=True, cashaddr=cashaddr)
    except TypeError:
        pass

    if len(output_script) == 25 and output_script.find(b'\x76\xa9\x14') == 0:
        return _make_pkh_address(
            output_script[3:23], witness=False, cashaddr=cashaddr)

    elif len(output_script) == 23 and output_script.find(b'\xa9\x14') == 0:
        return _hash_to_sh_address(
            output_script[2:22], witness=False, cashaddr=cashaddr)

    raise ValueError('Cannot parse address from script.')
1287458
def teredoAddrExtractInfo(x):
    
    addr = inet_pton(socket.AF_INET6, x)
    server = inet_ntop(socket.AF_INET, addr[4:8])
    flag = struct.unpack("!H", addr[8:10])[0]
    mappedport = struct.unpack("!H", strxor(addr[10:12], b'\xff' * 2))[0]
    mappedaddr = inet_ntop(socket.AF_INET, strxor(addr[12:16], b'\xff' * 4))
    return server, flag, mappedaddr, mappedport
729195
def btc_make_p2sh_address( script_hex ):
    
    h = hashing.bin_hash160(binascii.unhexlify(script_hex))
    addr = bin_hash160_to_address(h, version_byte=multisig_version_byte)
    return addr
956349
def convertforoutput(self,outputfile):
        """"""
        super(CharEncodingConverter,self).convertforoutput(outputfile)

        return withheaders( flask.make_response( ( line.encode(self.charset) for line in outputfile ) ) , 'text/plain; charset=' + self.charset)
125204
def to_str(data):
    
    if isinstance(data, bytes):
        return codecs.decode(data, TEXT_ENCODING)
    return data
1330657
def address_from_vm_code(code: str):
        
        script_hash = Address.to_script_hash(bytearray.fromhex(code))[::-1]
        return Address(script_hash)
917325
function writeScriptPayToPubKeyHash(address, buffer, offset) {
    offset = buffer.writeUInt8(25, offset); //Script length
    offset = buffer.writeUInt8(OPS.OP_DUP, offset);
    offset = buffer.writeUInt8(OPS.OP_HASH160, offset);
    //Write previous output address
    offset = buffer.writeUInt8(20, offset); //Address length
    offset += Buffer.from(base58check.decode(address, 'hex').data, 'hex').copy(buffer, offset);
    //Static transfer stuff
    offset = buffer.writeUInt8(OPS.OP_EQUALVERIFY, offset);
    offset = buffer.writeUInt8(OPS.OP_CHECKSIG, offset);
    return offset;
}
1316408
def script
      raise ArgumentError, "BTC::ScriptHashAddress: invalid data length (must be 20 bytes)" if self.data.bytesize != 20
      BTC::Script.new << OP_HASH160 << self.data << OP_EQUAL
    end
388804
def _make_output(value, output_script, version=None):
    '''
    
    '''
    if 'decred' in riemann.get_current_network_name():
        return tx.DecredTxOut(
            value=value,
            version=version,
            output_script=output_script)
    return tx.TxOut(value=value, output_script=output_script)
4219
function encodeOutputs(outputs) {

    //Initialize buffer and offset
    let offset = 0;
    var buffer = Buffer.allocUnsafe(100000);
    //Write number of inputs
    offset += bufferutils.writeVarInt(buffer, outputs.length, offset);

    outputs.forEach((output) => {
        //Write value as 8byte integer
        offset = bufferutils.writeUInt64LE(buffer, output.value, offset);
        //Output script
        if (output.script_type) {
            switch (output.script_type) {
                case 'p2sh':
                    offset = writeScriptPayToScriptHash(output.address, buffer, offset);
                    break;
                case 'pubkeyhash':
                    offset = writeScriptPayToPubKeyHash(output.address, buffer, offset);
                    break;
                case 'lock':
                    let locktime_le_string = parseInt(output.locktime).toString(16).replace(/^(.(..)*)$/, "0$1").match(/../g).reverse().join("");
                    offset = writeScriptLockedPayToPubKeyHash(output.address, locktime_le_string, buffer, offset);
                    break;
                case 'attenuation':
                    let model = Script.deserializeAttenuationModel(output.attenuation.model);
                    if (output.attenuation.height_delta > 0)
                        model = Script.adjustAttenuationModel(model, output.attenuation.height_delta);
                    offset = writeAttenuationScript(Script.serializeAttenuationModel(model), output.attenuation.from_tx, output.attenuation.from_index, output.address, buffer, offset);
                    break;
                default:
                    throw 'Unknown script type: ' + output.script_type;
            }
        } else if (output.script) {
            let script = Script.fromASM(output.script).buffer;
            offset += bufferutils.writeVarInt(buffer, script.length, offset);
            offset += script.copy(buffer, offset);
        } else {
            throw 'Neither script not script type present';
        }

        // attachment
        offset = buffer.writeUInt32LE(output.attachment.version, offset);
        offset = buffer.writeUInt32LE(output.attachment.type, offset);

        if (output.attachment.version === Constants.ATTACHMENT.VERSION.DID) {
            offset += encodeString(buffer, output.attachment.to_did, offset);
            offset += encodeString(buffer, output.attachment.from_did, offset);
        }

        switch (output.attachment.type) {
            case Constants.ATTACHMENT.TYPE.ETP_TRANSFER:
                break;
            case Constants.ATTACHMENT.TYPE.MST:
                switch (output.attachment.status) {
                    case Constants.MST.STATUS.REGISTER:
                        offset = encodeAttachmentAssetIssue(buffer, offset, output.attachment);
                        break;
                    case Constants.MST.STATUS.TRANSFER:
                        offset = encodeAttachmentMSTTransfer(buffer, offset, output.attachment.symbol, output.attachment.quantity);
                        break;
                    default:
                        throw Error("Asset status unknown");
                }
                break;
            case Constants.ATTACHMENT.TYPE.MESSAGE:
                offset = encodeAttachmentMessage(buffer, offset, output.attachment.message);
                break;
            case Constants.ATTACHMENT.TYPE.AVATAR:
                offset = encodeAttachmentDid(buffer, offset, output.attachment);
                break;
            case Constants.ATTACHMENT.TYPE.CERT:
                offset = encodeAttachmentCert(buffer, offset, output.attachment);
                break;
            case Constants.ATTACHMENT.TYPE.MIT:
                switch (output.attachment.status) {
                    case Constants.MIT.STATUS.REGISTER:
                        offset = encodeAttachmentMITRegister(buffer, offset, output.attachment.symbol, output.attachment.content, output.attachment.address);
                        break;
                    case Constants.MIT.STATUS.TRANSFER:
                        offset = encodeAttachmentMITTransfer(buffer, offset, output.attachment.symbol, output.attachment.address);
                        break;
                    default:
                        throw Error("Asset status unknown");
                }
                break;
            default:
                throw Error("What kind of an output is that?!");
        }
    });

    return buffer.slice(0, offset);
}
1262299
def _ser_script_to_sh_address(script_bytes, witness=False, cashaddr=True):
    '''
    
    '''
    if witness:
        script_hash = utils.sha256(script_bytes)
    else:
        script_hash = utils.hash160(script_bytes)
    return _hash_to_sh_address(
        script_hash=script_hash,
        witness=witness,
        cashaddr=cashaddr)
1129242
def put_str(content, path, share='C$', conn=None, host=None, username=None, password=None):
    '''
    
    '''
    if HAS_SMBPROTOCOL:
        return _put_str_smbprotocol(
            content, path, share, conn=conn, host=host,
            username=username, password=password
        )
    elif HAS_IMPACKET:
        return _put_str_impacket(
            content, path, share, conn=conn, host=host, username=username, password=password
        )
    raise MissingSmb("SMB library required (impacket or smbprotocol)")
1025811
def format_rpc(self, address, rpc_id, payload):
        """"""

        addr_word = (rpc_id | (address << 16) | ((1 << 1) << 24))

        send_length = len(payload)
        if len(payload) < 20:
            payload = payload + b'\0'*(20 - len(payload))

        payload_words = struct.unpack("<5L", payload)

        return self.base_address + self.RPC_TLS_OFFSET + 8, ([addr_word, send_length, 0] + [x for x in payload_words])
1146667
def add_output(self, address, value, unit='satoshi'):
        
        value_satoshi = self.from_unit_to_satoshi(value, unit)

        if self.verbose:
            print("Adding output of: %s satoshi (%.8f)" % (
                value_satoshi, (value_satoshi / 1e8)
            ))

        self.outs.append({
            'address': address,
            'value': value_satoshi
        })
215721
def btc_make_data_script( data, **ignored ):
    
    if len(data) >= MAX_DATA_LEN * 2:
        raise ValueError("Data hex string is too long")     # note: data is a hex string

    if len(data) % 2 != 0:
        raise ValueError("Data hex string is not even length")

    return "6a{:02x}{}".format(len(data)/2, data)
1312477
def hexlify(script, minify=False):
    
    if not script:
        return ''
    # Convert line endings in case the file was created on Windows.
    script = script.replace(b'\r\n', b'\n')
    script = script.replace(b'\r', b'\n')
    if minify:
        if not can_minify:
            raise ValueError("No minifier is available")
        script = nudatus.mangle(script.decode('utf-8')).encode('utf-8')
    # Add header, pad to multiple of 16 bytes.
    data = b'MP' + struct.pack('<H', len(script)) + script
    # Padding with null bytes in a 2/3 compatible way
    data = data + (b'\x00' * (16 - len(data) % 16))
    if len(data) > _MAX_SIZE:
        # 'MP' = 2 bytes, script length is another 2 bytes.
        raise ValueError("Python script must be less than 8188 bytes.")
    # Convert to .hex format.
    output = [':020000040003F7']  # extended linear address, 0x0003.
    addr = _SCRIPT_ADDR
    for i in range(0, len(data), 16):
        chunk = data[i:min(i + 16, len(data))]
        chunk = struct.pack('>BHB', len(chunk), addr & 0xffff, 0) + chunk
        checksum = (-(sum(bytearray(chunk)))) & 0xff
        hexline = ':%s%02X' % (strfunc(binascii.hexlify(chunk)).upper(),
                               checksum)
        output.append(hexline)
        addr += 16
    return '\n'.join(output)
309077
def convert_bytes(b):
    ''''''
    if b is None:
        return '#NA'
    for s in reversed(memory_symbols):
        if b >= memory_size[s]:
            value = float(b) / memory_size[s]
            return '%.1f%sB' % (value, s)
    return "%sB" % b