Пример #1
0
def rl_make_aggregation_puzzle(wallet_puzzle):
    """
    If Wallet A wants to send further funds to Wallet B then they can lock them up using this code
    Solution will be (my_id wallet_coin_primary_input wallet_coin_amount)
    """

    MOD = load_clvm("../puzzles/rl_aggregation.clvm")
    return MOD.curry(wallet_puzzle)
Пример #2
0
def rl_puzzle_for_pk(
    pubkey: bytes,
    rate_amount: uint64,
    interval_time: uint64,
    origin_id: bytes32,
    clawback_pk: bytes,
):
    """
    Solution to this puzzle must be in format:
    (1 my_parent_id, my_puzzlehash, my_amount, outgoing_puzzle_hash, outgoing_amount,
     min_block_time, parent_parent_id, parent_amount, fee)
    RATE LIMIT LOGIC:
    M - chia_per_interval
    N - interval_blocks
    V - amount being spent
    MIN_BLOCK_AGE = V / (M / N)
    if not (min_block_age * M >=  V * N) do X (raise)
    ASSERT_COIN_BLOCK_AGE_EXCEEDS min_block_age
    """

    MOD = load_clvm("../puzzles/rl.clvm")
    return MOD.curry(pubkey, rate_amount, interval_time, origin_id,
                     clawback_pk)
from unittest import TestCase

from src.types.program import SerializedProgram, Program
from src.wallet.puzzles.load_clvm import load_clvm


SHA256TREE_MOD = load_clvm("sha256tree_module.clvm")


# TODO: test multiple args
class TestSerializedProgram(TestCase):
    def test_tree_hash(self):
        p = SHA256TREE_MOD
        s = SerializedProgram.from_bytes(bytes(SHA256TREE_MOD))
        self.assertEqual(s.get_tree_hash(), p.get_tree_hash())

    def test_program_execution(self):
        p_result = SHA256TREE_MOD.run(SHA256TREE_MOD)
        sp = SerializedProgram.from_bytes(bytes(SHA256TREE_MOD))
        cost, sp_result = sp.run_with_cost(sp)
        self.assertEqual(p_result, sp_result)

    def test_serialization(self):
        s0 = SerializedProgram.from_bytes(b"\x00")
        p0 = Program.from_bytes(b"\x00")
        print(s0, p0)
        # TODO: enable when clvm updated for minimal encoding of zero
        # self.assertEqual(bytes(p0), bytes(s0))
Пример #4
0
from typing import Optional

from src.types.coin import Coin
from src.types.program import Program
from src.types.sized_bytes import bytes32
from src.wallet.puzzles.load_clvm import load_clvm


MOD = load_clvm("genesis-by-puzzle-hash-with-0.clvm", package_or_requirement=__name__)


def create_genesis_puzzle_or_zero_coin_checker(genesis_puzzle_hash: bytes32) -> Program:
    """
    Given a specific genesis coin id, create a `genesis_coin_mod` that allows
    both that coin id to issue a cc, or anyone to create a cc with amount 0.
    """
    genesis_coin_mod = MOD
    return genesis_coin_mod.curry(genesis_puzzle_hash)


def genesis_puzzle_hash_for_genesis_coin_checker(
    genesis_coin_checker: Program,
) -> Optional[bytes32]:
    """
    Given a `genesis_coin_checker` program, pull out the genesis puzzle hash.
    """
    r = genesis_coin_checker.uncurry()
    if r is None:
        return r
    f, args = r
    if f != MOD:
from src.wallet.puzzles.load_clvm import load_clvm

GENERATOR_MOD = load_clvm("generator.clvm", package_or_requirement=__name__)
GENERATOR_FOR_SINGLE_COIN_MOD = load_clvm("generator_for_single_coin.clvm",
                                          package_or_requirement=__name__)
from typing import Optional

from src.types.coin import Coin
from src.types.program import Program
from src.types.sized_bytes import bytes32
from src.wallet.puzzles.load_clvm import load_clvm

MOD = load_clvm("genesis-by-coin-id-with-0.clvm",
                package_or_requirement=__name__)


def create_genesis_or_zero_coin_checker(genesis_coin_id: bytes32) -> Program:
    """
    Given a specific genesis coin id, create a `genesis_coin_mod` that allows
    both that coin id to issue a cc, or anyone to create a cc with amount 0.
    """
    genesis_coin_mod = MOD
    return genesis_coin_mod.curry(genesis_coin_id)


def genesis_coin_id_for_genesis_coin_checker(
    genesis_coin_checker: Program, ) -> Optional[bytes32]:
    """
    Given a `genesis_coin_checker` program, pull out the genesis coin id.
    """
    r = genesis_coin_checker.uncurry()
    if r is None:
        return r
    f, args = r
    if f != MOD:
        return None
Пример #7
0
from src.wallet.puzzles.load_clvm import load_clvm

CC_MOD = load_clvm("cc.clvm", package_or_requirement=__name__)
LOCK_INNER_PUZZLE = load_clvm("lock.inner.puzzle.clvm", package_or_requirement=__name__)
from unittest import TestCase

from src.types.blockchain_format.program import Program
from src.util.byte_types import hexstr_to_bytes
from src.wallet.puzzles.load_clvm import load_clvm

DESERIALIZE_MOD = load_clvm("chialisp_deserialisation.clvm",
                            package_or_requirement="src.wallet.puzzles")


def serialized_atom_overflow(size):
    if size == 0:
        size_blob = b"\x80"
    elif size < 0x40:
        size_blob = bytes([0x80 | size])
    elif size < 0x2000:
        size_blob = bytes([0xC0 | (size >> 8), (size >> 0) & 0xFF])
    elif size < 0x100000:
        size_blob = bytes(
            [0xE0 | (size >> 16), (size >> 8) & 0xFF, (size >> 0) & 0xFF])
    elif size < 0x8000000:
        size_blob = bytes([
            0xF0 | (size >> 24),
            (size >> 16) & 0xFF,
            (size >> 8) & 0xFF,
            (size >> 0) & 0xFF,
        ])
    elif size < 0x400000000:
        size_blob = bytes([
            0xF8 | (size >> 32),
            (size >> 24) & 0xFF,
Пример #9
0
from src.wallet.puzzles.load_clvm import load_clvm

CC_MOD = load_clvm("cc.clvm", package_or_requirement=__name__)