# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


import unittest
import common
import binascii
from keepkeylib.tools import parse_path
from keepkeylib import messages_pb2 as proto
from keepkeylib import types_pb2 as proto_types
from keepkeylib import tx_api
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
                    proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
                    proto.TxRequest(
                        request_type=proto_types.TXINPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(
                        request_type=proto_types.TXOUTPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(
                        request_type=proto_types.TXOUTPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(request_type=proto_types.TXFINISHED),
                ]
            )
            _, serialized_tx = self.client.sign_tx(
                "Dash", [inp1], [out1]
            )

        self.assertEqual(
            binascii.hexlify(serialized_tx),
            "01000000014fb02af26dca339e7e06c4f148dfce57c9afa5f537d0d8e733022a4ba6ea7955010000006a4730440220387be4d1e4b5e355614091416373e99e1a3532b8cc9a8629368060aff2681bdb02200a0c4a5e9eb2ce6adb6c2e01ec8f954463dcc04f531ed8a89a2b40019d5aeb0b012102936f80cac2ba719ddb238646eb6b78a170a55a52a9b9f08c43523a4a6bd5c896ffffffff0118c69a3b000000001976a9149710d6545407e78c326aa8c8ae386ec7f883b0af88ac00000000"
        )

    def test_send_dash_dip2_input(self):
        self.setup_mnemonic_allallall()

# Path: keepkeylib/tools.py
# def parse_path(nstr):
#     """
#     Convert BIP32 path string to list of uint32 integers with hardened flags.
#     Several conventions are supported to set the hardened flag: -1, 1', 1h
#     e.g.: "0/1h/1" -> [0, 0x80000001, 1]
#     :param nstr: path string
#     :return: list of integers
#     """
#     if not nstr:
#         return []
# 
#     n = nstr.split('/')
# 
#     # m/a/b/c => a/b/c
#     if n[0] == 'm':
#         n = n[1:]
# 
#     # coin_name/a/b/c => 44'/SLIP44_constant'/a/b/c
#     #if n[0] in slip44:
#     #    coin_id = slip44[n[0]]
#     #    n[0:1] = ['44h', '{}h'.format(coin_id)]
# 
#     def str_to_harden(x):
#         if x.startswith('-'):
#             return H_(abs(int(x)))
#         elif x.endswith(('h', "'")):
#             return H_(int(x[:-1]))
#         else:
#             return int(x)
# 
#     try:
#         return list(str_to_harden(x) for x in n)
#     except Exception:
#         raise ValueError('Invalid BIP32 path', nstr)
# 
# Path: keepkeylib/tx_api.py
# def pack_varint(n):
#     def __init__(self, network, url):
#     def fetch_json(self, url, resource, resourceid):
#     def get_tx(self, txhash):
#     def __init__(self, network, url, zcash=None):
#     def get_tx(self, txhash):
#     def get_raw_tx(self, txhash):
# class TxApi(object):
# class TxApiInsight(TxApi):


# Path: tests/test_msg_signtx_dash.py
import unittest
import common
import binascii
from keepkeylib.tools import parse_path
from keepkeylib import messages_pb2 as proto
from keepkeylib import types_pb2 as proto_types
from keepkeylib import tx_api

                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.ButtonRequest(code=proto_types.ButtonRequest_ConfirmOutput),
                    proto.ButtonRequest(code=proto_types.ButtonRequest_SignTx),
                    proto.TxRequest(
                        request_type=proto_types.TXINPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(
                        request_type=proto_types.TXOUTPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(
                        request_type=proto_types.TXOUTPUT,
                        details=proto_types.TxRequestDetailsType(request_index=0),
                    ),
                    proto.TxRequest(request_type=proto_types.TXFINISHED),
                ]
            )
            _, serialized_tx = self.client.sign_tx(
                "Dash", [inp1], [out1]
            )

        self.assertEqual(
            binascii.hexlify(serialized_tx),
            "01000000014fb02af26dca339e7e06c4f148dfce57c9afa5f537d0d8e733022a4ba6ea7955010000006a4730440220387be4d1e4b5e355614091416373e99e1a3532b8cc9a8629368060aff2681bdb02200a0c4a5e9eb2ce6adb6c2e01ec8f954463dcc04f531ed8a89a2b40019d5aeb0b012102936f80cac2ba719ddb238646eb6b78a170a55a52a9b9f08c43523a4a6bd5c896ffffffff0118c69a3b000000001976a9149710d6545407e78c326aa8c8ae386ec7f883b0af88ac00000000"
        )

    def test_send_dash_dip2_input(self):
        self.setup_mnemonic_allallall()

        self.client.set_tx_api(tx_api.TxApiDash)