Exemple #1
0
    def test_add_to_circulation(self):
        fs = FundingStage()

        # Setting default info
        storage = StorageManager()
        storage.put_triple('FS', self.test_project_id,
                           self.test_funding_stage_id, self.test_fs_info)

        # # Running add_to_crowdfund_circulation()
        # fs.add_to_circulation(self.test_project_id, self.test_funding_stage_id, self.test_add_amount)
        # fs.add_to_circulation(self.test_project_id, self.test_funding_stage_id, self.test_add_amount)
        # fs.add_to_circulation(self.test_project_id, self.test_funding_stage_id, self.test_add_amount)

        in_circ = fs.get_circulation(self.test_project_id,
                                     self.test_funding_stage_id)

        test_in_circ = self.test_add_amount * 3

        # Check Test
        if in_circ == test_in_circ:
            print('test_add_to_circulation PASSED')
            return True

        print('test_add_to_circulation FAILED')
        return False
Exemple #2
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)
Exemple #3
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
Exemple #4
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
Exemple #5
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
Exemple #6
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)
Exemple #7
0
    def test_exchange(self):

        fs = FundingStage()
        attachments = get_asset_attachments()

        # Test vars
        tokens_per_gas = 100
        test_exchanged_sts = attachments.gas_attached * tokens_per_gas / 100000000

        # Sets balance to 0
        storage = StorageManager()
        storage.put_double(self.test_project_id, attachments.sender_addr, 0)

        # Registers KYC address
        storage.put_triple(self.test_project_id, 'KYC_address',
                           self.test_address1, True)

        # Setting default info
        storage = StorageManager()
        storage.delete_triple('FS', self.test_project_id,
                              self.test_funding_stage_id)

        # Creates new test fund
        fs.create(self.test_project_id, self.test_funding_stage_id, 1, 999999,
                  10000, tokens_per_gas)

        # Testing exchange method and checking stored balance
        fs.exchange(self.test_project_id, self.test_funding_stage_id)
        result1 = storage.get_double(self.test_project_id,
                                     attachments.sender_addr)

        # Testing exchange method and checking stored balance again (should double)
        fs.exchange(self.test_project_id, self.test_funding_stage_id)
        result2 = storage.get_double(self.test_project_id,
                                     attachments.sender_addr)

        # Check Test
        print('CHECK')

        if result1 == test_exchanged_sts and result2 == test_exchanged_sts * 2:
            print('test_exchange PASSED')
            return True

        print('test_exchange FAILED')
        return False
Exemple #8
0
    def kyc_register(self, project_id, addresses):
        """    
        Registers all input addresses 
        Args:
            args (list):
                list a list of arguments
            
            sts (SmartTokenShare):
                Smart Token Share reference object

        Return:
            (int): The number of addresses to registered for KYC
        """
        # Gets sts object
        sts = sts_get(project_id)
        print('kyc_register')
        print(sts.owner)
        ok_count = 0
        
        check_addr = sts.owner
        
        check = CheckWitness(check_addr)
        print('check')
        print(check)

        if CheckWitness(check_addr):
            for address in addresses:

                if len(address) == 20:

                    storage = StorageManager()
                    storage.put_triple(project_id, 'KYC_address', address, True)

                    OnKYCRegister(project_id, address)
                    ok_count += 1
        else:
            print(sts.owner)
            print('Only the project owner can register kyc addresses')            
            return 0

        return ok_count
Exemple #9
0
    def test_can_exchange(self):
        fs = FundingStage()

        attachments = get_asset_attachments()

        # Registers KYC address
        storage = StorageManager()
        storage.put_triple(self.test_project_id, 'KYC_address',
                           self.test_address2, True)

        fs.create(self.test_project_id, 'test_can_exchange', 1, 999999, 10000,
                  100)
        test_result = fs.can_exchange(self.test_project_id,
                                      'test_can_exchange', attachments)

        # Check Test
        if test_result:
            print('test_can_exchange PASSED')
            return True

        print('test_can_exchange FAILED')
        return False
Exemple #10
0
    def test_available_amount(self):
        fs = FundingStage()

        # Running crowdfund_available_amount()
        # fs.create(self.test_project_id, 'test_available_amount', self.test_start_block, self.test_end_block, self.test_supply, self.test_tokens_per_gas)
        storage = StorageManager()
        storage.put_triple('FS', self.test_project_id, 'test_available_amount',
                           self.test_fs_info)

        available = fs.available_amount(self.test_project_id,
                                        'test_available_amount')
        print('available')
        print(available)

        test_available = self.test_supply - 0

        # Check Test
        if available == test_available:
            print('test_available_amount PASSED')
            return True

        print('test_available_amount FAILED')
        return False
Exemple #11
0
def fs_set_addr_balance(fs: FundingStage, addr, new_balance):
    storage = StorageManager()
    storage.put_triple(fs.project_id, fs.funding_stage_id, addr, new_balance)
Exemple #12
0
    def test(self, operation, args):

        storage = StorageManager()
        attachments = get_asset_attachments()

        if operation == 'create_all':
            print('create_all')

            sts_create(self.project_id, self.symbol, self.decimals, self.owner,
                       self.total_supply)
            fs_create(self.project_id, 'first_stage', 1, 999999, 1000, 100)
            fs_create(self.project_id, 'second_stage', 1, 12750, 500, 100)
            fs_create(self.project_id, 'third_stage', 1, 12450, 100, 100)
            fs_create(self.project_id, 'fourth_stage', 1, 99999, 200, 100)

            fss = [
                'first_stage', 'second_stage', 'third_stage', 'fourth_stage'
            ]

            ms_create(self.project_id, 'first_mile', 'First', 'sub', 'hash')
            ms_create(self.project_id, 'second_mile', 'First', 'sub', 'hash')
            ms_create(self.project_id, 'third_mile', 'First', 'sub', 'hash')
            ms_create(self.project_id, 'fourth_mile', 'First', 'sub', 'hash')

            mss = ['first_mile', 'second_mile', 'third_mile', 'fourth_mile']

            admins = [self.owner]

            fr_add_funding_stages(self.project_id, fss)
            fr_add_milestones(self.project_id, mss)
            fr_add_project_admins(self.project_id, admins)
            fr_set_active_index(self.project_id, 0)

            return True

        if operation == 'get_funding_stages':
            print('get_funding_stages')

            stages = fr_get_funding_stages(self.project_id)
            print(stages)

            return stages

        if operation == 'kyc':
            print('attachments.sender_addr')
            print(attachments.sender_addr)
            storage.put_triple(self.project_id, 'KYC_address', self.owner,
                               True)

        if operation == 'calim_test':
            storage.put_double('CLAIM', attachments.sender_addr,
                               attachments.gas_attached)

        if operation == 'contribute':
            print('#contribute')
            # Registers KYC address
            storage.put_triple(self.project_id, 'KYC_address',
                               attachments.sender_addr, True)

            active_idx = fr_get_active_index(self.project_id)
            funding_stages = fr_get_funding_stages(self.project_id)
            active_funding_stage = funding_stages[active_idx]

            fs = fs_get(self.project_id, active_funding_stage)

            fs_contribute(fs)
            # storage.put_double('CLAIM', attachments.sender_addr, attachments.gas_attached)
            print('contribute#')

        if operation == 'get_idx':
            active_idx = fr_get_active_index(self.project_id)
            print(active_idx)
            return active_idx

        if operation == 'get_active_fs':
            active_idx = fr_get_active_index(self.project_id)
            funding_stages = fr_get_funding_stages(self.project_id)
            active_funding_stage = funding_stages[active_idx]
            print(active_funding_stage)
            return active_funding_stage

        # 4 Put == (1 GAS per KB)
        # 7 Get == 0.7 GAS
        if operation == 'contribute_fs':
            print('#contribute_fs')

            active_funding_stage = args[0]

            fs = fs_get(self.project_id, active_funding_stage)
            fs_contribute(fs)

            print('contribute_fs#')

        if operation == 'balance':
            print('balance')
            # bal = storage.get_double(self.project_id, attachments.sender_addr)
            fs_id = args[0]
            addr = args[1]

            fs = fs_get('projectID', fs_id)
            bal = fs_get_addr_balance(fs, addr)
            print(bal)

        if operation == 'funding_stage_status':
            print('#funding_stage_status')
            active_idx = fr_get_active_index(self.project_id)
            funding_stages = fr_get_funding_stages(self.project_id)
            active_funding_stage = funding_stages[active_idx]

            fs = fs_get(self.project_id, active_funding_stage)
            status = fs_status(fs)

            print('funding_stage_status#')
            print(status)
            return status

        if operation == 'current_index':
            active_idx = fr_get_active_index(self.project_id)
            print(active_idx)
            return active_idx

        if operation == 'milestone_progress':
            print('#milestone_progress')
            active_idx = fr_get_active_index(self.project_id)
            milestones = fr_get_milestones(self.project_id)
            active_milestone = milestones[active_idx]

            ms = ms_get(self.project_id, active_milestone)
            prog = ms_get_progress(ms)
            print('milestone_progress#')
            print(prog)
            return prog

        if operation == 'complete_milestone':
            print('complete_milestone')
            fr_update_milestone_progress(self.project_id, 100)

        if operation == 'sts_get':
            sts = sts_get('projectID')
            arg = args[0]

            if arg == 'project_id':
                return sts.project_id

            if arg == 'symbol':
                return sts.symbol

            if arg == 'decimals':
                return sts.decimals

            if arg == 'owner':
                return sts.owner

            if arg == 'total_supply':
                return sts.total_supply

            if arg == 'total_in_circulation':
                return get_total_in_circulation(sts)

        if operation == 'fs_get':
            active_idx = fr_get_active_index('projectID')
            funding_stages = fr_get_funding_stages('projectID')
            active_funding_stage = funding_stages[active_idx]

            fs = fs_get('projectID', active_funding_stage)

            arg = args[0]
            # attr = fs_get_attr(fs, arg)

            if arg == 'project_id':
                return fs.project_id

            if arg == 'funding_stage_id':
                return fs.funding_stage_id

            if arg == 'start_block':
                return fs.start_block

            if arg == 'end_block':
                return fs.end_block

            if arg == 'supply':
                return fs.supply

            if arg == 'tokens_per_gas':
                return fs.tokens_per_gas

            if arg == 'in_circulation':
                return get_in_circulation(fs)

        if operation == 'fs_claim_contributions':
            fs_id = args[0]
            deposit_addr = args[1]
            fs = fs_get('projectID', fs_id)
            fs_claim_contributions(fs, deposit_addr)

        if operation == 'fs_claim_fee':
            print('fs_claim_fee')
            fs_id = args[0]
            owner_addr = b'j\x1agL0\xff\x926\x02\xde.a\x1fR\xe3FT\x0f\xba|'
            fs = fs_get('projectID', fs_id)
            fs_claim_system_fee(fs, owner_addr)

        if operation == 'fs_refund':
            fs_id = args[0]
            refund_addr = args[1]
            fs = fs_get('projectID', fs_id)
            fs_refund(fs, refund_addr)

        return True