コード例 #1
0
import os.path
import sys

from trezorlib.tx_api import TxApi

if getattr(sys, "frozen", False):
    COINS_JSON = os.path.join(sys._MEIPASS, "trezor_coins.json")
else:
    COINS_JSON = os.path.join(os.path.dirname(__file__), "trezor_coins.json")


def _load_coins_json():
    with open(COINS_JSON) as coins_json:
        return json.load(coins_json)


__all__ = ["by_name", "slip44", "tx_api"]

try:
    coins_list = _load_coins_json()
    by_name = {coin["coin_name"]: coin for coin in coins_list}
except Exception as e:
    raise ImportError(
        "Failed to load trezor_coins.json. Please check your installation."
    ) from e

slip44 = {name: coin["slip44"] for name, coin in by_name.items()}
tx_api = {
    name: TxApi(coin)
    for name, coin in by_name.items() if coin["blockbook"] or coin["bitcore"]
}
コード例 #2
0
 def __init__(self, network, url, polisd_inf, cache_dir):
     TxApi.__init__(self, network)
     self.polisd_inf = polisd_inf
     self.cache_dir = cache_dir
     self.skip_cache = False
コード例 #3
0
 def __init__(self, network, url, geweld_inf, cache_dir):
     TxApi.__init__(self, network)
     self.geweld_inf = geweld_inf
     self.cache_dir = cache_dir
     self.skip_cache = False
コード例 #4
0
 def __init__(self, network, url, dashd_inf, cache_dir):
     TxApi.__init__(self, network)
     self.dashd_inf = dashd_inf
     self.cache_dir = cache_dir
     self.skip_cache = False
コード例 #5
0
 def __init__(self, network, url, crownd_inf, cache_dir):
     TxApi.__init__(self, network)
     self.crownd_inf = crownd_inf
     self.cache_dir = cache_dir
     self.skip_cache = False
コード例 #6
0
ファイル: trezorClient.py プロジェクト: lemonclik/PIVX-SPMT
    def prepare_transfer_tx_bulk(self,
                                 caller,
                                 rewardsArray,
                                 dest_address,
                                 tx_fee,
                                 useSwiftX=False,
                                 isTestnet=False):
        inputs = []
        outputs = []
        c_name = "PIVX"
        if isTestnet:
            c_name += " Testnet"
        coin = coins.by_name[c_name]
        with self.lock:
            self.amount = 0

            for mnode in rewardsArray:
                # Add proper HW path (for current device) on each utxo
                if isTestnet:
                    mnode['path'] = MPATH_TESTNET + mnode['path']
                else:
                    mnode['path'] = MPATH + mnode['path']

                # Create a TX input with each utxo
                for utxo in mnode['utxos']:
                    self.append_inputs_to_TX(utxo, mnode['path'], inputs)

            self.amount = int(self.amount)
            self.amount -= int(tx_fee)
            if self.amount < 0:
                raise Exception('Invalid TX: inputs + fee != outputs')

            outputs.append(
                trezor_proto.TxOutputType(
                    address=dest_address,
                    address_n=None,
                    amount=self.amount,
                    script_type=trezor_proto.OutputScriptType.PAYTOSCRIPTHASH))

            tx_api = TxApi(coin)

            for skip_cache in (False, True):
                try:
                    txes = self.load_prev_txes(tx_api, rewardsArray,
                                               skip_cache)
                    break
                except Exception as e:
                    if skip_cache:
                        raise

            self.mBox2 = QMessageBox(caller)
            self.messageText = "<p>Signing transaction...</p>"
            # messageText += "From bip32_path: <b>%s</b><br><br>" % str(bip32_path)
            self.messageText += "<p>Payment to:<br><b>%s</b></p>" % dest_address
            self.messageText += "<p>Net amount:<br><b>%s</b> PIV</p>" % str(
                round(self.amount / 1e8, 8))
            if useSwiftX:
                self.messageText += "<p>Fees (SwiftX flat rate):<br><b>%s</b> PIV<p>" % str(
                    round(int(tx_fee) / 1e8, 8))
            else:
                self.messageText += "<p>Fees:<br><b>%s</b> PIV<p>" % str(
                    round(int(tx_fee) / 1e8, 8))
            messageText = self.messageText + "Signature Progress: 0 %"
            self.mBox2.setText(messageText)
            self.setBoxIcon(self.mBox2, caller)
            self.mBox2.setWindowTitle("CHECK YOUR TREZOR")
            self.mBox2.setStandardButtons(QMessageBox.NoButton)
            self.mBox2.setMaximumWidth(500)
            self.mBox2.show()

        ThreadFuns.runInThread(self.signTxSign,
                               (inputs, outputs, txes, isTestnet),
                               self.signTxFinish)