예제 #1
0
    def transactions(self,**args):
        self.common()
        begin_date=args.get('begin_date','')
        end_date=args.get('end_date','')
        what=args.get('what','')
        action=args.get('action','SALE')
        deleteid=args.get('deleteid','0')
        if int(deleteid) >0:
            Transaction.delete(deleteid)
        
        
        self._transactionstemplate.begin_date=begin_date
        self._transactionstemplate.end_date=end_date
        self._transactionstemplate.what=what
        self._transactionstemplate.action=action

        self._transactionstemplate.transactions=[]
        if begin_date and end_date:
            self._transactionstemplate.transactions=list(Transaction.select("""
        transactionLog.date >= '%s' AND
        transactionLog.date <= ADDDATE('%s',INTERVAL 1 DAY) AND
        transactionLog.info LIKE '%%%s%%' AND
        transactionLog.action LIKE '%%%s%%'
                """ % (escape_string(begin_date),escape_string(end_date),escape_string(what),escape_string(action))))
            
        
                                                                        
        return  self._transactionstemplate.respond()
예제 #2
0
    def transactions(self, **args):
        self.common()
        begin_date = args.get('begin_date', '')
        end_date = args.get('end_date', '')
        what = args.get('what', '')
        action = args.get('action', 'SALE')
        deleteid = args.get('deleteid', '0')
        if int(deleteid) > 0:
            Transaction.delete(deleteid)

        self._transactionstemplate.begin_date = begin_date
        self._transactionstemplate.end_date = end_date
        self._transactionstemplate.what = what
        self._transactionstemplate.action = action

        self._transactionstemplate.transactions = []
        if begin_date and end_date:
            self._transactionstemplate.transactions = list(
                Transaction.select("""
        transactionLog.date >= '%s' AND
        transactionLog.date <= ADDDATE('%s',INTERVAL 1 DAY) AND
        transactionLog.info LIKE '%%%s%%' AND
        transactionLog.action LIKE '%%%s%%'
                """ % (escape_string(begin_date), escape_string(end_date),
                       escape_string(what), escape_string(action))))

        return self._transactionstemplate.respond()
예제 #3
0
    def begin_transaction(self, instruction):
        """ Begin a Transaction """

        trans_ident = instruction.transaction_identifier

        if instruction.instruction_type == InstructionType.BEGIN:
            transaction = Transaction(trans_ident, TransactionType.READ_WRITE, \
                                      self.clock.time)
            self.logger.log("Starting RW transaction %s" % \
                            instruction.transaction_identifier)
        else:
            self.logger.log("Starting Read-Only transaction %s" % \
                            instruction.transaction_identifier)
            # Take a snapshot of the data at the time of this transaction
            self.readonly_snapshots[trans_ident] = {}
            transaction = Transaction(trans_ident, TransactionType.READ_ONLY,
                                      self.clock.time)

            for site_identifier, site in self.sites.iteritems():
                if site.status == SiteStatus.UP:
                    for variable_identifier, variable in site.data_manager.variables.iteritems(
                    ):
                        if variable.readable:
                            if variable_identifier not in self.readonly_snapshots[
                                    trans_ident]:
                                self.readonly_snapshots[trans_ident][
                                    variable_identifier] = variable.value

            self.logger.log("Snapshot taken for RO Transaction %s" %
                            trans_ident)

        self.transactions[trans_ident] = transaction
예제 #4
0
def generate_genesis_block(WalletA):

    coinbase = Wallet()

    genesis = Transaction("0", coinbase.publicKey, WalletA.publicKey, 100,
                          None)
    genesis.generate_signature(coinbase.privateKey)
    genesis.outputs.append(
        TransactionOutput(genesis.transaction_id, genesis.reciepient,
                          genesis.value))
    main_utxo[genesis.outputs[0].id] = genesis.outputs[0]

    print("Creating and Mining Genesis block... ")
    block = Block("Hi I am a block 0", "0")
    block.add_transaction(genesis, main_utxo)
    add_block(block)
예제 #5
0
 def test_add_item_to_inventory_that_we_dont_have_records_transaction(self):
     random_item = random.sample(list(Book.select()), 1)[0]
     fakeargs = dict(
         title=random_item.title.booktitle,
         authors=random_item.title.authors_as_string(),
         publisher=random_item.title.publisher,
         distributor=random_item.distributor,
         owner="woodenshoe",
         listprice=random_item.listprice,
         ourprice=random_item.ourprice,
         isbn=random_item.title.isbn,
         categories=random_item.title.categories_as_string(),
         location=random_item.location,
         quantity=1,
         known_title=True,
         types=random_item.title.type,
         kind=random_item.title.kind.id,
         kind_name=random_item.title.kind.kindName,
     )
     response = self._my_app.post("/admin/add_item_to_inventory", fakeargs)
     nowish = Now.now.strftime("%Y-%m-%d %H:%M:%S")
     confirm = Transaction.select("date > %s" % nowish).filter(
         "info RLIKE %s" % random_item.title.booktitle)
     self.assertTrue(
         confirm,
         "test_add_item_to_inventory does not add item to inventory")
예제 #6
0
 def test_add_item_to_inventory_that_we_dont_have_records_transaction(self):
     random_item=random.sample(list(Book.select()), 1)[0]
     fakeargs=dict(title=random_item.title.booktitle, authors=random_item.title.authors_as_string(), publisher=random_item.title.publisher, distributor=random_item.distributor, owner='woodenshoe', listprice=random_item.listprice, ourprice=random_item.ourprice, isbn=random_item.title.isbn, categories=random_item.title.categories_as_string(), location=random_item.location, quantity=1, known_title=True, types=random_item.title.type, kind_name=random_item.title.kind.kindName)
     response=self._my_app.post('/admin/add_item_to_inventory', fakeargs)
     nowish=mx.DateTime.now().strftime('%Y-%m-%d %H:%M:%S')
     confirm=Transaction.select('date > %s' % nowish).filter('info RLIKE %s' % random_item.title.booktitle)
     self.assertTrue(confirm, "test_add_item_to_inventory does not add item to inventory")
예제 #7
0
 def test_check_out_records_transaction(self):
     random_item=random.sample(list(Book.selectBy(status='STOCK')), 1)[0]
     item={"department":"Book","isInventoried":"True","isTaxable":"True","booktitle":random_item.title.booktitle,"isbn":random_item.title.isbn,"bookID":random_item.id,"titleID":random_item.titleID,"ourprice":random_item.ourprice}
     self._my_app.post('/register/add_item_to_cart', {'item':json.dumps(item)})
     cart_id=self._my_app.get('/register/get_cart').json[0]['uuid']        
     self._my_app.post('/register/check_out')
     transaction=Transaction.selectBy(cartID=cart_id)
     #print transaction
     self.assertEqual('SOLD', 'SOLD', '/register/checkout failed mark book \'SOLD\'')
예제 #8
0
 def setup(self):
     # Generate a list of persons
     self.persons = []
     for x in xrange(25):
         self.persons.append(Transaction())
     
     self.schemes = [
         DisposableEmail(),
         SharedProperty(),
         Probing(),
     ]
예제 #9
0
    def send_funds(self, reciepient, value_sent , main_utxo):
        if(self.get_balance(main_utxo) < value_sent):
            print("#Not Enough funds to send transaction. Transaction Discarded.")
            return None

        total = 0
        inputs = []
        for key , value in self.utxo.items():
            utxo = value
            total += utxo.value 
            inputs.append(TransactionInput(utxo.id , utxo))
            if(total > value_sent):
                break

        #Pass "0" as default argument
        new_transaction = Transaction("0", self.publicKey, reciepient, value_sent, inputs)
        new_transaction.generate_signature(self.privateKey)  

        for obj in inputs:
            self.utxo.pop(obj.transaction_output_id)

        return new_transaction 
예제 #10
0
 def test_check_out_records_transaction(self):
     random_item = random.sample(list(Book.selectBy(status="STOCK")), 1)[0]
     item = {
         "department": "Book",
         "isInventoried": "True",
         "isTaxable": "True",
         "booktitle": random_item.title.booktitle,
         "isbn": random_item.title.isbn,
         "bookID": random_item.id,
         "titleID": random_item.titleID,
         "ourprice": random_item.ourprice,
     }
     self._my_app.post("/register/add_item_to_cart",
                       {"item": json.dumps(item)})
     cart_id = self._my_app.get("/register/get_cart").json[0]["uuid"]
     self._my_app.post("/register/check_out")
     transaction = Transaction.selectBy(cartID=cart_id)
     # print transaction
     self.assertEqual("SOLD", "SOLD",
                      "/register/checkout failed mark book 'SOLD'")
예제 #11
0
    def query(self,args):
        #print>>sys.stderr, "in query", args
        what="%%%s%%" % args.get('what', '')
        action=args.get('action', '')
        begin_date=args.get('begin_date','1990-01-01')
        end_date=args.get('end_date','2030-01-01')
        
        #build table of clauses for WHERE 
        clauses=[]
        if what:
            clauses.append("transactionLog.info LIKE '%%%s%%'" % what )
        if action:
            clauses.append("transactionLog.action LIKE '%%%s%%'" % action )
        if begin_date:
            clauses.append("transactionLog.date >= '%s'" % begin_date )
        if end_date:
            clauses.append("transactionLog.date <= ADDDATE('%s',INTERVAL 1 DAY)" % end_date )

        results=Transaction.select( ' AND '.join(clauses))
        #print>>sys.stderr, 'Results:', results
        return results
예제 #12
0
    def query(self, args):
        # print>>sys.stderr, "in query", args
        what = "%%%s%%" % args.get("what", "")
        action = args.get("action", "")
        begin_date = args.get("begin_date", "1990-01-01")
        end_date = args.get("end_date", "2030-01-01")

        # build table of clauses for WHERE
        clauses = []
        if what:
            clauses.append("transactionLog.info LIKE '%%%s%%'" % what)
        if action:
            clauses.append("transactionLog.action LIKE '%%%s%%'" % action)
        if begin_date:
            clauses.append("transactionLog.date >= '%s'" % begin_date)
        if end_date:
            clauses.append(
                "transactionLog.date <= ADDDATE('%s',INTERVAL 1 DAY)" %
                end_date)

        results = Transaction.select(" AND ".join(clauses))
        # print>>sys.stderr, 'Results:', results
        return results
예제 #13
0
파일: main.py 프로젝트: enriquenc/DCCD
def new_transaction():
    tx = None
    try:
        serialized_tx = request.get_json()['serialized']
        tx = Deserializer.deserialize(serialized_tx)
    except:
        try:
            dictionary_tx = request.get_json()['dictionary']
            tx = Transaction.from_dict(dictionary_tx)
        except Exception as m:
            return get_return_value(ReturnCode.INVALID_ARGUMENT.value)

    pool = FileSystem.getTransactionsFromMempool()
    if (Serializer.serialize(tx) in pool):
        return get_return_value(ReturnCode.CARGO_INFORMATION_ALREADY_EXISTS)

    code = tx_validator.validate_transaction(tx)
    if code.value != ReturnCode.OK.value:
        print("ERROR. Transaction wasn't added. " +
              color_output.prRed(code.name))
        return get_return_value(code.value)
    FileSystem.addTransactionToMempool(Serializer.serialize(tx))
    return get_return_value(ReturnCode.OK.value)
예제 #14
0
import sys
sys.path.append("../DCCD/")
import requests
import json
from objects import serializer
from crypto.wif import wifToPriv
from objects.transaction import Transaction

url = 'http://127.0.0.1:5100/transactions/new'

t = Transaction("134589037", '1588410854.301351', "25", "cargo_info")

private_key_wif = "5HpXfPm94cFqqZnQwZ5QnLrb4adRU9CrJXtxYWETxcnpWAPir61"
private_key = wifToPriv(private_key_wif)

t.sign(private_key)

obj = {'dictionary': t.to_dictionary()}

x = requests.post(url, json=obj)
print(json.loads(x.content.decode('utf-8')))
예제 #15
0
 def checktrans(self,what):
     transactions=Transaction.select("""info LIKE '%%%s%%'""" % (escape_string(what)),orderBy='date')
     return dict(transactions=transactions)
예제 #16
0
 def checktrans(self, what):
     transactions = Transaction.select("""info LIKE '%%%s%%'""" %
                                       (escape_string(what)),
                                       orderBy='date')
     return dict(transactions=transactions)
예제 #17
0
 def do_send(self, arg):
     trn = Transaction(arg, str(time.time()), "25")
     trn.sign(self.private_key)
     self.last_serialized = Serializer.serialize(trn)
     print(self.last_serialized)