def validate_hash(self, reveal_hash: bytes, block_idx: int, stake_address: bytes = None) -> bool: if stake_address not in self._data.sv_dict: return False sv = StakeValidator(self._data.sv_dict[stake_address]) result = sv.validate_hash(reveal_hash, block_idx) self._data.sv_dict[stake_address].CopyFrom(sv.pbdata) return result
def test_create2(self): alice_xmss = get_alice_xmss() slave_xmss = XMSS(alice_xmss.height, alice_xmss.get_seed()) h0 = sha256(b'hashchain_seed') h1 = sha256(h0) h2 = sha256(h1) h3 = sha256(h2) stake_transaction = StakeTransaction.create(activation_blocknumber=0, xmss=alice_xmss, slavePK=slave_xmss.pk(), hashchain_terminator=h3) sv = StakeValidator(100, stake_transaction) self.assertTrue(sv.validate_hash(h0, 2)) self.assertTrue(sv.validate_hash(h2, 0)) self.assertTrue(sv.validate_hash(h2, 0)) self.assertTrue(sv.validate_hash(h1, 1)) self.assertTrue(sv.validate_hash(h0, 2))