コード例 #1
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetCurrentAuctionWinner(args):
    owner = args[0]
    name = args[1]

    context = GetContext()

    date = getWarpedTime(context) + (
        SECONDS_IN_DAY -
        getWarpedTime(context) % SECONDS_IN_DAY) + SECONDS_IN_HOUR * -TIMEZONE
    args.append(date)

    publication_key = validatePublicationAuction(context, args)
    if not publication_key:
        return [False, 'Invalid auction params']

    date = date + 0

    auction_key = concat(publication_key, sha1(date))
    bids_key = concat(auction_key, 'bids')
    bids = Get(context, bids_key)

    if not bids:
        print('No bids')
        return [False, 'No bids']

    bids = Deserialize(bids)

    best_bid = bids[len(bids) - 1]

    return [True, best_bid]
コード例 #2
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def validatePublicationAuction(context, args):
    owner = args[0]
    name = args[1]
    date = args[2]

    date = date + 0

    if date < MIN or date > MAX:
        print('Date must be within bounds')
        return False

    modulo = (date - SECONDS_IN_HOUR * -TIMEZONE) % SECONDS_IN_DAY
    if modulo != 0:
        print('Date must be 00:00 in contract timezone')
        return False

    publications_key = concat('publications', owner)
    publication_key = concat(publications_key, sha1(name))
    publication = Get(context, publication_key)

    if len(publication) == 0:
        print('Publication does not exist')
        return False

    else:
        publication = Deserialize(publication)

        if not publication[5]:
            print('Publication is not currently active')
            return False

    return publication_key
コード例 #3
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetUserPublications(args):
    user = args[0]

    context = GetContext()

    publications_key = concat('publications', user)

    publications = Get(context, publications_key)

    user_publications = []

    if not publications:
        return [True, user_publications]

    publications = Deserialize(publications)

    # Go through each user publication and get details
    for i in range(0, len(publications)):
        publication_key = concat(publications_key, sha1(publications[i]))

        publication = Get(context, publication_key)
        publication = Deserialize(publication)

        # Append only if publication is active
        if publication[5]:
            user_publications.append(publication)

    return [True, user_publications]
コード例 #4
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetAuctionWinner(args):
    owner = args[0]
    name = args[1]
    date = args[2]

    context = GetContext()

    publication_key = validatePublicationAuction(context, args)
    if not publication_key:
        return [False, 'Invalid auction params']

    date = date + 0

    auction_key = concat(publication_key, sha1(date))
    bids_key = concat(auction_key, 'bids')
    bids = Get(context, bids_key)

    if not bids:
        print('No bids')
        return [False, 'No bids']

    bids = Deserialize(bids)

    best_bid = bids[len(bids) - 1]

    return [True, best_bid]
コード例 #5
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetAuctionByMonth(args):
    owner = args[0]
    name = args[1]
    date = args[2]

    context = GetContext()

    publication_key = validatePublicationAuction(context, args)
    if not publication_key:
        return [False, 'Invalid auction params']

    auctions = []

    # For simplicity, assume given first day of month & always retreive 31 days worth of info
    for days in range(0, 30):
        next_date = date + days * SECONDS_IN_DAY
        auction_key = concat(publication_key, sha1(next_date))
        auction_info = Get(context, auction_key)

        if auction_info:
            auction_info = Deserialize(auction_info)
            auctions.append(auction_info)
        else:
            auctions.append([])

    return [True, auctions]
コード例 #6
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetNewPublications():
    context = GetContext()

    publications = Get(context, 'new_publications')

    new_publications = []

    if not publications:
        return [True, new_publications]

    publications = Deserialize(publications)

    # Go through each new publication and get details
    for i in range(0, len(publications)):
        user = publications[i][0]
        name = publications[i][1]

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

        publication = Get(context, publication_key)
        publication = Deserialize(publication)

        # Append only if publication is active
        if publication[5]:
            new_publications.append(publication)

    return [True, new_publications]
コード例 #7
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, '']
コード例 #8
0
def Main():

    m = 3

    j2 = sha1("abc")

    j3 = MYSHA

    #    print(j2)

    return j2 == j3
コード例 #9
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def GetAuctionByDate(args):
    owner = args[0]
    name = args[1]
    date = args[2]

    context = GetContext()

    publication_key = validatePublicationAuction(context, args)
    if not publication_key:
        return [False, 'Invalid auction params']

    date = date + 0

    auction_key = concat(publication_key, sha1(date))
    bids_key = concat(auction_key, 'bids')
    bids = Get(context, bids_key)

    if not bids:
        print('No current bids')
        return [True, bids]

    bids = Deserialize(bids)

    return [True, bids]
コード例 #10
0
def Main(operation, a, b):

    if operation == 'omin':
        return min(a, b)

    elif operation == 'omax':
        return max(a, b)

    elif operation == 'oabs':
        return abs(a)

    elif operation == 'sha1':
        return sha1(a)

    elif operation == 'sha256':
        return sha256(a)

    elif operation == 'hash160':
        return hash160(a)

    elif operation == 'hash256':
        return hash256(a)

    return 'unknown'
コード例 #11
0
def Main(operation, a, b):

    if operation == "omin":
        return min(a, b)

    elif operation == "omax":
        return max(a, b)

    elif operation == "oabs":
        return abs(a)

    elif operation == "sha1":
        return sha1(a)

    elif operation == "sha256":
        return sha256(a)

    elif operation == "hash160":
        return hash160(a)

    elif operation == "hash256":
        return hash256(a)

    return "unknown"
コード例 #12
0
ファイル: neo-ads.py プロジェクト: xyz-labs/neo-ads
def PlaceNewBid(args):
    owner = args[0]
    name = args[1]
    date = args[2]
    ad_url = args[3]
    image_urls = args[4]

    context = GetContext()
    time = GetTime(context)
    attachments = get_asset_attachments()

    user = attachments[1]
    bid_amount = attachments[3]

    publication_key = validatePublicationAuction(context, args)
    if not publication_key:
        return [False, 'Invalid auction params']

    if time >= date:
        print('Auction has finished')
        return [False, 'Auction finished']

    if bid_amount <= 0:
        print('No NeoGAS has been attached')
        return [False, 'No GAS attached']

    has_claimed = False

    new_bid = [user, bid_amount, ad_url, image_urls, time]
    new_auction = [user, bid_amount, has_claimed]

    auction_key = concat(publication_key, sha1(date))
    bids_key = concat(auction_key, 'bids')
    auction = Get(context, auction_key)

    # If no previous bids automatically accept and store current bid
    if not auction:
        Put(context, auction_key, Serialize(new_auction))
        Put(context, bids_key, Serialize([new_bid]))

        return [True, '']

    auction = Deserialize(auction)

    previous_user = auction[0]
    previous_bid = auction[1]

    if previous_bid >= bid_amount:
        print('Must bid more than the current best bid')
        OnRefund(user, bid_amount)
        return [False, 'Must bid more than current best bid']

    bids = Get(context, bids_key)
    bids = Deserialize(bids)

    bids.append(new_bid)

    Put(context, auction_key, Serialize(new_auction))
    Put(context, bids_key, Serialize(bids))

    # Re-credit funds to previous bidder
    AddFunds(context, previous_user, previous_bid)

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

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

    # Add char limit to prevent big storage costs
    if (len(name) > 255 or len(url) > 255 or len(category) > 255):
        print('Args must be less than 255 chars')
        return [False, 'Arguments must be less than 255 chars']

    context = GetContext()

    publications_key = concat('publications', sender)  # Publications by user
    publication_key = concat(
        publications_key,
        sha1(name))  # Publication details - sha1 to prevent malicious input
    new_publications_key = 'new_publications'  # List of new publications for front page view

    publications = Get(context, publications_key)
    publication = Get(context, publication_key)
    new_publications = Get(context, new_publications_key)

    # If publication already exists check if it is active/deleted
    if publication:
        publication = Deserialize(publication)
        if publication[5]:
            print('Publication name currently active')
            return [False, 'Active publication name']

    # Check if user has publications already
    if publications:
        publications = Deserialize(publications)
    else:
        publications = []

    # Check if there are publications in the all_publications view
    if new_publications:
        new_publications = Deserialize(new_publications)
    else:
        new_publications = []

    first_date = getWarpedTime(context) + (
        SECONDS_IN_DAY -
        getWarpedTime(context) % SECONDS_IN_DAY) + SECONDS_IN_HOUR * -TIMEZONE
    is_active = True

    new_publication = [sender, name, url, category, first_date, is_active]
    publications.append(name)
    new_publications.append([sender, name])

    # Shift new publication list to the left
    if len(new_publications) > 5:
        new_publications = [
            new_publications[1], new_publications[2], new_publications[3],
            new_publications[4], new_publications[5]
        ]

    Put(context, publication_key, Serialize(new_publication))
    Put(context, publications_key, Serialize(publications))
    Put(context, new_publications_key, Serialize(new_publications))

    return [True, '']
コード例 #14
0
from boa.builtins import sha1

MYSHA = sha1("abc")


def Main():

    m = 3

    j2 = sha1("abc")

    j3 = MYSHA

    #    print(j2)

    return j2 == j3
コード例 #15
0
def Main(operation, args):
    sha1("123456789")
    sha256("123456789")
    hash160("123456789")
    hash256("123456789")