def _outputid_new(self, specifier, index): encoder = encoder_sia_get() encoder.add_array(specifier) encoder.add_array(self._id_input_compute()) encoder.add_int(index) hash = bytearray.fromhex(blake2_string(encoder.data)) return Hash(value=hash)
def signature_hash_get(self, *extra_objects): """ signature_hash_get is used to get the signature hash for this Transaction, which are used to proof the authenticity of the transaction. """ input = self._signature_hash_input_get(*extra_objects) return bytes.fromhex(blake2_string(input))
def _checksum(self): if self._type == UnlockHashType.NIL: return b'\x00' * UnlockHash._CHECKSUM_SIZE e = encoder_rivine_get() e.add_int8(int(self._type)) e.add(self._hash) return bytearray.fromhex(blake2_string(e.data))
def from_unlockhash(cls, unlockhash): """ Create an ERC20 Address from a TFT Address (type: UnlockHash). """ e = encoder_sia_get() unlockhash.sia_binary_encode(e) hash = bytes.fromhex(blake2_string(e.data)) return cls(value=hash[Hash.SIZE - ERC20Address.SIZE:])
def unlockhash(self): uhs = sorted(self.unlockhashes, key=lambda uh: str(uh)) tree = MerkleTree(hash_func=lambda o: bytes.fromhex(blake2_string(o))) tree.push(sia_encode(len(uhs))) for uh in uhs: tree.push(sia_encode(uh)) tree.push(sia_encode(self.required_signatures)) return UnlockHash(type=UnlockHashType.MULTI_SIG, hash=tree.root())
def unlockhash(self): e = encoder_rivine_get() self.sia_binary_encode_data(e) # need to encode again to add the length data = e.data e = encoder_sia_get() e.add_slice(data) hash = bytearray.fromhex(blake2_string(e.data)) return UnlockHash(type=UnlockHashType.ATOMIC_SWAP, hash=hash)
def test_basic_merkletree(): tree = Tree(hash_func=lambda o: bytes.fromhex(blake2_string(o))) tree.push(bytearray([1])) tree.push(bytearray([2])) tree.push(bytearray([3])) tree.push(bytearray([4])) tree.push(bytearray([5])) root = tree.root().hex() assert root == '0002789a97a9feee38af3709f06377ef0ad7d91407cbcad1ccb8605556b6578e' print('Root is {}'.format(root))
def unlockhash(self): """ Return the unlock hash generated from this public key. """ e = encoder_sia_get() self.sia_binary_encode(e) # need to encode again to add the length data = e.data e = encoder_sia_get() e.add_slice(data) hash = bytearray.fromhex(blake2_string(e.data)) return UnlockHash(type=UnlockHashType.PUBLIC_KEY, hash=hash)