当前位置: 首页>>代码示例>>Python>>正文


Python Transaction.from_io方法代码示例

本文整理汇总了Python中transaction.Transaction.from_io方法的典型用法代码示例。如果您正苦于以下问题:Python Transaction.from_io方法的具体用法?Python Transaction.from_io怎么用?Python Transaction.from_io使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在transaction.Transaction的用法示例。


在下文中一共展示了Transaction.from_io方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: serialize

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def serialize(self, jsontx):
        """Create a transaction from json inputs.
        Inputs must have a redeemPubkey.
        Outputs must be a list of {'address':address, 'value':satoshi_amount}.
        """
        keypairs = {}
        inputs = jsontx.get('inputs')
        outputs = jsontx.get('outputs')
        locktime = jsontx.get('locktime', 0)
        for txin in inputs:
            if txin.get('output'):
                prevout_hash, prevout_n = txin['output'].split(':')
                txin['prevout_n'] = int(prevout_n)
                txin['prevout_hash'] = prevout_hash
            if txin.get('redeemPubkey'):
                pubkey = txin['redeemPubkey']
                txin['type'] = 'p2pkh'
                txin['x_pubkeys'] = [pubkey]
                txin['signatures'] = [None]
                txin['num_sig'] = 1
                if txin.get('privkey'):
                    keypairs[pubkey] = txin['privkey']
            elif txin.get('redeemScript'):
                raise BaseException('Not implemented')

        outputs = map(lambda x: (TYPE_ADDRESS, x['address'], int(x['value'])), outputs)
        tx = Transaction.from_io(inputs, outputs, locktime=locktime)
        tx.sign(keypairs)
        return tx.as_dict()
开发者ID:Matoking,项目名称:electrum,代码行数:31,代码来源:commands.py

示例2: _mktx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned):
        self.nocheck = nocheck
        change_addr = self._resolver(change_addr)
        domain = None if domain is None else map(self._resolver, domain)
        fee = None if fee is None else int(COIN*Decimal(fee))
        final_outputs = []
        for address, amount in outputs:
            address = self._resolver(address)
            #assert self.wallet.is_mine(address)
            if amount == '!':
                assert len(outputs) == 1
                inputs = self.wallet.get_spendable_coins(domain)
                amount = sum(map(lambda x:x['value'], inputs))
                if fee is None:
                    for i in inputs:
                        self.wallet.add_input_info(i)
                    output = ('address', address, amount)
                    dummy_tx = Transaction.from_io(inputs, [output])
                    fee_per_kb = self.wallet.fee_per_kb(self.config)
                    fee = self.wallet.estimated_fee(dummy_tx, fee_per_kb)
                amount -= fee
            else:
                amount = int(COIN*Decimal(amount))
            final_outputs.append(('address', address, amount))

        coins = self.wallet.get_spendable_coins(domain)
        tx = self.wallet.make_unsigned_transaction(coins, final_outputs, self.config, fee, change_addr)
        str(tx) #this serializes
        if not unsigned:
            self.wallet.sign_transaction(tx, self.password)
        return tx
开发者ID:mnaamani,项目名称:electrum,代码行数:33,代码来源:commands.py

示例3: createrawtransaction

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtransaction(self, inputs, outputs):
     for i in inputs:
         i['prevout_hash'] = i['txid']
         i['prevout_n'] = i['vout']
     outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
     tx = Transaction.from_io(inputs, outputs)
     return tx
开发者ID:ROIV,项目名称:ViorCoin-ElectrumWallet,代码行数:9,代码来源:commands.py

示例4: make_tx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def make_tx(self, coins, outputs, change_addrs, fee_estimator,
                dust_threshold):
        '''Select unspent coins to spend to pay outputs.  If the change is
        greater than dust_threshold (after adding the change output to
        the transaction) it is kept, otherwise none is sent and it is
        added to the transaction fee.'''

        # Copy the ouputs so when adding change we don't modify "outputs"
        tx = Transaction.from_io([], outputs[:])
        # Size of the transaction with no inputs and no change
        base_size = tx.estimated_size()
        # Returns fee given input size
        fee = lambda input_size: fee_estimator(base_size + input_size)

        # Collect the coins into buckets, choose a subset of the buckets
        buckets = self.bucketize_coins(coins)
        buckets = self.choose_buckets(buckets, tx.output_value(), fee,
                                      self.penalty_func(tx))

        tx.inputs = [coin for b in buckets for coin in b.coins]
        tx_size = base_size + sum(bucket.size for bucket in buckets)

        # This takes a count of change outputs and returns a tx fee;
        # each pay-to-bitcoin-address output serializes as 34 bytes
        fee = lambda count: fee_estimator(tx_size + count * 34)
        self.add_change(tx, change_addrs, fee, dust_threshold)

        self.print_error("using %d inputs" % len(tx.inputs))
        self.print_error("using buckets:", [bucket.desc for bucket in buckets])

        return tx
开发者ID:ttytyper,项目名称:electrum,代码行数:33,代码来源:coinchooser.py

示例5: serialize

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def serialize(self, jsontx):
        """Create a transaction from json inputs. Inputs must have a redeemPubkey. Outputs must be a list of (address, value).
        """
        keypairs = {}
        inputs = jsontx.get('inputs')
        outputs = jsontx.get('outputs')
        locktime = jsontx.get('locktime', 0)
        for txin in inputs:
            if txin.get('output'):
                prevout_hash, prevout_n = txin['output'].split(':')
                txin['prevout_n'] = int(prevout_n)
                txin['prevout_hash'] = prevout_hash
            else:
                raise BaseException('Output point missing', txin)
            if txin.get('redeemPubkey'):
                pubkey = txin['redeemPubkey']
                txin['pubkeys'] = [pubkey]
                txin['x_pubkeys'] = [pubkey]
                txin['signatures'] = [None]
                txin['num_sig'] = 1
                privkey = txin.get('privkey')
                if privkey:
                    keypairs[pubkey] = privkey
            elif txin.get('redeemScript'):
                raise BaseException('Not implemented')
            else:
                raise BaseException('No redeem script')

        outputs = map(lambda x: (TYPE_ADDRESS, x[0], int(COIN*Decimal(x[1]))), outputs)
        tx = Transaction.from_io(inputs, outputs, locktime=locktime)
        tx.sign(keypairs)
        return tx.as_dict()
开发者ID:Marcdnd,项目名称:electrum-cesc,代码行数:34,代码来源:commands.py

示例6: make_tx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def make_tx(self, coins, outputs, change_addrs, fee_estimator,
                dust_threshold, abandon_txid=None):
        '''Select unspent coins to spend to pay outputs.  If the change is
        greater than dust_threshold (after adding the change output to
        the transaction) it is kept, otherwise none is sent and it is
        added to the transaction fee.'''

        # Deterministic randomness from coins
        utxos = [c['prevout_hash'] + str(c['prevout_n']) for c in coins]
        self.p = PRNG(''.join(sorted(utxos)))

        # Copy the ouputs so when adding change we don't modify "outputs"
        tx = Transaction.from_io([], outputs[:])
        # Size of the transaction with no inputs and no change
        base_size = tx.estimated_size()
        spent_amount = tx.output_value()

        claim_coin = None
        if abandon_txid is not None:
            claim_coins = [coin for coin in coins if coin['is_claim']]
            assert len(claim_coins) >= 1
            claim_coin = claim_coins[0]
            spent_amount -= claim_coin['value']
            coins = [coin for coin in coins if not coin['is_claim']]

        def sufficient_funds(buckets):
            '''Given a list of buckets, return True if it has enough
            value to pay for the transaction'''
            total_input = sum(bucket.value for bucket in buckets)
            total_size = sum(bucket.size for bucket in buckets) + base_size
            return total_input >= spent_amount + fee_estimator(total_size)

        # Collect the coins into buckets, choose a subset of the buckets
        buckets = self.bucketize_coins(coins)
        buckets = self.choose_buckets(buckets, sufficient_funds,
                                      self.penalty_func(tx))

        if claim_coin is not None:
            tx.add_inputs([claim_coin])
        tx.add_inputs([coin for b in buckets for coin in b.coins])
        tx_size = base_size + sum(bucket.size for bucket in buckets)

        # This takes a count of change outputs and returns a tx fee;
        # each pay-to-bitcoin-address output serializes as 34 bytes
        fee = lambda count: fee_estimator(tx_size + count * 34)
        change = self.change_outputs(tx, change_addrs, fee, dust_threshold)
        tx.add_outputs(change)

        self.print_error("using %d inputs" % len(tx.inputs()))
        self.print_error("using buckets:", [bucket.desc for bucket in buckets])

        return tx
开发者ID:DaveA50,项目名称:lbryum,代码行数:54,代码来源:coinchooser.py

示例7: sweep

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def sweep(self, privkey, to_address, fee = 0.0001):
     pubkey = public_key_from_private_key(privkey)
     address = address_from_private_key(privkey)
     pay_script = Transaction.pay_script(address)
     unspent = self.network.synchronous_get([ ('blockchain.address.listunspent',[address])])[0]
     if not unspent:
         return
     total = sum( map(lambda x:int(x.get('value')), unspent) ) - int(Decimal(fee)*100000000)
     inputs = map(lambda i: {'prevout_hash': i['tx_hash'], 'prevout_n':i['tx_pos'], 'scriptPubKey':pay_script, 'redeemPubkey':pubkey}, unspent)
     outputs = [(to_address, total)]
     tx = Transaction.from_io(inputs, outputs)
     tx.sign({ pubkey:privkey })
     return tx
开发者ID:RagnarDanneskjold,项目名称:electrum-ltc,代码行数:15,代码来源:commands.py

示例8: createrawtransaction

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtransaction(self, inputs, outputs):
     coins = self.wallet.get_spendable_coins(None)
     tx_inputs = []
     for i in inputs:
         prevout_hash = i['txid']
         prevout_n = i['vout']
         for c in coins:
             if c['prevout_hash'] == prevout_hash and c['prevout_n'] == prevout_n:
                 self.wallet.add_input_info(c)
                 tx_inputs.append(c)
                 break
         else:
             raise BaseException('Transaction output not in wallet', prevout_hash+":%d"%prevout_n)
     outputs = map(lambda x: ('address', x[0], int(1e6*x[1])), outputs.items())
     tx = Transaction.from_io(tx_inputs, outputs)
     return tx
开发者ID:vergecurrency,项目名称:electrum-xvg-tor,代码行数:18,代码来源:commands.py

示例9: _mktx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def _mktx(self, outputs, fee, change_addr, domain, nocheck, unsigned, claim_name=None, claim_val=None,
              abandon_txid=None, claim_id=None):
        self.nocheck = nocheck
        change_addr = self._resolver(change_addr)
        domain = None if domain is None else map(self._resolver, domain)
        fee = None if fee is None else int(COIN*Decimal(fee))
        final_outputs = []
        for address, amount in outputs:
            address = self._resolver(address)
            #assert self.wallet.is_mine(address)
            if amount == '!':
                assert len(outputs) == 1
                inputs = self.wallet.get_spendable_coins(domain)
                amount = sum(map(lambda x:x['value'], inputs))
                if fee is None:
                    for i in inputs:
                        self.wallet.add_input_info(i)
                    output = (TYPE_ADDRESS, address, amount)
                    dummy_tx = Transaction.from_io(inputs, [output])
                    fee_per_kb = self.wallet.fee_per_kb(self.config)
                    fee = dummy_tx.estimated_fee(fee_per_kb)
                amount -= fee
            else:
                amount = int(COIN*Decimal(amount))
            txout_type = TYPE_ADDRESS
            val = address
            if claim_name is not None and claim_val is not None and claim_id is not None and abandon_txid is not None:
                assert len(outputs) == 1
                txout_type |= TYPE_UPDATE
                val = ((claim_name, claim_id, claim_val), val)
            elif claim_name is not None and claim_id is not None:
                assert len(outputs) == 1
                txout_type |= TYPE_SUPPORT
                val = ((claim_name, claim_id), val)
            elif claim_name is not None and claim_val is not None:
                assert len(outputs) == 1
                txout_type |= TYPE_CLAIM
                val = ((claim_name, claim_val), val)
            final_outputs.append((txout_type, val, amount))

        coins = self.wallet.get_spendable_coins(domain, abandon_txid=abandon_txid)
        tx = self.wallet.make_unsigned_transaction(coins, final_outputs, self.config, fee, change_addr,
                                                   abandon_txid=abandon_txid)
        str(tx) #this serializes
        if not unsigned:
            self.wallet.sign_transaction(tx, self._password)
        return tx
开发者ID:DaveA50,项目名称:lbryum,代码行数:49,代码来源:commands.py

示例10: createrawtx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtx(self, inputs, outputs, unsigned=False):
     """Create a transaction from json inputs. The syntax is similar to bitcoind."""
     coins = self.wallet.get_spendable_coins(exclude_frozen = False)
     tx_inputs = []
     for i in inputs:
         prevout_hash = i['txid']
         prevout_n = i['vout']
         for c in coins:
             if c['prevout_hash'] == prevout_hash and c['prevout_n'] == prevout_n:
                 self.wallet.add_input_info(c)
                 tx_inputs.append(c)
                 break
         else:
             raise BaseException('Transaction output not in wallet', prevout_hash+":%d"%prevout_n)
     outputs = map(lambda x: ('address', x[0], int(COIN*x[1])), outputs.items())
     tx = Transaction.from_io(tx_inputs, outputs)
     if not unsigned:
         self.wallet.sign_transaction(tx, self.password)
     return tx
开发者ID:mnaamani,项目名称:electrum,代码行数:21,代码来源:commands.py

示例11: createrawtx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtx(self, inputs, outputs, unsigned=False):
     """Create a transaction from json inputs. The syntax is similar to gamecreditsd."""
     coins = self.wallet.get_spendable_coins(exclude_frozen=False)
     tx_inputs = []
     for i in inputs:
         prevout_hash = i["txid"]
         prevout_n = i["vout"]
         for c in coins:
             if c["prevout_hash"] == prevout_hash and c["prevout_n"] == prevout_n:
                 self.wallet.add_input_info(c)
                 tx_inputs.append(c)
                 break
         else:
             raise BaseException("Transaction output not in wallet", prevout_hash + ":%d" % prevout_n)
     outputs = map(lambda x: ("address", x[0], int(COIN * x[1])), outputs.items())
     tx = Transaction.from_io(tx_inputs, outputs)
     if not unsigned:
         self.wallet.sign_transaction(tx, self.password)
     return tx.as_dict()
开发者ID:Gamecredits-Universe,项目名称:Gamecredits-electrum-client,代码行数:21,代码来源:commands.py

示例12: make_tx

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
    def make_tx(self, coins, outputs, change_addrs, fee_estimator,
                dust_threshold):
        '''Select unspent coins to spend to pay outputs.  If the change is
        greater than dust_threshold (after adding the change output to
        the transaction) it is kept, otherwise none is sent and it is
        added to the transaction fee.'''
        output_total = sum(map(lambda x: x[2], outputs))

        # Size of the transaction with no inputs and no change
        tx = Transaction.from_io([], outputs)
        base_size = tx.estimated_size()
        # Returns fee given input size
        fee = lambda input_size: fee_estimator(base_size + input_size)

        # Collect the coins into buckets, choose a subset of the buckets
        buckets = self.bucketize_coins(coins)
        buckets = self.choose_buckets(buckets, output_total, fee)

        tx.inputs = [coin for b in buckets for coin in b.coins]
        input_total = sum(bucket.value for bucket in buckets)
        tx_size = base_size + sum(bucket.size for bucket in buckets)

        # If change is above dust threshold after accounting for the
        # size of the change output, add it to the transaction.
        # Pay to bitcoin address serializes as 34 bytes
        change_size = 34
        fee = fee_estimator(tx_size + change_size)
        change_amount = input_total - (output_total + fee)
        if change_amount > dust_threshold:
            tx.outputs.append(('address', change_addrs[0], change_amount))
            self.print_error('change', change_amount)
        elif change_amount:
            self.print_error('not keeping dust', change_amount)

        self.print_error("using %d inputs" % len(tx.inputs))
        self.print_error("using buckets:", [bucket.desc for bucket in buckets])

        return tx
开发者ID:nmarley,项目名称:electrum,代码行数:40,代码来源:coinchooser.py

示例13: createrawtransaction

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtransaction(self, inputs, outputs):
     inputs = map(lambda i: {'prevout_hash': i['txid'], 'prevout_n':i['vout']}, inputs )
     outputs = map(lambda x: (x[0],int(1e8*x[1])), outputs.items())
     tx = Transaction.from_io(inputs, outputs)
     return tx
开发者ID:309972460,项目名称:software,代码行数:7,代码来源:commands.py

示例14: createrawtransaction

# 需要导入模块: from transaction import Transaction [as 别名]
# 或者: from transaction.Transaction import from_io [as 别名]
 def createrawtransaction(self, inputs, outputs):
     inputs = map(lambda i: {"prevout_hash": i["txid"], "prevout_n": i["vout"]}, inputs)
     outputs = map(lambda x: (x[0], int(1e8 * x[1])), outputs.items())
     tx = Transaction.from_io(inputs, outputs)
     return tx
开发者ID:josephyzhou,项目名称:electrum,代码行数:7,代码来源:commands.py


注:本文中的transaction.Transaction.from_io方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。