コード例 #1
0
ファイル: formats.py プロジェクト: gitter-badger/txsc
def int_to_bytearray(value):
    """Encode an integer as a byte array or opcode value."""
    try:
        value = int(CScriptOp.encode_op_n(value))
    except ValueError:
        pass
    return _bignum.bn2vch(value)
コード例 #2
0
def push_script(x):
    """Return hex-encoded PUSH operation.

    Args:
        x(str): Hex-encoded string to push.
    """
    return CScriptOp.encode_op_pushdata(x.decode('hex')).encode('hex')
コード例 #3
0
	def send(self, amt=MIN_TAX, tax=MIN_TAX, dummy=False):
		(i, s) = self._i(amt, tax)
		o = self._o(s, amt, tax, i)
		self._create(i, o)

		assert(s - tax == round(sum([ v * 10 ** 8 for k, v in o.items() ])))

		# get the unpacked data and edit to suit our needs
		d = self.tx.unpack()

		# prep the OP_RETURN payload
		p = CScriptOp.encode_op_pushdata(self.msg)

		# append OP_RETURN tx out
		d['vout'].append({
			'value' : 0,
			'scriptPubKey' : RawTx.BinaryStream._unpack_hex(p) + '6a',
		})
		self.tx.pack(d)

		# signed, sealed, delivered
		# we're using the base _CALL() function to bypass bitcoin.rpc's object shenanigans
		tx = RawTx(self.proxy, self.proxy._call('signrawtransaction', self.tx.raw)['hex'])

		if not dummy:
			self.txid = self.proxy._call('sendrawtransaction', tx.raw)

		return str(self.txid)
コード例 #4
0
ファイル: utils.py プロジェクト: aesedepece/hashmal
def push_script(x):
    """Return hex-encoded PUSH operation.

    Args:
        x(str): Hex-encoded string to push.
    """
    return CScriptOp.encode_op_pushdata(x.decode('hex')).encode('hex')
コード例 #5
0
def int_to_bytearray(value, as_opcode=True):
    """Encode an integer as a byte array or opcode value."""
    if as_opcode:
        try:
            value = int(CScriptOp.encode_op_n(value))
        except ValueError:
            pass
    return _bignum.bn2vch(value)[::-1]
コード例 #6
0
def bytearray_to_int(data, decode_small_int=True):
    """Decode a byte array into an integer.

    If decode_small_int is True, a small integer will
    be returned if data is a small int opcode.
    """
    num = _bignum.vch2bn(data[::-1])
    # Decode num if it's a small integer.
    if decode_small_int:
        try:
            return CScriptOp(num).decode_op_n()
        except Exception:
            pass
    return num
コード例 #7
0
ファイル: keys.py プロジェクト: mickeystone/bitcoin_spv
    def add_private_key(self):
        seckey_str = input('\nInsert private key (WIF-compressed format):')
        if len(seckey_str) != 52 or (seckey_str[0] != 'K'
                                     and seckey_str[0] != 'L'):
            print("The key format is not valid!")
            return
        seckey = CBitcoinSecret(seckey_str)
        '''
        Calculate and store each data element of the scriptPubKey/scriptSig related to this private key.
        These data elements will be used in the Bloom Filters.
         
        From BIP 37:
        For each output, test each data element of the output script. This means each hash and key in the output script is tested independently. 
        For each input, test each data element of the input script (note: input scripts only ever contain data elements).
        
        The default scriptPubKey/scriptSig used by Bitcoin Core 0.16.0 are:
        - scriptPubKey: OP_HASH160 [20-byte-hash of {OP_0 hash160[pubkey]}] OP_EQUAL
        - scriptSig: 0x16 OP_0 hash160[pubkey]
        
        Note: 0x16 => The next opcode bytes is data to be pushed onto the stack

        The data element of the scriptSig should be only hash160[pubkey].
        Using only that data element the bloom filter doesn't work properly.
        Instead the filter works well using OP_0 hash160[pubkey].
        '''
        scriptPubKey_data_element = bitcoin.core.Hash160(
            CScript([OP_0, bitcoin.core.Hash160(seckey.pub)]))
        scriptSig_data_element = CScript(
            [OP_0, bitcoin.core.Hash160(seckey.pub)])
        # Calculate and store also scriptPubKey/scriptSig
        scriptSig = CScript(
            [CScriptOp(0x16), OP_0,
             bitcoin.core.Hash160(seckey.pub)])
        scriptPubKey = CScript([OP_0, bitcoin.core.Hash160(seckey.pub)
                                ]).to_p2sh_scriptPubKey()
        self.keys[seckey_str] = {
            "data_elements":
            [b2x(scriptPubKey_data_element),
             b2x(scriptSig_data_element)],
            "scriptSig":
            b2x(scriptSig),
            "scriptPubKey":
            b2x(scriptPubKey)
        }
        self.save_to_file()
コード例 #8
0
def scriptstuff2dict(opcode, data, idx):
    return {
        'opcode': str(CScriptOp(opcode)),
        'data': b2lx(data) if data else None,
        'sop_idx': idx
    }
コード例 #9
0
 def is_witness_scriptpubkey(self):
     """Returns true if this is a scriptpubkey signaling segregated witness
     data. """
     return 3 <= len(self) <= 42 and CScriptOp(
         struct.unpack('<b', self[0:1])[0]).is_small_int()
コード例 #10
0
    OP_CHECKSEQUENCEVERIFY,
    OP_EQUALVERIFY,
    OP_CHECKMULTISIG,
    OP_DUP,
    OP_HASH160,
    OP_CHECKSIG,
    OP_VERIFY,
    CScript,
    CScriptOp,
)
from naive_eval import eval_script

s = eval_script([], CScript([]))
print("blank is fine", len(s))

n = CScriptOp.encode_op_pushdata(b"qowie")
s = eval_script([n], CScript([n, OP_EQUALVERIFY]))
print("equalverify is fine", len(s))

s = eval_script(
    [
        CScriptOp.encode_op_pushdata(
            unhexlify(
                "30450220377bf4cab9bbdb219f1b0cca56f4a39fbf787d6fa9d04e248101d498de991d30022100b8e0c72dfab9a0d88eb2703c62e0e57ab2cb906e8f156b7641c2f0e24b8bba2b01"
            )),
    ],
    CScript([
        CScriptOp.encode_op_pushdata(
            unhexlify(
                "045e9392308b08d0d663961463b6cd056a66b757a2ced9dde197c21362360237f231b80ea66315898969f5c079f0ba3fc1c0661ed8c853ad15043f22f2b7779c95"
            )),
コード例 #11
0
ファイル: utils.py プロジェクト: mtrajano/hashmal
def push_script(x):
    return CScriptOp.encode_op_pushdata(x.decode('hex')).encode('hex')
コード例 #12
0
def push_script(x):
    return CScriptOp.encode_op_pushdata(x.decode('hex')).encode('hex')