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
def setup(self): # Generate a list of persons self.persons = [] for x in xrange(25): self.persons.append(Transaction()) self.schemes = [ DisposableEmail(), SharedProperty(), Probing(), ]
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)
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
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)
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')))