code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
return self._getNodeData(name, self._WRITENODE, channel)
def getWriteData(self, name, channel=None)
Returns a sensor node
11.293413
9.470636
1.192466
nodeChannel = None if name in metadata: nodeChannelList = metadata[name] if len(nodeChannelList) > 1: nodeChannel = channel if channel is not None else nodeChannelList[0] elif len(nodeChannelList) == 1: nodeChannel = nodeChanne...
def _getNodeData(self, name, metadata, channel=None)
Returns a data point from data
2.927428
2.878394
1.017035
nodeChannel = None if name in metadata: nodeChannelList = metadata[name] if len(nodeChannelList) > 1: nodeChannel = channel if channel is not None else nodeChannelList[0] elif len(nodeChannelList) == 1: nodeChannel = nodeChanne...
def _setNodeData(self, name, metadata, data, channel=None)
Returns a data point from data
3.749256
3.663756
1.023337
if hasattr(callback, '__call__'): if channel == 0: self._eventcallbacks.append(callback) elif not bequeath and channel > 0 and channel in self._hmchannels: self._hmchannels[channel]._eventcallbacks.append(callback) if bequeath: ...
def setEventCallback(self, callback, bequeath=True, channel=0)
Set additional event callbacks for the device. Set the callback for specific channels or use the device itself and let it bequeath the callback to all of its children. Signature for callback-functions: foo(address, interface_id, key, value)
3.192257
3.214991
0.992929
if channel in self.CHANNELS: return self.CHANNELS[channel].setValue(key, value) LOG.error("HMDevice.setValue: channel not found %i!" % channel)
def setValue(self, key, value, channel=1)
Some devices allow to directly set values to perform a specific task.
7.307098
6.962536
1.049488
if channel in self.CHANNELS: return self.CHANNELS[channel].getValue(key) LOG.error("HMDevice.getValue: channel not found %i!" % channel)
def getValue(self, key, channel=1)
Some devices allow to directly get values for specific parameters.
7.87538
7.434116
1.059357
try: target_temperature = float(target_temperature) except Exception as err: LOG.debug("Thermostat.set_temperature: Exception %s" % (err,)) return False self.writeNodeData("SET_TEMPERATURE", target_temperature)
def set_temperature(self, target_temperature)
Set the target temperature.
4.448206
4.382556
1.01498
set_data = True mode = None if setmode == self.AUTO_MODE: mode = 'AUTO_MODE' elif setmode == self.MANU_MODE: mode = 'MANU_MODE' set_data = self.get_set_temperature() elif setmode == self.BOOST_MODE: mode = 'BOOST_MODE' ...
def MODE(self, setmode)
Set mode.
3.185188
3.153916
1.009915
if setmode == self.BOOST_MODE: self.actionNodeData('BOOST_MODE', True) elif setmode in [self.AUTO_MODE, self.MANU_MODE]: if self.getAttributeData("BOOST_MODE"): self.actionNodeData('BOOST_MODE', False) self.actionNodeData('CONTROL_MODE', setmo...
def MODE(self, setmode)
Set mode.
4.550159
4.564587
0.996839
LOG.info("Shutting down server") self.server.shutdown() LOG.debug("ServerThread.stop: Stopping ServerThread") self.server.server_close() LOG.info("Server stopped")
def stop(self)
Shut down our XML-RPC server.
5.368222
4.764693
1.126667
'''Run the normal shovel functionality''' import os import sys import argparse import pkg_resources # First off, read the arguments parser = argparse.ArgumentParser(prog='shovel', description='Rake, for Python') parser.add_argument('method', help='The task to run') parser.add_argume...
def run(*args)
Run the normal shovel functionality
2.975682
2.918493
1.019596
'''Return a list of tuples of (fullname, docstring, level) for all the tasks in the provided shovel''' result = [] for key, value in sorted(shovel.map.items()): if prefix: key = prefix + '.' + key if isinstance(value, Shovel): result.append((key, None, level)) ...
def heirarchical_helper(shovel, prefix, level=0)
Return a list of tuples of (fullname, docstring, level) for all the tasks in the provided shovel
3.330198
2.184623
1.524381
'''Given a shovel of tasks, display a heirarchical list of the tasks''' result = [] tuples = heirarchical_helper(shovel, prefix) if not tuples: return '' # We need to figure out the longest fullname length longest = max(len(name + ' ' * level) for name, _, level in tuples) fmt = ...
def heirarchical_help(shovel, prefix)
Given a shovel of tasks, display a heirarchical list of the tasks
3.938241
3.597402
1.094746
'''Return a string about help with the tasks, or lists tasks available''' # If names are provided, and the name refers to a group of tasks, print out # the tasks and a brief docstring. Otherwise, just enumerate all the tasks # available if not len(names): return heirarchical_help(shovel, '')...
def shovel_help(shovel, *names)
Return a string about help with the tasks, or lists tasks available
6.764545
4.771535
1.417687
'''Either load a path and return a shovel object or return None''' obj = cls() obj.read(path, base) return obj
def load(cls, path, base=None)
Either load a path and return a shovel object or return None
11.654296
4.270509
2.729018
'''Add tasks to this particular shovel''' self._tasks.extend(tasks) for task in tasks: # We'll now go through all of our tasks and group them into # sub-shovels current = self.map modules = task.fullname.split('.') for module in modules...
def extend(self, tasks)
Add tasks to this particular shovel
3.916425
3.604353
1.086582
'''Import some tasks''' if base == None: base = os.getcwd() absolute = os.path.abspath(path) if os.path.isfile(absolute): # Load that particular file logger.info('Loading %s' % absolute) self.extend(Task.load(path, base)) elif os.pa...
def read(self, path, base=None)
Import some tasks
2.760704
2.564382
1.076558
'''Return all valid keys''' keys = [] for key, value in self.map.items(): if isinstance(value, Shovel): keys.extend([key + '.' + k for k in value.keys()]) else: keys.append(key) return sorted(keys)
def keys(self)
Return all valid keys
3.96242
3.660088
1.082602
'''Return a list of tuples of all the keys and tasks''' pairs = [] for key, value in self.map.items(): if isinstance(value, Shovel): pairs.extend([(key + '.' + k, v) for k, v in value.items()]) else: pairs.append((key, value)) retur...
def items(self)
Return a list of tuples of all the keys and tasks
4.331054
3.150447
1.374743
'''Get all the tasks that match a name''' found = self[name] if isinstance(found, Shovel): return [v for _, v in found.items()] return [found]
def tasks(self, name)
Get all the tasks that match a name
7.854498
7.296306
1.076503
'''Given a callable object, return a new callable object''' try: cls._cache.append(Task(obj)) except Exception: logger.exception('Unable to make task for %s' % repr(obj))
def make(cls, obj)
Given a callable object, return a new callable object
8.525264
6.588678
1.293926
'''Return a list of the tasks stored in a file''' base = base or os.getcwd() absolute = os.path.abspath(path) parent = os.path.dirname(absolute) name, _, _ = os.path.basename(absolute).rpartition('.py') fobj, path, description = imp.find_module(name, [parent]) try...
def load(cls, path, base=None)
Return a list of the tasks stored in a file
4.502989
4.209925
1.069613
'''Run a task and return a dictionary with stderr, stdout and the return value. Also, the traceback from the exception if there was one''' import traceback try: from StringIO import StringIO except ImportError: from io import StringIO stdou...
def capture(self, *args, **kwargs)
Run a task and return a dictionary with stderr, stdout and the return value. Also, the traceback from the exception if there was one
2.842964
1.897112
1.498575
'''Perform a dry-run of the task''' return 'Would have executed:\n%s%s' % ( self.name, Args(self.spec).explain(*args, **kwargs))
def dry(self, *args, **kwargs)
Perform a dry-run of the task
10.89417
11.224578
0.970564
'''Return the help string of the task''' # This returns a help string for a given task of the form: # # ================================================== # <name> # ============================== (If supplied) # <docstring> # =============================...
def help(self)
Return the help string of the task
5.771911
5.591529
1.03226
'''Return a string that describes how these args are interpreted''' args = self.get(*args, **kwargs) results = ['%s = %s' % (name, value) for name, value in args.required] results.extend(['%s = %s (overridden)' % ( name, value) for name, value in args.overridden]) res...
def explain(self, *args, **kwargs)
Return a string that describes how these args are interpreted
2.540047
2.200208
1.154458
'''Evaluate this argspec with the provided arguments''' # We'll go through all of our required args and make sure they're # present required = [arg for arg in self._args if arg not in kwargs] if len(args) < len(required): raise TypeError('Missing arguments %s' % requi...
def get(self, *args, **kwargs)
Evaluate this argspec with the provided arguments
4.131336
3.736825
1.105574
'''Parse the provided string to produce *args and **kwargs''' args = [] kwargs = {} last = None for token in tokens: if token.startswith('--'): # If this is a keyword flag, but we've already got one that we've # parsed, then we're going to interpret it as a bool ...
def parse(tokens)
Parse the provided string to produce *args and **kwargs
4.795243
4.26604
1.12405
'''Computes the sum of the provided numbers''' print('%s = %f' % (' + '.join(args), sum(float(arg) for arg in args)))
def sumnum(*args)
Computes the sum of the provided numbers
5.584384
5.660646
0.986528
'''Prints a name, and all keyword attributes''' print('%s has attributes:' % name) for key, value in kwargs.items(): print('\t%s => %s' % (key, value))
def attributes(name, **kwargs)
Prints a name, and all keyword attributes
4.412392
3.032544
1.455013
DJANGO_111_OR_UP = (VERSION[0] == 1 and VERSION[1] >= 11) or ( VERSION[0] >= 2 ) if DJANGO_111_OR_UP: return super(DynamicRawIDWidget, self).render( name, value, attrs, renderer=renderer ) if attrs is None: attrs =...
def render(self, name, value, attrs=None, multi=False, renderer=None)
Django <= 1.10 variant.
2.125856
2.093839
1.015291
context = super(DynamicRawIDWidget, self).get_context( name, value, attrs ) model = self.rel.model if VERSION[0] == 2 else self.rel.to related_url = reverse( 'admin:{0}_{1}_changelist'.format( model._meta.app_label, model._meta.object_name...
def get_context(self, name, value, attrs)
Django >= 1.11 variant.
2.286465
2.234432
1.023287
return DynamicRawIDFilterForm( admin_site=admin_site, rel=rel, field_name=self.field_path, data=self.used_parameters, )
def get_form(self, request, rel, admin_site)
Return filter form.
4.827082
3.994691
1.208374
if self.form.is_valid(): # get no null params filter_params = dict( filter(lambda x: bool(x[1]), self.form.cleaned_data.items()) ) return queryset.filter(**filter_params) return queryset
def queryset(self, request, queryset)
Filter queryset using params from the form.
3.791523
3.326896
1.139658
''' Decorate a control function in order to conduct an experiment when called. :param callable candidate: your candidate function :param iterable exp_args: positional arguments passed to :class:`Experiment` :param dict exp_kwargs: keyword arguments passed to :class:`Experiment` ...
def decorator(cls, candidate, *exp_args, **exp_kwargs)
Decorate a control function in order to conduct an experiment when called. :param callable candidate: your candidate function :param iterable exp_args: positional arguments passed to :class:`Experiment` :param dict exp_kwargs: keyword arguments passed to :class:`Experiment` Usage:: ...
3.942636
1.803023
2.186681
''' Set the experiment's control function. Must be set before ``conduct()`` is called. :param callable control_func: your control function :param iterable args: positional arguments to pass to your function :param dict kwargs: keyword arguments to pass to your function :...
def control(self, control_func, args=None, kwargs=None, name='Control', context=None)
Set the experiment's control function. Must be set before ``conduct()`` is called. :param callable control_func: your control function :param iterable args: positional arguments to pass to your function :param dict kwargs: keyword arguments to pass to your function :param string name: a...
3.779597
1.581955
2.389193
''' Adds a candidate function to an experiment. Can be used multiple times for multiple candidates. :param callable cand_func: your control function :param iterable args: positional arguments to pass to your function :param dict kwargs: keyword arguments to pass to your ...
def candidate(self, cand_func, args=None, kwargs=None, name='Candidate', context=None)
Adds a candidate function to an experiment. Can be used multiple times for multiple candidates. :param callable cand_func: your control function :param iterable args: positional arguments to pass to your function :param dict kwargs: keyword arguments to pass to your function :pa...
3.242547
1.457874
2.224162
''' Run control & candidate functions and return the control's return value. ``control()`` must be called first. :param bool randomize: controls whether we shuffle the order of execution between control and candidate :raise LaboratoryException: when no control case h...
def conduct(self, randomize=True)
Run control & candidate functions and return the control's return value. ``control()`` must be called first. :param bool randomize: controls whether we shuffle the order of execution between control and candidate :raise LaboratoryException: when no control case has been set ...
5.647808
3.676078
1.536368
''' Compares two :class:`Observation` instances. :param Observation control: The control block's :class:`Observation` :param Observation candidate: A candidate block's :class:`Observation` :raises MismatchException: If ``Experiment.raise_on_mismatch`` is True :return b...
def compare(self, control, candidate)
Compares two :class:`Observation` instances. :param Observation control: The control block's :class:`Observation` :param Observation candidate: A candidate block's :class:`Observation` :raises MismatchException: If ``Experiment.raise_on_mismatch`` is True :return bool: match?
7.033034
2.204068
3.190934
''' bytes -> str ''' if riemann.network.CASHADDR_PREFIX is None: raise ValueError('Network {} does not support cashaddresses.' .format(riemann.get_current_network_name())) data = convertbits(data, 8, 5) checksum = calculate_checksum(riemann.network.CASHADDR_PREF...
def encode(data)
bytes -> str
4.708553
4.328324
1.087847
''' str -> bytes ''' if riemann.network.CASHADDR_PREFIX is None: raise ValueError('Network {} does not support cashaddresses.' .format(riemann.get_current_network_name())) if data.find(riemann.network.CASHADDR_PREFIX) != 0: raise ValueError('Malformed cashadd...
def decode(data)
str -> bytes
5.280494
4.920965
1.073061
# fail if addsalt() was not called at the right time if self.state != 1: raise Exception('addsalt() not called after init() and before update()') # salt size is to be 4x word size saltsize = self.WORDBYTES * 4 # if too short, prefix with null bytes. if too l...
def addsalt(self, salt)
adds a salt to the hash function (OPTIONAL) should be called AFTER Init, and BEFORE update salt: a bytestring, length determined by hashbitlen. if not of sufficient length, the bytestring will be assumed to be a big endian number and pref...
3.942866
3.671519
1.073906
self.state = 2 BLKBYTES = self.BLKBYTES # de-referenced for improved readability BLKBITS = self.BLKBITS datalen = len(data) if not datalen: return if type(data) == type(u''): # use either of the next two lines for a proper # respon...
def update(self, data)
update the state with new data, storing excess data as necessary. may be called multiple times and if a call sends less than a full block in size, the leftover is cached and will be consumed in the next call data: data to be hashed (bytestring)
7.427929
7.063405
1.051608
if self.state == 3: # we have already finalized so simply return the # previously calculated/stored hash value return self.hash if data: self.update(data) ZZ = b'\x00' ZO = b'\x01' OZ = b'\x80' OO = b'\x81' ...
def final(self, data='')
finalize the hash -- pad and hash remaining data returns hashval, the digest
4.707017
4.591204
1.025225
''' TxIn -> TxIn ''' return TxIn( outpoint=outpoint if outpoint is not None else self.outpoint, stack_script=(stack_script if stack_script is not None else self.stack_script), redeem_script=(redeem_script if redeem_script is n...
def copy(self, outpoint=None, stack_script=None, redeem_script=None, sequence=None)
TxIn -> TxIn
2.18314
1.835022
1.189708
''' byte_string -> (byte_string, byte_string) ''' # Is there a better way to do this? stack_script = script_sig redeem_script = b'' try: # If the last entry deserializes, it's a p2sh input # There is a vanishingly small edge case where the ...
def _parse_script_sig(TxIn, script_sig)
byte_string -> (byte_string, byte_string)
7.970415
7.25914
1.097983
''' byte_string -> TxIn parses a TxIn from a byte-like object ''' outpoint = Outpoint.from_bytes(byte_string[:36]) script_sig_len = VarInt.from_bytes(byte_string[36:45]) script_start = 36 + len(script_sig_len) script_end = script_start + script_sig_len.nu...
def from_bytes(TxIn, byte_string)
byte_string -> TxIn parses a TxIn from a byte-like object
2.608938
2.393463
1.090027
''' Tx -> bytes ''' tx = bytes() tx += self.version tx += VarInt(len(self.tx_ins)).to_bytes() for tx_in in self.tx_ins: tx += tx_in.to_bytes() tx += VarInt(len(self.tx_outs)).to_bytes() for tx_out in self.tx_outs: tx += tx_o...
def no_witness(self)
Tx -> bytes
2.402551
2.143971
1.120608
''' Tx, list(int) -> int Inputs don't know their value without the whole chain. ''' return \ sum(input_values) \ - sum([utils.le2i(o.value) for o in self.tx_outs])
def calculate_fee(self, input_values)
Tx, list(int) -> int Inputs don't know their value without the whole chain.
17.561663
5.37447
3.267608
''' Tx, byte-like, byte-like, list(TxIn), list(TxOut), list(InputWitness), byte-like -> Tx Makes a copy. Allows over-writing specific pieces. ''' return Tx(version=version if version is not None else self.version, flag=flag if flag is not None else self...
def copy(self, version=None, flag=None, tx_ins=None, tx_outs=None, tx_witnesses=None, lock_time=None)
Tx, byte-like, byte-like, list(TxIn), list(TxOut), list(InputWitness), byte-like -> Tx Makes a copy. Allows over-writing specific pieces.
2.573353
1.494668
1.721688
''' Tx, int, byte-like, byte-like, bool -> bytearray Sighashes suck Generates the hash to be signed with SIGHASH_SINGLE https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE https://bitcoin.stackexchange.com/questions/3890/for-sighash-single-do-the-...
def sighash_single(self, index, script=None, prevout_value=None, anyone_can_pay=False)
Tx, int, byte-like, byte-like, bool -> bytearray Sighashes suck Generates the hash to be signed with SIGHASH_SINGLE https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_SINGLE https://bitcoin.stackexchange.com/questions/3890/for-sighash-single-do-the-outputs-other-than-a...
3.77433
2.237849
1.686588
''' this function sets up sighash in BIP143 style https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki https://ricette.giallozafferano.it/Spaghetti-alla-Norma.html ''' data = ByteData() # 1. nVersion of the transaction (4-byte little endian) dat...
def segwit_sighash(self, index, script, prevout_value=None, sighash_type=None, anyone_can_pay=False)
this function sets up sighash in BIP143 style https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki https://ricette.giallozafferano.it/Spaghetti-alla-Norma.html
2.654376
1.969945
1.347436
''' int, byte-like, Tx, int -> bytes Applies SIGHASH_ANYONECANPAY procedure. Should be called by another SIGHASH procedure. Not on its own. https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY ''' # The txCopy input vector is...
def _sighash_anyone_can_pay(self, index, copy_tx, sighash_type)
int, byte-like, Tx, int -> bytes Applies SIGHASH_ANYONECANPAY procedure. Should be called by another SIGHASH procedure. Not on its own. https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY
6.795709
2.933728
2.316408
''' Tx, int -> bytes Returns the hash that should be signed https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY ''' sighash = ByteData() sighash += copy_tx.to_bytes() sighash += utils.i2le_padded(sighash_type, 4) ret...
def _sighash_final_hashing(self, copy_tx, sighash_type)
Tx, int -> bytes Returns the hash that should be signed https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY
5.364676
2.600601
2.06286
'''BIP143 hashSequence implementation Args: sighash_type (int): SIGHASH_SINGLE or SIGHASH_ALL anyone_can_pay (bool): true if ANYONECANPAY should be set Returns: (bytes): the hashSequence, a 32 byte hash ''' if anyone_can_pay or sighash_type...
def _hash_sequence(self, sighash_type, anyone_can_pay)
BIP143 hashSequence implementation Args: sighash_type (int): SIGHASH_SINGLE or SIGHASH_ALL anyone_can_pay (bool): true if ANYONECANPAY should be set Returns: (bytes): the hashSequence, a 32 byte hash
4.67877
3.122375
1.498465
''' Checks if the script code pased in to the sighash function is already length-prepended This will break if there's a redeem script that's just a pushdata That won't happen in practice Args: script (bytes): the spend script Returns: (byt...
def _adjusted_script_code(self, script)
Checks if the script code pased in to the sighash function is already length-prepended This will break if there's a redeem script that's just a pushdata That won't happen in practice Args: script (bytes): the spend script Returns: (bytes): the length-prep...
8.663607
1.881953
4.60352
'''BIP143 hashOutputs implementation Args: index (int): index of input being signed sighash_type (int): SIGHASH_SINGLE or SIGHASH_ALL Returns: (bytes): the hashOutputs, a 32 byte hash ''' if sighash_type == shared.SIGHASH_ALL: ...
def _hash_outputs(self, index, sighash_type)
BIP143 hashOutputs implementation Args: index (int): index of input being signed sighash_type (int): SIGHASH_SINGLE or SIGHASH_ALL Returns: (bytes): the hashOutputs, a 32 byte hash
3.790066
2.939108
1.289529
''' https://github.com/decred/dcrd/blob/master/txscript/script.go ''' copy_tx = self._sighash_prep( index=index, script=script) try: copy_tx_outs = copy_tx.tx_outs[:index + 1] copy_tx_outs = [TxOut(value=b'\xff' * 8, output_script=...
def sighash_single(self, index, script=None, anyone_can_pay=False)
https://github.com/decred/dcrd/blob/master/txscript/script.go
2.634091
2.437807
1.080517
''' https://gist.github.com/davecgh/b00ec6e11f73620c3deddf160353961c https://github.com/decred/dcrd/blob/master/txscript/script.go ''' copy_tx = self._sighash_prep(index, script) if anyone_can_pay: return self._sighash_anyone_can_pay( index=in...
def sighash_all(self, index, script=None, anyone_can_pay=False)
https://gist.github.com/davecgh/b00ec6e11f73620c3deddf160353961c https://github.com/decred/dcrd/blob/master/txscript/script.go
4.538771
2.128022
2.132858
''' str -> bytearray ''' string_tokens = script_string.split() serialized_script = bytearray() for token in string_tokens: if token == 'OP_CODESEPARATOR' or token == 'OP_PUSHDATA4': raise NotImplementedError('{} is a bad idea.'.format(token)) if token in riemann.net...
def serialize(script_string)
str -> bytearray
2.201247
2.13245
1.032262
''' bytearray -> str ''' deserialized = [] i = 0 while i < len(serialized_script): current_byte = serialized_script[i] if current_byte == 0xab: raise NotImplementedError('OP_CODESEPARATOR is a bad idea.') if current_byte <= 75 and current_byte != 0: ...
def deserialize(serialized_script)
bytearray -> str
2.743641
2.681999
1.022984
''' inputs for the hsig hash ''' hsig_input = z.ZcashByteData() hsig_input += self.tx_joinsplits[index].random_seed hsig_input += self.tx_joinsplits[index].nullifiers hsig_input += self.joinsplit_pubkey return hsig_input.to_bytes()
def _hsig_input(self, index)
inputs for the hsig hash
7.618648
6.894496
1.105033
''' Primary input for the zkproof ''' primary_input = z.ZcashByteData() primary_input += self.tx_joinsplits[index].anchor primary_input += self.tx_joinsplits[index].nullifiers primary_input += self.tx_joinsplits[index].commitments primary_input += self.tx_...
def _primary_input(self, index)
Primary input for the zkproof
4.862043
3.849584
1.263005
''' byte-like -> SproutTx ''' version = byte_string[0:4] tx_ins = [] tx_ins_num = shared.VarInt.from_bytes(byte_string[4:]) current = 4 + len(tx_ins_num) for _ in range(tx_ins_num.number): tx_in = TxIn.from_bytes(byte_string[current:]) ...
def from_bytes(SproutTx, byte_string)
byte-like -> SproutTx
1.818377
1.781573
1.020658
''' Tx, list(int) -> int ''' total_in = sum(input_values) total_out = sum([utils.le2i(tx_out.value) for tx_out in self.tx_outs]) for js in self.tx_joinsplits: total_in += utils.le2i(js.vpub_new) total_out += utils.le2i(js.vpub_old) return t...
def calculate_fee(self, input_values)
Tx, list(int) -> int
4.902649
3.881835
1.262972
''' SproutTx, ... -> Tx Makes a copy. Allows over-writing specific pieces. ''' return SproutTx( version=version if version is not None else self.version, tx_ins=tx_ins if tx_ins is not None else self.tx_ins, tx_outs=tx_outs if tx_outs is not N...
def copy(self, version=None, tx_ins=None, tx_outs=None, lock_time=None, tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None)
SproutTx, ... -> Tx Makes a copy. Allows over-writing specific pieces.
2.083966
1.569081
1.328145
''' SproutTx, int, byte-like -> SproutTx Sighashes suck Performs the sighash setup described here: https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx We save on complexity by refusing to su...
def _sighash_prep(self, index, script)
SproutTx, int, byte-like -> SproutTx Sighashes suck Performs the sighash setup described here: https://en.bitcoin.it/wiki/OP_CHECKSIG#How_it_works https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx We save on complexity by refusing to support OP_CODESEPARAT...
7.266994
3.459435
2.10063
''' SproutTx, int, byte-like, byte-like, bool -> bytearray Sighashes suck Generates the hash to be signed with SIGHASH_ALL https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_ALL_.28default.29 ''' if riemann.network.FORKID is not None: return self...
def sighash_all(self, index=0, script=None, prevout_value=None, anyone_can_pay=False)
SproutTx, int, byte-like, byte-like, bool -> bytearray Sighashes suck Generates the hash to be signed with SIGHASH_ALL https://en.bitcoin.it/wiki/OP_CHECKSIG#Hashtype_SIGHASH_ALL_.28default.29
4.086933
2.277052
1.794835
''' SproutTx, int -> bytes Returns the hash that should be signed https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY ''' sighash = z.ZcashByteData() sighash += copy_tx.to_bytes() sighash += utils.i2le_padded(sighash_type, 4)...
def _sighash_final_hashing(self, copy_tx, sighash_type)
SproutTx, int -> bytes Returns the hash that should be signed https://en.bitcoin.it/wiki/OP_CHECKSIG#Procedure_for_Hashtype_SIGHASH_ANYONECANPAY
6.056089
2.751693
2.200859
ret = bech32_encode(hrp, [witver] + convertbits(witprog, 8, 5)) if segwit_decode(hrp, ret) == (None, None): return None return ret
def segwit_encode(hrp, witver, witprog)
Encode a segwit address.
3.492856
3.752781
0.930738
''' Prevents any future changes to the object ''' self._bytes = bytes(self._bytes) self.__immutable = True
def _make_immutable(self)
Prevents any future changes to the object
10.94229
5.457185
2.005116
''' byte-like -> int Finds the index of substring ''' if isinstance(substring, ByteData): substring = substring.to_bytes() return self._bytes.find(substring)
def find(self, substring)
byte-like -> int Finds the index of substring
9.202124
5.609523
1.640447
''' Raises ValueError if data is not bytes. Raises ValueError if len(data) is not length. Length may be None for unknown lengths (e.g. scripts). length=None will allow 0 length data. ''' if (not isinstance(data, ByteData) and not isinstance(data, b...
def validate_bytes(data, length=4)
Raises ValueError if data is not bytes. Raises ValueError if len(data) is not length. Length may be None for unknown lengths (e.g. scripts). length=None will allow 0 length data.
3.584923
2.079016
1.724336
''' byte-like -> VarInt accepts arbitrary length input, gets a VarInt off the front ''' num = byte_string if num[0] <= 0xfc: num = num[0:1] non_compact = False elif num[0] == 0xfd: num = num[1:3] non_compact = (num[-...
def from_bytes(VarInt, byte_string)
byte-like -> VarInt accepts arbitrary length input, gets a VarInt off the front
3.198162
2.749964
1.162983
''' SaplingTx, list(int) -> int ''' total_in = sum(input_values) total_out = sum([utils.le2i(tx_out.value) for tx_out in self.tx_outs]) shileded_net = utils.le2i(self.value_balance, signed=True) for js in self.tx_joinsplits: total_in += utils.le2i(js.v...
def calculate_fee(self, input_values)
SaplingTx, list(int) -> int
6.285395
4.722256
1.331015
''' SaplingTx, ... -> SaplingTx Makes a copy. Allows over-writing specific pieces. ''' return SaplingTx( tx_ins=tx_ins if tx_ins is not None else self.tx_ins, tx_outs=tx_outs if tx_outs is not None else self.tx_outs, lock_time=(lock_time if lo...
def copy(self, tx_ins=None, tx_outs=None, lock_time=None, expiry_height=None, value_balance=None, tx_shielded_spends=None, tx_shielded_outputs=None, tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None, binding_sig=None)
SaplingTx, ... -> SaplingTx Makes a copy. Allows over-writing specific pieces.
1.534102
1.305508
1.1751
''' byte-like -> SaplingTx ''' header = byte_string[0:4] group_id = byte_string[4:8] if header != b'\x04\x00\x00\x80' or group_id != b'\x85\x20\x2f\x89': raise ValueError( 'Bad header or group ID. Expected {} and {}. Got: {} and {}' ...
def from_bytes(SaplingTx, byte_string)
byte-like -> SaplingTx
1.527617
1.511956
1.010358
''' ZIP243 https://github.com/zcash/zips/blob/master/zip-0243.rst ''' if joinsplit and anyone_can_pay: raise ValueError('ANYONECANPAY can\'t be used with joinsplits') data = z.ZcashByteData() data += self.header data += self.group_id ...
def sighash(self, sighash_type, index=0, joinsplit=False, script_code=None, anyone_can_pay=False, prevout_value=None)
ZIP243 https://github.com/zcash/zips/blob/master/zip-0243.rst
3.633491
3.132227
1.160034
if checksum: data = data + utils.hash256(data)[:4] v, prefix = to_long(256, lambda x: x, iter(data)) data = from_long(v, prefix, BASE58_BASE, lambda v: BASE58_ALPHABET[v]) return data.decode("utf8")
def encode(data, checksum=True)
Convert binary to base58 using BASE58_ALPHABET.
7.044786
5.670221
1.242418
v, prefix = to_long( BASE58_BASE, lambda c: BASE58_LOOKUP[c], s.encode("utf8")) data = from_long(v, prefix, 256, lambda x: x) if checksum: data, the_hash = data[:-4], data[-4:] if utils.hash256(data)[:4] == the_hash: return data raise ValueError("hashed bas...
def decode(s, checksum=True)
Convert base58 to binary using BASE58_ALPHABET.
5.996397
5.74427
1.043892
ba = bytearray() while v > 0: try: v, mod = divmod(v, base) ba.append(charset(mod)) except Exception: raise ValueError( "can't convert to character corresponding to %d" % mod) ba.extend([charset(0)] * prefix) ba.reverse() retur...
def from_long(v, prefix, base, charset)
The inverse of to_long. Convert an integer to an arbitrary base. v: the integer value to convert prefix: the number of prefixed 0s to include base: the new base charset: an array indicating a printable character to use for each value.
3.968353
3.815641
1.040023
prefix = 0 v = 0 for c in s: v *= base try: v += lookup_f(c) except Exception: raise ValueError("bad character %s in string %s" % (c, s)) if v == 0: prefix += 1 return v, prefix
def to_long(base, lookup_f, s)
Convert an array to a (possibly bignum) integer, along with a prefix value of how many prefixed zeros there are. base: the source base lookup_f: a function to convert an element of s to a value between 0 and base-1. s: the value to convert
2.908952
2.76249
1.053018
''' str -> bytearray ''' if witness and not riemann.network.SEGWIT: raise ValueError( 'Network {} does not support witness scripts.' .format(riemann.get_current_network_name())) script_bytes = serialization.serialize(script_string) return make_sh_script_pubkey(sc...
def make_sh_output_script(script_string, witness=False)
str -> bytearray
5.608117
4.583373
1.223579
''' bytearray -> bytearray ''' if witness and not riemann.network.SEGWIT: raise ValueError( 'Network {} does not support witness scripts.' .format(riemann.get_current_network_name())) output_script = bytearray() if type(pubkey) is not bytearray and type(pubkey) ...
def make_pkh_output_script(pubkey, witness=False)
bytearray -> bytearray
2.692927
2.548875
1.056516
''' byte-like, byte-like -> TxOut ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxOut( value=value, version=version, output_script=output_script) return tx.TxOut(value=value, output_script=output_script)
def _make_output(value, output_script, version=None)
byte-like, byte-like -> TxOut
6.039622
4.210248
1.434505
''' int, str -> TxOut ''' return _make_output( value=utils.i2le_padded(value, 8), output_script=make_sh_output_script(output_script, witness))
def make_sh_output(value, output_script, witness=False)
int, str -> TxOut
7.369151
4.936055
1.492923
''' int, bytearray -> TxOut ''' return _make_output( value=utils.i2le_padded(value, 8), output_script=make_pkh_output_script(pubkey, witness))
def make_pkh_output(value, pubkey, witness=False)
int, bytearray -> TxOut
6.446026
4.624394
1.393918
'''Generates OP_RETURN output for data less than 78 bytes. If data is 76 or 77 bytes, OP_PUSHDATA1 is included: <OP_RETURN><OP_PUSHDATA1><data len><data> If data is less than 76 bytes, OP_PUSHDATA1 is not included: <OP_RETURN><data len><data> 80 bytes is the default setting for an OP_RETURN outp...
def make_op_return_output(data)
Generates OP_RETURN output for data less than 78 bytes. If data is 76 or 77 bytes, OP_PUSHDATA1 is included: <OP_RETURN><OP_PUSHDATA1><data len><data> If data is less than 76 bytes, OP_PUSHDATA1 is not included: <OP_RETURN><data len><data> 80 bytes is the default setting for an OP_RETURN output scri...
3.977295
2.051568
1.938661
''' byte-like, int, int -> Outpoint ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredOutpoint(tx_id=tx_id_le, index=utils.i2le_padded(index, 4), tree=utils.i2le_padded(tree, 1)) return tx.Outpoint(tx_id=t...
def make_outpoint(tx_id_le, index, tree=None)
byte-like, int, int -> Outpoint
3.921103
3.362535
1.166115
''' str, str -> bytearray ''' stack_script += ' {}'.format( serialization.hex_serialize(redeem_script)) return serialization.serialize(stack_script)
def make_script_sig(stack_script, redeem_script)
str, str -> bytearray
11.953648
7.086501
1.68682
''' Outpoint, byte-like, byte-like, int -> TxIn ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxIn( outpoint=outpoint, sequence=utils.i2le_padded(sequence, 4)) return tx.TxIn(outpoint=outpoint, stack_script=stack_script, ...
def make_legacy_input(outpoint, stack_script, redeem_script, sequence)
Outpoint, byte-like, byte-like, int -> TxIn
4.094895
3.15491
1.297944
''' Outpoint, byte-like, byte-like, int -> (TxIn, InputWitness) ''' return (make_legacy_input(outpoint=outpoint, stack_script=stack_script, redeem_script=redeem_script, sequence=sequence), make_empty_wi...
def make_legacy_input_and_empty_witness(outpoint, stack_script, redeem_script, sequence)
Outpoint, byte-like, byte-like, int -> (TxIn, InputWitness)
3.671668
2.065017
1.778032
''' Outpoint, int -> TxIn ''' if 'decred' in riemann.get_current_network_name(): return tx.DecredTxIn( outpoint=outpoint, sequence=utils.i2le_padded(sequence, 4)) return tx.TxIn(outpoint=outpoint, stack_script=b'', redeem_script=b...
def make_witness_input(outpoint, sequence)
Outpoint, int -> TxIn
4.920357
4.058612
1.212325
''' Outpoint, int, list(bytearray) -> (Input, InputWitness) ''' if 'decred' in riemann.get_current_network_name(): return(make_witness_input(outpoint, sequence), make_decred_witness(value=kwargs['value'], height=kwargs['height'], ...
def make_witness_input_and_witness(outpoint, sequence, stack=None, **kwargs)
Outpoint, int, list(bytearray) -> (Input, InputWitness)
4.351899
3.394791
1.281934
''' int, list(TxIn), list(TxOut), int, list(InputWitness) -> Tx ''' n = riemann.get_current_network_name() if 'decred' in n: return tx.DecredTx( version=utils.i2le_padded(version, 4), tx_ins=tx_ins, tx_outs=tx_outs, lock_time=utils.i2le_padded(...
def make_tx(version, tx_ins, tx_outs, lock_time, expiry=None, value_balance=0, tx_shielded_spends=None, tx_shielded_outputs=None, tx_witnesses=None, tx_joinsplits=None, joinsplit_pubkey=None, joinsplit_sig=None, binding_sig=None)
int, list(TxIn), list(TxOut), int, list(InputWitness) -> Tx
1.748498
1.67933
1.041188
''' bytes -> bytes ''' length = tx.VarInt(len(byte_string)) return length.to_bytes() + byte_string
def length_prepend(byte_string)
bytes -> bytes
9.085526
5.966467
1.522765
'''Convert int to signed little endian (l.e.) hex for scripts Args: number (int): int value to convert to bytes in l.e. format Returns: (str): the hex-encoded signed LE number ''' if number == 0: return '00' for i in range(80): try: return num...
def i2le_script(number)
Convert int to signed little endian (l.e.) hex for scripts Args: number (int): int value to convert to bytes in l.e. format Returns: (str): the hex-encoded signed LE number
7.489786
2.968855
2.522786
''' byte-like -> bytes ''' h = hashlib.new('ripemd160') h.update(msg_bytes) return h.digest()
def rmd160(msg_bytes)
byte-like -> bytes
4.105526
3.051546
1.345392
''' byte-like -> bytes ''' h = hashlib.new('ripemd160') if 'decred' in riemann.get_current_network_name(): h.update(blake256(msg_bytes)) return h.digest() h.update(sha256(msg_bytes)) return h.digest()
def hash160(msg_bytes)
byte-like -> bytes
4.195704
3.841918
1.092086
''' byte-like -> bytes ''' if 'decred' in riemann.get_current_network_name(): return blake256(blake256(msg_bytes)) return hashlib.sha256(hashlib.sha256(msg_bytes).digest()).digest()
def hash256(msg_bytes)
byte-like -> bytes
5.302706
4.571821
1.159867