Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added more entry points #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 79 additions & 26 deletions contracts/first_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def __init__(self, metadata):
all_groups = sp.nat(10),


users = sp.big_map( tkey = sp.TNat, tvalue = sp.TRecord(
user_friends = sp.TSet(sp.TAddress),
users = sp.big_map( tkey = sp.TString, tvalue = sp.TRecord(
user_friends = sp.TSet(sp.TString),
user_groups = sp.TSet(sp.TNat),
user_name = sp.TString,
user_bio = sp.TString,
Expand All @@ -19,7 +19,7 @@ def __init__(self, metadata):
tkey = sp.TNat,
tvalue = sp.TRecord(
group_name = sp.TString,
group_friends = sp.TSet(sp.TAddress),
group_friends = sp.TSet(sp.TString),
balance = sp.TMutez,
staking_amount = sp.TMutez

Expand All @@ -33,8 +33,13 @@ def __init__(self, metadata):

@sp.entry_point
def register(self, params):
self.data.users[self.data.all_users] = sp.record(
# sp.verify(
# params.status == False,
# "ALREADY_A_USER"),

self.data.users[params.user_name] = sp.record(
user_friends =sp.set() ,

user_groups = sp.set(),
user_name = params.user_name,
user_bio = params.user_bio,
Expand All @@ -45,20 +50,24 @@ def register(self, params):

@sp.entry_point
def addFriend(self, params):
self.data.users[params.id].user_friends.add(
self.data.users[params.friend_id].user_address )
sp.set_type(params,sp.TRecord(
user_name = sp.TString,
friend_name = sp.TString,
))
self.data.users[params.user_name].user_friends.add(
params.friend_name)


@sp.entry_point
def make_group(self, params):
sp.set_type(params,sp.TRecord(
group_name = sp.TString,
friends = sp.TList(sp.TNat),
friends = sp.TList(sp.TString),
))

group_friends = sp.local('group_friends', sp.set())
sp.for friend in params.friends:
group_friends.value.add(self.data.users[friend].user_address)
group_friends.value.add(friend)

self.data.groups[self.data.all_groups] = sp.record(
group_name = params.group_name,
Expand All @@ -74,7 +83,10 @@ def make_group(self, params):
@sp.entry_point
def addAmountToGroup(self, group_id):
sp.set_type(group_id, sp.TNat)


# sp.verify(
# self.data.groups[group_id].group_friends.contains(sp.sender),
# "YOU_ARE_NOT_A_MEMBER_OF_THIS_GROUP"),
# sp.send(sp.self_address, sp.amount),
self.data.groups[group_id].balance += sp.amount

Expand All @@ -86,12 +98,38 @@ def withdraw(self, params):
amount = sp.TMutez

))

# sp.verify(
# self.data.groups[params.group_id].group_friends.contains(sp.sender),
# "YOU_ARE_NOT_A_MEMBER_OF_THIS_GROUP"),
sp.send(sp.sender, params.amount),
self.data.groups[params.group_id].balance -= params.amount


@sp.entry_point
def transferAmountToFriend(self, friend_name):
sp.set_type(friend_name,sp.TString)

sp.send(self.data.users[friend_name].user_address,
sp.amount)


@sp.entry_point
def set_delegate(self, address):
sp.set_type(address, sp.TOption(sp.TKeyHash))
sp.set_delegate(address)


# @sp.entry_point
# def show_friends(self,user_id):
# sp.set_type(user_id,sp.TNat)

# return self.data.users[user_id].user_friends


# @sp.entry_point
# def show_groups(self,user_id):
# sp.set_type(user_id,sp.TNat)

# return self.data.users[user_id].user_groups

if "templates" not in __name__:
@sp.add_test(name = "StoreValue")
Expand Down Expand Up @@ -122,57 +160,72 @@ def test():
# Call register entry point
c1.register(
user_name = "alice",
user_bio = "Heyy there!"
user_bio = "Heyy there!",
).run(sender = alice)


scenario.h2("Register another user")
c1.register(
user_name = "bob",
user_bio = "Hii I'm new to Tezos"
user_bio = "Hii I'm new to Tezos",

).run(sender = bob)

c1.register(
user_name = "tom",
user_bio = "Hi there!"
user_bio = "Hi there!",

).run(sender = tom)

c1.register(
user_name = "lucy",
user_bio = "Heyy there!"
user_bio = "Heyy there!",

).run(sender = lucy)

scenario.h2("Add Friend")

c1.addFriend(
id = 1,
friend_id = 2
user_name = "bob",
friend_name = "alice"
).run(sender = bob)

c1.addFriend(
id = 1,
friend_id = 0
user_name = "bob",
friend_name ="lucy"
).run(sender = bob)

c1.addFriend(
id = 1,
friend_id = 1
user_name = "bob",
friend_name ="tom"
).run(sender = bob)

scenario.h2("Make group")

c1.make_group(
group_name = "GROUP 1",
friends = [ 0, 3]
friends = ["alice", "bob"]
)

c1.make_group(
group_name = "GROUP 2",
friends = [ 2, 1]
friends = ["tom", "lucy"]
)

scenario.h2("Add Money")
scenario.h2("Add Money to group")

c1.addAmountToGroup(
10
).run(amount = sp.mutez(100000))
11
).run(amount = sp.mutez(100000), sender = tom )

scenario.h2("send money to friend")

c1.transferAmountToFriend(
"bob"
).run(amount = sp.mutez(100000))

scenario.h2("delegate")

# c1.set_delegate(
# address here
# ).run(amount = sp.mutez(100000))
Loading