def test_sequence(self): sequence_0 = Sequence() self.assertEqual(sequence_0, MAX_SEQUENCE) self.assertTrue(sequence_0.is_max()) self.assertFalse(sequence_0.is_relative()) self.assertIsNone(sequence_0.relative_blocks()) self.assertIsNone(sequence_0.relative_time()) self.assertEqual(Sequence.parse(BytesIO(sequence_0.serialize())), sequence_0) time_amount = 512 * 1000 sequence_1 = Sequence.from_relative_time(time_amount) self.assertFalse(sequence_1.is_comparable(sequence_0)) self.assertIsNone(sequence_1.relative_blocks()) self.assertEqual(sequence_1.relative_time(), time_amount) self.assertEqual(Sequence.parse(BytesIO(sequence_1.serialize())), sequence_1) blocks_amount = 144 sequence_2 = Sequence.from_relative_blocks(blocks_amount) self.assertIsNone(sequence_2.relative_time()) self.assertEqual(sequence_2.relative_blocks(), blocks_amount) self.assertFalse(sequence_1.is_comparable(sequence_2)) sequence_3 = Sequence.from_relative_time(512 * 100) self.assertTrue(sequence_3 < sequence_1) with self.assertRaises(ValueError): sequence_2 < sequence_0 with self.assertRaises(ValueError): sequence_2 < sequence_1 with self.assertRaises(ValueError): Sequence(-1) with self.assertRaises(ValueError): Sequence(1 << 32)
def degrading_multisig_tap_node(self, sequence_block_interval=None, sequence_time_interval=None): """Can unlock with multisig as k-of-n, or (k-1)-of-n after a sequence_block_interval/sequence_time_interval amount of time, (k-2)-of-n after 2*sequence_block_interval/sequence_time_interval amount of time, (k-3)-of-n after 3*sequence_block_interval/ sequence_time_interval amount of time and so on.""" leaves = [] for num_keys_needed in range(self.k, 0, -1): if num_keys_needed == self.k: sequence = None elif sequence_block_interval: sequence = Sequence.from_relative_blocks( sequence_block_interval * (self.k - num_keys_needed)) elif sequence_time_interval: sequence = Sequence.from_relative_time( sequence_time_interval * (self.k - num_keys_needed)) for pubkeys in combinations(self.points, num_keys_needed): tap_script = MultiSigTapScript(pubkeys, num_keys_needed, sequence=sequence) leaves.append(tap_script.tap_leaf()) return TapBranch.combine(leaves)