Esempio n. 1
0
 def parse_block(chain, ds):
     d = chain.parse_block_header(ds)
     d['transactions'] = []
     nTransactions = ds.read_compact_size()
     for i in xrange(nTransactions):
         d['transactions'].append(deserialize.parse_Transaction(ds))
     return d
Esempio n. 2
0
def deserialize_tx(tx_hash, tx_height, raw_tx):
    vds = deserialize.BCDataStream()
    vds.write(raw_tx.decode('hex'))
    tx = deserialize.parse_Transaction(vds)
    tx['height'] = tx_height
    tx['tx_hash'] = tx_hash
    return tx
Esempio n. 3
0
    def deserialize_tx(self, tx_hash, tx_height, raw_tx):

        assert tx_hash == hash_encode(Hash(raw_tx.decode('hex')))
        import deserialize
        vds = deserialize.BCDataStream()
        vds.write(raw_tx.decode('hex'))
        d = deserialize.parse_Transaction(vds)
        d['height'] = tx_height
        d['tx_hash'] = tx_hash
        return d
Esempio n. 4
0
    def deserialize_tx(self, tx_hash, tx_height, raw_tx):

        assert tx_hash == hash_encode(Hash(raw_tx.decode('hex')))
        import deserialize
        vds = deserialize.BCDataStream()
        vds.write(raw_tx.decode('hex'))
        d = deserialize.parse_Transaction(vds)
        d['tx_hash'] = tx_hash
        d['timestamp'] = self.wallet.verifier.get_timestamp(tx_height)
        return d
    def get_mempool_transaction(self, txid):
        try:
            raw_tx = self.bitcoind('getrawtransaction', [txid, 0, -1])
        except:
            return None

        vds = deserialize.BCDataStream()
        vds.write(raw_tx.decode('hex'))
        out = deserialize.parse_Transaction(vds, is_coinbase = False)
        return out
Esempio n. 6
0
def parse_block(raw_block):
    vds = deserialize.BCDataStream()
    vds.write(raw_block)
    block = deserialize.parse_BlockHeader(vds)
    block["transactions"] = []
    number_tx = vds.read_compact_size()
    for i in xrange(number_tx):
        tx = deserialize.parse_Transaction(vds)
        block["transactions"].append(tx)
    return block
 def get_mempool_transaction(self, txid):
     try:
         raw_tx = self.bitcoind('getrawtransaction', (txid, 0))
     except:
         return None
     vds = deserialize.BCDataStream()
     vds.write(raw_tx.decode('hex'))
     try:
         return deserialize.parse_Transaction(vds, is_coinbase=False)
     except:
         print_log("ERROR: cannot parse", txid)
         return None
 def get_mempool_transaction(self, txid):
     try:
         raw_tx = self.quebecoind('getrawtransaction', (txid, 0))
     except:
         return None
     vds = deserialize.BCDataStream()
     vds.write(raw_tx.decode('hex'))
     try:
         return deserialize.parse_Transaction(vds, is_coinbase=False)
     except:
         print_log("ERROR: cannot parse", txid)
         return None
Esempio n. 9
0
def sendbitcoin(address, amount=0, comment="", comment_to=""):
    txid = sendtoaddress(address, amount, comment, comment_to)
    if txid['result']:
        _raw = getrawtransaction(txid['result'])
        if _raw['result']:
            ds = BCDataStream()
            ds.write(binascii.unhexlify(_raw['result']))
            _raw['result'] = deserialize.deserialize_TransactionRaw(deserialize.parse_Transaction(ds))
        return _raw
    else:
        if txid['error']['code']==-4:
            txid['error']['message']="Insufficient funds"
    return txid
 def deserialize_block(self, block):
     txlist = block.get('tx')
     tx_hashes = []  # ordered txids
     txdict = {}     # deserialized tx
     is_coinbase = True
     for raw_tx in txlist:
         tx_hash = hash_encode(Hash(raw_tx.decode('hex')))
         tx_hashes.append(tx_hash)
         vds = deserialize.BCDataStream()
         vds.write(raw_tx.decode('hex'))
         tx = deserialize.parse_Transaction(vds, is_coinbase)
         txdict[tx_hash] = tx
         is_coinbase = False
     return tx_hashes, txdict
Esempio n. 11
0
def sendbitcoin(address, amount=0, comment="", comment_to=""):
    txid = sendtoaddress(address, amount, comment, comment_to)
    if txid['result']:
        _raw = getrawtransaction(txid['result'])
        if _raw['result']:
            ds = BCDataStream()
            ds.write(binascii.unhexlify(_raw['result']))
            _raw['result'] = deserialize.deserialize_TransactionRaw(
                deserialize.parse_Transaction(ds))
        return _raw
    else:
        if txid['error']['code'] == -4:
            txid['error']['message'] = "Insufficient funds"
    return txid
 def deserialize_block(block):
     txlist = block.get('tx')
     tx_hashes = []  # ordered txids
     txdict = {}     # deserialized tx
     is_coinbase = True
     for raw_tx in txlist:
         tx_hash = hash_encode(Hash(raw_tx.decode('hex')))
         vds = deserialize.BCDataStream()
         vds.write(raw_tx.decode('hex'))
         try:
             tx = deserialize.parse_Transaction(vds, is_coinbase)
         except:
             print_log("ERROR: cannot parse", tx_hash)
             continue
         tx_hashes.append(tx_hash)
         txdict[tx_hash] = tx
         is_coinbase = False
     return tx_hashes, txdict
 def deserialize_block(block):
     txlist = block.get('tx')
     tx_hashes = []  # ordered txids
     txdict = {}  # deserialized tx
     is_coinbase = True
     for raw_tx in txlist:
         tx_hash = hash_encode(Hash(raw_tx.decode('hex')))
         vds = deserialize.BCDataStream()
         vds.write(raw_tx.decode('hex'))
         try:
             tx = deserialize.parse_Transaction(vds, is_coinbase)
         except:
             print_log("ERROR: cannot parse", tx_hash)
             continue
         tx_hashes.append(tx_hash)
         txdict[tx_hash] = tx
         is_coinbase = False
     return tx_hashes, txdict
Esempio n. 14
0
 def deserialize(self):
     import deserialize
     vds = deserialize.BCDataStream()
     vds.write(self.raw.decode('hex'))
     self.d = deserialize.parse_Transaction(vds)
     return self.d
Esempio n. 15
0
 def ds_parse_transaction(chain, ds):
     return deserialize.parse_Transaction(ds)
 def get_transaction(self, txid, block_height=-1, is_coinbase = False):
     raw_tx = self.bitcoind('getrawtransaction', [txid, 0, block_height])
     vds = deserialize.BCDataStream()
     vds.write(raw_tx.decode('hex'))
     out = deserialize.parse_Transaction(vds, is_coinbase)
     return out
Esempio n. 17
0
 def deserialize(self):
     import deserialize
     vds = deserialize.BCDataStream()
     vds.write(self.raw.decode('hex'))
     self.d = deserialize.parse_Transaction(vds)
     return self.d
Esempio n. 18
0
 def ds_parse_transaction(chain, ds):
     return deserialize.parse_Transaction(ds, has_nTime=True)
Esempio n. 19
0
COIN=100000000
#constant used to determine which part of the transaction is hashed.
SIGHASH_ALL=1
#private key whose public key hashes to the hash contained in scriptPubKey of output number *OUTPUT_INDEX* in the transaction described in HEX_TRANSACTION
PRIVATE_KEY=0x18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

def dsha256(data):
   return sha256.new(sha256.new(data).digest()).digest()

tx_data=HEX_TRANSACTION.decode('hex_codec')
tx_hash=dsha256(tx_data)

#here we use bitcointools to parse a transaction. this gives easy access to the various fields of the transaction from which we want to redeem an output
stream = BCDataStream()
stream.write(tx_data)
tx_info = parse_Transaction(stream)

if len(tx_info['txOut']) < (OUTPUT_INDEX+1):
   raise RuntimeError, "there are only %d output(s) in the transaction you're trying to redeem from. you want to redeem output index %d" % (len(tx_info['txOut']), OUTPUT_INDEX)

#this dictionary is used to store the values of the various transaction fields
#  this is useful because we need to construct one transaction to hash and sign
#  and another that will be the final transaction
tx_fields = {}

##here we start creating the transaction that we hash and sign
sign_tx = BCDataStream()
##first we write the version number, which is 1
tx_fields['version'] = 1
sign_tx.write_int32(tx_fields['version'])
##then we write the number of transaction inputs, which is one
Esempio n. 20
0
 def ds_parse_transaction(chain, ds):
     return deserialize.parse_Transaction(ds)
Esempio n. 21
0
 def ds_parse_transaction(chain, ds):
     return deserialize.parse_Transaction(ds, has_nTime=True)
Esempio n. 22
0
COIN=100000000
#constant used to determine which part of the transaction is hashed.
SIGHASH_ALL=1
#private key whose public key hashes to the hash contained in scriptPubKey of output number *OUTPUT_INDEX* in the transaction described in HEX_TRANSACTION
PRIVATE_KEY=0x18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725

def dsha256(data):
   return sha256.new(sha256.new(data).digest()).digest()

tx_data=HEX_TRANSACTION.decode('hex_codec')
tx_hash=dsha256(tx_data)

#here we use bitcointools to parse a transaction. this gives easy access to the various fields of the transaction from which we want to redeem an output
stream = BCDataStream()
stream.write(tx_data)
tx_info = parse_Transaction(stream)

if len(tx_info['txOut']) < (OUTPUT_INDEX+1):
   raise RuntimeError, "there are only %d output(s) in the transaction you're trying to redeem from. you want to redeem output index %d" % (len(tx_info['txOut']), OUTPUT_INDEX)

#this dictionary is used to store the values of the various transaction fields
#  this is useful because we need to construct one transaction to hash and sign
#  and another that will be the final transaction
tx_fields = {}

##here we start creating the transaction that we hash and sign
sign_tx = BCDataStream()
##first we write the version number, which is 1
tx_fields['version'] = 1
sign_tx.write_int32(tx_fields['version'])
##then we write the number of transaction inputs, which is one
Esempio n. 23
0
def parse_transaction(raw_tx):
    vds = deserialize.BCDataStream()
    vds.write(raw_tx)
    tx = deserialize.parse_Transaction(vds)
    tx["hash"] = deserialize.Hash(raw_tx)[::-1]
    return tx