Sign In Register

How can we help you today?

Start a new topic
Answered

Reserved currency?

I can't find any documentation on how to interact with the reserved currency and how it works. There doesn't seem to be any methods to call such as reserve1(), release1(), etc on SparkPlayer


Is this a deprecated feature?



Best Answer

Hi Ryan,


This is to do with challenge wagers. When a challenge is created with a currency wager the amount set as the wager for a particular currency is stored in the reserved currency field for the creator/joining player. If you look at the below example you can see a challenge created with a wager.


{
 "@class": ".CreateChallengeRequest",
 "accessType": "PUBLIC",
 "autoStartJoinedChallengeOnMaxPlayers": false,
 "challengeMessage": "",
 "challengeShortCode": "testChallenge",
 "currency1Wager": 500,
 "eligibilityCriteria": {},
 "endTime": "2016-09-05T15:01Z",
 "expiryTime": "2016-09-05T15:01Z",
 "maxAttempts": 0,
 "maxPlayers": 5,
 "minPlayers": 5,
 "silent": false,
 "startTime": "2016-09-05T15:01Z",
 "usersToChallenge": [
  ""
 ]
}

 

Two things will happen here. The challenge will be created and the wager amount will be placed into the reserved currency field for that player or they will receive an "INSUFFICIENT_FUNDS" error if they don't have the 500 to cover the wager. If you have any further questions just let me know.


Thanks,

Liam


Answer

Hi Ryan,


This is to do with challenge wagers. When a challenge is created with a currency wager the amount set as the wager for a particular currency is stored in the reserved currency field for the creator/joining player. If you look at the below example you can see a challenge created with a wager.


{
 "@class": ".CreateChallengeRequest",
 "accessType": "PUBLIC",
 "autoStartJoinedChallengeOnMaxPlayers": false,
 "challengeMessage": "",
 "challengeShortCode": "testChallenge",
 "currency1Wager": 500,
 "eligibilityCriteria": {},
 "endTime": "2016-09-05T15:01Z",
 "expiryTime": "2016-09-05T15:01Z",
 "maxAttempts": 0,
 "maxPlayers": 5,
 "minPlayers": 5,
 "silent": false,
 "startTime": "2016-09-05T15:01Z",
 "usersToChallenge": [
  ""
 ]
}

 

Two things will happen here. The challenge will be created and the wager amount will be placed into the reserved currency field for that player or they will receive an "INSUFFICIENT_FUNDS" error if they don't have the 500 to cover the wager. If you have any further questions just let me know.


Thanks,

Liam

Ah got it. this is bridging more into feature request territory, but it would be nice to have access to that field for atomicity. I have a complex custom playerState collection that changes fields after debiting or crediting some currency. But if the mongodb update fails for some reason, they will have lost the currency.


So it would be nice to reserve the currency upfront, and charge it or release it depending on the success of other mongo updates. I know we have getbalance() right now, but something can always happen in between.


Just a thought.


Thanks,

Ryan

Hi Ryan,


Although you don't have direct access to the reserved currency fields you can get them in Cloud Code by using a SparkRequest to send a AccountDetailsRequest, then get the required reserved fields from the response.

 

//example
var request = new SparkRequests.AccountDetailsRequest();
var response = request.Send();

Spark.setScriptData("reservedCurrency", response.reservedCurrency1)

 

As the wager amounts are locked into challenges for system use it's unlikely that a method to the release these values based on factors from outside of a challenge would be implemented. If you have any other questions just let us know.


Thanks,

Liam


Login to post a comment