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
fund.src
libs/listLib.src
fund.src
import_code("/home/me/fund/libs/listLib.src")
get_offers_list = function(wallet, coin_name)
raw_offers = wallet.get_global_offers(coin_name)
list = []
for offer in Lst.to_list(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
Fund = {}
Fund.init = function(coin, coin_name, owner_wallet, owner_name)
self.coin = coin
self.coin_name = coin_name
self.owner_wallet = owner_wallet
self.owner_name = owner_name
end function
// so we dont have a dead lock in case some one lock it and exit the program
Fund.date_last_sell_lock = function()
end function
Fund.pending_transactions = function()
pending_transactions = self.owner_wallet.get_pending_trade(self.coin_name)
if pending_transactions == "No pending trades found" then return []
end function
Fund.sell_lock = function()
f = function(o)
return o[0] == "Sell"
end function
sell = Lst.select(self.pending_transactions, @f)
if sell.len > 0 then return true
return false
end function
Fund.buy_lock = function()
f = function(o)
return o[0] == "Buy"
end function
sell = Lst.select(self.pending_transactions, @f)
if sell.len > 0 then return true
return false
end function
Fund.money_in_bank = function()
// if tranction is locked unlock it
// if there is a open sell order in this coin store its values(value, wallet)
// delete all open sell orders
// delete the coins of every user
// run the function to get_balance
// add a coin to the user that had a sell order
// open the sell order again
// lock transactions
end function
Fund.open_deposit_transaction = function(client_wallet, value)
// if transaction in locked open a loop and wait
// once its unlocked create a buy order with client_wallet_and value
end function
Fund.money_stored_by_clients = function()
end function
blockchain = include_lib("/lib/blockchain.so")
coin_name = "coin729"
coin = blockchain.get_coin(coin_name, "lol", "lol")
owner_wallet = blockchain.login_wallet("dead", "dead")
coin.create_subwallet("dead", owner_wallet.get_pin, "dead", "dead")
owner_sub = coin.get_subwallet("dead")
Fund.init(coin, coin_name, owner_wallet, "dead")
print(Fund.sell_lock)
print(owner_sub)
print(owner_sub.get_user)
owner_sub.add_coins(1)
owner_wallet.sell_coin(coin_name, 1, 1, "dead")
print(Fund.sell_lock)
libs/listLib.src
Lst = {}
Lst.to_list = function(map, shallow = false)
list = []
for i in map.indexes
if typeof(map[i]) == "map" then
if shallow == true then
list.push([i, map[i]])
else
list.push([i, Lst.to_list(map[i])])
end if
else
list.push([i, map[i]])
end if
end for
return list
end function
Lst.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]] = Lst.to_map(l[i][1])
else
map[l[i][0]] = l[i][1]
end if
end for
return map
end function
Lst.each = function(obj, func)
if typeof(obj) == "map" then
list = Lst.to_list(obj, true)
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
Lst.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
Lst.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
Lst.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
// do not rename funcc to to func it will infinite loop
Lst.lsort = function(list, funcc)
f = function(i)
return Lst.to_map([["sort_key", funcc(i)], ["obj", i]])
end function
result = Lst.map(list, @f)
result = result.sort("sort_key")
f = function(i)
return i["obj"]
end function
return Lst.map(result, @f)
end function
Lst.flat = function(list)
result = []
for i in list
if typeof(i) == "list" then
result = result + Lst.flat(i)
else
result.push(i)
end if
end for
return result
end function
Lst.uniq = function(list)
result = []
for i in list
if result.indexOf(i) == null then result.push(i)
end for
return result
end function
Lst.has_any = function(list, value)
for i in list
if i == value then return true
end for
return false
end function
Lst.min = function(list)
min = list[0]
for item in list
if item < min then
min = item
end if
end for
return min
end function
Lst.max = function(list)
max = list[0]
for item in list
if item < max then
max = item
end if
end for
return max
end function