예제 #1
0
def main(inflation):
    # TODO: Let user select the connection type
    # The stellar/quickstart Docker image uses PostgreSQL
    conn = sqlite3.connect(db_address)

    # Get the next sequence number for the transactions
    sequence = horizon.account(pool_address).get('sequence')
    inflation = XLM_Decimal(inflation)
    transactions = []
    total_payments_cost = 0
    num_payments = 0
    total_fee_cost = 0

    # Create one transaction for each batch
    for batch in accounts_payouts(conn, pool_address, inflation):
        op_count = 0
        ops = {'sequence': sequence, 'operations': []}
        for aid, amount in batch:
            # Check if the payment destination (aid) is valid
            try:
                acc = horizon.get(aid)
            except AccountNotExistError:
                continue
            if not acc:
                continue
            # Include payment operation on ops{}
            ops['operations'].append(aid, amount)
            op_count += 1

        # Build transaction
        tx = Transaction(source=pool_address, opts=ops)
        tx.fee = op_count * BASE_FEE
        envelope = Te(tx=tx, opts={"network_id": network})
        # Append the transaction plain-text (JSON) on the list
        transactions.append(envelope.xdr().decode("utf-8"))

        # Calculate stats
        total_fee_cost += XLM_Decimal(tx.fee) / XLM_STROOP
        total_payments_cost += sum(
            [XLM_Decimal(payment.amount) for payment in tx.operations])
        num_payments += len(tx.operations)

        # Prepare the next sequence number for the transactions
        sequence = int(sequence) + 1

    print(("Stats: \n"
           "Inflation received: %s\n"
           "A total of %s XLM paid over %s inflation payments "
           "using %s XLM in fees. \n"
           "Number of people that donated votes: %s\n") % (
               inflation,
               total_payments_cost,
               num_payments,
               total_fee_cost,
               len(donors),
           ))

    with open("transactions.json", 'w') as outf:
        json.dump(transactions, outf)
    print("Done. Output to transactions.json")
예제 #2
0
def main(inflation):
	inflation = XLM_Decimal(inflation)

	conn = sqlite3.connect(db_address)
	transactions = []

	sequence = horizon.account(pool_address).get('sequence')
	total_payments_cost = 0
	num_payments = 0
	total_fee_cost = 0

	for batch in accounts_payout(conn, pool_address, inflation):
		tx = Transaction(
			source = pool_address,
			opts = {
				'sequence': sequence,
				'operations': [make_payment_op(aid, amount) for aid, amount in batch]
			}
		)
		tx.fee = len(tx.operations) * 100
		envelope = Te(tx = tx, opts = {"network_id": network})
		transactions.append(envelope.xdr().decode("utf-8"))

		total_fee_cost += XLM_Decimal(tx.fee) / XLM_STROOP
		total_payments_cost += sum([XLM_Decimal(payment.amount) for payment in tx.operations])
		num_payments += len(tx.operations)

		sequence = int(sequence) + 1

	print(
		"Stats: \n\
		Inflation received: " + str(inflation) + "\n\
		A total of " + str(total_payments_cost) +\
		" XLM paid over " + str(num_payments) +\
		" inflation payments using " + str(total_fee_cost) + " XLM in fees. \n\
		People donated " + str(sum([n for n in donations.values()])) +\
		" XLM to " + str(len(donations.keys())) +\
		" different addresses.\n"
	)

	with open("transactions.json", 'w') as outf:
		json.dump(transactions, outf)
	print("Done. Output to transactions.json")
예제 #3
0
def main(inflation):
    # TODO: Let user select the connection type
    # The stellar/quickstart Docker image uses PostgreSQL

    logger.debug("Connecting to database...")
    conn = sqlite3.connect(db_address)
    logger.debug("Connected!")

    logger.debug("Getting the next transaction sequence number...")
    sequence = horizon.account(pool_address).get('sequence')
    logger.debug("Done! - Transaction Sequence: %(sequence)s")

    inflation = XLM_Decimal(inflation)
    transactions = []
    total_payments_cost = 0
    num_payments = 0
    total_fee_cost = 0

    logger.debug("Processing account batches...")
    # Create one transaction for each batch
    for batch in accounts_payouts(conn, pool_address, inflation):
        logger.debug("\tProcessing %(batch.aid)s with %(batch.amount)s")

        op_count = 0
        ops = {'sequence': sequence, 'operations': []}
        for aid, amount in batch:
            # Include payment operation on ops{}
            paymentOp = make_payment_op(aid, amount)

            logger.debug("\t\t\Created Payment %(paymentOp)s")
            ops['operations'].append(paymentOp)
            op_count += 1

        logger.debug("\t\tBuilding Transaction...")
        tx = Transaction(source=pool_address, opts=ops)
        tx.fee = op_count * BASE_FEE
        envelope = Te(tx=tx, opts={"network_id": network})
        # Append the transaction plain-text (JSON) on the list
        transaction = envelope.xdr().decode("utf-8")
        logger.debug("\t\tTransaction Created")
        logger.debug("\t\t%(transaction)s")

        transactions.append(transaction)

        # Calculate stats
        total_fee_cost += XLM_Decimal(tx.fee) / XLM_STROOP
        total_payments_cost += sum(
            [XLM_Decimal(payment.amount) for payment in tx.operations])
        num_payments += len(tx.operations)

        # Prepare the next sequence number for the transactions
        sequence = int(sequence) + 1

    logger.info(("Stats: \n"
                 "\tInflation received: %s\n"
                 "\tA total of %s XLM paid over %s inflation payments "
                 "using %s XLM in fees. \n"
                 "\tNumber of unique donation addresses: %s\n") % (
                     inflation,
                     total_payments_cost,
                     num_payments,
                     total_fee_cost,
                     len(donation_payouts),
                 ))

    with open("transactions.json", 'w') as outf:
        json.dump(transactions, outf)
    logger.info("Output to transactions.json")