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


Python wallet.CBitcoinAddress方法代码示例

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


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

示例1: getreceivedbyaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def getreceivedbyaddress(self, addr, minconf=1):
        """Return total amount received by given a (wallet) address

        Get the amount received by <address> in transactions with at least
        [minconf] confirmations.

        Works only for addresses in the local wallet; other addresses will
        always show zero.

        addr    - The address. (CBitcoinAddress instance)

        minconf - Only include transactions confirmed at least this many times.
        (default=1)
        """
        r = self._call('getreceivedbyaddress', str(addr), minconf)
        return int(r * COIN) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:18,代码来源:rpc.py

示例2: listunspent

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def listunspent(self, minconf=0, maxconf=9999999, addrs=None):
        """Return unspent transaction outputs in wallet

        Outputs will have between minconf and maxconf (inclusive)
        confirmations, optionally filtered to only include txouts paid to
        addresses in addrs.
        """
        r = None
        if addrs is None:
            r = self._call('listunspent', minconf, maxconf)
        else:
            addrs = [str(addr) for addr in addrs]
            r = self._call('listunspent', minconf, maxconf, addrs)

        r2 = []
        for unspent in r:
            unspent['outpoint'] = COutPoint(lx(unspent['txid']), unspent['vout'])
            del unspent['txid']
            del unspent['vout']

            unspent['address'] = CBitcoinAddress(unspent['address'])
            unspent['scriptPubKey'] = CScript(unhexlify(unspent['scriptPubKey']))
            unspent['amount'] = int(unspent['amount'] * COIN)
            r2.append(unspent)
        return r2 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:27,代码来源:rpc.py

示例3: getaccountaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def getaccountaddress(self, account=None):
        """Return the current Bitcoin address for receiving payments to this
        account."""
        r = self._call('getaccountaddress', account)
        return CBitcoinAddress(r) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:7,代码来源:rpc.py

示例4: getnewaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def getnewaddress(self, account=None):
        """Return a new Bitcoin address for receiving payments.

        If account is not None, it is added to the address book so payments
        received with the address will be credited to account.
        """
        r = None
        if account is not None:
            r = self._call('getnewaddress', account)
        else:
            r = self._call('getnewaddress')

        return CBitcoinAddress(r) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:15,代码来源:rpc.py

示例5: getrawchangeaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def getrawchangeaddress(self):
        """Returns a new Bitcoin address, for receiving change.

        This is for use with raw transactions, NOT normal use.
        """
        r = self._call('getrawchangeaddress')
        return CBitcoinAddress(r) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:9,代码来源:rpc.py

示例6: validateaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def validateaddress(self, address):
        """Return information about an address"""
        r = self._call('validateaddress', str(address))
        if r['isvalid']:
            r['address'] = CBitcoinAddress(r['address'])
        if 'pubkey' in r:
            r['pubkey'] = unhexlify(r['pubkey'])
        return r 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:10,代码来源:rpc.py

示例7: create_transaction_output

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def create_transaction_output(address, output_value):
    """
    Create a single transaction output
    :param address:
    :param output_value:
    :return:
    """
    bitcoin_address = CBitcoinAddress(address)
    tx_out = CMutableTxOut(output_value, bitcoin_address.to_scriptPubKey())
    return tx_out 
开发者ID:blockchain-certificates,项目名称:cert-issuer,代码行数:12,代码来源:tx_utils.py

示例8: spend_command

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def spend_command(args):
    args.addr = CBitcoinAddress(args.addr)

    redeemScript = hodl_redeemScript(args.privkey, args.nLockTime)
    scriptPubKey = redeemScript.to_p2sh_scriptPubKey()

    proxy = bitcoin.rpc.Proxy()

    prevouts = []
    for prevout in args.prevouts:
        try:
            txid,n = prevout.split(':')

            txid = lx(txid)
            n = int(n)

            outpoint = COutPoint(txid, n)
        except ValueError:
            args.parser.error('Invalid output: %s' % prevout)


        try:
            prevout = proxy.gettxout(outpoint)
        except IndexError:
            args.parser.error('Outpoint %s not found' % outpoint)

        prevout = prevout['txout']
        if prevout.scriptPubKey != scriptPubKey:
            args.parser.error('Outpoint not correct scriptPubKey')

        prevouts.append((outpoint, prevout))

    sum_in = sum(prev_txout.nValue for outpoint,prev_txout in prevouts)

    tx_size = (4                   + # version field
               2                   + # # of txins
               len(prevouts) * 153 + # txins, including sigs
               1                   + # # of txouts
               34                  + # txout
               4                     # nLockTime field
              )

    feerate = int(proxy._call('estimatefee', 1) * COIN) # satoshi's per KB
    if feerate <= 0:
        feerate = 10000
    fees = int(tx_size / 1000 * feerate)

    unsigned_tx = CTransaction([CTxIn(outpoint, nSequence=0) for outpoint, prevout in prevouts],
                               [CTxOut(sum_in - fees,
                                       args.addr.to_scriptPubKey())],
                               args.nLockTime)

    signed_tx = CTransaction(
        [CTxIn(txin.prevout,
               spend_hodl_redeemScript(args.privkey, args.nLockTime, unsigned_tx, i),
               nSequence=0)
            for i, txin in enumerate(unsigned_tx.vin)],
        unsigned_tx.vout,
        unsigned_tx.nLockTime)

    print(b2x(signed_tx.serialize())) 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:63,代码来源:hodl.py

示例9: check_order_for_payment

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def check_order_for_payment(order_id, db, libbitcoin_client, notification_listener, testnet=False):
    try:
        if os.path.exists(os.path.join(DATA_FOLDER, "purchases", "unfunded", order_id + ".json")):
            file_path = os.path.join(DATA_FOLDER, "purchases", "unfunded", order_id + ".json")
            is_purchase = True
        elif os.path.exists(os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", order_id + ".json")):
            file_path = os.path.join(DATA_FOLDER, "store", "contracts", "unfunded", order_id + ".json")
            is_purchase = False
        with open(file_path, 'r') as filename:
            order = json.load(filename, object_pairs_hook=OrderedDict)
        c = Contract(db, contract=order, testnet=testnet)
        c.blockchain = libbitcoin_client
        c.notification_listener = notification_listener
        c.is_purchase = is_purchase
        addr = c.contract["buyer_order"]["order"]["payment"]["address"]
        SelectParams("testnet" if testnet else "mainnet")
        script_pubkey = CBitcoinAddress(addr).to_scriptPubKey().encode("hex")

        def history_fetched(ec, history):
            if not ec:
                # pylint: disable=W0612
                # pylint: disable=W0640
                amount_funded = 0
                outpoints = []
                for objid, txhash, index, height, value in history:
                    amount_funded += value
                    o = {
                        "txid": txhash.encode("hex"),
                        "vout": index,
                        "value": value,
                        "scriptPubKey": script_pubkey
                    }
                    outpoints.append(o)

                # get the amount (in satoshi) the user is expected to pay
                amount_to_pay = int(float(c.contract["buyer_order"]["order"]["payment"]["amount"]) * 100000000)
                if amount_funded >= amount_to_pay:
                    c.outpoints = outpoints
                    c.payment_received()

        libbitcoin_client.fetch_history2(addr, history_fetched)
    except Exception:
        pass 
开发者ID:OpenBazaar,项目名称:OpenBazaar-Server,代码行数:45,代码来源:contracts.py

示例10: do_mesh_sendtoaddress

# 需要导入模块: from bitcoin import wallet [as 别名]
# 或者: from bitcoin.wallet import CBitcoinAddress [as 别名]
def do_mesh_sendtoaddress(self, rem) :
        """ 
        Create a signed transaction and broadcast it over the connected mesh device. The transaction 
        spends some amount of satoshis to the specified address from the local bitcoind wallet and selected network. 

        Usage: mesh_sendtoaddress ADDRESS SATS NETWORK(m|t)

        eg. txTenna> mesh_sendtoaddress 2N4BtwKZBU3kXkWT7ZBEcQLQ451AuDWiau2 13371337 t
        """
        try:

            proxy = bitcoin.rpc.Proxy()
            (addr, sats, network) = rem.split()

            # Create the txout. This time we create the scriptPubKey from a Bitcoin
            # address.
            txout = CMutableTxOut(sats, CBitcoinAddress(addr).to_scriptPubKey())

            # Create the unsigned transaction.
            unfunded_transaction = CMutableTransaction([], [txout])
            funded_transaction = proxy.fundrawtransaction(unfunded_transaction)
            signed_transaction = proxy.signrawtransaction(funded_transaction["tx"])
            txhex = b2x(signed_transaction["tx"].serialize())
            txid = b2lx(signed_transaction["tx"].GetTxid())
            print("sendtoaddress_mesh (tx, txid, network): " + txhex + ", " + txid, ", " + network)

            # broadcast over mesh
            self.do_mesh_broadcast_rawtx( txhex + " " + txid + " " + network)

        except Exception: # pylint: disable=broad-except
            traceback.print_exc()

        try :
            # lock UTXOs used to fund the tx if broadcast successful
            vin_outpoints = set()
            for txin in funded_transaction["tx"].vin:
                vin_outpoints.add(txin.prevout)
            ## json_outpoints = [{'txid':b2lx(outpoint.hash), 'vout':outpoint.n}
            ##              for outpoint in vin_outpoints]
            ## print(str(json_outpoints))
            proxy.lockunspent(False, vin_outpoints)
            
        except Exception: # pylint: disable=broad-except
            ## TODO: figure out why this is happening
            print("RPC timeout after calling lockunspent") 
开发者ID:remyers,项目名称:txtenna-python,代码行数:47,代码来源:txtenna.py


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