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


Python bitcoin.rpc方法代码示例

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


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

示例1: is_alive

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def is_alive(self):
        """Test if the node is alive."""
        try:
            self.proxy.getinfo()
        except (ConnectionRefusedError, ConnectionResetError):
            pass
        except bitcoin.rpc.JSONRPCException as err:
            if err.error['code'] == -28:
                pass
            else:
                raise
        except http.client.BadStatusLine:
            pass
        else:
            return True
        # Reinitialize proxy
        self.proxy = bitcoin.rpc.Proxy('http://rt:rt@localhost:%d' % self.rpc_port)
        return False 
开发者ID:hashplex,项目名称:Lightning,代码行数:20,代码来源:regnet.py

示例2: __getattr__

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            # Python internal stuff
            raise AttributeError

        # Create a callable to do the actual call
        f = lambda *args: self._call(name, *args)

        # Make debuggers show <function bitcoin.rpc.name> rather than <function
        # bitcoin.rpc.<lambda>>
        f.__name__ = name
        return f 
开发者ID:petertodd,项目名称:checklocktimeverify-demos,代码行数:14,代码来源:rpc.py

示例3: connect_to_bitcoind_rpc

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def connect_to_bitcoind_rpc(self):
        for i in range(1,settings.rcp_reconnect_max_retry+1):
            try:
                self.proxy = bitcoin.rpc.Proxy()
                return
            except http.client.HTTPException:
                print("Caught a connection error from Bitcoind RCP, Reconnecting...(%d/%d)" %(i,settings.rcp_reconnect_max_retry)) 
开发者ID:mathieulavoie,项目名称:Bitcluster,代码行数:9,代码来源:base_crawler.py

示例4: do_rpc_getrawtransaction

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def do_rpc_getrawtransaction(self, tx_id) :
        """
        Call local Bitcoin RPC method 'getrawtransaction'

        Usage: rpc_sendtoaddress TX_ID
        """
        try :
            proxy = bitcoin.rpc.Proxy()
            r = proxy.getrawtransaction(lx(tx_id), True)
            print(str(r))
        except:
            traceback.print_exc() 
开发者ID:remyers,项目名称:txtenna-python,代码行数:14,代码来源:txtenna.py

示例5: do_rpc_getbalance

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def do_rpc_getbalance(self, rem) :
        """
        Call local Bitcoin RPC method 'getbalance'

        Usage: rpc_getbalance
        """
        try :
            proxy = bitcoin.rpc.Proxy()
            balance = proxy.getbalance()
            print("getbalance: " + str(balance))
        except Exception: # pylint: disable=broad-except
            traceback.print_exc() 
开发者ID:remyers,项目名称:txtenna-python,代码行数:14,代码来源:txtenna.py

示例6: do_rpc_sendrawtransaction

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def do_rpc_sendrawtransaction(self, hex) :
        """
        Call local Bitcoin RPC method 'sendrawtransaction'

        Usage: rpc_sendrawtransaction RAW_TX_HEX
        """
        try :
            proxy = bitcoin.rpc.Proxy()
            r = proxy.sendrawtransaction(hex)
            print("sendrawtransaction: " + str(r))
        except Exception: # pylint: disable=broad-except
            traceback.print_exc() 
开发者ID:remyers,项目名称:txtenna-python,代码行数:14,代码来源:txtenna.py

示例7: do_rpc_sendtoaddress

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def do_rpc_sendtoaddress(self, rem) :
        """
        Call local Bitcoin RPC method 'sendtoaddress'

        Usage: rpc_sendtoaddress ADDRESS SATS
        """
        try:
            proxy = bitcoin.rpc.Proxy()
            (addr, amount) = rem.split()
            r = proxy.sendtoaddress(addr, amount)
            print("sendtoaddress, transaction id: " + str(r["hex"]))
        except Exception: # pylint: disable=broad-except
            traceback.print_exc() 
开发者ID:remyers,项目名称:txtenna-python,代码行数:15,代码来源:txtenna.py

示例8: start

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [as 别名]
def start(self):
        """Start the node."""
        self.process = subprocess.Popen(
            [
                BITCOIND, '-datadir=%s' % self.datadir, '-debug',
                '-regtest', '-txindex', '-listen', '-relaypriority=0',
                '-discover=0',
            ],
            stdin=subprocess.DEVNULL,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.STDOUT)
        self.proxy = bitcoin.rpc.Proxy('http://rt:rt@localhost:%d' % self.rpc_port) 
开发者ID:hashplex,项目名称:Lightning,代码行数:14,代码来源:regnet.py

示例9: spend_command

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [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

示例10: do_mesh_sendtoaddress

# 需要导入模块: import bitcoin [as 别名]
# 或者: from bitcoin import rpc [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.rpc方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。