public static function grant() { $net = new Gnet(); $m['account'] = config::$accountId; $m = GsonCrypt::sign(Gmsg::create($m)); $m = Gmsg::create(Gmsg::Prepare($m, "pullrequests", config::$bankId)); $net = new Gnet(); $r = $net->send($m); unset($net); if (!$r) { $status = 0; $res = "Unable to send the message"; } else { $v = GsonCrypt::verify($r, config::$bankId); if (!$v) { $status = 0; $res = "Unable to verify response from bank"; } else { $v = Gmsg::extract($v); if (!$v) { $status = 0; $res = "Unable to understand the response"; } else { $status = $v['status']; $res = $v['response']; } } } if (!$status) { gio::output($res); } else { $res = Gmsg::extract($res); if (!is_array($res)) { $status = 0; gio::output("Invalid response from bank"); } else { if (count($res) < 1) { gio::output("No pending payment requests"); } else { foreach ($res as $id => $req) { gio::output(); $payc[$id] = account::getcoins($req['amount']); $disp = $req; $disp['time'] = date(config::$timeFormat, $disp['time']); gio::display($disp); gio::output(); } if (gio::confirm("Do you want to grant the listed payment rerquests")) { foreach ($res as $id => $req) { $coins = $payc[$id]; if (!$coins) { gio::output("Isufficient ecash to process order id '{$id}'"); } else { $req['coins'] = $coins; $r = self::sendnotification($id, $req); $status = $r[0]; if ($status) { account::spentcoins($coins); } } } gio::output("All transactions completed"); } } } } }
public static function pgrant() { $acc = config::$accountId; $res = storage::load("{$acc}.request"); if (!$res || count($res) < 1) { gio::output("No pending payment requests"); } else { foreach ($res as $id => $req) { gio::output(); $disp = $req; $disp['time'] = date(config::$timeFormat, $disp['time']); gio::display($disp); gio::output(); if (gio::confirm("Do you want to grant this payment")) { while (true) { $amount = gio::input("Enter amount to confirm or c to cancel"); if ($amount == 'c' || $amount == 'C') { break; } if ($req['amount'] == $amount) { while (true) { $coins = account::getmycoins($amount); if (!$coins) { gio::output("Isufficient balance"); break; } $req['coins'] = $coins; foreach ($req['coins'] as $k => $v) { $req['coins'][$k]['secret'] = GsonCrypt::seal($req['coins'][$k]['secret'], config::$SRA); } $r = self::notification(array("{$id}" => $req), config::$accountId); $status = $r[0]; gio::output($r[1]); if ($status) { account::spentcoins($coins, config::$accountId); } if ($status || !$status && !gio::confirm("Do you want to try again")) { break; } } gio::output(); break; } } } } } }
public static function grant() { $net = new Gnet(); $m['account'] = config::$accountId; $m = GsonCrypt::sign(Gmsg::create($m)); $m = Gmsg::create(Gmsg::Prepare($m, "pullrequests", config::$bankId)); $net = new Gnet(); $r = $net->send($m); unset($net); if (!$r) { $status = 0; $res = "Unable to send the message"; } else { $v = GsonCrypt::verify($r, config::$bankId); if (!$v) { $status = 0; $res = "Unable to verify response from bank"; } else { $v = Gmsg::extract($v); if (!$v) { $status = 0; $res = "Unable to understand the response"; } else { $status = $v['status']; $res = $v['response']; } } } if (!$status) { gio::output($res); } else { $res = Gmsg::extract($res); if (!is_array($res)) { $status = 0; gio::output("Invalid response from bank"); } else { if (count($res) < 1) { gio::output("No pending payment requests"); } else { foreach ($res as $id => $req) { gio::output(); $disp = $req; $disp['time'] = date(config::$timeFormat, $disp['time']); gio::display($disp); gio::output(); if (gio::confirm("Do you want to grant this payment")) { while (true) { $amount = gio::input("Enter amount to confirm or c to cancel"); if ($amount == 'c' || $amount == 'C') { break; } if ($req['amount'] == $amount) { while (true) { $coins = account::getcoins($amount); if (!$coins) { gio::output("Isufficient balance"); break; } $req['coins'] = $coins; $r = self::sendnotification($id, $req); $status = $r[0]; gio::output($r[1]); if ($status) { account::spentcoins($coins); } if ($status || !$status && !gio::confirm("Do you want to try again")) { break; } } gio::output(); break; } } } } } } } }