Files
market.src
- blockchain = include_lib("/lib/blockchain.so")
- if not blockchain then exit("Error: Missing blockchain.so library in the /lib")
- import_code("/home/me/market/libs/listLib.src")
- import_code("/home/me/market/libs/offersLib.src") // depends on list
- import_code("/home/me/market/libs/coinLib.src") // depends on offers, list
- import_code("/home/me/market/libs/coinsLib.src") // depends on coin, list
- my_coin = {"user": "dead", "password": "dead", "name": "moneda"}
wallet = login_wallet("deadlock", "dead")
- wallet = blockchain.login_wallet("dead", "dead")
- Coin.blockchain = blockchain
- Coin.wallet = wallet
- Coins.blockchain = blockchain
- Coins.wallet = wallet
- Coins.init()
- for coin in Coins.sort
- print(coin.name)
- print("website: " + coin.website)
- 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
libs/coinLib.src
- Coin = {}
- Coin.blockchain = null
- Coin.wallet = null
- Coin.init = function(name, wallet)
- self.name = name
- end function
- Coin.website = function()
- out = self.wallet.buy_coin(self.name, 1, 1, "nosubwallet")
- key = "more information: "
- start = out.indexOf(key) + key.len
- return out[start:]
- 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