Commit d160f626 authored by Moul's avatar Moul
Browse files

[enh] #7: Use async for HeadBlock

parent a4fd2190
......@@ -35,7 +35,8 @@ async def send_certification(cli_args):
main_id_to_certify = id_to_certify["uids"][0]
# Display license and ask for confirmation
license_approval(HeadBlock().head_block["currency"])
head = await HeadBlock().head_block
license_approval(head["currency"])
# Authentication
seed = auth_method(cli_args)
......@@ -75,7 +76,7 @@ async def send_certification(cli_args):
):
await client.close()
return
cert_doc = generate_certification_document(
cert_doc = await generate_certification_document(
issuer_pubkey, id_to_certify, main_id_to_certify
)
cert_doc += sign_document_from_seed(cert_doc, seed) + "\n"
......@@ -103,8 +104,10 @@ def certification_confirmation(
return True
def generate_certification_document(issuer_pubkey, id_to_certify, main_id_to_certify):
head_block = HeadBlock().head_block
async def generate_certification_document(
issuer_pubkey, id_to_certify, main_id_to_certify
):
head_block = await HeadBlock().head_block
return (
"Version: 10\n\
Type: Certification\n\
......
......@@ -37,7 +37,7 @@ from silkaj.constants import NO_MATCHING_ID
async def currency_info():
head_block = HeadBlock().head_block
head_block = await HeadBlock().head_block
ep = EndPoint().ep
print(
"Connected to node:",
......@@ -218,7 +218,7 @@ def network_info(discover):
async def list_blocks(nbr, last):
head_block = HeadBlock().head_block
head_block = await HeadBlock().head_block
current_nbr = head_block["number"]
if nbr == 0:
nbr = head_block["issuersFrame"]
......@@ -303,7 +303,7 @@ async def list_blocks(nbr, last):
async def argos_info():
pretty_names = {"g1": "Ğ1", "gtest": "Ğtest"}
head_block = HeadBlock().head_block
head_block = await HeadBlock().head_block
pretty = head_block["currency"]
if head_block["currency"] in pretty_names:
pretty = pretty_names[head_block["currency"]]
......
......@@ -53,7 +53,7 @@ async def show_amount_from_pubkey(pubkey, value):
currency_symbol = await CurrencySymbol().symbol
ud_value = await UDValue().ud_value
average, monetary_mass = get_average()
average, monetary_mass = await get_average()
if totalAmountInput - amount != 0:
print("Blockchain:")
print("-----------")
......@@ -95,8 +95,8 @@ async def show_amount_from_pubkey(pubkey, value):
)
def get_average():
head = HeadBlock().head_block
async def get_average():
head = await HeadBlock().head_block
monetary_mass = head["monetaryMass"]
members_count = head["membersCount"]
average = monetary_mass / members_count
......@@ -141,7 +141,8 @@ async def get_sources(pubkey):
history = history["history"]
pendings = history["sending"] + history["receiving"] + history["pending"]
last_block_number = HeadBlock().head_block["number"]
head_block = await HeadBlock().head_block
last_block_number = head_block["number"]
# add pending output
for pending in pendings:
......
......@@ -24,6 +24,7 @@ import logging
from sys import exit, stderr
from commandlines import Command
from duniterpy.api.client import Client
from duniterpy.api.bma import blockchain
from silkaj.constants import (
G1_DEFAULT_ENDPOINT,
......@@ -242,4 +243,8 @@ class HeadBlock(object):
return HeadBlock.__instance
def __init__(self):
self.head_block = get_request("blockchain/current")
self.head_block = self.get_head()
async def get_head(self):
client = ClientInstance().client
return await client(blockchain.current)
......@@ -199,7 +199,7 @@ async def generate_and_send_transaction(
print(" - From: " + issuers)
print(" - To: " + issuers)
print(" - Amount: " + str(totalAmountInput / 100))
transaction = generate_transaction_document(
transaction = await generate_transaction_document(
issuers,
totalAmountInput,
listinput_and_amount,
......@@ -225,7 +225,7 @@ async def generate_and_send_transaction(
" - Amount: "
+ str(AmountTransfered / 100 * len(outputAddresses))
)
transaction = generate_transaction_document(
transaction = await generate_transaction_document(
issuers,
AmountTransfered,
listinput_and_amount,
......@@ -243,7 +243,7 @@ async def generate_and_send_transaction(
break
def generate_transaction_document(
async def generate_transaction_document(
issuers,
AmountTransfered,
listinput_and_amount,
......@@ -257,7 +257,7 @@ def generate_transaction_document(
listinput = listinput_and_amount[0]
totalAmountInput = listinput_and_amount[1]
head_block = HeadBlock().head_block
head_block = await HeadBlock().head_block
currency_name = head_block["currency"]
blockstamp_current = str(head_block["number"]) + "-" + str(head_block["hash"])
curentUnitBase = head_block["unitbase"]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment