Skip to content
Snippets Groups Projects
Commit ec143800 authored by Moul's avatar Moul
Browse files

[enh] #390, #396: Implement generic send_document()

Use it in cert, membership, and tx cmds
With urllib, the 200 error is no longer returned but an exception
TODO: write test_send_document()
parent fe9427b9
No related branches found
No related tags found
No related merge requests found
......@@ -24,12 +24,12 @@ from tabulate import tabulate
from silkaj import tui, wot
from silkaj import wot_tools as wt
from silkaj.auth import auth_method
from silkaj.tools import message_exit
from silkaj.network_tools import ClientInstance
from silkaj.blockchain_tools import BlockchainParams, HeadBlock
from silkaj.constants import ALL, DATE, SUCCESS_EXIT_STATUS
from silkaj.crypto_tools import is_pubkey_and_check
from silkaj.license import license_approval
from silkaj.network_tools import ClientInstance, send_document
from silkaj.tools import message_exit
@click.command("cert", help="Send certification")
......@@ -78,12 +78,7 @@ def send_certification(ctx, uid_pubkey_to_certify):
certification.sign([key])
# Send certification document
response = client(bma.wot.certify, certification.signed_raw())
if response.status == 200:
print("Certification successfully sent.")
else:
print("Error while publishing certification: {}".format(response.text()))
send_document(bma.wot.certify, certification)
def pre_checks(client, issuer_pubkey, pubkey_to_certify):
......
......@@ -26,7 +26,7 @@ from silkaj import auth, tui, wot
from silkaj.blockchain_tools import BlockchainParams, HeadBlock
from silkaj.constants import DATE, SUCCESS_EXIT_STATUS
from silkaj.license import license_approval
from silkaj.network_tools import ClientInstance
from silkaj.network_tools import ClientInstance, send_document
@click.command(
......@@ -81,13 +81,7 @@ def send_membership(ctx):
tui.send_doc_confirmation("membership document for this identity")
# Send the membership signed raw document to the node
response = client(bma.blockchain.membership, membership.signed_raw())
if response.status == 200:
print("Membership successfully sent")
else:
print("Error while publishing membership: {}".format(response.text()))
logging.debug(response.text())
send_document(bma.blockchain.membership, membership)
def display_confirmation_table(identity_uid, pubkey, identity_timestamp):
......
......@@ -13,6 +13,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import urllib
from duniterpy.api.client import Client
from silkaj.constants import G1_DEFAULT_ENDPOINT, G1_TEST_DEFAULT_ENDPOINT
......@@ -63,3 +65,13 @@ class EndPoint:
class ClientInstance:
def __init__(self):
self.client = Client(EndPoint().BMA_ENDPOINT)
def send_document(bma_path, document):
client = ClientInstance().client
doc_name = document.__class__.__name__
try:
client(bma_path, document.signed_raw())
print(f"{doc_name} successfully sent")
except urllib.error.HTTPError as e:
print(f"Error while publishing {doc_name.lower()}: {e}")
......@@ -403,14 +403,7 @@ def generate_and_send_transaction(
OutputbackChange,
)
transaction.sign([key])
response = client(process, transaction.signed_raw())
if response.status == 200:
print("Transaction successfully sent.")
else:
tools.message_exit(
"Error while publishing transaction: {}".format(response.text())
)
nt.send_document(process, transaction)
def display_sent_tx(outputAddress, amount):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment