public static function destroy() { $status = false; $net = new Gnet(); if (!self::isCreated()) { gio::output("No account found!"); } else { $m = Gmsg::create(Gmsg::prepare(config::$accountId, "revokecert", config::$SRA)); $m = GsonCrypt::seal($m, config::$SRA); $r = $net->send($m, true); if (!$r) { gio::output(); gio::output("Account Destruction Failed! Unable to connect to account server"); } else { $r = GsonCrypt::unseal($r); $r = Gmsg::extract($r); if ($r['status']) { self::rollback(); gio::output("Your account has been destroyed"); } else { gio::output($r['response']); } } } }
public static function hascert($userid = "") { if (empty($userid)) { $userid = config::$accountId; } $cert = self::getcert($userid); if (!file_exists($cert)) { $m = Gmsg::create(Gmsg::prepare("", "register", $userid)); $net = new Gnet(); $r = $net->send($m); unset($net); if (!$r) { } return false; $r = extract($r); if (!$r || !$r['status']) { return false; } if (!gio::saverawfile($r['cert'], $cert)) { return false; } } return true; }
public static function give($to, $amt) { $ramt = $amt; $rem = mine::countcoins($coins); if ($rem < $amt) { gio::output("Not enough coins"); return false; } $paths = Tools::address($to); if (!$paths) { gio::output("The destination account is invalid"); return false; } $getcoins = array(); $c = 1; if (!is_array($coins)) { return false; } $vals = array_keys($coins); rsort($vals); foreach ($vals as $val) { if ($amt < $val) { continue; } if ($amt <= 0) { break; } $ch[$val] = floor($amt / $val); if ($ch[$val] > count($coins[$val])) { $ch[$val] = count($coins[$val]); } $amt -= $ch[$val] * $val; } foreach ($ch as $v => $n) { while ($n > 0 && (list($id, $coin) = each($coins[$v]))) { $getcoins[$id] = $coin; unset($coins[$v][$id]); $n--; } } foreach ($getcoins as $k => $v) { $secret[$k] = Tools::makesecrets(); $getcoins[$k]['secret'] = GsonCrypt::seal($secret[$k], $paths['srakey']); } $net = new Gnet(); if (!$net->connect($paths['address'], intval($paths['port']))) { gio::output("Unable to connect to the destination account"); return false; } else { $m = Gmsg::create(Gmsg::prepare($getcoins, "deposit", $paths['account'])); $m = GsonCrypt::seal($m, $paths['bank']); if (!$m) { gio::output("Unable to send!"); gio::output("POSSIBLE CAUSES:"); gio::output("The destination bank's certificate is not avaiable!"); gio::output("Account may not be registered with sra!"); gio::output("Account may have been deregistered with sra!"); return false; } $r = $net->send($m); $s = GsonCrypt::unseal($r); $r = $s ? Gmsg::extract($s) : Gmsg::extract($r); unset($net); if (!$r || !$r['status']) { gio::output("Deposit of {$ramt} coins to {$to} Failed!"); gio::output($r['response']); return false; } else { $old = storage::load($paths['srakey']); foreach ($getcoins as $id => $coin) { $getcoins[$id]['secret'] = $secret[$id]; $val = $coin['value']; $old[$val][$id] =& $getcoins[$id]; } storage::save($old, $paths['srakey']); storage::save($coins); gio::output("Deposit of {$ramt} coins to {$to} was successful"); return true; } } }
$responsetime = date($dateformat); $_SESSION['shop2']['response'] = array("Order Id" => $_SESSION['shop2']['order id'], "Reference" => "", "Sent Time" => $timesent, "Response Time" => $responsetime, "Time Received" => "", "Time Completed" => "", "status" => $status, "Message" => "{$msg}", "Amount Valued" => $sum, "Amount Processed" => "", "From Account" => "{$address}", "To Account" => "{$merchantAddress}"); $_SESSION['shop2']['status'] = $status == 0 ? "successful" : "not successful"; $step = 3; } if (isset($_POST['step3'])) { $sum = $_SESSION['shop2']['sum']; $purchase = $_SESSION['shop2']['purchase']; $address = $_SESSION['shop2']['address']; //$response = $_SESSION['shop2']['response']; $mg['oid'] = $_SESSION['shop2']['order id']; $m['m'] = $mg; $m['k'] = $merchantKey; $net = new Gnet(); $my = Tools::address($merchantAddress); $m = Gmsg::create(Gmsg::prepare($m, "mstatus", $my['bank'])); $response['Order Id'] = $mg['oid']; $response['Order value'] = "{$sum} {$currency}"; $rr = $net->send($m); if (!$rr) { $status = 0; $msg = "Unable to connect to Merchant's bank to verify transaction's state"; } else { $rr = Gmsg::extract($rr); if (!$rr) { $status = 0; $msg = "Failed to communicate with Merchant's bank to verify transaction state of order"; } else { if ($rr['status']) { foreach ($rr['response'] as $vv) { $response['Transaction reference'] = $vv['acknowledgement']['id'];
public static function certexchange($addr) { $d = Tools::address($addr); if (file_exists(GsonCrypt::getcert($d['bank']))) { return true; } $c = GsonCrypt::getcert(null, true); $m = Gmsg::create(Gmsg::prepare($c, 'exchangecert', $d['bank'])); $net = new Gnet(); $r = $net->connect($d['address'], intval($d['port'])); if (!$r) { return false; } $r = $net->send($m); if (!$r) { return false; } $r = Gmsg::extract($r); if (!$r) { return false; } if ($r['status']) { $resp = gio::saverawfile($r['cert'], GsonCrypt::getcert($d['bank'])); } return isset($resp) ? $resp : false; }
private static function register() { if (self::isRegistered()) { return true; } $ba = Tools::address(gio::input("Enter the bank's address")); if (!$ba) { return false; } config::$bankAddress = $ba['address']; config::$bankPort = intval($ba['port']); $net = new Gnet(); $r = $net->send(Gmsg::create(Gmsg::prepare("", "register", config::$bankId))); $net = null; if (!$r) { return false; } $m = Gmsg::extract($r); if (!$m['status']) { return false; } if (gio::saverawfile($m['cert'], GsonCrypt::getcert($m['name'])) && gio::savetofile($m['cert'], GsonCrypt::getkey($m['name']))) { if (gio::savetofile($m['name'], config::$bankIdFile) && gio::savetofile(serialize(array(config::$bankAddress, config::$bankPort)), config::$walCfgFile)) { config::$bankId = $m['name']; config::$accountId = $m['account']; return true; } else { self::deregister(); return false; } } return false; }