For Creators

Our aim is to make implementing GoldPieces/GP into your new or existing project as easy as possible.

Table Of Contents

Part 1 Installing GoldPieces
Part 2 Checking For Deposits
Part 3 Processing Withdrawals
Part 4 A Template For An Online Game

Installing GoldPieces

Checking For Deposits

The idea is to have a script that runs every minute or so and checks to see if there are any new deposits it needs to credit to the appropriate user/player.

You will need the JSON-RPC package to communicate with the GoldPieces server to check balance, send, receive etc.

I have tried to comment the code as well as possible to help your understanding


// first connect and authenticate with the GoldPieces software running on your server
require("jsonRPCClient.php");
$rpcUser = ""; ////your rpc username that is set in GoldPieces.conf
$rpcPassword = ""; //your rpc password that is set in GoldPieces.conf
$gp = new jsonRPCClient("http://$rpcUser:[email protected]:23461/");

// connect to your games mysql database so you can save deposits and update the users balances
mysql_select_db(“game”);

$transactions = $gp->listtransactions(); //get recent transactions list to loop through
foreach ($transactions as $transaction) {
if ($transaction[“category”]==”receive”){
//its a deposit
$sql=mysql_query(“SELECT * FROM `bank_transactions` WHERE credited =0 && txid=’$transaction[txid]'”); //see if we recorded the deposit already
if (mysql_num_rows($sql)>0){
while($deposit = mysql_fetch_array($sql)){
//deposits already inserted that may need crediting
//it hasn’t been credited, this is the second cron run atleast. we can add the GP to their account.
$credit_sql = “UPDATE `bank_transactions` SET `credited`=’1′ WHERE `id`=’$deposit[id]'”;
mysql_query($credit_sql)or die(“Error updating bank transaction credited row to true”);
//now add GP to account if we made it this far
$add_gp_sql = “UPDATE `user` SET `currency`=currency+$deposit[amount] WHERE deposit_address=’$deposit[address]'”;
mysql_query($add_gp_sql)or die(mysql_error());
}//end of deposits loop
} else{
//see if we have it yet
$checksql=mysql_query(“SELECT * FROM bank_transactions where txid=’$transaction[txid]'”);
if (mysql_num_rows($checksql)==0){
//has not been added yet
$add_sql=”INSERT INTO `bank_transactions` (txid,amount,confirmations,credited,address)”;
$add_sql.=”VALUES (‘$transaction[txid]’,$transaction[amount],$transaction[confirmations],0,’$transaction[address]’);”;
mysql_query($add_sql)or die(mysql_error());
print “added transactions to bank ledger”;
}
}
}
}

?>

Processing Withdrawals

A Template For An Online Game