How to use the transaction.Transaction function in transaction

To help you get started, we’ve selected a few transaction examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github serverdensity / sd-agent / tests / core / test_transaction.py View on Github external
import simplejson as json
from tornado.web import Application

# project
from config import get_version
from sdagent import (
    APIMetricTransaction,
    APIServiceCheckTransaction,
    MAX_QUEUE_SIZE,
    MetricTransaction,
    THROTTLING_DELAY,
)
from transaction import Transaction, TransactionManager


class memTransaction(Transaction):
    def __init__(self, size, manager):
        Transaction.__init__(self)
        self._trManager = manager
        self._size = size
        self._flush_count = 0
        self._endpoint = 'https://example.com'
        self._api_key = 'a' * 32

        self.is_flushable = False

    def flush(self):
        self._flush_count = self._flush_count + 1
        if self.is_flushable:
            self._trManager.tr_success(self)
        else:
            self._trManager.tr_error(self)
github a-terada / lamp / readFile.py View on Github external
continue
			
			t_name = row_list[0]
			if t_name in gene_set:
				sys.stderr.write("Error: %s is contained two or more times in %s.\n" \
								 % (t_name, transaction_file))
				sys.exit()
			# check the number of columns
			if len( row_list ) != col_size:
				sys.stderr.write("Error in %s\n" % transaction_file)
				sys.stderr.write("    The header line contains %s columns, while line %s contains %s columns.\n" \
								 % (col_size, line_num, len( row_list )))
				sys.exit()
				
			gene_set.add(t_name)
			t = transaction.Transaction(t_name)
			gene2id[t_name] = len(transaction_list)
			for i in range(1, len(row_list)):
				flag = int(row_list[i])
				if flag == 1:
					t.addItem(i)
				elif flag == 0:
					continue
				else:
					sys.stderr.write("line %s in \'%s\' contains the value neither 0 or 1.\n" \
									 % (line_num, transaction_file) )
					sys.exit()
			transaction_list.append(t)
	except IOError, e:
		sys.stderr.write("Error: %s\n" % e)
		sys.exit()
	return transaction_list, gene2id, columnid2name
github sarchar / Bitmsg / msgwatch.py View on Github external
cb.watch_rc4(sys.argv[i].encode('utf8'))
        elif c == '-a':
            i += 1
            cb.watch_aes128(sys.argv[i].encode('utf8'))
        elif c == '-b':
            i += 1
            cb.watch_aes256(sys.argv[i].encode('utf8'))
        elif c == '-p':
            cb.watch_public()
        elif c == '-r':
            i += 1
            private_key = load_private_key(open(sys.argv[i], 'rb').read().decode('ascii'))
            cb.watch_rsa(private_key)
        elif c == '-t':
            i += 1
            cb.got_transaction(Transaction.unserialize(Bitcoin.hexstring_to_bytes(sys.argv[i], reverse=False))[0])
            done = True
        else:
            print('invalid command line argument: {}'.format(c))
            return
        i += 1

    if done:
        return

    # start network thread
    bitcoin_network = BitcoinNetwork(cb)
    bitcoin_network.start()

    try:
        while True:
            time.sleep(1)
github FeeFighters / samurai-client-python / samurai / processor.py View on Github external
def _transact(cls, payment_method_token, amount, processor_token,
                  transaction_type, endpoint, options):
        """
        Meant to be used internally and shouldn't be called from outside.

        Makes an `authorize` or `purchase` request.

        `authorize` and `purchase` have same flow, except for `transaction_type` and
        `endpoint`.
        """
        purchase_data = cls._construct_options(payment_method_token, transaction_type,
                                              amount, options)
        # Send payload and return transaction.
        req = Request(endpoint % processor_token, purchase_data, method='post')
        req.add_header("Content-Type", "application/xml")
        return Transaction(fetch_url(req))
github iotexproject / iotex-core / simulator / pbftconsensus.py View on Github external
def makeTransaction(self):
        """Returns a random transaction"""

        fee = max(random.gauss(self.player.MEAN_TX_FEE, self.player.STD_TX_FEE), 0)
        return transaction.Transaction(self.player.id, 0, fee)
github sarchar / Bitmsg / network.py View on Github external
def handle_tx(self, payload):
        tx, _ = Transaction.unserialize(payload)
        txhash = tx.hash()
        if txhash in self.transaction_requests_in_progress:
            self.bitcoin_network.got_transaction(tx)
            self.transaction_requests_in_progress.pop(txhash)
github notsag-dev / scroogecoin / transaction.py View on Github external
from hashutils import hash_sha256
from ecdsa import SigningKey

class Transaction():
    """ Generic coin transaction """
    pass

class Payment(Transaction):
    """ Transfer coins between wallets """
    def __init__(self, created_coins, consumed_coins, transaction_id=-1):
        self.created_coins = created_coins
        self.consumed_coins = consumed_coins
        self.id = transaction_id

    def verify_balance(self):
        """ Verify that the total amount of created coins is
            equal to the total amount of consumed coins
        """
        total_created = 0
        total_consumed = 0

        for consumed_coin in self.consumed_coins:
            total_consumed += consumed_coin.value
        for created_coin in self.created_coins:
github mauriciodotso / quantcoin / quantcoin / client.py View on Github external
if len(params) < 3:
            print("Missing parameters")
            return False
        if len(params[2:]) % 2 != 0:
            print("Parameters syntax wrong")
            return False

        transaction_base_args, params = params[:2], params[2:]
        my_address, commission = transaction_base_args
        to_wallets = [(None, float(commission))]
        while len(params) > 0:
            address, amount = params[:2]
            params = params[2:]
            to_wallets.append((address, float(amount)))

        transaction = Transaction(my_address, to_wallets)

        assert transaction.amount_spent() <= \
            self._quantcoin.amount_owned(my_address)

        using_wallet = None
        for wallet in self._quantcoin.wallets():
            if wallet['address'] == my_address:
                using_wallet = wallet
                break

        if using_wallet is None:
            print("You do not own a wallet with the address {}.".
                  format(my_address))
            return False

        transaction.sign(using_wallet['private_key'], using_wallet['public_key'])