Example #1
0
def ms_update_progress(ms: Milestone, updated_progress):
    """
    Args:
        ms (Milestone):
            Milestone object containing specific attributes
        
        updated_progress (int):
            New progress of the milestone

    Return:
        (int): The avaliable tokens for the Milestone
    """
    storage = StorageManager()

    # If the updated progress is higher
    if updated_progress > ms.progress:

        # Clamp at 100%
        if updated_progress > 100:
            updated_progress = 100

        # Updates object variable
        ms.progress = updated_progress

        # Output milestone info
        updated_milestone_info = [
            ms.title, ms.subtitle, ms.extra_info_hash, updated_progress
        ]

        # Saving info to storage
        updated_milestone_info_serialized = storage.serialize_array(
            updated_milestone_info)
        storage.put_triple('MS', ms.project_id, ms.milestone_id,
                           updated_milestone_info_serialized)
Example #2
0
def fr_list_append(project_id, key, new_item):
    """Adds the input list of funding stages to storage (as serialized array)
    Args:
        project_id (list): ID for referencing the project
        new_list (list): list of funding stages to save to storage
    """
    storage = StorageManager()

    print('new_item')
    print(new_item)

    # Gets current stored list
    current_serialized_list = storage.get_double(project_id, key)

    # Converts serialized list to normal list
    current_list = storage.deserialize_bytearray(current_serialized_list)
    current_list_len = len(current_list)
    print('current_list_len')
    print(current_list_len)

    if current_list_len == 0:
        output_list = [new_item]

    else:
        output_list = current_list
        output_list.append(new_item)

    # Serializes list
    serialized_output_list = storage.serialize_array(output_list)
    print('serialized_output_list')
    print(serialized_output_list)

    # Saves updated serialized list to storage
    storage.put_double(project_id, key, serialized_output_list)
Example #3
0
def sts_add_to_total_circulation(sts: SmartTokenShare, amount: int):
    """
    Adds an amount of token to circlulation

    Args:
        sts (SmartTokenShare):
            Smart Token Share object containing specific attributes

        amount (int):
            amount of tokens added
    """
    storage = StorageManager()

    # Calculation
    sts.total_in_circulation = sts.total_in_circulation + amount

    # output STS info
    updated_sts_info = [
        sts.symbol, sts.decimals, sts.owner, sts.total_supply,
        sts.total_in_circulation
    ]

    # Save STS info
    updated_sts_info_serialized = storage.serialize_array(updated_sts_info)
    storage.put_double('STS', sts.project_id, updated_sts_info_serialized)
Example #4
0
def fs_add_to_circulation(fs: FundingStage, amount: int) -> bool:
    """
    Args:
        fs (FundingStage):
            Funding Stage object containing specific attributes

        amount (int):
            Amount of tokens added  
    """
    storage = StorageManager()

    # Calculation
    fs.in_circulation = fs.in_circulation + amount

    # Output STS info
    updated_fs_info = [
        fs.start_block, fs.end_block, fs.supply, fs.tokens_per_gas,
        fs.in_circulation
    ]

    # Serialize array and save to storage
    updated_fs_info_serialized = storage.serialize_array(updated_fs_info)
    storage.put_triple('FS', fs.project_id, fs.funding_stage_id,
                       updated_fs_info_serialized)

    # Update sts **
    sts = sts_get(fs.project_id)
    sts_add_to_total_circulation(sts, amount)

    return True
Example #5
0
def ms_create(project_id, milestone_id, title, subtitle,
              extra_info_hash) -> Milestone:
    """
    Creates a new Milestone using the input attributes, saves it to storage and returns
    a Milestone object
    Args:
        project_id (str):
            ID for referencing the project

        milestone_id (str):
            ID for referencing the Milestone
            
        title (str):
            Block to start fund

        subtitle (str):
            Block to end fund

        extra_info_hash (str):
            Supply of the token in this fs

    Return:
        (Milestone):
            Returns a Milestone object containing these attributes
    """
    # init objects
    storage = StorageManager()
    ms = Milestone()

    # Saves vars to object
    ms.project_id = project_id
    ms.milestone_id = milestone_id
    ms.title = title
    ms.subtitle = subtitle
    ms.extra_info_hash = extra_info_hash

    # Sets progress to 0
    ms.progress = 0

    # Info structure
    milestone_info = [title, subtitle, extra_info_hash, 0]

    # Saving info to storage
    milestone_info_serialized = storage.serialize_array(milestone_info)
    storage.put_triple('MS', project_id, milestone_id,
                       milestone_info_serialized)

    return ms
Example #6
0
def fs_create(project_id, funding_stage_id, start_block, end_block, supply,
              tokens_per_gas) -> FundingStage:
    """
    Creates a new Funding Stage using the input attributes, saves it to storage and returns
    a FundingStage object
    Args:
        project_id (str):
            ID for referencing the project

        funding_stage_id (str):
            ID for referencing the funding stage
            
        start_block (int):
            Block to start fund

        end_block (int):
            Block to end fund

        supply (int):
            Supply of the token in this fs

        tokens_per_gas (int):
            Token to gas ratio
    Return:
        (FundingStage):
            Returns a funding stage object containing these attributes
    """
    # init objects
    storage = StorageManager()
    fs = FundingStage()

    # Saves vars to object
    fs.project_id = project_id
    fs.funding_stage_id = funding_stage_id
    fs.start_block = start_block
    fs.end_block = end_block
    fs.supply = supply
    fs.tokens_per_gas = tokens_per_gas
    fs.in_circulation = 0

    # Info structure
    fs_info = [start_block, end_block, supply, tokens_per_gas, 0]

    # Saving info to storage
    fs_info_serialized = storage.serialize_array(fs_info)
    storage.put_triple('FS', project_id, funding_stage_id, fs_info_serialized)

    return fs
Example #7
0
    def kyc_submit(self, project_id, address, phys_address, first_name, last_name, id_type, id_number, id_expiry, file_location, file_hash):
        """    
        Submits a KYC information to the smart contract 
        Args:
            sts (SmartTokenShare):
                Smart Token Share reference object
            
            address (str):
                Wallet address to whitelist

            phys_address (str):
                Physical Address

            first_name (str):
                First Name

            last_name (str):
                Last Name

            id_type (str):
                Id type, eg passport, drivers licence

            id_number (str):
                ID Number

            id_expiry (str):
                Expiry data

            file_location (str):
                web location where file is stored

            file_hash (str):
                hash of file
        """
        storage = StorageManager()

        # Checking its the correct address
        if CheckWitness(address):
            if len(address) == 20:

                # Combines all args into a single list
                output_kyc_array = list(address, phys_address, first_name, last_name, id_type, id_number, id_expiry, file_location, file_hash)
                
                # Serialises list into a single bytearray, and stores that into storeage
                serialized_kyc = storage.serialize_array(output_kyc_array)
                storage.put_triple('KYC', project_id, address, serialized_kyc)
Example #8
0
def sts_create(project_id, symbol, decimals, owner,
               total_supply) -> SmartTokenShare:
    """
    Args:
        project_id (str):
            ID for referencing the project

        symbol (str):
            Representation symbol
            
        decimals (int):
            Amount of decimal places, default 8

        owner (bytes):
            Owner of the token

        total_supply (int):
            total supply of the token
    Return:
        (SmartTokenShare): 
            Returns a Smart Token Share object containing these attributes
    """
    # init objects
    storage = StorageManager()
    sts = SmartTokenShare()

    # Saves vars to object
    sts.project_id = project_id
    sts.symbol = symbol
    sts.decimals = decimals
    sts.owner = owner
    sts.total_supply = total_supply

    # Default circulation
    sts.total_in_circulation = 0

    # Info structure
    sts_info = [symbol, decimals, owner, total_supply, 0]

    # Will only save to storage if none exsits for this project_id
    if not storage.get_double('STS', project_id):
        sts_info_serialized = storage.serialize_array(sts_info)
        storage.put_double('STS', project_id, sts_info_serialized)

    return sts