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


Python Wallet.get_balance方法代码示例

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


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

示例1: SimpleConfig

# 需要导入模块: from electrum.wallet import Wallet [as 别名]
# 或者: from electrum.wallet.Wallet import get_balance [as 别名]

config = SimpleConfig({"testnet": True})  # to use ~/.electrum/testnet as datadir
constants.set_testnet()  # to set testnet magic bytes
daemon = Daemon(config, listen_jsonrpc=False)
network = daemon.network
assert network.asyncio_loop.is_running()

# get wallet on disk
wallet_dir = os.path.dirname(config.get_wallet_path())
wallet_path = os.path.join(wallet_dir, "test_wallet")
if not os.path.exists(wallet_path):
    create_new_wallet(path=wallet_path, segwit=True)

# open wallet
storage = WalletStorage(wallet_path)
wallet = Wallet(storage)
wallet.start_network(network)

# you can use ~CLI commands by accessing command_runner
command_runner = Commands(config, wallet=None, network=network)
command_runner.wallet = wallet
print("balance", command_runner.getbalance())
print("addr",    command_runner.getunusedaddress())
print("gettx",   command_runner.gettransaction("bd3a700b2822e10a034d110c11a596ee7481732533eb6aca7f9ca02911c70a4f"))

# but you might as well interact with the underlying methods directly
print("balance", wallet.get_balance())
print("addr",    wallet.get_unused_address())
print("gettx",   network.run_from_another_thread(network.get_transaction("bd3a700b2822e10a034d110c11a596ee7481732533eb6aca7f9ca02911c70a4f")))
开发者ID:faircoin,项目名称:electrumfair,代码行数:31,代码来源:quick_start.py

示例2: __init__

# 需要导入模块: from electrum.wallet import Wallet [as 别名]
# 或者: from electrum.wallet.Wallet import get_balance [as 别名]
class ElectrumGui:
    def __init__(self, config, network, daemon, plugins):
        self.network = network
        self.config = config
        storage = WalletStorage(config.get_wallet_path())
        if not storage.file_exists:
            print "Wallet not found. try 'electrum create'"
            exit()

        self.done = 0
        self.last_balance = ""

        set_verbosity(False)

        self.str_recipient = ""
        self.str_description = ""
        self.str_amount = ""
        self.str_fee = ""

        self.wallet = Wallet(storage)
        self.wallet.start_threads(network)
        self.contacts = StoreDict(self.config, "contacts")

        network.register_callback(self.on_network, ["updated", "banner"])
        self.commands = [
            _("[h] - displays this help text"),
            _("[i] - display transaction history"),
            _("[o] - enter payment order"),
            _("[p] - print stored payment order"),
            _("[s] - send stored payment order"),
            _("[r] - show own receipt addresses"),
            _("[c] - display contacts"),
            _("[b] - print server banner"),
            _("[q] - quit"),
        ]
        self.num_commands = len(self.commands)

    def on_network(self, event, *args):
        if event == "updated":
            self.updated()
        elif event == "banner":
            self.print_banner()

    def main_command(self):
        self.print_balance()
        c = raw_input("enter command: ")
        if c == "h":
            self.print_commands()
        elif c == "i":
            self.print_history()
        elif c == "o":
            self.enter_order()
        elif c == "p":
            self.print_order()
        elif c == "s":
            self.send_order()
        elif c == "r":
            self.print_addresses()
        elif c == "c":
            self.print_contacts()
        elif c == "b":
            self.print_banner()
        elif c == "n":
            self.network_dialog()
        elif c == "e":
            self.settings_dialog()
        elif c == "q":
            self.done = 1
        else:
            self.print_commands()

    def updated(self):
        s = self.get_balance()
        if s != self.last_balance:
            print (s)
        self.last_balance = s
        return True

    def print_commands(self):
        self.print_list(self.commands, "Available commands")

    def print_history(self):
        width = [20, 40, 14, 14]
        delta = (80 - sum(width) - 4) / 3
        format_str = (
            "%"
            + "%d" % width[0]
            + "s"
            + "%"
            + "%d" % (width[1] + delta)
            + "s"
            + "%"
            + "%d" % (width[2] + delta)
            + "s"
            + "%"
            + "%d" % (width[3] + delta)
            + "s"
        )
        b = 0
        messages = []
#.........这里部分代码省略.........
开发者ID:bontaq,项目名称:electrum,代码行数:103,代码来源:stdio.py

示例3: __init__

# 需要导入模块: from electrum.wallet import Wallet [as 别名]
# 或者: from electrum.wallet.Wallet import get_balance [as 别名]

#.........这里部分代码省略.........

        self.print_list(self.history[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))

    def update_history(self):
        width = [20, 40, 14, 14]
        delta = (self.maxx - sum(width) - 4)/3
        format_str = "%"+"%d"%width[0]+"s"+"%"+"%d"%(width[1]+delta)+"s"+"%"+"%d"%(width[2]+delta)+"s"+"%"+"%d"%(width[3]+delta)+"s"

        b = 0
        self.history = []
        for tx_hash, tx_mined_status, value, balance in self.wallet.get_history():
            if tx_mined_status.conf:
                timestamp = tx_mined_status.timestamp
                try:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
                except Exception:
                    time_str = "------"
            else:
                time_str = 'unconfirmed'

            label = self.wallet.get_label(tx_hash)
            if len(label) > 40:
                label = label[0:37] + '...'
            self.history.append( format_str%( time_str, label, format_satoshis(value, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )


    def print_balance(self):
        if not self.network:
            msg = _("Offline")
        elif self.network.is_connected():
            if not self.wallet.up_to_date:
                msg = _("Synchronizing...")
            else:
                c, u, x =  self.wallet.get_balance()
                msg = _("Balance")+": %f  "%(Decimal(c) / COIN)
                if u:
                    msg += "  [%f unconfirmed]"%(Decimal(u) / COIN)
                if x:
                    msg += "  [%f unmatured]"%(Decimal(x) / COIN)
        else:
            msg = _("Not connected")

        self.stdscr.addstr( self.maxy -1, 3, msg)

        for i in range(self.num_tabs):
            self.stdscr.addstr( 0, 2 + 2*i + len(''.join(self.tab_names[0:i])), ' '+self.tab_names[i]+' ', curses.A_BOLD if self.tab == i else 0)

        self.stdscr.addstr(self.maxy -1, self.maxx-30, ' '.join([_("Settings"), _("Network"), _("Quit")]))

    def print_receive(self):
        addr = self.wallet.get_receiving_address()
        self.stdscr.addstr(2, 1, "Address: "+addr)
        self.print_qr(addr)

    def print_contacts(self):
        messages = map(lambda x: "%20s   %45s "%(x[0], x[1][1]), self.contacts.items())
        self.print_list(messages, "%19s  %15s "%("Key", "Value"))

    def print_addresses(self):
        fmt = "%-35s  %-30s"
        messages = map(lambda addr: fmt % (addr, self.wallet.labels.get(addr,"")), self.wallet.get_addresses())
        self.print_list(messages,   fmt % ("Address", "Label"))

    def print_edit_line(self, y, label, text, index, size):
        text += " "*(size - len(text) )
        self.stdscr.addstr( y, 2, label)
开发者ID:chrisrico,项目名称:electrum,代码行数:70,代码来源:text.py


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