55 lines
1.5 KiB
Python
Executable File
55 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import asyncio
|
|
import getpass
|
|
import sys
|
|
import silkaj.money, silkaj.tx, silkaj.auth
|
|
from duniterpy.key import SigningKey
|
|
|
|
# CONFIG #######################################
|
|
|
|
# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT]
|
|
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT]
|
|
# Here we use the secure BASIC_MERKLED_API (BMAS)
|
|
BMAS_ENDPOINT = "BMAS g1.duniter.org 443"
|
|
|
|
# Version of the transaction document
|
|
TRANSACTION_VERSION = 10
|
|
|
|
################################################
|
|
|
|
|
|
def sendTransaction(sender_keys, receiver_pubkey, amount, comment):
|
|
sender_amount = silkaj.money.get_amount_from_pubkey(sender_keys.pubkey)[0]
|
|
assert sender_amount >= amount, "not enough money"
|
|
silkaj.tx.generate_and_send_transaction(sender_keys.hex_seed().decode(), sender_keys.pubkey, amount, [receiver_pubkey], comment)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
"""
|
|
Main code
|
|
"""
|
|
# if bad number of arguments...
|
|
if len(sys.argv) != 6:
|
|
|
|
# display command usage
|
|
print("""
|
|
Usage:
|
|
./g1_send_transaction.py phone pin dest amount comment
|
|
""")
|
|
|
|
# exit with status code error
|
|
exit(1)
|
|
|
|
# capture arguments
|
|
_salt = sys.argv[1]
|
|
_password = sys.argv[2]
|
|
_dest = sys.argv[3]
|
|
_amount = sys.argv[4]
|
|
_comment = sys.argv[5]
|
|
|
|
# create keys from credentials
|
|
sender_keys = SigningKey(_salt, _password)
|
|
pubkey_from = sender_keys.pubkey
|
|
|
|
print("txstatus = sendTransaction(sender_keys, _dest, _amount, _comment)")
|