Created
October 5, 2016 22:56
-
-
Save AlexanderDzhoganov/3934ea0fdbf43ded35ded9470371289c to your computer and use it in GitHub Desktop.
This file contains 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
function(context, args) | |
{ | |
var SERVICE_USER = "foobar" | |
var CURRENT_USER = context.caller | |
function user_sells_rep(amount) { | |
var send_result = #s.rep.bank({ send: true, to: BANK_USER, from: CURRENT_USER, amount: amount }) | |
if(!send_result.ok) { | |
return { ok: false, msg: "Failed to create deposit transaction: " + send_result.msg } | |
} | |
// CHANGE THIS TO WORK WITH YOUR OTHER DB CODE | |
#db.u({ user: CURRENT_USER }, { $set: { unconfirmed_rep_id: send_result.transactionId } }) | |
return { ok: true, msg: "Deposit transaction created, please call the script again with { passcode: <your passcode> }" } | |
} | |
function users_sells_rep_finish(passcode) { | |
// CHANGE THIS TO WORK WITH YOUR OTHER DB CODE | |
var userData = #db.f({ user: CURRENT_USER }).single() | |
if(!userData.unconfirmed_rep_id) { | |
return { ok: false, msg: "User has no unconfirmed transaction!" } | |
} | |
var confirm_result = #s.rep.bank({ confirm: userData.unconfirmed_rep_id, passcode: passcode }) | |
if(!confirm_result.ok) { | |
return { ok: false, msg: "Failed to confirm deposit transaction: " + confirm_result.msg } | |
} | |
return { ok: true, msg: "Rep received from user" } | |
} | |
function user_buys_rep(amount) { | |
var send_result = #s.rep.bank({ send: true, to: CURRENT_USER, from: BANK_USER, amount: amount }) | |
if(!send_result.ok) { | |
return { ok: false, msg: "Failed to create withdrawal transaction: " + send_result.msg } | |
} | |
var confirm_result = #s.rep.bank({ confirm: send_result.transactionId }) | |
if(!confirm_result.ok) { | |
return { ok: false, msg: "Failed to confirm withdrawal transaction: " + confirm_result.msg } | |
} | |
return { ok: true, msg: "Rep sent to user" } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment