6 | | - | @Callable(i) |
---|
7 | | - | func buyNft (seller,nfts,price,totalamount) = { |
---|
8 | | - | let buyer = i.caller |
---|
9 | | - | let nft = size(nfts) |
---|
10 | | - | let buyerBalance = assetBalance(buyer, teams) |
---|
11 | | - | let amount = value(i.payments[0].amount) |
---|
12 | | - | if ((totalamount > amount)) |
---|
13 | | - | then throw("your paying ammount is wrong ") |
---|
14 | | - | else if (if ((size(nfts) != size(seller))) |
---|
15 | | - | then true |
---|
16 | | - | else (size(seller) != size(price))) |
---|
17 | | - | then throw("Invalid input: Number of NFTs, seller addresses, and costs must be the same.") |
---|
18 | | - | else if ((amount > buyerBalance)) |
---|
19 | | - | then throw("Buyer does not have enough funds to complete the purchase.") |
---|
20 | | - | else if ((i.payments[0].assetId == teams)) |
---|
21 | | - | then [StringEntry(toString(i.caller), toString(amount)), ScriptTransfer(buyer, 1, fromBase58String(nfts[0])), ScriptTransfer(buyer, 1, fromBase58String(nfts[1])), ScriptTransfer(buyer, 1, fromBase58String(nfts[2])), ScriptTransfer(Address(fromBase58String(seller[0])), price[0], teams), ScriptTransfer(Address(fromBase58String(seller[1])), price[1], teams), ScriptTransfer(Address(fromBase58String(seller[1])), price[2], teams)] |
---|
22 | | - | else if ((i.payments[0].assetId == unit)) |
---|
23 | | - | then [StringEntry(toString(i.caller), toString(amount)), ScriptTransfer(buyer, 1, fromBase58String(nfts[0])), ScriptTransfer(buyer, 1, fromBase58String(nfts[1])), ScriptTransfer(buyer, 1, fromBase58String(nfts[2])), ScriptTransfer(Address(fromBase58String(seller[0])), price[0], unit), ScriptTransfer(Address(fromBase58String(seller[1])), price[1], unit), ScriptTransfer(Address(fromBase58String(seller[1])), price[2], unit)] |
---|
24 | | - | else nil |
---|
| 6 | + | func foldFunc (acc,e) = e |
---|
| 7 | + | |
---|
| 8 | + | |
---|
| 9 | + | let final = { |
---|
| 10 | + | let $l = a |
---|
| 11 | + | let $s = size($l) |
---|
| 12 | + | let $acc0 = 0 |
---|
| 13 | + | func $f0_1 ($a,$i) = if (($i >= $s)) |
---|
| 14 | + | then $a |
---|
| 15 | + | else foldFunc($a, $l[$i]) |
---|
| 16 | + | |
---|
| 17 | + | func $f0_2 ($a,$i) = if (($i >= $s)) |
---|
| 18 | + | then $a |
---|
| 19 | + | else throw("List size exceeds 5") |
---|
| 20 | + | |
---|
| 21 | + | $f0_2($f0_1($f0_1($f0_1($f0_1($f0_1($acc0, 0), 1), 2), 3), 4), 5) |
---|