本文整理汇总了Python中util.format_satoshis函数的典型用法代码示例。如果您正苦于以下问题:Python format_satoshis函数的具体用法?Python format_satoshis怎么用?Python format_satoshis使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_satoshis函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_tx_details
def get_tx_details(self, tx_hash):
import datetime
if not tx_hash:
return ""
tx = self.transactions.get(tx_hash)
is_mine, v, fee = self.get_tx_value(tx_hash)
conf = self.verifier.get_confirmations(tx_hash)
timestamp = tx.get("timestamp")
if conf and timestamp:
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(" ")[:-3]
else:
time_str = "pending"
inputs = map(lambda x: x.get("address"), tx["inputs"])
outputs = map(lambda x: x.get("address"), tx["outputs"])
tx_details = (
"Transaction Details"
+ "\n\n"
+ "Transaction ID:\n"
+ tx_hash
+ "\n\n"
+ "Status: %d confirmations\n" % conf
)
if is_mine:
if fee:
tx_details += "Amount sent: %s\n" % format_satoshis(
v - fee, False
) + "Transaction fee: %s\n" % format_satoshis(fee, False)
else:
tx_details += "Amount sent: %s\n" % format_satoshis(v, False) + "Transaction fee: unknown\n"
else:
tx_details += "Amount received: %s\n" % format_satoshis(v, False)
tx_details += (
"Date: %s\n\n" % time_str + "Inputs:\n-" + "\n-".join(inputs) + "\n\n" + "Outputs:\n-" + "\n-".join(outputs)
)
r = self.receipts.get(tx_hash)
if r:
tx_details += (
"\n_______________________________________"
+ "\n\nSigned URI: "
+ r[2]
+ "\n\nSigned by: "
+ r[0]
+ "\n\nSignature: "
+ r[1]
)
return tx_details
示例2: listaddresses
def listaddresses(
self,
receiving=False,
change=False,
show_labels=False,
frozen=False,
unused=False,
funded=False,
show_balance=False,
):
"""List wallet addresses. Returns the list of all addresses in your wallet. Use optional arguments to filter the results."""
out = []
for addr in self.wallet.addresses(True):
if frozen and not self.wallet.is_frozen(addr):
continue
if receiving and self.wallet.is_change(addr):
continue
if change and not self.wallet.is_change(addr):
continue
if unused and self.wallet.is_used(addr):
continue
if funded and self.wallet.is_empty(addr):
continue
item = addr
if show_balance:
item += ", " + format_satoshis(sum(self.wallet.get_addr_balance(addr)))
if show_labels:
item += ", " + repr(self.wallet.labels.get(addr, ""))
out.append(item)
return out
示例3: get_tx_history
def get_tx_history(self):
with self.lock:
history = self.transactions.items()
history.sort(key = lambda x: self.verifier.get_height(x[0]) if self.verifier.get_height(x[0]) else 1e12)
result = []
balance = 0
for tx_hash, tx in history:
is_mine, v, fee = self.get_tx_value(tx)
if v is not None: balance += v
c, u = self.get_balance()
if balance != c+u:
v_str = format_satoshis( c+u - balance, True, self.num_zeros)
result.append( ('', 1000, 0, c+u-balance, None, c+u-balance, None ) )
balance = c + u - balance
for tx_hash, tx in history:
conf, timestamp = self.verifier.get_confirmations(tx_hash) if self.verifier else (None, None)
is_mine, value, fee = self.get_tx_value(tx)
if value is not None:
balance += value
result.append( (tx_hash, conf, is_mine, value, fee, balance, timestamp) )
return result
示例4: _format_request
def _format_request(self, v, show_status=False):
from paymentrequest import PR_PAID, PR_UNPAID, PR_UNKNOWN, PR_EXPIRED
pr_str = {
PR_UNKNOWN: 'Unknown',
PR_UNPAID: 'Pending',
PR_PAID: 'Paid',
PR_EXPIRED: 'Expired',
}
addr = v.get('address')
amount = v.get('amount')
timestamp = v.get('time')
expiration = v.get('expiration')
out = {
'address': addr,
'amount': format_satoshis(amount),
'time': timestamp,
'reason': self.wallet.get_label(addr)[0],
'expiration': expiration,
}
if v.get('path'):
url = 'file://' + v.get('path')
r = self.config.get('url_rewrite')
if r:
a, b = r
url = url.replace(a, b)
URI = 'bitcoin:?r=' + url
out['URI'] = URI
if show_status:
status = self.wallet.get_request_status(addr, amount, timestamp, expiration)
out['status'] = pr_str[status]
return out
示例5: get_tx_history
def get_tx_history(self):
with self.lock:
history = self.transactions.values()
history.sort(key=lambda x: x.get("timestamp") if x.get("timestamp") else 1e12)
result = []
balance = 0
for tx in history:
is_mine, v, fee = self.get_tx_value(tx["tx_hash"])
if v is not None:
balance += v
c, u = self.get_balance()
if balance != c + u:
v_str = format_satoshis(c + u - balance, True, self.num_zeros)
result.append(("", 1000, 0, c + u - balance, None, c + u - balance, None))
balance = c + u - balance
for tx in history:
tx_hash = tx["tx_hash"]
timestamp = tx.get("timestamp")
conf = self.verifier.get_confirmations(tx_hash) if self.verifier else None
is_mine, value, fee = self.get_tx_value(tx_hash)
if value is not None:
balance += value
result.append((tx_hash, conf, is_mine, value, fee, balance, timestamp))
return result
示例6: update_history
def update_history(self, tx_history):
from util import format_satoshis
for item in tx_history[-10:]:
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
label = self.actuator.wallet.get_label(tx_hash)[0]
#amount = D(value) / 10**8
v_str = format_satoshis(value, True)
self.history_list.append(label, v_str)
示例7: _format_request
def _format_request(self, out):
pr_str = {
PR_UNKNOWN: 'Unknown',
PR_UNPAID: 'Pending',
PR_PAID: 'Paid',
PR_EXPIRED: 'Expired',
}
out['amount'] = format_satoshis(out.get('amount')) + ' BTC'
out['status'] = pr_str[out.get('status', PR_UNKNOWN)]
return out
示例8: settings_dialog
def settings_dialog(self):
out = self.run_dialog('Settings', [
{'label':'Default GUI', 'type':'list', 'choices':['classic','lite','gtk','text'], 'value':self.config.get('gui')},
{'label':'Default fee', 'type':'satoshis', 'value': format_satoshis(self.config.get('fee')).strip() }
], buttons = 1)
if out:
if out.get('Default GUI'):
self.config.set_key('gui', out['Default GUI'], True)
if out.get('Default fee'):
fee = int ( Decimal( out['Default fee']) *10000000 )
self.config.set_key('fee', fee, True)
示例9: print_history
def print_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
messages = []
for item in self.wallet.get_tx_history():
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
if conf:
try:
time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
except:
time_str = "------"
else:
time_str = 'pending'
label, is_default_label = self.wallet.get_label(tx_hash)
messages.append( format_str%( time_str, label, format_satoshis(value), format_satoshis(balance) ) )
self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
示例10: get_tx_details
def get_tx_details(self, tx_hash):
import datetime
if not tx_hash: return ''
tx = self.transactions.get(tx_hash)
is_mine, v, fee = self.get_tx_value(tx)
conf, timestamp = self.verifier.get_confirmations(tx_hash)
if timestamp:
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
else:
time_str = 'pending'
inputs = map(lambda x: x.get('address'), tx.inputs)
outputs = map(lambda x: x.get('address'), tx.d['outputs'])
tx_details = "Transaction Details" +"\n\n" \
+ "Transaction ID:\n" + tx_hash + "\n\n" \
+ "Status: %d confirmations\n"%conf
if is_mine:
if fee:
tx_details += "Amount sent: %s\n"% format_satoshis(v-fee, False) \
+ "Transaction fee: %s\n"% format_satoshis(fee, False)
else:
tx_details += "Amount sent: %s\n"% format_satoshis(v, False) \
+ "Transaction fee: unknown\n"
else:
tx_details += "Amount received: %s\n"% format_satoshis(v, False) \
tx_details += "Date: %s\n\n"%time_str \
+ "Inputs:\n-"+ '\n-'.join(inputs) + "\n\n" \
+ "Outputs:\n-"+ '\n-'.join(outputs)
r = self.receipts.get(tx_hash)
if r:
tx_details += "\n_______________________________________" \
+ '\n\nSigned URI: ' + r[2] \
+ "\n\nSigned by: " + r[0] \
+ '\n\nSignature: ' + r[1]
return tx_details
示例11: print_history
def print_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
messages = []
for tx in self.wallet.get_tx_history():
v = self.wallet.get_tx_value(tx['tx_hash'])
b += v
try:
time_str = str( datetime.datetime.fromtimestamp( tx['timestamp']))
except:
print tx['timestamp']
time_str = 'pending'
tx_hash = tx['tx_hash']
label, is_default_label = self.wallet.get_label(tx_hash)
#label += ' '*(40 - len(label) )
messages.append( format_str%( time_str, label, format_satoshis(v), format_satoshis(b) ) )
self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
示例12: history
def history(self):
balance = 0
out = []
for item in self.wallet.get_tx_history():
tx_hash, conf, is_mine, value, fee, balance, timestamp = item
try:
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
except Exception:
time_str = "----"
label, is_default_label = self.wallet.get_label(tx_hash)
out.append({'txid': tx_hash, 'date': "%16s" % time_str, 'label': label,
'value': format_satoshis(value), 'confirmations': conf})
return out
示例13: listaddresses
def listaddresses(self, show_all=False, show_labels=False, frozen=False, unused=False, funded=False, show_balance=False):
"""List wallet addresses. Returns your list of addresses."""
out = []
for addr in self.wallet.addresses(True):
if frozen and not self.wallet.is_frozen(addr):
continue
if not show_all and self.wallet.is_change(addr):
continue
if unused and self.wallet.is_used(addr):
continue
if funded and self.wallet.is_empty(addr):
continue
item = addr
if show_balance:
item += ", "+ format_satoshis(sum(self.wallet.get_addr_balance(addr)))
if show_labels:
item += ', ' + self.wallet.labels.get(addr,'')
out.append(item)
return out
示例14: history
def history(self):
balance = 0
out = []
for item in self.wallet.get_history():
tx_hash, conf, value, timestamp, balance = item
try:
time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(" ")[:-3]
except Exception:
time_str = "----"
label, is_default_label = self.wallet.get_label(tx_hash)
out.append(
{
"txid": tx_hash,
"date": "%16s" % time_str,
"label": label,
"value": format_satoshis(value),
"confirmations": conf,
}
)
return out
示例15: _format_request
def _format_request(self, out):
pr_str = {PR_UNKNOWN: "Unknown", PR_UNPAID: "Pending", PR_PAID: "Paid", PR_EXPIRED: "Expired"}
out["amount (GMC)"] = format_satoshis(out.get("amount"))
out["status"] = pr_str[out.get("status", PR_UNKNOWN)]
return out