Created
February 4, 2021 17:01
-
-
Save t8/8bcbb74887c7b53eefadac93dbb154a5 to your computer and use it in GitHub Desktop.
A Profit-Sharing Token Contract built using uwu.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn handle(state, action): | |
let input = action["input"] | |
let caller = action["caller"] | |
if (input["function"] == "transfer"): | |
let target = input.target | |
let quantity = input.quantity | |
let balances = state.balances | |
if (!target): | |
return 0 | |
end | |
if (!quantity): | |
return 0 | |
end | |
if (!balances[caller]): | |
return 0 | |
end | |
if (balances[caller] < quantity): | |
return 0 | |
end | |
if (!balances[target]): | |
balances[target] = 0 | |
end | |
balances[caller] = balances[caller] - quantity | |
balances[target] = balances[target] + quantity | |
state["balances"] = balances | |
end | |
if (input["function"] == "balance"): | |
let balances = state.balances | |
let ticker = state.ticker | |
let target = "" | |
if (!input.target): | |
target = caller | |
else: | |
target = input.target | |
end | |
if (!balances[target]): | |
balances[target] = 0 | |
end | |
return { | |
"result": { | |
"target": target, | |
"ticker": ticker, | |
"balance": balances[target] | |
} | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment