コード例 #1
0
def do_approve(ctx, t_owner, t_spender, amount):
    if len(t_spender) != 20:
        return False

    if not CheckWitness(t_owner):
        return False

    if amount < 0:
        return False

    # Token owner logic to not touch the team funding and the company reserve
    # When making transfers
    from_balance = Get(ctx, t_owner)

    if CheckWitness(TOKEN_OWNER):
        team_reserve = Get(ctx, TEAM_RESERVE_KEY)
        company_reserve = Get(ctx, COMPANY_RESERVE_KEY)
        from_balance = from_balance - team_reserve
        from_balance = from_balance - company_reserve

    if from_balance >= amount:

        approval_key = concat(t_owner, t_spender)

        if amount == 0:
            Delete(ctx, approval_key)
        else:
            Put(ctx, approval_key, amount)

        OnApprove(t_owner, t_spender, amount)

        return True

    return False
コード例 #2
0
def kyc_register(ctx, args):
    """
    Register a list of addresses for KYC

    :param ctx:GetContext() used to access contract storage
    :param args:list a list of addresses to register.
        If called by KYC admin that is not token owner,
        first address must be address of KYC admin.

    :return:int The number of addresses registered for KYC
    """

    ok_count = 0

    canRegister = CheckWitness(TOKEN_OWNER)

    if not canRegister and get_kyc_admin_status(ctx, args[0]) and CheckWitness(
            args[0]):
        canRegister = True
        args.remove(0)

    if canRegister:
        for address in args:
            # validate the address is 20 bytes
            if len(address) == 20:
                Put(ctx, concat(KYC_KEY, address), True)
                OnKYCRegister(address)
                ok_count += 1

    return ok_count
コード例 #3
0
def kyc_deregister(ctx, args):
    """
    Deregister a list of addresses from KYC

    :param ctx:GetContext() used to access contract storage
    :param args:list a list of addresses to deregister

    :return:int The number of addresses deregistered from KYC
    """

    ok_count = 0

    canRegister = CheckWitness(TOKEN_OWNER)

    if not canRegister and get_kyc_admin_status(ctx, args[0]) and CheckWitness(
            args[0]):
        canRegister = True
        args.remove(0)

    if canRegister:
        for address in args:
            if len(address) == 20:
                Delete(ctx, concat(KYC_KEY, address))
                OnKycDeregister(address)
                ok_count += 1

    return ok_count
コード例 #4
0
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        is_owner = CheckWitness(CONTRACT_OWNER)
        if is_owner:
            return True
        else:
            return False
    elif trigger == Application():
        sender = args[0]
        authorized = CheckWitness(sender)
        """
            Make sure that invoker is valid
        """
        if not authorized:
            Notify("Not authorized")
            return False
        Log("test")
        Notify(len(args))
        """
            query operations    
        """
        if operation == "sendMessage" and len(args) == 4:
            Notify("In operation sendMessage")
            return sendMessage(args)
        else:
            return False
    return False
コード例 #5
0
def company_approve(ctx, t_owner, t_spender):
    if not CheckWitness(TOKEN_OWNER):
        print("Must be token owner to approve funds")
        return False

    if len(t_spender) != 20:
        return False

    if not CheckWitness(t_owner):
        return False

    company_reserv_amount = Get(ctx, COMPANY_RESERVE_KEY)

    if company_reserv_amount <= 0:
        return False

    if Get(ctx, t_owner) >= amount:
        approval_first_part = concat(t_owner, t_spender)
        approval_key = concat(approval_first_part, MONTH_KEY)
        height = GetHeight()
        deposit_address_key = concat(approval_key, deposit_key)
        Put(ctx, deposit_address_key, height)
        Put(ctx, approval_key, MONTHLY_ALLOWANCE)
        OnApprove(t_owner, t_spender, MONTHLY_ALLOWANCE)

        return True

    return False
コード例 #6
0
def Main(operation, args):
    """
    Main definition for the smart contracts

    :param operation: the operation to be performed
    :type operation: str

    :param args: list of arguments.
        args[0] is always sender script hash
        args[1] is always domain
        args[2] (optional) is either target or other address
        args[3] (optional) is target (if args[2] is address)
    :param type: str

    :return:
        byterarray: The result of the operation
    """
    # Common definitions
    user_hash = args[0]
    domain = args[1]
    domain_owner_key = concat(domain, ".owner")
    domain_target_key = concat(domain, ".target")
    owner = b'#\xba\'\x03\xc52c\xe8\xd6\xe5"\xdc2 39\xdc\xd8\xee\xe9'

    # This doesn't require authentication
    if operation == 'GetDomain':
        return Get(GetContext(), domain_target_key)

    # Everything after this requires authorization
    authorized = CheckWitness(user_hash)
    if not authorized:
        Log("Not Authorized")
        return False
    Log("Authorized")

    if operation == 'RegisterDomain':
        if (CheckWitness(owner)):
            address = args[2]
            Put(GetContext(), domain_owner_key, address)
            if len(args) == 4:
                target = args[3]
                Put(GetContext(), domain_target_key, target)
            return True

    if operation == 'SetDomainTarget':
        domain_owner = Get(GetContext(), domain_owner_key)
        if (CheckWitness(domain_owner)) or (CheckWitness(owner)):
            # License the product
            target = args[2]
            Put(GetContext(), domain_target_key, target)
            return True

    if operation == 'DeleteDomain':
        if (CheckWitness(owner)):
            Delete(GetContext(), domain_owner_key)
            Delete(GetContext(), domain_target_key)
            return True

    return False
コード例 #7
0
def do_transfer(ctx, t_from, t_to, amount):
    if amount <= 0:
        return False

    if len(t_to) != 20:
        return False

    if CheckWitness(t_from):

        if t_from == t_to:
            print("transfer to self!")
            return True

        from_val = Get(ctx, t_from)

        if CheckWitness(TOKEN_OWNER):
            team_reserve = Get(ctx, TEAM_RESERVE_KEY)
            company_reserve = Get(ctx, COMPANY_RESERVE_KEY)
            from_val = from_val - team_reserve
            from_val = from_val - company_reserve

            if from_val < amount:
                print("insufficient funds")
                return False

            difference = from_val - amount
            difference = difference + company_reserve
            difference = difference + team_reserve

            if difference == 0:
                Delete(ctx, t_from)
            else:
                Put(ctx, t_from, difference)
        else:
            if from_val < amount:
                print("insufficient funds")
                return False
            difference = from_val - amount
            if from_val == amount:
                Delete(ctx, t_from)
            else:
                Put(ctx, t_from, difference)

        to_value = Get(ctx, t_to)

        to_total = to_value + amount

        Put(ctx, t_to, to_total)

        OnTransfer(t_from, t_to, amount)

        return True
    else:
        print("from address is not the tx sender")

    return False
コード例 #8
0
ファイル: mct-dapp-template.py プロジェクト: kilimchoi/MCT
def Main(operation, args):

    trigger = GetTrigger()

    if trigger == Verification():
        if CheckWitness(OWNER):
            return True

        return False

    elif trigger == Application():

        if operation == 'hello':
            print('hello world!')
            totalcalls = Get('totalCalls')
            totalcalls = totalcalls + 1
            print(totalcalls)
            if Put('totalCalls', totalcalls):
                return True
            print('staked storage call failed')
            return False

            return True

        if operation == 'ownerWithdraw':
            if not CheckWitness(OWNER):
                print(
                    'only the contract owner can withdraw MCT from the contract'
                )
                return False

            if len(args) != 1:
                print('withdraw amount not specified')
                return False

            t_amount = args[0]
            myhash = GetExecutingScriptHash()

            return MCTContract('transfer', [myhash, OWNER, t_amount])

        # end of normal invocations, reject any non-MCT invocations

        caller = GetCallingScriptHash()

        if caller != MCT_SCRIPTHASH:
            print('token type not accepted by this contract')
            return False

        if operation == 'onTokenTransfer':
            print('onTokenTransfer() called')
            return handle_token_received(caller, args)

    return False
コード例 #9
0
ファイル: Offer.py プロジェクト: frenchtoasters/TrueD_ex
def make_offer(offer) -> bool:
    '''
    Make New Offer on books
    :param offer:
    :return: Result of if offer was valid
    '''
    if not CheckWitness(offer.MakerAddress):
        return False

    # Checking that the person that invoked this was the smart contract it self
    if not CheckWitness(OWNER):
        return False

    allowed = get_state()
    if allowed == 'Inactive' or allowed == 'Pending':
        return False

    if (allowed == 'Terminated' and not offer.OfferAssetID == NeoAssetID
            and offer.WantAssetID == GasAssetID
            and not offer.WantAssetID == NeoAssetID
            and offer.OfferAssetID == GasAssetID):
        return False
    trading_pair = offer.OfferAssetID + offer.WantAssetID
    offer_hash = hash(offer)
    storage = MCTManager()
    if storage.get(trading_pair + offer_hash):
        return False

    if not offer.OfferAmount > 0 and offer.WantAmount > 0:
        return False

    if offer.OfferAssetID == offer.WantAssetID:
        return False

    if (len(offer.OfferAssetID) != 20 and len(offer.OfferAssetID) != 32
            or len(offer.WantAssetID) != 20 and len(offer.WantAssetID) != 32):
        return False

    if not reduce_balance(offer.MakerAddress, offer.OfferAssetID,
                          offer.OfferAmount):
        return False

    store_offer(trading_pair, offer_hash, offer)

    created(offer.MakerAddress, offer_hash, offer.OfferAssetID,
            offer.OfferAmount, offer.WantAssetID, offer.WantAmount)

    return True
コード例 #10
0
def make_offer(offer):
    '''
    Make New Offer on books
    :param offer:
    :return: Result of if offer was valid
    '''
    if not CheckWitness(offer["MakerAddress"]):
        return False

    # Checking that the person that invoked this was the smart contract it self
    if not CheckWitness(OWNER):
        return False

    allowed = get("state")
    if allowed == 'Inactive' or allowed == 'Pending':
        return False

    if (allowed == 'Terminated' and not offer["OfferAssetID"] == NeoAssetID
            and offer["WantAssetID"] == GasAssetID
            and not offer["WantAssetID"] == NeoAssetID
            and offer["OfferAssetID"] == GasAssetID):
        return False
    trading_pair = offer["OfferAssetID"] + offer["WantAssetID"]
    offer_hash = serialize_array(offer)
    if get(trading_pair + offer_hash):
        return False

    if not offer["OfferAmount"] > 0 and offer["WantAmount"] > 0:
        return False

    if offer["OfferAssetID"] == offer["WantAssetID"]:
        return False

    if (len(offer["OfferAssetID"]) != 20 and len(offer["OfferAssetID"]) != 32
            or len(offer["WantAssetID"]) != 20
            and len(offer["WantAssetID"]) != 32):
        return False

    if not reduce_balance(offer["MakerAddress"], offer["OfferAssetID"],
                          offer["OfferAmount"]):
        return False

    store_offer(trading_pair, offer_hash, offer)

    created(offer["MakerAddress"], offer_hash, offer["OfferAssetID"],
            offer["OfferAmount"], offer["WantAssetID"], offer["WantAmount"])

    return True
コード例 #11
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def WithdrawFunds(args):
    sender = args[0]
    amount = args[1]

    if not CheckWitness(sender):
        print('Account owner must be sender')
        return [False, 'Account owner must be sender']

    if amount < 0:
        print('Must withdraw positive amount')
        return [False, 'Must withdraw positive amount']

    user_funds = GetUserFunds(args)
    funds = user_funds[1]

    if amount > funds:
        print('Not enough funds for desired amount')
        return [False, 'Not enough funds']

    context = GetContext()

    _ = AddFunds(context, sender,
                 -amount)  # Error if we don't define 'return' value

    OnWithdraw(sender, amount)

    return [True, '']
コード例 #12
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def DeletePublication(args):
    sender = args[0]
    name = args[1]

    if not CheckWitness(sender):
        print('Account owner must be sender')
        return [False, 'Account owner must be sender']

    context = GetContext()

    publications_key = concat('publications', sender)
    publication_key = concat(publications_key, sha1(name))

    publication = Get(context, publication_key)
    if not publication:
        print('Publication does not exist')
        return [False, 'Publication does not exist']

    publication = Deserialize(publication)
    if not publication[5]:
        print('Publication has already been deleted')
        return [False, 'Publication has already been deleted']
    """
    Check for active bids etc here - revisit if time (OOS)
    """

    publication[5] = False

    Put(context, publication_key, Serialize(publication))

    return [True, '']
コード例 #13
0
def prop_info_update(ctx,id,hash,address):
    isOwner = CheckWitness(address)
    prop_owner = get_prop_owner(ctx,id)
    prop_info = get_prop_info(ctx, id)

    if prop_info == b'':
        print('The property is not registered yet')
        return False

    if isOwner == False:
        print('Contract caller different from address')
        return False

    if prop_owner != b'':
        if prop_owner != address:
            print('The property is registered to another address')
            return False
    if prop_info == hash:
        print('The property is already registered to caller address')
        return False

    delete_prop_from_user(ctx,prop_owner,prop_info)
    store_prop(ctx,id,hash,prop_owner)

    OnPropUpdate(id)

    return True
コード例 #14
0
def perform_exchange(ctx, args):
    """

     :param token:Token The token object with NEP5/sale settings
     :return:
         bool: Whether the exchange was successful
     """
    if not CheckWitness(TOKEN_OWNER):
        print("Must be token owner to mint tokens")
        return False

    attachments = get_asset_attachments(
        args)  # [receiver, sender, amount of tokens]

    exchange_ok = can_exchange(ctx, attachments, False)

    if not exchange_ok:
        return False

    # lookup the current balance of the address
    current_balance = Get(ctx, attachments[1])

    # set the amount of tokens the receiver will get
    exchanged_tokens = attachments[2]

    new_total = exchanged_tokens + current_balance
    Put(ctx, attachments[1], new_total)

    # update the in circulation amount
    result = add_to_circulation(ctx, exchanged_tokens)

    # dispatch transfer event
    OnTransfer(attachments[0], attachments[1], exchanged_tokens)

    return True
コード例 #15
0
ファイル: neo_betting.py プロジェクト: DNK90/neo_api_server
def Main(operation, args):

    trigger = GetTrigger()
    if trigger == Verification():
        print("Verification")
        return CheckWitness(token_owner)

    if trigger == Application():
        if operation == "bet":
            if len(args) != 2 or args[1] == '':
                return False

            attachments = get_asset_attachments()
            sent_neo = attachments[2]
            sender = attachments[1]

            bet_id = args[0]
            option = args[1]

            print("sent_neo")
            print(sent_neo)

            if sent_neo > 0:
                bet(sender, bet_id, option, sent_neo)

            return True

    print("nothing matches")
    return False
コード例 #16
0
ファイル: ico_template.py プロジェクト: sotatek-dev/realista
def deploy():
    """

    :param token: Token The token to deploy
    :return:
        bool: Whether the operation was successful
    """
    if not CheckWitness(TOKEN_OWNER):
        log = debug_log("Must be owner to deploy")
        return False

    if not Get(ctx, 'initialized'):
        # do deploy logic
        Put(ctx, 'initialized', 1)
        Put(ctx, TOKEN_OWNER, TOKEN_INITIAL_AMOUNT)
        Put(ctx, ECOSYSTEM_RESERVE_ADDRESS, TOKEN_ECOSYSTEM_AMOUNT)
        Put(ctx, ADVISOR_FUNDS_ADDRESS, TOKEN_ADVISOR_AMOUNT)
        Put(ctx, EMPLOYEE_FUNDS_ADDRESS1, TOKEN_EMPLOYEES_AMOUNT_1)
        Put(ctx, EMPLOYEE_FUNDS_ADDRESS2, TOKEN_EMPLOYEES_AMOUNT_2)
        Put(ctx, RESERVE_FUNDS_ADDRESS, TOKEN_RESERVE_AMOUNT)
        Put(ctx, AFFILIATE_FUNDS_ADDRESS, TOKEN_AFFILIATE_AMOUNT)
        Put(ctx, SALE_FUNDS_ADDRESS, TOKEN_SALE_AMOUNT)

        log = set_locked(ctx)

        return add_to_circulation(ctx, TOKEN_TOTAL_SUPPLY)

    return False
コード例 #17
0
def DoMatch(src_order_key, dst_order_key, course):
    """
    Method for the dApp owner to match exchange requests
    Input data: all not matched requests.
    Output data: matched pairs
    """

    # Check if the method is triggered by the oracle for this exchange
    context = GetContext()
    src_order_data = Get(context, src_order_key)
    oracle = src_order_data[12]
    src_deposit_amount = src_order_data[10]

    dst_order_data = Get(context, dst_order_key)
    dst_deposit_amount = dst_order_data[10]

    if not CheckWitness(oracle):
        Log("Must be oracle to notice results")
        return False

    # refund deposit of the source wallet
    t1 = DoTransfer(DEPOSIT_WALLET, QUARK_WALLET, src_deposit_amount)

    # refund deposit of the source wallet
    t2 = DoTransfer(DEPOSIT_WALLET, QUARK_WALLET, dst_deposit_amount)
    if t1 and t2:
        DispatchExchangeEvent(src_order_key)
        DispatchExchangeEvent(dst_order_key)
        return True
    return False
コード例 #18
0
def load_challenge_reserve(ctx, amount):
    if not CheckWitness(get_owner_address(ctx)):
        print("Needs to be the token owner.")
        return False

    if amount <= 0:
        print("Negative amount.")
        return False

    owner_balance = Get(ctx, get_owner_address(ctx))
    if owner_balance < amount:
        print("The owner does not have enough balance.")
        return False

    current_challenge_reserve = Get(ctx, CHALLENGE_SYSTEM_RESERVE)
    if current_challenge_reserve + amount > CHALLENGE_SYSTEM_INITIAL_AMOUNT:
        print("Funds would exceed the maximum amount for challenge reserve.")
        return False

    print("Adding funds to the challenge reserve.")

    new_balance = owner_balance - amount
    Put(ctx, get_owner_address(ctx), new_balance)

    new_challenge_reserve = current_challenge_reserve + amount
    Put(ctx, CHALLENGE_SYSTEM_RESERVE, new_challenge_reserve)

    return True
コード例 #19
0
def Main(operation, args):

    if operation == 'add_users':
        print("Running Verification!")
        is_owner = CheckWitness(OWNER)

        if is_owner:
            print("Is Owner!")
            return add_users(args)

        print("Not Owner")
        return False

    if operation == 'check_user':
        user = args[0]
        return check_user(user)

    if operation == 'current_vote':
        user = args[0]
        return current_vote(user)

    if operation == 'add_poll':
        poll = args[0]
        return add_poll(poll)

    if operation == 'vote':
        vote = args[0]
        return make_vote(vote)
コード例 #20
0
def deploy():
    """

    :return:
        bool: Whether the operation was successful
    """

    if not Get(ctx, 'initialized'):

        owner_initial_address = b'\xee\xee\xf8\xe5_\xde\x1aI\xed\xef\xca\xa5>\x17\x83?x\xf4\xff3'
        set_owner_address(ctx, owner_initial_address)

        if not CheckWitness(get_owner_address(ctx)):
            print("Must be owner to deploy")
            return False

        # do deploy logic
        Put(ctx, 'initialized', 1)

        # Allocate owner balance of 41 m
        Put(ctx, get_owner_address(ctx), TOKEN_OWNER_AMOUNT)

        # Allocate Challenge Reserve balance
        Put(ctx, CHALLENGE_SYSTEM_RESERVE, CHALLENGE_SYSTEM_INITIAL_AMOUNT)
        
        circulation = TOKEN_OWNER_AMOUNT + CHALLENGE_SYSTEM_INITIAL_AMOUNT

        Log("Deployed successfully!")

        # Add owner balance and challenge reserve balance to circulation
        return add_to_circulation(ctx, circulation)

    return False
コード例 #21
0
def Main(operation, args):

    trigger = GetTrigger()

    # This is used in the Verification portion of the contract
    # To determine whether a transfer of system assets ( NEO/Gas) involving
    # This contract's address can proceed
    if trigger == Verification():
        print("verification step")
        # check if the invoker is the owner of this contract
        is_owner = CheckWitness(TOKEN_OWNER)

        # If owner, proceed
        if is_owner:
            print("is owner")
            return True
        print("not owner")
        return False

    elif trigger == Application():

        for op in NEP5_METHODS:
            if operation == op:
                return handle_nep51(ctx, operation, args)

        if operation == 'setToken':
            return setToken(args[0], args[1])

        elif operation == 'bonusToken':
            return bonusToken(args[0], args[1])

        elif operation == 'minusToken':
            return minusToken(args[0], args[1])

        elif operation == 'getTime':
            return getCurrentTime()

        elif operation == "setProposal":
            # update:
            minusToken(args[1], args[4])
            return setProposal(args[0], args[1], args[2], args[3], args[4])

        elif operation == "getProposal":
            return getProposal(args[0])

        elif operation == "upVote":
            return upVote(args[0], args[1])

        elif operation == "downVote":
            return downVote(args[0], args[1])

        elif operation == "isExped":
            return isExped(args[0])

        elif operation == "isVoted":
            return isVoted(args[0], args[1])

        return 'unknown operation'

    return False
コード例 #22
0
def burn(ctx, args):
    """
    Burn unsold tokens, main use case is for crowdsale.

    :param amount: int the amount to be burned
    :return:
        int: Whether the tokens were successfully burned or not
    """
    amount = int(args[0])

    if CheckWitness(TOKEN_OWNER):
        current_in_circulation = Get(ctx, TOKEN_CIRC_KEY)
        new_amount = current_in_circulation + amount

        if amount <= 0:
            return False
        if new_amount > TOKEN_TOTAL_SUPPLY:
            return False

        current_balance = Get(ctx, BURN_KEY)
        new_total = amount + current_balance
        Put(ctx, BURN_KEY, new_total)

        # update the in circulation amount
        # burned tokens is counted in circulation but removed from NEP5 totalSupply
        result = add_to_circulation(ctx, amount)

        # dispatch burn event
        OnBurn(amount)
        return True
    else:
        return False
コード例 #23
0
ファイル: neo_test.py プロジェクト: johnny7861532/nns
def SetSubdomain(domain_name, subdomain):
    msg = concat("SetSubdomain: ", domain_name, subdomain)
    Notify(msg)
    context = GetContext()
    owner = Get(context, domain_name)

    if stringCompare(subdomain):
        Notify("Domain has incorrect char inside")
        return False

    if not owner:
        Notify("Domain is not yet registered")
        return False

    if not CheckWitness(owner):
        Notify("Sender is not the owner, cannot set subdomain")
        return False

    domain = concat(subdomain, ".")
    domain = concat(domain, domain_name)

    Put(context, domain, owner)

    msg2 = [domain, "is owned by ", owner]
    Notify(msg2)
    return True
コード例 #24
0
ファイル: neo_test.py プロジェクト: johnny7861532/nns
def RegisterDomain(domain_name, owner):
    msg = concat("RegisterDomain: ", domain_name)
    Notify(msg)
    '''
    Check if the domain contain .
    if ture then return false
    '''
    if stringCompare(domain_name):
        Notify("Domain has incorrect char inside")
        return False

    if not CheckWitness(owner):
        Notify("Owner argument is not the same as the sender")
        return False

    context = GetContext()
    exists = Get(context, domain_name)
    if exists:
        Notify("Domain is already registered")
        return False

    Put(context, domain_name, owner)
    msg2 = [domain_name, "is owned by ", owner]
    Notify(msg2)
    return True
コード例 #25
0
def reallocate():
    """
    
    Once the token sale is over, the owner can take back the remaining tokens.
    :return:
        bool: Whether the operation was successful
    """
    if not CheckWitness(get_owner_address(ctx)):
        print("Must be owner to reallocate")
        return False

    time = GetTime()

    if time < SERIES_A_END:
        print("Must wait until the end of Series A before re-allocating.")
        return False

    current_balance = Get(ctx, get_owner_address(ctx))

    crowdsale_available = crowdsale_available_amount(ctx)

    new_balance = current_balance + crowdsale_available

    Put(ctx, get_owner_address(ctx), new_balance)

    Log("Reallocated successfully!")

    return add_to_circulation(ctx, crowdsale_available)
コード例 #26
0
ファイル: nep5.py プロジェクト: nickfujita/asura-coin
def do_approve(ctx, t_owner, t_spender, amount):

    if len(t_spender) != 20:
        return False

    if not CheckWitness(t_owner):
        return False

    if amount < 0:
        return False

    # cannot approve an amount that is
    # currently greater than the from balance
    if Get(ctx, t_owner) >= amount:

        approval_key = concat(t_owner, t_spender)

        if amount == 0:
            Delete(ctx, approval_key)
        else:
            Put(ctx, approval_key, amount)

        OnApprove(t_owner, t_spender, amount)

        return True

    return False
コード例 #27
0
def Main(operation, args):
    """

    :param operation: str The name of the operation to perform
    :param args: list A list of arguments along with the operation
    :return:
        bytearray: The result of the operation
    """

    trigger = GetTrigger()

    # This is used in the Verification portion of the contract
    # To determine whether a transfer of system assets ( NEO/Gas) involving
    # This contract's address can proceed
    if trigger == Verification():

        # check if the invoker is the owner of this contract
        is_owner = CheckWitness(TOKEN_OWNER)

        # If owner, proceed
        if is_owner:
            return is_owner

        # Otherwise, we need to lookup the assets and determine
        # If attachments of assets is ok
        attachments = get_asset_attachments()
        return can_exchange(ctx, attachments, True)

    elif trigger == Application():

        for op in NEP5_METHODS:
            if operation == op:
                return handle_nep51(ctx, operation, args)

        if operation == 'deploy':
            return deploy()

        elif operation == 'circulation':
            return get_circulation(ctx)

        elif operation == 'ico_sold':
            return get_ico_token_sold(ctx)

        # the following are handled by crowdsale

        elif operation == 'mintTokens':
            return perform_exchange(ctx)

        elif operation == 'crowdsale_register':
            return kyc_register(ctx, args)

        elif operation == 'crowdsale_status':
            return kyc_status(ctx, args)

        elif operation == 'airdrop':
            return drop_tokens(ctx, args)

        return 'unknown operation'

    return False
コード例 #28
0
ファイル: smart_farm_contract.py プロジェクト: saiffya/varimi
def TransferFarmContract(FarmContract_name, OwnerNeoAddress, to_address):
    msg = concat("TransferFarmContract: ", FarmContract_name)
    msg2 = concat(msg, OwnerNeoAddress)
    Notify(msg2)

    storage_key = concat(FarmContract_name, OwnerNeoAddress)

    context = GetContext()
    Owner = Get(context, storage_key)
    if not Owner:
        Notify("This farm contract is not yet registered")
        return False

    if not CheckWitness(Owner):
        Notify(
            "This person is not the Owner, Farm Contract ownership cannot be Transfered"
        )
        return False

    if not len(to_address) != 34:
        Notify("Invalid new owner neo address. Must be exactly 34 characters")
        return False

    putRegistry(context, storage_key, to_address)
    return True
コード例 #29
0
def register_delegator(context, args):
    if not CheckWitness(OWNER):
        Notify(ILLEGAL_CALL)
        return False

    delegator = args[0]
    name = args[1]

    if len(delegator) != 20:
        Notify(INVALID_ADDRESS)
        return False

    if not name:
        Notify(MISSING_DELEGATOR_NAME)
        return False

    if Get(context, delegator):
        Notify(ALREADY_EXISTING_DELEGATOR)
        return False

    Notify(['[REGISTER-DELEGATOR] delegator:', delegator, 'name:', name])

    Put(context, delegator, name)

    return True
コード例 #30
0
def DeleteOrder(order_key):
    """
    Method for the dApp owner to delete claimed or refunded exchanges

    :param order_key: order_key
    :type order_key: str

    :return: whether the deletion succeeded
    :rtype: bool
    """

    if not CheckWitness(OWNER):
        Log("Must be owner to delete an exchange")
        return False

    context = GetContext()
    order_data = Get(context, order_key)
    status = order_data[12]

    if status == 'claimed':
        Delete(context, order_key)
        DispatchDeleteOrderEvent(order_key)

    elif status == 'refunded':
        Delete(context, order_key)
        DispatchDeleteOrderEvent(order_key)

    return False