def get_client(verbose: bool = False): # Helper to get a working and conencted BismuthClient no matter the test context file_first = "../datadir/wallet.der" file_second = "../wallet.der" wallet_file = file_first if isfile(file_first) else file_second client = BismuthClient(servers_list={'127.0.0.1:3030'}, wallet_file=wallet_file, verbose=verbose) # Will raise and fail test if node is not connectible assert client is not None return client
def __init__(self, user_id: str): global BISMUTH_CLIENT user_id = str(user_id) self._user_id = user_id self._base_path = 'users/{}/{}/{}'.format(user_id[0], user_id[1], user_id) # print("self._base_path", self._base_path) base_dir = 'users/{}/{}'.format(user_id[0], user_id[1]) if not path.isdir(base_dir): makedirs(base_dir, exist_ok=True) self._wallet = None self._info = None if not BISMUTH_CLIENT: # Here we can force to use a local, dedicated wallet server # See servers_list BISMUTH_CLIENT = BismuthClient(verbose=True)
# time consuming on Termux to start the wallet, select the address, # activate the crystal, fetch the data, and submit. This script # does these steps for you. The script also demonstrates how # to use a multi-wallet together with bismuthclient. Note: the script # assumes that the wallet is not encrypted. # # This script could also form the basis for an IOT (internet-of- # things) script for Bismuth. The user input could for example # be replaced and the script placed in a regular cron job. import json from bismuthclient.bismuthclient import BismuthClient from phoneapihandler import PhoneAPIHandler if __name__ == "__main__": client = BismuthClient(servers_list={'wallet2.bismuth.online:5658'}) client.load_multi_wallet("../../../../bismuth-private/wallet.json") n = len(client._wallet._addresses) print("Available addresses in multi-wallet:") for i in range(n): print("{}. {}".format(i + 1, client._wallet._addresses[i]['address'])) user_input = input("Select an address (1-{}): ".format(n)) try: val = int(user_input) except ValueError: print("Input error") raise if val > 0 and val <= n: address = client._wallet._addresses[val - 1]['address'] client.set_address(address)
def _get_client(self, username): wallet_path = self.get_wallet_path(username) client = BismuthClient(wallet_file=wallet_path) return client
return datetime.utcfromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S') async def safe_send_message(recipient, message): try: if not recipient.dm_channel: await recipient.create_dm() await recipient.dm_channel.send(message) except Exception as e: print(e) HTTP_SESSION = None BISMUTH_CLIENT = BismuthClient(verbose=True) async def async_get(url, is_json=False): """Async gets an url content. If is_json, decodes the content """ global HTTP_SESSION # TODO: retry on error? if not HTTP_SESSION: HTTP_SESSION = aiohttp.ClientSession() # async with aiohttp.ClientSession() as session: async with HTTP_SESSION.get(url) as resp: if is_json: return json.loads(await resp.text())
def get_private_dir(): return BismuthClient.user_subdir(BISMUTH_PRIVATE_DIR)
#!/usr/bin/python3 from datetime import datetime from bismuthclient.bismuthclient import BismuthClient client = BismuthClient(wallet_file='wallet.der') default_wallet_address = [] def to_localtime(stamp_time): #print(stamp_time) t = datetime.utcfromtimestamp(stamp_time) return(t.strftime('%Y-%m-%d %H:%M')) def tx_history(addr): transactions = client.command("addlistlim", [addr, 5]) for tx in transactions: #print(tx) time = to_localtime(tx[1]) print("block:{}, utc:{}, from:{}, to:{}, amount:{}".format(tx[0],time,tx[2],tx[3],tx[4])) def main(): wallet_address = input("Wallet Address: ") if not wallet_address: wallet_address = default_wallet_address if client.address: wallet_address = wallet_address + [ client.address ] else: wallet_address = [ x.strip() for x in str(wallet_address).split(',') ] if len(wallet_address) < 2 : for addr in wallet_address: wallet_address = [ x.strip() for x in str(addr).split(' ') ] if client.address: wallet_address = wallet_address + [ client.address ]
if __name__ == '__main__': define("ip", default='127.0.0.1', help="Server IP to connect to, default 127.0.0.1") define("port", default=8150, help="Server port to connect to, default 8150") define("address", default='0634b5046b1e2b6a69006280fbe91951d5bb5604c6f469baa2bcd840', help="Address to test") define("verbose", default=False, help="verbose") options.parse_command_line() client = BismuthClient( wallet_file='wallet.der', servers_list=["{}:{}".format(options.ip, options.port)]) balance = client.command('balanceget', [options.address]) print(balance) balance = client.command( 'balanceget', ['86cbc69e9f8522c58f5c97fd13e7a5634ea6012207984c54bf83fc7d']) print(balance) # use with address 86cbc69e9f8522c58f5c97fd13e7a5634ea6012207984c54bf83fc7d """ listop = client.command('addlistopfromjson', [options.address, 'dragg:sell']) print(listop)
""" Demo Script, send a Bismuth transaction """ from bismuthclient.bismuthclient import BismuthClient if __name__ == "__main__": client = BismuthClient(wallet_file='wallet.der') if not client.address: client.new_wallet() client.load_wallet() """ BismuthClient does the heavy lifting of finding and connecting to a working wallet server. """ print(f"My address is {client.address}") # txid = client.send(recipient=client.address, amount=0) # sends 0 to self print(f"Txid is {txid}") # client.send(recipient="9ba0f8ca03439a8b4222b256a5f56f4f563f6d83755f525992fa5daf", operation='dragg:transfer', data='draggon_adn')
# and you are not at home, or at a public supercharger. # This script does the steps for you which previously required the # TornadoWallet. The script also demonstrates how to use a # multi-wallet together with bismuthclient in a script. # Note: the script assumes that the wallet is not encrypted. # # This script could also form the basis for an IOT (internet-of- # things) script for Bismuth. The user input could for example # be replaced and the script placed in a regular cron job. import json from bismuthclient.bismuthclient import BismuthClient from teslaapihandler import TeslaAPIHandler if __name__ == "__main__": client = BismuthClient() #Empty server list to use api client.load_multi_wallet("../../../../bismuth-private/wallet.json") n = len(client._wallet._addresses) print("Available addresses in multi-wallet:") for i in range(n): print("{}. {}".format(i+1,client._wallet._addresses[i]['address'])) user_input = input("Select an address (1-{}): ".format(n)) try: val = int(user_input) except ValueError: print("Input error") raise if val>0 and val<=n: address = client._wallet._addresses[val-1]['address'] client.set_address(address)
if __name__ == '__main__': define("ip", default='127.0.0.1', help="Server IP to connect to, default 127.0.0.1") define("port", default=8150, help="Server port to connect to, default 8150") define("address", default='0634b5046b1e2b6a69006280fbe91951d5bb5604c6f469baa2bcd840', help="Address to test") define("verbose", default=False, help="verbose") options.parse_command_line() client = BismuthClient( wallet_file='wallet.der', servers_list=["{}:{}".format(options.ip, options.port)]) """ balance = client.command('balanceget', [options.address]) print(balance) """ """ balance = client.command('balanceget', ['86cbc69e9f8522c58f5c97fd13e7a5634ea6012207984c54bf83fc7d']) print(balance) """ # use with address 86cbc69e9f8522c58f5c97fd13e7a5634ea6012207984c54bf83fc7d """ listop = client.command('addlistopfromjson', [options.address, 'dragg:sell']) print(listop)