Esempio n. 1
0
File: client.py Progetto: imak81/sx
    def fetch_history(self, address, cb, from_height=0):
        """Fetches the output points, output values, corresponding input point
        spends and the block heights associated with a Bitcoin address.
        The returned history is a list of rows with the following fields:
     
            output
            output_height
            value
            spend
            spend_height

        If an output is unspent then the input spend hash will be equivalent
        to null_hash.

        Summing the list of values for unspent outpoints gives the balance
        for an address.
        """
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash[::-1]  # address
        data += struct.pack('<I', from_height)  # from_height

        # run command
        self.send_command('address.fetch_history', data, cb)
Esempio n. 2
0
    def fetch_history(self, address, cb, from_height=0):
        """Fetches the output points, output values, corresponding input point
        spends and the block heights associated with a Bitcoin address.
        The returned history is a list of rows with the following fields:
     
            output
            output_height
            value
            spend
            spend_height

        If an output is unspent then the input spend hash will be equivalent
        to null_hash.

        Summing the list of values for unspent outpoints gives the balance
        for an address.
        """
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)    # address version
        data += address_hash[::-1]                  # address
        data += struct.pack('<I', from_height)      # from_height

        # run command
        self.send_command('address.fetch_history', data, cb)
Esempio n. 3
0
    def renew_address(self, address, cb=None):
        address_version, address_hash = bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack("B", address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command("address.renew", data, cb)
Esempio n. 4
0
    def renew_address(self, address, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command('address.renew', data, cb)
Esempio n. 5
0
    def renew_address(self, address, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', 0)          # type = address
        data += struct.pack('B', 160)       # bitsize
        data += address_hash                # address

        # run command
        self.send_command('address.renew', data, cb)
Esempio n. 6
0
    def unsubscribe_address(self, address, subscribed_cb, cb=None):
        address_version, address_hash = bitcoin.bc_address_to_hash_160(address)

        if address_hash in self._subscriptions["address"]:
            if subscribed_cb in self._subscriptions["address"][address_hash]:
                self._subscriptions["address"][address_hash].remove(subscribed_cb)
                if len(self._subscriptions["address"][address_hash]) == 0:
                    self._subscriptions["address"].pop(address_hash)
        if cb:
            cb(None, address)
    def renew_address(self, address, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', 0)  # type = address
        data += struct.pack('B', 160)  # bitsize
        data += address_hash  # address

        # run command
        self.send_command('address.renew', data, cb)
Esempio n. 8
0
File: client.py Progetto: imak81/sx
    def renew_address(self, address):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command('address.renew', data)
        # renew triggered again on response
        reactor.callLater(120, self.renew_address, address)
Esempio n. 9
0
    def renew_address(self, address):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)          # address version
        data += address_hash[::-1]               # address

        # run command
        self.send_command('address.renew', data)
        # renew triggered again on response
        reactor.callLater(120, self.renew_address, address)
Esempio n. 10
0
File: client.py Progetto: imak81/sx
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command('address.subscribe', data, cb)
        if notification_cb:
            self._subscriptions['address'][address_hash] = notification_cb
        reactor.callLater(120, self.renew_address, address)
Esempio n. 11
0
    def unsubscribe_address(self, address, subscribed_cb, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)

        subscriptions = self._subscriptions['address']
        if address_hash in subscriptions:
            if subscribed_cb in subscriptions[address_hash]:
                subscriptions[address_hash].remove(subscribed_cb)
                if len(subscriptions[address_hash]) == 0:
                    subscriptions.pop(address_hash)
        if cb:
            cb(None, address)
Esempio n. 12
0
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)          # address version
        data += address_hash[::-1]               # address

        # run command
        self.send_command('address.subscribe', data, cb)
        if notification_cb:
            self._subscriptions['address'][address_hash] = notification_cb
        reactor.callLater(120, self.renew_address, address)
Esempio n. 13
0
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack("B", address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command("address.subscribe", data, cb)
        if notification_cb:
            if not address_hash in self._subscriptions["address"]:
                self._subscriptions["address"][address_hash] = []
            if not notification_cb in self._subscriptions["address"][address_hash]:
                self._subscriptions["address"][address_hash].append(notification_cb)
Esempio n. 14
0
    def unsubscribe_address(self, address, subscribed_cb, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)

        subscriptions = self._subscriptions['address']
        if address_hash in subscriptions:
            if subscribed_cb in subscriptions[address_hash]:
                subscriptions[address_hash].remove(subscribed_cb)
                if len(subscriptions[address_hash]) == 0:
                    subscriptions.pop(address_hash)
        if cb:
            cb(None, address)
        if self.subscribed > 0:
            self.subscribed -= 1
Esempio n. 15
0
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash[::-1]  # address

        # run command
        self.send_command('address.subscribe', data, cb)
        if notification_cb:
            if not address_hash in self._subscriptions['address']:
                self._subscriptions['address'][address_hash] = []
            if not notification_cb in self._subscriptions['address'][
                    address_hash]:
                self._subscriptions['address'][address_hash].append(
                    notification_cb)
    def check_valid(self):
        """Evaluate whether this proposal is valid."""
        if not self.proposal_name:
            raise ValueError(_('A proposal name is required.'))
        elif len(self.proposal_name) > 20:
            raise ValueError(
                _('Proposal names have a limit of 20 characters.'))
        if not is_safe(self.proposal_name):
            raise ValueError(_('Unsafe characters in proposal name.'))

        if not self.proposal_url:
            raise ValueError(_('A proposal URL is required.'))
        elif len(self.proposal_url) > 64:
            raise ValueError(_('Proposal URLs have a limit of 64 characters.'))
        if not is_safe(self.proposal_url):
            raise ValueError(_('Unsafe characters in proposal URL.'))

        if self.end_block < self.start_block:
            raise ValueError(_('End block must be after start block.'))

        if not bitcoin.is_address(self.address):
            raise ValueError(_('Invalid address:') + ' %s' % self.address)
        addrtype, h160 = bitcoin.bc_address_to_hash_160(self.address)
        if addrtype != bitcoin.PUBKEY_ADDR:
            raise ValueError(
                _('Only P2PKH addresses are currently supported.'))

        if self.payment_amount < bitcoin.COIN:
            raise ValueError(_('Payments must be at least 1 DSR.'))

        # Calculate max budget.
        subsidy = 5 * bitcoin.COIN
        if bitcoin.TESTNET:
            for i in range(46200, self.start_block + 1,
                           SUBSIDY_HALVING_INTERVAL):
                subsidy -= subsidy / 14
        else:
            for i in range(SUBSIDY_HALVING_INTERVAL, self.start_block + 1,
                           SUBSIDY_HALVING_INTERVAL):
                subsidy -= subsidy / 14

        # 10%
        total_budget = ((subsidy / 100) * 10) * BUDGET_PAYMENTS_CYCLE_BLOCKS
        if self.payment_amount > total_budget:
            raise ValueError(
                _('Payment is more than max') +
                ' (%s).' % util.format_satoshis_plain(total_budget))
Esempio n. 17
0
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # Prepare parameters. Use full prefix for now.
        # Type. 0 is address, 1 is stealth.
        data = struct.pack('B', 0)
        # Bitsize
        data += struct.pack('B', 160)
        # Hash bytes
        data += address_hash

        # run command
        self.send_command('address.subscribe', data, cb)
        if notification_cb:
            subscriptions = self._subscriptions['address']
            if address_hash not in subscriptions:
                subscriptions[address_hash] = []
            subscriptions = self._subscriptions['address'][address_hash]
            if notification_cb not in subscriptions:
                subscriptions.append(notification_cb)
Esempio n. 18
0
    def subscribe_address(self, address, notification_cb=None, cb=None):
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)
        # Prepare parameters. Use full prefix for now.
        # Type. 0 is address, 1 is stealth.
        data = struct.pack('B', 0)
        # Bitsize
        data += struct.pack('B', 160)
        # Hash bytes
        data += address_hash

        # run command
        self.send_command('address.subscribe', data, cb)
        if notification_cb:
            subscriptions = self._subscriptions['address']
            if address_hash not in subscriptions:
                subscriptions[address_hash] = []
            subscriptions = self._subscriptions['address'][address_hash]
            if notification_cb not in subscriptions:
                subscriptions.append(notification_cb)
    def fetch_history2(self, address, cb, from_height=0):
        """Fetches history for an address. cb is a callback which
        accepts an error code, and a list of rows consisting of:

            id (obelisk.PointIdent.output or spend)
            point (hash and index)
            block height
            value / checksum

        If the row is for an output then the last item is the value.
        Otherwise it is a checksum of the previous output point, so
        spends can be matched to the rows they spend.
        Use spend_checksum(output_hash, output_index) to compute
        output point checksums."""
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)

        # prepare parameters
        data = struct.pack('B', address_version)  # address version
        data += address_hash  # address
        data += struct.pack('<I', from_height)  # from_height

        # run command
        self.send_command('address.fetch_history2', data, cb)
Esempio n. 20
0
    def fetch_history2(self, address, cb, from_height=0):
        """Fetches history for an address. cb is a callback which
        accepts an error code, and a list of rows consisting of:

            id (obelisk.PointIdent.output or spend)
            point (hash and index)
            block height
            value / checksum

        If the row is for an output then the last item is the value.
        Otherwise it is a checksum of the previous output point, so
        spends can be matched to the rows they spend.
        Use spend_checksum(output_hash, output_index) to compute
        output point checksums."""
        address_version, address_hash = \
            bitcoin.bc_address_to_hash_160(address)

        # prepare parameters
        data = struct.pack('B', address_version)    # address version
        data += address_hash                        # address
        data += struct.pack('<I', from_height)      # from_height

        # run command
        self.send_command('address.fetch_history2', data, cb)
Esempio n. 21
0
File: e.py Progetto: bcpki/bitcoin
def addr2id(addr):
  return bitcoin.bc_address_to_hash_160(addr)
Esempio n. 22
0
def to_hash160(hash):
    return bitcoin.bc_address_to_hash_160(hash)[1]
Esempio n. 23
0
File: e.py Progetto: bcpki/bitcoin
def addr2idx(addr):
  return tohex(bitcoin.bc_address_to_hash_160(addr))