Open main menu
Posts
Gists
Guilds
Users
Decipher
Docs
Open user menu
Log in
Sign up
Create a new gist
Posts
Gists
Guilds
Users
Decipher
Docs
Files
market.src
listLib.src
libs/listLib.src
libs/offersLib.src
libs/coinLib.src
libs/coinsLib.src
market.src
import_code("/home/me/market/listLib.src")
blockchain = include_lib("/lib/blockchain.so")
if not blockchain then exit("Error: Missing blockchain.so library in the /lib")
wallet = log
i
n_wallet("deadlock", "kek")
Offers = {}
Offers.init = function(raw_offers)
self.raw_offers = raw_offers
end function
Offers.
list
= function()
list = []
for offer in to_list(self.raw_offers)
wallet_id = offer[0]
order = offer[1]
type = order[0]
amount = order[1]
price = order[2]
new_offer = {}
new_offer["wallet_id"] = wallet_id
new_offer["type"] = type
new_offer["amount"] = amount
new_offer["price"] = price
list.push(new_
offer
)
end for
return list
end function
Offers.wallets = function()
f = function(offer)
return offer["wallet_id"]
end function
return map(self.list, @f)
end function
Offers.buys = function()
f = function(offer)
return offer["type"] == "Buy"
end function
return select(self.
list
, @f)
end function
Offers.buys_min = function()
if self.buys.len == 0 then return null
return self.buys.sort("price")[0]
end function
Offers.buys_max = function()
if self.buys.len == 0 then return null
return self.buys.sort("price")[-1]
end function
Offers.buys_list = function()
f = function(offer)
return [offer["price"], offer["amount"]]
end function
return map(self.buys, @f)
end function
Offers.sells = function()
f = function(
offer
)
return offer["type"] == "Sell"
end function
return select(self.list, @f)
end function
Offers.sells_
list
= function()
f = function(offer)
return [offer["price"], offer["amount"]]
end function
return map(self.sells, @f)
end function
Offers.sells_min = function()
if self.sells.len == 0 then return null
return self.sells.sort("price")[0]
end function
Offers.sells_max = function()
if self.sells.len == 0 then return null
return self.sells.sort("price")[-1]
end function
Offers.len = function()
return self.list.len
end function
Coins = {}
Coins.blockchain = blockchain
Coins.wallet = walle
t
i
mport_code("/home/me/market/
list
Lib.src")
import_code("/home/me/market/
offer
sLib.src") // depends on
list
import_code("/home/me/market/coinLib.src") // depends on
offer
s,
list
import_code("/home/me/market/coinsLib.src") // depends on coin, lis
t
Coins.init = function()
self.raw_list = wallet.list_global
_coin
s
end function
Coins.list = function()
f = function(coin_name)
coin = new Coin
coin.init(coin_name)
return coin
end function
return map(self.raw_list, @f)
end function
Coins.sort = function()
f = function(coin)
data = {}
data["transactions"] = coin.history.len
data["name"] = coin.name
return data
end function
new_raw_list = map(self.list, @f).sort("transactions")
new_raw_list.reverse
f = function(i)
return i[
"name"
]
end function
self.raw_list = map(new_raw_list, @f)
return self.list
end function
Coins.ignore_shit_coins = function()
end function
my
_coin
= {"user": "dead", "password": "dead",
"name"
: "moneda"}
wallet = login_wallet("deadlock", "dead")
Coin = {}
Coin.blockchain = blockchain
Coin.wallet = wallet
Coins.blockchain = blockchain
Coins.wallet = wallet
Coin
.init = function(name, wallet)
self.name = name
end function
Coin.mined = function()
return self.blockchain.amount_mined(self.name)
end function
Coin.price = function()
return self.blockchain.coin_price(self.name)
end function
Coin.history = function()
return self.blockchain.show_history(self.name)
end function
Coin.average_price = function()
f = function(i)
return i[1][0]
end function
prices = map(to_list(self.history), @f)
return prices.sum / prices.len
end function
Coin.offers = function()
offers = new Offers
offers.init(self.wallet.get_global_offers(self.name))
return offers
end function
Coins.init
Coin
s.init()
for coin in Coins.sort
print(coin.name)
print("average price(NOT ACCURATE AT ALL):" + coin.average_price)
print("last sold price: " + coin.price)
print("total coins mined: " + coin.mined)
print("total of completed transactions: " + coin.history.len)
print("sell offers: " + coin.offers.sells.len)
print("buy offers: " + coin.offers.buys.len)
if coin.offers.sells.len > 0 then
f = function(offer)
return offer["amount"]
end function
total_coins = map(coin.offers.sells, @f).sum
print(total_coins + " for sale starting at $" + coin.offers.sells_min["price"])
out = ["price quantity"]
for i in coin.offers.sells.sort("price")
out.push(i["price"] + " " + i["amount"])
end for
print(format_columns(out.join(char(10))))
end if
if coin.offers.buys.len > 0 then
f = function(offer)
return offer["amount"]
end function
total_coins = map(coin.offers.buys, @f).sum
print(total_coins + " requests to buy at $" + coin.offers.buys_max["price"] + " or lower")
out = ["price quantity"]
buys = coin.offers.buys.sort("price")
buys.reverse
for i in buys
out.push(i["price"] + " " + i["amount"])
end for
print(format_columns(out.join(char(10))))
end if
print(" ")
end for
end for
listLib.src
to_list = function(map)
list = []
for i in map.indexes
if typeof(map[i]) == "map" then
list.push([i, to_list(map[i])])
else
list.push([i, map[i]])
end if
end for
return list
end function
to_map = function(list)
l = list[0:]
map = {}
for i in indexes(l)
if typeof(l[i][1]) == "list" and l[i][1].len == 2 and typeof(l[i][1][0]) == "string" then
map[l[i][0]] = to_map(l[i][1])
else
map[l[i][0]] = l[i][1]
end if
end for
return map
end function
each = function(obj, func)
if typeof(obj) == "map" then
list = to_list(obj)
else
list = obj
end if
result = list[0:] //list copy.
for i in indexes(list)
if typeof(obj) == "map" then
func(result[i][0], result[i][1])
else
func(result[i])
end if
end for
end function
map = function(list, func)
result = list[0:] //list copy.
for i in indexes(list)
result[i] = func(result[i])
end for
return result
end function
reject = function(list, func)
result = list[0:] //list copy.
i = 0
while i < result.len
if func(result[i]) == true then
result.remove(i)
continue
end if
i = i + 1
end while
return result
end function
select = function(list, func)
result = list[0:] //list copy.
i = 0
while i < result.len
if func(result[i]) == false then
result.remove(i)
continue
end if
i = i + 1
end while
return result
end function
min = function(list)
min = list[0]
for item in list
if item < min then
min = item
end if
end for
return min
end function
max = function(list)
max = list[0]
for item in list
if item < max then
max = item
end if
end for
return max
end function
libs/listLib.src
to_list = function(map)
list = []
for i in map.indexes
if typeof(map[i]) == "map" then
list.push([i, to_list(map[i])])
else
list.push([i, map[i]])
end if
end for
return list
end function
to_map = function(list)
l = list[0:]
map = {}
for i in indexes(l)
if typeof(l[i][1]) == "list" and l[i][1].len == 2 and typeof(l[i][1][0]) == "string" then
map[l[i][0]] = to_map(l[i][1])
else
map[l[i][0]] = l[i][1]
end if
end for
return map
end function
each = function(obj, func)
if typeof(obj) == "map" then
list = to_list(obj)
else
list = obj
end if
result = list[0:] //list copy.
for i in indexes(list)
if typeof(obj) == "map" then
func(result[i][0], result[i][1])
else
func(result[i])
end if
end for
end function
map = function(list, func)
result = list[0:] //list copy.
for i in indexes(list)
result[i] = func(result[i])
end for
return result
end function
reject = function(list, func)
result = list[0:] //list copy.
i = 0
while i < result.len
if func(result[i]) == true then
result.remove(i)
continue
end if
i = i + 1
end while
return result
end function
select = function(list, func)
result = list[0:] //list copy.
i = 0
while i < result.len
if func(result[i]) == false then
result.remove(i)
continue
end if
i = i + 1
end while
return result
end function
min = function(list)
min = list[0]
for item in list
if item < min then
min = item
end if
end for
return min
end function
max = function(list)
max = list[0]
for item in list
if item < max then
max = item
end if
end for
return max
end function
libs/offersLib.src
Offers = {}
Offers.init = function(raw_offers)
self.raw_offers = raw_offers
end function
Offers.list = function()
list = []
for offer in to_list(self.raw_offers)
wallet_id = offer[0]
order = offer[1]
type = order[0]
amount = order[1]
price = order[2]
new_offer = {}
new_offer["wallet_id"] = wallet_id
new_offer["type"] = type
new_offer["amount"] = amount
new_offer["price"] = price
list.push(new_offer)
end for
return list
end function
Offers.wallets = function()
f = function(offer)
return offer["wallet_id"]
end function
return map(self.list, @f)
end function
Offers.buys = function()
f = function(offer)
return offer["type"] == "Buy"
end function
return select(self.list, @f)
end function
Offers.buys_min = function()
if self.buys.len == 0 then return null
return self.buys.sort("price")[0]
end function
Offers.buys_max = function()
if self.buys.len == 0 then return null
return self.buys.sort("price")[-1]
end function
Offers.buys_list = function()
f = function(offer)
return [offer["price"], offer["amount"]]
end function
return map(self.buys, @f)
end function
Offers.sells = function()
f = function(offer)
return offer["type"] == "Sell"
end function
return select(self.list, @f)
end function
Offers.sells_list = function()
f = function(offer)
return [offer["price"], offer["amount"]]
end function
return map(self.sells, @f)
end function
Offers.sells_min = function()
if self.sells.len == 0 then return null
return self.sells.sort("price")[0]
end function
Offers.sells_max = function()
if self.sells.len == 0 then return null
return self.sells.sort("price")[-1]
end function
Offers.len = function()
return self.list.len
end function
libs/coinLib.src
Coin = {}
Coin.blockchain = null
Coin.wallet = null
Coin.init = function(name, wallet)
self.name = name
end function
Coin.mined = function()
return self.blockchain.amount_mined(self.name)
end function
Coin.price = function()
return self.blockchain.coin_price(self.name)
end function
Coin.history = function()
return self.blockchain.show_history(self.name)
end function
Coin.average_price = function()
f = function(i)
return i[1][0]
end function
prices = map(to_list(self.history), @f)
return prices.sum / prices.len
end function
Coin.offers = function()
offers = new Offers
offers.init(self.wallet.get_global_offers(self.name))
return offers
end function
libs/coinsLib.src
Coins = {}
Coins.blockchain = null
Coins.wallet = null
Coins.init = function()
self.raw_list = self.wallet.list_global_coins
end function
Coins.list = function()
f = function(coin_name)
coin = new Coin
coin.init(coin_name)
return coin
end function
return map(self.raw_list, @f)
end function
Coins.sort = function()
f = function(coin)
data = {}
data["transactions"] = coin.history.len
data["name"] = coin.name
return data
end function
new_raw_list = map(self.list, @f).sort("transactions")
new_raw_list.reverse
f = function(i)
return i["name"]
end function
self.raw_list = map(new_raw_list, @f)
return self.list
end function
Coins.ignore_shit_coins = function()
end function
Coin = {}
Coin.blockchain = Coins.blockchain
Coin.wallet = Coins.wallet
Coin.init = function(name, wallet)
self.name = name
end function
Coin.mined = function()
return self.blockchain.amount_mined(self.name)
end function
Coin.price = function()
return self.blockchain.coin_price(self.name)
end function
Coin.history = function()
return self.blockchain.show_history(self.name)
end function
Coin.average_price = function()
f = function(i)
return i[1][0]
end function
prices = map(to_list(self.history), @f)
return prices.sum / prices.len
end function
Coin.offers = function()
offers = new Offers
offers.init(self.wallet.get_global_offers(self.name))
return offers
end function