def test_network_and_horizon(self, setup, test_data): builder = Builder(secret=test_data.cold_secret, sequence=100, network='MOE') assert builder.network == 'MOE' assert builder.horizon.horizon_uri == horizon_testnet().horizon_uri builder = Builder(secret=test_data.cold_secret, sequence=100, network='testnet') assert builder.network == 'TESTNET' assert builder.horizon.horizon_uri == horizon_testnet().horizon_uri builder = Builder(secret=test_data.cold_secret, sequence=100, network='public') assert builder.network == 'PUBLIC' assert builder.horizon.horizon_uri == horizon_livenet().horizon_uri builder = Builder(secret=test_data.cold_secret, sequence=100, network='public', horizon_uri=setup.horizon_endpoint_uri) assert builder.network == 'PUBLIC' assert builder.horizon.horizon_uri == Horizon( horizon_uri=setup.horizon_endpoint_uri).horizon_uri
def create_account(user): # type: (User) -> None # create keypair keypair = Keypair.random() public_key = keypair.address().decode() seed = keypair.seed().decode() # store account StellarAccount.objects.create(seed=seed, address=public_key, user=user, balance=0.0) horizon = horizon_testnet() if settings.DEMO_MODE else horizon_livenet() # fund account if settings.DEMO_MODE: for _ in range(5): # noinspection PyBroadException try: funding_keypair = Keypair.from_seed( settings.FUNDING_ACCOUNT_SEED) # create operation create_account_operation = CreateAccount({ 'destination': public_key, 'starting_balance': '1' }) # create transaction sequence = horizon.account( funding_keypair.address().decode()).get('sequence') tx = Transaction(source=funding_keypair.address().decode(), opts={ 'sequence': sequence, 'memo': TextMemo('Creating new Zendi account.'), 'operations': [create_account_operation] }) # create and sign envelope envelope = TransactionEnvelope(tx=tx, opts={"network_id": "TESTNET"}) envelope.sign(funding_keypair) # Submit the transaction to Horizon te_xdr = envelope.xdr() horizon.submit(te_xdr) break except Exception as ex: logger.error('Error while funding account', ex) time.sleep(1) logger.info('Created Stellar Lumen account {} for {}'.format( public_key, user))
def main( desired_tail, funding_account_secret_key, network_id, signers_file): horizon = (horizon_livenet() if network == 'PUBLIC' else horizon_testnet()) pool_kp = generate_pool_keypair(desired_tail) logger.info("Pool keypair: %s | %s" % ( pool_kp.address().decode(), pool_kp.seed().decode())) if create_pool_account( horizon, network_id, funding_account_secret_key, pool_kp): signers = get_signers(signers_file) set_account_signers(horizon, pool_kp, signers, SIGNING_THRESHOLD)
def __init__(self): #Usefull vars self.srcPath = os.path.dirname(os.path.realpath(__file__)) self.imageFolder = self.srcPath + "/img/" #Initializing the window self.window = tk.Tk() self.window.title("Wallet") iconImg = tk.PhotoImage(file=self.imageFolder + "stellarIcon.gif") self.window.tk.call('wm', 'iconphoto', self.window._w, iconImg) #Infos about the user self.connected = False self.kp = "" self.key = "" self.address = "" self.infos = {} self.nbOfSubentrys = 0 #Stellar self.horizon = horizon_livenet()
def main_loop(): LARGE_PAYMENT_MIN_AMOUNT = 10000 global previous_data previous_data = defaultdict(lambda: 0) global previous_payment_detail previous_payment_detail = defaultdict(lambda: defaultdict(lambda: 0)) global previous_large_native_payment_detail previous_large_native_payment_detail = defaultdict( lambda: defaultdict(lambda: 0)) parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('--port', nargs='?', const=9101, help='The TCP port to listen on. Defaults to 9101.', default=9101) args = parser.parse_args() log.info(args.port) current_data = defaultdict(lambda: 0) current_payment_detail = defaultdict(lambda: defaultdict(lambda: 0)) current_large_native_payment_detail = defaultdict( lambda: defaultdict(lambda: 0)) REGISTRY.register(StatsCollector()) start_http_server(int(args.port)) h = horizon_livenet() p = { 'limit': 200, 'cursor': 'now', } current_minute = None r = h.operations(sse=True, params=p) try: for resp in r: try: m = json.loads(str(resp)) except json.decoder.JSONDecodeError: pass if m == 'hello': continue cm = m['created_at'][:-4] if cm != current_minute: log.info('minute change %s => %s' % (current_minute, cm)) current_minute = cm previous_data = copy.deepcopy(current_data) previous_payment_detail = copy.deepcopy(current_payment_detail) previous_large_native_payment_detail = copy.deepcopy( current_large_native_payment_detail) current_data = defaultdict(lambda: 0) current_payment_detail = defaultdict( lambda: defaultdict(lambda: 0)) current_large_native_payment_detail = defaultdict( lambda: defaultdict(lambda: 0)) op_type = m['type'] current_data['nb_operation'] += 1 current_data['nb_operation_%s' % op_type] += 1 if op_type == 'payment': current_data['total_amount_payment'] += float(m['amount']) if m['asset_type'] == 'native': asset = 'native' v = float(m['amount']) if v >= LARGE_PAYMENT_MIN_AMOUNT: from_addr = m['from'] to_addr = m['to'] current_large_native_payment_detail[from_addr][ to_addr] += v else: asset = m['asset_code'] current_payment_detail[asset]['nb'] += 1 current_payment_detail[asset]['sum'] += float(m['amount']) except requests.exceptions.HTTPError as e: log.info(str(e)) lolog.infoo('http exception, restarting') return
Created on Wed Jul 5 22:49:48 2017 @author: fanbingxia """ #%% import requests from stellar_base.address import Address from stellar_base.operation import ChangeTrust from stellar_base.asset import Asset from stellar_base.horizon import horizon_livenet from stellar_base.transaction_envelope import TransactionEnvelope as Te from stellar_base.transaction import Transaction from stellar_base.keypair import Keypair from stellar_base.operation import Payment horizon = horizon_livenet() #%% Create an account (Do not execute again to avoid rewriting of kp3) #CMIssuer = Keypair.random() #CMIssuer_Add = CMIssuer.address().decode() #CMIssuer_Seed = CMIssuer.seed().decode() #CMDistributor = Keypair.random() #CMDistributor_Add = CMDistributor.address().decode() #CMDistributor_Seed = CMDistributor.seed().decode() #%% Pass or not def passed_or_not(response): if '_links' in response: print('Transaction passed') return True
def __init__(self, base_seed='', horizon_endpoint_uri='', network='PUBLIC', channel_seeds=[]): """Create a new instance of the KIN SDK for Stellar. If seed is not provided, the SDK can still be used in "anonymous" mode with only the following functions available: - get_address_lumen_balance - get_address_kin_balance - check_kin_trusted - check_account_exists - get_account_data - get_transaction_data - monitor_address_transactions :param str seed: a seed to initialize the sdk wallet account with. If not provided, the wallet will not be initialized and methods needing the wallet will raise exception. :param str horizon_endpoint_uri: a Horizon endpoint. If not provided, a default endpoint will be used, either a testnet or pubnet, depending on the `network` parameter. :param str network: either PUBLIC or TESTNET, will set the Horizon endpoint in the absence of `horizon_endpoint_uri`. :param list channel_seeds: a list of channels to sign transactions with. More channels means less blocking on transactions and better response time. :return: An instance of the SDK. :rtype: :class:`~kin.SDK` :raises: :class:`~kin.SdkConfigurationError` if some of the configuration parameters are invalid. """ self.network = network if not self.network: self.network = 'PUBLIC' if horizon_endpoint_uri: self.horizon = Horizon(horizon_endpoint_uri) else: if self.network == 'TESTNET': self.horizon = horizon_testnet() else: self.horizon = horizon_livenet() # check Horizon connection try: self.horizon.query('') except Exception as e: raise SdkConfigurationError('cannot connect to horizon') # init sdk account base_keypair if a base_seed is supplied self.base_keypair = None if base_seed: try: validate_seed(base_seed) except ValueError: raise SdkConfigurationError('invalid base seed: {}'.format(base_seed)) self.base_keypair = Keypair.from_seed(base_seed) # check channel seeds if channel_seeds: for channel_seed in channel_seeds: try: validate_seed(channel_seed) except ValueError: raise SdkConfigurationError('invalid channel seed: {}'.format(channel_seed)) else: channel_seeds = [base_seed] # init channel manager self.channel_manager = ChannelManager(base_seed, channel_seeds, self.network, self.horizon.horizon)