private static function savecoins($coins) { $old = storage::load(); if (!$old) { $old = array(); } foreach ($coins as $val => $ccs) { foreach ($ccs as $id => $coin) { $old[$val][$id] = $coin; } } if (storage::save($old)) { return true; } return false; }
public static function spentcoins($coins, $account) { if (!is_array($coins)) { return false; } $old = storage::load($account); if (!$old) { return false; } foreach ($coins as $id => $coin) { $val = $coin['value']; if (array_key_exists($id, $old[$val])) { unset($old[$val][$id]); } } $ret = storage::save($old, $account); $ret = $ret ? 1 : 0; return $ret; }
public static function log(&$in) { list($oid, $t) = each($in); if (!is_array($t) || !isset($t['order id'])) { $t = $in; $oid = $t['order id']; } if (isset($t['coins'])) { unset($t['coins']); } if (isset($t['change'])) { unset($t['change']); } $acc = Tools::address($t['client']); $acm = Tools::address($t['merchant']); $ac = $acc['account']; $am = $acm['account']; $tr[$oid] = $t; if (account::exists($ac) || $ac == config::$accountId) { $oldc = storage::load("{$ac}.transaction"); if (!$oldc) { $oldc = array(); } $oldc[$oid] = $tr[$oid]; storage::save($oldc, "{$ac}.transaction"); } if (account::exists($am) || $am == config::$accountId) { $oldm = storage::load("{$am}.transaction"); if (!$oldm) { $oldm = array(); } $oldm[$oid] = $tr[$oid]; storage::save($oldm, "{$am}.transaction"); } }
public static function log(&$t) { if (isset($t['coins'])) { unset($t['coins']); } if (isset($t['change'])) { unset($t['change']); } $tid = $t['acknowledgement']['id']; $tr[$tid] = $t; $old = storage::load('__Transactions__.lg'); if (!$old) { $old = array(); } $new = array_merge($old, $tr); storage::save($new, '__Transactions__.lg'); }
public static function pullcoins() { $m = Gmsg::create(Gmsg::prepare(GsonCrypt::sign(Gmsg::create(array('account' => config::$accountId))), 'pullcoins', config::$bankId)); $net = new Gnet(); $r = $net->send($m); $v = GsonCrypt::verify($r, config::$bankId); if (!$v) { $status = 0; gio::log("Unable to verify response from bank while pulling coins", E_USER_WARNING); } else { $v = Gmsg::extract($v); if (!$v) { $status = 0; gio::log("Unable to understand the response while pulling coins", E_USER_WARNING); } else { $status = $v['status']; $res = $v['response']; } } if (!$status) { gio::output("Could not pull eCash from bank"); } else { if (!is_array($res)) { gio::output("Could not pull eCash from bank"); } else { $check = 1; foreach ($res as $val => $ccs) { foreach ($ccs as $id => $coin) { $res[$val][$id]['secret'] = GsonCrypt::unseal($coin['secret']); if (!$res[$val][$id]['secret']) { $check = 0; } } } if (!$check) { gio::output("Could not get the secret of some eCash"); } } if (is_array($res) && count($res)) { $old = storage::load(); if (!$old) { $old = array(); } foreach ($res as $val => $ccs) { foreach ($ccs as $id => $coin) { $val = $coin['value']; $old[$val][$id] = $coin; } } storage::save($old); } } }
public static function spentcoins($coins, $account) { if (!is_array($coins) || $account != config::$accountId && !account::exists($account)) { return false; } if (!is_array($coins)) { return false; } $dest = strtolower($account) == strtolower(config::$accountId) ? config::$walfile : $account; $old = storage::load($dest); if (!$old) { return false; } foreach ($coins as $id => $coin) { $val = $coin['value']; if (array_key_exists($id, $old[$val])) { unset($old[$val][$id]); } } $ret = storage::save($old, $dest); $ret = $ret ? 1 : 0; return $ret; }
public static function balance(&$coins) { self::pullcoins(); $coins = storage::load(); if (!$coins) { $coins = array(); } $cnt = 0; foreach ($coins as $val => $ccs) { $cnt += intval(count($ccs)) * intval($val); } return $cnt; }
/** Get database object @param $force_reload boolean @public **/ static function &getDBO($force_reload = false) { static $dbo; if ($force_reload) { // re-init db instance $dbo = null; } // create if don't exists if (!is_object($dbo)) { $config = Factory::getConfig(); // extract timezone for DB @(list($tz_script, $tz_db) = explode('|', $config->timezone)); $storage = new storage(); // set timezone $storage->set_timezone($tz_db); // load db instance $dbo = $storage->load($config->dsn); if (!$dbo) { die('Cannot connect to database.'); } } return $dbo; }