예제 #1
0
    def apply_tx(self, txhash, tx=None):
        """Given a transaction <composed_tx_spec>, delete any
        utxos that it spends and add any utxos that are new
        """

        all_addresses = [a.get_address() for a in
                         self.model.get_address_manager().get_all_addresses()]

        bs = self.model.ccc.blockchain_state
        if self.full_spv:
            block_hash, _ = bs.get_tx_blockhash(txhash)
        else:
            block_hash = None
        if not tx:
            raw_tx = bs.get_raw(txhash).decode('hex')
            tx = RawTxSpec.from_tx_data(self.model, raw_tx)

        # record spends
        for txin in tx.composed_tx_spec.txins:
            prev_txhash, prev_outindex = txin.get_outpoint()
            coin_id = self.store.find_coin(prev_txhash, prev_outindex)
            if coin_id:
                self.store.add_spend(coin_id, txhash)
                
        # put the new utxo into the db
        for i, txout in enumerate(tx.composed_tx_spec.txouts):
            script = tx.pycoin_tx.txs_out[i].script.encode('hex')
            if txout.target_addr in all_addresses:
                self.add_coin(txout.target_addr, txhash, i,
                              txout.value, script, block_hash)
예제 #2
0
    def apply_tx(self, txhash, tx=None):
        """Given a transaction <composed_tx_spec>, delete any
        utxos that it spends and add any utxos that are new
        """

        all_addresses = [
            a.get_address()
            for a in self.model.get_address_manager().get_all_addresses()
        ]

        if not tx:
            bs = self.model.ccc.blockchain_state
            raw_tx = bs.bitcoind.getrawtransaction(txhash, 0).decode('hex')
            tx = RawTxSpec.from_tx_data(self.model, raw_tx)

        # delete the spent utxo from the db
        for txin in tx.composed_tx_spec.txins:
            oldtxhash, outindex = txin.get_outpoint()
            self.store.del_utxo(oldtxhash, outindex)

        # put the new utxo into the db
        for i, txout in enumerate(tx.composed_tx_spec.txouts):
            script = tx.pycoin_tx.txs_out[i].script.encode('hex')
            if txout.target_addr in all_addresses:
                self.store.add_utxo(txout.target_addr, txhash, i, txout.value,
                                    script)
예제 #3
0
 def populate_history(self):
     txdb = self.model.get_tx_db()
     for txhash in txdb.get_all_tx_hashes():
         if txhash not in self.entries:
             tx_data = txdb.get_tx_by_hash(txhash)['data']
             raw_tx = RawTxSpec.from_tx_data(self.model,
                                             tx_data.decode('hex'))
             self.add_entry_from_tx(raw_tx)
예제 #4
0
 def populate_history(self):
     txdb = self.model.get_tx_db()
     for txhash in txdb.get_all_tx_hashes():
         if txhash not in self.entries:
             tx_data = txdb.get_tx_by_hash(txhash)['data']
             raw_tx  = RawTxSpec.from_tx_data(self.model,
                                              tx_data.decode('hex'))
             self.add_entry_from_tx(raw_tx)
예제 #5
0
 def populate_history(self):
     txdb = self.model.get_tx_db()
     for txhash in txdb.get_all_tx_hashes():
         if (txhash not in self.entries or            # new transaction
                 not self.entries[txhash]['txtime']): # update unconfirmed
             tx_data = txdb.get_tx_by_hash(txhash)['data']
             raw_tx  = RawTxSpec.from_tx_data(self.model,
                                              tx_data.decode('hex'))
             self.add_entry_from_tx(raw_tx)
예제 #6
0
    def apply_tx(self, txhash, tx=None):
        """Given a transaction <composed_tx_spec>, delete any
        utxos that it spends and add any utxos that are new
        """

        all_addresses = [a.get_address() for a in
                         self.model.get_address_manager().get_all_addresses()]

        if not tx:
            bs = self.model.ccc.blockchain_state
            raw_tx = bs.bitcoind.getrawtransaction(txhash, 0).decode('hex')
            tx = RawTxSpec.from_tx_data(self.model, raw_tx)

        # delete the spent utxo from the db
        for txin in tx.composed_tx_spec.txins:
            oldtxhash, outindex = txin.get_outpoint()
            self.store.del_utxo(oldtxhash, outindex)

        # put the new utxo into the db
        for i, txout in enumerate(tx.composed_tx_spec.txouts):
            script = tx.pycoin_tx.txs_out[i].script.encode('hex')
            if txout.target_addr in all_addresses:
                self.store.add_utxo(txout.target_addr, txhash, i,
                                    txout.value, script)
예제 #7
0
 def add_tx_by_hash(self, txhash, status=None):
     bs = self.model.get_blockchain_state()
     txdata = bs.get_raw(txhash)
     raw_tx = RawTxSpec.from_tx_data(self.model, txdata.decode('hex'))
     return self.add_tx(txhash, txdata, raw_tx, status)
예제 #8
0
 def process_reply(self, reply_ep):
     rtxs = RawTxSpec.from_tx_data(self.ewctrl.model,
                                   reply_ep.etx_data.decode('hex'))
     rtxs.sign(self.etx_spec.my_utxo_list)
     self.etx_data = rtxs.get_hex_tx_data()
예제 #9
0
파일: txdb.py 프로젝트: Andymeows/ngcccbase
 def add_tx_by_hash(self, txhash, status=None):
     bs = self.model.get_blockchain_state()
     txdata = bs.get_raw(txhash)
     raw_tx = RawTxSpec.from_tx_data(self.model,
                                     txdata.decode('hex'))
     return self.add_tx(txhash, txdata, raw_tx, status)
예제 #10
0
 def process_reply(self, reply_ep):
     rtxs = RawTxSpec.from_tx_data(self.ewctrl.model,
                                   reply_ep.etx_data.decode('hex'))
     self.ewctrl.publish_tx(rtxs) # TODO: ???