Skip to content

Instantly share code, notes, and snippets.

@littledivy
Forked from t8/pst.uwu
Last active February 8, 2021 03:31
Show Gist options
  • Save littledivy/f9d576671a1da1e6049eff967993dc5e to your computer and use it in GitHub Desktop.
Save littledivy/f9d576671a1da1e6049eff967993dc5e to your computer and use it in GitHub Desktop.
A Profit-Sharing Token Contract built using uwu.
function 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
}
if (!quantity) {
return
}
if (!balances[caller]) {
return
}
if (!balances[target]) {
balances[target] = 0
}
balances[caller] -= quantity
balances[target] += quantity
state.balances = balances
}
if (input.function == "balance") {
let balances = state.balances
let ticker = state.ticker
let target = !input.target ? caller : input.target;
if (!balances[target]) {
balances[target] = 0
}
return {
result: {
target,
ticker,
balance: balances[target]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment