-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.rsh
102 lines (92 loc) · 2.93 KB
/
index.rsh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'reach 0.1';
"use strict";
const NftProps = Object({
nftId: UInt,
artistId: UInt,
createdAt: Bytes(50), // Number of bytes that createdAt can take
managerAddress: Address,
});
const AuctionProps = Object({
nftPrice: UInt,
timeout: UInt,
});
const BidderProps = {
buyNft: Fun([UInt, UInt, UInt], Bool),
};
const OwnerInterface = {
showOwner: Fun([UInt, UInt, Address], Null),
informTimeout: Fun([], Null),
getAuctionProps: Fun([], AuctionProps)
};
const BuyerInterface = {
...BidderProps,
showOwner: Fun([UInt, UInt, Address], Null),
informTimeout: Fun([], Null),
noBuy: Fun([Bool], Null),
}
const CreatorInterface = {
...OwnerInterface,
getNftProps: Fun([], NftProps),
};
const emptyAuction = {
nftPrice: 0, timeout: 0
};
export const main = Reach.App(
{},
[
Participant('Creator', CreatorInterface),
ParticipantClass('Owner', OwnerInterface),
ParticipantClass('Buyer', BuyerInterface),
View('NFT', {owner: Address })
],
(Creator, Owner,Buyer,vNFT) => {
Creator.only(() => {
const { nftId, artistId, createdAt, managerAddress } = declassify(interact.getNftProps());
});
Creator.publish(nftId, artistId, createdAt, managerAddress);
var owner = Creator;
{ vNFT.owner.set(owner); };
invariant(balance() == 0);
while (true) {
commit();
Owner.only(() => {
const amOwner = this == owner;
const { nftPrice, timeout } =
amOwner ? declassify(interact.getAuctionProps()) : emptyAuction;
});
Owner.publish(nftPrice, timeout).when(amOwner).timeout(false);
commit();
Buyer.only(() => {
const buy = declassify(interact.buyNft(nftPrice, nftId, artistId));
const buyNft = buy && this !== owner;
const bidder = this;
if(!buy){
interact.noBuy(buy);
}
})
Buyer.publish(buy,bidder);
if(!buy){
commit();
exit();
}
commit();
Buyer.publish(buyNft).pay(nftPrice).when(buyNft).timeout(relativeTime(timeout), () => {
each([Creator, Owner,Buyer], () => {
interact.informTimeout();
})
Anybody.publish();
[owner] = [owner];
continue;
});
each([Creator,Owner,Buyer], () => {
interact.showOwner(nftId, nftPrice, bidder);
});
transfer((owner == Creator ? nftPrice * 15 / 100 : nftPrice * 5 / 100)).to(managerAddress);
transfer((owner == Creator ? 0 : nftPrice / 10 )).to(Creator);
transfer(balance()).to(owner);
[owner] = [bidder];
continue;
};
commit();
// exit();
});