Exemplo n.º 1
0
def DepositNeo():
    # get reference to the tx the invocation is in
    tx = GetScriptContainer()

    references = tx.References

    if len(references) < 1:
        print("no neo attached")
        return False

    # we need to determine who sent the tx
    reference = references[0]
    sender = GetScriptHash(reference)

    # this will keep track of how much neo was deposited
    value = 0

    output_asset_id = GetAssetId(reference)

    if output_asset_id != NEO_ASSET_ID:
        print("Must deposit NEO")
        return False

    # this is the contract's address
    receiver = GetExecutingScriptHash()

    # go through all the outputs
    # and check if the receiver is the contract
    # if that is true, we add the value of the output to the
    # total sum that was deposited

    for output in tx.Outputs:
        shash = GetScriptHash(output)
        if shash == receiver:
            output_val = GetValue(output)
            value = value + output_val

    if value > 0:

        print("neo was deposited")
        Notify(value)

        timestamp = GetHeight()
        # now we know value was deposited from the sender

        context = GetContext()

        print("timestamp: ", timestamp)
        Put(context, "timestamp", timestamp)

        print("deposited")

        return True

    return False
Exemplo n.º 2
0
def DepositNeo():

    # get reference to the tx the invocation is in
    tx = GetScriptContainer()

    references = tx.References

    if len(references) < 1:
        print("no neo attached")
        return False

    # we need to determine who sent the tx
    reference = references[0]
    sender = GetScriptHash(reference)

    # this will keep track of how much neo was deposited
    value = 0

    # this is the contract's address
    receiver = GetExecutingScriptHash()

    # go through all the outputs
    # and check if the receiver is the contract
    # if that is true, we add the value of the output to the
    # total sum that was deposited

    for output in tx.Outputs:
        shash = GetScriptHash(output)
        if shash == receiver:

            output_asset_id = GetAssetId(output)

            if output_asset_id == NEO_ASSET_ID:

                output_val = GetValue(output)
                value = value + output_val

    if value > 0:

        # now we know value was deposited from the sender

        # check the current balance of the sender
        # add it to the deposit amount, and save
        context = GetContext()
        current_balance = Get(context, sender)
        new_balance = current_balance + value
        Put(context, sender, new_balance)

        # send deposit event
        onDeposit(sender, value)

        return True

    return False
Exemplo n.º 3
0
def getValue():
    tx = GetScriptContainer()
    references = tx.References
    reference = references[0]
    output_asset_id = GetAssetId(reference)
    if output_asset_id == GAS_ASSET_ID:
        for output in tx.Outputs:
            shash = GetScriptHash(output)
            value = GetValue(output) / 100000000
            remainder = value % 1
            value = value - remainder
            return value
    print("gas not found rip")
    return 0
Exemplo n.º 4
0
def Main(num):
	receiver = GetExecutingScriptHash()

	tx = GetScriptContainer()
	references = tx.References
	reference = references[0]
	sender = GetScriptHash(reference)

	output_asset_id = GetAssetId(reference)
	if output_asset_id == GAS_ASSET_ID:
		print("good")

	for output in tx.Outputs:
		shash = GetScriptHash(output)
		value = GetValue(output) / 100000000
		remainder = value % 1
		value = value - remainder
		OnSpend(b'AFxLPTwPoxowEHvvYYd5RKfJ3VqMTwh4pm', value, receiver)
		return num

	return 0
Exemplo n.º 5
0
def LookupVIN(txid, index):

    tx = GetTransaction(txid)

    if tx:

        outputs = tx.Outputs

        output_len = len(outputs)

        if index < output_len:

            output = outputs[index]

            assetType = GetAssetId(output)
            assetAmount = GetValue(output)
            toret = [assetAmount, assetType]
            return toret

    print("could not lookup vin. TX or output not found")
    return False
Exemplo n.º 6
0
def Deposit(escrow_script_hash, note):
    """
    Put money into the contract and set the transactions vins to be owned by escrow_script_hash

    :param escrow_script_hash: the script hash who will be able to move these funds out
    :type escrow_script_hash: bytearray

    :param note: a note for the recipient (escrow_script_hash)
    :type note: strung

    :return: True if the deposit was successful, otherwise, false.
    :rtype: bool

    """

    # Get the transaction info.
    tx = GetScriptContainer()

    # Check if the transactions has currency attached
    references = tx.References
    if len(references) < 1:
        return False

    # Sender's script hash. We'll also grant them ownership of the funds if they need to retrieve their money
    # before it's claimed or if it will never be claimed.
    reference = references[0]
    sender = GetScriptHash(reference)

    # This is the contract's address
    contract_script_hash = GetExecutingScriptHash()

    context = GetContext()

    deposited = False

    # Go through all the outputs and handle deposits
    for output in tx.Outputs:
        shash = GetScriptHash(output)
        output_asset_id = GetAssetId(output)

        # We only care about NEO/GAS coming to the contract.
        if shash == contract_script_hash:
            output_val = GetValue(output)

            deposited = True

            # Update our total counter for this asset. This is just for fun display purposes
            total_all_time_key = concat("totalAllTime", output_asset_id)
            total_all_time = Get(context, total_all_time_key)
            new_total_all_time = total_all_time + output_val
            Put(context, total_all_time_key, new_total_all_time)

    # Here we keep a record of all the tx hashes belonging to the sender and recipient.
    # The idea is that they can view a list of these transactions.
    #
    # Also, the sender can rescind any that was still idle after a week (Mom didn't care enough to pick up
    # her GAS)
    if deposited:
        tx_hash = GetHash(tx)
        time = GetCurrentTimestamp()
        tx_info = [escrow_script_hash, sender, time, note]
        tx_info_serialized = serialize_array(tx_info)
        Put(context, tx_hash, tx_info_serialized)

        AddTransactionToScriptHash('recipient_history', escrow_script_hash,
                                   tx_hash)
        AddTransactionToScriptHash('sender_history', sender, tx_hash)

        return True

    return False
Exemplo n.º 7
0
def ReconcileBalances():

    print("[Reconcile balances]")
    # this is the contract's address
    sender_addr = GetExecutingScriptHash()

    tx = GetScriptContainer()

    withdrawal_amount = 0

    receiver_addr = bytearray(0)

    # go through the outputs of the tx
    # and find ones that are neo
    # and also the receiver cannot be the contract ( sender_addr )
    for output in tx.Outputs:
        shash = GetScriptHash(output)

        output_asset_id = GetAssetId(output)

        if output_asset_id == NEO_ASSET_ID:

            if shash != sender_addr:

                print("[reconcile] output is to receiver")
                receiver_addr = shash

                output_val = GetValue(output)

                withdrawal_amount = withdrawal_amount + output_val

                Notify(withdrawal_amount)
                Notify(output)

            else:

                print(
                    "[Reconcile balances] output is to contract sender addr, ignore"
                )
                Notify(output)
        else:

            print("[Reconcile balances] output is not neo")
            Notify(output)

    # we check recevier addr and amount

    if len(receiver_addr) > 0:

        print("[Reconcile balances] receiver addr is valid")
        Notify(receiver_addr)

        context = GetContext()

        current_balance = Get(context, receiver_addr)

        print("[Reconcile balances] current balance")
        Notify(current_balance)
        Notify(withdrawal_amount)

        if withdrawal_amount <= current_balance:

            new_balance = current_balance - withdrawal_amount

            print("[Reconcile balances] new balance is...")
            Notify(current_balance)
            Notify(new_balance)

            Put(context, receiver_addr, new_balance)

            onWithdrawReconciled(receiver_addr, new_balance)
            print("[Reconcile balances] withdrawl amount il less than balance")
            return True

        else:

            print("[Reconcile balances] not enough to witdraw")
    else:

        print("[Reconcile balances] receiver addr not set")

    return False
Exemplo n.º 8
0
def CanWithdrawNeo():

    print("[can withdraw]")
    is_invocation = IsInvocationTx()

    if is_invocation:
        # this is the contract's address
        sender_addr = GetExecutingScriptHash()

        tx = GetScriptContainer()

        withdrawal_amount = 0

        receiver_addr = bytearray(0)

        # go through the outputs of the tx
        # and find ones that are neo
        # and also the receiver cannot be the contract ( sender_addr )
        for output in tx.Outputs:
            shash = GetScriptHash(output)

            output_asset_id = GetAssetId(output)

            if output_asset_id == NEO_ASSET_ID:

                if shash != sender_addr:

                    print("[can withdraw] output is to receiver")
                    receiver_addr = shash

                    output_val = GetValue(output)

                    withdrawal_amount = withdrawal_amount + output_val

                    Notify(withdrawal_amount)
                    Notify(output)

                else:

                    print(
                        "[can withdraw] output is to contract sender addr, ignore"
                    )
                    Notify(output)
            else:

                print("[can withdraw] output is not neo")
                Notify(output)

        # we check recevier addr and amount

        if len(receiver_addr) > 0:

            print("[can withdraw] receiver addr is valid")
            Notify(receiver_addr)

            context = GetContext()

            current_balance = Get(context, receiver_addr)

            print("[can withdraw] current balance")
            Notify(current_balance)
            Notify(withdrawal_amount)

            if withdrawal_amount <= current_balance:

                print("[can withdraw] withdrawl amount il less than balance")

                onWithdraw(receiver_addr, withdrawal_amount)

                return True

            else:

                print("[can withdraw] not enough to witdraw")
        else:

            print("[can withdraw] receiver addr not set")

    return False
Exemplo n.º 9
0
def CanWithdrawNeo():

    print("[can withdraw]")

    tx = GetScriptContainer()

    type = GetType(tx)

    invoke_type = b'\xd1'

    print("[can withdraw] got tx type...")

    if type == invoke_type:
        print("[can withdraw] Is invocation!!")

        # this is the contract's address
        sender_addr = GetExecutingScriptHash()

        withdrawal_amount = 0

        receiver_addr = bytearray(0)

        # go through the outputs of the tx
        # and find ones that are neo
        # and also the receiver cannot be the contract ( sender_addr )
        for output in tx.Outputs:
            shash = GetScriptHash(output)

            output_asset_id = GetAssetId(output)

            if output_asset_id == NEO_ASSET_ID:

                output_val = GetValue(output)

                if shash != sender_addr:

                    print("[can withdraw] output is to receiver")
                    receiver_addr = shash

                    withdrawal_amount = withdrawal_amount + output_val

                    Notify(withdrawal_amount)
                    Notify(output)

                else:

                    print(
                        "[can withdraw] output is to contract sender addr, subtract from withdraw total"
                    )

                    withdrawal_amount = withdrawal_amount - output_val

                    Notify(output)
            else:

                print("[can withdraw] output is not neo")
                Notify(output)

        # we check recevier addr and amount

        if len(receiver_addr) > 0:

            print("[can withdraw] receiver addr is valid")
            Notify(receiver_addr)

            context = GetContext()

            current_balance = Get(context, receiver_addr)

            print("[can withdraw] current balance")
            Notify(current_balance)
            Notify(withdrawal_amount)

            if withdrawal_amount <= current_balance:

                print("[can withdraw] withdrawl amount il less than balance")

                onWithdraw(receiver_addr, withdrawal_amount)

                return True

            else:

                print("[can withdraw] not enough to witdraw")
        else:

            print("[can withdraw] receiver addr not set")
    else:

        print("[can withdraw] tx is not invocation tx. return false")

    return False
Exemplo n.º 10
0
def Main(operation, args):

    # The trigger determines whether this smart contract is being
    # run in 'verification' mode or 'application'

    trigger = GetTrigger()

    # 'Verification' mode is used when trying to spend assets ( eg NEO, Gas)
    # on behalf of this contract's address
    if trigger == Verification():

        storage = StorageAPI()
        attachments = get_asset_attachments()

        approval_storage_location = 'claim:approval:' + attachments.sender_addr
        approval = storage.get(approval_storage_location)

        if approval == GetValue():
            storage.delete(approval_storage_location)
            return True

        return False

    # 'Application' mode is the main body of the smart contract
    elif trigger == Application():

        if operation == 'setBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = SetBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'revokeBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = RevokeBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'claimBounty':
            if len(args) == 1:
                issue_url = args[0]
                result = ClaimBounty(issue_url)
                return result
            else:
                return False

        elif operation == 'approveClaim':
            if len(args) == 2:
                issue_url = args[0]
                claimee_address = args[1]
                result = ApproveClaim(issue_url, claimee_address)
                return result
            else:
                return False

        result = 'unknown operation'

        return result

    return False
Exemplo n.º 11
0
def MintTokens():
    """
    Method for an address to call in order to deposit NEO into the NEP5 token owner's address in exchange for a calculated amount of NEP5 tokens

    :return: whether the token minting was successful
    :rtype: bool

    """
    print("minting tokens!")

    tx = GetScriptContainer()

    references = tx.References

    print("helol1")
    if len(references) < 1:
        print("no neo attached")
        return False

    print("hello2")
    reference = references[0]
    print("hello2")
    #    sender = reference.ScriptHash

    sender = GetScriptHash(reference)
    print("hello4")

    value = 0
    print("hello5")
    output_asset_id = GetAssetId(reference)
    if output_asset_id == NEO_ASSET_ID:

        print("hello6")
        receiver = GetExecutingScriptHash()
        print("hello7")
        for output in tx.Outputs:
            shash = GetScriptHash(output)
            print("getting shash..")
            if shash == receiver:
                print("adding value?")
                output_val = GetValue(output)
                value = value + output_val

        print("getting rate")
        rate = CurrentSwapRate()
        print("got rate")
        if rate == 0:
            OnRefund(sender, value)
            return False

        num_tokens = value * rate / 100000000

        context = GetContext()

        balance = Get(context, sender)

        new_total = num_tokens + balance

        Put(context, sender, new_total)

        total_supply = Get(context, 'totalSupply')

        new_total_supply = total_supply + num_tokens

        Put(context, 'totalSupply', new_total_supply)

        OnTransfer(0, sender, num_tokens)

        return True

    return False
Exemplo n.º 12
0
def AddEntry():
    tx = GetScriptContainer()
    context = GetContext()
    references = tx.References
    if _TimeHasExpired():
        # refund gas and neo and pick winner
        PickWinner()
        return 0
    print("adding entry")
    if len(references) < 1:
        print("no gas attached")
        return False

    print("reading reference")
    reference = references[0]
    print("reference read")

    sender = GetScriptHash(reference)
    print("sender hash is")
    print(sender)
    print("reading script hash")

    print("getting asset ID. ID is here:")
    output_asset_id = GetAssetId(reference)
    print(output_asset_id)
    print('asset id printed above')
    if output_asset_id == GAS_ASSET_ID:
        print("executing script hash")
        receiver = GetExecutingScriptHash()
        for output in tx.Outputs:
            shash = GetScriptHash(output)
            print("getting shash..")
            if shash == receiver:
                print("adding value?")
                value = GetValue(output) / 100000000
                print("value storing in entries")
                print(value)
                print('string we will save to the entries array')
                entries = Get(context, 'entries')
                print('current entries')
                print(entries)
                remainder = value % 1
                print('remainder is')
                Notify(remainder)
                value = value - remainder
                print('remainder and value set')
                Notify(value)
                if value > 0:
                    if entries != bytearray(b''):
                        print('deserializing the byte array')
                        entries = deserialize_bytearray(entries)
                        end = len(entries) + value
                        if end > 1024:
                            print('contest capped at 1024')
                            return 0
                        new_entries = range(0, end)
                        i = 0
                        for item in new_entries:
                            if i < len(entries):
                                new_entries[i] = entries[i]
                            else:
                                new_entries[i] = sender
                            i += 1
                        # last_entry = entries[len(entries) - 1]
                        # colon_index = [pos for pos, char in enumerate(
                        #     last_entry) if char == ':']
                        # previous_total = substr(
                        #     last_entry, 0, colon_index)
                    else:
                        print('setting an empty array')
                        # list isn't working below
                        new_entries = range(0, value)
                        j = 0
                        for item in new_entries:
                            new_entries[j] = sender
                            j += 1
                else:
                    print("no gas added")
                Notify(new_entries)
                new_entries = serialize_array(new_entries)
                Put(context, "entries", new_entries)
    return entries