Skip to content

Instantly share code, notes, and snippets.

@t8
Created February 4, 2021 17:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save t8/8bcbb74887c7b53eefadac93dbb154a5 to your computer and use it in GitHub Desktop.
Save t8/8bcbb74887c7b53eefadac93dbb154a5 to your computer and use it in GitHub Desktop.
A Profit-Sharing Token Contract built using uwu.
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